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 int ip_close(queue_t
*, int);
612 static char *ip_dot_saddr(uchar_t
*, char *);
613 static void ip_lrput(queue_t
*, mblk_t
*);
614 ipaddr_t
ip_net_mask(ipaddr_t
);
615 char *ip_nv_lookup(nv_t
*, int);
616 void ip_rput(queue_t
*, mblk_t
*);
617 static void ip_rput_dlpi_writer(ipsq_t
*dummy_sq
, queue_t
*q
, mblk_t
*mp
,
619 int ip_snmp_get(queue_t
*, mblk_t
*, int, boolean_t
);
620 static mblk_t
*ip_snmp_get_mib2_ip(queue_t
*, mblk_t
*,
621 mib2_ipIfStatsEntry_t
*, ip_stack_t
*, boolean_t
);
622 static mblk_t
*ip_snmp_get_mib2_ip_traffic_stats(queue_t
*, mblk_t
*,
623 ip_stack_t
*, boolean_t
);
624 static mblk_t
*ip_snmp_get_mib2_ip6(queue_t
*, mblk_t
*, ip_stack_t
*,
626 static mblk_t
*ip_snmp_get_mib2_icmp(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
627 static mblk_t
*ip_snmp_get_mib2_icmp6(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
628 static mblk_t
*ip_snmp_get_mib2_igmp(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
629 static mblk_t
*ip_snmp_get_mib2_multi(queue_t
*, mblk_t
*, ip_stack_t
*ipst
);
630 static mblk_t
*ip_snmp_get_mib2_ip_addr(queue_t
*, mblk_t
*,
631 ip_stack_t
*ipst
, boolean_t
);
632 static mblk_t
*ip_snmp_get_mib2_ip6_addr(queue_t
*, mblk_t
*,
633 ip_stack_t
*ipst
, boolean_t
);
634 static mblk_t
*ip_snmp_get_mib2_ip_group_src(queue_t
*, mblk_t
*,
636 static mblk_t
*ip_snmp_get_mib2_ip6_group_src(queue_t
*, mblk_t
*,
638 static mblk_t
*ip_snmp_get_mib2_ip_group_mem(queue_t
*, mblk_t
*,
640 static mblk_t
*ip_snmp_get_mib2_ip6_group_mem(queue_t
*, mblk_t
*,
642 static mblk_t
*ip_snmp_get_mib2_virt_multi(queue_t
*, mblk_t
*,
644 static mblk_t
*ip_snmp_get_mib2_multi_rtable(queue_t
*, mblk_t
*,
646 static mblk_t
*ip_snmp_get_mib2_ip_route_media(queue_t
*, mblk_t
*, int,
648 static mblk_t
*ip_snmp_get_mib2_ip6_route_media(queue_t
*, mblk_t
*, int,
650 static void ip_snmp_get2_v4(ire_t
*, iproutedata_t
*);
651 static void ip_snmp_get2_v6_route(ire_t
*, iproutedata_t
*);
652 static int ip_snmp_get2_v4_media(ncec_t
*, iproutedata_t
*);
653 static int ip_snmp_get2_v6_media(ncec_t
*, iproutedata_t
*);
654 int ip_snmp_set(queue_t
*, int, int, uchar_t
*, int);
656 static mblk_t
*ip_fragment_copyhdr(uchar_t
*, int, int, ip_stack_t
*,
659 static void conn_drain_init(ip_stack_t
*);
660 static void conn_drain_fini(ip_stack_t
*);
661 static void conn_drain(conn_t
*connp
, boolean_t closing
);
663 static void conn_walk_drain(ip_stack_t
*, idl_tx_list_t
*);
664 static void conn_walk_sctp(pfv_t
, void *, zoneid_t
, netstack_t
*);
666 static void *ip_stack_init(netstackid_t stackid
, netstack_t
*ns
);
667 static void ip_stack_shutdown(netstackid_t stackid
, void *arg
);
668 static void ip_stack_fini(netstackid_t stackid
, void *arg
);
670 static int ip_squeue_switch(int);
672 static void *ip_kstat_init(netstackid_t
, ip_stack_t
*);
673 static void ip_kstat_fini(netstackid_t
, kstat_t
*);
674 static int ip_kstat_update(kstat_t
*kp
, int rw
);
675 static void *icmp_kstat_init(netstackid_t
);
676 static void icmp_kstat_fini(netstackid_t
, kstat_t
*);
677 static int icmp_kstat_update(kstat_t
*kp
, int rw
);
678 static void *ip_kstat2_init(netstackid_t
, ip_stat_t
*);
679 static void ip_kstat2_fini(netstackid_t
, kstat_t
*);
681 static void ipobs_init(ip_stack_t
*);
682 static void ipobs_fini(ip_stack_t
*);
684 static int ip_tp_cpu_update(cpu_setup_t
, int, void *);
686 ipaddr_t ip_g_all_ones
= IP_HOST_MASK
;
688 static long ip_rput_pullups
;
689 int dohwcksum
= 1; /* use h/w cksum if supported by the hardware */
691 vmem_t
*ip_minor_arena_sa
; /* for minor nos. from INET_MIN_DEV+2 thru 2^^18-1 */
692 vmem_t
*ip_minor_arena_la
; /* for minor nos. from 2^^18 thru 2^^32-1 */
697 * IP tunables related declarations. Definitions are in ip_tunables.c
699 extern mod_prop_info_t ip_propinfo_tbl
[];
700 extern int ip_propinfo_count
;
703 * Table of IP ioctls encoding the various properties of the ioctl and
704 * indexed based on the last byte of the ioctl command. Occasionally there
705 * is a clash, and there is more than 1 ioctl with the same last byte.
706 * In such a case 1 ioctl is encoded in the ndx table and the remaining
707 * ioctls are encoded in the misc table. An entry in the ndx table is
708 * retrieved by indexing on the last byte of the ioctl command and comparing
709 * the ioctl command with the value in the ndx table. In the event of a
710 * mismatch the misc table is then searched sequentially for the desired
713 * Entry: <command> <copyin_size> <flags> <cmd_type> <function> <restart_func>
715 ip_ioctl_cmd_t ip_ndx_ioctl_table
[] = {
716 /* 000 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
717 /* 001 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
718 /* 002 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
719 /* 003 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
720 /* 004 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
721 /* 005 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
722 /* 006 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
723 /* 007 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
724 /* 008 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
725 /* 009 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
727 /* 010 */ { SIOCADDRT
, sizeof (struct rtentry
), IPI_PRIV
,
728 MISC_CMD
, ip_siocaddrt
, NULL
},
729 /* 011 */ { SIOCDELRT
, sizeof (struct rtentry
), IPI_PRIV
,
730 MISC_CMD
, ip_siocdelrt
, NULL
},
732 /* 012 */ { SIOCSIFADDR
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
733 IF_CMD
, ip_sioctl_addr
, ip_sioctl_addr_restart
},
734 /* 013 */ { SIOCGIFADDR
, sizeof (struct ifreq
), IPI_GET_CMD
,
735 IF_CMD
, ip_sioctl_get_addr
, NULL
},
737 /* 014 */ { SIOCSIFDSTADDR
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
738 IF_CMD
, ip_sioctl_dstaddr
, ip_sioctl_dstaddr_restart
},
739 /* 015 */ { SIOCGIFDSTADDR
, sizeof (struct ifreq
),
740 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_dstaddr
, NULL
},
742 /* 016 */ { SIOCSIFFLAGS
, sizeof (struct ifreq
),
744 IF_CMD
, ip_sioctl_flags
, ip_sioctl_flags_restart
},
745 /* 017 */ { SIOCGIFFLAGS
, sizeof (struct ifreq
),
746 IPI_MODOK
| IPI_GET_CMD
,
747 IF_CMD
, ip_sioctl_get_flags
, NULL
},
749 /* 018 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
750 /* 019 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
752 /* copyin size cannot be coded for SIOCGIFCONF */
753 /* 020 */ { O_SIOCGIFCONF
, 0, IPI_GET_CMD
,
754 MISC_CMD
, ip_sioctl_get_ifconf
, NULL
},
756 /* 021 */ { SIOCSIFMTU
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
757 IF_CMD
, ip_sioctl_mtu
, NULL
},
758 /* 022 */ { SIOCGIFMTU
, sizeof (struct ifreq
), IPI_GET_CMD
,
759 IF_CMD
, ip_sioctl_get_mtu
, NULL
},
760 /* 023 */ { SIOCGIFBRDADDR
, sizeof (struct ifreq
),
761 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_brdaddr
, NULL
},
762 /* 024 */ { SIOCSIFBRDADDR
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
763 IF_CMD
, ip_sioctl_brdaddr
, NULL
},
764 /* 025 */ { SIOCGIFNETMASK
, sizeof (struct ifreq
),
765 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_netmask
, NULL
},
766 /* 026 */ { SIOCSIFNETMASK
, sizeof (struct ifreq
), IPI_PRIV
| IPI_WR
,
767 IF_CMD
, ip_sioctl_netmask
, ip_sioctl_netmask_restart
},
768 /* 027 */ { SIOCGIFMETRIC
, sizeof (struct ifreq
),
769 IPI_GET_CMD
, IF_CMD
, ip_sioctl_get_metric
, NULL
},
770 /* 028 */ { SIOCSIFMETRIC
, sizeof (struct ifreq
), IPI_PRIV
,
771 IF_CMD
, ip_sioctl_metric
, NULL
},
772 /* 029 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
774 /* See 166-168 below for extended SIOC*XARP ioctls */
775 /* 030 */ { SIOCSARP
, sizeof (struct arpreq
), IPI_PRIV
| IPI_WR
,
776 ARP_CMD
, ip_sioctl_arp
, NULL
},
777 /* 031 */ { SIOCGARP
, sizeof (struct arpreq
), IPI_GET_CMD
,
778 ARP_CMD
, ip_sioctl_arp
, NULL
},
779 /* 032 */ { SIOCDARP
, sizeof (struct arpreq
), IPI_PRIV
| IPI_WR
,
780 ARP_CMD
, ip_sioctl_arp
, NULL
},
782 /* 033 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
783 /* 034 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
784 /* 035 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
785 /* 036 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
786 /* 037 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
787 /* 038 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
788 /* 039 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
789 /* 040 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
790 /* 041 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
791 /* 042 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
792 /* 043 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
793 /* 044 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
794 /* 045 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
795 /* 046 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
796 /* 047 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
797 /* 048 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
798 /* 049 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
799 /* 050 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
800 /* 051 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
801 /* 052 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
802 /* 053 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
804 /* 054 */ { IF_UNITSEL
, sizeof (int), IPI_PRIV
| IPI_WR
| IPI_MODOK
,
805 MISC_CMD
, if_unitsel
, if_unitsel_restart
},
807 /* 055 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
808 /* 056 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
809 /* 057 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
810 /* 058 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
811 /* 059 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
812 /* 060 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
813 /* 061 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
814 /* 062 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
815 /* 063 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
816 /* 064 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
817 /* 065 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
818 /* 066 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
819 /* 067 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
820 /* 068 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
821 /* 069 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
822 /* 070 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
823 /* 071 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
824 /* 072 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
826 /* 073 */ { SIOCSIFNAME
, sizeof (struct ifreq
),
827 IPI_PRIV
| IPI_WR
| IPI_MODOK
,
828 IF_CMD
, ip_sioctl_sifname
, NULL
},
830 /* 074 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
831 /* 075 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
832 /* 076 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
833 /* 077 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
834 /* 078 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
835 /* 079 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
836 /* 080 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
837 /* 081 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
838 /* 082 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
839 /* 083 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
840 /* 084 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
841 /* 085 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
842 /* 086 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
844 /* 087 */ { SIOCGIFNUM
, sizeof (int), IPI_GET_CMD
,
845 MISC_CMD
, ip_sioctl_get_ifnum
, NULL
},
846 /* 088 */ { SIOCGIFMUXID
, sizeof (struct ifreq
), IPI_GET_CMD
,
847 IF_CMD
, ip_sioctl_get_muxid
, NULL
},
848 /* 089 */ { SIOCSIFMUXID
, sizeof (struct ifreq
),
849 IPI_PRIV
| IPI_WR
, IF_CMD
, ip_sioctl_muxid
, NULL
},
851 /* Both if and lif variants share same func */
852 /* 090 */ { SIOCGIFINDEX
, sizeof (struct ifreq
), IPI_GET_CMD
,
853 IF_CMD
, ip_sioctl_get_lifindex
, NULL
},
854 /* Both if and lif variants share same func */
855 /* 091 */ { SIOCSIFINDEX
, sizeof (struct ifreq
),
856 IPI_PRIV
| IPI_WR
, IF_CMD
, ip_sioctl_slifindex
, NULL
},
858 /* copyin size cannot be coded for SIOCGIFCONF */
859 /* 092 */ { SIOCGIFCONF
, 0, IPI_GET_CMD
,
860 MISC_CMD
, ip_sioctl_get_ifconf
, NULL
},
861 /* 093 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
862 /* 094 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
863 /* 095 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
864 /* 096 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
865 /* 097 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
866 /* 098 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
867 /* 099 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
868 /* 100 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
869 /* 101 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
870 /* 102 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
871 /* 103 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
872 /* 104 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
873 /* 105 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
874 /* 106 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
875 /* 107 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
876 /* 108 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
877 /* 109 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
879 /* 110 */ { SIOCLIFREMOVEIF
, sizeof (struct lifreq
),
880 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_removeif
,
881 ip_sioctl_removeif_restart
},
882 /* 111 */ { SIOCLIFADDIF
, sizeof (struct lifreq
),
883 IPI_GET_CMD
| IPI_PRIV
| IPI_WR
,
884 LIF_CMD
, ip_sioctl_addif
, NULL
},
885 #define SIOCLIFADDR_NDX 112
886 /* 112 */ { SIOCSLIFADDR
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
887 LIF_CMD
, ip_sioctl_addr
, ip_sioctl_addr_restart
},
888 /* 113 */ { SIOCGLIFADDR
, sizeof (struct lifreq
),
889 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_addr
, NULL
},
890 /* 114 */ { SIOCSLIFDSTADDR
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
891 LIF_CMD
, ip_sioctl_dstaddr
, ip_sioctl_dstaddr_restart
},
892 /* 115 */ { SIOCGLIFDSTADDR
, sizeof (struct lifreq
),
893 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_dstaddr
, NULL
},
894 /* 116 */ { SIOCSLIFFLAGS
, sizeof (struct lifreq
),
896 LIF_CMD
, ip_sioctl_flags
, ip_sioctl_flags_restart
},
897 /* 117 */ { SIOCGLIFFLAGS
, sizeof (struct lifreq
),
898 IPI_GET_CMD
| IPI_MODOK
,
899 LIF_CMD
, ip_sioctl_get_flags
, NULL
},
901 /* 118 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
902 /* 119 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
904 /* 120 */ { O_SIOCGLIFCONF
, 0, IPI_GET_CMD
, MISC_CMD
,
905 ip_sioctl_get_lifconf
, NULL
},
906 /* 121 */ { SIOCSLIFMTU
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
907 LIF_CMD
, ip_sioctl_mtu
, NULL
},
908 /* 122 */ { SIOCGLIFMTU
, sizeof (struct lifreq
), IPI_GET_CMD
,
909 LIF_CMD
, ip_sioctl_get_mtu
, NULL
},
910 /* 123 */ { SIOCGLIFBRDADDR
, sizeof (struct lifreq
),
911 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_brdaddr
, NULL
},
912 /* 124 */ { SIOCSLIFBRDADDR
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
913 LIF_CMD
, ip_sioctl_brdaddr
, NULL
},
914 /* 125 */ { SIOCGLIFNETMASK
, sizeof (struct lifreq
),
915 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_netmask
, NULL
},
916 /* 126 */ { SIOCSLIFNETMASK
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
917 LIF_CMD
, ip_sioctl_netmask
, ip_sioctl_netmask_restart
},
918 /* 127 */ { SIOCGLIFMETRIC
, sizeof (struct lifreq
),
919 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_metric
, NULL
},
920 /* 128 */ { SIOCSLIFMETRIC
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
921 LIF_CMD
, ip_sioctl_metric
, NULL
},
922 /* 129 */ { SIOCSLIFNAME
, sizeof (struct lifreq
),
923 IPI_PRIV
| IPI_WR
| IPI_MODOK
,
924 LIF_CMD
, ip_sioctl_slifname
,
925 ip_sioctl_slifname_restart
},
927 /* 130 */ { SIOCGLIFNUM
, sizeof (struct lifnum
), IPI_GET_CMD
,
928 MISC_CMD
, ip_sioctl_get_lifnum
, NULL
},
929 /* 131 */ { SIOCGLIFMUXID
, sizeof (struct lifreq
),
930 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_muxid
, NULL
},
931 /* 132 */ { SIOCSLIFMUXID
, sizeof (struct lifreq
),
932 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_muxid
, NULL
},
933 /* 133 */ { SIOCGLIFINDEX
, sizeof (struct lifreq
),
934 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_lifindex
, 0 },
935 /* 134 */ { SIOCSLIFINDEX
, sizeof (struct lifreq
),
936 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_slifindex
, 0 },
937 /* 135 */ { SIOCSLIFTOKEN
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
938 LIF_CMD
, ip_sioctl_token
, NULL
},
939 /* 136 */ { SIOCGLIFTOKEN
, sizeof (struct lifreq
),
940 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_token
, NULL
},
941 /* 137 */ { SIOCSLIFSUBNET
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
942 LIF_CMD
, ip_sioctl_subnet
, ip_sioctl_subnet_restart
},
943 /* 138 */ { SIOCGLIFSUBNET
, sizeof (struct lifreq
),
944 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_subnet
, NULL
},
945 /* 139 */ { SIOCSLIFLNKINFO
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
946 LIF_CMD
, ip_sioctl_lnkinfo
, NULL
},
948 /* 140 */ { SIOCGLIFLNKINFO
, sizeof (struct lifreq
),
949 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_lnkinfo
, NULL
},
950 /* 141 */ { SIOCLIFDELND
, sizeof (struct lifreq
), IPI_PRIV
,
951 LIF_CMD
, ip_siocdelndp_v6
, NULL
},
952 /* 142 */ { SIOCLIFGETND
, sizeof (struct lifreq
), IPI_GET_CMD
,
953 LIF_CMD
, ip_siocqueryndp_v6
, NULL
},
954 /* 143 */ { SIOCLIFSETND
, sizeof (struct lifreq
), IPI_PRIV
,
955 LIF_CMD
, ip_siocsetndp_v6
, NULL
},
956 /* 144 */ { SIOCTMYADDR
, sizeof (struct sioc_addrreq
), IPI_GET_CMD
,
957 MISC_CMD
, ip_sioctl_tmyaddr
, NULL
},
958 /* 145 */ { SIOCTONLINK
, sizeof (struct sioc_addrreq
), IPI_GET_CMD
,
959 MISC_CMD
, ip_sioctl_tonlink
, NULL
},
960 /* 146 */ { SIOCTMYSITE
, sizeof (struct sioc_addrreq
), 0,
961 MISC_CMD
, ip_sioctl_tmysite
, NULL
},
962 /* 147 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
963 /* 148 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
965 /* Old *IPSECONFIG ioctls are now deprecated, now see spdsock.c */
966 /* 149 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
967 /* 150 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
968 /* 151 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
969 /* 152 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
971 /* 153 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
973 /* 154 */ { SIOCGLIFBINDING
, sizeof (struct lifreq
), IPI_GET_CMD
,
974 LIF_CMD
, ip_sioctl_get_binding
, NULL
},
975 /* 155 */ { SIOCSLIFGROUPNAME
, sizeof (struct lifreq
),
977 LIF_CMD
, ip_sioctl_groupname
, ip_sioctl_groupname
},
978 /* 156 */ { SIOCGLIFGROUPNAME
, sizeof (struct lifreq
),
979 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_groupname
, NULL
},
980 /* 157 */ { SIOCGLIFGROUPINFO
, sizeof (lifgroupinfo_t
),
981 IPI_GET_CMD
, MISC_CMD
, ip_sioctl_groupinfo
, NULL
},
983 /* Leave 158-160 unused; used to be SIOC*IFARP ioctls */
984 /* 158 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
985 /* 159 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
986 /* 160 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
988 /* 161 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
990 /* These are handled in ip_sioctl_copyin_setup itself */
991 /* 162 */ { SIOCGIP6ADDRPOLICY
, 0, IPI_NULL_BCONT
,
992 MISC_CMD
, NULL
, NULL
},
993 /* 163 */ { SIOCSIP6ADDRPOLICY
, 0, IPI_PRIV
| IPI_NULL_BCONT
,
994 MISC_CMD
, NULL
, NULL
},
995 /* 164 */ { SIOCGDSTINFO
, 0, IPI_GET_CMD
, MISC_CMD
, NULL
, NULL
},
997 /* 165 */ { SIOCGLIFCONF
, 0, IPI_GET_CMD
, MISC_CMD
,
998 ip_sioctl_get_lifconf
, NULL
},
1000 /* 166 */ { SIOCSXARP
, sizeof (struct xarpreq
), IPI_PRIV
| IPI_WR
,
1001 XARP_CMD
, ip_sioctl_arp
, NULL
},
1002 /* 167 */ { SIOCGXARP
, sizeof (struct xarpreq
), IPI_GET_CMD
,
1003 XARP_CMD
, ip_sioctl_arp
, NULL
},
1004 /* 168 */ { SIOCDXARP
, sizeof (struct xarpreq
), IPI_PRIV
| IPI_WR
,
1005 XARP_CMD
, ip_sioctl_arp
, NULL
},
1007 /* SIOCPOPSOCKFS is not handled by IP */
1008 /* 169 */ { IPI_DONTCARE
/* SIOCPOPSOCKFS */, 0, 0, 0, NULL
, NULL
},
1010 /* 170 */ { SIOCGLIFZONE
, sizeof (struct lifreq
),
1011 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_lifzone
, NULL
},
1012 /* 171 */ { SIOCSLIFZONE
, sizeof (struct lifreq
),
1013 IPI_PRIV
| IPI_WR
, LIF_CMD
, ip_sioctl_slifzone
,
1014 ip_sioctl_slifzone_restart
},
1015 /* 172-174 are SCTP ioctls and not handled by IP */
1016 /* 172 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1017 /* 173 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1018 /* 174 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1019 /* 175 */ { SIOCGLIFUSESRC
, sizeof (struct lifreq
),
1020 IPI_GET_CMD
, LIF_CMD
,
1021 ip_sioctl_get_lifusesrc
, 0 },
1022 /* 176 */ { SIOCSLIFUSESRC
, sizeof (struct lifreq
),
1024 LIF_CMD
, ip_sioctl_slifusesrc
,
1026 /* 177 */ { SIOCGLIFSRCOF
, 0, IPI_GET_CMD
, MISC_CMD
,
1027 ip_sioctl_get_lifsrcof
, NULL
},
1028 /* 178 */ { SIOCGMSFILTER
, sizeof (struct group_filter
), IPI_GET_CMD
,
1029 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1030 /* 179 */ { SIOCSMSFILTER
, sizeof (struct group_filter
), 0,
1031 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1032 /* 180 */ { SIOCGIPMSFILTER
, sizeof (struct ip_msfilter
), IPI_GET_CMD
,
1033 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1034 /* 181 */ { SIOCSIPMSFILTER
, sizeof (struct ip_msfilter
), 0,
1035 MSFILT_CMD
, ip_sioctl_msfilter
, NULL
},
1036 /* 182 */ { IPI_DONTCARE
, 0, 0, 0, NULL
, NULL
},
1037 /* SIOCSENABLESDP is handled by SDP */
1038 /* 183 */ { IPI_DONTCARE
/* SIOCSENABLESDP */, 0, 0, 0, NULL
, NULL
},
1039 /* 184 */ { IPI_DONTCARE
/* SIOCSQPTR */, 0, 0, 0, NULL
, NULL
},
1040 /* 185 */ { SIOCGIFHWADDR
, sizeof (struct ifreq
), IPI_GET_CMD
,
1041 IF_CMD
, ip_sioctl_get_ifhwaddr
, NULL
},
1042 /* 186 */ { IPI_DONTCARE
/* SIOCGSTAMP */, 0, 0, 0, NULL
, NULL
},
1043 /* 187 */ { SIOCILB
, 0, IPI_PRIV
| IPI_GET_CMD
, MISC_CMD
,
1044 ip_sioctl_ilb_cmd
, NULL
},
1045 /* 188 */ { SIOCGETPROP
, sizeof (mod_ioc_prop_t
), IPI_GET_CMD
,
1046 MISC_CMD
, ip_sioctl_getsetprop
, NULL
},
1047 /* 189 */ { SIOCSETPROP
, sizeof (mod_ioc_prop_t
), IPI_PRIV
,
1048 MISC_CMD
, ip_sioctl_getsetprop
, NULL
},
1049 /* 190 */ { SIOCGLIFDADSTATE
, sizeof (struct lifreq
),
1050 IPI_GET_CMD
, LIF_CMD
, ip_sioctl_get_dadstate
, NULL
},
1051 /* 191 */ { SIOCSLIFPREFIX
, sizeof (struct lifreq
), IPI_PRIV
| IPI_WR
,
1052 LIF_CMD
, ip_sioctl_prefix
, ip_sioctl_prefix_restart
},
1053 /* 192 */ { SIOCGLIFHWADDR
, sizeof (struct lifreq
), IPI_GET_CMD
,
1054 LIF_CMD
, ip_sioctl_get_lifhwaddr
, NULL
}
1057 int ip_ndx_ioctl_count
= sizeof (ip_ndx_ioctl_table
) / sizeof (ip_ioctl_cmd_t
);
1059 ip_ioctl_cmd_t ip_misc_ioctl_table
[] = {
1060 { I_LINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1061 { I_UNLINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1062 { I_PLINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1063 { I_PUNLINK
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1064 { ND_GET
, 0, 0, 0, NULL
, NULL
},
1065 { ND_SET
, 0, IPI_PRIV
| IPI_WR
, 0, NULL
, NULL
},
1066 { IP_IOCTL
, 0, 0, 0, NULL
, NULL
},
1067 { SIOCGETVIFCNT
, sizeof (struct sioc_vif_req
), IPI_GET_CMD
,
1068 MISC_CMD
, mrt_ioctl
},
1069 { SIOCGETSGCNT
, sizeof (struct sioc_sg_req
), IPI_GET_CMD
,
1070 MISC_CMD
, mrt_ioctl
},
1071 { SIOCGETLSGCNT
, sizeof (struct sioc_lsg_req
), IPI_GET_CMD
,
1072 MISC_CMD
, mrt_ioctl
}
1075 int ip_misc_ioctl_count
=
1076 sizeof (ip_misc_ioctl_table
) / sizeof (ip_ioctl_cmd_t
);
1078 int conn_drain_nthreads
; /* Number of drainers reqd. */
1079 /* Settable in /etc/system */
1080 /* Defined in ip_ire.c */
1081 extern uint32_t ip_ire_max_bucket_cnt
, ip6_ire_max_bucket_cnt
;
1082 extern uint32_t ip_ire_min_bucket_cnt
, ip6_ire_min_bucket_cnt
;
1083 extern uint32_t ip_ire_mem_ratio
, ip_ire_cpu_ratio
;
1085 static nv_t ire_nv_arr
[] = {
1086 { IRE_BROADCAST
, "BROADCAST" },
1087 { IRE_LOCAL
, "LOCAL" },
1088 { IRE_LOOPBACK
, "LOOPBACK" },
1089 { IRE_DEFAULT
, "DEFAULT" },
1090 { IRE_PREFIX
, "PREFIX" },
1091 { IRE_IF_NORESOLVER
, "IF_NORESOL" },
1092 { IRE_IF_RESOLVER
, "IF_RESOLV" },
1093 { IRE_IF_CLONE
, "IF_CLONE" },
1094 { IRE_HOST
, "HOST" },
1095 { IRE_MULTICAST
, "MULTICAST" },
1096 { IRE_NOROUTE
, "NOROUTE" },
1100 nv_t
*ire_nv_tbl
= ire_nv_arr
;
1102 /* Simple ICMP IP Header Template */
1103 static ipha_t icmp_ipha
= {
1104 IP_SIMPLE_HDR_VERSION
, 0, 0, 0, 0, 0, IPPROTO_ICMP
1107 struct module_info ip_mod_info
= {
1108 IP_MOD_ID
, IP_MOD_NAME
, IP_MOD_MINPSZ
, IP_MOD_MAXPSZ
, IP_MOD_HIWAT
,
1113 * Duplicate static symbols within a module confuses mdb; so we avoid the
1114 * problem by making the symbols here distinct from those in udp.c.
1118 * Entry points for IP as a device and as a module.
1119 * We have separate open functions for the /dev/ip and /dev/ip6 devices.
1121 static struct qinit iprinitv4
= {
1122 (pfi_t
)ip_rput
, NULL
, ip_openv4
, ip_close
, NULL
,
1126 struct qinit iprinitv6
= {
1127 (pfi_t
)ip_rput_v6
, NULL
, ip_openv6
, ip_close
, NULL
,
1131 static struct qinit ipwinit
= {
1132 (pfi_t
)ip_wput_nondata
, (pfi_t
)ip_wsrv
, NULL
, NULL
, NULL
,
1136 static struct qinit iplrinit
= {
1137 (pfi_t
)ip_lrput
, NULL
, ip_openv4
, ip_close
, NULL
,
1141 static struct qinit iplwinit
= {
1142 (pfi_t
)ip_lwput
, NULL
, NULL
, NULL
, NULL
,
1146 /* For AF_INET aka /dev/ip */
1147 struct streamtab ipinfov4
= {
1148 &iprinitv4
, &ipwinit
, &iplrinit
, &iplwinit
1151 /* For AF_INET6 aka /dev/ip6 */
1152 struct streamtab ipinfov6
= {
1153 &iprinitv6
, &ipwinit
, &iplrinit
, &iplwinit
1157 boolean_t skip_sctp_cksum
= B_FALSE
;
1161 * Generate an ICMP fragmentation needed message.
1162 * When called from ip_output side a minimal ip_recv_attr_t needs to be
1163 * constructed by the caller.
1166 icmp_frag_needed(mblk_t
*mp
, int mtu
, ip_recv_attr_t
*ira
)
1169 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
1171 mp
= icmp_pkt_err_ok(mp
, ira
);
1175 bzero(&icmph
, sizeof (icmph_t
));
1176 icmph
.icmph_type
= ICMP_DEST_UNREACHABLE
;
1177 icmph
.icmph_code
= ICMP_FRAGMENTATION_NEEDED
;
1178 icmph
.icmph_du_mtu
= htons((uint16_t)mtu
);
1179 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutFragNeeded
);
1180 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDestUnreachs
);
1182 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
1186 * icmp_inbound_v4 deals with ICMP messages that are handled by IP.
1187 * If the ICMP message is consumed by IP, i.e., it should not be delivered
1188 * to any IPPROTO_ICMP raw sockets, then it returns NULL.
1189 * Likewise, if the ICMP error is misformed (too short, etc), then it
1190 * returns NULL. The caller uses this to determine whether or not to send
1193 * All error messages are passed to the matching transport stream.
1195 * The following cases are handled by icmp_inbound:
1196 * 1) It needs to send a reply back and possibly delivering it
1197 * to the "interested" upper clients.
1198 * 2) Return the mblk so that the caller can pass it to the RAW socket clients.
1199 * 3) It needs to change some values in IP only.
1200 * 4) It needs to change some values in IP and upper layers e.g TCP
1201 * by delivering an error to the upper layers.
1203 * We handle the above three cases in the context of IPsec in the
1206 * 1) Send the reply back in the same way as the request came in.
1207 * If it came in encrypted, it goes out encrypted. If it came in
1208 * clear, it goes out in clear. Thus, this will prevent chosen
1209 * plain text attack.
1210 * 2) The client may or may not expect things to come in secure.
1211 * If it comes in secure, the policy constraints are checked
1212 * before delivering it to the upper layers. If it comes in
1213 * clear, ipsec_inbound_accept_clear will decide whether to
1214 * accept this in clear or not. In both the cases, if the returned
1215 * message (IP header + 8 bytes) that caused the icmp message has
1216 * AH/ESP headers, it is sent up to AH/ESP for validation before
1217 * sending up. If there are only 8 bytes of returned message, then
1218 * upper client will not be notified.
1219 * 3) Check with global policy to see whether it matches the constaints.
1220 * But this will be done only if icmp_accept_messages_in_clear is
1222 * 4) If we need to change both in IP and ULP, then the decision taken
1223 * while affecting the values in IP and while delivering up to TCP
1224 * should be the same.
1226 * There are two cases.
1228 * a) If we reject data at the IP layer (ipsec_check_global_policy()
1229 * failed), we will not deliver it to the ULP, even though they
1230 * are *willing* to accept in *clear*. This is fine as our global
1231 * disposition to icmp messages asks us reject the datagram.
1233 * b) If we accept data at the IP layer (ipsec_check_global_policy()
1234 * succeeded or icmp_accept_messages_in_clear is 1), and not able
1235 * to deliver it to ULP (policy failed), it can lead to
1236 * consistency problems. The cases known at this time are
1237 * ICMP_DESTINATION_UNREACHABLE messages with following code
1240 * - ICMP_FRAGMENTATION_NEEDED : IP adapts to the new value
1241 * and Upper layer rejects. Then the communication will
1242 * come to a stop. This is solved by making similar decisions
1243 * at both levels. Currently, when we are unable to deliver
1244 * to the Upper Layer (due to policy failures) while IP has
1245 * adjusted dce_pmtu, the next outbound datagram would
1246 * generate a local ICMP_FRAGMENTATION_NEEDED message - which
1247 * will be with the right level of protection. Thus the right
1248 * value will be communicated even if we are not able to
1249 * communicate when we get from the wire initially. But this
1250 * assumes there would be at least one outbound datagram after
1251 * IP has adjusted its dce_pmtu value. To make things
1252 * simpler, we accept in clear after the validation of
1255 * - Other ICMP ERRORS : We may not be able to deliver it to the
1256 * upper layer depending on the level of protection the upper
1257 * layer expects and the disposition in ipsec_inbound_accept_clear().
1258 * ipsec_inbound_accept_clear() decides whether a given ICMP error
1259 * should be accepted in clear when the Upper layer expects secure.
1260 * Thus the communication may get aborted by some bad ICMP
1264 icmp_inbound_v4(mblk_t
*mp
, ip_recv_attr_t
*ira
)
1267 ipha_t
*ipha
; /* Outer header */
1268 int ip_hdr_length
; /* Outer header length */
1269 boolean_t interested
;
1274 ill_t
*ill
= ira
->ira_ill
;
1275 ip_stack_t
*ipst
= ill
->ill_ipst
;
1276 zoneid_t zoneid
= ira
->ira_zoneid
;
1278 mblk_t
*mp_ret
= NULL
;
1280 ipha
= (ipha_t
*)mp
->b_rptr
;
1282 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInMsgs
);
1284 ip_hdr_length
= ira
->ira_ip_hdr_length
;
1285 if ((mp
->b_wptr
- mp
->b_rptr
) < (ip_hdr_length
+ ICMPH_SIZE
)) {
1286 if (ira
->ira_pktlen
< (ip_hdr_length
+ ICMPH_SIZE
)) {
1287 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
1288 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
1292 /* Last chance to get real. */
1293 ipha
= ip_pullup(mp
, ip_hdr_length
+ ICMPH_SIZE
, ira
);
1295 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInErrors
);
1301 /* The IP header will always be a multiple of four bytes */
1302 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1303 ip2dbg(("icmp_inbound_v4: type %d code %d\n", icmph
->icmph_type
,
1304 icmph
->icmph_code
));
1307 * We will set "interested" to "true" if we should pass a copy to
1308 * the transport or if we handle the packet locally.
1310 interested
= B_FALSE
;
1311 switch (icmph
->icmph_type
) {
1312 case ICMP_ECHO_REPLY
:
1313 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInEchoReps
);
1315 case ICMP_DEST_UNREACHABLE
:
1316 if (icmph
->icmph_code
== ICMP_FRAGMENTATION_NEEDED
)
1317 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInFragNeeded
);
1318 interested
= B_TRUE
; /* Pass up to transport */
1319 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInDestUnreachs
);
1321 case ICMP_SOURCE_QUENCH
:
1322 interested
= B_TRUE
; /* Pass up to transport */
1323 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInSrcQuenchs
);
1326 if (!ipst
->ips_ip_ignore_redirect
)
1327 interested
= B_TRUE
;
1328 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInRedirects
);
1330 case ICMP_ECHO_REQUEST
:
1332 * Whether to respond to echo requests that come in as IP
1333 * broadcasts or as IP multicast is subject to debate
1334 * (what isn't?). We aim to please, you pick it.
1337 if (ira
->ira_flags
& IRAF_MULTICAST
) {
1338 /* multicast: respond based on tunable */
1339 interested
= ipst
->ips_ip_g_resp_to_echo_mcast
;
1340 } else if (ira
->ira_flags
& IRAF_BROADCAST
) {
1341 /* broadcast: respond based on tunable */
1342 interested
= ipst
->ips_ip_g_resp_to_echo_bcast
;
1344 /* unicast: always respond */
1345 interested
= B_TRUE
;
1347 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInEchos
);
1349 /* We never pass these to RAW sockets */
1354 /* Check db_ref to make sure we can modify the packet. */
1355 if (mp
->b_datap
->db_ref
> 1) {
1361 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
1365 ipha
= (ipha_t
*)mp
->b_rptr
;
1366 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1368 icmph
->icmph_type
= ICMP_ECHO_REPLY
;
1369 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutEchoReps
);
1370 icmp_send_reply_v4(mp
, ipha
, icmph
, ira
);
1373 case ICMP_ROUTER_ADVERTISEMENT
:
1374 case ICMP_ROUTER_SOLICITATION
:
1376 case ICMP_TIME_EXCEEDED
:
1377 interested
= B_TRUE
; /* Pass up to transport */
1378 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInTimeExcds
);
1380 case ICMP_PARAM_PROBLEM
:
1381 interested
= B_TRUE
; /* Pass up to transport */
1382 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInParmProbs
);
1384 case ICMP_TIME_STAMP_REQUEST
:
1385 /* Response to Time Stamp Requests is local policy. */
1386 if (ipst
->ips_ip_g_resp_to_timestamp
) {
1387 if (ira
->ira_flags
& IRAF_MULTIBROADCAST
)
1389 ipst
->ips_ip_g_resp_to_timestamp_bcast
;
1391 interested
= B_TRUE
;
1394 /* We never pass these to RAW sockets */
1399 /* Make sure we have enough of the packet */
1400 len_needed
= ip_hdr_length
+ ICMPH_SIZE
+
1401 3 * sizeof (uint32_t);
1403 if (mp
->b_wptr
- mp
->b_rptr
< len_needed
) {
1404 ipha
= ip_pullup(mp
, len_needed
, ira
);
1406 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1407 ip_drop_input("ipIfStatsInDiscards - ip_pullup",
1412 /* Refresh following the pullup. */
1413 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1415 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInTimestamps
);
1416 /* Check db_ref to make sure we can modify the packet. */
1417 if (mp
->b_datap
->db_ref
> 1) {
1423 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
1427 ipha
= (ipha_t
*)mp
->b_rptr
;
1428 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1430 icmph
->icmph_type
= ICMP_TIME_STAMP_REPLY
;
1431 tsp
= (uint32_t *)&icmph
[1];
1432 tsp
++; /* Skip past 'originate time' */
1433 /* Compute # of milliseconds since midnight */
1435 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
1436 NSEC2MSEC(now
.tv_nsec
);
1437 *tsp
++ = htonl(ts
); /* Lay in 'receive time' */
1438 *tsp
++ = htonl(ts
); /* Lay in 'send time' */
1439 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutTimestampReps
);
1440 icmp_send_reply_v4(mp
, ipha
, icmph
, ira
);
1443 case ICMP_TIME_STAMP_REPLY
:
1444 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInTimestampReps
);
1446 case ICMP_INFO_REQUEST
:
1447 /* Per RFC 1122 3.2.2.7, ignore this. */
1448 case ICMP_INFO_REPLY
:
1450 case ICMP_ADDRESS_MASK_REQUEST
:
1451 if (ira
->ira_flags
& IRAF_MULTIBROADCAST
) {
1453 ipst
->ips_ip_respond_to_address_mask_broadcast
;
1455 interested
= B_TRUE
;
1458 /* We never pass these to RAW sockets */
1462 len_needed
= ip_hdr_length
+ ICMPH_SIZE
+ IP_ADDR_LEN
;
1463 if (mp
->b_wptr
- mp
->b_rptr
< len_needed
) {
1464 ipha
= ip_pullup(mp
, len_needed
, ira
);
1466 BUMP_MIB(ill
->ill_ip_mib
,
1467 ipIfStatsInTruncatedPkts
);
1468 ip_drop_input("ipIfStatsInTruncatedPkts", mp
,
1473 /* Refresh following the pullup. */
1474 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1476 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInAddrMasks
);
1477 /* Check db_ref to make sure we can modify the packet. */
1478 if (mp
->b_datap
->db_ref
> 1) {
1484 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
1488 ipha
= (ipha_t
*)mp
->b_rptr
;
1489 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1492 * Need the ipif with the mask be the same as the source
1493 * address of the mask reply. For unicast we have a specific
1494 * ipif. For multicast/broadcast we only handle onlink
1495 * senders, and use the source address to pick an ipif.
1497 ipif
= ipif_lookup_addr(ipha
->ipha_dst
, ill
, zoneid
, ipst
);
1499 /* Broadcast or multicast */
1500 ipif
= ipif_lookup_remote(ill
, ipha
->ipha_src
, zoneid
);
1506 icmph
->icmph_type
= ICMP_ADDRESS_MASK_REPLY
;
1507 bcopy(&ipif
->ipif_net_mask
, &icmph
[1], IP_ADDR_LEN
);
1509 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutAddrMaskReps
);
1510 icmp_send_reply_v4(mp
, ipha
, icmph
, ira
);
1513 case ICMP_ADDRESS_MASK_REPLY
:
1514 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInAddrMaskReps
);
1517 interested
= B_TRUE
; /* Pass up to transport */
1518 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInUnknowns
);
1522 * See if there is an ICMP client to avoid an extra copymsg/freemsg
1523 * if there isn't one.
1525 if (ipst
->ips_ipcl_proto_fanout_v4
[IPPROTO_ICMP
].connf_head
!= NULL
) {
1526 /* If there is an ICMP client and we want one too, copy it. */
1529 /* Caller will deliver to RAW sockets */
1532 mp_ret
= copymsg(mp
);
1533 if (mp_ret
== NULL
) {
1534 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1535 ip_drop_input("ipIfStatsInDiscards - copymsg", mp
, ill
);
1537 } else if (!interested
) {
1538 /* Neither we nor raw sockets are interested. Drop packet now */
1544 * ICMP error or redirect packet. Make sure we have enough of
1545 * the header and that db_ref == 1 since we might end up modifying
1548 if (mp
->b_cont
!= NULL
) {
1549 if (ip_pullup(mp
, -1, ira
) == NULL
) {
1550 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1551 ip_drop_input("ipIfStatsInDiscards - ip_pullup",
1558 if (mp
->b_datap
->db_ref
> 1) {
1563 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1564 ip_drop_input("ipIfStatsInDiscards - copymsg", mp
, ill
);
1573 * In case mp has changed, verify the message before any further
1576 ipha
= (ipha_t
*)mp
->b_rptr
;
1577 icmph
= (icmph_t
*)&mp
->b_rptr
[ip_hdr_length
];
1578 if (!icmp_inbound_verify_v4(mp
, icmph
, ira
)) {
1583 switch (icmph
->icmph_type
) {
1585 icmp_redirect_v4(mp
, ipha
, icmph
, ira
);
1587 case ICMP_DEST_UNREACHABLE
:
1588 if (icmph
->icmph_code
== ICMP_FRAGMENTATION_NEEDED
) {
1589 /* Update DCE and adjust MTU is icmp header if needed */
1590 icmp_inbound_too_big_v4(icmph
, ira
);
1594 icmp_inbound_error_fanout_v4(mp
, icmph
, ira
);
1601 * Send an ICMP echo, timestamp or address mask reply.
1602 * The caller has already updated the payload part of the packet.
1603 * We handle the ICMP checksum, IP source address selection and feed
1604 * the packet into ip_output_simple.
1607 icmp_send_reply_v4(mblk_t
*mp
, ipha_t
*ipha
, icmph_t
*icmph
,
1608 ip_recv_attr_t
*ira
)
1610 uint_t ip_hdr_length
= ira
->ira_ip_hdr_length
;
1611 ill_t
*ill
= ira
->ira_ill
;
1612 ip_stack_t
*ipst
= ill
->ill_ipst
;
1613 ip_xmit_attr_t ixas
;
1615 /* Send out an ICMP packet */
1616 icmph
->icmph_checksum
= 0;
1617 icmph
->icmph_checksum
= IP_CSUM(mp
, ip_hdr_length
, 0);
1618 /* Reset time to live. */
1619 ipha
->ipha_ttl
= ipst
->ips_ip_def_ttl
;
1621 /* Swap source and destination addresses */
1624 tmp
= ipha
->ipha_src
;
1625 ipha
->ipha_src
= ipha
->ipha_dst
;
1626 ipha
->ipha_dst
= tmp
;
1628 ipha
->ipha_ident
= 0;
1629 if (!IS_SIMPLE_IPH(ipha
))
1630 icmp_options_update(ipha
);
1632 bzero(&ixas
, sizeof (ixas
));
1633 ixas
.ixa_flags
= IXAF_BASIC_SIMPLE_V4
;
1634 ixas
.ixa_zoneid
= ira
->ira_zoneid
;
1635 ixas
.ixa_cred
= kcred
;
1636 ixas
.ixa_cpid
= NOPID
;
1637 ixas
.ixa_ifindex
= 0;
1638 ixas
.ixa_ipst
= ipst
;
1639 ixas
.ixa_multicast_ttl
= IP_DEFAULT_MULTICAST_TTL
;
1641 if (!(ira
->ira_flags
& IRAF_IPSEC_SECURE
)) {
1643 * This packet should go out the same way as it
1644 * came in i.e in clear, independent of the IPsec policy
1645 * for transmitting packets.
1647 ixas
.ixa_flags
|= IXAF_NO_IPSEC
;
1649 if (!ipsec_in_to_out(ira
, &ixas
, mp
, ipha
, NULL
)) {
1650 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1651 /* Note: mp already consumed and ip_drop_packet done */
1655 if (ira
->ira_flags
& IRAF_MULTIBROADCAST
) {
1657 * Not one or our addresses (IRE_LOCALs), thus we let
1658 * ip_output_simple pick the source.
1660 ipha
->ipha_src
= INADDR_ANY
;
1661 ixas
.ixa_flags
|= IXAF_SET_SOURCE
;
1663 /* Should we send with DF and use dce_pmtu? */
1664 if (ipst
->ips_ipv4_icmp_return_pmtu
) {
1665 ixas
.ixa_flags
|= IXAF_PMTU_DISCOVERY
;
1666 ipha
->ipha_fragment_offset_and_flags
|= IPH_DF_HTONS
;
1669 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutMsgs
);
1671 (void) ip_output_simple(mp
, &ixas
);
1676 * Verify the ICMP messages for either for ICMP error or redirect packet.
1677 * The caller should have fully pulled up the message. If it's a redirect
1678 * packet, only basic checks on IP header will be done; otherwise, verify
1679 * the packet by looking at the included ULP header.
1681 * Called before icmp_inbound_error_fanout_v4 is called.
1684 icmp_inbound_verify_v4(mblk_t
*mp
, icmph_t
*icmph
, ip_recv_attr_t
*ira
)
1686 ill_t
*ill
= ira
->ira_ill
;
1688 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
1690 ipha_t
*ipha
; /* Inner IP header */
1692 ipha
= (ipha_t
*)&icmph
[1];
1693 if ((uchar_t
*)ipha
+ IP_SIMPLE_HDR_LENGTH
> mp
->b_wptr
)
1696 hdr_length
= IPH_HDR_LENGTH(ipha
);
1698 if ((IPH_HDR_VERSION(ipha
) != IPV4_VERSION
))
1701 if (hdr_length
< sizeof (ipha_t
))
1704 if ((uchar_t
*)ipha
+ hdr_length
> mp
->b_wptr
)
1708 * Stop here for ICMP_REDIRECT.
1710 if (icmph
->icmph_type
== ICMP_REDIRECT
)
1716 switch (ipha
->ipha_protocol
) {
1719 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
1722 if ((uchar_t
*)ipha
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
1730 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
1733 if ((uchar_t
*)ipha
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
1737 tcpha
= (tcpha_t
*)((uchar_t
*)ipha
+ hdr_length
);
1738 connp
= ipcl_tcp_lookup_reversed_ipv4(ipha
, tcpha
, TCPS_LISTEN
,
1743 if ((connp
->conn_verifyicmp
!= NULL
) &&
1744 !connp
->conn_verifyicmp(connp
, tcpha
, icmph
, NULL
, ira
)) {
1745 CONN_DEC_REF(connp
);
1748 CONN_DEC_REF(connp
);
1753 * Verify we have at least ICMP_MIN_TP_HDR_LEN bytes of
1756 if ((uchar_t
*)ipha
+ hdr_length
+ ICMP_MIN_TP_HDR_LEN
>
1764 if ((uchar_t
*)ipha
+ hdr_length
+ sizeof (ipha_t
) >
1775 /* Bogus ICMP error. */
1776 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
1780 /* We pulled up everthing already. Must be truncated */
1781 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
1782 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
1786 /* Table from RFC 1191 */
1787 static int icmp_frag_size_table
[] =
1788 { 32000, 17914, 8166, 4352, 2002, 1496, 1006, 508, 296, 68 };
1791 * Process received ICMP Packet too big.
1792 * Just handles the DCE create/update, including using the above table of
1793 * PMTU guesses. The caller is responsible for validating the packet before
1794 * passing it in and also to fanout the ICMP error to any matching transport
1795 * conns. Assumes the message has been fully pulled up and verified.
1797 * Before getting here, the caller has called icmp_inbound_verify_v4()
1798 * that should have verified with ULP to prevent undoing the changes we're
1799 * going to make to DCE. For example, TCP might have verified that the packet
1800 * which generated error is in the send window.
1802 * In some cases modified this MTU in the ICMP header packet; the caller
1803 * should pass to the matching ULP after this returns.
1806 icmp_inbound_too_big_v4(icmph_t
*icmph
, ip_recv_attr_t
*ira
)
1812 boolean_t disable_pmtud
;
1813 ill_t
*ill
= ira
->ira_ill
;
1814 ip_stack_t
*ipst
= ill
->ill_ipst
;
1818 /* Caller already pulled up everything. */
1819 ipha
= (ipha_t
*)&icmph
[1];
1820 ASSERT(icmph
->icmph_type
== ICMP_DEST_UNREACHABLE
&&
1821 icmph
->icmph_code
== ICMP_FRAGMENTATION_NEEDED
);
1822 ASSERT(ill
!= NULL
);
1824 hdr_length
= IPH_HDR_LENGTH(ipha
);
1827 * We handle path MTU for source routed packets since the DCE
1828 * is looked up using the final destination.
1830 dst
= ip_get_dst(ipha
);
1832 dce
= dce_lookup_and_add_v4(dst
, ipst
);
1834 /* Couldn't add a unique one - ENOMEM */
1835 ip1dbg(("icmp_inbound_too_big_v4: no dce for 0x%x\n",
1840 /* Check for MTU discovery advice as described in RFC 1191 */
1841 mtu
= ntohs(icmph
->icmph_du_mtu
);
1843 disable_pmtud
= B_FALSE
;
1845 mutex_enter(&dce
->dce_lock
);
1846 if (dce
->dce_flags
& DCEF_PMTU
)
1847 old_mtu
= dce
->dce_pmtu
;
1849 old_mtu
= ill
->ill_mtu
;
1851 if (icmph
->icmph_du_zero
!= 0 || mtu
< ipst
->ips_ip_pmtu_min
) {
1856 * Use the table from RFC 1191 to figure out
1857 * the next "plateau" based on the length in
1858 * the original IP packet.
1860 length
= ntohs(ipha
->ipha_length
);
1861 DTRACE_PROBE2(ip4__pmtu__guess
, dce_t
*, dce
,
1863 if (old_mtu
<= length
&&
1864 old_mtu
>= length
- hdr_length
) {
1866 * Handle broken BSD 4.2 systems that
1867 * return the wrong ipha_length in ICMP
1870 ip1dbg(("Wrong mtu: sent %d, dce %d\n",
1872 length
-= hdr_length
;
1874 for (i
= 0; i
< A_CNT(icmp_frag_size_table
); i
++) {
1875 if (length
> icmp_frag_size_table
[i
])
1878 if (i
== A_CNT(icmp_frag_size_table
)) {
1879 /* Smaller than IP_MIN_MTU! */
1880 ip1dbg(("Too big for packet size %d\n",
1882 disable_pmtud
= B_TRUE
;
1883 mtu
= ipst
->ips_ip_pmtu_min
;
1885 mtu
= icmp_frag_size_table
[i
];
1886 ip1dbg(("Calculated mtu %d, packet size %d, "
1887 "before %d\n", mtu
, length
, old_mtu
));
1888 if (mtu
< ipst
->ips_ip_pmtu_min
) {
1889 mtu
= ipst
->ips_ip_pmtu_min
;
1890 disable_pmtud
= B_TRUE
;
1895 dce
->dce_flags
|= DCEF_TOO_SMALL_PMTU
;
1897 dce
->dce_flags
&= ~DCEF_TOO_SMALL_PMTU
;
1899 dce
->dce_pmtu
= MIN(old_mtu
, mtu
);
1900 /* Prepare to send the new max frag size for the ULP. */
1901 icmph
->icmph_du_zero
= 0;
1902 icmph
->icmph_du_mtu
= htons((uint16_t)dce
->dce_pmtu
);
1903 DTRACE_PROBE4(ip4__pmtu__change
, icmph_t
*, icmph
, dce_t
*,
1904 dce
, int, orig_mtu
, int, mtu
);
1906 /* We now have a PMTU for sure */
1907 dce
->dce_flags
|= DCEF_PMTU
;
1908 dce
->dce_last_change_time
= TICK_TO_SEC(ddi_get_lbolt64());
1909 mutex_exit(&dce
->dce_lock
);
1911 * After dropping the lock the new value is visible to everyone.
1912 * Then we bump the generation number so any cached values reinspect
1915 dce_increment_generation(dce
);
1920 * If the packet in error is Self-Encapsulated, icmp_inbound_error_fanout_v4
1921 * calls this function.
1924 icmp_inbound_self_encap_error_v4(mblk_t
*mp
, ipha_t
*ipha
, ipha_t
*in_ipha
)
1928 ASSERT(mp
->b_datap
->db_type
== M_DATA
);
1930 /* icmp_inbound_v4 has already pulled up the whole error packet */
1931 ASSERT(mp
->b_cont
== NULL
);
1934 * The length that we want to overlay is the inner header
1935 * and what follows it.
1937 length
= msgdsize(mp
) - ((uchar_t
*)in_ipha
- mp
->b_rptr
);
1940 * Overlay the inner header and whatever follows it over the
1943 bcopy((uchar_t
*)in_ipha
, (uchar_t
*)ipha
, length
);
1945 /* Adjust for what we removed */
1946 mp
->b_wptr
-= (uchar_t
*)in_ipha
- (uchar_t
*)ipha
;
1951 * Try to pass the ICMP message upstream in case the ULP cares.
1953 * If the packet that caused the ICMP error is secure, we send
1954 * it to AH/ESP to make sure that the attached packet has a
1955 * valid association. ipha in the code below points to the
1956 * IP header of the packet that caused the error.
1958 * For IPsec cases, we let the next-layer-up (which has access to
1959 * cached policy on the conn_t, or can query the SPD directly)
1960 * subtract out any IPsec overhead if they must. We therefore make no
1961 * adjustments here for IPsec overhead.
1963 * IFN could have been generated locally or by some router.
1965 * LOCAL : ire_send_wire (before calling ipsec_out_process) can call
1966 * icmp_frag_needed/icmp_pkt2big_v6 to generated a local IFN.
1967 * This happens because IP adjusted its value of MTU on an
1968 * earlier IFN message and could not tell the upper layer,
1969 * the new adjusted value of MTU e.g. Packet was encrypted
1970 * or there was not enough information to fanout to upper
1971 * layers. Thus on the next outbound datagram, ire_send_wire
1972 * generates the IFN, where IPsec processing has *not* been
1975 * Note that we retain ixa_fragsize across IPsec thus once
1976 * we have picking ixa_fragsize and entered ipsec_out_process we do
1977 * no change the fragsize even if the path MTU changes before
1978 * we reach ip_output_post_ipsec.
1980 * In the local case, IRAF_LOOPBACK will be set indicating
1981 * that IFN was generated locally.
1983 * ROUTER : IFN could be secure or non-secure.
1985 * * SECURE : We use the IPSEC_IN to fanout to AH/ESP if the
1986 * packet in error has AH/ESP headers to validate the AH/ESP
1987 * headers. AH/ESP will verify whether there is a valid SA or
1988 * not and send it back. We will fanout again if we have more
1989 * data in the packet.
1991 * If the packet in error does not have AH/ESP, we handle it
1992 * like any other case.
1994 * * NON_SECURE : If the packet in error has AH/ESP headers, we send it
1995 * up to AH/ESP for validation. AH/ESP will verify whether there is a
1996 * valid SA or not and send it back. We will fanout again if
1997 * we have more data in the packet.
1999 * If the packet in error does not have AH/ESP, we handle it
2000 * like any other case.
2002 * The caller must have called icmp_inbound_verify_v4.
2005 icmp_inbound_error_fanout_v4(mblk_t
*mp
, icmph_t
*icmph
, ip_recv_attr_t
*ira
)
2007 uint16_t *up
; /* Pointer to ports in ULP header */
2008 uint32_t ports
; /* reversed ports for fanout */
2009 ipha_t ripha
; /* With reversed addresses */
2010 ipha_t
*ipha
; /* Inner IP header */
2011 uint_t hdr_length
; /* Inner IP header length */
2014 ill_t
*ill
= ira
->ira_ill
;
2015 ip_stack_t
*ipst
= ill
->ill_ipst
;
2016 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
2017 ill_t
*rill
= ira
->ira_rill
;
2019 /* Caller already pulled up everything. */
2020 ipha
= (ipha_t
*)&icmph
[1];
2021 ASSERT((uchar_t
*)&ipha
[1] <= mp
->b_wptr
);
2022 ASSERT(mp
->b_cont
== NULL
);
2024 hdr_length
= IPH_HDR_LENGTH(ipha
);
2025 ira
->ira_protocol
= ipha
->ipha_protocol
;
2028 * We need a separate IP header with the source and destination
2029 * addresses reversed to do fanout/classification because the ipha in
2030 * the ICMP error is in the form we sent it out.
2032 ripha
.ipha_src
= ipha
->ipha_dst
;
2033 ripha
.ipha_dst
= ipha
->ipha_src
;
2034 ripha
.ipha_protocol
= ipha
->ipha_protocol
;
2035 ripha
.ipha_version_and_hdr_length
= ipha
->ipha_version_and_hdr_length
;
2037 ip2dbg(("icmp_inbound_error_v4: proto %d %x to %x: %d/%d\n",
2038 ripha
.ipha_protocol
, ntohl(ipha
->ipha_src
),
2039 ntohl(ipha
->ipha_dst
),
2040 icmph
->icmph_type
, icmph
->icmph_code
));
2042 switch (ipha
->ipha_protocol
) {
2044 up
= (uint16_t *)((uchar_t
*)ipha
+ hdr_length
);
2046 /* Attempt to find a client stream based on port. */
2047 ip2dbg(("icmp_inbound_error_v4: UDP ports %d to %d\n",
2048 ntohs(up
[0]), ntohs(up
[1])));
2050 /* Note that we send error to all matches. */
2051 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2052 ip_fanout_udp_multi_v4(mp
, &ripha
, up
[0], up
[1], ira
);
2053 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2058 * Find a TCP client stream for this packet.
2059 * Note that we do a reverse lookup since the header is
2060 * in the form we sent it out.
2062 tcpha
= (tcpha_t
*)((uchar_t
*)ipha
+ hdr_length
);
2063 connp
= ipcl_tcp_lookup_reversed_ipv4(ipha
, tcpha
, TCPS_LISTEN
,
2068 if (CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) ||
2069 (ira
->ira_flags
& IRAF_IPSEC_SECURE
)) {
2070 mp
= ipsec_check_inbound_policy(mp
, connp
,
2073 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
2074 /* Note that mp is NULL */
2075 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
2076 CONN_DEC_REF(connp
);
2081 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2082 ira
->ira_ill
= ira
->ira_rill
= NULL
;
2083 if (IPCL_IS_TCP(connp
)) {
2084 SQUEUE_ENTER_ONE(connp
->conn_sqp
, mp
,
2085 connp
->conn_recvicmp
, connp
, ira
, SQ_FILL
,
2086 SQTAG_TCP_INPUT_ICMP_ERR
);
2088 /* Not TCP; must be SOCK_RAW, IPPROTO_TCP */
2089 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
2090 CONN_DEC_REF(connp
);
2093 ira
->ira_rill
= rill
;
2094 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2098 up
= (uint16_t *)((uchar_t
*)ipha
+ hdr_length
);
2099 /* Find a SCTP client stream for this packet. */
2100 ((uint16_t *)&ports
)[0] = up
[1];
2101 ((uint16_t *)&ports
)[1] = up
[0];
2103 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2104 ip_fanout_sctp(mp
, &ripha
, NULL
, ports
, ira
);
2105 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2110 if (!ipsec_loaded(ipss
)) {
2111 ip_proto_not_sup(mp
, ira
);
2115 if (ipha
->ipha_protocol
== IPPROTO_ESP
)
2116 mp
= ipsecesp_icmp_error(mp
, ira
);
2118 mp
= ipsecah_icmp_error(mp
, ira
);
2122 /* Just in case ipsec didn't preserve the NULL b_cont */
2123 if (mp
->b_cont
!= NULL
) {
2124 if (!pullupmsg(mp
, -1))
2129 * Note that ira_pktlen and ira_ip_hdr_length are no longer
2130 * correct, but we don't use them any more here.
2132 * If succesful, the mp has been modified to not include
2133 * the ESP/AH header so we can fanout to the ULP's icmp
2136 if (mp
->b_wptr
- mp
->b_rptr
< IP_SIMPLE_HDR_LENGTH
)
2139 /* Verify the modified message before any further processes. */
2140 ipha
= (ipha_t
*)mp
->b_rptr
;
2141 hdr_length
= IPH_HDR_LENGTH(ipha
);
2142 icmph
= (icmph_t
*)&mp
->b_rptr
[hdr_length
];
2143 if (!icmp_inbound_verify_v4(mp
, icmph
, ira
)) {
2148 icmp_inbound_error_fanout_v4(mp
, icmph
, ira
);
2151 case IPPROTO_ENCAP
: {
2152 /* Look for self-encapsulated packets that caused an error */
2156 * Caller has verified that length has to be
2157 * at least the size of IP header.
2159 ASSERT(hdr_length
>= sizeof (ipha_t
));
2161 * Check the sanity of the inner IP header like
2162 * we did for the outer header.
2164 in_ipha
= (ipha_t
*)((uchar_t
*)ipha
+ hdr_length
);
2165 if ((IPH_HDR_VERSION(in_ipha
) != IPV4_VERSION
)) {
2168 if (IPH_HDR_LENGTH(in_ipha
) < sizeof (ipha_t
)) {
2171 /* Check for Self-encapsulated tunnels */
2172 if (in_ipha
->ipha_src
== ipha
->ipha_src
&&
2173 in_ipha
->ipha_dst
== ipha
->ipha_dst
) {
2175 mp
= icmp_inbound_self_encap_error_v4(mp
, ipha
,
2181 * Just in case self_encap didn't preserve the NULL
2184 if (mp
->b_cont
!= NULL
) {
2185 if (!pullupmsg(mp
, -1))
2189 * Note that ira_pktlen and ira_ip_hdr_length are no
2190 * longer correct, but we don't use them any more here.
2192 if (mp
->b_wptr
- mp
->b_rptr
< IP_SIMPLE_HDR_LENGTH
)
2196 * Verify the modified message before any further
2199 ipha
= (ipha_t
*)mp
->b_rptr
;
2200 hdr_length
= IPH_HDR_LENGTH(ipha
);
2201 icmph
= (icmph_t
*)&mp
->b_rptr
[hdr_length
];
2202 if (!icmp_inbound_verify_v4(mp
, icmph
, ira
)) {
2208 * The packet in error is self-encapsualted.
2209 * And we are finding it further encapsulated
2210 * which we could not have possibly generated.
2212 if (ipha
->ipha_protocol
== IPPROTO_ENCAP
) {
2215 icmp_inbound_error_fanout_v4(mp
, icmph
, ira
);
2218 /* No self-encapsulated */
2222 if ((connp
= ipcl_iptun_classify_v4(&ripha
.ipha_src
,
2223 &ripha
.ipha_dst
, ipst
)) != NULL
) {
2224 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2225 connp
->conn_recvicmp(connp
, mp
, NULL
, ira
);
2226 CONN_DEC_REF(connp
);
2227 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2231 * No IP tunnel is interested, fallthrough and see
2232 * if a raw socket will want it.
2236 ira
->ira_flags
|= IRAF_ICMP_ERROR
;
2237 ip_fanout_proto_v4(mp
, &ripha
, ira
);
2238 ira
->ira_flags
&= ~IRAF_ICMP_ERROR
;
2243 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
2244 ip1dbg(("icmp_inbound_error_fanout_v4: drop pkt\n"));
2245 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
2250 /* We pulled up everthing already. Must be truncated */
2251 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
2252 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
2257 * Common IP options parser.
2259 * Setup routine: fill in *optp with options-parsing state, then
2260 * tail-call ipoptp_next to return the first option.
2263 ipoptp_first(ipoptp_t
*optp
, ipha_t
*ipha
)
2265 uint32_t totallen
; /* total length of all options */
2267 totallen
= ipha
->ipha_version_and_hdr_length
-
2268 (uint8_t)((IP_VERSION
<< 4) + IP_SIMPLE_HDR_LENGTH_IN_WORDS
);
2270 optp
->ipoptp_next
= (uint8_t *)(&ipha
[1]);
2271 optp
->ipoptp_end
= optp
->ipoptp_next
+ totallen
;
2272 optp
->ipoptp_flags
= 0;
2273 return (ipoptp_next(optp
));
2276 /* Like above but without an ipha_t */
2278 ipoptp_first2(ipoptp_t
*optp
, uint32_t totallen
, uint8_t *opt
)
2280 optp
->ipoptp_next
= opt
;
2281 optp
->ipoptp_end
= optp
->ipoptp_next
+ totallen
;
2282 optp
->ipoptp_flags
= 0;
2283 return (ipoptp_next(optp
));
2287 * Common IP options parser: extract next option.
2290 ipoptp_next(ipoptp_t
*optp
)
2292 uint8_t *end
= optp
->ipoptp_end
;
2293 uint8_t *cur
= optp
->ipoptp_next
;
2294 uint8_t opt
, len
, pointer
;
2297 * If cur > end already, then the ipoptp_end or ipoptp_next pointer
2298 * has been corrupted.
2305 opt
= cur
[IPOPT_OPTVAL
];
2308 * Skip any NOP options.
2310 while (opt
== IPOPT_NOP
) {
2314 opt
= cur
[IPOPT_OPTVAL
];
2317 if (opt
== IPOPT_EOL
)
2321 * Option requiring a length.
2323 if ((cur
+ 1) >= end
) {
2324 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2327 len
= cur
[IPOPT_OLEN
];
2329 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2332 optp
->ipoptp_cur
= cur
;
2333 optp
->ipoptp_len
= len
;
2334 optp
->ipoptp_next
= cur
+ len
;
2335 if (cur
+ len
> end
) {
2336 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2341 * For the options which require a pointer field, make sure
2342 * its there, and make sure it points to either something
2343 * inside this option, or the end of the option.
2350 if (len
<= IPOPT_OFFSET
) {
2351 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2354 pointer
= cur
[IPOPT_OFFSET
];
2355 if (pointer
- 1 > len
) {
2356 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2363 * Sanity check the pointer field based on the type of the
2370 if (pointer
< IPOPT_MINOFF_SR
)
2371 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2374 if (pointer
< IPOPT_MINOFF_IT
)
2375 optp
->ipoptp_flags
|= IPOPTP_ERROR
;
2377 * Note that the Internet Timestamp option also
2378 * contains two four bit fields (the Overflow field,
2379 * and the Flag field), which follow the pointer
2380 * field. We don't need to check that these fields
2381 * fall within the length of the option because this
2382 * was implicitely done above. We've checked that the
2383 * pointer value is at least IPOPT_MINOFF_IT, and that
2384 * it falls within the option. Since IPOPT_MINOFF_IT >
2385 * IPOPT_POS_OV_FLG, we don't need the explicit check.
2387 ASSERT(len
> IPOPT_POS_OV_FLG
);
2395 * Use the outgoing IP header to create an IP_OPTIONS option the way
2396 * it was passed down from the application.
2398 * This is compatible with BSD in that it returns
2399 * the reverse source route with the final destination
2400 * as the last entry. The first 4 bytes of the option
2401 * will contain the final destination.
2404 ip_opt_get_user(conn_t
*connp
, uchar_t
*buf
)
2411 uchar_t
*buf1
= buf
;
2414 ip_pkt_t
*ipp
= &connp
->conn_xmit_ipp
;
2416 if (!(ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
))
2419 totallen
= ipp
->ipp_ipv4_options_len
;
2423 buf
+= IP_ADDR_LEN
; /* Leave room for final destination */
2425 bzero(buf1
, IP_ADDR_LEN
);
2427 dst
= connp
->conn_faddr_v4
;
2429 for (optval
= ipoptp_first2(&opts
, totallen
, ipp
->ipp_ipv4_options
);
2430 optval
!= IPOPT_EOL
;
2431 optval
= ipoptp_next(&opts
)) {
2434 opt
= opts
.ipoptp_cur
;
2435 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
2438 optlen
= opts
.ipoptp_len
;
2445 * Insert destination as the first entry in the source
2446 * route and move down the entries on step.
2447 * The last entry gets placed at buf1.
2449 buf
[IPOPT_OPTVAL
] = optval
;
2450 buf
[IPOPT_OLEN
] = optlen
;
2451 buf
[IPOPT_OFFSET
] = optlen
;
2453 off
= optlen
- IP_ADDR_LEN
;
2455 /* No entries in source route */
2458 /* Last entry in source route if not already set */
2459 if (dst
== INADDR_ANY
)
2460 bcopy(opt
+ off
, buf1
, IP_ADDR_LEN
);
2465 buf
+ off
+ IP_ADDR_LEN
,
2469 /* ipha_dst into first slot */
2470 bcopy(&dst
, buf
+ off
+ IP_ADDR_LEN
,
2477 bcopy(opt
, buf
, optlen
);
2484 /* Pad the resulting options */
2493 * Update any record route or timestamp options to include this host.
2494 * Reverse any source route option.
2495 * This routine assumes that the options are well formed i.e. that they
2496 * have already been checked.
2499 icmp_options_update(ipha_t
*ipha
)
2504 ipaddr_t src
; /* Our local address */
2507 ip2dbg(("icmp_options_update\n"));
2508 src
= ipha
->ipha_src
;
2509 dst
= ipha
->ipha_dst
;
2511 for (optval
= ipoptp_first(&opts
, ipha
);
2512 optval
!= IPOPT_EOL
;
2513 optval
= ipoptp_next(&opts
)) {
2514 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
2515 opt
= opts
.ipoptp_cur
;
2516 ip2dbg(("icmp_options_update: opt %d, len %d\n",
2517 optval
, opts
.ipoptp_len
));
2523 * Reverse the source route. The first entry
2524 * should be the next to last one in the current
2525 * source route (the last entry is our address).
2526 * The last entry should be the final destination.
2528 off1
= IPOPT_MINOFF_SR
- 1;
2529 off2
= opt
[IPOPT_OFFSET
] - IP_ADDR_LEN
- 1;
2531 /* No entries in source route */
2533 "icmp_options_update: bad src route\n"));
2536 bcopy((char *)opt
+ off2
, &dst
, IP_ADDR_LEN
);
2537 bcopy(&ipha
->ipha_dst
, (char *)opt
+ off2
, IP_ADDR_LEN
);
2538 bcopy(&dst
, &ipha
->ipha_dst
, IP_ADDR_LEN
);
2539 off2
-= IP_ADDR_LEN
;
2541 while (off1
< off2
) {
2542 bcopy((char *)opt
+ off1
, &src
, IP_ADDR_LEN
);
2543 bcopy((char *)opt
+ off2
, (char *)opt
+ off1
,
2545 bcopy(&src
, (char *)opt
+ off2
, IP_ADDR_LEN
);
2546 off1
+= IP_ADDR_LEN
;
2547 off2
-= IP_ADDR_LEN
;
2549 opt
[IPOPT_OFFSET
] = IPOPT_MINOFF_SR
;
2556 * Process received ICMP Redirect messages.
2557 * Assumes the caller has verified that the headers are in the pulled up mblk.
2561 icmp_redirect_v4(mblk_t
*mp
, ipha_t
*ipha
, icmph_t
*icmph
, ip_recv_attr_t
*ira
)
2565 ipaddr_t src
, dst
, gateway
;
2566 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2567 ipha_t
*inner_ipha
; /* Inner IP header */
2569 /* Caller already pulled up everything. */
2570 inner_ipha
= (ipha_t
*)&icmph
[1];
2571 src
= ipha
->ipha_src
;
2572 dst
= inner_ipha
->ipha_dst
;
2573 gateway
= icmph
->icmph_rd_gateway
;
2574 /* Make sure the new gateway is reachable somehow. */
2575 ire
= ire_ftable_lookup_v4(gateway
, 0, 0, IRE_ONLINK
, NULL
,
2576 ALL_ZONES
, MATCH_IRE_TYPE
, 0, ipst
, NULL
);
2578 * Make sure we had a route for the dest in question and that
2579 * that route was pointing to the old gateway (the source of the
2581 * We do longest match and then compare ire_gateway_addr below.
2583 prev_ire
= ire_ftable_lookup_v4(dst
, 0, 0, 0, NULL
, ALL_ZONES
,
2584 MATCH_IRE_DSTONLY
, 0, ipst
, NULL
);
2587 * the redirect was not from ourselves
2588 * the new gateway and the old gateway are directly reachable
2590 if (prev_ire
== NULL
|| ire
== NULL
||
2591 (prev_ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
)) ||
2592 (prev_ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
)) ||
2593 !(ire
->ire_type
& IRE_IF_ALL
) ||
2594 prev_ire
->ire_gateway_addr
!= src
) {
2595 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInBadRedirects
);
2596 ip_drop_input("icmpInBadRedirects - ire", mp
, ira
->ira_ill
);
2600 if (prev_ire
!= NULL
)
2601 ire_refrele(prev_ire
);
2605 ire_refrele(prev_ire
);
2609 * TODO: more precise handling for cases 0, 2, 3, the latter two
2610 * require TOS routing
2612 switch (icmph
->icmph_code
) {
2615 /* TODO: TOS specificity for cases 2 and 3 */
2620 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInBadRedirects
);
2621 ip_drop_input("icmpInBadRedirects - code", mp
, ira
->ira_ill
);
2626 * Create a Route Association. This will allow us to remember that
2627 * someone we believe told us to use the particular gateway.
2630 (uchar_t
*)&dst
, /* dest addr */
2631 (uchar_t
*)&ip_g_all_ones
, /* mask */
2632 (uchar_t
*)&gateway
, /* gateway addr */
2636 (RTF_DYNAMIC
| RTF_GATEWAY
| RTF_HOST
),
2643 nire
= ire_add(ire
);
2644 /* Check if it was a duplicate entry */
2645 if (nire
!= NULL
&& nire
!= ire
) {
2646 ASSERT(nire
->ire_identical_ref
> 1);
2653 ire_refrele(ire
); /* Held in ire_add */
2655 /* tell routing sockets that we received a redirect */
2656 ip_rts_change(RTM_REDIRECT
, dst
, gateway
, IP_HOST_MASK
, 0, src
,
2657 (RTF_DYNAMIC
| RTF_GATEWAY
| RTF_HOST
), 0,
2658 (RTA_DST
| RTA_GATEWAY
| RTA_NETMASK
| RTA_AUTHOR
), ipst
);
2662 * Delete any existing IRE_HOST type redirect ires for this destination.
2663 * This together with the added IRE has the effect of
2664 * modifying an existing redirect.
2666 prev_ire
= ire_ftable_lookup_v4(dst
, 0, src
, IRE_HOST
, NULL
,
2667 ALL_ZONES
, (MATCH_IRE_GW
| MATCH_IRE_TYPE
), 0, ipst
, NULL
);
2668 if (prev_ire
!= NULL
) {
2669 if (prev_ire
->ire_flags
& RTF_DYNAMIC
)
2670 ire_delete(prev_ire
);
2671 ire_refrele(prev_ire
);
2678 * Generate an ICMP parameter problem message.
2679 * When called from ip_output side a minimal ip_recv_attr_t needs to be
2680 * constructed by the caller.
2683 icmp_param_problem(mblk_t
*mp
, uint8_t ptr
, ip_recv_attr_t
*ira
)
2686 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2688 mp
= icmp_pkt_err_ok(mp
, ira
);
2692 bzero(&icmph
, sizeof (icmph_t
));
2693 icmph
.icmph_type
= ICMP_PARAM_PROBLEM
;
2694 icmph
.icmph_pp_ptr
= ptr
;
2695 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutParmProbs
);
2696 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
2700 * Build and ship an IPv4 ICMP message using the packet data in mp, and
2701 * the ICMP header pointed to by "stuff". (May be called as writer.)
2702 * Note: assumes that icmp_pkt_err_ok has been called to verify that
2703 * an icmp error packet can be sent.
2704 * Assigns an appropriate source address to the packet. If ipha_dst is
2705 * one of our addresses use it for source. Otherwise let ip_output_simple
2706 * pick the source address.
2709 icmp_pkt(mblk_t
*mp
, void *stuff
, size_t len
, ip_recv_attr_t
*ira
)
2719 ip_xmit_attr_t ixas
;
2720 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2722 ipha
= (ipha_t
*)mp
->b_rptr
;
2724 bzero(&ixas
, sizeof (ixas
));
2725 ixas
.ixa_flags
= IXAF_BASIC_SIMPLE_V4
;
2726 ixas
.ixa_zoneid
= ira
->ira_zoneid
;
2727 ixas
.ixa_ifindex
= 0;
2728 ixas
.ixa_ipst
= ipst
;
2729 ixas
.ixa_cred
= kcred
;
2730 ixas
.ixa_cpid
= NOPID
;
2731 ixas
.ixa_multicast_ttl
= IP_DEFAULT_MULTICAST_TTL
;
2733 if (ira
->ira_flags
& IRAF_IPSEC_SECURE
) {
2735 * Apply IPsec based on how IPsec was applied to
2736 * the packet that had the error.
2738 * If it was an outbound packet that caused the ICMP
2739 * error, then the caller will have setup the IRA
2742 if (!ipsec_in_to_out(ira
, &ixas
, mp
, ipha
, NULL
)) {
2743 BUMP_MIB(&ipst
->ips_ip_mib
, ipIfStatsOutDiscards
);
2744 /* Note: mp already consumed and ip_drop_packet done */
2749 * This is in clear. The icmp message we are building
2750 * here should go out in clear, independent of our policy.
2752 ixas
.ixa_flags
|= IXAF_NO_IPSEC
;
2755 /* Remember our eventual destination */
2756 dst
= ipha
->ipha_src
;
2759 * If the packet was for one of our unicast addresses, make
2760 * sure we respond with that as the source. Otherwise
2761 * have ip_output_simple pick the source address.
2763 ire
= ire_ftable_lookup_v4(ipha
->ipha_dst
, 0, 0,
2764 (IRE_LOCAL
|IRE_LOOPBACK
), NULL
, ira
->ira_zoneid
,
2765 MATCH_IRE_TYPE
|MATCH_IRE_ZONEONLY
, 0, ipst
, NULL
);
2768 src
= ipha
->ipha_dst
;
2771 ixas
.ixa_flags
|= IXAF_SET_SOURCE
;
2775 * Check if we can send back more then 8 bytes in addition to
2776 * the IP header. We try to send 64 bytes of data and the internal
2777 * header in the special cases of ipv4 encapsulated ipv4 or ipv6.
2779 len_needed
= IPH_HDR_LENGTH(ipha
);
2780 if (ipha
->ipha_protocol
== IPPROTO_ENCAP
||
2781 ipha
->ipha_protocol
== IPPROTO_IPV6
) {
2782 if (!pullupmsg(mp
, -1)) {
2783 BUMP_MIB(&ipst
->ips_ip_mib
, ipIfStatsOutDiscards
);
2784 ip_drop_output("ipIfStatsOutDiscards", mp
, NULL
);
2788 ipha
= (ipha_t
*)mp
->b_rptr
;
2790 if (ipha
->ipha_protocol
== IPPROTO_ENCAP
) {
2791 len_needed
+= IPH_HDR_LENGTH(((uchar_t
*)ipha
+
2794 ip6_t
*ip6h
= (ip6_t
*)((uchar_t
*)ipha
+ len_needed
);
2796 ASSERT(ipha
->ipha_protocol
== IPPROTO_IPV6
);
2797 len_needed
+= ip_hdr_length_v6(mp
, ip6h
);
2800 len_needed
+= ipst
->ips_ip_icmp_return
;
2801 msg_len
= msgdsize(mp
);
2802 if (msg_len
> len_needed
) {
2803 (void) adjmsg(mp
, len_needed
- msg_len
);
2804 msg_len
= len_needed
;
2806 mp1
= allocb(sizeof (icmp_ipha
) + len
, BPRI_MED
);
2808 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutErrors
);
2816 * Set IXAF_TRUSTED_ICMP so we can let the ICMP messages this
2817 * node generates be accepted in peace by all on-host destinations.
2818 * If we do NOT assume that all on-host destinations trust
2819 * self-generated ICMP messages, then rework here, ip6.c, and spd.c.
2820 * (Look for IXAF_TRUSTED_ICMP).
2822 ixas
.ixa_flags
|= IXAF_TRUSTED_ICMP
;
2824 ipha
= (ipha_t
*)mp
->b_rptr
;
2825 mp1
->b_wptr
= (uchar_t
*)ipha
+ (sizeof (icmp_ipha
) + len
);
2827 ipha
->ipha_src
= src
;
2828 ipha
->ipha_dst
= dst
;
2829 ipha
->ipha_ttl
= ipst
->ips_ip_def_ttl
;
2830 msg_len
+= sizeof (icmp_ipha
) + len
;
2831 if (msg_len
> IP_MAXPACKET
) {
2832 (void) adjmsg(mp
, IP_MAXPACKET
- msg_len
);
2833 msg_len
= IP_MAXPACKET
;
2835 ipha
->ipha_length
= htons((uint16_t)msg_len
);
2836 icmph
= (icmph_t
*)&ipha
[1];
2837 bcopy(stuff
, icmph
, len
);
2838 icmph
->icmph_checksum
= 0;
2839 icmph
->icmph_checksum
= IP_CSUM(mp
, (int32_t)sizeof (ipha_t
), 0);
2840 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutMsgs
);
2842 (void) ip_output_simple(mp
, &ixas
);
2847 * Determine if an ICMP error packet can be sent given the rate limit.
2848 * The limit consists of an average frequency (icmp_pkt_err_interval measured
2849 * in milliseconds) and a burst size. Burst size number of packets can
2850 * be sent arbitrarely closely spaced.
2851 * The state is tracked using two variables to implement an approximate
2852 * token bucket filter:
2853 * icmp_pkt_err_last - lbolt value when the last burst started
2854 * icmp_pkt_err_sent - number of packets sent in current burst
2857 icmp_err_rate_limit(ip_stack_t
*ipst
)
2859 clock_t now
= TICK_TO_MSEC(ddi_get_lbolt());
2860 uint_t refilled
; /* Number of packets refilled in tbf since last */
2861 /* Guard against changes by loading into local variable */
2862 uint_t err_interval
= ipst
->ips_ip_icmp_err_interval
;
2864 if (err_interval
== 0)
2867 if (ipst
->ips_icmp_pkt_err_last
> now
) {
2868 /* 100HZ lbolt in ms for 32bit arch wraps every 49.7 days */
2869 ipst
->ips_icmp_pkt_err_last
= 0;
2870 ipst
->ips_icmp_pkt_err_sent
= 0;
2873 * If we are in a burst update the token bucket filter.
2874 * Update the "last" time to be close to "now" but make sure
2875 * we don't loose precision.
2877 if (ipst
->ips_icmp_pkt_err_sent
!= 0) {
2878 refilled
= (now
- ipst
->ips_icmp_pkt_err_last
)/err_interval
;
2879 if (refilled
> ipst
->ips_icmp_pkt_err_sent
) {
2880 ipst
->ips_icmp_pkt_err_sent
= 0;
2882 ipst
->ips_icmp_pkt_err_sent
-= refilled
;
2883 ipst
->ips_icmp_pkt_err_last
+= refilled
* err_interval
;
2886 if (ipst
->ips_icmp_pkt_err_sent
== 0) {
2887 /* Start of new burst */
2888 ipst
->ips_icmp_pkt_err_last
= now
;
2890 if (ipst
->ips_icmp_pkt_err_sent
< ipst
->ips_ip_icmp_err_burst
) {
2891 ipst
->ips_icmp_pkt_err_sent
++;
2892 ip1dbg(("icmp_err_rate_limit: %d sent in burst\n",
2893 ipst
->ips_icmp_pkt_err_sent
));
2896 ip1dbg(("icmp_err_rate_limit: dropped\n"));
2901 * Check if it is ok to send an IPv4 ICMP error packet in
2902 * response to the IPv4 packet in mp.
2903 * Free the message and return null if no
2904 * ICMP error packet should be sent.
2907 icmp_pkt_err_ok(mblk_t
*mp
, ip_recv_attr_t
*ira
)
2909 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2916 ipha
= (ipha_t
*)mp
->b_rptr
;
2917 if (ip_csum_hdr(ipha
)) {
2918 BUMP_MIB(&ipst
->ips_ip_mib
, ipIfStatsInCksumErrs
);
2919 ip_drop_input("ipIfStatsInCksumErrs", mp
, NULL
);
2923 if (ip_type_v4(ipha
->ipha_dst
, ipst
) == IRE_BROADCAST
||
2924 ip_type_v4(ipha
->ipha_src
, ipst
) == IRE_BROADCAST
||
2925 CLASSD(ipha
->ipha_dst
) ||
2926 CLASSD(ipha
->ipha_src
) ||
2927 (ntohs(ipha
->ipha_fragment_offset_and_flags
) & IPH_OFFSET
)) {
2928 /* Note: only errors to the fragment with offset 0 */
2929 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
2933 if (ipha
->ipha_protocol
== IPPROTO_ICMP
) {
2935 * Check the ICMP type. RFC 1122 sez: don't send ICMP
2936 * errors in response to any ICMP errors.
2938 len_needed
= IPH_HDR_LENGTH(ipha
) + ICMPH_SIZE
;
2939 if (mp
->b_wptr
- mp
->b_rptr
< len_needed
) {
2940 if (!pullupmsg(mp
, len_needed
)) {
2941 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInErrors
);
2945 ipha
= (ipha_t
*)mp
->b_rptr
;
2948 (&((char *)ipha
)[IPH_HDR_LENGTH(ipha
)]);
2949 switch (icmph
->icmph_type
) {
2950 case ICMP_DEST_UNREACHABLE
:
2951 case ICMP_SOURCE_QUENCH
:
2952 case ICMP_TIME_EXCEEDED
:
2953 case ICMP_PARAM_PROBLEM
:
2955 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDrops
);
2962 if (icmp_err_rate_limit(ipst
)) {
2964 * Only send ICMP error packets every so often.
2965 * This should be done on a per port/source basis,
2966 * but for now this will suffice.
2975 * Called when a packet was sent out the same link that it arrived on.
2976 * Check if it is ok to send a redirect and then send it.
2979 ip_send_potential_redirect_v4(mblk_t
*mp
, ipha_t
*ipha
, ire_t
*ire
,
2980 ip_recv_attr_t
*ira
)
2982 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
2988 * Check the source address to see if it originated
2989 * on the same logical subnet it is going back out on.
2990 * If so, we should be able to send it a redirect.
2991 * Avoid sending a redirect if the destination
2992 * is directly connected (i.e., we matched an IRE_ONLINK),
2993 * or if the packet was source routed out this interface.
2995 * We avoid sending a redirect if the
2996 * destination is directly connected
2997 * because it is possible that multiple
2998 * IP subnets may have been configured on
2999 * the link, and the source may not
3000 * be on the same subnet as ip destination,
3001 * even though they are on the same
3004 if ((ire
->ire_type
& IRE_ONLINK
) ||
3005 ip_source_routed(ipha
, ipst
))
3008 nhop_ire
= ire_nexthop(ire
);
3009 if (nhop_ire
== NULL
)
3012 nhop
= nhop_ire
->ire_addr
;
3014 if (nhop_ire
->ire_type
& IRE_IF_CLONE
) {
3017 /* Follow ire_dep_parent to find non-clone IRE_INTERFACE */
3018 mutex_enter(&nhop_ire
->ire_lock
);
3019 ire2
= nhop_ire
->ire_dep_parent
;
3022 mutex_exit(&nhop_ire
->ire_lock
);
3023 ire_refrele(nhop_ire
);
3026 if (nhop_ire
== NULL
)
3029 ASSERT(!(nhop_ire
->ire_type
& IRE_IF_CLONE
));
3031 src
= ipha
->ipha_src
;
3034 * We look at the interface ire for the nexthop,
3035 * to see if ipha_src is in the same subnet
3038 if ((src
& nhop_ire
->ire_mask
) == (nhop
& nhop_ire
->ire_mask
)) {
3040 * The source is directly connected.
3044 icmp_send_redirect(mp1
, nhop
, ira
);
3047 ire_refrele(nhop_ire
);
3051 * Generate an ICMP redirect message.
3054 icmp_send_redirect(mblk_t
*mp
, ipaddr_t gateway
, ip_recv_attr_t
*ira
)
3057 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
3059 mp
= icmp_pkt_err_ok(mp
, ira
);
3063 bzero(&icmph
, sizeof (icmph_t
));
3064 icmph
.icmph_type
= ICMP_REDIRECT
;
3065 icmph
.icmph_code
= 1;
3066 icmph
.icmph_rd_gateway
= gateway
;
3067 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutRedirects
);
3068 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
3072 * Generate an ICMP time exceeded message.
3075 icmp_time_exceeded(mblk_t
*mp
, uint8_t code
, ip_recv_attr_t
*ira
)
3078 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
3080 mp
= icmp_pkt_err_ok(mp
, ira
);
3084 bzero(&icmph
, sizeof (icmph_t
));
3085 icmph
.icmph_type
= ICMP_TIME_EXCEEDED
;
3086 icmph
.icmph_code
= code
;
3087 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutTimeExcds
);
3088 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
3092 * Generate an ICMP unreachable message.
3093 * When called from ip_output side a minimal ip_recv_attr_t needs to be
3094 * constructed by the caller.
3097 icmp_unreachable(mblk_t
*mp
, uint8_t code
, ip_recv_attr_t
*ira
)
3100 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
3102 mp
= icmp_pkt_err_ok(mp
, ira
);
3106 bzero(&icmph
, sizeof (icmph_t
));
3107 icmph
.icmph_type
= ICMP_DEST_UNREACHABLE
;
3108 icmph
.icmph_code
= code
;
3109 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpOutDestUnreachs
);
3110 icmp_pkt(mp
, &icmph
, sizeof (icmph_t
), ira
);
3114 * Latch in the IPsec state for a stream based the policy in the listener
3115 * and the actions in the ip_recv_attr_t.
3116 * Called directly from TCP and SCTP.
3119 ip_ipsec_policy_inherit(conn_t
*connp
, conn_t
*lconnp
, ip_recv_attr_t
*ira
)
3121 ASSERT(lconnp
->conn_policy
!= NULL
);
3122 ASSERT(connp
->conn_policy
== NULL
);
3124 IPPH_REFHOLD(lconnp
->conn_policy
);
3125 connp
->conn_policy
= lconnp
->conn_policy
;
3127 if (ira
->ira_ipsec_action
!= NULL
) {
3128 if (connp
->conn_latch
== NULL
) {
3129 connp
->conn_latch
= iplatch_create();
3130 if (connp
->conn_latch
== NULL
)
3133 ipsec_latch_inbound(connp
, ira
);
3139 * Verify whether or not the IP address is a valid local address.
3140 * Could be a unicast, including one for a down interface.
3141 * If allow_mcbc then a multicast or broadcast address is also
3144 * In the case of a broadcast/multicast address, however, the
3145 * upper protocol is expected to reset the src address
3146 * to zero when we return IPVL_MCAST/IPVL_BCAST so that
3147 * no packets are emitted with broadcast/multicast address as
3148 * source address (that violates hosts requirements RFC 1122)
3149 * The addresses valid for bind are:
3150 * (1) - INADDR_ANY (0)
3151 * (2) - IP address of an UP interface
3152 * (3) - IP address of a DOWN interface
3153 * (4) - valid local IP broadcast addresses. In this case
3154 * the conn will only receive packets destined to
3155 * the specified broadcast address.
3156 * (5) - a multicast address. In this case
3157 * the conn will only receive packets destined to
3158 * the specified multicast address. Note: the
3159 * application still has to issue an
3160 * IP_ADD_MEMBERSHIP socket option.
3162 * In all the above cases, the bound address must be valid in the current zone.
3163 * When the address is loopback, multicast or broadcast, there might be many
3164 * matching IREs so bind has to look up based on the zone.
3167 ip_laddr_verify_v4(ipaddr_t src_addr
, zoneid_t zoneid
,
3168 ip_stack_t
*ipst
, boolean_t allow_mcbc
)
3172 ASSERT(src_addr
!= INADDR_ANY
);
3174 src_ire
= ire_ftable_lookup_v4(src_addr
, 0, 0, 0,
3175 NULL
, zoneid
, MATCH_IRE_ZONEONLY
, 0, ipst
, NULL
);
3178 * If an address other than in6addr_any is requested,
3179 * we verify that it is a valid address for bind
3180 * Note: Following code is in if-else-if form for
3181 * readability compared to a condition check.
3183 if (src_ire
!= NULL
&& (src_ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
))) {
3185 * (2) Bind to address of local UP interface
3187 ire_refrele(src_ire
);
3188 return (IPVL_UNICAST_UP
);
3189 } else if (src_ire
!= NULL
&& src_ire
->ire_type
& IRE_BROADCAST
) {
3191 * (4) Bind to broadcast address
3193 ire_refrele(src_ire
);
3195 return (IPVL_BCAST
);
3198 } else if (CLASSD(src_addr
)) {
3199 /* (5) bind to multicast address. */
3200 if (src_ire
!= NULL
)
3201 ire_refrele(src_ire
);
3204 return (IPVL_MCAST
);
3211 * (3) Bind to address of local DOWN interface?
3212 * (ipif_lookup_addr() looks up all interfaces
3213 * but we do not get here for UP interfaces
3216 if (src_ire
!= NULL
)
3217 ire_refrele(src_ire
);
3219 ipif
= ipif_lookup_addr(src_addr
, NULL
, zoneid
, ipst
);
3223 /* Not a useful source? */
3224 if (ipif
->ipif_flags
& (IPIF_NOLOCAL
| IPIF_ANYCAST
)) {
3229 return (IPVL_UNICAST_DOWN
);
3234 * Insert in the bind fanout for IPv4 and IPv6.
3235 * The caller should already have used ip_laddr_verify_v*() before calling
3239 ip_laddr_fanout_insert(conn_t
*connp
)
3244 * Allow setting new policies. For example, disconnects result
3245 * in us being called. As we would have set conn_policy_cached
3246 * to B_TRUE before, we should set it to B_FALSE, so that policy
3247 * can change after the disconnect.
3249 connp
->conn_policy_cached
= B_FALSE
;
3251 return (ipcl_bind_insert(connp
));
3255 * Verify that both the source and destination addresses are valid. If
3256 * IPDF_VERIFY_DST is not set, then the destination address may be unreachable,
3257 * i.e. have no route to it. Protocols like TCP want to verify destination
3258 * reachability, while tunnels do not.
3260 * Determine the route, the interface, and (optionally) the source address
3261 * to use to reach a given destination.
3262 * Note that we allow connect to broadcast and multicast addresses when
3263 * IPDF_ALLOW_MCBC is set.
3264 * first_hop and dst_addr are normally the same, but if source routing
3265 * they will differ; in that case the first_hop is what we'll use for the
3266 * routing lookup but the dce checks will be done on dst_addr,
3268 * If uinfo is set, then we fill in the best available information
3269 * we have for the destination. This is based on (in priority order) any
3270 * metrics and path MTU stored in a dce_t, route metrics, and finally the
3271 * ill_mtu/ill_mc_mtu.
3274 ip_set_destination_v4(ipaddr_t
*src_addrp
, ipaddr_t dst_addr
, ipaddr_t firsthop
,
3275 ip_xmit_attr_t
*ixa
, iulp_t
*uinfo
, uint32_t flags
)
3279 ipaddr_t setsrc
; /* RTF_SETSRC */
3280 zoneid_t zoneid
= ixa
->ixa_zoneid
; /* Honors SO_ALLZONES */
3281 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
3288 ASSERT(ixa
->ixa_flags
& IXAF_IS_IPV4
);
3291 * We never send to zero; the ULPs map it to the loopback address.
3292 * We can't allow it since we use zero to mean unitialized in some
3295 ASSERT(dst_addr
!= INADDR_ANY
);
3297 setsrc
= INADDR_ANY
;
3299 * Select a route; For IPMP interfaces, we would only select
3300 * a "hidden" route (i.e., going through a specific under_ill)
3301 * if ixa_ifindex has been specified.
3303 ire
= ip_select_route_v4(firsthop
, *src_addrp
, ixa
,
3304 &generation
, &setsrc
, &error
);
3305 ASSERT(ire
!= NULL
); /* IRE_NOROUTE if none found */
3310 * ire can't be a broadcast or multicast unless IPDF_ALLOW_MCBC is set.
3311 * If IPDF_VERIFY_DST is set, the destination must be reachable;
3312 * Otherwise the destination needn't be reachable.
3314 * If we match on a reject or black hole, then we've got a
3315 * local failure. May as well fail out the connect() attempt,
3316 * since it's never going to succeed.
3318 if (ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
)) {
3320 * If we're verifying destination reachability, we always want
3323 * If we're not verifying destination reachability but the
3324 * destination has a route, we still want to fail on the
3325 * temporary address and broadcast address tests.
3327 * In both cases do we let the code continue so some reasonable
3328 * information is returned to the caller. That enables the
3329 * caller to use (and even cache) the IRE. conn_ip_ouput will
3330 * use the generation mismatch path to check for the unreachable
3331 * case thereby avoiding any specific check in the main path.
3333 ASSERT(generation
== IRE_GENERATION_VERIFY
);
3334 if (flags
& IPDF_VERIFY_DST
) {
3336 * Set errno but continue to set up ixa_ire to be
3337 * the RTF_REJECT|RTF_BLACKHOLE IRE.
3338 * That allows callers to use ip_output to get an
3341 if (!(ire
->ire_type
& IRE_HOST
))
3342 error
= ENETUNREACH
;
3344 error
= EHOSTUNREACH
;
3348 if ((ire
->ire_type
& (IRE_BROADCAST
|IRE_MULTICAST
)) &&
3349 !(flags
& IPDF_ALLOW_MCBC
)) {
3351 ire
= ire_reject(ipst
, B_FALSE
);
3352 generation
= IRE_GENERATION_VERIFY
;
3353 error
= ENETUNREACH
;
3357 if (ixa
->ixa_ire
!= NULL
)
3358 ire_refrele_notr(ixa
->ixa_ire
);
3360 ire_refhold_notr(ire
);
3364 ixa
->ixa_ire_generation
= generation
;
3367 * Ensure that ixa_dce is always set any time that ixa_ire is set,
3368 * since some callers will send a packet to conn_ip_output() even if
3371 if (flags
& IPDF_UNIQUE_DCE
) {
3372 /* Fallback to the default dce if allocation fails */
3373 dce
= dce_lookup_and_add_v4(dst_addr
, ipst
);
3375 generation
= dce
->dce_generation
;
3377 dce
= dce_lookup_v4(dst_addr
, ipst
, &generation
);
3379 dce
= dce_lookup_v4(dst_addr
, ipst
, &generation
);
3381 ASSERT(dce
!= NULL
);
3382 if (ixa
->ixa_dce
!= NULL
)
3383 dce_refrele_notr(ixa
->ixa_dce
);
3385 dce_refhold_notr(dce
);
3389 ixa
->ixa_dce_generation
= generation
;
3390 ixa
->ixa_postfragfn
= ire
->ire_postfragfn
;
3392 if (!(ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))) {
3393 /* Get an nce to cache. */
3394 nce
= ire_to_nce(ire
, firsthop
, NULL
);
3396 /* Allocation failure? */
3397 ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
3399 if (ixa
->ixa_nce
!= NULL
)
3400 nce_refrele(ixa
->ixa_nce
);
3406 * If the source address is a loopback address, the
3407 * destination had best be local or multicast.
3408 * If we are sending to an IRE_LOCAL using a loopback source then
3409 * it had better be the same zoneid.
3411 if (*src_addrp
== htonl(INADDR_LOOPBACK
)) {
3412 if ((ire
->ire_type
& IRE_LOCAL
) && ire
->ire_zoneid
!= zoneid
) {
3413 ire
= NULL
; /* Stored in ixa_ire */
3414 error
= EADDRNOTAVAIL
;
3417 if (!(ire
->ire_type
& (IRE_LOOPBACK
|IRE_LOCAL
|IRE_MULTICAST
))) {
3418 ire
= NULL
; /* Stored in ixa_ire */
3419 error
= EADDRNOTAVAIL
;
3423 if (ire
->ire_type
& IRE_BROADCAST
) {
3425 * If the ULP didn't have a specified source, then we
3426 * make sure we reselect the source when sending
3427 * broadcasts out different interfaces.
3429 if (flags
& IPDF_SELECT_SRC
)
3430 ixa
->ixa_flags
|= IXAF_SET_SOURCE
;
3432 ixa
->ixa_flags
&= ~IXAF_SET_SOURCE
;
3436 * Does the caller want us to pick a source address?
3438 if (flags
& IPDF_SELECT_SRC
) {
3442 * We use use ire_nexthop_ill to avoid the under ipmp
3443 * interface for source address selection. Note that for ipmp
3444 * probe packets, ixa_ifindex would have been specified, and
3445 * the ip_select_route() invocation would have picked an ire
3446 * will ire_ill pointing at an under interface.
3448 ill
= ire_nexthop_ill(ire
);
3450 /* If unreachable we have no ill but need some source */
3452 src_addr
= htonl(INADDR_LOOPBACK
);
3453 /* Make sure we look for a better source address */
3454 generation
= SRC_GENERATION_VERIFY
;
3456 error
= ip_select_source_v4(ill
, setsrc
, dst_addr
,
3457 ixa
->ixa_multicast_ifaddr
, zoneid
,
3458 ipst
, &src_addr
, &generation
, NULL
);
3460 ire
= NULL
; /* Stored in ixa_ire */
3466 * We allow the source address to to down.
3467 * However, we check that we don't use the loopback address
3468 * as a source when sending out on the wire.
3470 if ((src_addr
== htonl(INADDR_LOOPBACK
)) &&
3471 !(ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
|IRE_MULTICAST
)) &&
3472 !(ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))) {
3473 ire
= NULL
; /* Stored in ixa_ire */
3474 error
= EADDRNOTAVAIL
;
3478 *src_addrp
= src_addr
;
3479 ixa
->ixa_src_generation
= generation
;
3483 * Make sure we don't leave an unreachable ixa_nce in place
3484 * since ip_select_route is used when we unplumb i.e., remove
3485 * references on ixa_ire, ixa_nce, and ixa_dce.
3488 if (nce
!= NULL
&& nce
->nce_is_condemned
) {
3490 ixa
->ixa_nce
= NULL
;
3491 ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
3495 * The caller has set IXAF_PMTU_DISCOVERY if path MTU is desired.
3496 * However, we can't do it for IPv4 multicast or broadcast.
3498 if (ire
->ire_type
& (IRE_BROADCAST
|IRE_MULTICAST
))
3499 ixa
->ixa_flags
&= ~IXAF_PMTU_DISCOVERY
;
3502 * Set initial value for fragmentation limit. Either conn_ip_output
3503 * or ULP might updates it when there are routing changes.
3504 * Handles a NULL ixa_ire->ire_ill or a NULL ixa_nce for RTF_REJECT.
3506 pmtu
= ip_get_pmtu(ixa
);
3507 ixa
->ixa_fragsize
= pmtu
;
3508 /* Make sure ixa_fragsize and ixa_pmtu remain identical */
3509 if (ixa
->ixa_flags
& IXAF_VERIFY_PMTU
)
3510 ixa
->ixa_pmtu
= pmtu
;
3513 * Extract information useful for some transports.
3514 * First we look for DCE metrics. Then we take what we have in
3515 * the metrics in the route, where the offlink is used if we have
3518 if (uinfo
!= NULL
) {
3519 bzero(uinfo
, sizeof (*uinfo
));
3521 if (dce
->dce_flags
& DCEF_UINFO
)
3522 *uinfo
= dce
->dce_uinfo
;
3524 rts_merge_metrics(uinfo
, &ire
->ire_metrics
);
3526 /* Allow ire_metrics to decrease the path MTU from above */
3527 if (uinfo
->iulp_mtu
== 0 || uinfo
->iulp_mtu
> pmtu
)
3528 uinfo
->iulp_mtu
= pmtu
;
3530 uinfo
->iulp_localnet
= (ire
->ire_type
& IRE_ONLINK
) != 0;
3531 uinfo
->iulp_loopback
= (ire
->ire_type
& IRE_LOOPBACK
) != 0;
3532 uinfo
->iulp_local
= (ire
->ire_type
& IRE_LOCAL
) != 0;
3548 * Make sure we don't leave an unreachable ixa_nce in place
3549 * since ip_select_route is used when we unplumb i.e., remove
3550 * references on ixa_ire, ixa_nce, and ixa_dce.
3553 if (nce
!= NULL
&& nce
->nce_is_condemned
) {
3555 ixa
->ixa_nce
= NULL
;
3556 ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
3564 * Get the base MTU for the case when path MTU discovery is not used.
3565 * Takes the MTU of the IRE into account.
3568 ip_get_base_mtu(ill_t
*ill
, ire_t
*ire
)
3571 uint_t iremtu
= ire
->ire_metrics
.iulp_mtu
;
3573 if (ire
->ire_type
& (IRE_MULTICAST
|IRE_BROADCAST
))
3574 mtu
= ill
->ill_mc_mtu
;
3578 if (iremtu
!= 0 && iremtu
< mtu
)
3585 * Get the PMTU for the attributes. Handles both IPv4 and IPv6.
3586 * Assumes that ixa_ire, dce, and nce have already been set up.
3588 * The caller has set IXAF_PMTU_DISCOVERY if path MTU discovery is desired.
3589 * We avoid path MTU discovery if it is disabled with ndd.
3590 * Furtermore, if the path MTU is too small, then we don't set DF for IPv4.
3592 * NOTE: We also used to turn it off for source routed packets. That
3593 * is no longer required since the dce is per final destination.
3596 ip_get_pmtu(ip_xmit_attr_t
*ixa
)
3598 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
3609 * If path MTU discovery has been turned off by ndd, then we ignore
3610 * any dce_pmtu and for IPv4 we will not set DF.
3612 if (!ipst
->ips_ip_path_mtu_discovery
)
3613 ixa
->ixa_flags
&= ~IXAF_PMTU_DISCOVERY
;
3615 pmtu
= IP_MAXPACKET
;
3617 * Decide whether whether IPv4 sets DF
3618 * For IPv6 "no DF" means to use the 1280 mtu
3620 if (ixa
->ixa_flags
& IXAF_PMTU_DISCOVERY
) {
3621 ixa
->ixa_flags
|= IXAF_PMTU_IPV4_DF
;
3623 ixa
->ixa_flags
&= ~IXAF_PMTU_IPV4_DF
;
3624 if (!(ixa
->ixa_flags
& IXAF_IS_IPV4
))
3625 pmtu
= IPV6_MIN_MTU
;
3628 /* Check if the PMTU is to old before we use it */
3629 if ((dce
->dce_flags
& DCEF_PMTU
) &&
3630 TICK_TO_SEC(ddi_get_lbolt64()) - dce
->dce_last_change_time
>
3631 ipst
->ips_ip_pathmtu_interval
) {
3633 * Older than 20 minutes. Drop the path MTU information.
3635 mutex_enter(&dce
->dce_lock
);
3636 dce
->dce_flags
&= ~(DCEF_PMTU
|DCEF_TOO_SMALL_PMTU
);
3637 dce
->dce_last_change_time
= TICK_TO_SEC(ddi_get_lbolt64());
3638 mutex_exit(&dce
->dce_lock
);
3639 dce_increment_generation(dce
);
3642 /* The metrics on the route can lower the path MTU */
3643 if (ire
->ire_metrics
.iulp_mtu
!= 0 &&
3644 ire
->ire_metrics
.iulp_mtu
< pmtu
)
3645 pmtu
= ire
->ire_metrics
.iulp_mtu
;
3648 * If the path MTU is smaller than some minimum, we still use dce_pmtu
3649 * above (would be 576 for IPv4 and 1280 for IPv6), but we clear
3650 * IXAF_PMTU_IPV4_DF so that we avoid setting DF for IPv4.
3652 if (ixa
->ixa_flags
& IXAF_PMTU_DISCOVERY
) {
3653 if (dce
->dce_flags
& DCEF_PMTU
) {
3654 if (dce
->dce_pmtu
< pmtu
)
3655 pmtu
= dce
->dce_pmtu
;
3657 if (dce
->dce_flags
& DCEF_TOO_SMALL_PMTU
) {
3658 ixa
->ixa_flags
|= IXAF_PMTU_TOO_SMALL
;
3659 ixa
->ixa_flags
&= ~IXAF_PMTU_IPV4_DF
;
3661 ixa
->ixa_flags
&= ~IXAF_PMTU_TOO_SMALL
;
3662 ixa
->ixa_flags
|= IXAF_PMTU_IPV4_DF
;
3665 ixa
->ixa_flags
&= ~IXAF_PMTU_TOO_SMALL
;
3666 ixa
->ixa_flags
|= IXAF_PMTU_IPV4_DF
;
3671 * If we have an IRE_LOCAL we use the loopback mtu instead of
3672 * the ill for going out the wire i.e., IRE_LOCAL gets the same
3673 * mtu as IRE_LOOPBACK.
3675 if (ire
->ire_type
& (IRE_LOCAL
|IRE_LOOPBACK
)) {
3676 uint_t loopback_mtu
;
3678 loopback_mtu
= (ire
->ire_ipversion
== IPV6_VERSION
) ?
3679 ip_loopback_mtu_v6plus
: ip_loopback_mtuplus
;
3681 if (loopback_mtu
< pmtu
)
3682 pmtu
= loopback_mtu
;
3683 } else if (nce
!= NULL
) {
3685 * Make sure we don't exceed the interface MTU.
3686 * In the case of RTF_REJECT or RTF_BLACKHOLE we might not have
3687 * an ill. We'd use the above IP_MAXPACKET in that case just
3688 * to tell the transport something larger than zero.
3690 if (ire
->ire_type
& (IRE_MULTICAST
|IRE_BROADCAST
)) {
3691 if (nce
->nce_common
->ncec_ill
->ill_mc_mtu
< pmtu
)
3692 pmtu
= nce
->nce_common
->ncec_ill
->ill_mc_mtu
;
3693 if (nce
->nce_common
->ncec_ill
!= nce
->nce_ill
&&
3694 nce
->nce_ill
->ill_mc_mtu
< pmtu
) {
3696 * for interfaces in an IPMP group, the mtu of
3697 * the nce_ill (under_ill) could be different
3698 * from the mtu of the ncec_ill, so we take the
3701 pmtu
= nce
->nce_ill
->ill_mc_mtu
;
3704 if (nce
->nce_common
->ncec_ill
->ill_mtu
< pmtu
)
3705 pmtu
= nce
->nce_common
->ncec_ill
->ill_mtu
;
3706 if (nce
->nce_common
->ncec_ill
!= nce
->nce_ill
&&
3707 nce
->nce_ill
->ill_mtu
< pmtu
) {
3709 * for interfaces in an IPMP group, the mtu of
3710 * the nce_ill (under_ill) could be different
3711 * from the mtu of the ncec_ill, so we take the
3714 pmtu
= nce
->nce_ill
->ill_mtu
;
3720 * Handle the IPV6_USE_MIN_MTU socket option or ancillary data.
3721 * Only applies to IPv6.
3723 if (!(ixa
->ixa_flags
& IXAF_IS_IPV4
)) {
3724 if (ixa
->ixa_flags
& IXAF_USE_MIN_MTU
) {
3725 switch (ixa
->ixa_use_min_mtu
) {
3726 case IPV6_USE_MIN_MTU_MULTICAST
:
3727 if (ire
->ire_type
& IRE_MULTICAST
)
3728 pmtu
= IPV6_MIN_MTU
;
3730 case IPV6_USE_MIN_MTU_ALWAYS
:
3731 pmtu
= IPV6_MIN_MTU
;
3733 case IPV6_USE_MIN_MTU_NEVER
:
3737 /* Default is IPV6_USE_MIN_MTU_MULTICAST */
3738 if (ire
->ire_type
& IRE_MULTICAST
)
3739 pmtu
= IPV6_MIN_MTU
;
3747 * Carve "len" bytes out of an mblk chain, consuming any we empty, and duping
3748 * the final piece where we don't. Return a pointer to the first mblk in the
3749 * result, and update the pointer to the next mblk to chew on. If anything
3750 * goes wrong (i.e., dupb fails), we waste everything in sight and return a
3754 ip_carve_mp(mblk_t
**mpp
, ssize_t len
)
3760 if (!len
|| !mpp
|| !(mp0
= *mpp
))
3762 /* If we aren't going to consume the first mblk, we need a dup. */
3763 if (mp0
->b_wptr
- mp0
->b_rptr
> len
) {
3766 /* Partition the data between the two mblks. */
3767 mp1
->b_wptr
= mp1
->b_rptr
+ len
;
3768 mp0
->b_rptr
= mp1
->b_wptr
;
3770 * after adjustments if mblk not consumed is now
3771 * unaligned, try to align it. If this fails free
3772 * all messages and let upper layer recover.
3774 if (!OK_32PTR(mp0
->b_rptr
)) {
3775 if (!pullupmsg(mp0
, -1)) {
3785 /* Eat through as many mblks as we need to get len bytes. */
3786 len
-= mp0
->b_wptr
- mp0
->b_rptr
;
3787 for (mp2
= mp1
= mp0
; (mp2
= mp2
->b_cont
) != 0 && len
; mp1
= mp2
) {
3788 if (mp2
->b_wptr
- mp2
->b_rptr
> len
) {
3790 * We won't consume the entire last mblk. Like
3791 * above, dup and partition it.
3793 mp1
->b_cont
= dupb(mp2
);
3797 * Trouble. Rather than go to a lot of
3798 * trouble to clean up, we free the messages.
3799 * This won't be any worse than losing it on
3807 mp1
->b_wptr
= mp1
->b_rptr
+ len
;
3808 mp2
->b_rptr
= mp1
->b_wptr
;
3810 * after adjustments if mblk not consumed is now
3811 * unaligned, try to align it. If this fails free
3812 * all messages and let upper layer recover.
3814 if (!OK_32PTR(mp2
->b_rptr
)) {
3815 if (!pullupmsg(mp2
, -1)) {
3825 /* Decrement len by the amount we just got. */
3826 len
-= mp2
->b_wptr
- mp2
->b_rptr
;
3829 * len should be reduced to zero now. If not our caller has
3833 /* Shouldn't happen! */
3839 * We consumed up to exactly the end of an mblk. Detach the part
3840 * we are returning from the rest of the chain.
3847 /* The ill stream is being unplumbed. Called from ip_close */
3849 ip_modclose(ill_t
*ill
)
3854 queue_t
*q
= ill
->ill_rq
;
3855 ip_stack_t
*ipst
= ill
->ill_ipst
;
3857 arl_ill_common_t
*ai
= ill
->ill_common
;
3860 * The punlink prior to this may have initiated a capability
3861 * negotiation. But ipsq_enter will block until that finishes or
3864 success
= ipsq_enter(ill
, B_FALSE
, NEW_OP
);
3867 * Open/close/push/pop is guaranteed to be single threaded
3868 * per stream by STREAMS. FS guarantees that all references
3869 * from top are gone before close is called. So there can't
3870 * be another close thread that has set CONDEMNED on this ill.
3871 * and cause ipsq_enter to return failure.
3874 ipsq
= ill
->ill_phyint
->phyint_ipsq
;
3877 * Mark it condemned. No new reference will be made to this ill.
3878 * Lookup functions will return an error. Threads that try to
3879 * increment the refcnt must check for ILL_CAN_LOOKUP. This ensures
3880 * that the refcnt will drop down to zero.
3882 mutex_enter(&ill
->ill_lock
);
3883 ill
->ill_state_flags
|= ILL_CONDEMNED
;
3884 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
3885 ipif
= ipif
->ipif_next
) {
3886 ipif
->ipif_state_flags
|= IPIF_CONDEMNED
;
3889 * Wake up anybody waiting to enter the ipsq. ipsq_enter
3890 * returns error if ILL_CONDEMNED is set
3892 cv_broadcast(&ill
->ill_cv
);
3893 mutex_exit(&ill
->ill_lock
);
3896 * Send all the deferred DLPI messages downstream which came in
3897 * during the small window right before ipsq_enter(). We do this
3898 * without waiting for the ACKs because all the ACKs for M_PROTO
3899 * messages are ignored in ip_rput() when ILL_CONDEMNED is set.
3901 ill_dlpi_send_deferred(ill
);
3904 * Shut down fragmentation reassembly.
3905 * ill_frag_timer won't start a timer again.
3906 * Now cancel any existing timer
3908 (void) untimeout(ill
->ill_frag_timer_id
);
3909 (void) ill_frag_timeout(ill
, 0);
3912 * Call ill_delete to bring down the ipifs, ilms and ill on
3913 * this ill. Then wait for the refcnts to drop to zero.
3914 * ill_is_freeable checks whether the ill is really quiescent.
3915 * Then make sure that threads that are waiting to enter the
3916 * ipsq have seen the error returned by ipsq_enter and have
3917 * gone away. Then we call ill_delete_tail which does the
3918 * DL_UNBIND_REQ with the driver and then qprocsoff.
3921 mutex_enter(&ill
->ill_lock
);
3922 while (!ill_is_freeable(ill
))
3923 cv_wait(&ill
->ill_cv
, &ill
->ill_lock
);
3925 while (ill
->ill_waiters
)
3926 cv_wait(&ill
->ill_cv
, &ill
->ill_lock
);
3928 mutex_exit(&ill
->ill_lock
);
3931 * ill_delete_tail drops reference on ill_ipst, but we need to keep
3932 * it held until the end of the function since the cleanup
3933 * below needs to be able to use the ip_stack_t.
3935 netstack_hold(ipst
->ips_netstack
);
3937 /* qprocsoff is done via ill_delete_tail */
3938 ill_delete_tail(ill
);
3940 * synchronously wait for arp stream to unbind. After this, we
3941 * cannot get any data packets up from the driver.
3943 arp_unbind_complete(ill
);
3944 ASSERT(ill
->ill_ipst
== NULL
);
3947 * Walk through all conns and qenable those that have queued data.
3948 * Close synchronization needs this to
3949 * be done to ensure that all upper layers blocked
3950 * due to flow control to the closing device
3953 ip1dbg(("ip_wsrv: walking\n"));
3954 for (i
= 0; i
< TX_FANOUT_SIZE
; i
++) {
3955 conn_walk_drain(ipst
, &ipst
->ips_idl_tx_list
[i
]);
3959 * ai can be null if this is an IPv6 ill, or if the IPv4
3960 * stream is being torn down before ARP was plumbed (e.g.,
3961 * /sbin/ifconfig plumbing a stream twice, and encountering
3965 ASSERT(!ill
->ill_isv6
);
3966 mutex_enter(&ai
->ai_lock
);
3968 if (ai
->ai_arl
== NULL
) {
3969 mutex_destroy(&ai
->ai_lock
);
3970 kmem_free(ai
, sizeof (*ai
));
3972 cv_signal(&ai
->ai_ill_unplumb_done
);
3973 mutex_exit(&ai
->ai_lock
);
3977 mutex_enter(&ipst
->ips_ip_mi_lock
);
3978 mi_close_unlink(&ipst
->ips_ip_g_head
, (IDP
)ill
);
3979 mutex_exit(&ipst
->ips_ip_mi_lock
);
3982 * credp could be null if the open didn't succeed and ip_modopen
3983 * itself calls ip_close.
3985 if (ill
->ill_credp
!= NULL
)
3986 crfree(ill
->ill_credp
);
3988 mutex_destroy(&ill
->ill_saved_ire_lock
);
3989 mutex_destroy(&ill
->ill_lock
);
3990 rw_destroy(&ill
->ill_mcast_lock
);
3991 mutex_destroy(&ill
->ill_mcast_serializer
);
3992 list_destroy(&ill
->ill_nce
);
3995 * Now we are done with the module close pieces that
3996 * need the netstack_t.
3998 netstack_rele(ipst
->ips_netstack
);
4000 mi_close_free((IDP
)ill
);
4001 q
->q_ptr
= WR(q
)->q_ptr
= NULL
;
4009 * This is called as part of close() for IP, UDP, ICMP, and RTS
4010 * in order to quiesce the conn.
4013 ip_quiesce_conn(conn_t
*connp
)
4015 boolean_t drain_cleanup_reqd
= B_FALSE
;
4016 boolean_t conn_ioctl_cleanup_reqd
= B_FALSE
;
4017 boolean_t ilg_cleanup_reqd
= B_FALSE
;
4020 ASSERT(!IPCL_IS_TCP(connp
));
4021 ipst
= connp
->conn_netstack
->netstack_ip
;
4024 * Mark the conn as closing, and this conn must not be
4025 * inserted in future into any list. Eg. conn_drain_insert(),
4026 * won't insert this conn into the conn_drain_list.
4028 * conn_idl, and conn_ilg cannot get set henceforth.
4030 mutex_enter(&connp
->conn_lock
);
4031 ASSERT(!(connp
->conn_state_flags
& CONN_QUIESCED
));
4032 connp
->conn_state_flags
|= CONN_CLOSING
;
4033 if (connp
->conn_idl
!= NULL
)
4034 drain_cleanup_reqd
= B_TRUE
;
4035 if (connp
->conn_oper_pending_ill
!= NULL
)
4036 conn_ioctl_cleanup_reqd
= B_TRUE
;
4037 if (connp
->conn_dhcpinit_ill
!= NULL
) {
4038 ASSERT(connp
->conn_dhcpinit_ill
->ill_dhcpinit
!= 0);
4039 atomic_dec_32(&connp
->conn_dhcpinit_ill
->ill_dhcpinit
);
4040 ill_set_inputfn(connp
->conn_dhcpinit_ill
);
4041 connp
->conn_dhcpinit_ill
= NULL
;
4043 if (connp
->conn_ilg
!= NULL
)
4044 ilg_cleanup_reqd
= B_TRUE
;
4045 mutex_exit(&connp
->conn_lock
);
4047 if (conn_ioctl_cleanup_reqd
)
4048 conn_ioctl_cleanup(connp
);
4051 * Remove this conn from any fanout list it is on.
4052 * and then wait for any threads currently operating
4053 * on this endpoint to finish
4055 ipcl_hash_remove(connp
);
4058 * Remove this conn from the drain list, and do any other cleanup that
4059 * may be required. (TCP conns are never flow controlled, and
4060 * conn_idl will be NULL.)
4062 if (drain_cleanup_reqd
&& connp
->conn_idl
!= NULL
) {
4063 idl_t
*idl
= connp
->conn_idl
;
4065 mutex_enter(&idl
->idl_lock
);
4066 conn_drain(connp
, B_TRUE
);
4067 mutex_exit(&idl
->idl_lock
);
4070 if (connp
== ipst
->ips_ip_g_mrouter
)
4071 (void) ip_mrouter_done(ipst
);
4073 if (ilg_cleanup_reqd
)
4074 ilg_delete_all(connp
);
4077 * Now conn refcnt can increase only thru CONN_INC_REF_LOCKED.
4078 * callers from write side can't be there now because close
4079 * is in progress. The only other caller is ipcl_walk
4080 * which checks for the condemned flag.
4082 mutex_enter(&connp
->conn_lock
);
4083 connp
->conn_state_flags
|= CONN_CONDEMNED
;
4084 while (connp
->conn_ref
!= 1)
4085 cv_wait(&connp
->conn_cv
, &connp
->conn_lock
);
4086 connp
->conn_state_flags
|= CONN_QUIESCED
;
4087 mutex_exit(&connp
->conn_lock
);
4092 ip_close(queue_t
*q
, int flags
)
4097 * Call the appropriate delete routine depending on whether this is
4098 * a module or device.
4100 if (WR(q
)->q_next
!= NULL
) {
4101 /* This is a module close */
4102 return (ip_modclose((ill_t
*)q
->q_ptr
));
4106 ip_quiesce_conn(connp
);
4111 * Now we are truly single threaded on this stream, and can
4112 * delete the things hanging off the connp, and finally the connp.
4113 * We removed this connp from the fanout list, it cannot be
4114 * accessed thru the fanouts, and we already waited for the
4115 * conn_ref to drop to 0. We are already in close, so
4116 * there cannot be any other thread from the top. qprocsoff
4117 * has completed, and service has completed or won't run in
4120 ASSERT(connp
->conn_ref
== 1);
4122 inet_minor_free(connp
->conn_minor_arena
, connp
->conn_dev
);
4125 ipcl_conn_destroy(connp
);
4127 q
->q_ptr
= WR(q
)->q_ptr
= NULL
;
4132 * Wapper around putnext() so that ip_rts_request can merely use
4137 ip_conn_input(void *arg1
, mblk_t
*mp
, void *arg2
, ip_recv_attr_t
*ira
)
4139 conn_t
*connp
= (conn_t
*)arg1
;
4141 putnext(connp
->conn_rq
, mp
);
4144 /* Dummy in case ICMP error delivery is attempted to a /dev/ip instance */
4147 ip_conn_input_icmp(void *arg1
, mblk_t
*mp
, void *arg2
, ip_recv_attr_t
*ira
)
4153 * Called when the module is about to be unloaded
4156 ip_ddi_destroy(void)
4158 /* This needs to be called before destroying any transports. */
4159 mutex_enter(&cpu_lock
);
4160 unregister_cpu_setup_func(ip_tp_cpu_update
, NULL
);
4161 mutex_exit(&cpu_lock
);
4163 icmp_ddi_g_destroy();
4164 rts_ddi_g_destroy();
4165 udp_ddi_g_destroy();
4166 sctp_ddi_g_destroy();
4167 tcp_ddi_g_destroy();
4168 ilb_ddi_g_destroy();
4170 ipsec_policy_g_destroy();
4174 inet_minor_destroy(ip_minor_arena_sa
);
4176 inet_minor_destroy(ip_minor_arena_la
);
4180 list_destroy(&ip_thread_list
);
4181 rw_destroy(&ip_thread_rwlock
);
4182 tsd_destroy(&ip_thread_data
);
4185 netstack_unregister(NS_IP
);
4189 * First step in cleanup.
4193 ip_stack_shutdown(netstackid_t stackid
, void *arg
)
4195 ip_stack_t
*ipst
= (ip_stack_t
*)arg
;
4199 printf("ip_stack_shutdown(%p, stack %d)\n", (void *)ipst
, stackid
);
4203 * Perform cleanup for special interfaces (loopback and IPMP).
4205 ip_interface_cleanup(ipst
);
4208 * The *_hook_shutdown()s start the process of notifying any
4209 * consumers that things are going away.... nothing is destroyed.
4211 ipv4_hook_shutdown(ipst
);
4212 ipv6_hook_shutdown(ipst
);
4213 arp_hook_shutdown(ipst
);
4215 mutex_enter(&ipst
->ips_capab_taskq_lock
);
4216 ktid
= ipst
->ips_capab_taskq_thread
->t_did
;
4217 ipst
->ips_capab_taskq_quit
= B_TRUE
;
4218 cv_signal(&ipst
->ips_capab_taskq_cv
);
4219 mutex_exit(&ipst
->ips_capab_taskq_lock
);
4222 * In rare occurrences, particularly on virtual hardware where CPUs can
4223 * be de-scheduled, the thread that we just signaled will not run until
4224 * after we have gotten through parts of ip_stack_fini. If that happens
4225 * then we'll try to grab the ips_capab_taskq_lock as part of returning
4226 * from cv_wait which no longer exists.
4232 * Free the IP stack instance.
4235 ip_stack_fini(netstackid_t stackid
, void *arg
)
4237 ip_stack_t
*ipst
= (ip_stack_t
*)arg
;
4241 printf("ip_stack_fini(%p, stack %d)\n", (void *)ipst
, stackid
);
4244 * At this point, all of the notifications that the events and
4245 * protocols are going away have been run, meaning that we can
4246 * now set about starting to clean things up.
4249 ipv4_hook_destroy(ipst
);
4250 ipv6_hook_destroy(ipst
);
4251 arp_hook_destroy(ipst
);
4252 ip_net_destroy(ipst
);
4256 ip_kstat_fini(stackid
, ipst
->ips_ip_mibkp
);
4257 ipst
->ips_ip_mibkp
= NULL
;
4258 icmp_kstat_fini(stackid
, ipst
->ips_icmp_mibkp
);
4259 ipst
->ips_icmp_mibkp
= NULL
;
4260 ip_kstat2_fini(stackid
, ipst
->ips_ip_kstat
);
4261 ipst
->ips_ip_kstat
= NULL
;
4262 bzero(&ipst
->ips_ip_statistics
, sizeof (ipst
->ips_ip_statistics
));
4263 ip6_kstat_fini(stackid
, ipst
->ips_ip6_kstat
);
4264 ipst
->ips_ip6_kstat
= NULL
;
4265 bzero(&ipst
->ips_ip6_statistics
, sizeof (ipst
->ips_ip6_statistics
));
4267 kmem_free(ipst
->ips_propinfo_tbl
,
4268 ip_propinfo_count
* sizeof (mod_prop_info_t
));
4269 ipst
->ips_propinfo_tbl
= NULL
;
4271 dce_stack_destroy(ipst
);
4272 ip_mrouter_stack_destroy(ipst
);
4275 * Quiesce all of our timers. Note we set the quiesce flags before we
4276 * call untimeout. The slowtimers may actually kick off another instance
4277 * of the non-slow timers.
4279 mutex_enter(&ipst
->ips_igmp_timer_lock
);
4280 ipst
->ips_igmp_timer_quiesce
= B_TRUE
;
4281 mutex_exit(&ipst
->ips_igmp_timer_lock
);
4283 mutex_enter(&ipst
->ips_mld_timer_lock
);
4284 ipst
->ips_mld_timer_quiesce
= B_TRUE
;
4285 mutex_exit(&ipst
->ips_mld_timer_lock
);
4287 mutex_enter(&ipst
->ips_igmp_slowtimeout_lock
);
4288 ipst
->ips_igmp_slowtimeout_quiesce
= B_TRUE
;
4289 mutex_exit(&ipst
->ips_igmp_slowtimeout_lock
);
4291 mutex_enter(&ipst
->ips_mld_slowtimeout_lock
);
4292 ipst
->ips_mld_slowtimeout_quiesce
= B_TRUE
;
4293 mutex_exit(&ipst
->ips_mld_slowtimeout_lock
);
4295 ret
= untimeout(ipst
->ips_igmp_timeout_id
);
4297 ASSERT(ipst
->ips_igmp_timeout_id
== 0);
4299 ASSERT(ipst
->ips_igmp_timeout_id
!= 0);
4300 ipst
->ips_igmp_timeout_id
= 0;
4302 ret
= untimeout(ipst
->ips_igmp_slowtimeout_id
);
4304 ASSERT(ipst
->ips_igmp_slowtimeout_id
== 0);
4306 ASSERT(ipst
->ips_igmp_slowtimeout_id
!= 0);
4307 ipst
->ips_igmp_slowtimeout_id
= 0;
4309 ret
= untimeout(ipst
->ips_mld_timeout_id
);
4311 ASSERT(ipst
->ips_mld_timeout_id
== 0);
4313 ASSERT(ipst
->ips_mld_timeout_id
!= 0);
4314 ipst
->ips_mld_timeout_id
= 0;
4316 ret
= untimeout(ipst
->ips_mld_slowtimeout_id
);
4318 ASSERT(ipst
->ips_mld_slowtimeout_id
== 0);
4320 ASSERT(ipst
->ips_mld_slowtimeout_id
!= 0);
4321 ipst
->ips_mld_slowtimeout_id
= 0;
4326 conn_drain_fini(ipst
);
4329 mutex_destroy(&ipst
->ips_ndp4
->ndp_g_lock
);
4330 mutex_destroy(&ipst
->ips_ndp6
->ndp_g_lock
);
4331 kmem_free(ipst
->ips_ndp4
, sizeof (ndp_g_t
));
4332 ipst
->ips_ndp4
= NULL
;
4333 kmem_free(ipst
->ips_ndp6
, sizeof (ndp_g_t
));
4334 ipst
->ips_ndp6
= NULL
;
4336 if (ipst
->ips_loopback_ksp
!= NULL
) {
4337 kstat_delete_netstack(ipst
->ips_loopback_ksp
, stackid
);
4338 ipst
->ips_loopback_ksp
= NULL
;
4341 mutex_destroy(&ipst
->ips_capab_taskq_lock
);
4342 cv_destroy(&ipst
->ips_capab_taskq_cv
);
4344 rw_destroy(&ipst
->ips_srcid_lock
);
4346 mutex_destroy(&ipst
->ips_ip_mi_lock
);
4347 rw_destroy(&ipst
->ips_ill_g_usesrc_lock
);
4349 mutex_destroy(&ipst
->ips_igmp_timer_lock
);
4350 mutex_destroy(&ipst
->ips_mld_timer_lock
);
4351 mutex_destroy(&ipst
->ips_igmp_slowtimeout_lock
);
4352 mutex_destroy(&ipst
->ips_mld_slowtimeout_lock
);
4353 mutex_destroy(&ipst
->ips_ip_addr_avail_lock
);
4354 rw_destroy(&ipst
->ips_ill_g_lock
);
4356 kmem_free(ipst
->ips_phyint_g_list
, sizeof (phyint_list_t
));
4357 ipst
->ips_phyint_g_list
= NULL
;
4358 kmem_free(ipst
->ips_ill_g_heads
, sizeof (ill_g_head_t
) * MAX_G_HEADS
);
4359 ipst
->ips_ill_g_heads
= NULL
;
4361 ldi_ident_release(ipst
->ips_ldi_ident
);
4362 kmem_free(ipst
, sizeof (*ipst
));
4366 * This function is called from the TSD destructor, and is used to debug
4367 * reference count issues in IP. See block comment in <inet/ip_if.h> for
4371 ip_thread_exit(void *phash
)
4373 th_hash_t
*thh
= phash
;
4375 rw_enter(&ip_thread_rwlock
, RW_WRITER
);
4376 list_remove(&ip_thread_list
, thh
);
4377 rw_exit(&ip_thread_rwlock
);
4378 mod_hash_destroy_hash(thh
->thh_hash
);
4379 kmem_free(thh
, sizeof (*thh
));
4383 * Called when the IP kernel module is loaded into the kernel
4388 ip_squeue_flag
= ip_squeue_switch(ip_squeue_enter
);
4391 * For IP and TCP the minor numbers should start from 2 since we have 4
4392 * initial devices: ip, ip6, tcp, tcp6.
4395 * If this is a 64-bit kernel, then create two separate arenas -
4396 * one for TLIs in the range of INET_MIN_DEV+2 through 2^^18-1, and the
4397 * other for socket apps in the range 2^^18 through 2^^32-1.
4399 ip_minor_arena_la
= NULL
;
4400 ip_minor_arena_sa
= NULL
;
4402 if ((ip_minor_arena_sa
= inet_minor_create("ip_minor_arena_sa",
4403 INET_MIN_DEV
+ 2, MAXMIN32
, KM_SLEEP
)) == NULL
) {
4405 "ip_ddi_init: ip_minor_arena_sa creation failed\n");
4407 if ((ip_minor_arena_la
= inet_minor_create("ip_minor_arena_la",
4408 MAXMIN32
+ 1, MAXMIN64
, KM_SLEEP
)) == NULL
) {
4410 "ip_ddi_init: ip_minor_arena_la creation failed\n");
4413 if ((ip_minor_arena_sa
= inet_minor_create("ip_minor_arena_sa",
4414 INET_MIN_DEV
+ 2, MAXMIN
, KM_SLEEP
)) == NULL
) {
4416 "ip_ddi_init: ip_minor_arena_sa creation failed\n");
4419 ip_poll_normal_ticks
= MSEC_TO_TICK_ROUNDUP(ip_poll_normal_ms
);
4426 tsd_create(&ip_thread_data
, ip_thread_exit
);
4427 rw_init(&ip_thread_rwlock
, NULL
, RW_DEFAULT
, NULL
);
4428 list_create(&ip_thread_list
, sizeof (th_hash_t
),
4429 offsetof(th_hash_t
, thh_link
));
4431 ipsec_policy_g_init();
4437 * We want to be informed each time a stack is created or
4438 * destroyed in the kernel, so we can maintain the
4439 * set of udp_stack_t's.
4441 netstack_register(NS_IP
, ip_stack_init
, ip_stack_shutdown
,
4449 /* This needs to be called after all transports are initialized. */
4450 mutex_enter(&cpu_lock
);
4451 register_cpu_setup_func(ip_tp_cpu_update
, NULL
);
4452 mutex_exit(&cpu_lock
);
4456 * Initialize the IP stack instance.
4459 ip_stack_init(netstackid_t stackid
, netstack_t
*ns
)
4466 printf("ip_stack_init(stack %d)\n", stackid
);
4469 ipst
= (ip_stack_t
*)kmem_zalloc(sizeof (*ipst
), KM_SLEEP
);
4470 ipst
->ips_netstack
= ns
;
4472 ipst
->ips_ill_g_heads
= kmem_zalloc(sizeof (ill_g_head_t
) * MAX_G_HEADS
,
4474 ipst
->ips_phyint_g_list
= kmem_zalloc(sizeof (phyint_list_t
),
4476 ipst
->ips_ndp4
= kmem_zalloc(sizeof (ndp_g_t
), KM_SLEEP
);
4477 ipst
->ips_ndp6
= kmem_zalloc(sizeof (ndp_g_t
), KM_SLEEP
);
4478 mutex_init(&ipst
->ips_ndp4
->ndp_g_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4479 mutex_init(&ipst
->ips_ndp6
->ndp_g_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4481 mutex_init(&ipst
->ips_igmp_timer_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4482 ipst
->ips_igmp_deferred_next
= INFINITY
;
4483 mutex_init(&ipst
->ips_mld_timer_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4484 ipst
->ips_mld_deferred_next
= INFINITY
;
4485 mutex_init(&ipst
->ips_igmp_slowtimeout_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4486 mutex_init(&ipst
->ips_mld_slowtimeout_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4487 mutex_init(&ipst
->ips_ip_mi_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4488 mutex_init(&ipst
->ips_ip_addr_avail_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4489 rw_init(&ipst
->ips_ill_g_lock
, NULL
, RW_DEFAULT
, NULL
);
4490 rw_init(&ipst
->ips_ill_g_usesrc_lock
, NULL
, RW_DEFAULT
, NULL
);
4496 conn_drain_init(ipst
);
4497 ip_mrouter_stack_init(ipst
);
4498 dce_stack_init(ipst
);
4500 ipst
->ips_ill_index
= 1;
4502 ipst
->ips_saved_ip_forwarding
= -1;
4503 ipst
->ips_reg_vif_num
= ALL_VIFS
; /* Index to Register vif */
4505 arrsz
= ip_propinfo_count
* sizeof (mod_prop_info_t
);
4506 ipst
->ips_propinfo_tbl
= (mod_prop_info_t
*)kmem_alloc(arrsz
, KM_SLEEP
);
4507 bcopy(ip_propinfo_tbl
, ipst
->ips_propinfo_tbl
, arrsz
);
4509 ipst
->ips_ip_mibkp
= ip_kstat_init(stackid
, ipst
);
4510 ipst
->ips_icmp_mibkp
= icmp_kstat_init(stackid
);
4511 ipst
->ips_ip_kstat
= ip_kstat2_init(stackid
, &ipst
->ips_ip_statistics
);
4512 ipst
->ips_ip6_kstat
=
4513 ip6_kstat_init(stackid
, &ipst
->ips_ip6_statistics
);
4515 ipst
->ips_ip_src_id
= 1;
4516 rw_init(&ipst
->ips_srcid_lock
, NULL
, RW_DEFAULT
, NULL
);
4518 ipst
->ips_src_generation
= SRC_GENERATION_INITIAL
;
4520 ip_net_init(ipst
, ns
);
4521 ipv4_hook_init(ipst
);
4522 ipv6_hook_init(ipst
);
4523 arp_hook_init(ipst
);
4528 * Create the taskq dispatcher thread and initialize related stuff.
4530 mutex_init(&ipst
->ips_capab_taskq_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
4531 cv_init(&ipst
->ips_capab_taskq_cv
, NULL
, CV_DEFAULT
, NULL
);
4532 ipst
->ips_capab_taskq_thread
= thread_create(NULL
, 0,
4533 ill_taskq_dispatch
, ipst
, 0, &p0
, TS_RUN
, minclsyspri
);
4535 major
= mod_name_to_major(INET_NAME
);
4536 (void) ldi_ident_from_major(major
, &ipst
->ips_ldi_ident
);
4541 * Allocate and initialize a DLPI template of the specified length. (May be
4542 * called as writer.)
4545 ip_dlpi_alloc(size_t len
, t_uscalar_t prim
)
4549 mp
= allocb(len
, BPRI_MED
);
4554 * DLPIv2 says that DL_INFO_REQ and DL_TOKEN_REQ (the latter
4555 * of which we don't seem to use) are sent with M_PCPROTO, and
4556 * that other DLPI are M_PROTO.
4558 if (prim
== DL_INFO_REQ
) {
4559 mp
->b_datap
->db_type
= M_PCPROTO
;
4561 mp
->b_datap
->db_type
= M_PROTO
;
4564 mp
->b_wptr
= mp
->b_rptr
+ len
;
4565 bzero(mp
->b_rptr
, len
);
4566 ((dl_unitdata_req_t
*)mp
->b_rptr
)->dl_primitive
= prim
;
4571 * Allocate and initialize a DLPI notification. (May be called as writer.)
4574 ip_dlnotify_alloc(uint_t notification
, uint_t data
)
4576 dl_notify_ind_t
*notifyp
;
4579 if ((mp
= ip_dlpi_alloc(DL_NOTIFY_IND_SIZE
, DL_NOTIFY_IND
)) == NULL
)
4582 notifyp
= (dl_notify_ind_t
*)mp
->b_rptr
;
4583 notifyp
->dl_notification
= notification
;
4584 notifyp
->dl_data
= data
;
4589 ip_dlnotify_alloc2(uint_t notification
, uint_t data1
, uint_t data2
)
4591 dl_notify_ind_t
*notifyp
;
4594 if ((mp
= ip_dlpi_alloc(DL_NOTIFY_IND_SIZE
, DL_NOTIFY_IND
)) == NULL
)
4597 notifyp
= (dl_notify_ind_t
*)mp
->b_rptr
;
4598 notifyp
->dl_notification
= notification
;
4599 notifyp
->dl_data1
= data1
;
4600 notifyp
->dl_data2
= data2
;
4605 * Debug formatting routine. Returns a character string representation of the
4606 * addr in buf, of the form xxx.xxx.xxx.xxx. This routine takes the address
4607 * in the form of a ipaddr_t and calls ip_dot_saddr with a pointer.
4609 * Once the ndd table-printing interfaces are removed, this can be changed to
4610 * standard dotted-decimal form.
4613 ip_dot_addr(ipaddr_t addr
, char *buf
)
4615 uint8_t *ap
= (uint8_t *)&addr
;
4617 (void) mi_sprintf(buf
, "%03d.%03d.%03d.%03d",
4618 ap
[0] & 0xFF, ap
[1] & 0xFF, ap
[2] & 0xFF, ap
[3] & 0xFF);
4623 * Write the given MAC address as a printable string in the usual colon-
4627 mac_colon_addr(const uint8_t *addr
, size_t alen
, char *buf
, size_t buflen
)
4631 if (alen
== 0 || buflen
< 4)
4636 * If there are more MAC address bytes available, but we won't
4637 * have any room to print them, then add "..." to the string
4638 * instead. See below for the 'magic number' explanation.
4640 if ((alen
== 2 && buflen
< 6) || (alen
> 2 && buflen
< 7)) {
4641 (void) strcpy(bp
, "...");
4644 (void) sprintf(bp
, "%02x", *addr
++);
4651 * At this point, based on the first 'if' statement above,
4652 * either alen == 1 and buflen >= 3, or alen > 1 and
4653 * buflen >= 4. The first case leaves room for the final "xx"
4654 * number and trailing NUL byte. The second leaves room for at
4655 * least "...". Thus the apparently 'magic' numbers chosen for
4663 * Called when it is conceptually a ULP that would sent the packet
4664 * e.g., port unreachable and protocol unreachable. Check that the packet
4665 * would have passed the IPsec global policy before sending the error.
4667 * Send an ICMP error after patching up the packet appropriately.
4668 * Uses ip_drop_input and bumps the appropriate MIB.
4671 ip_fanout_send_icmp_v4(mblk_t
*mp
, uint_t icmp_type
, uint_t icmp_code
,
4672 ip_recv_attr_t
*ira
)
4676 ill_t
*ill
= ira
->ira_ill
;
4677 ip_stack_t
*ipst
= ill
->ill_ipst
;
4678 netstack_t
*ns
= ipst
->ips_netstack
;
4679 ipsec_stack_t
*ipss
= ns
->netstack_ipsec
;
4681 secure
= ira
->ira_flags
& IRAF_IPSEC_SECURE
;
4684 * We are generating an icmp error for some inbound packet.
4685 * Called from all ip_fanout_(udp, tcp, proto) functions.
4686 * Before we generate an error, check with global policy
4687 * to see whether this is allowed to enter the system. As
4688 * there is no "conn", we are checking with global policy.
4690 ipha
= (ipha_t
*)mp
->b_rptr
;
4691 if (secure
|| ipss
->ipsec_inbound_v4_policy_present
) {
4692 mp
= ipsec_check_global_policy(mp
, NULL
, ipha
, NULL
, ira
, ns
);
4697 /* We never send errors for protocols that we do implement */
4698 if (ira
->ira_protocol
== IPPROTO_ICMP
||
4699 ira
->ira_protocol
== IPPROTO_IGMP
) {
4700 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
4701 ip_drop_input("ip_fanout_send_icmp_v4", mp
, ill
);
4706 * Have to correct checksum since
4707 * the packet might have been
4708 * fragmented and the reassembly code in ip_rput
4709 * does not restore the IP checksum.
4711 ipha
->ipha_hdr_checksum
= 0;
4712 ipha
->ipha_hdr_checksum
= ip_csum_hdr(ipha
);
4714 switch (icmp_type
) {
4715 case ICMP_DEST_UNREACHABLE
:
4716 switch (icmp_code
) {
4717 case ICMP_PROTOCOL_UNREACHABLE
:
4718 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInUnknownProtos
);
4719 ip_drop_input("ipIfStatsInUnknownProtos", mp
, ill
);
4721 case ICMP_PORT_UNREACHABLE
:
4722 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsNoPorts
);
4723 ip_drop_input("ipIfStatsNoPorts", mp
, ill
);
4727 icmp_unreachable(mp
, icmp_code
, ira
);
4731 panic("ip_fanout_send_icmp_v4: wrong type");
4741 * Used to send an ICMP error message when a packet is received for
4742 * a protocol that is not supported. The mblk passed as argument
4743 * is consumed by this function.
4746 ip_proto_not_sup(mblk_t
*mp
, ip_recv_attr_t
*ira
)
4750 ipha
= (ipha_t
*)mp
->b_rptr
;
4751 if (ira
->ira_flags
& IRAF_IS_IPV4
) {
4752 ASSERT(IPH_HDR_VERSION(ipha
) == IP_VERSION
);
4753 ip_fanout_send_icmp_v4(mp
, ICMP_DEST_UNREACHABLE
,
4754 ICMP_PROTOCOL_UNREACHABLE
, ira
);
4756 ASSERT(IPH_HDR_VERSION(ipha
) == IPV6_VERSION
);
4757 ip_fanout_send_icmp_v6(mp
, ICMP6_PARAM_PROB
,
4758 ICMP6_PARAMPROB_NEXTHEADER
, ira
);
4763 * Deliver a rawip packet to the given conn, possibly applying ipsec policy.
4764 * Handles IPv4 and IPv6.
4765 * We are responsible for disposing of mp, such as by freemsg() or putnext()
4766 * Caller is responsible for dropping references to the conn.
4769 ip_fanout_proto_conn(conn_t
*connp
, mblk_t
*mp
, ipha_t
*ipha
, ip6_t
*ip6h
,
4770 ip_recv_attr_t
*ira
)
4772 ill_t
*ill
= ira
->ira_ill
;
4773 ip_stack_t
*ipst
= ill
->ill_ipst
;
4774 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
4776 uint_t protocol
= ira
->ira_protocol
;
4777 iaflags_t iraflags
= ira
->ira_flags
;
4780 secure
= iraflags
& IRAF_IPSEC_SECURE
;
4782 rq
= connp
->conn_rq
;
4783 if (IPCL_IS_NONSTR(connp
) ? connp
->conn_flow_cntrld
: !canputnext(rq
)) {
4785 case IPPROTO_ICMPV6
:
4786 BUMP_MIB(ill
->ill_icmp6_mib
, ipv6IfIcmpInOverflows
);
4789 BUMP_MIB(&ipst
->ips_icmp_mib
, icmpInOverflows
);
4792 BUMP_MIB(ill
->ill_ip_mib
, rawipIfStatsInOverflows
);
4799 ASSERT(!(IPCL_IS_IPTUN(connp
)));
4801 if (((iraflags
& IRAF_IS_IPV4
) ?
4802 CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) :
4803 CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
)) ||
4805 mp
= ipsec_check_inbound_policy(mp
, connp
, ipha
,
4808 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
4809 /* Note that mp is NULL */
4810 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
4815 if (iraflags
& IRAF_ICMP_ERROR
) {
4816 (connp
->conn_recvicmp
)(connp
, mp
, NULL
, ira
);
4818 ill_t
*rill
= ira
->ira_rill
;
4820 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
4821 ira
->ira_ill
= ira
->ira_rill
= NULL
;
4822 /* Send it upstream */
4823 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
4825 ira
->ira_rill
= rill
;
4830 * Handle protocols with which IP is less intimate. There
4831 * can be more than one stream bound to a particular
4832 * protocol. When this is the case, normally each one gets a copy
4833 * of any incoming packets.
4837 * Don't allow a secure packet going up a non-secure connection.
4838 * We don't allow this because
4840 * 1) Reply might go out in clear which will be dropped at
4842 * 2) If the reply goes out in clear it will give the
4843 * adversary enough information for getting the key in
4844 * most of the cases.
4846 * Moreover getting a secure packet when we expect clear
4847 * implies that SA's were added without checking for
4848 * policy on both ends. This should not happen once ISAKMP
4849 * is used to negotiate SAs as SAs will be added only after
4850 * verifying the policy.
4853 * Earlier in ip_input on a system with multiple shared-IP zones we
4854 * duplicate the multicast and broadcast packets and send them up
4855 * with each explicit zoneid that exists on that ill.
4856 * This means that here we can match the zoneid with SO_ALLZONES being special.
4859 ip_fanout_proto_v4(mblk_t
*mp
, ipha_t
*ipha
, ip_recv_attr_t
*ira
)
4863 conn_t
*connp
, *first_connp
, *next_connp
;
4865 ill_t
*ill
= ira
->ira_ill
;
4866 ip_stack_t
*ipst
= ill
->ill_ipst
;
4868 laddr
= ipha
->ipha_dst
;
4870 connfp
= &ipst
->ips_ipcl_proto_fanout_v4
[ira
->ira_protocol
];
4871 mutex_enter(&connfp
->connf_lock
);
4872 connp
= connfp
->connf_head
;
4874 if (connp
== NULL
) {
4876 * No one bound to these addresses. Is
4877 * there a client that wants all
4878 * unclaimed datagrams?
4880 mutex_exit(&connfp
->connf_lock
);
4881 ip_fanout_send_icmp_v4(mp
, ICMP_DEST_UNREACHABLE
,
4882 ICMP_PROTOCOL_UNREACHABLE
, ira
);
4886 ASSERT(IPCL_IS_NONSTR(connp
) || connp
->conn_rq
!= NULL
);
4888 CONN_INC_REF(connp
);
4889 first_connp
= connp
;
4890 connp
= connp
->conn_next
;
4893 while (connp
!= NULL
) {
4894 /* Note: IPCL_PROTO_MATCH includes conn_wantpacket */
4895 if (IPCL_PROTO_MATCH(connp
, ira
, ipha
))
4897 connp
= connp
->conn_next
;
4900 if (connp
== NULL
) {
4901 /* No more interested clients */
4902 connp
= first_connp
;
4905 if (((mp1
= dupmsg(mp
)) == NULL
) &&
4906 ((mp1
= copymsg(mp
)) == NULL
)) {
4907 /* Memory allocation failed */
4908 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
4909 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
4910 connp
= first_connp
;
4914 CONN_INC_REF(connp
);
4915 mutex_exit(&connfp
->connf_lock
);
4917 ip_fanout_proto_conn(connp
, mp1
, (ipha_t
*)mp1
->b_rptr
, NULL
,
4920 mutex_enter(&connfp
->connf_lock
);
4921 /* Follow the next pointer before releasing the conn. */
4922 next_connp
= connp
->conn_next
;
4923 CONN_DEC_REF(connp
);
4927 /* Last one. Send it upstream. */
4928 mutex_exit(&connfp
->connf_lock
);
4930 ip_fanout_proto_conn(connp
, mp
, ipha
, NULL
, ira
);
4932 CONN_DEC_REF(connp
);
4936 * If we have a IPsec NAT-Traversal packet, strip the zero-SPI or
4937 * pass it along to ESP if the SPI is non-zero. Returns the mblk if the mblk
4940 * One of three things can happen, all of which affect the passed-in mblk:
4942 * 1.) The packet is stock UDP and gets its zero-SPI stripped. Return mblk..
4944 * 2.) The packet is ESP-in-UDP, gets transformed into an equivalent
4945 * ESP packet, and is passed along to ESP for consumption. Return NULL.
4947 * 3.) The packet is an ESP-in-UDP Keepalive. Drop it and return NULL.
4950 zero_spi_check(mblk_t
*mp
, ip_recv_attr_t
*ira
)
4952 int shift
, plen
, iph_len
;
4958 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
4959 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
4961 ipha
= (ipha_t
*)mp
->b_rptr
;
4962 iph_len
= ira
->ira_ip_hdr_length
;
4963 plen
= ira
->ira_pktlen
;
4965 if (plen
- iph_len
- sizeof (udpha_t
) < sizeof (uint32_t)) {
4967 * Most likely a keepalive for the benefit of an intervening
4968 * NAT. These aren't for us, per se, so drop it.
4970 * RFC 3947/8 doesn't say for sure what to do for 2-3
4971 * byte packets (keepalives are 1-byte), but we'll drop them
4974 ip_drop_packet(mp
, B_TRUE
, ira
->ira_ill
,
4975 DROPPER(ipss
, ipds_esp_nat_t_ka
), &ipss
->ipsec_dropper
);
4979 if (MBLKL(mp
) < iph_len
+ sizeof (udpha_t
) + sizeof (*spi
)) {
4980 /* might as well pull it all up - it might be ESP. */
4981 if (!pullupmsg(mp
, -1)) {
4982 ip_drop_packet(mp
, B_TRUE
, ira
->ira_ill
,
4983 DROPPER(ipss
, ipds_esp_nomem
),
4984 &ipss
->ipsec_dropper
);
4988 ipha
= (ipha_t
*)mp
->b_rptr
;
4990 spi
= (uint32_t *)(mp
->b_rptr
+ iph_len
+ sizeof (udpha_t
));
4992 /* UDP packet - remove 0-spi. */
4993 shift
= sizeof (uint32_t);
4995 /* ESP-in-UDP packet - reduce to ESP. */
4996 ipha
->ipha_protocol
= IPPROTO_ESP
;
4997 shift
= sizeof (udpha_t
);
5001 ira
->ira_pktlen
= (plen
- shift
);
5002 ipha
->ipha_length
= htons(ira
->ira_pktlen
);
5003 ipha
->ipha_hdr_checksum
= 0;
5006 mp
->b_rptr
+= shift
;
5008 udpha
= (udpha_t
*)(orptr
+ iph_len
);
5010 ASSERT((uint8_t *)ipha
== orptr
);
5011 udpha
->uha_length
= htons(plen
- shift
- iph_len
);
5012 iph_len
+= sizeof (udpha_t
); /* For the call to ovbcopy(). */
5015 esp_ports
= *((uint32_t *)udpha
);
5016 ASSERT(esp_ports
!= 0);
5018 ovbcopy(orptr
, orptr
+ shift
, iph_len
);
5019 if (esp_ports
!= 0) /* Punt up for ESP processing. */ {
5020 ipha
= (ipha_t
*)(orptr
+ shift
);
5022 ira
->ira_flags
|= IRAF_ESP_UDP_PORTS
;
5023 ira
->ira_esp_udp_ports
= esp_ports
;
5024 ip_fanout_v4(mp
, ipha
, ira
);
5031 * Deliver a udp packet to the given conn, possibly applying ipsec policy.
5032 * Handles IPv4 and IPv6.
5033 * We are responsible for disposing of mp, such as by freemsg() or putnext()
5034 * Caller is responsible for dropping references to the conn.
5037 ip_fanout_udp_conn(conn_t
*connp
, mblk_t
*mp
, ipha_t
*ipha
, ip6_t
*ip6h
,
5038 ip_recv_attr_t
*ira
)
5040 ill_t
*ill
= ira
->ira_ill
;
5041 ip_stack_t
*ipst
= ill
->ill_ipst
;
5042 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
5044 iaflags_t iraflags
= ira
->ira_flags
;
5046 secure
= iraflags
& IRAF_IPSEC_SECURE
;
5048 if (IPCL_IS_NONSTR(connp
) ? connp
->conn_flow_cntrld
:
5049 !canputnext(connp
->conn_rq
)) {
5050 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsInOverflows
);
5055 if (((iraflags
& IRAF_IS_IPV4
) ?
5056 CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) :
5057 CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
)) ||
5059 mp
= ipsec_check_inbound_policy(mp
, connp
, ipha
,
5062 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
5063 /* Note that mp is NULL */
5064 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
5070 * Since this code is not used for UDP unicast we don't need a NAT_T
5071 * check. Only ip_fanout_v4 has that check.
5073 if (ira
->ira_flags
& IRAF_ICMP_ERROR
) {
5074 (connp
->conn_recvicmp
)(connp
, mp
, NULL
, ira
);
5076 ill_t
*rill
= ira
->ira_rill
;
5078 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
5079 ira
->ira_ill
= ira
->ira_rill
= NULL
;
5080 /* Send it upstream */
5081 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
5083 ira
->ira_rill
= rill
;
5088 * Fanout for UDP packets that are multicast or broadcast, and ICMP errors.
5089 * (Unicast fanout is handled in ip_input_v4.)
5091 * If SO_REUSEADDR is set all multicast and broadcast packets
5092 * will be delivered to all conns bound to the same port.
5094 * If there is at least one matching AF_INET receiver, then we will
5095 * ignore any AF_INET6 receivers.
5096 * In the special case where an AF_INET socket binds to 0.0.0.0/<port> and an
5097 * AF_INET6 socket binds to ::/<port>, only the AF_INET socket receives the IPv4
5101 * Earlier in ip_input on a system with multiple shared-IP zones we
5102 * duplicate the multicast and broadcast packets and send them up
5103 * with each explicit zoneid that exists on that ill.
5104 * This means that here we can match the zoneid with SO_ALLZONES being special.
5107 ip_fanout_udp_multi_v4(mblk_t
*mp
, ipha_t
*ipha
, uint16_t lport
, uint16_t fport
,
5108 ip_recv_attr_t
*ira
)
5115 ill_t
*ill
= ira
->ira_ill
;
5116 ip_stack_t
*ipst
= ill
->ill_ipst
;
5118 ASSERT(ira
->ira_flags
& (IRAF_MULTIBROADCAST
|IRAF_ICMP_ERROR
));
5120 laddr
= ipha
->ipha_dst
;
5121 faddr
= ipha
->ipha_src
;
5123 connfp
= &ipst
->ips_ipcl_udp_fanout
[IPCL_UDP_HASH(lport
, ipst
)];
5124 mutex_enter(&connfp
->connf_lock
);
5125 connp
= connfp
->connf_head
;
5128 * If SO_REUSEADDR has been set on the first we send the
5129 * packet to all clients that have joined the group and
5132 while (connp
!= NULL
) {
5133 if ((IPCL_UDP_MATCH(connp
, lport
, laddr
, fport
, faddr
)) &&
5134 conn_wantpacket(connp
, ira
, ipha
))
5136 connp
= connp
->conn_next
;
5142 CONN_INC_REF(connp
);
5144 if (connp
->conn_reuseaddr
) {
5145 conn_t
*first_connp
= connp
;
5149 connp
= connp
->conn_next
;
5151 while (connp
!= NULL
) {
5152 if (IPCL_UDP_MATCH(connp
, lport
, laddr
,
5154 conn_wantpacket(connp
, ira
, ipha
))
5156 connp
= connp
->conn_next
;
5158 if (connp
== NULL
) {
5159 /* No more interested clients */
5160 connp
= first_connp
;
5163 if (((mp1
= dupmsg(mp
)) == NULL
) &&
5164 ((mp1
= copymsg(mp
)) == NULL
)) {
5165 /* Memory allocation failed */
5166 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
5167 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
5168 connp
= first_connp
;
5171 CONN_INC_REF(connp
);
5172 mutex_exit(&connfp
->connf_lock
);
5174 IP_STAT(ipst
, ip_udp_fanmb
);
5175 ip_fanout_udp_conn(connp
, mp1
, (ipha_t
*)mp1
->b_rptr
,
5177 mutex_enter(&connfp
->connf_lock
);
5178 /* Follow the next pointer before releasing the conn */
5179 next_connp
= connp
->conn_next
;
5180 CONN_DEC_REF(connp
);
5185 /* Last one. Send it upstream. */
5186 mutex_exit(&connfp
->connf_lock
);
5187 IP_STAT(ipst
, ip_udp_fanmb
);
5188 ip_fanout_udp_conn(connp
, mp
, ipha
, NULL
, ira
);
5189 CONN_DEC_REF(connp
);
5193 mutex_exit(&connfp
->connf_lock
);
5195 * IPv6 endpoints bound to multicast IPv4-mapped addresses
5196 * have already been matched above, since they live in the IPv4
5197 * fanout tables. This implies we only need to
5198 * check for IPv6 in6addr_any endpoints here.
5199 * Thus we compare using ipv6_all_zeros instead of the destination
5200 * address, except for the multicast group membership lookup which
5201 * uses the IPv4 destination.
5203 IN6_IPADDR_TO_V4MAPPED(ipha
->ipha_src
, &v6faddr
);
5204 connfp
= &ipst
->ips_ipcl_udp_fanout
[IPCL_UDP_HASH(lport
, ipst
)];
5205 mutex_enter(&connfp
->connf_lock
);
5206 connp
= connfp
->connf_head
;
5208 * IPv4 multicast packet being delivered to an AF_INET6
5209 * in6addr_any endpoint.
5210 * Need to check conn_wantpacket(). Note that we use conn_wantpacket()
5211 * and not conn_wantpacket_v6() since any multicast membership is
5212 * for an IPv4-mapped multicast address.
5214 while (connp
!= NULL
) {
5215 if (IPCL_UDP_MATCH_V6(connp
, lport
, ipv6_all_zeros
,
5217 conn_wantpacket(connp
, ira
, ipha
))
5219 connp
= connp
->conn_next
;
5222 if (connp
== NULL
) {
5224 * No one bound to this port. Is
5225 * there a client that wants all
5226 * unclaimed datagrams?
5228 mutex_exit(&connfp
->connf_lock
);
5230 if (ipst
->ips_ipcl_proto_fanout_v4
[IPPROTO_UDP
].connf_head
!=
5232 ASSERT(ira
->ira_protocol
== IPPROTO_UDP
);
5233 ip_fanout_proto_v4(mp
, ipha
, ira
);
5236 * We used to attempt to send an icmp error here, but
5237 * since this is known to be a multicast packet
5238 * and we don't send icmp errors in response to
5239 * multicast, just drop the packet and give up sooner.
5241 BUMP_MIB(ill
->ill_ip_mib
, udpIfStatsNoPorts
);
5246 CONN_INC_REF(connp
);
5247 ASSERT(IPCL_IS_NONSTR(connp
) || connp
->conn_rq
!= NULL
);
5250 * If SO_REUSEADDR has been set on the first we send the
5251 * packet to all clients that have joined the group and
5254 if (connp
->conn_reuseaddr
) {
5255 conn_t
*first_connp
= connp
;
5259 connp
= connp
->conn_next
;
5261 while (connp
!= NULL
) {
5262 if (IPCL_UDP_MATCH_V6(connp
, lport
,
5263 ipv6_all_zeros
, fport
, v6faddr
) &&
5264 conn_wantpacket(connp
, ira
, ipha
))
5266 connp
= connp
->conn_next
;
5268 if (connp
== NULL
) {
5269 /* No more interested clients */
5270 connp
= first_connp
;
5273 if (((mp1
= dupmsg(mp
)) == NULL
) &&
5274 ((mp1
= copymsg(mp
)) == NULL
)) {
5275 /* Memory allocation failed */
5276 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
5277 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
5278 connp
= first_connp
;
5281 CONN_INC_REF(connp
);
5282 mutex_exit(&connfp
->connf_lock
);
5284 IP_STAT(ipst
, ip_udp_fanmb
);
5285 ip_fanout_udp_conn(connp
, mp1
, (ipha_t
*)mp1
->b_rptr
,
5287 mutex_enter(&connfp
->connf_lock
);
5288 /* Follow the next pointer before releasing the conn */
5289 next_connp
= connp
->conn_next
;
5290 CONN_DEC_REF(connp
);
5295 /* Last one. Send it upstream. */
5296 mutex_exit(&connfp
->connf_lock
);
5297 IP_STAT(ipst
, ip_udp_fanmb
);
5298 ip_fanout_udp_conn(connp
, mp
, ipha
, NULL
, ira
);
5299 CONN_DEC_REF(connp
);
5303 * Split an incoming packet's IPv4 options into options.
5304 * If 'allocate' is set it does memory allocation for the ip_pkt_t, including
5305 * clearing out any leftover options.
5306 * Otherwise it just makes ipp point into the packet.
5308 * Returns zero if ok; ENOMEM if the buffer couldn't be allocated.
5311 ip_find_hdr_v4(ipha_t
*ipha
, ip_pkt_t
*ipp
, boolean_t allocate
)
5318 ipp
->ipp_fields
|= IPPF_HOPLIMIT
| IPPF_TCLASS
| IPPF_ADDR
;
5319 ipp
->ipp_hoplimit
= ipha
->ipha_ttl
;
5320 ipp
->ipp_type_of_service
= ipha
->ipha_type_of_service
;
5321 IN6_IPADDR_TO_V4MAPPED(ipha
->ipha_dst
, &ipp
->ipp_addr
);
5324 * Get length (in 4 byte octets) of IP header options.
5326 totallen
= ipha
->ipha_version_and_hdr_length
-
5327 (uint8_t)((IP_VERSION
<< 4) + IP_SIMPLE_HDR_LENGTH_IN_WORDS
);
5329 if (totallen
== 0) {
5333 /* Clear out anything from a previous packet */
5334 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
5335 kmem_free(ipp
->ipp_ipv4_options
,
5336 ipp
->ipp_ipv4_options_len
);
5337 ipp
->ipp_ipv4_options
= NULL
;
5338 ipp
->ipp_ipv4_options_len
= 0;
5339 ipp
->ipp_fields
&= ~IPPF_IPV4_OPTIONS
;
5345 opt
= (uchar_t
*)&ipha
[1];
5349 if (totallen
!= 0) {
5350 ipp
->ipp_ipv4_options
= opt
;
5351 ipp
->ipp_ipv4_options_len
= totallen
;
5352 ipp
->ipp_fields
|= IPPF_IPV4_OPTIONS
;
5356 /* Just copy all of options */
5357 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
5358 if (totallen
== ipp
->ipp_ipv4_options_len
) {
5359 bcopy(opt
, ipp
->ipp_ipv4_options
, totallen
);
5362 kmem_free(ipp
->ipp_ipv4_options
,
5363 ipp
->ipp_ipv4_options_len
);
5364 ipp
->ipp_ipv4_options
= NULL
;
5365 ipp
->ipp_ipv4_options_len
= 0;
5366 ipp
->ipp_fields
&= ~IPPF_IPV4_OPTIONS
;
5371 ipp
->ipp_ipv4_options
= kmem_alloc(totallen
, KM_NOSLEEP
);
5372 if (ipp
->ipp_ipv4_options
== NULL
)
5374 ipp
->ipp_ipv4_options_len
= totallen
;
5375 ipp
->ipp_fields
|= IPPF_IPV4_OPTIONS
;
5376 bcopy(opt
, ipp
->ipp_ipv4_options
, totallen
);
5379 totallen
= ipha
->ipha_version_and_hdr_length
-
5380 (uint8_t)((IP_VERSION
<< 4) + IP_SIMPLE_HDR_LENGTH_IN_WORDS
);
5382 opt
= (uchar_t
*)&ipha
[1];
5387 * Efficient versions of lookup for an IRE when we only
5388 * match the address.
5389 * For RTF_REJECT or BLACKHOLE we return IRE_NOROUTE.
5390 * Does not handle multicast addresses.
5393 ip_type_v4(ipaddr_t addr
, ip_stack_t
*ipst
)
5398 ire
= ire_ftable_lookup_simple_v4(addr
, 0, ipst
, NULL
);
5399 ASSERT(ire
!= NULL
);
5400 if (ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))
5401 result
= IRE_NOROUTE
;
5403 result
= ire
->ire_type
;
5409 * Efficient versions of lookup for an IRE when we only
5410 * match the address.
5411 * For RTF_REJECT or BLACKHOLE we return IRE_NOROUTE.
5412 * Does not handle multicast addresses.
5415 ip_type_v6(const in6_addr_t
*addr
, ip_stack_t
*ipst
)
5420 ire
= ire_ftable_lookup_simple_v6(addr
, 0, ipst
, NULL
);
5421 ASSERT(ire
!= NULL
);
5422 if (ire
->ire_flags
& (RTF_REJECT
|RTF_BLACKHOLE
))
5423 result
= IRE_NOROUTE
;
5425 result
= ire
->ire_type
;
5431 * Nobody should be sending
5432 * packets up this stream
5435 ip_lrput(queue_t
*q
, mblk_t
*mp
)
5437 switch (mp
->b_datap
->db_type
) {
5440 if (*mp
->b_rptr
& FLUSHW
) {
5441 *mp
->b_rptr
&= ~FLUSHR
;
5450 /* Nobody should be sending packets down this stream */
5453 ip_lwput(queue_t
*q
, mblk_t
*mp
)
5459 * Move the first hop in any source route to ipha_dst and remove that part of
5460 * the source route. Called by other protocols. Errors in option formatting
5461 * are ignored - will be handled by ip_output_options. Return the final
5462 * destination (either ipha_dst or the last entry in a source route.)
5465 ip_massage_options(ipha_t
*ipha
, netstack_t
*ns
)
5473 ip_stack_t
*ipst
= ns
->netstack_ip
;
5475 ip2dbg(("ip_massage_options\n"));
5476 dst
= ipha
->ipha_dst
;
5477 for (optval
= ipoptp_first(&opts
, ipha
);
5478 optval
!= IPOPT_EOL
;
5479 optval
= ipoptp_next(&opts
)) {
5480 opt
= opts
.ipoptp_cur
;
5485 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
5486 ip1dbg(("ip_massage_options: bad src route\n"));
5489 optlen
= opts
.ipoptp_len
;
5490 off
= opt
[IPOPT_OFFSET
];
5493 if (optlen
< IP_ADDR_LEN
||
5494 off
> optlen
- IP_ADDR_LEN
) {
5495 /* End of source route */
5496 ip1dbg(("ip_massage_options: end of SR\n"));
5499 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
5500 ip1dbg(("ip_massage_options: next hop 0x%x\n",
5503 * Check if our address is present more than
5504 * once as consecutive hops in source route.
5505 * XXX verify per-interface ip_forwarding
5508 if (ip_type_v4(dst
, ipst
) == IRE_LOCAL
) {
5512 if (dst
== htonl(INADDR_LOOPBACK
)) {
5513 ip1dbg(("ip_massage_options: loopback addr in "
5514 "source route!\n"));
5518 * Update ipha_dst to be the first hop and remove the
5519 * first hop from the source route (by overwriting
5520 * part of the option with NOP options).
5522 ipha
->ipha_dst
= dst
;
5523 /* Put the last entry in dst */
5524 off
= ((optlen
- IP_ADDR_LEN
- 3) & ~(IP_ADDR_LEN
-1)) +
5526 bcopy(&opt
[off
], &dst
, IP_ADDR_LEN
);
5528 ip1dbg(("ip_massage_options: last hop 0x%x\n",
5530 /* Move down and overwrite */
5531 opt
[IP_ADDR_LEN
] = opt
[0];
5532 opt
[IP_ADDR_LEN
+1] = opt
[IPOPT_OLEN
] - IP_ADDR_LEN
;
5533 opt
[IP_ADDR_LEN
+2] = opt
[IPOPT_OFFSET
];
5534 for (i
= 0; i
< IP_ADDR_LEN
; i
++)
5543 * Return the network mask
5544 * associated with the specified address.
5547 ip_net_mask(ipaddr_t addr
)
5549 uchar_t
*up
= (uchar_t
*)&addr
;
5551 uchar_t
*maskp
= (uchar_t
*)&mask
;
5553 #if defined(__i386) || defined(__amd64)
5554 #define TOTALLY_BRAIN_DAMAGED_C_COMPILER
5556 #ifdef TOTALLY_BRAIN_DAMAGED_C_COMPILER
5557 maskp
[0] = maskp
[1] = maskp
[2] = maskp
[3] = 0;
5564 /* We assume Class E default netmask to be 32 */
5566 return (0xffffffffU
);
5571 if ((up
[0] & 0x80) == 0)
5575 if ((up
[0] & 0xC0) == 0x80)
5579 if ((up
[0] & 0xE0) == 0xC0)
5582 /* Otherwise return no mask */
5583 return ((ipaddr_t
)0);
5586 /* Name/Value Table Lookup Routine */
5588 ip_nv_lookup(nv_t
*nv
, int value
)
5592 for (; nv
->nv_name
; nv
++) {
5593 if (nv
->nv_value
== value
)
5594 return (nv
->nv_name
);
5600 ip_wait_for_info_ack(ill_t
*ill
)
5604 mutex_enter(&ill
->ill_lock
);
5605 while (ill
->ill_state_flags
& ILL_LL_SUBNET_PENDING
) {
5607 * Return value of 0 indicates a pending signal.
5609 err
= cv_wait_sig(&ill
->ill_cv
, &ill
->ill_lock
);
5611 mutex_exit(&ill
->ill_lock
);
5615 mutex_exit(&ill
->ill_lock
);
5617 * ip_rput_other could have set an error in ill_error on
5618 * receipt of M_ERROR.
5620 return (ill
->ill_error
);
5624 * This is a module open, i.e. this is a control stream for access
5625 * to a DLPI device. We allocate an ill_t as the instance data in
5629 ip_modopen(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
)
5638 * Prevent unprivileged processes from pushing IP so that
5639 * they can't send raw IP.
5641 if (secpolicy_net_rawaccess(credp
) != 0)
5644 ns
= netstack_find_by_cred(credp
);
5646 ipst
= ns
->netstack_ip
;
5647 ASSERT(ipst
!= NULL
);
5650 * For exclusive stacks we set the zoneid to zero
5651 * to make IP operate as if in the global zone.
5653 if (ipst
->ips_netstack
->netstack_stackid
!= GLOBAL_NETSTACKID
)
5654 zoneid
= GLOBAL_ZONEID
;
5656 zoneid
= crgetzoneid(credp
);
5658 ill
= (ill_t
*)mi_open_alloc_sleep(sizeof (ill_t
));
5659 q
->q_ptr
= WR(q
)->q_ptr
= ill
;
5660 ill
->ill_ipst
= ipst
;
5661 ill
->ill_zoneid
= zoneid
;
5664 * ill_init initializes the ill fields and then sends down
5665 * down a DL_INFO_REQ after calling qprocson.
5667 err
= ill_init(q
, ill
);
5671 netstack_rele(ipst
->ips_netstack
);
5673 WR(q
)->q_ptr
= NULL
;
5678 * Wait for the DL_INFO_ACK if a DL_INFO_REQ was sent.
5680 * ill_init initializes the ipsq marking this thread as
5683 ipsq_exit(ill
->ill_phyint
->phyint_ipsq
);
5684 err
= ip_wait_for_info_ack(ill
);
5686 ill
->ill_credp
= credp
;
5692 mutex_enter(&ipst
->ips_ip_mi_lock
);
5693 err
= mi_open_link(&ipst
->ips_ip_g_head
, (IDP
)q
->q_ptr
, devp
, flag
,
5695 mutex_exit(&ipst
->ips_ip_mi_lock
);
5698 (void) ip_close(q
, 0);
5704 /* For /dev/ip aka AF_INET open */
5706 ip_openv4(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
)
5708 return (ip_open(q
, devp
, flag
, sflag
, credp
, B_FALSE
));
5711 /* For /dev/ip6 aka AF_INET6 open */
5713 ip_openv6(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
)
5715 return (ip_open(q
, devp
, flag
, sflag
, credp
, B_TRUE
));
5718 /* IP open routine. */
5720 ip_open(queue_t
*q
, dev_t
*devp
, int flag
, int sflag
, cred_t
*credp
,
5730 if (q
->q_ptr
!= NULL
)
5733 if (sflag
& MODOPEN
) {
5734 /* This is a module open */
5735 return (ip_modopen(q
, devp
, flag
, sflag
, credp
));
5738 if ((flag
& ~(FKLYR
)) == IP_HELPER_STR
) {
5740 * Non streams based socket looking for a stream
5743 return (ip_helper_stream_setup(q
, devp
, flag
, sflag
,
5747 ns
= netstack_find_by_cred(credp
);
5749 ipst
= ns
->netstack_ip
;
5750 ASSERT(ipst
!= NULL
);
5753 * For exclusive stacks we set the zoneid to zero
5754 * to make IP operate as if in the global zone.
5756 if (ipst
->ips_netstack
->netstack_stackid
!= GLOBAL_NETSTACKID
)
5757 zoneid
= GLOBAL_ZONEID
;
5759 zoneid
= crgetzoneid(credp
);
5762 * We are opening as a device. This is an IP client stream, and we
5763 * allocate an conn_t as the instance data.
5765 connp
= ipcl_conn_create(IPCL_IPCCONN
, KM_SLEEP
, ipst
->ips_netstack
);
5768 * ipcl_conn_create did a netstack_hold. Undo the hold that was
5769 * done by netstack_find_by_cred()
5771 netstack_rele(ipst
->ips_netstack
);
5773 connp
->conn_ixa
->ixa_flags
|= IXAF_MULTICAST_LOOP
| IXAF_SET_ULP_CKSUM
;
5774 /* conn_allzones can not be set this early, hence no IPCL_ZONEID */
5775 connp
->conn_ixa
->ixa_zoneid
= zoneid
;
5776 connp
->conn_zoneid
= zoneid
;
5779 q
->q_ptr
= WR(q
)->q_ptr
= connp
;
5781 /* Minor tells us which /dev entry was opened */
5783 connp
->conn_family
= AF_INET6
;
5784 connp
->conn_ipversion
= IPV6_VERSION
;
5785 connp
->conn_ixa
->ixa_flags
&= ~IXAF_IS_IPV4
;
5786 connp
->conn_ixa
->ixa_src_preferences
= IPV6_PREFER_SRC_DEFAULT
;
5788 connp
->conn_family
= AF_INET
;
5789 connp
->conn_ipversion
= IPV4_VERSION
;
5790 connp
->conn_ixa
->ixa_flags
|= IXAF_IS_IPV4
;
5793 if ((ip_minor_arena_la
!= NULL
) && (flag
& SO_SOCKSTR
) &&
5794 ((connp
->conn_dev
= inet_minor_alloc(ip_minor_arena_la
)) != 0)) {
5795 connp
->conn_minor_arena
= ip_minor_arena_la
;
5798 * Either minor numbers in the large arena were exhausted
5799 * or a non socket application is doing the open.
5800 * Try to allocate from the small arena.
5802 if ((connp
->conn_dev
=
5803 inet_minor_alloc(ip_minor_arena_sa
)) == 0) {
5804 /* CONN_DEC_REF takes care of netstack_rele() */
5805 q
->q_ptr
= WR(q
)->q_ptr
= NULL
;
5806 CONN_DEC_REF(connp
);
5809 connp
->conn_minor_arena
= ip_minor_arena_sa
;
5812 maj
= getemajor(*devp
);
5813 *devp
= makedevice(maj
, (minor_t
)connp
->conn_dev
);
5816 * connp->conn_cred is crfree()ed in ipcl_conn_destroy()
5818 connp
->conn_cred
= credp
;
5819 connp
->conn_cpid
= curproc
->p_pid
;
5820 /* Cache things in ixa without an extra refhold */
5821 ASSERT(!(connp
->conn_ixa
->ixa_free_flags
& IXA_FREE_CRED
));
5822 connp
->conn_ixa
->ixa_cred
= connp
->conn_cred
;
5823 connp
->conn_ixa
->ixa_cpid
= connp
->conn_cpid
;
5826 * Handle IP_IOC_RTS_REQUEST and other ioctls which use conn_recv
5828 connp
->conn_recv
= ip_conn_input
;
5829 connp
->conn_recvicmp
= ip_conn_input_icmp
;
5831 crhold(connp
->conn_cred
);
5833 connp
->conn_zone_is_global
= (crgetzoneid(credp
) == GLOBAL_ZONEID
);
5836 connp
->conn_wq
= WR(q
);
5838 /* Non-zero default values */
5839 connp
->conn_ixa
->ixa_flags
|= IXAF_MULTICAST_LOOP
;
5842 * Make the conn globally visible to walkers
5844 ASSERT(connp
->conn_ref
== 1);
5845 mutex_enter(&connp
->conn_lock
);
5846 connp
->conn_state_flags
&= ~CONN_INCIPIENT
;
5847 mutex_exit(&connp
->conn_lock
);
5855 * Set IPsec policy from an ipsec_req_t. If the req is not "zero" and valid,
5856 * all of them are copied to the conn_t. If the req is "zero", the policy is
5857 * zeroed out. A "zero" policy has zero ipsr_{ah,req,self_encap}_req
5859 * We keep only the latest setting of the policy and thus policy setting
5860 * is not incremental/cumulative.
5862 * Requests to set policies with multiple alternative actions will
5863 * go through a different API.
5866 ipsec_set_req(cred_t
*cr
, conn_t
*connp
, ipsec_req_t
*req
)
5871 ipsec_act_t
*actp
= NULL
;
5873 ipsec_policy_head_t
*ph
;
5874 boolean_t is_pol_reset
, is_pol_inserted
= B_FALSE
;
5876 netstack_t
*ns
= connp
->conn_netstack
;
5877 ip_stack_t
*ipst
= ns
->netstack_ip
;
5878 ipsec_stack_t
*ipss
= ns
->netstack_ipsec
;
5880 #define REQ_MASK (IPSEC_PREF_REQUIRED|IPSEC_PREF_NEVER)
5883 * The IP_SEC_OPT option does not allow variable length parameters,
5884 * hence a request cannot be NULL.
5889 ah_req
= req
->ipsr_ah_req
;
5890 esp_req
= req
->ipsr_esp_req
;
5891 se_req
= req
->ipsr_self_encap_req
;
5893 /* Don't allow setting self-encap without one or more of AH/ESP. */
5894 if (se_req
!= 0 && esp_req
== 0 && ah_req
== 0)
5898 * Are we dealing with a request to reset the policy (i.e.
5901 is_pol_reset
= ((ah_req
& REQ_MASK
) == 0 &&
5902 (esp_req
& REQ_MASK
) == 0 &&
5903 (se_req
& REQ_MASK
) == 0);
5905 if (!is_pol_reset
) {
5907 * If we couldn't load IPsec, fail with "protocol
5909 * IPsec may not have been loaded for a request with zero
5910 * policies, so we don't fail in this case.
5912 mutex_enter(&ipss
->ipsec_loader_lock
);
5913 if (ipss
->ipsec_loader_state
!= IPSEC_LOADER_SUCCEEDED
) {
5914 mutex_exit(&ipss
->ipsec_loader_lock
);
5915 return (EPROTONOSUPPORT
);
5917 mutex_exit(&ipss
->ipsec_loader_lock
);
5920 * Test for valid requests. Invalid algorithms
5921 * need to be tested by IPsec code because new
5922 * algorithms can be added dynamically.
5924 if ((ah_req
& ~(REQ_MASK
|IPSEC_PREF_UNIQUE
)) != 0 ||
5925 (esp_req
& ~(REQ_MASK
|IPSEC_PREF_UNIQUE
)) != 0 ||
5926 (se_req
& ~(REQ_MASK
|IPSEC_PREF_UNIQUE
)) != 0) {
5931 * Only privileged users can issue these
5934 if (((ah_req
& IPSEC_PREF_NEVER
) ||
5935 (esp_req
& IPSEC_PREF_NEVER
) ||
5936 (se_req
& IPSEC_PREF_NEVER
)) &&
5937 secpolicy_ip_config(cr
, B_FALSE
) != 0) {
5942 * The IPSEC_PREF_REQUIRED and IPSEC_PREF_NEVER
5943 * are mutually exclusive.
5945 if (((ah_req
& REQ_MASK
) == REQ_MASK
) ||
5946 ((esp_req
& REQ_MASK
) == REQ_MASK
) ||
5947 ((se_req
& REQ_MASK
) == REQ_MASK
)) {
5948 /* Both of them are set */
5953 ASSERT(MUTEX_HELD(&connp
->conn_lock
));
5956 * If we have already cached policies in conn_connect(), don't
5957 * let them change now. We cache policies for connections
5958 * whose src,dst [addr, port] is known.
5960 if (connp
->conn_policy_cached
) {
5965 * We have a zero policies, reset the connection policy if already
5966 * set. This will cause the connection to inherit the
5967 * global policy, if any.
5970 if (connp
->conn_policy
!= NULL
) {
5971 IPPH_REFRELE(connp
->conn_policy
, ipst
->ips_netstack
);
5972 connp
->conn_policy
= NULL
;
5974 connp
->conn_in_enforce_policy
= B_FALSE
;
5975 connp
->conn_out_enforce_policy
= B_FALSE
;
5979 ph
= connp
->conn_policy
= ipsec_polhead_split(connp
->conn_policy
,
5980 ipst
->ips_netstack
);
5984 ipsec_actvec_from_req(req
, &actp
, &nact
, ipst
->ips_netstack
);
5989 * Always insert IPv4 policy entries, since they can also apply to
5990 * ipv6 sockets being used in ipv4-compat mode.
5992 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V4
,
5993 IPSEC_TYPE_INBOUND
, ns
))
5995 is_pol_inserted
= B_TRUE
;
5996 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V4
,
5997 IPSEC_TYPE_OUTBOUND
, ns
))
6001 * We're looking at a v6 socket, also insert the v6-specific
6004 if (connp
->conn_family
== AF_INET6
) {
6005 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V6
,
6006 IPSEC_TYPE_INBOUND
, ns
))
6008 if (!ipsec_polhead_insert(ph
, actp
, nact
, IPSEC_AF_V6
,
6009 IPSEC_TYPE_OUTBOUND
, ns
))
6013 ipsec_actvec_free(actp
, nact
);
6016 * If the requests need security, set enforce_policy.
6017 * If the requests are IPSEC_PREF_NEVER, one should
6018 * still set conn_out_enforce_policy so that ip_set_destination
6019 * marks the ip_xmit_attr_t appropriatly. This is needed so that
6020 * for connections that we don't cache policy in at connect time,
6021 * if global policy matches in ip_output_attach_policy, we
6022 * don't wrongly inherit global policy. Similarly, we need
6023 * to set conn_in_enforce_policy also so that we don't verify
6026 if ((ah_req
& REQ_MASK
) != 0 ||
6027 (esp_req
& REQ_MASK
) != 0 ||
6028 (se_req
& REQ_MASK
) != 0) {
6029 connp
->conn_in_enforce_policy
= B_TRUE
;
6030 connp
->conn_out_enforce_policy
= B_TRUE
;
6037 * Common memory-allocation-failure exit path.
6041 ipsec_actvec_free(actp
, nact
);
6042 if (is_pol_inserted
)
6043 ipsec_polhead_flush(ph
, ns
);
6048 * Set socket options for joining and leaving multicast groups.
6049 * Common to IPv4 and IPv6; inet6 indicates the type of socket.
6050 * The caller has already check that the option name is consistent with
6051 * the address family of the socket.
6054 ip_opt_set_multicast_group(conn_t
*connp
, t_scalar_t name
,
6055 uchar_t
*invalp
, boolean_t inet6
, boolean_t checkonly
)
6057 int *i1
= (int *)invalp
;
6059 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
6060 struct ip_mreq
*v4_mreqp
;
6061 struct ipv6_mreq
*v6_mreqp
;
6062 struct group_req
*greqp
;
6064 boolean_t done
= B_FALSE
;
6068 boolean_t mcast_opt
= B_TRUE
;
6069 mcast_record_t fmode
;
6070 int (*optfn
)(conn_t
*, boolean_t
, const in6_addr_t
*,
6071 ipaddr_t
, uint_t
, mcast_record_t
, const in6_addr_t
*);
6074 case IP_ADD_MEMBERSHIP
:
6075 case IPV6_JOIN_GROUP
:
6076 mcast_opt
= B_FALSE
;
6078 case MCAST_JOIN_GROUP
:
6079 fmode
= MODE_IS_EXCLUDE
;
6080 optfn
= ip_opt_add_group
;
6083 case IP_DROP_MEMBERSHIP
:
6084 case IPV6_LEAVE_GROUP
:
6085 mcast_opt
= B_FALSE
;
6087 case MCAST_LEAVE_GROUP
:
6088 fmode
= MODE_IS_INCLUDE
;
6089 optfn
= ip_opt_delete_group
;
6096 struct sockaddr_in
*sin
;
6097 struct sockaddr_in6
*sin6
;
6099 greqp
= (struct group_req
*)i1
;
6100 if (greqp
->gr_group
.ss_family
== AF_INET
) {
6101 sin
= (struct sockaddr_in
*)&(greqp
->gr_group
);
6102 IN6_INADDR_TO_V4MAPPED(&sin
->sin_addr
, &v6group
);
6105 return (EINVAL
); /* Not on INET socket */
6107 sin6
= (struct sockaddr_in6
*)&(greqp
->gr_group
);
6108 v6group
= sin6
->sin6_addr
;
6110 ifaddr
= INADDR_ANY
;
6111 ifindex
= greqp
->gr_interface
;
6113 v6_mreqp
= (struct ipv6_mreq
*)i1
;
6114 v6group
= v6_mreqp
->ipv6mr_multiaddr
;
6115 ifaddr
= INADDR_ANY
;
6116 ifindex
= v6_mreqp
->ipv6mr_interface
;
6118 v4_mreqp
= (struct ip_mreq
*)i1
;
6119 IN6_INADDR_TO_V4MAPPED(&v4_mreqp
->imr_multiaddr
, &v6group
);
6120 ifaddr
= (ipaddr_t
)v4_mreqp
->imr_interface
.s_addr
;
6125 * In the multirouting case, we need to replicate
6126 * the request on all interfaces that will take part
6127 * in replication. We do so because multirouting is
6128 * reflective, thus we will probably receive multi-
6129 * casts on those interfaces.
6131 if (IN6_IS_ADDR_V4MAPPED(&v6group
)) {
6134 IN6_V4MAPPED_TO_IPADDR(&v6group
, group
);
6136 ire
= ire_ftable_lookup_v4(group
, IP_HOST_MASK
, 0,
6137 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6138 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6140 ire
= ire_ftable_lookup_v6(&v6group
, &ipv6_all_ones
, 0,
6141 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6142 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6148 error
= optfn(connp
, checkonly
, &v6group
, ifaddr
, ifindex
,
6149 fmode
, &ipv6_all_zeros
);
6155 * Set socket options for joining and leaving multicast groups
6156 * for specific sources.
6157 * Common to IPv4 and IPv6; inet6 indicates the type of socket.
6158 * The caller has already check that the option name is consistent with
6159 * the address family of the socket.
6162 ip_opt_set_multicast_sources(conn_t
*connp
, t_scalar_t name
,
6163 uchar_t
*invalp
, boolean_t inet6
, boolean_t checkonly
)
6165 int *i1
= (int *)invalp
;
6166 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
6167 struct ip_mreq_source
*imreqp
;
6168 struct group_source_req
*gsreqp
;
6169 in6_addr_t v6group
, v6src
;
6172 boolean_t mcast_opt
= B_TRUE
;
6173 mcast_record_t fmode
;
6175 int (*optfn
)(conn_t
*, boolean_t
, const in6_addr_t
*,
6176 ipaddr_t
, uint_t
, mcast_record_t
, const in6_addr_t
*);
6179 case IP_BLOCK_SOURCE
:
6180 mcast_opt
= B_FALSE
;
6182 case MCAST_BLOCK_SOURCE
:
6183 fmode
= MODE_IS_EXCLUDE
;
6184 optfn
= ip_opt_add_group
;
6187 case IP_UNBLOCK_SOURCE
:
6188 mcast_opt
= B_FALSE
;
6190 case MCAST_UNBLOCK_SOURCE
:
6191 fmode
= MODE_IS_EXCLUDE
;
6192 optfn
= ip_opt_delete_group
;
6195 case IP_ADD_SOURCE_MEMBERSHIP
:
6196 mcast_opt
= B_FALSE
;
6198 case MCAST_JOIN_SOURCE_GROUP
:
6199 fmode
= MODE_IS_INCLUDE
;
6200 optfn
= ip_opt_add_group
;
6203 case IP_DROP_SOURCE_MEMBERSHIP
:
6204 mcast_opt
= B_FALSE
;
6206 case MCAST_LEAVE_SOURCE_GROUP
:
6207 fmode
= MODE_IS_INCLUDE
;
6208 optfn
= ip_opt_delete_group
;
6215 gsreqp
= (struct group_source_req
*)i1
;
6216 ifindex
= gsreqp
->gsr_interface
;
6217 if (gsreqp
->gsr_group
.ss_family
== AF_INET
) {
6218 struct sockaddr_in
*s
;
6219 s
= (struct sockaddr_in
*)&gsreqp
->gsr_group
;
6220 IN6_INADDR_TO_V4MAPPED(&s
->sin_addr
, &v6group
);
6221 s
= (struct sockaddr_in
*)&gsreqp
->gsr_source
;
6222 IN6_INADDR_TO_V4MAPPED(&s
->sin_addr
, &v6src
);
6224 struct sockaddr_in6
*s6
;
6227 return (EINVAL
); /* Not on INET socket */
6229 s6
= (struct sockaddr_in6
*)&gsreqp
->gsr_group
;
6230 v6group
= s6
->sin6_addr
;
6231 s6
= (struct sockaddr_in6
*)&gsreqp
->gsr_source
;
6232 v6src
= s6
->sin6_addr
;
6234 ifaddr
= INADDR_ANY
;
6236 imreqp
= (struct ip_mreq_source
*)i1
;
6237 IN6_INADDR_TO_V4MAPPED(&imreqp
->imr_multiaddr
, &v6group
);
6238 IN6_INADDR_TO_V4MAPPED(&imreqp
->imr_sourceaddr
, &v6src
);
6239 ifaddr
= (ipaddr_t
)imreqp
->imr_interface
.s_addr
;
6244 * Handle src being mapped INADDR_ANY by changing it to unspecified.
6246 if (IN6_IS_ADDR_V4MAPPED_ANY(&v6src
))
6247 v6src
= ipv6_all_zeros
;
6250 * In the multirouting case, we need to replicate
6251 * the request as noted in the mcast cases above.
6253 if (IN6_IS_ADDR_V4MAPPED(&v6group
)) {
6256 IN6_V4MAPPED_TO_IPADDR(&v6group
, group
);
6258 ire
= ire_ftable_lookup_v4(group
, IP_HOST_MASK
, 0,
6259 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6260 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6262 ire
= ire_ftable_lookup_v6(&v6group
, &ipv6_all_ones
, 0,
6263 IRE_HOST
| IRE_INTERFACE
, NULL
, ALL_ZONES
,
6264 MATCH_IRE_MASK
| MATCH_IRE_TYPE
, 0, ipst
, NULL
);
6268 return (optfn(connp
, checkonly
, &v6group
, ifaddr
, ifindex
,
6273 * Given a destination address and a pointer to where to put the information
6274 * this routine fills in the mtuinfo.
6275 * The socket must be connected.
6276 * For sctp conn_faddr is the primary address.
6279 ip_fill_mtuinfo(conn_t
*connp
, ip_xmit_attr_t
*ixa
, struct ip6_mtuinfo
*mtuinfo
)
6281 uint32_t pmtu
= IP_MAXPACKET
;
6284 if (IN6_IS_ADDR_UNSPECIFIED(&connp
->conn_faddr_v6
))
6287 /* In case we never sent or called ip_set_destination_v4/v6 */
6288 if (ixa
->ixa_ire
!= NULL
)
6289 pmtu
= ip_get_pmtu(ixa
);
6291 if (ixa
->ixa_flags
& IXAF_SCOPEID_SET
)
6292 scopeid
= ixa
->ixa_scopeid
;
6296 bzero(mtuinfo
, sizeof (*mtuinfo
));
6297 mtuinfo
->ip6m_addr
.sin6_family
= AF_INET6
;
6298 mtuinfo
->ip6m_addr
.sin6_port
= connp
->conn_fport
;
6299 mtuinfo
->ip6m_addr
.sin6_addr
= connp
->conn_faddr_v6
;
6300 mtuinfo
->ip6m_addr
.sin6_scope_id
= scopeid
;
6301 mtuinfo
->ip6m_mtu
= pmtu
;
6303 return (sizeof (struct ip6_mtuinfo
));
6307 * When the src multihoming is changed from weak to [strong, preferred]
6308 * ip_ire_rebind_walker is called to walk the list of all ire_t entries
6309 * and identify routes that were created by user-applications in the
6310 * unbound state (i.e., without RTA_IFP), and for which an ire_ill is not
6311 * currently defined. These routes are then 'rebound', i.e., their ire_ill
6312 * is selected by finding an interface route for the gateway.
6316 ip_ire_rebind_walker(ire_t
*ire
, void *notused
)
6318 if (!ire
->ire_unbound
|| ire
->ire_ill
!= NULL
)
6325 * When the src multihoming is changed from [strong, preferred] to weak,
6326 * ip_ire_unbind_walker is called to walk the list of all ire_t entries, and
6327 * set any entries that were created by user-applications in the unbound state
6328 * (i.e., without RTA_IFP) back to having a NULL ire_ill.
6332 ip_ire_unbind_walker(ire_t
*ire
, void *notused
)
6336 if (!ire
->ire_unbound
|| ire
->ire_ill
== NULL
)
6338 if (ire
->ire_ipversion
== IPV6_VERSION
) {
6339 new_ire
= ire_create_v6(&ire
->ire_addr_v6
, &ire
->ire_mask_v6
,
6340 &ire
->ire_gateway_addr_v6
, ire
->ire_type
, NULL
,
6341 ire
->ire_zoneid
, ire
->ire_flags
, ire
->ire_ipst
);
6343 new_ire
= ire_create((uchar_t
*)&ire
->ire_addr
,
6344 (uchar_t
*)&ire
->ire_mask
,
6345 (uchar_t
*)&ire
->ire_gateway_addr
, ire
->ire_type
, NULL
,
6346 ire
->ire_zoneid
, ire
->ire_flags
, ire
->ire_ipst
);
6348 if (new_ire
== NULL
)
6350 new_ire
->ire_unbound
= B_TRUE
;
6352 * The bound ire must first be deleted so that we don't return
6353 * the existing one on the attempt to add the unbound new_ire.
6356 new_ire
= ire_add(new_ire
);
6357 if (new_ire
!= NULL
)
6358 ire_refrele(new_ire
);
6362 * When the settings of ip*_strict_src_multihoming tunables are changed,
6363 * all cached routes need to be recomputed. This recomputation needs to be
6364 * done when going from weaker to stronger modes so that the cached ire
6365 * for the connection does not violate the current ip*_strict_src_multihoming
6366 * setting. It also needs to be done when going from stronger to weaker modes,
6367 * so that we fall back to matching on the longest-matching-route (as opposed
6368 * to a shorter match that may have been selected in the strong mode
6369 * to satisfy src_multihoming settings).
6371 * The cached ixa_ire entires for all conn_t entries are marked as
6372 * "verify" so that they will be recomputed for the next packet.
6375 conn_ire_revalidate(conn_t
*connp
, void *arg
)
6377 boolean_t isv6
= (boolean_t
)arg
;
6379 if ((isv6
&& connp
->conn_ipversion
!= IPV6_VERSION
) ||
6380 (!isv6
&& connp
->conn_ipversion
!= IPV4_VERSION
))
6382 connp
->conn_ixa
->ixa_ire_generation
= IRE_GENERATION_VERIFY
;
6386 * Handles both IPv4 and IPv6 reassembly - doing the out-of-order cases,
6387 * When an ipf is passed here for the first time, if
6388 * we already have in-order fragments on the queue, we convert from the fast-
6389 * path reassembly scheme to the hard-case scheme. From then on, additional
6390 * fragments are reassembled here. We keep track of the start and end offsets
6391 * of each piece, and the number of holes in the chain. When the hole count
6392 * goes to zero, we are done!
6394 * The ipf_count will be updated to account for any mblk(s) added (pointed to
6395 * by mp) or subtracted (freeb()ed dups), upon return the caller must update
6396 * ipfb_count and ill_frag_count by the difference of ipf_count before and
6397 * after the call to ip_reassemble().
6400 ip_reassemble(mblk_t
*mp
, ipf_t
*ipf
, uint_t start
, boolean_t more
, ill_t
*ill
,
6407 boolean_t incr_dups
= B_TRUE
;
6408 boolean_t offset_zero_seen
= B_FALSE
;
6409 boolean_t pkt_boundary_checked
= B_FALSE
;
6411 /* If start == 0 then ipf_nf_hdr_len has to be set. */
6412 ASSERT(start
!= 0 || ipf
->ipf_nf_hdr_len
!= 0);
6414 /* Add in byte count */
6415 ipf
->ipf_count
+= msg_len
;
6418 * We were part way through in-order reassembly, but now there
6419 * is a hole. We walk through messages already queued, and
6420 * mark them for hard case reassembly. We know that up till
6421 * now they were in order starting from offset zero.
6424 for (mp1
= ipf
->ipf_mp
->b_cont
; mp1
; mp1
= mp1
->b_cont
) {
6425 IP_REASS_SET_START(mp1
, offset
);
6427 ASSERT(ipf
->ipf_nf_hdr_len
!= 0);
6428 offset
= -ipf
->ipf_nf_hdr_len
;
6430 offset
+= mp1
->b_wptr
- mp1
->b_rptr
;
6431 IP_REASS_SET_END(mp1
, offset
);
6433 /* One hole at the end. */
6434 ipf
->ipf_hole_cnt
= 1;
6435 /* Brand it as a hard case, forever. */
6438 /* Walk through all the new pieces. */
6440 end
= start
+ (mp
->b_wptr
- mp
->b_rptr
);
6442 * If start is 0, decrease 'end' only for the first mblk of
6443 * the fragment. Otherwise 'end' can get wrong value in the
6444 * second pass of the loop if first mblk is exactly the
6445 * size of ipf_nf_hdr_len.
6447 if (start
== 0 && !offset_zero_seen
) {
6449 ASSERT(ipf
->ipf_nf_hdr_len
!= 0);
6450 end
-= ipf
->ipf_nf_hdr_len
;
6451 offset_zero_seen
= B_TRUE
;
6453 next_mp
= mp
->b_cont
;
6455 * We are checking to see if there is any interesing data
6456 * to process. If there isn't and the mblk isn't the
6457 * one which carries the unfragmentable header then we
6458 * drop it. It's possible to have just the unfragmentable
6459 * header come through without any data. That needs to be
6462 * If the assert at the top of this function holds then the
6463 * term "ipf->ipf_nf_hdr_len != 0" isn't needed. This code
6464 * is infrequently traveled enough that the test is left in
6465 * to protect against future code changes which break that
6468 if (start
== end
&& start
!= 0 && ipf
->ipf_nf_hdr_len
!= 0) {
6469 /* Empty. Blast it. */
6470 IP_REASS_SET_START(mp
, 0);
6471 IP_REASS_SET_END(mp
, 0);
6473 * If the ipf points to the mblk we are about to free,
6474 * update ipf to point to the next mblk (or NULL
6477 if (ipf
->ipf_mp
->b_cont
== mp
)
6478 ipf
->ipf_mp
->b_cont
= next_mp
;
6483 IP_REASS_SET_START(mp
, start
);
6484 IP_REASS_SET_END(mp
, end
);
6485 if (!ipf
->ipf_tail_mp
) {
6486 ipf
->ipf_tail_mp
= mp
;
6487 ipf
->ipf_mp
->b_cont
= mp
;
6488 if (start
== 0 || !more
) {
6489 ipf
->ipf_hole_cnt
= 1;
6491 * if the first fragment comes in more than one
6492 * mblk, this loop will be executed for each
6493 * mblk. Need to adjust hole count so exiting
6494 * this routine will leave hole count at 1.
6497 ipf
->ipf_hole_cnt
++;
6499 ipf
->ipf_hole_cnt
= 2;
6501 } else if (ipf
->ipf_last_frag_seen
&& !more
&&
6502 !pkt_boundary_checked
) {
6504 * We check datagram boundary only if this fragment
6505 * claims to be the last fragment and we have seen a
6506 * last fragment in the past too. We do this only
6507 * once for a given fragment.
6509 * start cannot be 0 here as fragments with start=0
6510 * and MF=0 gets handled as a complete packet. These
6511 * fragments should not reach here.
6514 if (start
+ msgdsize(mp
) !=
6515 IP_REASS_END(ipf
->ipf_tail_mp
)) {
6517 * We have two fragments both of which claim
6518 * to be the last fragment but gives conflicting
6519 * information about the whole datagram size.
6520 * Something fishy is going on. Drop the
6521 * fragment and free up the reassembly list.
6523 return (IP_REASS_FAILED
);
6527 * We shouldn't come to this code block again for this
6528 * particular fragment.
6530 pkt_boundary_checked
= B_TRUE
;
6533 /* New stuff at or beyond tail? */
6534 offset
= IP_REASS_END(ipf
->ipf_tail_mp
);
6535 if (start
>= offset
) {
6536 if (ipf
->ipf_last_frag_seen
) {
6537 /* current fragment is beyond last fragment */
6538 return (IP_REASS_FAILED
);
6540 /* Link it on end. */
6541 ipf
->ipf_tail_mp
->b_cont
= mp
;
6542 ipf
->ipf_tail_mp
= mp
;
6544 if (start
!= offset
)
6545 ipf
->ipf_hole_cnt
++;
6546 } else if (start
== offset
&& next_mp
== NULL
)
6547 ipf
->ipf_hole_cnt
--;
6550 mp1
= ipf
->ipf_mp
->b_cont
;
6551 offset
= IP_REASS_START(mp1
);
6552 /* New stuff at the front? */
6553 if (start
< offset
) {
6555 if (end
>= offset
) {
6556 /* Nailed the hole at the begining. */
6557 ipf
->ipf_hole_cnt
--;
6559 } else if (end
< offset
) {
6561 * A hole, stuff, and a hole where there used
6562 * to be just a hole.
6564 ipf
->ipf_hole_cnt
++;
6567 /* Check for overlap. */
6568 while (end
> offset
) {
6569 if (end
< IP_REASS_END(mp1
)) {
6570 mp
->b_wptr
-= end
- offset
;
6571 IP_REASS_SET_END(mp
, offset
);
6572 BUMP_MIB(ill
->ill_ip_mib
,
6573 ipIfStatsReasmPartDups
);
6576 /* Did we cover another hole? */
6578 IP_REASS_END(mp1
) !=
6579 IP_REASS_START(mp1
->b_cont
) &&
6580 end
>= IP_REASS_START(mp1
->b_cont
)) ||
6581 (!ipf
->ipf_last_frag_seen
&& !more
)) {
6582 ipf
->ipf_hole_cnt
--;
6585 if ((mp
->b_cont
= mp1
->b_cont
) == NULL
) {
6587 * After clipping out mp1, this guy
6588 * is now hanging off the end.
6590 ipf
->ipf_tail_mp
= mp
;
6592 IP_REASS_SET_START(mp1
, 0);
6593 IP_REASS_SET_END(mp1
, 0);
6594 /* Subtract byte count */
6595 ipf
->ipf_count
-= mp1
->b_datap
->db_lim
-
6596 mp1
->b_datap
->db_base
;
6598 BUMP_MIB(ill
->ill_ip_mib
,
6599 ipIfStatsReasmPartDups
);
6603 offset
= IP_REASS_START(mp1
);
6605 ipf
->ipf_mp
->b_cont
= mp
;
6609 * The new piece starts somewhere between the start of the head
6610 * and before the end of the tail.
6612 for (; mp1
; mp1
= mp1
->b_cont
) {
6613 offset
= IP_REASS_END(mp1
);
6614 if (start
< offset
) {
6615 if (end
<= offset
) {
6617 IP_REASS_SET_START(mp
, 0);
6618 IP_REASS_SET_END(mp
, 0);
6619 /* Subtract byte count */
6620 ipf
->ipf_count
-= mp
->b_datap
->db_lim
-
6621 mp
->b_datap
->db_base
;
6623 ipf
->ipf_num_dups
++;
6624 incr_dups
= B_FALSE
;
6627 BUMP_MIB(ill
->ill_ip_mib
,
6628 ipIfStatsReasmDuplicates
);
6632 * Trim redundant stuff off beginning of new
6635 IP_REASS_SET_START(mp
, offset
);
6636 mp
->b_rptr
+= offset
- start
;
6637 BUMP_MIB(ill
->ill_ip_mib
,
6638 ipIfStatsReasmPartDups
);
6642 * After trimming, this guy is now
6643 * hanging off the end.
6646 ipf
->ipf_tail_mp
= mp
;
6648 ipf
->ipf_hole_cnt
--;
6653 if (start
>= IP_REASS_START(mp1
->b_cont
))
6657 ipf
->ipf_hole_cnt
++;
6658 mp
->b_cont
= mp1
->b_cont
;
6661 offset
= IP_REASS_START(mp1
);
6662 if (end
>= offset
) {
6663 ipf
->ipf_hole_cnt
--;
6664 /* Check for overlap. */
6665 while (end
> offset
) {
6666 if (end
< IP_REASS_END(mp1
)) {
6667 mp
->b_wptr
-= end
- offset
;
6668 IP_REASS_SET_END(mp
, offset
);
6670 * TODO we might bump
6671 * this up twice if there is
6672 * overlap at both ends.
6674 BUMP_MIB(ill
->ill_ip_mib
,
6675 ipIfStatsReasmPartDups
);
6678 /* Did we cover another hole? */
6681 != IP_REASS_START(mp1
->b_cont
) &&
6683 IP_REASS_START(mp1
->b_cont
)) ||
6684 (!ipf
->ipf_last_frag_seen
&&
6686 ipf
->ipf_hole_cnt
--;
6689 if ((mp
->b_cont
= mp1
->b_cont
) ==
6692 * After clipping out mp1,
6693 * this guy is now hanging
6696 ipf
->ipf_tail_mp
= mp
;
6698 IP_REASS_SET_START(mp1
, 0);
6699 IP_REASS_SET_END(mp1
, 0);
6700 /* Subtract byte count */
6702 mp1
->b_datap
->db_lim
-
6703 mp1
->b_datap
->db_base
;
6705 BUMP_MIB(ill
->ill_ip_mib
,
6706 ipIfStatsReasmPartDups
);
6710 offset
= IP_REASS_START(mp1
);
6715 } while (start
= end
, mp
= next_mp
);
6717 /* Fragment just processed could be the last one. Remember this fact */
6719 ipf
->ipf_last_frag_seen
= B_TRUE
;
6721 /* Still got holes? */
6722 if (ipf
->ipf_hole_cnt
)
6723 return (IP_REASS_PARTIAL
);
6724 /* Clean up overloaded fields to avoid upstream disasters. */
6725 for (mp1
= ipf
->ipf_mp
->b_cont
; mp1
; mp1
= mp1
->b_cont
) {
6726 IP_REASS_SET_START(mp1
, 0);
6727 IP_REASS_SET_END(mp1
, 0);
6729 return (IP_REASS_COMPLETE
);
6733 * Fragmentation reassembly. Each ILL has a hash table for
6734 * queuing packets undergoing reassembly for all IPIFs
6735 * associated with the ILL. The hash is based on the packet
6736 * IP ident field. The ILL frag hash table was allocated
6737 * as a timer block at the time the ILL was created. Whenever
6738 * there is anything on the reassembly queue, the timer will
6739 * be running. Returns the reassembled packet if reassembly completes.
6742 ip_input_fragment(mblk_t
*mp
, ipha_t
*ipha
, ip_recv_attr_t
*ira
)
6744 uint32_t frag_offset_flags
;
6747 uint8_t proto
= ipha
->ipha_protocol
;
6762 uint8_t ecn_info
= 0;
6763 uint32_t packet_size
;
6764 boolean_t pruned
= B_FALSE
;
6765 ill_t
*ill
= ira
->ira_ill
;
6766 ip_stack_t
*ipst
= ill
->ill_ipst
;
6769 * Drop the fragmented as early as possible, if
6770 * we don't have resource(s) to re-assemble.
6772 if (ipst
->ips_ip_reass_queue_bytes
== 0) {
6777 /* Check for fragmentation offset; return if there's none */
6778 if ((frag_offset_flags
= ntohs(ipha
->ipha_fragment_offset_and_flags
) &
6779 (IPH_MF
| IPH_OFFSET
)) == 0)
6783 * We utilize hardware computed checksum info only for UDP since
6784 * IP fragmentation is a normal occurrence for the protocol. In
6785 * addition, checksum offload support for IP fragments carrying
6786 * UDP payload is commonly implemented across network adapters.
6788 ASSERT(ira
->ira_rill
!= NULL
);
6789 if (proto
== IPPROTO_UDP
&& dohwcksum
&&
6790 ILL_HCKSUM_CAPABLE(ira
->ira_rill
) &&
6791 (DB_CKSUMFLAGS(mp
) & (HCK_FULLCKSUM
| HCK_PARTIALCKSUM
))) {
6792 mblk_t
*mp1
= mp
->b_cont
;
6795 /* Record checksum information from the packet */
6796 sum_val
= (uint32_t)DB_CKSUM16(mp
);
6797 sum_flags
= DB_CKSUMFLAGS(mp
);
6799 /* IP payload offset from beginning of mblk */
6800 offset
= ((uchar_t
*)ipha
+ IPH_HDR_LENGTH(ipha
)) - mp
->b_rptr
;
6802 if ((sum_flags
& HCK_PARTIALCKSUM
) &&
6803 (mp1
== NULL
|| mp1
->b_cont
== NULL
) &&
6804 offset
>= DB_CKSUMSTART(mp
) &&
6805 ((len
= offset
- DB_CKSUMSTART(mp
)) & 1) == 0) {
6808 * Partial checksum has been calculated by hardware
6809 * and attached to the packet; in addition, any
6810 * prepended extraneous data is even byte aligned.
6811 * If any such data exists, we adjust the checksum;
6812 * this would also handle any postpended data.
6814 IP_ADJCKSUM_PARTIAL(mp
->b_rptr
+ DB_CKSUMSTART(mp
),
6817 /* One's complement subtract extraneous checksum */
6819 sum_val
= ~(adj
- sum_val
) & 0xFFFF;
6828 /* Clear hardware checksumming flag */
6829 DB_CKSUMFLAGS(mp
) = 0;
6831 ident
= ipha
->ipha_ident
;
6832 offset
= (frag_offset_flags
<< 3) & 0xFFFF;
6833 src
= ipha
->ipha_src
;
6834 dst
= ipha
->ipha_dst
;
6835 hdr_length
= IPH_HDR_LENGTH(ipha
);
6836 end
= ntohs(ipha
->ipha_length
) - hdr_length
;
6838 /* If end == 0 then we have a packet with no data, so just free it */
6844 /* Record the ECN field info. */
6845 ecn_info
= (ipha
->ipha_type_of_service
& 0x3);
6848 * If this isn't the first piece, strip the header, and
6849 * add the offset to the end value.
6851 mp
->b_rptr
+= hdr_length
;
6855 /* Handle vnic loopback of fragments */
6856 if (mp
->b_datap
->db_ref
> 2)
6859 msg_len
= MBLKSIZE(mp
);
6862 while (tail_mp
->b_cont
!= NULL
) {
6863 tail_mp
= tail_mp
->b_cont
;
6864 if (tail_mp
->b_datap
->db_ref
<= 2)
6865 msg_len
+= MBLKSIZE(tail_mp
);
6868 /* If the reassembly list for this ILL will get too big, prune it */
6869 if ((msg_len
+ sizeof (*ipf
) + ill
->ill_frag_count
) >=
6870 ipst
->ips_ip_reass_queue_bytes
) {
6871 DTRACE_PROBE3(ip_reass_queue_bytes
, uint_t
, msg_len
,
6872 uint_t
, ill
->ill_frag_count
,
6873 uint_t
, ipst
->ips_ip_reass_queue_bytes
);
6875 (ipst
->ips_ip_reass_queue_bytes
< msg_len
) ? 0 :
6876 (ipst
->ips_ip_reass_queue_bytes
- msg_len
));
6880 ipfb
= &ill
->ill_frag_hash_tbl
[ILL_FRAG_HASH(src
, ident
)];
6881 mutex_enter(&ipfb
->ipfb_lock
);
6883 ipfp
= &ipfb
->ipfb_ipf
;
6884 /* Try to find an existing fragment queue for this packet. */
6889 * It has to match on ident and src/dst address.
6891 if (ipf
->ipf_ident
== ident
&&
6892 ipf
->ipf_src
== src
&&
6893 ipf
->ipf_dst
== dst
&&
6894 ipf
->ipf_protocol
== proto
) {
6896 * If we have received too many
6897 * duplicate fragments for this packet
6900 if (ipf
->ipf_num_dups
> ip_max_frag_dups
) {
6901 ill_frag_free_pkts(ill
, ipfb
, ipf
, 1);
6903 mutex_exit(&ipfb
->ipfb_lock
);
6909 ipfp
= &ipf
->ipf_hash_next
;
6914 * If we pruned the list, do we want to store this new
6915 * fragment?. We apply an optimization here based on the
6916 * fact that most fragments will be received in order.
6917 * So if the offset of this incoming fragment is zero,
6918 * it is the first fragment of a new packet. We will
6919 * keep it. Otherwise drop the fragment, as we have
6920 * probably pruned the packet already (since the
6921 * packet cannot be found).
6923 if (pruned
&& offset
!= 0) {
6924 mutex_exit(&ipfb
->ipfb_lock
);
6929 if (ipfb
->ipfb_frag_pkts
>= MAX_FRAG_PKTS(ipst
)) {
6931 * Too many fragmented packets in this hash
6932 * bucket. Free the oldest.
6934 ill_frag_free_pkts(ill
, ipfb
, ipfb
->ipfb_ipf
, 1);
6937 /* New guy. Allocate a frag message. */
6938 mp1
= allocb(sizeof (*ipf
), BPRI_MED
);
6940 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
6941 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
6944 mutex_exit(&ipfb
->ipfb_lock
);
6948 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmReqds
);
6951 /* Initialize the fragment header. */
6952 ipf
= (ipf_t
*)mp1
->b_rptr
;
6954 ipf
->ipf_ptphn
= ipfp
;
6956 ipf
->ipf_hash_next
= NULL
;
6957 ipf
->ipf_ident
= ident
;
6958 ipf
->ipf_protocol
= proto
;
6961 ipf
->ipf_nf_hdr_len
= 0;
6962 /* Record reassembly start time. */
6963 ipf
->ipf_timestamp
= gethrestime_sec();
6964 /* Record ipf generation and account for frag header */
6965 ipf
->ipf_gen
= ill
->ill_ipf_gen
++;
6966 ipf
->ipf_count
= MBLKSIZE(mp1
);
6967 ipf
->ipf_last_frag_seen
= B_FALSE
;
6968 ipf
->ipf_ecn
= ecn_info
;
6969 ipf
->ipf_num_dups
= 0;
6970 ipfb
->ipfb_frag_pkts
++;
6971 ipf
->ipf_checksum
= 0;
6972 ipf
->ipf_checksum_flags
= 0;
6974 /* Store checksum value in fragment header */
6975 if (sum_flags
!= 0) {
6976 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
6977 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
6978 ipf
->ipf_checksum
= sum_val
;
6979 ipf
->ipf_checksum_flags
= sum_flags
;
6983 * We handle reassembly two ways. In the easy case,
6984 * where all the fragments show up in order, we do
6985 * minimal bookkeeping, and just clip new pieces on
6986 * the end. If we ever see a hole, then we go off
6987 * to ip_reassemble which has to mark the pieces and
6988 * keep track of the number of holes, etc. Obviously,
6989 * the point of having both mechanisms is so we can
6990 * handle the easy case as efficiently as possible.
6993 /* Easy case, in-order reassembly so far. */
6994 ipf
->ipf_count
+= msg_len
;
6995 ipf
->ipf_tail_mp
= tail_mp
;
6997 * Keep track of next expected offset in
7001 ipf
->ipf_nf_hdr_len
= hdr_length
;
7003 /* Hard case, hole at the beginning. */
7004 ipf
->ipf_tail_mp
= NULL
;
7006 * ipf_end == 0 means that we have given up
7007 * on easy reassembly.
7011 /* Forget checksum offload from now on */
7012 ipf
->ipf_checksum_flags
= 0;
7015 * ipf_hole_cnt is set by ip_reassemble.
7016 * ipf_count is updated by ip_reassemble.
7017 * No need to check for return value here
7018 * as we don't expect reassembly to complete
7019 * or fail for the first fragment itself.
7021 (void) ip_reassemble(mp
, ipf
,
7022 (frag_offset_flags
& IPH_OFFSET
) << 3,
7023 (frag_offset_flags
& IPH_MF
), ill
, msg_len
);
7025 /* Update per ipfb and ill byte counts */
7026 ipfb
->ipfb_count
+= ipf
->ipf_count
;
7027 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
7028 atomic_add_32(&ill
->ill_frag_count
, ipf
->ipf_count
);
7029 /* If the frag timer wasn't already going, start it. */
7030 mutex_enter(&ill
->ill_lock
);
7031 ill_frag_timer_start(ill
);
7032 mutex_exit(&ill
->ill_lock
);
7037 * If the packet's flag has changed (it could be coming up
7038 * from an interface different than the previous, therefore
7039 * possibly different checksum capability), then forget about
7040 * any stored checksum states. Otherwise add the value to
7041 * the existing one stored in the fragment header.
7043 if (sum_flags
!= 0 && sum_flags
== ipf
->ipf_checksum_flags
) {
7044 sum_val
+= ipf
->ipf_checksum
;
7045 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
7046 sum_val
= (sum_val
& 0xFFFF) + (sum_val
>> 16);
7047 ipf
->ipf_checksum
= sum_val
;
7048 } else if (ipf
->ipf_checksum_flags
!= 0) {
7049 /* Forget checksum offload from now on */
7050 ipf
->ipf_checksum_flags
= 0;
7054 * We have a new piece of a datagram which is already being
7055 * reassembled. Update the ECN info if all IP fragments
7056 * are ECN capable. If there is one which is not, clear
7057 * all the info. If there is at least one which has CE
7058 * code point, IP needs to report that up to transport.
7060 if (ecn_info
!= IPH_ECN_NECT
&& ipf
->ipf_ecn
!= IPH_ECN_NECT
) {
7061 if (ecn_info
== IPH_ECN_CE
)
7062 ipf
->ipf_ecn
= IPH_ECN_CE
;
7064 ipf
->ipf_ecn
= IPH_ECN_NECT
;
7066 if (offset
&& ipf
->ipf_end
== offset
) {
7067 /* The new fragment fits at the end */
7068 ipf
->ipf_tail_mp
->b_cont
= mp
;
7069 /* Update the byte count */
7070 ipf
->ipf_count
+= msg_len
;
7071 /* Update per ipfb and ill byte counts */
7072 ipfb
->ipfb_count
+= msg_len
;
7073 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
7074 atomic_add_32(&ill
->ill_frag_count
, msg_len
);
7075 if (frag_offset_flags
& IPH_MF
) {
7078 ipf
->ipf_tail_mp
= tail_mp
;
7082 /* Go do the hard cases. */
7086 ipf
->ipf_nf_hdr_len
= hdr_length
;
7088 /* Save current byte count */
7089 count
= ipf
->ipf_count
;
7090 ret
= ip_reassemble(mp
, ipf
,
7091 (frag_offset_flags
& IPH_OFFSET
) << 3,
7092 (frag_offset_flags
& IPH_MF
), ill
, msg_len
);
7093 /* Count of bytes added and subtracted (freeb()ed) */
7094 count
= ipf
->ipf_count
- count
;
7096 /* Update per ipfb and ill byte counts */
7097 ipfb
->ipfb_count
+= count
;
7098 ASSERT(ipfb
->ipfb_count
> 0); /* Wraparound */
7099 atomic_add_32(&ill
->ill_frag_count
, count
);
7101 if (ret
== IP_REASS_PARTIAL
) {
7103 } else if (ret
== IP_REASS_FAILED
) {
7104 /* Reassembly failed. Free up all resources */
7105 ill_frag_free_pkts(ill
, ipfb
, ipf
, 1);
7106 for (t_mp
= mp
; t_mp
!= NULL
; t_mp
= t_mp
->b_cont
) {
7107 IP_REASS_SET_START(t_mp
, 0);
7108 IP_REASS_SET_END(t_mp
, 0);
7113 /* We will reach here iff 'ret' is IP_REASS_COMPLETE */
7116 * We have completed reassembly. Unhook the frag header from
7117 * the reassembly list.
7119 * Before we free the frag header, record the ECN info
7120 * to report back to the transport.
7122 ecn_info
= ipf
->ipf_ecn
;
7123 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsReasmOKs
);
7124 ipfp
= ipf
->ipf_ptphn
;
7126 /* We need to supply these to caller */
7127 if ((sum_flags
= ipf
->ipf_checksum_flags
) != 0)
7128 sum_val
= ipf
->ipf_checksum
;
7133 count
= ipf
->ipf_count
;
7134 ipf
= ipf
->ipf_hash_next
;
7136 ipf
->ipf_ptphn
= ipfp
;
7138 atomic_add_32(&ill
->ill_frag_count
, -count
);
7139 ASSERT(ipfb
->ipfb_count
>= count
);
7140 ipfb
->ipfb_count
-= count
;
7141 ipfb
->ipfb_frag_pkts
--;
7142 mutex_exit(&ipfb
->ipfb_lock
);
7143 /* Ditch the frag header. */
7148 /* Restore original IP length in header. */
7149 packet_size
= (uint32_t)msgdsize(mp
);
7150 if (packet_size
> IP_MAXPACKET
) {
7151 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7152 ip_drop_input("Reassembled packet too large", mp
, ill
);
7157 if (DB_REF(mp
) > 1) {
7158 mblk_t
*mp2
= copymsg(mp
);
7161 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7162 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7169 ipha
= (ipha_t
*)mp
->b_rptr
;
7171 ipha
->ipha_length
= htons((uint16_t)packet_size
);
7172 /* We're now complete, zip the frag state */
7173 ipha
->ipha_fragment_offset_and_flags
= 0;
7174 /* Record the ECN info. */
7175 ipha
->ipha_type_of_service
&= 0xFC;
7176 ipha
->ipha_type_of_service
|= ecn_info
;
7178 /* Update the receive attributes */
7179 ira
->ira_pktlen
= packet_size
;
7180 ira
->ira_ip_hdr_length
= IPH_HDR_LENGTH(ipha
);
7182 /* Reassembly is successful; set checksum information in packet */
7183 DB_CKSUM16(mp
) = (uint16_t)sum_val
;
7184 DB_CKSUMFLAGS(mp
) = sum_flags
;
7185 DB_CKSUMSTART(mp
) = ira
->ira_ip_hdr_length
;
7191 * Pullup function that should be used for IP input in order to
7192 * ensure we do not loose the L2 source address; we need the l2 source
7193 * address for IP_RECVSLLA and for ndp_input.
7195 * We return either NULL or b_rptr.
7198 ip_pullup(mblk_t
*mp
, ssize_t len
, ip_recv_attr_t
*ira
)
7200 ill_t
*ill
= ira
->ira_ill
;
7202 if (ip_rput_pullups
++ == 0) {
7203 (void) mi_strlog(ill
->ill_rq
, 1, SL_ERROR
|SL_TRACE
,
7204 "ip_pullup: %s forced us to "
7205 " pullup pkt, hdr len %ld, hdr addr %p",
7206 ill
->ill_name
, len
, (void *)mp
->b_rptr
);
7208 if (!(ira
->ira_flags
& IRAF_L2SRC_SET
))
7209 ip_setl2src(mp
, ira
, ira
->ira_rill
);
7210 ASSERT(ira
->ira_flags
& IRAF_L2SRC_SET
);
7211 if (!pullupmsg(mp
, len
))
7214 return (mp
->b_rptr
);
7218 * Make sure ira_l2src has an address. If we don't have one fill with zeros.
7219 * When called from the ULP ira_rill will be NULL hence the caller has to
7224 ip_setl2src(mblk_t
*mp
, ip_recv_attr_t
*ira
, ill_t
*ill
)
7226 const uchar_t
*addr
;
7229 if (ira
->ira_flags
& IRAF_L2SRC_SET
)
7232 ASSERT(ill
!= NULL
);
7233 alen
= ill
->ill_phys_addr_length
;
7234 ASSERT(alen
<= sizeof (ira
->ira_l2src
));
7235 if (ira
->ira_mhip
!= NULL
&&
7236 (addr
= ira
->ira_mhip
->mhi_saddr
) != NULL
) {
7237 bcopy(addr
, ira
->ira_l2src
, alen
);
7238 } else if ((ira
->ira_flags
& IRAF_L2SRC_LOOPBACK
) &&
7239 (addr
= ill
->ill_phys_addr
) != NULL
) {
7240 bcopy(addr
, ira
->ira_l2src
, alen
);
7242 bzero(ira
->ira_l2src
, alen
);
7244 ira
->ira_flags
|= IRAF_L2SRC_SET
;
7248 * check ip header length and align it.
7251 ip_check_and_align_header(mblk_t
*mp
, uint_t min_size
, ip_recv_attr_t
*ira
)
7253 ill_t
*ill
= ira
->ira_ill
;
7258 if (!OK_32PTR(mp
->b_rptr
))
7259 IP_STAT(ill
->ill_ipst
, ip_notaligned
);
7261 IP_STAT(ill
->ill_ipst
, ip_recv_pullup
);
7263 /* Guard against bogus device drivers */
7265 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7266 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7272 /* GLD sometimes sends up mblk with b_rptr == b_wptr! */
7273 mblk_t
*mp1
= mp
->b_cont
;
7275 if (!(ira
->ira_flags
& IRAF_L2SRC_SET
))
7276 ip_setl2src(mp
, ira
, ira
->ira_rill
);
7277 ASSERT(ira
->ira_flags
& IRAF_L2SRC_SET
);
7284 if (OK_32PTR(mp
->b_rptr
) && MBLKL(mp
) >= min_size
)
7287 if (ip_pullup(mp
, min_size
, ira
) == NULL
) {
7288 if (msgdsize(mp
) < min_size
) {
7289 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7290 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7292 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7293 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7302 * Common code for IPv4 and IPv6 to check and pullup multi-mblks
7305 ip_check_length(mblk_t
*mp
, uchar_t
*rptr
, ssize_t len
, uint_t pkt_len
,
7306 uint_t min_size
, ip_recv_attr_t
*ira
)
7308 ill_t
*ill
= ira
->ira_ill
;
7311 * Make sure we have data length consistent
7312 * with the IP header.
7314 if (mp
->b_cont
== NULL
) {
7315 /* pkt_len is based on ipha_len, not the mblk length */
7316 if (pkt_len
< min_size
) {
7317 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7318 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7323 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
7324 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
7329 mp
->b_wptr
= rptr
+ pkt_len
;
7330 } else if ((len
+= msgdsize(mp
->b_cont
)) != 0) {
7331 ASSERT(pkt_len
>= min_size
);
7332 if (pkt_len
< min_size
) {
7333 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7334 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7339 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInTruncatedPkts
);
7340 ip_drop_input("ipIfStatsInTruncatedPkts", mp
, ill
);
7345 (void) adjmsg(mp
, -len
);
7347 * adjmsg may have freed an mblk from the chain, hence
7348 * invalidate any hw checksum here. This will force IP to
7349 * calculate the checksum in sw, but only for this packet.
7351 DB_CKSUMFLAGS(mp
) = 0;
7352 IP_STAT(ill
->ill_ipst
, ip_multimblk
);
7358 * Check that the IPv4 opt_len is consistent with the packet and pullup
7362 ip_check_optlen(mblk_t
*mp
, ipha_t
*ipha
, uint_t opt_len
, uint_t pkt_len
,
7363 ip_recv_attr_t
*ira
)
7365 ill_t
*ill
= ira
->ira_ill
;
7368 /* Assume no IPv6 packets arrive over the IPv4 queue */
7369 if (IPH_HDR_VERSION(ipha
) != IPV4_VERSION
) {
7370 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7371 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInWrongIPVersion
);
7372 ip_drop_input("IPvN packet on IPv4 ill", mp
, ill
);
7377 if (opt_len
> (15 - IP_SIMPLE_HDR_LENGTH_IN_WORDS
)) {
7378 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7379 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7384 * Recompute complete header length and make sure we
7385 * have access to all of it.
7387 len
= ((size_t)opt_len
+ IP_SIMPLE_HDR_LENGTH_IN_WORDS
) << 2;
7388 if (len
> (mp
->b_wptr
- mp
->b_rptr
)) {
7389 if (len
> pkt_len
) {
7390 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInHdrErrors
);
7391 ip_drop_input("ipIfStatsInHdrErrors", mp
, ill
);
7395 if (ip_pullup(mp
, len
, ira
) == NULL
) {
7396 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7397 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7406 * Returns a new ire, or the same ire, or NULL.
7407 * If a different IRE is returned, then it is held; the caller
7408 * needs to release it.
7409 * In no case is there any hold/release on the ire argument.
7412 ip_check_multihome(void *addr
, ire_t
*ire
, ill_t
*ill
)
7417 ip_stack_t
*ipst
= ill
->ill_ipst
;
7418 boolean_t strict_check
= B_FALSE
;
7421 * IPMP common case: if IRE and ILL are in the same group, there's no
7422 * issue (e.g. packet received on an underlying interface matched an
7423 * IRE_LOCAL on its associated group interface).
7425 ASSERT(ire
->ire_ill
!= NULL
);
7426 if (IS_IN_SAME_ILLGRP(ill
, ire
->ire_ill
))
7430 * Do another ire lookup here, using the ingress ill, to see if the
7431 * interface is in a usesrc group.
7432 * As long as the ills belong to the same group, we don't consider
7433 * them to be arriving on the wrong interface. Thus, if the switch
7434 * is doing inbound load spreading, we won't drop packets when the
7435 * ip*_strict_dst_multihoming switch is on.
7436 * We also need to check for IPIF_UNNUMBERED point2point interfaces
7437 * where the local address may not be unique. In this case we were
7438 * at the mercy of the initial ire lookup and the IRE_LOCAL it
7439 * actually returned. The new lookup, which is more specific, should
7440 * only find the IRE_LOCAL associated with the ingress ill if one
7443 if (ire
->ire_ipversion
== IPV4_VERSION
) {
7444 if (ipst
->ips_ip_strict_dst_multihoming
)
7445 strict_check
= B_TRUE
;
7446 new_ire
= ire_ftable_lookup_v4(*((ipaddr_t
*)addr
), 0, 0,
7447 IRE_LOCAL
, ill
, ALL_ZONES
,
7448 (MATCH_IRE_TYPE
|MATCH_IRE_ILL
), 0, ipst
, NULL
);
7450 ASSERT(!IN6_IS_ADDR_MULTICAST((in6_addr_t
*)addr
));
7451 if (ipst
->ips_ipv6_strict_dst_multihoming
)
7452 strict_check
= B_TRUE
;
7453 new_ire
= ire_ftable_lookup_v6((in6_addr_t
*)addr
, NULL
, NULL
,
7454 IRE_LOCAL
, ill
, ALL_ZONES
,
7455 (MATCH_IRE_TYPE
|MATCH_IRE_ILL
), 0, ipst
, NULL
);
7458 * If the same ire that was returned in ip_input() is found then this
7459 * is an indication that usesrc groups are in use. The packet
7460 * arrived on a different ill in the group than the one associated with
7461 * the destination address. If a different ire was found then the same
7462 * IP address must be hosted on multiple ills. This is possible with
7463 * unnumbered point2point interfaces. We switch to use this new ire in
7464 * order to have accurate interface statistics.
7466 if (new_ire
!= NULL
) {
7467 /* Note: held in one case but not the other? Caller handles */
7471 ire_refrele(new_ire
);
7476 * Chase pointers once and store locally.
7478 ASSERT(ire
->ire_ill
!= NULL
);
7479 ire_ill
= ire
->ire_ill
;
7480 ifindex
= ill
->ill_usesrc_ifindex
;
7483 * Check if it's a legal address on the 'usesrc' interface.
7484 * For IPMP data addresses the IRE_LOCAL is the upper, hence we
7485 * can just check phyint_ifindex.
7487 if (ifindex
!= 0 && ifindex
== ire_ill
->ill_phyint
->phyint_ifindex
) {
7492 * If the ip*_strict_dst_multihoming switch is on then we can
7493 * only accept this packet if the interface is marked as routing.
7495 if (!(strict_check
))
7498 if ((ill
->ill_flags
& ire
->ire_ill
->ill_flags
& ILLF_ROUTER
) != 0) {
7505 * This function is used to construct a mac_header_info_s from a
7506 * DL_UNITDATA_IND message.
7507 * The address fields in the mhi structure points into the message,
7508 * thus the caller can't use those fields after freeing the message.
7510 * We determine whether the packet received is a non-unicast packet
7511 * and in doing so, determine whether or not it is broadcast vs multicast.
7512 * For it to be a broadcast packet, we must have the appropriate mblk_t
7513 * hanging off the ill_t. If this is either not present or doesn't match
7514 * the destination mac address in the DL_UNITDATA_IND, the packet is deemed
7515 * to be multicast. Thus NICs that have no broadcast address (or no
7516 * capability for one, such as point to point links) cannot return as
7517 * the packet being broadcast.
7520 ip_dlur_to_mhi(ill_t
*ill
, mblk_t
*mb
, struct mac_header_info_s
*mhip
)
7522 dl_unitdata_ind_t
*ind
= (dl_unitdata_ind_t
*)mb
->b_rptr
;
7524 uint_t extra_offset
;
7526 bzero(mhip
, sizeof (struct mac_header_info_s
));
7528 mhip
->mhi_dsttype
= MAC_ADDRTYPE_UNICAST
;
7530 if (ill
->ill_sap_length
< 0)
7533 extra_offset
= ill
->ill_sap_length
;
7535 mhip
->mhi_daddr
= (uchar_t
*)ind
+ ind
->dl_dest_addr_offset
+
7537 mhip
->mhi_saddr
= (uchar_t
*)ind
+ ind
->dl_src_addr_offset
+
7540 if (!ind
->dl_group_address
)
7543 /* Multicast or broadcast */
7544 mhip
->mhi_dsttype
= MAC_ADDRTYPE_MULTICAST
;
7546 if (ind
->dl_dest_addr_offset
> sizeof (*ind
) &&
7547 ind
->dl_dest_addr_offset
+ ind
->dl_dest_addr_length
< MBLKL(mb
) &&
7548 (bmp
= ill
->ill_bcast_mp
) != NULL
) {
7549 dl_unitdata_req_t
*dlur
;
7550 uint8_t *bphys_addr
;
7552 dlur
= (dl_unitdata_req_t
*)bmp
->b_rptr
;
7553 bphys_addr
= (uchar_t
*)dlur
+ dlur
->dl_dest_addr_offset
+
7556 if (bcmp(mhip
->mhi_daddr
, bphys_addr
,
7557 ind
->dl_dest_addr_length
) == 0)
7558 mhip
->mhi_dsttype
= MAC_ADDRTYPE_BROADCAST
;
7563 * This function is used to construct a mac_header_info_s from a
7564 * M_DATA fastpath message from a DLPI driver.
7565 * The address fields in the mhi structure points into the message,
7566 * thus the caller can't use those fields after freeing the message.
7568 * We determine whether the packet received is a non-unicast packet
7569 * and in doing so, determine whether or not it is broadcast vs multicast.
7570 * For it to be a broadcast packet, we must have the appropriate mblk_t
7571 * hanging off the ill_t. If this is either not present or doesn't match
7572 * the destination mac address in the DL_UNITDATA_IND, the packet is deemed
7573 * to be multicast. Thus NICs that have no broadcast address (or no
7574 * capability for one, such as point to point links) cannot return as
7575 * the packet being broadcast.
7578 ip_mdata_to_mhi(ill_t
*ill
, mblk_t
*mp
, struct mac_header_info_s
*mhip
)
7581 struct ether_header
*pether
;
7583 bzero(mhip
, sizeof (struct mac_header_info_s
));
7585 mhip
->mhi_dsttype
= MAC_ADDRTYPE_UNICAST
;
7587 pether
= (struct ether_header
*)((char *)mp
->b_rptr
7588 - sizeof (struct ether_header
));
7591 * Make sure the interface is an ethernet type, since we don't
7592 * know the header format for anything but Ethernet. Also make
7593 * sure we are pointing correctly above db_base.
7595 if (ill
->ill_type
!= IFT_ETHER
)
7599 if ((uchar_t
*)pether
< mp
->b_datap
->db_base
)
7602 /* Is there a VLAN tag? */
7603 if (ill
->ill_isv6
) {
7604 if (pether
->ether_type
!= htons(ETHERTYPE_IPV6
)) {
7605 pether
= (struct ether_header
*)((char *)pether
- 4);
7609 if (pether
->ether_type
!= htons(ETHERTYPE_IP
)) {
7610 pether
= (struct ether_header
*)((char *)pether
- 4);
7614 mhip
->mhi_daddr
= (uchar_t
*)&pether
->ether_dhost
;
7615 mhip
->mhi_saddr
= (uchar_t
*)&pether
->ether_shost
;
7617 if (!(mhip
->mhi_daddr
[0] & 0x01))
7620 /* Multicast or broadcast */
7621 mhip
->mhi_dsttype
= MAC_ADDRTYPE_MULTICAST
;
7623 if ((bmp
= ill
->ill_bcast_mp
) != NULL
) {
7624 dl_unitdata_req_t
*dlur
;
7625 uint8_t *bphys_addr
;
7628 dlur
= (dl_unitdata_req_t
*)bmp
->b_rptr
;
7629 addrlen
= dlur
->dl_dest_addr_length
;
7630 if (ill
->ill_sap_length
< 0) {
7631 bphys_addr
= (uchar_t
*)dlur
+
7632 dlur
->dl_dest_addr_offset
;
7633 addrlen
+= ill
->ill_sap_length
;
7635 bphys_addr
= (uchar_t
*)dlur
+
7636 dlur
->dl_dest_addr_offset
+
7637 ill
->ill_sap_length
;
7638 addrlen
-= ill
->ill_sap_length
;
7640 if (bcmp(mhip
->mhi_daddr
, bphys_addr
, addrlen
) == 0)
7641 mhip
->mhi_dsttype
= MAC_ADDRTYPE_BROADCAST
;
7646 * Handle anything but M_DATA messages
7647 * We see the DL_UNITDATA_IND which are part
7648 * of the data path, and also the other messages from the driver.
7651 ip_rput_notdata(ill_t
*ill
, mblk_t
*mp
)
7654 struct iocblk
*iocp
;
7655 struct mac_header_info_s mhi
;
7657 switch (DB_TYPE(mp
)) {
7660 if (((dl_unitdata_ind_t
*)mp
->b_rptr
)->dl_primitive
!=
7662 /* Go handle anything other than data elsewhere. */
7663 ip_rput_dlpi(ill
, mp
);
7668 mp
= first_mp
->b_cont
;
7669 first_mp
->b_cont
= NULL
;
7675 ip_dlur_to_mhi(ill
, first_mp
, &mhi
);
7677 ip_input_v6(ill
, NULL
, mp
, &mhi
);
7679 ip_input(ill
, NULL
, mp
, &mhi
);
7681 /* Ditch the DLPI header. */
7686 iocp
= (struct iocblk
*)mp
->b_rptr
;
7687 switch (iocp
->ioc_cmd
) {
7688 case DL_IOC_HDR_INFO
:
7689 ill_fastpath_ack(ill
, mp
);
7692 putnext(ill
->ill_rq
, mp
);
7698 mutex_enter(&ill
->ill_lock
);
7699 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
7700 mutex_exit(&ill
->ill_lock
);
7704 ill_refhold_locked(ill
);
7705 mutex_exit(&ill
->ill_lock
);
7706 qwriter_ip(ill
, ill
->ill_rq
, mp
, ip_rput_other
, CUR_OP
,
7710 putnext(ill
->ill_rq
, mp
);
7713 ip1dbg(("got iocnak "));
7714 iocp
= (struct iocblk
*)mp
->b_rptr
;
7715 switch (iocp
->ioc_cmd
) {
7716 case DL_IOC_HDR_INFO
:
7717 ip_rput_other(NULL
, ill
->ill_rq
, mp
, NULL
);
7724 putnext(ill
->ill_rq
, mp
);
7729 /* Read side put procedure. Packets coming from the wire arrive here. */
7731 ip_rput(queue_t
*q
, mblk_t
*mp
)
7734 union DL_primitives
*dl
;
7736 ill
= (ill_t
*)q
->q_ptr
;
7738 if (ill
->ill_state_flags
& (ILL_CONDEMNED
| ILL_LL_SUBNET_PENDING
)) {
7740 * If things are opening or closing, only accept high-priority
7741 * DLPI messages. (On open ill->ill_ipif has not yet been
7742 * created; on close, things hanging off the ill may have been
7745 dl
= (union DL_primitives
*)mp
->b_rptr
;
7746 if (DB_TYPE(mp
) != M_PCPROTO
||
7747 dl
->dl_primitive
== DL_UNITDATA_IND
) {
7752 if (DB_TYPE(mp
) == M_DATA
) {
7753 struct mac_header_info_s mhi
;
7755 ip_mdata_to_mhi(ill
, mp
, &mhi
);
7756 ip_input(ill
, NULL
, mp
, &mhi
);
7758 ip_rput_notdata(ill
, mp
);
7763 * Move the information to a copy.
7766 ip_fix_dbref(mblk_t
*mp
, ip_recv_attr_t
*ira
)
7769 ill_t
*ill
= ira
->ira_ill
;
7770 ip_stack_t
*ipst
= ill
->ill_ipst
;
7772 IP_STAT(ipst
, ip_db_ref
);
7774 /* Make sure we have ira_l2src before we loose the original mblk */
7775 if (!(ira
->ira_flags
& IRAF_L2SRC_SET
))
7776 ip_setl2src(mp
, ira
, ira
->ira_rill
);
7780 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
7781 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
7785 /* preserve the hardware checksum flags and data, if present */
7786 if (DB_CKSUMFLAGS(mp
) != 0) {
7787 DB_CKSUMFLAGS(mp1
) = DB_CKSUMFLAGS(mp
);
7788 DB_CKSUMSTART(mp1
) = DB_CKSUMSTART(mp
);
7789 DB_CKSUMSTUFF(mp1
) = DB_CKSUMSTUFF(mp
);
7790 DB_CKSUMEND(mp1
) = DB_CKSUMEND(mp
);
7791 DB_CKSUM16(mp1
) = DB_CKSUM16(mp
);
7798 ip_dlpi_error(ill_t
*ill
, t_uscalar_t prim
, t_uscalar_t dl_err
,
7801 if (dl_err
== DL_SYSERR
) {
7802 (void) mi_strlog(ill
->ill_rq
, 1, SL_CONSOLE
|SL_ERROR
|SL_TRACE
,
7803 "%s: %s failed: DL_SYSERR (errno %u)\n",
7804 ill
->ill_name
, dl_primstr(prim
), err
);
7808 (void) mi_strlog(ill
->ill_rq
, 1, SL_CONSOLE
|SL_ERROR
|SL_TRACE
,
7809 "%s: %s failed: %s\n", ill
->ill_name
, dl_primstr(prim
),
7814 * ip_rput_dlpi is called by ip_rput to handle all DLPI messages other
7815 * than DL_UNITDATA_IND messages. If we need to process this message
7816 * exclusively, we call qwriter_ip, in which case we also need to call
7817 * ill_refhold before that, since qwriter_ip does an ill_refrele.
7820 ip_rput_dlpi(ill_t
*ill
, mblk_t
*mp
)
7822 dl_ok_ack_t
*dloa
= (dl_ok_ack_t
*)mp
->b_rptr
;
7823 dl_error_ack_t
*dlea
= (dl_error_ack_t
*)dloa
;
7824 queue_t
*q
= ill
->ill_rq
;
7825 t_uscalar_t prim
= dloa
->dl_primitive
;
7826 t_uscalar_t reqprim
= DL_PRIM_INVAL
;
7828 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi",
7829 char *, dl_primstr(prim
), ill_t
*, ill
);
7830 ip1dbg(("ip_rput_dlpi"));
7833 * If we received an ACK but didn't send a request for it, then it
7834 * can't be part of any pending operation; discard up-front.
7838 reqprim
= dlea
->dl_error_primitive
;
7839 ip2dbg(("ip_rput_dlpi(%s): DL_ERROR_ACK for %s (0x%x): %s "
7840 "(0x%x), unix %u\n", ill
->ill_name
, dl_primstr(reqprim
),
7841 reqprim
, dl_errstr(dlea
->dl_errno
), dlea
->dl_errno
,
7842 dlea
->dl_unix_errno
));
7845 reqprim
= dloa
->dl_correct_primitive
;
7848 reqprim
= DL_INFO_REQ
;
7851 reqprim
= DL_BIND_REQ
;
7853 case DL_PHYS_ADDR_ACK
:
7854 reqprim
= DL_PHYS_ADDR_REQ
;
7857 reqprim
= DL_NOTIFY_REQ
;
7859 case DL_CAPABILITY_ACK
:
7860 reqprim
= DL_CAPABILITY_REQ
;
7864 if (prim
!= DL_NOTIFY_IND
) {
7865 if (reqprim
== DL_PRIM_INVAL
||
7866 !ill_dlpi_pending(ill
, reqprim
)) {
7867 /* Not a DLPI message we support or expected */
7871 ip1dbg(("ip_rput: received %s for %s\n", dl_primstr(prim
),
7872 dl_primstr(reqprim
)));
7878 * NOTE: we mark the unbind as complete even if we got a
7879 * DL_ERROR_ACK, since there's not much else we can do.
7881 mutex_enter(&ill
->ill_lock
);
7882 ill
->ill_state_flags
&= ~ILL_DL_UNBIND_IN_PROGRESS
;
7883 cv_signal(&ill
->ill_cv
);
7884 mutex_exit(&ill
->ill_lock
);
7887 case DL_ENABMULTI_REQ
:
7888 if (prim
== DL_OK_ACK
) {
7889 if (ill
->ill_dlpi_multicast_state
== IDS_INPROGRESS
)
7890 ill
->ill_dlpi_multicast_state
= IDS_OK
;
7896 * The message is one we're waiting for (or DL_NOTIFY_IND), but we
7897 * need to become writer to continue to process it. Because an
7898 * exclusive operation doesn't complete until replies to all queued
7899 * DLPI messages have been received, we know we're in the middle of an
7900 * exclusive operation and pass CUR_OP (except for DL_NOTIFY_IND).
7902 * As required by qwriter_ip(), we refhold the ill; it will refrele.
7903 * Since this is on the ill stream we unconditionally bump up the
7904 * refcount without doing ILL_CAN_LOOKUP().
7907 if (prim
== DL_NOTIFY_IND
)
7908 qwriter_ip(ill
, q
, mp
, ip_rput_dlpi_writer
, NEW_OP
, B_FALSE
);
7910 qwriter_ip(ill
, q
, mp
, ip_rput_dlpi_writer
, CUR_OP
, B_FALSE
);
7914 * Handling of DLPI messages that require exclusive access to the ipsq.
7916 * Need to do ipsq_pending_mp_get on ioctl completion, which could
7917 * happen here. (along with mi_copy_done)
7921 ip_rput_dlpi_writer(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
7923 dl_ok_ack_t
*dloa
= (dl_ok_ack_t
*)mp
->b_rptr
;
7924 dl_error_ack_t
*dlea
= (dl_error_ack_t
*)dloa
;
7926 ill_t
*ill
= (ill_t
*)q
->q_ptr
;
7927 ipif_t
*ipif
= NULL
;
7929 conn_t
*connp
= NULL
;
7930 t_uscalar_t paddrreq
;
7933 boolean_t ioctl_aborted
= B_FALSE
;
7934 boolean_t log
= B_TRUE
;
7936 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi_writer",
7937 char *, dl_primstr(dloa
->dl_primitive
), ill_t
*, ill
);
7939 ip1dbg(("ip_rput_dlpi_writer .."));
7940 ASSERT(ipsq
->ipsq_xop
== ill
->ill_phyint
->phyint_ipsq
->ipsq_xop
);
7941 ASSERT(IAM_WRITER_ILL(ill
));
7943 ipif
= ipsq
->ipsq_xop
->ipx_pending_ipif
;
7945 * The current ioctl could have been aborted by the user and a new
7946 * ioctl to bring up another ill could have started. We could still
7947 * get a response from the driver later.
7949 if (ipif
!= NULL
&& ipif
->ipif_ill
!= ill
)
7950 ioctl_aborted
= B_TRUE
;
7952 switch (dloa
->dl_primitive
) {
7954 ip1dbg(("ip_rput_dlpi_writer: got DL_ERROR_ACK for %s\n",
7955 dl_primstr(dlea
->dl_error_primitive
)));
7957 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi_writer error",
7958 char *, dl_primstr(dlea
->dl_error_primitive
),
7961 switch (dlea
->dl_error_primitive
) {
7962 case DL_DISABMULTI_REQ
:
7963 ill_dlpi_done(ill
, dlea
->dl_error_primitive
);
7965 case DL_PROMISCON_REQ
:
7966 case DL_PROMISCOFF_REQ
:
7970 ill_dlpi_done(ill
, dlea
->dl_error_primitive
);
7973 ill_dlpi_done(ill
, DL_NOTIFY_REQ
);
7976 case DL_PHYS_ADDR_REQ
:
7978 * For IPv6 only, there are two additional
7979 * phys_addr_req's sent to the driver to get the
7980 * IPv6 token and lla. This allows IP to acquire
7981 * the hardware address format for a given interface
7982 * without having built in knowledge of the hardware
7983 * address. ill_phys_addr_pend keeps track of the last
7984 * DL_PAR sent so we know which response we are
7985 * dealing with. ill_dlpi_done will update
7986 * ill_phys_addr_pend when it sends the next req.
7987 * We don't complete the IOCTL until all three DL_PARs
7988 * have been attempted, so set *_len to 0 and break.
7990 paddrreq
= ill
->ill_phys_addr_pend
;
7991 ill_dlpi_done(ill
, DL_PHYS_ADDR_REQ
);
7992 if (paddrreq
== DL_IPV6_TOKEN
) {
7993 ill
->ill_token_length
= 0;
7996 } else if (paddrreq
== DL_IPV6_LINK_LAYER_ADDR
) {
7997 ill
->ill_nd_lla_len
= 0;
8002 * Something went wrong with the DL_PHYS_ADDR_REQ.
8003 * We presumably have an IOCTL hanging out waiting
8004 * for completion. Find it and complete the IOCTL
8005 * with the error noted.
8006 * However, ill_dl_phys was called on an ill queue
8007 * (from SIOCSLIFNAME), thus conn_pending_ill is not
8008 * set. But the ioctl is known to be pending on ill_wq.
8010 if (!ill
->ill_ifname_pending
)
8012 ill
->ill_ifname_pending
= 0;
8014 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8017 * This operation (SIOCSLIFNAME) must have
8018 * happened on the ill. Assert there is no conn
8020 ASSERT(connp
== NULL
);
8025 ill_dlpi_done(ill
, DL_BIND_REQ
);
8026 if (ill
->ill_ifname_pending
)
8028 mutex_enter(&ill
->ill_lock
);
8029 ill
->ill_state_flags
&= ~ILL_DOWN_IN_PROGRESS
;
8030 mutex_exit(&ill
->ill_lock
);
8032 * Something went wrong with the bind. We presumably
8033 * have an IOCTL hanging out waiting for completion.
8034 * Find it, take down the interface that was coming
8035 * up, and complete the IOCTL with the error noted.
8038 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8041 * This might be a result of a DL_NOTE_REPLUMB
8042 * notification. In that case, connp is NULL.
8045 q
= CONNP_TO_WQ(connp
);
8047 (void) ipif_down(ipif
, NULL
, NULL
);
8048 /* error is set below the switch */
8051 case DL_ENABMULTI_REQ
:
8052 ill_dlpi_done(ill
, DL_ENABMULTI_REQ
);
8054 if (ill
->ill_dlpi_multicast_state
== IDS_INPROGRESS
)
8055 ill
->ill_dlpi_multicast_state
= IDS_FAILED
;
8056 if (ill
->ill_dlpi_multicast_state
== IDS_FAILED
) {
8058 printf("ip: joining multicasts failed (%d)"
8059 " on %s - will use link layer "
8060 "broadcasts for multicast\n",
8061 dlea
->dl_errno
, ill
->ill_name
);
8064 * Set up for multi_bcast; We are the
8065 * writer, so ok to access ill->ill_ipif
8068 mutex_enter(&ill
->ill_phyint
->phyint_lock
);
8069 ill
->ill_phyint
->phyint_flags
|=
8071 mutex_exit(&ill
->ill_phyint
->phyint_lock
);
8074 freemsg(mp
); /* Don't want to pass this up */
8076 case DL_CAPABILITY_REQ
:
8077 ip1dbg(("ip_rput_dlpi_writer: got DL_ERROR_ACK for "
8078 "DL_CAPABILITY REQ\n"));
8079 if (ill
->ill_dlpi_capab_state
== IDCS_PROBE_SENT
)
8080 ill
->ill_dlpi_capab_state
= IDCS_FAILED
;
8081 ill_capability_done(ill
);
8086 * Note the error for IOCTL completion (mp1 is set when
8087 * ready to complete ioctl). If ill_ifname_pending_err is
8088 * set, an error occured during plumbing (ill_ifname_pending),
8089 * so we want to report that error.
8091 * NOTE: there are two addtional DL_PHYS_ADDR_REQ's
8092 * (DL_IPV6_TOKEN and DL_IPV6_LINK_LAYER_ADDR) that are
8093 * expected to get errack'd if the driver doesn't support
8094 * these flags (e.g. ethernet). log will be set to B_FALSE
8095 * if these error conditions are encountered.
8098 if (ill
->ill_ifname_pending_err
!= 0) {
8099 err
= ill
->ill_ifname_pending_err
;
8100 ill
->ill_ifname_pending_err
= 0;
8102 err
= dlea
->dl_unix_errno
?
8103 dlea
->dl_unix_errno
: ENXIO
;
8106 * If we're plumbing an interface and an error hasn't already
8107 * been saved, set ill_ifname_pending_err to the error passed
8108 * up. Ignore the error if log is B_FALSE (see comment above).
8110 } else if (log
&& ill
->ill_ifname_pending
&&
8111 ill
->ill_ifname_pending_err
== 0) {
8112 ill
->ill_ifname_pending_err
= dlea
->dl_unix_errno
?
8113 dlea
->dl_unix_errno
: ENXIO
;
8117 ip_dlpi_error(ill
, dlea
->dl_error_primitive
,
8118 dlea
->dl_errno
, dlea
->dl_unix_errno
);
8120 case DL_CAPABILITY_ACK
:
8121 ill_capability_ack(ill
, mp
);
8123 * The message has been handed off to ill_capability_ack
8124 * and must not be freed below
8130 /* Call a routine to handle this one. */
8131 ill_dlpi_done(ill
, DL_INFO_REQ
);
8132 ip_ll_subnet_defaults(ill
, mp
);
8133 ASSERT(!MUTEX_HELD(&ill
->ill_phyint
->phyint_ipsq
->ipsq_lock
));
8137 * We should have an IOCTL waiting on this unless
8138 * sent by ill_dl_phys, in which case just return
8140 ill_dlpi_done(ill
, DL_BIND_REQ
);
8142 if (ill
->ill_ifname_pending
) {
8143 DTRACE_PROBE2(ip__rput__dlpi__ifname__pending
,
8144 ill_t
*, ill
, mblk_t
*, mp
);
8147 mutex_enter(&ill
->ill_lock
);
8149 ill
->ill_state_flags
&= ~ILL_DOWN_IN_PROGRESS
;
8150 mutex_exit(&ill
->ill_lock
);
8153 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8155 DTRACE_PROBE1(ip__rput__dlpi__no__mblk
, ill_t
*, ill
);
8159 * mp1 was added by ill_dl_up(). if that is a result of
8160 * a DL_NOTE_REPLUMB notification, connp could be NULL.
8163 q
= CONNP_TO_WQ(connp
);
8165 * We are exclusive. So nothing can change even after
8166 * we get the pending mp.
8168 ip1dbg(("ip_rput_dlpi: bind_ack %s\n", ill
->ill_name
));
8169 DTRACE_PROBE1(ip__rput__dlpi__bind__ack
, ill_t
*, ill
);
8170 ill_nic_event_dispatch(ill
, 0, NE_UP
, NULL
, 0);
8173 * Now bring up the resolver; when that is complete, we'll
8174 * create IREs. Note that we intentionally mirror what
8175 * ipif_up() would have done, because we got here by way of
8176 * ill_dl_up(), which stopped ipif_up()'s processing.
8178 if (ill
->ill_isv6
) {
8181 * Unlike ARP which has to do another bind
8182 * and attach, once we get here we are
8185 (void) ipif_resolver_up(ipif
, Res_act_initial
);
8186 if ((err
= ipif_ndp_up(ipif
, B_TRUE
)) == 0)
8187 err
= ipif_up_done_v6(ipif
);
8188 } else if (ill
->ill_net_type
== IRE_IF_RESOLVER
) {
8190 * ARP and other v4 external resolvers.
8191 * Leave the pending mblk intact so that
8192 * the ioctl completes in ip_rput().
8195 mutex_enter(&connp
->conn_lock
);
8196 mutex_enter(&ill
->ill_lock
);
8197 success
= ipsq_pending_mp_add(connp
, ipif
, q
, mp1
, 0);
8198 mutex_exit(&ill
->ill_lock
);
8200 mutex_exit(&connp
->conn_lock
);
8202 err
= ipif_resolver_up(ipif
, Res_act_initial
);
8203 if (err
== EINPROGRESS
) {
8207 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8209 /* The conn has started closing */
8214 * This one is complete. Reply to pending ioctl.
8216 (void) ipif_resolver_up(ipif
, Res_act_initial
);
8217 err
= ipif_up_done(ipif
);
8220 if ((err
== 0) && (ill
->ill_up_ipifs
)) {
8221 err
= ill_up_ipifs(ill
, q
, mp1
);
8222 if (err
== EINPROGRESS
) {
8229 * If we have a moved ipif to bring up, and everything has
8230 * succeeded to this point, bring it up on the IPMP ill.
8231 * Otherwise, leave it down -- the admin can try to bring it
8232 * up by hand if need be.
8234 if (ill
->ill_move_ipif
!= NULL
) {
8236 ill
->ill_move_ipif
= NULL
;
8238 ipif
= ill
->ill_move_ipif
;
8239 ill
->ill_move_ipif
= NULL
;
8240 err
= ipif_up(ipif
, q
, mp1
);
8241 if (err
== EINPROGRESS
) {
8249 case DL_NOTIFY_IND
: {
8250 dl_notify_ind_t
*notify
= (dl_notify_ind_t
*)mp
->b_rptr
;
8251 uint_t orig_mtu
, orig_mc_mtu
;
8253 switch (notify
->dl_notification
) {
8254 case DL_NOTE_PHYS_ADDR
:
8255 err
= ill_set_phys_addr(ill
, mp
);
8258 case DL_NOTE_REPLUMB
:
8260 * Directly return after calling ill_replumb().
8261 * Note that we should not free mp as it is reused
8262 * in the ill_replumb() function.
8264 err
= ill_replumb(ill
, mp
);
8267 case DL_NOTE_FASTPATH_FLUSH
:
8268 nce_flush(ill
, B_FALSE
);
8271 case DL_NOTE_SDU_SIZE
:
8272 case DL_NOTE_SDU_SIZE2
:
8274 * The dce and fragmentation code can cope with
8275 * this changing while packets are being sent.
8276 * When packets are sent ip_output will discover
8279 * Change the MTU size of the interface.
8281 mutex_enter(&ill
->ill_lock
);
8282 orig_mtu
= ill
->ill_mtu
;
8283 orig_mc_mtu
= ill
->ill_mc_mtu
;
8284 switch (notify
->dl_notification
) {
8285 case DL_NOTE_SDU_SIZE
:
8286 ill
->ill_current_frag
=
8287 (uint_t
)notify
->dl_data
;
8288 ill
->ill_mc_mtu
= (uint_t
)notify
->dl_data
;
8290 case DL_NOTE_SDU_SIZE2
:
8291 ill
->ill_current_frag
=
8292 (uint_t
)notify
->dl_data1
;
8293 ill
->ill_mc_mtu
= (uint_t
)notify
->dl_data2
;
8296 if (ill
->ill_current_frag
> ill
->ill_max_frag
)
8297 ill
->ill_max_frag
= ill
->ill_current_frag
;
8299 if (!(ill
->ill_flags
& ILLF_FIXEDMTU
)) {
8300 ill
->ill_mtu
= ill
->ill_current_frag
;
8303 * If ill_user_mtu was set (via
8304 * SIOCSLIFLNKINFO), clamp ill_mtu at it.
8306 if (ill
->ill_user_mtu
!= 0 &&
8307 ill
->ill_user_mtu
< ill
->ill_mtu
)
8308 ill
->ill_mtu
= ill
->ill_user_mtu
;
8310 if (ill
->ill_user_mtu
!= 0 &&
8311 ill
->ill_user_mtu
< ill
->ill_mc_mtu
)
8312 ill
->ill_mc_mtu
= ill
->ill_user_mtu
;
8314 if (ill
->ill_isv6
) {
8315 if (ill
->ill_mtu
< IPV6_MIN_MTU
)
8316 ill
->ill_mtu
= IPV6_MIN_MTU
;
8317 if (ill
->ill_mc_mtu
< IPV6_MIN_MTU
)
8318 ill
->ill_mc_mtu
= IPV6_MIN_MTU
;
8320 if (ill
->ill_mtu
< IP_MIN_MTU
)
8321 ill
->ill_mtu
= IP_MIN_MTU
;
8322 if (ill
->ill_mc_mtu
< IP_MIN_MTU
)
8323 ill
->ill_mc_mtu
= IP_MIN_MTU
;
8325 } else if (ill
->ill_mc_mtu
> ill
->ill_mtu
) {
8326 ill
->ill_mc_mtu
= ill
->ill_mtu
;
8329 mutex_exit(&ill
->ill_lock
);
8331 * Make sure all dce_generation checks find out
8332 * that ill_mtu/ill_mc_mtu has changed.
8334 if (orig_mtu
!= ill
->ill_mtu
||
8335 orig_mc_mtu
!= ill
->ill_mc_mtu
) {
8336 dce_increment_all_generations(ill
->ill_isv6
,
8341 * Refresh IPMP meta-interface MTU if necessary.
8343 if (IS_UNDER_IPMP(ill
))
8344 ipmp_illgrp_refresh_mtu(ill
->ill_grp
);
8347 case DL_NOTE_LINK_UP
:
8348 case DL_NOTE_LINK_DOWN
: {
8350 * We are writer. ill / phyint / ipsq assocs stable.
8351 * The RUNNING flag reflects the state of the link.
8353 phyint_t
*phyint
= ill
->ill_phyint
;
8354 uint64_t new_phyint_flags
;
8355 boolean_t changed
= B_FALSE
;
8358 went_up
= notify
->dl_notification
== DL_NOTE_LINK_UP
;
8359 mutex_enter(&phyint
->phyint_lock
);
8361 new_phyint_flags
= went_up
?
8362 phyint
->phyint_flags
| PHYI_RUNNING
:
8363 phyint
->phyint_flags
& ~PHYI_RUNNING
;
8366 new_phyint_flags
= went_up
?
8367 new_phyint_flags
& ~PHYI_FAILED
:
8368 new_phyint_flags
| PHYI_FAILED
;
8371 if (new_phyint_flags
!= phyint
->phyint_flags
) {
8372 phyint
->phyint_flags
= new_phyint_flags
;
8375 mutex_exit(&phyint
->phyint_lock
);
8377 * ill_restart_dad handles the DAD restart and routing
8378 * socket notification logic.
8381 ill_restart_dad(phyint
->phyint_illv4
, went_up
);
8382 ill_restart_dad(phyint
->phyint_illv6
, went_up
);
8386 case DL_NOTE_PROMISC_ON_PHYS
: {
8387 phyint_t
*phyint
= ill
->ill_phyint
;
8389 mutex_enter(&phyint
->phyint_lock
);
8390 phyint
->phyint_flags
|= PHYI_PROMISC
;
8391 mutex_exit(&phyint
->phyint_lock
);
8394 case DL_NOTE_PROMISC_OFF_PHYS
: {
8395 phyint_t
*phyint
= ill
->ill_phyint
;
8397 mutex_enter(&phyint
->phyint_lock
);
8398 phyint
->phyint_flags
&= ~PHYI_PROMISC
;
8399 mutex_exit(&phyint
->phyint_lock
);
8402 case DL_NOTE_CAPAB_RENEG
:
8404 * Something changed on the driver side.
8405 * It wants us to renegotiate the capabilities
8406 * on this ill. One possible cause is the aggregation
8407 * interface under us where a port got added or
8410 * If the capability negotiation is already done
8411 * or is in progress, reset the capabilities and
8412 * mark the ill's ill_capab_reneg to be B_TRUE,
8413 * so that when the ack comes back, we can start
8414 * the renegotiation process.
8416 * Note that if ill_capab_reneg is already B_TRUE
8417 * (ill_dlpi_capab_state is IDS_UNKNOWN in this case),
8418 * the capability resetting request has been sent
8419 * and the renegotiation has not been started yet;
8420 * nothing needs to be done in this case.
8422 ipsq_current_start(ipsq
, ill
->ill_ipif
, 0);
8423 ill_capability_reset(ill
, B_TRUE
);
8424 ipsq_current_finish(ipsq
);
8427 case DL_NOTE_ALLOWED_IPS
:
8428 ill_set_allowed_ips(ill
, mp
);
8431 ip0dbg(("ip_rput_dlpi_writer: unknown notification "
8432 "type 0x%x for DL_NOTIFY_IND\n",
8433 notify
->dl_notification
));
8438 * As this is an asynchronous operation, we
8439 * should not call ill_dlpi_done
8443 case DL_NOTIFY_ACK
: {
8444 dl_notify_ack_t
*noteack
= (dl_notify_ack_t
*)mp
->b_rptr
;
8446 if (noteack
->dl_notifications
& DL_NOTE_LINK_UP
)
8447 ill
->ill_note_link
= 1;
8448 ill_dlpi_done(ill
, DL_NOTIFY_REQ
);
8451 case DL_PHYS_ADDR_ACK
: {
8453 * As part of plumbing the interface via SIOCSLIFNAME,
8454 * ill_dl_phys() will queue a series of DL_PHYS_ADDR_REQs,
8455 * whose answers we receive here. As each answer is received,
8456 * we call ill_dlpi_done() to dispatch the next request as
8457 * we're processing the current one. Once all answers have
8458 * been received, we use ipsq_pending_mp_get() to dequeue the
8459 * outstanding IOCTL and reply to it. (Because ill_dl_phys()
8460 * is invoked from an ill queue, conn_oper_pending_ill is not
8461 * available, but we know the ioctl is pending on ill_wq.)
8463 uint_t paddrlen
, paddroff
;
8466 paddrreq
= ill
->ill_phys_addr_pend
;
8467 paddrlen
= ((dl_phys_addr_ack_t
*)mp
->b_rptr
)->dl_addr_length
;
8468 paddroff
= ((dl_phys_addr_ack_t
*)mp
->b_rptr
)->dl_addr_offset
;
8469 addr
= mp
->b_rptr
+ paddroff
;
8471 ill_dlpi_done(ill
, DL_PHYS_ADDR_REQ
);
8472 if (paddrreq
== DL_IPV6_TOKEN
) {
8474 * bcopy to low-order bits of ill_token
8476 * XXX Temporary hack - currently, all known tokens
8477 * are 64 bits, so I'll cheat for the moment.
8479 bcopy(addr
, &ill
->ill_token
.s6_addr32
[2], paddrlen
);
8480 ill
->ill_token_length
= paddrlen
;
8482 } else if (paddrreq
== DL_IPV6_LINK_LAYER_ADDR
) {
8483 ASSERT(ill
->ill_nd_lla_mp
== NULL
);
8484 ill_set_ndmp(ill
, mp
, paddroff
, paddrlen
);
8487 } else if (paddrreq
== DL_CURR_DEST_ADDR
) {
8488 ASSERT(ill
->ill_dest_addr_mp
== NULL
);
8489 ill
->ill_dest_addr_mp
= mp
;
8490 ill
->ill_dest_addr
= addr
;
8492 if (ill
->ill_isv6
) {
8493 ill_setdesttoken(ill
);
8494 ipif_setdestlinklocal(ill
->ill_ipif
);
8499 ASSERT(paddrreq
== DL_CURR_PHYS_ADDR
);
8500 ASSERT(ill
->ill_phys_addr_mp
== NULL
);
8501 if (!ill
->ill_ifname_pending
)
8503 ill
->ill_ifname_pending
= 0;
8505 mp1
= ipsq_pending_mp_get(ipsq
, &connp
);
8507 ASSERT(connp
== NULL
);
8511 * If any error acks received during the plumbing sequence,
8512 * ill_ifname_pending_err will be set. Break out and send up
8513 * the error to the pending ioctl.
8515 if (ill
->ill_ifname_pending_err
!= 0) {
8516 err
= ill
->ill_ifname_pending_err
;
8517 ill
->ill_ifname_pending_err
= 0;
8521 ill
->ill_phys_addr_mp
= mp
;
8522 ill
->ill_phys_addr
= (paddrlen
== 0 ? NULL
: addr
);
8526 * If paddrlen or ill_phys_addr_length is zero, the DLPI
8527 * provider doesn't support physical addresses. We check both
8528 * paddrlen and ill_phys_addr_length because sppp (PPP) does
8529 * not have physical addresses, but historically adversises a
8530 * physical address length of 0 in its DL_INFO_ACK, but 6 in
8531 * its DL_PHYS_ADDR_ACK.
8533 if (paddrlen
== 0 || ill
->ill_phys_addr_length
== 0) {
8534 ill
->ill_phys_addr
= NULL
;
8535 } else if (paddrlen
!= ill
->ill_phys_addr_length
) {
8536 ip0dbg(("DL_PHYS_ADDR_ACK: got addrlen %d, expected %d",
8537 paddrlen
, ill
->ill_phys_addr_length
));
8542 if (ill
->ill_nd_lla_mp
== NULL
) {
8543 if ((mp_hw
= copyb(ill
->ill_phys_addr_mp
)) == NULL
) {
8547 ill_set_ndmp(ill
, mp_hw
, paddroff
, paddrlen
);
8550 if (ill
->ill_isv6
) {
8551 ill_setdefaulttoken(ill
);
8552 ipif_setlinklocal(ill
->ill_ipif
);
8557 ip2dbg(("DL_OK_ACK %s (0x%x)\n",
8558 dl_primstr((int)dloa
->dl_correct_primitive
),
8559 dloa
->dl_correct_primitive
));
8560 DTRACE_PROBE3(ill__dlpi
, char *, "ip_rput_dlpi_writer ok",
8561 char *, dl_primstr(dloa
->dl_correct_primitive
),
8564 switch (dloa
->dl_correct_primitive
) {
8565 case DL_ENABMULTI_REQ
:
8566 case DL_DISABMULTI_REQ
:
8567 ill_dlpi_done(ill
, dloa
->dl_correct_primitive
);
8569 case DL_PROMISCON_REQ
:
8570 case DL_PROMISCOFF_REQ
:
8573 ill_dlpi_done(ill
, dloa
->dl_correct_primitive
);
8586 * The operation must complete without EINPROGRESS since
8587 * ipsq_pending_mp_get() has removed the mblk (mp1). Otherwise,
8588 * the operation will be stuck forever inside the IPSQ.
8590 ASSERT(err
!= EINPROGRESS
);
8592 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_rput_dlpi_writer finish",
8593 int, ipsq
->ipsq_xop
->ipx_current_ioctl
, ill_t
*, ill
,
8596 switch (ipsq
->ipsq_xop
->ipx_current_ioctl
) {
8598 ipsq_current_finish(ipsq
);
8603 ill_t
*ill_other
= ILL_OTHER(ill
);
8606 * If SIOCSLIFNAME or IF_UNITSEL is about to succeed, and the
8607 * ill has a peer which is in an IPMP group, then place ill
8608 * into the same group. One catch: although ifconfig plumbs
8609 * the appropriate IPMP meta-interface prior to plumbing this
8610 * ill, it is possible for multiple ifconfig applications to
8611 * race (or for another application to adjust plumbing), in
8612 * which case the IPMP meta-interface we need will be missing.
8613 * If so, kick the phyint out of the group.
8615 if (err
== 0 && ill_other
!= NULL
&& IS_UNDER_IPMP(ill_other
)) {
8616 ipmp_grp_t
*grp
= ill
->ill_phyint
->phyint_grp
;
8617 ipmp_illgrp_t
*illg
;
8619 illg
= ill
->ill_isv6
? grp
->gr_v6
: grp
->gr_v4
;
8621 ipmp_phyint_leave_grp(ill
->ill_phyint
);
8623 ipmp_ill_join_illgrp(ill
, illg
);
8626 if (ipsq
->ipsq_xop
->ipx_current_ioctl
== IF_UNITSEL
)
8627 ip_ioctl_finish(q
, mp1
, err
, NO_COPYOUT
, ipsq
);
8629 ip_ioctl_finish(q
, mp1
, err
, COPYOUT
, ipsq
);
8633 ip_ioctl_finish(q
, mp1
, err
, COPYOUT
, ipsq
);
8637 ip_ioctl_finish(q
, mp1
, err
, NO_COPYOUT
, ipsq
);
8643 * ip_rput_other is called by ip_rput to handle messages modifying the global
8644 * state in IP. If 'ipsq' is non-NULL, caller is writer on it.
8648 ip_rput_other(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
8650 ill_t
*ill
= q
->q_ptr
;
8651 struct iocblk
*iocp
;
8653 ip1dbg(("ip_rput_other "));
8655 ASSERT(IAM_WRITER_IPSQ(ipsq
));
8656 ASSERT(ipsq
->ipsq_xop
==
8657 ill
->ill_phyint
->phyint_ipsq
->ipsq_xop
);
8660 switch (mp
->b_datap
->db_type
) {
8664 * The device has a problem. We force the ILL down. It can
8665 * be brought up again manually using SIOCSIFFLAGS (via
8666 * ifconfig or equivalent).
8668 ASSERT(ipsq
!= NULL
);
8669 if (mp
->b_rptr
< mp
->b_wptr
)
8670 ill
->ill_error
= (int)(*mp
->b_rptr
& 0xFF);
8671 if (ill
->ill_error
== 0)
8672 ill
->ill_error
= ENXIO
;
8673 if (!ill_down_start(q
, mp
))
8675 ipif_all_down_tail(ipsq
, q
, mp
, NULL
);
8678 iocp
= (struct iocblk
*)mp
->b_rptr
;
8680 ASSERT(iocp
->ioc_cmd
== DL_IOC_HDR_INFO
);
8682 * If this was the first attempt, turn off the fastpath
8685 mutex_enter(&ill
->ill_lock
);
8686 if (ill
->ill_dlpi_fastpath_state
== IDS_INPROGRESS
) {
8687 ill
->ill_dlpi_fastpath_state
= IDS_FAILED
;
8688 mutex_exit(&ill
->ill_lock
);
8690 * don't flush the nce_t entries: we use them
8691 * as an index to the ncec itself.
8693 ip1dbg(("ip_rput: DLPI fastpath off on interface %s\n",
8696 mutex_exit(&ill
->ill_lock
);
8708 * Update any source route, record route or timestamp options
8709 * When it fails it has consumed the message and BUMPed the MIB.
8712 ip_forward_options(mblk_t
*mp
, ipha_t
*ipha
, ill_t
*dst_ill
,
8713 ip_recv_attr_t
*ira
)
8723 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
8725 ip2dbg(("ip_forward_options\n"));
8726 dst
= ipha
->ipha_dst
;
8727 for (optval
= ipoptp_first(&opts
, ipha
);
8728 optval
!= IPOPT_EOL
;
8729 optval
= ipoptp_next(&opts
)) {
8730 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
8731 opt
= opts
.ipoptp_cur
;
8732 optlen
= opts
.ipoptp_len
;
8733 ip2dbg(("ip_forward_options: opt %d, len %d\n",
8734 optval
, opts
.ipoptp_len
));
8739 /* Check if adminstratively disabled */
8740 if (!ipst
->ips_ip_forward_src_routed
) {
8741 BUMP_MIB(dst_ill
->ill_ip_mib
,
8742 ipIfStatsForwProhibits
);
8743 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED",
8745 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
,
8749 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
8751 * Must be partial since ip_input_options
8752 * checked for strict.
8756 off
= opt
[IPOPT_OFFSET
];
8759 if (optlen
< IP_ADDR_LEN
||
8760 off
> optlen
- IP_ADDR_LEN
) {
8761 /* End of source route */
8763 "ip_forward_options: end of SR\n"));
8766 /* Pick a reasonable address on the outbound if */
8767 ASSERT(dst_ill
!= NULL
);
8768 if (ip_select_source_v4(dst_ill
, INADDR_ANY
, dst
,
8769 INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
, NULL
,
8771 /* No source! Shouldn't happen */
8772 ifaddr
= INADDR_ANY
;
8774 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
8775 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
8776 ip1dbg(("ip_forward_options: next hop 0x%x\n",
8780 * Check if our address is present more than
8781 * once as consecutive hops in source route.
8783 if (ip_type_v4(dst
, ipst
) == IRE_LOCAL
) {
8785 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8788 ipha
->ipha_dst
= dst
;
8789 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8792 off
= opt
[IPOPT_OFFSET
];
8794 if (optlen
< IP_ADDR_LEN
||
8795 off
> optlen
- IP_ADDR_LEN
) {
8796 /* No more room - ignore */
8798 "ip_forward_options: end of RR\n"));
8801 /* Pick a reasonable address on the outbound if */
8802 ASSERT(dst_ill
!= NULL
);
8803 if (ip_select_source_v4(dst_ill
, INADDR_ANY
, dst
,
8804 INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
, NULL
,
8806 /* No source! Shouldn't happen */
8807 ifaddr
= INADDR_ANY
;
8809 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
8810 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8813 /* Insert timestamp if there is room */
8814 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
8815 case IPOPT_TS_TSONLY
:
8816 off
= IPOPT_TS_TIMELEN
;
8818 case IPOPT_TS_PRESPEC
:
8819 case IPOPT_TS_PRESPEC_RFC791
:
8820 /* Verify that the address matched */
8821 off
= opt
[IPOPT_OFFSET
] - 1;
8822 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
8823 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
8828 case IPOPT_TS_TSANDADDR
:
8829 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
8833 * ip_*put_options should have already
8834 * dropped this packet.
8836 cmn_err(CE_PANIC
, "ip_forward_options: "
8837 "unknown IT - bug in ip_input_options?\n");
8838 return (B_TRUE
); /* Keep "lint" happy */
8840 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
) {
8841 /* Increase overflow counter */
8842 off
= (opt
[IPOPT_POS_OV_FLG
] >> 4) + 1;
8843 opt
[IPOPT_POS_OV_FLG
] =
8844 (uint8_t)((opt
[IPOPT_POS_OV_FLG
] & 0x0F) |
8848 off
= opt
[IPOPT_OFFSET
] - 1;
8849 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
8850 case IPOPT_TS_PRESPEC
:
8851 case IPOPT_TS_PRESPEC_RFC791
:
8852 case IPOPT_TS_TSANDADDR
:
8853 /* Pick a reasonable addr on the outbound if */
8854 ASSERT(dst_ill
!= NULL
);
8855 if (ip_select_source_v4(dst_ill
, INADDR_ANY
,
8856 dst
, INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
,
8858 /* No source! Shouldn't happen */
8859 ifaddr
= INADDR_ANY
;
8861 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
8862 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
8864 case IPOPT_TS_TSONLY
:
8865 off
= opt
[IPOPT_OFFSET
] - 1;
8866 /* Compute # of milliseconds since midnight */
8868 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
8869 NSEC2MSEC(now
.tv_nsec
);
8870 bcopy(&ts
, (char *)opt
+ off
, IPOPT_TS_TIMELEN
);
8871 opt
[IPOPT_OFFSET
] += IPOPT_TS_TIMELEN
;
8881 * Call ill_frag_timeout to do garbage collection. ill_frag_timeout
8882 * returns 'true' if there are still fragments left on the queue, in
8883 * which case we restart the timer.
8886 ill_frag_timer(void *arg
)
8888 ill_t
*ill
= (ill_t
*)arg
;
8889 boolean_t frag_pending
;
8890 ip_stack_t
*ipst
= ill
->ill_ipst
;
8893 mutex_enter(&ill
->ill_lock
);
8894 ASSERT(!ill
->ill_fragtimer_executing
);
8895 if (ill
->ill_state_flags
& ILL_CONDEMNED
) {
8896 ill
->ill_frag_timer_id
= 0;
8897 mutex_exit(&ill
->ill_lock
);
8900 ill
->ill_fragtimer_executing
= 1;
8901 mutex_exit(&ill
->ill_lock
);
8903 timeout
= (ill
->ill_isv6
? ipst
->ips_ipv6_reassembly_timeout
:
8904 ipst
->ips_ip_reassembly_timeout
);
8906 frag_pending
= ill_frag_timeout(ill
, timeout
);
8909 * Restart the timer, if we have fragments pending or if someone
8910 * wanted us to be scheduled again.
8912 mutex_enter(&ill
->ill_lock
);
8913 ill
->ill_fragtimer_executing
= 0;
8914 ill
->ill_frag_timer_id
= 0;
8915 if (frag_pending
|| ill
->ill_fragtimer_needrestart
)
8916 ill_frag_timer_start(ill
);
8917 mutex_exit(&ill
->ill_lock
);
8921 ill_frag_timer_start(ill_t
*ill
)
8923 ip_stack_t
*ipst
= ill
->ill_ipst
;
8926 ASSERT(MUTEX_HELD(&ill
->ill_lock
));
8928 /* If the ill is closing or opening don't proceed */
8929 if (ill
->ill_state_flags
& ILL_CONDEMNED
)
8932 if (ill
->ill_fragtimer_executing
) {
8934 * ill_frag_timer is currently executing. Just record the
8935 * the fact that we want the timer to be restarted.
8936 * ill_frag_timer will post a timeout before it returns,
8937 * ensuring it will be called again.
8939 ill
->ill_fragtimer_needrestart
= 1;
8943 if (ill
->ill_frag_timer_id
== 0) {
8944 timeo_ms
= (ill
->ill_isv6
? ipst
->ips_ipv6_reassembly_timeout
:
8945 ipst
->ips_ip_reassembly_timeout
) * SECONDS
;
8948 * The timer is neither running nor is the timeout handler
8949 * executing. Post a timeout so that ill_frag_timer will be
8952 ill
->ill_frag_timer_id
= timeout(ill_frag_timer
, ill
,
8953 MSEC_TO_TICK(timeo_ms
>> 1));
8954 ill
->ill_fragtimer_needrestart
= 0;
8959 * Update any source route, record route or timestamp options.
8960 * Check that we are at end of strict source route.
8961 * The options have already been checked for sanity in ip_input_options().
8964 ip_input_local_options(mblk_t
*mp
, ipha_t
*ipha
, ip_recv_attr_t
*ira
)
8974 ill_t
*ill
= ira
->ira_ill
;
8975 ip_stack_t
*ipst
= ill
->ill_ipst
;
8977 ip2dbg(("ip_input_local_options\n"));
8979 for (optval
= ipoptp_first(&opts
, ipha
);
8980 optval
!= IPOPT_EOL
;
8981 optval
= ipoptp_next(&opts
)) {
8982 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
8983 opt
= opts
.ipoptp_cur
;
8984 optlen
= opts
.ipoptp_len
;
8985 ip2dbg(("ip_input_local_options: opt %d, len %d\n",
8991 off
= opt
[IPOPT_OFFSET
];
8993 if (optlen
< IP_ADDR_LEN
||
8994 off
> optlen
- IP_ADDR_LEN
) {
8995 /* End of source route */
8996 ip1dbg(("ip_input_local_options: end of SR\n"));
9000 * This will only happen if two consecutive entries
9001 * in the source route contains our address or if
9002 * it is a packet with a loose source route which
9003 * reaches us before consuming the whole source route
9005 ip1dbg(("ip_input_local_options: not end of SR\n"));
9006 if (optval
== IPOPT_SSRR
) {
9010 * Hack: instead of dropping the packet truncate the
9011 * source route to what has been used by filling the
9012 * rest with IPOPT_NOP.
9014 opt
[IPOPT_OLEN
] = (uint8_t)off
;
9015 while (off
< optlen
) {
9016 opt
[off
++] = IPOPT_NOP
;
9020 off
= opt
[IPOPT_OFFSET
];
9022 if (optlen
< IP_ADDR_LEN
||
9023 off
> optlen
- IP_ADDR_LEN
) {
9024 /* No more room - ignore */
9026 "ip_input_local_options: end of RR\n"));
9029 /* Pick a reasonable address on the outbound if */
9030 if (ip_select_source_v4(ill
, INADDR_ANY
, ipha
->ipha_dst
,
9031 INADDR_ANY
, ALL_ZONES
, ipst
, &ifaddr
, NULL
,
9033 /* No source! Shouldn't happen */
9034 ifaddr
= INADDR_ANY
;
9036 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
9037 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
9040 /* Insert timestamp if there is romm */
9041 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
9042 case IPOPT_TS_TSONLY
:
9043 off
= IPOPT_TS_TIMELEN
;
9045 case IPOPT_TS_PRESPEC
:
9046 case IPOPT_TS_PRESPEC_RFC791
:
9047 /* Verify that the address matched */
9048 off
= opt
[IPOPT_OFFSET
] - 1;
9049 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
9050 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
9055 case IPOPT_TS_TSANDADDR
:
9056 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
9060 * ip_*put_options should have already
9061 * dropped this packet.
9063 cmn_err(CE_PANIC
, "ip_input_local_options: "
9064 "unknown IT - bug in ip_input_options?\n");
9065 return (B_TRUE
); /* Keep "lint" happy */
9067 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
) {
9068 /* Increase overflow counter */
9069 off
= (opt
[IPOPT_POS_OV_FLG
] >> 4) + 1;
9070 opt
[IPOPT_POS_OV_FLG
] =
9071 (uint8_t)((opt
[IPOPT_POS_OV_FLG
] & 0x0F) |
9075 off
= opt
[IPOPT_OFFSET
] - 1;
9076 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
9077 case IPOPT_TS_PRESPEC
:
9078 case IPOPT_TS_PRESPEC_RFC791
:
9079 case IPOPT_TS_TSANDADDR
:
9080 /* Pick a reasonable addr on the outbound if */
9081 if (ip_select_source_v4(ill
, INADDR_ANY
,
9082 ipha
->ipha_dst
, INADDR_ANY
, ALL_ZONES
, ipst
,
9083 &ifaddr
, NULL
, NULL
) != 0) {
9084 /* No source! Shouldn't happen */
9085 ifaddr
= INADDR_ANY
;
9087 bcopy(&ifaddr
, (char *)opt
+ off
, IP_ADDR_LEN
);
9088 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
9090 case IPOPT_TS_TSONLY
:
9091 off
= opt
[IPOPT_OFFSET
] - 1;
9092 /* Compute # of milliseconds since midnight */
9094 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
9095 NSEC2MSEC(now
.tv_nsec
);
9096 bcopy(&ts
, (char *)opt
+ off
, IPOPT_TS_TIMELEN
);
9097 opt
[IPOPT_OFFSET
] += IPOPT_TS_TIMELEN
;
9106 /* make sure we clear any indication of a hardware checksum */
9107 DB_CKSUMFLAGS(mp
) = 0;
9108 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", mp
, ill
);
9109 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
, ira
);
9115 * Process IP options in an inbound packet. Always returns the nexthop.
9116 * Normally this is the passed in nexthop, but if there is an option
9117 * that effects the nexthop (such as a source route) that will be returned.
9118 * Sets *errorp if there is an error, in which case an ICMP error has been sent
9122 ip_input_options(ipha_t
*ipha
, ipaddr_t dst
, mblk_t
*mp
,
9123 ip_recv_attr_t
*ira
, int *errorp
)
9125 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
9133 ip2dbg(("ip_input_options\n"));
9135 for (optval
= ipoptp_first(&opts
, ipha
);
9136 optval
!= IPOPT_EOL
;
9137 optval
= ipoptp_next(&opts
)) {
9138 opt
= opts
.ipoptp_cur
;
9139 optlen
= opts
.ipoptp_len
;
9140 ip2dbg(("ip_input_options: opt %d, len %d\n",
9143 * Note: we need to verify the checksum before we
9144 * modify anything thus this routine only extracts the next
9145 * hop dst from any source route.
9151 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
9152 if (optval
== IPOPT_SSRR
) {
9153 ip1dbg(("ip_input_options: not next"
9154 " strict source route 0x%x\n",
9156 code
= (char *)&ipha
->ipha_dst
-
9158 goto param_prob
; /* RouterReq's */
9160 ip2dbg(("ip_input_options: "
9161 "not next source route 0x%x\n",
9166 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
9168 "ip_input_options: bad option offset\n"));
9169 code
= (char *)&opt
[IPOPT_OLEN
] -
9173 off
= opt
[IPOPT_OFFSET
];
9176 if (optlen
< IP_ADDR_LEN
||
9177 off
> optlen
- IP_ADDR_LEN
) {
9178 /* End of source route */
9179 ip1dbg(("ip_input_options: end of SR\n"));
9182 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
9183 ip1dbg(("ip_input_options: next hop 0x%x\n",
9187 * Check if our address is present more than
9188 * once as consecutive hops in source route.
9189 * XXX verify per-interface ip_forwarding
9192 if (ip_type_v4(dst
, ipst
) == IRE_LOCAL
) {
9197 if (dst
== htonl(INADDR_LOOPBACK
)) {
9198 ip1dbg(("ip_input_options: loopback addr in "
9199 "source route!\n"));
9203 * For strict: verify that dst is directly
9206 if (optval
== IPOPT_SSRR
) {
9207 ire
= ire_ftable_lookup_v4(dst
, 0, 0,
9208 IRE_INTERFACE
, NULL
, ALL_ZONES
,
9209 MATCH_IRE_TYPE
, 0, ipst
, NULL
);
9211 ip1dbg(("ip_input_options: SSRR not "
9212 "directly reachable: 0x%x\n",
9219 * Defer update of the offset and the record route
9220 * until the packet is forwarded.
9224 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
9226 "ip_input_options: bad option offset\n"));
9227 code
= (char *)&opt
[IPOPT_OLEN
] -
9234 * Verify that length >= 5 and that there is either
9235 * room for another timestamp or that the overflow
9236 * counter is not maxed out.
9238 code
= (char *)&opt
[IPOPT_OLEN
] - (char *)ipha
;
9239 if (optlen
< IPOPT_MINLEN_IT
) {
9242 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
9244 "ip_input_options: bad option offset\n"));
9245 code
= (char *)&opt
[IPOPT_OFFSET
] -
9249 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
9250 case IPOPT_TS_TSONLY
:
9251 off
= IPOPT_TS_TIMELEN
;
9253 case IPOPT_TS_TSANDADDR
:
9254 case IPOPT_TS_PRESPEC
:
9255 case IPOPT_TS_PRESPEC_RFC791
:
9256 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
9259 code
= (char *)&opt
[IPOPT_POS_OV_FLG
] -
9263 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
&&
9264 (opt
[IPOPT_POS_OV_FLG
] & 0xF0) == 0xF0) {
9266 * No room and the overflow counter is 15
9275 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0) {
9279 ip1dbg(("ip_input_options: error processing IP options."));
9280 code
= (char *)&opt
[IPOPT_OFFSET
] - (char *)ipha
;
9283 /* make sure we clear any indication of a hardware checksum */
9284 DB_CKSUMFLAGS(mp
) = 0;
9285 ip_drop_input("ICMP_PARAM_PROBLEM", mp
, ira
->ira_ill
);
9286 icmp_param_problem(mp
, (uint8_t)code
, ira
);
9291 /* make sure we clear any indication of a hardware checksum */
9292 DB_CKSUMFLAGS(mp
) = 0;
9293 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", mp
, ira
->ira_ill
);
9294 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
, ira
);
9300 * IP & ICMP info in >=14 msg's ...
9301 * - ip fixed part (mib2_ip_t)
9302 * - icmp fixed part (mib2_icmp_t)
9303 * - ipAddrEntryTable (ip 20) all IPv4 ipifs
9304 * - ipRouteEntryTable (ip 21) all IPv4 IREs
9305 * - ipNetToMediaEntryTable (ip 22) all IPv4 Neighbor Cache entries
9306 * - ip multicast membership (ip_member_t)
9307 * - ip multicast source filtering (ip_grpsrc_t)
9308 * - igmp fixed part (struct igmpstat)
9309 * - multicast routing stats (struct mrtstat)
9310 * - multicast routing vifs (array of struct vifctl)
9311 * - multicast routing routes (array of struct mfcctl)
9312 * - ip6 fixed part (mib2_ipv6IfStatsEntry_t)
9313 * One per ill plus one generic
9314 * - icmp6 fixed part (mib2_ipv6IfIcmpEntry_t)
9315 * One per ill plus one generic
9316 * - ipv6RouteEntry all IPv6 IREs
9317 * - ipv6NetToMediaEntry all IPv6 Neighbor Cache entries
9318 * - ipv6AddrEntry all IPv6 ipifs
9319 * - ipv6 multicast membership (ipv6_member_t)
9320 * - ipv6 multicast source filtering (ipv6_grpsrc_t)
9322 * NOTE: original mpctl is copied for msg's 2..N, since its ctl part is
9323 * already filled in by the caller.
9324 * If legacy_req is true then MIB structures needs to be truncated to their
9325 * legacy sizes before being returned.
9326 * Return value of 0 indicates that no messages were sent and caller
9327 * should free mpctl.
9330 ip_snmp_get(queue_t
*q
, mblk_t
*mpctl
, int level
, boolean_t legacy_req
)
9333 sctp_stack_t
*sctps
;
9335 if (q
->q_next
!= NULL
) {
9336 ipst
= ILLQ_TO_IPST(q
);
9338 ipst
= CONNQ_TO_IPST(q
);
9340 ASSERT(ipst
!= NULL
);
9341 sctps
= ipst
->ips_netstack
->netstack_sctp
;
9343 if (mpctl
== NULL
|| mpctl
->b_cont
== NULL
) {
9348 * For the purposes of the (broken) packet shell use
9349 * of the level we make sure MIB2_TCP/MIB2_UDP can be used
9350 * to make TCP and UDP appear first in the list of mib items.
9351 * TBD: We could expand this and use it in netstat so that
9352 * the kernel doesn't have to produce large tables (connections,
9353 * routes, etc) when netstat only wants the statistics or a particular
9356 if (!(level
== MIB2_TCP
|| level
== MIB2_UDP
)) {
9357 if ((mpctl
= icmp_snmp_get(q
, mpctl
)) == NULL
) {
9362 if (level
!= MIB2_TCP
) {
9363 if ((mpctl
= udp_snmp_get(q
, mpctl
, legacy_req
)) == NULL
) {
9368 if (level
!= MIB2_UDP
) {
9369 if ((mpctl
= tcp_snmp_get(q
, mpctl
, legacy_req
)) == NULL
) {
9374 if ((mpctl
= ip_snmp_get_mib2_ip_traffic_stats(q
, mpctl
,
9375 ipst
, legacy_req
)) == NULL
) {
9379 if ((mpctl
= ip_snmp_get_mib2_ip6(q
, mpctl
, ipst
,
9380 legacy_req
)) == NULL
) {
9384 if ((mpctl
= ip_snmp_get_mib2_icmp(q
, mpctl
, ipst
)) == NULL
) {
9388 if ((mpctl
= ip_snmp_get_mib2_icmp6(q
, mpctl
, ipst
)) == NULL
) {
9392 if ((mpctl
= ip_snmp_get_mib2_igmp(q
, mpctl
, ipst
)) == NULL
) {
9396 if ((mpctl
= ip_snmp_get_mib2_multi(q
, mpctl
, ipst
)) == NULL
) {
9400 if ((mpctl
= ip_snmp_get_mib2_ip_addr(q
, mpctl
, ipst
,
9401 legacy_req
)) == NULL
) {
9405 if ((mpctl
= ip_snmp_get_mib2_ip6_addr(q
, mpctl
, ipst
,
9406 legacy_req
)) == NULL
) {
9410 if ((mpctl
= ip_snmp_get_mib2_ip_group_mem(q
, mpctl
, ipst
)) == NULL
) {
9414 if ((mpctl
= ip_snmp_get_mib2_ip6_group_mem(q
, mpctl
, ipst
)) == NULL
) {
9418 if ((mpctl
= ip_snmp_get_mib2_ip_group_src(q
, mpctl
, ipst
)) == NULL
) {
9422 if ((mpctl
= ip_snmp_get_mib2_ip6_group_src(q
, mpctl
, ipst
)) == NULL
) {
9426 if ((mpctl
= ip_snmp_get_mib2_virt_multi(q
, mpctl
, ipst
)) == NULL
) {
9430 if ((mpctl
= ip_snmp_get_mib2_multi_rtable(q
, mpctl
, ipst
)) == NULL
) {
9434 mpctl
= ip_snmp_get_mib2_ip_route_media(q
, mpctl
, level
, ipst
);
9438 mpctl
= ip_snmp_get_mib2_ip6_route_media(q
, mpctl
, level
, ipst
);
9442 if ((mpctl
= sctp_snmp_get_mib2(q
, mpctl
, sctps
)) == NULL
) {
9445 if ((mpctl
= ip_snmp_get_mib2_ip_dce(q
, mpctl
, ipst
)) == NULL
) {
9452 /* Get global (legacy) IPv4 statistics */
9454 ip_snmp_get_mib2_ip(queue_t
*q
, mblk_t
*mpctl
, mib2_ipIfStatsEntry_t
*ipmib
,
9455 ip_stack_t
*ipst
, boolean_t legacy_req
)
9457 mib2_ip_t old_ip_mib
;
9458 struct opthdr
*optp
;
9460 mib2_ipAddrEntry_t mae
;
9463 * make a copy of the original message
9465 mp2ctl
= copymsg(mpctl
);
9467 /* fixed length IP structure... */
9468 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9469 optp
->level
= MIB2_IP
;
9471 SET_MIB(old_ip_mib
.ipForwarding
,
9472 (WE_ARE_FORWARDING(ipst
) ? 1 : 2));
9473 SET_MIB(old_ip_mib
.ipDefaultTTL
,
9474 (uint32_t)ipst
->ips_ip_def_ttl
);
9475 SET_MIB(old_ip_mib
.ipReasmTimeout
,
9476 ipst
->ips_ip_reassembly_timeout
);
9477 SET_MIB(old_ip_mib
.ipAddrEntrySize
,
9478 (legacy_req
) ? LEGACY_MIB_SIZE(&mae
, mib2_ipAddrEntry_t
) :
9479 sizeof (mib2_ipAddrEntry_t
));
9480 SET_MIB(old_ip_mib
.ipRouteEntrySize
,
9481 sizeof (mib2_ipRouteEntry_t
));
9482 SET_MIB(old_ip_mib
.ipNetToMediaEntrySize
,
9483 sizeof (mib2_ipNetToMediaEntry_t
));
9484 SET_MIB(old_ip_mib
.ipMemberEntrySize
, sizeof (ip_member_t
));
9485 SET_MIB(old_ip_mib
.ipGroupSourceEntrySize
, sizeof (ip_grpsrc_t
));
9486 SET_MIB(old_ip_mib
.ipDestEntrySize
, sizeof (dest_cache_entry_t
));
9489 * Grab the statistics from the new IP MIB
9491 SET_MIB(old_ip_mib
.ipInReceives
,
9492 (uint32_t)ipmib
->ipIfStatsHCInReceives
);
9493 SET_MIB(old_ip_mib
.ipInHdrErrors
, ipmib
->ipIfStatsInHdrErrors
);
9494 SET_MIB(old_ip_mib
.ipInAddrErrors
, ipmib
->ipIfStatsInAddrErrors
);
9495 SET_MIB(old_ip_mib
.ipForwDatagrams
,
9496 (uint32_t)ipmib
->ipIfStatsHCOutForwDatagrams
);
9497 SET_MIB(old_ip_mib
.ipInUnknownProtos
,
9498 ipmib
->ipIfStatsInUnknownProtos
);
9499 SET_MIB(old_ip_mib
.ipInDiscards
, ipmib
->ipIfStatsInDiscards
);
9500 SET_MIB(old_ip_mib
.ipInDelivers
,
9501 (uint32_t)ipmib
->ipIfStatsHCInDelivers
);
9502 SET_MIB(old_ip_mib
.ipOutRequests
,
9503 (uint32_t)ipmib
->ipIfStatsHCOutRequests
);
9504 SET_MIB(old_ip_mib
.ipOutDiscards
, ipmib
->ipIfStatsOutDiscards
);
9505 SET_MIB(old_ip_mib
.ipOutNoRoutes
, ipmib
->ipIfStatsOutNoRoutes
);
9506 SET_MIB(old_ip_mib
.ipReasmReqds
, ipmib
->ipIfStatsReasmReqds
);
9507 SET_MIB(old_ip_mib
.ipReasmOKs
, ipmib
->ipIfStatsReasmOKs
);
9508 SET_MIB(old_ip_mib
.ipReasmFails
, ipmib
->ipIfStatsReasmFails
);
9509 SET_MIB(old_ip_mib
.ipFragOKs
, ipmib
->ipIfStatsOutFragOKs
);
9510 SET_MIB(old_ip_mib
.ipFragFails
, ipmib
->ipIfStatsOutFragFails
);
9511 SET_MIB(old_ip_mib
.ipFragCreates
, ipmib
->ipIfStatsOutFragCreates
);
9513 /* ipRoutingDiscards is not being used */
9514 SET_MIB(old_ip_mib
.ipRoutingDiscards
, 0);
9515 SET_MIB(old_ip_mib
.tcpInErrs
, ipmib
->tcpIfStatsInErrs
);
9516 SET_MIB(old_ip_mib
.udpNoPorts
, ipmib
->udpIfStatsNoPorts
);
9517 SET_MIB(old_ip_mib
.ipInCksumErrs
, ipmib
->ipIfStatsInCksumErrs
);
9518 SET_MIB(old_ip_mib
.ipReasmDuplicates
,
9519 ipmib
->ipIfStatsReasmDuplicates
);
9520 SET_MIB(old_ip_mib
.ipReasmPartDups
, ipmib
->ipIfStatsReasmPartDups
);
9521 SET_MIB(old_ip_mib
.ipForwProhibits
, ipmib
->ipIfStatsForwProhibits
);
9522 SET_MIB(old_ip_mib
.udpInCksumErrs
, ipmib
->udpIfStatsInCksumErrs
);
9523 SET_MIB(old_ip_mib
.udpInOverflows
, ipmib
->udpIfStatsInOverflows
);
9524 SET_MIB(old_ip_mib
.rawipInOverflows
,
9525 ipmib
->rawipIfStatsInOverflows
);
9527 SET_MIB(old_ip_mib
.ipsecInSucceeded
, ipmib
->ipsecIfStatsInSucceeded
);
9528 SET_MIB(old_ip_mib
.ipsecInFailed
, ipmib
->ipsecIfStatsInFailed
);
9529 SET_MIB(old_ip_mib
.ipInIPv6
, ipmib
->ipIfStatsInWrongIPVersion
);
9530 SET_MIB(old_ip_mib
.ipOutIPv6
, ipmib
->ipIfStatsOutWrongIPVersion
);
9531 SET_MIB(old_ip_mib
.ipOutSwitchIPv6
,
9532 ipmib
->ipIfStatsOutSwitchIPVersion
);
9534 if (!snmp_append_data(mpctl
->b_cont
, (char *)&old_ip_mib
,
9535 (int)sizeof (old_ip_mib
))) {
9536 ip1dbg(("ip_snmp_get_mib2_ip: failed to allocate %u bytes\n",
9537 (uint_t
)sizeof (old_ip_mib
)));
9540 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9541 ip3dbg(("ip_snmp_get_mib2_ip: level %d, name %d, len %d\n",
9542 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9547 /* Per interface IPv4 statistics */
9549 ip_snmp_get_mib2_ip_traffic_stats(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
9550 boolean_t legacy_req
)
9552 struct opthdr
*optp
;
9555 ill_walk_context_t ctx
;
9556 mblk_t
*mp_tail
= NULL
;
9557 mib2_ipIfStatsEntry_t global_ip_mib
;
9558 mib2_ipAddrEntry_t mae
;
9561 * Make a copy of the original message
9563 mp2ctl
= copymsg(mpctl
);
9565 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9566 optp
->level
= MIB2_IP
;
9567 optp
->name
= MIB2_IP_TRAFFIC_STATS
;
9568 /* Include "unknown interface" ip_mib */
9569 ipst
->ips_ip_mib
.ipIfStatsIPVersion
= MIB2_INETADDRESSTYPE_ipv4
;
9570 ipst
->ips_ip_mib
.ipIfStatsIfIndex
=
9571 MIB2_UNKNOWN_INTERFACE
; /* Flag to netstat */
9572 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsForwarding
,
9573 (ipst
->ips_ip_forwarding
? 1 : 2));
9574 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsDefaultTTL
,
9575 (uint32_t)ipst
->ips_ip_def_ttl
);
9576 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsEntrySize
,
9577 sizeof (mib2_ipIfStatsEntry_t
));
9578 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsAddrEntrySize
,
9579 sizeof (mib2_ipAddrEntry_t
));
9580 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsRouteEntrySize
,
9581 sizeof (mib2_ipRouteEntry_t
));
9582 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsNetToMediaEntrySize
,
9583 sizeof (mib2_ipNetToMediaEntry_t
));
9584 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsMemberEntrySize
,
9585 sizeof (ip_member_t
));
9586 SET_MIB(ipst
->ips_ip_mib
.ipIfStatsGroupSourceEntrySize
,
9587 sizeof (ip_grpsrc_t
));
9589 bcopy(&ipst
->ips_ip_mib
, &global_ip_mib
, sizeof (global_ip_mib
));
9592 SET_MIB(global_ip_mib
.ipIfStatsAddrEntrySize
,
9593 LEGACY_MIB_SIZE(&mae
, mib2_ipAddrEntry_t
));
9596 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9597 (char *)&global_ip_mib
, (int)sizeof (global_ip_mib
))) {
9598 ip1dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
9599 "failed to allocate %u bytes\n",
9600 (uint_t
)sizeof (global_ip_mib
)));
9603 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9604 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
9605 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9606 ill
->ill_ip_mib
->ipIfStatsIfIndex
=
9607 ill
->ill_phyint
->phyint_ifindex
;
9608 SET_MIB(ill
->ill_ip_mib
->ipIfStatsForwarding
,
9609 (ipst
->ips_ip_forwarding
? 1 : 2));
9610 SET_MIB(ill
->ill_ip_mib
->ipIfStatsDefaultTTL
,
9611 (uint32_t)ipst
->ips_ip_def_ttl
);
9613 ip_mib2_add_ip_stats(&global_ip_mib
, ill
->ill_ip_mib
);
9614 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9615 (char *)ill
->ill_ip_mib
,
9616 (int)sizeof (*ill
->ill_ip_mib
))) {
9617 ip1dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
9618 "failed to allocate %u bytes\n",
9619 (uint_t
)sizeof (*ill
->ill_ip_mib
)));
9622 rw_exit(&ipst
->ips_ill_g_lock
);
9624 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9625 ip3dbg(("ip_snmp_get_mib2_ip_traffic_stats: "
9626 "level %d, name %d, len %d\n",
9627 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9633 return (ip_snmp_get_mib2_ip(q
, mp2ctl
, &global_ip_mib
, ipst
,
9637 /* Global IPv4 ICMP statistics */
9639 ip_snmp_get_mib2_icmp(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9641 struct opthdr
*optp
;
9645 * Make a copy of the original message
9647 mp2ctl
= copymsg(mpctl
);
9649 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9650 optp
->level
= MIB2_ICMP
;
9652 if (!snmp_append_data(mpctl
->b_cont
, (char *)&ipst
->ips_icmp_mib
,
9653 (int)sizeof (ipst
->ips_icmp_mib
))) {
9654 ip1dbg(("ip_snmp_get_mib2_icmp: failed to allocate %u bytes\n",
9655 (uint_t
)sizeof (ipst
->ips_icmp_mib
)));
9657 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9658 ip3dbg(("ip_snmp_get_mib2_icmp: level %d, name %d, len %d\n",
9659 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9664 /* Global IPv4 IGMP statistics */
9666 ip_snmp_get_mib2_igmp(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9668 struct opthdr
*optp
;
9672 * make a copy of the original message
9674 mp2ctl
= copymsg(mpctl
);
9676 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9677 optp
->level
= EXPER_IGMP
;
9679 if (!snmp_append_data(mpctl
->b_cont
, (char *)&ipst
->ips_igmpstat
,
9680 (int)sizeof (ipst
->ips_igmpstat
))) {
9681 ip1dbg(("ip_snmp_get_mib2_igmp: failed to allocate %u bytes\n",
9682 (uint_t
)sizeof (ipst
->ips_igmpstat
)));
9684 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9685 ip3dbg(("ip_snmp_get_mib2_igmp: level %d, name %d, len %d\n",
9686 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9691 /* Global IPv4 Multicast Routing statistics */
9693 ip_snmp_get_mib2_multi(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9695 struct opthdr
*optp
;
9699 * make a copy of the original message
9701 mp2ctl
= copymsg(mpctl
);
9703 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9704 optp
->level
= EXPER_DVMRP
;
9706 if (!ip_mroute_stats(mpctl
->b_cont
, ipst
)) {
9707 ip0dbg(("ip_mroute_stats: failed\n"));
9709 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9710 ip3dbg(("ip_snmp_get_mib2_multi: level %d, name %d, len %d\n",
9711 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9716 /* IPv4 address information */
9718 ip_snmp_get_mib2_ip_addr(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
9719 boolean_t legacy_req
)
9721 struct opthdr
*optp
;
9723 mblk_t
*mp_tail
= NULL
;
9727 mib2_ipAddrEntry_t mae
;
9730 ill_walk_context_t ctx
;
9733 * make a copy of the original message
9735 mp2ctl
= copymsg(mpctl
);
9737 mae_size
= (legacy_req
) ? LEGACY_MIB_SIZE(&mae
, mib2_ipAddrEntry_t
) :
9738 sizeof (mib2_ipAddrEntry_t
);
9740 /* ipAddrEntryTable */
9742 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9743 optp
->level
= MIB2_IP
;
9744 optp
->name
= MIB2_IP_ADDR
;
9745 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
9747 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9748 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
9749 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9750 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9751 ipif
= ipif
->ipif_next
) {
9752 if (ipif
->ipif_zoneid
!= zoneid
&&
9753 ipif
->ipif_zoneid
!= ALL_ZONES
)
9755 /* Sum of count from dead IRE_LO* and our current */
9756 mae
.ipAdEntInfo
.ae_ibcnt
= ipif
->ipif_ib_pkt_count
;
9757 if (ipif
->ipif_ire_local
!= NULL
) {
9758 mae
.ipAdEntInfo
.ae_ibcnt
+=
9759 ipif
->ipif_ire_local
->ire_ib_pkt_count
;
9761 mae
.ipAdEntInfo
.ae_obcnt
= 0;
9762 mae
.ipAdEntInfo
.ae_focnt
= 0;
9764 ipif_get_name(ipif
, mae
.ipAdEntIfIndex
.o_bytes
,
9766 mae
.ipAdEntIfIndex
.o_length
=
9767 mi_strlen(mae
.ipAdEntIfIndex
.o_bytes
);
9768 mae
.ipAdEntAddr
= ipif
->ipif_lcl_addr
;
9769 mae
.ipAdEntNetMask
= ipif
->ipif_net_mask
;
9770 mae
.ipAdEntInfo
.ae_subnet
= ipif
->ipif_subnet
;
9771 mae
.ipAdEntInfo
.ae_subnet_len
=
9772 ip_mask_to_plen(ipif
->ipif_net_mask
);
9773 mae
.ipAdEntInfo
.ae_src_addr
= ipif
->ipif_lcl_addr
;
9776 !(bitval
& ipif
->ipif_brd_addr
);
9779 mae
.ipAdEntBcastAddr
= bitval
;
9780 mae
.ipAdEntReasmMaxSize
= IP_MAXPACKET
;
9781 mae
.ipAdEntInfo
.ae_mtu
= ipif
->ipif_ill
->ill_mtu
;
9782 mae
.ipAdEntInfo
.ae_metric
= ipif
->ipif_ill
->ill_metric
;
9783 mae
.ipAdEntInfo
.ae_broadcast_addr
=
9784 ipif
->ipif_brd_addr
;
9785 mae
.ipAdEntInfo
.ae_pp_dst_addr
=
9786 ipif
->ipif_pp_dst_addr
;
9787 mae
.ipAdEntInfo
.ae_flags
= ipif
->ipif_flags
|
9788 ill
->ill_flags
| ill
->ill_phyint
->phyint_flags
;
9789 mae
.ipAdEntRetransmitTime
=
9790 ill
->ill_reachable_retrans_time
;
9792 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9793 (char *)&mae
, (int)mae_size
)) {
9794 ip1dbg(("ip_snmp_get_mib2_ip_addr: failed to "
9795 "allocate %u bytes\n", (uint_t
)mae_size
));
9799 rw_exit(&ipst
->ips_ill_g_lock
);
9801 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9802 ip3dbg(("ip_snmp_get_mib2_ip_addr: level %d, name %d, len %d\n",
9803 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9808 /* IPv6 address information */
9810 ip_snmp_get_mib2_ip6_addr(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
9811 boolean_t legacy_req
)
9813 struct opthdr
*optp
;
9815 mblk_t
*mp_tail
= NULL
;
9818 mib2_ipv6AddrEntry_t mae6
;
9821 ill_walk_context_t ctx
;
9824 * make a copy of the original message
9826 mp2ctl
= copymsg(mpctl
);
9828 mae6_size
= (legacy_req
) ?
9829 LEGACY_MIB_SIZE(&mae6
, mib2_ipv6AddrEntry_t
) :
9830 sizeof (mib2_ipv6AddrEntry_t
);
9832 /* ipv6AddrEntryTable */
9834 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
9835 optp
->level
= MIB2_IP6
;
9836 optp
->name
= MIB2_IP6_ADDR
;
9837 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
9839 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9840 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
9841 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9842 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9843 ipif
= ipif
->ipif_next
) {
9844 if (ipif
->ipif_zoneid
!= zoneid
&&
9845 ipif
->ipif_zoneid
!= ALL_ZONES
)
9847 /* Sum of count from dead IRE_LO* and our current */
9848 mae6
.ipv6AddrInfo
.ae_ibcnt
= ipif
->ipif_ib_pkt_count
;
9849 if (ipif
->ipif_ire_local
!= NULL
) {
9850 mae6
.ipv6AddrInfo
.ae_ibcnt
+=
9851 ipif
->ipif_ire_local
->ire_ib_pkt_count
;
9853 mae6
.ipv6AddrInfo
.ae_obcnt
= 0;
9854 mae6
.ipv6AddrInfo
.ae_focnt
= 0;
9856 ipif_get_name(ipif
, mae6
.ipv6AddrIfIndex
.o_bytes
,
9858 mae6
.ipv6AddrIfIndex
.o_length
=
9859 mi_strlen(mae6
.ipv6AddrIfIndex
.o_bytes
);
9860 mae6
.ipv6AddrAddress
= ipif
->ipif_v6lcl_addr
;
9861 mae6
.ipv6AddrPfxLength
=
9862 ip_mask_to_plen_v6(&ipif
->ipif_v6net_mask
);
9863 mae6
.ipv6AddrInfo
.ae_subnet
= ipif
->ipif_v6subnet
;
9864 mae6
.ipv6AddrInfo
.ae_subnet_len
=
9865 mae6
.ipv6AddrPfxLength
;
9866 mae6
.ipv6AddrInfo
.ae_src_addr
= ipif
->ipif_v6lcl_addr
;
9868 /* Type: stateless(1), stateful(2), unknown(3) */
9869 if (ipif
->ipif_flags
& IPIF_ADDRCONF
)
9870 mae6
.ipv6AddrType
= 1;
9872 mae6
.ipv6AddrType
= 2;
9873 /* Anycast: true(1), false(2) */
9874 if (ipif
->ipif_flags
& IPIF_ANYCAST
)
9875 mae6
.ipv6AddrAnycastFlag
= 1;
9877 mae6
.ipv6AddrAnycastFlag
= 2;
9880 * Address status: preferred(1), deprecated(2),
9881 * invalid(3), inaccessible(4), unknown(5)
9883 if (ipif
->ipif_flags
& IPIF_NOLOCAL
)
9884 mae6
.ipv6AddrStatus
= 3;
9885 else if (ipif
->ipif_flags
& IPIF_DEPRECATED
)
9886 mae6
.ipv6AddrStatus
= 2;
9888 mae6
.ipv6AddrStatus
= 1;
9889 mae6
.ipv6AddrInfo
.ae_mtu
= ipif
->ipif_ill
->ill_mtu
;
9890 mae6
.ipv6AddrInfo
.ae_metric
=
9891 ipif
->ipif_ill
->ill_metric
;
9892 mae6
.ipv6AddrInfo
.ae_pp_dst_addr
=
9893 ipif
->ipif_v6pp_dst_addr
;
9894 mae6
.ipv6AddrInfo
.ae_flags
= ipif
->ipif_flags
|
9895 ill
->ill_flags
| ill
->ill_phyint
->phyint_flags
;
9896 mae6
.ipv6AddrReasmMaxSize
= IP_MAXPACKET
;
9897 mae6
.ipv6AddrIdentifier
= ill
->ill_token
;
9898 mae6
.ipv6AddrIdentifierLen
= ill
->ill_token_length
;
9899 mae6
.ipv6AddrReachableTime
= ill
->ill_reachable_time
;
9900 mae6
.ipv6AddrRetransmitTime
=
9901 ill
->ill_reachable_retrans_time
;
9902 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9903 (char *)&mae6
, (int)mae6_size
)) {
9904 ip1dbg(("ip_snmp_get_mib2_ip6_addr: failed to "
9905 "allocate %u bytes\n",
9906 (uint_t
)mae6_size
));
9910 rw_exit(&ipst
->ips_ill_g_lock
);
9912 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9913 ip3dbg(("ip_snmp_get_mib2_ip6_addr: level %d, name %d, len %d\n",
9914 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
9919 /* IPv4 multicast group membership. */
9921 ip_snmp_get_mib2_ip_group_mem(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
9923 struct opthdr
*optp
;
9929 mblk_t
*mp_tail
= NULL
;
9930 ill_walk_context_t ctx
;
9934 * make a copy of the original message
9936 mp2ctl
= copymsg(mpctl
);
9937 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
9939 /* ipGroupMember table */
9940 optp
= (struct opthdr
*)&mpctl
->b_rptr
[
9941 sizeof (struct T_optmgmt_ack
)];
9942 optp
->level
= MIB2_IP
;
9943 optp
->name
= EXPER_IP_GROUP_MEMBERSHIP
;
9945 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9946 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
9947 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
9948 /* Make sure the ill isn't going away. */
9949 if (!ill_check_and_refhold(ill
))
9951 rw_exit(&ipst
->ips_ill_g_lock
);
9952 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
9953 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
9954 if (ilm
->ilm_zoneid
!= zoneid
&&
9955 ilm
->ilm_zoneid
!= ALL_ZONES
)
9958 /* Is there an ipif for ilm_ifaddr? */
9959 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
9960 ipif
= ipif
->ipif_next
) {
9961 if (!IPIF_IS_CONDEMNED(ipif
) &&
9962 ipif
->ipif_lcl_addr
== ilm
->ilm_ifaddr
&&
9963 ilm
->ilm_ifaddr
!= INADDR_ANY
)
9968 ipm
.ipGroupMemberIfIndex
.o_bytes
,
9972 ipm
.ipGroupMemberIfIndex
.o_bytes
,
9975 ipm
.ipGroupMemberIfIndex
.o_length
=
9976 mi_strlen(ipm
.ipGroupMemberIfIndex
.o_bytes
);
9978 ipm
.ipGroupMemberAddress
= ilm
->ilm_addr
;
9979 ipm
.ipGroupMemberRefCnt
= ilm
->ilm_refcnt
;
9980 ipm
.ipGroupMemberFilterMode
= ilm
->ilm_fmode
;
9981 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
9982 (char *)&ipm
, (int)sizeof (ipm
))) {
9983 ip1dbg(("ip_snmp_get_mib2_ip_group: "
9984 "failed to allocate %u bytes\n",
9985 (uint_t
)sizeof (ipm
)));
9988 rw_exit(&ill
->ill_mcast_lock
);
9990 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
9992 rw_exit(&ipst
->ips_ill_g_lock
);
9993 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
9994 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
9995 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10000 /* IPv6 multicast group membership. */
10002 ip_snmp_get_mib2_ip6_group_mem(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10004 struct opthdr
*optp
;
10008 ipv6_member_t ipm6
;
10009 mblk_t
*mp_tail
= NULL
;
10010 ill_walk_context_t ctx
;
10014 * make a copy of the original message
10016 mp2ctl
= copymsg(mpctl
);
10017 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10019 /* ip6GroupMember table */
10020 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10021 optp
->level
= MIB2_IP6
;
10022 optp
->name
= EXPER_IP6_GROUP_MEMBERSHIP
;
10024 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10025 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10026 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10027 /* Make sure the ill isn't going away. */
10028 if (!ill_check_and_refhold(ill
))
10030 rw_exit(&ipst
->ips_ill_g_lock
);
10032 * Normally we don't have any members on under IPMP interfaces.
10033 * We report them as a debugging aid.
10035 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
10036 ipm6
.ipv6GroupMemberIfIndex
= ill
->ill_phyint
->phyint_ifindex
;
10037 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
10038 if (ilm
->ilm_zoneid
!= zoneid
&&
10039 ilm
->ilm_zoneid
!= ALL_ZONES
)
10040 continue; /* not this zone */
10041 ipm6
.ipv6GroupMemberAddress
= ilm
->ilm_v6addr
;
10042 ipm6
.ipv6GroupMemberRefCnt
= ilm
->ilm_refcnt
;
10043 ipm6
.ipv6GroupMemberFilterMode
= ilm
->ilm_fmode
;
10044 if (!snmp_append_data2(mpctl
->b_cont
,
10046 (char *)&ipm6
, (int)sizeof (ipm6
))) {
10047 ip1dbg(("ip_snmp_get_mib2_ip6_group: "
10048 "failed to allocate %u bytes\n",
10049 (uint_t
)sizeof (ipm6
)));
10052 rw_exit(&ill
->ill_mcast_lock
);
10054 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10056 rw_exit(&ipst
->ips_ill_g_lock
);
10058 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10059 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
10060 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10065 /* IP multicast filtered sources */
10067 ip_snmp_get_mib2_ip_group_src(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10069 struct opthdr
*optp
;
10075 mblk_t
*mp_tail
= NULL
;
10076 ill_walk_context_t ctx
;
10082 * make a copy of the original message
10084 mp2ctl
= copymsg(mpctl
);
10085 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10087 /* ipGroupSource table */
10088 optp
= (struct opthdr
*)&mpctl
->b_rptr
[
10089 sizeof (struct T_optmgmt_ack
)];
10090 optp
->level
= MIB2_IP
;
10091 optp
->name
= EXPER_IP_GROUP_SOURCES
;
10093 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10094 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
10095 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10096 /* Make sure the ill isn't going away. */
10097 if (!ill_check_and_refhold(ill
))
10099 rw_exit(&ipst
->ips_ill_g_lock
);
10100 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
10101 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
10102 sl
= ilm
->ilm_filter
;
10103 if (ilm
->ilm_zoneid
!= zoneid
&&
10104 ilm
->ilm_zoneid
!= ALL_ZONES
)
10106 if (SLIST_IS_EMPTY(sl
))
10109 /* Is there an ipif for ilm_ifaddr? */
10110 for (ipif
= ill
->ill_ipif
; ipif
!= NULL
;
10111 ipif
= ipif
->ipif_next
) {
10112 if (!IPIF_IS_CONDEMNED(ipif
) &&
10113 ipif
->ipif_lcl_addr
== ilm
->ilm_ifaddr
&&
10114 ilm
->ilm_ifaddr
!= INADDR_ANY
)
10117 if (ipif
!= NULL
) {
10118 ipif_get_name(ipif
,
10119 ips
.ipGroupSourceIfIndex
.o_bytes
,
10123 ips
.ipGroupSourceIfIndex
.o_bytes
,
10126 ips
.ipGroupSourceIfIndex
.o_length
=
10127 mi_strlen(ips
.ipGroupSourceIfIndex
.o_bytes
);
10129 ips
.ipGroupSourceGroup
= ilm
->ilm_addr
;
10130 for (i
= 0; i
< sl
->sl_numsrc
; i
++) {
10131 if (!IN6_IS_ADDR_V4MAPPED(&sl
->sl_addr
[i
]))
10133 IN6_V4MAPPED_TO_IPADDR(&sl
->sl_addr
[i
],
10134 ips
.ipGroupSourceAddress
);
10135 if (snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10136 (char *)&ips
, (int)sizeof (ips
)) == 0) {
10137 ip1dbg(("ip_snmp_get_mib2_ip_group_src:"
10138 " failed to allocate %u bytes\n",
10139 (uint_t
)sizeof (ips
)));
10143 rw_exit(&ill
->ill_mcast_lock
);
10145 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10147 rw_exit(&ipst
->ips_ill_g_lock
);
10148 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10149 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
10150 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10155 /* IPv6 multicast filtered sources. */
10157 ip_snmp_get_mib2_ip6_group_src(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10159 struct opthdr
*optp
;
10163 ipv6_grpsrc_t ips6
;
10164 mblk_t
*mp_tail
= NULL
;
10165 ill_walk_context_t ctx
;
10171 * make a copy of the original message
10173 mp2ctl
= copymsg(mpctl
);
10174 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10176 /* ip6GroupMember table */
10177 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10178 optp
->level
= MIB2_IP6
;
10179 optp
->name
= EXPER_IP6_GROUP_SOURCES
;
10181 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10182 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10183 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10184 /* Make sure the ill isn't going away. */
10185 if (!ill_check_and_refhold(ill
))
10187 rw_exit(&ipst
->ips_ill_g_lock
);
10189 * Normally we don't have any members on under IPMP interfaces.
10190 * We report them as a debugging aid.
10192 rw_enter(&ill
->ill_mcast_lock
, RW_READER
);
10193 ips6
.ipv6GroupSourceIfIndex
= ill
->ill_phyint
->phyint_ifindex
;
10194 for (ilm
= ill
->ill_ilm
; ilm
; ilm
= ilm
->ilm_next
) {
10195 sl
= ilm
->ilm_filter
;
10196 if (ilm
->ilm_zoneid
!= zoneid
&&
10197 ilm
->ilm_zoneid
!= ALL_ZONES
)
10199 if (SLIST_IS_EMPTY(sl
))
10201 ips6
.ipv6GroupSourceGroup
= ilm
->ilm_v6addr
;
10202 for (i
= 0; i
< sl
->sl_numsrc
; i
++) {
10203 ips6
.ipv6GroupSourceAddress
= sl
->sl_addr
[i
];
10204 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10205 (char *)&ips6
, (int)sizeof (ips6
))) {
10206 ip1dbg(("ip_snmp_get_mib2_ip6_"
10207 "group_src: failed to allocate "
10209 (uint_t
)sizeof (ips6
)));
10213 rw_exit(&ill
->ill_mcast_lock
);
10215 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10217 rw_exit(&ipst
->ips_ill_g_lock
);
10219 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10220 ip3dbg(("ip_snmp_get: level %d, name %d, len %d\n",
10221 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10226 /* Multicast routing virtual interface table. */
10228 ip_snmp_get_mib2_virt_multi(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10230 struct opthdr
*optp
;
10234 * make a copy of the original message
10236 mp2ctl
= copymsg(mpctl
);
10238 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10239 optp
->level
= EXPER_DVMRP
;
10240 optp
->name
= EXPER_DVMRP_VIF
;
10241 if (!ip_mroute_vif(mpctl
->b_cont
, ipst
)) {
10242 ip0dbg(("ip_mroute_vif: failed\n"));
10244 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10245 ip3dbg(("ip_snmp_get_mib2_virt_multi: level %d, name %d, len %d\n",
10246 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10251 /* Multicast routing table. */
10253 ip_snmp_get_mib2_multi_rtable(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10255 struct opthdr
*optp
;
10259 * make a copy of the original message
10261 mp2ctl
= copymsg(mpctl
);
10263 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10264 optp
->level
= EXPER_DVMRP
;
10265 optp
->name
= EXPER_DVMRP_MRT
;
10266 if (!ip_mroute_mrt(mpctl
->b_cont
, ipst
)) {
10267 ip0dbg(("ip_mroute_mrt: failed\n"));
10269 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10270 ip3dbg(("ip_snmp_get_mib2_multi_rtable: level %d, name %d, len %d\n",
10271 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10277 * Return ipRouteEntryTable and ipNetToMediaEntryTable in one IRE walk.
10280 ip_snmp_get_mib2_ip_route_media(queue_t
*q
, mblk_t
*mpctl
, int level
,
10283 struct opthdr
*optp
;
10284 mblk_t
*mp2ctl
; /* Returned */
10285 mblk_t
*mp3ctl
; /* nettomedia */
10290 * make copies of the original message
10291 * - mp2ctl is returned unchanged to the caller for its use
10292 * - mpctl is sent upstream as ipRouteEntryTable
10293 * - mp3ctl is sent upstream as ipNetToMediaEntryTable
10295 mp2ctl
= copymsg(mpctl
);
10296 mp3ctl
= copymsg(mpctl
);
10297 if (mp3ctl
== NULL
) {
10304 bzero(&ird
, sizeof (ird
));
10306 ird
.ird_route
.lp_head
= mpctl
->b_cont
;
10307 ird
.ird_netmedia
.lp_head
= mp3ctl
->b_cont
;
10309 * If the level has been set the special EXPER_IP_AND_ALL_IRES value,
10310 * then also include ire_testhidden IREs and IRE_IF_CLONE. This is
10311 * intended a temporary solution until a proper MIB API is provided
10312 * that provides complete filtering/caller-opt-in.
10314 if (level
== EXPER_IP_AND_ALL_IRES
)
10315 ird
.ird_flags
|= IRD_REPORT_ALL
;
10317 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10318 ire_walk_v4(ip_snmp_get2_v4
, &ird
, zoneid
, ipst
);
10320 /* ipRouteEntryTable in mpctl */
10321 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10322 optp
->level
= MIB2_IP
;
10323 optp
->name
= MIB2_IP_ROUTE
;
10324 optp
->len
= msgdsize(ird
.ird_route
.lp_head
);
10325 ip3dbg(("ip_snmp_get_mib2_ip_route_media: level %d, name %d, len %d\n",
10326 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10329 /* ipNetToMediaEntryTable in mp3ctl */
10330 ncec_walk(NULL
, ip_snmp_get2_v4_media
, &ird
, ipst
);
10332 optp
= (struct opthdr
*)&mp3ctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10333 optp
->level
= MIB2_IP
;
10334 optp
->name
= MIB2_IP_MEDIA
;
10335 optp
->len
= msgdsize(ird
.ird_netmedia
.lp_head
);
10336 ip3dbg(("ip_snmp_get_mib2_ip_route_media: level %d, name %d, len %d\n",
10337 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10344 * Return ipv6RouteEntryTable in one IRE walk, and ipv6NetToMediaEntryTable in
10348 ip_snmp_get_mib2_ip6_route_media(queue_t
*q
, mblk_t
*mpctl
, int level
,
10351 struct opthdr
*optp
;
10352 mblk_t
*mp2ctl
; /* Returned */
10353 mblk_t
*mp3ctl
; /* nettomedia */
10358 * make copies of the original message
10359 * - mp2ctl is returned unchanged to the caller for its use
10360 * - mpctl is sent upstream as ipv6RouteEntryTable
10361 * - mp3ctl is sent upstream as ipv6NetToMediaEntryTable
10363 mp2ctl
= copymsg(mpctl
);
10364 mp3ctl
= copymsg(mpctl
);
10365 if (mp3ctl
== NULL
) {
10372 bzero(&ird
, sizeof (ird
));
10374 ird
.ird_route
.lp_head
= mpctl
->b_cont
;
10375 ird
.ird_netmedia
.lp_head
= mp3ctl
->b_cont
;
10377 * If the level has been set the special EXPER_IP_AND_ALL_IRES value,
10378 * then also include ire_testhidden IREs and IRE_IF_CLONE. This is
10379 * intended a temporary solution until a proper MIB API is provided
10380 * that provides complete filtering/caller-opt-in.
10382 if (level
== EXPER_IP_AND_ALL_IRES
)
10383 ird
.ird_flags
|= IRD_REPORT_ALL
;
10385 zoneid
= Q_TO_CONN(q
)->conn_zoneid
;
10386 ire_walk_v6(ip_snmp_get2_v6_route
, &ird
, zoneid
, ipst
);
10388 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10389 optp
->level
= MIB2_IP6
;
10390 optp
->name
= MIB2_IP6_ROUTE
;
10391 optp
->len
= msgdsize(ird
.ird_route
.lp_head
);
10392 ip3dbg(("ip_snmp_get_mib2_ip6_route_media: level %d, name %d, len %d\n",
10393 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10396 /* ipv6NetToMediaEntryTable in mp3ctl */
10397 ncec_walk(NULL
, ip_snmp_get2_v6_media
, &ird
, ipst
);
10399 optp
= (struct opthdr
*)&mp3ctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10400 optp
->level
= MIB2_IP6
;
10401 optp
->name
= MIB2_IP6_MEDIA
;
10402 optp
->len
= msgdsize(ird
.ird_netmedia
.lp_head
);
10403 ip3dbg(("ip_snmp_get_mib2_ip6_route_media: level %d, name %d, len %d\n",
10404 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10411 * IPv6 mib: One per ill
10414 ip_snmp_get_mib2_ip6(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
,
10415 boolean_t legacy_req
)
10417 struct opthdr
*optp
;
10420 ill_walk_context_t ctx
;
10421 mblk_t
*mp_tail
= NULL
;
10422 mib2_ipv6AddrEntry_t mae6
;
10423 mib2_ipIfStatsEntry_t
*ise
;
10424 size_t ise_size
, iae_size
;
10427 * Make a copy of the original message
10429 mp2ctl
= copymsg(mpctl
);
10431 /* fixed length IPv6 structure ... */
10434 ise_size
= LEGACY_MIB_SIZE(&ipst
->ips_ip6_mib
,
10435 mib2_ipIfStatsEntry_t
);
10436 iae_size
= LEGACY_MIB_SIZE(&mae6
, mib2_ipv6AddrEntry_t
);
10438 ise_size
= sizeof (mib2_ipIfStatsEntry_t
);
10439 iae_size
= sizeof (mib2_ipv6AddrEntry_t
);
10442 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10443 optp
->level
= MIB2_IP6
;
10445 /* Include "unknown interface" ip6_mib */
10446 ipst
->ips_ip6_mib
.ipIfStatsIPVersion
= MIB2_INETADDRESSTYPE_ipv6
;
10447 ipst
->ips_ip6_mib
.ipIfStatsIfIndex
=
10448 MIB2_UNKNOWN_INTERFACE
; /* Flag to netstat */
10449 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsForwarding
,
10450 ipst
->ips_ipv6_forwarding
? 1 : 2);
10451 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsDefaultHopLimit
,
10452 ipst
->ips_ipv6_def_hops
);
10453 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsEntrySize
,
10454 sizeof (mib2_ipIfStatsEntry_t
));
10455 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsAddrEntrySize
,
10456 sizeof (mib2_ipv6AddrEntry_t
));
10457 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsRouteEntrySize
,
10458 sizeof (mib2_ipv6RouteEntry_t
));
10459 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsNetToMediaEntrySize
,
10460 sizeof (mib2_ipv6NetToMediaEntry_t
));
10461 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsMemberEntrySize
,
10462 sizeof (ipv6_member_t
));
10463 SET_MIB(ipst
->ips_ip6_mib
.ipIfStatsGroupSourceEntrySize
,
10464 sizeof (ipv6_grpsrc_t
));
10467 * Synchronize 64- and 32-bit counters
10469 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInReceives
,
10470 ipIfStatsHCInReceives
);
10471 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInDelivers
,
10472 ipIfStatsHCInDelivers
);
10473 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutRequests
,
10474 ipIfStatsHCOutRequests
);
10475 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutForwDatagrams
,
10476 ipIfStatsHCOutForwDatagrams
);
10477 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsOutMcastPkts
,
10478 ipIfStatsHCOutMcastPkts
);
10479 SYNC32_MIB(&ipst
->ips_ip6_mib
, ipIfStatsInMcastPkts
,
10480 ipIfStatsHCInMcastPkts
);
10482 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10483 (char *)&ipst
->ips_ip6_mib
, (int)ise_size
)) {
10484 ip1dbg(("ip_snmp_get_mib2_ip6: failed to allocate %u bytes\n",
10485 (uint_t
)ise_size
));
10486 } else if (legacy_req
) {
10487 /* Adjust the EntrySize fields for legacy requests. */
10489 (mib2_ipIfStatsEntry_t
*)(mp_tail
->b_wptr
- (int)ise_size
);
10490 SET_MIB(ise
->ipIfStatsEntrySize
, ise_size
);
10491 SET_MIB(ise
->ipIfStatsAddrEntrySize
, iae_size
);
10494 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10495 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10496 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10497 ill
->ill_ip_mib
->ipIfStatsIfIndex
=
10498 ill
->ill_phyint
->phyint_ifindex
;
10499 SET_MIB(ill
->ill_ip_mib
->ipIfStatsForwarding
,
10500 ipst
->ips_ipv6_forwarding
? 1 : 2);
10501 SET_MIB(ill
->ill_ip_mib
->ipIfStatsDefaultHopLimit
,
10502 ill
->ill_max_hops
);
10505 * Synchronize 64- and 32-bit counters
10507 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsInReceives
,
10508 ipIfStatsHCInReceives
);
10509 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsInDelivers
,
10510 ipIfStatsHCInDelivers
);
10511 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsOutRequests
,
10512 ipIfStatsHCOutRequests
);
10513 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsOutForwDatagrams
,
10514 ipIfStatsHCOutForwDatagrams
);
10515 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsOutMcastPkts
,
10516 ipIfStatsHCOutMcastPkts
);
10517 SYNC32_MIB(ill
->ill_ip_mib
, ipIfStatsInMcastPkts
,
10518 ipIfStatsHCInMcastPkts
);
10520 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10521 (char *)ill
->ill_ip_mib
, (int)ise_size
)) {
10522 ip1dbg(("ip_snmp_get_mib2_ip6: failed to allocate "
10523 "%u bytes\n", (uint_t
)ise_size
));
10524 } else if (legacy_req
) {
10525 /* Adjust the EntrySize fields for legacy requests. */
10526 ise
= (mib2_ipIfStatsEntry_t
*)(mp_tail
->b_wptr
-
10528 SET_MIB(ise
->ipIfStatsEntrySize
, ise_size
);
10529 SET_MIB(ise
->ipIfStatsAddrEntrySize
, iae_size
);
10532 rw_exit(&ipst
->ips_ill_g_lock
);
10534 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10535 ip3dbg(("ip_snmp_get_mib2_ip6: level %d, name %d, len %d\n",
10536 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10542 * ICMPv6 mib: One per ill
10545 ip_snmp_get_mib2_icmp6(queue_t
*q
, mblk_t
*mpctl
, ip_stack_t
*ipst
)
10547 struct opthdr
*optp
;
10550 ill_walk_context_t ctx
;
10551 mblk_t
*mp_tail
= NULL
;
10553 * Make a copy of the original message
10555 mp2ctl
= copymsg(mpctl
);
10557 /* fixed length ICMPv6 structure ... */
10559 optp
= (struct opthdr
*)&mpctl
->b_rptr
[sizeof (struct T_optmgmt_ack
)];
10560 optp
->level
= MIB2_ICMP6
;
10562 /* Include "unknown interface" icmp6_mib */
10563 ipst
->ips_icmp6_mib
.ipv6IfIcmpIfIndex
=
10564 MIB2_UNKNOWN_INTERFACE
; /* netstat flag */
10565 ipst
->ips_icmp6_mib
.ipv6IfIcmpEntrySize
=
10566 sizeof (mib2_ipv6IfIcmpEntry_t
);
10567 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10568 (char *)&ipst
->ips_icmp6_mib
,
10569 (int)sizeof (ipst
->ips_icmp6_mib
))) {
10570 ip1dbg(("ip_snmp_get_mib2_icmp6: failed to allocate %u bytes\n",
10571 (uint_t
)sizeof (ipst
->ips_icmp6_mib
)));
10574 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
10575 ill
= ILL_START_WALK_V6(&ctx
, ipst
);
10576 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
)) {
10577 ill
->ill_icmp6_mib
->ipv6IfIcmpIfIndex
=
10578 ill
->ill_phyint
->phyint_ifindex
;
10579 if (!snmp_append_data2(mpctl
->b_cont
, &mp_tail
,
10580 (char *)ill
->ill_icmp6_mib
,
10581 (int)sizeof (*ill
->ill_icmp6_mib
))) {
10582 ip1dbg(("ip_snmp_get_mib2_icmp6: failed to allocate "
10584 (uint_t
)sizeof (*ill
->ill_icmp6_mib
)));
10587 rw_exit(&ipst
->ips_ill_g_lock
);
10589 optp
->len
= (t_uscalar_t
)msgdsize(mpctl
->b_cont
);
10590 ip3dbg(("ip_snmp_get_mib2_icmp6: level %d, name %d, len %d\n",
10591 (int)optp
->level
, (int)optp
->name
, (int)optp
->len
));
10597 * ire_walk routine to create ipRouteEntryTable in one IRE walk
10600 ip_snmp_get2_v4(ire_t
*ire
, iproutedata_t
*ird
)
10603 mib2_ipRouteEntry_t
*re
;
10604 ip_stack_t
*ipst
= ire
->ire_ipst
;
10606 ASSERT(ire
->ire_ipversion
== IPV4_VERSION
);
10608 if (!(ird
->ird_flags
& IRD_REPORT_ALL
)) {
10609 if (ire
->ire_testhidden
)
10611 if (ire
->ire_type
& IRE_IF_CLONE
)
10615 if ((re
= kmem_zalloc(sizeof (*re
), KM_NOSLEEP
)) == NULL
)
10619 * Return all IRE types for route table... let caller pick and choose
10621 re
->ipRouteDest
= ire
->ire_addr
;
10622 ill
= ire
->ire_ill
;
10623 re
->ipRouteIfIndex
.o_length
= 0;
10625 ill_get_name(ill
, re
->ipRouteIfIndex
.o_bytes
, OCTET_LENGTH
);
10626 re
->ipRouteIfIndex
.o_length
=
10627 mi_strlen(re
->ipRouteIfIndex
.o_bytes
);
10629 re
->ipRouteMetric1
= -1;
10630 re
->ipRouteMetric2
= -1;
10631 re
->ipRouteMetric3
= -1;
10632 re
->ipRouteMetric4
= -1;
10634 re
->ipRouteNextHop
= ire
->ire_gateway_addr
;
10635 /* indirect(4), direct(3), or invalid(2) */
10636 if (ire
->ire_flags
& (RTF_REJECT
| RTF_BLACKHOLE
))
10637 re
->ipRouteType
= 2;
10638 else if (ire
->ire_type
& IRE_ONLINK
)
10639 re
->ipRouteType
= 3;
10641 re
->ipRouteType
= 4;
10643 re
->ipRouteProto
= -1;
10644 re
->ipRouteAge
= gethrestime_sec() - ire
->ire_create_time
;
10645 re
->ipRouteMask
= ire
->ire_mask
;
10646 re
->ipRouteMetric5
= -1;
10647 re
->ipRouteInfo
.re_max_frag
= ire
->ire_metrics
.iulp_mtu
;
10648 if (ire
->ire_ill
!= NULL
&& re
->ipRouteInfo
.re_max_frag
== 0)
10649 re
->ipRouteInfo
.re_max_frag
= ire
->ire_ill
->ill_mtu
;
10651 re
->ipRouteInfo
.re_frag_flag
= 0;
10652 re
->ipRouteInfo
.re_rtt
= 0;
10653 re
->ipRouteInfo
.re_src_addr
= 0;
10654 re
->ipRouteInfo
.re_ref
= ire
->ire_refcnt
;
10655 re
->ipRouteInfo
.re_obpkt
= ire
->ire_ob_pkt_count
;
10656 re
->ipRouteInfo
.re_ibpkt
= ire
->ire_ib_pkt_count
;
10657 re
->ipRouteInfo
.re_flags
= ire
->ire_flags
;
10659 /* Add the IRE_IF_CLONE's counters to their parent IRE_INTERFACE */
10660 if (ire
->ire_type
& IRE_INTERFACE
) {
10663 rw_enter(&ipst
->ips_ire_dep_lock
, RW_READER
);
10664 child
= ire
->ire_dep_children
;
10665 while (child
!= NULL
) {
10666 re
->ipRouteInfo
.re_obpkt
+= child
->ire_ob_pkt_count
;
10667 re
->ipRouteInfo
.re_ibpkt
+= child
->ire_ib_pkt_count
;
10668 child
= child
->ire_dep_sib_next
;
10670 rw_exit(&ipst
->ips_ire_dep_lock
);
10673 if (ire
->ire_flags
& RTF_DYNAMIC
) {
10674 re
->ipRouteInfo
.re_ire_type
= IRE_HOST_REDIRECT
;
10676 re
->ipRouteInfo
.re_ire_type
= ire
->ire_type
;
10679 if (!snmp_append_data2(ird
->ird_route
.lp_head
, &ird
->ird_route
.lp_tail
,
10680 (char *)re
, (int)sizeof (*re
))) {
10681 ip1dbg(("ip_snmp_get2_v4: failed to allocate %u bytes\n",
10682 (uint_t
)sizeof (*re
)));
10685 /* bump route index for next pass */
10688 kmem_free(re
, sizeof (*re
));
10692 * ire_walk routine to create ipv6RouteEntryTable and ipRouteEntryTable.
10695 ip_snmp_get2_v6_route(ire_t
*ire
, iproutedata_t
*ird
)
10698 mib2_ipv6RouteEntry_t
*re
;
10699 ip_stack_t
*ipst
= ire
->ire_ipst
;
10701 ASSERT(ire
->ire_ipversion
== IPV6_VERSION
);
10703 if (!(ird
->ird_flags
& IRD_REPORT_ALL
)) {
10704 if (ire
->ire_testhidden
)
10706 if (ire
->ire_type
& IRE_IF_CLONE
)
10710 if ((re
= kmem_zalloc(sizeof (*re
), KM_NOSLEEP
)) == NULL
)
10714 * Return all IRE types for route table... let caller pick and choose
10716 re
->ipv6RouteDest
= ire
->ire_addr_v6
;
10717 re
->ipv6RoutePfxLength
= ip_mask_to_plen_v6(&ire
->ire_mask_v6
);
10718 re
->ipv6RouteIndex
= 0; /* Unique when multiple with same dest/plen */
10719 re
->ipv6RouteIfIndex
.o_length
= 0;
10720 ill
= ire
->ire_ill
;
10722 ill_get_name(ill
, re
->ipv6RouteIfIndex
.o_bytes
, OCTET_LENGTH
);
10723 re
->ipv6RouteIfIndex
.o_length
=
10724 mi_strlen(re
->ipv6RouteIfIndex
.o_bytes
);
10727 ASSERT(!(ire
->ire_type
& IRE_BROADCAST
));
10729 mutex_enter(&ire
->ire_lock
);
10730 re
->ipv6RouteNextHop
= ire
->ire_gateway_addr_v6
;
10731 mutex_exit(&ire
->ire_lock
);
10733 /* remote(4), local(3), or discard(2) */
10734 if (ire
->ire_flags
& (RTF_REJECT
| RTF_BLACKHOLE
))
10735 re
->ipv6RouteType
= 2;
10736 else if (ire
->ire_type
& IRE_ONLINK
)
10737 re
->ipv6RouteType
= 3;
10739 re
->ipv6RouteType
= 4;
10741 re
->ipv6RouteProtocol
= -1;
10742 re
->ipv6RoutePolicy
= 0;
10743 re
->ipv6RouteAge
= gethrestime_sec() - ire
->ire_create_time
;
10744 re
->ipv6RouteNextHopRDI
= 0;
10745 re
->ipv6RouteWeight
= 0;
10746 re
->ipv6RouteMetric
= 0;
10747 re
->ipv6RouteInfo
.re_max_frag
= ire
->ire_metrics
.iulp_mtu
;
10748 if (ire
->ire_ill
!= NULL
&& re
->ipv6RouteInfo
.re_max_frag
== 0)
10749 re
->ipv6RouteInfo
.re_max_frag
= ire
->ire_ill
->ill_mtu
;
10751 re
->ipv6RouteInfo
.re_frag_flag
= 0;
10752 re
->ipv6RouteInfo
.re_rtt
= 0;
10753 re
->ipv6RouteInfo
.re_src_addr
= ipv6_all_zeros
;
10754 re
->ipv6RouteInfo
.re_obpkt
= ire
->ire_ob_pkt_count
;
10755 re
->ipv6RouteInfo
.re_ibpkt
= ire
->ire_ib_pkt_count
;
10756 re
->ipv6RouteInfo
.re_ref
= ire
->ire_refcnt
;
10757 re
->ipv6RouteInfo
.re_flags
= ire
->ire_flags
;
10759 /* Add the IRE_IF_CLONE's counters to their parent IRE_INTERFACE */
10760 if (ire
->ire_type
& IRE_INTERFACE
) {
10763 rw_enter(&ipst
->ips_ire_dep_lock
, RW_READER
);
10764 child
= ire
->ire_dep_children
;
10765 while (child
!= NULL
) {
10766 re
->ipv6RouteInfo
.re_obpkt
+= child
->ire_ob_pkt_count
;
10767 re
->ipv6RouteInfo
.re_ibpkt
+= child
->ire_ib_pkt_count
;
10768 child
= child
->ire_dep_sib_next
;
10770 rw_exit(&ipst
->ips_ire_dep_lock
);
10772 if (ire
->ire_flags
& RTF_DYNAMIC
) {
10773 re
->ipv6RouteInfo
.re_ire_type
= IRE_HOST_REDIRECT
;
10775 re
->ipv6RouteInfo
.re_ire_type
= ire
->ire_type
;
10778 if (!snmp_append_data2(ird
->ird_route
.lp_head
, &ird
->ird_route
.lp_tail
,
10779 (char *)re
, (int)sizeof (*re
))) {
10780 ip1dbg(("ip_snmp_get2_v6: failed to allocate %u bytes\n",
10781 (uint_t
)sizeof (*re
)));
10784 /* bump route index for next pass */
10787 kmem_free(re
, sizeof (*re
));
10791 * ncec_walk routine to create ipv6NetToMediaEntryTable
10794 ip_snmp_get2_v6_media(ncec_t
*ncec
, iproutedata_t
*ird
)
10797 mib2_ipv6NetToMediaEntry_t ntme
;
10799 ill
= ncec
->ncec_ill
;
10800 /* skip arpce entries, and loopback ncec entries */
10801 if (ill
->ill_isv6
== B_FALSE
|| ill
->ill_net_type
== IRE_LOOPBACK
)
10804 * Neighbor cache entry attached to IRE with on-link
10806 * We report all IPMP groups on ncec_ill which is normally the upper.
10808 ntme
.ipv6NetToMediaIfIndex
= ill
->ill_phyint
->phyint_ifindex
;
10809 ntme
.ipv6NetToMediaNetAddress
= ncec
->ncec_addr
;
10810 ntme
.ipv6NetToMediaPhysAddress
.o_length
= ill
->ill_phys_addr_length
;
10811 if (ncec
->ncec_lladdr
!= NULL
) {
10812 bcopy(ncec
->ncec_lladdr
, ntme
.ipv6NetToMediaPhysAddress
.o_bytes
,
10813 ntme
.ipv6NetToMediaPhysAddress
.o_length
);
10816 * Note: Returns ND_* states. Should be:
10817 * reachable(1), stale(2), delay(3), probe(4),
10818 * invalid(5), unknown(6)
10820 ntme
.ipv6NetToMediaState
= ncec
->ncec_state
;
10821 ntme
.ipv6NetToMediaLastUpdated
= 0;
10823 /* other(1), dynamic(2), static(3), local(4) */
10824 if (NCE_MYADDR(ncec
)) {
10825 ntme
.ipv6NetToMediaType
= 4;
10826 } else if (ncec
->ncec_flags
& NCE_F_PUBLISH
) {
10827 ntme
.ipv6NetToMediaType
= 1; /* proxy */
10828 } else if (ncec
->ncec_flags
& NCE_F_STATIC
) {
10829 ntme
.ipv6NetToMediaType
= 3;
10830 } else if (ncec
->ncec_flags
& (NCE_F_MCAST
|NCE_F_BCAST
)) {
10831 ntme
.ipv6NetToMediaType
= 1;
10833 ntme
.ipv6NetToMediaType
= 2;
10836 if (!snmp_append_data2(ird
->ird_netmedia
.lp_head
,
10837 &ird
->ird_netmedia
.lp_tail
, (char *)&ntme
, sizeof (ntme
))) {
10838 ip1dbg(("ip_snmp_get2_v6_media: failed to allocate %u bytes\n",
10839 (uint_t
)sizeof (ntme
)));
10845 nce2ace(ncec_t
*ncec
)
10849 if (NCE_ISREACHABLE(ncec
))
10850 flags
|= ACE_F_RESOLVED
;
10851 if (ncec
->ncec_flags
& NCE_F_AUTHORITY
)
10852 flags
|= ACE_F_AUTHORITY
;
10853 if (ncec
->ncec_flags
& NCE_F_PUBLISH
)
10854 flags
|= ACE_F_PUBLISH
;
10855 if ((ncec
->ncec_flags
& NCE_F_NONUD
) != 0)
10856 flags
|= ACE_F_PERMANENT
;
10857 if (NCE_MYADDR(ncec
))
10858 flags
|= (ACE_F_MYADDR
| ACE_F_AUTHORITY
);
10859 if (ncec
->ncec_flags
& NCE_F_UNVERIFIED
)
10860 flags
|= ACE_F_UNVERIFIED
;
10861 if (ncec
->ncec_flags
& NCE_F_AUTHORITY
)
10862 flags
|= ACE_F_AUTHORITY
;
10863 if (ncec
->ncec_flags
& NCE_F_DELAYED
)
10864 flags
|= ACE_F_DELAYED
;
10869 * ncec_walk routine to create ipNetToMediaEntryTable
10872 ip_snmp_get2_v4_media(ncec_t
*ncec
, iproutedata_t
*ird
)
10875 mib2_ipNetToMediaEntry_t ntme
;
10876 const char *name
= "unknown";
10877 ipaddr_t ncec_addr
;
10879 ill
= ncec
->ncec_ill
;
10880 if (ill
->ill_isv6
|| (ncec
->ncec_flags
& NCE_F_BCAST
) ||
10881 ill
->ill_net_type
== IRE_LOOPBACK
)
10884 /* We report all IPMP groups on ncec_ill which is normally the upper. */
10885 name
= ill
->ill_name
;
10886 /* Based on RFC 4293: other(1), inval(2), dyn(3), stat(4) */
10887 if (NCE_MYADDR(ncec
)) {
10888 ntme
.ipNetToMediaType
= 4;
10889 } else if (ncec
->ncec_flags
& (NCE_F_MCAST
|NCE_F_BCAST
|NCE_F_PUBLISH
)) {
10890 ntme
.ipNetToMediaType
= 1;
10892 ntme
.ipNetToMediaType
= 3;
10894 ntme
.ipNetToMediaIfIndex
.o_length
= MIN(OCTET_LENGTH
, strlen(name
));
10895 bcopy(name
, ntme
.ipNetToMediaIfIndex
.o_bytes
,
10896 ntme
.ipNetToMediaIfIndex
.o_length
);
10898 IN6_V4MAPPED_TO_IPADDR(&ncec
->ncec_addr
, ncec_addr
);
10899 bcopy(&ncec_addr
, &ntme
.ipNetToMediaNetAddress
, sizeof (ncec_addr
));
10901 ntme
.ipNetToMediaInfo
.ntm_mask
.o_length
= sizeof (ipaddr_t
);
10902 ncec_addr
= INADDR_BROADCAST
;
10903 bcopy(&ncec_addr
, ntme
.ipNetToMediaInfo
.ntm_mask
.o_bytes
,
10904 sizeof (ncec_addr
));
10906 * map all the flags to the ACE counterpart.
10908 ntme
.ipNetToMediaInfo
.ntm_flags
= nce2ace(ncec
);
10910 ntme
.ipNetToMediaPhysAddress
.o_length
=
10911 MIN(OCTET_LENGTH
, ill
->ill_phys_addr_length
);
10913 if (!NCE_ISREACHABLE(ncec
))
10914 ntme
.ipNetToMediaPhysAddress
.o_length
= 0;
10916 if (ncec
->ncec_lladdr
!= NULL
) {
10917 bcopy(ncec
->ncec_lladdr
,
10918 ntme
.ipNetToMediaPhysAddress
.o_bytes
,
10919 ntme
.ipNetToMediaPhysAddress
.o_length
);
10923 if (!snmp_append_data2(ird
->ird_netmedia
.lp_head
,
10924 &ird
->ird_netmedia
.lp_tail
, (char *)&ntme
, sizeof (ntme
))) {
10925 ip1dbg(("ip_snmp_get2_v4_media: failed to allocate %u bytes\n",
10926 (uint_t
)sizeof (ntme
)));
10932 * return (0) if invalid set request, 1 otherwise, including non-tcp requests
10936 ip_snmp_set(queue_t
*q
, int level
, int name
, uchar_t
*ptr
, int len
)
10952 * When there exists both a 64- and 32-bit counter of a particular type
10953 * (i.e., InReceives), only the 64-bit counters are added.
10956 ip_mib2_add_ip_stats(mib2_ipIfStatsEntry_t
*o1
, mib2_ipIfStatsEntry_t
*o2
)
10958 UPDATE_MIB(o1
, ipIfStatsInHdrErrors
, o2
->ipIfStatsInHdrErrors
);
10959 UPDATE_MIB(o1
, ipIfStatsInTooBigErrors
, o2
->ipIfStatsInTooBigErrors
);
10960 UPDATE_MIB(o1
, ipIfStatsInNoRoutes
, o2
->ipIfStatsInNoRoutes
);
10961 UPDATE_MIB(o1
, ipIfStatsInAddrErrors
, o2
->ipIfStatsInAddrErrors
);
10962 UPDATE_MIB(o1
, ipIfStatsInUnknownProtos
, o2
->ipIfStatsInUnknownProtos
);
10963 UPDATE_MIB(o1
, ipIfStatsInTruncatedPkts
, o2
->ipIfStatsInTruncatedPkts
);
10964 UPDATE_MIB(o1
, ipIfStatsInDiscards
, o2
->ipIfStatsInDiscards
);
10965 UPDATE_MIB(o1
, ipIfStatsOutDiscards
, o2
->ipIfStatsOutDiscards
);
10966 UPDATE_MIB(o1
, ipIfStatsOutFragOKs
, o2
->ipIfStatsOutFragOKs
);
10967 UPDATE_MIB(o1
, ipIfStatsOutFragFails
, o2
->ipIfStatsOutFragFails
);
10968 UPDATE_MIB(o1
, ipIfStatsOutFragCreates
, o2
->ipIfStatsOutFragCreates
);
10969 UPDATE_MIB(o1
, ipIfStatsReasmReqds
, o2
->ipIfStatsReasmReqds
);
10970 UPDATE_MIB(o1
, ipIfStatsReasmOKs
, o2
->ipIfStatsReasmOKs
);
10971 UPDATE_MIB(o1
, ipIfStatsReasmFails
, o2
->ipIfStatsReasmFails
);
10972 UPDATE_MIB(o1
, ipIfStatsOutNoRoutes
, o2
->ipIfStatsOutNoRoutes
);
10973 UPDATE_MIB(o1
, ipIfStatsReasmDuplicates
, o2
->ipIfStatsReasmDuplicates
);
10974 UPDATE_MIB(o1
, ipIfStatsReasmPartDups
, o2
->ipIfStatsReasmPartDups
);
10975 UPDATE_MIB(o1
, ipIfStatsForwProhibits
, o2
->ipIfStatsForwProhibits
);
10976 UPDATE_MIB(o1
, udpInCksumErrs
, o2
->udpInCksumErrs
);
10977 UPDATE_MIB(o1
, udpInOverflows
, o2
->udpInOverflows
);
10978 UPDATE_MIB(o1
, rawipInOverflows
, o2
->rawipInOverflows
);
10979 UPDATE_MIB(o1
, ipIfStatsInWrongIPVersion
,
10980 o2
->ipIfStatsInWrongIPVersion
);
10981 UPDATE_MIB(o1
, ipIfStatsOutWrongIPVersion
,
10982 o2
->ipIfStatsInWrongIPVersion
);
10983 UPDATE_MIB(o1
, ipIfStatsOutSwitchIPVersion
,
10984 o2
->ipIfStatsOutSwitchIPVersion
);
10985 UPDATE_MIB(o1
, ipIfStatsHCInReceives
, o2
->ipIfStatsHCInReceives
);
10986 UPDATE_MIB(o1
, ipIfStatsHCInOctets
, o2
->ipIfStatsHCInOctets
);
10987 UPDATE_MIB(o1
, ipIfStatsHCInForwDatagrams
,
10988 o2
->ipIfStatsHCInForwDatagrams
);
10989 UPDATE_MIB(o1
, ipIfStatsHCInDelivers
, o2
->ipIfStatsHCInDelivers
);
10990 UPDATE_MIB(o1
, ipIfStatsHCOutRequests
, o2
->ipIfStatsHCOutRequests
);
10991 UPDATE_MIB(o1
, ipIfStatsHCOutForwDatagrams
,
10992 o2
->ipIfStatsHCOutForwDatagrams
);
10993 UPDATE_MIB(o1
, ipIfStatsOutFragReqds
, o2
->ipIfStatsOutFragReqds
);
10994 UPDATE_MIB(o1
, ipIfStatsHCOutTransmits
, o2
->ipIfStatsHCOutTransmits
);
10995 UPDATE_MIB(o1
, ipIfStatsHCOutOctets
, o2
->ipIfStatsHCOutOctets
);
10996 UPDATE_MIB(o1
, ipIfStatsHCInMcastPkts
, o2
->ipIfStatsHCInMcastPkts
);
10997 UPDATE_MIB(o1
, ipIfStatsHCInMcastOctets
, o2
->ipIfStatsHCInMcastOctets
);
10998 UPDATE_MIB(o1
, ipIfStatsHCOutMcastPkts
, o2
->ipIfStatsHCOutMcastPkts
);
10999 UPDATE_MIB(o1
, ipIfStatsHCOutMcastOctets
,
11000 o2
->ipIfStatsHCOutMcastOctets
);
11001 UPDATE_MIB(o1
, ipIfStatsHCInBcastPkts
, o2
->ipIfStatsHCInBcastPkts
);
11002 UPDATE_MIB(o1
, ipIfStatsHCOutBcastPkts
, o2
->ipIfStatsHCOutBcastPkts
);
11003 UPDATE_MIB(o1
, ipsecInSucceeded
, o2
->ipsecInSucceeded
);
11004 UPDATE_MIB(o1
, ipsecInFailed
, o2
->ipsecInFailed
);
11005 UPDATE_MIB(o1
, ipInCksumErrs
, o2
->ipInCksumErrs
);
11006 UPDATE_MIB(o1
, tcpInErrs
, o2
->tcpInErrs
);
11007 UPDATE_MIB(o1
, udpNoPorts
, o2
->udpNoPorts
);
11011 ip_mib2_add_icmp6_stats(mib2_ipv6IfIcmpEntry_t
*o1
, mib2_ipv6IfIcmpEntry_t
*o2
)
11013 UPDATE_MIB(o1
, ipv6IfIcmpInMsgs
, o2
->ipv6IfIcmpInMsgs
);
11014 UPDATE_MIB(o1
, ipv6IfIcmpInErrors
, o2
->ipv6IfIcmpInErrors
);
11015 UPDATE_MIB(o1
, ipv6IfIcmpInDestUnreachs
, o2
->ipv6IfIcmpInDestUnreachs
);
11016 UPDATE_MIB(o1
, ipv6IfIcmpInAdminProhibs
, o2
->ipv6IfIcmpInAdminProhibs
);
11017 UPDATE_MIB(o1
, ipv6IfIcmpInTimeExcds
, o2
->ipv6IfIcmpInTimeExcds
);
11018 UPDATE_MIB(o1
, ipv6IfIcmpInParmProblems
, o2
->ipv6IfIcmpInParmProblems
);
11019 UPDATE_MIB(o1
, ipv6IfIcmpInPktTooBigs
, o2
->ipv6IfIcmpInPktTooBigs
);
11020 UPDATE_MIB(o1
, ipv6IfIcmpInEchos
, o2
->ipv6IfIcmpInEchos
);
11021 UPDATE_MIB(o1
, ipv6IfIcmpInEchoReplies
, o2
->ipv6IfIcmpInEchoReplies
);
11022 UPDATE_MIB(o1
, ipv6IfIcmpInRouterSolicits
,
11023 o2
->ipv6IfIcmpInRouterSolicits
);
11024 UPDATE_MIB(o1
, ipv6IfIcmpInRouterAdvertisements
,
11025 o2
->ipv6IfIcmpInRouterAdvertisements
);
11026 UPDATE_MIB(o1
, ipv6IfIcmpInNeighborSolicits
,
11027 o2
->ipv6IfIcmpInNeighborSolicits
);
11028 UPDATE_MIB(o1
, ipv6IfIcmpInNeighborAdvertisements
,
11029 o2
->ipv6IfIcmpInNeighborAdvertisements
);
11030 UPDATE_MIB(o1
, ipv6IfIcmpInRedirects
, o2
->ipv6IfIcmpInRedirects
);
11031 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembQueries
,
11032 o2
->ipv6IfIcmpInGroupMembQueries
);
11033 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembResponses
,
11034 o2
->ipv6IfIcmpInGroupMembResponses
);
11035 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembReductions
,
11036 o2
->ipv6IfIcmpInGroupMembReductions
);
11037 UPDATE_MIB(o1
, ipv6IfIcmpOutMsgs
, o2
->ipv6IfIcmpOutMsgs
);
11038 UPDATE_MIB(o1
, ipv6IfIcmpOutErrors
, o2
->ipv6IfIcmpOutErrors
);
11039 UPDATE_MIB(o1
, ipv6IfIcmpOutDestUnreachs
,
11040 o2
->ipv6IfIcmpOutDestUnreachs
);
11041 UPDATE_MIB(o1
, ipv6IfIcmpOutAdminProhibs
,
11042 o2
->ipv6IfIcmpOutAdminProhibs
);
11043 UPDATE_MIB(o1
, ipv6IfIcmpOutTimeExcds
, o2
->ipv6IfIcmpOutTimeExcds
);
11044 UPDATE_MIB(o1
, ipv6IfIcmpOutParmProblems
,
11045 o2
->ipv6IfIcmpOutParmProblems
);
11046 UPDATE_MIB(o1
, ipv6IfIcmpOutPktTooBigs
, o2
->ipv6IfIcmpOutPktTooBigs
);
11047 UPDATE_MIB(o1
, ipv6IfIcmpOutEchos
, o2
->ipv6IfIcmpOutEchos
);
11048 UPDATE_MIB(o1
, ipv6IfIcmpOutEchoReplies
, o2
->ipv6IfIcmpOutEchoReplies
);
11049 UPDATE_MIB(o1
, ipv6IfIcmpOutRouterSolicits
,
11050 o2
->ipv6IfIcmpOutRouterSolicits
);
11051 UPDATE_MIB(o1
, ipv6IfIcmpOutRouterAdvertisements
,
11052 o2
->ipv6IfIcmpOutRouterAdvertisements
);
11053 UPDATE_MIB(o1
, ipv6IfIcmpOutNeighborSolicits
,
11054 o2
->ipv6IfIcmpOutNeighborSolicits
);
11055 UPDATE_MIB(o1
, ipv6IfIcmpOutNeighborAdvertisements
,
11056 o2
->ipv6IfIcmpOutNeighborAdvertisements
);
11057 UPDATE_MIB(o1
, ipv6IfIcmpOutRedirects
, o2
->ipv6IfIcmpOutRedirects
);
11058 UPDATE_MIB(o1
, ipv6IfIcmpOutGroupMembQueries
,
11059 o2
->ipv6IfIcmpOutGroupMembQueries
);
11060 UPDATE_MIB(o1
, ipv6IfIcmpOutGroupMembResponses
,
11061 o2
->ipv6IfIcmpOutGroupMembResponses
);
11062 UPDATE_MIB(o1
, ipv6IfIcmpOutGroupMembReductions
,
11063 o2
->ipv6IfIcmpOutGroupMembReductions
);
11064 UPDATE_MIB(o1
, ipv6IfIcmpInOverflows
, o2
->ipv6IfIcmpInOverflows
);
11065 UPDATE_MIB(o1
, ipv6IfIcmpBadHoplimit
, o2
->ipv6IfIcmpBadHoplimit
);
11066 UPDATE_MIB(o1
, ipv6IfIcmpInBadNeighborAdvertisements
,
11067 o2
->ipv6IfIcmpInBadNeighborAdvertisements
);
11068 UPDATE_MIB(o1
, ipv6IfIcmpInBadNeighborSolicitations
,
11069 o2
->ipv6IfIcmpInBadNeighborSolicitations
);
11070 UPDATE_MIB(o1
, ipv6IfIcmpInBadRedirects
, o2
->ipv6IfIcmpInBadRedirects
);
11071 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembTotal
,
11072 o2
->ipv6IfIcmpInGroupMembTotal
);
11073 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembBadQueries
,
11074 o2
->ipv6IfIcmpInGroupMembBadQueries
);
11075 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembBadReports
,
11076 o2
->ipv6IfIcmpInGroupMembBadReports
);
11077 UPDATE_MIB(o1
, ipv6IfIcmpInGroupMembOurReports
,
11078 o2
->ipv6IfIcmpInGroupMembOurReports
);
11082 * Called before the options are updated to check if this packet will
11083 * be source routed from here.
11084 * This routine assumes that the options are well formed i.e. that they
11085 * have already been checked.
11088 ip_source_routed(ipha_t
*ipha
, ip_stack_t
*ipst
)
11096 if (IS_SIMPLE_IPH(ipha
)) {
11097 ip2dbg(("not source routed\n"));
11100 dst
= ipha
->ipha_dst
;
11101 for (optval
= ipoptp_first(&opts
, ipha
);
11102 optval
!= IPOPT_EOL
;
11103 optval
= ipoptp_next(&opts
)) {
11104 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
11105 opt
= opts
.ipoptp_cur
;
11106 optlen
= opts
.ipoptp_len
;
11107 ip2dbg(("ip_source_routed: opt %d, len %d\n",
11114 * If dst is one of our addresses and there are some
11115 * entries left in the source route return (true).
11117 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
11118 ip2dbg(("ip_source_routed: not next"
11119 " source route 0x%x\n",
11123 off
= opt
[IPOPT_OFFSET
];
11125 if (optlen
< IP_ADDR_LEN
||
11126 off
> optlen
- IP_ADDR_LEN
) {
11127 /* End of source route */
11128 ip1dbg(("ip_source_routed: end of SR\n"));
11134 ip2dbg(("not source routed\n"));
11139 * ip_unbind is called by the transports to remove a conn from
11140 * the fanout table.
11143 ip_unbind(conn_t
*connp
)
11146 ASSERT(!MUTEX_HELD(&connp
->conn_lock
));
11148 ipcl_hash_remove(connp
);
11152 * Used for deciding the MSS size for the upper layer. Thus
11153 * we need to check the outbound policy values in the conn.
11156 conn_ipsec_length(conn_t
*connp
)
11158 ipsec_latch_t
*ipl
;
11160 ipl
= connp
->conn_latch
;
11164 if (connp
->conn_ixa
->ixa_ipsec_policy
== NULL
)
11167 return (connp
->conn_ixa
->ixa_ipsec_policy
->ipsp_act
->ipa_ovhd
);
11171 * Returns an estimate of the IPsec headers size. This is used if
11172 * we don't want to call into IPsec to get the exact size.
11175 ipsec_out_extra_length(ip_xmit_attr_t
*ixa
)
11179 if (!(ixa
->ixa_flags
& IXAF_IPSEC_SECURE
))
11182 a
= ixa
->ixa_ipsec_action
;
11184 ASSERT(ixa
->ixa_ipsec_policy
!= NULL
);
11185 a
= ixa
->ixa_ipsec_policy
->ipsp_act
;
11189 return (a
->ipa_ovhd
);
11193 * If there are any source route options, return the true final
11194 * destination. Otherwise, return the destination.
11197 ip_get_dst(ipha_t
*ipha
)
11206 dst
= ipha
->ipha_dst
;
11208 if (IS_SIMPLE_IPH(ipha
))
11211 for (optval
= ipoptp_first(&opts
, ipha
);
11212 optval
!= IPOPT_EOL
;
11213 optval
= ipoptp_next(&opts
)) {
11214 opt
= opts
.ipoptp_cur
;
11215 optlen
= opts
.ipoptp_len
;
11216 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
11220 off
= opt
[IPOPT_OFFSET
];
11222 * If one of the conditions is true, it means
11223 * end of options and dst already has the right
11226 if (!(optlen
< IP_ADDR_LEN
|| off
> optlen
- 3)) {
11227 off
= optlen
- IP_ADDR_LEN
;
11228 bcopy(&opt
[off
], &dst
, IP_ADDR_LEN
);
11240 * Outbound IP fragmentation routine.
11241 * Assumes the caller has checked whether or not fragmentation should
11242 * be allowed. Here we copy the DF bit from the header to all the generated
11246 ip_fragment_v4(mblk_t
*mp_orig
, nce_t
*nce
, iaflags_t ixaflags
,
11247 uint_t pkt_len
, uint32_t max_frag
, uint32_t xmit_hint
, zoneid_t szone
,
11248 zoneid_t nolzid
, pfirepostfrag_t postfragfn
, uintptr_t *ixa_cookie
)
11256 mblk_t
*mp
= mp_orig
;
11258 ill_t
*ill
= nce
->nce_ill
;
11259 ip_stack_t
*ipst
= ill
->ill_ipst
;
11261 uint32_t frag_flag
;
11262 uint_t priority
= mp
->b_band
;
11265 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragReqds
);
11267 if (pkt_len
!= msgdsize(mp
)) {
11268 ip0dbg(("Packet length mismatch: %d, %ld\n",
11269 pkt_len
, msgdsize(mp
)));
11274 if (max_frag
== 0) {
11275 ip1dbg(("ip_fragment_v4: max_frag is zero. Dropping packet\n"));
11276 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11277 ip_drop_output("FragFails: zero max_frag", mp
, ill
);
11282 ASSERT(MBLKL(mp
) >= sizeof (ipha_t
));
11283 ipha
= (ipha_t
*)mp
->b_rptr
;
11284 ASSERT(ntohs(ipha
->ipha_length
) == pkt_len
);
11285 frag_flag
= ntohs(ipha
->ipha_fragment_offset_and_flags
) & IPH_DF
;
11288 * Establish the starting offset. May not be zero if we are fragging
11289 * a fragment that is being forwarded.
11291 offset
= ntohs(ipha
->ipha_fragment_offset_and_flags
) & IPH_OFFSET
;
11293 /* TODO why is this test needed? */
11294 if (((max_frag
- ntohs(ipha
->ipha_length
)) & ~7) < 8) {
11295 /* TODO: notify ulp somehow */
11296 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11297 ip_drop_output("FragFails: bad starting offset", mp
, ill
);
11302 hdr_len
= IPH_HDR_LENGTH(ipha
);
11303 ipha
->ipha_hdr_checksum
= 0;
11306 * Establish the number of bytes maximum per frag, after putting
11309 len
= (max_frag
- hdr_len
) & ~7;
11311 /* Get a copy of the header for the trailing frags */
11312 hdr_mp
= ip_fragment_copyhdr((uchar_t
*)ipha
, hdr_len
, offset
, ipst
,
11314 if (hdr_mp
== NULL
) {
11315 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11316 ip_drop_output("FragFails: no hdr_mp", mp
, ill
);
11321 /* Store the starting offset, with the MoreFrags flag. */
11322 i1
= offset
| IPH_MF
| frag_flag
;
11323 ipha
->ipha_fragment_offset_and_flags
= htons((uint16_t)i1
);
11325 /* Establish the ending byte offset, based on the starting offset. */
11327 ip_data_end
= offset
+ ntohs(ipha
->ipha_length
) - hdr_len
;
11329 /* Store the length of the first fragment in the IP header. */
11330 i1
= len
+ hdr_len
;
11331 ASSERT(i1
<= IP_MAXPACKET
);
11332 ipha
->ipha_length
= htons((uint16_t)i1
);
11335 * Compute the IP header checksum for the first frag. We have to
11336 * watch out that we stop at the end of the header.
11338 ipha
->ipha_hdr_checksum
= ip_csum_hdr(ipha
);
11341 * Now carve off the first frag. Note that this will include the
11342 * original IP header.
11344 if (!(mp
= ip_carve_mp(&mp_orig
, i1
))) {
11345 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11346 ip_drop_output("FragFails: could not carve mp", mp_orig
, ill
);
11352 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragCreates
);
11354 error
= postfragfn(mp
, nce
, ixaflags
, i1
, xmit_hint
, szone
, nolzid
,
11356 if (error
!= 0 && error
!= EWOULDBLOCK
) {
11357 /* No point in sending the other fragments */
11358 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11359 ip_drop_output("FragFails: postfragfn failed", mp_orig
, ill
);
11365 /* No need to redo state machine in loop */
11366 ixaflags
&= ~IXAF_REACH_CONF
;
11368 /* Advance the offset to the second frag starting point. */
11371 * Update hdr_len from the copied header - there might be less options
11372 * in the later fragments.
11374 hdr_len
= IPH_HDR_LENGTH(hdr_mp
->b_rptr
);
11375 /* Loop until done. */
11377 uint16_t offset_and_flags
;
11380 if (ip_data_end
- offset
> len
) {
11382 * Carve off the appropriate amount from the original
11385 if (!(carve_mp
= ip_carve_mp(&mp_orig
, len
))) {
11390 * More frags after this one. Get another copy
11393 if (carve_mp
->b_datap
->db_ref
== 1 &&
11394 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
<
11395 carve_mp
->b_rptr
- carve_mp
->b_datap
->db_base
) {
11396 /* Inline IP header */
11397 carve_mp
->b_rptr
-= hdr_mp
->b_wptr
-
11399 bcopy(hdr_mp
->b_rptr
, carve_mp
->b_rptr
,
11400 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
);
11403 if (!(mp
= copyb(hdr_mp
))) {
11407 /* Get priority marking, if any. */
11408 mp
->b_band
= priority
;
11409 mp
->b_cont
= carve_mp
;
11411 ipha
= (ipha_t
*)mp
->b_rptr
;
11412 offset_and_flags
= IPH_MF
;
11415 * Last frag. Consume the header. Set len to
11416 * the length of this last piece.
11418 len
= ip_data_end
- offset
;
11421 * Carve off the appropriate amount from the original
11424 if (!(carve_mp
= ip_carve_mp(&mp_orig
, len
))) {
11428 if (carve_mp
->b_datap
->db_ref
== 1 &&
11429 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
<
11430 carve_mp
->b_rptr
- carve_mp
->b_datap
->db_base
) {
11431 /* Inline IP header */
11432 carve_mp
->b_rptr
-= hdr_mp
->b_wptr
-
11434 bcopy(hdr_mp
->b_rptr
, carve_mp
->b_rptr
,
11435 hdr_mp
->b_wptr
- hdr_mp
->b_rptr
);
11441 /* Get priority marking, if any. */
11442 mp
->b_band
= priority
;
11443 mp
->b_cont
= carve_mp
;
11445 ipha
= (ipha_t
*)mp
->b_rptr
;
11446 /* A frag of a frag might have IPH_MF non-zero */
11448 ntohs(ipha
->ipha_fragment_offset_and_flags
) &
11451 offset_and_flags
|= (uint16_t)(offset
>> 3);
11452 offset_and_flags
|= (uint16_t)frag_flag
;
11453 /* Store the offset and flags in the IP header. */
11454 ipha
->ipha_fragment_offset_and_flags
= htons(offset_and_flags
);
11456 /* Store the length in the IP header. */
11457 ip_len
= (uint16_t)(len
+ hdr_len
);
11458 ipha
->ipha_length
= htons(ip_len
);
11461 * Set the IP header checksum. Note that mp is just
11462 * the header, so this is easy to pass to ip_csum.
11464 ipha
->ipha_hdr_checksum
= ip_csum_hdr(ipha
);
11466 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragCreates
);
11468 error
= postfragfn(mp
, nce
, ixaflags
, ip_len
, xmit_hint
, szone
,
11469 nolzid
, ixa_cookie
);
11470 /* All done if we just consumed the hdr_mp. */
11471 if (mp
== hdr_mp
) {
11472 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragOKs
);
11475 if (error
!= 0 && error
!= EWOULDBLOCK
) {
11476 DTRACE_PROBE2(ip__xmit__frag__fail
, ill_t
*, ill
,
11478 /* No point in sending the other fragments */
11482 /* Otherwise, advance and loop. */
11485 /* Clean up following allocation failure. */
11486 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutFragFails
);
11487 ip_drop_output("FragFails: loop ended", NULL
, ill
);
11496 * Copy the header plus those options which have the copy bit set
11499 ip_fragment_copyhdr(uchar_t
*rptr
, int hdr_len
, int offset
, ip_stack_t
*ipst
,
11506 * Quick check if we need to look for options without the copy bit
11509 mp
= allocb_tmpl(ipst
->ips_ip_wroff_extra
+ hdr_len
, src
);
11512 mp
->b_rptr
+= ipst
->ips_ip_wroff_extra
;
11513 if (hdr_len
== IP_SIMPLE_HDR_LENGTH
|| offset
!= 0) {
11514 bcopy(rptr
, mp
->b_rptr
, hdr_len
);
11515 mp
->b_wptr
+= hdr_len
+ ipst
->ips_ip_wroff_extra
;
11519 bcopy(rptr
, up
, IP_SIMPLE_HDR_LENGTH
);
11520 up
+= IP_SIMPLE_HDR_LENGTH
;
11521 rptr
+= IP_SIMPLE_HDR_LENGTH
;
11522 hdr_len
-= IP_SIMPLE_HDR_LENGTH
;
11523 while (hdr_len
> 0) {
11528 if (optval
== IPOPT_EOL
)
11530 if (optval
== IPOPT_NOP
)
11534 if (optval
& IPOPT_COPY
) {
11535 bcopy(rptr
, up
, optlen
);
11542 * Make sure that we drop an even number of words by filling
11543 * with EOL to the next word boundary.
11545 for (hdr_len
= up
- (mp
->b_rptr
+ IP_SIMPLE_HDR_LENGTH
);
11546 hdr_len
& 0x3; hdr_len
++)
11549 /* Update header length */
11550 mp
->b_rptr
[0] = (uint8_t)((IP_VERSION
<< 4) | ((up
- mp
->b_rptr
) >> 2));
11555 * Update any source route, record route, or timestamp options when
11556 * sending a packet back to ourselves.
11557 * Check that we are at end of strict source route.
11558 * The options have been sanity checked by ip_output_options().
11561 ip_output_local_options(ipha_t
*ipha
, ip_stack_t
*ipst
)
11571 for (optval
= ipoptp_first(&opts
, ipha
);
11572 optval
!= IPOPT_EOL
;
11573 optval
= ipoptp_next(&opts
)) {
11574 opt
= opts
.ipoptp_cur
;
11575 optlen
= opts
.ipoptp_len
;
11576 ASSERT((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0);
11581 off
= opt
[IPOPT_OFFSET
];
11583 if (optlen
< IP_ADDR_LEN
||
11584 off
> optlen
- IP_ADDR_LEN
) {
11585 /* End of source route */
11589 * This will only happen if two consecutive entries
11590 * in the source route contains our address or if
11591 * it is a packet with a loose source route which
11592 * reaches us before consuming the whole source route
11595 if (optval
== IPOPT_SSRR
) {
11599 * Hack: instead of dropping the packet truncate the
11600 * source route to what has been used by filling the
11601 * rest with IPOPT_NOP.
11603 opt
[IPOPT_OLEN
] = (uint8_t)off
;
11604 while (off
< optlen
) {
11605 opt
[off
++] = IPOPT_NOP
;
11609 off
= opt
[IPOPT_OFFSET
];
11611 if (optlen
< IP_ADDR_LEN
||
11612 off
> optlen
- IP_ADDR_LEN
) {
11613 /* No more room - ignore */
11615 "ip_output_local_options: end of RR\n"));
11618 dst
= htonl(INADDR_LOOPBACK
);
11619 bcopy(&dst
, (char *)opt
+ off
, IP_ADDR_LEN
);
11620 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
11623 /* Insert timestamp if there is romm */
11624 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
11625 case IPOPT_TS_TSONLY
:
11626 off
= IPOPT_TS_TIMELEN
;
11628 case IPOPT_TS_PRESPEC
:
11629 case IPOPT_TS_PRESPEC_RFC791
:
11630 /* Verify that the address matched */
11631 off
= opt
[IPOPT_OFFSET
] - 1;
11632 bcopy((char *)opt
+ off
, &dst
, IP_ADDR_LEN
);
11633 if (ip_type_v4(dst
, ipst
) != IRE_LOCAL
) {
11638 case IPOPT_TS_TSANDADDR
:
11639 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
11643 * ip_*put_options should have already
11644 * dropped this packet.
11646 cmn_err(CE_PANIC
, "ip_output_local_options: "
11647 "unknown IT - bug in ip_output_options?\n");
11648 return; /* Keep "lint" happy */
11650 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
) {
11651 /* Increase overflow counter */
11652 off
= (opt
[IPOPT_POS_OV_FLG
] >> 4) + 1;
11653 opt
[IPOPT_POS_OV_FLG
] = (uint8_t)
11654 (opt
[IPOPT_POS_OV_FLG
] & 0x0F) |
11658 off
= opt
[IPOPT_OFFSET
] - 1;
11659 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
11660 case IPOPT_TS_PRESPEC
:
11661 case IPOPT_TS_PRESPEC_RFC791
:
11662 case IPOPT_TS_TSANDADDR
:
11663 dst
= htonl(INADDR_LOOPBACK
);
11664 bcopy(&dst
, (char *)opt
+ off
, IP_ADDR_LEN
);
11665 opt
[IPOPT_OFFSET
] += IP_ADDR_LEN
;
11667 case IPOPT_TS_TSONLY
:
11668 off
= opt
[IPOPT_OFFSET
] - 1;
11669 /* Compute # of milliseconds since midnight */
11671 ts
= (now
.tv_sec
% (24 * 60 * 60)) * 1000 +
11672 NSEC2MSEC(now
.tv_nsec
);
11673 bcopy(&ts
, (char *)opt
+ off
, IPOPT_TS_TIMELEN
);
11674 opt
[IPOPT_OFFSET
] += IPOPT_TS_TIMELEN
;
11683 * Prepend an M_DATA fastpath header, and if none present prepend a
11684 * DL_UNITDATA_REQ. Frees the mblk on failure.
11686 * nce_dlur_mp and nce_fp_mp can not disappear once they have been set.
11687 * If there is a change to them, the nce will be deleted (condemned) and
11688 * a new nce_t will be created when packets are sent. Thus we need no locks
11689 * to access those fields.
11691 * We preserve b_band to support IPQoS. If a DL_UNITDATA_REQ is prepended
11692 * we place b_band in dl_priority.dl_max.
11695 ip_xmit_attach_llhdr(mblk_t
*mp
, nce_t
*nce
)
11704 ASSERT(DB_TYPE(mp
) == M_DATA
);
11705 priority
= mp
->b_band
;
11707 ASSERT(nce
!= NULL
);
11708 if ((mp1
= nce
->nce_fp_mp
) != NULL
) {
11711 * Check if we have enough room to prepend fastpath
11714 if (hlen
!= 0 && (rptr
- mp
->b_datap
->db_base
) >= hlen
) {
11716 bcopy(mp1
->b_rptr
, rptr
, hlen
);
11718 * Set the b_rptr to the start of the link layer
11726 ill_t
*ill
= nce
->nce_ill
;
11728 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
11729 ip_drop_output("ipIfStatsOutDiscards", mp
, ill
);
11733 mp1
->b_band
= priority
;
11735 DB_CKSUMSTART(mp1
) = DB_CKSUMSTART(mp
);
11736 DB_CKSUMSTUFF(mp1
) = DB_CKSUMSTUFF(mp
);
11737 DB_CKSUMEND(mp1
) = DB_CKSUMEND(mp
);
11738 DB_CKSUMFLAGS(mp1
) = DB_CKSUMFLAGS(mp
);
11739 DB_LSOMSS(mp1
) = DB_LSOMSS(mp
);
11740 DTRACE_PROBE1(ip__xmit__copyb
, (mblk_t
*), mp1
);
11742 * XXX disable ICK_VALID and compute checksum
11743 * here; can happen if nce_fp_mp changes and
11744 * it can't be copied now due to insufficient
11745 * space. (unlikely, fp mp can change, but it
11746 * does not increase in length)
11750 mp1
= copyb(nce
->nce_dlur_mp
);
11753 ill_t
*ill
= nce
->nce_ill
;
11755 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
11756 ip_drop_output("ipIfStatsOutDiscards", mp
, ill
);
11761 if (priority
!= 0) {
11762 mp1
->b_band
= priority
;
11763 ((dl_unitdata_req_t
*)(mp1
->b_rptr
))->dl_priority
.dl_max
=
11770 * Finish the outbound IPsec processing. This function is called from
11771 * ipsec_out_process() if the IPsec packet was processed
11772 * synchronously, or from {ah,esp}_kcf_callback_outbound() if it was processed
11775 * This is common to IPv4 and IPv6.
11778 ip_output_post_ipsec(mblk_t
*mp
, ip_xmit_attr_t
*ixa
)
11780 iaflags_t ixaflags
= ixa
->ixa_flags
;
11784 /* AH/ESP don't update ixa_pktlen when they modify the packet */
11785 if (ixaflags
& IXAF_IS_IPV4
) {
11786 ipha_t
*ipha
= (ipha_t
*)mp
->b_rptr
;
11788 ASSERT(IPH_HDR_VERSION(ipha
) == IPV4_VERSION
);
11789 pktlen
= ntohs(ipha
->ipha_length
);
11791 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
11793 ASSERT(IPH_HDR_VERSION(mp
->b_rptr
) == IPV6_VERSION
);
11794 pktlen
= ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
;
11798 * We release any hard reference on the SAs here to make
11799 * sure the SAs can be garbage collected. ipsr_sa has a soft reference
11801 * If in the future we want the hard latching of the SAs in the
11802 * ip_xmit_attr_t then we should remove this.
11804 if (ixa
->ixa_ipsec_esp_sa
!= NULL
) {
11805 IPSA_REFRELE(ixa
->ixa_ipsec_esp_sa
);
11806 ixa
->ixa_ipsec_esp_sa
= NULL
;
11808 if (ixa
->ixa_ipsec_ah_sa
!= NULL
) {
11809 IPSA_REFRELE(ixa
->ixa_ipsec_ah_sa
);
11810 ixa
->ixa_ipsec_ah_sa
= NULL
;
11813 /* Do we need to fragment? */
11814 if ((ixa
->ixa_flags
& IXAF_IPV6_ADD_FRAGHDR
) ||
11815 pktlen
> ixa
->ixa_fragsize
) {
11816 if (ixaflags
& IXAF_IS_IPV4
) {
11817 ASSERT(!(ixa
->ixa_flags
& IXAF_IPV6_ADD_FRAGHDR
));
11819 * We check for the DF case in ipsec_out_process
11820 * hence this only handles the non-DF case.
11822 return (ip_fragment_v4(mp
, ixa
->ixa_nce
, ixa
->ixa_flags
,
11823 pktlen
, ixa
->ixa_fragsize
,
11824 ixa
->ixa_xmit_hint
, ixa
->ixa_zoneid
,
11825 ixa
->ixa_no_loop_zoneid
, ixa
->ixa_postfragfn
,
11826 &ixa
->ixa_cookie
));
11828 mp
= ip_fraghdr_add_v6(mp
, ixa
->ixa_ident
, ixa
);
11830 /* MIB and ip_drop_output already done */
11833 pktlen
+= sizeof (ip6_frag_t
);
11834 if (pktlen
> ixa
->ixa_fragsize
) {
11835 return (ip_fragment_v6(mp
, ixa
->ixa_nce
,
11836 ixa
->ixa_flags
, pktlen
,
11837 ixa
->ixa_fragsize
, ixa
->ixa_xmit_hint
,
11838 ixa
->ixa_zoneid
, ixa
->ixa_no_loop_zoneid
,
11839 ixa
->ixa_postfragfn
, &ixa
->ixa_cookie
));
11843 return ((ixa
->ixa_postfragfn
)(mp
, ixa
->ixa_nce
, ixa
->ixa_flags
,
11844 pktlen
, ixa
->ixa_xmit_hint
, ixa
->ixa_zoneid
,
11845 ixa
->ixa_no_loop_zoneid
, NULL
));
11849 * Finish the inbound IPsec processing. This function is called from
11850 * ipsec_out_process() if the IPsec packet was processed
11851 * synchronously, or from {ah,esp}_kcf_callback_outbound() if it was processed
11854 * This is common to IPv4 and IPv6.
11857 ip_input_post_ipsec(mblk_t
*mp
, ip_recv_attr_t
*ira
)
11859 iaflags_t iraflags
= ira
->ira_flags
;
11861 /* Length might have changed */
11862 if (iraflags
& IRAF_IS_IPV4
) {
11863 ipha_t
*ipha
= (ipha_t
*)mp
->b_rptr
;
11865 ASSERT(IPH_HDR_VERSION(ipha
) == IPV4_VERSION
);
11866 ira
->ira_pktlen
= ntohs(ipha
->ipha_length
);
11867 ira
->ira_ip_hdr_length
= IPH_HDR_LENGTH(ipha
);
11868 ira
->ira_protocol
= ipha
->ipha_protocol
;
11870 ip_fanout_v4(mp
, ipha
, ira
);
11872 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
11875 ASSERT(IPH_HDR_VERSION(mp
->b_rptr
) == IPV6_VERSION
);
11876 ira
->ira_pktlen
= ntohs(ip6h
->ip6_plen
) + IPV6_HDR_LEN
;
11877 if (!ip_hdr_length_nexthdr_v6(mp
, ip6h
, &ira
->ira_ip_hdr_length
,
11879 /* Malformed packet */
11880 BUMP_MIB(ira
->ira_ill
->ill_ip_mib
, ipIfStatsInDiscards
);
11881 ip_drop_input("ipIfStatsInDiscards", mp
, ira
->ira_ill
);
11885 ira
->ira_protocol
= *nexthdrp
;
11886 ip_fanout_v6(mp
, ip6h
, ira
);
11891 * Select which AH & ESP SA's to use (if any) for the outbound packet.
11893 * If this function returns B_TRUE, the requested SA's have been filled
11894 * into the ixa_ipsec_*_sa pointers.
11896 * If the function returns B_FALSE, the packet has been "consumed", most
11897 * likely by an ACQUIRE sent up via PF_KEY to a key management daemon.
11899 * The SA references created by the protocol-specific "select"
11900 * function will be released in ip_output_post_ipsec.
11903 ipsec_out_select_sa(mblk_t
*mp
, ip_xmit_attr_t
*ixa
)
11905 boolean_t need_ah_acquire
= B_FALSE
, need_esp_acquire
= B_FALSE
;
11906 ipsec_policy_t
*pp
;
11907 ipsec_action_t
*ap
;
11909 ASSERT(ixa
->ixa_flags
& IXAF_IPSEC_SECURE
);
11910 ASSERT((ixa
->ixa_ipsec_policy
!= NULL
) ||
11911 (ixa
->ixa_ipsec_action
!= NULL
));
11913 ap
= ixa
->ixa_ipsec_action
;
11915 pp
= ixa
->ixa_ipsec_policy
;
11916 ASSERT(pp
!= NULL
);
11918 ASSERT(ap
!= NULL
);
11922 * We have an action. now, let's select SA's.
11923 * A side effect of setting ixa_ipsec_*_sa is that it will
11924 * be cached in the conn_t.
11926 if (ap
->ipa_want_esp
) {
11927 if (ixa
->ixa_ipsec_esp_sa
== NULL
) {
11928 need_esp_acquire
= !ipsec_outbound_sa(mp
, ixa
,
11931 ASSERT(need_esp_acquire
|| ixa
->ixa_ipsec_esp_sa
!= NULL
);
11934 if (ap
->ipa_want_ah
) {
11935 if (ixa
->ixa_ipsec_ah_sa
== NULL
) {
11936 need_ah_acquire
= !ipsec_outbound_sa(mp
, ixa
,
11939 ASSERT(need_ah_acquire
|| ixa
->ixa_ipsec_ah_sa
!= NULL
);
11941 * The ESP and AH processing order needs to be preserved
11942 * when both protocols are required (ESP should be applied
11943 * before AH for an outbound packet). Force an ESP ACQUIRE
11944 * when both ESP and AH are required, and an AH ACQUIRE
11947 if (ap
->ipa_want_esp
&& need_ah_acquire
)
11948 need_esp_acquire
= B_TRUE
;
11952 * Send an ACQUIRE (extended, regular, or both) if we need one.
11953 * Release SAs that got referenced, but will not be used until we
11954 * acquire _all_ of the SAs we need.
11956 if (need_ah_acquire
|| need_esp_acquire
) {
11957 if (ixa
->ixa_ipsec_ah_sa
!= NULL
) {
11958 IPSA_REFRELE(ixa
->ixa_ipsec_ah_sa
);
11959 ixa
->ixa_ipsec_ah_sa
= NULL
;
11961 if (ixa
->ixa_ipsec_esp_sa
!= NULL
) {
11962 IPSA_REFRELE(ixa
->ixa_ipsec_esp_sa
);
11963 ixa
->ixa_ipsec_esp_sa
= NULL
;
11966 sadb_acquire(mp
, ixa
, need_ah_acquire
, need_esp_acquire
);
11974 * Handle IPsec output processing.
11975 * This function is only entered once for a given packet.
11976 * We try to do things synchronously, but if we need to have user-level
11977 * set up SAs, or ESP or AH uses asynchronous kEF, then the operation
11978 * will be completed
11979 * - when the SAs are added in esp_add_sa_finish/ah_add_sa_finish
11980 * - when asynchronous ESP is done it will do AH
11982 * In all cases we come back in ip_output_post_ipsec() to fragment and
11983 * send out the packet.
11986 ipsec_out_process(mblk_t
*mp
, ip_xmit_attr_t
*ixa
)
11988 ill_t
*ill
= ixa
->ixa_nce
->nce_ill
;
11989 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
11990 ipsec_stack_t
*ipss
;
11991 ipsec_policy_t
*pp
;
11992 ipsec_action_t
*ap
;
11994 ASSERT(ixa
->ixa_flags
& IXAF_IPSEC_SECURE
);
11996 ASSERT((ixa
->ixa_ipsec_policy
!= NULL
) ||
11997 (ixa
->ixa_ipsec_action
!= NULL
));
11999 ipss
= ipst
->ips_netstack
->netstack_ipsec
;
12000 if (!ipsec_loaded(ipss
)) {
12001 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
12002 ip_drop_packet(mp
, B_TRUE
, ill
,
12003 DROPPER(ipss
, ipds_ip_ipsec_not_loaded
),
12004 &ipss
->ipsec_dropper
);
12008 ap
= ixa
->ixa_ipsec_action
;
12010 pp
= ixa
->ixa_ipsec_policy
;
12011 ASSERT(pp
!= NULL
);
12013 ASSERT(ap
!= NULL
);
12016 /* Handle explicit drop action and bypass. */
12017 switch (ap
->ipa_act
.ipa_type
) {
12018 case IPSEC_ACT_DISCARD
:
12019 case IPSEC_ACT_REJECT
:
12020 ip_drop_packet(mp
, B_FALSE
, ill
,
12021 DROPPER(ipss
, ipds_spd_explicit
), &ipss
->ipsec_spd_dropper
);
12022 return (EHOSTUNREACH
); /* IPsec policy failure */
12023 case IPSEC_ACT_BYPASS
:
12024 return (ip_output_post_ipsec(mp
, ixa
));
12028 * The order of processing is first insert a IP header if needed.
12029 * Then insert the ESP header and then the AH header.
12031 if ((ixa
->ixa_flags
& IXAF_IS_IPV4
) && ap
->ipa_want_se
) {
12033 * First get the outer IP header before sending
12036 ipha_t
*oipha
, *iipha
;
12037 mblk_t
*outer_mp
, *inner_mp
;
12039 if ((outer_mp
= allocb(sizeof (ipha_t
), BPRI_HI
)) == NULL
) {
12040 (void) mi_strlog(ill
->ill_rq
, 0,
12041 SL_ERROR
|SL_TRACE
|SL_CONSOLE
,
12042 "ipsec_out_process: "
12043 "Self-Encapsulation failed: Out of memory\n");
12044 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
12045 ip_drop_output("ipIfStatsOutDiscards", mp
, ill
);
12050 ASSERT(inner_mp
->b_datap
->db_type
== M_DATA
);
12051 oipha
= (ipha_t
*)outer_mp
->b_rptr
;
12052 iipha
= (ipha_t
*)inner_mp
->b_rptr
;
12054 outer_mp
->b_wptr
+= sizeof (ipha_t
);
12055 oipha
->ipha_length
= htons(ntohs(iipha
->ipha_length
) +
12057 oipha
->ipha_protocol
= IPPROTO_ENCAP
;
12058 oipha
->ipha_version_and_hdr_length
=
12059 IP_SIMPLE_HDR_VERSION
;
12060 oipha
->ipha_hdr_checksum
= 0;
12061 oipha
->ipha_hdr_checksum
= ip_csum_hdr(oipha
);
12062 outer_mp
->b_cont
= inner_mp
;
12065 ixa
->ixa_flags
|= IXAF_IPSEC_TUNNEL
;
12068 /* If we need to wait for a SA then we can't return any errno */
12069 if (((ap
->ipa_want_ah
&& (ixa
->ixa_ipsec_ah_sa
== NULL
)) ||
12070 (ap
->ipa_want_esp
&& (ixa
->ixa_ipsec_esp_sa
== NULL
))) &&
12071 !ipsec_out_select_sa(mp
, ixa
))
12075 * By now, we know what SA's to use. Toss over to ESP & AH
12076 * to do the heavy lifting.
12078 if (ap
->ipa_want_esp
) {
12079 ASSERT(ixa
->ixa_ipsec_esp_sa
!= NULL
);
12081 mp
= ixa
->ixa_ipsec_esp_sa
->ipsa_output_func(mp
, ixa
);
12084 * Either it failed or is pending. In the former case
12085 * ipIfStatsInDiscards was increased.
12091 if (ap
->ipa_want_ah
) {
12092 ASSERT(ixa
->ixa_ipsec_ah_sa
!= NULL
);
12094 mp
= ixa
->ixa_ipsec_ah_sa
->ipsa_output_func(mp
, ixa
);
12097 * Either it failed or is pending. In the former case
12098 * ipIfStatsInDiscards was increased.
12104 * We are done with IPsec processing. Send it over
12107 return (ip_output_post_ipsec(mp
, ixa
));
12111 * ioctls that go through a down/up sequence may need to wait for the down
12112 * to complete. This involves waiting for the ire and ipif refcnts to go down
12113 * to zero. Subsequently the ioctl is restarted from ipif_ill_refrele_tail.
12117 ip_reprocess_ioctl(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *dummy_arg
)
12119 struct iocblk
*iocp
;
12121 ip_ioctl_cmd_t
*ipip
;
12124 struct lifreq
*lifr
;
12127 iocp
= (struct iocblk
*)mp
->b_rptr
;
12128 ASSERT(ipsq
!= NULL
);
12129 /* Existence of mp1 verified in ip_wput_nondata */
12130 mp1
= mp
->b_cont
->b_cont
;
12131 ipip
= ip_sioctl_lookup(iocp
->ioc_cmd
);
12132 if (ipip
->ipi_cmd
== SIOCSLIFNAME
|| ipip
->ipi_cmd
== IF_UNITSEL
) {
12134 * Special case where ipx_current_ipif is not set:
12135 * ill_phyint_reinit merged the v4 and v6 into a single ipsq.
12136 * We are here as were not able to complete the operation in
12137 * ipif_set_values because we could not become exclusive on
12140 ill_t
*ill
= q
->q_ptr
;
12141 ipsq_current_start(ipsq
, ill
->ill_ipif
, ipip
->ipi_cmd
);
12143 ASSERT(ipsq
->ipsq_xop
->ipx_current_ipif
!= NULL
);
12145 if (ipip
->ipi_cmd_type
== IF_CMD
) {
12146 /* This a old style SIOC[GS]IF* command */
12147 ifr
= (struct ifreq
*)mp1
->b_rptr
;
12148 sin
= (sin_t
*)&ifr
->ifr_addr
;
12149 } else if (ipip
->ipi_cmd_type
== LIF_CMD
) {
12150 /* This a new style SIOC[GS]LIF* command */
12151 lifr
= (struct lifreq
*)mp1
->b_rptr
;
12152 sin
= (sin_t
*)&lifr
->lifr_addr
;
12157 err
= (*ipip
->ipi_func_restart
)(ipsq
->ipsq_xop
->ipx_current_ipif
, sin
,
12158 q
, mp
, ipip
, mp1
->b_rptr
);
12160 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_reprocess_ioctl finish",
12161 int, ipip
->ipi_cmd
,
12162 ill_t
*, ipsq
->ipsq_xop
->ipx_current_ipif
->ipif_ill
,
12163 ipif_t
*, ipsq
->ipsq_xop
->ipx_current_ipif
);
12165 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), ipsq
);
12171 * ioctl processing starts with ip_sioctl_copyin_setup(), which looks up
12172 * the ioctl command in the ioctl tables, determines the copyin data size
12173 * from the ipi_copyin_size field, and does an mi_copyin() of that size.
12175 * ioctl processing then continues when the M_IOCDATA makes its way down to
12176 * ip_wput_nondata(). The ioctl is looked up again in the ioctl table, its
12177 * associated 'conn' is refheld till the end of the ioctl and the general
12178 * ioctl processing function ip_process_ioctl() is called to extract the
12179 * arguments and process the ioctl. To simplify extraction, ioctl commands
12180 * are "typed" based on the arguments they take (e.g., LIF_CMD which takes a
12181 * `struct lifreq'), and a common extract function (e.g., ip_extract_lifreq())
12182 * is used to extract the ioctl's arguments.
12184 * ip_process_ioctl determines if the ioctl needs to be serialized, and if
12185 * so goes thru the serialization primitive ipsq_try_enter. Then the
12186 * appropriate function to handle the ioctl is called based on the entry in
12187 * the ioctl table. ioctl completion is encapsulated in ip_ioctl_finish
12188 * which also refreleases the 'conn' that was refheld at the start of the
12189 * ioctl. Finally ipsq_exit is called if needed to exit the ipsq.
12191 * Many exclusive ioctls go thru an internal down up sequence as part of
12192 * the operation. For example an attempt to change the IP address of an
12193 * ipif entails ipif_down, set address, ipif_up. Bringing down the interface
12194 * does all the cleanup such as deleting all ires that use this address.
12195 * Then we need to wait till all references to the interface go away.
12198 ip_process_ioctl(ipsq_t
*ipsq
, queue_t
*q
, mblk_t
*mp
, void *arg
)
12200 struct iocblk
*iocp
= (struct iocblk
*)mp
->b_rptr
;
12201 ip_ioctl_cmd_t
*ipip
= arg
;
12202 ip_extract_func_t
*extract_funcp
;
12205 boolean_t entered_ipsq
= B_FALSE
;
12207 ip3dbg(("ip_process_ioctl: ioctl %X\n", iocp
->ioc_cmd
));
12210 ipip
= ip_sioctl_lookup(iocp
->ioc_cmd
);
12213 * SIOCLIFADDIF needs to go thru a special path since the
12214 * ill may not exist yet. This happens in the case of lo0
12215 * which is created using this ioctl.
12217 if (ipip
->ipi_cmd
== SIOCLIFADDIF
) {
12218 err
= ip_sioctl_addif(NULL
, NULL
, q
, mp
, NULL
, NULL
);
12219 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_process_ioctl finish",
12220 int, ipip
->ipi_cmd
, ill_t
*, NULL
, ipif_t
*, NULL
);
12221 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), NULL
);
12226 switch (ipip
->ipi_cmd_type
) {
12230 * All MISC_CMD ioctls come in here -- e.g. SIOCGLIFCONF.
12232 if (ipip
->ipi_cmd
== IF_UNITSEL
) {
12233 /* ioctl comes down the ill */
12234 ci
.ci_ipif
= ((ill_t
*)q
->q_ptr
)->ill_ipif
;
12235 ipif_refhold(ci
.ci_ipif
);
12241 extract_funcp
= NULL
;
12246 extract_funcp
= ip_extract_lifreq
;
12251 extract_funcp
= ip_extract_arpreq
;
12258 if (extract_funcp
!= NULL
) {
12259 err
= (*extract_funcp
)(q
, mp
, ipip
, &ci
);
12261 DTRACE_PROBE4(ipif__ioctl
,
12262 char *, "ip_process_ioctl finish err",
12263 int, ipip
->ipi_cmd
, ill_t
*, NULL
, ipif_t
*, NULL
);
12264 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), NULL
);
12269 * All of the extraction functions return a refheld ipif.
12271 ASSERT(ci
.ci_ipif
!= NULL
);
12274 if (!(ipip
->ipi_flags
& IPI_WR
)) {
12276 * A return value of EINPROGRESS means the ioctl is
12277 * either queued and waiting for some reason or has
12278 * already completed.
12280 err
= (*ipip
->ipi_func
)(ci
.ci_ipif
, ci
.ci_sin
, q
, mp
, ipip
,
12282 if (ci
.ci_ipif
!= NULL
) {
12283 DTRACE_PROBE4(ipif__ioctl
,
12284 char *, "ip_process_ioctl finish RD",
12285 int, ipip
->ipi_cmd
, ill_t
*, ci
.ci_ipif
->ipif_ill
,
12286 ipif_t
*, ci
.ci_ipif
);
12287 ipif_refrele(ci
.ci_ipif
);
12289 DTRACE_PROBE4(ipif__ioctl
,
12290 char *, "ip_process_ioctl finish RD",
12291 int, ipip
->ipi_cmd
, ill_t
*, NULL
, ipif_t
*, NULL
);
12293 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), NULL
);
12297 ASSERT(ci
.ci_ipif
!= NULL
);
12300 * If ipsq is non-NULL, we are already being called exclusively
12302 ASSERT(ipsq
== NULL
|| IAM_WRITER_IPSQ(ipsq
));
12303 if (ipsq
== NULL
) {
12304 ipsq
= ipsq_try_enter(ci
.ci_ipif
, NULL
, q
, mp
, ip_process_ioctl
,
12306 if (ipsq
== NULL
) {
12307 ipif_refrele(ci
.ci_ipif
);
12310 entered_ipsq
= B_TRUE
;
12313 * Release the ipif so that ipif_down and friends that wait for
12314 * references to go away are not misled about the current ipif_refcnt
12315 * values. We are writer so we can access the ipif even after releasing
12318 ipif_refrele(ci
.ci_ipif
);
12320 ipsq_current_start(ipsq
, ci
.ci_ipif
, ipip
->ipi_cmd
);
12323 * A return value of EINPROGRESS means the ioctl is
12324 * either queued and waiting for some reason or has
12325 * already completed.
12327 err
= (*ipip
->ipi_func
)(ci
.ci_ipif
, ci
.ci_sin
, q
, mp
, ipip
, ci
.ci_lifr
);
12329 DTRACE_PROBE4(ipif__ioctl
, char *, "ip_process_ioctl finish WR",
12330 int, ipip
->ipi_cmd
,
12331 ill_t
*, ci
.ci_ipif
== NULL
? NULL
: ci
.ci_ipif
->ipif_ill
,
12332 ipif_t
*, ci
.ci_ipif
);
12333 ip_ioctl_finish(q
, mp
, err
, IPI2MODE(ipip
), ipsq
);
12340 * Complete the ioctl. Typically ioctls use the mi package and need to
12341 * do mi_copyout/mi_copy_done.
12344 ip_ioctl_finish(queue_t
*q
, mblk_t
*mp
, int err
, int mode
, ipsq_t
*ipsq
)
12346 conn_t
*connp
= NULL
;
12348 if (err
== EINPROGRESS
)
12352 connp
= Q_TO_CONN(q
);
12353 ASSERT(connp
->conn_ref
>= 2);
12361 mi_copy_done(q
, mp
, err
);
12365 mi_copy_done(q
, mp
, err
);
12369 ASSERT(mode
== CONN_CLOSE
); /* aborted through CONN_CLOSE */
12374 * The conn refhold and ioctlref placed on the conn at the start of the
12375 * ioctl are released here.
12377 if (connp
!= NULL
) {
12378 CONN_DEC_IOCTLREF(connp
);
12379 CONN_OPER_PENDING_DONE(connp
);
12383 ipsq_current_finish(ipsq
);
12386 /* Handles all non data messages */
12388 ip_wput_nondata(queue_t
*q
, mblk_t
*mp
)
12391 struct iocblk
*iocp
;
12392 ip_ioctl_cmd_t
*ipip
;
12398 connp
= Q_TO_CONN(q
);
12402 switch (DB_TYPE(mp
)) {
12405 * IOCTL processing begins in ip_sioctl_copyin_setup which
12406 * will arrange to copy in associated control structures.
12408 ip_sioctl_copyin_setup(q
, mp
);
12412 * Ensure that this is associated with one of our trans-
12413 * parent ioctls. If it's not ours, discard it if we're
12414 * running as a driver, or pass it on if we're a module.
12416 iocp
= (struct iocblk
*)mp
->b_rptr
;
12417 ipip
= ip_sioctl_lookup(iocp
->ioc_cmd
);
12418 if (ipip
== NULL
) {
12419 if (q
->q_next
== NULL
) {
12426 if ((q
->q_next
!= NULL
) && !(ipip
->ipi_flags
& IPI_MODOK
)) {
12428 * The ioctl is one we recognise, but is not consumed
12429 * by IP as a module and we are a module, so we drop
12434 /* IOCTL continuation following copyin or copyout. */
12435 if (mi_copy_state(q
, mp
, NULL
) == -1) {
12437 * The copy operation failed. mi_copy_state already
12438 * cleaned up, so we're out of here.
12443 * If we just completed a copy in, we become writer and
12444 * continue processing in ip_sioctl_copyin_done. If it
12445 * was a copy out, we call mi_copyout again. If there is
12446 * nothing more to copy out, it will complete the IOCTL.
12448 if (MI_COPY_DIRECTION(mp
) == MI_COPY_IN
) {
12449 if (!(mp1
= mp
->b_cont
) || !(mp1
= mp1
->b_cont
)) {
12450 mi_copy_done(q
, mp
, EPROTO
);
12454 * Check for cases that need more copying. A return
12455 * value of 0 means a second copyin has been started,
12456 * so we return; a return value of 1 means no more
12457 * copying is needed, so we continue.
12459 if (ipip
->ipi_cmd_type
== MSFILT_CMD
&&
12460 MI_COPY_COUNT(mp
) == 1) {
12461 if (ip_copyin_msfilter(q
, mp
) == 0)
12465 * Refhold the conn, till the ioctl completes. This is
12466 * needed in case the ioctl ends up in the pending mp
12467 * list. Every mp in the ipx_pending_mp list must have
12468 * a refhold on the conn to resume processing. The
12469 * refhold is released when the ioctl completes
12470 * (whether normally or abnormally). An ioctlref is also
12471 * placed on the conn to prevent TCP from removing the
12472 * queue needed to send the ioctl reply back.
12473 * In all cases ip_ioctl_finish is called to finish
12474 * the ioctl and release the refholds.
12476 if (connp
!= NULL
) {
12477 /* This is not a reentry */
12478 CONN_INC_REF(connp
);
12479 CONN_INC_IOCTLREF(connp
);
12481 if (!(ipip
->ipi_flags
& IPI_MODOK
)) {
12482 mi_copy_done(q
, mp
, EINVAL
);
12487 ip_process_ioctl(NULL
, q
, mp
, ipip
);
12496 * The only way we could get here is if a resolver didn't like
12497 * an IOCTL we sent it. This shouldn't happen.
12499 (void) mi_strlog(q
, 1, SL_ERROR
|SL_TRACE
,
12500 "ip_wput_nondata: unexpected M_IOCNAK, ioc_cmd 0x%x",
12501 ((struct iocblk
*)mp
->b_rptr
)->ioc_cmd
);
12505 /* /dev/ip shouldn't see this */
12508 if (*mp
->b_rptr
& FLUSHW
)
12509 flushq(q
, FLUSHALL
);
12514 if (*mp
->b_rptr
& FLUSHR
) {
12515 *mp
->b_rptr
&= ~FLUSHW
;
12526 * The only PROTO messages we expect are SNMP-related.
12528 switch (((union T_primitives
*)mp
->b_rptr
)->type
) {
12529 case T_SVR4_OPTMGMT_REQ
:
12530 ip2dbg(("ip_wput_nondata: T_SVR4_OPTMGMT_REQ "
12532 ((struct T_optmgmt_req
*)mp
->b_rptr
)->MGMT_flags
));
12534 if (connp
== NULL
) {
12535 proto_str
= "T_SVR4_OPTMGMT_REQ";
12540 * All Solaris components should pass a db_credp
12541 * for this TPI message, hence we ASSERT.
12542 * But in case there is some other M_PROTO that looks
12543 * like a TPI message sent by some other kernel
12544 * component, we check and return an error.
12546 cr
= msg_getcred(mp
, NULL
);
12547 ASSERT(cr
!= NULL
);
12549 mp
= mi_tpi_err_ack_alloc(mp
, TSYSERR
, EINVAL
);
12555 if (!snmpcom_req(q
, mp
, ip_snmp_set
, ip_snmp_get
, cr
)) {
12556 proto_str
= "Bad SNMPCOM request?";
12561 ip1dbg(("ip_wput_nondata: dropping M_PROTO prim %u\n",
12562 (int)*(uint_t
*)mp
->b_rptr
));
12576 iocp
->ioc_error
= EINVAL
;
12577 mp
->b_datap
->db_type
= M_IOCNAK
;
12578 iocp
->ioc_count
= 0;
12583 cmn_err(CE_NOTE
, "IP doesn't process %s as a module", proto_str
);
12584 if ((mp
= mi_tpi_err_ack_alloc(mp
, TPROTO
, EINVAL
)) != NULL
)
12589 * Process IP options in an outbound packet. Verify that the nexthop in a
12590 * strict source route is onlink.
12591 * Returns non-zero if something fails in which case an ICMP error has been
12592 * sent and mp freed.
12594 * Assumes the ULP has called ip_massage_options to move nexthop into ipha_dst.
12597 ip_output_options(mblk_t
*mp
, ipha_t
*ipha
, ip_xmit_attr_t
*ixa
, ill_t
*ill
)
12606 ip_stack_t
*ipst
= ixa
->ixa_ipst
;
12607 ip_recv_attr_t iras
;
12609 ip2dbg(("ip_output_options\n"));
12611 dst
= ipha
->ipha_dst
;
12612 for (optval
= ipoptp_first(&opts
, ipha
);
12613 optval
!= IPOPT_EOL
;
12614 optval
= ipoptp_next(&opts
)) {
12615 opt
= opts
.ipoptp_cur
;
12616 optlen
= opts
.ipoptp_len
;
12617 ip2dbg(("ip_output_options: opt %d, len %d\n",
12623 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
12625 "ip_output_options: bad option offset\n"));
12626 code
= (char *)&opt
[IPOPT_OLEN
] -
12630 off
= opt
[IPOPT_OFFSET
];
12631 ip1dbg(("ip_output_options: next hop 0x%x\n",
12634 * For strict: verify that dst is directly
12637 if (optval
== IPOPT_SSRR
) {
12638 ire
= ire_ftable_lookup_v4(dst
, 0, 0,
12639 IRE_INTERFACE
, NULL
, ALL_ZONES
,
12640 MATCH_IRE_TYPE
, 0, ipst
, NULL
);
12642 ip1dbg(("ip_output_options: SSRR not"
12643 " directly reachable: 0x%x\n",
12645 goto bad_src_route
;
12651 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
12653 "ip_output_options: bad option offset\n"));
12654 code
= (char *)&opt
[IPOPT_OLEN
] -
12661 * Verify that length >=5 and that there is either
12662 * room for another timestamp or that the overflow
12663 * counter is not maxed out.
12665 code
= (char *)&opt
[IPOPT_OLEN
] - (char *)ipha
;
12666 if (optlen
< IPOPT_MINLEN_IT
) {
12669 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
12671 "ip_output_options: bad option offset\n"));
12672 code
= (char *)&opt
[IPOPT_OFFSET
] -
12676 switch (opt
[IPOPT_POS_OV_FLG
] & 0x0F) {
12677 case IPOPT_TS_TSONLY
:
12678 off
= IPOPT_TS_TIMELEN
;
12680 case IPOPT_TS_TSANDADDR
:
12681 case IPOPT_TS_PRESPEC
:
12682 case IPOPT_TS_PRESPEC_RFC791
:
12683 off
= IP_ADDR_LEN
+ IPOPT_TS_TIMELEN
;
12686 code
= (char *)&opt
[IPOPT_POS_OV_FLG
] -
12690 if (opt
[IPOPT_OFFSET
] - 1 + off
> optlen
&&
12691 (opt
[IPOPT_POS_OV_FLG
] & 0xF0) == 0xF0) {
12693 * No room and the overflow counter is 15
12702 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) == 0)
12705 ip1dbg(("ip_output_options: error processing IP options."));
12706 code
= (char *)&opt
[IPOPT_OFFSET
] - (char *)ipha
;
12709 bzero(&iras
, sizeof (iras
));
12710 iras
.ira_ill
= iras
.ira_rill
= ill
;
12711 iras
.ira_ruifindex
= ill
->ill_phyint
->phyint_ifindex
;
12712 iras
.ira_rifindex
= iras
.ira_ruifindex
;
12713 iras
.ira_flags
= IRAF_IS_IPV4
;
12715 ip_drop_output("ip_output_options", mp
, ill
);
12716 icmp_param_problem(mp
, (uint8_t)code
, &iras
);
12717 ASSERT(!(iras
.ira_flags
& IRAF_IPSEC_SECURE
));
12721 bzero(&iras
, sizeof (iras
));
12722 iras
.ira_ill
= iras
.ira_rill
= ill
;
12723 iras
.ira_ruifindex
= ill
->ill_phyint
->phyint_ifindex
;
12724 iras
.ira_rifindex
= iras
.ira_ruifindex
;
12725 iras
.ira_flags
= IRAF_IS_IPV4
;
12727 ip_drop_input("ICMP_SOURCE_ROUTE_FAILED", mp
, ill
);
12728 icmp_unreachable(mp
, ICMP_SOURCE_ROUTE_FAILED
, &iras
);
12729 ASSERT(!(iras
.ira_flags
& IRAF_IPSEC_SECURE
));
12734 * The maximum value of conn_drain_list_cnt is CONN_MAXDRAINCNT.
12735 * conn_drain_list_cnt can be changed by setting conn_drain_nthreads
12736 * thru /etc/system.
12738 #define CONN_MAXDRAINCNT 64
12741 conn_drain_init(ip_stack_t
*ipst
)
12744 idl_tx_list_t
*itl_tx
;
12746 ipst
->ips_conn_drain_list_cnt
= conn_drain_nthreads
;
12748 if ((ipst
->ips_conn_drain_list_cnt
== 0) ||
12749 (ipst
->ips_conn_drain_list_cnt
> CONN_MAXDRAINCNT
)) {
12751 * Default value of the number of drainers is the
12752 * number of cpus, subject to maximum of 8 drainers.
12754 if (boot_max_ncpus
!= -1)
12755 ipst
->ips_conn_drain_list_cnt
= MIN(boot_max_ncpus
, 8);
12757 ipst
->ips_conn_drain_list_cnt
= MIN(max_ncpus
, 8);
12760 ipst
->ips_idl_tx_list
=
12761 kmem_zalloc(TX_FANOUT_SIZE
* sizeof (idl_tx_list_t
), KM_SLEEP
);
12762 for (i
= 0; i
< TX_FANOUT_SIZE
; i
++) {
12763 itl_tx
= &ipst
->ips_idl_tx_list
[i
];
12764 itl_tx
->txl_drain_list
=
12765 kmem_zalloc(ipst
->ips_conn_drain_list_cnt
*
12766 sizeof (idl_t
), KM_SLEEP
);
12767 mutex_init(&itl_tx
->txl_lock
, NULL
, MUTEX_DEFAULT
, NULL
);
12768 for (j
= 0; j
< ipst
->ips_conn_drain_list_cnt
; j
++) {
12769 mutex_init(&itl_tx
->txl_drain_list
[j
].idl_lock
, NULL
,
12770 MUTEX_DEFAULT
, NULL
);
12771 itl_tx
->txl_drain_list
[j
].idl_itl
= itl_tx
;
12777 conn_drain_fini(ip_stack_t
*ipst
)
12780 idl_tx_list_t
*itl_tx
;
12782 for (i
= 0; i
< TX_FANOUT_SIZE
; i
++) {
12783 itl_tx
= &ipst
->ips_idl_tx_list
[i
];
12784 kmem_free(itl_tx
->txl_drain_list
,
12785 ipst
->ips_conn_drain_list_cnt
* sizeof (idl_t
));
12787 kmem_free(ipst
->ips_idl_tx_list
,
12788 TX_FANOUT_SIZE
* sizeof (idl_tx_list_t
));
12789 ipst
->ips_idl_tx_list
= NULL
;
12793 * Flow control has blocked us from proceeding. Insert the given conn in one
12794 * of the conn drain lists. When flow control is unblocked, either ip_wsrv()
12795 * (STREAMS) or ill_flow_enable() (direct) will be called back, which in turn
12796 * will call conn_walk_drain(). See the flow control notes at the top of this
12797 * file for more details.
12800 conn_drain_insert(conn_t
*connp
, idl_tx_list_t
*tx_list
)
12802 idl_t
*idl
= tx_list
->txl_drain_list
;
12804 ip_stack_t
*ipst
= connp
->conn_netstack
->netstack_ip
;
12806 mutex_enter(&connp
->conn_lock
);
12807 if (connp
->conn_state_flags
& CONN_CLOSING
) {
12809 * The conn is closing as a result of which CONN_CLOSING
12812 mutex_exit(&connp
->conn_lock
);
12814 } else if (connp
->conn_idl
== NULL
) {
12816 * Assign the next drain list round robin. We dont' use
12817 * a lock, and thus it may not be strictly round robin.
12818 * Atomicity of load/stores is enough to make sure that
12819 * conn_drain_list_index is always within bounds.
12821 index
= tx_list
->txl_drain_index
;
12822 ASSERT(index
< ipst
->ips_conn_drain_list_cnt
);
12823 connp
->conn_idl
= &tx_list
->txl_drain_list
[index
];
12825 if (index
== ipst
->ips_conn_drain_list_cnt
)
12827 tx_list
->txl_drain_index
= index
;
12829 ASSERT(connp
->conn_idl
->idl_itl
== tx_list
);
12831 mutex_exit(&connp
->conn_lock
);
12833 idl
= connp
->conn_idl
;
12834 mutex_enter(&idl
->idl_lock
);
12835 if ((connp
->conn_drain_prev
!= NULL
) ||
12836 (connp
->conn_state_flags
& CONN_CLOSING
)) {
12838 * The conn is either already in the drain list or closing.
12839 * (We needed to check for CONN_CLOSING again since close can
12840 * sneak in between dropping conn_lock and acquiring idl_lock.)
12842 mutex_exit(&idl
->idl_lock
);
12847 * The conn is not in the drain list. Insert it at the
12848 * tail of the drain list. The drain list is circular
12849 * and doubly linked. idl_conn points to the 1st element
12852 if (idl
->idl_conn
== NULL
) {
12853 idl
->idl_conn
= connp
;
12854 connp
->conn_drain_next
= connp
;
12855 connp
->conn_drain_prev
= connp
;
12857 conn_t
*head
= idl
->idl_conn
;
12859 connp
->conn_drain_next
= head
;
12860 connp
->conn_drain_prev
= head
->conn_drain_prev
;
12861 head
->conn_drain_prev
->conn_drain_next
= connp
;
12862 head
->conn_drain_prev
= connp
;
12865 * For non streams based sockets assert flow control.
12867 conn_setqfull(connp
, NULL
);
12868 mutex_exit(&idl
->idl_lock
);
12872 conn_drain_remove(conn_t
*connp
)
12874 idl_t
*idl
= connp
->conn_idl
;
12878 * Remove ourself from the drain list.
12880 if (connp
->conn_drain_next
== connp
) {
12881 /* Singleton in the list */
12882 ASSERT(connp
->conn_drain_prev
== connp
);
12883 idl
->idl_conn
= NULL
;
12885 connp
->conn_drain_prev
->conn_drain_next
=
12886 connp
->conn_drain_next
;
12887 connp
->conn_drain_next
->conn_drain_prev
=
12888 connp
->conn_drain_prev
;
12889 if (idl
->idl_conn
== connp
)
12890 idl
->idl_conn
= connp
->conn_drain_next
;
12894 * NOTE: because conn_idl is associated with a specific drain
12895 * list which in turn is tied to the index the TX ring
12896 * (txl_cookie) hashes to, and because the TX ring can change
12897 * over the lifetime of the conn_t, we must clear conn_idl so
12898 * a subsequent conn_drain_insert() will set conn_idl again
12899 * based on the latest txl_cookie.
12901 connp
->conn_idl
= NULL
;
12903 connp
->conn_drain_next
= NULL
;
12904 connp
->conn_drain_prev
= NULL
;
12906 conn_clrqfull(connp
, NULL
);
12908 * For streams based sockets open up flow control.
12910 if (!IPCL_IS_NONSTR(connp
))
12911 enableok(connp
->conn_wq
);
12915 * This conn is closing, and we are called from ip_close. OR
12916 * this conn is draining because flow-control on the ill has been relieved.
12918 * We must also need to remove conn's on this idl from the list, and also
12919 * inform the sockfs upcalls about the change in flow-control.
12922 conn_drain(conn_t
*connp
, boolean_t closing
)
12925 conn_t
*next_connp
;
12928 * connp->conn_idl is stable at this point, and no lock is needed
12929 * to check it. If we are called from ip_close, close has already
12930 * set CONN_CLOSING, thus freezing the value of conn_idl, and
12931 * called us only because conn_idl is non-null. If we are called thru
12932 * service, conn_idl could be null, but it cannot change because
12933 * service is single-threaded per queue, and there cannot be another
12934 * instance of service trying to call conn_drain_insert on this conn
12937 ASSERT(!closing
|| connp
== NULL
|| connp
->conn_idl
!= NULL
);
12940 * If the conn doesn't exist or is not on a drain list, bail.
12942 if (connp
== NULL
|| connp
->conn_idl
== NULL
||
12943 connp
->conn_drain_prev
== NULL
) {
12947 idl
= connp
->conn_idl
;
12948 ASSERT(MUTEX_HELD(&idl
->idl_lock
));
12951 next_connp
= connp
->conn_drain_next
;
12952 while (next_connp
!= connp
) {
12953 conn_t
*delconnp
= next_connp
;
12955 next_connp
= next_connp
->conn_drain_next
;
12956 conn_drain_remove(delconnp
);
12958 ASSERT(connp
->conn_drain_next
== idl
->idl_conn
);
12960 conn_drain_remove(connp
);
12964 * Write service routine. Shared perimeter entry point.
12965 * The device queue's messages has fallen below the low water mark and STREAMS
12966 * has backenabled the ill_wq. Send sockfs notification about flow-control on
12967 * each waiting conn.
12970 ip_wsrv(queue_t
*q
)
12974 ill
= (ill_t
*)q
->q_ptr
;
12975 if (ill
->ill_state_flags
== 0) {
12976 ip_stack_t
*ipst
= ill
->ill_ipst
;
12979 * The device flow control has opened up.
12980 * Walk through conn drain lists and qenable the
12981 * first conn in each list. This makes sense only
12982 * if the stream is fully plumbed and setup.
12983 * Hence the ill_state_flags check above.
12985 ip1dbg(("ip_wsrv: walking\n"));
12986 conn_walk_drain(ipst
, &ipst
->ips_idl_tx_list
[0]);
12987 enableok(ill
->ill_wq
);
12992 * Callback to disable flow control in IP.
12994 * This is a mac client callback added when the DLD_CAPAB_DIRECT capability
12997 * When MAC_TX() is not able to send any more packets, dld sets its queue
12998 * to QFULL and enable the STREAMS flow control. Later, when the underlying
12999 * driver is able to continue to send packets, it calls mac_tx_(ring_)update()
13000 * function and wakes up corresponding mac worker threads, which in turn
13001 * calls this callback function, and disables flow control.
13004 ill_flow_enable(void *arg
, ip_mac_tx_cookie_t cookie
)
13006 ill_t
*ill
= (ill_t
*)arg
;
13007 ip_stack_t
*ipst
= ill
->ill_ipst
;
13008 idl_tx_list_t
*idl_txl
;
13010 idl_txl
= &ipst
->ips_idl_tx_list
[IDLHASHINDEX(cookie
)];
13011 mutex_enter(&idl_txl
->txl_lock
);
13012 /* add code to to set a flag to indicate idl_txl is enabled */
13013 conn_walk_drain(ipst
, idl_txl
);
13014 mutex_exit(&idl_txl
->txl_lock
);
13018 * Flow control has been relieved and STREAMS has backenabled us; drain
13019 * all the conn lists on `tx_list'.
13022 conn_walk_drain(ip_stack_t
*ipst
, idl_tx_list_t
*tx_list
)
13027 IP_STAT(ipst
, ip_conn_walk_drain
);
13029 for (i
= 0; i
< ipst
->ips_conn_drain_list_cnt
; i
++) {
13030 idl
= &tx_list
->txl_drain_list
[i
];
13031 mutex_enter(&idl
->idl_lock
);
13032 conn_drain(idl
->idl_conn
, B_FALSE
);
13033 mutex_exit(&idl
->idl_lock
);
13038 * Determine if the ill and multicast aspects of that packets
13039 * "matches" the conn.
13042 conn_wantpacket(conn_t
*connp
, ip_recv_attr_t
*ira
, ipha_t
*ipha
)
13044 ill_t
*ill
= ira
->ira_rill
;
13045 zoneid_t zoneid
= ira
->ira_zoneid
;
13049 dst
= ipha
->ipha_dst
;
13050 src
= ipha
->ipha_src
;
13053 * conn_incoming_ifindex is set by IP_BOUND_IF which limits
13054 * unicast, broadcast and multicast reception to
13055 * conn_incoming_ifindex.
13056 * conn_wantpacket is called for unicast, broadcast and
13057 * multicast packets.
13059 in_ifindex
= connp
->conn_incoming_ifindex
;
13061 /* mpathd can bind to the under IPMP interface, which we allow */
13062 if (in_ifindex
!= 0 && in_ifindex
!= ill
->ill_phyint
->phyint_ifindex
) {
13063 if (!IS_UNDER_IPMP(ill
))
13066 if (in_ifindex
!= ipmp_ill_get_ipmp_ifindex(ill
))
13070 if (!IPCL_ZONE_MATCH(connp
, zoneid
))
13073 if (!(ira
->ira_flags
& IRAF_MULTICAST
))
13076 if (connp
->conn_multi_router
) {
13077 /* multicast packet and multicast router socket: send up */
13081 if (ipha
->ipha_protocol
== IPPROTO_PIM
||
13082 ipha
->ipha_protocol
== IPPROTO_RSVP
)
13085 return (conn_hasmembers_ill_withsrc_v4(connp
, dst
, src
, ira
->ira_ill
));
13089 conn_setqfull(conn_t
*connp
, boolean_t
*flow_stopped
)
13091 if (IPCL_IS_NONSTR(connp
)) {
13092 (*connp
->conn_upcalls
->su_txq_full
)
13093 (connp
->conn_upper_handle
, B_TRUE
);
13094 if (flow_stopped
!= NULL
)
13095 *flow_stopped
= B_TRUE
;
13097 queue_t
*q
= connp
->conn_wq
;
13100 if (!(q
->q_flag
& QFULL
)) {
13101 mutex_enter(QLOCK(q
));
13102 if (!(q
->q_flag
& QFULL
)) {
13103 /* still need to set QFULL */
13104 q
->q_flag
|= QFULL
;
13105 /* set flow_stopped to true under QLOCK */
13106 if (flow_stopped
!= NULL
)
13107 *flow_stopped
= B_TRUE
;
13108 mutex_exit(QLOCK(q
));
13110 /* flow_stopped is left unchanged */
13111 mutex_exit(QLOCK(q
));
13118 conn_clrqfull(conn_t
*connp
, boolean_t
*flow_stopped
)
13120 if (IPCL_IS_NONSTR(connp
)) {
13121 (*connp
->conn_upcalls
->su_txq_full
)
13122 (connp
->conn_upper_handle
, B_FALSE
);
13123 if (flow_stopped
!= NULL
)
13124 *flow_stopped
= B_FALSE
;
13126 queue_t
*q
= connp
->conn_wq
;
13129 if (q
->q_flag
& QFULL
) {
13130 mutex_enter(QLOCK(q
));
13131 if (q
->q_flag
& QFULL
) {
13132 q
->q_flag
&= ~QFULL
;
13133 /* set flow_stopped to false under QLOCK */
13134 if (flow_stopped
!= NULL
)
13135 *flow_stopped
= B_FALSE
;
13136 mutex_exit(QLOCK(q
));
13137 if (q
->q_flag
& QWANTW
)
13140 /* flow_stopped is left unchanged */
13141 mutex_exit(QLOCK(q
));
13146 mutex_enter(&connp
->conn_lock
);
13147 connp
->conn_blocked
= B_FALSE
;
13148 mutex_exit(&connp
->conn_lock
);
13152 * Return the length in bytes of the IPv4 headers (base header and IP options)
13153 * that will be needed based on the ip_pkt_t structure passed by the caller.
13155 * The returned length does not include the length of the upper level
13156 * protocol (ULP) header.
13157 * The caller needs to check that the length doesn't exceed the max for IPv4.
13160 ip_total_hdrs_len_v4(const ip_pkt_t
*ipp
)
13164 len
= IP_SIMPLE_HDR_LENGTH
;
13166 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
13167 ASSERT(ipp
->ipp_ipv4_options_len
!= 0);
13168 ASSERT((ipp
->ipp_ipv4_options_len
& 3) == 0);
13169 len
+= ipp
->ipp_ipv4_options_len
;
13175 * All-purpose routine to build an IPv4 header with options based
13176 * on the abstract ip_pkt_t.
13178 * The caller has to set the source and destination address as well as
13179 * ipha_length. The caller has to massage any source route and compensate
13180 * for the ULP pseudo-header checksum due to the source route.
13183 ip_build_hdrs_v4(uchar_t
*buf
, uint_t buf_len
, const ip_pkt_t
*ipp
,
13186 ipha_t
*ipha
= (ipha_t
*)buf
;
13189 /* Initialize IPv4 header */
13190 ipha
->ipha_type_of_service
= ipp
->ipp_type_of_service
;
13191 ipha
->ipha_length
= 0; /* Caller will set later */
13192 ipha
->ipha_ident
= 0;
13193 ipha
->ipha_fragment_offset_and_flags
= 0;
13194 ipha
->ipha_ttl
= ipp
->ipp_unicast_hops
;
13195 ipha
->ipha_protocol
= protocol
;
13196 ipha
->ipha_hdr_checksum
= 0;
13198 if ((ipp
->ipp_fields
& IPPF_ADDR
) &&
13199 IN6_IS_ADDR_V4MAPPED(&ipp
->ipp_addr
))
13200 ipha
->ipha_src
= ipp
->ipp_addr_v4
;
13202 cp
= (uint8_t *)&ipha
[1];
13204 if (ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
) {
13205 ASSERT(ipp
->ipp_ipv4_options_len
!= 0);
13206 ASSERT((ipp
->ipp_ipv4_options_len
& 3) == 0);
13207 bcopy(ipp
->ipp_ipv4_options
, cp
, ipp
->ipp_ipv4_options_len
);
13208 cp
+= ipp
->ipp_ipv4_options_len
;
13210 ipha
->ipha_version_and_hdr_length
=
13211 (uint8_t)((IP_VERSION
<< 4) + buf_len
/ 4);
13213 ASSERT((int)(cp
- buf
) == buf_len
);
13216 /* Allocate the private structure */
13218 ip_priv_alloc(void **bufp
)
13222 if ((buf
= kmem_alloc(sizeof (ip_priv_t
), KM_NOSLEEP
)) == NULL
)
13229 /* Function to delete the private structure */
13231 ip_priv_free(void *buf
)
13233 ASSERT(buf
!= NULL
);
13234 kmem_free(buf
, sizeof (ip_priv_t
));
13238 * The entry point for IPPF processing.
13239 * If the classifier (IPGPC_CLASSIFY) is not loaded and configured, the
13240 * routine just returns.
13242 * When called, ip_process generates an ipp_packet_t structure
13243 * which holds the state information for this packet and invokes the
13244 * the classifier (via ipp_packet_process). The classification, depending on
13245 * configured filters, results in a list of actions for this packet. Invoking
13246 * an action may cause the packet to be dropped, in which case we return NULL.
13247 * proc indicates the callout position for
13248 * this packet and ill is the interface this packet arrived on or will leave
13249 * on (inbound and outbound resp.).
13251 * We do the processing on the rill (mapped to the upper if ipmp), but MIB
13252 * on the ill corrsponding to the destination IP address.
13255 ip_process(ip_proc_t proc
, mblk_t
*mp
, ill_t
*rill
, ill_t
*ill
)
13258 ipp_action_id_t aid
;
13262 /* If the classifier is not loaded, return */
13263 if ((aid
= ipp_action_lookup(IPGPC_CLASSIFY
)) == IPP_ACTION_INVAL
) {
13267 ASSERT(mp
!= NULL
);
13269 /* Allocate the packet structure */
13270 rc
= ipp_packet_alloc(&pp
, "ip", aid
);
13274 /* Allocate the private structure */
13275 rc
= ip_priv_alloc((void **)&priv
);
13277 ipp_packet_free(pp
);
13281 priv
->ill_index
= ill_get_upper_ifindex(rill
);
13283 ipp_packet_set_private(pp
, priv
, ip_priv_free
);
13284 ipp_packet_set_data(pp
, mp
);
13286 /* Invoke the classifier */
13287 rc
= ipp_packet_process(&pp
);
13289 mp
= ipp_packet_get_data(pp
);
13290 ipp_packet_free(pp
);
13295 /* No mp to trace in ip_drop_input/ip_drop_output */
13299 if (proc
== IPP_LOCAL_IN
|| proc
== IPP_FWD_IN
) {
13300 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
13301 ip_drop_input("ip_process", mp
, ill
);
13303 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
13304 ip_drop_output("ip_process", mp
, ill
);
13311 ip_squeue_switch(int val
)
13316 case IP_SQUEUE_ENTER_NODRAIN
:
13319 case IP_SQUEUE_ENTER
:
13322 case IP_SQUEUE_FILL
:
13331 ip_kstat2_init(netstackid_t stackid
, ip_stat_t
*ip_statisticsp
)
13335 ip_stat_t
template = {
13336 { "ip_udp_fannorm", KSTAT_DATA_UINT64
},
13337 { "ip_udp_fanmb", KSTAT_DATA_UINT64
},
13338 { "ip_recv_pullup", KSTAT_DATA_UINT64
},
13339 { "ip_db_ref", KSTAT_DATA_UINT64
},
13340 { "ip_notaligned", KSTAT_DATA_UINT64
},
13341 { "ip_multimblk", KSTAT_DATA_UINT64
},
13342 { "ip_opt", KSTAT_DATA_UINT64
},
13343 { "ipsec_proto_ahesp", KSTAT_DATA_UINT64
},
13344 { "ip_conn_flputbq", KSTAT_DATA_UINT64
},
13345 { "ip_conn_walk_drain", KSTAT_DATA_UINT64
},
13346 { "ip_out_sw_cksum", KSTAT_DATA_UINT64
},
13347 { "ip_out_sw_cksum_bytes", KSTAT_DATA_UINT64
},
13348 { "ip_in_sw_cksum", KSTAT_DATA_UINT64
},
13349 { "ip_ire_reclaim_calls", KSTAT_DATA_UINT64
},
13350 { "ip_ire_reclaim_deleted", KSTAT_DATA_UINT64
},
13351 { "ip_nce_reclaim_calls", KSTAT_DATA_UINT64
},
13352 { "ip_nce_reclaim_deleted", KSTAT_DATA_UINT64
},
13353 { "ip_dce_reclaim_calls", KSTAT_DATA_UINT64
},
13354 { "ip_dce_reclaim_deleted", KSTAT_DATA_UINT64
},
13355 { "ip_tcp_in_full_hw_cksum_err", KSTAT_DATA_UINT64
},
13356 { "ip_tcp_in_part_hw_cksum_err", KSTAT_DATA_UINT64
},
13357 { "ip_tcp_in_sw_cksum_err", KSTAT_DATA_UINT64
},
13358 { "ip_udp_in_full_hw_cksum_err", KSTAT_DATA_UINT64
},
13359 { "ip_udp_in_part_hw_cksum_err", KSTAT_DATA_UINT64
},
13360 { "ip_udp_in_sw_cksum_err", KSTAT_DATA_UINT64
},
13361 { "conn_in_recvdstaddr", KSTAT_DATA_UINT64
},
13362 { "conn_in_recvopts", KSTAT_DATA_UINT64
},
13363 { "conn_in_recvif", KSTAT_DATA_UINT64
},
13364 { "conn_in_recvslla", KSTAT_DATA_UINT64
},
13365 { "conn_in_recvucred", KSTAT_DATA_UINT64
},
13366 { "conn_in_recvttl", KSTAT_DATA_UINT64
},
13367 { "conn_in_recvhopopts", KSTAT_DATA_UINT64
},
13368 { "conn_in_recvhoplimit", KSTAT_DATA_UINT64
},
13369 { "conn_in_recvdstopts", KSTAT_DATA_UINT64
},
13370 { "conn_in_recvrthdrdstopts", KSTAT_DATA_UINT64
},
13371 { "conn_in_recvrthdr", KSTAT_DATA_UINT64
},
13372 { "conn_in_recvpktinfo", KSTAT_DATA_UINT64
},
13373 { "conn_in_recvtclass", KSTAT_DATA_UINT64
},
13374 { "conn_in_timestamp", KSTAT_DATA_UINT64
},
13377 ksp
= kstat_create_netstack("ip", 0, "ipstat", "net",
13378 KSTAT_TYPE_NAMED
, sizeof (template) / sizeof (kstat_named_t
),
13379 KSTAT_FLAG_VIRTUAL
, stackid
);
13384 bcopy(&template, ip_statisticsp
, sizeof (template));
13385 ksp
->ks_data
= (void *)ip_statisticsp
;
13386 ksp
->ks_private
= (void *)(uintptr_t)stackid
;
13388 kstat_install(ksp
);
13393 ip_kstat2_fini(netstackid_t stackid
, kstat_t
*ksp
)
13396 ASSERT(stackid
== (netstackid_t
)(uintptr_t)ksp
->ks_private
);
13397 kstat_delete_netstack(ksp
, stackid
);
13402 ip_kstat_init(netstackid_t stackid
, ip_stack_t
*ipst
)
13406 ip_named_kstat_t
template = {
13407 { "forwarding", KSTAT_DATA_UINT32
, 0 },
13408 { "defaultTTL", KSTAT_DATA_UINT32
, 0 },
13409 { "inReceives", KSTAT_DATA_UINT64
, 0 },
13410 { "inHdrErrors", KSTAT_DATA_UINT32
, 0 },
13411 { "inAddrErrors", KSTAT_DATA_UINT32
, 0 },
13412 { "forwDatagrams", KSTAT_DATA_UINT64
, 0 },
13413 { "inUnknownProtos", KSTAT_DATA_UINT32
, 0 },
13414 { "inDiscards", KSTAT_DATA_UINT32
, 0 },
13415 { "inDelivers", KSTAT_DATA_UINT64
, 0 },
13416 { "outRequests", KSTAT_DATA_UINT64
, 0 },
13417 { "outDiscards", KSTAT_DATA_UINT32
, 0 },
13418 { "outNoRoutes", KSTAT_DATA_UINT32
, 0 },
13419 { "reasmTimeout", KSTAT_DATA_UINT32
, 0 },
13420 { "reasmReqds", KSTAT_DATA_UINT32
, 0 },
13421 { "reasmOKs", KSTAT_DATA_UINT32
, 0 },
13422 { "reasmFails", KSTAT_DATA_UINT32
, 0 },
13423 { "fragOKs", KSTAT_DATA_UINT32
, 0 },
13424 { "fragFails", KSTAT_DATA_UINT32
, 0 },
13425 { "fragCreates", KSTAT_DATA_UINT32
, 0 },
13426 { "addrEntrySize", KSTAT_DATA_INT32
, 0 },
13427 { "routeEntrySize", KSTAT_DATA_INT32
, 0 },
13428 { "netToMediaEntrySize", KSTAT_DATA_INT32
, 0 },
13429 { "routingDiscards", KSTAT_DATA_UINT32
, 0 },
13430 { "inErrs", KSTAT_DATA_UINT32
, 0 },
13431 { "noPorts", KSTAT_DATA_UINT32
, 0 },
13432 { "inCksumErrs", KSTAT_DATA_UINT32
, 0 },
13433 { "reasmDuplicates", KSTAT_DATA_UINT32
, 0 },
13434 { "reasmPartDups", KSTAT_DATA_UINT32
, 0 },
13435 { "forwProhibits", KSTAT_DATA_UINT32
, 0 },
13436 { "udpInCksumErrs", KSTAT_DATA_UINT32
, 0 },
13437 { "udpInOverflows", KSTAT_DATA_UINT32
, 0 },
13438 { "rawipInOverflows", KSTAT_DATA_UINT32
, 0 },
13439 { "ipsecInSucceeded", KSTAT_DATA_UINT32
, 0 },
13440 { "ipsecInFailed", KSTAT_DATA_INT32
, 0 },
13441 { "memberEntrySize", KSTAT_DATA_INT32
, 0 },
13442 { "inIPv6", KSTAT_DATA_UINT32
, 0 },
13443 { "outIPv6", KSTAT_DATA_UINT32
, 0 },
13444 { "outSwitchIPv6", KSTAT_DATA_UINT32
, 0 },
13447 ksp
= kstat_create_netstack("ip", 0, "ip", "mib2", KSTAT_TYPE_NAMED
,
13448 NUM_OF_FIELDS(ip_named_kstat_t
), 0, stackid
);
13449 if (ksp
== NULL
|| ksp
->ks_data
== NULL
)
13452 template.forwarding
.value
.ui32
= WE_ARE_FORWARDING(ipst
) ? 1:2;
13453 template.defaultTTL
.value
.ui32
= (uint32_t)ipst
->ips_ip_def_ttl
;
13454 template.reasmTimeout
.value
.ui32
= ipst
->ips_ip_reassembly_timeout
;
13455 template.addrEntrySize
.value
.i32
= sizeof (mib2_ipAddrEntry_t
);
13456 template.routeEntrySize
.value
.i32
= sizeof (mib2_ipRouteEntry_t
);
13458 template.netToMediaEntrySize
.value
.i32
=
13459 sizeof (mib2_ipNetToMediaEntry_t
);
13461 template.memberEntrySize
.value
.i32
= sizeof (ipv6_member_t
);
13463 bcopy(&template, ksp
->ks_data
, sizeof (template));
13464 ksp
->ks_update
= ip_kstat_update
;
13465 ksp
->ks_private
= (void *)(uintptr_t)stackid
;
13467 kstat_install(ksp
);
13472 ip_kstat_fini(netstackid_t stackid
, kstat_t
*ksp
)
13475 ASSERT(stackid
== (netstackid_t
)(uintptr_t)ksp
->ks_private
);
13476 kstat_delete_netstack(ksp
, stackid
);
13481 ip_kstat_update(kstat_t
*kp
, int rw
)
13483 ip_named_kstat_t
*ipkp
;
13484 mib2_ipIfStatsEntry_t ipmib
;
13485 ill_walk_context_t ctx
;
13487 netstackid_t stackid
= (zoneid_t
)(uintptr_t)kp
->ks_private
;
13491 if (kp
== NULL
|| kp
->ks_data
== NULL
)
13494 if (rw
== KSTAT_WRITE
)
13497 ns
= netstack_find_by_stackid(stackid
);
13500 ipst
= ns
->netstack_ip
;
13501 if (ipst
== NULL
) {
13505 ipkp
= (ip_named_kstat_t
*)kp
->ks_data
;
13507 bcopy(&ipst
->ips_ip_mib
, &ipmib
, sizeof (ipmib
));
13508 rw_enter(&ipst
->ips_ill_g_lock
, RW_READER
);
13509 ill
= ILL_START_WALK_V4(&ctx
, ipst
);
13510 for (; ill
!= NULL
; ill
= ill_next(&ctx
, ill
))
13511 ip_mib2_add_ip_stats(&ipmib
, ill
->ill_ip_mib
);
13512 rw_exit(&ipst
->ips_ill_g_lock
);
13514 ipkp
->forwarding
.value
.ui32
= ipmib
.ipIfStatsForwarding
;
13515 ipkp
->defaultTTL
.value
.ui32
= ipmib
.ipIfStatsDefaultTTL
;
13516 ipkp
->inReceives
.value
.ui64
= ipmib
.ipIfStatsHCInReceives
;
13517 ipkp
->inHdrErrors
.value
.ui32
= ipmib
.ipIfStatsInHdrErrors
;
13518 ipkp
->inAddrErrors
.value
.ui32
= ipmib
.ipIfStatsInAddrErrors
;
13519 ipkp
->forwDatagrams
.value
.ui64
= ipmib
.ipIfStatsHCOutForwDatagrams
;
13520 ipkp
->inUnknownProtos
.value
.ui32
= ipmib
.ipIfStatsInUnknownProtos
;
13521 ipkp
->inDiscards
.value
.ui32
= ipmib
.ipIfStatsInDiscards
;
13522 ipkp
->inDelivers
.value
.ui64
= ipmib
.ipIfStatsHCInDelivers
;
13523 ipkp
->outRequests
.value
.ui64
= ipmib
.ipIfStatsHCOutRequests
;
13524 ipkp
->outDiscards
.value
.ui32
= ipmib
.ipIfStatsOutDiscards
;
13525 ipkp
->outNoRoutes
.value
.ui32
= ipmib
.ipIfStatsOutNoRoutes
;
13526 ipkp
->reasmTimeout
.value
.ui32
= ipst
->ips_ip_reassembly_timeout
;
13527 ipkp
->reasmReqds
.value
.ui32
= ipmib
.ipIfStatsReasmReqds
;
13528 ipkp
->reasmOKs
.value
.ui32
= ipmib
.ipIfStatsReasmOKs
;
13529 ipkp
->reasmFails
.value
.ui32
= ipmib
.ipIfStatsReasmFails
;
13530 ipkp
->fragOKs
.value
.ui32
= ipmib
.ipIfStatsOutFragOKs
;
13531 ipkp
->fragFails
.value
.ui32
= ipmib
.ipIfStatsOutFragFails
;
13532 ipkp
->fragCreates
.value
.ui32
= ipmib
.ipIfStatsOutFragCreates
;
13534 ipkp
->routingDiscards
.value
.ui32
= 0;
13535 ipkp
->inErrs
.value
.ui32
= ipmib
.tcpIfStatsInErrs
;
13536 ipkp
->noPorts
.value
.ui32
= ipmib
.udpIfStatsNoPorts
;
13537 ipkp
->inCksumErrs
.value
.ui32
= ipmib
.ipIfStatsInCksumErrs
;
13538 ipkp
->reasmDuplicates
.value
.ui32
= ipmib
.ipIfStatsReasmDuplicates
;
13539 ipkp
->reasmPartDups
.value
.ui32
= ipmib
.ipIfStatsReasmPartDups
;
13540 ipkp
->forwProhibits
.value
.ui32
= ipmib
.ipIfStatsForwProhibits
;
13541 ipkp
->udpInCksumErrs
.value
.ui32
= ipmib
.udpIfStatsInCksumErrs
;
13542 ipkp
->udpInOverflows
.value
.ui32
= ipmib
.udpIfStatsInOverflows
;
13543 ipkp
->rawipInOverflows
.value
.ui32
= ipmib
.rawipIfStatsInOverflows
;
13544 ipkp
->ipsecInSucceeded
.value
.ui32
= ipmib
.ipsecIfStatsInSucceeded
;
13545 ipkp
->ipsecInFailed
.value
.i32
= ipmib
.ipsecIfStatsInFailed
;
13547 ipkp
->inIPv6
.value
.ui32
= ipmib
.ipIfStatsInWrongIPVersion
;
13548 ipkp
->outIPv6
.value
.ui32
= ipmib
.ipIfStatsOutWrongIPVersion
;
13549 ipkp
->outSwitchIPv6
.value
.ui32
= ipmib
.ipIfStatsOutSwitchIPVersion
;
13557 icmp_kstat_init(netstackid_t stackid
)
13561 icmp_named_kstat_t
template = {
13562 { "inMsgs", KSTAT_DATA_UINT32
},
13563 { "inErrors", KSTAT_DATA_UINT32
},
13564 { "inDestUnreachs", KSTAT_DATA_UINT32
},
13565 { "inTimeExcds", KSTAT_DATA_UINT32
},
13566 { "inParmProbs", KSTAT_DATA_UINT32
},
13567 { "inSrcQuenchs", KSTAT_DATA_UINT32
},
13568 { "inRedirects", KSTAT_DATA_UINT32
},
13569 { "inEchos", KSTAT_DATA_UINT32
},
13570 { "inEchoReps", KSTAT_DATA_UINT32
},
13571 { "inTimestamps", KSTAT_DATA_UINT32
},
13572 { "inTimestampReps", KSTAT_DATA_UINT32
},
13573 { "inAddrMasks", KSTAT_DATA_UINT32
},
13574 { "inAddrMaskReps", KSTAT_DATA_UINT32
},
13575 { "outMsgs", KSTAT_DATA_UINT32
},
13576 { "outErrors", KSTAT_DATA_UINT32
},
13577 { "outDestUnreachs", KSTAT_DATA_UINT32
},
13578 { "outTimeExcds", KSTAT_DATA_UINT32
},
13579 { "outParmProbs", KSTAT_DATA_UINT32
},
13580 { "outSrcQuenchs", KSTAT_DATA_UINT32
},
13581 { "outRedirects", KSTAT_DATA_UINT32
},
13582 { "outEchos", KSTAT_DATA_UINT32
},
13583 { "outEchoReps", KSTAT_DATA_UINT32
},
13584 { "outTimestamps", KSTAT_DATA_UINT32
},
13585 { "outTimestampReps", KSTAT_DATA_UINT32
},
13586 { "outAddrMasks", KSTAT_DATA_UINT32
},
13587 { "outAddrMaskReps", KSTAT_DATA_UINT32
},
13588 { "inChksumErrs", KSTAT_DATA_UINT32
},
13589 { "inUnknowns", KSTAT_DATA_UINT32
},
13590 { "inFragNeeded", KSTAT_DATA_UINT32
},
13591 { "outFragNeeded", KSTAT_DATA_UINT32
},
13592 { "outDrops", KSTAT_DATA_UINT32
},
13593 { "inOverFlows", KSTAT_DATA_UINT32
},
13594 { "inBadRedirects", KSTAT_DATA_UINT32
},
13597 ksp
= kstat_create_netstack("ip", 0, "icmp", "mib2", KSTAT_TYPE_NAMED
,
13598 NUM_OF_FIELDS(icmp_named_kstat_t
), 0, stackid
);
13599 if (ksp
== NULL
|| ksp
->ks_data
== NULL
)
13602 bcopy(&template, ksp
->ks_data
, sizeof (template));
13604 ksp
->ks_update
= icmp_kstat_update
;
13605 ksp
->ks_private
= (void *)(uintptr_t)stackid
;
13607 kstat_install(ksp
);
13612 icmp_kstat_fini(netstackid_t stackid
, kstat_t
*ksp
)
13615 ASSERT(stackid
== (netstackid_t
)(uintptr_t)ksp
->ks_private
);
13616 kstat_delete_netstack(ksp
, stackid
);
13621 icmp_kstat_update(kstat_t
*kp
, int rw
)
13623 icmp_named_kstat_t
*icmpkp
;
13624 netstackid_t stackid
= (zoneid_t
)(uintptr_t)kp
->ks_private
;
13628 if ((kp
== NULL
) || (kp
->ks_data
== NULL
))
13631 if (rw
== KSTAT_WRITE
)
13634 ns
= netstack_find_by_stackid(stackid
);
13637 ipst
= ns
->netstack_ip
;
13638 if (ipst
== NULL
) {
13642 icmpkp
= (icmp_named_kstat_t
*)kp
->ks_data
;
13644 icmpkp
->inMsgs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInMsgs
;
13645 icmpkp
->inErrors
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInErrors
;
13646 icmpkp
->inDestUnreachs
.value
.ui32
=
13647 ipst
->ips_icmp_mib
.icmpInDestUnreachs
;
13648 icmpkp
->inTimeExcds
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInTimeExcds
;
13649 icmpkp
->inParmProbs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInParmProbs
;
13650 icmpkp
->inSrcQuenchs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInSrcQuenchs
;
13651 icmpkp
->inRedirects
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInRedirects
;
13652 icmpkp
->inEchos
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInEchos
;
13653 icmpkp
->inEchoReps
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInEchoReps
;
13654 icmpkp
->inTimestamps
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInTimestamps
;
13655 icmpkp
->inTimestampReps
.value
.ui32
=
13656 ipst
->ips_icmp_mib
.icmpInTimestampReps
;
13657 icmpkp
->inAddrMasks
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInAddrMasks
;
13658 icmpkp
->inAddrMaskReps
.value
.ui32
=
13659 ipst
->ips_icmp_mib
.icmpInAddrMaskReps
;
13660 icmpkp
->outMsgs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutMsgs
;
13661 icmpkp
->outErrors
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutErrors
;
13662 icmpkp
->outDestUnreachs
.value
.ui32
=
13663 ipst
->ips_icmp_mib
.icmpOutDestUnreachs
;
13664 icmpkp
->outTimeExcds
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutTimeExcds
;
13665 icmpkp
->outParmProbs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutParmProbs
;
13666 icmpkp
->outSrcQuenchs
.value
.ui32
=
13667 ipst
->ips_icmp_mib
.icmpOutSrcQuenchs
;
13668 icmpkp
->outRedirects
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutRedirects
;
13669 icmpkp
->outEchos
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutEchos
;
13670 icmpkp
->outEchoReps
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutEchoReps
;
13671 icmpkp
->outTimestamps
.value
.ui32
=
13672 ipst
->ips_icmp_mib
.icmpOutTimestamps
;
13673 icmpkp
->outTimestampReps
.value
.ui32
=
13674 ipst
->ips_icmp_mib
.icmpOutTimestampReps
;
13675 icmpkp
->outAddrMasks
.value
.ui32
=
13676 ipst
->ips_icmp_mib
.icmpOutAddrMasks
;
13677 icmpkp
->outAddrMaskReps
.value
.ui32
=
13678 ipst
->ips_icmp_mib
.icmpOutAddrMaskReps
;
13679 icmpkp
->inCksumErrs
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInCksumErrs
;
13680 icmpkp
->inUnknowns
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInUnknowns
;
13681 icmpkp
->inFragNeeded
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInFragNeeded
;
13682 icmpkp
->outFragNeeded
.value
.ui32
=
13683 ipst
->ips_icmp_mib
.icmpOutFragNeeded
;
13684 icmpkp
->outDrops
.value
.ui32
= ipst
->ips_icmp_mib
.icmpOutDrops
;
13685 icmpkp
->inOverflows
.value
.ui32
= ipst
->ips_icmp_mib
.icmpInOverflows
;
13686 icmpkp
->inBadRedirects
.value
.ui32
=
13687 ipst
->ips_icmp_mib
.icmpInBadRedirects
;
13694 * This is the fanout function for raw socket opened for SCTP. Note
13695 * that it is called after SCTP checks that there is no socket which
13696 * wants a packet. Then before SCTP handles this out of the blue packet,
13697 * this function is called to see if there is any raw socket for SCTP.
13698 * If there is and it is bound to the correct address, the packet will
13699 * be sent to that socket. Note that only one raw socket can be bound to
13700 * a port. This is assured in ipcl_sctp_hash_insert();
13703 ip_fanout_sctp_raw(mblk_t
*mp
, ipha_t
*ipha
, ip6_t
*ip6h
, uint32_t ports
,
13704 ip_recv_attr_t
*ira
)
13709 ill_t
*ill
= ira
->ira_ill
;
13710 ip_stack_t
*ipst
= ill
->ill_ipst
;
13711 ipsec_stack_t
*ipss
= ipst
->ips_netstack
->netstack_ipsec
;
13712 sctp_stack_t
*sctps
= ipst
->ips_netstack
->netstack_sctp
;
13713 iaflags_t iraflags
= ira
->ira_flags
;
13714 ill_t
*rill
= ira
->ira_rill
;
13716 secure
= iraflags
& IRAF_IPSEC_SECURE
;
13718 connp
= ipcl_classify_raw(mp
, IPPROTO_SCTP
, ports
, ipha
, ip6h
,
13720 if (connp
== NULL
) {
13722 * Although raw sctp is not summed, OOB chunks must be.
13723 * Drop the packet here if the sctp checksum failed.
13725 if (iraflags
& IRAF_SCTP_CSUM_ERR
) {
13726 SCTPS_BUMP_MIB(sctps
, sctpChecksumError
);
13730 ira
->ira_ill
= ira
->ira_rill
= NULL
;
13731 sctp_ootb_input(mp
, ira
, ipst
);
13732 ira
->ira_ill
= ill
;
13733 ira
->ira_rill
= rill
;
13736 rq
= connp
->conn_rq
;
13737 if (IPCL_IS_NONSTR(connp
) ? connp
->conn_flow_cntrld
: !canputnext(rq
)) {
13738 CONN_DEC_REF(connp
);
13739 BUMP_MIB(ill
->ill_ip_mib
, rawipIfStatsInOverflows
);
13743 if (((iraflags
& IRAF_IS_IPV4
) ?
13744 CONN_INBOUND_POLICY_PRESENT(connp
, ipss
) :
13745 CONN_INBOUND_POLICY_PRESENT_V6(connp
, ipss
)) ||
13747 mp
= ipsec_check_inbound_policy(mp
, connp
, ipha
,
13750 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsInDiscards
);
13751 /* Note that mp is NULL */
13752 ip_drop_input("ipIfStatsInDiscards", mp
, ill
);
13753 CONN_DEC_REF(connp
);
13758 if (iraflags
& IRAF_ICMP_ERROR
) {
13759 (connp
->conn_recvicmp
)(connp
, mp
, NULL
, ira
);
13761 ill_t
*rill
= ira
->ira_rill
;
13763 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCInDelivers
);
13764 /* This is the SOCK_RAW, IPPROTO_SCTP case. */
13765 ira
->ira_ill
= ira
->ira_rill
= NULL
;
13766 (connp
->conn_recv
)(connp
, mp
, NULL
, ira
);
13767 ira
->ira_ill
= ill
;
13768 ira
->ira_rill
= rill
;
13770 CONN_DEC_REF(connp
);
13774 * Free a packet that has the link-layer dl_unitdata_req_t or fast-path
13775 * header before the ip payload.
13778 ip_xmit_flowctl_drop(ill_t
*ill
, mblk_t
*mp
, boolean_t is_fp_mp
, int fp_mp_len
)
13780 int len
= (mp
->b_wptr
- mp
->b_rptr
);
13783 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
13784 if (is_fp_mp
|| len
!= fp_mp_len
) {
13785 if (len
> fp_mp_len
) {
13787 * fastpath header and ip header in the first mblk
13789 mp
->b_rptr
+= fp_mp_len
;
13792 * ip_xmit_attach_llhdr had to prepend an mblk to
13793 * attach the fastpath header before ip header.
13795 ip_mp
= mp
->b_cont
;
13798 mp
->b_rptr
+= (fp_mp_len
- len
);
13801 ip_mp
= mp
->b_cont
;
13805 ip_drop_output("ipIfStatsOutDiscards - flow ctl", mp
, ill
);
13810 * Normal post fragmentation function.
13812 * Send a packet using the passed in nce. This handles both IPv4 and IPv6
13813 * using the same state machine.
13815 * We return an error on failure. In particular we return EWOULDBLOCK
13816 * when the driver flow controls. In that case this ensures that ip_wsrv runs
13817 * (currently by canputnext failure resulting in backenabling from GLD.)
13818 * This allows the callers of conn_ip_output() to use EWOULDBLOCK as an
13819 * indication that they can flow control until ip_wsrv() tells then to restart.
13821 * If the nce passed by caller is incomplete, this function
13822 * queues the packet and if necessary, sends ARP request and bails.
13823 * If the Neighbor Cache passed is fully resolved, we simply prepend
13824 * the link-layer header to the packet, do ipsec hw acceleration
13825 * work if necessary, and send the packet out on the wire.
13829 ip_xmit(mblk_t
*mp
, nce_t
*nce
, iaflags_t ixaflags
, uint_t pkt_len
,
13830 uint32_t xmit_hint
, zoneid_t szone
, zoneid_t nolzid
, uintptr_t *ixacookie
)
13833 ill_t
*ill
= nce
->nce_ill
;
13834 ip_stack_t
*ipst
= ill
->ill_ipst
;
13836 boolean_t isv6
= ill
->ill_isv6
;
13838 ncec_t
*ncec
= nce
->nce_common
;
13839 int64_t now
= LBOLT_FASTPATH64
;
13840 boolean_t is_probe
;
13842 DTRACE_PROBE1(ip__xmit
, nce_t
*, nce
);
13844 ASSERT(mp
!= NULL
);
13845 ASSERT(mp
->b_datap
->db_type
== M_DATA
);
13846 ASSERT(pkt_len
== msgdsize(mp
));
13849 * If we have already been here and are coming back after ARP/ND.
13850 * the IXAF_NO_TRACE flag is set. We skip FW_HOOKS, DTRACE and ipobs
13851 * in that case since they have seen the packet when it came here
13854 if (ixaflags
& IXAF_NO_TRACE
)
13857 if (ixaflags
& IXAF_IS_IPV4
) {
13858 ipha_t
*ipha
= (ipha_t
*)mp
->b_rptr
;
13861 ASSERT(pkt_len
== ntohs(((ipha_t
*)mp
->b_rptr
)->ipha_length
));
13862 if (HOOKS4_INTERESTED_PHYSICAL_OUT(ipst
) &&
13863 !(ixaflags
& IXAF_NO_PFHOOK
)) {
13866 FW_HOOKS(ipst
->ips_ip4_physical_out_event
,
13867 ipst
->ips_ipv4firewall_physical_out
,
13868 NULL
, ill
, ipha
, mp
, mp
, 0, ipst
, error
);
13869 DTRACE_PROBE1(ip4__physical__out__end
,
13874 /* The length could have changed */
13875 pkt_len
= msgdsize(mp
);
13877 if (ipst
->ips_ip4_observe
.he_interested
) {
13879 * Note that for TX the zoneid is the sending
13880 * zone, whether or not MLP is in play.
13881 * Since the szone argument is the IP zoneid (i.e.,
13882 * zero for exclusive-IP zones) and ipobs wants
13883 * the system zoneid, we map it here.
13885 szone
= IP_REAL_ZONEID(szone
, ipst
);
13888 * On the outbound path the destination zone will be
13889 * unknown as we're sending this packet out on the
13892 ipobs_hook(mp
, IPOBS_HOOK_OUTBOUND
, szone
, ALL_ZONES
,
13895 DTRACE_IP7(send
, mblk_t
*, mp
, conn_t
*, NULL
,
13896 void_ip_t
*, ipha
, __dtrace_ipsr_ill_t
*, ill
,
13897 ipha_t
*, ipha
, ip6_t
*, NULL
, int, 0);
13899 ip6_t
*ip6h
= (ip6_t
*)mp
->b_rptr
;
13903 ntohs(((ip6_t
*)mp
->b_rptr
)->ip6_plen
) + IPV6_HDR_LEN
);
13904 if (HOOKS6_INTERESTED_PHYSICAL_OUT(ipst
) &&
13905 !(ixaflags
& IXAF_NO_PFHOOK
)) {
13908 FW_HOOKS6(ipst
->ips_ip6_physical_out_event
,
13909 ipst
->ips_ipv6firewall_physical_out
,
13910 NULL
, ill
, ip6h
, mp
, mp
, 0, ipst
, error
);
13911 DTRACE_PROBE1(ip6__physical__out__end
,
13916 /* The length could have changed */
13917 pkt_len
= msgdsize(mp
);
13919 if (ipst
->ips_ip6_observe
.he_interested
) {
13921 szone
= IP_REAL_ZONEID(szone
, ipst
);
13923 ipobs_hook(mp
, IPOBS_HOOK_OUTBOUND
, szone
, ALL_ZONES
,
13926 DTRACE_IP7(send
, mblk_t
*, mp
, conn_t
*, NULL
,
13927 void_ip_t
*, ip6h
, __dtrace_ipsr_ill_t
*, ill
,
13928 ipha_t
*, NULL
, ip6_t
*, ip6h
, int, 0);
13933 * We check the state without a lock because the state can never
13934 * move "backwards" to initial or incomplete.
13936 switch (ncec
->ncec_state
) {
13941 mp
= ip_xmit_attach_llhdr(mp
, nce
);
13944 * ip_xmit_attach_llhdr has increased
13945 * ipIfStatsOutDiscards and called ip_drop_output()
13950 * check if nce_fastpath completed and we tagged on a
13951 * copy of nce_fp_mp in ip_xmit_attach_llhdr().
13953 fp_mp
= (mp
->b_datap
->db_type
== M_DATA
);
13956 (ill
->ill_capabilities
& ILL_CAPAB_DLD_DIRECT
)) {
13957 ill_dld_direct_t
*idd
;
13959 idd
= &ill
->ill_dld_capab
->idc_direct
;
13961 * Send the packet directly to DLD, where it
13962 * may be queued depending on the availability
13963 * of transmit resources at the media layer.
13964 * Return value should be taken into
13965 * account and flow control the TCP.
13967 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutTransmits
);
13968 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutOctets
,
13971 if (ixaflags
& IXAF_NO_DEV_FLOW_CTL
) {
13972 (void) idd
->idd_tx_df(idd
->idd_tx_dh
, mp
,
13973 (uintptr_t)xmit_hint
, IP_DROP_ON_NO_DESC
);
13977 if ((cookie
= idd
->idd_tx_df(idd
->idd_tx_dh
,
13978 mp
, (uintptr_t)xmit_hint
, 0)) != 0) {
13979 if (ixacookie
!= NULL
)
13980 *ixacookie
= cookie
;
13981 return (EWOULDBLOCK
);
13987 if (!(ixaflags
& IXAF_NO_DEV_FLOW_CTL
) &&
13989 if (ixacookie
!= NULL
)
13991 ip_xmit_flowctl_drop(ill
, mp
, fp_mp
,
13992 nce
->nce_fp_mp
!= NULL
?
13993 MBLKL(nce
->nce_fp_mp
) : 0);
13994 return (EWOULDBLOCK
);
13996 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutTransmits
);
13997 UPDATE_MIB(ill
->ill_ip_mib
, ipIfStatsHCOutOctets
,
14003 * The rest of this function implements Neighbor Unreachability
14004 * detection. Determine if the ncec is eligible for NUD.
14006 if (ncec
->ncec_flags
& NCE_F_NONUD
)
14009 ASSERT(ncec
->ncec_state
!= ND_INCOMPLETE
);
14012 * Check for upper layer advice
14014 if (ixaflags
& IXAF_REACH_CONF
) {
14018 * It should be o.k. to check the state without
14019 * a lock here, at most we lose an advice.
14021 ncec
->ncec_last
= TICK_TO_MSEC(now
);
14022 if (ncec
->ncec_state
!= ND_REACHABLE
) {
14023 mutex_enter(&ncec
->ncec_lock
);
14024 ncec
->ncec_state
= ND_REACHABLE
;
14025 tid
= ncec
->ncec_timeout_id
;
14026 ncec
->ncec_timeout_id
= 0;
14027 mutex_exit(&ncec
->ncec_lock
);
14028 (void) untimeout(tid
);
14029 if (ip_debug
> 2) {
14031 pr_addr_dbg("ip_xmit: state"
14032 " for %s changed to"
14033 " REACHABLE\n", AF_INET6
,
14040 delta
= TICK_TO_MSEC(now
) - ncec
->ncec_last
;
14041 ip1dbg(("ip_xmit: delta = %" PRId64
14042 " ill_reachable_time = %d \n", delta
,
14043 ill
->ill_reachable_time
));
14044 if (delta
> (uint64_t)ill
->ill_reachable_time
) {
14045 mutex_enter(&ncec
->ncec_lock
);
14046 switch (ncec
->ncec_state
) {
14048 ASSERT((ncec
->ncec_flags
& NCE_F_NONUD
) == 0);
14052 * ND_REACHABLE is identical to
14053 * ND_STALE in this specific case. If
14054 * reachable time has expired for this
14055 * neighbor (delta is greater than
14056 * reachable time), conceptually, the
14057 * neighbor cache is no longer in
14058 * REACHABLE state, but already in
14059 * STALE state. So the correct
14060 * transition here is to ND_DELAY.
14062 ncec
->ncec_state
= ND_DELAY
;
14063 mutex_exit(&ncec
->ncec_lock
);
14064 nce_restart_timer(ncec
,
14065 ipst
->ips_delay_first_probe_time
);
14066 if (ip_debug
> 3) {
14068 pr_addr_dbg("ip_xmit: state"
14069 " for %s changed to"
14070 " DELAY\n", AF_INET6
,
14076 mutex_exit(&ncec
->ncec_lock
);
14077 /* Timers have already started */
14079 case ND_UNREACHABLE
:
14081 * nce_timer has detected that this ncec
14082 * is unreachable and initiated deleting
14084 * This is a harmless race where we found the
14085 * ncec before it was deleted and have
14086 * just sent out a packet using this
14087 * unreachable ncec.
14089 mutex_exit(&ncec
->ncec_lock
);
14093 mutex_exit(&ncec
->ncec_lock
);
14098 case ND_INCOMPLETE
:
14100 * the state could have changed since we didn't hold the lock.
14101 * Re-verify state under lock.
14103 is_probe
= ipmp_packet_is_probe(mp
, nce
->nce_ill
);
14104 mutex_enter(&ncec
->ncec_lock
);
14105 if (NCE_ISREACHABLE(ncec
)) {
14106 mutex_exit(&ncec
->ncec_lock
);
14109 /* queue the packet */
14110 nce_queue_mp(ncec
, mp
, is_probe
);
14111 mutex_exit(&ncec
->ncec_lock
);
14112 DTRACE_PROBE2(ip__xmit__incomplete
,
14113 (ncec_t
*), ncec
, (mblk_t
*), mp
);
14118 * State could have changed since we didn't hold the lock, so
14121 is_probe
= ipmp_packet_is_probe(mp
, nce
->nce_ill
);
14122 mutex_enter(&ncec
->ncec_lock
);
14123 if (NCE_ISREACHABLE(ncec
)) {
14124 mutex_exit(&ncec
->ncec_lock
);
14127 nce_queue_mp(ncec
, mp
, is_probe
);
14128 if (ncec
->ncec_state
== ND_INITIAL
) {
14129 ncec
->ncec_state
= ND_INCOMPLETE
;
14130 mutex_exit(&ncec
->ncec_lock
);
14132 * figure out the source we want to use
14135 ip_ndp_resolve(ncec
);
14137 mutex_exit(&ncec
->ncec_lock
);
14141 case ND_UNREACHABLE
:
14142 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
14143 ip_drop_output("ipIfStatsOutDiscards - ND_UNREACHABLE",
14150 BUMP_MIB(ill
->ill_ip_mib
, ipIfStatsOutDiscards
);
14151 ip_drop_output("ipIfStatsOutDiscards - ND_other",
14154 return (ENETUNREACH
);
14159 * Return B_TRUE if the buffers differ in length or content.
14160 * This is used for comparing extension header buffers.
14161 * Note that an extension header would be declared different
14162 * even if all that changed was the next header value in that header i.e.
14163 * what really changed is the next extension header.
14166 ip_cmpbuf(const void *abuf
, uint_t alen
, boolean_t b_valid
, const void *bbuf
,
14175 return (B_FALSE
); /* Both zero length */
14176 return (bcmp(abuf
, bbuf
, alen
));
14180 * Preallocate memory for ip_savebuf(). Returns B_TRUE if ok.
14181 * Return B_FALSE if memory allocation fails - don't change any state!
14184 ip_allocbuf(void **dstp
, uint_t
*dstlenp
, boolean_t src_valid
,
14185 const void *src
, uint_t srclen
)
14192 ASSERT(*dstlenp
== 0);
14193 if (src
!= NULL
&& srclen
!= 0) {
14194 dst
= mi_alloc(srclen
, BPRI_MED
);
14203 *dstlenp
= dst
== NULL
? 0 : srclen
;
14208 * Replace what is in *dst, *dstlen with the source.
14209 * Assumes ip_allocbuf has already been called.
14212 ip_savebuf(void **dstp
, uint_t
*dstlenp
, boolean_t src_valid
,
14213 const void *src
, uint_t srclen
)
14218 ASSERT(*dstlenp
== srclen
);
14219 if (src
!= NULL
&& srclen
!= 0)
14220 bcopy(src
, *dstp
, srclen
);
14224 * Free the storage pointed to by the members of an ip_pkt_t.
14227 ip_pkt_free(ip_pkt_t
*ipp
)
14229 uint_t fields
= ipp
->ipp_fields
;
14231 if (fields
& IPPF_HOPOPTS
) {
14232 kmem_free(ipp
->ipp_hopopts
, ipp
->ipp_hopoptslen
);
14233 ipp
->ipp_hopopts
= NULL
;
14234 ipp
->ipp_hopoptslen
= 0;
14236 if (fields
& IPPF_RTHDRDSTOPTS
) {
14237 kmem_free(ipp
->ipp_rthdrdstopts
, ipp
->ipp_rthdrdstoptslen
);
14238 ipp
->ipp_rthdrdstopts
= NULL
;
14239 ipp
->ipp_rthdrdstoptslen
= 0;
14241 if (fields
& IPPF_DSTOPTS
) {
14242 kmem_free(ipp
->ipp_dstopts
, ipp
->ipp_dstoptslen
);
14243 ipp
->ipp_dstopts
= NULL
;
14244 ipp
->ipp_dstoptslen
= 0;
14246 if (fields
& IPPF_RTHDR
) {
14247 kmem_free(ipp
->ipp_rthdr
, ipp
->ipp_rthdrlen
);
14248 ipp
->ipp_rthdr
= NULL
;
14249 ipp
->ipp_rthdrlen
= 0;
14251 if (fields
& IPPF_IPV4_OPTIONS
) {
14252 kmem_free(ipp
->ipp_ipv4_options
, ipp
->ipp_ipv4_options_len
);
14253 ipp
->ipp_ipv4_options
= NULL
;
14254 ipp
->ipp_ipv4_options_len
= 0;
14256 ipp
->ipp_fields
&= ~(IPPF_HOPOPTS
| IPPF_RTHDRDSTOPTS
| IPPF_DSTOPTS
|
14257 IPPF_RTHDR
| IPPF_IPV4_OPTIONS
);
14261 * Copy from src to dst and allocate as needed.
14262 * Returns zero or ENOMEM.
14264 * The caller must initialize dst to zero.
14267 ip_pkt_copy(ip_pkt_t
*src
, ip_pkt_t
*dst
, int kmflag
)
14269 uint_t fields
= src
->ipp_fields
;
14271 /* Start with fields that don't require memory allocation */
14272 dst
->ipp_fields
= fields
&
14273 ~(IPPF_HOPOPTS
| IPPF_RTHDRDSTOPTS
| IPPF_DSTOPTS
|
14274 IPPF_RTHDR
| IPPF_IPV4_OPTIONS
);
14276 dst
->ipp_addr
= src
->ipp_addr
;
14277 dst
->ipp_unicast_hops
= src
->ipp_unicast_hops
;
14278 dst
->ipp_hoplimit
= src
->ipp_hoplimit
;
14279 dst
->ipp_tclass
= src
->ipp_tclass
;
14280 dst
->ipp_type_of_service
= src
->ipp_type_of_service
;
14282 if (!(fields
& (IPPF_HOPOPTS
| IPPF_RTHDRDSTOPTS
| IPPF_DSTOPTS
|
14283 IPPF_RTHDR
| IPPF_IPV4_OPTIONS
)))
14286 if (fields
& IPPF_HOPOPTS
) {
14287 dst
->ipp_hopopts
= kmem_alloc(src
->ipp_hopoptslen
, kmflag
);
14288 if (dst
->ipp_hopopts
== NULL
) {
14292 dst
->ipp_fields
|= IPPF_HOPOPTS
;
14293 bcopy(src
->ipp_hopopts
, dst
->ipp_hopopts
,
14294 src
->ipp_hopoptslen
);
14295 dst
->ipp_hopoptslen
= src
->ipp_hopoptslen
;
14297 if (fields
& IPPF_RTHDRDSTOPTS
) {
14298 dst
->ipp_rthdrdstopts
= kmem_alloc(src
->ipp_rthdrdstoptslen
,
14300 if (dst
->ipp_rthdrdstopts
== NULL
) {
14304 dst
->ipp_fields
|= IPPF_RTHDRDSTOPTS
;
14305 bcopy(src
->ipp_rthdrdstopts
, dst
->ipp_rthdrdstopts
,
14306 src
->ipp_rthdrdstoptslen
);
14307 dst
->ipp_rthdrdstoptslen
= src
->ipp_rthdrdstoptslen
;
14309 if (fields
& IPPF_DSTOPTS
) {
14310 dst
->ipp_dstopts
= kmem_alloc(src
->ipp_dstoptslen
, kmflag
);
14311 if (dst
->ipp_dstopts
== NULL
) {
14315 dst
->ipp_fields
|= IPPF_DSTOPTS
;
14316 bcopy(src
->ipp_dstopts
, dst
->ipp_dstopts
,
14317 src
->ipp_dstoptslen
);
14318 dst
->ipp_dstoptslen
= src
->ipp_dstoptslen
;
14320 if (fields
& IPPF_RTHDR
) {
14321 dst
->ipp_rthdr
= kmem_alloc(src
->ipp_rthdrlen
, kmflag
);
14322 if (dst
->ipp_rthdr
== NULL
) {
14326 dst
->ipp_fields
|= IPPF_RTHDR
;
14327 bcopy(src
->ipp_rthdr
, dst
->ipp_rthdr
,
14328 src
->ipp_rthdrlen
);
14329 dst
->ipp_rthdrlen
= src
->ipp_rthdrlen
;
14331 if (fields
& IPPF_IPV4_OPTIONS
) {
14332 dst
->ipp_ipv4_options
= kmem_alloc(src
->ipp_ipv4_options_len
,
14334 if (dst
->ipp_ipv4_options
== NULL
) {
14338 dst
->ipp_fields
|= IPPF_IPV4_OPTIONS
;
14339 bcopy(src
->ipp_ipv4_options
, dst
->ipp_ipv4_options
,
14340 src
->ipp_ipv4_options_len
);
14341 dst
->ipp_ipv4_options_len
= src
->ipp_ipv4_options_len
;
14343 if (fields
& IPPF_FRAGHDR
) {
14344 dst
->ipp_fraghdr
= kmem_alloc(src
->ipp_fraghdrlen
, kmflag
);
14345 if (dst
->ipp_fraghdr
== NULL
) {
14349 dst
->ipp_fields
|= IPPF_FRAGHDR
;
14350 bcopy(src
->ipp_fraghdr
, dst
->ipp_fraghdr
,
14351 src
->ipp_fraghdrlen
);
14352 dst
->ipp_fraghdrlen
= src
->ipp_fraghdrlen
;
14358 * Returns INADDR_ANY if no source route
14361 ip_pkt_source_route_v4(const ip_pkt_t
*ipp
)
14363 ipaddr_t nexthop
= INADDR_ANY
;
14370 if (!(ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
))
14371 return (INADDR_ANY
);
14373 totallen
= ipp
->ipp_ipv4_options_len
;
14374 if (totallen
& 0x3)
14375 return (INADDR_ANY
);
14377 for (optval
= ipoptp_first2(&opts
, totallen
, ipp
->ipp_ipv4_options
);
14378 optval
!= IPOPT_EOL
;
14379 optval
= ipoptp_next(&opts
)) {
14380 opt
= opts
.ipoptp_cur
;
14385 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
14388 optlen
= opts
.ipoptp_len
;
14389 off
= opt
[IPOPT_OFFSET
];
14391 if (optlen
< IP_ADDR_LEN
||
14392 off
> optlen
- IP_ADDR_LEN
) {
14393 /* End of source route */
14396 bcopy((char *)opt
+ off
, &nexthop
, IP_ADDR_LEN
);
14397 if (nexthop
== htonl(INADDR_LOOPBACK
)) {
14399 nexthop
= INADDR_ANY
;
14409 * Reverse a source route.
14412 ip_pkt_source_route_reverse_v4(ip_pkt_t
*ipp
)
14420 if (!(ipp
->ipp_fields
& IPPF_IPV4_OPTIONS
))
14423 totallen
= ipp
->ipp_ipv4_options_len
;
14424 if (totallen
& 0x3)
14427 for (optval
= ipoptp_first2(&opts
, totallen
, ipp
->ipp_ipv4_options
);
14428 optval
!= IPOPT_EOL
;
14429 optval
= ipoptp_next(&opts
)) {
14430 uint8_t off1
, off2
;
14432 opt
= opts
.ipoptp_cur
;
14436 if ((opts
.ipoptp_flags
& IPOPTP_ERROR
) != 0) {
14439 off1
= IPOPT_MINOFF_SR
- 1;
14440 off2
= opt
[IPOPT_OFFSET
] - IP_ADDR_LEN
- 1;
14441 while (off2
> off1
) {
14442 bcopy(opt
+ off2
, &tmp
, IP_ADDR_LEN
);
14443 bcopy(opt
+ off1
, opt
+ off2
, IP_ADDR_LEN
);
14444 bcopy(&tmp
, opt
+ off2
, IP_ADDR_LEN
);
14445 off2
-= IP_ADDR_LEN
;
14446 off1
+= IP_ADDR_LEN
;
14448 opt
[IPOPT_OFFSET
] = IPOPT_MINOFF_SR
;
14455 * Returns NULL if no routing header
14458 ip_pkt_source_route_v6(const ip_pkt_t
*ipp
)
14460 in6_addr_t
*nexthop
= NULL
;
14461 ip6_rthdr0_t
*rthdr
;
14463 if (!(ipp
->ipp_fields
& IPPF_RTHDR
))
14466 rthdr
= (ip6_rthdr0_t
*)ipp
->ipp_rthdr
;
14467 if (rthdr
->ip6r0_segleft
== 0)
14470 nexthop
= (in6_addr_t
*)((char *)rthdr
+ sizeof (*rthdr
));
14475 ip_get_zoneid_v4(ipaddr_t addr
, mblk_t
*mp
, ip_recv_attr_t
*ira
,
14476 zoneid_t lookup_zoneid
)
14478 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
14480 int ire_flags
= MATCH_IRE_TYPE
;
14481 zoneid_t zoneid
= ALL_ZONES
;
14483 if (lookup_zoneid
!= ALL_ZONES
)
14484 ire_flags
|= MATCH_IRE_ZONEONLY
;
14485 ire
= ire_ftable_lookup_v4(addr
, 0, 0, IRE_LOCAL
| IRE_LOOPBACK
,
14486 NULL
, lookup_zoneid
, ire_flags
, 0, ipst
, NULL
);
14488 zoneid
= IP_REAL_ZONEID(ire
->ire_zoneid
, ipst
);
14495 ip_get_zoneid_v6(in6_addr_t
*addr
, mblk_t
*mp
, const ill_t
*ill
,
14496 ip_recv_attr_t
*ira
, zoneid_t lookup_zoneid
)
14498 ip_stack_t
*ipst
= ira
->ira_ill
->ill_ipst
;
14500 int ire_flags
= MATCH_IRE_TYPE
;
14501 zoneid_t zoneid
= ALL_ZONES
;
14503 if (IN6_IS_ADDR_LINKLOCAL(addr
))
14504 ire_flags
|= MATCH_IRE_ILL
;
14506 if (lookup_zoneid
!= ALL_ZONES
)
14507 ire_flags
|= MATCH_IRE_ZONEONLY
;
14508 ire
= ire_ftable_lookup_v6(addr
, NULL
, NULL
, IRE_LOCAL
| IRE_LOOPBACK
,
14509 ill
, lookup_zoneid
, ire_flags
, 0, ipst
, NULL
);
14511 zoneid
= IP_REAL_ZONEID(ire
->ire_zoneid
, ipst
);
14518 * IP obserability hook support functions.
14521 ipobs_init(ip_stack_t
*ipst
)
14525 id
= net_getnetidbynetstackid(ipst
->ips_netstack
->netstack_stackid
);
14527 ipst
->ips_ip4_observe_pr
= net_protocol_lookup(id
, NHF_INET
);
14528 VERIFY(ipst
->ips_ip4_observe_pr
!= NULL
);
14530 ipst
->ips_ip6_observe_pr
= net_protocol_lookup(id
, NHF_INET6
);
14531 VERIFY(ipst
->ips_ip6_observe_pr
!= NULL
);
14535 ipobs_fini(ip_stack_t
*ipst
)
14538 VERIFY(net_protocol_release(ipst
->ips_ip4_observe_pr
) == 0);
14539 VERIFY(net_protocol_release(ipst
->ips_ip6_observe_pr
) == 0);
14543 * hook_pkt_observe_t is composed in network byte order so that the
14544 * entire mblk_t chain handed into hook_run can be used as-is.
14545 * The caveat is that use of the fields, such as the zone fields,
14546 * requires conversion into host byte order first.
14549 ipobs_hook(mblk_t
*mp
, int htype
, zoneid_t zsrc
, zoneid_t zdst
,
14550 const ill_t
*ill
, ip_stack_t
*ipst
)
14552 hook_pkt_observe_t
*hdr
;
14553 uint64_t grifindex
;
14556 imp
= allocb(sizeof (*hdr
), BPRI_HI
);
14560 hdr
= (hook_pkt_observe_t
*)imp
->b_rptr
;
14562 * b_wptr is set to make the apparent size of the data in the mblk_t
14563 * to exclude the pointers at the end of hook_pkt_observer_t.
14565 imp
->b_wptr
= imp
->b_rptr
+ sizeof (dl_ipnetinfo_t
);
14568 ASSERT(DB_TYPE(mp
) == M_DATA
);
14570 if (IS_UNDER_IPMP(ill
))
14571 grifindex
= ipmp_ill_get_ipmp_ifindex(ill
);
14575 hdr
->hpo_version
= 1;
14576 hdr
->hpo_htype
= htons(htype
);
14577 hdr
->hpo_pktlen
= htonl((ulong_t
)msgdsize(mp
));
14578 hdr
->hpo_ifindex
= htonl(ill
->ill_phyint
->phyint_ifindex
);
14579 hdr
->hpo_grifindex
= htonl(grifindex
);
14580 hdr
->hpo_zsrc
= htonl(zsrc
);
14581 hdr
->hpo_zdst
= htonl(zdst
);
14582 hdr
->hpo_pkt
= imp
;
14583 hdr
->hpo_ctx
= ipst
->ips_netstack
;
14585 if (ill
->ill_isv6
) {
14586 hdr
->hpo_family
= AF_INET6
;
14587 (void) hook_run(ipst
->ips_ipv6_net_data
->netd_hooks
,
14588 ipst
->ips_ipv6observing
, (hook_data_t
)hdr
);
14590 hdr
->hpo_family
= AF_INET
;
14591 (void) hook_run(ipst
->ips_ipv4_net_data
->netd_hooks
,
14592 ipst
->ips_ipv4observing
, (hook_data_t
)hdr
);
14595 imp
->b_cont
= NULL
;
14600 * Utility routine that checks if `v4srcp' is a valid address on underlying
14601 * interface `ill'. If `ipifp' is non-NULL, it's set to a held ipif
14602 * associated with `v4srcp' on success. NOTE: if this is not called from
14603 * inside the IPSQ (ill_g_lock is not held), `ill' may be removed from the
14604 * group during or after this lookup.
14607 ipif_lookup_testaddr_v4(ill_t
*ill
, const in_addr_t
*v4srcp
, ipif_t
**ipifp
)
14611 ipif
= ipif_lookup_addr_exact(*v4srcp
, ill
, ill
->ill_ipst
);
14612 if (ipif
!= NULL
) {
14616 ipif_refrele(ipif
);
14620 ip1dbg(("ipif_lookup_testaddr_v4: cannot find ipif for src %x\n",
14626 * Transport protocol call back function for CPU state change.
14630 ip_tp_cpu_update(cpu_setup_t what
, int id
, void *arg
)
14632 processorid_t cpu_seqid
;
14633 netstack_handle_t nh
;
14636 ASSERT(MUTEX_HELD(&cpu_lock
));
14642 case CPU_CPUPART_IN
:
14643 cpu_seqid
= cpu
[id
]->cpu_seqid
;
14644 netstack_next_init(&nh
);
14645 while ((ns
= netstack_next(&nh
)) != NULL
) {
14646 tcp_stack_cpu_add(ns
->netstack_tcp
, cpu_seqid
);
14647 sctp_stack_cpu_add(ns
->netstack_sctp
, cpu_seqid
);
14648 udp_stack_cpu_add(ns
->netstack_udp
, cpu_seqid
);
14651 netstack_next_fini(&nh
);
14655 case CPU_CPUPART_OUT
:
14657 * Nothing to do. We don't remove the per CPU stats from
14658 * the IP stack even when the CPU goes offline.