4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 1990 Mentat Inc.
25 * Copyright (c) 2017 OmniTI Computer Consulting, Inc. All rights reserved.
26 * Copyright (c) 2016 by Delphix. All rights reserved.
27 * Copyright (c) 2018 Joyent, Inc. All rights reserved.
30 #include <sys/types.h>
31 #include <sys/stream.h>
33 #include <sys/stropts.h>
34 #include <sys/sysmacros.h>
35 #include <sys/strsubr.h>
36 #include <sys/strlog.h>
37 #include <sys/strsun.h>
39 #define _SUN_TPI_VERSION 2
40 #include <sys/tihdr.h>
41 #include <sys/xti_inet.h>
43 #include <sys/suntpi.h>
44 #include <sys/cmn_err.h>
45 #include <sys/debug.h>
47 #include <sys/modctl.h>
48 #include <sys/atomic.h>
49 #include <sys/policy.h>
51 #include <sys/taskq.h>
53 #include <sys/systm.h>
54 #include <sys/param.h>
57 #include <sys/socket.h>
58 #include <sys/vtrace.h>
59 #include <sys/isa_defs.h>
62 #include <net/if_arp.h>
63 #include <net/route.h>
64 #include <sys/sockio.h>
65 #include <netinet/in.h>
66 #include <net/if_dl.h>
68 #include <inet/common.h>
70 #include <inet/mib2.h>
73 #include <inet/snmpcom.h>
74 #include <inet/optcom.h>
75 #include <inet/kstatcom.h>
77 #include <netinet/igmp_var.h>
78 #include <netinet/ip6.h>
79 #include <netinet/icmp6.h>
80 #include <netinet/sctp.h>
83 #include <inet/ip_impl.h>
85 #include <inet/ip6_asp.h>
87 #include <inet/tcp_impl.h>
88 #include <inet/ip_multi.h>
89 #include <inet/ip_if.h>
90 #include <inet/ip_ire.h>
91 #include <inet/ip_ftable.h>
92 #include <inet/ip_rts.h>
93 #include <inet/ip_ndp.h>
94 #include <inet/ip_listutils.h>
95 #include <netinet/igmp.h>
96 #include <netinet/ip_mroute.h>
97 #include <inet/ipp_common.h>
99 #include <net/pfkeyv2.h>
100 #include <inet/sadb.h>
101 #include <inet/ipsec_impl.h>
102 #include <inet/iptun/iptun_impl.h>
103 #include <inet/ipdrop.h>
104 #include <inet/ip_netinfo.h>
105 #include <inet/ilb_ip.h>
107 #include <sys/ethernet.h>
108 #include <net/if_types.h>
109 #include <sys/cpuvar.h>
112 #include <ipp/ipp_impl.h>
113 #include <ipp/ipgpc/ipgpc.h>
115 #include <sys/pattr.h>
116 #include <inet/ipclassifier.h>
117 #include <inet/sctp_ip.h>
118 #include <inet/sctp/sctp_impl.h>
119 #include <inet/udp_impl.h>
120 #include <inet/rawip_impl.h>
121 #include <inet/rts_impl.h>
123 #include <sys/squeue_impl.h>
124 #include <inet/ip_arp.h>
126 #include <sys/clock_impl.h> /* For LBOLT_FASTPATH{,64} */
129 * Values for squeue switch:
130 * IP_SQUEUE_ENTER_NODRAIN: SQ_NODRAIN
131 * IP_SQUEUE_ENTER: SQ_PROCESS
132 * IP_SQUEUE_FILL: SQ_FILL
134 int ip_squeue_enter
= IP_SQUEUE_ENTER
; /* Setable in /etc/system */
139 * Setable in /etc/system
141 int ip_poll_normal_ms
= 100;
142 int ip_poll_normal_ticks
= 0;
143 int ip_modclose_ackwait_ms
= 3000;
146 * It would be nice to have these present only in DEBUG systems, but the
147 * current design of the global symbol checking logic requires them to be
148 * unconditionally present.
150 uint_t ip_thread_data
; /* TSD key for debug support */
151 krwlock_t ip_thread_rwlock
;
152 list_t ip_thread_list
;
155 * Structure to represent a linked list of msgblks. Used by ip_snmp_ functions.
159 mblk_t
*lp_head
; /* pointer to the head of the list */
160 mblk_t
*lp_tail
; /* pointer to the tail of the list */
163 typedef struct listptr_s listptr_t
;
166 * This is used by ip_snmp_get_mib2_ip_route_media and
167 * ip_snmp_get_mib2_ip6_route_media to carry the lists of return data.
169 typedef struct iproutedata_s
{
171 uint_t ird_flags
; /* see below */
172 listptr_t ird_route
; /* ipRouteEntryTable */
173 listptr_t ird_netmedia
; /* ipNetToMediaEntryTable */
176 /* Include ire_testhidden and IRE_IF_CLONE routes */
177 #define IRD_REPORT_ALL 0x01
180 * Synchronization notes:
182 * IP is a fully D_MP STREAMS module/driver. Thus it does not depend on any
183 * MT level protection given by STREAMS. IP uses a combination of its own
184 * internal serialization mechanism and standard Solaris locking techniques.
185 * The internal serialization is per phyint. This is used to serialize
186 * plumbing operations, IPMP operations, most set ioctls, etc.
188 * Plumbing is a long sequence of operations involving message
189 * exchanges between IP, ARP and device drivers. Many set ioctls are typically
190 * involved in plumbing operations. A natural model is to serialize these
191 * ioctls one per ill. For example plumbing of hme0 and qfe0 can go on in
192 * parallel without any interference. But various set ioctls on hme0 are best
193 * serialized, along with IPMP operations and processing of DLPI control
194 * messages received from drivers on a per phyint basis. This serialization is
195 * provided by the ipsq_t and primitives operating on this. Details can
196 * be found in ip_if.c above the core primitives operating on ipsq_t.
198 * Lookups of an ipif or ill by a thread return a refheld ipif / ill.
199 * Simiarly lookup of an ire by a thread also returns a refheld ire.
200 * In addition ipif's and ill's referenced by the ire are also indirectly
201 * refheld. Thus no ipif or ill can vanish as long as an ipif is refheld
202 * directly or indirectly. For example an SIOCSLIFADDR ioctl that changes the
203 * address of an ipif has to go through the ipsq_t. This ensures that only
204 * one such exclusive operation proceeds at any time on the ipif. It then
205 * waits for all refcnts
206 * associated with this ipif to come down to zero. The address is changed
207 * only after the ipif has been quiesced. Then the ipif is brought up again.
208 * More details are described above the comment in ip_sioctl_flags.
210 * Packet processing is based mostly on IREs and are fully multi-threaded
211 * using standard Solaris MT techniques.
213 * There are explicit locks in IP to handle:
214 * - The ip_g_head list maintained by mi_open_link() and friends.
216 * - The reassembly data structures (one lock per hash bucket)
218 * - conn_lock is meant to protect conn_t fields. The fields actually
219 * protected by conn_lock are documented in the conn_t definition.
221 * - ire_lock to protect some of the fields of the ire, IRE tables
222 * (one lock per hash bucket). Refer to ip_ire.c for details.
224 * - ndp_g_lock and ncec_lock for protecting NCEs.
226 * - ill_lock protects fields of the ill and ipif. Details in ip.h
228 * - ill_g_lock: This is a global reader/writer lock. Protects the following
229 * * The AVL tree based global multi list of all ills.
230 * * The linked list of all ipifs of an ill
231 * * The <ipsq-xop> mapping
232 * * <ill-phyint> association
233 * Insertion/deletion of an ill in the system, insertion/deletion of an ipif
234 * into an ill, changing the <ipsq-xop> mapping of an ill, changing the
235 * <ill-phyint> assoc of an ill will all have to hold the ill_g_lock as
236 * writer for the actual duration of the insertion/deletion/change.
238 * - ill_lock: This is a per ill mutex.
239 * It protects some members of the ill_t struct; see ip.h for details.
240 * It also protects the <ill-phyint> assoc.
241 * It also protects the list of ipifs hanging off the ill.
243 * - ipsq_lock: This is a per ipsq_t mutex lock.
244 * This protects some members of the ipsq_t struct; see ip.h for details.
245 * It also protects the <ipsq-ipxop> mapping
247 * - ipx_lock: This is a per ipxop_t mutex lock.
248 * This protects some members of the ipxop_t struct; see ip.h for details.
250 * - phyint_lock: This is a per phyint mutex lock. Protects just the
253 * - ip_addr_avail_lock: This is used to ensure the uniqueness of IP addresses.
254 * This lock is held in ipif_up_done and the ipif is marked IPIF_UP and the
255 * uniqueness check also done atomically.
257 * - ill_g_usesrc_lock: This readers/writer lock protects the usesrc
258 * group list linked by ill_usesrc_grp_next. It also protects the
259 * ill_usesrc_ifindex field. It is taken as a writer when a member of the
260 * group is being added or deleted. This lock is taken as a reader when
261 * walking the list/group(eg: to get the number of members in a usesrc group).
262 * Note, it is only necessary to take this lock if the ill_usesrc_grp_next
263 * field is changing state i.e from NULL to non-NULL or vice-versa. For
264 * example, it is not necessary to take this lock in the initial portion
265 * of ip_sioctl_slifusesrc or at all in ip_sioctl_flags since these
266 * operations are executed exclusively and that ensures that the "usesrc
267 * group state" cannot change. The "usesrc group state" change can happen
268 * only in the latter part of ip_sioctl_slifusesrc and in ill_delete.
270 * Changing <ill-phyint>, <ipsq-xop> assocications:
272 * To change the <ill-phyint> association, the ill_g_lock must be held
273 * as writer, and the ill_locks of both the v4 and v6 instance of the ill
276 * To change the <ipsq-xop> association, the ill_g_lock must be held as
277 * writer, the ipsq_lock must be held, and one must be writer on the ipsq.
278 * This is only done when ills are added or removed from IPMP groups.
280 * To add or delete an ipif from the list of ipifs hanging off the ill,
281 * ill_g_lock (writer) and ill_lock must be held and the thread must be
282 * a writer on the associated ipsq.
284 * To add or delete an ill to the system, the ill_g_lock must be held as
285 * writer and the thread must be a writer on the associated ipsq.
287 * To add or delete an ilm to an ill, the ill_lock must be held and the thread
288 * must be a writer on the associated ipsq.
292 * Some lock hierarchy scenarios are listed below.
294 * ill_g_lock -> conn_lock -> ill_lock -> ipsq_lock -> ipx_lock
295 * ill_g_lock -> ill_lock(s) -> phyint_lock
296 * ill_g_lock -> ndp_g_lock -> ill_lock -> ncec_lock
297 * ill_g_lock -> ip_addr_avail_lock
298 * conn_lock -> irb_lock -> ill_lock -> ire_lock
299 * ill_g_lock -> ip_g_nd_lock
300 * ill_g_lock -> ips_ipmp_lock -> ill_lock -> nce_lock
301 * ill_g_lock -> ndp_g_lock -> ill_lock -> ncec_lock -> nce_lock
302 * arl_lock -> ill_lock
303 * ips_ire_dep_lock -> irb_lock
305 * When more than 1 ill lock is needed to be held, all ill lock addresses
306 * are sorted on address and locked starting from highest addressed lock
309 * Multicast scenarios
310 * ips_ill_g_lock -> ill_mcast_lock
311 * conn_ilg_lock -> ips_ill_g_lock -> ill_lock
312 * ill_mcast_serializer -> ill_mcast_lock -> ips_ipmp_lock -> ill_lock
313 * ill_mcast_serializer -> ill_mcast_lock -> connf_lock -> conn_lock
314 * ill_mcast_serializer -> ill_mcast_lock -> conn_ilg_lock
315 * ill_mcast_serializer -> ill_mcast_lock -> ips_igmp_timer_lock
319 * ipsa_lock -> ill_g_lock -> ill_lock
320 * ill_g_usesrc_lock -> ill_g_lock -> ill_lock
322 * squeue(sq_lock), flow related (ft_lock, fe_lock) locking
324 * cpu_lock --> ill_lock --> sqset_lock --> sq_lock
325 * sq_lock -> conn_lock -> QLOCK(q)
326 * ill_lock -> ft_lock -> fe_lock
328 * Routing/forwarding table locking notes:
330 * Lock acquisition order: Radix tree lock, irb_lock.
332 * i. Walker must not hold any locks during the walker callback.
333 * ii Walker must not see a truncated tree during the walk because of any node
335 * iii Existing code assumes ire_bucket is valid if it is non-null and is used
336 * in many places in the code to walk the irb list. Thus even if all the
337 * ires in a bucket have been deleted, we still can't free the radix node
338 * until the ires have actually been inactive'd (freed).
340 * Tree traversal - Need to hold the global tree lock in read mode.
341 * Before dropping the global tree lock, need to either increment the ire_refcnt
342 * to ensure that the radix node can't be deleted.
344 * Tree add - Need to hold the global tree lock in write mode to add a
345 * radix node. To prevent the node from being deleted, increment the
346 * irb_refcnt, after the node is added to the tree. The ire itself is
347 * added later while holding the irb_lock, but not the tree lock.
349 * Tree delete - Need to hold the global tree lock and irb_lock in write mode.
350 * All associated ires must be inactive (i.e. freed), and irb_refcnt
353 * Walker - Increment irb_refcnt before calling the walker callback. Hold the
354 * global tree lock (read mode) for traversal.
356 * IRE dependencies - In some cases we hold ips_ire_dep_lock across ire_refrele
357 * hence we will acquire irb_lock while holding ips_ire_dep_lock.
361 * IP interacts with the IPsec code (AH/ESP) by storing IPsec attributes
362 * in the ip_xmit_attr_t ip_recv_attr_t. For outbound datagrams, the
363 * ip_xmit_attr_t has the
364 * information used by the IPsec code for applying the right level of
365 * protection. The information initialized by IP in the ip_xmit_attr_t
366 * is determined by the per-socket policy or global policy in the system.
367 * For inbound datagrams, the ip_recv_attr_t
368 * starts out with nothing in it. It gets filled
369 * with the right information if it goes through the AH/ESP code, which
370 * happens if the incoming packet is secure. The information initialized
371 * by AH/ESP, is later used by IP (during fanouts to ULP) to see whether
372 * the policy requirements needed by per-socket policy or global policy
375 * For fully connected sockets i.e dst, src [addr, port] is known,
376 * conn_policy_cached is set indicating that policy has been cached.
377 * conn_in_enforce_policy may or may not be set depending on whether
378 * there is a global policy match or per-socket policy match.
379 * Policy inheriting happpens in ip_policy_set once the destination is known.
380 * Once the right policy is set on the conn_t, policy cannot change for
381 * this socket. This makes life simpler for TCP (UDP ?) where
382 * re-transmissions go out with the same policy. For symmetry, policy
383 * is cached for fully connected UDP sockets also. Thus if policy is cached,
384 * it also implies that policy is latched i.e policy cannot change
385 * on these sockets. As we have the right policy on the conn, we don't
386 * have to lookup global policy for every outbound and inbound datagram
387 * and thus serving as an optimization. Note that a global policy change
388 * does not affect fully connected sockets if they have policy. If fully
389 * connected sockets did not have any policy associated with it, global
390 * policy change may affect them.
392 * IP Flow control notes:
393 * ---------------------
394 * Non-TCP streams are flow controlled by IP. The way this is accomplished
395 * differs when ILL_CAPAB_DLD_DIRECT is enabled for that IP instance. When
396 * ILL_DIRECT_CAPABLE(ill) is TRUE, IP can do direct function calls into
397 * GLDv3. Otherwise packets are sent down to lower layers using STREAMS
400 * Per Tx ring udp flow control:
401 * This is applicable only when ILL_CAPAB_DLD_DIRECT capability is set in
402 * the ill (i.e. ILL_DIRECT_CAPABLE(ill) is true).
404 * The underlying link can expose multiple Tx rings to the GLDv3 mac layer.
405 * To achieve best performance, outgoing traffic need to be fanned out among
406 * these Tx ring. mac_tx() is called (via str_mdata_fastpath_put()) to send
407 * traffic out of the NIC and it takes a fanout hint. UDP connections pass
408 * the address of connp as fanout hint to mac_tx(). Under flow controlled
409 * condition, mac_tx() returns a non-NULL cookie (ip_mac_tx_cookie_t). This
410 * cookie points to a specific Tx ring that is blocked. The cookie is used to
411 * hash into an idl_tx_list[] entry in idl_tx_list[] array. Each idl_tx_list_t
412 * point to drain_lists (idl_t's). These drain list will store the blocked UDP
413 * connp's. The drain list is not a single list but a configurable number of
416 * The diagram below shows idl_tx_list_t's and their drain_lists. ip_stack_t
417 * has an array of idl_tx_list_t. The size of the array is TX_FANOUT_SIZE
418 * which is equal to 128. This array in turn contains a pointer to idl_t[],
419 * the ip drain list. The idl_t[] array size is MIN(max_ncpus, 8). The drain
420 * list will point to the list of connp's that are flow controlled.
422 * --------------- ------- ------- -------
423 * |->|drain_list[0]|-->|connp|-->|connp|-->|connp|-->
424 * | --------------- ------- ------- -------
425 * | --------------- ------- ------- -------
426 * |->|drain_list[1]|-->|connp|-->|connp|-->|connp|-->
427 * ---------------- | --------------- ------- ------- -------
428 * |idl_tx_list[0]|->| --------------- ------- ------- -------
429 * ---------------- |->|drain_list[2]|-->|connp|-->|connp|-->|connp|-->
430 * | --------------- ------- ------- -------
432 * | --------------- ------- ------- -------
433 * |->|drain_list[n]|-->|connp|-->|connp|-->|connp|-->
434 * --------------- ------- ------- -------
435 * --------------- ------- ------- -------
436 * |->|drain_list[0]|-->|connp|-->|connp|-->|connp|-->
437 * | --------------- ------- ------- -------
438 * | --------------- ------- ------- -------
439 * ---------------- |->|drain_list[1]|-->|connp|-->|connp|-->|connp|-->
440 * |idl_tx_list[1]|->| --------------- ------- ------- -------
441 * ---------------- | . . . .
442 * | --------------- ------- ------- -------
443 * |->|drain_list[n]|-->|connp|-->|connp|-->|connp|-->
444 * --------------- ------- ------- -------
447 * |idl_tx_list[n]|-> ...
450 * When mac_tx() returns a cookie, the cookie is hashed into an index into
451 * ips_idl_tx_list[], and conn_drain_insert() is called with the idl_tx_list
452 * to insert the conn onto. conn_drain_insert() asserts flow control for the
453 * sockets via su_txq_full() (non-STREAMS) or QFULL on conn_wq (STREAMS).
454 * Further, conn_blocked is set to indicate that the conn is blocked.
456 * GLDv3 calls ill_flow_enable() when flow control is relieved. The cookie
457 * passed in the call to ill_flow_enable() identifies the blocked Tx ring and
458 * is again hashed to locate the appropriate idl_tx_list, which is then
459 * drained via conn_walk_drain(). conn_walk_drain() goes through each conn in
460 * the drain list and calls conn_drain_remove() to clear flow control (via
461 * calling su_txq_full() or clearing QFULL), and remove the conn from the
464 * Note that the drain list is not a single list but a (configurable) array of
465 * lists (8 elements by default). Synchronization between drain insertion and
466 * flow control wakeup is handled by using idl_txl->txl_lock, and only
467 * conn_drain_insert() and conn_drain_remove() manipulate the drain list.
469 * Flow control via STREAMS is used when ILL_DIRECT_CAPABLE() returns FALSE.
470 * On the send side, if the packet cannot be sent down to the driver by IP
471 * (canput() fails), ip_xmit() drops the packet and returns EWOULDBLOCK to the
472 * caller, who may then invoke ixa_check_drain_insert() to insert the conn on
473 * the 0'th drain list. When ip_wsrv() runs on the ill_wq because flow
474 * control has been relieved, the blocked conns in the 0'th drain list are
475 * drained as in the non-STREAMS case.
477 * In both the STREAMS and non-STREAMS cases, the sockfs upcall to set QFULL
478 * is done when the conn is inserted into the drain list (conn_drain_insert())
479 * and cleared when the conn is removed from the it (conn_drain_remove()).
483 * IPQoS Policies are applied to packets using IPPF (IP Policy framework)
484 * and IPQoS modules. IPPF includes hooks in IP at different control points
485 * (callout positions) which direct packets to IPQoS modules for policy
486 * processing. Policies, if present, are global.
488 * The callout positions are located in the following paths:
489 * o local_in (packets destined for this host)
490 * o local_out (packets orginating from this host )
491 * o fwd_in (packets forwarded by this m/c - inbound)
492 * o fwd_out (packets forwarded by this m/c - outbound)
493 * Hooks at these callout points can be enabled/disabled using the ndd variable
494 * ip_policy_mask (a bit mask with the 4 LSB indicating the callout positions).
495 * By default all the callout positions are enabled.
497 * Outbound (local_out)
498 * Hooks are placed in ire_send_wire_v4 and ire_send_wire_v6.
501 * Hooks are placed in ip_fanout_v4 and ip_fanout_v6.
503 * Forwarding (in and out)
504 * Hooks are placed in ire_recv_forward_v4/v6.
506 * IP Policy Framework processing (IPPF processing)
507 * Policy processing for a packet is initiated by ip_process, which ascertains
508 * that the classifier (ipgpc) is loaded and configured, failing which the
509 * packet resumes normal processing in IP. If the clasifier is present, the
510 * packet is acted upon by one or more IPQoS modules (action instances), per
511 * filters configured in ipgpc and resumes normal IP processing thereafter.
512 * An action instance can drop a packet in course of its processing.
516 * The partitioning rules for networking are as follows:
517 * 1) Packets coming from a zone must have a source address belonging to that
519 * 2) Packets coming from a zone can only be sent on a physical interface on
520 * which the zone has an IP address.
521 * 3) Between two zones on the same machine, packet delivery is only allowed if
522 * there's a matching route for the destination and zone in the forwarding
524 * 4) The TCP and UDP port spaces are per-zone; that is, two processes in
525 * different zones can bind to the same port with the wildcard address
528 * The granularity of interface partitioning is at the logical interface level.
529 * Therefore, every zone has its own IP addresses, and incoming packets can be
530 * attributed to a zone unambiguously. A logical interface is placed into a zone
531 * using the SIOCSLIFZONE ioctl; this sets the ipif_zoneid field in the ipif_t
532 * structure. Rule (1) is implemented by modifying the source address selection
533 * algorithm so that the list of eligible addresses is filtered based on the
534 * sending process zone.
536 * The Internet Routing Entries (IREs) are either exclusive to a zone or shared
537 * across all zones, depending on their type. Here is the break-up:
539 * IRE type Shared/exclusive
540 * -------- ----------------
541 * IRE_BROADCAST Exclusive
542 * IRE_DEFAULT (default routes) Shared (*)
543 * IRE_LOCAL Exclusive (x)
544 * IRE_LOOPBACK Exclusive
545 * IRE_PREFIX (net routes) Shared (*)
546 * IRE_IF_NORESOLVER (interface routes) Exclusive
547 * IRE_IF_RESOLVER (interface routes) Exclusive
548 * IRE_IF_CLONE (interface routes) Exclusive
549 * IRE_HOST (host routes) Shared (*)
551 * (*) A zone can only use a default or off-subnet route if the gateway is
552 * directly reachable from the zone, that is, if the gateway's address matches
553 * one of the zone's logical interfaces.
555 * (x) IRE_LOCAL are handled a bit differently.
556 * When ip_restrict_interzone_loopback is set (the default),
557 * ire_route_recursive restricts loopback using an IRE_LOCAL
558 * between zone to the case when L2 would have conceptually looped the packet
559 * back, i.e. the loopback which is required since neither Ethernet drivers
560 * nor Ethernet hardware loops them back. This is the case when the normal
561 * routes (ignoring IREs with different zoneids) would send out the packet on
562 * the same ill as the ill with which is IRE_LOCAL is associated.
564 * Multiple zones can share a common broadcast address; typically all zones
565 * share the 255.255.255.255 address. Incoming as well as locally originated
566 * broadcast packets must be dispatched to all the zones on the broadcast
567 * network. For directed broadcasts (e.g. 10.16.72.255) this is not trivial
568 * since some zones may not be on the 10.16.72/24 network. To handle this, each
569 * zone has its own set of IRE_BROADCAST entries; then, broadcast packets are
570 * sent to every zone that has an IRE_BROADCAST entry for the destination
571 * address on the input ill, see ip_input_broadcast().
573 * Applications in different zones can join the same multicast group address.
574 * The same logic applies for multicast as for broadcast. ip_input_multicast
575 * dispatches packets to all zones that have members on the physical interface.
579 * Squeue Fanout flags:
581 * 1: Fanout across all squeues
583 boolean_t ip_squeue_fanout
= 0;
586 * Maximum dups allowed per packet.
588 uint_t ip_max_frag_dups
= 10;
590 static int ip_open(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
,
591 cred_t
*credp
, boolean_t isv6
);
592 static mblk_t
*ip_xmit_attach_llhdr(mblk_t
*, nce_t
*);
594 static boolean_t
icmp_inbound_verify_v4(mblk_t
*, icmph_t
*, ip_recv_attr_t
*);
595 static void icmp_inbound_too_big_v4(icmph_t
*, ip_recv_attr_t
*);
596 static void icmp_inbound_error_fanout_v4(mblk_t
*, icmph_t
*,
598 static void icmp_options_update(ipha_t
*);
599 static void icmp_param_problem(mblk_t
*, uint8_t, ip_recv_attr_t
*);
600 static void icmp_pkt(mblk_t
*, void *, size_t, ip_recv_attr_t
*);
601 static mblk_t
*icmp_pkt_err_ok(mblk_t
*, ip_recv_attr_t
*);
602 static void icmp_redirect_v4(mblk_t
*mp
, ipha_t
*, icmph_t
*,
604 static void icmp_send_redirect(mblk_t
*, ipaddr_t
, ip_recv_attr_t
*);
605 static void icmp_send_reply_v4(mblk_t
*, ipha_t
*, icmph_t
*,
608 mblk_t
*ip_dlpi_alloc(size_t, t_uscalar_t
);
609 char *ip_dot_addr(ipaddr_t
, char *);
610 mblk_t
*ip_carve_mp(mblk_t
**, ssize_t
);
611 static char *ip_dot_saddr(uchar_t
*, char *);
612 static int ip_lrput(queue_t
*, mblk_t
*);
613 ipaddr_t
ip_net_mask(ipaddr_t
);
614 char *ip_nv_lookup(nv_t
*, int);
615 int ip_rput(queue_t
*, mblk_t
*);
616 static void ip_rput_dlpi_writer(ipsq_t
*dummy_sq
, queue_t
*q
, mblk_t
*mp
,
618 int ip_snmp_get(queue_t
*, mblk_t
*, int, boolean_t
);
619 static mblk_t
*ip_snmp_get_mib2_ip(queue_t
*, mblk_t
*,
620 mib2_ipIfStatsEntry_t
*, ip_stack_t
*, boolean_t
);
621 static mblk_t
*ip_snmp_get_mib2_ip_traffic_stats(queue_t
*, mblk_t
*,
622 ip_stack_t
*, boolean_t
);
623 static mblk_t
*ip_snmp_get_mib2_ip6(queue_t
*, mblk_t
*, ip_stack_t
*,
625 static mblk_t
*ip_snmp_get_mib2_icmp(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
626 static mblk_t
*ip_snmp_get_mib2_icmp6(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
627 static mblk_t
*ip_snmp_get_mib2_igmp(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
628 static mblk_t
*ip_snmp_get_mib2_multi(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
629 static mblk_t
*ip_snmp_get_mib2_ip_addr(queue_t
*, mblk_t
*,
630 ip_stack_t
*ipst
, boolean_t
);
631 static mblk_t
*ip_snmp_get_mib2_ip6_addr(queue_t
*, mblk_t
*,
632 ip_stack_t
*ipst
, boolean_t
);
633 static mblk_t
*ip_snmp_get_mib2_ip_group_src(queue_t
*, mblk_t
*,
635 static mblk_t
*ip_snmp_get_mib2_ip6_group_src(queue_t
*, mblk_t
*,
637 static mblk_t
*ip_snmp_get_mib2_ip_group_mem(queue_t
*, mblk_t
*,
639 static mblk_t
*ip_snmp_get_mib2_ip6_group_mem(queue_t
*, mblk_t
*,
641 static mblk_t
*ip_snmp_get_mib2_virt_multi(queue_t
*, mblk_t
*,
643 static mblk_t
*ip_snmp_get_mib2_multi_rtable(queue_t
*, mblk_t
*,
645 static mblk_t
*ip_snmp_get_mib2_ip_route_media(queue_t
*, mblk_t
*, int,
647 static mblk_t
*ip_snmp_get_mib2_ip6_route_media(queue_t
*, mblk_t
*, int,
649 static void ip_snmp_get2_v4(ire_t
*, iproutedata_t
*);
650 static void ip_snmp_get2_v6_route(ire_t
*, iproutedata_t
*);
651 static void ip_snmp_get2_v4_media(ncec_t
*, void *);
652 static void ip_snmp_get2_v6_media(ncec_t
*, void *);
653 int ip_snmp_set(queue_t
*, int, int, uchar_t
*, int);
655 static mblk_t
*ip_fragment_copyhdr(uchar_t
*, int, int, ip_stack_t
*,
658 static void conn_drain_init(ip_stack_t
*);
659 static void conn_drain_fini(ip_stack_t
*);
660 static void conn_drain(conn_t
*connp
, boolean_t closing
);
662 static void conn_walk_drain(ip_stack_t
*, idl_tx_list_t
*);
663 static void conn_walk_sctp(pfv_t
, void *, zoneid_t
, netstack_t
*);
665 static void *ip_stack_init(netstackid_t stackid
, netstack_t
*ns
);
666 static void ip_stack_shutdown(netstackid_t stackid
, void *arg
);
667 static void ip_stack_fini(netstackid_t stackid
, void *arg
);
669 static int ip_squeue_switch(int);
671 static void *ip_kstat_init(netstackid_t
, ip_stack_t
*);
672 static void ip_kstat_fini(netstackid_t
, kstat_t
*);
673 static int ip_kstat_update(kstat_t
*kp
, int rw
);
674 static void *icmp_kstat_init(netstackid_t
);
675 static void icmp_kstat_fini(netstackid_t
, kstat_t
*);
676 static int icmp_kstat_update(kstat_t
*kp
, int rw
);
677 static void *ip_kstat2_init(netstackid_t
, ip_stat_t
*);
678 static void ip_kstat2_fini(netstackid_t
, kstat_t
*);
680 static void ipobs_init(ip_stack_t
*);
681 static void ipobs_fini(ip_stack_t
*);
683 static int ip_tp_cpu_update(cpu_setup_t
, int, void *);
685 ipaddr_t ip_g_all_ones
= IP_HOST_MASK
;
687 static long ip_rput_pullups
;
688 int dohwcksum
= 1; /* use h/w cksum if supported by the hardware */
690 vmem_t
*ip_minor_arena_sa
; /* for minor nos. from INET_MIN_DEV+2 thru 2^^18-1 */
691 vmem_t
*ip_minor_arena_la
; /* for minor nos. from 2^^18 thru 2^^32-1 */
696 * IP tunables related declarations. Definitions are in ip_tunables.c
698 extern mod_prop_info_t ip_propinfo_tbl
[];
699 extern int ip_propinfo_count
;
702 * Table of IP ioctls encoding the various properties of the ioctl and
703 * indexed based on the last byte of the ioctl command. Occasionally there
704 * is a clash, and there is more than 1 ioctl with the same last byte.
705 * In such a case 1 ioctl is encoded in the ndx table and the remaining
706 * ioctls are encoded in the misc table. An entry in the ndx table is
707 * retrieved by indexing on the last byte of the ioctl command and comparing
708 * the ioctl command with the value in the ndx table. In the event of a
709 * mismatch the misc table is then searched sequentially for the desired
712 * Entry: <command> <copyin_size> <flags> <cmd_type> <function> <restart_func>
714 ip_ioctl_cmd_t ip_ndx_ioctl_table
[] = {
715 /* 000 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
716 /* 001 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
717 /* 002 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
718 /* 003 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
719 /* 004 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
720 /* 005 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
721 /* 006 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
722 /* 007 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
723 /* 008 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
724 /* 009 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
726 /* 010 */ { SIOCADDRT
, sizeof (struct rtentry
), IPI_PRIV
,
727 MISC_CMD
, ip_siocaddrt
, NULL
},
728 /* 011 */ { SIOCDELRT
, sizeof (struct rtentry
), IPI_PRIV
,
729 MISC_CMD
, ip_siocdelrt
, NULL
},
731 /* 012 */ { SIOCSIFADDR
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
732 IF_CMD
, ip_sioctl_addr
, ip_sioctl_addr_restart
},
733 /* 013 */ { SIOCGIFADDR
, sizeof (struct ifreq
), IPI_GET_CMD
,
734 IF_CMD
, ip_sioctl_get_addr
, NULL
},
736 /* 014 */ { SIOCSIFDSTADDR
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
737 IF_CMD
, ip_sioctl_dstaddr
, ip_sioctl_dstaddr_restart
},
738 /* 015 */ { SIOCGIFDSTADDR
, sizeof (struct ifreq
),
739 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_dstaddr
, NULL
},
741 /* 016 */ { SIOCSIFFLAGS
, sizeof (struct ifreq
),
743 IF_CMD
, ip_sioctl_flags
, ip_sioctl_flags_restart
},
744 /* 017 */ { SIOCGIFFLAGS
, sizeof (struct ifreq
),
745 IPI_MODOK
| IPI_GET_CMD
,
746 IF_CMD
, ip_sioctl_get_flags
, NULL
},
748 /* 018 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
749 /* 019 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
751 /* copyin size cannot be coded for SIOCGIFCONF */
752 /* 020 */ { O_SIOCGIFCONF
, 0, IPI_GET_CMD
,
753 MISC_CMD
, ip_sioctl_get_ifconf
, NULL
},
755 /* 021 */ { SIOCSIFMTU
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
756 IF_CMD
, ip_sioctl_mtu
, NULL
},
757 /* 022 */ { SIOCGIFMTU
, sizeof (struct ifreq
), IPI_GET_CMD
,
758 IF_CMD
, ip_sioctl_get_mtu
, NULL
},
759 /* 023 */ { SIOCGIFBRDADDR
, sizeof (struct ifreq
),
760 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_brdaddr
, NULL
},
761 /* 024 */ { SIOCSIFBRDADDR
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
762 IF_CMD
, ip_sioctl_brdaddr
, NULL
},
763 /* 025 */ { SIOCGIFNETMASK
, sizeof (struct ifreq
),
764 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_netmask
, NULL
},
765 /* 026 */ { SIOCSIFNETMASK
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
766 IF_CMD
, ip_sioctl_netmask
, ip_sioctl_netmask_restart
},
767 /* 027 */ { SIOCGIFMETRIC
, sizeof (struct ifreq
),
768 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_metric
, NULL
},
769 /* 028 */ { SIOCSIFMETRIC
, sizeof (struct ifreq
), IPI_PRIV
,
770 IF_CMD
, ip_sioctl_metric
, NULL
},
771 /* 029 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
773 /* See 166-168 below for extended SIOC*XARP ioctls */
774 /* 030 */ { SIOCSARP
, sizeof (struct arpreq
), IPI_PRIV
| IPI_WR
,
775 ARP_CMD
, ip_sioctl_arp
, NULL
},
776 /* 031 */ { SIOCGARP
, sizeof (struct arpreq
), IPI_GET_CMD
,
777 ARP_CMD
, ip_sioctl_arp
, NULL
},
778 /* 032 */ { SIOCDARP
, sizeof (struct arpreq
), IPI_PRIV
| IPI_WR
,
779 ARP_CMD
, ip_sioctl_arp
, NULL
},
781 /* 033 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
782 /* 034 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
783 /* 035 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
784 /* 036 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
785 /* 037 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
786 /* 038 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
787 /* 039 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
788 /* 040 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
789 /* 041 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
790 /* 042 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
791 /* 043 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
792 /* 044 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
793 /* 045 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
794 /* 046 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
795 /* 047 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
796 /* 048 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
797 /* 049 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
798 /* 050 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
799 /* 051 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
800 /* 052 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
801 /* 053 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
803 /* 054 */ { IF_UNITSEL
, sizeof (int), IPI_PRIV
| IPI_WR
| IPI_MODOK
,
804 MISC_CMD
, if_unitsel
, if_unitsel_restart
},
806 /* 055 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
807 /* 056 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
808 /* 057 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
809 /* 058 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
810 /* 059 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
811 /* 060 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
812 /* 061 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
813 /* 062 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
814 /* 063 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
815 /* 064 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
816 /* 065 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
817 /* 066 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
818 /* 067 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
819 /* 068 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
820 /* 069 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
821 /* 070 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
822 /* 071 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
823 /* 072 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
825 /* 073 */ { SIOCSIFNAME
, sizeof (struct ifreq
),
826 IPI_PRIV
| IPI_WR
| IPI_MODOK
,
827 IF_CMD
, ip_sioctl_sifname
, NULL
},
829 /* 074 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
830 /* 075 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
831 /* 076 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
832 /* 077 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
833 /* 078 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
834 /* 079 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
835 /* 080 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
836 /* 081 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
837 /* 082 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
838 /* 083 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
839 /* 084 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
840 /* 085 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
841 /* 086 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
843 /* 087 */ { SIOCGIFNUM
, sizeof (int), IPI_GET_CMD
,
844 MISC_CMD
, ip_sioctl_get_ifnum
, NULL
},
845 /* 088 */ { SIOCGIFMUXID
, sizeof (struct ifreq
), IPI_GET_CMD
,
846 IF_CMD
, ip_sioctl_get_muxid
, NULL
},
847 /* 089 */ { SIOCSIFMUXID
, sizeof (struct ifreq
),
848 IPI_PRIV
| IPI_WR
, IF_CMD
, ip_sioctl_muxid
, NULL
},
850 /* Both if and lif variants share same func */
851 /* 090 */ { SIOCGIFINDEX
, sizeof (struct ifreq
), IPI_GET_CMD
,
852 IF_CMD
, ip_sioctl_get_lifindex
, NULL
},
853 /* Both if and lif variants share same func */
854 /* 091 */ { SIOCSIFINDEX
, sizeof (struct ifreq
),
855 IPI_PRIV
| IPI_WR
, IF_CMD
, ip_sioctl_slifindex
, NULL
},
857 /* copyin size cannot be coded for SIOCGIFCONF */
858 /* 092 */ { SIOCGIFCONF
, 0, IPI_GET_CMD
,
859 MISC_CMD
, ip_sioctl_get_ifconf
, NULL
},
860 /* 093 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
861 /* 094 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
862 /* 095 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
863 /* 096 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
864 /* 097 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
865 /* 098 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
866 /* 099 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
867 /* 100 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
868 /* 101 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
869 /* 102 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
870 /* 103 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
871 /* 104 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
872 /* 105 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
873 /* 106 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
874 /* 107 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
875 /* 108 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
876 /* 109 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
878 /* 110 */ { SIOCLIFREMOVEIF
, sizeof (struct lifreq
),
879 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_removeif
,
880 ip_sioctl_removeif_restart
},
881 /* 111 */ { SIOCLIFADDIF
, sizeof (struct lifreq
),
882 IPI_GET_CMD
| IPI_PRIV
| IPI_WR
,
883 LIF_CMD
, ip_sioctl_addif
, NULL
},
884 #define SIOCLIFADDR_NDX 112
885 /* 112 */ { SIOCSLIFADDR
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
886 LIF_CMD
, ip_sioctl_addr
, ip_sioctl_addr_restart
},
887 /* 113 */ { SIOCGLIFADDR
, sizeof (struct lifreq
),
888 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_addr
, NULL
},
889 /* 114 */ { SIOCSLIFDSTADDR
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
890 LIF_CMD
, ip_sioctl_dstaddr
, ip_sioctl_dstaddr_restart
},
891 /* 115 */ { SIOCGLIFDSTADDR
, sizeof (struct lifreq
),
892 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_dstaddr
, NULL
},
893 /* 116 */ { SIOCSLIFFLAGS
, sizeof (struct lifreq
),
895 LIF_CMD
, ip_sioctl_flags
, ip_sioctl_flags_restart
},
896 /* 117 */ { SIOCGLIFFLAGS
, sizeof (struct lifreq
),
897 IPI_GET_CMD
| IPI_MODOK
,
898 LIF_CMD
, ip_sioctl_get_flags
, NULL
},
900 /* 118 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
901 /* 119 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
903 /* 120 */ { O_SIOCGLIFCONF
, 0, IPI_GET_CMD
, MISC_CMD
,
904 ip_sioctl_get_lifconf
, NULL
},
905 /* 121 */ { SIOCSLIFMTU
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
906 LIF_CMD
, ip_sioctl_mtu
, NULL
},
907 /* 122 */ { SIOCGLIFMTU
, sizeof (struct lifreq
), IPI_GET_CMD
,
908 LIF_CMD
, ip_sioctl_get_mtu
, NULL
},
909 /* 123 */ { SIOCGLIFBRDADDR
, sizeof (struct lifreq
),
910 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_brdaddr
, NULL
},
911 /* 124 */ { SIOCSLIFBRDADDR
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
912 LIF_CMD
, ip_sioctl_brdaddr
, NULL
},
913 /* 125 */ { SIOCGLIFNETMASK
, sizeof (struct lifreq
),
914 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_netmask
, NULL
},
915 /* 126 */ { SIOCSLIFNETMASK
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
916 LIF_CMD
, ip_sioctl_netmask
, ip_sioctl_netmask_restart
},
917 /* 127 */ { SIOCGLIFMETRIC
, sizeof (struct lifreq
),
918 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_metric
, NULL
},
919 /* 128 */ { SIOCSLIFMETRIC
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
920 LIF_CMD
, ip_sioctl_metric
, NULL
},
921 /* 129 */ { SIOCSLIFNAME
, sizeof (struct lifreq
),
922 IPI_PRIV
| IPI_WR
| IPI_MODOK
,
923 LIF_CMD
, ip_sioctl_slifname
,
924 ip_sioctl_slifname_restart
},
926 /* 130 */ { SIOCGLIFNUM
, sizeof (struct lifnum
), IPI_GET_CMD
,
927 MISC_CMD
, ip_sioctl_get_lifnum
, NULL
},
928 /* 131 */ { SIOCGLIFMUXID
, sizeof (struct lifreq
),
929 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_muxid
, NULL
},
930 /* 132 */ { SIOCSLIFMUXID
, sizeof (struct lifreq
),
931 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_muxid
, NULL
},
932 /* 133 */ { SIOCGLIFINDEX
, sizeof (struct lifreq
),
933 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_lifindex
, 0 },
934 /* 134 */ { SIOCSLIFINDEX
, sizeof (struct lifreq
),
935 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_slifindex
, 0 },
936 /* 135 */ { SIOCSLIFTOKEN
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
937 LIF_CMD
, ip_sioctl_token
, NULL
},
938 /* 136 */ { SIOCGLIFTOKEN
, sizeof (struct lifreq
),
939 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_token
, NULL
},
940 /* 137 */ { SIOCSLIFSUBNET
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
941 LIF_CMD
, ip_sioctl_subnet
, ip_sioctl_subnet_restart
},
942 /* 138 */ { SIOCGLIFSUBNET
, sizeof (struct lifreq
),
943 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_subnet
, NULL
},
944 /* 139 */ { SIOCSLIFLNKINFO
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
945 LIF_CMD
, ip_sioctl_lnkinfo
, NULL
},
947 /* 140 */ { SIOCGLIFLNKINFO
, sizeof (struct lifreq
),
948 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_lnkinfo
, NULL
},
949 /* 141 */ { SIOCLIFDELND
, sizeof (struct lifreq
), IPI_PRIV
,
950 LIF_CMD
, ip_siocdelndp_v6
, NULL
},
951 /* 142 */ { SIOCLIFGETND
, sizeof (struct lifreq
), IPI_GET_CMD
,
952 LIF_CMD
, ip_siocqueryndp_v6
, NULL
},
953 /* 143 */ { SIOCLIFSETND
, sizeof (struct lifreq
), IPI_PRIV
,
954 LIF_CMD
, ip_siocsetndp_v6
, NULL
},
955 /* 144 */ { SIOCTMYADDR
, sizeof (struct sioc_addrreq
), IPI_GET_CMD
,
956 MISC_CMD
, ip_sioctl_tmyaddr
, NULL
},
957 /* 145 */ { SIOCTONLINK
, sizeof (struct sioc_addrreq
), IPI_GET_CMD
,
958 MISC_CMD
, ip_sioctl_tonlink
, NULL
},
959 /* 146 */ { SIOCTMYSITE
, sizeof (struct sioc_addrreq
), 0,
960 MISC_CMD
, ip_sioctl_tmysite
, NULL
},
961 /* 147 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
962 /* 148 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
964 /* Old *IPSECONFIG ioctls are now deprecated, now see spdsock.c */
965 /* 149 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
966 /* 150 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
967 /* 151 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
968 /* 152 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
970 /* 153 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
972 /* 154 */ { SIOCGLIFBINDING
, sizeof (struct lifreq
), IPI_GET_CMD
,
973 LIF_CMD
, ip_sioctl_get_binding
, NULL
},
974 /* 155 */ { SIOCSLIFGROUPNAME
, sizeof (struct lifreq
),
976 LIF_CMD
, ip_sioctl_groupname
, ip_sioctl_groupname
},
977 /* 156 */ { SIOCGLIFGROUPNAME
, sizeof (struct lifreq
),
978 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_groupname
, NULL
},
979 /* 157 */ { SIOCGLIFGROUPINFO
, sizeof (lifgroupinfo_t
),
980 IPI_GET_CMD
, MISC_CMD
, ip_sioctl_groupinfo
, NULL
},
982 /* Leave 158-160 unused; used to be SIOC*IFARP ioctls */
983 /* 158 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
984 /* 159 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
985 /* 160 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
987 /* 161 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
989 /* These are handled in ip_sioctl_copyin_setup itself */
990 /* 162 */ { SIOCGIP6ADDRPOLICY
, 0, IPI_NULL_BCONT
,
991 MISC_CMD
, NULL
, NULL
},
992 /* 163 */ { SIOCSIP6ADDRPOLICY
, 0, IPI_PRIV
| IPI_NULL_BCONT
,
993 MISC_CMD
, NULL
, NULL
},
994 /* 164 */ { SIOCGDSTINFO
, 0, IPI_GET_CMD
, MISC_CMD
, NULL
, NULL
},
996 /* 165 */ { SIOCGLIFCONF
, 0, IPI_GET_CMD
, MISC_CMD
,
997 ip_sioctl_get_lifconf
, NULL
},
999 /* 166 */ { SIOCSXARP
, sizeof (struct xarpreq
), IPI_PRIV
| IPI_WR
,
1000 XARP_CMD
, ip_sioctl_arp
, NULL
},
1001 /* 167 */ { SIOCGXARP
, sizeof (struct xarpreq
), IPI_GET_CMD
,
1002 XARP_CMD
, ip_sioctl_arp
, NULL
},
1003 /* 168 */ { SIOCDXARP
, sizeof (struct xarpreq
), IPI_PRIV
| IPI_WR
,
1004 XARP_CMD
, ip_sioctl_arp
, NULL
},
1006 /* SIOCPOPSOCKFS is not handled by IP */
1007 /* 169 */ { IPI_DONTCARE
/* SIOCPOPSOCKFS */, 0, 0, 0, NULL
, NULL
},
1009 /* 170 */ { SIOCGLIFZONE
, sizeof (struct lifreq
),
1010 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_lifzone
, NULL
},
1011 /* 171 */ { SIOCSLIFZONE
, sizeof (struct lifreq
),
1012 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_slifzone
,
1013 ip_sioctl_slifzone_restart
},
1014 /* 172-174 are SCTP ioctls and not handled by IP */
1015 /* 172 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1016 /* 173 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1017 /* 174 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1018 /* 175 */ { SIOCGLIFUSESRC
, sizeof (struct lifreq
),
1019 IPI_GET_CMD
, LIF_CMD
,
1020 ip_sioctl_get_lifusesrc
, 0 },
1021 /* 176 */ { SIOCSLIFUSESRC
, sizeof (struct lifreq
),
1023 LIF_CMD
, ip_sioctl_slifusesrc
,
1025 /* 177 */ { SIOCGLIFSRCOF
, 0, IPI_GET_CMD
, MISC_CMD
,
1026 ip_sioctl_get_lifsrcof
, NULL
},
1027 /* 178 */ { SIOCGMSFILTER
, sizeof (struct group_filter
), IPI_GET_CMD
,
1028 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1029 /* 179 */ { SIOCSMSFILTER
, sizeof (struct group_filter
), 0,
1030 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1031 /* 180 */ { SIOCGIPMSFILTER
, sizeof (struct ip_msfilter
), IPI_GET_CMD
,
1032 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1033 /* 181 */ { SIOCSIPMSFILTER
, sizeof (struct ip_msfilter
), 0,
1034 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1035 /* 182 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1036 /* SIOCSENABLESDP is handled by SDP */
1037 /* 183 */ { IPI_DONTCARE
/* SIOCSENABLESDP */, 0, 0, 0, NULL
, NULL
},
1038 /* 184 */ { IPI_DONTCARE
/* SIOCSQPTR */, 0, 0, 0, NULL
, NULL
},
1039 /* 185 */ { SIOCGIFHWADDR
, sizeof (struct ifreq
), IPI_GET_CMD
,
1040 IF_CMD
, ip_sioctl_get_ifhwaddr
, NULL
},
1041 /* 186 */ { IPI_DONTCARE
/* SIOCGSTAMP */, 0, 0, 0, NULL
, NULL
},
1042 /* 187 */ { SIOCILB
, 0, IPI_PRIV
| IPI_GET_CMD
, MISC_CMD
,
1043 ip_sioctl_ilb_cmd
, NULL
},
1044 /* 188 */ { SIOCGETPROP
, sizeof (mod_ioc_prop_t
), IPI_GET_CMD
,
1045 MISC_CMD
, ip_sioctl_getsetprop
, NULL
},
1046 /* 189 */ { SIOCSETPROP
, sizeof (mod_ioc_prop_t
), IPI_PRIV
,
1047 MISC_CMD
, ip_sioctl_getsetprop
, NULL
},
1048 /* 190 */ { SIOCGLIFDADSTATE
, sizeof (struct lifreq
),
1049 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_dadstate
, NULL
},
1050 /* 191 */ { SIOCSLIFPREFIX
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
1051 LIF_CMD
, ip_sioctl_prefix
, ip_sioctl_prefix_restart
},
1052 /* 192 */ { SIOCGLIFHWADDR
, sizeof (struct lifreq
), IPI_GET_CMD
,
1053 LIF_CMD
, ip_sioctl_get_lifhwaddr
, NULL
}
1056 int ip_ndx_ioctl_count
= sizeof (ip_ndx_ioctl_table
) / sizeof (ip_ioctl_cmd_t
);
1058 ip_ioctl_cmd_t ip_misc_ioctl_table
[] = {
1059 { I_LINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1060 { I_UNLINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1061 { I_PLINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1062 { I_PUNLINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1063 { ND_GET
, 0, 0, 0, NULL
, NULL
},
1064 { ND_SET
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1065 { IP_IOCTL
, 0, 0, 0, NULL
, NULL
},
1066 { SIOCGETVIFCNT
, sizeof (struct sioc_vif_req
), IPI_GET_CMD
,
1067 MISC_CMD
, mrt_ioctl
},
1068 { SIOCGETSGCNT
, sizeof (struct sioc_sg_req
), IPI_GET_CMD
,
1069 MISC_CMD
, mrt_ioctl
},
1070 { SIOCGETLSGCNT
, sizeof (struct sioc_lsg_req
), IPI_GET_CMD
,
1071 MISC_CMD
, mrt_ioctl
}
1074 int ip_misc_ioctl_count
=
1075 sizeof (ip_misc_ioctl_table
) / sizeof (ip_ioctl_cmd_t
);
1077 int conn_drain_nthreads
; /* Number of drainers reqd. */
1078 /* Settable in /etc/system */
1079 /* Defined in ip_ire.c */
1080 extern uint32_t ip_ire_max_bucket_cnt
, ip6_ire_max_bucket_cnt
;
1081 extern uint32_t ip_ire_min_bucket_cnt
, ip6_ire_min_bucket_cnt
;
1082 extern uint32_t ip_ire_mem_ratio
, ip_ire_cpu_ratio
;
1084 static nv_t ire_nv_arr
[] = {
1085 { IRE_BROADCAST
, "BROADCAST" },
1086 { IRE_LOCAL
, "LOCAL" },
1087 { IRE_LOOPBACK
, "LOOPBACK" },
1088 { IRE_DEFAULT
, "DEFAULT" },
1089 { IRE_PREFIX
, "PREFIX" },
1090 { IRE_IF_NORESOLVER
, "IF_NORESOL" },
1091 { IRE_IF_RESOLVER
, "IF_RESOLV" },
1092 { IRE_IF_CLONE
, "IF_CLONE" },
1093 { IRE_HOST
, "HOST" },
1094 { IRE_MULTICAST
, "MULTICAST" },
1095 { IRE_NOROUTE
, "NOROUTE" },
1099 nv_t
*ire_nv_tbl
= ire_nv_arr
;
1101 /* Simple ICMP IP Header Template */
1102 static ipha_t icmp_ipha
= {
1103 IP_SIMPLE_HDR_VERSION
, 0, 0, 0, 0, 0, IPPROTO_ICMP
1106 struct module_info ip_mod_info
= {
1107 IP_MOD_ID
, IP_MOD_NAME
, IP_MOD_MINPSZ
, IP_MOD_MAXPSZ
, IP_MOD_HIWAT
,
1112 * Duplicate static symbols within a module confuses mdb; so we avoid the
1113 * problem by making the symbols here distinct from those in udp.c.
1117 * Entry points for IP as a device and as a module.
1118 * We have separate open functions for the /dev/ip and /dev/ip6 devices.
1120 static struct qinit iprinitv4
= {
1121 ip_rput
, NULL
, ip_openv4
, ip_close
, NULL
, &ip_mod_info
1124 struct qinit iprinitv6
= {
1125 ip_rput_v6
, NULL
, ip_openv6
, ip_close
, NULL
, &ip_mod_info
1128 static struct qinit ipwinit
= {
1129 ip_wput_nondata
, ip_wsrv
, NULL
, NULL
, NULL
, &ip_mod_info
1132 static struct qinit iplrinit
= {
1133 ip_lrput
, NULL
, ip_openv4
, ip_close
, NULL
, &ip_mod_info
1136 static struct qinit iplwinit
= {
1137 ip_lwput
, NULL
, NULL
, NULL
, NULL
, &ip_mod_info
1140 /* For AF_INET aka /dev/ip */
1141 struct streamtab ipinfov4
= {
1142 &iprinitv4
, &ipwinit
, &iplrinit
, &iplwinit
1145 /* For AF_INET6 aka /dev/ip6 */
1146 struct streamtab ipinfov6
= {
1147 &iprinitv6
, &ipwinit
, &iplrinit
, &iplwinit
1151 boolean_t skip_sctp_cksum
= B_FALSE
;
1155 * Generate an ICMP fragmentation needed message.
1156 * When called from ip_output side a minimal ip_recv_attr_t needs to be
1157 * constructed by the caller.
1160 icmp_frag_needed(mblk_t
*mp
, int mtu
, ip_recv_attr_t
*ira
)
1163 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
1165 mp
= icmp_pkt_err_ok(mp
, ira
);
1169 bzero(&icmph
, sizeof (icmph_t
));
1170 icmph
.icmph_type
= ICMP_DEST_UNREACHABLE
;
1171 icmph
.icmph_code
= ICMP_FRAGMENTATION_NEEDED
;
1172 icmph
.icmph_du_mtu
= htons((uint16_t)mtu
);
1173 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutFragNeeded
);
1174 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDestUnreachs
);
1176 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
1180 * icmp_inbound_v4 deals with ICMP messages that are handled by IP.
1181 * If the ICMP message is consumed by IP, i.e., it should not be delivered
1182 * to any IPPROTO_ICMP raw sockets, then it returns NULL.
1183 * Likewise, if the ICMP error is misformed (too short, etc), then it
1184 * returns NULL. The caller uses this to determine whether or not to send
1187 * All error messages are passed to the matching transport stream.
1189 * The following cases are handled by icmp_inbound:
1190 * 1) It needs to send a reply back and possibly delivering it
1191 * to the "interested" upper clients.
1192 * 2) Return the mblk so that the caller can pass it to the RAW socket clients.
1193 * 3) It needs to change some values in IP only.
1194 * 4) It needs to change some values in IP and upper layers e.g TCP
1195 * by delivering an error to the upper layers.
1197 * We handle the above three cases in the context of IPsec in the
1200 * 1) Send the reply back in the same way as the request came in.
1201 * If it came in encrypted, it goes out encrypted. If it came in
1202 * clear, it goes out in clear. Thus, this will prevent chosen
1203 * plain text attack.
1204 * 2) The client may or may not expect things to come in secure.
1205 * If it comes in secure, the policy constraints are checked
1206 * before delivering it to the upper layers. If it comes in
1207 * clear, ipsec_inbound_accept_clear will decide whether to
1208 * accept this in clear or not. In both the cases, if the returned
1209 * message (IP header + 8 bytes) that caused the icmp message has
1210 * AH/ESP headers, it is sent up to AH/ESP for validation before
1211 * sending up. If there are only 8 bytes of returned message, then
1212 * upper client will not be notified.
1213 * 3) Check with global policy to see whether it matches the constaints.
1214 * But this will be done only if icmp_accept_messages_in_clear is
1216 * 4) If we need to change both in IP and ULP, then the decision taken
1217 * while affecting the values in IP and while delivering up to TCP
1218 * should be the same.
1220 * There are two cases.
1222 * a) If we reject data at the IP layer (ipsec_check_global_policy()
1223 * failed), we will not deliver it to the ULP, even though they
1224 * are *willing* to accept in *clear*. This is fine as our global
1225 * disposition to icmp messages asks us reject the datagram.
1227 * b) If we accept data at the IP layer (ipsec_check_global_policy()
1228 * succeeded or icmp_accept_messages_in_clear is 1), and not able
1229 * to deliver it to ULP (policy failed), it can lead to
1230 * consistency problems. The cases known at this time are
1231 * ICMP_DESTINATION_UNREACHABLE messages with following code
1234 * - ICMP_FRAGMENTATION_NEEDED : IP adapts to the new value
1235 * and Upper layer rejects. Then the communication will
1236 * come to a stop. This is solved by making similar decisions
1237 * at both levels. Currently, when we are unable to deliver
1238 * to the Upper Layer (due to policy failures) while IP has
1239 * adjusted dce_pmtu, the next outbound datagram would
1240 * generate a local ICMP_FRAGMENTATION_NEEDED message - which
1241 * will be with the right level of protection. Thus the right
1242 * value will be communicated even if we are not able to
1243 * communicate when we get from the wire initially. But this
1244 * assumes there would be at least one outbound datagram after
1245 * IP has adjusted its dce_pmtu value. To make things
1246 * simpler, we accept in clear after the validation of
1249 * - Other ICMP ERRORS : We may not be able to deliver it to the
1250 * upper layer depending on the level of protection the upper
1251 * layer expects and the disposition in ipsec_inbound_accept_clear().
1252 * ipsec_inbound_accept_clear() decides whether a given ICMP error
1253 * should be accepted in clear when the Upper layer expects secure.
1254 * Thus the communication may get aborted by some bad ICMP
1258 icmp_inbound_v4(mblk_t
*mp
, ip_recv_attr_t
*ira
)
1261 ipha_t
*ipha
; /* Outer header */
1262 int ip_hdr_length
; /* Outer header length */
1263 boolean_t interested
;
1268 ill_t
*ill
= ira
->ira_ill
;
1269 ip_stack_t
*ipst
= ill
->ill_ipst
;
1270 zoneid_t zoneid
= ira
->ira_zoneid
;
1272 mblk_t
*mp_ret
= NULL
;
1274 ipha
= (ipha_t
*)mp
->b_rptr
;
1276 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInMsgs
);
1278 ip_hdr_length
= ira
->ira_ip_hdr_length
;
1279 if ((mp
->b_wptr
- mp
->b_rptr
) < (ip_hdr_length
+ ICMPH_SIZE
)) {
1280 if (ira
->ira_pktlen
< (ip_hdr_length
+ ICMPH_SIZE
)) {
1281 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
1282 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
1286 /* Last chance to get real. */
1287 ipha
= ip_pullup(mp
, ip_hdr_length
+ ICMPH_SIZE
, ira
);
1289 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInErrors
);
1295 /* The IP header will always be a multiple of four bytes */
1296 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1297 ip2dbg(("icmp_inbound_v4: type %d code %d\n", icmph
->icmph_type
,
1298 icmph
->icmph_code
));
1301 * We will set "interested" to "true" if we should pass a copy to
1302 * the transport or if we handle the packet locally.
1304 interested
= B_FALSE
;
1305 switch (icmph
->icmph_type
) {
1306 case ICMP_ECHO_REPLY
:
1307 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInEchoReps
);
1309 case ICMP_DEST_UNREACHABLE
:
1310 if (icmph
->icmph_code
== ICMP_FRAGMENTATION_NEEDED
)
1311 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInFragNeeded
);
1312 interested
= B_TRUE
; /* Pass up to transport */
1313 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInDestUnreachs
);
1315 case ICMP_SOURCE_QUENCH
:
1316 interested
= B_TRUE
; /* Pass up to transport */
1317 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInSrcQuenchs
);
1320 if (!ipst
->ips_ip_ignore_redirect
)
1321 interested
= B_TRUE
;
1322 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInRedirects
);
1324 case ICMP_ECHO_REQUEST
:
1326 * Whether to respond to echo requests that come in as IP
1327 * broadcasts or as IP multicast is subject to debate
1328 * (what isn't?). We aim to please, you pick it.
1331 if (ira
->ira_flags
& IRAF_MULTICAST
) {
1332 /* multicast: respond based on tunable */
1333 interested
= ipst
->ips_ip_g_resp_to_echo_mcast
;
1334 } else if (ira
->ira_flags
& IRAF_BROADCAST
) {
1335 /* broadcast: respond based on tunable */
1336 interested
= ipst
->ips_ip_g_resp_to_echo_bcast
;
1338 /* unicast: always respond */
1339 interested
= B_TRUE
;
1341 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInEchos
);
1343 /* We never pass these to RAW sockets */
1348 /* Check db_ref to make sure we can modify the packet. */
1349 if (mp
->b_datap
->db_ref
> 1) {
1355 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
1359 ipha
= (ipha_t
*)mp
->b_rptr
;
1360 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1362 icmph
->icmph_type
= ICMP_ECHO_REPLY
;
1363 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutEchoReps
);
1364 icmp_send_reply_v4(mp
, ipha
, icmph
, ira
);
1367 case ICMP_ROUTER_ADVERTISEMENT
:
1368 case ICMP_ROUTER_SOLICITATION
:
1370 case ICMP_TIME_EXCEEDED
:
1371 interested
= B_TRUE
; /* Pass up to transport */
1372 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInTimeExcds
);
1374 case ICMP_PARAM_PROBLEM
:
1375 interested
= B_TRUE
; /* Pass up to transport */
1376 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInParmProbs
);
1378 case ICMP_TIME_STAMP_REQUEST
:
1379 /* Response to Time Stamp Requests is local policy. */
1380 if (ipst
->ips_ip_g_resp_to_timestamp
) {
1381 if (ira
->ira_flags
& IRAF_MULTIBROADCAST
)
1383 ipst
->ips_ip_g_resp_to_timestamp_bcast
;
1385 interested
= B_TRUE
;
1388 /* We never pass these to RAW sockets */
1393 /* Make sure we have enough of the packet */
1394 len_needed
= ip_hdr_length
+ ICMPH_SIZE
+
1395 3 * sizeof (uint32_t);
1397 if (mp
->b_wptr
- mp
->b_rptr
< len_needed
) {
1398 ipha
= ip_pullup(mp
, len_needed
, ira
);
1400 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1401 ip_drop_input("ipIfStatsInDiscards - ip_pullup",
1406 /* Refresh following the pullup. */
1407 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1409 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInTimestamps
);
1410 /* Check db_ref to make sure we can modify the packet. */
1411 if (mp
->b_datap
->db_ref
> 1) {
1417 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
1421 ipha
= (ipha_t
*)mp
->b_rptr
;
1422 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1424 icmph
->icmph_type
= ICMP_TIME_STAMP_REPLY
;
1425 tsp
= (uint32_t *)&icmph
[1];
1426 tsp
++; /* Skip past 'originate time' */
1427 /* Compute # of milliseconds since midnight */
1429 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
1430 NSEC2MSEC(now
.tv_nsec
);
1431 *tsp
++ = htonl(ts
); /* Lay in 'receive time' */
1432 *tsp
++ = htonl(ts
); /* Lay in 'send time' */
1433 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutTimestampReps
);
1434 icmp_send_reply_v4(mp
, ipha
, icmph
, ira
);
1437 case ICMP_TIME_STAMP_REPLY
:
1438 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInTimestampReps
);
1440 case ICMP_INFO_REQUEST
:
1441 /* Per RFC 1122 3.2.2.7, ignore this. */
1442 case ICMP_INFO_REPLY
:
1444 case ICMP_ADDRESS_MASK_REQUEST
:
1445 if (ira
->ira_flags
& IRAF_MULTIBROADCAST
) {
1447 ipst
->ips_ip_respond_to_address_mask_broadcast
;
1449 interested
= B_TRUE
;
1452 /* We never pass these to RAW sockets */
1456 len_needed
= ip_hdr_length
+ ICMPH_SIZE
+ IP_ADDR_LEN
;
1457 if (mp
->b_wptr
- mp
->b_rptr
< len_needed
) {
1458 ipha
= ip_pullup(mp
, len_needed
, ira
);
1460 BUMP_MIB(ill
->ill_ip_mib
,
1461 ipIfStatsInTruncatedPkts
);
1462 ip_drop_input("ipIfStatsInTruncatedPkts", mp
,
1467 /* Refresh following the pullup. */
1468 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1470 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInAddrMasks
);
1471 /* Check db_ref to make sure we can modify the packet. */
1472 if (mp
->b_datap
->db_ref
> 1) {
1478 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
1482 ipha
= (ipha_t
*)mp
->b_rptr
;
1483 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1486 * Need the ipif with the mask be the same as the source
1487 * address of the mask reply. For unicast we have a specific
1488 * ipif. For multicast/broadcast we only handle onlink
1489 * senders, and use the source address to pick an ipif.
1491 ipif
= ipif_lookup_addr(ipha
->ipha_dst
, ill
, zoneid
, ipst
);
1493 /* Broadcast or multicast */
1494 ipif
= ipif_lookup_remote(ill
, ipha
->ipha_src
, zoneid
);
1500 icmph
->icmph_type
= ICMP_ADDRESS_MASK_REPLY
;
1501 bcopy(&ipif
->ipif_net_mask
, &icmph
[1], IP_ADDR_LEN
);
1503 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutAddrMaskReps
);
1504 icmp_send_reply_v4(mp
, ipha
, icmph
, ira
);
1507 case ICMP_ADDRESS_MASK_REPLY
:
1508 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInAddrMaskReps
);
1511 interested
= B_TRUE
; /* Pass up to transport */
1512 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInUnknowns
);
1516 * See if there is an ICMP client to avoid an extra copymsg/freemsg
1517 * if there isn't one.
1519 if (ipst
->ips_ipcl_proto_fanout_v4
[IPPROTO_ICMP
].connf_head
!= NULL
) {
1520 /* If there is an ICMP client and we want one too, copy it. */
1523 /* Caller will deliver to RAW sockets */
1526 mp_ret
= copymsg(mp
);
1527 if (mp_ret
== NULL
) {
1528 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1529 ip_drop_input("ipIfStatsInDiscards - copymsg", mp
, ill
);
1531 } else if (!interested
) {
1532 /* Neither we nor raw sockets are interested. Drop packet now */
1538 * ICMP error or redirect packet. Make sure we have enough of
1539 * the header and that db_ref == 1 since we might end up modifying
1542 if (mp
->b_cont
!= NULL
) {
1543 if (ip_pullup(mp
, -1, ira
) == NULL
) {
1544 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1545 ip_drop_input("ipIfStatsInDiscards - ip_pullup",
1552 if (mp
->b_datap
->db_ref
> 1) {
1557 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1558 ip_drop_input("ipIfStatsInDiscards - copymsg", mp
, ill
);
1567 * In case mp has changed, verify the message before any further
1570 ipha
= (ipha_t
*)mp
->b_rptr
;
1571 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1572 if (!icmp_inbound_verify_v4(mp
, icmph
, ira
)) {
1577 switch (icmph
->icmph_type
) {
1579 icmp_redirect_v4(mp
, ipha
, icmph
, ira
);
1581 case ICMP_DEST_UNREACHABLE
:
1582 if (icmph
->icmph_code
== ICMP_FRAGMENTATION_NEEDED
) {
1583 /* Update DCE and adjust MTU is icmp header if needed */
1584 icmp_inbound_too_big_v4(icmph
, ira
);
1588 icmp_inbound_error_fanout_v4(mp
, icmph
, ira
);
1595 * Send an ICMP echo, timestamp or address mask reply.
1596 * The caller has already updated the payload part of the packet.
1597 * We handle the ICMP checksum, IP source address selection and feed
1598 * the packet into ip_output_simple.
1601 icmp_send_reply_v4(mblk_t
*mp
, ipha_t
*ipha
, icmph_t
*icmph
,
1602 ip_recv_attr_t
*ira
)
1604 uint_t ip_hdr_length
= ira
->ira_ip_hdr_length
;
1605 ill_t
*ill
= ira
->ira_ill
;
1606 ip_stack_t
*ipst
= ill
->ill_ipst
;
1607 ip_xmit_attr_t ixas
;
1609 /* Send out an ICMP packet */
1610 icmph
->icmph_checksum
= 0;
1611 icmph
->icmph_checksum
= IP_CSUM(mp
, ip_hdr_length
, 0);
1612 /* Reset time to live. */
1613 ipha
->ipha_ttl
= ipst
->ips_ip_def_ttl
;
1615 /* Swap source and destination addresses */
1618 tmp
= ipha
->ipha_src
;
1619 ipha
->ipha_src
= ipha
->ipha_dst
;
1620 ipha
->ipha_dst
= tmp
;
1622 ipha
->ipha_ident
= 0;
1623 if (!IS_SIMPLE_IPH(ipha
))
1624 icmp_options_update(ipha
);
1626 bzero(&ixas
, sizeof (ixas
));
1627 ixas
.ixa_flags
= IXAF_BASIC_SIMPLE_V4
;
1628 ixas
.ixa_zoneid
= ira
->ira_zoneid
;
1629 ixas
.ixa_cred
= kcred
;
1630 ixas
.ixa_cpid
= NOPID
;
1631 ixas
.ixa_ifindex
= 0;
1632 ixas
.ixa_ipst
= ipst
;
1633 ixas
.ixa_multicast_ttl
= IP_DEFAULT_MULTICAST_TTL
;
1635 if (!(ira
->ira_flags
& IRAF_IPSEC_SECURE
)) {
1637 * This packet should go out the same way as it
1638 * came in i.e in clear, independent of the IPsec policy
1639 * for transmitting packets.
1641 ixas
.ixa_flags
|= IXAF_NO_IPSEC
;
1643 if (!ipsec_in_to_out(ira
, &ixas
, mp
, ipha
, NULL
)) {
1644 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1645 /* Note: mp already consumed and ip_drop_packet done */
1649 if (ira
->ira_flags
& IRAF_MULTIBROADCAST
) {
1651 * Not one or our addresses (IRE_LOCALs), thus we let
1652 * ip_output_simple pick the source.
1654 ipha
->ipha_src
= INADDR_ANY
;
1655 ixas
.ixa_flags
|= IXAF_SET_SOURCE
;
1657 /* Should we send with DF and use dce_pmtu? */
1658 if (ipst
->ips_ipv4_icmp_return_pmtu
) {
1659 ixas
.ixa_flags
|= IXAF_PMTU_DISCOVERY
;
1660 ipha
->ipha_fragment_offset_and_flags
|= IPH_DF_HTONS
;
1663 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutMsgs
);
1665 (void) ip_output_simple(mp
, &ixas
);
1670 * Verify the ICMP messages for either for ICMP error or redirect packet.
1671 * The caller should have fully pulled up the message. If it's a redirect
1672 * packet, only basic checks on IP header will be done; otherwise, verify
1673 * the packet by looking at the included ULP header.
1675 * Called before icmp_inbound_error_fanout_v4 is called.
1678 icmp_inbound_verify_v4(mblk_t
*mp
, icmph_t
*icmph
, ip_recv_attr_t
*ira
)
1680 ill_t
*ill
= ira
->ira_ill
;
1682 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
1684 ipha_t
*ipha
; /* Inner IP header */
1686 ipha
= (ipha_t
*)&icmph
[1];
1687 if ((uchar_t
*)ipha
+ IP_SIMPLE_HDR_LENGTH
> mp
->b_wptr
)
1690 hdr_length
= IPH_HDR_LENGTH(ipha
);
1692 if ((IPH_HDR_VERSION(ipha
) != IPV4_VERSION
))
1695 if (hdr_length
< sizeof (ipha_t
))
1698 if ((uchar_t
*)ipha
+ hdr_length
> mp
->b_wptr
)
1702 * Stop here for ICMP_REDIRECT.
1704 if (icmph
->icmph_type
== ICMP_REDIRECT
)
1710 switch (ipha
->ipha_protocol
) {
1713 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
1716 if ((uchar_t
*)ipha
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
1724 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
1727 if ((uchar_t
*)ipha
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
1731 tcpha
= (tcpha_t
*)((uchar_t
*)ipha
+ hdr_length
);
1732 connp
= ipcl_tcp_lookup_reversed_ipv4(ipha
, tcpha
, TCPS_LISTEN
,
1737 if ((connp
->conn_verifyicmp
!= NULL
) &&
1738 !connp
->conn_verifyicmp(connp
, tcpha
, icmph
, NULL
, ira
)) {
1739 CONN_DEC_REF(connp
);
1742 CONN_DEC_REF(connp
);
1747 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
1750 if ((uchar_t
*)ipha
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
1758 if ((uchar_t
*)ipha
+ hdr_length
+ sizeof (ipha_t
) >
1769 /* Bogus ICMP error. */
1770 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1774 /* We pulled up everthing already. Must be truncated */
1775 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
1776 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
1780 /* Table from RFC 1191 */
1781 static int icmp_frag_size_table
[] =
1782 { 32000, 17914, 8166, 4352, 2002, 1496, 1006, 508, 296, 68 };
1785 * Process received ICMP Packet too big.
1786 * Just handles the DCE create/update, including using the above table of
1787 * PMTU guesses. The caller is responsible for validating the packet before
1788 * passing it in and also to fanout the ICMP error to any matching transport
1789 * conns. Assumes the message has been fully pulled up and verified.
1791 * Before getting here, the caller has called icmp_inbound_verify_v4()
1792 * that should have verified with ULP to prevent undoing the changes we're
1793 * going to make to DCE. For example, TCP might have verified that the packet
1794 * which generated error is in the send window.
1796 * In some cases modified this MTU in the ICMP header packet; the caller
1797 * should pass to the matching ULP after this returns.
1800 icmp_inbound_too_big_v4(icmph_t
*icmph
, ip_recv_attr_t
*ira
)
1806 boolean_t disable_pmtud
;
1807 ill_t
*ill
= ira
->ira_ill
;
1808 ip_stack_t
*ipst
= ill
->ill_ipst
;
1812 /* Caller already pulled up everything. */
1813 ipha
= (ipha_t
*)&icmph
[1];
1814 ASSERT(icmph
->icmph_type
== ICMP_DEST_UNREACHABLE
&&
1815 icmph
->icmph_code
== ICMP_FRAGMENTATION_NEEDED
);
1816 ASSERT(ill
!= NULL
);
1818 hdr_length
= IPH_HDR_LENGTH(ipha
);
1821 * We handle path MTU for source routed packets since the DCE
1822 * is looked up using the final destination.
1824 dst
= ip_get_dst(ipha
);
1826 dce
= dce_lookup_and_add_v4(dst
, ipst
);
1828 /* Couldn't add a unique one - ENOMEM */
1829 ip1dbg(("icmp_inbound_too_big_v4: no dce for 0x%x\n",
1834 /* Check for MTU discovery advice as described in RFC 1191 */
1835 mtu
= ntohs(icmph
->icmph_du_mtu
);
1837 disable_pmtud
= B_FALSE
;
1839 mutex_enter(&dce
->dce_lock
);
1840 if (dce
->dce_flags
& DCEF_PMTU
)
1841 old_mtu
= dce
->dce_pmtu
;
1843 old_mtu
= ill
->ill_mtu
;
1845 if (icmph
->icmph_du_zero
!= 0 || mtu
< ipst
->ips_ip_pmtu_min
) {
1850 * Use the table from RFC 1191 to figure out
1851 * the next "plateau" based on the length in
1852 * the original IP packet.
1854 length
= ntohs(ipha
->ipha_length
);
1855 DTRACE_PROBE2(ip4__pmtu__guess
, dce_t
*, dce
,
1857 if (old_mtu
<= length
&&
1858 old_mtu
>= length
- hdr_length
) {
1860 * Handle broken BSD 4.2 systems that
1861 * return the wrong ipha_length in ICMP
1864 ip1dbg(("Wrong mtu: sent %d, dce %d\n",
1866 length
-= hdr_length
;
1868 for (i
= 0; i
< A_CNT(icmp_frag_size_table
); i
++) {
1869 if (length
> icmp_frag_size_table
[i
])
1872 if (i
== A_CNT(icmp_frag_size_table
)) {
1873 /* Smaller than IP_MIN_MTU! */
1874 ip1dbg(("Too big for packet size %d\n",
1876 disable_pmtud
= B_TRUE
;
1877 mtu
= ipst
->ips_ip_pmtu_min
;
1879 mtu
= icmp_frag_size_table
[i
];
1880 ip1dbg(("Calculated mtu %d, packet size %d, "
1881 "before %d\n", mtu
, length
, old_mtu
));
1882 if (mtu
< ipst
->ips_ip_pmtu_min
) {
1883 mtu
= ipst
->ips_ip_pmtu_min
;
1884 disable_pmtud
= B_TRUE
;
1889 dce
->dce_flags
|= DCEF_TOO_SMALL_PMTU
;
1891 dce
->dce_flags
&= ~DCEF_TOO_SMALL_PMTU
;
1893 dce
->dce_pmtu
= MIN(old_mtu
, mtu
);
1894 /* Prepare to send the new max frag size for the ULP. */
1895 icmph
->icmph_du_zero
= 0;
1896 icmph
->icmph_du_mtu
= htons((uint16_t)dce
->dce_pmtu
);
1897 DTRACE_PROBE4(ip4__pmtu__change
, icmph_t
*, icmph
, dce_t
*,
1898 dce
, int, orig_mtu
, int, mtu
);
1900 /* We now have a PMTU for sure */
1901 dce
->dce_flags
|= DCEF_PMTU
;
1902 dce
->dce_last_change_time
= TICK_TO_SEC(ddi_get_lbolt64());
1903 mutex_exit(&dce
->dce_lock
);
1905 * After dropping the lock the new value is visible to everyone.
1906 * Then we bump the generation number so any cached values reinspect
1909 dce_increment_generation(dce
);
1914 * If the packet in error is Self-Encapsulated, icmp_inbound_error_fanout_v4
1915 * calls this function.
1918 icmp_inbound_self_encap_error_v4(mblk_t
*mp
, ipha_t
*ipha
, ipha_t
*in_ipha
)
1922 ASSERT(mp
->b_datap
->db_type
== M_DATA
);
1924 /* icmp_inbound_v4 has already pulled up the whole error packet */
1925 ASSERT(mp
->b_cont
== NULL
);
1928 * The length that we want to overlay is the inner header
1929 * and what follows it.
1931 length
= msgdsize(mp
) - ((uchar_t
*)in_ipha
- mp
->b_rptr
);
1934 * Overlay the inner header and whatever follows it over the
1937 bcopy((uchar_t
*)in_ipha
, (uchar_t
*)ipha
, length
);
1939 /* Adjust for what we removed */
1940 mp
->b_wptr
-= (uchar_t
*)in_ipha
- (uchar_t
*)ipha
;
1945 * Try to pass the ICMP message upstream in case the ULP cares.
1947 * If the packet that caused the ICMP error is secure, we send
1948 * it to AH/ESP to make sure that the attached packet has a
1949 * valid association. ipha in the code below points to the
1950 * IP header of the packet that caused the error.
1952 * For IPsec cases, we let the next-layer-up (which has access to
1953 * cached policy on the conn_t, or can query the SPD directly)
1954 * subtract out any IPsec overhead if they must. We therefore make no
1955 * adjustments here for IPsec overhead.
1957 * IFN could have been generated locally or by some router.
1959 * LOCAL : ire_send_wire (before calling ipsec_out_process) can call
1960 * icmp_frag_needed/icmp_pkt2big_v6 to generated a local IFN.
1961 * This happens because IP adjusted its value of MTU on an
1962 * earlier IFN message and could not tell the upper layer,
1963 * the new adjusted value of MTU e.g. Packet was encrypted
1964 * or there was not enough information to fanout to upper
1965 * layers. Thus on the next outbound datagram, ire_send_wire
1966 * generates the IFN, where IPsec processing has *not* been
1969 * Note that we retain ixa_fragsize across IPsec thus once
1970 * we have picking ixa_fragsize and entered ipsec_out_process we do
1971 * no change the fragsize even if the path MTU changes before
1972 * we reach ip_output_post_ipsec.
1974 * In the local case, IRAF_LOOPBACK will be set indicating
1975 * that IFN was generated locally.
1977 * ROUTER : IFN could be secure or non-secure.
1979 * * SECURE : We use the IPSEC_IN to fanout to AH/ESP if the
1980 * packet in error has AH/ESP headers to validate the AH/ESP
1981 * headers. AH/ESP will verify whether there is a valid SA or
1982 * not and send it back. We will fanout again if we have more
1983 * data in the packet.
1985 * If the packet in error does not have AH/ESP, we handle it
1986 * like any other case.
1988 * * NON_SECURE : If the packet in error has AH/ESP headers, we send it
1989 * up to AH/ESP for validation. AH/ESP will verify whether there is a
1990 * valid SA or not and send it back. We will fanout again if
1991 * we have more data in the packet.
1993 * If the packet in error does not have AH/ESP, we handle it
1994 * like any other case.
1996 * The caller must have called icmp_inbound_verify_v4.
1999 icmp_inbound_error_fanout_v4(mblk_t
*mp
, icmph_t
*icmph
, ip_recv_attr_t
*ira
)
2001 uint16_t *up
; /* Pointer to ports in ULP header */
2002 uint32_t ports
; /* reversed ports for fanout */
2003 ipha_t ripha
; /* With reversed addresses */
2004 ipha_t
*ipha
; /* Inner IP header */
2005 uint_t hdr_length
; /* Inner IP header length */
2008 ill_t
*ill
= ira
->ira_ill
;
2009 ip_stack_t
*ipst
= ill
->ill_ipst
;
2010 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
2011 ill_t
*rill
= ira
->ira_rill
;
2013 /* Caller already pulled up everything. */
2014 ipha
= (ipha_t
*)&icmph
[1];
2015 ASSERT((uchar_t
*)&ipha
[1] <= mp
->b_wptr
);
2016 ASSERT(mp
->b_cont
== NULL
);
2018 hdr_length
= IPH_HDR_LENGTH(ipha
);
2019 ira
->ira_protocol
= ipha
->ipha_protocol
;
2022 * We need a separate IP header with the source and destination
2023 * addresses reversed to do fanout/classification because the ipha in
2024 * the ICMP error is in the form we sent it out.
2026 ripha
.ipha_src
= ipha
->ipha_dst
;
2027 ripha
.ipha_dst
= ipha
->ipha_src
;
2028 ripha
.ipha_protocol
= ipha
->ipha_protocol
;
2029 ripha
.ipha_version_and_hdr_length
= ipha
->ipha_version_and_hdr_length
;
2031 ip2dbg(("icmp_inbound_error_v4: proto %d %x to %x: %d/%d\n",
2032 ripha
.ipha_protocol
, ntohl(ipha
->ipha_src
),
2033 ntohl(ipha
->ipha_dst
),
2034 icmph
->icmph_type
, icmph
->icmph_code
));
2036 switch (ipha
->ipha_protocol
) {
2038 up
= (uint16_t *)((uchar_t
*)ipha
+ hdr_length
);
2040 /* Attempt to find a client stream based on port. */
2041 ip2dbg(("icmp_inbound_error_v4: UDP ports %d to %d\n",
2042 ntohs(up
[0]), ntohs(up
[1])));
2044 /* Note that we send error to all matches. */
2045 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2046 ip_fanout_udp_multi_v4(mp
, &ripha
, up
[0], up
[1], ira
);
2047 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2052 * Find a TCP client stream for this packet.
2053 * Note that we do a reverse lookup since the header is
2054 * in the form we sent it out.
2056 tcpha
= (tcpha_t
*)((uchar_t
*)ipha
+ hdr_length
);
2057 connp
= ipcl_tcp_lookup_reversed_ipv4(ipha
, tcpha
, TCPS_LISTEN
,
2062 if (CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) ||
2063 (ira
->ira_flags
& IRAF_IPSEC_SECURE
)) {
2064 mp
= ipsec_check_inbound_policy(mp
, connp
,
2067 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
2068 /* Note that mp is NULL */
2069 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
2070 CONN_DEC_REF(connp
);
2075 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2076 ira
->ira_ill
= ira
->ira_rill
= NULL
;
2077 if (IPCL_IS_TCP(connp
)) {
2078 SQUEUE_ENTER_ONE(connp
->conn_sqp
, mp
,
2079 connp
->conn_recvicmp
, connp
, ira
, SQ_FILL
,
2080 SQTAG_TCP_INPUT_ICMP_ERR
);
2082 /* Not TCP; must be SOCK_RAW, IPPROTO_TCP */
2083 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
2084 CONN_DEC_REF(connp
);
2087 ira
->ira_rill
= rill
;
2088 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2092 up
= (uint16_t *)((uchar_t
*)ipha
+ hdr_length
);
2093 /* Find a SCTP client stream for this packet. */
2094 ((uint16_t *)&ports
)[0] = up
[1];
2095 ((uint16_t *)&ports
)[1] = up
[0];
2097 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2098 ip_fanout_sctp(mp
, &ripha
, NULL
, ports
, ira
);
2099 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2104 if (!ipsec_loaded(ipss
)) {
2105 ip_proto_not_sup(mp
, ira
);
2109 if (ipha
->ipha_protocol
== IPPROTO_ESP
)
2110 mp
= ipsecesp_icmp_error(mp
, ira
);
2112 mp
= ipsecah_icmp_error(mp
, ira
);
2116 /* Just in case ipsec didn't preserve the NULL b_cont */
2117 if (mp
->b_cont
!= NULL
) {
2118 if (!pullupmsg(mp
, -1))
2123 * Note that ira_pktlen and ira_ip_hdr_length are no longer
2124 * correct, but we don't use them any more here.
2126 * If succesful, the mp has been modified to not include
2127 * the ESP/AH header so we can fanout to the ULP's icmp
2130 if (mp
->b_wptr
- mp
->b_rptr
< IP_SIMPLE_HDR_LENGTH
)
2133 /* Verify the modified message before any further processes. */
2134 ipha
= (ipha_t
*)mp
->b_rptr
;
2135 hdr_length
= IPH_HDR_LENGTH(ipha
);
2136 icmph
= (icmph_t
*)&mp
->b_rptr
[hdr_length
];
2137 if (!icmp_inbound_verify_v4(mp
, icmph
, ira
)) {
2142 icmp_inbound_error_fanout_v4(mp
, icmph
, ira
);
2145 case IPPROTO_ENCAP
: {
2146 /* Look for self-encapsulated packets that caused an error */
2150 * Caller has verified that length has to be
2151 * at least the size of IP header.
2153 ASSERT(hdr_length
>= sizeof (ipha_t
));
2155 * Check the sanity of the inner IP header like
2156 * we did for the outer header.
2158 in_ipha
= (ipha_t
*)((uchar_t
*)ipha
+ hdr_length
);
2159 if ((IPH_HDR_VERSION(in_ipha
) != IPV4_VERSION
)) {
2162 if (IPH_HDR_LENGTH(in_ipha
) < sizeof (ipha_t
)) {
2165 /* Check for Self-encapsulated tunnels */
2166 if (in_ipha
->ipha_src
== ipha
->ipha_src
&&
2167 in_ipha
->ipha_dst
== ipha
->ipha_dst
) {
2169 mp
= icmp_inbound_self_encap_error_v4(mp
, ipha
,
2175 * Just in case self_encap didn't preserve the NULL
2178 if (mp
->b_cont
!= NULL
) {
2179 if (!pullupmsg(mp
, -1))
2183 * Note that ira_pktlen and ira_ip_hdr_length are no
2184 * longer correct, but we don't use them any more here.
2186 if (mp
->b_wptr
- mp
->b_rptr
< IP_SIMPLE_HDR_LENGTH
)
2190 * Verify the modified message before any further
2193 ipha
= (ipha_t
*)mp
->b_rptr
;
2194 hdr_length
= IPH_HDR_LENGTH(ipha
);
2195 icmph
= (icmph_t
*)&mp
->b_rptr
[hdr_length
];
2196 if (!icmp_inbound_verify_v4(mp
, icmph
, ira
)) {
2202 * The packet in error is self-encapsualted.
2203 * And we are finding it further encapsulated
2204 * which we could not have possibly generated.
2206 if (ipha
->ipha_protocol
== IPPROTO_ENCAP
) {
2209 icmp_inbound_error_fanout_v4(mp
, icmph
, ira
);
2212 /* No self-encapsulated */
2216 if ((connp
= ipcl_iptun_classify_v4(&ripha
.ipha_src
,
2217 &ripha
.ipha_dst
, ipst
)) != NULL
) {
2218 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2219 connp
->conn_recvicmp(connp
, mp
, NULL
, ira
);
2220 CONN_DEC_REF(connp
);
2221 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2225 * No IP tunnel is interested, fallthrough and see
2226 * if a raw socket will want it.
2230 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2231 ip_fanout_proto_v4(mp
, &ripha
, ira
);
2232 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2237 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
2238 ip1dbg(("icmp_inbound_error_fanout_v4: drop pkt\n"));
2239 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
2244 /* We pulled up everthing already. Must be truncated */
2245 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
2246 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
2251 * Common IP options parser.
2253 * Setup routine: fill in *optp with options-parsing state, then
2254 * tail-call ipoptp_next to return the first option.
2257 ipoptp_first(ipoptp_t
*optp
, ipha_t
*ipha
)
2259 uint32_t totallen
; /* total length of all options */
2261 totallen
= ipha
->ipha_version_and_hdr_length
-
2262 (uint8_t)((IP_VERSION
<< 4) + IP_SIMPLE_HDR_LENGTH_IN_WORDS
);
2264 optp
->ipoptp_next
= (uint8_t *)(&ipha
[1]);
2265 optp
->ipoptp_end
= optp
->ipoptp_next
+ totallen
;
2266 optp
->ipoptp_flags
= 0;
2267 return (ipoptp_next(optp
));
2270 /* Like above but without an ipha_t */
2272 ipoptp_first2(ipoptp_t
*optp
, uint32_t totallen
, uint8_t *opt
)
2274 optp
->ipoptp_next
= opt
;
2275 optp
->ipoptp_end
= optp
->ipoptp_next
+ totallen
;
2276 optp
->ipoptp_flags
= 0;
2277 return (ipoptp_next(optp
));
2281 * Common IP options parser: extract next option.
2284 ipoptp_next(ipoptp_t
*optp
)
2286 uint8_t *end
= optp
->ipoptp_end
;
2287 uint8_t *cur
= optp
->ipoptp_next
;
2288 uint8_t opt
, len
, pointer
;
2291 * If cur > end already, then the ipoptp_end or ipoptp_next pointer
2292 * has been corrupted.
2299 opt
= cur
[IPOPT_OPTVAL
];
2302 * Skip any NOP options.
2304 while (opt
== IPOPT_NOP
) {
2308 opt
= cur
[IPOPT_OPTVAL
];
2311 if (opt
== IPOPT_EOL
)
2315 * Option requiring a length.
2317 if ((cur
+ 1) >= end
) {
2318 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2321 len
= cur
[IPOPT_OLEN
];
2323 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2326 optp
->ipoptp_cur
= cur
;
2327 optp
->ipoptp_len
= len
;
2328 optp
->ipoptp_next
= cur
+ len
;
2329 if (cur
+ len
> end
) {
2330 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2335 * For the options which require a pointer field, make sure
2336 * its there, and make sure it points to either something
2337 * inside this option, or the end of the option.
2344 if (len
<= IPOPT_OFFSET
) {
2345 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2348 pointer
= cur
[IPOPT_OFFSET
];
2349 if (pointer
- 1 > len
) {
2350 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2357 * Sanity check the pointer field based on the type of the
2364 if (pointer
< IPOPT_MINOFF_SR
)
2365 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2368 if (pointer
< IPOPT_MINOFF_IT
)
2369 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2371 * Note that the Internet Timestamp option also
2372 * contains two four bit fields (the Overflow field,
2373 * and the Flag field), which follow the pointer
2374 * field. We don't need to check that these fields
2375 * fall within the length of the option because this
2376 * was implicitely done above. We've checked that the
2377 * pointer value is at least IPOPT_MINOFF_IT, and that
2378 * it falls within the option. Since IPOPT_MINOFF_IT >
2379 * IPOPT_POS_OV_FLG, we don't need the explicit check.
2381 ASSERT(len
> IPOPT_POS_OV_FLG
);
2389 * Use the outgoing IP header to create an IP_OPTIONS option the way
2390 * it was passed down from the application.
2392 * This is compatible with BSD in that it returns
2393 * the reverse source route with the final destination
2394 * as the last entry. The first 4 bytes of the option
2395 * will contain the final destination.
2398 ip_opt_get_user(conn_t
*connp
, uchar_t
*buf
)
2405 uchar_t
*buf1
= buf
;
2408 ip_pkt_t
*ipp
= &connp
->conn_xmit_ipp
;
2410 if (!(ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
))
2413 totallen
= ipp
->ipp_ipv4_options_len
;
2417 buf
+= IP_ADDR_LEN
; /* Leave room for final destination */
2419 bzero(buf1
, IP_ADDR_LEN
);
2421 dst
= connp
->conn_faddr_v4
;
2423 for (optval
= ipoptp_first2(&opts
, totallen
, ipp
->ipp_ipv4_options
);
2424 optval
!= IPOPT_EOL
;
2425 optval
= ipoptp_next(&opts
)) {
2428 opt
= opts
.ipoptp_cur
;
2429 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
2432 optlen
= opts
.ipoptp_len
;
2439 * Insert destination as the first entry in the source
2440 * route and move down the entries on step.
2441 * The last entry gets placed at buf1.
2443 buf
[IPOPT_OPTVAL
] = optval
;
2444 buf
[IPOPT_OLEN
] = optlen
;
2445 buf
[IPOPT_OFFSET
] = optlen
;
2447 off
= optlen
- IP_ADDR_LEN
;
2449 /* No entries in source route */
2452 /* Last entry in source route if not already set */
2453 if (dst
== INADDR_ANY
)
2454 bcopy(opt
+ off
, buf1
, IP_ADDR_LEN
);
2459 buf
+ off
+ IP_ADDR_LEN
,
2463 /* ipha_dst into first slot */
2464 bcopy(&dst
, buf
+ off
+ IP_ADDR_LEN
,
2471 bcopy(opt
, buf
, optlen
);
2478 /* Pad the resulting options */
2487 * Update any record route or timestamp options to include this host.
2488 * Reverse any source route option.
2489 * This routine assumes that the options are well formed i.e. that they
2490 * have already been checked.
2493 icmp_options_update(ipha_t
*ipha
)
2498 ipaddr_t src
; /* Our local address */
2501 ip2dbg(("icmp_options_update\n"));
2502 src
= ipha
->ipha_src
;
2503 dst
= ipha
->ipha_dst
;
2505 for (optval
= ipoptp_first(&opts
, ipha
);
2506 optval
!= IPOPT_EOL
;
2507 optval
= ipoptp_next(&opts
)) {
2508 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
2509 opt
= opts
.ipoptp_cur
;
2510 ip2dbg(("icmp_options_update: opt %d, len %d\n",
2511 optval
, opts
.ipoptp_len
));
2517 * Reverse the source route. The first entry
2518 * should be the next to last one in the current
2519 * source route (the last entry is our address).
2520 * The last entry should be the final destination.
2522 off1
= IPOPT_MINOFF_SR
- 1;
2523 off2
= opt
[IPOPT_OFFSET
] - IP_ADDR_LEN
- 1;
2525 /* No entries in source route */
2527 "icmp_options_update: bad src route\n"));
2530 bcopy((char *)opt
+ off2
, &dst
, IP_ADDR_LEN
);
2531 bcopy(&ipha
->ipha_dst
, (char *)opt
+ off2
, IP_ADDR_LEN
);
2532 bcopy(&dst
, &ipha
->ipha_dst
, IP_ADDR_LEN
);
2533 off2
-= IP_ADDR_LEN
;
2535 while (off1
< off2
) {
2536 bcopy((char *)opt
+ off1
, &src
, IP_ADDR_LEN
);
2537 bcopy((char *)opt
+ off2
, (char *)opt
+ off1
,
2539 bcopy(&src
, (char *)opt
+ off2
, IP_ADDR_LEN
);
2540 off1
+= IP_ADDR_LEN
;
2541 off2
-= IP_ADDR_LEN
;
2543 opt
[IPOPT_OFFSET
] = IPOPT_MINOFF_SR
;
2550 * Process received ICMP Redirect messages.
2551 * Assumes the caller has verified that the headers are in the pulled up mblk.
2555 icmp_redirect_v4(mblk_t
*mp
, ipha_t
*ipha
, icmph_t
*icmph
, ip_recv_attr_t
*ira
)
2559 ipaddr_t src
, dst
, gateway
;
2560 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2561 ipha_t
*inner_ipha
; /* Inner IP header */
2563 /* Caller already pulled up everything. */
2564 inner_ipha
= (ipha_t
*)&icmph
[1];
2565 src
= ipha
->ipha_src
;
2566 dst
= inner_ipha
->ipha_dst
;
2567 gateway
= icmph
->icmph_rd_gateway
;
2568 /* Make sure the new gateway is reachable somehow. */
2569 ire
= ire_ftable_lookup_v4(gateway
, 0, 0, IRE_ONLINK
, NULL
,
2570 ALL_ZONES
, MATCH_IRE_TYPE
, 0, ipst
, NULL
);
2572 * Make sure we had a route for the dest in question and that
2573 * that route was pointing to the old gateway (the source of the
2575 * We do longest match and then compare ire_gateway_addr below.
2577 prev_ire
= ire_ftable_lookup_v4(dst
, 0, 0, 0, NULL
, ALL_ZONES
,
2578 MATCH_IRE_DSTONLY
, 0, ipst
, NULL
);
2581 * the redirect was not from ourselves
2582 * the new gateway and the old gateway are directly reachable
2584 if (prev_ire
== NULL
|| ire
== NULL
||
2585 (prev_ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
)) ||
2586 (prev_ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
)) ||
2587 !(ire
->ire_type
& IRE_IF_ALL
) ||
2588 prev_ire
->ire_gateway_addr
!= src
) {
2589 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInBadRedirects
);
2590 ip_drop_input("icmpInBadRedirects - ire", mp
, ira
->ira_ill
);
2594 if (prev_ire
!= NULL
)
2595 ire_refrele(prev_ire
);
2599 ire_refrele(prev_ire
);
2603 * TODO: more precise handling for cases 0, 2, 3, the latter two
2604 * require TOS routing
2606 switch (icmph
->icmph_code
) {
2609 /* TODO: TOS specificity for cases 2 and 3 */
2614 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInBadRedirects
);
2615 ip_drop_input("icmpInBadRedirects - code", mp
, ira
->ira_ill
);
2620 * Create a Route Association. This will allow us to remember that
2621 * someone we believe told us to use the particular gateway.
2624 (uchar_t
*)&dst
, /* dest addr */
2625 (uchar_t
*)&ip_g_all_ones
, /* mask */
2626 (uchar_t
*)&gateway
, /* gateway addr */
2630 (RTF_DYNAMIC
| RTF_GATEWAY
| RTF_HOST
),
2637 nire
= ire_add(ire
);
2638 /* Check if it was a duplicate entry */
2639 if (nire
!= NULL
&& nire
!= ire
) {
2640 ASSERT(nire
->ire_identical_ref
> 1);
2647 ire_refrele(ire
); /* Held in ire_add */
2649 /* tell routing sockets that we received a redirect */
2650 ip_rts_change(RTM_REDIRECT
, dst
, gateway
, IP_HOST_MASK
, 0, src
,
2651 (RTF_DYNAMIC
| RTF_GATEWAY
| RTF_HOST
), 0,
2652 (RTA_DST
| RTA_GATEWAY
| RTA_NETMASK
| RTA_AUTHOR
), ipst
);
2656 * Delete any existing IRE_HOST type redirect ires for this destination.
2657 * This together with the added IRE has the effect of
2658 * modifying an existing redirect.
2660 prev_ire
= ire_ftable_lookup_v4(dst
, 0, src
, IRE_HOST
, NULL
,
2661 ALL_ZONES
, (MATCH_IRE_GW
| MATCH_IRE_TYPE
), 0, ipst
, NULL
);
2662 if (prev_ire
!= NULL
) {
2663 if (prev_ire
->ire_flags
& RTF_DYNAMIC
)
2664 ire_delete(prev_ire
);
2665 ire_refrele(prev_ire
);
2672 * Generate an ICMP parameter problem message.
2673 * When called from ip_output side a minimal ip_recv_attr_t needs to be
2674 * constructed by the caller.
2677 icmp_param_problem(mblk_t
*mp
, uint8_t ptr
, ip_recv_attr_t
*ira
)
2680 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2682 mp
= icmp_pkt_err_ok(mp
, ira
);
2686 bzero(&icmph
, sizeof (icmph_t
));
2687 icmph
.icmph_type
= ICMP_PARAM_PROBLEM
;
2688 icmph
.icmph_pp_ptr
= ptr
;
2689 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutParmProbs
);
2690 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
2694 * Build and ship an IPv4 ICMP message using the packet data in mp, and
2695 * the ICMP header pointed to by "stuff". (May be called as writer.)
2696 * Note: assumes that icmp_pkt_err_ok has been called to verify that
2697 * an icmp error packet can be sent.
2698 * Assigns an appropriate source address to the packet. If ipha_dst is
2699 * one of our addresses use it for source. Otherwise let ip_output_simple
2700 * pick the source address.
2703 icmp_pkt(mblk_t
*mp
, void *stuff
, size_t len
, ip_recv_attr_t
*ira
)
2713 ip_xmit_attr_t ixas
;
2714 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2716 ipha
= (ipha_t
*)mp
->b_rptr
;
2718 bzero(&ixas
, sizeof (ixas
));
2719 ixas
.ixa_flags
= IXAF_BASIC_SIMPLE_V4
;
2720 ixas
.ixa_zoneid
= ira
->ira_zoneid
;
2721 ixas
.ixa_ifindex
= 0;
2722 ixas
.ixa_ipst
= ipst
;
2723 ixas
.ixa_cred
= kcred
;
2724 ixas
.ixa_cpid
= NOPID
;
2725 ixas
.ixa_multicast_ttl
= IP_DEFAULT_MULTICAST_TTL
;
2727 if (ira
->ira_flags
& IRAF_IPSEC_SECURE
) {
2729 * Apply IPsec based on how IPsec was applied to
2730 * the packet that had the error.
2732 * If it was an outbound packet that caused the ICMP
2733 * error, then the caller will have setup the IRA
2736 if (!ipsec_in_to_out(ira
, &ixas
, mp
, ipha
, NULL
)) {
2737 BUMP_MIB(&ipst
->ips_ip_mib
, ipIfStatsOutDiscards
);
2738 /* Note: mp already consumed and ip_drop_packet done */
2743 * This is in clear. The icmp message we are building
2744 * here should go out in clear, independent of our policy.
2746 ixas
.ixa_flags
|= IXAF_NO_IPSEC
;
2749 /* Remember our eventual destination */
2750 dst
= ipha
->ipha_src
;
2753 * If the packet was for one of our unicast addresses, make
2754 * sure we respond with that as the source. Otherwise
2755 * have ip_output_simple pick the source address.
2757 ire
= ire_ftable_lookup_v4(ipha
->ipha_dst
, 0, 0,
2758 (IRE_LOCAL
|IRE_LOOPBACK
), NULL
, ira
->ira_zoneid
,
2759 MATCH_IRE_TYPE
|MATCH_IRE_ZONEONLY
, 0, ipst
, NULL
);
2762 src
= ipha
->ipha_dst
;
2765 ixas
.ixa_flags
|= IXAF_SET_SOURCE
;
2769 * Check if we can send back more then 8 bytes in addition to
2770 * the IP header. We try to send 64 bytes of data and the internal
2771 * header in the special cases of ipv4 encapsulated ipv4 or ipv6.
2773 len_needed
= IPH_HDR_LENGTH(ipha
);
2774 if (ipha
->ipha_protocol
== IPPROTO_ENCAP
||
2775 ipha
->ipha_protocol
== IPPROTO_IPV6
) {
2776 if (!pullupmsg(mp
, -1)) {
2777 BUMP_MIB(&ipst
->ips_ip_mib
, ipIfStatsOutDiscards
);
2778 ip_drop_output("ipIfStatsOutDiscards", mp
, NULL
);
2782 ipha
= (ipha_t
*)mp
->b_rptr
;
2784 if (ipha
->ipha_protocol
== IPPROTO_ENCAP
) {
2785 len_needed
+= IPH_HDR_LENGTH(((uchar_t
*)ipha
+
2788 ip6_t
*ip6h
= (ip6_t
*)((uchar_t
*)ipha
+ len_needed
);
2790 ASSERT(ipha
->ipha_protocol
== IPPROTO_IPV6
);
2791 len_needed
+= ip_hdr_length_v6(mp
, ip6h
);
2794 len_needed
+= ipst
->ips_ip_icmp_return
;
2795 msg_len
= msgdsize(mp
);
2796 if (msg_len
> len_needed
) {
2797 (void) adjmsg(mp
, len_needed
- msg_len
);
2798 msg_len
= len_needed
;
2800 mp1
= allocb(sizeof (icmp_ipha
) + len
, BPRI_MED
);
2802 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutErrors
);
2810 * Set IXAF_TRUSTED_ICMP so we can let the ICMP messages this
2811 * node generates be accepted in peace by all on-host destinations.
2812 * If we do NOT assume that all on-host destinations trust
2813 * self-generated ICMP messages, then rework here, ip6.c, and spd.c.
2814 * (Look for IXAF_TRUSTED_ICMP).
2816 ixas
.ixa_flags
|= IXAF_TRUSTED_ICMP
;
2818 ipha
= (ipha_t
*)mp
->b_rptr
;
2819 mp1
->b_wptr
= (uchar_t
*)ipha
+ (sizeof (icmp_ipha
) + len
);
2821 ipha
->ipha_src
= src
;
2822 ipha
->ipha_dst
= dst
;
2823 ipha
->ipha_ttl
= ipst
->ips_ip_def_ttl
;
2824 msg_len
+= sizeof (icmp_ipha
) + len
;
2825 if (msg_len
> IP_MAXPACKET
) {
2826 (void) adjmsg(mp
, IP_MAXPACKET
- msg_len
);
2827 msg_len
= IP_MAXPACKET
;
2829 ipha
->ipha_length
= htons((uint16_t)msg_len
);
2830 icmph
= (icmph_t
*)&ipha
[1];
2831 bcopy(stuff
, icmph
, len
);
2832 icmph
->icmph_checksum
= 0;
2833 icmph
->icmph_checksum
= IP_CSUM(mp
, (int32_t)sizeof (ipha_t
), 0);
2834 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutMsgs
);
2836 (void) ip_output_simple(mp
, &ixas
);
2841 * Determine if an ICMP error packet can be sent given the rate limit.
2842 * The limit consists of an average frequency (icmp_pkt_err_interval measured
2843 * in milliseconds) and a burst size. Burst size number of packets can
2844 * be sent arbitrarely closely spaced.
2845 * The state is tracked using two variables to implement an approximate
2846 * token bucket filter:
2847 * icmp_pkt_err_last - lbolt value when the last burst started
2848 * icmp_pkt_err_sent - number of packets sent in current burst
2851 icmp_err_rate_limit(ip_stack_t
*ipst
)
2853 clock_t now
= TICK_TO_MSEC(ddi_get_lbolt());
2854 uint_t refilled
; /* Number of packets refilled in tbf since last */
2855 /* Guard against changes by loading into local variable */
2856 uint_t err_interval
= ipst
->ips_ip_icmp_err_interval
;
2858 if (err_interval
== 0)
2861 if (ipst
->ips_icmp_pkt_err_last
> now
) {
2862 /* 100HZ lbolt in ms for 32bit arch wraps every 49.7 days */
2863 ipst
->ips_icmp_pkt_err_last
= 0;
2864 ipst
->ips_icmp_pkt_err_sent
= 0;
2867 * If we are in a burst update the token bucket filter.
2868 * Update the "last" time to be close to "now" but make sure
2869 * we don't loose precision.
2871 if (ipst
->ips_icmp_pkt_err_sent
!= 0) {
2872 refilled
= (now
- ipst
->ips_icmp_pkt_err_last
)/err_interval
;
2873 if (refilled
> ipst
->ips_icmp_pkt_err_sent
) {
2874 ipst
->ips_icmp_pkt_err_sent
= 0;
2876 ipst
->ips_icmp_pkt_err_sent
-= refilled
;
2877 ipst
->ips_icmp_pkt_err_last
+= refilled
* err_interval
;
2880 if (ipst
->ips_icmp_pkt_err_sent
== 0) {
2881 /* Start of new burst */
2882 ipst
->ips_icmp_pkt_err_last
= now
;
2884 if (ipst
->ips_icmp_pkt_err_sent
< ipst
->ips_ip_icmp_err_burst
) {
2885 ipst
->ips_icmp_pkt_err_sent
++;
2886 ip1dbg(("icmp_err_rate_limit: %d sent in burst\n",
2887 ipst
->ips_icmp_pkt_err_sent
));
2890 ip1dbg(("icmp_err_rate_limit: dropped\n"));
2895 * Check if it is ok to send an IPv4 ICMP error packet in
2896 * response to the IPv4 packet in mp.
2897 * Free the message and return null if no
2898 * ICMP error packet should be sent.
2901 icmp_pkt_err_ok(mblk_t
*mp
, ip_recv_attr_t
*ira
)
2903 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2910 ipha
= (ipha_t
*)mp
->b_rptr
;
2911 if (ip_csum_hdr(ipha
)) {
2912 BUMP_MIB(&ipst
->ips_ip_mib
, ipIfStatsInCksumErrs
);
2913 ip_drop_input("ipIfStatsInCksumErrs", mp
, NULL
);
2917 if (ip_type_v4(ipha
->ipha_dst
, ipst
) == IRE_BROADCAST
||
2918 ip_type_v4(ipha
->ipha_src
, ipst
) == IRE_BROADCAST
||
2919 CLASSD(ipha
->ipha_dst
) ||
2920 CLASSD(ipha
->ipha_src
) ||
2921 (ntohs(ipha
->ipha_fragment_offset_and_flags
) & IPH_OFFSET
)) {
2922 /* Note: only errors to the fragment with offset 0 */
2923 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
2927 if (ipha
->ipha_protocol
== IPPROTO_ICMP
) {
2929 * Check the ICMP type. RFC 1122 sez: don't send ICMP
2930 * errors in response to any ICMP errors.
2932 len_needed
= IPH_HDR_LENGTH(ipha
) + ICMPH_SIZE
;
2933 if (mp
->b_wptr
- mp
->b_rptr
< len_needed
) {
2934 if (!pullupmsg(mp
, len_needed
)) {
2935 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInErrors
);
2939 ipha
= (ipha_t
*)mp
->b_rptr
;
2942 (&((char *)ipha
)[IPH_HDR_LENGTH(ipha
)]);
2943 switch (icmph
->icmph_type
) {
2944 case ICMP_DEST_UNREACHABLE
:
2945 case ICMP_SOURCE_QUENCH
:
2946 case ICMP_TIME_EXCEEDED
:
2947 case ICMP_PARAM_PROBLEM
:
2949 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
2956 if (icmp_err_rate_limit(ipst
)) {
2958 * Only send ICMP error packets every so often.
2959 * This should be done on a per port/source basis,
2960 * but for now this will suffice.
2969 * Called when a packet was sent out the same link that it arrived on.
2970 * Check if it is ok to send a redirect and then send it.
2973 ip_send_potential_redirect_v4(mblk_t
*mp
, ipha_t
*ipha
, ire_t
*ire
,
2974 ip_recv_attr_t
*ira
)
2976 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2982 * Check the source address to see if it originated
2983 * on the same logical subnet it is going back out on.
2984 * If so, we should be able to send it a redirect.
2985 * Avoid sending a redirect if the destination
2986 * is directly connected (i.e., we matched an IRE_ONLINK),
2987 * or if the packet was source routed out this interface.
2989 * We avoid sending a redirect if the
2990 * destination is directly connected
2991 * because it is possible that multiple
2992 * IP subnets may have been configured on
2993 * the link, and the source may not
2994 * be on the same subnet as ip destination,
2995 * even though they are on the same
2998 if ((ire
->ire_type
& IRE_ONLINK
) ||
2999 ip_source_routed(ipha
, ipst
))
3002 nhop_ire
= ire_nexthop(ire
);
3003 if (nhop_ire
== NULL
)
3006 nhop
= nhop_ire
->ire_addr
;
3008 if (nhop_ire
->ire_type
& IRE_IF_CLONE
) {
3011 /* Follow ire_dep_parent to find non-clone IRE_INTERFACE */
3012 mutex_enter(&nhop_ire
->ire_lock
);
3013 ire2
= nhop_ire
->ire_dep_parent
;
3016 mutex_exit(&nhop_ire
->ire_lock
);
3017 ire_refrele(nhop_ire
);
3020 if (nhop_ire
== NULL
)
3023 ASSERT(!(nhop_ire
->ire_type
& IRE_IF_CLONE
));
3025 src
= ipha
->ipha_src
;
3028 * We look at the interface ire for the nexthop,
3029 * to see if ipha_src is in the same subnet
3032 if ((src
& nhop_ire
->ire_mask
) == (nhop
& nhop_ire
->ire_mask
)) {
3034 * The source is directly connected.
3038 icmp_send_redirect(mp1
, nhop
, ira
);
3041 ire_refrele(nhop_ire
);
3045 * Generate an ICMP redirect message.
3048 icmp_send_redirect(mblk_t
*mp
, ipaddr_t gateway
, ip_recv_attr_t
*ira
)
3051 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
3053 mp
= icmp_pkt_err_ok(mp
, ira
);
3057 bzero(&icmph
, sizeof (icmph_t
));
3058 icmph
.icmph_type
= ICMP_REDIRECT
;
3059 icmph
.icmph_code
= 1;
3060 icmph
.icmph_rd_gateway
= gateway
;
3061 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutRedirects
);
3062 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
3066 * Generate an ICMP time exceeded message.
3069 icmp_time_exceeded(mblk_t
*mp
, uint8_t code
, ip_recv_attr_t
*ira
)
3072 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
3074 mp
= icmp_pkt_err_ok(mp
, ira
);
3078 bzero(&icmph
, sizeof (icmph_t
));
3079 icmph
.icmph_type
= ICMP_TIME_EXCEEDED
;
3080 icmph
.icmph_code
= code
;
3081 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutTimeExcds
);
3082 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
3086 * Generate an ICMP unreachable message.
3087 * When called from ip_output side a minimal ip_recv_attr_t needs to be
3088 * constructed by the caller.
3091 icmp_unreachable(mblk_t
*mp
, uint8_t code
, ip_recv_attr_t
*ira
)
3094 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
3096 mp
= icmp_pkt_err_ok(mp
, ira
);
3100 bzero(&icmph
, sizeof (icmph_t
));
3101 icmph
.icmph_type
= ICMP_DEST_UNREACHABLE
;
3102 icmph
.icmph_code
= code
;
3103 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDestUnreachs
);
3104 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
3108 * Latch in the IPsec state for a stream based the policy in the listener
3109 * and the actions in the ip_recv_attr_t.
3110 * Called directly from TCP and SCTP.
3113 ip_ipsec_policy_inherit(conn_t
*connp
, conn_t
*lconnp
, ip_recv_attr_t
*ira
)
3115 ASSERT(lconnp
->conn_policy
!= NULL
);
3116 ASSERT(connp
->conn_policy
== NULL
);
3118 IPPH_REFHOLD(lconnp
->conn_policy
);
3119 connp
->conn_policy
= lconnp
->conn_policy
;
3121 if (ira
->ira_ipsec_action
!= NULL
) {
3122 if (connp
->conn_latch
== NULL
) {
3123 connp
->conn_latch
= iplatch_create();
3124 if (connp
->conn_latch
== NULL
)
3127 ipsec_latch_inbound(connp
, ira
);
3133 * Verify whether or not the IP address is a valid local address.
3134 * Could be a unicast, including one for a down interface.
3135 * If allow_mcbc then a multicast or broadcast address is also
3138 * In the case of a broadcast/multicast address, however, the
3139 * upper protocol is expected to reset the src address
3140 * to zero when we return IPVL_MCAST/IPVL_BCAST so that
3141 * no packets are emitted with broadcast/multicast address as
3142 * source address (that violates hosts requirements RFC 1122)
3143 * The addresses valid for bind are:
3144 * (1) - INADDR_ANY (0)
3145 * (2) - IP address of an UP interface
3146 * (3) - IP address of a DOWN interface
3147 * (4) - valid local IP broadcast addresses. In this case
3148 * the conn will only receive packets destined to
3149 * the specified broadcast address.
3150 * (5) - a multicast address. In this case
3151 * the conn will only receive packets destined to
3152 * the specified multicast address. Note: the
3153 * application still has to issue an
3154 * IP_ADD_MEMBERSHIP socket option.
3156 * In all the above cases, the bound address must be valid in the current zone.
3157 * When the address is loopback, multicast or broadcast, there might be many
3158 * matching IREs so bind has to look up based on the zone.
3161 ip_laddr_verify_v4(ipaddr_t src_addr
, zoneid_t zoneid
,
3162 ip_stack_t
*ipst
, boolean_t allow_mcbc
)
3166 ASSERT(src_addr
!= INADDR_ANY
);
3168 src_ire
= ire_ftable_lookup_v4(src_addr
, 0, 0, 0,
3169 NULL
, zoneid
, MATCH_IRE_ZONEONLY
, 0, ipst
, NULL
);
3172 * If an address other than in6addr_any is requested,
3173 * we verify that it is a valid address for bind
3174 * Note: Following code is in if-else-if form for
3175 * readability compared to a condition check.
3177 if (src_ire
!= NULL
&& (src_ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
))) {
3179 * (2) Bind to address of local UP interface
3181 ire_refrele(src_ire
);
3182 return (IPVL_UNICAST_UP
);
3183 } else if (src_ire
!= NULL
&& src_ire
->ire_type
& IRE_BROADCAST
) {
3185 * (4) Bind to broadcast address
3187 ire_refrele(src_ire
);
3189 return (IPVL_BCAST
);
3192 } else if (CLASSD(src_addr
)) {
3193 /* (5) bind to multicast address. */
3194 if (src_ire
!= NULL
)
3195 ire_refrele(src_ire
);
3198 return (IPVL_MCAST
);
3205 * (3) Bind to address of local DOWN interface?
3206 * (ipif_lookup_addr() looks up all interfaces
3207 * but we do not get here for UP interfaces
3210 if (src_ire
!= NULL
)
3211 ire_refrele(src_ire
);
3213 ipif
= ipif_lookup_addr(src_addr
, NULL
, zoneid
, ipst
);
3217 /* Not a useful source? */
3218 if (ipif
->ipif_flags
& (IPIF_NOLOCAL
| IPIF_ANYCAST
)) {
3223 return (IPVL_UNICAST_DOWN
);
3228 * Insert in the bind fanout for IPv4 and IPv6.
3229 * The caller should already have used ip_laddr_verify_v*() before calling
3233 ip_laddr_fanout_insert(conn_t
*connp
)
3238 * Allow setting new policies. For example, disconnects result
3239 * in us being called. As we would have set conn_policy_cached
3240 * to B_TRUE before, we should set it to B_FALSE, so that policy
3241 * can change after the disconnect.
3243 connp
->conn_policy_cached
= B_FALSE
;
3245 return (ipcl_bind_insert(connp
));
3249 * Verify that both the source and destination addresses are valid. If
3250 * IPDF_VERIFY_DST is not set, then the destination address may be unreachable,
3251 * i.e. have no route to it. Protocols like TCP want to verify destination
3252 * reachability, while tunnels do not.
3254 * Determine the route, the interface, and (optionally) the source address
3255 * to use to reach a given destination.
3256 * Note that we allow connect to broadcast and multicast addresses when
3257 * IPDF_ALLOW_MCBC is set.
3258 * first_hop and dst_addr are normally the same, but if source routing
3259 * they will differ; in that case the first_hop is what we'll use for the
3260 * routing lookup but the dce checks will be done on dst_addr,
3262 * If uinfo is set, then we fill in the best available information
3263 * we have for the destination. This is based on (in priority order) any
3264 * metrics and path MTU stored in a dce_t, route metrics, and finally the
3265 * ill_mtu/ill_mc_mtu.
3268 ip_set_destination_v4(ipaddr_t
*src_addrp
, ipaddr_t dst_addr
, ipaddr_t firsthop
,
3269 ip_xmit_attr_t
*ixa
, iulp_t
*uinfo
, uint32_t flags
)
3273 ipaddr_t setsrc
; /* RTF_SETSRC */
3274 zoneid_t zoneid
= ixa
->ixa_zoneid
; /* Honors SO_ALLZONES */
3275 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
3282 ASSERT(ixa
->ixa_flags
& IXAF_IS_IPV4
);
3285 * We never send to zero; the ULPs map it to the loopback address.
3286 * We can't allow it since we use zero to mean unitialized in some
3289 ASSERT(dst_addr
!= INADDR_ANY
);
3291 setsrc
= INADDR_ANY
;
3293 * Select a route; For IPMP interfaces, we would only select
3294 * a "hidden" route (i.e., going through a specific under_ill)
3295 * if ixa_ifindex has been specified.
3297 ire
= ip_select_route_v4(firsthop
, *src_addrp
, ixa
,
3298 &generation
, &setsrc
, &error
);
3299 ASSERT(ire
!= NULL
); /* IRE_NOROUTE if none found */
3304 * ire can't be a broadcast or multicast unless IPDF_ALLOW_MCBC is set.
3305 * If IPDF_VERIFY_DST is set, the destination must be reachable;
3306 * Otherwise the destination needn't be reachable.
3308 * If we match on a reject or black hole, then we've got a
3309 * local failure. May as well fail out the connect() attempt,
3310 * since it's never going to succeed.
3312 if (ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
)) {
3314 * If we're verifying destination reachability, we always want
3317 * If we're not verifying destination reachability but the
3318 * destination has a route, we still want to fail on the
3319 * temporary address and broadcast address tests.
3321 * In both cases do we let the code continue so some reasonable
3322 * information is returned to the caller. That enables the
3323 * caller to use (and even cache) the IRE. conn_ip_ouput will
3324 * use the generation mismatch path to check for the unreachable
3325 * case thereby avoiding any specific check in the main path.
3327 ASSERT(generation
== IRE_GENERATION_VERIFY
);
3328 if (flags
& IPDF_VERIFY_DST
) {
3330 * Set errno but continue to set up ixa_ire to be
3331 * the RTF_REJECT|RTF_BLACKHOLE IRE.
3332 * That allows callers to use ip_output to get an
3335 if (!(ire
->ire_type
& IRE_HOST
))
3336 error
= ENETUNREACH
;
3338 error
= EHOSTUNREACH
;
3342 if ((ire
->ire_type
& (IRE_BROADCAST
|IRE_MULTICAST
)) &&
3343 !(flags
& IPDF_ALLOW_MCBC
)) {
3345 ire
= ire_reject(ipst
, B_FALSE
);
3346 generation
= IRE_GENERATION_VERIFY
;
3347 error
= ENETUNREACH
;
3351 if (ixa
->ixa_ire
!= NULL
)
3352 ire_refrele_notr(ixa
->ixa_ire
);
3354 ire_refhold_notr(ire
);
3358 ixa
->ixa_ire_generation
= generation
;
3361 * Ensure that ixa_dce is always set any time that ixa_ire is set,
3362 * since some callers will send a packet to conn_ip_output() even if
3365 if (flags
& IPDF_UNIQUE_DCE
) {
3366 /* Fallback to the default dce if allocation fails */
3367 dce
= dce_lookup_and_add_v4(dst_addr
, ipst
);
3369 generation
= dce
->dce_generation
;
3371 dce
= dce_lookup_v4(dst_addr
, ipst
, &generation
);
3373 dce
= dce_lookup_v4(dst_addr
, ipst
, &generation
);
3375 ASSERT(dce
!= NULL
);
3376 if (ixa
->ixa_dce
!= NULL
)
3377 dce_refrele_notr(ixa
->ixa_dce
);
3379 dce_refhold_notr(dce
);
3383 ixa
->ixa_dce_generation
= generation
;
3384 ixa
->ixa_postfragfn
= ire
->ire_postfragfn
;
3386 if (!(ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))) {
3387 /* Get an nce to cache. */
3388 nce
= ire_to_nce(ire
, firsthop
, NULL
);
3390 /* Allocation failure? */
3391 ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
3393 if (ixa
->ixa_nce
!= NULL
)
3394 nce_refrele(ixa
->ixa_nce
);
3400 * If the source address is a loopback address, the
3401 * destination had best be local or multicast.
3402 * If we are sending to an IRE_LOCAL using a loopback source then
3403 * it had better be the same zoneid.
3405 if (*src_addrp
== htonl(INADDR_LOOPBACK
)) {
3406 if ((ire
->ire_type
& IRE_LOCAL
) && ire
->ire_zoneid
!= zoneid
) {
3407 ire
= NULL
; /* Stored in ixa_ire */
3408 error
= EADDRNOTAVAIL
;
3411 if (!(ire
->ire_type
& (IRE_LOOPBACK
|IRE_LOCAL
|IRE_MULTICAST
))) {
3412 ire
= NULL
; /* Stored in ixa_ire */
3413 error
= EADDRNOTAVAIL
;
3417 if (ire
->ire_type
& IRE_BROADCAST
) {
3419 * If the ULP didn't have a specified source, then we
3420 * make sure we reselect the source when sending
3421 * broadcasts out different interfaces.
3423 if (flags
& IPDF_SELECT_SRC
)
3424 ixa
->ixa_flags
|= IXAF_SET_SOURCE
;
3426 ixa
->ixa_flags
&= ~IXAF_SET_SOURCE
;
3430 * Does the caller want us to pick a source address?
3432 if (flags
& IPDF_SELECT_SRC
) {
3436 * We use use ire_nexthop_ill to avoid the under ipmp
3437 * interface for source address selection. Note that for ipmp
3438 * probe packets, ixa_ifindex would have been specified, and
3439 * the ip_select_route() invocation would have picked an ire
3440 * will ire_ill pointing at an under interface.
3442 ill
= ire_nexthop_ill(ire
);
3444 /* If unreachable we have no ill but need some source */
3446 src_addr
= htonl(INADDR_LOOPBACK
);
3447 /* Make sure we look for a better source address */
3448 generation
= SRC_GENERATION_VERIFY
;
3450 error
= ip_select_source_v4(ill
, setsrc
, dst_addr
,
3451 ixa
->ixa_multicast_ifaddr
, zoneid
,
3452 ipst
, &src_addr
, &generation
, NULL
);
3454 ire
= NULL
; /* Stored in ixa_ire */
3460 * We allow the source address to to down.
3461 * However, we check that we don't use the loopback address
3462 * as a source when sending out on the wire.
3464 if ((src_addr
== htonl(INADDR_LOOPBACK
)) &&
3465 !(ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
|IRE_MULTICAST
)) &&
3466 !(ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))) {
3467 ire
= NULL
; /* Stored in ixa_ire */
3468 error
= EADDRNOTAVAIL
;
3472 *src_addrp
= src_addr
;
3473 ixa
->ixa_src_generation
= generation
;
3477 * Make sure we don't leave an unreachable ixa_nce in place
3478 * since ip_select_route is used when we unplumb i.e., remove
3479 * references on ixa_ire, ixa_nce, and ixa_dce.
3482 if (nce
!= NULL
&& nce
->nce_is_condemned
) {
3484 ixa
->ixa_nce
= NULL
;
3485 ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
3489 * The caller has set IXAF_PMTU_DISCOVERY if path MTU is desired.
3490 * However, we can't do it for IPv4 multicast or broadcast.
3492 if (ire
->ire_type
& (IRE_BROADCAST
|IRE_MULTICAST
))
3493 ixa
->ixa_flags
&= ~IXAF_PMTU_DISCOVERY
;
3496 * Set initial value for fragmentation limit. Either conn_ip_output
3497 * or ULP might updates it when there are routing changes.
3498 * Handles a NULL ixa_ire->ire_ill or a NULL ixa_nce for RTF_REJECT.
3500 pmtu
= ip_get_pmtu(ixa
);
3501 ixa
->ixa_fragsize
= pmtu
;
3502 /* Make sure ixa_fragsize and ixa_pmtu remain identical */
3503 if (ixa
->ixa_flags
& IXAF_VERIFY_PMTU
)
3504 ixa
->ixa_pmtu
= pmtu
;
3507 * Extract information useful for some transports.
3508 * First we look for DCE metrics. Then we take what we have in
3509 * the metrics in the route, where the offlink is used if we have
3512 if (uinfo
!= NULL
) {
3513 bzero(uinfo
, sizeof (*uinfo
));
3515 if (dce
->dce_flags
& DCEF_UINFO
)
3516 *uinfo
= dce
->dce_uinfo
;
3518 rts_merge_metrics(uinfo
, &ire
->ire_metrics
);
3520 /* Allow ire_metrics to decrease the path MTU from above */
3521 if (uinfo
->iulp_mtu
== 0 || uinfo
->iulp_mtu
> pmtu
)
3522 uinfo
->iulp_mtu
= pmtu
;
3524 uinfo
->iulp_localnet
= (ire
->ire_type
& IRE_ONLINK
) != 0;
3525 uinfo
->iulp_loopback
= (ire
->ire_type
& IRE_LOOPBACK
) != 0;
3526 uinfo
->iulp_local
= (ire
->ire_type
& IRE_LOCAL
) != 0;
3542 * Make sure we don't leave an unreachable ixa_nce in place
3543 * since ip_select_route is used when we unplumb i.e., remove
3544 * references on ixa_ire, ixa_nce, and ixa_dce.
3547 if (nce
!= NULL
&& nce
->nce_is_condemned
) {
3549 ixa
->ixa_nce
= NULL
;
3550 ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
3558 * Get the base MTU for the case when path MTU discovery is not used.
3559 * Takes the MTU of the IRE into account.
3562 ip_get_base_mtu(ill_t
*ill
, ire_t
*ire
)
3565 uint_t iremtu
= ire
->ire_metrics
.iulp_mtu
;
3567 if (ire
->ire_type
& (IRE_MULTICAST
|IRE_BROADCAST
))
3568 mtu
= ill
->ill_mc_mtu
;
3572 if (iremtu
!= 0 && iremtu
< mtu
)
3579 * Get the PMTU for the attributes. Handles both IPv4 and IPv6.
3580 * Assumes that ixa_ire, dce, and nce have already been set up.
3582 * The caller has set IXAF_PMTU_DISCOVERY if path MTU discovery is desired.
3583 * We avoid path MTU discovery if it is disabled with ndd.
3584 * Furtermore, if the path MTU is too small, then we don't set DF for IPv4.
3586 * NOTE: We also used to turn it off for source routed packets. That
3587 * is no longer required since the dce is per final destination.
3590 ip_get_pmtu(ip_xmit_attr_t
*ixa
)
3592 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
3603 * If path MTU discovery has been turned off by ndd, then we ignore
3604 * any dce_pmtu and for IPv4 we will not set DF.
3606 if (!ipst
->ips_ip_path_mtu_discovery
)
3607 ixa
->ixa_flags
&= ~IXAF_PMTU_DISCOVERY
;
3609 pmtu
= IP_MAXPACKET
;
3611 * Decide whether whether IPv4 sets DF
3612 * For IPv6 "no DF" means to use the 1280 mtu
3614 if (ixa
->ixa_flags
& IXAF_PMTU_DISCOVERY
) {
3615 ixa
->ixa_flags
|= IXAF_PMTU_IPV4_DF
;
3617 ixa
->ixa_flags
&= ~IXAF_PMTU_IPV4_DF
;
3618 if (!(ixa
->ixa_flags
& IXAF_IS_IPV4
))
3619 pmtu
= IPV6_MIN_MTU
;
3622 /* Check if the PMTU is to old before we use it */
3623 if ((dce
->dce_flags
& DCEF_PMTU
) &&
3624 TICK_TO_SEC(ddi_get_lbolt64()) - dce
->dce_last_change_time
>
3625 ipst
->ips_ip_pathmtu_interval
) {
3627 * Older than 20 minutes. Drop the path MTU information.
3629 mutex_enter(&dce
->dce_lock
);
3630 dce
->dce_flags
&= ~(DCEF_PMTU
|DCEF_TOO_SMALL_PMTU
);
3631 dce
->dce_last_change_time
= TICK_TO_SEC(ddi_get_lbolt64());
3632 mutex_exit(&dce
->dce_lock
);
3633 dce_increment_generation(dce
);
3636 /* The metrics on the route can lower the path MTU */
3637 if (ire
->ire_metrics
.iulp_mtu
!= 0 &&
3638 ire
->ire_metrics
.iulp_mtu
< pmtu
)
3639 pmtu
= ire
->ire_metrics
.iulp_mtu
;
3642 * If the path MTU is smaller than some minimum, we still use dce_pmtu
3643 * above (would be 576 for IPv4 and 1280 for IPv6), but we clear
3644 * IXAF_PMTU_IPV4_DF so that we avoid setting DF for IPv4.
3646 if (ixa
->ixa_flags
& IXAF_PMTU_DISCOVERY
) {
3647 if (dce
->dce_flags
& DCEF_PMTU
) {
3648 if (dce
->dce_pmtu
< pmtu
)
3649 pmtu
= dce
->dce_pmtu
;
3651 if (dce
->dce_flags
& DCEF_TOO_SMALL_PMTU
) {
3652 ixa
->ixa_flags
|= IXAF_PMTU_TOO_SMALL
;
3653 ixa
->ixa_flags
&= ~IXAF_PMTU_IPV4_DF
;
3655 ixa
->ixa_flags
&= ~IXAF_PMTU_TOO_SMALL
;
3656 ixa
->ixa_flags
|= IXAF_PMTU_IPV4_DF
;
3659 ixa
->ixa_flags
&= ~IXAF_PMTU_TOO_SMALL
;
3660 ixa
->ixa_flags
|= IXAF_PMTU_IPV4_DF
;
3665 * If we have an IRE_LOCAL we use the loopback mtu instead of
3666 * the ill for going out the wire i.e., IRE_LOCAL gets the same
3667 * mtu as IRE_LOOPBACK.
3669 if (ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
)) {
3670 uint_t loopback_mtu
;
3672 loopback_mtu
= (ire
->ire_ipversion
== IPV6_VERSION
) ?
3673 ip_loopback_mtu_v6plus
: ip_loopback_mtuplus
;
3675 if (loopback_mtu
< pmtu
)
3676 pmtu
= loopback_mtu
;
3677 } else if (nce
!= NULL
) {
3679 * Make sure we don't exceed the interface MTU.
3680 * In the case of RTF_REJECT or RTF_BLACKHOLE we might not have
3681 * an ill. We'd use the above IP_MAXPACKET in that case just
3682 * to tell the transport something larger than zero.
3684 if (ire
->ire_type
& (IRE_MULTICAST
|IRE_BROADCAST
)) {
3685 if (nce
->nce_common
->ncec_ill
->ill_mc_mtu
< pmtu
)
3686 pmtu
= nce
->nce_common
->ncec_ill
->ill_mc_mtu
;
3687 if (nce
->nce_common
->ncec_ill
!= nce
->nce_ill
&&
3688 nce
->nce_ill
->ill_mc_mtu
< pmtu
) {
3690 * for interfaces in an IPMP group, the mtu of
3691 * the nce_ill (under_ill) could be different
3692 * from the mtu of the ncec_ill, so we take the
3695 pmtu
= nce
->nce_ill
->ill_mc_mtu
;
3698 if (nce
->nce_common
->ncec_ill
->ill_mtu
< pmtu
)
3699 pmtu
= nce
->nce_common
->ncec_ill
->ill_mtu
;
3700 if (nce
->nce_common
->ncec_ill
!= nce
->nce_ill
&&
3701 nce
->nce_ill
->ill_mtu
< pmtu
) {
3703 * for interfaces in an IPMP group, the mtu of
3704 * the nce_ill (under_ill) could be different
3705 * from the mtu of the ncec_ill, so we take the
3708 pmtu
= nce
->nce_ill
->ill_mtu
;
3714 * Handle the IPV6_USE_MIN_MTU socket option or ancillary data.
3715 * Only applies to IPv6.
3717 if (!(ixa
->ixa_flags
& IXAF_IS_IPV4
)) {
3718 if (ixa
->ixa_flags
& IXAF_USE_MIN_MTU
) {
3719 switch (ixa
->ixa_use_min_mtu
) {
3720 case IPV6_USE_MIN_MTU_MULTICAST
:
3721 if (ire
->ire_type
& IRE_MULTICAST
)
3722 pmtu
= IPV6_MIN_MTU
;
3724 case IPV6_USE_MIN_MTU_ALWAYS
:
3725 pmtu
= IPV6_MIN_MTU
;
3727 case IPV6_USE_MIN_MTU_NEVER
:
3731 /* Default is IPV6_USE_MIN_MTU_MULTICAST */
3732 if (ire
->ire_type
& IRE_MULTICAST
)
3733 pmtu
= IPV6_MIN_MTU
;
3741 * Carve "len" bytes out of an mblk chain, consuming any we empty, and duping
3742 * the final piece where we don't. Return a pointer to the first mblk in the
3743 * result, and update the pointer to the next mblk to chew on. If anything
3744 * goes wrong (i.e., dupb fails), we waste everything in sight and return a
3748 ip_carve_mp(mblk_t
**mpp
, ssize_t len
)
3754 if (!len
|| !mpp
|| !(mp0
= *mpp
))
3756 /* If we aren't going to consume the first mblk, we need a dup. */
3757 if (mp0
->b_wptr
- mp0
->b_rptr
> len
) {
3760 /* Partition the data between the two mblks. */
3761 mp1
->b_wptr
= mp1
->b_rptr
+ len
;
3762 mp0
->b_rptr
= mp1
->b_wptr
;
3764 * after adjustments if mblk not consumed is now
3765 * unaligned, try to align it. If this fails free
3766 * all messages and let upper layer recover.
3768 if (!OK_32PTR(mp0
->b_rptr
)) {
3769 if (!pullupmsg(mp0
, -1)) {
3779 /* Eat through as many mblks as we need to get len bytes. */
3780 len
-= mp0
->b_wptr
- mp0
->b_rptr
;
3781 for (mp2
= mp1
= mp0
; (mp2
= mp2
->b_cont
) != 0 && len
; mp1
= mp2
) {
3782 if (mp2
->b_wptr
- mp2
->b_rptr
> len
) {
3784 * We won't consume the entire last mblk. Like
3785 * above, dup and partition it.
3787 mp1
->b_cont
= dupb(mp2
);
3791 * Trouble. Rather than go to a lot of
3792 * trouble to clean up, we free the messages.
3793 * This won't be any worse than losing it on
3801 mp1
->b_wptr
= mp1
->b_rptr
+ len
;
3802 mp2
->b_rptr
= mp1
->b_wptr
;
3804 * after adjustments if mblk not consumed is now
3805 * unaligned, try to align it. If this fails free
3806 * all messages and let upper layer recover.
3808 if (!OK_32PTR(mp2
->b_rptr
)) {
3809 if (!pullupmsg(mp2
, -1)) {
3819 /* Decrement len by the amount we just got. */
3820 len
-= mp2
->b_wptr
- mp2
->b_rptr
;
3823 * len should be reduced to zero now. If not our caller has
3827 /* Shouldn't happen! */
3833 * We consumed up to exactly the end of an mblk. Detach the part
3834 * we are returning from the rest of the chain.
3841 /* The ill stream is being unplumbed. Called from ip_close */
3843 ip_modclose(ill_t
*ill
)
3848 queue_t
*q
= ill
->ill_rq
;
3849 ip_stack_t
*ipst
= ill
->ill_ipst
;
3851 arl_ill_common_t
*ai
= ill
->ill_common
;
3854 * The punlink prior to this may have initiated a capability
3855 * negotiation. But ipsq_enter will block until that finishes or
3858 success
= ipsq_enter(ill
, B_FALSE
, NEW_OP
);
3861 * Open/close/push/pop is guaranteed to be single threaded
3862 * per stream by STREAMS. FS guarantees that all references
3863 * from top are gone before close is called. So there can't
3864 * be another close thread that has set CONDEMNED on this ill.
3865 * and cause ipsq_enter to return failure.
3868 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
3871 * Mark it condemned. No new reference will be made to this ill.
3872 * Lookup functions will return an error. Threads that try to
3873 * increment the refcnt must check for ILL_CAN_LOOKUP. This ensures
3874 * that the refcnt will drop down to zero.
3876 mutex_enter(&ill
->ill_lock
);
3877 ill
->ill_state_flags
|= ILL_CONDEMNED
;
3878 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
3879 ipif
= ipif
->ipif_next
) {
3880 ipif
->ipif_state_flags
|= IPIF_CONDEMNED
;
3883 * Wake up anybody waiting to enter the ipsq. ipsq_enter
3884 * returns error if ILL_CONDEMNED is set
3886 cv_broadcast(&ill
->ill_cv
);
3887 mutex_exit(&ill
->ill_lock
);
3890 * Send all the deferred DLPI messages downstream which came in
3891 * during the small window right before ipsq_enter(). We do this
3892 * without waiting for the ACKs because all the ACKs for M_PROTO
3893 * messages are ignored in ip_rput() when ILL_CONDEMNED is set.
3895 ill_dlpi_send_deferred(ill
);
3898 * Shut down fragmentation reassembly.
3899 * ill_frag_timer won't start a timer again.
3900 * Now cancel any existing timer
3902 (void) untimeout(ill
->ill_frag_timer_id
);
3903 (void) ill_frag_timeout(ill
, 0);
3906 * Call ill_delete to bring down the ipifs, ilms and ill on
3907 * this ill. Then wait for the refcnts to drop to zero.
3908 * ill_is_freeable checks whether the ill is really quiescent.
3909 * Then make sure that threads that are waiting to enter the
3910 * ipsq have seen the error returned by ipsq_enter and have
3911 * gone away. Then we call ill_delete_tail which does the
3912 * DL_UNBIND_REQ with the driver and then qprocsoff.
3915 mutex_enter(&ill
->ill_lock
);
3916 while (!ill_is_freeable(ill
))
3917 cv_wait(&ill
->ill_cv
, &ill
->ill_lock
);
3919 while (ill
->ill_waiters
)
3920 cv_wait(&ill
->ill_cv
, &ill
->ill_lock
);
3922 mutex_exit(&ill
->ill_lock
);
3925 * ill_delete_tail drops reference on ill_ipst, but we need to keep
3926 * it held until the end of the function since the cleanup
3927 * below needs to be able to use the ip_stack_t.
3929 netstack_hold(ipst
->ips_netstack
);
3931 /* qprocsoff is done via ill_delete_tail */
3932 ill_delete_tail(ill
);
3934 * synchronously wait for arp stream to unbind. After this, we
3935 * cannot get any data packets up from the driver.
3937 arp_unbind_complete(ill
);
3938 ASSERT(ill
->ill_ipst
== NULL
);
3941 * Walk through all conns and qenable those that have queued data.
3942 * Close synchronization needs this to
3943 * be done to ensure that all upper layers blocked
3944 * due to flow control to the closing device
3947 ip1dbg(("ip_wsrv: walking\n"));
3948 for (i
= 0; i
< TX_FANOUT_SIZE
; i
++) {
3949 conn_walk_drain(ipst
, &ipst
->ips_idl_tx_list
[i
]);
3953 * ai can be null if this is an IPv6 ill, or if the IPv4
3954 * stream is being torn down before ARP was plumbed (e.g.,
3955 * /sbin/ifconfig plumbing a stream twice, and encountering
3959 ASSERT(!ill
->ill_isv6
);
3960 mutex_enter(&ai
->ai_lock
);
3962 if (ai
->ai_arl
== NULL
) {
3963 mutex_destroy(&ai
->ai_lock
);
3964 kmem_free(ai
, sizeof (*ai
));
3966 cv_signal(&ai
->ai_ill_unplumb_done
);
3967 mutex_exit(&ai
->ai_lock
);
3971 mutex_enter(&ipst
->ips_ip_mi_lock
);
3972 mi_close_unlink(&ipst
->ips_ip_g_head
, (IDP
)ill
);
3973 mutex_exit(&ipst
->ips_ip_mi_lock
);
3976 * credp could be null if the open didn't succeed and ip_modopen
3977 * itself calls ip_close.
3979 if (ill
->ill_credp
!= NULL
)
3980 crfree(ill
->ill_credp
);
3982 mutex_destroy(&ill
->ill_saved_ire_lock
);
3983 mutex_destroy(&ill
->ill_lock
);
3984 rw_destroy(&ill
->ill_mcast_lock
);
3985 mutex_destroy(&ill
->ill_mcast_serializer
);
3986 list_destroy(&ill
->ill_nce
);
3989 * Now we are done with the module close pieces that
3990 * need the netstack_t.
3992 netstack_rele(ipst
->ips_netstack
);
3994 mi_close_free((IDP
)ill
);
3995 q
->q_ptr
= WR(q
)->q_ptr
= NULL
;
4003 * This is called as part of close() for IP, UDP, ICMP, and RTS
4004 * in order to quiesce the conn.
4007 ip_quiesce_conn(conn_t
*connp
)
4009 boolean_t drain_cleanup_reqd
= B_FALSE
;
4010 boolean_t conn_ioctl_cleanup_reqd
= B_FALSE
;
4011 boolean_t ilg_cleanup_reqd
= B_FALSE
;
4014 ASSERT(!IPCL_IS_TCP(connp
));
4015 ipst
= connp
->conn_netstack
->netstack_ip
;
4018 * Mark the conn as closing, and this conn must not be
4019 * inserted in future into any list. Eg. conn_drain_insert(),
4020 * won't insert this conn into the conn_drain_list.
4022 * conn_idl, and conn_ilg cannot get set henceforth.
4024 mutex_enter(&connp
->conn_lock
);
4025 ASSERT(!(connp
->conn_state_flags
& CONN_QUIESCED
));
4026 connp
->conn_state_flags
|= CONN_CLOSING
;
4027 if (connp
->conn_idl
!= NULL
)
4028 drain_cleanup_reqd
= B_TRUE
;
4029 if (connp
->conn_oper_pending_ill
!= NULL
)
4030 conn_ioctl_cleanup_reqd
= B_TRUE
;
4031 if (connp
->conn_dhcpinit_ill
!= NULL
) {
4032 ASSERT(connp
->conn_dhcpinit_ill
->ill_dhcpinit
!= 0);
4033 atomic_dec_32(&connp
->conn_dhcpinit_ill
->ill_dhcpinit
);
4034 ill_set_inputfn(connp
->conn_dhcpinit_ill
);
4035 connp
->conn_dhcpinit_ill
= NULL
;
4037 if (connp
->conn_ilg
!= NULL
)
4038 ilg_cleanup_reqd
= B_TRUE
;
4039 mutex_exit(&connp
->conn_lock
);
4041 if (conn_ioctl_cleanup_reqd
)
4042 conn_ioctl_cleanup(connp
);
4045 * Remove this conn from any fanout list it is on.
4046 * and then wait for any threads currently operating
4047 * on this endpoint to finish
4049 ipcl_hash_remove(connp
);
4052 * Remove this conn from the drain list, and do any other cleanup that
4053 * may be required. (TCP conns are never flow controlled, and
4054 * conn_idl will be NULL.)
4056 if (drain_cleanup_reqd
&& connp
->conn_idl
!= NULL
) {
4057 idl_t
*idl
= connp
->conn_idl
;
4059 mutex_enter(&idl
->idl_lock
);
4060 conn_drain(connp
, B_TRUE
);
4061 mutex_exit(&idl
->idl_lock
);
4064 if (connp
== ipst
->ips_ip_g_mrouter
)
4065 (void) ip_mrouter_done(ipst
);
4067 if (ilg_cleanup_reqd
)
4068 ilg_delete_all(connp
);
4071 * Now conn refcnt can increase only thru CONN_INC_REF_LOCKED.
4072 * callers from write side can't be there now because close
4073 * is in progress. The only other caller is ipcl_walk
4074 * which checks for the condemned flag.
4076 mutex_enter(&connp
->conn_lock
);
4077 connp
->conn_state_flags
|= CONN_CONDEMNED
;
4078 while (connp
->conn_ref
!= 1)
4079 cv_wait(&connp
->conn_cv
, &connp
->conn_lock
);
4080 connp
->conn_state_flags
|= CONN_QUIESCED
;
4081 mutex_exit(&connp
->conn_lock
);
4086 ip_close(queue_t
*q
, int flags
, cred_t
*credp __unused
)
4091 * Call the appropriate delete routine depending on whether this is
4092 * a module or device.
4094 if (WR(q
)->q_next
!= NULL
) {
4095 /* This is a module close */
4096 return (ip_modclose((ill_t
*)q
->q_ptr
));
4100 ip_quiesce_conn(connp
);
4105 * Now we are truly single threaded on this stream, and can
4106 * delete the things hanging off the connp, and finally the connp.
4107 * We removed this connp from the fanout list, it cannot be
4108 * accessed thru the fanouts, and we already waited for the
4109 * conn_ref to drop to 0. We are already in close, so
4110 * there cannot be any other thread from the top. qprocsoff
4111 * has completed, and service has completed or won't run in
4114 ASSERT(connp
->conn_ref
== 1);
4116 inet_minor_free(connp
->conn_minor_arena
, connp
->conn_dev
);
4119 ipcl_conn_destroy(connp
);
4121 q
->q_ptr
= WR(q
)->q_ptr
= NULL
;
4126 * Wapper around putnext() so that ip_rts_request can merely use
4131 ip_conn_input(void *arg1
, mblk_t
*mp
, void *arg2
, ip_recv_attr_t
*ira
)
4133 conn_t
*connp
= (conn_t
*)arg1
;
4135 putnext(connp
->conn_rq
, mp
);
4138 /* Dummy in case ICMP error delivery is attempted to a /dev/ip instance */
4141 ip_conn_input_icmp(void *arg1
, mblk_t
*mp
, void *arg2
, ip_recv_attr_t
*ira
)
4147 * Called when the module is about to be unloaded
4150 ip_ddi_destroy(void)
4152 /* This needs to be called before destroying any transports. */
4153 mutex_enter(&cpu_lock
);
4154 unregister_cpu_setup_func(ip_tp_cpu_update
, NULL
);
4155 mutex_exit(&cpu_lock
);
4157 icmp_ddi_g_destroy();
4158 rts_ddi_g_destroy();
4159 udp_ddi_g_destroy();
4160 sctp_ddi_g_destroy();
4161 tcp_ddi_g_destroy();
4162 ilb_ddi_g_destroy();
4164 ipsec_policy_g_destroy();
4168 inet_minor_destroy(ip_minor_arena_sa
);
4170 inet_minor_destroy(ip_minor_arena_la
);
4174 list_destroy(&ip_thread_list
);
4175 rw_destroy(&ip_thread_rwlock
);
4176 tsd_destroy(&ip_thread_data
);
4179 netstack_unregister(NS_IP
);
4183 * First step in cleanup.
4187 ip_stack_shutdown(netstackid_t stackid
, void *arg
)
4189 ip_stack_t
*ipst
= (ip_stack_t
*)arg
;
4193 printf("ip_stack_shutdown(%p, stack %d)\n", (void *)ipst
, stackid
);
4197 * Perform cleanup for special interfaces (loopback and IPMP).
4199 ip_interface_cleanup(ipst
);
4202 * The *_hook_shutdown()s start the process of notifying any
4203 * consumers that things are going away.... nothing is destroyed.
4205 ipv4_hook_shutdown(ipst
);
4206 ipv6_hook_shutdown(ipst
);
4207 arp_hook_shutdown(ipst
);
4209 mutex_enter(&ipst
->ips_capab_taskq_lock
);
4210 ktid
= ipst
->ips_capab_taskq_thread
->t_did
;
4211 ipst
->ips_capab_taskq_quit
= B_TRUE
;
4212 cv_signal(&ipst
->ips_capab_taskq_cv
);
4213 mutex_exit(&ipst
->ips_capab_taskq_lock
);
4216 * In rare occurrences, particularly on virtual hardware where CPUs can
4217 * be de-scheduled, the thread that we just signaled will not run until
4218 * after we have gotten through parts of ip_stack_fini. If that happens
4219 * then we'll try to grab the ips_capab_taskq_lock as part of returning
4220 * from cv_wait which no longer exists.
4226 * Free the IP stack instance.
4229 ip_stack_fini(netstackid_t stackid
, void *arg
)
4231 ip_stack_t
*ipst
= (ip_stack_t
*)arg
;
4235 printf("ip_stack_fini(%p, stack %d)\n", (void *)ipst
, stackid
);
4238 * At this point, all of the notifications that the events and
4239 * protocols are going away have been run, meaning that we can
4240 * now set about starting to clean things up.
4243 ipv4_hook_destroy(ipst
);
4244 ipv6_hook_destroy(ipst
);
4245 arp_hook_destroy(ipst
);
4246 ip_net_destroy(ipst
);
4250 ip_kstat_fini(stackid
, ipst
->ips_ip_mibkp
);
4251 ipst
->ips_ip_mibkp
= NULL
;
4252 icmp_kstat_fini(stackid
, ipst
->ips_icmp_mibkp
);
4253 ipst
->ips_icmp_mibkp
= NULL
;
4254 ip_kstat2_fini(stackid
, ipst
->ips_ip_kstat
);
4255 ipst
->ips_ip_kstat
= NULL
;
4256 bzero(&ipst
->ips_ip_statistics
, sizeof (ipst
->ips_ip_statistics
));
4257 ip6_kstat_fini(stackid
, ipst
->ips_ip6_kstat
);
4258 ipst
->ips_ip6_kstat
= NULL
;
4259 bzero(&ipst
->ips_ip6_statistics
, sizeof (ipst
->ips_ip6_statistics
));
4261 kmem_free(ipst
->ips_propinfo_tbl
,
4262 ip_propinfo_count
* sizeof (mod_prop_info_t
));
4263 ipst
->ips_propinfo_tbl
= NULL
;
4265 dce_stack_destroy(ipst
);
4266 ip_mrouter_stack_destroy(ipst
);
4269 * Quiesce all of our timers. Note we set the quiesce flags before we
4270 * call untimeout. The slowtimers may actually kick off another instance
4271 * of the non-slow timers.
4273 mutex_enter(&ipst
->ips_igmp_timer_lock
);
4274 ipst
->ips_igmp_timer_quiesce
= B_TRUE
;
4275 mutex_exit(&ipst
->ips_igmp_timer_lock
);
4277 mutex_enter(&ipst
->ips_mld_timer_lock
);
4278 ipst
->ips_mld_timer_quiesce
= B_TRUE
;
4279 mutex_exit(&ipst
->ips_mld_timer_lock
);
4281 mutex_enter(&ipst
->ips_igmp_slowtimeout_lock
);
4282 ipst
->ips_igmp_slowtimeout_quiesce
= B_TRUE
;
4283 mutex_exit(&ipst
->ips_igmp_slowtimeout_lock
);
4285 mutex_enter(&ipst
->ips_mld_slowtimeout_lock
);
4286 ipst
->ips_mld_slowtimeout_quiesce
= B_TRUE
;
4287 mutex_exit(&ipst
->ips_mld_slowtimeout_lock
);
4289 ret
= untimeout(ipst
->ips_igmp_timeout_id
);
4291 ASSERT(ipst
->ips_igmp_timeout_id
== 0);
4293 ASSERT(ipst
->ips_igmp_timeout_id
!= 0);
4294 ipst
->ips_igmp_timeout_id
= 0;
4296 ret
= untimeout(ipst
->ips_igmp_slowtimeout_id
);
4298 ASSERT(ipst
->ips_igmp_slowtimeout_id
== 0);
4300 ASSERT(ipst
->ips_igmp_slowtimeout_id
!= 0);
4301 ipst
->ips_igmp_slowtimeout_id
= 0;
4303 ret
= untimeout(ipst
->ips_mld_timeout_id
);
4305 ASSERT(ipst
->ips_mld_timeout_id
== 0);
4307 ASSERT(ipst
->ips_mld_timeout_id
!= 0);
4308 ipst
->ips_mld_timeout_id
= 0;
4310 ret
= untimeout(ipst
->ips_mld_slowtimeout_id
);
4312 ASSERT(ipst
->ips_mld_slowtimeout_id
== 0);
4314 ASSERT(ipst
->ips_mld_slowtimeout_id
!= 0);
4315 ipst
->ips_mld_slowtimeout_id
= 0;
4320 conn_drain_fini(ipst
);
4323 mutex_destroy(&ipst
->ips_ndp4
->ndp_g_lock
);
4324 mutex_destroy(&ipst
->ips_ndp6
->ndp_g_lock
);
4325 kmem_free(ipst
->ips_ndp4
, sizeof (ndp_g_t
));
4326 ipst
->ips_ndp4
= NULL
;
4327 kmem_free(ipst
->ips_ndp6
, sizeof (ndp_g_t
));
4328 ipst
->ips_ndp6
= NULL
;
4330 if (ipst
->ips_loopback_ksp
!= NULL
) {
4331 kstat_delete_netstack(ipst
->ips_loopback_ksp
, stackid
);
4332 ipst
->ips_loopback_ksp
= NULL
;
4335 mutex_destroy(&ipst
->ips_capab_taskq_lock
);
4336 cv_destroy(&ipst
->ips_capab_taskq_cv
);
4338 rw_destroy(&ipst
->ips_srcid_lock
);
4340 mutex_destroy(&ipst
->ips_ip_mi_lock
);
4341 rw_destroy(&ipst
->ips_ill_g_usesrc_lock
);
4343 mutex_destroy(&ipst
->ips_igmp_timer_lock
);
4344 mutex_destroy(&ipst
->ips_mld_timer_lock
);
4345 mutex_destroy(&ipst
->ips_igmp_slowtimeout_lock
);
4346 mutex_destroy(&ipst
->ips_mld_slowtimeout_lock
);
4347 mutex_destroy(&ipst
->ips_ip_addr_avail_lock
);
4348 rw_destroy(&ipst
->ips_ill_g_lock
);
4350 kmem_free(ipst
->ips_phyint_g_list
, sizeof (phyint_list_t
));
4351 ipst
->ips_phyint_g_list
= NULL
;
4352 kmem_free(ipst
->ips_ill_g_heads
, sizeof (ill_g_head_t
) * MAX_G_HEADS
);
4353 ipst
->ips_ill_g_heads
= NULL
;
4355 ldi_ident_release(ipst
->ips_ldi_ident
);
4356 kmem_free(ipst
, sizeof (*ipst
));
4360 * This function is called from the TSD destructor, and is used to debug
4361 * reference count issues in IP. See block comment in <inet/ip_if.h> for
4365 ip_thread_exit(void *phash
)
4367 th_hash_t
*thh
= phash
;
4369 rw_enter(&ip_thread_rwlock
, RW_WRITER
);
4370 list_remove(&ip_thread_list
, thh
);
4371 rw_exit(&ip_thread_rwlock
);
4372 mod_hash_destroy_hash(thh
->thh_hash
);
4373 kmem_free(thh
, sizeof (*thh
));
4377 * Called when the IP kernel module is loaded into the kernel
4382 ip_squeue_flag
= ip_squeue_switch(ip_squeue_enter
);
4385 * For IP and TCP the minor numbers should start from 2 since we have 4
4386 * initial devices: ip, ip6, tcp, tcp6.
4389 * If this is a 64-bit kernel, then create two separate arenas -
4390 * one for TLIs in the range of INET_MIN_DEV+2 through 2^^18-1, and the
4391 * other for socket apps in the range 2^^18 through 2^^32-1.
4393 ip_minor_arena_la
= NULL
;
4394 ip_minor_arena_sa
= NULL
;
4396 if ((ip_minor_arena_sa
= inet_minor_create("ip_minor_arena_sa",
4397 INET_MIN_DEV
+ 2, MAXMIN32
, KM_SLEEP
)) == NULL
) {
4399 "ip_ddi_init: ip_minor_arena_sa creation failed\n");
4401 if ((ip_minor_arena_la
= inet_minor_create("ip_minor_arena_la",
4402 MAXMIN32
+ 1, MAXMIN64
, KM_SLEEP
)) == NULL
) {
4404 "ip_ddi_init: ip_minor_arena_la creation failed\n");
4407 if ((ip_minor_arena_sa
= inet_minor_create("ip_minor_arena_sa",
4408 INET_MIN_DEV
+ 2, MAXMIN
, KM_SLEEP
)) == NULL
) {
4410 "ip_ddi_init: ip_minor_arena_sa creation failed\n");
4413 ip_poll_normal_ticks
= MSEC_TO_TICK_ROUNDUP(ip_poll_normal_ms
);
4420 tsd_create(&ip_thread_data
, ip_thread_exit
);
4421 rw_init(&ip_thread_rwlock
, NULL
, RW_DEFAULT
, NULL
);
4422 list_create(&ip_thread_list
, sizeof (th_hash_t
),
4423 offsetof(th_hash_t
, thh_link
));
4425 ipsec_policy_g_init();
4431 * We want to be informed each time a stack is created or
4432 * destroyed in the kernel, so we can maintain the
4433 * set of udp_stack_t's.
4435 netstack_register(NS_IP
, ip_stack_init
, ip_stack_shutdown
,
4443 /* This needs to be called after all transports are initialized. */
4444 mutex_enter(&cpu_lock
);
4445 register_cpu_setup_func(ip_tp_cpu_update
, NULL
);
4446 mutex_exit(&cpu_lock
);
4450 * Initialize the IP stack instance.
4453 ip_stack_init(netstackid_t stackid
, netstack_t
*ns
)
4460 printf("ip_stack_init(stack %d)\n", stackid
);
4463 ipst
= (ip_stack_t
*)kmem_zalloc(sizeof (*ipst
), KM_SLEEP
);
4464 ipst
->ips_netstack
= ns
;
4466 ipst
->ips_ill_g_heads
= kmem_zalloc(sizeof (ill_g_head_t
) * MAX_G_HEADS
,
4468 ipst
->ips_phyint_g_list
= kmem_zalloc(sizeof (phyint_list_t
),
4470 ipst
->ips_ndp4
= kmem_zalloc(sizeof (ndp_g_t
), KM_SLEEP
);
4471 ipst
->ips_ndp6
= kmem_zalloc(sizeof (ndp_g_t
), KM_SLEEP
);
4472 mutex_init(&ipst
->ips_ndp4
->ndp_g_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4473 mutex_init(&ipst
->ips_ndp6
->ndp_g_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4475 mutex_init(&ipst
->ips_igmp_timer_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4476 ipst
->ips_igmp_deferred_next
= INFINITY
;
4477 mutex_init(&ipst
->ips_mld_timer_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4478 ipst
->ips_mld_deferred_next
= INFINITY
;
4479 mutex_init(&ipst
->ips_igmp_slowtimeout_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4480 mutex_init(&ipst
->ips_mld_slowtimeout_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4481 mutex_init(&ipst
->ips_ip_mi_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4482 mutex_init(&ipst
->ips_ip_addr_avail_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4483 rw_init(&ipst
->ips_ill_g_lock
, NULL
, RW_DEFAULT
, NULL
);
4484 rw_init(&ipst
->ips_ill_g_usesrc_lock
, NULL
, RW_DEFAULT
, NULL
);
4490 conn_drain_init(ipst
);
4491 ip_mrouter_stack_init(ipst
);
4492 dce_stack_init(ipst
);
4494 ipst
->ips_ill_index
= 1;
4496 ipst
->ips_saved_ip_forwarding
= -1;
4497 ipst
->ips_reg_vif_num
= ALL_VIFS
; /* Index to Register vif */
4499 arrsz
= ip_propinfo_count
* sizeof (mod_prop_info_t
);
4500 ipst
->ips_propinfo_tbl
= (mod_prop_info_t
*)kmem_alloc(arrsz
, KM_SLEEP
);
4501 bcopy(ip_propinfo_tbl
, ipst
->ips_propinfo_tbl
, arrsz
);
4503 ipst
->ips_ip_mibkp
= ip_kstat_init(stackid
, ipst
);
4504 ipst
->ips_icmp_mibkp
= icmp_kstat_init(stackid
);
4505 ipst
->ips_ip_kstat
= ip_kstat2_init(stackid
, &ipst
->ips_ip_statistics
);
4506 ipst
->ips_ip6_kstat
=
4507 ip6_kstat_init(stackid
, &ipst
->ips_ip6_statistics
);
4509 ipst
->ips_ip_src_id
= 1;
4510 rw_init(&ipst
->ips_srcid_lock
, NULL
, RW_DEFAULT
, NULL
);
4512 ipst
->ips_src_generation
= SRC_GENERATION_INITIAL
;
4514 ip_net_init(ipst
, ns
);
4515 ipv4_hook_init(ipst
);
4516 ipv6_hook_init(ipst
);
4517 arp_hook_init(ipst
);
4522 * Create the taskq dispatcher thread and initialize related stuff.
4524 mutex_init(&ipst
->ips_capab_taskq_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4525 cv_init(&ipst
->ips_capab_taskq_cv
, NULL
, CV_DEFAULT
, NULL
);
4526 ipst
->ips_capab_taskq_thread
= thread_create(NULL
, 0,
4527 ill_taskq_dispatch
, ipst
, 0, &p0
, TS_RUN
, minclsyspri
);
4529 major
= mod_name_to_major(INET_NAME
);
4530 (void) ldi_ident_from_major(major
, &ipst
->ips_ldi_ident
);
4535 * Allocate and initialize a DLPI template of the specified length. (May be
4536 * called as writer.)
4539 ip_dlpi_alloc(size_t len
, t_uscalar_t prim
)
4543 mp
= allocb(len
, BPRI_MED
);
4548 * DLPIv2 says that DL_INFO_REQ and DL_TOKEN_REQ (the latter
4549 * of which we don't seem to use) are sent with M_PCPROTO, and
4550 * that other DLPI are M_PROTO.
4552 if (prim
== DL_INFO_REQ
) {
4553 mp
->b_datap
->db_type
= M_PCPROTO
;
4555 mp
->b_datap
->db_type
= M_PROTO
;
4558 mp
->b_wptr
= mp
->b_rptr
+ len
;
4559 bzero(mp
->b_rptr
, len
);
4560 ((dl_unitdata_req_t
*)mp
->b_rptr
)->dl_primitive
= prim
;
4565 * Allocate and initialize a DLPI notification. (May be called as writer.)
4568 ip_dlnotify_alloc(uint_t notification
, uint_t data
)
4570 dl_notify_ind_t
*notifyp
;
4573 if ((mp
= ip_dlpi_alloc(DL_NOTIFY_IND_SIZE
, DL_NOTIFY_IND
)) == NULL
)
4576 notifyp
= (dl_notify_ind_t
*)mp
->b_rptr
;
4577 notifyp
->dl_notification
= notification
;
4578 notifyp
->dl_data
= data
;
4583 ip_dlnotify_alloc2(uint_t notification
, uint_t data1
, uint_t data2
)
4585 dl_notify_ind_t
*notifyp
;
4588 if ((mp
= ip_dlpi_alloc(DL_NOTIFY_IND_SIZE
, DL_NOTIFY_IND
)) == NULL
)
4591 notifyp
= (dl_notify_ind_t
*)mp
->b_rptr
;
4592 notifyp
->dl_notification
= notification
;
4593 notifyp
->dl_data1
= data1
;
4594 notifyp
->dl_data2
= data2
;
4599 * Debug formatting routine. Returns a character string representation of the
4600 * addr in buf, of the form xxx.xxx.xxx.xxx. This routine takes the address
4601 * in the form of a ipaddr_t and calls ip_dot_saddr with a pointer.
4603 * Once the ndd table-printing interfaces are removed, this can be changed to
4604 * standard dotted-decimal form.
4607 ip_dot_addr(ipaddr_t addr
, char *buf
)
4609 uint8_t *ap
= (uint8_t *)&addr
;
4611 (void) mi_sprintf(buf
, "%03d.%03d.%03d.%03d",
4612 ap
[0] & 0xFF, ap
[1] & 0xFF, ap
[2] & 0xFF, ap
[3] & 0xFF);
4617 * Write the given MAC address as a printable string in the usual colon-
4621 mac_colon_addr(const uint8_t *addr
, size_t alen
, char *buf
, size_t buflen
)
4625 if (alen
== 0 || buflen
< 4)
4630 * If there are more MAC address bytes available, but we won't
4631 * have any room to print them, then add "..." to the string
4632 * instead. See below for the 'magic number' explanation.
4634 if ((alen
== 2 && buflen
< 6) || (alen
> 2 && buflen
< 7)) {
4635 (void) strcpy(bp
, "...");
4638 (void) sprintf(bp
, "%02x", *addr
++);
4645 * At this point, based on the first 'if' statement above,
4646 * either alen == 1 and buflen >= 3, or alen > 1 and
4647 * buflen >= 4. The first case leaves room for the final "xx"
4648 * number and trailing NUL byte. The second leaves room for at
4649 * least "...". Thus the apparently 'magic' numbers chosen for
4657 * Called when it is conceptually a ULP that would sent the packet
4658 * e.g., port unreachable and protocol unreachable. Check that the packet
4659 * would have passed the IPsec global policy before sending the error.
4661 * Send an ICMP error after patching up the packet appropriately.
4662 * Uses ip_drop_input and bumps the appropriate MIB.
4665 ip_fanout_send_icmp_v4(mblk_t
*mp
, uint_t icmp_type
, uint_t icmp_code
,
4666 ip_recv_attr_t
*ira
)
4670 ill_t
*ill
= ira
->ira_ill
;
4671 ip_stack_t
*ipst
= ill
->ill_ipst
;
4672 netstack_t
*ns
= ipst
->ips_netstack
;
4673 ipsec_stack_t
*ipss
= ns
->netstack_ipsec
;
4675 secure
= ira
->ira_flags
& IRAF_IPSEC_SECURE
;
4678 * We are generating an icmp error for some inbound packet.
4679 * Called from all ip_fanout_(udp, tcp, proto) functions.
4680 * Before we generate an error, check with global policy
4681 * to see whether this is allowed to enter the system. As
4682 * there is no "conn", we are checking with global policy.
4684 ipha
= (ipha_t
*)mp
->b_rptr
;
4685 if (secure
|| ipss
->ipsec_inbound_v4_policy_present
) {
4686 mp
= ipsec_check_global_policy(mp
, NULL
, ipha
, NULL
, ira
, ns
);
4691 /* We never send errors for protocols that we do implement */
4692 if (ira
->ira_protocol
== IPPROTO_ICMP
||
4693 ira
->ira_protocol
== IPPROTO_IGMP
) {
4694 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
4695 ip_drop_input("ip_fanout_send_icmp_v4", mp
, ill
);
4700 * Have to correct checksum since
4701 * the packet might have been
4702 * fragmented and the reassembly code in ip_rput
4703 * does not restore the IP checksum.
4705 ipha
->ipha_hdr_checksum
= 0;
4706 ipha
->ipha_hdr_checksum
= ip_csum_hdr(ipha
);
4708 switch (icmp_type
) {
4709 case ICMP_DEST_UNREACHABLE
:
4710 switch (icmp_code
) {
4711 case ICMP_PROTOCOL_UNREACHABLE
:
4712 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInUnknownProtos
);
4713 ip_drop_input("ipIfStatsInUnknownProtos", mp
, ill
);
4715 case ICMP_PORT_UNREACHABLE
:
4716 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsNoPorts
);
4717 ip_drop_input("ipIfStatsNoPorts", mp
, ill
);
4721 icmp_unreachable(mp
, icmp_code
, ira
);
4725 panic("ip_fanout_send_icmp_v4: wrong type");
4735 * Used to send an ICMP error message when a packet is received for
4736 * a protocol that is not supported. The mblk passed as argument
4737 * is consumed by this function.
4740 ip_proto_not_sup(mblk_t
*mp
, ip_recv_attr_t
*ira
)
4744 ipha
= (ipha_t
*)mp
->b_rptr
;
4745 if (ira
->ira_flags
& IRAF_IS_IPV4
) {
4746 ASSERT(IPH_HDR_VERSION(ipha
) == IP_VERSION
);
4747 ip_fanout_send_icmp_v4(mp
, ICMP_DEST_UNREACHABLE
,
4748 ICMP_PROTOCOL_UNREACHABLE
, ira
);
4750 ASSERT(IPH_HDR_VERSION(ipha
) == IPV6_VERSION
);
4751 ip_fanout_send_icmp_v6(mp
, ICMP6_PARAM_PROB
,
4752 ICMP6_PARAMPROB_NEXTHEADER
, ira
);
4757 * Deliver a rawip packet to the given conn, possibly applying ipsec policy.
4758 * Handles IPv4 and IPv6.
4759 * We are responsible for disposing of mp, such as by freemsg() or putnext()
4760 * Caller is responsible for dropping references to the conn.
4763 ip_fanout_proto_conn(conn_t
*connp
, mblk_t
*mp
, ipha_t
*ipha
, ip6_t
*ip6h
,
4764 ip_recv_attr_t
*ira
)
4766 ill_t
*ill
= ira
->ira_ill
;
4767 ip_stack_t
*ipst
= ill
->ill_ipst
;
4768 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
4770 uint_t protocol
= ira
->ira_protocol
;
4771 iaflags_t iraflags
= ira
->ira_flags
;
4774 secure
= iraflags
& IRAF_IPSEC_SECURE
;
4776 rq
= connp
->conn_rq
;
4777 if (IPCL_IS_NONSTR(connp
) ? connp
->conn_flow_cntrld
: !canputnext(rq
)) {
4779 case IPPROTO_ICMPV6
:
4780 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInOverflows
);
4783 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInOverflows
);
4786 BUMP_MIB(ill
->ill_ip_mib
, rawipIfStatsInOverflows
);
4793 ASSERT(!(IPCL_IS_IPTUN(connp
)));
4795 if (((iraflags
& IRAF_IS_IPV4
) ?
4796 CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) :
4797 CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
)) ||
4799 mp
= ipsec_check_inbound_policy(mp
, connp
, ipha
,
4802 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
4803 /* Note that mp is NULL */
4804 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
4809 if (iraflags
& IRAF_ICMP_ERROR
) {
4810 (connp
->conn_recvicmp
)(connp
, mp
, NULL
, ira
);
4812 ill_t
*rill
= ira
->ira_rill
;
4814 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
4815 ira
->ira_ill
= ira
->ira_rill
= NULL
;
4816 /* Send it upstream */
4817 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
4819 ira
->ira_rill
= rill
;
4824 * Handle protocols with which IP is less intimate. There
4825 * can be more than one stream bound to a particular
4826 * protocol. When this is the case, normally each one gets a copy
4827 * of any incoming packets.
4831 * Don't allow a secure packet going up a non-secure connection.
4832 * We don't allow this because
4834 * 1) Reply might go out in clear which will be dropped at
4836 * 2) If the reply goes out in clear it will give the
4837 * adversary enough information for getting the key in
4838 * most of the cases.
4840 * Moreover getting a secure packet when we expect clear
4841 * implies that SA's were added without checking for
4842 * policy on both ends. This should not happen once ISAKMP
4843 * is used to negotiate SAs as SAs will be added only after
4844 * verifying the policy.
4847 * Earlier in ip_input on a system with multiple shared-IP zones we
4848 * duplicate the multicast and broadcast packets and send them up
4849 * with each explicit zoneid that exists on that ill.
4850 * This means that here we can match the zoneid with SO_ALLZONES being special.
4853 ip_fanout_proto_v4(mblk_t
*mp
, ipha_t
*ipha
, ip_recv_attr_t
*ira
)
4857 conn_t
*connp
, *first_connp
, *next_connp
;
4859 ill_t
*ill
= ira
->ira_ill
;
4860 ip_stack_t
*ipst
= ill
->ill_ipst
;
4862 laddr
= ipha
->ipha_dst
;
4864 connfp
= &ipst
->ips_ipcl_proto_fanout_v4
[ira
->ira_protocol
];
4865 mutex_enter(&connfp
->connf_lock
);
4866 connp
= connfp
->connf_head
;
4868 if (connp
== NULL
) {
4870 * No one bound to these addresses. Is
4871 * there a client that wants all
4872 * unclaimed datagrams?
4874 mutex_exit(&connfp
->connf_lock
);
4875 ip_fanout_send_icmp_v4(mp
, ICMP_DEST_UNREACHABLE
,
4876 ICMP_PROTOCOL_UNREACHABLE
, ira
);
4880 ASSERT(IPCL_IS_NONSTR(connp
) || connp
->conn_rq
!= NULL
);
4882 CONN_INC_REF(connp
);
4883 first_connp
= connp
;
4884 connp
= connp
->conn_next
;
4887 while (connp
!= NULL
) {
4888 /* Note: IPCL_PROTO_MATCH includes conn_wantpacket */
4889 if (IPCL_PROTO_MATCH(connp
, ira
, ipha
))
4891 connp
= connp
->conn_next
;
4894 if (connp
== NULL
) {
4895 /* No more interested clients */
4896 connp
= first_connp
;
4899 if (((mp1
= dupmsg(mp
)) == NULL
) &&
4900 ((mp1
= copymsg(mp
)) == NULL
)) {
4901 /* Memory allocation failed */
4902 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
4903 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
4904 connp
= first_connp
;
4908 CONN_INC_REF(connp
);
4909 mutex_exit(&connfp
->connf_lock
);
4911 ip_fanout_proto_conn(connp
, mp1
, (ipha_t
*)mp1
->b_rptr
, NULL
,
4914 mutex_enter(&connfp
->connf_lock
);
4915 /* Follow the next pointer before releasing the conn. */
4916 next_connp
= connp
->conn_next
;
4917 CONN_DEC_REF(connp
);
4921 /* Last one. Send it upstream. */
4922 mutex_exit(&connfp
->connf_lock
);
4924 ip_fanout_proto_conn(connp
, mp
, ipha
, NULL
, ira
);
4926 CONN_DEC_REF(connp
);
4930 * If we have a IPsec NAT-Traversal packet, strip the zero-SPI or
4931 * pass it along to ESP if the SPI is non-zero. Returns the mblk if the mblk
4934 * One of three things can happen, all of which affect the passed-in mblk:
4936 * 1.) The packet is stock UDP and gets its zero-SPI stripped. Return mblk..
4938 * 2.) The packet is ESP-in-UDP, gets transformed into an equivalent
4939 * ESP packet, and is passed along to ESP for consumption. Return NULL.
4941 * 3.) The packet is an ESP-in-UDP Keepalive. Drop it and return NULL.
4944 zero_spi_check(mblk_t
*mp
, ip_recv_attr_t
*ira
)
4946 int shift
, plen
, iph_len
;
4952 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
4953 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
4955 ipha
= (ipha_t
*)mp
->b_rptr
;
4956 iph_len
= ira
->ira_ip_hdr_length
;
4957 plen
= ira
->ira_pktlen
;
4959 if (plen
- iph_len
- sizeof (udpha_t
) < sizeof (uint32_t)) {
4961 * Most likely a keepalive for the benefit of an intervening
4962 * NAT. These aren't for us, per se, so drop it.
4964 * RFC 3947/8 doesn't say for sure what to do for 2-3
4965 * byte packets (keepalives are 1-byte), but we'll drop them
4968 ip_drop_packet(mp
, B_TRUE
, ira
->ira_ill
,
4969 DROPPER(ipss
, ipds_esp_nat_t_ka
), &ipss
->ipsec_dropper
);
4973 if (MBLKL(mp
) < iph_len
+ sizeof (udpha_t
) + sizeof (*spi
)) {
4974 /* might as well pull it all up - it might be ESP. */
4975 if (!pullupmsg(mp
, -1)) {
4976 ip_drop_packet(mp
, B_TRUE
, ira
->ira_ill
,
4977 DROPPER(ipss
, ipds_esp_nomem
),
4978 &ipss
->ipsec_dropper
);
4982 ipha
= (ipha_t
*)mp
->b_rptr
;
4984 spi
= (uint32_t *)(mp
->b_rptr
+ iph_len
+ sizeof (udpha_t
));
4986 /* UDP packet - remove 0-spi. */
4987 shift
= sizeof (uint32_t);
4989 /* ESP-in-UDP packet - reduce to ESP. */
4990 ipha
->ipha_protocol
= IPPROTO_ESP
;
4991 shift
= sizeof (udpha_t
);
4995 ira
->ira_pktlen
= (plen
- shift
);
4996 ipha
->ipha_length
= htons(ira
->ira_pktlen
);
4997 ipha
->ipha_hdr_checksum
= 0;
5000 mp
->b_rptr
+= shift
;
5002 udpha
= (udpha_t
*)(orptr
+ iph_len
);
5004 ASSERT((uint8_t *)ipha
== orptr
);
5005 udpha
->uha_length
= htons(plen
- shift
- iph_len
);
5006 iph_len
+= sizeof (udpha_t
); /* For the call to ovbcopy(). */
5009 esp_ports
= *((uint32_t *)udpha
);
5010 ASSERT(esp_ports
!= 0);
5012 ovbcopy(orptr
, orptr
+ shift
, iph_len
);
5013 if (esp_ports
!= 0) /* Punt up for ESP processing. */ {
5014 ipha
= (ipha_t
*)(orptr
+ shift
);
5016 ira
->ira_flags
|= IRAF_ESP_UDP_PORTS
;
5017 ira
->ira_esp_udp_ports
= esp_ports
;
5018 ip_fanout_v4(mp
, ipha
, ira
);
5025 * Deliver a udp packet to the given conn, possibly applying ipsec policy.
5026 * Handles IPv4 and IPv6.
5027 * We are responsible for disposing of mp, such as by freemsg() or putnext()
5028 * Caller is responsible for dropping references to the conn.
5031 ip_fanout_udp_conn(conn_t
*connp
, mblk_t
*mp
, ipha_t
*ipha
, ip6_t
*ip6h
,
5032 ip_recv_attr_t
*ira
)
5034 ill_t
*ill
= ira
->ira_ill
;
5035 ip_stack_t
*ipst
= ill
->ill_ipst
;
5036 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
5038 iaflags_t iraflags
= ira
->ira_flags
;
5040 secure
= iraflags
& IRAF_IPSEC_SECURE
;
5042 if (IPCL_IS_NONSTR(connp
) ? connp
->conn_flow_cntrld
:
5043 !canputnext(connp
->conn_rq
)) {
5044 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsInOverflows
);
5049 if (((iraflags
& IRAF_IS_IPV4
) ?
5050 CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) :
5051 CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
)) ||
5053 mp
= ipsec_check_inbound_policy(mp
, connp
, ipha
,
5056 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
5057 /* Note that mp is NULL */
5058 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
5064 * Since this code is not used for UDP unicast we don't need a NAT_T
5065 * check. Only ip_fanout_v4 has that check.
5067 if (ira
->ira_flags
& IRAF_ICMP_ERROR
) {
5068 (connp
->conn_recvicmp
)(connp
, mp
, NULL
, ira
);
5070 ill_t
*rill
= ira
->ira_rill
;
5072 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
5073 ira
->ira_ill
= ira
->ira_rill
= NULL
;
5074 /* Send it upstream */
5075 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
5077 ira
->ira_rill
= rill
;
5082 * Fanout for UDP packets that are multicast or broadcast, and ICMP errors.
5083 * (Unicast fanout is handled in ip_input_v4.)
5085 * If SO_REUSEADDR is set all multicast and broadcast packets
5086 * will be delivered to all conns bound to the same port.
5088 * If there is at least one matching AF_INET receiver, then we will
5089 * ignore any AF_INET6 receivers.
5090 * In the special case where an AF_INET socket binds to 0.0.0.0/<port> and an
5091 * AF_INET6 socket binds to ::/<port>, only the AF_INET socket receives the IPv4
5095 * Earlier in ip_input on a system with multiple shared-IP zones we
5096 * duplicate the multicast and broadcast packets and send them up
5097 * with each explicit zoneid that exists on that ill.
5098 * This means that here we can match the zoneid with SO_ALLZONES being special.
5101 ip_fanout_udp_multi_v4(mblk_t
*mp
, ipha_t
*ipha
, uint16_t lport
, uint16_t fport
,
5102 ip_recv_attr_t
*ira
)
5109 ill_t
*ill
= ira
->ira_ill
;
5110 ip_stack_t
*ipst
= ill
->ill_ipst
;
5112 ASSERT(ira
->ira_flags
& (IRAF_MULTIBROADCAST
|IRAF_ICMP_ERROR
));
5114 laddr
= ipha
->ipha_dst
;
5115 faddr
= ipha
->ipha_src
;
5117 connfp
= &ipst
->ips_ipcl_udp_fanout
[IPCL_UDP_HASH(lport
, ipst
)];
5118 mutex_enter(&connfp
->connf_lock
);
5119 connp
= connfp
->connf_head
;
5122 * If SO_REUSEADDR has been set on the first we send the
5123 * packet to all clients that have joined the group and
5126 while (connp
!= NULL
) {
5127 if ((IPCL_UDP_MATCH(connp
, lport
, laddr
, fport
, faddr
)) &&
5128 conn_wantpacket(connp
, ira
, ipha
))
5130 connp
= connp
->conn_next
;
5136 CONN_INC_REF(connp
);
5138 if (connp
->conn_reuseaddr
) {
5139 conn_t
*first_connp
= connp
;
5143 connp
= connp
->conn_next
;
5145 while (connp
!= NULL
) {
5146 if (IPCL_UDP_MATCH(connp
, lport
, laddr
,
5148 conn_wantpacket(connp
, ira
, ipha
))
5150 connp
= connp
->conn_next
;
5152 if (connp
== NULL
) {
5153 /* No more interested clients */
5154 connp
= first_connp
;
5157 if (((mp1
= dupmsg(mp
)) == NULL
) &&
5158 ((mp1
= copymsg(mp
)) == NULL
)) {
5159 /* Memory allocation failed */
5160 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
5161 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
5162 connp
= first_connp
;
5165 CONN_INC_REF(connp
);
5166 mutex_exit(&connfp
->connf_lock
);
5168 IP_STAT(ipst
, ip_udp_fanmb
);
5169 ip_fanout_udp_conn(connp
, mp1
, (ipha_t
*)mp1
->b_rptr
,
5171 mutex_enter(&connfp
->connf_lock
);
5172 /* Follow the next pointer before releasing the conn */
5173 next_connp
= connp
->conn_next
;
5174 CONN_DEC_REF(connp
);
5179 /* Last one. Send it upstream. */
5180 mutex_exit(&connfp
->connf_lock
);
5181 IP_STAT(ipst
, ip_udp_fanmb
);
5182 ip_fanout_udp_conn(connp
, mp
, ipha
, NULL
, ira
);
5183 CONN_DEC_REF(connp
);
5187 mutex_exit(&connfp
->connf_lock
);
5189 * IPv6 endpoints bound to multicast IPv4-mapped addresses
5190 * have already been matched above, since they live in the IPv4
5191 * fanout tables. This implies we only need to
5192 * check for IPv6 in6addr_any endpoints here.
5193 * Thus we compare using ipv6_all_zeros instead of the destination
5194 * address, except for the multicast group membership lookup which
5195 * uses the IPv4 destination.
5197 IN6_IPADDR_TO_V4MAPPED(ipha
->ipha_src
, &v6faddr
);
5198 connfp
= &ipst
->ips_ipcl_udp_fanout
[IPCL_UDP_HASH(lport
, ipst
)];
5199 mutex_enter(&connfp
->connf_lock
);
5200 connp
= connfp
->connf_head
;
5202 * IPv4 multicast packet being delivered to an AF_INET6
5203 * in6addr_any endpoint.
5204 * Need to check conn_wantpacket(). Note that we use conn_wantpacket()
5205 * and not conn_wantpacket_v6() since any multicast membership is
5206 * for an IPv4-mapped multicast address.
5208 while (connp
!= NULL
) {
5209 if (IPCL_UDP_MATCH_V6(connp
, lport
, ipv6_all_zeros
,
5211 conn_wantpacket(connp
, ira
, ipha
))
5213 connp
= connp
->conn_next
;
5216 if (connp
== NULL
) {
5218 * No one bound to this port. Is
5219 * there a client that wants all
5220 * unclaimed datagrams?
5222 mutex_exit(&connfp
->connf_lock
);
5224 if (ipst
->ips_ipcl_proto_fanout_v4
[IPPROTO_UDP
].connf_head
!=
5226 ASSERT(ira
->ira_protocol
== IPPROTO_UDP
);
5227 ip_fanout_proto_v4(mp
, ipha
, ira
);
5230 * We used to attempt to send an icmp error here, but
5231 * since this is known to be a multicast packet
5232 * and we don't send icmp errors in response to
5233 * multicast, just drop the packet and give up sooner.
5235 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsNoPorts
);
5240 CONN_INC_REF(connp
);
5241 ASSERT(IPCL_IS_NONSTR(connp
) || connp
->conn_rq
!= NULL
);
5244 * If SO_REUSEADDR has been set on the first we send the
5245 * packet to all clients that have joined the group and
5248 if (connp
->conn_reuseaddr
) {
5249 conn_t
*first_connp
= connp
;
5253 connp
= connp
->conn_next
;
5255 while (connp
!= NULL
) {
5256 if (IPCL_UDP_MATCH_V6(connp
, lport
,
5257 ipv6_all_zeros
, fport
, v6faddr
) &&
5258 conn_wantpacket(connp
, ira
, ipha
))
5260 connp
= connp
->conn_next
;
5262 if (connp
== NULL
) {
5263 /* No more interested clients */
5264 connp
= first_connp
;
5267 if (((mp1
= dupmsg(mp
)) == NULL
) &&
5268 ((mp1
= copymsg(mp
)) == NULL
)) {
5269 /* Memory allocation failed */
5270 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
5271 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
5272 connp
= first_connp
;
5275 CONN_INC_REF(connp
);
5276 mutex_exit(&connfp
->connf_lock
);
5278 IP_STAT(ipst
, ip_udp_fanmb
);
5279 ip_fanout_udp_conn(connp
, mp1
, (ipha_t
*)mp1
->b_rptr
,
5281 mutex_enter(&connfp
->connf_lock
);
5282 /* Follow the next pointer before releasing the conn */
5283 next_connp
= connp
->conn_next
;
5284 CONN_DEC_REF(connp
);
5289 /* Last one. Send it upstream. */
5290 mutex_exit(&connfp
->connf_lock
);
5291 IP_STAT(ipst
, ip_udp_fanmb
);
5292 ip_fanout_udp_conn(connp
, mp
, ipha
, NULL
, ira
);
5293 CONN_DEC_REF(connp
);
5297 * Split an incoming packet's IPv4 options into options.
5298 * If 'allocate' is set it does memory allocation for the ip_pkt_t, including
5299 * clearing out any leftover options.
5300 * Otherwise it just makes ipp point into the packet.
5302 * Returns zero if ok; ENOMEM if the buffer couldn't be allocated.
5305 ip_find_hdr_v4(ipha_t
*ipha
, ip_pkt_t
*ipp
, boolean_t allocate
)
5312 ipp
->ipp_fields
|= IPPF_HOPLIMIT
| IPPF_TCLASS
| IPPF_ADDR
;
5313 ipp
->ipp_hoplimit
= ipha
->ipha_ttl
;
5314 ipp
->ipp_type_of_service
= ipha
->ipha_type_of_service
;
5315 IN6_IPADDR_TO_V4MAPPED(ipha
->ipha_dst
, &ipp
->ipp_addr
);
5318 * Get length (in 4 byte octets) of IP header options.
5320 totallen
= ipha
->ipha_version_and_hdr_length
-
5321 (uint8_t)((IP_VERSION
<< 4) + IP_SIMPLE_HDR_LENGTH_IN_WORDS
);
5323 if (totallen
== 0) {
5327 /* Clear out anything from a previous packet */
5328 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
5329 kmem_free(ipp
->ipp_ipv4_options
,
5330 ipp
->ipp_ipv4_options_len
);
5331 ipp
->ipp_ipv4_options
= NULL
;
5332 ipp
->ipp_ipv4_options_len
= 0;
5333 ipp
->ipp_fields
&= ~IPPF_IPV4_OPTIONS
;
5339 opt
= (uchar_t
*)&ipha
[1];
5343 if (totallen
!= 0) {
5344 ipp
->ipp_ipv4_options
= opt
;
5345 ipp
->ipp_ipv4_options_len
= totallen
;
5346 ipp
->ipp_fields
|= IPPF_IPV4_OPTIONS
;
5350 /* Just copy all of options */
5351 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
5352 if (totallen
== ipp
->ipp_ipv4_options_len
) {
5353 bcopy(opt
, ipp
->ipp_ipv4_options
, totallen
);
5356 kmem_free(ipp
->ipp_ipv4_options
,
5357 ipp
->ipp_ipv4_options_len
);
5358 ipp
->ipp_ipv4_options
= NULL
;
5359 ipp
->ipp_ipv4_options_len
= 0;
5360 ipp
->ipp_fields
&= ~IPPF_IPV4_OPTIONS
;
5365 ipp
->ipp_ipv4_options
= kmem_alloc(totallen
, KM_NOSLEEP
);
5366 if (ipp
->ipp_ipv4_options
== NULL
)
5368 ipp
->ipp_ipv4_options_len
= totallen
;
5369 ipp
->ipp_fields
|= IPPF_IPV4_OPTIONS
;
5370 bcopy(opt
, ipp
->ipp_ipv4_options
, totallen
);
5373 totallen
= ipha
->ipha_version_and_hdr_length
-
5374 (uint8_t)((IP_VERSION
<< 4) + IP_SIMPLE_HDR_LENGTH_IN_WORDS
);
5376 opt
= (uchar_t
*)&ipha
[1];
5381 * Efficient versions of lookup for an IRE when we only
5382 * match the address.
5383 * For RTF_REJECT or BLACKHOLE we return IRE_NOROUTE.
5384 * Does not handle multicast addresses.
5387 ip_type_v4(ipaddr_t addr
, ip_stack_t
*ipst
)
5392 ire
= ire_ftable_lookup_simple_v4(addr
, 0, ipst
, NULL
);
5393 ASSERT(ire
!= NULL
);
5394 if (ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))
5395 result
= IRE_NOROUTE
;
5397 result
= ire
->ire_type
;
5403 * Efficient versions of lookup for an IRE when we only
5404 * match the address.
5405 * For RTF_REJECT or BLACKHOLE we return IRE_NOROUTE.
5406 * Does not handle multicast addresses.
5409 ip_type_v6(const in6_addr_t
*addr
, ip_stack_t
*ipst
)
5414 ire
= ire_ftable_lookup_simple_v6(addr
, 0, ipst
, NULL
);
5415 ASSERT(ire
!= NULL
);
5416 if (ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))
5417 result
= IRE_NOROUTE
;
5419 result
= ire
->ire_type
;
5425 * Nobody should be sending
5426 * packets up this stream
5429 ip_lrput(queue_t
*q
, mblk_t
*mp
)
5431 switch (mp
->b_datap
->db_type
) {
5434 if (*mp
->b_rptr
& FLUSHW
) {
5435 *mp
->b_rptr
&= ~FLUSHR
;
5445 /* Nobody should be sending packets down this stream */
5448 ip_lwput(queue_t
*q
, mblk_t
*mp
)
5455 * Move the first hop in any source route to ipha_dst and remove that part of
5456 * the source route. Called by other protocols. Errors in option formatting
5457 * are ignored - will be handled by ip_output_options. Return the final
5458 * destination (either ipha_dst or the last entry in a source route.)
5461 ip_massage_options(ipha_t
*ipha
, netstack_t
*ns
)
5469 ip_stack_t
*ipst
= ns
->netstack_ip
;
5471 ip2dbg(("ip_massage_options\n"));
5472 dst
= ipha
->ipha_dst
;
5473 for (optval
= ipoptp_first(&opts
, ipha
);
5474 optval
!= IPOPT_EOL
;
5475 optval
= ipoptp_next(&opts
)) {
5476 opt
= opts
.ipoptp_cur
;
5481 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
5482 ip1dbg(("ip_massage_options: bad src route\n"));
5485 optlen
= opts
.ipoptp_len
;
5486 off
= opt
[IPOPT_OFFSET
];
5489 if (optlen
< IP_ADDR_LEN
||
5490 off
> optlen
- IP_ADDR_LEN
) {
5491 /* End of source route */
5492 ip1dbg(("ip_massage_options: end of SR\n"));
5495 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
5496 ip1dbg(("ip_massage_options: next hop 0x%x\n",
5499 * Check if our address is present more than
5500 * once as consecutive hops in source route.
5501 * XXX verify per-interface ip_forwarding
5504 if (ip_type_v4(dst
, ipst
) == IRE_LOCAL
) {
5508 if (dst
== htonl(INADDR_LOOPBACK
)) {
5509 ip1dbg(("ip_massage_options: loopback addr in "
5510 "source route!\n"));
5514 * Update ipha_dst to be the first hop and remove the
5515 * first hop from the source route (by overwriting
5516 * part of the option with NOP options).
5518 ipha
->ipha_dst
= dst
;
5519 /* Put the last entry in dst */
5520 off
= ((optlen
- IP_ADDR_LEN
- 3) & ~(IP_ADDR_LEN
-1)) +
5522 bcopy(&opt
[off
], &dst
, IP_ADDR_LEN
);
5524 ip1dbg(("ip_massage_options: last hop 0x%x\n",
5526 /* Move down and overwrite */
5527 opt
[IP_ADDR_LEN
] = opt
[0];
5528 opt
[IP_ADDR_LEN
+1] = opt
[IPOPT_OLEN
] - IP_ADDR_LEN
;
5529 opt
[IP_ADDR_LEN
+2] = opt
[IPOPT_OFFSET
];
5530 for (i
= 0; i
< IP_ADDR_LEN
; i
++)
5539 * Return the network mask
5540 * associated with the specified address.
5543 ip_net_mask(ipaddr_t addr
)
5545 uchar_t
*up
= (uchar_t
*)&addr
;
5547 uchar_t
*maskp
= (uchar_t
*)&mask
;
5549 #if defined(__i386) || defined(__amd64)
5550 #define TOTALLY_BRAIN_DAMAGED_C_COMPILER
5552 #ifdef TOTALLY_BRAIN_DAMAGED_C_COMPILER
5553 maskp
[0] = maskp
[1] = maskp
[2] = maskp
[3] = 0;
5560 /* We assume Class E default netmask to be 32 */
5562 return (0xffffffffU
);
5567 if ((up
[0] & 0x80) == 0)
5571 if ((up
[0] & 0xC0) == 0x80)
5575 if ((up
[0] & 0xE0) == 0xC0)
5578 /* Otherwise return no mask */
5579 return ((ipaddr_t
)0);
5582 /* Name/Value Table Lookup Routine */
5584 ip_nv_lookup(nv_t
*nv
, int value
)
5588 for (; nv
->nv_name
; nv
++) {
5589 if (nv
->nv_value
== value
)
5590 return (nv
->nv_name
);
5596 ip_wait_for_info_ack(ill_t
*ill
)
5600 mutex_enter(&ill
->ill_lock
);
5601 while (ill
->ill_state_flags
& ILL_LL_SUBNET_PENDING
) {
5603 * Return value of 0 indicates a pending signal.
5605 err
= cv_wait_sig(&ill
->ill_cv
, &ill
->ill_lock
);
5607 mutex_exit(&ill
->ill_lock
);
5611 mutex_exit(&ill
->ill_lock
);
5613 * ip_rput_other could have set an error in ill_error on
5614 * receipt of M_ERROR.
5616 return (ill
->ill_error
);
5620 * This is a module open, i.e. this is a control stream for access
5621 * to a DLPI device. We allocate an ill_t as the instance data in
5625 ip_modopen(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
)
5634 * Prevent unprivileged processes from pushing IP so that
5635 * they can't send raw IP.
5637 if (secpolicy_net_rawaccess(credp
) != 0)
5640 ns
= netstack_find_by_cred(credp
);
5642 ipst
= ns
->netstack_ip
;
5643 ASSERT(ipst
!= NULL
);
5646 * For exclusive stacks we set the zoneid to zero
5647 * to make IP operate as if in the global zone.
5649 if (ipst
->ips_netstack
->netstack_stackid
!= GLOBAL_NETSTACKID
)
5650 zoneid
= GLOBAL_ZONEID
;
5652 zoneid
= crgetzoneid(credp
);
5654 ill
= (ill_t
*)mi_open_alloc_sleep(sizeof (ill_t
));
5655 q
->q_ptr
= WR(q
)->q_ptr
= ill
;
5656 ill
->ill_ipst
= ipst
;
5657 ill
->ill_zoneid
= zoneid
;
5660 * ill_init initializes the ill fields and then sends down
5661 * down a DL_INFO_REQ after calling qprocson.
5663 err
= ill_init(q
, ill
);
5667 netstack_rele(ipst
->ips_netstack
);
5669 WR(q
)->q_ptr
= NULL
;
5674 * Wait for the DL_INFO_ACK if a DL_INFO_REQ was sent.
5676 * ill_init initializes the ipsq marking this thread as
5679 ipsq_exit(ill
->ill_phyint
->phyint_ipsq
);
5680 err
= ip_wait_for_info_ack(ill
);
5682 ill
->ill_credp
= credp
;
5688 mutex_enter(&ipst
->ips_ip_mi_lock
);
5689 err
= mi_open_link(&ipst
->ips_ip_g_head
, (IDP
)q
->q_ptr
, devp
, flag
,
5691 mutex_exit(&ipst
->ips_ip_mi_lock
);
5694 (void) ip_close(q
, 0, credp
);
5700 /* For /dev/ip aka AF_INET open */
5702 ip_openv4(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
)
5704 return (ip_open(q
, devp
, flag
, sflag
, credp
, B_FALSE
));
5707 /* For /dev/ip6 aka AF_INET6 open */
5709 ip_openv6(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
)
5711 return (ip_open(q
, devp
, flag
, sflag
, credp
, B_TRUE
));
5714 /* IP open routine. */
5716 ip_open(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
,
5726 if (q
->q_ptr
!= NULL
)
5729 if (sflag
& MODOPEN
) {
5730 /* This is a module open */
5731 return (ip_modopen(q
, devp
, flag
, sflag
, credp
));
5734 if ((flag
& ~(FKLYR
)) == IP_HELPER_STR
) {
5736 * Non streams based socket looking for a stream
5739 return (ip_helper_stream_setup(q
, devp
, flag
, sflag
,
5743 ns
= netstack_find_by_cred(credp
);
5745 ipst
= ns
->netstack_ip
;
5746 ASSERT(ipst
!= NULL
);
5749 * For exclusive stacks we set the zoneid to zero
5750 * to make IP operate as if in the global zone.
5752 if (ipst
->ips_netstack
->netstack_stackid
!= GLOBAL_NETSTACKID
)
5753 zoneid
= GLOBAL_ZONEID
;
5755 zoneid
= crgetzoneid(credp
);
5758 * We are opening as a device. This is an IP client stream, and we
5759 * allocate an conn_t as the instance data.
5761 connp
= ipcl_conn_create(IPCL_IPCCONN
, KM_SLEEP
, ipst
->ips_netstack
);
5764 * ipcl_conn_create did a netstack_hold. Undo the hold that was
5765 * done by netstack_find_by_cred()
5767 netstack_rele(ipst
->ips_netstack
);
5769 connp
->conn_ixa
->ixa_flags
|= IXAF_MULTICAST_LOOP
| IXAF_SET_ULP_CKSUM
;
5770 /* conn_allzones can not be set this early, hence no IPCL_ZONEID */
5771 connp
->conn_ixa
->ixa_zoneid
= zoneid
;
5772 connp
->conn_zoneid
= zoneid
;
5775 q
->q_ptr
= WR(q
)->q_ptr
= connp
;
5777 /* Minor tells us which /dev entry was opened */
5779 connp
->conn_family
= AF_INET6
;
5780 connp
->conn_ipversion
= IPV6_VERSION
;
5781 connp
->conn_ixa
->ixa_flags
&= ~IXAF_IS_IPV4
;
5782 connp
->conn_ixa
->ixa_src_preferences
= IPV6_PREFER_SRC_DEFAULT
;
5784 connp
->conn_family
= AF_INET
;
5785 connp
->conn_ipversion
= IPV4_VERSION
;
5786 connp
->conn_ixa
->ixa_flags
|= IXAF_IS_IPV4
;
5789 if ((ip_minor_arena_la
!= NULL
) && (flag
& SO_SOCKSTR
) &&
5790 ((connp
->conn_dev
= inet_minor_alloc(ip_minor_arena_la
)) != 0)) {
5791 connp
->conn_minor_arena
= ip_minor_arena_la
;
5794 * Either minor numbers in the large arena were exhausted
5795 * or a non socket application is doing the open.
5796 * Try to allocate from the small arena.
5798 if ((connp
->conn_dev
=
5799 inet_minor_alloc(ip_minor_arena_sa
)) == 0) {
5800 /* CONN_DEC_REF takes care of netstack_rele() */
5801 q
->q_ptr
= WR(q
)->q_ptr
= NULL
;
5802 CONN_DEC_REF(connp
);
5805 connp
->conn_minor_arena
= ip_minor_arena_sa
;
5808 maj
= getemajor(*devp
);
5809 *devp
= makedevice(maj
, (minor_t
)connp
->conn_dev
);
5812 * connp->conn_cred is crfree()ed in ipcl_conn_destroy()
5814 connp
->conn_cred
= credp
;
5815 connp
->conn_cpid
= curproc
->p_pid
;
5816 /* Cache things in ixa without an extra refhold */
5817 ASSERT(!(connp
->conn_ixa
->ixa_free_flags
& IXA_FREE_CRED
));
5818 connp
->conn_ixa
->ixa_cred
= connp
->conn_cred
;
5819 connp
->conn_ixa
->ixa_cpid
= connp
->conn_cpid
;
5822 * Handle IP_IOC_RTS_REQUEST and other ioctls which use conn_recv
5824 connp
->conn_recv
= ip_conn_input
;
5825 connp
->conn_recvicmp
= ip_conn_input_icmp
;
5827 crhold(connp
->conn_cred
);
5829 connp
->conn_zone_is_global
= (crgetzoneid(credp
) == GLOBAL_ZONEID
);
5832 connp
->conn_wq
= WR(q
);
5834 /* Non-zero default values */
5835 connp
->conn_ixa
->ixa_flags
|= IXAF_MULTICAST_LOOP
;
5838 * Make the conn globally visible to walkers
5840 ASSERT(connp
->conn_ref
== 1);
5841 mutex_enter(&connp
->conn_lock
);
5842 connp
->conn_state_flags
&= ~CONN_INCIPIENT
;
5843 mutex_exit(&connp
->conn_lock
);
5851 * Set IPsec policy from an ipsec_req_t. If the req is not "zero" and valid,
5852 * all of them are copied to the conn_t. If the req is "zero", the policy is
5853 * zeroed out. A "zero" policy has zero ipsr_{ah,req,self_encap}_req
5855 * We keep only the latest setting of the policy and thus policy setting
5856 * is not incremental/cumulative.
5858 * Requests to set policies with multiple alternative actions will
5859 * go through a different API.
5862 ipsec_set_req(cred_t
*cr
, conn_t
*connp
, ipsec_req_t
*req
)
5867 ipsec_act_t
*actp
= NULL
;
5869 ipsec_policy_head_t
*ph
;
5870 boolean_t is_pol_reset
, is_pol_inserted
= B_FALSE
;
5872 netstack_t
*ns
= connp
->conn_netstack
;
5873 ip_stack_t
*ipst
= ns
->netstack_ip
;
5874 ipsec_stack_t
*ipss
= ns
->netstack_ipsec
;
5876 #define REQ_MASK (IPSEC_PREF_REQUIRED|IPSEC_PREF_NEVER)
5879 * The IP_SEC_OPT option does not allow variable length parameters,
5880 * hence a request cannot be NULL.
5885 ah_req
= req
->ipsr_ah_req
;
5886 esp_req
= req
->ipsr_esp_req
;
5887 se_req
= req
->ipsr_self_encap_req
;
5889 /* Don't allow setting self-encap without one or more of AH/ESP. */
5890 if (se_req
!= 0 && esp_req
== 0 && ah_req
== 0)
5894 * Are we dealing with a request to reset the policy (i.e.
5897 is_pol_reset
= ((ah_req
& REQ_MASK
) == 0 &&
5898 (esp_req
& REQ_MASK
) == 0 &&
5899 (se_req
& REQ_MASK
) == 0);
5901 if (!is_pol_reset
) {
5903 * If we couldn't load IPsec, fail with "protocol
5905 * IPsec may not have been loaded for a request with zero
5906 * policies, so we don't fail in this case.
5908 mutex_enter(&ipss
->ipsec_loader_lock
);
5909 if (ipss
->ipsec_loader_state
!= IPSEC_LOADER_SUCCEEDED
) {
5910 mutex_exit(&ipss
->ipsec_loader_lock
);
5911 return (EPROTONOSUPPORT
);
5913 mutex_exit(&ipss
->ipsec_loader_lock
);
5916 * Test for valid requests. Invalid algorithms
5917 * need to be tested by IPsec code because new
5918 * algorithms can be added dynamically.
5920 if ((ah_req
& ~(REQ_MASK
|IPSEC_PREF_UNIQUE
)) != 0 ||
5921 (esp_req
& ~(REQ_MASK
|IPSEC_PREF_UNIQUE
)) != 0 ||
5922 (se_req
& ~(REQ_MASK
|IPSEC_PREF_UNIQUE
)) != 0) {
5927 * Only privileged users can issue these
5930 if (((ah_req
& IPSEC_PREF_NEVER
) ||
5931 (esp_req
& IPSEC_PREF_NEVER
) ||
5932 (se_req
& IPSEC_PREF_NEVER
)) &&
5933 secpolicy_ip_config(cr
, B_FALSE
) != 0) {
5938 * The IPSEC_PREF_REQUIRED and IPSEC_PREF_NEVER
5939 * are mutually exclusive.
5941 if (((ah_req
& REQ_MASK
) == REQ_MASK
) ||
5942 ((esp_req
& REQ_MASK
) == REQ_MASK
) ||
5943 ((se_req
& REQ_MASK
) == REQ_MASK
)) {
5944 /* Both of them are set */
5949 ASSERT(MUTEX_HELD(&connp
->conn_lock
));
5952 * If we have already cached policies in conn_connect(), don't
5953 * let them change now. We cache policies for connections
5954 * whose src,dst [addr, port] is known.
5956 if (connp
->conn_policy_cached
) {
5961 * We have a zero policies, reset the connection policy if already
5962 * set. This will cause the connection to inherit the
5963 * global policy, if any.
5966 if (connp
->conn_policy
!= NULL
) {
5967 IPPH_REFRELE(connp
->conn_policy
, ipst
->ips_netstack
);
5968 connp
->conn_policy
= NULL
;
5970 connp
->conn_in_enforce_policy
= B_FALSE
;
5971 connp
->conn_out_enforce_policy
= B_FALSE
;
5975 ph
= connp
->conn_policy
= ipsec_polhead_split(connp
->conn_policy
,
5976 ipst
->ips_netstack
);
5980 ipsec_actvec_from_req(req
, &actp
, &nact
, ipst
->ips_netstack
);
5985 * Always insert IPv4 policy entries, since they can also apply to
5986 * ipv6 sockets being used in ipv4-compat mode.
5988 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V4
,
5989 IPSEC_TYPE_INBOUND
, ns
))
5991 is_pol_inserted
= B_TRUE
;
5992 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V4
,
5993 IPSEC_TYPE_OUTBOUND
, ns
))
5997 * We're looking at a v6 socket, also insert the v6-specific
6000 if (connp
->conn_family
== AF_INET6
) {
6001 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V6
,
6002 IPSEC_TYPE_INBOUND
, ns
))
6004 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V6
,
6005 IPSEC_TYPE_OUTBOUND
, ns
))
6009 ipsec_actvec_free(actp
, nact
);
6012 * If the requests need security, set enforce_policy.
6013 * If the requests are IPSEC_PREF_NEVER, one should
6014 * still set conn_out_enforce_policy so that ip_set_destination
6015 * marks the ip_xmit_attr_t appropriatly. This is needed so that
6016 * for connections that we don't cache policy in at connect time,
6017 * if global policy matches in ip_output_attach_policy, we
6018 * don't wrongly inherit global policy. Similarly, we need
6019 * to set conn_in_enforce_policy also so that we don't verify
6022 if ((ah_req
& REQ_MASK
) != 0 ||
6023 (esp_req
& REQ_MASK
) != 0 ||
6024 (se_req
& REQ_MASK
) != 0) {
6025 connp
->conn_in_enforce_policy
= B_TRUE
;
6026 connp
->conn_out_enforce_policy
= B_TRUE
;
6033 * Common memory-allocation-failure exit path.
6037 ipsec_actvec_free(actp
, nact
);
6038 if (is_pol_inserted
)
6039 ipsec_polhead_flush(ph
, ns
);
6044 * Set socket options for joining and leaving multicast groups.
6045 * Common to IPv4 and IPv6; inet6 indicates the type of socket.
6046 * The caller has already check that the option name is consistent with
6047 * the address family of the socket.
6050 ip_opt_set_multicast_group(conn_t
*connp
, t_scalar_t name
,
6051 uchar_t
*invalp
, boolean_t inet6
, boolean_t checkonly
)
6053 int *i1
= (int *)invalp
;
6055 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
6056 struct ip_mreq
*v4_mreqp
;
6057 struct ipv6_mreq
*v6_mreqp
;
6058 struct group_req
*greqp
;
6060 boolean_t done
= B_FALSE
;
6064 boolean_t mcast_opt
= B_TRUE
;
6065 mcast_record_t fmode
;
6066 int (*optfn
)(conn_t
*, boolean_t
, const in6_addr_t
*,
6067 ipaddr_t
, uint_t
, mcast_record_t
, const in6_addr_t
*);
6070 case IP_ADD_MEMBERSHIP
:
6071 case IPV6_JOIN_GROUP
:
6072 mcast_opt
= B_FALSE
;
6074 case MCAST_JOIN_GROUP
:
6075 fmode
= MODE_IS_EXCLUDE
;
6076 optfn
= ip_opt_add_group
;
6079 case IP_DROP_MEMBERSHIP
:
6080 case IPV6_LEAVE_GROUP
:
6081 mcast_opt
= B_FALSE
;
6083 case MCAST_LEAVE_GROUP
:
6084 fmode
= MODE_IS_INCLUDE
;
6085 optfn
= ip_opt_delete_group
;
6092 struct sockaddr_in
*sin
;
6093 struct sockaddr_in6
*sin6
;
6095 greqp
= (struct group_req
*)i1
;
6096 if (greqp
->gr_group
.ss_family
== AF_INET
) {
6097 sin
= (struct sockaddr_in
*)&(greqp
->gr_group
);
6098 IN6_INADDR_TO_V4MAPPED(&sin
->sin_addr
, &v6group
);
6101 return (EINVAL
); /* Not on INET socket */
6103 sin6
= (struct sockaddr_in6
*)&(greqp
->gr_group
);
6104 v6group
= sin6
->sin6_addr
;
6106 ifaddr
= INADDR_ANY
;
6107 ifindex
= greqp
->gr_interface
;
6109 v6_mreqp
= (struct ipv6_mreq
*)i1
;
6110 v6group
= v6_mreqp
->ipv6mr_multiaddr
;
6111 ifaddr
= INADDR_ANY
;
6112 ifindex
= v6_mreqp
->ipv6mr_interface
;
6114 v4_mreqp
= (struct ip_mreq
*)i1
;
6115 IN6_INADDR_TO_V4MAPPED(&v4_mreqp
->imr_multiaddr
, &v6group
);
6116 ifaddr
= (ipaddr_t
)v4_mreqp
->imr_interface
.s_addr
;
6121 * In the multirouting case, we need to replicate
6122 * the request on all interfaces that will take part
6123 * in replication. We do so because multirouting is
6124 * reflective, thus we will probably receive multi-
6125 * casts on those interfaces.
6127 if (IN6_IS_ADDR_V4MAPPED(&v6group
)) {
6130 IN6_V4MAPPED_TO_IPADDR(&v6group
, group
);
6132 ire
= ire_ftable_lookup_v4(group
, IP_HOST_MASK
, 0,
6133 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6134 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6136 ire
= ire_ftable_lookup_v6(&v6group
, &ipv6_all_ones
, 0,
6137 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6138 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6144 error
= optfn(connp
, checkonly
, &v6group
, ifaddr
, ifindex
,
6145 fmode
, &ipv6_all_zeros
);
6151 * Set socket options for joining and leaving multicast groups
6152 * for specific sources.
6153 * Common to IPv4 and IPv6; inet6 indicates the type of socket.
6154 * The caller has already check that the option name is consistent with
6155 * the address family of the socket.
6158 ip_opt_set_multicast_sources(conn_t
*connp
, t_scalar_t name
,
6159 uchar_t
*invalp
, boolean_t inet6
, boolean_t checkonly
)
6161 int *i1
= (int *)invalp
;
6162 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
6163 struct ip_mreq_source
*imreqp
;
6164 struct group_source_req
*gsreqp
;
6165 in6_addr_t v6group
, v6src
;
6168 boolean_t mcast_opt
= B_TRUE
;
6169 mcast_record_t fmode
;
6171 int (*optfn
)(conn_t
*, boolean_t
, const in6_addr_t
*,
6172 ipaddr_t
, uint_t
, mcast_record_t
, const in6_addr_t
*);
6175 case IP_BLOCK_SOURCE
:
6176 mcast_opt
= B_FALSE
;
6178 case MCAST_BLOCK_SOURCE
:
6179 fmode
= MODE_IS_EXCLUDE
;
6180 optfn
= ip_opt_add_group
;
6183 case IP_UNBLOCK_SOURCE
:
6184 mcast_opt
= B_FALSE
;
6186 case MCAST_UNBLOCK_SOURCE
:
6187 fmode
= MODE_IS_EXCLUDE
;
6188 optfn
= ip_opt_delete_group
;
6191 case IP_ADD_SOURCE_MEMBERSHIP
:
6192 mcast_opt
= B_FALSE
;
6194 case MCAST_JOIN_SOURCE_GROUP
:
6195 fmode
= MODE_IS_INCLUDE
;
6196 optfn
= ip_opt_add_group
;
6199 case IP_DROP_SOURCE_MEMBERSHIP
:
6200 mcast_opt
= B_FALSE
;
6202 case MCAST_LEAVE_SOURCE_GROUP
:
6203 fmode
= MODE_IS_INCLUDE
;
6204 optfn
= ip_opt_delete_group
;
6211 gsreqp
= (struct group_source_req
*)i1
;
6212 ifindex
= gsreqp
->gsr_interface
;
6213 if (gsreqp
->gsr_group
.ss_family
== AF_INET
) {
6214 struct sockaddr_in
*s
;
6215 s
= (struct sockaddr_in
*)&gsreqp
->gsr_group
;
6216 IN6_INADDR_TO_V4MAPPED(&s
->sin_addr
, &v6group
);
6217 s
= (struct sockaddr_in
*)&gsreqp
->gsr_source
;
6218 IN6_INADDR_TO_V4MAPPED(&s
->sin_addr
, &v6src
);
6220 struct sockaddr_in6
*s6
;
6223 return (EINVAL
); /* Not on INET socket */
6225 s6
= (struct sockaddr_in6
*)&gsreqp
->gsr_group
;
6226 v6group
= s6
->sin6_addr
;
6227 s6
= (struct sockaddr_in6
*)&gsreqp
->gsr_source
;
6228 v6src
= s6
->sin6_addr
;
6230 ifaddr
= INADDR_ANY
;
6232 imreqp
= (struct ip_mreq_source
*)i1
;
6233 IN6_INADDR_TO_V4MAPPED(&imreqp
->imr_multiaddr
, &v6group
);
6234 IN6_INADDR_TO_V4MAPPED(&imreqp
->imr_sourceaddr
, &v6src
);
6235 ifaddr
= (ipaddr_t
)imreqp
->imr_interface
.s_addr
;
6240 * Handle src being mapped INADDR_ANY by changing it to unspecified.
6242 if (IN6_IS_ADDR_V4MAPPED_ANY(&v6src
))
6243 v6src
= ipv6_all_zeros
;
6246 * In the multirouting case, we need to replicate
6247 * the request as noted in the mcast cases above.
6249 if (IN6_IS_ADDR_V4MAPPED(&v6group
)) {
6252 IN6_V4MAPPED_TO_IPADDR(&v6group
, group
);
6254 ire
= ire_ftable_lookup_v4(group
, IP_HOST_MASK
, 0,
6255 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6256 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6258 ire
= ire_ftable_lookup_v6(&v6group
, &ipv6_all_ones
, 0,
6259 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6260 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6264 return (optfn(connp
, checkonly
, &v6group
, ifaddr
, ifindex
,
6269 * Given a destination address and a pointer to where to put the information
6270 * this routine fills in the mtuinfo.
6271 * The socket must be connected.
6272 * For sctp conn_faddr is the primary address.
6275 ip_fill_mtuinfo(conn_t
*connp
, ip_xmit_attr_t
*ixa
, struct ip6_mtuinfo
*mtuinfo
)
6277 uint32_t pmtu
= IP_MAXPACKET
;
6280 if (IN6_IS_ADDR_UNSPECIFIED(&connp
->conn_faddr_v6
))
6283 /* In case we never sent or called ip_set_destination_v4/v6 */
6284 if (ixa
->ixa_ire
!= NULL
)
6285 pmtu
= ip_get_pmtu(ixa
);
6287 if (ixa
->ixa_flags
& IXAF_SCOPEID_SET
)
6288 scopeid
= ixa
->ixa_scopeid
;
6292 bzero(mtuinfo
, sizeof (*mtuinfo
));
6293 mtuinfo
->ip6m_addr
.sin6_family
= AF_INET6
;
6294 mtuinfo
->ip6m_addr
.sin6_port
= connp
->conn_fport
;
6295 mtuinfo
->ip6m_addr
.sin6_addr
= connp
->conn_faddr_v6
;
6296 mtuinfo
->ip6m_addr
.sin6_scope_id
= scopeid
;
6297 mtuinfo
->ip6m_mtu
= pmtu
;
6299 return (sizeof (struct ip6_mtuinfo
));
6303 * When the src multihoming is changed from weak to [strong, preferred]
6304 * ip_ire_rebind_walker is called to walk the list of all ire_t entries
6305 * and identify routes that were created by user-applications in the
6306 * unbound state (i.e., without RTA_IFP), and for which an ire_ill is not
6307 * currently defined. These routes are then 'rebound', i.e., their ire_ill
6308 * is selected by finding an interface route for the gateway.
6312 ip_ire_rebind_walker(ire_t
*ire
, void *notused
)
6314 if (!ire
->ire_unbound
|| ire
->ire_ill
!= NULL
)
6321 * When the src multihoming is changed from [strong, preferred] to weak,
6322 * ip_ire_unbind_walker is called to walk the list of all ire_t entries, and
6323 * set any entries that were created by user-applications in the unbound state
6324 * (i.e., without RTA_IFP) back to having a NULL ire_ill.
6328 ip_ire_unbind_walker(ire_t
*ire
, void *notused
)
6332 if (!ire
->ire_unbound
|| ire
->ire_ill
== NULL
)
6334 if (ire
->ire_ipversion
== IPV6_VERSION
) {
6335 new_ire
= ire_create_v6(&ire
->ire_addr_v6
, &ire
->ire_mask_v6
,
6336 &ire
->ire_gateway_addr_v6
, ire
->ire_type
, NULL
,
6337 ire
->ire_zoneid
, ire
->ire_flags
, ire
->ire_ipst
);
6339 new_ire
= ire_create((uchar_t
*)&ire
->ire_addr
,
6340 (uchar_t
*)&ire
->ire_mask
,
6341 (uchar_t
*)&ire
->ire_gateway_addr
, ire
->ire_type
, NULL
,
6342 ire
->ire_zoneid
, ire
->ire_flags
, ire
->ire_ipst
);
6344 if (new_ire
== NULL
)
6346 new_ire
->ire_unbound
= B_TRUE
;
6348 * The bound ire must first be deleted so that we don't return
6349 * the existing one on the attempt to add the unbound new_ire.
6352 new_ire
= ire_add(new_ire
);
6353 if (new_ire
!= NULL
)
6354 ire_refrele(new_ire
);
6358 * When the settings of ip*_strict_src_multihoming tunables are changed,
6359 * all cached routes need to be recomputed. This recomputation needs to be
6360 * done when going from weaker to stronger modes so that the cached ire
6361 * for the connection does not violate the current ip*_strict_src_multihoming
6362 * setting. It also needs to be done when going from stronger to weaker modes,
6363 * so that we fall back to matching on the longest-matching-route (as opposed
6364 * to a shorter match that may have been selected in the strong mode
6365 * to satisfy src_multihoming settings).
6367 * The cached ixa_ire entires for all conn_t entries are marked as
6368 * "verify" so that they will be recomputed for the next packet.
6371 conn_ire_revalidate(conn_t
*connp
, void *arg
)
6373 boolean_t isv6
= (boolean_t
)arg
;
6375 if ((isv6
&& connp
->conn_ipversion
!= IPV6_VERSION
) ||
6376 (!isv6
&& connp
->conn_ipversion
!= IPV4_VERSION
))
6378 connp
->conn_ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
6382 * Handles both IPv4 and IPv6 reassembly - doing the out-of-order cases,
6383 * When an ipf is passed here for the first time, if
6384 * we already have in-order fragments on the queue, we convert from the fast-
6385 * path reassembly scheme to the hard-case scheme. From then on, additional
6386 * fragments are reassembled here. We keep track of the start and end offsets
6387 * of each piece, and the number of holes in the chain. When the hole count
6388 * goes to zero, we are done!
6390 * The ipf_count will be updated to account for any mblk(s) added (pointed to
6391 * by mp) or subtracted (freeb()ed dups), upon return the caller must update
6392 * ipfb_count and ill_frag_count by the difference of ipf_count before and
6393 * after the call to ip_reassemble().
6396 ip_reassemble(mblk_t
*mp
, ipf_t
*ipf
, uint_t start
, boolean_t more
, ill_t
*ill
,
6403 boolean_t incr_dups
= B_TRUE
;
6404 boolean_t offset_zero_seen
= B_FALSE
;
6405 boolean_t pkt_boundary_checked
= B_FALSE
;
6407 /* If start == 0 then ipf_nf_hdr_len has to be set. */
6408 ASSERT(start
!= 0 || ipf
->ipf_nf_hdr_len
!= 0);
6410 /* Add in byte count */
6411 ipf
->ipf_count
+= msg_len
;
6414 * We were part way through in-order reassembly, but now there
6415 * is a hole. We walk through messages already queued, and
6416 * mark them for hard case reassembly. We know that up till
6417 * now they were in order starting from offset zero.
6420 for (mp1
= ipf
->ipf_mp
->b_cont
; mp1
; mp1
= mp1
->b_cont
) {
6421 IP_REASS_SET_START(mp1
, offset
);
6423 ASSERT(ipf
->ipf_nf_hdr_len
!= 0);
6424 offset
= -ipf
->ipf_nf_hdr_len
;
6426 offset
+= mp1
->b_wptr
- mp1
->b_rptr
;
6427 IP_REASS_SET_END(mp1
, offset
);
6429 /* One hole at the end. */
6430 ipf
->ipf_hole_cnt
= 1;
6431 /* Brand it as a hard case, forever. */
6434 /* Walk through all the new pieces. */
6436 end
= start
+ (mp
->b_wptr
- mp
->b_rptr
);
6438 * If start is 0, decrease 'end' only for the first mblk of
6439 * the fragment. Otherwise 'end' can get wrong value in the
6440 * second pass of the loop if first mblk is exactly the
6441 * size of ipf_nf_hdr_len.
6443 if (start
== 0 && !offset_zero_seen
) {
6445 ASSERT(ipf
->ipf_nf_hdr_len
!= 0);
6446 end
-= ipf
->ipf_nf_hdr_len
;
6447 offset_zero_seen
= B_TRUE
;
6449 next_mp
= mp
->b_cont
;
6451 * We are checking to see if there is any interesing data
6452 * to process. If there isn't and the mblk isn't the
6453 * one which carries the unfragmentable header then we
6454 * drop it. It's possible to have just the unfragmentable
6455 * header come through without any data. That needs to be
6458 * If the assert at the top of this function holds then the
6459 * term "ipf->ipf_nf_hdr_len != 0" isn't needed. This code
6460 * is infrequently traveled enough that the test is left in
6461 * to protect against future code changes which break that
6464 if (start
== end
&& start
!= 0 && ipf
->ipf_nf_hdr_len
!= 0) {
6465 /* Empty. Blast it. */
6466 IP_REASS_SET_START(mp
, 0);
6467 IP_REASS_SET_END(mp
, 0);
6469 * If the ipf points to the mblk we are about to free,
6470 * update ipf to point to the next mblk (or NULL
6473 if (ipf
->ipf_mp
->b_cont
== mp
)
6474 ipf
->ipf_mp
->b_cont
= next_mp
;
6479 IP_REASS_SET_START(mp
, start
);
6480 IP_REASS_SET_END(mp
, end
);
6481 if (!ipf
->ipf_tail_mp
) {
6482 ipf
->ipf_tail_mp
= mp
;
6483 ipf
->ipf_mp
->b_cont
= mp
;
6484 if (start
== 0 || !more
) {
6485 ipf
->ipf_hole_cnt
= 1;
6487 * if the first fragment comes in more than one
6488 * mblk, this loop will be executed for each
6489 * mblk. Need to adjust hole count so exiting
6490 * this routine will leave hole count at 1.
6493 ipf
->ipf_hole_cnt
++;
6495 ipf
->ipf_hole_cnt
= 2;
6497 } else if (ipf
->ipf_last_frag_seen
&& !more
&&
6498 !pkt_boundary_checked
) {
6500 * We check datagram boundary only if this fragment
6501 * claims to be the last fragment and we have seen a
6502 * last fragment in the past too. We do this only
6503 * once for a given fragment.
6505 * start cannot be 0 here as fragments with start=0
6506 * and MF=0 gets handled as a complete packet. These
6507 * fragments should not reach here.
6510 if (start
+ msgdsize(mp
) !=
6511 IP_REASS_END(ipf
->ipf_tail_mp
)) {
6513 * We have two fragments both of which claim
6514 * to be the last fragment but gives conflicting
6515 * information about the whole datagram size.
6516 * Something fishy is going on. Drop the
6517 * fragment and free up the reassembly list.
6519 return (IP_REASS_FAILED
);
6523 * We shouldn't come to this code block again for this
6524 * particular fragment.
6526 pkt_boundary_checked
= B_TRUE
;
6529 /* New stuff at or beyond tail? */
6530 offset
= IP_REASS_END(ipf
->ipf_tail_mp
);
6531 if (start
>= offset
) {
6532 if (ipf
->ipf_last_frag_seen
) {
6533 /* current fragment is beyond last fragment */
6534 return (IP_REASS_FAILED
);
6536 /* Link it on end. */
6537 ipf
->ipf_tail_mp
->b_cont
= mp
;
6538 ipf
->ipf_tail_mp
= mp
;
6540 if (start
!= offset
)
6541 ipf
->ipf_hole_cnt
++;
6542 } else if (start
== offset
&& next_mp
== NULL
)
6543 ipf
->ipf_hole_cnt
--;
6546 mp1
= ipf
->ipf_mp
->b_cont
;
6547 offset
= IP_REASS_START(mp1
);
6548 /* New stuff at the front? */
6549 if (start
< offset
) {
6551 if (end
>= offset
) {
6552 /* Nailed the hole at the begining. */
6553 ipf
->ipf_hole_cnt
--;
6555 } else if (end
< offset
) {
6557 * A hole, stuff, and a hole where there used
6558 * to be just a hole.
6560 ipf
->ipf_hole_cnt
++;
6563 /* Check for overlap. */
6564 while (end
> offset
) {
6565 if (end
< IP_REASS_END(mp1
)) {
6566 mp
->b_wptr
-= end
- offset
;
6567 IP_REASS_SET_END(mp
, offset
);
6568 BUMP_MIB(ill
->ill_ip_mib
,
6569 ipIfStatsReasmPartDups
);
6572 /* Did we cover another hole? */
6574 IP_REASS_END(mp1
) !=
6575 IP_REASS_START(mp1
->b_cont
) &&
6576 end
>= IP_REASS_START(mp1
->b_cont
)) ||
6577 (!ipf
->ipf_last_frag_seen
&& !more
)) {
6578 ipf
->ipf_hole_cnt
--;
6581 if ((mp
->b_cont
= mp1
->b_cont
) == NULL
) {
6583 * After clipping out mp1, this guy
6584 * is now hanging off the end.
6586 ipf
->ipf_tail_mp
= mp
;
6588 IP_REASS_SET_START(mp1
, 0);
6589 IP_REASS_SET_END(mp1
, 0);
6590 /* Subtract byte count */
6591 ipf
->ipf_count
-= mp1
->b_datap
->db_lim
-
6592 mp1
->b_datap
->db_base
;
6594 BUMP_MIB(ill
->ill_ip_mib
,
6595 ipIfStatsReasmPartDups
);
6599 offset
= IP_REASS_START(mp1
);
6601 ipf
->ipf_mp
->b_cont
= mp
;
6605 * The new piece starts somewhere between the start of the head
6606 * and before the end of the tail.
6608 for (; mp1
; mp1
= mp1
->b_cont
) {
6609 offset
= IP_REASS_END(mp1
);
6610 if (start
< offset
) {
6611 if (end
<= offset
) {
6613 IP_REASS_SET_START(mp
, 0);
6614 IP_REASS_SET_END(mp
, 0);
6615 /* Subtract byte count */
6616 ipf
->ipf_count
-= mp
->b_datap
->db_lim
-
6617 mp
->b_datap
->db_base
;
6619 ipf
->ipf_num_dups
++;
6620 incr_dups
= B_FALSE
;
6623 BUMP_MIB(ill
->ill_ip_mib
,
6624 ipIfStatsReasmDuplicates
);
6628 * Trim redundant stuff off beginning of new
6631 IP_REASS_SET_START(mp
, offset
);
6632 mp
->b_rptr
+= offset
- start
;
6633 BUMP_MIB(ill
->ill_ip_mib
,
6634 ipIfStatsReasmPartDups
);
6638 * After trimming, this guy is now
6639 * hanging off the end.
6642 ipf
->ipf_tail_mp
= mp
;
6644 ipf
->ipf_hole_cnt
--;
6649 if (start
>= IP_REASS_START(mp1
->b_cont
))
6653 ipf
->ipf_hole_cnt
++;
6654 mp
->b_cont
= mp1
->b_cont
;
6657 offset
= IP_REASS_START(mp1
);
6658 if (end
>= offset
) {
6659 ipf
->ipf_hole_cnt
--;
6660 /* Check for overlap. */
6661 while (end
> offset
) {
6662 if (end
< IP_REASS_END(mp1
)) {
6663 mp
->b_wptr
-= end
- offset
;
6664 IP_REASS_SET_END(mp
, offset
);
6666 * TODO we might bump
6667 * this up twice if there is
6668 * overlap at both ends.
6670 BUMP_MIB(ill
->ill_ip_mib
,
6671 ipIfStatsReasmPartDups
);
6674 /* Did we cover another hole? */
6677 != IP_REASS_START(mp1
->b_cont
) &&
6679 IP_REASS_START(mp1
->b_cont
)) ||
6680 (!ipf
->ipf_last_frag_seen
&&
6682 ipf
->ipf_hole_cnt
--;
6685 if ((mp
->b_cont
= mp1
->b_cont
) ==
6688 * After clipping out mp1,
6689 * this guy is now hanging
6692 ipf
->ipf_tail_mp
= mp
;
6694 IP_REASS_SET_START(mp1
, 0);
6695 IP_REASS_SET_END(mp1
, 0);
6696 /* Subtract byte count */
6698 mp1
->b_datap
->db_lim
-
6699 mp1
->b_datap
->db_base
;
6701 BUMP_MIB(ill
->ill_ip_mib
,
6702 ipIfStatsReasmPartDups
);
6706 offset
= IP_REASS_START(mp1
);
6711 } while (start
= end
, mp
= next_mp
);
6713 /* Fragment just processed could be the last one. Remember this fact */
6715 ipf
->ipf_last_frag_seen
= B_TRUE
;
6717 /* Still got holes? */
6718 if (ipf
->ipf_hole_cnt
)
6719 return (IP_REASS_PARTIAL
);
6720 /* Clean up overloaded fields to avoid upstream disasters. */
6721 for (mp1
= ipf
->ipf_mp
->b_cont
; mp1
; mp1
= mp1
->b_cont
) {
6722 IP_REASS_SET_START(mp1
, 0);
6723 IP_REASS_SET_END(mp1
, 0);
6725 return (IP_REASS_COMPLETE
);
6729 * Fragmentation reassembly. Each ILL has a hash table for
6730 * queuing packets undergoing reassembly for all IPIFs
6731 * associated with the ILL. The hash is based on the packet
6732 * IP ident field. The ILL frag hash table was allocated
6733 * as a timer block at the time the ILL was created. Whenever
6734 * there is anything on the reassembly queue, the timer will
6735 * be running. Returns the reassembled packet if reassembly completes.
6738 ip_input_fragment(mblk_t
*mp
, ipha_t
*ipha
, ip_recv_attr_t
*ira
)
6740 uint32_t frag_offset_flags
;
6743 uint8_t proto
= ipha
->ipha_protocol
;
6758 uint8_t ecn_info
= 0;
6759 uint32_t packet_size
;
6760 boolean_t pruned
= B_FALSE
;
6761 ill_t
*ill
= ira
->ira_ill
;
6762 ip_stack_t
*ipst
= ill
->ill_ipst
;
6765 * Drop the fragmented as early as possible, if
6766 * we don't have resource(s) to re-assemble.
6768 if (ipst
->ips_ip_reass_queue_bytes
== 0) {
6773 /* Check for fragmentation offset; return if there's none */
6774 if ((frag_offset_flags
= ntohs(ipha
->ipha_fragment_offset_and_flags
) &
6775 (IPH_MF
| IPH_OFFSET
)) == 0)
6779 * We utilize hardware computed checksum info only for UDP since
6780 * IP fragmentation is a normal occurrence for the protocol. In
6781 * addition, checksum offload support for IP fragments carrying
6782 * UDP payload is commonly implemented across network adapters.
6784 ASSERT(ira
->ira_rill
!= NULL
);
6785 if (proto
== IPPROTO_UDP
&& dohwcksum
&&
6786 ILL_HCKSUM_CAPABLE(ira
->ira_rill
) &&
6787 (DB_CKSUMFLAGS(mp
) & (HCK_FULLCKSUM
| HCK_PARTIALCKSUM
))) {
6788 mblk_t
*mp1
= mp
->b_cont
;
6791 /* Record checksum information from the packet */
6792 sum_val
= (uint32_t)DB_CKSUM16(mp
);
6793 sum_flags
= DB_CKSUMFLAGS(mp
);
6795 /* IP payload offset from beginning of mblk */
6796 offset
= ((uchar_t
*)ipha
+ IPH_HDR_LENGTH(ipha
)) - mp
->b_rptr
;
6798 if ((sum_flags
& HCK_PARTIALCKSUM
) &&
6799 (mp1
== NULL
|| mp1
->b_cont
== NULL
) &&
6800 offset
>= DB_CKSUMSTART(mp
) &&
6801 ((len
= offset
- DB_CKSUMSTART(mp
)) & 1) == 0) {
6804 * Partial checksum has been calculated by hardware
6805 * and attached to the packet; in addition, any
6806 * prepended extraneous data is even byte aligned.
6807 * If any such data exists, we adjust the checksum;
6808 * this would also handle any postpended data.
6810 IP_ADJCKSUM_PARTIAL(mp
->b_rptr
+ DB_CKSUMSTART(mp
),
6813 /* One's complement subtract extraneous checksum */
6815 sum_val
= ~(adj
- sum_val
) & 0xFFFF;
6824 /* Clear hardware checksumming flag */
6825 DB_CKSUMFLAGS(mp
) = 0;
6827 ident
= ipha
->ipha_ident
;
6828 offset
= (frag_offset_flags
<< 3) & 0xFFFF;
6829 src
= ipha
->ipha_src
;
6830 dst
= ipha
->ipha_dst
;
6831 hdr_length
= IPH_HDR_LENGTH(ipha
);
6832 end
= ntohs(ipha
->ipha_length
) - hdr_length
;
6834 /* If end == 0 then we have a packet with no data, so just free it */
6840 /* Record the ECN field info. */
6841 ecn_info
= (ipha
->ipha_type_of_service
& 0x3);
6844 * If this isn't the first piece, strip the header, and
6845 * add the offset to the end value.
6847 mp
->b_rptr
+= hdr_length
;
6851 /* Handle vnic loopback of fragments */
6852 if (mp
->b_datap
->db_ref
> 2)
6855 msg_len
= MBLKSIZE(mp
);
6858 while (tail_mp
->b_cont
!= NULL
) {
6859 tail_mp
= tail_mp
->b_cont
;
6860 if (tail_mp
->b_datap
->db_ref
<= 2)
6861 msg_len
+= MBLKSIZE(tail_mp
);
6864 /* If the reassembly list for this ILL will get too big, prune it */
6865 if ((msg_len
+ sizeof (*ipf
) + ill
->ill_frag_count
) >=
6866 ipst
->ips_ip_reass_queue_bytes
) {
6867 DTRACE_PROBE3(ip_reass_queue_bytes
, uint_t
, msg_len
,
6868 uint_t
, ill
->ill_frag_count
,
6869 uint_t
, ipst
->ips_ip_reass_queue_bytes
);
6871 (ipst
->ips_ip_reass_queue_bytes
< msg_len
) ? 0 :
6872 (ipst
->ips_ip_reass_queue_bytes
- msg_len
));
6876 ipfb
= &ill
->ill_frag_hash_tbl
[ILL_FRAG_HASH(src
, ident
)];
6877 mutex_enter(&ipfb
->ipfb_lock
);
6879 ipfp
= &ipfb
->ipfb_ipf
;
6880 /* Try to find an existing fragment queue for this packet. */
6885 * It has to match on ident and src/dst address.
6887 if (ipf
->ipf_ident
== ident
&&
6888 ipf
->ipf_src
== src
&&
6889 ipf
->ipf_dst
== dst
&&
6890 ipf
->ipf_protocol
== proto
) {
6892 * If we have received too many
6893 * duplicate fragments for this packet
6896 if (ipf
->ipf_num_dups
> ip_max_frag_dups
) {
6897 ill_frag_free_pkts(ill
, ipfb
, ipf
, 1);
6899 mutex_exit(&ipfb
->ipfb_lock
);
6905 ipfp
= &ipf
->ipf_hash_next
;
6910 * If we pruned the list, do we want to store this new
6911 * fragment?. We apply an optimization here based on the
6912 * fact that most fragments will be received in order.
6913 * So if the offset of this incoming fragment is zero,
6914 * it is the first fragment of a new packet. We will
6915 * keep it. Otherwise drop the fragment, as we have
6916 * probably pruned the packet already (since the
6917 * packet cannot be found).
6919 if (pruned
&& offset
!= 0) {
6920 mutex_exit(&ipfb
->ipfb_lock
);
6925 if (ipfb
->ipfb_frag_pkts
>= MAX_FRAG_PKTS(ipst
)) {
6927 * Too many fragmented packets in this hash
6928 * bucket. Free the oldest.
6930 ill_frag_free_pkts(ill
, ipfb
, ipfb
->ipfb_ipf
, 1);
6933 /* New guy. Allocate a frag message. */
6934 mp1
= allocb(sizeof (*ipf
), BPRI_MED
);
6936 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6937 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
6940 mutex_exit(&ipfb
->ipfb_lock
);
6944 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmReqds
);
6947 /* Initialize the fragment header. */
6948 ipf
= (ipf_t
*)mp1
->b_rptr
;
6950 ipf
->ipf_ptphn
= ipfp
;
6952 ipf
->ipf_hash_next
= NULL
;
6953 ipf
->ipf_ident
= ident
;
6954 ipf
->ipf_protocol
= proto
;
6957 ipf
->ipf_nf_hdr_len
= 0;
6958 /* Record reassembly start time. */
6959 ipf
->ipf_timestamp
= gethrestime_sec();
6960 /* Record ipf generation and account for frag header */
6961 ipf
->ipf_gen
= ill
->ill_ipf_gen
++;
6962 ipf
->ipf_count
= MBLKSIZE(mp1
);
6963 ipf
->ipf_last_frag_seen
= B_FALSE
;
6964 ipf
->ipf_ecn
= ecn_info
;
6965 ipf
->ipf_num_dups
= 0;
6966 ipfb
->ipfb_frag_pkts
++;
6967 ipf
->ipf_checksum
= 0;
6968 ipf
->ipf_checksum_flags
= 0;
6970 /* Store checksum value in fragment header */
6971 if (sum_flags
!= 0) {
6972 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
6973 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
6974 ipf
->ipf_checksum
= sum_val
;
6975 ipf
->ipf_checksum_flags
= sum_flags
;
6979 * We handle reassembly two ways. In the easy case,
6980 * where all the fragments show up in order, we do
6981 * minimal bookkeeping, and just clip new pieces on
6982 * the end. If we ever see a hole, then we go off
6983 * to ip_reassemble which has to mark the pieces and
6984 * keep track of the number of holes, etc. Obviously,
6985 * the point of having both mechanisms is so we can
6986 * handle the easy case as efficiently as possible.
6989 /* Easy case, in-order reassembly so far. */
6990 ipf
->ipf_count
+= msg_len
;
6991 ipf
->ipf_tail_mp
= tail_mp
;
6993 * Keep track of next expected offset in
6997 ipf
->ipf_nf_hdr_len
= hdr_length
;
6999 /* Hard case, hole at the beginning. */
7000 ipf
->ipf_tail_mp
= NULL
;
7002 * ipf_end == 0 means that we have given up
7003 * on easy reassembly.
7007 /* Forget checksum offload from now on */
7008 ipf
->ipf_checksum_flags
= 0;
7011 * ipf_hole_cnt is set by ip_reassemble.
7012 * ipf_count is updated by ip_reassemble.
7013 * No need to check for return value here
7014 * as we don't expect reassembly to complete
7015 * or fail for the first fragment itself.
7017 (void) ip_reassemble(mp
, ipf
,
7018 (frag_offset_flags
& IPH_OFFSET
) << 3,
7019 (frag_offset_flags
& IPH_MF
), ill
, msg_len
);
7021 /* Update per ipfb and ill byte counts */
7022 ipfb
->ipfb_count
+= ipf
->ipf_count
;
7023 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
7024 atomic_add_32(&ill
->ill_frag_count
, ipf
->ipf_count
);
7025 /* If the frag timer wasn't already going, start it. */
7026 mutex_enter(&ill
->ill_lock
);
7027 ill_frag_timer_start(ill
);
7028 mutex_exit(&ill
->ill_lock
);
7033 * If the packet's flag has changed (it could be coming up
7034 * from an interface different than the previous, therefore
7035 * possibly different checksum capability), then forget about
7036 * any stored checksum states. Otherwise add the value to
7037 * the existing one stored in the fragment header.
7039 if (sum_flags
!= 0 && sum_flags
== ipf
->ipf_checksum_flags
) {
7040 sum_val
+= ipf
->ipf_checksum
;
7041 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
7042 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
7043 ipf
->ipf_checksum
= sum_val
;
7044 } else if (ipf
->ipf_checksum_flags
!= 0) {
7045 /* Forget checksum offload from now on */
7046 ipf
->ipf_checksum_flags
= 0;
7050 * We have a new piece of a datagram which is already being
7051 * reassembled. Update the ECN info if all IP fragments
7052 * are ECN capable. If there is one which is not, clear
7053 * all the info. If there is at least one which has CE
7054 * code point, IP needs to report that up to transport.
7056 if (ecn_info
!= IPH_ECN_NECT
&& ipf
->ipf_ecn
!= IPH_ECN_NECT
) {
7057 if (ecn_info
== IPH_ECN_CE
)
7058 ipf
->ipf_ecn
= IPH_ECN_CE
;
7060 ipf
->ipf_ecn
= IPH_ECN_NECT
;
7062 if (offset
&& ipf
->ipf_end
== offset
) {
7063 /* The new fragment fits at the end */
7064 ipf
->ipf_tail_mp
->b_cont
= mp
;
7065 /* Update the byte count */
7066 ipf
->ipf_count
+= msg_len
;
7067 /* Update per ipfb and ill byte counts */
7068 ipfb
->ipfb_count
+= msg_len
;
7069 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
7070 atomic_add_32(&ill
->ill_frag_count
, msg_len
);
7071 if (frag_offset_flags
& IPH_MF
) {
7074 ipf
->ipf_tail_mp
= tail_mp
;
7078 /* Go do the hard cases. */
7082 ipf
->ipf_nf_hdr_len
= hdr_length
;
7084 /* Save current byte count */
7085 count
= ipf
->ipf_count
;
7086 ret
= ip_reassemble(mp
, ipf
,
7087 (frag_offset_flags
& IPH_OFFSET
) << 3,
7088 (frag_offset_flags
& IPH_MF
), ill
, msg_len
);
7089 /* Count of bytes added and subtracted (freeb()ed) */
7090 count
= ipf
->ipf_count
- count
;
7092 /* Update per ipfb and ill byte counts */
7093 ipfb
->ipfb_count
+= count
;
7094 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
7095 atomic_add_32(&ill
->ill_frag_count
, count
);
7097 if (ret
== IP_REASS_PARTIAL
) {
7099 } else if (ret
== IP_REASS_FAILED
) {
7100 /* Reassembly failed. Free up all resources */
7101 ill_frag_free_pkts(ill
, ipfb
, ipf
, 1);
7102 for (t_mp
= mp
; t_mp
!= NULL
; t_mp
= t_mp
->b_cont
) {
7103 IP_REASS_SET_START(t_mp
, 0);
7104 IP_REASS_SET_END(t_mp
, 0);
7109 /* We will reach here iff 'ret' is IP_REASS_COMPLETE */
7112 * We have completed reassembly. Unhook the frag header from
7113 * the reassembly list.
7115 * Before we free the frag header, record the ECN info
7116 * to report back to the transport.
7118 ecn_info
= ipf
->ipf_ecn
;
7119 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmOKs
);
7120 ipfp
= ipf
->ipf_ptphn
;
7122 /* We need to supply these to caller */
7123 if ((sum_flags
= ipf
->ipf_checksum_flags
) != 0)
7124 sum_val
= ipf
->ipf_checksum
;
7129 count
= ipf
->ipf_count
;
7130 ipf
= ipf
->ipf_hash_next
;
7132 ipf
->ipf_ptphn
= ipfp
;
7134 atomic_add_32(&ill
->ill_frag_count
, -count
);
7135 ASSERT(ipfb
->ipfb_count
>= count
);
7136 ipfb
->ipfb_count
-= count
;
7137 ipfb
->ipfb_frag_pkts
--;
7138 mutex_exit(&ipfb
->ipfb_lock
);
7139 /* Ditch the frag header. */
7144 /* Restore original IP length in header. */
7145 packet_size
= (uint32_t)msgdsize(mp
);
7146 if (packet_size
> IP_MAXPACKET
) {
7147 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7148 ip_drop_input("Reassembled packet too large", mp
, ill
);
7153 if (DB_REF(mp
) > 1) {
7154 mblk_t
*mp2
= copymsg(mp
);
7157 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7158 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7165 ipha
= (ipha_t
*)mp
->b_rptr
;
7167 ipha
->ipha_length
= htons((uint16_t)packet_size
);
7168 /* We're now complete, zip the frag state */
7169 ipha
->ipha_fragment_offset_and_flags
= 0;
7170 /* Record the ECN info. */
7171 ipha
->ipha_type_of_service
&= 0xFC;
7172 ipha
->ipha_type_of_service
|= ecn_info
;
7174 /* Update the receive attributes */
7175 ira
->ira_pktlen
= packet_size
;
7176 ira
->ira_ip_hdr_length
= IPH_HDR_LENGTH(ipha
);
7178 /* Reassembly is successful; set checksum information in packet */
7179 DB_CKSUM16(mp
) = (uint16_t)sum_val
;
7180 DB_CKSUMFLAGS(mp
) = sum_flags
;
7181 DB_CKSUMSTART(mp
) = ira
->ira_ip_hdr_length
;
7187 * Pullup function that should be used for IP input in order to
7188 * ensure we do not loose the L2 source address; we need the l2 source
7189 * address for IP_RECVSLLA and for ndp_input.
7191 * We return either NULL or b_rptr.
7194 ip_pullup(mblk_t
*mp
, ssize_t len
, ip_recv_attr_t
*ira
)
7196 ill_t
*ill
= ira
->ira_ill
;
7198 if (ip_rput_pullups
++ == 0) {
7199 (void) mi_strlog(ill
->ill_rq
, 1, SL_ERROR
|SL_TRACE
,
7200 "ip_pullup: %s forced us to "
7201 " pullup pkt, hdr len %ld, hdr addr %p",
7202 ill
->ill_name
, len
, (void *)mp
->b_rptr
);
7204 if (!(ira
->ira_flags
& IRAF_L2SRC_SET
))
7205 ip_setl2src(mp
, ira
, ira
->ira_rill
);
7206 ASSERT(ira
->ira_flags
& IRAF_L2SRC_SET
);
7207 if (!pullupmsg(mp
, len
))
7210 return (mp
->b_rptr
);
7214 * Make sure ira_l2src has an address. If we don't have one fill with zeros.
7215 * When called from the ULP ira_rill will be NULL hence the caller has to
7220 ip_setl2src(mblk_t
*mp
, ip_recv_attr_t
*ira
, ill_t
*ill
)
7222 const uchar_t
*addr
;
7225 if (ira
->ira_flags
& IRAF_L2SRC_SET
)
7228 ASSERT(ill
!= NULL
);
7229 alen
= ill
->ill_phys_addr_length
;
7230 ASSERT(alen
<= sizeof (ira
->ira_l2src
));
7231 if (ira
->ira_mhip
!= NULL
&&
7232 (addr
= ira
->ira_mhip
->mhi_saddr
) != NULL
) {
7233 bcopy(addr
, ira
->ira_l2src
, alen
);
7234 } else if ((ira
->ira_flags
& IRAF_L2SRC_LOOPBACK
) &&
7235 (addr
= ill
->ill_phys_addr
) != NULL
) {
7236 bcopy(addr
, ira
->ira_l2src
, alen
);
7238 bzero(ira
->ira_l2src
, alen
);
7240 ira
->ira_flags
|= IRAF_L2SRC_SET
;
7244 * check ip header length and align it.
7247 ip_check_and_align_header(mblk_t
*mp
, uint_t min_size
, ip_recv_attr_t
*ira
)
7249 ill_t
*ill
= ira
->ira_ill
;
7254 if (!OK_32PTR(mp
->b_rptr
))
7255 IP_STAT(ill
->ill_ipst
, ip_notaligned
);
7257 IP_STAT(ill
->ill_ipst
, ip_recv_pullup
);
7259 /* Guard against bogus device drivers */
7261 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7262 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7268 /* GLD sometimes sends up mblk with b_rptr == b_wptr! */
7269 mblk_t
*mp1
= mp
->b_cont
;
7271 if (!(ira
->ira_flags
& IRAF_L2SRC_SET
))
7272 ip_setl2src(mp
, ira
, ira
->ira_rill
);
7273 ASSERT(ira
->ira_flags
& IRAF_L2SRC_SET
);
7280 if (OK_32PTR(mp
->b_rptr
) && MBLKL(mp
) >= min_size
)
7283 if (ip_pullup(mp
, min_size
, ira
) == NULL
) {
7284 if (msgdsize(mp
) < min_size
) {
7285 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7286 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7288 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7289 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7298 * Common code for IPv4 and IPv6 to check and pullup multi-mblks
7301 ip_check_length(mblk_t
*mp
, uchar_t
*rptr
, ssize_t len
, uint_t pkt_len
,
7302 uint_t min_size
, ip_recv_attr_t
*ira
)
7304 ill_t
*ill
= ira
->ira_ill
;
7307 * Make sure we have data length consistent
7308 * with the IP header.
7310 if (mp
->b_cont
== NULL
) {
7311 /* pkt_len is based on ipha_len, not the mblk length */
7312 if (pkt_len
< min_size
) {
7313 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7314 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7319 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
7320 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
7325 mp
->b_wptr
= rptr
+ pkt_len
;
7326 } else if ((len
+= msgdsize(mp
->b_cont
)) != 0) {
7327 ASSERT(pkt_len
>= min_size
);
7328 if (pkt_len
< min_size
) {
7329 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7330 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7335 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
7336 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
7341 (void) adjmsg(mp
, -len
);
7343 * adjmsg may have freed an mblk from the chain, hence
7344 * invalidate any hw checksum here. This will force IP to
7345 * calculate the checksum in sw, but only for this packet.
7347 DB_CKSUMFLAGS(mp
) = 0;
7348 IP_STAT(ill
->ill_ipst
, ip_multimblk
);
7354 * Check that the IPv4 opt_len is consistent with the packet and pullup
7358 ip_check_optlen(mblk_t
*mp
, ipha_t
*ipha
, uint_t opt_len
, uint_t pkt_len
,
7359 ip_recv_attr_t
*ira
)
7361 ill_t
*ill
= ira
->ira_ill
;
7364 /* Assume no IPv6 packets arrive over the IPv4 queue */
7365 if (IPH_HDR_VERSION(ipha
) != IPV4_VERSION
) {
7366 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7367 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInWrongIPVersion
);
7368 ip_drop_input("IPvN packet on IPv4 ill", mp
, ill
);
7373 if (opt_len
> (15 - IP_SIMPLE_HDR_LENGTH_IN_WORDS
)) {
7374 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7375 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7380 * Recompute complete header length and make sure we
7381 * have access to all of it.
7383 len
= ((size_t)opt_len
+ IP_SIMPLE_HDR_LENGTH_IN_WORDS
) << 2;
7384 if (len
> (mp
->b_wptr
- mp
->b_rptr
)) {
7385 if (len
> pkt_len
) {
7386 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7387 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7391 if (ip_pullup(mp
, len
, ira
) == NULL
) {
7392 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7393 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7402 * Returns a new ire, or the same ire, or NULL.
7403 * If a different IRE is returned, then it is held; the caller
7404 * needs to release it.
7405 * In no case is there any hold/release on the ire argument.
7408 ip_check_multihome(void *addr
, ire_t
*ire
, ill_t
*ill
)
7413 ip_stack_t
*ipst
= ill
->ill_ipst
;
7414 boolean_t strict_check
= B_FALSE
;
7417 * IPMP common case: if IRE and ILL are in the same group, there's no
7418 * issue (e.g. packet received on an underlying interface matched an
7419 * IRE_LOCAL on its associated group interface).
7421 ASSERT(ire
->ire_ill
!= NULL
);
7422 if (IS_IN_SAME_ILLGRP(ill
, ire
->ire_ill
))
7426 * Do another ire lookup here, using the ingress ill, to see if the
7427 * interface is in a usesrc group.
7428 * As long as the ills belong to the same group, we don't consider
7429 * them to be arriving on the wrong interface. Thus, if the switch
7430 * is doing inbound load spreading, we won't drop packets when the
7431 * ip*_strict_dst_multihoming switch is on.
7432 * We also need to check for IPIF_UNNUMBERED point2point interfaces
7433 * where the local address may not be unique. In this case we were
7434 * at the mercy of the initial ire lookup and the IRE_LOCAL it
7435 * actually returned. The new lookup, which is more specific, should
7436 * only find the IRE_LOCAL associated with the ingress ill if one
7439 if (ire
->ire_ipversion
== IPV4_VERSION
) {
7440 if (ipst
->ips_ip_strict_dst_multihoming
)
7441 strict_check
= B_TRUE
;
7442 new_ire
= ire_ftable_lookup_v4(*((ipaddr_t
*)addr
), 0, 0,
7443 IRE_LOCAL
, ill
, ALL_ZONES
,
7444 (MATCH_IRE_TYPE
|MATCH_IRE_ILL
), 0, ipst
, NULL
);
7446 ASSERT(!IN6_IS_ADDR_MULTICAST((in6_addr_t
*)addr
));
7447 if (ipst
->ips_ipv6_strict_dst_multihoming
)
7448 strict_check
= B_TRUE
;
7449 new_ire
= ire_ftable_lookup_v6((in6_addr_t
*)addr
, NULL
, NULL
,
7450 IRE_LOCAL
, ill
, ALL_ZONES
,
7451 (MATCH_IRE_TYPE
|MATCH_IRE_ILL
), 0, ipst
, NULL
);
7454 * If the same ire that was returned in ip_input() is found then this
7455 * is an indication that usesrc groups are in use. The packet
7456 * arrived on a different ill in the group than the one associated with
7457 * the destination address. If a different ire was found then the same
7458 * IP address must be hosted on multiple ills. This is possible with
7459 * unnumbered point2point interfaces. We switch to use this new ire in
7460 * order to have accurate interface statistics.
7462 if (new_ire
!= NULL
) {
7463 /* Note: held in one case but not the other? Caller handles */
7467 ire_refrele(new_ire
);
7472 * Chase pointers once and store locally.
7474 ASSERT(ire
->ire_ill
!= NULL
);
7475 ire_ill
= ire
->ire_ill
;
7476 ifindex
= ill
->ill_usesrc_ifindex
;
7479 * Check if it's a legal address on the 'usesrc' interface.
7480 * For IPMP data addresses the IRE_LOCAL is the upper, hence we
7481 * can just check phyint_ifindex.
7483 if (ifindex
!= 0 && ifindex
== ire_ill
->ill_phyint
->phyint_ifindex
) {
7488 * If the ip*_strict_dst_multihoming switch is on then we can
7489 * only accept this packet if the interface is marked as routing.
7491 if (!(strict_check
))
7494 if ((ill
->ill_flags
& ire
->ire_ill
->ill_flags
& ILLF_ROUTER
) != 0) {
7501 * This function is used to construct a mac_header_info_s from a
7502 * DL_UNITDATA_IND message.
7503 * The address fields in the mhi structure points into the message,
7504 * thus the caller can't use those fields after freeing the message.
7506 * We determine whether the packet received is a non-unicast packet
7507 * and in doing so, determine whether or not it is broadcast vs multicast.
7508 * For it to be a broadcast packet, we must have the appropriate mblk_t
7509 * hanging off the ill_t. If this is either not present or doesn't match
7510 * the destination mac address in the DL_UNITDATA_IND, the packet is deemed
7511 * to be multicast. Thus NICs that have no broadcast address (or no
7512 * capability for one, such as point to point links) cannot return as
7513 * the packet being broadcast.
7516 ip_dlur_to_mhi(ill_t
*ill
, mblk_t
*mb
, struct mac_header_info_s
*mhip
)
7518 dl_unitdata_ind_t
*ind
= (dl_unitdata_ind_t
*)mb
->b_rptr
;
7520 uint_t extra_offset
;
7522 bzero(mhip
, sizeof (struct mac_header_info_s
));
7524 mhip
->mhi_dsttype
= MAC_ADDRTYPE_UNICAST
;
7526 if (ill
->ill_sap_length
< 0)
7529 extra_offset
= ill
->ill_sap_length
;
7531 mhip
->mhi_daddr
= (uchar_t
*)ind
+ ind
->dl_dest_addr_offset
+
7533 mhip
->mhi_saddr
= (uchar_t
*)ind
+ ind
->dl_src_addr_offset
+
7536 if (!ind
->dl_group_address
)
7539 /* Multicast or broadcast */
7540 mhip
->mhi_dsttype
= MAC_ADDRTYPE_MULTICAST
;
7542 if (ind
->dl_dest_addr_offset
> sizeof (*ind
) &&
7543 ind
->dl_dest_addr_offset
+ ind
->dl_dest_addr_length
< MBLKL(mb
) &&
7544 (bmp
= ill
->ill_bcast_mp
) != NULL
) {
7545 dl_unitdata_req_t
*dlur
;
7546 uint8_t *bphys_addr
;
7548 dlur
= (dl_unitdata_req_t
*)bmp
->b_rptr
;
7549 bphys_addr
= (uchar_t
*)dlur
+ dlur
->dl_dest_addr_offset
+
7552 if (bcmp(mhip
->mhi_daddr
, bphys_addr
,
7553 ind
->dl_dest_addr_length
) == 0)
7554 mhip
->mhi_dsttype
= MAC_ADDRTYPE_BROADCAST
;
7559 * This function is used to construct a mac_header_info_s from a
7560 * M_DATA fastpath message from a DLPI driver.
7561 * The address fields in the mhi structure points into the message,
7562 * thus the caller can't use those fields after freeing the message.
7564 * We determine whether the packet received is a non-unicast packet
7565 * and in doing so, determine whether or not it is broadcast vs multicast.
7566 * For it to be a broadcast packet, we must have the appropriate mblk_t
7567 * hanging off the ill_t. If this is either not present or doesn't match
7568 * the destination mac address in the DL_UNITDATA_IND, the packet is deemed
7569 * to be multicast. Thus NICs that have no broadcast address (or no
7570 * capability for one, such as point to point links) cannot return as
7571 * the packet being broadcast.
7574 ip_mdata_to_mhi(ill_t
*ill
, mblk_t
*mp
, struct mac_header_info_s
*mhip
)
7577 struct ether_header
*pether
;
7579 bzero(mhip
, sizeof (struct mac_header_info_s
));
7581 mhip
->mhi_dsttype
= MAC_ADDRTYPE_UNICAST
;
7583 pether
= (struct ether_header
*)((char *)mp
->b_rptr
7584 - sizeof (struct ether_header
));
7587 * Make sure the interface is an ethernet type, since we don't
7588 * know the header format for anything but Ethernet. Also make
7589 * sure we are pointing correctly above db_base.
7591 if (ill
->ill_type
!= IFT_ETHER
)
7595 if ((uchar_t
*)pether
< mp
->b_datap
->db_base
)
7598 /* Is there a VLAN tag? */
7599 if (ill
->ill_isv6
) {
7600 if (pether
->ether_type
!= htons(ETHERTYPE_IPV6
)) {
7601 pether
= (struct ether_header
*)((char *)pether
- 4);
7605 if (pether
->ether_type
!= htons(ETHERTYPE_IP
)) {
7606 pether
= (struct ether_header
*)((char *)pether
- 4);
7610 mhip
->mhi_daddr
= (uchar_t
*)&pether
->ether_dhost
;
7611 mhip
->mhi_saddr
= (uchar_t
*)&pether
->ether_shost
;
7613 if (!(mhip
->mhi_daddr
[0] & 0x01))
7616 /* Multicast or broadcast */
7617 mhip
->mhi_dsttype
= MAC_ADDRTYPE_MULTICAST
;
7619 if ((bmp
= ill
->ill_bcast_mp
) != NULL
) {
7620 dl_unitdata_req_t
*dlur
;
7621 uint8_t *bphys_addr
;
7624 dlur
= (dl_unitdata_req_t
*)bmp
->b_rptr
;
7625 addrlen
= dlur
->dl_dest_addr_length
;
7626 if (ill
->ill_sap_length
< 0) {
7627 bphys_addr
= (uchar_t
*)dlur
+
7628 dlur
->dl_dest_addr_offset
;
7629 addrlen
+= ill
->ill_sap_length
;
7631 bphys_addr
= (uchar_t
*)dlur
+
7632 dlur
->dl_dest_addr_offset
+
7633 ill
->ill_sap_length
;
7634 addrlen
-= ill
->ill_sap_length
;
7636 if (bcmp(mhip
->mhi_daddr
, bphys_addr
, addrlen
) == 0)
7637 mhip
->mhi_dsttype
= MAC_ADDRTYPE_BROADCAST
;
7642 * Handle anything but M_DATA messages
7643 * We see the DL_UNITDATA_IND which are part
7644 * of the data path, and also the other messages from the driver.
7647 ip_rput_notdata(ill_t
*ill
, mblk_t
*mp
)
7650 struct iocblk
*iocp
;
7651 struct mac_header_info_s mhi
;
7653 switch (DB_TYPE(mp
)) {
7656 if (((dl_unitdata_ind_t
*)mp
->b_rptr
)->dl_primitive
!=
7658 /* Go handle anything other than data elsewhere. */
7659 ip_rput_dlpi(ill
, mp
);
7664 mp
= first_mp
->b_cont
;
7665 first_mp
->b_cont
= NULL
;
7671 ip_dlur_to_mhi(ill
, first_mp
, &mhi
);
7673 ip_input_v6(ill
, NULL
, mp
, &mhi
);
7675 ip_input(ill
, NULL
, mp
, &mhi
);
7677 /* Ditch the DLPI header. */
7682 iocp
= (struct iocblk
*)mp
->b_rptr
;
7683 switch (iocp
->ioc_cmd
) {
7684 case DL_IOC_HDR_INFO
:
7685 ill_fastpath_ack(ill
, mp
);
7688 putnext(ill
->ill_rq
, mp
);
7694 mutex_enter(&ill
->ill_lock
);
7695 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
7696 mutex_exit(&ill
->ill_lock
);
7700 ill_refhold_locked(ill
);
7701 mutex_exit(&ill
->ill_lock
);
7702 qwriter_ip(ill
, ill
->ill_rq
, mp
, ip_rput_other
, CUR_OP
,
7706 putnext(ill
->ill_rq
, mp
);
7709 ip1dbg(("got iocnak "));
7710 iocp
= (struct iocblk
*)mp
->b_rptr
;
7711 switch (iocp
->ioc_cmd
) {
7712 case DL_IOC_HDR_INFO
:
7713 ip_rput_other(NULL
, ill
->ill_rq
, mp
, NULL
);
7720 putnext(ill
->ill_rq
, mp
);
7725 /* Read side put procedure. Packets coming from the wire arrive here. */
7727 ip_rput(queue_t
*q
, mblk_t
*mp
)
7730 union DL_primitives
*dl
;
7732 ill
= (ill_t
*)q
->q_ptr
;
7734 if (ill
->ill_state_flags
& (ILL_CONDEMNED
| ILL_LL_SUBNET_PENDING
)) {
7736 * If things are opening or closing, only accept high-priority
7737 * DLPI messages. (On open ill->ill_ipif has not yet been
7738 * created; on close, things hanging off the ill may have been
7741 dl
= (union DL_primitives
*)mp
->b_rptr
;
7742 if (DB_TYPE(mp
) != M_PCPROTO
||
7743 dl
->dl_primitive
== DL_UNITDATA_IND
) {
7748 if (DB_TYPE(mp
) == M_DATA
) {
7749 struct mac_header_info_s mhi
;
7751 ip_mdata_to_mhi(ill
, mp
, &mhi
);
7752 ip_input(ill
, NULL
, mp
, &mhi
);
7754 ip_rput_notdata(ill
, mp
);
7760 * Move the information to a copy.
7763 ip_fix_dbref(mblk_t
*mp
, ip_recv_attr_t
*ira
)
7766 ill_t
*ill
= ira
->ira_ill
;
7767 ip_stack_t
*ipst
= ill
->ill_ipst
;
7769 IP_STAT(ipst
, ip_db_ref
);
7771 /* Make sure we have ira_l2src before we loose the original mblk */
7772 if (!(ira
->ira_flags
& IRAF_L2SRC_SET
))
7773 ip_setl2src(mp
, ira
, ira
->ira_rill
);
7777 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7778 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7782 /* preserve the hardware checksum flags and data, if present */
7783 if (DB_CKSUMFLAGS(mp
) != 0) {
7784 DB_CKSUMFLAGS(mp1
) = DB_CKSUMFLAGS(mp
);
7785 DB_CKSUMSTART(mp1
) = DB_CKSUMSTART(mp
);
7786 DB_CKSUMSTUFF(mp1
) = DB_CKSUMSTUFF(mp
);
7787 DB_CKSUMEND(mp1
) = DB_CKSUMEND(mp
);
7788 DB_CKSUM16(mp1
) = DB_CKSUM16(mp
);
7795 ip_dlpi_error(ill_t
*ill
, t_uscalar_t prim
, t_uscalar_t dl_err
,
7798 if (dl_err
== DL_SYSERR
) {
7799 (void) mi_strlog(ill
->ill_rq
, 1, SL_CONSOLE
|SL_ERROR
|SL_TRACE
,
7800 "%s: %s failed: DL_SYSERR (errno %u)\n",
7801 ill
->ill_name
, dl_primstr(prim
), err
);
7805 (void) mi_strlog(ill
->ill_rq
, 1, SL_CONSOLE
|SL_ERROR
|SL_TRACE
,
7806 "%s: %s failed: %s\n", ill
->ill_name
, dl_primstr(prim
),
7811 * ip_rput_dlpi is called by ip_rput to handle all DLPI messages other
7812 * than DL_UNITDATA_IND messages. If we need to process this message
7813 * exclusively, we call qwriter_ip, in which case we also need to call
7814 * ill_refhold before that, since qwriter_ip does an ill_refrele.
7817 ip_rput_dlpi(ill_t
*ill
, mblk_t
*mp
)
7819 dl_ok_ack_t
*dloa
= (dl_ok_ack_t
*)mp
->b_rptr
;
7820 dl_error_ack_t
*dlea
= (dl_error_ack_t
*)dloa
;
7821 queue_t
*q
= ill
->ill_rq
;
7822 t_uscalar_t prim
= dloa
->dl_primitive
;
7823 t_uscalar_t reqprim
= DL_PRIM_INVAL
;
7825 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi",
7826 char *, dl_primstr(prim
), ill_t
*, ill
);
7827 ip1dbg(("ip_rput_dlpi"));
7830 * If we received an ACK but didn't send a request for it, then it
7831 * can't be part of any pending operation; discard up-front.
7835 reqprim
= dlea
->dl_error_primitive
;
7836 ip2dbg(("ip_rput_dlpi(%s): DL_ERROR_ACK for %s (0x%x): %s "
7837 "(0x%x), unix %u\n", ill
->ill_name
, dl_primstr(reqprim
),
7838 reqprim
, dl_errstr(dlea
->dl_errno
), dlea
->dl_errno
,
7839 dlea
->dl_unix_errno
));
7842 reqprim
= dloa
->dl_correct_primitive
;
7845 reqprim
= DL_INFO_REQ
;
7848 reqprim
= DL_BIND_REQ
;
7850 case DL_PHYS_ADDR_ACK
:
7851 reqprim
= DL_PHYS_ADDR_REQ
;
7854 reqprim
= DL_NOTIFY_REQ
;
7856 case DL_CAPABILITY_ACK
:
7857 reqprim
= DL_CAPABILITY_REQ
;
7861 if (prim
!= DL_NOTIFY_IND
) {
7862 if (reqprim
== DL_PRIM_INVAL
||
7863 !ill_dlpi_pending(ill
, reqprim
)) {
7864 /* Not a DLPI message we support or expected */
7868 ip1dbg(("ip_rput: received %s for %s\n", dl_primstr(prim
),
7869 dl_primstr(reqprim
)));
7875 * NOTE: we mark the unbind as complete even if we got a
7876 * DL_ERROR_ACK, since there's not much else we can do.
7878 mutex_enter(&ill
->ill_lock
);
7879 ill
->ill_state_flags
&= ~ILL_DL_UNBIND_IN_PROGRESS
;
7880 cv_signal(&ill
->ill_cv
);
7881 mutex_exit(&ill
->ill_lock
);
7884 case DL_ENABMULTI_REQ
:
7885 if (prim
== DL_OK_ACK
) {
7886 if (ill
->ill_dlpi_multicast_state
== IDS_INPROGRESS
)
7887 ill
->ill_dlpi_multicast_state
= IDS_OK
;
7893 * The message is one we're waiting for (or DL_NOTIFY_IND), but we
7894 * need to become writer to continue to process it. Because an
7895 * exclusive operation doesn't complete until replies to all queued
7896 * DLPI messages have been received, we know we're in the middle of an
7897 * exclusive operation and pass CUR_OP (except for DL_NOTIFY_IND).
7899 * As required by qwriter_ip(), we refhold the ill; it will refrele.
7900 * Since this is on the ill stream we unconditionally bump up the
7901 * refcount without doing ILL_CAN_LOOKUP().
7904 if (prim
== DL_NOTIFY_IND
)
7905 qwriter_ip(ill
, q
, mp
, ip_rput_dlpi_writer
, NEW_OP
, B_FALSE
);
7907 qwriter_ip(ill
, q
, mp
, ip_rput_dlpi_writer
, CUR_OP
, B_FALSE
);
7911 * Handling of DLPI messages that require exclusive access to the ipsq.
7913 * Need to do ipsq_pending_mp_get on ioctl completion, which could
7914 * happen here. (along with mi_copy_done)
7918 ip_rput_dlpi_writer(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
7920 dl_ok_ack_t
*dloa
= (dl_ok_ack_t
*)mp
->b_rptr
;
7921 dl_error_ack_t
*dlea
= (dl_error_ack_t
*)dloa
;
7923 ill_t
*ill
= (ill_t
*)q
->q_ptr
;
7924 ipif_t
*ipif
= NULL
;
7926 conn_t
*connp
= NULL
;
7927 t_uscalar_t paddrreq
;
7930 boolean_t ioctl_aborted
= B_FALSE
;
7931 boolean_t log
= B_TRUE
;
7933 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi_writer",
7934 char *, dl_primstr(dloa
->dl_primitive
), ill_t
*, ill
);
7936 ip1dbg(("ip_rput_dlpi_writer .."));
7937 ASSERT(ipsq
->ipsq_xop
== ill
->ill_phyint
->phyint_ipsq
->ipsq_xop
);
7938 ASSERT(IAM_WRITER_ILL(ill
));
7940 ipif
= ipsq
->ipsq_xop
->ipx_pending_ipif
;
7942 * The current ioctl could have been aborted by the user and a new
7943 * ioctl to bring up another ill could have started. We could still
7944 * get a response from the driver later.
7946 if (ipif
!= NULL
&& ipif
->ipif_ill
!= ill
)
7947 ioctl_aborted
= B_TRUE
;
7949 switch (dloa
->dl_primitive
) {
7951 ip1dbg(("ip_rput_dlpi_writer: got DL_ERROR_ACK for %s\n",
7952 dl_primstr(dlea
->dl_error_primitive
)));
7954 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi_writer error",
7955 char *, dl_primstr(dlea
->dl_error_primitive
),
7958 switch (dlea
->dl_error_primitive
) {
7959 case DL_DISABMULTI_REQ
:
7960 ill_dlpi_done(ill
, dlea
->dl_error_primitive
);
7962 case DL_PROMISCON_REQ
:
7963 case DL_PROMISCOFF_REQ
:
7967 ill_dlpi_done(ill
, dlea
->dl_error_primitive
);
7970 ill_dlpi_done(ill
, DL_NOTIFY_REQ
);
7973 case DL_PHYS_ADDR_REQ
:
7975 * For IPv6 only, there are two additional
7976 * phys_addr_req's sent to the driver to get the
7977 * IPv6 token and lla. This allows IP to acquire
7978 * the hardware address format for a given interface
7979 * without having built in knowledge of the hardware
7980 * address. ill_phys_addr_pend keeps track of the last
7981 * DL_PAR sent so we know which response we are
7982 * dealing with. ill_dlpi_done will update
7983 * ill_phys_addr_pend when it sends the next req.
7984 * We don't complete the IOCTL until all three DL_PARs
7985 * have been attempted, so set *_len to 0 and break.
7987 paddrreq
= ill
->ill_phys_addr_pend
;
7988 ill_dlpi_done(ill
, DL_PHYS_ADDR_REQ
);
7989 if (paddrreq
== DL_IPV6_TOKEN
) {
7990 ill
->ill_token_length
= 0;
7993 } else if (paddrreq
== DL_IPV6_LINK_LAYER_ADDR
) {
7994 ill
->ill_nd_lla_len
= 0;
7999 * Something went wrong with the DL_PHYS_ADDR_REQ.
8000 * We presumably have an IOCTL hanging out waiting
8001 * for completion. Find it and complete the IOCTL
8002 * with the error noted.
8003 * However, ill_dl_phys was called on an ill queue
8004 * (from SIOCSLIFNAME), thus conn_pending_ill is not
8005 * set. But the ioctl is known to be pending on ill_wq.
8007 if (!ill
->ill_ifname_pending
)
8009 ill
->ill_ifname_pending
= 0;
8011 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8014 * This operation (SIOCSLIFNAME) must have
8015 * happened on the ill. Assert there is no conn
8017 ASSERT(connp
== NULL
);
8022 ill_dlpi_done(ill
, DL_BIND_REQ
);
8023 if (ill
->ill_ifname_pending
)
8025 mutex_enter(&ill
->ill_lock
);
8026 ill
->ill_state_flags
&= ~ILL_DOWN_IN_PROGRESS
;
8027 mutex_exit(&ill
->ill_lock
);
8029 * Something went wrong with the bind. We presumably
8030 * have an IOCTL hanging out waiting for completion.
8031 * Find it, take down the interface that was coming
8032 * up, and complete the IOCTL with the error noted.
8035 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8038 * This might be a result of a DL_NOTE_REPLUMB
8039 * notification. In that case, connp is NULL.
8042 q
= CONNP_TO_WQ(connp
);
8044 (void) ipif_down(ipif
, NULL
, NULL
);
8045 /* error is set below the switch */
8048 case DL_ENABMULTI_REQ
:
8049 ill_dlpi_done(ill
, DL_ENABMULTI_REQ
);
8051 if (ill
->ill_dlpi_multicast_state
== IDS_INPROGRESS
)
8052 ill
->ill_dlpi_multicast_state
= IDS_FAILED
;
8053 if (ill
->ill_dlpi_multicast_state
== IDS_FAILED
) {
8055 printf("ip: joining multicasts failed (%d)"
8056 " on %s - will use link layer "
8057 "broadcasts for multicast\n",
8058 dlea
->dl_errno
, ill
->ill_name
);
8061 * Set up for multi_bcast; We are the
8062 * writer, so ok to access ill->ill_ipif
8065 mutex_enter(&ill
->ill_phyint
->phyint_lock
);
8066 ill
->ill_phyint
->phyint_flags
|=
8068 mutex_exit(&ill
->ill_phyint
->phyint_lock
);
8071 freemsg(mp
); /* Don't want to pass this up */
8073 case DL_CAPABILITY_REQ
:
8074 ip1dbg(("ip_rput_dlpi_writer: got DL_ERROR_ACK for "
8075 "DL_CAPABILITY REQ\n"));
8076 if (ill
->ill_dlpi_capab_state
== IDCS_PROBE_SENT
)
8077 ill
->ill_dlpi_capab_state
= IDCS_FAILED
;
8078 ill_capability_done(ill
);
8083 * Note the error for IOCTL completion (mp1 is set when
8084 * ready to complete ioctl). If ill_ifname_pending_err is
8085 * set, an error occured during plumbing (ill_ifname_pending),
8086 * so we want to report that error.
8088 * NOTE: there are two addtional DL_PHYS_ADDR_REQ's
8089 * (DL_IPV6_TOKEN and DL_IPV6_LINK_LAYER_ADDR) that are
8090 * expected to get errack'd if the driver doesn't support
8091 * these flags (e.g. ethernet). log will be set to B_FALSE
8092 * if these error conditions are encountered.
8095 if (ill
->ill_ifname_pending_err
!= 0) {
8096 err
= ill
->ill_ifname_pending_err
;
8097 ill
->ill_ifname_pending_err
= 0;
8099 err
= dlea
->dl_unix_errno
?
8100 dlea
->dl_unix_errno
: ENXIO
;
8103 * If we're plumbing an interface and an error hasn't already
8104 * been saved, set ill_ifname_pending_err to the error passed
8105 * up. Ignore the error if log is B_FALSE (see comment above).
8107 } else if (log
&& ill
->ill_ifname_pending
&&
8108 ill
->ill_ifname_pending_err
== 0) {
8109 ill
->ill_ifname_pending_err
= dlea
->dl_unix_errno
?
8110 dlea
->dl_unix_errno
: ENXIO
;
8114 ip_dlpi_error(ill
, dlea
->dl_error_primitive
,
8115 dlea
->dl_errno
, dlea
->dl_unix_errno
);
8117 case DL_CAPABILITY_ACK
:
8118 ill_capability_ack(ill
, mp
);
8120 * The message has been handed off to ill_capability_ack
8121 * and must not be freed below
8127 /* Call a routine to handle this one. */
8128 ill_dlpi_done(ill
, DL_INFO_REQ
);
8129 ip_ll_subnet_defaults(ill
, mp
);
8130 ASSERT(!MUTEX_HELD(&ill
->ill_phyint
->phyint_ipsq
->ipsq_lock
));
8134 * We should have an IOCTL waiting on this unless
8135 * sent by ill_dl_phys, in which case just return
8137 ill_dlpi_done(ill
, DL_BIND_REQ
);
8139 if (ill
->ill_ifname_pending
) {
8140 DTRACE_PROBE2(ip__rput__dlpi__ifname__pending
,
8141 ill_t
*, ill
, mblk_t
*, mp
);
8144 mutex_enter(&ill
->ill_lock
);
8146 ill
->ill_state_flags
&= ~ILL_DOWN_IN_PROGRESS
;
8147 mutex_exit(&ill
->ill_lock
);
8150 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8152 DTRACE_PROBE1(ip__rput__dlpi__no__mblk
, ill_t
*, ill
);
8156 * mp1 was added by ill_dl_up(). if that is a result of
8157 * a DL_NOTE_REPLUMB notification, connp could be NULL.
8160 q
= CONNP_TO_WQ(connp
);
8162 * We are exclusive. So nothing can change even after
8163 * we get the pending mp.
8165 ip1dbg(("ip_rput_dlpi: bind_ack %s\n", ill
->ill_name
));
8166 DTRACE_PROBE1(ip__rput__dlpi__bind__ack
, ill_t
*, ill
);
8167 ill_nic_event_dispatch(ill
, 0, NE_UP
, NULL
, 0);
8170 * Now bring up the resolver; when that is complete, we'll
8171 * create IREs. Note that we intentionally mirror what
8172 * ipif_up() would have done, because we got here by way of
8173 * ill_dl_up(), which stopped ipif_up()'s processing.
8175 if (ill
->ill_isv6
) {
8178 * Unlike ARP which has to do another bind
8179 * and attach, once we get here we are
8182 (void) ipif_resolver_up(ipif
, Res_act_initial
);
8183 if ((err
= ipif_ndp_up(ipif
, B_TRUE
)) == 0)
8184 err
= ipif_up_done_v6(ipif
);
8185 } else if (ill
->ill_net_type
== IRE_IF_RESOLVER
) {
8187 * ARP and other v4 external resolvers.
8188 * Leave the pending mblk intact so that
8189 * the ioctl completes in ip_rput().
8192 mutex_enter(&connp
->conn_lock
);
8193 mutex_enter(&ill
->ill_lock
);
8194 success
= ipsq_pending_mp_add(connp
, ipif
, q
, mp1
, 0);
8195 mutex_exit(&ill
->ill_lock
);
8197 mutex_exit(&connp
->conn_lock
);
8199 err
= ipif_resolver_up(ipif
, Res_act_initial
);
8200 if (err
== EINPROGRESS
) {
8204 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8206 /* The conn has started closing */
8211 * This one is complete. Reply to pending ioctl.
8213 (void) ipif_resolver_up(ipif
, Res_act_initial
);
8214 err
= ipif_up_done(ipif
);
8217 if ((err
== 0) && (ill
->ill_up_ipifs
)) {
8218 err
= ill_up_ipifs(ill
, q
, mp1
);
8219 if (err
== EINPROGRESS
) {
8226 * If we have a moved ipif to bring up, and everything has
8227 * succeeded to this point, bring it up on the IPMP ill.
8228 * Otherwise, leave it down -- the admin can try to bring it
8229 * up by hand if need be.
8231 if (ill
->ill_move_ipif
!= NULL
) {
8233 ill
->ill_move_ipif
= NULL
;
8235 ipif
= ill
->ill_move_ipif
;
8236 ill
->ill_move_ipif
= NULL
;
8237 err
= ipif_up(ipif
, q
, mp1
);
8238 if (err
== EINPROGRESS
) {
8246 case DL_NOTIFY_IND
: {
8247 dl_notify_ind_t
*notify
= (dl_notify_ind_t
*)mp
->b_rptr
;
8248 uint_t orig_mtu
, orig_mc_mtu
;
8250 switch (notify
->dl_notification
) {
8251 case DL_NOTE_PHYS_ADDR
:
8252 err
= ill_set_phys_addr(ill
, mp
);
8255 case DL_NOTE_REPLUMB
:
8257 * Directly return after calling ill_replumb().
8258 * Note that we should not free mp as it is reused
8259 * in the ill_replumb() function.
8261 err
= ill_replumb(ill
, mp
);
8264 case DL_NOTE_FASTPATH_FLUSH
:
8265 nce_flush(ill
, B_FALSE
);
8268 case DL_NOTE_SDU_SIZE
:
8269 case DL_NOTE_SDU_SIZE2
:
8271 * The dce and fragmentation code can cope with
8272 * this changing while packets are being sent.
8273 * When packets are sent ip_output will discover
8276 * Change the MTU size of the interface.
8278 mutex_enter(&ill
->ill_lock
);
8279 orig_mtu
= ill
->ill_mtu
;
8280 orig_mc_mtu
= ill
->ill_mc_mtu
;
8281 switch (notify
->dl_notification
) {
8282 case DL_NOTE_SDU_SIZE
:
8283 ill
->ill_current_frag
=
8284 (uint_t
)notify
->dl_data
;
8285 ill
->ill_mc_mtu
= (uint_t
)notify
->dl_data
;
8287 case DL_NOTE_SDU_SIZE2
:
8288 ill
->ill_current_frag
=
8289 (uint_t
)notify
->dl_data1
;
8290 ill
->ill_mc_mtu
= (uint_t
)notify
->dl_data2
;
8293 if (ill
->ill_current_frag
> ill
->ill_max_frag
)
8294 ill
->ill_max_frag
= ill
->ill_current_frag
;
8296 if (!(ill
->ill_flags
& ILLF_FIXEDMTU
)) {
8297 ill
->ill_mtu
= ill
->ill_current_frag
;
8300 * If ill_user_mtu was set (via
8301 * SIOCSLIFLNKINFO), clamp ill_mtu at it.
8303 if (ill
->ill_user_mtu
!= 0 &&
8304 ill
->ill_user_mtu
< ill
->ill_mtu
)
8305 ill
->ill_mtu
= ill
->ill_user_mtu
;
8307 if (ill
->ill_user_mtu
!= 0 &&
8308 ill
->ill_user_mtu
< ill
->ill_mc_mtu
)
8309 ill
->ill_mc_mtu
= ill
->ill_user_mtu
;
8311 if (ill
->ill_isv6
) {
8312 if (ill
->ill_mtu
< IPV6_MIN_MTU
)
8313 ill
->ill_mtu
= IPV6_MIN_MTU
;
8314 if (ill
->ill_mc_mtu
< IPV6_MIN_MTU
)
8315 ill
->ill_mc_mtu
= IPV6_MIN_MTU
;
8317 if (ill
->ill_mtu
< IP_MIN_MTU
)
8318 ill
->ill_mtu
= IP_MIN_MTU
;
8319 if (ill
->ill_mc_mtu
< IP_MIN_MTU
)
8320 ill
->ill_mc_mtu
= IP_MIN_MTU
;
8322 } else if (ill
->ill_mc_mtu
> ill
->ill_mtu
) {
8323 ill
->ill_mc_mtu
= ill
->ill_mtu
;
8326 mutex_exit(&ill
->ill_lock
);
8328 * Make sure all dce_generation checks find out
8329 * that ill_mtu/ill_mc_mtu has changed.
8331 if (orig_mtu
!= ill
->ill_mtu
||
8332 orig_mc_mtu
!= ill
->ill_mc_mtu
) {
8333 dce_increment_all_generations(ill
->ill_isv6
,
8338 * Refresh IPMP meta-interface MTU if necessary.
8340 if (IS_UNDER_IPMP(ill
))
8341 ipmp_illgrp_refresh_mtu(ill
->ill_grp
);
8344 case DL_NOTE_LINK_UP
:
8345 case DL_NOTE_LINK_DOWN
: {
8347 * We are writer. ill / phyint / ipsq assocs stable.
8348 * The RUNNING flag reflects the state of the link.
8350 phyint_t
*phyint
= ill
->ill_phyint
;
8351 uint64_t new_phyint_flags
;
8352 boolean_t changed
= B_FALSE
;
8355 went_up
= notify
->dl_notification
== DL_NOTE_LINK_UP
;
8356 mutex_enter(&phyint
->phyint_lock
);
8358 new_phyint_flags
= went_up
?
8359 phyint
->phyint_flags
| PHYI_RUNNING
:
8360 phyint
->phyint_flags
& ~PHYI_RUNNING
;
8363 new_phyint_flags
= went_up
?
8364 new_phyint_flags
& ~PHYI_FAILED
:
8365 new_phyint_flags
| PHYI_FAILED
;
8368 if (new_phyint_flags
!= phyint
->phyint_flags
) {
8369 phyint
->phyint_flags
= new_phyint_flags
;
8372 mutex_exit(&phyint
->phyint_lock
);
8374 * ill_restart_dad handles the DAD restart and routing
8375 * socket notification logic.
8378 ill_restart_dad(phyint
->phyint_illv4
, went_up
);
8379 ill_restart_dad(phyint
->phyint_illv6
, went_up
);
8383 case DL_NOTE_PROMISC_ON_PHYS
: {
8384 phyint_t
*phyint
= ill
->ill_phyint
;
8386 mutex_enter(&phyint
->phyint_lock
);
8387 phyint
->phyint_flags
|= PHYI_PROMISC
;
8388 mutex_exit(&phyint
->phyint_lock
);
8391 case DL_NOTE_PROMISC_OFF_PHYS
: {
8392 phyint_t
*phyint
= ill
->ill_phyint
;
8394 mutex_enter(&phyint
->phyint_lock
);
8395 phyint
->phyint_flags
&= ~PHYI_PROMISC
;
8396 mutex_exit(&phyint
->phyint_lock
);
8399 case DL_NOTE_CAPAB_RENEG
:
8401 * Something changed on the driver side.
8402 * It wants us to renegotiate the capabilities
8403 * on this ill. One possible cause is the aggregation
8404 * interface under us where a port got added or
8407 * If the capability negotiation is already done
8408 * or is in progress, reset the capabilities and
8409 * mark the ill's ill_capab_reneg to be B_TRUE,
8410 * so that when the ack comes back, we can start
8411 * the renegotiation process.
8413 * Note that if ill_capab_reneg is already B_TRUE
8414 * (ill_dlpi_capab_state is IDS_UNKNOWN in this case),
8415 * the capability resetting request has been sent
8416 * and the renegotiation has not been started yet;
8417 * nothing needs to be done in this case.
8419 ipsq_current_start(ipsq
, ill
->ill_ipif
, 0);
8420 ill_capability_reset(ill
, B_TRUE
);
8421 ipsq_current_finish(ipsq
);
8424 case DL_NOTE_ALLOWED_IPS
:
8425 ill_set_allowed_ips(ill
, mp
);
8428 ip0dbg(("ip_rput_dlpi_writer: unknown notification "
8429 "type 0x%x for DL_NOTIFY_IND\n",
8430 notify
->dl_notification
));
8435 * As this is an asynchronous operation, we
8436 * should not call ill_dlpi_done
8440 case DL_NOTIFY_ACK
: {
8441 dl_notify_ack_t
*noteack
= (dl_notify_ack_t
*)mp
->b_rptr
;
8443 if (noteack
->dl_notifications
& DL_NOTE_LINK_UP
)
8444 ill
->ill_note_link
= 1;
8445 ill_dlpi_done(ill
, DL_NOTIFY_REQ
);
8448 case DL_PHYS_ADDR_ACK
: {
8450 * As part of plumbing the interface via SIOCSLIFNAME,
8451 * ill_dl_phys() will queue a series of DL_PHYS_ADDR_REQs,
8452 * whose answers we receive here. As each answer is received,
8453 * we call ill_dlpi_done() to dispatch the next request as
8454 * we're processing the current one. Once all answers have
8455 * been received, we use ipsq_pending_mp_get() to dequeue the
8456 * outstanding IOCTL and reply to it. (Because ill_dl_phys()
8457 * is invoked from an ill queue, conn_oper_pending_ill is not
8458 * available, but we know the ioctl is pending on ill_wq.)
8460 uint_t paddrlen
, paddroff
;
8463 paddrreq
= ill
->ill_phys_addr_pend
;
8464 paddrlen
= ((dl_phys_addr_ack_t
*)mp
->b_rptr
)->dl_addr_length
;
8465 paddroff
= ((dl_phys_addr_ack_t
*)mp
->b_rptr
)->dl_addr_offset
;
8466 addr
= mp
->b_rptr
+ paddroff
;
8468 ill_dlpi_done(ill
, DL_PHYS_ADDR_REQ
);
8469 if (paddrreq
== DL_IPV6_TOKEN
) {
8471 * bcopy to low-order bits of ill_token
8473 * XXX Temporary hack - currently, all known tokens
8474 * are 64 bits, so I'll cheat for the moment.
8476 bcopy(addr
, &ill
->ill_token
.s6_addr32
[2], paddrlen
);
8477 ill
->ill_token_length
= paddrlen
;
8479 } else if (paddrreq
== DL_IPV6_LINK_LAYER_ADDR
) {
8480 ASSERT(ill
->ill_nd_lla_mp
== NULL
);
8481 ill_set_ndmp(ill
, mp
, paddroff
, paddrlen
);
8484 } else if (paddrreq
== DL_CURR_DEST_ADDR
) {
8485 ASSERT(ill
->ill_dest_addr_mp
== NULL
);
8486 ill
->ill_dest_addr_mp
= mp
;
8487 ill
->ill_dest_addr
= addr
;
8489 if (ill
->ill_isv6
) {
8490 ill_setdesttoken(ill
);
8491 ipif_setdestlinklocal(ill
->ill_ipif
);
8496 ASSERT(paddrreq
== DL_CURR_PHYS_ADDR
);
8497 ASSERT(ill
->ill_phys_addr_mp
== NULL
);
8498 if (!ill
->ill_ifname_pending
)
8500 ill
->ill_ifname_pending
= 0;
8502 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8504 ASSERT(connp
== NULL
);
8508 * If any error acks received during the plumbing sequence,
8509 * ill_ifname_pending_err will be set. Break out and send up
8510 * the error to the pending ioctl.
8512 if (ill
->ill_ifname_pending_err
!= 0) {
8513 err
= ill
->ill_ifname_pending_err
;
8514 ill
->ill_ifname_pending_err
= 0;
8518 ill
->ill_phys_addr_mp
= mp
;
8519 ill
->ill_phys_addr
= (paddrlen
== 0 ? NULL
: addr
);
8523 * If paddrlen or ill_phys_addr_length is zero, the DLPI
8524 * provider doesn't support physical addresses. We check both
8525 * paddrlen and ill_phys_addr_length because sppp (PPP) does
8526 * not have physical addresses, but historically adversises a
8527 * physical address length of 0 in its DL_INFO_ACK, but 6 in
8528 * its DL_PHYS_ADDR_ACK.
8530 if (paddrlen
== 0 || ill
->ill_phys_addr_length
== 0) {
8531 ill
->ill_phys_addr
= NULL
;
8532 } else if (paddrlen
!= ill
->ill_phys_addr_length
) {
8533 ip0dbg(("DL_PHYS_ADDR_ACK: got addrlen %d, expected %d",
8534 paddrlen
, ill
->ill_phys_addr_length
));
8539 if (ill
->ill_nd_lla_mp
== NULL
) {
8540 if ((mp_hw
= copyb(ill
->ill_phys_addr_mp
)) == NULL
) {
8544 ill_set_ndmp(ill
, mp_hw
, paddroff
, paddrlen
);
8547 if (ill
->ill_isv6
) {
8548 ill_setdefaulttoken(ill
);
8549 ipif_setlinklocal(ill
->ill_ipif
);
8554 ip2dbg(("DL_OK_ACK %s (0x%x)\n",
8555 dl_primstr((int)dloa
->dl_correct_primitive
),
8556 dloa
->dl_correct_primitive
));
8557 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi_writer ok",
8558 char *, dl_primstr(dloa
->dl_correct_primitive
),
8561 switch (dloa
->dl_correct_primitive
) {
8562 case DL_ENABMULTI_REQ
:
8563 case DL_DISABMULTI_REQ
:
8564 ill_dlpi_done(ill
, dloa
->dl_correct_primitive
);
8566 case DL_PROMISCON_REQ
:
8567 case DL_PROMISCOFF_REQ
:
8570 ill_dlpi_done(ill
, dloa
->dl_correct_primitive
);
8583 * The operation must complete without EINPROGRESS since
8584 * ipsq_pending_mp_get() has removed the mblk (mp1). Otherwise,
8585 * the operation will be stuck forever inside the IPSQ.
8587 ASSERT(err
!= EINPROGRESS
);
8589 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_rput_dlpi_writer finish",
8590 int, ipsq
->ipsq_xop
->ipx_current_ioctl
, ill_t
*, ill
,
8593 switch (ipsq
->ipsq_xop
->ipx_current_ioctl
) {
8595 ipsq_current_finish(ipsq
);
8600 ill_t
*ill_other
= ILL_OTHER(ill
);
8603 * If SIOCSLIFNAME or IF_UNITSEL is about to succeed, and the
8604 * ill has a peer which is in an IPMP group, then place ill
8605 * into the same group. One catch: although ifconfig plumbs
8606 * the appropriate IPMP meta-interface prior to plumbing this
8607 * ill, it is possible for multiple ifconfig applications to
8608 * race (or for another application to adjust plumbing), in
8609 * which case the IPMP meta-interface we need will be missing.
8610 * If so, kick the phyint out of the group.
8612 if (err
== 0 && ill_other
!= NULL
&& IS_UNDER_IPMP(ill_other
)) {
8613 ipmp_grp_t
*grp
= ill
->ill_phyint
->phyint_grp
;
8614 ipmp_illgrp_t
*illg
;
8616 illg
= ill
->ill_isv6
? grp
->gr_v6
: grp
->gr_v4
;
8618 ipmp_phyint_leave_grp(ill
->ill_phyint
);
8620 ipmp_ill_join_illgrp(ill
, illg
);
8623 if (ipsq
->ipsq_xop
->ipx_current_ioctl
== IF_UNITSEL
)
8624 ip_ioctl_finish(q
, mp1
, err
, NO_COPYOUT
, ipsq
);
8626 ip_ioctl_finish(q
, mp1
, err
, COPYOUT
, ipsq
);
8630 ip_ioctl_finish(q
, mp1
, err
, COPYOUT
, ipsq
);
8634 ip_ioctl_finish(q
, mp1
, err
, NO_COPYOUT
, ipsq
);
8640 * ip_rput_other is called by ip_rput to handle messages modifying the global
8641 * state in IP. If 'ipsq' is non-NULL, caller is writer on it.
8645 ip_rput_other(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
8647 ill_t
*ill
= q
->q_ptr
;
8648 struct iocblk
*iocp
;
8650 ip1dbg(("ip_rput_other "));
8652 ASSERT(IAM_WRITER_IPSQ(ipsq
));
8653 ASSERT(ipsq
->ipsq_xop
==
8654 ill
->ill_phyint
->phyint_ipsq
->ipsq_xop
);
8657 switch (mp
->b_datap
->db_type
) {
8661 * The device has a problem. We force the ILL down. It can
8662 * be brought up again manually using SIOCSIFFLAGS (via
8663 * ifconfig or equivalent).
8665 ASSERT(ipsq
!= NULL
);
8666 if (mp
->b_rptr
< mp
->b_wptr
)
8667 ill
->ill_error
= (int)(*mp
->b_rptr
& 0xFF);
8668 if (ill
->ill_error
== 0)
8669 ill
->ill_error
= ENXIO
;
8670 if (!ill_down_start(q
, mp
))
8672 ipif_all_down_tail(ipsq
, q
, mp
, NULL
);
8675 iocp
= (struct iocblk
*)mp
->b_rptr
;
8677 ASSERT(iocp
->ioc_cmd
== DL_IOC_HDR_INFO
);
8679 * If this was the first attempt, turn off the fastpath
8682 mutex_enter(&ill
->ill_lock
);
8683 if (ill
->ill_dlpi_fastpath_state
== IDS_INPROGRESS
) {
8684 ill
->ill_dlpi_fastpath_state
= IDS_FAILED
;
8685 mutex_exit(&ill
->ill_lock
);
8687 * don't flush the nce_t entries: we use them
8688 * as an index to the ncec itself.
8690 ip1dbg(("ip_rput: DLPI fastpath off on interface %s\n",
8693 mutex_exit(&ill
->ill_lock
);
8705 * Update any source route, record route or timestamp options
8706 * When it fails it has consumed the message and BUMPed the MIB.
8709 ip_forward_options(mblk_t
*mp
, ipha_t
*ipha
, ill_t
*dst_ill
,
8710 ip_recv_attr_t
*ira
)
8720 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
8722 ip2dbg(("ip_forward_options\n"));
8723 dst
= ipha
->ipha_dst
;
8724 for (optval
= ipoptp_first(&opts
, ipha
);
8725 optval
!= IPOPT_EOL
;
8726 optval
= ipoptp_next(&opts
)) {
8727 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
8728 opt
= opts
.ipoptp_cur
;
8729 optlen
= opts
.ipoptp_len
;
8730 ip2dbg(("ip_forward_options: opt %d, len %d\n",
8731 optval
, opts
.ipoptp_len
));
8736 /* Check if adminstratively disabled */
8737 if (!ipst
->ips_ip_forward_src_routed
) {
8738 BUMP_MIB(dst_ill
->ill_ip_mib
,
8739 ipIfStatsForwProhibits
);
8740 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED",
8742 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
,
8746 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
8748 * Must be partial since ip_input_options
8749 * checked for strict.
8753 off
= opt
[IPOPT_OFFSET
];
8756 if (optlen
< IP_ADDR_LEN
||
8757 off
> optlen
- IP_ADDR_LEN
) {
8758 /* End of source route */
8760 "ip_forward_options: end of SR\n"));
8763 /* Pick a reasonable address on the outbound if */
8764 ASSERT(dst_ill
!= NULL
);
8765 if (ip_select_source_v4(dst_ill
, INADDR_ANY
, dst
,
8766 INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
, NULL
,
8768 /* No source! Shouldn't happen */
8769 ifaddr
= INADDR_ANY
;
8771 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
8772 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
8773 ip1dbg(("ip_forward_options: next hop 0x%x\n",
8777 * Check if our address is present more than
8778 * once as consecutive hops in source route.
8780 if (ip_type_v4(dst
, ipst
) == IRE_LOCAL
) {
8782 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8785 ipha
->ipha_dst
= dst
;
8786 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8789 off
= opt
[IPOPT_OFFSET
];
8791 if (optlen
< IP_ADDR_LEN
||
8792 off
> optlen
- IP_ADDR_LEN
) {
8793 /* No more room - ignore */
8795 "ip_forward_options: end of RR\n"));
8798 /* Pick a reasonable address on the outbound if */
8799 ASSERT(dst_ill
!= NULL
);
8800 if (ip_select_source_v4(dst_ill
, INADDR_ANY
, dst
,
8801 INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
, NULL
,
8803 /* No source! Shouldn't happen */
8804 ifaddr
= INADDR_ANY
;
8806 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
8807 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8810 /* Insert timestamp if there is room */
8811 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
8812 case IPOPT_TS_TSONLY
:
8813 off
= IPOPT_TS_TIMELEN
;
8815 case IPOPT_TS_PRESPEC
:
8816 case IPOPT_TS_PRESPEC_RFC791
:
8817 /* Verify that the address matched */
8818 off
= opt
[IPOPT_OFFSET
] - 1;
8819 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
8820 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
8825 case IPOPT_TS_TSANDADDR
:
8826 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
8830 * ip_*put_options should have already
8831 * dropped this packet.
8833 cmn_err(CE_PANIC
, "ip_forward_options: "
8834 "unknown IT - bug in ip_input_options?\n");
8835 return (B_TRUE
); /* Keep "lint" happy */
8837 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
) {
8838 /* Increase overflow counter */
8839 off
= (opt
[IPOPT_POS_OV_FLG
] >> 4) + 1;
8840 opt
[IPOPT_POS_OV_FLG
] =
8841 (uint8_t)((opt
[IPOPT_POS_OV_FLG
] & 0x0F) |
8845 off
= opt
[IPOPT_OFFSET
] - 1;
8846 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
8847 case IPOPT_TS_PRESPEC
:
8848 case IPOPT_TS_PRESPEC_RFC791
:
8849 case IPOPT_TS_TSANDADDR
:
8850 /* Pick a reasonable addr on the outbound if */
8851 ASSERT(dst_ill
!= NULL
);
8852 if (ip_select_source_v4(dst_ill
, INADDR_ANY
,
8853 dst
, INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
,
8855 /* No source! Shouldn't happen */
8856 ifaddr
= INADDR_ANY
;
8858 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
8859 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8861 case IPOPT_TS_TSONLY
:
8862 off
= opt
[IPOPT_OFFSET
] - 1;
8863 /* Compute # of milliseconds since midnight */
8865 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
8866 NSEC2MSEC(now
.tv_nsec
);
8867 bcopy(&ts
, (char *)opt
+ off
, IPOPT_TS_TIMELEN
);
8868 opt
[IPOPT_OFFSET
] += IPOPT_TS_TIMELEN
;
8878 * Call ill_frag_timeout to do garbage collection. ill_frag_timeout
8879 * returns 'true' if there are still fragments left on the queue, in
8880 * which case we restart the timer.
8883 ill_frag_timer(void *arg
)
8885 ill_t
*ill
= (ill_t
*)arg
;
8886 boolean_t frag_pending
;
8887 ip_stack_t
*ipst
= ill
->ill_ipst
;
8890 mutex_enter(&ill
->ill_lock
);
8891 ASSERT(!ill
->ill_fragtimer_executing
);
8892 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
8893 ill
->ill_frag_timer_id
= 0;
8894 mutex_exit(&ill
->ill_lock
);
8897 ill
->ill_fragtimer_executing
= 1;
8898 mutex_exit(&ill
->ill_lock
);
8900 timeout
= (ill
->ill_isv6
? ipst
->ips_ipv6_reassembly_timeout
:
8901 ipst
->ips_ip_reassembly_timeout
);
8903 frag_pending
= ill_frag_timeout(ill
, timeout
);
8906 * Restart the timer, if we have fragments pending or if someone
8907 * wanted us to be scheduled again.
8909 mutex_enter(&ill
->ill_lock
);
8910 ill
->ill_fragtimer_executing
= 0;
8911 ill
->ill_frag_timer_id
= 0;
8912 if (frag_pending
|| ill
->ill_fragtimer_needrestart
)
8913 ill_frag_timer_start(ill
);
8914 mutex_exit(&ill
->ill_lock
);
8918 ill_frag_timer_start(ill_t
*ill
)
8920 ip_stack_t
*ipst
= ill
->ill_ipst
;
8923 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
8925 /* If the ill is closing or opening don't proceed */
8926 if (ill
->ill_state_flags
& ILL_CONDEMNED
)
8929 if (ill
->ill_fragtimer_executing
) {
8931 * ill_frag_timer is currently executing. Just record the
8932 * the fact that we want the timer to be restarted.
8933 * ill_frag_timer will post a timeout before it returns,
8934 * ensuring it will be called again.
8936 ill
->ill_fragtimer_needrestart
= 1;
8940 if (ill
->ill_frag_timer_id
== 0) {
8941 timeo_ms
= (ill
->ill_isv6
? ipst
->ips_ipv6_reassembly_timeout
:
8942 ipst
->ips_ip_reassembly_timeout
) * SECONDS
;
8945 * The timer is neither running nor is the timeout handler
8946 * executing. Post a timeout so that ill_frag_timer will be
8949 ill
->ill_frag_timer_id
= timeout(ill_frag_timer
, ill
,
8950 MSEC_TO_TICK(timeo_ms
>> 1));
8951 ill
->ill_fragtimer_needrestart
= 0;
8956 * Update any source route, record route or timestamp options.
8957 * Check that we are at end of strict source route.
8958 * The options have already been checked for sanity in ip_input_options().
8961 ip_input_local_options(mblk_t
*mp
, ipha_t
*ipha
, ip_recv_attr_t
*ira
)
8971 ill_t
*ill
= ira
->ira_ill
;
8972 ip_stack_t
*ipst
= ill
->ill_ipst
;
8974 ip2dbg(("ip_input_local_options\n"));
8976 for (optval
= ipoptp_first(&opts
, ipha
);
8977 optval
!= IPOPT_EOL
;
8978 optval
= ipoptp_next(&opts
)) {
8979 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
8980 opt
= opts
.ipoptp_cur
;
8981 optlen
= opts
.ipoptp_len
;
8982 ip2dbg(("ip_input_local_options: opt %d, len %d\n",
8988 off
= opt
[IPOPT_OFFSET
];
8990 if (optlen
< IP_ADDR_LEN
||
8991 off
> optlen
- IP_ADDR_LEN
) {
8992 /* End of source route */
8993 ip1dbg(("ip_input_local_options: end of SR\n"));
8997 * This will only happen if two consecutive entries
8998 * in the source route contains our address or if
8999 * it is a packet with a loose source route which
9000 * reaches us before consuming the whole source route
9002 ip1dbg(("ip_input_local_options: not end of SR\n"));
9003 if (optval
== IPOPT_SSRR
) {
9007 * Hack: instead of dropping the packet truncate the
9008 * source route to what has been used by filling the
9009 * rest with IPOPT_NOP.
9011 opt
[IPOPT_OLEN
] = (uint8_t)off
;
9012 while (off
< optlen
) {
9013 opt
[off
++] = IPOPT_NOP
;
9017 off
= opt
[IPOPT_OFFSET
];
9019 if (optlen
< IP_ADDR_LEN
||
9020 off
> optlen
- IP_ADDR_LEN
) {
9021 /* No more room - ignore */
9023 "ip_input_local_options: end of RR\n"));
9026 /* Pick a reasonable address on the outbound if */
9027 if (ip_select_source_v4(ill
, INADDR_ANY
, ipha
->ipha_dst
,
9028 INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
, NULL
,
9030 /* No source! Shouldn't happen */
9031 ifaddr
= INADDR_ANY
;
9033 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
9034 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
9037 /* Insert timestamp if there is romm */
9038 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
9039 case IPOPT_TS_TSONLY
:
9040 off
= IPOPT_TS_TIMELEN
;
9042 case IPOPT_TS_PRESPEC
:
9043 case IPOPT_TS_PRESPEC_RFC791
:
9044 /* Verify that the address matched */
9045 off
= opt
[IPOPT_OFFSET
] - 1;
9046 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
9047 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
9052 case IPOPT_TS_TSANDADDR
:
9053 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
9057 * ip_*put_options should have already
9058 * dropped this packet.
9060 cmn_err(CE_PANIC
, "ip_input_local_options: "
9061 "unknown IT - bug in ip_input_options?\n");
9062 return (B_TRUE
); /* Keep "lint" happy */
9064 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
) {
9065 /* Increase overflow counter */
9066 off
= (opt
[IPOPT_POS_OV_FLG
] >> 4) + 1;
9067 opt
[IPOPT_POS_OV_FLG
] =
9068 (uint8_t)((opt
[IPOPT_POS_OV_FLG
] & 0x0F) |
9072 off
= opt
[IPOPT_OFFSET
] - 1;
9073 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
9074 case IPOPT_TS_PRESPEC
:
9075 case IPOPT_TS_PRESPEC_RFC791
:
9076 case IPOPT_TS_TSANDADDR
:
9077 /* Pick a reasonable addr on the outbound if */
9078 if (ip_select_source_v4(ill
, INADDR_ANY
,
9079 ipha
->ipha_dst
, INADDR_ANY
, ALL_ZONES
, ipst
,
9080 &ifaddr
, NULL
, NULL
) != 0) {
9081 /* No source! Shouldn't happen */
9082 ifaddr
= INADDR_ANY
;
9084 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
9085 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
9087 case IPOPT_TS_TSONLY
:
9088 off
= opt
[IPOPT_OFFSET
] - 1;
9089 /* Compute # of milliseconds since midnight */
9091 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
9092 NSEC2MSEC(now
.tv_nsec
);
9093 bcopy(&ts
, (char *)opt
+ off
, IPOPT_TS_TIMELEN
);
9094 opt
[IPOPT_OFFSET
] += IPOPT_TS_TIMELEN
;
9103 /* make sure we clear any indication of a hardware checksum */
9104 DB_CKSUMFLAGS(mp
) = 0;
9105 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", mp
, ill
);
9106 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
, ira
);
9112 * Process IP options in an inbound packet. Always returns the nexthop.
9113 * Normally this is the passed in nexthop, but if there is an option
9114 * that effects the nexthop (such as a source route) that will be returned.
9115 * Sets *errorp if there is an error, in which case an ICMP error has been sent
9119 ip_input_options(ipha_t
*ipha
, ipaddr_t dst
, mblk_t
*mp
,
9120 ip_recv_attr_t
*ira
, int *errorp
)
9122 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
9130 ip2dbg(("ip_input_options\n"));
9132 for (optval
= ipoptp_first(&opts
, ipha
);
9133 optval
!= IPOPT_EOL
;
9134 optval
= ipoptp_next(&opts
)) {
9135 opt
= opts
.ipoptp_cur
;
9136 optlen
= opts
.ipoptp_len
;
9137 ip2dbg(("ip_input_options: opt %d, len %d\n",
9140 * Note: we need to verify the checksum before we
9141 * modify anything thus this routine only extracts the next
9142 * hop dst from any source route.
9148 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
9149 if (optval
== IPOPT_SSRR
) {
9150 ip1dbg(("ip_input_options: not next"
9151 " strict source route 0x%x\n",
9153 code
= (char *)&ipha
->ipha_dst
-
9155 goto param_prob
; /* RouterReq's */
9157 ip2dbg(("ip_input_options: "
9158 "not next source route 0x%x\n",
9163 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
9165 "ip_input_options: bad option offset\n"));
9166 code
= (char *)&opt
[IPOPT_OLEN
] -
9170 off
= opt
[IPOPT_OFFSET
];
9173 if (optlen
< IP_ADDR_LEN
||
9174 off
> optlen
- IP_ADDR_LEN
) {
9175 /* End of source route */
9176 ip1dbg(("ip_input_options: end of SR\n"));
9179 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
9180 ip1dbg(("ip_input_options: next hop 0x%x\n",
9184 * Check if our address is present more than
9185 * once as consecutive hops in source route.
9186 * XXX verify per-interface ip_forwarding
9189 if (ip_type_v4(dst
, ipst
) == IRE_LOCAL
) {
9194 if (dst
== htonl(INADDR_LOOPBACK
)) {
9195 ip1dbg(("ip_input_options: loopback addr in "
9196 "source route!\n"));
9200 * For strict: verify that dst is directly
9203 if (optval
== IPOPT_SSRR
) {
9204 ire
= ire_ftable_lookup_v4(dst
, 0, 0,
9205 IRE_INTERFACE
, NULL
, ALL_ZONES
,
9206 MATCH_IRE_TYPE
, 0, ipst
, NULL
);
9208 ip1dbg(("ip_input_options: SSRR not "
9209 "directly reachable: 0x%x\n",
9216 * Defer update of the offset and the record route
9217 * until the packet is forwarded.
9221 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
9223 "ip_input_options: bad option offset\n"));
9224 code
= (char *)&opt
[IPOPT_OLEN
] -
9231 * Verify that length >= 5 and that there is either
9232 * room for another timestamp or that the overflow
9233 * counter is not maxed out.
9235 code
= (char *)&opt
[IPOPT_OLEN
] - (char *)ipha
;
9236 if (optlen
< IPOPT_MINLEN_IT
) {
9239 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
9241 "ip_input_options: bad option offset\n"));
9242 code
= (char *)&opt
[IPOPT_OFFSET
] -
9246 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
9247 case IPOPT_TS_TSONLY
:
9248 off
= IPOPT_TS_TIMELEN
;
9250 case IPOPT_TS_TSANDADDR
:
9251 case IPOPT_TS_PRESPEC
:
9252 case IPOPT_TS_PRESPEC_RFC791
:
9253 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
9256 code
= (char *)&opt
[IPOPT_POS_OV_FLG
] -
9260 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
&&
9261 (opt
[IPOPT_POS_OV_FLG
] & 0xF0) == 0xF0) {
9263 * No room and the overflow counter is 15
9272 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0) {
9276 ip1dbg(("ip_input_options: error processing IP options."));
9277 code
= (char *)&opt
[IPOPT_OFFSET
] - (char *)ipha
;
9280 /* make sure we clear any indication of a hardware checksum */
9281 DB_CKSUMFLAGS(mp
) = 0;
9282 ip_drop_input("ICMP_PARAM_PROBLEM", mp
, ira
->ira_ill
);
9283 icmp_param_problem(mp
, (uint8_t)code
, ira
);
9288 /* make sure we clear any indication of a hardware checksum */
9289 DB_CKSUMFLAGS(mp
) = 0;
9290 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", mp
, ira
->ira_ill
);
9291 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
, ira
);
9297 * IP & ICMP info in >=14 msg's ...
9298 * - ip fixed part (mib2_ip_t)
9299 * - icmp fixed part (mib2_icmp_t)
9300 * - ipAddrEntryTable (ip 20) all IPv4 ipifs
9301 * - ipRouteEntryTable (ip 21) all IPv4 IREs
9302 * - ipNetToMediaEntryTable (ip 22) all IPv4 Neighbor Cache entries
9303 * - ip multicast membership (ip_member_t)
9304 * - ip multicast source filtering (ip_grpsrc_t)
9305 * - igmp fixed part (struct igmpstat)
9306 * - multicast routing stats (struct mrtstat)
9307 * - multicast routing vifs (array of struct vifctl)
9308 * - multicast routing routes (array of struct mfcctl)
9309 * - ip6 fixed part (mib2_ipv6IfStatsEntry_t)
9310 * One per ill plus one generic
9311 * - icmp6 fixed part (mib2_ipv6IfIcmpEntry_t)
9312 * One per ill plus one generic
9313 * - ipv6RouteEntry all IPv6 IREs
9314 * - ipv6NetToMediaEntry all IPv6 Neighbor Cache entries
9315 * - ipv6AddrEntry all IPv6 ipifs
9316 * - ipv6 multicast membership (ipv6_member_t)
9317 * - ipv6 multicast source filtering (ipv6_grpsrc_t)
9319 * NOTE: original mpctl is copied for msg's 2..N, since its ctl part is
9320 * already filled in by the caller.
9321 * If legacy_req is true then MIB structures needs to be truncated to their
9322 * legacy sizes before being returned.
9323 * Return value of 0 indicates that no messages were sent and caller
9324 * should free mpctl.
9327 ip_snmp_get(queue_t
*q
, mblk_t
*mpctl
, int level
, boolean_t legacy_req
)
9330 sctp_stack_t
*sctps
;
9332 if (q
->q_next
!= NULL
) {
9333 ipst
= ILLQ_TO_IPST(q
);
9335 ipst
= CONNQ_TO_IPST(q
);
9337 ASSERT(ipst
!= NULL
);
9338 sctps
= ipst
->ips_netstack
->netstack_sctp
;
9340 if (mpctl
== NULL
|| mpctl
->b_cont
== NULL
) {
9345 * For the purposes of the (broken) packet shell use
9346 * of the level we make sure MIB2_TCP/MIB2_UDP can be used
9347 * to make TCP and UDP appear first in the list of mib items.
9348 * TBD: We could expand this and use it in netstat so that
9349 * the kernel doesn't have to produce large tables (connections,
9350 * routes, etc) when netstat only wants the statistics or a particular
9353 if (!(level
== MIB2_TCP
|| level
== MIB2_UDP
)) {
9354 if ((mpctl
= icmp_snmp_get(q
, mpctl
)) == NULL
) {
9359 if (level
!= MIB2_TCP
) {
9360 if ((mpctl
= udp_snmp_get(q
, mpctl
, legacy_req
)) == NULL
) {
9365 if (level
!= MIB2_UDP
) {
9366 if ((mpctl
= tcp_snmp_get(q
, mpctl
, legacy_req
)) == NULL
) {
9371 if ((mpctl
= ip_snmp_get_mib2_ip_traffic_stats(q
, mpctl
,
9372 ipst
, legacy_req
)) == NULL
) {
9376 if ((mpctl
= ip_snmp_get_mib2_ip6(q
, mpctl
, ipst
,
9377 legacy_req
)) == NULL
) {
9381 if ((mpctl
= ip_snmp_get_mib2_icmp(q
, mpctl
, ipst
)) == NULL
) {
9385 if ((mpctl
= ip_snmp_get_mib2_icmp6(q
, mpctl
, ipst
)) == NULL
) {
9389 if ((mpctl
= ip_snmp_get_mib2_igmp(q
, mpctl
, ipst
)) == NULL
) {
9393 if ((mpctl
= ip_snmp_get_mib2_multi(q
, mpctl
, ipst
)) == NULL
) {
9397 if ((mpctl
= ip_snmp_get_mib2_ip_addr(q
, mpctl
, ipst
,
9398 legacy_req
)) == NULL
) {
9402 if ((mpctl
= ip_snmp_get_mib2_ip6_addr(q
, mpctl
, ipst
,
9403 legacy_req
)) == NULL
) {
9407 if ((mpctl
= ip_snmp_get_mib2_ip_group_mem(q
, mpctl
, ipst
)) == NULL
) {
9411 if ((mpctl
= ip_snmp_get_mib2_ip6_group_mem(q
, mpctl
, ipst
)) == NULL
) {
9415 if ((mpctl
= ip_snmp_get_mib2_ip_group_src(q
, mpctl
, ipst
)) == NULL
) {
9419 if ((mpctl
= ip_snmp_get_mib2_ip6_group_src(q
, mpctl
, ipst
)) == NULL
) {
9423 if ((mpctl
= ip_snmp_get_mib2_virt_multi(q
, mpctl
, ipst
)) == NULL
) {
9427 if ((mpctl
= ip_snmp_get_mib2_multi_rtable(q
, mpctl
, ipst
)) == NULL
) {
9431 mpctl
= ip_snmp_get_mib2_ip_route_media(q
, mpctl
, level
, ipst
);
9435 mpctl
= ip_snmp_get_mib2_ip6_route_media(q
, mpctl
, level
, ipst
);
9439 if ((mpctl
= sctp_snmp_get_mib2(q
, mpctl
, sctps
)) == NULL
) {
9442 if ((mpctl
= ip_snmp_get_mib2_ip_dce(q
, mpctl
, ipst
)) == NULL
) {
9449 /* Get global (legacy) IPv4 statistics */
9451 ip_snmp_get_mib2_ip(queue_t
*q
, mblk_t
*mpctl
, mib2_ipIfStatsEntry_t
*ipmib
,
9452 ip_stack_t
*ipst
, boolean_t legacy_req
)
9454 mib2_ip_t old_ip_mib
;
9455 struct opthdr
*optp
;
9457 mib2_ipAddrEntry_t mae
;
9460 * make a copy of the original message
9462 mp2ctl
= copymsg(mpctl
);
9464 /* fixed length IP structure... */
9465 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9466 optp
->level
= MIB2_IP
;
9468 SET_MIB(old_ip_mib
.ipForwarding
,
9469 (WE_ARE_FORWARDING(ipst
) ? 1 : 2));
9470 SET_MIB(old_ip_mib
.ipDefaultTTL
,
9471 (uint32_t)ipst
->ips_ip_def_ttl
);
9472 SET_MIB(old_ip_mib
.ipReasmTimeout
,
9473 ipst
->ips_ip_reassembly_timeout
);
9474 SET_MIB(old_ip_mib
.ipAddrEntrySize
,
9475 (legacy_req
) ? LEGACY_MIB_SIZE(&mae
, mib2_ipAddrEntry_t
) :
9476 sizeof (mib2_ipAddrEntry_t
));
9477 SET_MIB(old_ip_mib
.ipRouteEntrySize
,
9478 sizeof (mib2_ipRouteEntry_t
));
9479 SET_MIB(old_ip_mib
.ipNetToMediaEntrySize
,
9480 sizeof (mib2_ipNetToMediaEntry_t
));
9481 SET_MIB(old_ip_mib
.ipMemberEntrySize
, sizeof (ip_member_t
));
9482 SET_MIB(old_ip_mib
.ipGroupSourceEntrySize
, sizeof (ip_grpsrc_t
));
9483 SET_MIB(old_ip_mib
.ipDestEntrySize
, sizeof (dest_cache_entry_t
));
9486 * Grab the statistics from the new IP MIB
9488 SET_MIB(old_ip_mib
.ipInReceives
,
9489 (uint32_t)ipmib
->ipIfStatsHCInReceives
);
9490 SET_MIB(old_ip_mib
.ipInHdrErrors
, ipmib
->ipIfStatsInHdrErrors
);
9491 SET_MIB(old_ip_mib
.ipInAddrErrors
, ipmib
->ipIfStatsInAddrErrors
);
9492 SET_MIB(old_ip_mib
.ipForwDatagrams
,
9493 (uint32_t)ipmib
->ipIfStatsHCOutForwDatagrams
);
9494 SET_MIB(old_ip_mib
.ipInUnknownProtos
,
9495 ipmib
->ipIfStatsInUnknownProtos
);
9496 SET_MIB(old_ip_mib
.ipInDiscards
, ipmib
->ipIfStatsInDiscards
);
9497 SET_MIB(old_ip_mib
.ipInDelivers
,
9498 (uint32_t)ipmib
->ipIfStatsHCInDelivers
);
9499 SET_MIB(old_ip_mib
.ipOutRequests
,
9500 (uint32_t)ipmib
->ipIfStatsHCOutRequests
);
9501 SET_MIB(old_ip_mib
.ipOutDiscards
, ipmib
->ipIfStatsOutDiscards
);
9502 SET_MIB(old_ip_mib
.ipOutNoRoutes
, ipmib
->ipIfStatsOutNoRoutes
);
9503 SET_MIB(old_ip_mib
.ipReasmReqds
, ipmib
->ipIfStatsReasmReqds
);
9504 SET_MIB(old_ip_mib
.ipReasmOKs
, ipmib
->ipIfStatsReasmOKs
);
9505 SET_MIB(old_ip_mib
.ipReasmFails
, ipmib
->ipIfStatsReasmFails
);
9506 SET_MIB(old_ip_mib
.ipFragOKs
, ipmib
->ipIfStatsOutFragOKs
);
9507 SET_MIB(old_ip_mib
.ipFragFails
, ipmib
->ipIfStatsOutFragFails
);
9508 SET_MIB(old_ip_mib
.ipFragCreates
, ipmib
->ipIfStatsOutFragCreates
);
9510 /* ipRoutingDiscards is not being used */
9511 SET_MIB(old_ip_mib
.ipRoutingDiscards
, 0);
9512 SET_MIB(old_ip_mib
.tcpInErrs
, ipmib
->tcpIfStatsInErrs
);
9513 SET_MIB(old_ip_mib
.udpNoPorts
, ipmib
->udpIfStatsNoPorts
);
9514 SET_MIB(old_ip_mib
.ipInCksumErrs
, ipmib
->ipIfStatsInCksumErrs
);
9515 SET_MIB(old_ip_mib
.ipReasmDuplicates
,
9516 ipmib
->ipIfStatsReasmDuplicates
);
9517 SET_MIB(old_ip_mib
.ipReasmPartDups
, ipmib
->ipIfStatsReasmPartDups
);
9518 SET_MIB(old_ip_mib
.ipForwProhibits
, ipmib
->ipIfStatsForwProhibits
);
9519 SET_MIB(old_ip_mib
.udpInCksumErrs
, ipmib
->udpIfStatsInCksumErrs
);
9520 SET_MIB(old_ip_mib
.udpInOverflows
, ipmib
->udpIfStatsInOverflows
);
9521 SET_MIB(old_ip_mib
.rawipInOverflows
,
9522 ipmib
->rawipIfStatsInOverflows
);
9524 SET_MIB(old_ip_mib
.ipsecInSucceeded
, ipmib
->ipsecIfStatsInSucceeded
);
9525 SET_MIB(old_ip_mib
.ipsecInFailed
, ipmib
->ipsecIfStatsInFailed
);
9526 SET_MIB(old_ip_mib
.ipInIPv6
, ipmib
->ipIfStatsInWrongIPVersion
);
9527 SET_MIB(old_ip_mib
.ipOutIPv6
, ipmib
->ipIfStatsOutWrongIPVersion
);
9528 SET_MIB(old_ip_mib
.ipOutSwitchIPv6
,
9529 ipmib
->ipIfStatsOutSwitchIPVersion
);
9531 if (!snmp_append_data(mpctl
->b_cont
, (char *)&old_ip_mib
,
9532 (int)sizeof (old_ip_mib
))) {
9533 ip1dbg(("ip_snmp_get_mib2_ip: failed to allocate %u bytes\n",
9534 (uint_t
)sizeof (old_ip_mib
)));
9537 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9538 ip3dbg(("ip_snmp_get_mib2_ip: level %d, name %d, len %d\n",
9539 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9544 /* Per interface IPv4 statistics */
9546 ip_snmp_get_mib2_ip_traffic_stats(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
9547 boolean_t legacy_req
)
9549 struct opthdr
*optp
;
9552 ill_walk_context_t ctx
;
9553 mblk_t
*mp_tail
= NULL
;
9554 mib2_ipIfStatsEntry_t global_ip_mib
;
9555 mib2_ipAddrEntry_t mae
;
9558 * Make a copy of the original message
9560 mp2ctl
= copymsg(mpctl
);
9562 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9563 optp
->level
= MIB2_IP
;
9564 optp
->name
= MIB2_IP_TRAFFIC_STATS
;
9565 /* Include "unknown interface" ip_mib */
9566 ipst
->ips_ip_mib
.ipIfStatsIPVersion
= MIB2_INETADDRESSTYPE_ipv4
;
9567 ipst
->ips_ip_mib
.ipIfStatsIfIndex
=
9568 MIB2_UNKNOWN_INTERFACE
; /* Flag to netstat */
9569 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsForwarding
,
9570 (ipst
->ips_ip_forwarding
? 1 : 2));
9571 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsDefaultTTL
,
9572 (uint32_t)ipst
->ips_ip_def_ttl
);
9573 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsEntrySize
,
9574 sizeof (mib2_ipIfStatsEntry_t
));
9575 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsAddrEntrySize
,
9576 sizeof (mib2_ipAddrEntry_t
));
9577 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsRouteEntrySize
,
9578 sizeof (mib2_ipRouteEntry_t
));
9579 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsNetToMediaEntrySize
,
9580 sizeof (mib2_ipNetToMediaEntry_t
));
9581 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsMemberEntrySize
,
9582 sizeof (ip_member_t
));
9583 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsGroupSourceEntrySize
,
9584 sizeof (ip_grpsrc_t
));
9586 bcopy(&ipst
->ips_ip_mib
, &global_ip_mib
, sizeof (global_ip_mib
));
9589 SET_MIB(global_ip_mib
.ipIfStatsAddrEntrySize
,
9590 LEGACY_MIB_SIZE(&mae
, mib2_ipAddrEntry_t
));
9593 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9594 (char *)&global_ip_mib
, (int)sizeof (global_ip_mib
))) {
9595 ip1dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
9596 "failed to allocate %u bytes\n",
9597 (uint_t
)sizeof (global_ip_mib
)));
9600 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9601 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
9602 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9603 ill
->ill_ip_mib
->ipIfStatsIfIndex
=
9604 ill
->ill_phyint
->phyint_ifindex
;
9605 SET_MIB(ill
->ill_ip_mib
->ipIfStatsForwarding
,
9606 (ipst
->ips_ip_forwarding
? 1 : 2));
9607 SET_MIB(ill
->ill_ip_mib
->ipIfStatsDefaultTTL
,
9608 (uint32_t)ipst
->ips_ip_def_ttl
);
9610 ip_mib2_add_ip_stats(&global_ip_mib
, ill
->ill_ip_mib
);
9611 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9612 (char *)ill
->ill_ip_mib
,
9613 (int)sizeof (*ill
->ill_ip_mib
))) {
9614 ip1dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
9615 "failed to allocate %u bytes\n",
9616 (uint_t
)sizeof (*ill
->ill_ip_mib
)));
9619 rw_exit(&ipst
->ips_ill_g_lock
);
9621 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9622 ip3dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
9623 "level %d, name %d, len %d\n",
9624 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9630 return (ip_snmp_get_mib2_ip(q
, mp2ctl
, &global_ip_mib
, ipst
,
9634 /* Global IPv4 ICMP statistics */
9636 ip_snmp_get_mib2_icmp(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9638 struct opthdr
*optp
;
9642 * Make a copy of the original message
9644 mp2ctl
= copymsg(mpctl
);
9646 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9647 optp
->level
= MIB2_ICMP
;
9649 if (!snmp_append_data(mpctl
->b_cont
, (char *)&ipst
->ips_icmp_mib
,
9650 (int)sizeof (ipst
->ips_icmp_mib
))) {
9651 ip1dbg(("ip_snmp_get_mib2_icmp: failed to allocate %u bytes\n",
9652 (uint_t
)sizeof (ipst
->ips_icmp_mib
)));
9654 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9655 ip3dbg(("ip_snmp_get_mib2_icmp: level %d, name %d, len %d\n",
9656 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9661 /* Global IPv4 IGMP statistics */
9663 ip_snmp_get_mib2_igmp(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9665 struct opthdr
*optp
;
9669 * make a copy of the original message
9671 mp2ctl
= copymsg(mpctl
);
9673 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9674 optp
->level
= EXPER_IGMP
;
9676 if (!snmp_append_data(mpctl
->b_cont
, (char *)&ipst
->ips_igmpstat
,
9677 (int)sizeof (ipst
->ips_igmpstat
))) {
9678 ip1dbg(("ip_snmp_get_mib2_igmp: failed to allocate %u bytes\n",
9679 (uint_t
)sizeof (ipst
->ips_igmpstat
)));
9681 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9682 ip3dbg(("ip_snmp_get_mib2_igmp: level %d, name %d, len %d\n",
9683 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9688 /* Global IPv4 Multicast Routing statistics */
9690 ip_snmp_get_mib2_multi(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9692 struct opthdr
*optp
;
9696 * make a copy of the original message
9698 mp2ctl
= copymsg(mpctl
);
9700 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9701 optp
->level
= EXPER_DVMRP
;
9703 if (!ip_mroute_stats(mpctl
->b_cont
, ipst
)) {
9704 ip0dbg(("ip_mroute_stats: failed\n"));
9706 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9707 ip3dbg(("ip_snmp_get_mib2_multi: level %d, name %d, len %d\n",
9708 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9713 /* IPv4 address information */
9715 ip_snmp_get_mib2_ip_addr(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
9716 boolean_t legacy_req
)
9718 struct opthdr
*optp
;
9720 mblk_t
*mp_tail
= NULL
;
9724 mib2_ipAddrEntry_t mae
;
9727 ill_walk_context_t ctx
;
9730 * make a copy of the original message
9732 mp2ctl
= copymsg(mpctl
);
9734 mae_size
= (legacy_req
) ? LEGACY_MIB_SIZE(&mae
, mib2_ipAddrEntry_t
) :
9735 sizeof (mib2_ipAddrEntry_t
);
9737 /* ipAddrEntryTable */
9739 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9740 optp
->level
= MIB2_IP
;
9741 optp
->name
= MIB2_IP_ADDR
;
9742 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
9744 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9745 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
9746 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9747 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9748 ipif
= ipif
->ipif_next
) {
9749 if (ipif
->ipif_zoneid
!= zoneid
&&
9750 ipif
->ipif_zoneid
!= ALL_ZONES
)
9752 /* Sum of count from dead IRE_LO* and our current */
9753 mae
.ipAdEntInfo
.ae_ibcnt
= ipif
->ipif_ib_pkt_count
;
9754 if (ipif
->ipif_ire_local
!= NULL
) {
9755 mae
.ipAdEntInfo
.ae_ibcnt
+=
9756 ipif
->ipif_ire_local
->ire_ib_pkt_count
;
9758 mae
.ipAdEntInfo
.ae_obcnt
= 0;
9759 mae
.ipAdEntInfo
.ae_focnt
= 0;
9761 ipif_get_name(ipif
, mae
.ipAdEntIfIndex
.o_bytes
,
9763 mae
.ipAdEntIfIndex
.o_length
=
9764 mi_strlen(mae
.ipAdEntIfIndex
.o_bytes
);
9765 mae
.ipAdEntAddr
= ipif
->ipif_lcl_addr
;
9766 mae
.ipAdEntNetMask
= ipif
->ipif_net_mask
;
9767 mae
.ipAdEntInfo
.ae_subnet
= ipif
->ipif_subnet
;
9768 mae
.ipAdEntInfo
.ae_subnet_len
=
9769 ip_mask_to_plen(ipif
->ipif_net_mask
);
9770 mae
.ipAdEntInfo
.ae_src_addr
= ipif
->ipif_lcl_addr
;
9773 !(bitval
& ipif
->ipif_brd_addr
);
9776 mae
.ipAdEntBcastAddr
= bitval
;
9777 mae
.ipAdEntReasmMaxSize
= IP_MAXPACKET
;
9778 mae
.ipAdEntInfo
.ae_mtu
= ipif
->ipif_ill
->ill_mtu
;
9779 mae
.ipAdEntInfo
.ae_metric
= ipif
->ipif_ill
->ill_metric
;
9780 mae
.ipAdEntInfo
.ae_broadcast_addr
=
9781 ipif
->ipif_brd_addr
;
9782 mae
.ipAdEntInfo
.ae_pp_dst_addr
=
9783 ipif
->ipif_pp_dst_addr
;
9784 mae
.ipAdEntInfo
.ae_flags
= ipif
->ipif_flags
|
9785 ill
->ill_flags
| ill
->ill_phyint
->phyint_flags
;
9786 mae
.ipAdEntRetransmitTime
=
9787 ill
->ill_reachable_retrans_time
;
9789 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9790 (char *)&mae
, (int)mae_size
)) {
9791 ip1dbg(("ip_snmp_get_mib2_ip_addr: failed to "
9792 "allocate %u bytes\n", (uint_t
)mae_size
));
9796 rw_exit(&ipst
->ips_ill_g_lock
);
9798 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9799 ip3dbg(("ip_snmp_get_mib2_ip_addr: level %d, name %d, len %d\n",
9800 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9805 /* IPv6 address information */
9807 ip_snmp_get_mib2_ip6_addr(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
9808 boolean_t legacy_req
)
9810 struct opthdr
*optp
;
9812 mblk_t
*mp_tail
= NULL
;
9815 mib2_ipv6AddrEntry_t mae6
;
9818 ill_walk_context_t ctx
;
9821 * make a copy of the original message
9823 mp2ctl
= copymsg(mpctl
);
9825 mae6_size
= (legacy_req
) ?
9826 LEGACY_MIB_SIZE(&mae6
, mib2_ipv6AddrEntry_t
) :
9827 sizeof (mib2_ipv6AddrEntry_t
);
9829 /* ipv6AddrEntryTable */
9831 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9832 optp
->level
= MIB2_IP6
;
9833 optp
->name
= MIB2_IP6_ADDR
;
9834 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
9836 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9837 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
9838 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9839 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9840 ipif
= ipif
->ipif_next
) {
9841 if (ipif
->ipif_zoneid
!= zoneid
&&
9842 ipif
->ipif_zoneid
!= ALL_ZONES
)
9844 /* Sum of count from dead IRE_LO* and our current */
9845 mae6
.ipv6AddrInfo
.ae_ibcnt
= ipif
->ipif_ib_pkt_count
;
9846 if (ipif
->ipif_ire_local
!= NULL
) {
9847 mae6
.ipv6AddrInfo
.ae_ibcnt
+=
9848 ipif
->ipif_ire_local
->ire_ib_pkt_count
;
9850 mae6
.ipv6AddrInfo
.ae_obcnt
= 0;
9851 mae6
.ipv6AddrInfo
.ae_focnt
= 0;
9853 ipif_get_name(ipif
, mae6
.ipv6AddrIfIndex
.o_bytes
,
9855 mae6
.ipv6AddrIfIndex
.o_length
=
9856 mi_strlen(mae6
.ipv6AddrIfIndex
.o_bytes
);
9857 mae6
.ipv6AddrAddress
= ipif
->ipif_v6lcl_addr
;
9858 mae6
.ipv6AddrPfxLength
=
9859 ip_mask_to_plen_v6(&ipif
->ipif_v6net_mask
);
9860 mae6
.ipv6AddrInfo
.ae_subnet
= ipif
->ipif_v6subnet
;
9861 mae6
.ipv6AddrInfo
.ae_subnet_len
=
9862 mae6
.ipv6AddrPfxLength
;
9863 mae6
.ipv6AddrInfo
.ae_src_addr
= ipif
->ipif_v6lcl_addr
;
9865 /* Type: stateless(1), stateful(2), unknown(3) */
9866 if (ipif
->ipif_flags
& IPIF_ADDRCONF
)
9867 mae6
.ipv6AddrType
= 1;
9869 mae6
.ipv6AddrType
= 2;
9870 /* Anycast: true(1), false(2) */
9871 if (ipif
->ipif_flags
& IPIF_ANYCAST
)
9872 mae6
.ipv6AddrAnycastFlag
= 1;
9874 mae6
.ipv6AddrAnycastFlag
= 2;
9877 * Address status: preferred(1), deprecated(2),
9878 * invalid(3), inaccessible(4), unknown(5)
9880 if (ipif
->ipif_flags
& IPIF_NOLOCAL
)
9881 mae6
.ipv6AddrStatus
= 3;
9882 else if (ipif
->ipif_flags
& IPIF_DEPRECATED
)
9883 mae6
.ipv6AddrStatus
= 2;
9885 mae6
.ipv6AddrStatus
= 1;
9886 mae6
.ipv6AddrInfo
.ae_mtu
= ipif
->ipif_ill
->ill_mtu
;
9887 mae6
.ipv6AddrInfo
.ae_metric
=
9888 ipif
->ipif_ill
->ill_metric
;
9889 mae6
.ipv6AddrInfo
.ae_pp_dst_addr
=
9890 ipif
->ipif_v6pp_dst_addr
;
9891 mae6
.ipv6AddrInfo
.ae_flags
= ipif
->ipif_flags
|
9892 ill
->ill_flags
| ill
->ill_phyint
->phyint_flags
;
9893 mae6
.ipv6AddrReasmMaxSize
= IP_MAXPACKET
;
9894 mae6
.ipv6AddrIdentifier
= ill
->ill_token
;
9895 mae6
.ipv6AddrIdentifierLen
= ill
->ill_token_length
;
9896 mae6
.ipv6AddrReachableTime
= ill
->ill_reachable_time
;
9897 mae6
.ipv6AddrRetransmitTime
=
9898 ill
->ill_reachable_retrans_time
;
9899 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9900 (char *)&mae6
, (int)mae6_size
)) {
9901 ip1dbg(("ip_snmp_get_mib2_ip6_addr: failed to "
9902 "allocate %u bytes\n",
9903 (uint_t
)mae6_size
));
9907 rw_exit(&ipst
->ips_ill_g_lock
);
9909 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9910 ip3dbg(("ip_snmp_get_mib2_ip6_addr: level %d, name %d, len %d\n",
9911 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9916 /* IPv4 multicast group membership. */
9918 ip_snmp_get_mib2_ip_group_mem(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9920 struct opthdr
*optp
;
9926 mblk_t
*mp_tail
= NULL
;
9927 ill_walk_context_t ctx
;
9931 * make a copy of the original message
9933 mp2ctl
= copymsg(mpctl
);
9934 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
9936 /* ipGroupMember table */
9937 optp
= (struct opthdr
*)&mpctl
->b_rptr
[
9938 sizeof (struct T_optmgmt_ack
)];
9939 optp
->level
= MIB2_IP
;
9940 optp
->name
= EXPER_IP_GROUP_MEMBERSHIP
;
9942 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9943 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
9944 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9945 /* Make sure the ill isn't going away. */
9946 if (!ill_check_and_refhold(ill
))
9948 rw_exit(&ipst
->ips_ill_g_lock
);
9949 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
9950 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
9951 if (ilm
->ilm_zoneid
!= zoneid
&&
9952 ilm
->ilm_zoneid
!= ALL_ZONES
)
9955 /* Is there an ipif for ilm_ifaddr? */
9956 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9957 ipif
= ipif
->ipif_next
) {
9958 if (!IPIF_IS_CONDEMNED(ipif
) &&
9959 ipif
->ipif_lcl_addr
== ilm
->ilm_ifaddr
&&
9960 ilm
->ilm_ifaddr
!= INADDR_ANY
)
9965 ipm
.ipGroupMemberIfIndex
.o_bytes
,
9969 ipm
.ipGroupMemberIfIndex
.o_bytes
,
9972 ipm
.ipGroupMemberIfIndex
.o_length
=
9973 mi_strlen(ipm
.ipGroupMemberIfIndex
.o_bytes
);
9975 ipm
.ipGroupMemberAddress
= ilm
->ilm_addr
;
9976 ipm
.ipGroupMemberRefCnt
= ilm
->ilm_refcnt
;
9977 ipm
.ipGroupMemberFilterMode
= ilm
->ilm_fmode
;
9978 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9979 (char *)&ipm
, (int)sizeof (ipm
))) {
9980 ip1dbg(("ip_snmp_get_mib2_ip_group: "
9981 "failed to allocate %u bytes\n",
9982 (uint_t
)sizeof (ipm
)));
9985 rw_exit(&ill
->ill_mcast_lock
);
9987 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9989 rw_exit(&ipst
->ips_ill_g_lock
);
9990 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9991 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
9992 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9997 /* IPv6 multicast group membership. */
9999 ip_snmp_get_mib2_ip6_group_mem(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10001 struct opthdr
*optp
;
10005 ipv6_member_t ipm6
;
10006 mblk_t
*mp_tail
= NULL
;
10007 ill_walk_context_t ctx
;
10011 * make a copy of the original message
10013 mp2ctl
= copymsg(mpctl
);
10014 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10016 /* ip6GroupMember table */
10017 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10018 optp
->level
= MIB2_IP6
;
10019 optp
->name
= EXPER_IP6_GROUP_MEMBERSHIP
;
10021 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10022 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10023 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10024 /* Make sure the ill isn't going away. */
10025 if (!ill_check_and_refhold(ill
))
10027 rw_exit(&ipst
->ips_ill_g_lock
);
10029 * Normally we don't have any members on under IPMP interfaces.
10030 * We report them as a debugging aid.
10032 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
10033 ipm6
.ipv6GroupMemberIfIndex
= ill
->ill_phyint
->phyint_ifindex
;
10034 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
10035 if (ilm
->ilm_zoneid
!= zoneid
&&
10036 ilm
->ilm_zoneid
!= ALL_ZONES
)
10037 continue; /* not this zone */
10038 ipm6
.ipv6GroupMemberAddress
= ilm
->ilm_v6addr
;
10039 ipm6
.ipv6GroupMemberRefCnt
= ilm
->ilm_refcnt
;
10040 ipm6
.ipv6GroupMemberFilterMode
= ilm
->ilm_fmode
;
10041 if (!snmp_append_data2(mpctl
->b_cont
,
10043 (char *)&ipm6
, (int)sizeof (ipm6
))) {
10044 ip1dbg(("ip_snmp_get_mib2_ip6_group: "
10045 "failed to allocate %u bytes\n",
10046 (uint_t
)sizeof (ipm6
)));
10049 rw_exit(&ill
->ill_mcast_lock
);
10051 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10053 rw_exit(&ipst
->ips_ill_g_lock
);
10055 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10056 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
10057 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10062 /* IP multicast filtered sources */
10064 ip_snmp_get_mib2_ip_group_src(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10066 struct opthdr
*optp
;
10072 mblk_t
*mp_tail
= NULL
;
10073 ill_walk_context_t ctx
;
10079 * make a copy of the original message
10081 mp2ctl
= copymsg(mpctl
);
10082 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10084 /* ipGroupSource table */
10085 optp
= (struct opthdr
*)&mpctl
->b_rptr
[
10086 sizeof (struct T_optmgmt_ack
)];
10087 optp
->level
= MIB2_IP
;
10088 optp
->name
= EXPER_IP_GROUP_SOURCES
;
10090 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10091 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
10092 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10093 /* Make sure the ill isn't going away. */
10094 if (!ill_check_and_refhold(ill
))
10096 rw_exit(&ipst
->ips_ill_g_lock
);
10097 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
10098 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
10099 sl
= ilm
->ilm_filter
;
10100 if (ilm
->ilm_zoneid
!= zoneid
&&
10101 ilm
->ilm_zoneid
!= ALL_ZONES
)
10103 if (SLIST_IS_EMPTY(sl
))
10106 /* Is there an ipif for ilm_ifaddr? */
10107 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
10108 ipif
= ipif
->ipif_next
) {
10109 if (!IPIF_IS_CONDEMNED(ipif
) &&
10110 ipif
->ipif_lcl_addr
== ilm
->ilm_ifaddr
&&
10111 ilm
->ilm_ifaddr
!= INADDR_ANY
)
10114 if (ipif
!= NULL
) {
10115 ipif_get_name(ipif
,
10116 ips
.ipGroupSourceIfIndex
.o_bytes
,
10120 ips
.ipGroupSourceIfIndex
.o_bytes
,
10123 ips
.ipGroupSourceIfIndex
.o_length
=
10124 mi_strlen(ips
.ipGroupSourceIfIndex
.o_bytes
);
10126 ips
.ipGroupSourceGroup
= ilm
->ilm_addr
;
10127 for (i
= 0; i
< sl
->sl_numsrc
; i
++) {
10128 if (!IN6_IS_ADDR_V4MAPPED(&sl
->sl_addr
[i
]))
10130 IN6_V4MAPPED_TO_IPADDR(&sl
->sl_addr
[i
],
10131 ips
.ipGroupSourceAddress
);
10132 if (snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10133 (char *)&ips
, (int)sizeof (ips
)) == 0) {
10134 ip1dbg(("ip_snmp_get_mib2_ip_group_src:"
10135 " failed to allocate %u bytes\n",
10136 (uint_t
)sizeof (ips
)));
10140 rw_exit(&ill
->ill_mcast_lock
);
10142 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10144 rw_exit(&ipst
->ips_ill_g_lock
);
10145 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10146 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
10147 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10152 /* IPv6 multicast filtered sources. */
10154 ip_snmp_get_mib2_ip6_group_src(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10156 struct opthdr
*optp
;
10160 ipv6_grpsrc_t ips6
;
10161 mblk_t
*mp_tail
= NULL
;
10162 ill_walk_context_t ctx
;
10168 * make a copy of the original message
10170 mp2ctl
= copymsg(mpctl
);
10171 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10173 /* ip6GroupMember table */
10174 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10175 optp
->level
= MIB2_IP6
;
10176 optp
->name
= EXPER_IP6_GROUP_SOURCES
;
10178 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10179 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10180 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10181 /* Make sure the ill isn't going away. */
10182 if (!ill_check_and_refhold(ill
))
10184 rw_exit(&ipst
->ips_ill_g_lock
);
10186 * Normally we don't have any members on under IPMP interfaces.
10187 * We report them as a debugging aid.
10189 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
10190 ips6
.ipv6GroupSourceIfIndex
= ill
->ill_phyint
->phyint_ifindex
;
10191 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
10192 sl
= ilm
->ilm_filter
;
10193 if (ilm
->ilm_zoneid
!= zoneid
&&
10194 ilm
->ilm_zoneid
!= ALL_ZONES
)
10196 if (SLIST_IS_EMPTY(sl
))
10198 ips6
.ipv6GroupSourceGroup
= ilm
->ilm_v6addr
;
10199 for (i
= 0; i
< sl
->sl_numsrc
; i
++) {
10200 ips6
.ipv6GroupSourceAddress
= sl
->sl_addr
[i
];
10201 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10202 (char *)&ips6
, (int)sizeof (ips6
))) {
10203 ip1dbg(("ip_snmp_get_mib2_ip6_"
10204 "group_src: failed to allocate "
10206 (uint_t
)sizeof (ips6
)));
10210 rw_exit(&ill
->ill_mcast_lock
);
10212 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10214 rw_exit(&ipst
->ips_ill_g_lock
);
10216 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10217 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
10218 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10223 /* Multicast routing virtual interface table. */
10225 ip_snmp_get_mib2_virt_multi(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10227 struct opthdr
*optp
;
10231 * make a copy of the original message
10233 mp2ctl
= copymsg(mpctl
);
10235 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10236 optp
->level
= EXPER_DVMRP
;
10237 optp
->name
= EXPER_DVMRP_VIF
;
10238 if (!ip_mroute_vif(mpctl
->b_cont
, ipst
)) {
10239 ip0dbg(("ip_mroute_vif: failed\n"));
10241 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10242 ip3dbg(("ip_snmp_get_mib2_virt_multi: level %d, name %d, len %d\n",
10243 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10248 /* Multicast routing table. */
10250 ip_snmp_get_mib2_multi_rtable(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10252 struct opthdr
*optp
;
10256 * make a copy of the original message
10258 mp2ctl
= copymsg(mpctl
);
10260 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10261 optp
->level
= EXPER_DVMRP
;
10262 optp
->name
= EXPER_DVMRP_MRT
;
10263 if (!ip_mroute_mrt(mpctl
->b_cont
, ipst
)) {
10264 ip0dbg(("ip_mroute_mrt: failed\n"));
10266 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10267 ip3dbg(("ip_snmp_get_mib2_multi_rtable: level %d, name %d, len %d\n",
10268 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10274 * Return ipRouteEntryTable and ipNetToMediaEntryTable in one IRE walk.
10277 ip_snmp_get_mib2_ip_route_media(queue_t
*q
, mblk_t
*mpctl
, int level
,
10280 struct opthdr
*optp
;
10281 mblk_t
*mp2ctl
; /* Returned */
10282 mblk_t
*mp3ctl
; /* nettomedia */
10287 * make copies of the original message
10288 * - mp2ctl is returned unchanged to the caller for its use
10289 * - mpctl is sent upstream as ipRouteEntryTable
10290 * - mp3ctl is sent upstream as ipNetToMediaEntryTable
10292 mp2ctl
= copymsg(mpctl
);
10293 mp3ctl
= copymsg(mpctl
);
10294 if (mp3ctl
== NULL
) {
10301 bzero(&ird
, sizeof (ird
));
10303 ird
.ird_route
.lp_head
= mpctl
->b_cont
;
10304 ird
.ird_netmedia
.lp_head
= mp3ctl
->b_cont
;
10306 * If the level has been set the special EXPER_IP_AND_ALL_IRES value,
10307 * then also include ire_testhidden IREs and IRE_IF_CLONE. This is
10308 * intended a temporary solution until a proper MIB API is provided
10309 * that provides complete filtering/caller-opt-in.
10311 if (level
== EXPER_IP_AND_ALL_IRES
)
10312 ird
.ird_flags
|= IRD_REPORT_ALL
;
10314 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10315 ire_walk_v4(ip_snmp_get2_v4
, &ird
, zoneid
, ipst
);
10317 /* ipRouteEntryTable in mpctl */
10318 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10319 optp
->level
= MIB2_IP
;
10320 optp
->name
= MIB2_IP_ROUTE
;
10321 optp
->len
= msgdsize(ird
.ird_route
.lp_head
);
10322 ip3dbg(("ip_snmp_get_mib2_ip_route_media: level %d, name %d, len %d\n",
10323 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10326 /* ipNetToMediaEntryTable in mp3ctl */
10327 ncec_walk(NULL
, ip_snmp_get2_v4_media
, &ird
, ipst
);
10329 optp
= (struct opthdr
*)&mp3ctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10330 optp
->level
= MIB2_IP
;
10331 optp
->name
= MIB2_IP_MEDIA
;
10332 optp
->len
= msgdsize(ird
.ird_netmedia
.lp_head
);
10333 ip3dbg(("ip_snmp_get_mib2_ip_route_media: level %d, name %d, len %d\n",
10334 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10341 * Return ipv6RouteEntryTable in one IRE walk, and ipv6NetToMediaEntryTable in
10345 ip_snmp_get_mib2_ip6_route_media(queue_t
*q
, mblk_t
*mpctl
, int level
,
10348 struct opthdr
*optp
;
10349 mblk_t
*mp2ctl
; /* Returned */
10350 mblk_t
*mp3ctl
; /* nettomedia */
10355 * make copies of the original message
10356 * - mp2ctl is returned unchanged to the caller for its use
10357 * - mpctl is sent upstream as ipv6RouteEntryTable
10358 * - mp3ctl is sent upstream as ipv6NetToMediaEntryTable
10360 mp2ctl
= copymsg(mpctl
);
10361 mp3ctl
= copymsg(mpctl
);
10362 if (mp3ctl
== NULL
) {
10369 bzero(&ird
, sizeof (ird
));
10371 ird
.ird_route
.lp_head
= mpctl
->b_cont
;
10372 ird
.ird_netmedia
.lp_head
= mp3ctl
->b_cont
;
10374 * If the level has been set the special EXPER_IP_AND_ALL_IRES value,
10375 * then also include ire_testhidden IREs and IRE_IF_CLONE. This is
10376 * intended a temporary solution until a proper MIB API is provided
10377 * that provides complete filtering/caller-opt-in.
10379 if (level
== EXPER_IP_AND_ALL_IRES
)
10380 ird
.ird_flags
|= IRD_REPORT_ALL
;
10382 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10383 ire_walk_v6(ip_snmp_get2_v6_route
, &ird
, zoneid
, ipst
);
10385 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10386 optp
->level
= MIB2_IP6
;
10387 optp
->name
= MIB2_IP6_ROUTE
;
10388 optp
->len
= msgdsize(ird
.ird_route
.lp_head
);
10389 ip3dbg(("ip_snmp_get_mib2_ip6_route_media: level %d, name %d, len %d\n",
10390 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10393 /* ipv6NetToMediaEntryTable in mp3ctl */
10394 ncec_walk(NULL
, ip_snmp_get2_v6_media
, &ird
, ipst
);
10396 optp
= (struct opthdr
*)&mp3ctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10397 optp
->level
= MIB2_IP6
;
10398 optp
->name
= MIB2_IP6_MEDIA
;
10399 optp
->len
= msgdsize(ird
.ird_netmedia
.lp_head
);
10400 ip3dbg(("ip_snmp_get_mib2_ip6_route_media: level %d, name %d, len %d\n",
10401 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10408 * IPv6 mib: One per ill
10411 ip_snmp_get_mib2_ip6(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
10412 boolean_t legacy_req
)
10414 struct opthdr
*optp
;
10417 ill_walk_context_t ctx
;
10418 mblk_t
*mp_tail
= NULL
;
10419 mib2_ipv6AddrEntry_t mae6
;
10420 mib2_ipIfStatsEntry_t
*ise
;
10421 size_t ise_size
, iae_size
;
10424 * Make a copy of the original message
10426 mp2ctl
= copymsg(mpctl
);
10428 /* fixed length IPv6 structure ... */
10431 ise_size
= LEGACY_MIB_SIZE(&ipst
->ips_ip6_mib
,
10432 mib2_ipIfStatsEntry_t
);
10433 iae_size
= LEGACY_MIB_SIZE(&mae6
, mib2_ipv6AddrEntry_t
);
10435 ise_size
= sizeof (mib2_ipIfStatsEntry_t
);
10436 iae_size
= sizeof (mib2_ipv6AddrEntry_t
);
10439 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10440 optp
->level
= MIB2_IP6
;
10442 /* Include "unknown interface" ip6_mib */
10443 ipst
->ips_ip6_mib
.ipIfStatsIPVersion
= MIB2_INETADDRESSTYPE_ipv6
;
10444 ipst
->ips_ip6_mib
.ipIfStatsIfIndex
=
10445 MIB2_UNKNOWN_INTERFACE
; /* Flag to netstat */
10446 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsForwarding
,
10447 ipst
->ips_ipv6_forwarding
? 1 : 2);
10448 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsDefaultHopLimit
,
10449 ipst
->ips_ipv6_def_hops
);
10450 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsEntrySize
,
10451 sizeof (mib2_ipIfStatsEntry_t
));
10452 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsAddrEntrySize
,
10453 sizeof (mib2_ipv6AddrEntry_t
));
10454 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsRouteEntrySize
,
10455 sizeof (mib2_ipv6RouteEntry_t
));
10456 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsNetToMediaEntrySize
,
10457 sizeof (mib2_ipv6NetToMediaEntry_t
));
10458 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsMemberEntrySize
,
10459 sizeof (ipv6_member_t
));
10460 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsGroupSourceEntrySize
,
10461 sizeof (ipv6_grpsrc_t
));
10464 * Synchronize 64- and 32-bit counters
10466 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInReceives
,
10467 ipIfStatsHCInReceives
);
10468 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInDelivers
,
10469 ipIfStatsHCInDelivers
);
10470 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutRequests
,
10471 ipIfStatsHCOutRequests
);
10472 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutForwDatagrams
,
10473 ipIfStatsHCOutForwDatagrams
);
10474 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutMcastPkts
,
10475 ipIfStatsHCOutMcastPkts
);
10476 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInMcastPkts
,
10477 ipIfStatsHCInMcastPkts
);
10479 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10480 (char *)&ipst
->ips_ip6_mib
, (int)ise_size
)) {
10481 ip1dbg(("ip_snmp_get_mib2_ip6: failed to allocate %u bytes\n",
10482 (uint_t
)ise_size
));
10483 } else if (legacy_req
) {
10484 /* Adjust the EntrySize fields for legacy requests. */
10486 (mib2_ipIfStatsEntry_t
*)(mp_tail
->b_wptr
- (int)ise_size
);
10487 SET_MIB(ise
->ipIfStatsEntrySize
, ise_size
);
10488 SET_MIB(ise
->ipIfStatsAddrEntrySize
, iae_size
);
10491 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10492 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10493 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10494 ill
->ill_ip_mib
->ipIfStatsIfIndex
=
10495 ill
->ill_phyint
->phyint_ifindex
;
10496 SET_MIB(ill
->ill_ip_mib
->ipIfStatsForwarding
,
10497 ipst
->ips_ipv6_forwarding
? 1 : 2);
10498 SET_MIB(ill
->ill_ip_mib
->ipIfStatsDefaultHopLimit
,
10499 ill
->ill_max_hops
);
10502 * Synchronize 64- and 32-bit counters
10504 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsInReceives
,
10505 ipIfStatsHCInReceives
);
10506 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsInDelivers
,
10507 ipIfStatsHCInDelivers
);
10508 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsOutRequests
,
10509 ipIfStatsHCOutRequests
);
10510 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsOutForwDatagrams
,
10511 ipIfStatsHCOutForwDatagrams
);
10512 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsOutMcastPkts
,
10513 ipIfStatsHCOutMcastPkts
);
10514 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsInMcastPkts
,
10515 ipIfStatsHCInMcastPkts
);
10517 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10518 (char *)ill
->ill_ip_mib
, (int)ise_size
)) {
10519 ip1dbg(("ip_snmp_get_mib2_ip6: failed to allocate "
10520 "%u bytes\n", (uint_t
)ise_size
));
10521 } else if (legacy_req
) {
10522 /* Adjust the EntrySize fields for legacy requests. */
10523 ise
= (mib2_ipIfStatsEntry_t
*)(mp_tail
->b_wptr
-
10525 SET_MIB(ise
->ipIfStatsEntrySize
, ise_size
);
10526 SET_MIB(ise
->ipIfStatsAddrEntrySize
, iae_size
);
10529 rw_exit(&ipst
->ips_ill_g_lock
);
10531 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10532 ip3dbg(("ip_snmp_get_mib2_ip6: level %d, name %d, len %d\n",
10533 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10539 * ICMPv6 mib: One per ill
10542 ip_snmp_get_mib2_icmp6(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10544 struct opthdr
*optp
;
10547 ill_walk_context_t ctx
;
10548 mblk_t
*mp_tail
= NULL
;
10550 * Make a copy of the original message
10552 mp2ctl
= copymsg(mpctl
);
10554 /* fixed length ICMPv6 structure ... */
10556 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10557 optp
->level
= MIB2_ICMP6
;
10559 /* Include "unknown interface" icmp6_mib */
10560 ipst
->ips_icmp6_mib
.ipv6IfIcmpIfIndex
=
10561 MIB2_UNKNOWN_INTERFACE
; /* netstat flag */
10562 ipst
->ips_icmp6_mib
.ipv6IfIcmpEntrySize
=
10563 sizeof (mib2_ipv6IfIcmpEntry_t
);
10564 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10565 (char *)&ipst
->ips_icmp6_mib
,
10566 (int)sizeof (ipst
->ips_icmp6_mib
))) {
10567 ip1dbg(("ip_snmp_get_mib2_icmp6: failed to allocate %u bytes\n",
10568 (uint_t
)sizeof (ipst
->ips_icmp6_mib
)));
10571 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10572 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10573 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10574 ill
->ill_icmp6_mib
->ipv6IfIcmpIfIndex
=
10575 ill
->ill_phyint
->phyint_ifindex
;
10576 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10577 (char *)ill
->ill_icmp6_mib
,
10578 (int)sizeof (*ill
->ill_icmp6_mib
))) {
10579 ip1dbg(("ip_snmp_get_mib2_icmp6: failed to allocate "
10581 (uint_t
)sizeof (*ill
->ill_icmp6_mib
)));
10584 rw_exit(&ipst
->ips_ill_g_lock
);
10586 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10587 ip3dbg(("ip_snmp_get_mib2_icmp6: level %d, name %d, len %d\n",
10588 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10594 * ire_walk routine to create ipRouteEntryTable in one IRE walk
10597 ip_snmp_get2_v4(ire_t
*ire
, iproutedata_t
*ird
)
10600 mib2_ipRouteEntry_t
*re
;
10601 ip_stack_t
*ipst
= ire
->ire_ipst
;
10603 ASSERT(ire
->ire_ipversion
== IPV4_VERSION
);
10605 if (!(ird
->ird_flags
& IRD_REPORT_ALL
)) {
10606 if (ire
->ire_testhidden
)
10608 if (ire
->ire_type
& IRE_IF_CLONE
)
10612 if ((re
= kmem_zalloc(sizeof (*re
), KM_NOSLEEP
)) == NULL
)
10616 * Return all IRE types for route table... let caller pick and choose
10618 re
->ipRouteDest
= ire
->ire_addr
;
10619 ill
= ire
->ire_ill
;
10620 re
->ipRouteIfIndex
.o_length
= 0;
10622 ill_get_name(ill
, re
->ipRouteIfIndex
.o_bytes
, OCTET_LENGTH
);
10623 re
->ipRouteIfIndex
.o_length
=
10624 mi_strlen(re
->ipRouteIfIndex
.o_bytes
);
10626 re
->ipRouteMetric1
= -1;
10627 re
->ipRouteMetric2
= -1;
10628 re
->ipRouteMetric3
= -1;
10629 re
->ipRouteMetric4
= -1;
10631 re
->ipRouteNextHop
= ire
->ire_gateway_addr
;
10632 /* indirect(4), direct(3), or invalid(2) */
10633 if (ire
->ire_flags
& (RTF_REJECT
| RTF_BLACKHOLE
))
10634 re
->ipRouteType
= 2;
10635 else if (ire
->ire_type
& IRE_ONLINK
)
10636 re
->ipRouteType
= 3;
10638 re
->ipRouteType
= 4;
10640 re
->ipRouteProto
= -1;
10641 re
->ipRouteAge
= gethrestime_sec() - ire
->ire_create_time
;
10642 re
->ipRouteMask
= ire
->ire_mask
;
10643 re
->ipRouteMetric5
= -1;
10644 re
->ipRouteInfo
.re_max_frag
= ire
->ire_metrics
.iulp_mtu
;
10645 if (ire
->ire_ill
!= NULL
&& re
->ipRouteInfo
.re_max_frag
== 0)
10646 re
->ipRouteInfo
.re_max_frag
= ire
->ire_ill
->ill_mtu
;
10648 re
->ipRouteInfo
.re_frag_flag
= 0;
10649 re
->ipRouteInfo
.re_rtt
= 0;
10650 re
->ipRouteInfo
.re_src_addr
= 0;
10651 re
->ipRouteInfo
.re_ref
= ire
->ire_refcnt
;
10652 re
->ipRouteInfo
.re_obpkt
= ire
->ire_ob_pkt_count
;
10653 re
->ipRouteInfo
.re_ibpkt
= ire
->ire_ib_pkt_count
;
10654 re
->ipRouteInfo
.re_flags
= ire
->ire_flags
;
10656 /* Add the IRE_IF_CLONE's counters to their parent IRE_INTERFACE */
10657 if (ire
->ire_type
& IRE_INTERFACE
) {
10660 rw_enter(&ipst
->ips_ire_dep_lock
, RW_READER
);
10661 child
= ire
->ire_dep_children
;
10662 while (child
!= NULL
) {
10663 re
->ipRouteInfo
.re_obpkt
+= child
->ire_ob_pkt_count
;
10664 re
->ipRouteInfo
.re_ibpkt
+= child
->ire_ib_pkt_count
;
10665 child
= child
->ire_dep_sib_next
;
10667 rw_exit(&ipst
->ips_ire_dep_lock
);
10670 if (ire
->ire_flags
& RTF_DYNAMIC
) {
10671 re
->ipRouteInfo
.re_ire_type
= IRE_HOST_REDIRECT
;
10673 re
->ipRouteInfo
.re_ire_type
= ire
->ire_type
;
10676 if (!snmp_append_data2(ird
->ird_route
.lp_head
, &ird
->ird_route
.lp_tail
,
10677 (char *)re
, (int)sizeof (*re
))) {
10678 ip1dbg(("ip_snmp_get2_v4: failed to allocate %u bytes\n",
10679 (uint_t
)sizeof (*re
)));
10682 /* bump route index for next pass */
10685 kmem_free(re
, sizeof (*re
));
10689 * ire_walk routine to create ipv6RouteEntryTable and ipRouteEntryTable.
10692 ip_snmp_get2_v6_route(ire_t
*ire
, iproutedata_t
*ird
)
10695 mib2_ipv6RouteEntry_t
*re
;
10696 ip_stack_t
*ipst
= ire
->ire_ipst
;
10698 ASSERT(ire
->ire_ipversion
== IPV6_VERSION
);
10700 if (!(ird
->ird_flags
& IRD_REPORT_ALL
)) {
10701 if (ire
->ire_testhidden
)
10703 if (ire
->ire_type
& IRE_IF_CLONE
)
10707 if ((re
= kmem_zalloc(sizeof (*re
), KM_NOSLEEP
)) == NULL
)
10711 * Return all IRE types for route table... let caller pick and choose
10713 re
->ipv6RouteDest
= ire
->ire_addr_v6
;
10714 re
->ipv6RoutePfxLength
= ip_mask_to_plen_v6(&ire
->ire_mask_v6
);
10715 re
->ipv6RouteIndex
= 0; /* Unique when multiple with same dest/plen */
10716 re
->ipv6RouteIfIndex
.o_length
= 0;
10717 ill
= ire
->ire_ill
;
10719 ill_get_name(ill
, re
->ipv6RouteIfIndex
.o_bytes
, OCTET_LENGTH
);
10720 re
->ipv6RouteIfIndex
.o_length
=
10721 mi_strlen(re
->ipv6RouteIfIndex
.o_bytes
);
10724 ASSERT(!(ire
->ire_type
& IRE_BROADCAST
));
10726 mutex_enter(&ire
->ire_lock
);
10727 re
->ipv6RouteNextHop
= ire
->ire_gateway_addr_v6
;
10728 mutex_exit(&ire
->ire_lock
);
10730 /* remote(4), local(3), or discard(2) */
10731 if (ire
->ire_flags
& (RTF_REJECT
| RTF_BLACKHOLE
))
10732 re
->ipv6RouteType
= 2;
10733 else if (ire
->ire_type
& IRE_ONLINK
)
10734 re
->ipv6RouteType
= 3;
10736 re
->ipv6RouteType
= 4;
10738 re
->ipv6RouteProtocol
= -1;
10739 re
->ipv6RoutePolicy
= 0;
10740 re
->ipv6RouteAge
= gethrestime_sec() - ire
->ire_create_time
;
10741 re
->ipv6RouteNextHopRDI
= 0;
10742 re
->ipv6RouteWeight
= 0;
10743 re
->ipv6RouteMetric
= 0;
10744 re
->ipv6RouteInfo
.re_max_frag
= ire
->ire_metrics
.iulp_mtu
;
10745 if (ire
->ire_ill
!= NULL
&& re
->ipv6RouteInfo
.re_max_frag
== 0)
10746 re
->ipv6RouteInfo
.re_max_frag
= ire
->ire_ill
->ill_mtu
;
10748 re
->ipv6RouteInfo
.re_frag_flag
= 0;
10749 re
->ipv6RouteInfo
.re_rtt
= 0;
10750 re
->ipv6RouteInfo
.re_src_addr
= ipv6_all_zeros
;
10751 re
->ipv6RouteInfo
.re_obpkt
= ire
->ire_ob_pkt_count
;
10752 re
->ipv6RouteInfo
.re_ibpkt
= ire
->ire_ib_pkt_count
;
10753 re
->ipv6RouteInfo
.re_ref
= ire
->ire_refcnt
;
10754 re
->ipv6RouteInfo
.re_flags
= ire
->ire_flags
;
10756 /* Add the IRE_IF_CLONE's counters to their parent IRE_INTERFACE */
10757 if (ire
->ire_type
& IRE_INTERFACE
) {
10760 rw_enter(&ipst
->ips_ire_dep_lock
, RW_READER
);
10761 child
= ire
->ire_dep_children
;
10762 while (child
!= NULL
) {
10763 re
->ipv6RouteInfo
.re_obpkt
+= child
->ire_ob_pkt_count
;
10764 re
->ipv6RouteInfo
.re_ibpkt
+= child
->ire_ib_pkt_count
;
10765 child
= child
->ire_dep_sib_next
;
10767 rw_exit(&ipst
->ips_ire_dep_lock
);
10769 if (ire
->ire_flags
& RTF_DYNAMIC
) {
10770 re
->ipv6RouteInfo
.re_ire_type
= IRE_HOST_REDIRECT
;
10772 re
->ipv6RouteInfo
.re_ire_type
= ire
->ire_type
;
10775 if (!snmp_append_data2(ird
->ird_route
.lp_head
, &ird
->ird_route
.lp_tail
,
10776 (char *)re
, (int)sizeof (*re
))) {
10777 ip1dbg(("ip_snmp_get2_v6: failed to allocate %u bytes\n",
10778 (uint_t
)sizeof (*re
)));
10781 /* bump route index for next pass */
10784 kmem_free(re
, sizeof (*re
));
10788 * ncec_walk routine to create ipv6NetToMediaEntryTable
10791 ip_snmp_get2_v6_media(ncec_t
*ncec
, void *ptr
)
10793 iproutedata_t
*ird
= ptr
;
10795 mib2_ipv6NetToMediaEntry_t ntme
;
10797 ill
= ncec
->ncec_ill
;
10798 /* skip arpce entries, and loopback ncec entries */
10799 if (ill
->ill_isv6
== B_FALSE
|| ill
->ill_net_type
== IRE_LOOPBACK
)
10802 * Neighbor cache entry attached to IRE with on-link
10804 * We report all IPMP groups on ncec_ill which is normally the upper.
10806 ntme
.ipv6NetToMediaIfIndex
= ill
->ill_phyint
->phyint_ifindex
;
10807 ntme
.ipv6NetToMediaNetAddress
= ncec
->ncec_addr
;
10808 ntme
.ipv6NetToMediaPhysAddress
.o_length
= ill
->ill_phys_addr_length
;
10809 if (ncec
->ncec_lladdr
!= NULL
) {
10810 bcopy(ncec
->ncec_lladdr
, ntme
.ipv6NetToMediaPhysAddress
.o_bytes
,
10811 ntme
.ipv6NetToMediaPhysAddress
.o_length
);
10814 * Note: Returns ND_* states. Should be:
10815 * reachable(1), stale(2), delay(3), probe(4),
10816 * invalid(5), unknown(6)
10818 ntme
.ipv6NetToMediaState
= ncec
->ncec_state
;
10819 ntme
.ipv6NetToMediaLastUpdated
= 0;
10821 /* other(1), dynamic(2), static(3), local(4) */
10822 if (NCE_MYADDR(ncec
)) {
10823 ntme
.ipv6NetToMediaType
= 4;
10824 } else if (ncec
->ncec_flags
& NCE_F_PUBLISH
) {
10825 ntme
.ipv6NetToMediaType
= 1; /* proxy */
10826 } else if (ncec
->ncec_flags
& NCE_F_STATIC
) {
10827 ntme
.ipv6NetToMediaType
= 3;
10828 } else if (ncec
->ncec_flags
& (NCE_F_MCAST
|NCE_F_BCAST
)) {
10829 ntme
.ipv6NetToMediaType
= 1;
10831 ntme
.ipv6NetToMediaType
= 2;
10834 if (!snmp_append_data2(ird
->ird_netmedia
.lp_head
,
10835 &ird
->ird_netmedia
.lp_tail
, (char *)&ntme
, sizeof (ntme
))) {
10836 ip1dbg(("ip_snmp_get2_v6_media: failed to allocate %u bytes\n",
10837 (uint_t
)sizeof (ntme
)));
10842 nce2ace(ncec_t
*ncec
)
10846 if (NCE_ISREACHABLE(ncec
))
10847 flags
|= ACE_F_RESOLVED
;
10848 if (ncec
->ncec_flags
& NCE_F_AUTHORITY
)
10849 flags
|= ACE_F_AUTHORITY
;
10850 if (ncec
->ncec_flags
& NCE_F_PUBLISH
)
10851 flags
|= ACE_F_PUBLISH
;
10852 if ((ncec
->ncec_flags
& NCE_F_NONUD
) != 0)
10853 flags
|= ACE_F_PERMANENT
;
10854 if (NCE_MYADDR(ncec
))
10855 flags
|= (ACE_F_MYADDR
| ACE_F_AUTHORITY
);
10856 if (ncec
->ncec_flags
& NCE_F_UNVERIFIED
)
10857 flags
|= ACE_F_UNVERIFIED
;
10858 if (ncec
->ncec_flags
& NCE_F_AUTHORITY
)
10859 flags
|= ACE_F_AUTHORITY
;
10860 if (ncec
->ncec_flags
& NCE_F_DELAYED
)
10861 flags
|= ACE_F_DELAYED
;
10866 * ncec_walk routine to create ipNetToMediaEntryTable
10869 ip_snmp_get2_v4_media(ncec_t
*ncec
, void *ptr
)
10871 iproutedata_t
*ird
= ptr
;
10873 mib2_ipNetToMediaEntry_t ntme
;
10874 const char *name
= "unknown";
10875 ipaddr_t ncec_addr
;
10877 ill
= ncec
->ncec_ill
;
10878 if (ill
->ill_isv6
|| (ncec
->ncec_flags
& NCE_F_BCAST
) ||
10879 ill
->ill_net_type
== IRE_LOOPBACK
)
10882 /* We report all IPMP groups on ncec_ill which is normally the upper. */
10883 name
= ill
->ill_name
;
10884 /* Based on RFC 4293: other(1), inval(2), dyn(3), stat(4) */
10885 if (NCE_MYADDR(ncec
)) {
10886 ntme
.ipNetToMediaType
= 4;
10887 } else if (ncec
->ncec_flags
& (NCE_F_MCAST
|NCE_F_BCAST
|NCE_F_PUBLISH
)) {
10888 ntme
.ipNetToMediaType
= 1;
10890 ntme
.ipNetToMediaType
= 3;
10892 ntme
.ipNetToMediaIfIndex
.o_length
= MIN(OCTET_LENGTH
, strlen(name
));
10893 bcopy(name
, ntme
.ipNetToMediaIfIndex
.o_bytes
,
10894 ntme
.ipNetToMediaIfIndex
.o_length
);
10896 IN6_V4MAPPED_TO_IPADDR(&ncec
->ncec_addr
, ncec_addr
);
10897 bcopy(&ncec_addr
, &ntme
.ipNetToMediaNetAddress
, sizeof (ncec_addr
));
10899 ntme
.ipNetToMediaInfo
.ntm_mask
.o_length
= sizeof (ipaddr_t
);
10900 ncec_addr
= INADDR_BROADCAST
;
10901 bcopy(&ncec_addr
, ntme
.ipNetToMediaInfo
.ntm_mask
.o_bytes
,
10902 sizeof (ncec_addr
));
10904 * map all the flags to the ACE counterpart.
10906 ntme
.ipNetToMediaInfo
.ntm_flags
= nce2ace(ncec
);
10908 ntme
.ipNetToMediaPhysAddress
.o_length
=
10909 MIN(OCTET_LENGTH
, ill
->ill_phys_addr_length
);
10911 if (!NCE_ISREACHABLE(ncec
))
10912 ntme
.ipNetToMediaPhysAddress
.o_length
= 0;
10914 if (ncec
->ncec_lladdr
!= NULL
) {
10915 bcopy(ncec
->ncec_lladdr
,
10916 ntme
.ipNetToMediaPhysAddress
.o_bytes
,
10917 ntme
.ipNetToMediaPhysAddress
.o_length
);
10921 if (!snmp_append_data2(ird
->ird_netmedia
.lp_head
,
10922 &ird
->ird_netmedia
.lp_tail
, (char *)&ntme
, sizeof (ntme
))) {
10923 ip1dbg(("ip_snmp_get2_v4_media: failed to allocate %u bytes\n",
10924 (uint_t
)sizeof (ntme
)));
10929 * return (0) if invalid set request, 1 otherwise, including non-tcp requests
10933 ip_snmp_set(queue_t
*q
, int level
, int name
, uchar_t
*ptr
, int len
)
10949 * When there exists both a 64- and 32-bit counter of a particular type
10950 * (i.e., InReceives), only the 64-bit counters are added.
10953 ip_mib2_add_ip_stats(mib2_ipIfStatsEntry_t
*o1
, mib2_ipIfStatsEntry_t
*o2
)
10955 UPDATE_MIB(o1
, ipIfStatsInHdrErrors
, o2
->ipIfStatsInHdrErrors
);
10956 UPDATE_MIB(o1
, ipIfStatsInTooBigErrors
, o2
->ipIfStatsInTooBigErrors
);
10957 UPDATE_MIB(o1
, ipIfStatsInNoRoutes
, o2
->ipIfStatsInNoRoutes
);
10958 UPDATE_MIB(o1
, ipIfStatsInAddrErrors
, o2
->ipIfStatsInAddrErrors
);
10959 UPDATE_MIB(o1
, ipIfStatsInUnknownProtos
, o2
->ipIfStatsInUnknownProtos
);
10960 UPDATE_MIB(o1
, ipIfStatsInTruncatedPkts
, o2
->ipIfStatsInTruncatedPkts
);
10961 UPDATE_MIB(o1
, ipIfStatsInDiscards
, o2
->ipIfStatsInDiscards
);
10962 UPDATE_MIB(o1
, ipIfStatsOutDiscards
, o2
->ipIfStatsOutDiscards
);
10963 UPDATE_MIB(o1
, ipIfStatsOutFragOKs
, o2
->ipIfStatsOutFragOKs
);
10964 UPDATE_MIB(o1
, ipIfStatsOutFragFails
, o2
->ipIfStatsOutFragFails
);
10965 UPDATE_MIB(o1
, ipIfStatsOutFragCreates
, o2
->ipIfStatsOutFragCreates
);
10966 UPDATE_MIB(o1
, ipIfStatsReasmReqds
, o2
->ipIfStatsReasmReqds
);
10967 UPDATE_MIB(o1
, ipIfStatsReasmOKs
, o2
->ipIfStatsReasmOKs
);
10968 UPDATE_MIB(o1
, ipIfStatsReasmFails
, o2
->ipIfStatsReasmFails
);
10969 UPDATE_MIB(o1
, ipIfStatsOutNoRoutes
, o2
->ipIfStatsOutNoRoutes
);
10970 UPDATE_MIB(o1
, ipIfStatsReasmDuplicates
, o2
->ipIfStatsReasmDuplicates
);
10971 UPDATE_MIB(o1
, ipIfStatsReasmPartDups
, o2
->ipIfStatsReasmPartDups
);
10972 UPDATE_MIB(o1
, ipIfStatsForwProhibits
, o2
->ipIfStatsForwProhibits
);
10973 UPDATE_MIB(o1
, udpInCksumErrs
, o2
->udpInCksumErrs
);
10974 UPDATE_MIB(o1
, udpInOverflows
, o2
->udpInOverflows
);
10975 UPDATE_MIB(o1
, rawipInOverflows
, o2
->rawipInOverflows
);
10976 UPDATE_MIB(o1
, ipIfStatsInWrongIPVersion
,
10977 o2
->ipIfStatsInWrongIPVersion
);
10978 UPDATE_MIB(o1
, ipIfStatsOutWrongIPVersion
,
10979 o2
->ipIfStatsInWrongIPVersion
);
10980 UPDATE_MIB(o1
, ipIfStatsOutSwitchIPVersion
,
10981 o2
->ipIfStatsOutSwitchIPVersion
);
10982 UPDATE_MIB(o1
, ipIfStatsHCInReceives
, o2
->ipIfStatsHCInReceives
);
10983 UPDATE_MIB(o1
, ipIfStatsHCInOctets
, o2
->ipIfStatsHCInOctets
);
10984 UPDATE_MIB(o1
, ipIfStatsHCInForwDatagrams
,
10985 o2
->ipIfStatsHCInForwDatagrams
);
10986 UPDATE_MIB(o1
, ipIfStatsHCInDelivers
, o2
->ipIfStatsHCInDelivers
);
10987 UPDATE_MIB(o1
, ipIfStatsHCOutRequests
, o2
->ipIfStatsHCOutRequests
);
10988 UPDATE_MIB(o1
, ipIfStatsHCOutForwDatagrams
,
10989 o2
->ipIfStatsHCOutForwDatagrams
);
10990 UPDATE_MIB(o1
, ipIfStatsOutFragReqds
, o2
->ipIfStatsOutFragReqds
);
10991 UPDATE_MIB(o1
, ipIfStatsHCOutTransmits
, o2
->ipIfStatsHCOutTransmits
);
10992 UPDATE_MIB(o1
, ipIfStatsHCOutOctets
, o2
->ipIfStatsHCOutOctets
);
10993 UPDATE_MIB(o1
, ipIfStatsHCInMcastPkts
, o2
->ipIfStatsHCInMcastPkts
);
10994 UPDATE_MIB(o1
, ipIfStatsHCInMcastOctets
, o2
->ipIfStatsHCInMcastOctets
);
10995 UPDATE_MIB(o1
, ipIfStatsHCOutMcastPkts
, o2
->ipIfStatsHCOutMcastPkts
);
10996 UPDATE_MIB(o1
, ipIfStatsHCOutMcastOctets
,
10997 o2
->ipIfStatsHCOutMcastOctets
);
10998 UPDATE_MIB(o1
, ipIfStatsHCInBcastPkts
, o2
->ipIfStatsHCInBcastPkts
);
10999 UPDATE_MIB(o1
, ipIfStatsHCOutBcastPkts
, o2
->ipIfStatsHCOutBcastPkts
);
11000 UPDATE_MIB(o1
, ipsecInSucceeded
, o2
->ipsecInSucceeded
);
11001 UPDATE_MIB(o1
, ipsecInFailed
, o2
->ipsecInFailed
);
11002 UPDATE_MIB(o1
, ipInCksumErrs
, o2
->ipInCksumErrs
);
11003 UPDATE_MIB(o1
, tcpInErrs
, o2
->tcpInErrs
);
11004 UPDATE_MIB(o1
, udpNoPorts
, o2
->udpNoPorts
);
11008 ip_mib2_add_icmp6_stats(mib2_ipv6IfIcmpEntry_t
*o1
, mib2_ipv6IfIcmpEntry_t
*o2
)
11010 UPDATE_MIB(o1
, ipv6IfIcmpInMsgs
, o2
->ipv6IfIcmpInMsgs
);
11011 UPDATE_MIB(o1
, ipv6IfIcmpInErrors
, o2
->ipv6IfIcmpInErrors
);
11012 UPDATE_MIB(o1
, ipv6IfIcmpInDestUnreachs
, o2
->ipv6IfIcmpInDestUnreachs
);
11013 UPDATE_MIB(o1
, ipv6IfIcmpInAdminProhibs
, o2
->ipv6IfIcmpInAdminProhibs
);
11014 UPDATE_MIB(o1
, ipv6IfIcmpInTimeExcds
, o2
->ipv6IfIcmpInTimeExcds
);
11015 UPDATE_MIB(o1
, ipv6IfIcmpInParmProblems
, o2
->ipv6IfIcmpInParmProblems
);
11016 UPDATE_MIB(o1
, ipv6IfIcmpInPktTooBigs
, o2
->ipv6IfIcmpInPktTooBigs
);
11017 UPDATE_MIB(o1
, ipv6IfIcmpInEchos
, o2
->ipv6IfIcmpInEchos
);
11018 UPDATE_MIB(o1
, ipv6IfIcmpInEchoReplies
, o2
->ipv6IfIcmpInEchoReplies
);
11019 UPDATE_MIB(o1
, ipv6IfIcmpInRouterSolicits
,
11020 o2
->ipv6IfIcmpInRouterSolicits
);
11021 UPDATE_MIB(o1
, ipv6IfIcmpInRouterAdvertisements
,
11022 o2
->ipv6IfIcmpInRouterAdvertisements
);
11023 UPDATE_MIB(o1
, ipv6IfIcmpInNeighborSolicits
,
11024 o2
->ipv6IfIcmpInNeighborSolicits
);
11025 UPDATE_MIB(o1
, ipv6IfIcmpInNeighborAdvertisements
,
11026 o2
->ipv6IfIcmpInNeighborAdvertisements
);
11027 UPDATE_MIB(o1
, ipv6IfIcmpInRedirects
, o2
->ipv6IfIcmpInRedirects
);
11028 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembQueries
,
11029 o2
->ipv6IfIcmpInGroupMembQueries
);
11030 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembResponses
,
11031 o2
->ipv6IfIcmpInGroupMembResponses
);
11032 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembReductions
,
11033 o2
->ipv6IfIcmpInGroupMembReductions
);
11034 UPDATE_MIB(o1
, ipv6IfIcmpOutMsgs
, o2
->ipv6IfIcmpOutMsgs
);
11035 UPDATE_MIB(o1
, ipv6IfIcmpOutErrors
, o2
->ipv6IfIcmpOutErrors
);
11036 UPDATE_MIB(o1
, ipv6IfIcmpOutDestUnreachs
,
11037 o2
->ipv6IfIcmpOutDestUnreachs
);
11038 UPDATE_MIB(o1
, ipv6IfIcmpOutAdminProhibs
,
11039 o2
->ipv6IfIcmpOutAdminProhibs
);
11040 UPDATE_MIB(o1
, ipv6IfIcmpOutTimeExcds
, o2
->ipv6IfIcmpOutTimeExcds
);
11041 UPDATE_MIB(o1
, ipv6IfIcmpOutParmProblems
,
11042 o2
->ipv6IfIcmpOutParmProblems
);
11043 UPDATE_MIB(o1
, ipv6IfIcmpOutPktTooBigs
, o2
->ipv6IfIcmpOutPktTooBigs
);
11044 UPDATE_MIB(o1
, ipv6IfIcmpOutEchos
, o2
->ipv6IfIcmpOutEchos
);
11045 UPDATE_MIB(o1
, ipv6IfIcmpOutEchoReplies
, o2
->ipv6IfIcmpOutEchoReplies
);
11046 UPDATE_MIB(o1
, ipv6IfIcmpOutRouterSolicits
,
11047 o2
->ipv6IfIcmpOutRouterSolicits
);
11048 UPDATE_MIB(o1
, ipv6IfIcmpOutRouterAdvertisements
,
11049 o2
->ipv6IfIcmpOutRouterAdvertisements
);
11050 UPDATE_MIB(o1
, ipv6IfIcmpOutNeighborSolicits
,
11051 o2
->ipv6IfIcmpOutNeighborSolicits
);
11052 UPDATE_MIB(o1
, ipv6IfIcmpOutNeighborAdvertisements
,
11053 o2
->ipv6IfIcmpOutNeighborAdvertisements
);
11054 UPDATE_MIB(o1
, ipv6IfIcmpOutRedirects
, o2
->ipv6IfIcmpOutRedirects
);
11055 UPDATE_MIB(o1
, ipv6IfIcmpOutGroupMembQueries
,
11056 o2
->ipv6IfIcmpOutGroupMembQueries
);
11057 UPDATE_MIB(o1
, ipv6IfIcmpOutGroupMembResponses
,
11058 o2
->ipv6IfIcmpOutGroupMembResponses
);
11059 UPDATE_MIB(o1
, ipv6IfIcmpOutGroupMembReductions
,
11060 o2
->ipv6IfIcmpOutGroupMembReductions
);
11061 UPDATE_MIB(o1
, ipv6IfIcmpInOverflows
, o2
->ipv6IfIcmpInOverflows
);
11062 UPDATE_MIB(o1
, ipv6IfIcmpBadHoplimit
, o2
->ipv6IfIcmpBadHoplimit
);
11063 UPDATE_MIB(o1
, ipv6IfIcmpInBadNeighborAdvertisements
,
11064 o2
->ipv6IfIcmpInBadNeighborAdvertisements
);
11065 UPDATE_MIB(o1
, ipv6IfIcmpInBadNeighborSolicitations
,
11066 o2
->ipv6IfIcmpInBadNeighborSolicitations
);
11067 UPDATE_MIB(o1
, ipv6IfIcmpInBadRedirects
, o2
->ipv6IfIcmpInBadRedirects
);
11068 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembTotal
,
11069 o2
->ipv6IfIcmpInGroupMembTotal
);
11070 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembBadQueries
,
11071 o2
->ipv6IfIcmpInGroupMembBadQueries
);
11072 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembBadReports
,
11073 o2
->ipv6IfIcmpInGroupMembBadReports
);
11074 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembOurReports
,
11075 o2
->ipv6IfIcmpInGroupMembOurReports
);
11079 * Called before the options are updated to check if this packet will
11080 * be source routed from here.
11081 * This routine assumes that the options are well formed i.e. that they
11082 * have already been checked.
11085 ip_source_routed(ipha_t
*ipha
, ip_stack_t
*ipst
)
11093 if (IS_SIMPLE_IPH(ipha
)) {
11094 ip2dbg(("not source routed\n"));
11097 dst
= ipha
->ipha_dst
;
11098 for (optval
= ipoptp_first(&opts
, ipha
);
11099 optval
!= IPOPT_EOL
;
11100 optval
= ipoptp_next(&opts
)) {
11101 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
11102 opt
= opts
.ipoptp_cur
;
11103 optlen
= opts
.ipoptp_len
;
11104 ip2dbg(("ip_source_routed: opt %d, len %d\n",
11111 * If dst is one of our addresses and there are some
11112 * entries left in the source route return (true).
11114 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
11115 ip2dbg(("ip_source_routed: not next"
11116 " source route 0x%x\n",
11120 off
= opt
[IPOPT_OFFSET
];
11122 if (optlen
< IP_ADDR_LEN
||
11123 off
> optlen
- IP_ADDR_LEN
) {
11124 /* End of source route */
11125 ip1dbg(("ip_source_routed: end of SR\n"));
11131 ip2dbg(("not source routed\n"));
11136 * ip_unbind is called by the transports to remove a conn from
11137 * the fanout table.
11140 ip_unbind(conn_t
*connp
)
11143 ASSERT(!MUTEX_HELD(&connp
->conn_lock
));
11145 ipcl_hash_remove(connp
);
11149 * Used for deciding the MSS size for the upper layer. Thus
11150 * we need to check the outbound policy values in the conn.
11153 conn_ipsec_length(conn_t
*connp
)
11155 ipsec_latch_t
*ipl
;
11157 ipl
= connp
->conn_latch
;
11161 if (connp
->conn_ixa
->ixa_ipsec_policy
== NULL
)
11164 return (connp
->conn_ixa
->ixa_ipsec_policy
->ipsp_act
->ipa_ovhd
);
11168 * Returns an estimate of the IPsec headers size. This is used if
11169 * we don't want to call into IPsec to get the exact size.
11172 ipsec_out_extra_length(ip_xmit_attr_t
*ixa
)
11176 if (!(ixa
->ixa_flags
& IXAF_IPSEC_SECURE
))
11179 a
= ixa
->ixa_ipsec_action
;
11181 ASSERT(ixa
->ixa_ipsec_policy
!= NULL
);
11182 a
= ixa
->ixa_ipsec_policy
->ipsp_act
;
11186 return (a
->ipa_ovhd
);
11190 * If there are any source route options, return the true final
11191 * destination. Otherwise, return the destination.
11194 ip_get_dst(ipha_t
*ipha
)
11203 dst
= ipha
->ipha_dst
;
11205 if (IS_SIMPLE_IPH(ipha
))
11208 for (optval
= ipoptp_first(&opts
, ipha
);
11209 optval
!= IPOPT_EOL
;
11210 optval
= ipoptp_next(&opts
)) {
11211 opt
= opts
.ipoptp_cur
;
11212 optlen
= opts
.ipoptp_len
;
11213 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
11217 off
= opt
[IPOPT_OFFSET
];
11219 * If one of the conditions is true, it means
11220 * end of options and dst already has the right
11223 if (!(optlen
< IP_ADDR_LEN
|| off
> optlen
- 3)) {
11224 off
= optlen
- IP_ADDR_LEN
;
11225 bcopy(&opt
[off
], &dst
, IP_ADDR_LEN
);
11237 * Outbound IP fragmentation routine.
11238 * Assumes the caller has checked whether or not fragmentation should
11239 * be allowed. Here we copy the DF bit from the header to all the generated
11243 ip_fragment_v4(mblk_t
*mp_orig
, nce_t
*nce
, iaflags_t ixaflags
,
11244 uint_t pkt_len
, uint32_t max_frag
, uint32_t xmit_hint
, zoneid_t szone
,
11245 zoneid_t nolzid
, pfirepostfrag_t postfragfn
, uintptr_t *ixa_cookie
)
11253 mblk_t
*mp
= mp_orig
;
11255 ill_t
*ill
= nce
->nce_ill
;
11256 ip_stack_t
*ipst
= ill
->ill_ipst
;
11258 uint32_t frag_flag
;
11259 uint_t priority
= mp
->b_band
;
11262 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragReqds
);
11264 if (pkt_len
!= msgdsize(mp
)) {
11265 ip0dbg(("Packet length mismatch: %d, %ld\n",
11266 pkt_len
, msgdsize(mp
)));
11271 if (max_frag
== 0) {
11272 ip1dbg(("ip_fragment_v4: max_frag is zero. Dropping packet\n"));
11273 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11274 ip_drop_output("FragFails: zero max_frag", mp
, ill
);
11279 ASSERT(MBLKL(mp
) >= sizeof (ipha_t
));
11280 ipha
= (ipha_t
*)mp
->b_rptr
;
11281 ASSERT(ntohs(ipha
->ipha_length
) == pkt_len
);
11282 frag_flag
= ntohs(ipha
->ipha_fragment_offset_and_flags
) & IPH_DF
;
11285 * Establish the starting offset. May not be zero if we are fragging
11286 * a fragment that is being forwarded.
11288 offset
= ntohs(ipha
->ipha_fragment_offset_and_flags
) & IPH_OFFSET
;
11290 /* TODO why is this test needed? */
11291 if (((max_frag
- ntohs(ipha
->ipha_length
)) & ~7) < 8) {
11292 /* TODO: notify ulp somehow */
11293 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11294 ip_drop_output("FragFails: bad starting offset", mp
, ill
);
11299 hdr_len
= IPH_HDR_LENGTH(ipha
);
11300 ipha
->ipha_hdr_checksum
= 0;
11303 * Establish the number of bytes maximum per frag, after putting
11306 len
= (max_frag
- hdr_len
) & ~7;
11308 /* Get a copy of the header for the trailing frags */
11309 hdr_mp
= ip_fragment_copyhdr((uchar_t
*)ipha
, hdr_len
, offset
, ipst
,
11311 if (hdr_mp
== NULL
) {
11312 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11313 ip_drop_output("FragFails: no hdr_mp", mp
, ill
);
11318 /* Store the starting offset, with the MoreFrags flag. */
11319 i1
= offset
| IPH_MF
| frag_flag
;
11320 ipha
->ipha_fragment_offset_and_flags
= htons((uint16_t)i1
);
11322 /* Establish the ending byte offset, based on the starting offset. */
11324 ip_data_end
= offset
+ ntohs(ipha
->ipha_length
) - hdr_len
;
11326 /* Store the length of the first fragment in the IP header. */
11327 i1
= len
+ hdr_len
;
11328 ASSERT(i1
<= IP_MAXPACKET
);
11329 ipha
->ipha_length
= htons((uint16_t)i1
);
11332 * Compute the IP header checksum for the first frag. We have to
11333 * watch out that we stop at the end of the header.
11335 ipha
->ipha_hdr_checksum
= ip_csum_hdr(ipha
);
11338 * Now carve off the first frag. Note that this will include the
11339 * original IP header.
11341 if (!(mp
= ip_carve_mp(&mp_orig
, i1
))) {
11342 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11343 ip_drop_output("FragFails: could not carve mp", mp_orig
, ill
);
11349 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragCreates
);
11351 error
= postfragfn(mp
, nce
, ixaflags
, i1
, xmit_hint
, szone
, nolzid
,
11353 if (error
!= 0 && error
!= EWOULDBLOCK
) {
11354 /* No point in sending the other fragments */
11355 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11356 ip_drop_output("FragFails: postfragfn failed", mp_orig
, ill
);
11362 /* No need to redo state machine in loop */
11363 ixaflags
&= ~IXAF_REACH_CONF
;
11365 /* Advance the offset to the second frag starting point. */
11368 * Update hdr_len from the copied header - there might be less options
11369 * in the later fragments.
11371 hdr_len
= IPH_HDR_LENGTH(hdr_mp
->b_rptr
);
11372 /* Loop until done. */
11374 uint16_t offset_and_flags
;
11377 if (ip_data_end
- offset
> len
) {
11379 * Carve off the appropriate amount from the original
11382 if (!(carve_mp
= ip_carve_mp(&mp_orig
, len
))) {
11387 * More frags after this one. Get another copy
11390 if (carve_mp
->b_datap
->db_ref
== 1 &&
11391 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
<
11392 carve_mp
->b_rptr
- carve_mp
->b_datap
->db_base
) {
11393 /* Inline IP header */
11394 carve_mp
->b_rptr
-= hdr_mp
->b_wptr
-
11396 bcopy(hdr_mp
->b_rptr
, carve_mp
->b_rptr
,
11397 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
);
11400 if (!(mp
= copyb(hdr_mp
))) {
11404 /* Get priority marking, if any. */
11405 mp
->b_band
= priority
;
11406 mp
->b_cont
= carve_mp
;
11408 ipha
= (ipha_t
*)mp
->b_rptr
;
11409 offset_and_flags
= IPH_MF
;
11412 * Last frag. Consume the header. Set len to
11413 * the length of this last piece.
11415 len
= ip_data_end
- offset
;
11418 * Carve off the appropriate amount from the original
11421 if (!(carve_mp
= ip_carve_mp(&mp_orig
, len
))) {
11425 if (carve_mp
->b_datap
->db_ref
== 1 &&
11426 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
<
11427 carve_mp
->b_rptr
- carve_mp
->b_datap
->db_base
) {
11428 /* Inline IP header */
11429 carve_mp
->b_rptr
-= hdr_mp
->b_wptr
-
11431 bcopy(hdr_mp
->b_rptr
, carve_mp
->b_rptr
,
11432 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
);
11438 /* Get priority marking, if any. */
11439 mp
->b_band
= priority
;
11440 mp
->b_cont
= carve_mp
;
11442 ipha
= (ipha_t
*)mp
->b_rptr
;
11443 /* A frag of a frag might have IPH_MF non-zero */
11445 ntohs(ipha
->ipha_fragment_offset_and_flags
) &
11448 offset_and_flags
|= (uint16_t)(offset
>> 3);
11449 offset_and_flags
|= (uint16_t)frag_flag
;
11450 /* Store the offset and flags in the IP header. */
11451 ipha
->ipha_fragment_offset_and_flags
= htons(offset_and_flags
);
11453 /* Store the length in the IP header. */
11454 ip_len
= (uint16_t)(len
+ hdr_len
);
11455 ipha
->ipha_length
= htons(ip_len
);
11458 * Set the IP header checksum. Note that mp is just
11459 * the header, so this is easy to pass to ip_csum.
11461 ipha
->ipha_hdr_checksum
= ip_csum_hdr(ipha
);
11463 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragCreates
);
11465 error
= postfragfn(mp
, nce
, ixaflags
, ip_len
, xmit_hint
, szone
,
11466 nolzid
, ixa_cookie
);
11467 /* All done if we just consumed the hdr_mp. */
11468 if (mp
== hdr_mp
) {
11469 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragOKs
);
11472 if (error
!= 0 && error
!= EWOULDBLOCK
) {
11473 DTRACE_PROBE2(ip__xmit__frag__fail
, ill_t
*, ill
,
11475 /* No point in sending the other fragments */
11479 /* Otherwise, advance and loop. */
11482 /* Clean up following allocation failure. */
11483 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11484 ip_drop_output("FragFails: loop ended", NULL
, ill
);
11493 * Copy the header plus those options which have the copy bit set
11496 ip_fragment_copyhdr(uchar_t
*rptr
, int hdr_len
, int offset
, ip_stack_t
*ipst
,
11503 * Quick check if we need to look for options without the copy bit
11506 mp
= allocb_tmpl(ipst
->ips_ip_wroff_extra
+ hdr_len
, src
);
11509 mp
->b_rptr
+= ipst
->ips_ip_wroff_extra
;
11510 if (hdr_len
== IP_SIMPLE_HDR_LENGTH
|| offset
!= 0) {
11511 bcopy(rptr
, mp
->b_rptr
, hdr_len
);
11512 mp
->b_wptr
+= hdr_len
+ ipst
->ips_ip_wroff_extra
;
11516 bcopy(rptr
, up
, IP_SIMPLE_HDR_LENGTH
);
11517 up
+= IP_SIMPLE_HDR_LENGTH
;
11518 rptr
+= IP_SIMPLE_HDR_LENGTH
;
11519 hdr_len
-= IP_SIMPLE_HDR_LENGTH
;
11520 while (hdr_len
> 0) {
11525 if (optval
== IPOPT_EOL
)
11527 if (optval
== IPOPT_NOP
)
11531 if (optval
& IPOPT_COPY
) {
11532 bcopy(rptr
, up
, optlen
);
11539 * Make sure that we drop an even number of words by filling
11540 * with EOL to the next word boundary.
11542 for (hdr_len
= up
- (mp
->b_rptr
+ IP_SIMPLE_HDR_LENGTH
);
11543 hdr_len
& 0x3; hdr_len
++)
11546 /* Update header length */
11547 mp
->b_rptr
[0] = (uint8_t)((IP_VERSION
<< 4) | ((up
- mp
->b_rptr
) >> 2));
11552 * Update any source route, record route, or timestamp options when
11553 * sending a packet back to ourselves.
11554 * Check that we are at end of strict source route.
11555 * The options have been sanity checked by ip_output_options().
11558 ip_output_local_options(ipha_t
*ipha
, ip_stack_t
*ipst
)
11568 for (optval
= ipoptp_first(&opts
, ipha
);
11569 optval
!= IPOPT_EOL
;
11570 optval
= ipoptp_next(&opts
)) {
11571 opt
= opts
.ipoptp_cur
;
11572 optlen
= opts
.ipoptp_len
;
11573 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
11578 off
= opt
[IPOPT_OFFSET
];
11580 if (optlen
< IP_ADDR_LEN
||
11581 off
> optlen
- IP_ADDR_LEN
) {
11582 /* End of source route */
11586 * This will only happen if two consecutive entries
11587 * in the source route contains our address or if
11588 * it is a packet with a loose source route which
11589 * reaches us before consuming the whole source route
11592 if (optval
== IPOPT_SSRR
) {
11596 * Hack: instead of dropping the packet truncate the
11597 * source route to what has been used by filling the
11598 * rest with IPOPT_NOP.
11600 opt
[IPOPT_OLEN
] = (uint8_t)off
;
11601 while (off
< optlen
) {
11602 opt
[off
++] = IPOPT_NOP
;
11606 off
= opt
[IPOPT_OFFSET
];
11608 if (optlen
< IP_ADDR_LEN
||
11609 off
> optlen
- IP_ADDR_LEN
) {
11610 /* No more room - ignore */
11612 "ip_output_local_options: end of RR\n"));
11615 dst
= htonl(INADDR_LOOPBACK
);
11616 bcopy(&dst
, (char *)opt
+ off
, IP_ADDR_LEN
);
11617 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
11620 /* Insert timestamp if there is romm */
11621 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
11622 case IPOPT_TS_TSONLY
:
11623 off
= IPOPT_TS_TIMELEN
;
11625 case IPOPT_TS_PRESPEC
:
11626 case IPOPT_TS_PRESPEC_RFC791
:
11627 /* Verify that the address matched */
11628 off
= opt
[IPOPT_OFFSET
] - 1;
11629 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
11630 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
11635 case IPOPT_TS_TSANDADDR
:
11636 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
11640 * ip_*put_options should have already
11641 * dropped this packet.
11643 cmn_err(CE_PANIC
, "ip_output_local_options: "
11644 "unknown IT - bug in ip_output_options?\n");
11645 return; /* Keep "lint" happy */
11647 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
) {
11648 /* Increase overflow counter */
11649 off
= (opt
[IPOPT_POS_OV_FLG
] >> 4) + 1;
11650 opt
[IPOPT_POS_OV_FLG
] = (uint8_t)
11651 (opt
[IPOPT_POS_OV_FLG
] & 0x0F) |
11655 off
= opt
[IPOPT_OFFSET
] - 1;
11656 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
11657 case IPOPT_TS_PRESPEC
:
11658 case IPOPT_TS_PRESPEC_RFC791
:
11659 case IPOPT_TS_TSANDADDR
:
11660 dst
= htonl(INADDR_LOOPBACK
);
11661 bcopy(&dst
, (char *)opt
+ off
, IP_ADDR_LEN
);
11662 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
11664 case IPOPT_TS_TSONLY
:
11665 off
= opt
[IPOPT_OFFSET
] - 1;
11666 /* Compute # of milliseconds since midnight */
11668 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
11669 NSEC2MSEC(now
.tv_nsec
);
11670 bcopy(&ts
, (char *)opt
+ off
, IPOPT_TS_TIMELEN
);
11671 opt
[IPOPT_OFFSET
] += IPOPT_TS_TIMELEN
;
11680 * Prepend an M_DATA fastpath header, and if none present prepend a
11681 * DL_UNITDATA_REQ. Frees the mblk on failure.
11683 * nce_dlur_mp and nce_fp_mp can not disappear once they have been set.
11684 * If there is a change to them, the nce will be deleted (condemned) and
11685 * a new nce_t will be created when packets are sent. Thus we need no locks
11686 * to access those fields.
11688 * We preserve b_band to support IPQoS. If a DL_UNITDATA_REQ is prepended
11689 * we place b_band in dl_priority.dl_max.
11692 ip_xmit_attach_llhdr(mblk_t
*mp
, nce_t
*nce
)
11701 ASSERT(DB_TYPE(mp
) == M_DATA
);
11702 priority
= mp
->b_band
;
11704 ASSERT(nce
!= NULL
);
11705 if ((mp1
= nce
->nce_fp_mp
) != NULL
) {
11708 * Check if we have enough room to prepend fastpath
11711 if (hlen
!= 0 && (rptr
- mp
->b_datap
->db_base
) >= hlen
) {
11713 bcopy(mp1
->b_rptr
, rptr
, hlen
);
11715 * Set the b_rptr to the start of the link layer
11723 ill_t
*ill
= nce
->nce_ill
;
11725 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
11726 ip_drop_output("ipIfStatsOutDiscards", mp
, ill
);
11730 mp1
->b_band
= priority
;
11732 DB_CKSUMSTART(mp1
) = DB_CKSUMSTART(mp
);
11733 DB_CKSUMSTUFF(mp1
) = DB_CKSUMSTUFF(mp
);
11734 DB_CKSUMEND(mp1
) = DB_CKSUMEND(mp
);
11735 DB_CKSUMFLAGS(mp1
) = DB_CKSUMFLAGS(mp
);
11736 DB_LSOMSS(mp1
) = DB_LSOMSS(mp
);
11737 DTRACE_PROBE1(ip__xmit__copyb
, (mblk_t
*), mp1
);
11739 * XXX disable ICK_VALID and compute checksum
11740 * here; can happen if nce_fp_mp changes and
11741 * it can't be copied now due to insufficient
11742 * space. (unlikely, fp mp can change, but it
11743 * does not increase in length)
11747 mp1
= copyb(nce
->nce_dlur_mp
);
11750 ill_t
*ill
= nce
->nce_ill
;
11752 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
11753 ip_drop_output("ipIfStatsOutDiscards", mp
, ill
);
11758 if (priority
!= 0) {
11759 mp1
->b_band
= priority
;
11760 ((dl_unitdata_req_t
*)(mp1
->b_rptr
))->dl_priority
.dl_max
=
11767 * Finish the outbound IPsec processing. This function is called from
11768 * ipsec_out_process() if the IPsec packet was processed
11769 * synchronously, or from {ah,esp}_kcf_callback_outbound() if it was processed
11772 * This is common to IPv4 and IPv6.
11775 ip_output_post_ipsec(mblk_t
*mp
, ip_xmit_attr_t
*ixa
)
11777 iaflags_t ixaflags
= ixa
->ixa_flags
;
11781 /* AH/ESP don't update ixa_pktlen when they modify the packet */
11782 if (ixaflags
& IXAF_IS_IPV4
) {
11783 ipha_t
*ipha
= (ipha_t
*)mp
->b_rptr
;
11785 ASSERT(IPH_HDR_VERSION(ipha
) == IPV4_VERSION
);
11786 pktlen
= ntohs(ipha
->ipha_length
);
11788 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
11790 ASSERT(IPH_HDR_VERSION(mp
->b_rptr
) == IPV6_VERSION
);
11791 pktlen
= ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
;
11795 * We release any hard reference on the SAs here to make
11796 * sure the SAs can be garbage collected. ipsr_sa has a soft reference
11798 * If in the future we want the hard latching of the SAs in the
11799 * ip_xmit_attr_t then we should remove this.
11801 if (ixa
->ixa_ipsec_esp_sa
!= NULL
) {
11802 IPSA_REFRELE(ixa
->ixa_ipsec_esp_sa
);
11803 ixa
->ixa_ipsec_esp_sa
= NULL
;
11805 if (ixa
->ixa_ipsec_ah_sa
!= NULL
) {
11806 IPSA_REFRELE(ixa
->ixa_ipsec_ah_sa
);
11807 ixa
->ixa_ipsec_ah_sa
= NULL
;
11810 /* Do we need to fragment? */
11811 if ((ixa
->ixa_flags
& IXAF_IPV6_ADD_FRAGHDR
) ||
11812 pktlen
> ixa
->ixa_fragsize
) {
11813 if (ixaflags
& IXAF_IS_IPV4
) {
11814 ASSERT(!(ixa
->ixa_flags
& IXAF_IPV6_ADD_FRAGHDR
));
11816 * We check for the DF case in ipsec_out_process
11817 * hence this only handles the non-DF case.
11819 return (ip_fragment_v4(mp
, ixa
->ixa_nce
, ixa
->ixa_flags
,
11820 pktlen
, ixa
->ixa_fragsize
,
11821 ixa
->ixa_xmit_hint
, ixa
->ixa_zoneid
,
11822 ixa
->ixa_no_loop_zoneid
, ixa
->ixa_postfragfn
,
11823 &ixa
->ixa_cookie
));
11825 mp
= ip_fraghdr_add_v6(mp
, ixa
->ixa_ident
, ixa
);
11827 /* MIB and ip_drop_output already done */
11830 pktlen
+= sizeof (ip6_frag_t
);
11831 if (pktlen
> ixa
->ixa_fragsize
) {
11832 return (ip_fragment_v6(mp
, ixa
->ixa_nce
,
11833 ixa
->ixa_flags
, pktlen
,
11834 ixa
->ixa_fragsize
, ixa
->ixa_xmit_hint
,
11835 ixa
->ixa_zoneid
, ixa
->ixa_no_loop_zoneid
,
11836 ixa
->ixa_postfragfn
, &ixa
->ixa_cookie
));
11840 return ((ixa
->ixa_postfragfn
)(mp
, ixa
->ixa_nce
, ixa
->ixa_flags
,
11841 pktlen
, ixa
->ixa_xmit_hint
, ixa
->ixa_zoneid
,
11842 ixa
->ixa_no_loop_zoneid
, NULL
));
11846 * Finish the inbound IPsec processing. This function is called from
11847 * ipsec_out_process() if the IPsec packet was processed
11848 * synchronously, or from {ah,esp}_kcf_callback_outbound() if it was processed
11851 * This is common to IPv4 and IPv6.
11854 ip_input_post_ipsec(mblk_t
*mp
, ip_recv_attr_t
*ira
)
11856 iaflags_t iraflags
= ira
->ira_flags
;
11858 /* Length might have changed */
11859 if (iraflags
& IRAF_IS_IPV4
) {
11860 ipha_t
*ipha
= (ipha_t
*)mp
->b_rptr
;
11862 ASSERT(IPH_HDR_VERSION(ipha
) == IPV4_VERSION
);
11863 ira
->ira_pktlen
= ntohs(ipha
->ipha_length
);
11864 ira
->ira_ip_hdr_length
= IPH_HDR_LENGTH(ipha
);
11865 ira
->ira_protocol
= ipha
->ipha_protocol
;
11867 ip_fanout_v4(mp
, ipha
, ira
);
11869 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
11872 ASSERT(IPH_HDR_VERSION(mp
->b_rptr
) == IPV6_VERSION
);
11873 ira
->ira_pktlen
= ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
;
11874 if (!ip_hdr_length_nexthdr_v6(mp
, ip6h
, &ira
->ira_ip_hdr_length
,
11876 /* Malformed packet */
11877 BUMP_MIB(ira
->ira_ill
->ill_ip_mib
, ipIfStatsInDiscards
);
11878 ip_drop_input("ipIfStatsInDiscards", mp
, ira
->ira_ill
);
11882 ira
->ira_protocol
= *nexthdrp
;
11883 ip_fanout_v6(mp
, ip6h
, ira
);
11888 * Select which AH & ESP SA's to use (if any) for the outbound packet.
11890 * If this function returns B_TRUE, the requested SA's have been filled
11891 * into the ixa_ipsec_*_sa pointers.
11893 * If the function returns B_FALSE, the packet has been "consumed", most
11894 * likely by an ACQUIRE sent up via PF_KEY to a key management daemon.
11896 * The SA references created by the protocol-specific "select"
11897 * function will be released in ip_output_post_ipsec.
11900 ipsec_out_select_sa(mblk_t
*mp
, ip_xmit_attr_t
*ixa
)
11902 boolean_t need_ah_acquire
= B_FALSE
, need_esp_acquire
= B_FALSE
;
11903 ipsec_policy_t
*pp
;
11904 ipsec_action_t
*ap
;
11906 ASSERT(ixa
->ixa_flags
& IXAF_IPSEC_SECURE
);
11907 ASSERT((ixa
->ixa_ipsec_policy
!= NULL
) ||
11908 (ixa
->ixa_ipsec_action
!= NULL
));
11910 ap
= ixa
->ixa_ipsec_action
;
11912 pp
= ixa
->ixa_ipsec_policy
;
11913 ASSERT(pp
!= NULL
);
11915 ASSERT(ap
!= NULL
);
11919 * We have an action. now, let's select SA's.
11920 * A side effect of setting ixa_ipsec_*_sa is that it will
11921 * be cached in the conn_t.
11923 if (ap
->ipa_want_esp
) {
11924 if (ixa
->ixa_ipsec_esp_sa
== NULL
) {
11925 need_esp_acquire
= !ipsec_outbound_sa(mp
, ixa
,
11928 ASSERT(need_esp_acquire
|| ixa
->ixa_ipsec_esp_sa
!= NULL
);
11931 if (ap
->ipa_want_ah
) {
11932 if (ixa
->ixa_ipsec_ah_sa
== NULL
) {
11933 need_ah_acquire
= !ipsec_outbound_sa(mp
, ixa
,
11936 ASSERT(need_ah_acquire
|| ixa
->ixa_ipsec_ah_sa
!= NULL
);
11938 * The ESP and AH processing order needs to be preserved
11939 * when both protocols are required (ESP should be applied
11940 * before AH for an outbound packet). Force an ESP ACQUIRE
11941 * when both ESP and AH are required, and an AH ACQUIRE
11944 if (ap
->ipa_want_esp
&& need_ah_acquire
)
11945 need_esp_acquire
= B_TRUE
;
11949 * Send an ACQUIRE (extended, regular, or both) if we need one.
11950 * Release SAs that got referenced, but will not be used until we
11951 * acquire _all_ of the SAs we need.
11953 if (need_ah_acquire
|| need_esp_acquire
) {
11954 if (ixa
->ixa_ipsec_ah_sa
!= NULL
) {
11955 IPSA_REFRELE(ixa
->ixa_ipsec_ah_sa
);
11956 ixa
->ixa_ipsec_ah_sa
= NULL
;
11958 if (ixa
->ixa_ipsec_esp_sa
!= NULL
) {
11959 IPSA_REFRELE(ixa
->ixa_ipsec_esp_sa
);
11960 ixa
->ixa_ipsec_esp_sa
= NULL
;
11963 sadb_acquire(mp
, ixa
, need_ah_acquire
, need_esp_acquire
);
11971 * Handle IPsec output processing.
11972 * This function is only entered once for a given packet.
11973 * We try to do things synchronously, but if we need to have user-level
11974 * set up SAs, or ESP or AH uses asynchronous kEF, then the operation
11975 * will be completed
11976 * - when the SAs are added in esp_add_sa_finish/ah_add_sa_finish
11977 * - when asynchronous ESP is done it will do AH
11979 * In all cases we come back in ip_output_post_ipsec() to fragment and
11980 * send out the packet.
11983 ipsec_out_process(mblk_t
*mp
, ip_xmit_attr_t
*ixa
)
11985 ill_t
*ill
= ixa
->ixa_nce
->nce_ill
;
11986 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
11987 ipsec_stack_t
*ipss
;
11988 ipsec_policy_t
*pp
;
11989 ipsec_action_t
*ap
;
11991 ASSERT(ixa
->ixa_flags
& IXAF_IPSEC_SECURE
);
11993 ASSERT((ixa
->ixa_ipsec_policy
!= NULL
) ||
11994 (ixa
->ixa_ipsec_action
!= NULL
));
11996 ipss
= ipst
->ips_netstack
->netstack_ipsec
;
11997 if (!ipsec_loaded(ipss
)) {
11998 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
11999 ip_drop_packet(mp
, B_TRUE
, ill
,
12000 DROPPER(ipss
, ipds_ip_ipsec_not_loaded
),
12001 &ipss
->ipsec_dropper
);
12005 ap
= ixa
->ixa_ipsec_action
;
12007 pp
= ixa
->ixa_ipsec_policy
;
12008 ASSERT(pp
!= NULL
);
12010 ASSERT(ap
!= NULL
);
12013 /* Handle explicit drop action and bypass. */
12014 switch (ap
->ipa_act
.ipa_type
) {
12015 case IPSEC_ACT_DISCARD
:
12016 case IPSEC_ACT_REJECT
:
12017 ip_drop_packet(mp
, B_FALSE
, ill
,
12018 DROPPER(ipss
, ipds_spd_explicit
), &ipss
->ipsec_spd_dropper
);
12019 return (EHOSTUNREACH
); /* IPsec policy failure */
12020 case IPSEC_ACT_BYPASS
:
12021 return (ip_output_post_ipsec(mp
, ixa
));
12025 * The order of processing is first insert a IP header if needed.
12026 * Then insert the ESP header and then the AH header.
12028 if ((ixa
->ixa_flags
& IXAF_IS_IPV4
) && ap
->ipa_want_se
) {
12030 * First get the outer IP header before sending
12033 ipha_t
*oipha
, *iipha
;
12034 mblk_t
*outer_mp
, *inner_mp
;
12036 if ((outer_mp
= allocb(sizeof (ipha_t
), BPRI_HI
)) == NULL
) {
12037 (void) mi_strlog(ill
->ill_rq
, 0,
12038 SL_ERROR
|SL_TRACE
|SL_CONSOLE
,
12039 "ipsec_out_process: "
12040 "Self-Encapsulation failed: Out of memory\n");
12041 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
12042 ip_drop_output("ipIfStatsOutDiscards", mp
, ill
);
12047 ASSERT(inner_mp
->b_datap
->db_type
== M_DATA
);
12048 oipha
= (ipha_t
*)outer_mp
->b_rptr
;
12049 iipha
= (ipha_t
*)inner_mp
->b_rptr
;
12051 outer_mp
->b_wptr
+= sizeof (ipha_t
);
12052 oipha
->ipha_length
= htons(ntohs(iipha
->ipha_length
) +
12054 oipha
->ipha_protocol
= IPPROTO_ENCAP
;
12055 oipha
->ipha_version_and_hdr_length
=
12056 IP_SIMPLE_HDR_VERSION
;
12057 oipha
->ipha_hdr_checksum
= 0;
12058 oipha
->ipha_hdr_checksum
= ip_csum_hdr(oipha
);
12059 outer_mp
->b_cont
= inner_mp
;
12062 ixa
->ixa_flags
|= IXAF_IPSEC_TUNNEL
;
12065 /* If we need to wait for a SA then we can't return any errno */
12066 if (((ap
->ipa_want_ah
&& (ixa
->ixa_ipsec_ah_sa
== NULL
)) ||
12067 (ap
->ipa_want_esp
&& (ixa
->ixa_ipsec_esp_sa
== NULL
))) &&
12068 !ipsec_out_select_sa(mp
, ixa
))
12072 * By now, we know what SA's to use. Toss over to ESP & AH
12073 * to do the heavy lifting.
12075 if (ap
->ipa_want_esp
) {
12076 ASSERT(ixa
->ixa_ipsec_esp_sa
!= NULL
);
12078 mp
= ixa
->ixa_ipsec_esp_sa
->ipsa_output_func(mp
, ixa
);
12081 * Either it failed or is pending. In the former case
12082 * ipIfStatsInDiscards was increased.
12088 if (ap
->ipa_want_ah
) {
12089 ASSERT(ixa
->ixa_ipsec_ah_sa
!= NULL
);
12091 mp
= ixa
->ixa_ipsec_ah_sa
->ipsa_output_func(mp
, ixa
);
12094 * Either it failed or is pending. In the former case
12095 * ipIfStatsInDiscards was increased.
12101 * We are done with IPsec processing. Send it over
12104 return (ip_output_post_ipsec(mp
, ixa
));
12108 * ioctls that go through a down/up sequence may need to wait for the down
12109 * to complete. This involves waiting for the ire and ipif refcnts to go down
12110 * to zero. Subsequently the ioctl is restarted from ipif_ill_refrele_tail.
12114 ip_reprocess_ioctl(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
12116 struct iocblk
*iocp
;
12118 ip_ioctl_cmd_t
*ipip
;
12121 struct lifreq
*lifr
;
12124 iocp
= (struct iocblk
*)mp
->b_rptr
;
12125 ASSERT(ipsq
!= NULL
);
12126 /* Existence of mp1 verified in ip_wput_nondata */
12127 mp1
= mp
->b_cont
->b_cont
;
12128 ipip
= ip_sioctl_lookup(iocp
->ioc_cmd
);
12129 if (ipip
->ipi_cmd
== SIOCSLIFNAME
|| ipip
->ipi_cmd
== IF_UNITSEL
) {
12131 * Special case where ipx_current_ipif is not set:
12132 * ill_phyint_reinit merged the v4 and v6 into a single ipsq.
12133 * We are here as were not able to complete the operation in
12134 * ipif_set_values because we could not become exclusive on
12137 ill_t
*ill
= q
->q_ptr
;
12138 ipsq_current_start(ipsq
, ill
->ill_ipif
, ipip
->ipi_cmd
);
12140 ASSERT(ipsq
->ipsq_xop
->ipx_current_ipif
!= NULL
);
12142 if (ipip
->ipi_cmd_type
== IF_CMD
) {
12143 /* This a old style SIOC[GS]IF* command */
12144 ifr
= (struct ifreq
*)mp1
->b_rptr
;
12145 sin
= (sin_t
*)&ifr
->ifr_addr
;
12146 } else if (ipip
->ipi_cmd_type
== LIF_CMD
) {
12147 /* This a new style SIOC[GS]LIF* command */
12148 lifr
= (struct lifreq
*)mp1
->b_rptr
;
12149 sin
= (sin_t
*)&lifr
->lifr_addr
;
12154 err
= (*ipip
->ipi_func_restart
)(ipsq
->ipsq_xop
->ipx_current_ipif
, sin
,
12155 q
, mp
, ipip
, mp1
->b_rptr
);
12157 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_reprocess_ioctl finish",
12158 int, ipip
->ipi_cmd
,
12159 ill_t
*, ipsq
->ipsq_xop
->ipx_current_ipif
->ipif_ill
,
12160 ipif_t
*, ipsq
->ipsq_xop
->ipx_current_ipif
);
12162 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), ipsq
);
12168 * ioctl processing starts with ip_sioctl_copyin_setup(), which looks up
12169 * the ioctl command in the ioctl tables, determines the copyin data size
12170 * from the ipi_copyin_size field, and does an mi_copyin() of that size.
12172 * ioctl processing then continues when the M_IOCDATA makes its way down to
12173 * ip_wput_nondata(). The ioctl is looked up again in the ioctl table, its
12174 * associated 'conn' is refheld till the end of the ioctl and the general
12175 * ioctl processing function ip_process_ioctl() is called to extract the
12176 * arguments and process the ioctl. To simplify extraction, ioctl commands
12177 * are "typed" based on the arguments they take (e.g., LIF_CMD which takes a
12178 * `struct lifreq'), and a common extract function (e.g., ip_extract_lifreq())
12179 * is used to extract the ioctl's arguments.
12181 * ip_process_ioctl determines if the ioctl needs to be serialized, and if
12182 * so goes thru the serialization primitive ipsq_try_enter. Then the
12183 * appropriate function to handle the ioctl is called based on the entry in
12184 * the ioctl table. ioctl completion is encapsulated in ip_ioctl_finish
12185 * which also refreleases the 'conn' that was refheld at the start of the
12186 * ioctl. Finally ipsq_exit is called if needed to exit the ipsq.
12188 * Many exclusive ioctls go thru an internal down up sequence as part of
12189 * the operation. For example an attempt to change the IP address of an
12190 * ipif entails ipif_down, set address, ipif_up. Bringing down the interface
12191 * does all the cleanup such as deleting all ires that use this address.
12192 * Then we need to wait till all references to the interface go away.
12195 ip_process_ioctl(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *arg
)
12197 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
12198 ip_ioctl_cmd_t
*ipip
= arg
;
12199 ip_extract_func_t
*extract_funcp
;
12202 boolean_t entered_ipsq
= B_FALSE
;
12204 ip3dbg(("ip_process_ioctl: ioctl %X\n", iocp
->ioc_cmd
));
12207 ipip
= ip_sioctl_lookup(iocp
->ioc_cmd
);
12210 * SIOCLIFADDIF needs to go thru a special path since the
12211 * ill may not exist yet. This happens in the case of lo0
12212 * which is created using this ioctl.
12214 if (ipip
->ipi_cmd
== SIOCLIFADDIF
) {
12215 err
= ip_sioctl_addif(NULL
, NULL
, q
, mp
, NULL
, NULL
);
12216 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_process_ioctl finish",
12217 int, ipip
->ipi_cmd
, ill_t
*, NULL
, ipif_t
*, NULL
);
12218 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), NULL
);
12223 switch (ipip
->ipi_cmd_type
) {
12227 * All MISC_CMD ioctls come in here -- e.g. SIOCGLIFCONF.
12229 if (ipip
->ipi_cmd
== IF_UNITSEL
) {
12230 /* ioctl comes down the ill */
12231 ci
.ci_ipif
= ((ill_t
*)q
->q_ptr
)->ill_ipif
;
12232 ipif_refhold(ci
.ci_ipif
);
12238 extract_funcp
= NULL
;
12243 extract_funcp
= ip_extract_lifreq
;
12248 extract_funcp
= ip_extract_arpreq
;
12255 if (extract_funcp
!= NULL
) {
12256 err
= (*extract_funcp
)(q
, mp
, ipip
, &ci
);
12258 DTRACE_PROBE4(ipif__ioctl
,
12259 char *, "ip_process_ioctl finish err",
12260 int, ipip
->ipi_cmd
, ill_t
*, NULL
, ipif_t
*, NULL
);
12261 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), NULL
);
12266 * All of the extraction functions return a refheld ipif.
12268 ASSERT(ci
.ci_ipif
!= NULL
);
12271 if (!(ipip
->ipi_flags
& IPI_WR
)) {
12273 * A return value of EINPROGRESS means the ioctl is
12274 * either queued and waiting for some reason or has
12275 * already completed.
12277 err
= (*ipip
->ipi_func
)(ci
.ci_ipif
, ci
.ci_sin
, q
, mp
, ipip
,
12279 if (ci
.ci_ipif
!= NULL
) {
12280 DTRACE_PROBE4(ipif__ioctl
,
12281 char *, "ip_process_ioctl finish RD",
12282 int, ipip
->ipi_cmd
, ill_t
*, ci
.ci_ipif
->ipif_ill
,
12283 ipif_t
*, ci
.ci_ipif
);
12284 ipif_refrele(ci
.ci_ipif
);
12286 DTRACE_PROBE4(ipif__ioctl
,
12287 char *, "ip_process_ioctl finish RD",
12288 int, ipip
->ipi_cmd
, ill_t
*, NULL
, ipif_t
*, NULL
);
12290 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), NULL
);
12294 ASSERT(ci
.ci_ipif
!= NULL
);
12297 * If ipsq is non-NULL, we are already being called exclusively
12299 ASSERT(ipsq
== NULL
|| IAM_WRITER_IPSQ(ipsq
));
12300 if (ipsq
== NULL
) {
12301 ipsq
= ipsq_try_enter(ci
.ci_ipif
, NULL
, q
, mp
, ip_process_ioctl
,
12303 if (ipsq
== NULL
) {
12304 ipif_refrele(ci
.ci_ipif
);
12307 entered_ipsq
= B_TRUE
;
12310 * Release the ipif so that ipif_down and friends that wait for
12311 * references to go away are not misled about the current ipif_refcnt
12312 * values. We are writer so we can access the ipif even after releasing
12315 ipif_refrele(ci
.ci_ipif
);
12317 ipsq_current_start(ipsq
, ci
.ci_ipif
, ipip
->ipi_cmd
);
12320 * A return value of EINPROGRESS means the ioctl is
12321 * either queued and waiting for some reason or has
12322 * already completed.
12324 err
= (*ipip
->ipi_func
)(ci
.ci_ipif
, ci
.ci_sin
, q
, mp
, ipip
, ci
.ci_lifr
);
12326 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_process_ioctl finish WR",
12327 int, ipip
->ipi_cmd
,
12328 ill_t
*, ci
.ci_ipif
== NULL
? NULL
: ci
.ci_ipif
->ipif_ill
,
12329 ipif_t
*, ci
.ci_ipif
);
12330 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), ipsq
);
12337 * Complete the ioctl. Typically ioctls use the mi package and need to
12338 * do mi_copyout/mi_copy_done.
12341 ip_ioctl_finish(queue_t
*q
, mblk_t
*mp
, int err
, int mode
, ipsq_t
*ipsq
)
12343 conn_t
*connp
= NULL
;
12345 if (err
== EINPROGRESS
)
12349 connp
= Q_TO_CONN(q
);
12350 ASSERT(connp
->conn_ref
>= 2);
12358 mi_copy_done(q
, mp
, err
);
12362 mi_copy_done(q
, mp
, err
);
12366 ASSERT(mode
== CONN_CLOSE
); /* aborted through CONN_CLOSE */
12371 * The conn refhold and ioctlref placed on the conn at the start of the
12372 * ioctl are released here.
12374 if (connp
!= NULL
) {
12375 CONN_DEC_IOCTLREF(connp
);
12376 CONN_OPER_PENDING_DONE(connp
);
12380 ipsq_current_finish(ipsq
);
12383 /* Handles all non data messages */
12385 ip_wput_nondata(queue_t
*q
, mblk_t
*mp
)
12388 struct iocblk
*iocp
;
12389 ip_ioctl_cmd_t
*ipip
;
12395 connp
= Q_TO_CONN(q
);
12399 switch (DB_TYPE(mp
)) {
12402 * IOCTL processing begins in ip_sioctl_copyin_setup which
12403 * will arrange to copy in associated control structures.
12405 ip_sioctl_copyin_setup(q
, mp
);
12409 * Ensure that this is associated with one of our trans-
12410 * parent ioctls. If it's not ours, discard it if we're
12411 * running as a driver, or pass it on if we're a module.
12413 iocp
= (struct iocblk
*)mp
->b_rptr
;
12414 ipip
= ip_sioctl_lookup(iocp
->ioc_cmd
);
12415 if (ipip
== NULL
) {
12416 if (q
->q_next
== NULL
) {
12423 if ((q
->q_next
!= NULL
) && !(ipip
->ipi_flags
& IPI_MODOK
)) {
12425 * The ioctl is one we recognise, but is not consumed
12426 * by IP as a module and we are a module, so we drop
12431 /* IOCTL continuation following copyin or copyout. */
12432 if (mi_copy_state(q
, mp
, NULL
) == -1) {
12434 * The copy operation failed. mi_copy_state already
12435 * cleaned up, so we're out of here.
12440 * If we just completed a copy in, we become writer and
12441 * continue processing in ip_sioctl_copyin_done. If it
12442 * was a copy out, we call mi_copyout again. If there is
12443 * nothing more to copy out, it will complete the IOCTL.
12445 if (MI_COPY_DIRECTION(mp
) == MI_COPY_IN
) {
12446 if (!(mp1
= mp
->b_cont
) || !(mp1
= mp1
->b_cont
)) {
12447 mi_copy_done(q
, mp
, EPROTO
);
12451 * Check for cases that need more copying. A return
12452 * value of 0 means a second copyin has been started,
12453 * so we return; a return value of 1 means no more
12454 * copying is needed, so we continue.
12456 if (ipip
->ipi_cmd_type
== MSFILT_CMD
&&
12457 MI_COPY_COUNT(mp
) == 1) {
12458 if (ip_copyin_msfilter(q
, mp
) == 0)
12462 * Refhold the conn, till the ioctl completes. This is
12463 * needed in case the ioctl ends up in the pending mp
12464 * list. Every mp in the ipx_pending_mp list must have
12465 * a refhold on the conn to resume processing. The
12466 * refhold is released when the ioctl completes
12467 * (whether normally or abnormally). An ioctlref is also
12468 * placed on the conn to prevent TCP from removing the
12469 * queue needed to send the ioctl reply back.
12470 * In all cases ip_ioctl_finish is called to finish
12471 * the ioctl and release the refholds.
12473 if (connp
!= NULL
) {
12474 /* This is not a reentry */
12475 CONN_INC_REF(connp
);
12476 CONN_INC_IOCTLREF(connp
);
12478 if (!(ipip
->ipi_flags
& IPI_MODOK
)) {
12479 mi_copy_done(q
, mp
, EINVAL
);
12484 ip_process_ioctl(NULL
, q
, mp
, ipip
);
12493 * The only way we could get here is if a resolver didn't like
12494 * an IOCTL we sent it. This shouldn't happen.
12496 (void) mi_strlog(q
, 1, SL_ERROR
|SL_TRACE
,
12497 "ip_wput_nondata: unexpected M_IOCNAK, ioc_cmd 0x%x",
12498 ((struct iocblk
*)mp
->b_rptr
)->ioc_cmd
);
12502 /* /dev/ip shouldn't see this */
12505 if (*mp
->b_rptr
& FLUSHW
)
12506 flushq(q
, FLUSHALL
);
12511 if (*mp
->b_rptr
& FLUSHR
) {
12512 *mp
->b_rptr
&= ~FLUSHW
;
12523 * The only PROTO messages we expect are SNMP-related.
12525 switch (((union T_primitives
*)mp
->b_rptr
)->type
) {
12526 case T_SVR4_OPTMGMT_REQ
:
12527 ip2dbg(("ip_wput_nondata: T_SVR4_OPTMGMT_REQ "
12529 ((struct T_optmgmt_req
*)mp
->b_rptr
)->MGMT_flags
));
12531 if (connp
== NULL
) {
12532 proto_str
= "T_SVR4_OPTMGMT_REQ";
12537 * All Solaris components should pass a db_credp
12538 * for this TPI message, hence we ASSERT.
12539 * But in case there is some other M_PROTO that looks
12540 * like a TPI message sent by some other kernel
12541 * component, we check and return an error.
12543 cr
= msg_getcred(mp
, NULL
);
12544 ASSERT(cr
!= NULL
);
12546 mp
= mi_tpi_err_ack_alloc(mp
, TSYSERR
, EINVAL
);
12552 if (!snmpcom_req(q
, mp
, ip_snmp_set
, ip_snmp_get
, cr
)) {
12553 proto_str
= "Bad SNMPCOM request?";
12558 ip1dbg(("ip_wput_nondata: dropping M_PROTO prim %u\n",
12559 (int)*(uint_t
*)mp
->b_rptr
));
12573 iocp
->ioc_error
= EINVAL
;
12574 mp
->b_datap
->db_type
= M_IOCNAK
;
12575 iocp
->ioc_count
= 0;
12580 cmn_err(CE_NOTE
, "IP doesn't process %s as a module", proto_str
);
12581 if ((mp
= mi_tpi_err_ack_alloc(mp
, TPROTO
, EINVAL
)) != NULL
)
12587 * Process IP options in an outbound packet. Verify that the nexthop in a
12588 * strict source route is onlink.
12589 * Returns non-zero if something fails in which case an ICMP error has been
12590 * sent and mp freed.
12592 * Assumes the ULP has called ip_massage_options to move nexthop into ipha_dst.
12595 ip_output_options(mblk_t
*mp
, ipha_t
*ipha
, ip_xmit_attr_t
*ixa
, ill_t
*ill
)
12604 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
12605 ip_recv_attr_t iras
;
12607 ip2dbg(("ip_output_options\n"));
12609 dst
= ipha
->ipha_dst
;
12610 for (optval
= ipoptp_first(&opts
, ipha
);
12611 optval
!= IPOPT_EOL
;
12612 optval
= ipoptp_next(&opts
)) {
12613 opt
= opts
.ipoptp_cur
;
12614 optlen
= opts
.ipoptp_len
;
12615 ip2dbg(("ip_output_options: opt %d, len %d\n",
12621 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
12623 "ip_output_options: bad option offset\n"));
12624 code
= (char *)&opt
[IPOPT_OLEN
] -
12628 off
= opt
[IPOPT_OFFSET
];
12629 ip1dbg(("ip_output_options: next hop 0x%x\n",
12632 * For strict: verify that dst is directly
12635 if (optval
== IPOPT_SSRR
) {
12636 ire
= ire_ftable_lookup_v4(dst
, 0, 0,
12637 IRE_INTERFACE
, NULL
, ALL_ZONES
,
12638 MATCH_IRE_TYPE
, 0, ipst
, NULL
);
12640 ip1dbg(("ip_output_options: SSRR not"
12641 " directly reachable: 0x%x\n",
12643 goto bad_src_route
;
12649 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
12651 "ip_output_options: bad option offset\n"));
12652 code
= (char *)&opt
[IPOPT_OLEN
] -
12659 * Verify that length >=5 and that there is either
12660 * room for another timestamp or that the overflow
12661 * counter is not maxed out.
12663 code
= (char *)&opt
[IPOPT_OLEN
] - (char *)ipha
;
12664 if (optlen
< IPOPT_MINLEN_IT
) {
12667 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
12669 "ip_output_options: bad option offset\n"));
12670 code
= (char *)&opt
[IPOPT_OFFSET
] -
12674 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
12675 case IPOPT_TS_TSONLY
:
12676 off
= IPOPT_TS_TIMELEN
;
12678 case IPOPT_TS_TSANDADDR
:
12679 case IPOPT_TS_PRESPEC
:
12680 case IPOPT_TS_PRESPEC_RFC791
:
12681 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
12684 code
= (char *)&opt
[IPOPT_POS_OV_FLG
] -
12688 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
&&
12689 (opt
[IPOPT_POS_OV_FLG
] & 0xF0) == 0xF0) {
12691 * No room and the overflow counter is 15
12700 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0)
12703 ip1dbg(("ip_output_options: error processing IP options."));
12704 code
= (char *)&opt
[IPOPT_OFFSET
] - (char *)ipha
;
12707 bzero(&iras
, sizeof (iras
));
12708 iras
.ira_ill
= iras
.ira_rill
= ill
;
12709 iras
.ira_ruifindex
= ill
->ill_phyint
->phyint_ifindex
;
12710 iras
.ira_rifindex
= iras
.ira_ruifindex
;
12711 iras
.ira_flags
= IRAF_IS_IPV4
;
12713 ip_drop_output("ip_output_options", mp
, ill
);
12714 icmp_param_problem(mp
, (uint8_t)code
, &iras
);
12715 ASSERT(!(iras
.ira_flags
& IRAF_IPSEC_SECURE
));
12719 bzero(&iras
, sizeof (iras
));
12720 iras
.ira_ill
= iras
.ira_rill
= ill
;
12721 iras
.ira_ruifindex
= ill
->ill_phyint
->phyint_ifindex
;
12722 iras
.ira_rifindex
= iras
.ira_ruifindex
;
12723 iras
.ira_flags
= IRAF_IS_IPV4
;
12725 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", mp
, ill
);
12726 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
, &iras
);
12727 ASSERT(!(iras
.ira_flags
& IRAF_IPSEC_SECURE
));
12732 * The maximum value of conn_drain_list_cnt is CONN_MAXDRAINCNT.
12733 * conn_drain_list_cnt can be changed by setting conn_drain_nthreads
12734 * thru /etc/system.
12736 #define CONN_MAXDRAINCNT 64
12739 conn_drain_init(ip_stack_t
*ipst
)
12742 idl_tx_list_t
*itl_tx
;
12744 ipst
->ips_conn_drain_list_cnt
= conn_drain_nthreads
;
12746 if ((ipst
->ips_conn_drain_list_cnt
== 0) ||
12747 (ipst
->ips_conn_drain_list_cnt
> CONN_MAXDRAINCNT
)) {
12749 * Default value of the number of drainers is the
12750 * number of cpus, subject to maximum of 8 drainers.
12752 if (boot_max_ncpus
!= -1)
12753 ipst
->ips_conn_drain_list_cnt
= MIN(boot_max_ncpus
, 8);
12755 ipst
->ips_conn_drain_list_cnt
= MIN(max_ncpus
, 8);
12758 ipst
->ips_idl_tx_list
=
12759 kmem_zalloc(TX_FANOUT_SIZE
* sizeof (idl_tx_list_t
), KM_SLEEP
);
12760 for (i
= 0; i
< TX_FANOUT_SIZE
; i
++) {
12761 itl_tx
= &ipst
->ips_idl_tx_list
[i
];
12762 itl_tx
->txl_drain_list
=
12763 kmem_zalloc(ipst
->ips_conn_drain_list_cnt
*
12764 sizeof (idl_t
), KM_SLEEP
);
12765 mutex_init(&itl_tx
->txl_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
12766 for (j
= 0; j
< ipst
->ips_conn_drain_list_cnt
; j
++) {
12767 mutex_init(&itl_tx
->txl_drain_list
[j
].idl_lock
, NULL
,
12768 MUTEX_DEFAULT
, NULL
);
12769 itl_tx
->txl_drain_list
[j
].idl_itl
= itl_tx
;
12775 conn_drain_fini(ip_stack_t
*ipst
)
12778 idl_tx_list_t
*itl_tx
;
12780 for (i
= 0; i
< TX_FANOUT_SIZE
; i
++) {
12781 itl_tx
= &ipst
->ips_idl_tx_list
[i
];
12782 kmem_free(itl_tx
->txl_drain_list
,
12783 ipst
->ips_conn_drain_list_cnt
* sizeof (idl_t
));
12785 kmem_free(ipst
->ips_idl_tx_list
,
12786 TX_FANOUT_SIZE
* sizeof (idl_tx_list_t
));
12787 ipst
->ips_idl_tx_list
= NULL
;
12791 * Flow control has blocked us from proceeding. Insert the given conn in one
12792 * of the conn drain lists. When flow control is unblocked, either ip_wsrv()
12793 * (STREAMS) or ill_flow_enable() (direct) will be called back, which in turn
12794 * will call conn_walk_drain(). See the flow control notes at the top of this
12795 * file for more details.
12798 conn_drain_insert(conn_t
*connp
, idl_tx_list_t
*tx_list
)
12800 idl_t
*idl
= tx_list
->txl_drain_list
;
12802 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
12804 mutex_enter(&connp
->conn_lock
);
12805 if (connp
->conn_state_flags
& CONN_CLOSING
) {
12807 * The conn is closing as a result of which CONN_CLOSING
12810 mutex_exit(&connp
->conn_lock
);
12812 } else if (connp
->conn_idl
== NULL
) {
12814 * Assign the next drain list round robin. We dont' use
12815 * a lock, and thus it may not be strictly round robin.
12816 * Atomicity of load/stores is enough to make sure that
12817 * conn_drain_list_index is always within bounds.
12819 index
= tx_list
->txl_drain_index
;
12820 ASSERT(index
< ipst
->ips_conn_drain_list_cnt
);
12821 connp
->conn_idl
= &tx_list
->txl_drain_list
[index
];
12823 if (index
== ipst
->ips_conn_drain_list_cnt
)
12825 tx_list
->txl_drain_index
= index
;
12827 ASSERT(connp
->conn_idl
->idl_itl
== tx_list
);
12829 mutex_exit(&connp
->conn_lock
);
12831 idl
= connp
->conn_idl
;
12832 mutex_enter(&idl
->idl_lock
);
12833 if ((connp
->conn_drain_prev
!= NULL
) ||
12834 (connp
->conn_state_flags
& CONN_CLOSING
)) {
12836 * The conn is either already in the drain list or closing.
12837 * (We needed to check for CONN_CLOSING again since close can
12838 * sneak in between dropping conn_lock and acquiring idl_lock.)
12840 mutex_exit(&idl
->idl_lock
);
12845 * The conn is not in the drain list. Insert it at the
12846 * tail of the drain list. The drain list is circular
12847 * and doubly linked. idl_conn points to the 1st element
12850 if (idl
->idl_conn
== NULL
) {
12851 idl
->idl_conn
= connp
;
12852 connp
->conn_drain_next
= connp
;
12853 connp
->conn_drain_prev
= connp
;
12855 conn_t
*head
= idl
->idl_conn
;
12857 connp
->conn_drain_next
= head
;
12858 connp
->conn_drain_prev
= head
->conn_drain_prev
;
12859 head
->conn_drain_prev
->conn_drain_next
= connp
;
12860 head
->conn_drain_prev
= connp
;
12863 * For non streams based sockets assert flow control.
12865 conn_setqfull(connp
, NULL
);
12866 mutex_exit(&idl
->idl_lock
);
12870 conn_drain_remove(conn_t
*connp
)
12872 idl_t
*idl
= connp
->conn_idl
;
12876 * Remove ourself from the drain list.
12878 if (connp
->conn_drain_next
== connp
) {
12879 /* Singleton in the list */
12880 ASSERT(connp
->conn_drain_prev
== connp
);
12881 idl
->idl_conn
= NULL
;
12883 connp
->conn_drain_prev
->conn_drain_next
=
12884 connp
->conn_drain_next
;
12885 connp
->conn_drain_next
->conn_drain_prev
=
12886 connp
->conn_drain_prev
;
12887 if (idl
->idl_conn
== connp
)
12888 idl
->idl_conn
= connp
->conn_drain_next
;
12892 * NOTE: because conn_idl is associated with a specific drain
12893 * list which in turn is tied to the index the TX ring
12894 * (txl_cookie) hashes to, and because the TX ring can change
12895 * over the lifetime of the conn_t, we must clear conn_idl so
12896 * a subsequent conn_drain_insert() will set conn_idl again
12897 * based on the latest txl_cookie.
12899 connp
->conn_idl
= NULL
;
12901 connp
->conn_drain_next
= NULL
;
12902 connp
->conn_drain_prev
= NULL
;
12904 conn_clrqfull(connp
, NULL
);
12906 * For streams based sockets open up flow control.
12908 if (!IPCL_IS_NONSTR(connp
))
12909 enableok(connp
->conn_wq
);
12913 * This conn is closing, and we are called from ip_close. OR
12914 * this conn is draining because flow-control on the ill has been relieved.
12916 * We must also need to remove conn's on this idl from the list, and also
12917 * inform the sockfs upcalls about the change in flow-control.
12920 conn_drain(conn_t
*connp
, boolean_t closing
)
12923 conn_t
*next_connp
;
12926 * connp->conn_idl is stable at this point, and no lock is needed
12927 * to check it. If we are called from ip_close, close has already
12928 * set CONN_CLOSING, thus freezing the value of conn_idl, and
12929 * called us only because conn_idl is non-null. If we are called thru
12930 * service, conn_idl could be null, but it cannot change because
12931 * service is single-threaded per queue, and there cannot be another
12932 * instance of service trying to call conn_drain_insert on this conn
12935 ASSERT(!closing
|| connp
== NULL
|| connp
->conn_idl
!= NULL
);
12938 * If the conn doesn't exist or is not on a drain list, bail.
12940 if (connp
== NULL
|| connp
->conn_idl
== NULL
||
12941 connp
->conn_drain_prev
== NULL
) {
12945 idl
= connp
->conn_idl
;
12946 ASSERT(MUTEX_HELD(&idl
->idl_lock
));
12949 next_connp
= connp
->conn_drain_next
;
12950 while (next_connp
!= connp
) {
12951 conn_t
*delconnp
= next_connp
;
12953 next_connp
= next_connp
->conn_drain_next
;
12954 conn_drain_remove(delconnp
);
12956 ASSERT(connp
->conn_drain_next
== idl
->idl_conn
);
12958 conn_drain_remove(connp
);
12962 * Write service routine. Shared perimeter entry point.
12963 * The device queue's messages has fallen below the low water mark and STREAMS
12964 * has backenabled the ill_wq. Send sockfs notification about flow-control on
12965 * each waiting conn.
12968 ip_wsrv(queue_t
*q
)
12972 ill
= (ill_t
*)q
->q_ptr
;
12973 if (ill
->ill_state_flags
== 0) {
12974 ip_stack_t
*ipst
= ill
->ill_ipst
;
12977 * The device flow control has opened up.
12978 * Walk through conn drain lists and qenable the
12979 * first conn in each list. This makes sense only
12980 * if the stream is fully plumbed and setup.
12981 * Hence the ill_state_flags check above.
12983 ip1dbg(("ip_wsrv: walking\n"));
12984 conn_walk_drain(ipst
, &ipst
->ips_idl_tx_list
[0]);
12985 enableok(ill
->ill_wq
);
12991 * Callback to disable flow control in IP.
12993 * This is a mac client callback added when the DLD_CAPAB_DIRECT capability
12996 * When MAC_TX() is not able to send any more packets, dld sets its queue
12997 * to QFULL and enable the STREAMS flow control. Later, when the underlying
12998 * driver is able to continue to send packets, it calls mac_tx_(ring_)update()
12999 * function and wakes up corresponding mac worker threads, which in turn
13000 * calls this callback function, and disables flow control.
13003 ill_flow_enable(void *arg
, ip_mac_tx_cookie_t cookie
)
13005 ill_t
*ill
= (ill_t
*)arg
;
13006 ip_stack_t
*ipst
= ill
->ill_ipst
;
13007 idl_tx_list_t
*idl_txl
;
13009 idl_txl
= &ipst
->ips_idl_tx_list
[IDLHASHINDEX(cookie
)];
13010 mutex_enter(&idl_txl
->txl_lock
);
13011 /* add code to to set a flag to indicate idl_txl is enabled */
13012 conn_walk_drain(ipst
, idl_txl
);
13013 mutex_exit(&idl_txl
->txl_lock
);
13017 * Flow control has been relieved and STREAMS has backenabled us; drain
13018 * all the conn lists on `tx_list'.
13021 conn_walk_drain(ip_stack_t
*ipst
, idl_tx_list_t
*tx_list
)
13026 IP_STAT(ipst
, ip_conn_walk_drain
);
13028 for (i
= 0; i
< ipst
->ips_conn_drain_list_cnt
; i
++) {
13029 idl
= &tx_list
->txl_drain_list
[i
];
13030 mutex_enter(&idl
->idl_lock
);
13031 conn_drain(idl
->idl_conn
, B_FALSE
);
13032 mutex_exit(&idl
->idl_lock
);
13037 * Determine if the ill and multicast aspects of that packets
13038 * "matches" the conn.
13041 conn_wantpacket(conn_t
*connp
, ip_recv_attr_t
*ira
, ipha_t
*ipha
)
13043 ill_t
*ill
= ira
->ira_rill
;
13044 zoneid_t zoneid
= ira
->ira_zoneid
;
13048 dst
= ipha
->ipha_dst
;
13049 src
= ipha
->ipha_src
;
13052 * conn_incoming_ifindex is set by IP_BOUND_IF which limits
13053 * unicast, broadcast and multicast reception to
13054 * conn_incoming_ifindex.
13055 * conn_wantpacket is called for unicast, broadcast and
13056 * multicast packets.
13058 in_ifindex
= connp
->conn_incoming_ifindex
;
13060 /* mpathd can bind to the under IPMP interface, which we allow */
13061 if (in_ifindex
!= 0 && in_ifindex
!= ill
->ill_phyint
->phyint_ifindex
) {
13062 if (!IS_UNDER_IPMP(ill
))
13065 if (in_ifindex
!= ipmp_ill_get_ipmp_ifindex(ill
))
13069 if (!IPCL_ZONE_MATCH(connp
, zoneid
))
13072 if (!(ira
->ira_flags
& IRAF_MULTICAST
))
13075 if (connp
->conn_multi_router
) {
13076 /* multicast packet and multicast router socket: send up */
13080 if (ipha
->ipha_protocol
== IPPROTO_PIM
||
13081 ipha
->ipha_protocol
== IPPROTO_RSVP
)
13084 return (conn_hasmembers_ill_withsrc_v4(connp
, dst
, src
, ira
->ira_ill
));
13088 conn_setqfull(conn_t
*connp
, boolean_t
*flow_stopped
)
13090 if (IPCL_IS_NONSTR(connp
)) {
13091 (*connp
->conn_upcalls
->su_txq_full
)
13092 (connp
->conn_upper_handle
, B_TRUE
);
13093 if (flow_stopped
!= NULL
)
13094 *flow_stopped
= B_TRUE
;
13096 queue_t
*q
= connp
->conn_wq
;
13099 if (!(q
->q_flag
& QFULL
)) {
13100 mutex_enter(QLOCK(q
));
13101 if (!(q
->q_flag
& QFULL
)) {
13102 /* still need to set QFULL */
13103 q
->q_flag
|= QFULL
;
13104 /* set flow_stopped to true under QLOCK */
13105 if (flow_stopped
!= NULL
)
13106 *flow_stopped
= B_TRUE
;
13107 mutex_exit(QLOCK(q
));
13109 /* flow_stopped is left unchanged */
13110 mutex_exit(QLOCK(q
));
13117 conn_clrqfull(conn_t
*connp
, boolean_t
*flow_stopped
)
13119 if (IPCL_IS_NONSTR(connp
)) {
13120 (*connp
->conn_upcalls
->su_txq_full
)
13121 (connp
->conn_upper_handle
, B_FALSE
);
13122 if (flow_stopped
!= NULL
)
13123 *flow_stopped
= B_FALSE
;
13125 queue_t
*q
= connp
->conn_wq
;
13128 if (q
->q_flag
& QFULL
) {
13129 mutex_enter(QLOCK(q
));
13130 if (q
->q_flag
& QFULL
) {
13131 q
->q_flag
&= ~QFULL
;
13132 /* set flow_stopped to false under QLOCK */
13133 if (flow_stopped
!= NULL
)
13134 *flow_stopped
= B_FALSE
;
13135 mutex_exit(QLOCK(q
));
13136 if (q
->q_flag
& QWANTW
)
13139 /* flow_stopped is left unchanged */
13140 mutex_exit(QLOCK(q
));
13145 mutex_enter(&connp
->conn_lock
);
13146 connp
->conn_blocked
= B_FALSE
;
13147 mutex_exit(&connp
->conn_lock
);
13151 * Return the length in bytes of the IPv4 headers (base header and IP options)
13152 * that will be needed based on the ip_pkt_t structure passed by the caller.
13154 * The returned length does not include the length of the upper level
13155 * protocol (ULP) header.
13156 * The caller needs to check that the length doesn't exceed the max for IPv4.
13159 ip_total_hdrs_len_v4(const ip_pkt_t
*ipp
)
13163 len
= IP_SIMPLE_HDR_LENGTH
;
13165 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
13166 ASSERT(ipp
->ipp_ipv4_options_len
!= 0);
13167 ASSERT((ipp
->ipp_ipv4_options_len
& 3) == 0);
13168 len
+= ipp
->ipp_ipv4_options_len
;
13174 * All-purpose routine to build an IPv4 header with options based
13175 * on the abstract ip_pkt_t.
13177 * The caller has to set the source and destination address as well as
13178 * ipha_length. The caller has to massage any source route and compensate
13179 * for the ULP pseudo-header checksum due to the source route.
13182 ip_build_hdrs_v4(uchar_t
*buf
, uint_t buf_len
, const ip_pkt_t
*ipp
,
13185 ipha_t
*ipha
= (ipha_t
*)buf
;
13188 /* Initialize IPv4 header */
13189 ipha
->ipha_type_of_service
= ipp
->ipp_type_of_service
;
13190 ipha
->ipha_length
= 0; /* Caller will set later */
13191 ipha
->ipha_ident
= 0;
13192 ipha
->ipha_fragment_offset_and_flags
= 0;
13193 ipha
->ipha_ttl
= ipp
->ipp_unicast_hops
;
13194 ipha
->ipha_protocol
= protocol
;
13195 ipha
->ipha_hdr_checksum
= 0;
13197 if ((ipp
->ipp_fields
& IPPF_ADDR
) &&
13198 IN6_IS_ADDR_V4MAPPED(&ipp
->ipp_addr
))
13199 ipha
->ipha_src
= ipp
->ipp_addr_v4
;
13201 cp
= (uint8_t *)&ipha
[1];
13203 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
13204 ASSERT(ipp
->ipp_ipv4_options_len
!= 0);
13205 ASSERT((ipp
->ipp_ipv4_options_len
& 3) == 0);
13206 bcopy(ipp
->ipp_ipv4_options
, cp
, ipp
->ipp_ipv4_options_len
);
13207 cp
+= ipp
->ipp_ipv4_options_len
;
13209 ipha
->ipha_version_and_hdr_length
=
13210 (uint8_t)((IP_VERSION
<< 4) + buf_len
/ 4);
13212 ASSERT((int)(cp
- buf
) == buf_len
);
13215 /* Allocate the private structure */
13217 ip_priv_alloc(void **bufp
)
13221 if ((buf
= kmem_alloc(sizeof (ip_priv_t
), KM_NOSLEEP
)) == NULL
)
13228 /* Function to delete the private structure */
13230 ip_priv_free(void *buf
)
13232 ASSERT(buf
!= NULL
);
13233 kmem_free(buf
, sizeof (ip_priv_t
));
13237 * The entry point for IPPF processing.
13238 * If the classifier (IPGPC_CLASSIFY) is not loaded and configured, the
13239 * routine just returns.
13241 * When called, ip_process generates an ipp_packet_t structure
13242 * which holds the state information for this packet and invokes the
13243 * the classifier (via ipp_packet_process). The classification, depending on
13244 * configured filters, results in a list of actions for this packet. Invoking
13245 * an action may cause the packet to be dropped, in which case we return NULL.
13246 * proc indicates the callout position for
13247 * this packet and ill is the interface this packet arrived on or will leave
13248 * on (inbound and outbound resp.).
13250 * We do the processing on the rill (mapped to the upper if ipmp), but MIB
13251 * on the ill corrsponding to the destination IP address.
13254 ip_process(ip_proc_t proc
, mblk_t
*mp
, ill_t
*rill
, ill_t
*ill
)
13257 ipp_action_id_t aid
;
13261 /* If the classifier is not loaded, return */
13262 if ((aid
= ipp_action_lookup(IPGPC_CLASSIFY
)) == IPP_ACTION_INVAL
) {
13266 ASSERT(mp
!= NULL
);
13268 /* Allocate the packet structure */
13269 rc
= ipp_packet_alloc(&pp
, "ip", aid
);
13273 /* Allocate the private structure */
13274 rc
= ip_priv_alloc((void **)&priv
);
13276 ipp_packet_free(pp
);
13280 priv
->ill_index
= ill_get_upper_ifindex(rill
);
13282 ipp_packet_set_private(pp
, priv
, ip_priv_free
);
13283 ipp_packet_set_data(pp
, mp
);
13285 /* Invoke the classifier */
13286 rc
= ipp_packet_process(&pp
);
13288 mp
= ipp_packet_get_data(pp
);
13289 ipp_packet_free(pp
);
13294 /* No mp to trace in ip_drop_input/ip_drop_output */
13298 if (proc
== IPP_LOCAL_IN
|| proc
== IPP_FWD_IN
) {
13299 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
13300 ip_drop_input("ip_process", mp
, ill
);
13302 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
13303 ip_drop_output("ip_process", mp
, ill
);
13310 ip_squeue_switch(int val
)
13315 case IP_SQUEUE_ENTER_NODRAIN
:
13318 case IP_SQUEUE_ENTER
:
13321 case IP_SQUEUE_FILL
:
13330 ip_kstat2_init(netstackid_t stackid
, ip_stat_t
*ip_statisticsp
)
13334 ip_stat_t
template = {
13335 { "ip_udp_fannorm", KSTAT_DATA_UINT64
},
13336 { "ip_udp_fanmb", KSTAT_DATA_UINT64
},
13337 { "ip_recv_pullup", KSTAT_DATA_UINT64
},
13338 { "ip_db_ref", KSTAT_DATA_UINT64
},
13339 { "ip_notaligned", KSTAT_DATA_UINT64
},
13340 { "ip_multimblk", KSTAT_DATA_UINT64
},
13341 { "ip_opt", KSTAT_DATA_UINT64
},
13342 { "ipsec_proto_ahesp", KSTAT_DATA_UINT64
},
13343 { "ip_conn_flputbq", KSTAT_DATA_UINT64
},
13344 { "ip_conn_walk_drain", KSTAT_DATA_UINT64
},
13345 { "ip_out_sw_cksum", KSTAT_DATA_UINT64
},
13346 { "ip_out_sw_cksum_bytes", KSTAT_DATA_UINT64
},
13347 { "ip_in_sw_cksum", KSTAT_DATA_UINT64
},
13348 { "ip_ire_reclaim_calls", KSTAT_DATA_UINT64
},
13349 { "ip_ire_reclaim_deleted", KSTAT_DATA_UINT64
},
13350 { "ip_nce_reclaim_calls", KSTAT_DATA_UINT64
},
13351 { "ip_nce_reclaim_deleted", KSTAT_DATA_UINT64
},
13352 { "ip_dce_reclaim_calls", KSTAT_DATA_UINT64
},
13353 { "ip_dce_reclaim_deleted", KSTAT_DATA_UINT64
},
13354 { "ip_tcp_in_full_hw_cksum_err", KSTAT_DATA_UINT64
},
13355 { "ip_tcp_in_part_hw_cksum_err", KSTAT_DATA_UINT64
},
13356 { "ip_tcp_in_sw_cksum_err", KSTAT_DATA_UINT64
},
13357 { "ip_udp_in_full_hw_cksum_err", KSTAT_DATA_UINT64
},
13358 { "ip_udp_in_part_hw_cksum_err", KSTAT_DATA_UINT64
},
13359 { "ip_udp_in_sw_cksum_err", KSTAT_DATA_UINT64
},
13360 { "conn_in_recvdstaddr", KSTAT_DATA_UINT64
},
13361 { "conn_in_recvopts", KSTAT_DATA_UINT64
},
13362 { "conn_in_recvif", KSTAT_DATA_UINT64
},
13363 { "conn_in_recvslla", KSTAT_DATA_UINT64
},
13364 { "conn_in_recvucred", KSTAT_DATA_UINT64
},
13365 { "conn_in_recvttl", KSTAT_DATA_UINT64
},
13366 { "conn_in_recvhopopts", KSTAT_DATA_UINT64
},
13367 { "conn_in_recvhoplimit", KSTAT_DATA_UINT64
},
13368 { "conn_in_recvdstopts", KSTAT_DATA_UINT64
},
13369 { "conn_in_recvrthdrdstopts", KSTAT_DATA_UINT64
},
13370 { "conn_in_recvrthdr", KSTAT_DATA_UINT64
},
13371 { "conn_in_recvpktinfo", KSTAT_DATA_UINT64
},
13372 { "conn_in_recvtclass", KSTAT_DATA_UINT64
},
13373 { "conn_in_timestamp", KSTAT_DATA_UINT64
},
13376 ksp
= kstat_create_netstack("ip", 0, "ipstat", "net",
13377 KSTAT_TYPE_NAMED
, sizeof (template) / sizeof (kstat_named_t
),
13378 KSTAT_FLAG_VIRTUAL
, stackid
);
13383 bcopy(&template, ip_statisticsp
, sizeof (template));
13384 ksp
->ks_data
= (void *)ip_statisticsp
;
13385 ksp
->ks_private
= (void *)(uintptr_t)stackid
;
13387 kstat_install(ksp
);
13392 ip_kstat2_fini(netstackid_t stackid
, kstat_t
*ksp
)
13395 ASSERT(stackid
== (netstackid_t
)(uintptr_t)ksp
->ks_private
);
13396 kstat_delete_netstack(ksp
, stackid
);
13401 ip_kstat_init(netstackid_t stackid
, ip_stack_t
*ipst
)
13405 ip_named_kstat_t
template = {
13406 { "forwarding", KSTAT_DATA_UINT32
, 0 },
13407 { "defaultTTL", KSTAT_DATA_UINT32
, 0 },
13408 { "inReceives", KSTAT_DATA_UINT64
, 0 },
13409 { "inHdrErrors", KSTAT_DATA_UINT32
, 0 },
13410 { "inAddrErrors", KSTAT_DATA_UINT32
, 0 },
13411 { "forwDatagrams", KSTAT_DATA_UINT64
, 0 },
13412 { "inUnknownProtos", KSTAT_DATA_UINT32
, 0 },
13413 { "inDiscards", KSTAT_DATA_UINT32
, 0 },
13414 { "inDelivers", KSTAT_DATA_UINT64
, 0 },
13415 { "outRequests", KSTAT_DATA_UINT64
, 0 },
13416 { "outDiscards", KSTAT_DATA_UINT32
, 0 },
13417 { "outNoRoutes", KSTAT_DATA_UINT32
, 0 },
13418 { "reasmTimeout", KSTAT_DATA_UINT32
, 0 },
13419 { "reasmReqds", KSTAT_DATA_UINT32
, 0 },
13420 { "reasmOKs", KSTAT_DATA_UINT32
, 0 },
13421 { "reasmFails", KSTAT_DATA_UINT32
, 0 },
13422 { "fragOKs", KSTAT_DATA_UINT32
, 0 },
13423 { "fragFails", KSTAT_DATA_UINT32
, 0 },
13424 { "fragCreates", KSTAT_DATA_UINT32
, 0 },
13425 { "addrEntrySize", KSTAT_DATA_INT32
, 0 },
13426 { "routeEntrySize", KSTAT_DATA_INT32
, 0 },
13427 { "netToMediaEntrySize", KSTAT_DATA_INT32
, 0 },
13428 { "routingDiscards", KSTAT_DATA_UINT32
, 0 },
13429 { "inErrs", KSTAT_DATA_UINT32
, 0 },
13430 { "noPorts", KSTAT_DATA_UINT32
, 0 },
13431 { "inCksumErrs", KSTAT_DATA_UINT32
, 0 },
13432 { "reasmDuplicates", KSTAT_DATA_UINT32
, 0 },
13433 { "reasmPartDups", KSTAT_DATA_UINT32
, 0 },
13434 { "forwProhibits", KSTAT_DATA_UINT32
, 0 },
13435 { "udpInCksumErrs", KSTAT_DATA_UINT32
, 0 },
13436 { "udpInOverflows", KSTAT_DATA_UINT32
, 0 },
13437 { "rawipInOverflows", KSTAT_DATA_UINT32
, 0 },
13438 { "ipsecInSucceeded", KSTAT_DATA_UINT32
, 0 },
13439 { "ipsecInFailed", KSTAT_DATA_INT32
, 0 },
13440 { "memberEntrySize", KSTAT_DATA_INT32
, 0 },
13441 { "inIPv6", KSTAT_DATA_UINT32
, 0 },
13442 { "outIPv6", KSTAT_DATA_UINT32
, 0 },
13443 { "outSwitchIPv6", KSTAT_DATA_UINT32
, 0 },
13446 ksp
= kstat_create_netstack("ip", 0, "ip", "mib2", KSTAT_TYPE_NAMED
,
13447 NUM_OF_FIELDS(ip_named_kstat_t
), 0, stackid
);
13448 if (ksp
== NULL
|| ksp
->ks_data
== NULL
)
13451 template.forwarding
.value
.ui32
= WE_ARE_FORWARDING(ipst
) ? 1:2;
13452 template.defaultTTL
.value
.ui32
= (uint32_t)ipst
->ips_ip_def_ttl
;
13453 template.reasmTimeout
.value
.ui32
= ipst
->ips_ip_reassembly_timeout
;
13454 template.addrEntrySize
.value
.i32
= sizeof (mib2_ipAddrEntry_t
);
13455 template.routeEntrySize
.value
.i32
= sizeof (mib2_ipRouteEntry_t
);
13457 template.netToMediaEntrySize
.value
.i32
=
13458 sizeof (mib2_ipNetToMediaEntry_t
);
13460 template.memberEntrySize
.value
.i32
= sizeof (ipv6_member_t
);
13462 bcopy(&template, ksp
->ks_data
, sizeof (template));
13463 ksp
->ks_update
= ip_kstat_update
;
13464 ksp
->ks_private
= (void *)(uintptr_t)stackid
;
13466 kstat_install(ksp
);
13471 ip_kstat_fini(netstackid_t stackid
, kstat_t
*ksp
)
13474 ASSERT(stackid
== (netstackid_t
)(uintptr_t)ksp
->ks_private
);
13475 kstat_delete_netstack(ksp
, stackid
);
13480 ip_kstat_update(kstat_t
*kp
, int rw
)
13482 ip_named_kstat_t
*ipkp
;
13483 mib2_ipIfStatsEntry_t ipmib
;
13484 ill_walk_context_t ctx
;
13486 netstackid_t stackid
= (zoneid_t
)(uintptr_t)kp
->ks_private
;
13490 if (kp
== NULL
|| kp
->ks_data
== NULL
)
13493 if (rw
== KSTAT_WRITE
)
13496 ns
= netstack_find_by_stackid(stackid
);
13499 ipst
= ns
->netstack_ip
;
13500 if (ipst
== NULL
) {
13504 ipkp
= (ip_named_kstat_t
*)kp
->ks_data
;
13506 bcopy(&ipst
->ips_ip_mib
, &ipmib
, sizeof (ipmib
));
13507 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
13508 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
13509 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
))
13510 ip_mib2_add_ip_stats(&ipmib
, ill
->ill_ip_mib
);
13511 rw_exit(&ipst
->ips_ill_g_lock
);
13513 ipkp
->forwarding
.value
.ui32
= ipmib
.ipIfStatsForwarding
;
13514 ipkp
->defaultTTL
.value
.ui32
= ipmib
.ipIfStatsDefaultTTL
;
13515 ipkp
->inReceives
.value
.ui64
= ipmib
.ipIfStatsHCInReceives
;
13516 ipkp
->inHdrErrors
.value
.ui32
= ipmib
.ipIfStatsInHdrErrors
;
13517 ipkp
->inAddrErrors
.value
.ui32
= ipmib
.ipIfStatsInAddrErrors
;
13518 ipkp
->forwDatagrams
.value
.ui64
= ipmib
.ipIfStatsHCOutForwDatagrams
;
13519 ipkp
->inUnknownProtos
.value
.ui32
= ipmib
.ipIfStatsInUnknownProtos
;
13520 ipkp
->inDiscards
.value
.ui32
= ipmib
.ipIfStatsInDiscards
;
13521 ipkp
->inDelivers
.value
.ui64
= ipmib
.ipIfStatsHCInDelivers
;
13522 ipkp
->outRequests
.value
.ui64
= ipmib
.ipIfStatsHCOutRequests
;
13523 ipkp
->outDiscards
.value
.ui32
= ipmib
.ipIfStatsOutDiscards
;
13524 ipkp
->outNoRoutes
.value
.ui32
= ipmib
.ipIfStatsOutNoRoutes
;
13525 ipkp
->reasmTimeout
.value
.ui32
= ipst
->ips_ip_reassembly_timeout
;
13526 ipkp
->reasmReqds
.value
.ui32
= ipmib
.ipIfStatsReasmReqds
;
13527 ipkp
->reasmOKs
.value
.ui32
= ipmib
.ipIfStatsReasmOKs
;
13528 ipkp
->reasmFails
.value
.ui32
= ipmib
.ipIfStatsReasmFails
;
13529 ipkp
->fragOKs
.value
.ui32
= ipmib
.ipIfStatsOutFragOKs
;
13530 ipkp
->fragFails
.value
.ui32
= ipmib
.ipIfStatsOutFragFails
;
13531 ipkp
->fragCreates
.value
.ui32
= ipmib
.ipIfStatsOutFragCreates
;
13533 ipkp
->routingDiscards
.value
.ui32
= 0;
13534 ipkp
->inErrs
.value
.ui32
= ipmib
.tcpIfStatsInErrs
;
13535 ipkp
->noPorts
.value
.ui32
= ipmib
.udpIfStatsNoPorts
;
13536 ipkp
->inCksumErrs
.value
.ui32
= ipmib
.ipIfStatsInCksumErrs
;
13537 ipkp
->reasmDuplicates
.value
.ui32
= ipmib
.ipIfStatsReasmDuplicates
;
13538 ipkp
->reasmPartDups
.value
.ui32
= ipmib
.ipIfStatsReasmPartDups
;
13539 ipkp
->forwProhibits
.value
.ui32
= ipmib
.ipIfStatsForwProhibits
;
13540 ipkp
->udpInCksumErrs
.value
.ui32
= ipmib
.udpIfStatsInCksumErrs
;
13541 ipkp
->udpInOverflows
.value
.ui32
= ipmib
.udpIfStatsInOverflows
;
13542 ipkp
->rawipInOverflows
.value
.ui32
= ipmib
.rawipIfStatsInOverflows
;
13543 ipkp
->ipsecInSucceeded
.value
.ui32
= ipmib
.ipsecIfStatsInSucceeded
;
13544 ipkp
->ipsecInFailed
.value
.i32
= ipmib
.ipsecIfStatsInFailed
;
13546 ipkp
->inIPv6
.value
.ui32
= ipmib
.ipIfStatsInWrongIPVersion
;
13547 ipkp
->outIPv6
.value
.ui32
= ipmib
.ipIfStatsOutWrongIPVersion
;
13548 ipkp
->outSwitchIPv6
.value
.ui32
= ipmib
.ipIfStatsOutSwitchIPVersion
;
13556 icmp_kstat_init(netstackid_t stackid
)
13560 icmp_named_kstat_t
template = {
13561 { "inMsgs", KSTAT_DATA_UINT32
},
13562 { "inErrors", KSTAT_DATA_UINT32
},
13563 { "inDestUnreachs", KSTAT_DATA_UINT32
},
13564 { "inTimeExcds", KSTAT_DATA_UINT32
},
13565 { "inParmProbs", KSTAT_DATA_UINT32
},
13566 { "inSrcQuenchs", KSTAT_DATA_UINT32
},
13567 { "inRedirects", KSTAT_DATA_UINT32
},
13568 { "inEchos", KSTAT_DATA_UINT32
},
13569 { "inEchoReps", KSTAT_DATA_UINT32
},
13570 { "inTimestamps", KSTAT_DATA_UINT32
},
13571 { "inTimestampReps", KSTAT_DATA_UINT32
},
13572 { "inAddrMasks", KSTAT_DATA_UINT32
},
13573 { "inAddrMaskReps", KSTAT_DATA_UINT32
},
13574 { "outMsgs", KSTAT_DATA_UINT32
},
13575 { "outErrors", KSTAT_DATA_UINT32
},
13576 { "outDestUnreachs", KSTAT_DATA_UINT32
},
13577 { "outTimeExcds", KSTAT_DATA_UINT32
},
13578 { "outParmProbs", KSTAT_DATA_UINT32
},
13579 { "outSrcQuenchs", KSTAT_DATA_UINT32
},
13580 { "outRedirects", KSTAT_DATA_UINT32
},
13581 { "outEchos", KSTAT_DATA_UINT32
},
13582 { "outEchoReps", KSTAT_DATA_UINT32
},
13583 { "outTimestamps", KSTAT_DATA_UINT32
},
13584 { "outTimestampReps", KSTAT_DATA_UINT32
},
13585 { "outAddrMasks", KSTAT_DATA_UINT32
},
13586 { "outAddrMaskReps", KSTAT_DATA_UINT32
},
13587 { "inChksumErrs", KSTAT_DATA_UINT32
},
13588 { "inUnknowns", KSTAT_DATA_UINT32
},
13589 { "inFragNeeded", KSTAT_DATA_UINT32
},
13590 { "outFragNeeded", KSTAT_DATA_UINT32
},
13591 { "outDrops", KSTAT_DATA_UINT32
},
13592 { "inOverFlows", KSTAT_DATA_UINT32
},
13593 { "inBadRedirects", KSTAT_DATA_UINT32
},
13596 ksp
= kstat_create_netstack("ip", 0, "icmp", "mib2", KSTAT_TYPE_NAMED
,
13597 NUM_OF_FIELDS(icmp_named_kstat_t
), 0, stackid
);
13598 if (ksp
== NULL
|| ksp
->ks_data
== NULL
)
13601 bcopy(&template, ksp
->ks_data
, sizeof (template));
13603 ksp
->ks_update
= icmp_kstat_update
;
13604 ksp
->ks_private
= (void *)(uintptr_t)stackid
;
13606 kstat_install(ksp
);
13611 icmp_kstat_fini(netstackid_t stackid
, kstat_t
*ksp
)
13614 ASSERT(stackid
== (netstackid_t
)(uintptr_t)ksp
->ks_private
);
13615 kstat_delete_netstack(ksp
, stackid
);
13620 icmp_kstat_update(kstat_t
*kp
, int rw
)
13622 icmp_named_kstat_t
*icmpkp
;
13623 netstackid_t stackid
= (zoneid_t
)(uintptr_t)kp
->ks_private
;
13627 if ((kp
== NULL
) || (kp
->ks_data
== NULL
))
13630 if (rw
== KSTAT_WRITE
)
13633 ns
= netstack_find_by_stackid(stackid
);
13636 ipst
= ns
->netstack_ip
;
13637 if (ipst
== NULL
) {
13641 icmpkp
= (icmp_named_kstat_t
*)kp
->ks_data
;
13643 icmpkp
->inMsgs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInMsgs
;
13644 icmpkp
->inErrors
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInErrors
;
13645 icmpkp
->inDestUnreachs
.value
.ui32
=
13646 ipst
->ips_icmp_mib
.icmpInDestUnreachs
;
13647 icmpkp
->inTimeExcds
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInTimeExcds
;
13648 icmpkp
->inParmProbs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInParmProbs
;
13649 icmpkp
->inSrcQuenchs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInSrcQuenchs
;
13650 icmpkp
->inRedirects
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInRedirects
;
13651 icmpkp
->inEchos
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInEchos
;
13652 icmpkp
->inEchoReps
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInEchoReps
;
13653 icmpkp
->inTimestamps
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInTimestamps
;
13654 icmpkp
->inTimestampReps
.value
.ui32
=
13655 ipst
->ips_icmp_mib
.icmpInTimestampReps
;
13656 icmpkp
->inAddrMasks
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInAddrMasks
;
13657 icmpkp
->inAddrMaskReps
.value
.ui32
=
13658 ipst
->ips_icmp_mib
.icmpInAddrMaskReps
;
13659 icmpkp
->outMsgs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutMsgs
;
13660 icmpkp
->outErrors
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutErrors
;
13661 icmpkp
->outDestUnreachs
.value
.ui32
=
13662 ipst
->ips_icmp_mib
.icmpOutDestUnreachs
;
13663 icmpkp
->outTimeExcds
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutTimeExcds
;
13664 icmpkp
->outParmProbs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutParmProbs
;
13665 icmpkp
->outSrcQuenchs
.value
.ui32
=
13666 ipst
->ips_icmp_mib
.icmpOutSrcQuenchs
;
13667 icmpkp
->outRedirects
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutRedirects
;
13668 icmpkp
->outEchos
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutEchos
;
13669 icmpkp
->outEchoReps
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutEchoReps
;
13670 icmpkp
->outTimestamps
.value
.ui32
=
13671 ipst
->ips_icmp_mib
.icmpOutTimestamps
;
13672 icmpkp
->outTimestampReps
.value
.ui32
=
13673 ipst
->ips_icmp_mib
.icmpOutTimestampReps
;
13674 icmpkp
->outAddrMasks
.value
.ui32
=
13675 ipst
->ips_icmp_mib
.icmpOutAddrMasks
;
13676 icmpkp
->outAddrMaskReps
.value
.ui32
=
13677 ipst
->ips_icmp_mib
.icmpOutAddrMaskReps
;
13678 icmpkp
->inCksumErrs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInCksumErrs
;
13679 icmpkp
->inUnknowns
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInUnknowns
;
13680 icmpkp
->inFragNeeded
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInFragNeeded
;
13681 icmpkp
->outFragNeeded
.value
.ui32
=
13682 ipst
->ips_icmp_mib
.icmpOutFragNeeded
;
13683 icmpkp
->outDrops
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutDrops
;
13684 icmpkp
->inOverflows
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInOverflows
;
13685 icmpkp
->inBadRedirects
.value
.ui32
=
13686 ipst
->ips_icmp_mib
.icmpInBadRedirects
;
13693 * This is the fanout function for raw socket opened for SCTP. Note
13694 * that it is called after SCTP checks that there is no socket which
13695 * wants a packet. Then before SCTP handles this out of the blue packet,
13696 * this function is called to see if there is any raw socket for SCTP.
13697 * If there is and it is bound to the correct address, the packet will
13698 * be sent to that socket. Note that only one raw socket can be bound to
13699 * a port. This is assured in ipcl_sctp_hash_insert();
13702 ip_fanout_sctp_raw(mblk_t
*mp
, ipha_t
*ipha
, ip6_t
*ip6h
, uint32_t ports
,
13703 ip_recv_attr_t
*ira
)
13708 ill_t
*ill
= ira
->ira_ill
;
13709 ip_stack_t
*ipst
= ill
->ill_ipst
;
13710 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
13711 sctp_stack_t
*sctps
= ipst
->ips_netstack
->netstack_sctp
;
13712 iaflags_t iraflags
= ira
->ira_flags
;
13713 ill_t
*rill
= ira
->ira_rill
;
13715 secure
= iraflags
& IRAF_IPSEC_SECURE
;
13717 connp
= ipcl_classify_raw(mp
, IPPROTO_SCTP
, ports
, ipha
, ip6h
,
13719 if (connp
== NULL
) {
13721 * Although raw sctp is not summed, OOB chunks must be.
13722 * Drop the packet here if the sctp checksum failed.
13724 if (iraflags
& IRAF_SCTP_CSUM_ERR
) {
13725 SCTPS_BUMP_MIB(sctps
, sctpChecksumError
);
13729 ira
->ira_ill
= ira
->ira_rill
= NULL
;
13730 sctp_ootb_input(mp
, ira
, ipst
);
13731 ira
->ira_ill
= ill
;
13732 ira
->ira_rill
= rill
;
13735 rq
= connp
->conn_rq
;
13736 if (IPCL_IS_NONSTR(connp
) ? connp
->conn_flow_cntrld
: !canputnext(rq
)) {
13737 CONN_DEC_REF(connp
);
13738 BUMP_MIB(ill
->ill_ip_mib
, rawipIfStatsInOverflows
);
13742 if (((iraflags
& IRAF_IS_IPV4
) ?
13743 CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) :
13744 CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
)) ||
13746 mp
= ipsec_check_inbound_policy(mp
, connp
, ipha
,
13749 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
13750 /* Note that mp is NULL */
13751 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
13752 CONN_DEC_REF(connp
);
13757 if (iraflags
& IRAF_ICMP_ERROR
) {
13758 (connp
->conn_recvicmp
)(connp
, mp
, NULL
, ira
);
13760 ill_t
*rill
= ira
->ira_rill
;
13762 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
13763 /* This is the SOCK_RAW, IPPROTO_SCTP case. */
13764 ira
->ira_ill
= ira
->ira_rill
= NULL
;
13765 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
13766 ira
->ira_ill
= ill
;
13767 ira
->ira_rill
= rill
;
13769 CONN_DEC_REF(connp
);
13773 * Free a packet that has the link-layer dl_unitdata_req_t or fast-path
13774 * header before the ip payload.
13777 ip_xmit_flowctl_drop(ill_t
*ill
, mblk_t
*mp
, boolean_t is_fp_mp
, int fp_mp_len
)
13779 int len
= (mp
->b_wptr
- mp
->b_rptr
);
13782 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
13783 if (is_fp_mp
|| len
!= fp_mp_len
) {
13784 if (len
> fp_mp_len
) {
13786 * fastpath header and ip header in the first mblk
13788 mp
->b_rptr
+= fp_mp_len
;
13791 * ip_xmit_attach_llhdr had to prepend an mblk to
13792 * attach the fastpath header before ip header.
13794 ip_mp
= mp
->b_cont
;
13797 mp
->b_rptr
+= (fp_mp_len
- len
);
13800 ip_mp
= mp
->b_cont
;
13804 ip_drop_output("ipIfStatsOutDiscards - flow ctl", mp
, ill
);
13809 * Normal post fragmentation function.
13811 * Send a packet using the passed in nce. This handles both IPv4 and IPv6
13812 * using the same state machine.
13814 * We return an error on failure. In particular we return EWOULDBLOCK
13815 * when the driver flow controls. In that case this ensures that ip_wsrv runs
13816 * (currently by canputnext failure resulting in backenabling from GLD.)
13817 * This allows the callers of conn_ip_output() to use EWOULDBLOCK as an
13818 * indication that they can flow control until ip_wsrv() tells then to restart.
13820 * If the nce passed by caller is incomplete, this function
13821 * queues the packet and if necessary, sends ARP request and bails.
13822 * If the Neighbor Cache passed is fully resolved, we simply prepend
13823 * the link-layer header to the packet, do ipsec hw acceleration
13824 * work if necessary, and send the packet out on the wire.
13828 ip_xmit(mblk_t
*mp
, nce_t
*nce
, iaflags_t ixaflags
, uint_t pkt_len
,
13829 uint32_t xmit_hint
, zoneid_t szone
, zoneid_t nolzid
, uintptr_t *ixacookie
)
13832 ill_t
*ill
= nce
->nce_ill
;
13833 ip_stack_t
*ipst
= ill
->ill_ipst
;
13835 boolean_t isv6
= ill
->ill_isv6
;
13837 ncec_t
*ncec
= nce
->nce_common
;
13838 int64_t now
= LBOLT_FASTPATH64
;
13839 boolean_t is_probe
;
13841 DTRACE_PROBE1(ip__xmit
, nce_t
*, nce
);
13843 ASSERT(mp
!= NULL
);
13844 ASSERT(mp
->b_datap
->db_type
== M_DATA
);
13845 ASSERT(pkt_len
== msgdsize(mp
));
13848 * If we have already been here and are coming back after ARP/ND.
13849 * the IXAF_NO_TRACE flag is set. We skip FW_HOOKS, DTRACE and ipobs
13850 * in that case since they have seen the packet when it came here
13853 if (ixaflags
& IXAF_NO_TRACE
)
13856 if (ixaflags
& IXAF_IS_IPV4
) {
13857 ipha_t
*ipha
= (ipha_t
*)mp
->b_rptr
;
13860 ASSERT(pkt_len
== ntohs(((ipha_t
*)mp
->b_rptr
)->ipha_length
));
13861 if (HOOKS4_INTERESTED_PHYSICAL_OUT(ipst
) &&
13862 !(ixaflags
& IXAF_NO_PFHOOK
)) {
13865 FW_HOOKS(ipst
->ips_ip4_physical_out_event
,
13866 ipst
->ips_ipv4firewall_physical_out
,
13867 NULL
, ill
, ipha
, mp
, mp
, 0, ipst
, error
);
13868 DTRACE_PROBE1(ip4__physical__out__end
,
13873 /* The length could have changed */
13874 pkt_len
= msgdsize(mp
);
13876 if (ipst
->ips_ip4_observe
.he_interested
) {
13878 * Note that for TX the zoneid is the sending
13879 * zone, whether or not MLP is in play.
13880 * Since the szone argument is the IP zoneid (i.e.,
13881 * zero for exclusive-IP zones) and ipobs wants
13882 * the system zoneid, we map it here.
13884 szone
= IP_REAL_ZONEID(szone
, ipst
);
13887 * On the outbound path the destination zone will be
13888 * unknown as we're sending this packet out on the
13891 ipobs_hook(mp
, IPOBS_HOOK_OUTBOUND
, szone
, ALL_ZONES
,
13894 DTRACE_IP7(send
, mblk_t
*, mp
, conn_t
*, NULL
,
13895 void_ip_t
*, ipha
, __dtrace_ipsr_ill_t
*, ill
,
13896 ipha_t
*, ipha
, ip6_t
*, NULL
, int, 0);
13898 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
13902 ntohs(((ip6_t
*)mp
->b_rptr
)->ip6_plen
) + IPV6_HDR_LEN
);
13903 if (HOOKS6_INTERESTED_PHYSICAL_OUT(ipst
) &&
13904 !(ixaflags
& IXAF_NO_PFHOOK
)) {
13907 FW_HOOKS6(ipst
->ips_ip6_physical_out_event
,
13908 ipst
->ips_ipv6firewall_physical_out
,
13909 NULL
, ill
, ip6h
, mp
, mp
, 0, ipst
, error
);
13910 DTRACE_PROBE1(ip6__physical__out__end
,
13915 /* The length could have changed */
13916 pkt_len
= msgdsize(mp
);
13918 if (ipst
->ips_ip6_observe
.he_interested
) {
13920 szone
= IP_REAL_ZONEID(szone
, ipst
);
13922 ipobs_hook(mp
, IPOBS_HOOK_OUTBOUND
, szone
, ALL_ZONES
,
13925 DTRACE_IP7(send
, mblk_t
*, mp
, conn_t
*, NULL
,
13926 void_ip_t
*, ip6h
, __dtrace_ipsr_ill_t
*, ill
,
13927 ipha_t
*, NULL
, ip6_t
*, ip6h
, int, 0);
13932 * We check the state without a lock because the state can never
13933 * move "backwards" to initial or incomplete.
13935 switch (ncec
->ncec_state
) {
13940 mp
= ip_xmit_attach_llhdr(mp
, nce
);
13943 * ip_xmit_attach_llhdr has increased
13944 * ipIfStatsOutDiscards and called ip_drop_output()
13949 * check if nce_fastpath completed and we tagged on a
13950 * copy of nce_fp_mp in ip_xmit_attach_llhdr().
13952 fp_mp
= (mp
->b_datap
->db_type
== M_DATA
);
13955 (ill
->ill_capabilities
& ILL_CAPAB_DLD_DIRECT
)) {
13956 ill_dld_direct_t
*idd
;
13958 idd
= &ill
->ill_dld_capab
->idc_direct
;
13960 * Send the packet directly to DLD, where it
13961 * may be queued depending on the availability
13962 * of transmit resources at the media layer.
13963 * Return value should be taken into
13964 * account and flow control the TCP.
13966 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutTransmits
);
13967 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutOctets
,
13970 if (ixaflags
& IXAF_NO_DEV_FLOW_CTL
) {
13971 (void) idd
->idd_tx_df(idd
->idd_tx_dh
, mp
,
13972 (uintptr_t)xmit_hint
, IP_DROP_ON_NO_DESC
);
13976 if ((cookie
= idd
->idd_tx_df(idd
->idd_tx_dh
,
13977 mp
, (uintptr_t)xmit_hint
, 0)) != 0) {
13978 if (ixacookie
!= NULL
)
13979 *ixacookie
= cookie
;
13980 return (EWOULDBLOCK
);
13986 if (!(ixaflags
& IXAF_NO_DEV_FLOW_CTL
) &&
13988 if (ixacookie
!= NULL
)
13990 ip_xmit_flowctl_drop(ill
, mp
, fp_mp
,
13991 nce
->nce_fp_mp
!= NULL
?
13992 MBLKL(nce
->nce_fp_mp
) : 0);
13993 return (EWOULDBLOCK
);
13995 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutTransmits
);
13996 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutOctets
,
14002 * The rest of this function implements Neighbor Unreachability
14003 * detection. Determine if the ncec is eligible for NUD.
14005 if (ncec
->ncec_flags
& NCE_F_NONUD
)
14008 ASSERT(ncec
->ncec_state
!= ND_INCOMPLETE
);
14011 * Check for upper layer advice
14013 if (ixaflags
& IXAF_REACH_CONF
) {
14017 * It should be o.k. to check the state without
14018 * a lock here, at most we lose an advice.
14020 ncec
->ncec_last
= TICK_TO_MSEC(now
);
14021 if (ncec
->ncec_state
!= ND_REACHABLE
) {
14022 mutex_enter(&ncec
->ncec_lock
);
14023 ncec
->ncec_state
= ND_REACHABLE
;
14024 tid
= ncec
->ncec_timeout_id
;
14025 ncec
->ncec_timeout_id
= 0;
14026 mutex_exit(&ncec
->ncec_lock
);
14027 (void) untimeout(tid
);
14028 if (ip_debug
> 2) {
14030 pr_addr_dbg("ip_xmit: state"
14031 " for %s changed to"
14032 " REACHABLE\n", AF_INET6
,
14039 delta
= TICK_TO_MSEC(now
) - ncec
->ncec_last
;
14040 ip1dbg(("ip_xmit: delta = %" PRId64
14041 " ill_reachable_time = %d \n", delta
,
14042 ill
->ill_reachable_time
));
14043 if (delta
> (uint64_t)ill
->ill_reachable_time
) {
14044 mutex_enter(&ncec
->ncec_lock
);
14045 switch (ncec
->ncec_state
) {
14047 ASSERT((ncec
->ncec_flags
& NCE_F_NONUD
) == 0);
14051 * ND_REACHABLE is identical to
14052 * ND_STALE in this specific case. If
14053 * reachable time has expired for this
14054 * neighbor (delta is greater than
14055 * reachable time), conceptually, the
14056 * neighbor cache is no longer in
14057 * REACHABLE state, but already in
14058 * STALE state. So the correct
14059 * transition here is to ND_DELAY.
14061 ncec
->ncec_state
= ND_DELAY
;
14062 mutex_exit(&ncec
->ncec_lock
);
14063 nce_restart_timer(ncec
,
14064 ipst
->ips_delay_first_probe_time
);
14065 if (ip_debug
> 3) {
14067 pr_addr_dbg("ip_xmit: state"
14068 " for %s changed to"
14069 " DELAY\n", AF_INET6
,
14075 mutex_exit(&ncec
->ncec_lock
);
14076 /* Timers have already started */
14078 case ND_UNREACHABLE
:
14080 * nce_timer has detected that this ncec
14081 * is unreachable and initiated deleting
14083 * This is a harmless race where we found the
14084 * ncec before it was deleted and have
14085 * just sent out a packet using this
14086 * unreachable ncec.
14088 mutex_exit(&ncec
->ncec_lock
);
14092 mutex_exit(&ncec
->ncec_lock
);
14097 case ND_INCOMPLETE
:
14099 * the state could have changed since we didn't hold the lock.
14100 * Re-verify state under lock.
14102 is_probe
= ipmp_packet_is_probe(mp
, nce
->nce_ill
);
14103 mutex_enter(&ncec
->ncec_lock
);
14104 if (NCE_ISREACHABLE(ncec
)) {
14105 mutex_exit(&ncec
->ncec_lock
);
14108 /* queue the packet */
14109 nce_queue_mp(ncec
, mp
, is_probe
);
14110 mutex_exit(&ncec
->ncec_lock
);
14111 DTRACE_PROBE2(ip__xmit__incomplete
,
14112 (ncec_t
*), ncec
, (mblk_t
*), mp
);
14117 * State could have changed since we didn't hold the lock, so
14120 is_probe
= ipmp_packet_is_probe(mp
, nce
->nce_ill
);
14121 mutex_enter(&ncec
->ncec_lock
);
14122 if (NCE_ISREACHABLE(ncec
)) {
14123 mutex_exit(&ncec
->ncec_lock
);
14126 nce_queue_mp(ncec
, mp
, is_probe
);
14127 if (ncec
->ncec_state
== ND_INITIAL
) {
14128 ncec
->ncec_state
= ND_INCOMPLETE
;
14129 mutex_exit(&ncec
->ncec_lock
);
14131 * figure out the source we want to use
14134 ip_ndp_resolve(ncec
);
14136 mutex_exit(&ncec
->ncec_lock
);
14140 case ND_UNREACHABLE
:
14141 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
14142 ip_drop_output("ipIfStatsOutDiscards - ND_UNREACHABLE",
14149 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
14150 ip_drop_output("ipIfStatsOutDiscards - ND_other",
14153 return (ENETUNREACH
);
14158 * Return B_TRUE if the buffers differ in length or content.
14159 * This is used for comparing extension header buffers.
14160 * Note that an extension header would be declared different
14161 * even if all that changed was the next header value in that header i.e.
14162 * what really changed is the next extension header.
14165 ip_cmpbuf(const void *abuf
, uint_t alen
, boolean_t b_valid
, const void *bbuf
,
14174 return (B_FALSE
); /* Both zero length */
14175 return (bcmp(abuf
, bbuf
, alen
));
14179 * Preallocate memory for ip_savebuf(). Returns B_TRUE if ok.
14180 * Return B_FALSE if memory allocation fails - don't change any state!
14183 ip_allocbuf(void **dstp
, uint_t
*dstlenp
, boolean_t src_valid
,
14184 const void *src
, uint_t srclen
)
14191 ASSERT(*dstlenp
== 0);
14192 if (src
!= NULL
&& srclen
!= 0) {
14193 dst
= mi_alloc(srclen
, BPRI_MED
);
14202 *dstlenp
= dst
== NULL
? 0 : srclen
;
14207 * Replace what is in *dst, *dstlen with the source.
14208 * Assumes ip_allocbuf has already been called.
14211 ip_savebuf(void **dstp
, uint_t
*dstlenp
, boolean_t src_valid
,
14212 const void *src
, uint_t srclen
)
14217 ASSERT(*dstlenp
== srclen
);
14218 if (src
!= NULL
&& srclen
!= 0)
14219 bcopy(src
, *dstp
, srclen
);
14223 * Free the storage pointed to by the members of an ip_pkt_t.
14226 ip_pkt_free(ip_pkt_t
*ipp
)
14228 uint_t fields
= ipp
->ipp_fields
;
14230 if (fields
& IPPF_HOPOPTS
) {
14231 kmem_free(ipp
->ipp_hopopts
, ipp
->ipp_hopoptslen
);
14232 ipp
->ipp_hopopts
= NULL
;
14233 ipp
->ipp_hopoptslen
= 0;
14235 if (fields
& IPPF_RTHDRDSTOPTS
) {
14236 kmem_free(ipp
->ipp_rthdrdstopts
, ipp
->ipp_rthdrdstoptslen
);
14237 ipp
->ipp_rthdrdstopts
= NULL
;
14238 ipp
->ipp_rthdrdstoptslen
= 0;
14240 if (fields
& IPPF_DSTOPTS
) {
14241 kmem_free(ipp
->ipp_dstopts
, ipp
->ipp_dstoptslen
);
14242 ipp
->ipp_dstopts
= NULL
;
14243 ipp
->ipp_dstoptslen
= 0;
14245 if (fields
& IPPF_RTHDR
) {
14246 kmem_free(ipp
->ipp_rthdr
, ipp
->ipp_rthdrlen
);
14247 ipp
->ipp_rthdr
= NULL
;
14248 ipp
->ipp_rthdrlen
= 0;
14250 if (fields
& IPPF_IPV4_OPTIONS
) {
14251 kmem_free(ipp
->ipp_ipv4_options
, ipp
->ipp_ipv4_options_len
);
14252 ipp
->ipp_ipv4_options
= NULL
;
14253 ipp
->ipp_ipv4_options_len
= 0;
14255 ipp
->ipp_fields
&= ~(IPPF_HOPOPTS
| IPPF_RTHDRDSTOPTS
| IPPF_DSTOPTS
|
14256 IPPF_RTHDR
| IPPF_IPV4_OPTIONS
);
14260 * Copy from src to dst and allocate as needed.
14261 * Returns zero or ENOMEM.
14263 * The caller must initialize dst to zero.
14266 ip_pkt_copy(ip_pkt_t
*src
, ip_pkt_t
*dst
, int kmflag
)
14268 uint_t fields
= src
->ipp_fields
;
14270 /* Start with fields that don't require memory allocation */
14271 dst
->ipp_fields
= fields
&
14272 ~(IPPF_HOPOPTS
| IPPF_RTHDRDSTOPTS
| IPPF_DSTOPTS
|
14273 IPPF_RTHDR
| IPPF_IPV4_OPTIONS
);
14275 dst
->ipp_addr
= src
->ipp_addr
;
14276 dst
->ipp_unicast_hops
= src
->ipp_unicast_hops
;
14277 dst
->ipp_hoplimit
= src
->ipp_hoplimit
;
14278 dst
->ipp_tclass
= src
->ipp_tclass
;
14279 dst
->ipp_type_of_service
= src
->ipp_type_of_service
;
14281 if (!(fields
& (IPPF_HOPOPTS
| IPPF_RTHDRDSTOPTS
| IPPF_DSTOPTS
|
14282 IPPF_RTHDR
| IPPF_IPV4_OPTIONS
)))
14285 if (fields
& IPPF_HOPOPTS
) {
14286 dst
->ipp_hopopts
= kmem_alloc(src
->ipp_hopoptslen
, kmflag
);
14287 if (dst
->ipp_hopopts
== NULL
) {
14291 dst
->ipp_fields
|= IPPF_HOPOPTS
;
14292 bcopy(src
->ipp_hopopts
, dst
->ipp_hopopts
,
14293 src
->ipp_hopoptslen
);
14294 dst
->ipp_hopoptslen
= src
->ipp_hopoptslen
;
14296 if (fields
& IPPF_RTHDRDSTOPTS
) {
14297 dst
->ipp_rthdrdstopts
= kmem_alloc(src
->ipp_rthdrdstoptslen
,
14299 if (dst
->ipp_rthdrdstopts
== NULL
) {
14303 dst
->ipp_fields
|= IPPF_RTHDRDSTOPTS
;
14304 bcopy(src
->ipp_rthdrdstopts
, dst
->ipp_rthdrdstopts
,
14305 src
->ipp_rthdrdstoptslen
);
14306 dst
->ipp_rthdrdstoptslen
= src
->ipp_rthdrdstoptslen
;
14308 if (fields
& IPPF_DSTOPTS
) {
14309 dst
->ipp_dstopts
= kmem_alloc(src
->ipp_dstoptslen
, kmflag
);
14310 if (dst
->ipp_dstopts
== NULL
) {
14314 dst
->ipp_fields
|= IPPF_DSTOPTS
;
14315 bcopy(src
->ipp_dstopts
, dst
->ipp_dstopts
,
14316 src
->ipp_dstoptslen
);
14317 dst
->ipp_dstoptslen
= src
->ipp_dstoptslen
;
14319 if (fields
& IPPF_RTHDR
) {
14320 dst
->ipp_rthdr
= kmem_alloc(src
->ipp_rthdrlen
, kmflag
);
14321 if (dst
->ipp_rthdr
== NULL
) {
14325 dst
->ipp_fields
|= IPPF_RTHDR
;
14326 bcopy(src
->ipp_rthdr
, dst
->ipp_rthdr
,
14327 src
->ipp_rthdrlen
);
14328 dst
->ipp_rthdrlen
= src
->ipp_rthdrlen
;
14330 if (fields
& IPPF_IPV4_OPTIONS
) {
14331 dst
->ipp_ipv4_options
= kmem_alloc(src
->ipp_ipv4_options_len
,
14333 if (dst
->ipp_ipv4_options
== NULL
) {
14337 dst
->ipp_fields
|= IPPF_IPV4_OPTIONS
;
14338 bcopy(src
->ipp_ipv4_options
, dst
->ipp_ipv4_options
,
14339 src
->ipp_ipv4_options_len
);
14340 dst
->ipp_ipv4_options_len
= src
->ipp_ipv4_options_len
;
14342 if (fields
& IPPF_FRAGHDR
) {
14343 dst
->ipp_fraghdr
= kmem_alloc(src
->ipp_fraghdrlen
, kmflag
);
14344 if (dst
->ipp_fraghdr
== NULL
) {
14348 dst
->ipp_fields
|= IPPF_FRAGHDR
;
14349 bcopy(src
->ipp_fraghdr
, dst
->ipp_fraghdr
,
14350 src
->ipp_fraghdrlen
);
14351 dst
->ipp_fraghdrlen
= src
->ipp_fraghdrlen
;
14357 * Returns INADDR_ANY if no source route
14360 ip_pkt_source_route_v4(const ip_pkt_t
*ipp
)
14362 ipaddr_t nexthop
= INADDR_ANY
;
14369 if (!(ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
))
14370 return (INADDR_ANY
);
14372 totallen
= ipp
->ipp_ipv4_options_len
;
14373 if (totallen
& 0x3)
14374 return (INADDR_ANY
);
14376 for (optval
= ipoptp_first2(&opts
, totallen
, ipp
->ipp_ipv4_options
);
14377 optval
!= IPOPT_EOL
;
14378 optval
= ipoptp_next(&opts
)) {
14379 opt
= opts
.ipoptp_cur
;
14384 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
14387 optlen
= opts
.ipoptp_len
;
14388 off
= opt
[IPOPT_OFFSET
];
14390 if (optlen
< IP_ADDR_LEN
||
14391 off
> optlen
- IP_ADDR_LEN
) {
14392 /* End of source route */
14395 bcopy((char *)opt
+ off
, &nexthop
, IP_ADDR_LEN
);
14396 if (nexthop
== htonl(INADDR_LOOPBACK
)) {
14398 nexthop
= INADDR_ANY
;
14408 * Reverse a source route.
14411 ip_pkt_source_route_reverse_v4(ip_pkt_t
*ipp
)
14419 if (!(ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
))
14422 totallen
= ipp
->ipp_ipv4_options_len
;
14423 if (totallen
& 0x3)
14426 for (optval
= ipoptp_first2(&opts
, totallen
, ipp
->ipp_ipv4_options
);
14427 optval
!= IPOPT_EOL
;
14428 optval
= ipoptp_next(&opts
)) {
14429 uint8_t off1
, off2
;
14431 opt
= opts
.ipoptp_cur
;
14435 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
14438 off1
= IPOPT_MINOFF_SR
- 1;
14439 off2
= opt
[IPOPT_OFFSET
] - IP_ADDR_LEN
- 1;
14440 while (off2
> off1
) {
14441 bcopy(opt
+ off2
, &tmp
, IP_ADDR_LEN
);
14442 bcopy(opt
+ off1
, opt
+ off2
, IP_ADDR_LEN
);
14443 bcopy(&tmp
, opt
+ off2
, IP_ADDR_LEN
);
14444 off2
-= IP_ADDR_LEN
;
14445 off1
+= IP_ADDR_LEN
;
14447 opt
[IPOPT_OFFSET
] = IPOPT_MINOFF_SR
;
14454 * Returns NULL if no routing header
14457 ip_pkt_source_route_v6(const ip_pkt_t
*ipp
)
14459 in6_addr_t
*nexthop
= NULL
;
14460 ip6_rthdr0_t
*rthdr
;
14462 if (!(ipp
->ipp_fields
& IPPF_RTHDR
))
14465 rthdr
= (ip6_rthdr0_t
*)ipp
->ipp_rthdr
;
14466 if (rthdr
->ip6r0_segleft
== 0)
14469 nexthop
= (in6_addr_t
*)((char *)rthdr
+ sizeof (*rthdr
));
14474 ip_get_zoneid_v4(ipaddr_t addr
, mblk_t
*mp
, ip_recv_attr_t
*ira
,
14475 zoneid_t lookup_zoneid
)
14477 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
14479 int ire_flags
= MATCH_IRE_TYPE
;
14480 zoneid_t zoneid
= ALL_ZONES
;
14482 if (lookup_zoneid
!= ALL_ZONES
)
14483 ire_flags
|= MATCH_IRE_ZONEONLY
;
14484 ire
= ire_ftable_lookup_v4(addr
, 0, 0, IRE_LOCAL
| IRE_LOOPBACK
,
14485 NULL
, lookup_zoneid
, ire_flags
, 0, ipst
, NULL
);
14487 zoneid
= IP_REAL_ZONEID(ire
->ire_zoneid
, ipst
);
14494 ip_get_zoneid_v6(in6_addr_t
*addr
, mblk_t
*mp
, const ill_t
*ill
,
14495 ip_recv_attr_t
*ira
, zoneid_t lookup_zoneid
)
14497 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
14499 int ire_flags
= MATCH_IRE_TYPE
;
14500 zoneid_t zoneid
= ALL_ZONES
;
14502 if (IN6_IS_ADDR_LINKLOCAL(addr
))
14503 ire_flags
|= MATCH_IRE_ILL
;
14505 if (lookup_zoneid
!= ALL_ZONES
)
14506 ire_flags
|= MATCH_IRE_ZONEONLY
;
14507 ire
= ire_ftable_lookup_v6(addr
, NULL
, NULL
, IRE_LOCAL
| IRE_LOOPBACK
,
14508 ill
, lookup_zoneid
, ire_flags
, 0, ipst
, NULL
);
14510 zoneid
= IP_REAL_ZONEID(ire
->ire_zoneid
, ipst
);
14517 * IP obserability hook support functions.
14520 ipobs_init(ip_stack_t
*ipst
)
14524 id
= net_getnetidbynetstackid(ipst
->ips_netstack
->netstack_stackid
);
14526 ipst
->ips_ip4_observe_pr
= net_protocol_lookup(id
, NHF_INET
);
14527 VERIFY(ipst
->ips_ip4_observe_pr
!= NULL
);
14529 ipst
->ips_ip6_observe_pr
= net_protocol_lookup(id
, NHF_INET6
);
14530 VERIFY(ipst
->ips_ip6_observe_pr
!= NULL
);
14534 ipobs_fini(ip_stack_t
*ipst
)
14537 VERIFY(net_protocol_release(ipst
->ips_ip4_observe_pr
) == 0);
14538 VERIFY(net_protocol_release(ipst
->ips_ip6_observe_pr
) == 0);
14542 * hook_pkt_observe_t is composed in network byte order so that the
14543 * entire mblk_t chain handed into hook_run can be used as-is.
14544 * The caveat is that use of the fields, such as the zone fields,
14545 * requires conversion into host byte order first.
14548 ipobs_hook(mblk_t
*mp
, int htype
, zoneid_t zsrc
, zoneid_t zdst
,
14549 const ill_t
*ill
, ip_stack_t
*ipst
)
14551 hook_pkt_observe_t
*hdr
;
14552 uint64_t grifindex
;
14555 imp
= allocb(sizeof (*hdr
), BPRI_HI
);
14559 hdr
= (hook_pkt_observe_t
*)imp
->b_rptr
;
14561 * b_wptr is set to make the apparent size of the data in the mblk_t
14562 * to exclude the pointers at the end of hook_pkt_observer_t.
14564 imp
->b_wptr
= imp
->b_rptr
+ sizeof (dl_ipnetinfo_t
);
14567 ASSERT(DB_TYPE(mp
) == M_DATA
);
14569 if (IS_UNDER_IPMP(ill
))
14570 grifindex
= ipmp_ill_get_ipmp_ifindex(ill
);
14574 hdr
->hpo_version
= 1;
14575 hdr
->hpo_htype
= htons(htype
);
14576 hdr
->hpo_pktlen
= htonl((ulong_t
)msgdsize(mp
));
14577 hdr
->hpo_ifindex
= htonl(ill
->ill_phyint
->phyint_ifindex
);
14578 hdr
->hpo_grifindex
= htonl(grifindex
);
14579 hdr
->hpo_zsrc
= htonl(zsrc
);
14580 hdr
->hpo_zdst
= htonl(zdst
);
14581 hdr
->hpo_pkt
= imp
;
14582 hdr
->hpo_ctx
= ipst
->ips_netstack
;
14584 if (ill
->ill_isv6
) {
14585 hdr
->hpo_family
= AF_INET6
;
14586 (void) hook_run(ipst
->ips_ipv6_net_data
->netd_hooks
,
14587 ipst
->ips_ipv6observing
, (hook_data_t
)hdr
);
14589 hdr
->hpo_family
= AF_INET
;
14590 (void) hook_run(ipst
->ips_ipv4_net_data
->netd_hooks
,
14591 ipst
->ips_ipv4observing
, (hook_data_t
)hdr
);
14594 imp
->b_cont
= NULL
;
14599 * Utility routine that checks if `v4srcp' is a valid address on underlying
14600 * interface `ill'. If `ipifp' is non-NULL, it's set to a held ipif
14601 * associated with `v4srcp' on success. NOTE: if this is not called from
14602 * inside the IPSQ (ill_g_lock is not held), `ill' may be removed from the
14603 * group during or after this lookup.
14606 ipif_lookup_testaddr_v4(ill_t
*ill
, const in_addr_t
*v4srcp
, ipif_t
**ipifp
)
14610 ipif
= ipif_lookup_addr_exact(*v4srcp
, ill
, ill
->ill_ipst
);
14611 if (ipif
!= NULL
) {
14615 ipif_refrele(ipif
);
14619 ip1dbg(("ipif_lookup_testaddr_v4: cannot find ipif for src %x\n",
14625 * Transport protocol call back function for CPU state change.
14629 ip_tp_cpu_update(cpu_setup_t what
, int id
, void *arg
)
14631 processorid_t cpu_seqid
;
14632 netstack_handle_t nh
;
14635 ASSERT(MUTEX_HELD(&cpu_lock
));
14641 case CPU_CPUPART_IN
:
14642 cpu_seqid
= cpu
[id
]->cpu_seqid
;
14643 netstack_next_init(&nh
);
14644 while ((ns
= netstack_next(&nh
)) != NULL
) {
14645 tcp_stack_cpu_add(ns
->netstack_tcp
, cpu_seqid
);
14646 sctp_stack_cpu_add(ns
->netstack_sctp
, cpu_seqid
);
14647 udp_stack_cpu_add(ns
->netstack_udp
, cpu_seqid
);
14650 netstack_next_fini(&nh
);
14654 case CPU_CPUPART_OUT
:
14656 * Nothing to do. We don't remove the per CPU stats from
14657 * the IP stack even when the CPU goes offline.