xref: /titanic_51/usr/src/uts/common/inet/ip.h (revision 67dbe2be0c0f1e2eb428b89088bb5667e8f0b9f6)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /* Copyright (c) 1990 Mentat Inc. */
27 
28 #ifndef	_INET_IP_H
29 #define	_INET_IP_H
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/isa_defs.h>
36 #include <sys/types.h>
37 #include <inet/mib2.h>
38 #include <inet/nd.h>
39 #include <sys/atomic.h>
40 #include <net/if_dl.h>
41 #include <net/if.h>
42 #include <netinet/ip.h>
43 #include <netinet/igmp.h>
44 #include <sys/neti.h>
45 #include <sys/hook.h>
46 #include <sys/hook_event.h>
47 #include <sys/hook_impl.h>
48 #include <inet/ip_stack.h>
49 
50 #ifdef _KERNEL
51 #include <netinet/ip6.h>
52 #include <sys/avl.h>
53 #include <sys/list.h>
54 #include <sys/vmem.h>
55 #include <sys/squeue.h>
56 #include <net/route.h>
57 #include <sys/systm.h>
58 #include <net/radix.h>
59 #include <sys/modhash.h>
60 
61 #ifdef DEBUG
62 #define	CONN_DEBUG
63 #endif
64 
65 #define	IP_DEBUG
66 /*
67  * The mt-streams(9F) flags for the IP module; put here so that other
68  * "drivers" that are actually IP (e.g., ICMP, UDP) can use the same set
69  * of flags.
70  */
71 #define	IP_DEVMTFLAGS D_MP
72 #endif	/* _KERNEL */
73 
74 #define	IP_MOD_NAME	"ip"
75 #define	IP_DEV_NAME	"/dev/ip"
76 #define	IP6_DEV_NAME	"/dev/ip6"
77 
78 #define	UDP_MOD_NAME	"udp"
79 #define	UDP_DEV_NAME	"/dev/udp"
80 #define	UDP6_DEV_NAME	"/dev/udp6"
81 
82 #define	TCP_MOD_NAME	"tcp"
83 #define	TCP_DEV_NAME	"/dev/tcp"
84 #define	TCP6_DEV_NAME	"/dev/tcp6"
85 
86 #define	SCTP_MOD_NAME	"sctp"
87 
88 #ifndef	_IPADDR_T
89 #define	_IPADDR_T
90 typedef uint32_t ipaddr_t;
91 #endif
92 
93 /* Number of bits in an address */
94 #define	IP_ABITS		32
95 #define	IPV4_ABITS		IP_ABITS
96 #define	IPV6_ABITS		128
97 
98 #define	IP_HOST_MASK		(ipaddr_t)0xffffffffU
99 
100 #define	IP_CSUM(mp, off, sum)		(~ip_cksum(mp, off, sum) & 0xFFFF)
101 #define	IP_CSUM_PARTIAL(mp, off, sum)	ip_cksum(mp, off, sum)
102 #define	IP_BCSUM_PARTIAL(bp, len, sum)	bcksum(bp, len, sum)
103 
104 #define	ILL_FRAG_HASH_TBL_COUNT	((unsigned int)64)
105 #define	ILL_FRAG_HASH_TBL_SIZE	(ILL_FRAG_HASH_TBL_COUNT * sizeof (ipfb_t))
106 
107 #define	IPV4_ADDR_LEN			4
108 #define	IP_ADDR_LEN			IPV4_ADDR_LEN
109 #define	IP_ARP_PROTO_TYPE		0x0800
110 
111 #define	IPV4_VERSION			4
112 #define	IP_VERSION			IPV4_VERSION
113 #define	IP_SIMPLE_HDR_LENGTH_IN_WORDS	5
114 #define	IP_SIMPLE_HDR_LENGTH		20
115 #define	IP_MAX_HDR_LENGTH		60
116 
117 #define	IP_MAX_OPT_LENGTH (IP_MAX_HDR_LENGTH-IP_SIMPLE_HDR_LENGTH)
118 
119 #define	IP_MIN_MTU			(IP_MAX_HDR_LENGTH + 8)	/* 68 bytes */
120 
121 /*
122  * XXX IP_MAXPACKET is defined in <netinet/ip.h> as well. At some point the
123  * 2 files should be cleaned up to remove all redundant definitions.
124  */
125 #define	IP_MAXPACKET			65535
126 #define	IP_SIMPLE_HDR_VERSION \
127 	((IP_VERSION << 4) | IP_SIMPLE_HDR_LENGTH_IN_WORDS)
128 
129 #define	UDPH_SIZE			8
130 
131 /*
132  * Constants and type definitions to support IP IOCTL commands
133  */
134 #define	IP_IOCTL			(('i'<<8)|'p')
135 #define	IP_IOC_IRE_DELETE		4
136 #define	IP_IOC_IRE_DELETE_NO_REPLY	5
137 #define	IP_IOC_RTS_REQUEST		7
138 
139 /* Common definitions used by IP IOCTL data structures */
140 typedef struct ipllcmd_s {
141 	uint_t	ipllc_cmd;
142 	uint_t	ipllc_name_offset;
143 	uint_t	ipllc_name_length;
144 } ipllc_t;
145 
146 /* IP IRE Delete Command Structure. */
147 typedef struct ipid_s {
148 	ipllc_t	ipid_ipllc;
149 	uint_t	ipid_ire_type;
150 	uint_t	ipid_addr_offset;
151 	uint_t	ipid_addr_length;
152 	uint_t	ipid_mask_offset;
153 	uint_t	ipid_mask_length;
154 } ipid_t;
155 
156 #define	ipid_cmd		ipid_ipllc.ipllc_cmd
157 
158 #ifdef _KERNEL
159 /*
160  * Temporary state for ip options parser.
161  */
162 typedef struct ipoptp_s
163 {
164 	uint8_t		*ipoptp_next;	/* next option to look at */
165 	uint8_t		*ipoptp_end;	/* end of options */
166 	uint8_t		*ipoptp_cur;	/* start of current option */
167 	uint8_t		ipoptp_len;	/* length of current option */
168 	uint32_t	ipoptp_flags;
169 } ipoptp_t;
170 
171 /*
172  * Flag(s) for ipoptp_flags
173  */
174 #define	IPOPTP_ERROR	0x00000001
175 #endif	/* _KERNEL */
176 
177 /* Controls forwarding of IP packets, set via ndd */
178 #define	IP_FORWARD_NEVER	0
179 #define	IP_FORWARD_ALWAYS	1
180 
181 #define	WE_ARE_FORWARDING(ipst)	((ipst)->ips_ip_g_forward == IP_FORWARD_ALWAYS)
182 
183 #define	IPH_HDR_LENGTH(ipha)						\
184 	((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length & 0xF) << 2)
185 
186 #define	IPH_HDR_VERSION(ipha)						\
187 	((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length) >> 4)
188 
189 #ifdef _KERNEL
190 /*
191  * IP reassembly macros.  We hide starting and ending offsets in b_next and
192  * b_prev of messages on the reassembly queue.	The messages are chained using
193  * b_cont.  These macros are used in ip_reassemble() so we don't have to see
194  * the ugly casts and assignments.
195  * Note that the offsets are <= 64k i.e. a uint_t is sufficient to represent
196  * them.
197  */
198 #define	IP_REASS_START(mp)		((uint_t)(uintptr_t)((mp)->b_next))
199 #define	IP_REASS_SET_START(mp, u)	\
200 	((mp)->b_next = (mblk_t *)(uintptr_t)(u))
201 #define	IP_REASS_END(mp)		((uint_t)(uintptr_t)((mp)->b_prev))
202 #define	IP_REASS_SET_END(mp, u)		\
203 	((mp)->b_prev = (mblk_t *)(uintptr_t)(u))
204 
205 #define	IP_REASS_COMPLETE	0x1
206 #define	IP_REASS_PARTIAL	0x2
207 #define	IP_REASS_FAILED		0x4
208 
209 /*
210  * Test to determine whether this is a module instance of IP or a
211  * driver instance of IP.
212  */
213 #define	CONN_Q(q)	(WR(q)->q_next == NULL)
214 
215 #define	Q_TO_CONN(q)	((conn_t *)(q)->q_ptr)
216 #define	Q_TO_TCP(q)	(Q_TO_CONN((q))->conn_tcp)
217 #define	Q_TO_UDP(q)	(Q_TO_CONN((q))->conn_udp)
218 #define	Q_TO_ICMP(q)	(Q_TO_CONN((q))->conn_icmp)
219 #define	Q_TO_RTS(q)	(Q_TO_CONN((q))->conn_rts)
220 
221 #define	CONNP_TO_WQ(connp)	((connp)->conn_wq)
222 #define	CONNP_TO_RQ(connp)	((connp)->conn_rq)
223 
224 #define	GRAB_CONN_LOCK(q)	{				\
225 	if (q != NULL && CONN_Q(q))				\
226 		mutex_enter(&(Q_TO_CONN(q))->conn_lock);	\
227 }
228 
229 #define	RELEASE_CONN_LOCK(q)	{				\
230 	if (q != NULL && CONN_Q(q))				\
231 		mutex_exit(&(Q_TO_CONN(q))->conn_lock);		\
232 }
233 
234 /*
235  * Complete the pending operation. Usually an ioctl. Can also
236  * be a bind or option management request that got enqueued
237  * in an ipsq_t. Called on completion of the operation.
238  */
239 #define	CONN_OPER_PENDING_DONE(connp)	{			\
240 	mutex_enter(&(connp)->conn_lock);			\
241 	(connp)->conn_oper_pending_ill = NULL;			\
242 	cv_broadcast(&(connp)->conn_refcv);			\
243 	mutex_exit(&(connp)->conn_lock);			\
244 	CONN_DEC_REF(connp);					\
245 }
246 
247 /*
248  * Values for squeue switch:
249  */
250 #define	IP_SQUEUE_ENTER_NODRAIN	1
251 #define	IP_SQUEUE_ENTER	2
252 #define	IP_SQUEUE_FILL 3
253 
254 extern int ip_squeue_flag;
255 
256 /* IP Fragmentation Reassembly Header */
257 typedef struct ipf_s {
258 	struct ipf_s	*ipf_hash_next;
259 	struct ipf_s	**ipf_ptphn;	/* Pointer to previous hash next. */
260 	uint32_t	ipf_ident;	/* Ident to match. */
261 	uint8_t		ipf_protocol;	/* Protocol to match. */
262 	uchar_t		ipf_last_frag_seen : 1;	/* Last fragment seen ? */
263 	time_t		ipf_timestamp;	/* Reassembly start time. */
264 	mblk_t		*ipf_mp;	/* mblk we live in. */
265 	mblk_t		*ipf_tail_mp;	/* Frag queue tail pointer. */
266 	int		ipf_hole_cnt;	/* Number of holes (hard-case). */
267 	int		ipf_end;	/* Tail end offset (0 -> hard-case). */
268 	uint_t		ipf_gen;	/* Frag queue generation */
269 	size_t		ipf_count;	/* Count of bytes used by frag */
270 	uint_t		ipf_nf_hdr_len; /* Length of nonfragmented header */
271 	in6_addr_t	ipf_v6src;	/* IPv6 source address */
272 	in6_addr_t	ipf_v6dst;	/* IPv6 dest address */
273 	uint_t		ipf_prev_nexthdr_offset; /* Offset for nexthdr value */
274 	uint8_t		ipf_ecn;	/* ECN info for the fragments */
275 	uint8_t		ipf_num_dups;	/* Number of times dup frags recvd */
276 	uint16_t	ipf_checksum_flags; /* Hardware checksum flags */
277 	uint32_t	ipf_checksum;	/* Partial checksum of fragment data */
278 } ipf_t;
279 
280 /*
281  * IPv4 Fragments
282  */
283 #define	IS_V4_FRAGMENT(ipha_fragment_offset_and_flags)			\
284 	(((ntohs(ipha_fragment_offset_and_flags) & IPH_OFFSET) != 0) ||	\
285 	((ntohs(ipha_fragment_offset_and_flags) & IPH_MF) != 0))
286 
287 #define	ipf_src	V4_PART_OF_V6(ipf_v6src)
288 #define	ipf_dst	V4_PART_OF_V6(ipf_v6dst)
289 
290 #endif /* _KERNEL */
291 
292 /* ICMP types */
293 #define	ICMP_ECHO_REPLY			0
294 #define	ICMP_DEST_UNREACHABLE		3
295 #define	ICMP_SOURCE_QUENCH		4
296 #define	ICMP_REDIRECT			5
297 #define	ICMP_ECHO_REQUEST		8
298 #define	ICMP_ROUTER_ADVERTISEMENT	9
299 #define	ICMP_ROUTER_SOLICITATION	10
300 #define	ICMP_TIME_EXCEEDED		11
301 #define	ICMP_PARAM_PROBLEM		12
302 #define	ICMP_TIME_STAMP_REQUEST		13
303 #define	ICMP_TIME_STAMP_REPLY		14
304 #define	ICMP_INFO_REQUEST		15
305 #define	ICMP_INFO_REPLY			16
306 #define	ICMP_ADDRESS_MASK_REQUEST	17
307 #define	ICMP_ADDRESS_MASK_REPLY		18
308 
309 /* Evaluates to true if the ICMP type is an ICMP error */
310 #define	ICMP_IS_ERROR(type)	(		\
311 	(type) == ICMP_DEST_UNREACHABLE ||	\
312 	(type) == ICMP_SOURCE_QUENCH ||		\
313 	(type) == ICMP_TIME_EXCEEDED ||		\
314 	(type) == ICMP_PARAM_PROBLEM)
315 
316 /* ICMP_TIME_EXCEEDED codes */
317 #define	ICMP_TTL_EXCEEDED		0
318 #define	ICMP_REASSEMBLY_TIME_EXCEEDED	1
319 
320 /* ICMP_DEST_UNREACHABLE codes */
321 #define	ICMP_NET_UNREACHABLE		0
322 #define	ICMP_HOST_UNREACHABLE		1
323 #define	ICMP_PROTOCOL_UNREACHABLE	2
324 #define	ICMP_PORT_UNREACHABLE		3
325 #define	ICMP_FRAGMENTATION_NEEDED	4
326 #define	ICMP_SOURCE_ROUTE_FAILED	5
327 #define	ICMP_DEST_NET_UNKNOWN		6
328 #define	ICMP_DEST_HOST_UNKNOWN		7
329 #define	ICMP_SRC_HOST_ISOLATED		8
330 #define	ICMP_DEST_NET_UNREACH_ADMIN	9
331 #define	ICMP_DEST_HOST_UNREACH_ADMIN	10
332 #define	ICMP_DEST_NET_UNREACH_TOS	11
333 #define	ICMP_DEST_HOST_UNREACH_TOS	12
334 
335 /* ICMP Header Structure */
336 typedef struct icmph_s {
337 	uint8_t		icmph_type;
338 	uint8_t		icmph_code;
339 	uint16_t	icmph_checksum;
340 	union {
341 		struct { /* ECHO request/response structure */
342 			uint16_t	u_echo_ident;
343 			uint16_t	u_echo_seqnum;
344 		} u_echo;
345 		struct { /* Destination unreachable structure */
346 			uint16_t	u_du_zero;
347 			uint16_t	u_du_mtu;
348 		} u_du;
349 		struct { /* Parameter problem structure */
350 			uint8_t		u_pp_ptr;
351 			uint8_t		u_pp_rsvd[3];
352 		} u_pp;
353 		struct { /* Redirect structure */
354 			ipaddr_t	u_rd_gateway;
355 		} u_rd;
356 	} icmph_u;
357 } icmph_t;
358 
359 #define	icmph_echo_ident	icmph_u.u_echo.u_echo_ident
360 #define	icmph_echo_seqnum	icmph_u.u_echo.u_echo_seqnum
361 #define	icmph_du_zero		icmph_u.u_du.u_du_zero
362 #define	icmph_du_mtu		icmph_u.u_du.u_du_mtu
363 #define	icmph_pp_ptr		icmph_u.u_pp.u_pp_ptr
364 #define	icmph_rd_gateway	icmph_u.u_rd.u_rd_gateway
365 
366 #define	ICMPH_SIZE	8
367 
368 /*
369  * Minimum length of transport layer header included in an ICMP error
370  * message for it to be considered valid.
371  */
372 #define	ICMP_MIN_TP_HDR_LEN	8
373 
374 /* Aligned IP header */
375 typedef struct ipha_s {
376 	uint8_t		ipha_version_and_hdr_length;
377 	uint8_t		ipha_type_of_service;
378 	uint16_t	ipha_length;
379 	uint16_t	ipha_ident;
380 	uint16_t	ipha_fragment_offset_and_flags;
381 	uint8_t		ipha_ttl;
382 	uint8_t		ipha_protocol;
383 	uint16_t	ipha_hdr_checksum;
384 	ipaddr_t	ipha_src;
385 	ipaddr_t	ipha_dst;
386 } ipha_t;
387 
388 /*
389  * IP Flags
390  *
391  * Some of these constant names are copied for the DTrace IP provider in
392  * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
393  * in sync.
394  */
395 #define	IPH_DF		0x4000	/* Don't fragment */
396 #define	IPH_MF		0x2000	/* More fragments to come */
397 #define	IPH_OFFSET	0x1FFF	/* Where the offset lives */
398 
399 /* Byte-order specific values */
400 #ifdef	_BIG_ENDIAN
401 #define	IPH_DF_HTONS	0x4000	/* Don't fragment */
402 #define	IPH_MF_HTONS	0x2000	/* More fragments to come */
403 #define	IPH_OFFSET_HTONS 0x1FFF	/* Where the offset lives */
404 #else
405 #define	IPH_DF_HTONS	0x0040	/* Don't fragment */
406 #define	IPH_MF_HTONS	0x0020	/* More fragments to come */
407 #define	IPH_OFFSET_HTONS 0xFF1F	/* Where the offset lives */
408 #endif
409 
410 /* ECN code points for IPv4 TOS byte and IPv6 traffic class octet. */
411 #define	IPH_ECN_NECT	0x0	/* Not ECN-Capable Transport */
412 #define	IPH_ECN_ECT1	0x1	/* ECN-Capable Transport, ECT(1) */
413 #define	IPH_ECN_ECT0	0x2	/* ECN-Capable Transport, ECT(0) */
414 #define	IPH_ECN_CE	0x3	/* ECN-Congestion Experienced (CE) */
415 
416 struct ill_s;
417 
418 typedef	void ip_v6intfid_func_t(struct ill_s *, in6_addr_t *);
419 typedef void ip_v6mapinfo_func_t(struct ill_s *, uchar_t *, uchar_t *);
420 typedef void ip_v4mapinfo_func_t(struct ill_s *, uchar_t *, uchar_t *);
421 
422 /* IP Mac info structure */
423 typedef struct ip_m_s {
424 	t_uscalar_t		ip_m_mac_type;	/* From <sys/dlpi.h> */
425 	int			ip_m_type;	/* From <net/if_types.h> */
426 	t_uscalar_t		ip_m_ipv4sap;
427 	t_uscalar_t		ip_m_ipv6sap;
428 	ip_v4mapinfo_func_t	*ip_m_v4mapping;
429 	ip_v6mapinfo_func_t	*ip_m_v6mapping;
430 	ip_v6intfid_func_t	*ip_m_v6intfid;
431 	ip_v6intfid_func_t	*ip_m_v6destintfid;
432 } ip_m_t;
433 
434 /*
435  * The following functions attempt to reduce the link layer dependency
436  * of the IP stack. The current set of link specific operations are:
437  * a. map from IPv4 class D (224.0/4) multicast address range or the
438  * IPv6 multicast address range (ff00::/8) to the link layer multicast
439  * address.
440  * b. derive the default IPv6 interface identifier from the interface.
441  * c. derive the default IPv6 destination interface identifier from
442  * the interface (point-to-point only).
443  */
444 extern	void ip_mcast_mapping(struct ill_s *, uchar_t *, uchar_t *);
445 /* ip_m_v6*intfid return void and are never NULL */
446 #define	MEDIA_V6INTFID(ip_m, ill, v6ptr) (ip_m)->ip_m_v6intfid(ill, v6ptr)
447 #define	MEDIA_V6DESTINTFID(ip_m, ill, v6ptr) \
448 	(ip_m)->ip_m_v6destintfid(ill, v6ptr)
449 
450 /* Router entry types */
451 #define	IRE_BROADCAST		0x0001	/* Route entry for broadcast address */
452 #define	IRE_DEFAULT		0x0002	/* Route entry for default gateway */
453 #define	IRE_LOCAL		0x0004	/* Route entry for local address */
454 #define	IRE_LOOPBACK		0x0008	/* Route entry for loopback address */
455 #define	IRE_PREFIX		0x0010	/* Route entry for prefix routes */
456 #ifndef _KERNEL
457 /* Keep so user-level still compiles */
458 #define	IRE_CACHE		0x0020	/* Cached Route entry */
459 #endif
460 #define	IRE_IF_NORESOLVER	0x0040	/* Route entry for local interface */
461 					/* net without any address mapping. */
462 #define	IRE_IF_RESOLVER		0x0080	/* Route entry for local interface */
463 					/* net with resolver. */
464 #define	IRE_HOST		0x0100	/* Host route entry */
465 /* Keep so user-level still compiles */
466 #define	IRE_HOST_REDIRECT	0x0200	/* only used for T_SVR4_OPTMGMT_REQ */
467 #define	IRE_IF_CLONE		0x0400	/* Per host clone of IRE_IF */
468 #define	IRE_MULTICAST		0x0800	/* Special - not in table */
469 #define	IRE_NOROUTE		0x1000	/* Special - not in table */
470 
471 #define	IRE_INTERFACE		(IRE_IF_NORESOLVER | IRE_IF_RESOLVER)
472 
473 #define	IRE_IF_ALL		(IRE_IF_NORESOLVER | IRE_IF_RESOLVER | \
474 				    IRE_IF_CLONE)
475 #define	IRE_OFFSUBNET		(IRE_DEFAULT | IRE_PREFIX | IRE_HOST)
476 #define	IRE_OFFLINK		IRE_OFFSUBNET
477 /*
478  * Note that we view IRE_NOROUTE as ONLINK since we can "send" to them without
479  * going through a router; the result of sending will be an error/icmp error.
480  */
481 #define	IRE_ONLINK		(IRE_IF_ALL|IRE_LOCAL|IRE_LOOPBACK| \
482 				    IRE_BROADCAST|IRE_MULTICAST|IRE_NOROUTE)
483 
484 /* Arguments to ire_flush_cache() */
485 #define	IRE_FLUSH_DELETE	0
486 #define	IRE_FLUSH_ADD		1
487 #define	IRE_FLUSH_GWCHANGE	2
488 
489 /*
490  * Open/close synchronization flags.
491  * These are kept in a separate field in the conn and the synchronization
492  * depends on the atomic 32 bit access to that field.
493  */
494 #define	CONN_CLOSING		0x01	/* ip_close waiting for ip_wsrv */
495 #define	CONN_CONDEMNED		0x02	/* conn is closing, no more refs */
496 #define	CONN_INCIPIENT		0x04	/* conn not yet visible, no refs */
497 #define	CONN_QUIESCED		0x08	/* conn is now quiescent */
498 #define	CONN_UPDATE_ILL		0x10	/* conn_update_ill in progress */
499 
500 /*
501  * Flags for dce_flags field. Specifies which information has been set.
502  * dce_ident is always present, but the other ones are identified by the flags.
503  */
504 #define	DCEF_DEFAULT		0x0001	/* Default DCE - no pmtu or uinfo */
505 #define	DCEF_PMTU		0x0002	/* Different than interface MTU */
506 #define	DCEF_UINFO		0x0004	/* dce_uinfo set */
507 #define	DCEF_TOO_SMALL_PMTU	0x0008	/* Smaller than IPv4/IPv6 MIN */
508 
509 #ifdef _KERNEL
510 /*
511  * Extra structures need for per-src-addr filtering (IGMPv3/MLDv2)
512  */
513 #define	MAX_FILTER_SIZE	64
514 
515 typedef struct slist_s {
516 	int		sl_numsrc;
517 	in6_addr_t	sl_addr[MAX_FILTER_SIZE];
518 } slist_t;
519 
520 /*
521  * Following struct is used to maintain retransmission state for
522  * a multicast group.  One rtx_state_t struct is an in-line field
523  * of the ilm_t struct; the slist_ts in the rtx_state_t struct are
524  * alloc'd as needed.
525  */
526 typedef struct rtx_state_s {
527 	uint_t		rtx_timer;	/* retrans timer */
528 	int		rtx_cnt;	/* retrans count */
529 	int		rtx_fmode_cnt;	/* retrans count for fmode change */
530 	slist_t		*rtx_allow;
531 	slist_t		*rtx_block;
532 } rtx_state_t;
533 
534 /*
535  * Used to construct list of multicast address records that will be
536  * sent in a single listener report.
537  */
538 typedef struct mrec_s {
539 	struct mrec_s	*mrec_next;
540 	uint8_t		mrec_type;
541 	uint8_t		mrec_auxlen;	/* currently unused */
542 	in6_addr_t	mrec_group;
543 	slist_t		mrec_srcs;
544 } mrec_t;
545 
546 /* Group membership list per upper conn */
547 
548 /*
549  * We record the multicast information from the socket option in
550  * ilg_ifaddr/ilg_ifindex. This allows rejoining the group in the case when
551  * the ifaddr (or ifindex) disappears and later reappears, potentially on
552  * a different ill. The IPv6 multicast socket options and ioctls all specify
553  * the interface using an ifindex. For IPv4 some socket options/ioctls use
554  * the interface address and others use the index. We record here the method
555  * that was actually used (and leave the other of ilg_ifaddr or ilg_ifindex)
556  * at zero so that we can rejoin the way the application intended.
557  *
558  * We track the ill on which we will or already have joined an ilm using
559  * ilg_ill. When we have succeeded joining the ilm and have a refhold on it
560  * then we set ilg_ilm. Thus intentionally there is a window where ilg_ill is
561  * set and ilg_ilm is not set. This allows clearing ilg_ill as a signal that
562  * the ill is being unplumbed and the ilm should be discarded.
563  *
564  * ilg records the state of multicast memberships of a socket end point.
565  * ilm records the state of multicast memberships with the driver and is
566  * maintained per interface.
567  *
568  * The ilg state is protected by conn_ilg_lock.
569  * The ilg will not be freed until ilg_refcnt drops to zero.
570  */
571 typedef struct ilg_s {
572 	struct ilg_s	*ilg_next;
573 	struct ilg_s	**ilg_ptpn;
574 	struct conn_s	*ilg_connp;	/* Back pointer to get lock */
575 	in6_addr_t	ilg_v6group;
576 	ipaddr_t	ilg_ifaddr;	/* For some IPv4 cases */
577 	uint_t		ilg_ifindex;	/* IPv6 and some other IPv4 cases */
578 	struct ill_s	*ilg_ill;	/* Where ilm is joined. No refhold */
579 	struct ilm_s	*ilg_ilm;	/* With ilm_refhold */
580 	uint_t		ilg_refcnt;
581 	mcast_record_t	ilg_fmode;	/* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
582 	slist_t		*ilg_filter;
583 	boolean_t	ilg_condemned;	/* Conceptually deleted */
584 } ilg_t;
585 
586 /*
587  * Multicast address list entry for ill.
588  * ilm_ill is used by IPv4 and IPv6
589  *
590  * The ilm state (and other multicast state on the ill) is protected by
591  * ill_mcast_lock. Operations that change state on both an ilg and ilm
592  * in addition use ill_mcast_serializer to ensure that we can't have
593  * interleaving between e.g., add and delete operations for the same conn_t,
594  * group, and ill.
595  *
596  * The comment below (and for other netstack_t references) refers
597  * to the fact that we only do netstack_hold in particular cases,
598  * such as the references from open endpoints (ill_t and conn_t's
599  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
600  * ire_t's when an ill goes away.
601  */
602 typedef struct ilm_s {
603 	in6_addr_t	ilm_v6addr;
604 	int		ilm_refcnt;
605 	uint_t		ilm_timer;	/* IGMP/MLD query resp timer, in msec */
606 	struct ilm_s	*ilm_next;	/* Linked list for each ill */
607 	uint_t		ilm_state;	/* state of the membership */
608 	struct ill_s	*ilm_ill;	/* Back pointer to ill - ill_ilm_cnt */
609 	zoneid_t	ilm_zoneid;
610 	int		ilm_no_ilg_cnt;	/* number of joins w/ no ilg */
611 	mcast_record_t	ilm_fmode;	/* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
612 	slist_t		*ilm_filter;	/* source filter list */
613 	slist_t		*ilm_pendsrcs;	/* relevant src addrs for pending req */
614 	rtx_state_t	ilm_rtx;	/* SCR retransmission state */
615 	ipaddr_t	ilm_ifaddr;	/* For IPv4 netstat */
616 	ip_stack_t	*ilm_ipst;	/* Does not have a netstack_hold */
617 } ilm_t;
618 
619 #define	ilm_addr	V4_PART_OF_V6(ilm_v6addr)
620 
621 /*
622  * Soft reference to an IPsec SA.
623  *
624  * On relative terms, conn's can be persistent (living as long as the
625  * processes which create them), while SA's are ephemeral (dying when
626  * they hit their time-based or byte-based lifetimes).
627  *
628  * We could hold a hard reference to an SA from an ipsec_latch_t,
629  * but this would cause expired SA's to linger for a potentially
630  * unbounded time.
631  *
632  * Instead, we remember the hash bucket number and bucket generation
633  * in addition to the pointer.  The bucket generation is incremented on
634  * each deletion.
635  */
636 typedef struct ipsa_ref_s
637 {
638 	struct ipsa_s	*ipsr_sa;
639 	struct isaf_s	*ipsr_bucket;
640 	uint64_t	ipsr_gen;
641 } ipsa_ref_t;
642 
643 /*
644  * IPsec "latching" state.
645  *
646  * In the presence of IPsec policy, fully-bound conn's bind a connection
647  * to more than just the 5-tuple, but also a specific IPsec action and
648  * identity-pair.
649  * The identity pair is accessed from both the receive and transmit side
650  * hence it is maintained in the ipsec_latch_t structure. conn_latch and
651  * ixa_ipsec_latch points to it.
652  * The policy and actions are stored in conn_latch_in_policy and
653  * conn_latch_in_action for the inbound side, and in ixa_ipsec_policy and
654  * ixa_ipsec_action for the transmit side.
655  *
656  * As an optimization, we also cache soft references to IPsec SA's in
657  * ip_xmit_attr_t so that we can fast-path around most of the work needed for
658  * outbound IPsec SA selection.
659  */
660 typedef struct ipsec_latch_s
661 {
662 	kmutex_t	ipl_lock;
663 	uint32_t	ipl_refcnt;
664 
665 	struct ipsid_s	*ipl_local_cid;
666 	struct ipsid_s	*ipl_remote_cid;
667 	unsigned int
668 			ipl_ids_latched : 1,
669 
670 			ipl_pad_to_bit_31 : 31;
671 } ipsec_latch_t;
672 
673 #define	IPLATCH_REFHOLD(ipl) { \
674 	atomic_add_32(&(ipl)->ipl_refcnt, 1);		\
675 	ASSERT((ipl)->ipl_refcnt != 0);			\
676 }
677 
678 #define	IPLATCH_REFRELE(ipl) {				\
679 	ASSERT((ipl)->ipl_refcnt != 0);				\
680 	membar_exit();						\
681 	if (atomic_add_32_nv(&(ipl)->ipl_refcnt, -1) == 0)	\
682 		iplatch_free(ipl);				\
683 }
684 
685 /*
686  * peer identity structure.
687  */
688 typedef struct conn_s conn_t;
689 
690 /*
691  * This is used to match an inbound/outbound datagram with policy.
692  */
693 typedef	struct ipsec_selector {
694 	in6_addr_t	ips_local_addr_v6;
695 	in6_addr_t	ips_remote_addr_v6;
696 	uint16_t	ips_local_port;
697 	uint16_t	ips_remote_port;
698 	uint8_t		ips_icmp_type;
699 	uint8_t		ips_icmp_code;
700 	uint8_t		ips_protocol;
701 	uint8_t		ips_isv4 : 1,
702 			ips_is_icmp_inv_acq: 1;
703 } ipsec_selector_t;
704 
705 /*
706  * Note that we put v4 addresses in the *first* 32-bit word of the
707  * selector rather than the last to simplify the prefix match/mask code
708  * in spd.c
709  */
710 #define	ips_local_addr_v4 ips_local_addr_v6.s6_addr32[0]
711 #define	ips_remote_addr_v4 ips_remote_addr_v6.s6_addr32[0]
712 
713 /* Values used in IP by IPSEC Code */
714 #define		IPSEC_OUTBOUND		B_TRUE
715 #define		IPSEC_INBOUND		B_FALSE
716 
717 /*
718  * There are two variants in policy failures. The packet may come in
719  * secure when not needed (IPSEC_POLICY_???_NOT_NEEDED) or it may not
720  * have the desired level of protection (IPSEC_POLICY_MISMATCH).
721  */
722 #define	IPSEC_POLICY_NOT_NEEDED		0
723 #define	IPSEC_POLICY_MISMATCH		1
724 #define	IPSEC_POLICY_AUTH_NOT_NEEDED	2
725 #define	IPSEC_POLICY_ENCR_NOT_NEEDED	3
726 #define	IPSEC_POLICY_SE_NOT_NEEDED	4
727 #define	IPSEC_POLICY_MAX		5	/* Always max + 1. */
728 
729 /*
730  * Check with IPSEC inbound policy if
731  *
732  * 1) per-socket policy is present - indicated by conn_in_enforce_policy.
733  * 2) Or if we have not cached policy on the conn and the global policy is
734  *    non-empty.
735  */
736 #define	CONN_INBOUND_POLICY_PRESENT(connp, ipss)	\
737 	((connp)->conn_in_enforce_policy ||		\
738 	(!((connp)->conn_policy_cached) && 		\
739 	(ipss)->ipsec_inbound_v4_policy_present))
740 
741 #define	CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss)	\
742 	((connp)->conn_in_enforce_policy ||		\
743 	(!(connp)->conn_policy_cached &&		\
744 	(ipss)->ipsec_inbound_v6_policy_present))
745 
746 #define	CONN_OUTBOUND_POLICY_PRESENT(connp, ipss)	\
747 	((connp)->conn_out_enforce_policy ||		\
748 	(!((connp)->conn_policy_cached) &&		\
749 	(ipss)->ipsec_outbound_v4_policy_present))
750 
751 #define	CONN_OUTBOUND_POLICY_PRESENT_V6(connp, ipss)	\
752 	((connp)->conn_out_enforce_policy ||		\
753 	(!(connp)->conn_policy_cached &&		\
754 	(ipss)->ipsec_outbound_v6_policy_present))
755 
756 /*
757  * Information cached in IRE for upper layer protocol (ULP).
758  */
759 typedef struct iulp_s {
760 	boolean_t	iulp_set;	/* Is any metric set? */
761 	uint32_t	iulp_ssthresh;	/* Slow start threshold (TCP). */
762 	clock_t		iulp_rtt;	/* Guestimate in millisecs. */
763 	clock_t		iulp_rtt_sd;	/* Cached value of RTT variance. */
764 	uint32_t	iulp_spipe;	/* Send pipe size. */
765 	uint32_t	iulp_rpipe;	/* Receive pipe size. */
766 	uint32_t	iulp_rtomax;	/* Max round trip timeout. */
767 	uint32_t	iulp_sack;	/* Use SACK option (TCP)? */
768 	uint32_t	iulp_mtu;	/* Setable with routing sockets */
769 
770 	uint32_t
771 		iulp_tstamp_ok : 1,	/* Use timestamp option (TCP)? */
772 		iulp_wscale_ok : 1,	/* Use window scale option (TCP)? */
773 		iulp_ecn_ok : 1,	/* Enable ECN (for TCP)? */
774 		iulp_pmtud_ok : 1,	/* Enable PMTUd? */
775 
776 		/* These three are passed out by ip_set_destination */
777 		iulp_localnet: 1,	/* IRE_ONLINK */
778 		iulp_loopback: 1,	/* IRE_LOOPBACK */
779 		iulp_local: 1,		/* IRE_LOCAL */
780 
781 		iulp_not_used : 25;
782 } iulp_t;
783 
784 /*
785  * The conn drain list structure (idl_t).
786  * The list is protected by idl_lock. Each conn_t inserted in the list
787  * points back at this idl_t using conn_idl. IP primes the draining of the
788  * conns queued in these lists, by qenabling the 1st conn of each list. This
789  * occurs when STREAMS backenables ip_wsrv on the IP module. Each conn instance
790  * of ip_wsrv successively qenables the next conn in the list.
791  * idl_lock protects all other members of idl_t and conn_drain_next
792  * and conn_drain_prev of conn_t. The conn_lock protects IPCF_DRAIN_DISABLED
793  * flag of the conn_t and conn_idl.
794  *
795  * The conn drain list, idl_t, itself is part of tx cookie list structure.
796  * A tx cookie list points to a blocked Tx ring and contains the list of
797  * all conn's that are blocked due to the flow-controlled Tx ring (via
798  * the idl drain list). Note that a link can have multiple Tx rings. The
799  * drain list will store the conn's blocked due to Tx ring being flow
800  * controlled.
801  */
802 
803 typedef uintptr_t ip_mac_tx_cookie_t;
804 typedef	struct idl_s idl_t;
805 typedef	struct idl_tx_list_s idl_tx_list_t;
806 
807 struct idl_tx_list_s {
808 	ip_mac_tx_cookie_t	txl_cookie;
809 	kmutex_t		txl_lock;	/* Lock for this list */
810 	idl_t			*txl_drain_list;
811 	int			txl_drain_index;
812 };
813 
814 struct idl_s {
815 	conn_t		*idl_conn;		/* Head of drain list */
816 	kmutex_t	idl_lock;		/* Lock for this list */
817 	uint32_t
818 		idl_repeat : 1,			/* Last conn must re-enable */
819 						/* drain list again */
820 		idl_unused : 31;
821 	idl_tx_list_t	*idl_itl;
822 };
823 
824 #define	CONN_DRAIN_LIST_LOCK(connp)	(&((connp)->conn_idl->idl_lock))
825 
826 /*
827  * Interface route structure which holds the necessary information to recreate
828  * routes that are tied to an interface i.e. have ire_ill set.
829  *
830  * These routes which were initially created via a routing socket or via the
831  * SIOCADDRT ioctl may be gateway routes (RTF_GATEWAY being set) or may be
832  * traditional interface routes.  When an ill comes back up after being
833  * down, this information will be used to recreate the routes.  These
834  * are part of an mblk_t chain that hangs off of the ILL (ill_saved_ire_mp).
835  */
836 typedef struct ifrt_s {
837 	ushort_t	ifrt_type;		/* Type of IRE */
838 	in6_addr_t	ifrt_v6addr;		/* Address IRE represents. */
839 	in6_addr_t	ifrt_v6gateway_addr;	/* Gateway if IRE_OFFLINK */
840 	in6_addr_t	ifrt_v6setsrc_addr;	/* Src addr if RTF_SETSRC */
841 	in6_addr_t	ifrt_v6mask;		/* Mask for matching IRE. */
842 	uint32_t	ifrt_flags;		/* flags related to route */
843 	iulp_t		ifrt_metrics;		/* Routing socket metrics */
844 	zoneid_t	ifrt_zoneid;		/* zoneid for route */
845 } ifrt_t;
846 
847 #define	ifrt_addr		V4_PART_OF_V6(ifrt_v6addr)
848 #define	ifrt_gateway_addr	V4_PART_OF_V6(ifrt_v6gateway_addr)
849 #define	ifrt_mask		V4_PART_OF_V6(ifrt_v6mask)
850 #define	ifrt_setsrc_addr	V4_PART_OF_V6(ifrt_v6setsrc_addr)
851 
852 /* Number of IP addresses that can be hosted on a physical interface */
853 #define	MAX_ADDRS_PER_IF	8192
854 /*
855  * Number of Source addresses to be considered for source address
856  * selection. Used by ipif_select_source_v4/v6.
857  */
858 #define	MAX_IPIF_SELECT_SOURCE	50
859 
860 #ifdef IP_DEBUG
861 /*
862  * Trace refholds and refreles for debugging.
863  */
864 #define	TR_STACK_DEPTH	14
865 typedef struct tr_buf_s {
866 	int	tr_depth;
867 	clock_t	tr_time;
868 	pc_t	tr_stack[TR_STACK_DEPTH];
869 } tr_buf_t;
870 
871 typedef struct th_trace_s {
872 	int		th_refcnt;
873 	uint_t		th_trace_lastref;
874 	kthread_t	*th_id;
875 #define	TR_BUF_MAX	38
876 	tr_buf_t	th_trbuf[TR_BUF_MAX];
877 } th_trace_t;
878 
879 typedef struct th_hash_s {
880 	list_node_t	thh_link;
881 	mod_hash_t	*thh_hash;
882 	ip_stack_t	*thh_ipst;
883 } th_hash_t;
884 #endif
885 
886 /* The following are ipif_state_flags */
887 #define	IPIF_CONDEMNED		0x1	/* The ipif is being removed */
888 #define	IPIF_CHANGING		0x2	/* A critcal ipif field is changing */
889 #define	IPIF_SET_LINKLOCAL	0x10	/* transient flag during bringup */
890 
891 /* IP interface structure, one per local address */
892 typedef struct ipif_s {
893 	struct	ipif_s	*ipif_next;
894 	struct	ill_s	*ipif_ill;	/* Back pointer to our ill */
895 	int	ipif_id;		/* Logical unit number */
896 	in6_addr_t ipif_v6lcl_addr;	/* Local IP address for this if. */
897 	in6_addr_t ipif_v6subnet;	/* Subnet prefix for this if. */
898 	in6_addr_t ipif_v6net_mask;	/* Net mask for this interface. */
899 	in6_addr_t ipif_v6brd_addr;	/* Broadcast addr for this interface. */
900 	in6_addr_t ipif_v6pp_dst_addr;	/* Point-to-point dest address. */
901 	uint64_t ipif_flags;		/* Interface flags. */
902 	uint_t	ipif_metric;		/* BSD if metric, for compatibility. */
903 	uint_t	ipif_ire_type;		/* IRE_LOCAL or IRE_LOOPBACK */
904 
905 	/*
906 	 * The packet count in the ipif contain the sum of the
907 	 * packet counts in dead IRE_LOCAL/LOOPBACK for this ipif.
908 	 */
909 	uint_t	ipif_ib_pkt_count;	/* Inbound packets for our dead IREs */
910 
911 	/* Exclusive bit fields, protected by ipsq_t */
912 	unsigned int
913 		ipif_was_up : 1,	/* ipif was up before */
914 		ipif_addr_ready : 1,	/* DAD is done */
915 		ipif_was_dup : 1,	/* DAD had failed */
916 		ipif_added_nce : 1,	/* nce added for local address */
917 
918 		ipif_pad_to_31 : 28;
919 
920 	ilm_t	*ipif_allhosts_ilm;	/* For all-nodes join */
921 	ilm_t	*ipif_solmulti_ilm;	/* For IPv6 solicited multicast join */
922 
923 	uint_t	ipif_seqid;		/* unique index across all ills */
924 	uint_t	ipif_state_flags;	/* See IPIF_* flag defs above */
925 	uint_t	ipif_refcnt;		/* active consistent reader cnt */
926 
927 	zoneid_t ipif_zoneid;		/* zone ID number */
928 	timeout_id_t ipif_recovery_id;	/* Timer for DAD recovery */
929 	boolean_t ipif_trace_disable;	/* True when alloc fails */
930 	/*
931 	 * For an IPMP interface, ipif_bound_ill tracks the ill whose hardware
932 	 * information this ipif is associated with via ARP/NDP.  We can use
933 	 * an ill pointer (rather than an index) because only ills that are
934 	 * part of a group will be pointed to, and an ill cannot disappear
935 	 * while it's in a group.
936 	 */
937 	struct ill_s    *ipif_bound_ill;
938 	struct ipif_s   *ipif_bound_next; /* bound ipif chain */
939 	boolean_t	ipif_bound;	/* B_TRUE if we successfully bound */
940 
941 	struct ire_s	*ipif_ire_local; /* Our IRE_LOCAL or LOOPBACK */
942 	struct ire_s	*ipif_ire_if;	 /* Our IRE_INTERFACE */
943 } ipif_t;
944 
945 /*
946  * The following table lists the protection levels of the various members
947  * of the ipif_t. The following notation is used.
948  *
949  * Write once - Written to only once at the time of bringing up
950  * the interface and can be safely read after the bringup without any lock.
951  *
952  * ipsq - Need to execute in the ipsq to perform the indicated access.
953  *
954  * ill_lock - Need to hold this mutex to perform the indicated access.
955  *
956  * ill_g_lock - Need to hold this rw lock as reader/writer for read access or
957  * write access respectively.
958  *
959  * down ill - Written to only when the ill is down (i.e all ipifs are down)
960  * up ill - Read only when the ill is up (i.e. at least 1 ipif is up)
961  *
962  *		 Table of ipif_t members and their protection
963  *
964  * ipif_next		ipsq + ill_lock +	ipsq OR ill_lock OR
965  *			ill_g_lock		ill_g_lock
966  * ipif_ill		ipsq + down ipif	write once
967  * ipif_id		ipsq + down ipif	write once
968  * ipif_v6lcl_addr	ipsq + down ipif	up ipif
969  * ipif_v6subnet	ipsq + down ipif	up ipif
970  * ipif_v6net_mask	ipsq + down ipif	up ipif
971  *
972  * ipif_v6brd_addr
973  * ipif_v6pp_dst_addr
974  * ipif_flags		ill_lock		ill_lock
975  * ipif_metric
976  * ipif_ire_type	ipsq + down ill		up ill
977  *
978  * ipif_ib_pkt_count	Approx
979  *
980  * bit fields		ill_lock		ill_lock
981  *
982  * ipif_allhosts_ilm	ipsq			ipsq
983  * ipif_solmulti_ilm	ipsq			ipsq
984  *
985  * ipif_seqid		ipsq			Write once
986  *
987  * ipif_state_flags	ill_lock		ill_lock
988  * ipif_refcnt		ill_lock		ill_lock
989  * ipif_bound_ill	ipsq + ipmp_lock	ipsq OR ipmp_lock
990  * ipif_bound_next	ipsq			ipsq
991  * ipif_bound		ipsq			ipsq
992  *
993  * ipif_ire_local	ipsq + ips_ill_g_lock	ipsq OR ips_ill_g_lock
994  * ipif_ire_if		ipsq + ips_ill_g_lock	ipsq OR ips_ill_g_lock
995  */
996 
997 /*
998  * Return values from ip_laddr_verify_{v4,v6}
999  */
1000 typedef enum { IPVL_UNICAST_UP, IPVL_UNICAST_DOWN, IPVL_MCAST, IPVL_BCAST,
1001 	    IPVL_BAD} ip_laddr_t;
1002 
1003 
1004 #define	IP_TR_HASH(tid)	((((uintptr_t)tid) >> 6) & (IP_TR_HASH_MAX - 1))
1005 
1006 #ifdef DEBUG
1007 #define	IPIF_TRACE_REF(ipif)	ipif_trace_ref(ipif)
1008 #define	ILL_TRACE_REF(ill)	ill_trace_ref(ill)
1009 #define	IPIF_UNTRACE_REF(ipif)	ipif_untrace_ref(ipif)
1010 #define	ILL_UNTRACE_REF(ill)	ill_untrace_ref(ill)
1011 #else
1012 #define	IPIF_TRACE_REF(ipif)
1013 #define	ILL_TRACE_REF(ill)
1014 #define	IPIF_UNTRACE_REF(ipif)
1015 #define	ILL_UNTRACE_REF(ill)
1016 #endif
1017 
1018 /* IPv4 compatibility macros */
1019 #define	ipif_lcl_addr		V4_PART_OF_V6(ipif_v6lcl_addr)
1020 #define	ipif_subnet		V4_PART_OF_V6(ipif_v6subnet)
1021 #define	ipif_net_mask		V4_PART_OF_V6(ipif_v6net_mask)
1022 #define	ipif_brd_addr		V4_PART_OF_V6(ipif_v6brd_addr)
1023 #define	ipif_pp_dst_addr	V4_PART_OF_V6(ipif_v6pp_dst_addr)
1024 
1025 /* Macros for easy backreferences to the ill. */
1026 #define	ipif_isv6		ipif_ill->ill_isv6
1027 
1028 #define	SIOCLIFADDR_NDX 112	/* ndx of SIOCLIFADDR in the ndx ioctl table */
1029 
1030 /*
1031  * mode value for ip_ioctl_finish for finishing an ioctl
1032  */
1033 #define	CONN_CLOSE	1		/* No mi_copy */
1034 #define	COPYOUT		2		/* do an mi_copyout if needed */
1035 #define	NO_COPYOUT	3		/* do an mi_copy_done */
1036 #define	IPI2MODE(ipi)	((ipi)->ipi_flags & IPI_GET_CMD ? COPYOUT : NO_COPYOUT)
1037 
1038 /*
1039  * The IP-MT design revolves around the serialization objects ipsq_t (IPSQ)
1040  * and ipxop_t (exclusive operation or "xop").  Becoming "writer" on an IPSQ
1041  * ensures that no other threads can become "writer" on any IPSQs sharing that
1042  * IPSQ's xop until the writer thread is done.
1043  *
1044  * Each phyint points to one IPSQ that remains fixed over the phyint's life.
1045  * Each IPSQ points to one xop that can change over the IPSQ's life.  If a
1046  * phyint is *not* in an IPMP group, then its IPSQ will refer to the IPSQ's
1047  * "own" xop (ipsq_ownxop).  If a phyint *is* part of an IPMP group, then its
1048  * IPSQ will refer to the "group" xop, which is shorthand for the xop of the
1049  * IPSQ of the IPMP meta-interface's phyint.  Thus, all phyints that are part
1050  * of the same IPMP group will have their IPSQ's point to the group xop, and
1051  * thus becoming "writer" on any phyint in the group will prevent any other
1052  * writer on any other phyint in the group.  All IPSQs sharing the same xop
1053  * are chained together through ipsq_next (in the degenerate common case,
1054  * ipsq_next simply refers to itself).  Note that the group xop is guaranteed
1055  * to exist at least as long as there are members in the group, since the IPMP
1056  * meta-interface can only be destroyed if the group is empty.
1057  *
1058  * Incoming exclusive operation requests are enqueued on the IPSQ they arrived
1059  * on rather than the xop.  This makes switching xop's (as would happen when a
1060  * phyint leaves an IPMP group) simple, because after the phyint leaves the
1061  * group, any operations enqueued on its IPSQ can be safely processed with
1062  * respect to its new xop, and any operations enqueued on the IPSQs of its
1063  * former group can be processed with respect to their existing group xop.
1064  * Even so, switching xops is a subtle dance; see ipsq_dq() for details.
1065  *
1066  * An IPSQ's "own" xop is embedded within the IPSQ itself since they have have
1067  * identical lifetimes, and because doing so simplifies pointer management.
1068  * While each phyint and IPSQ point to each other, it is not possible to free
1069  * the IPSQ when the phyint is freed, since we may still *inside* the IPSQ
1070  * when the phyint is being freed.  Thus, ipsq_phyint is set to NULL when the
1071  * phyint is freed, and the IPSQ free is later done in ipsq_exit().
1072  *
1073  * ipsq_t synchronization:	read			write
1074  *
1075  *	ipsq_xopq_mphead	ipx_lock		ipx_lock
1076  *	ipsq_xopq_mptail	ipx_lock		ipx_lock
1077  *	ipsq_xop_switch_mp	ipsq_lock		ipsq_lock
1078  *	ipsq_phyint		write once		write once
1079  *	ipsq_next		RW_READER ill_g_lock	RW_WRITER ill_g_lock
1080  *	ipsq_xop 		ipsq_lock or ipsq	ipsq_lock + ipsq
1081  *	ipsq_swxop		ipsq			ipsq
1082  * 	ipsq_ownxop		see ipxop_t		see ipxop_t
1083  *	ipsq_ipst		write once		write once
1084  *
1085  * ipxop_t synchronization:     read			write
1086  *
1087  *	ipx_writer  		ipx_lock		ipx_lock
1088  *	ipx_xop_queued		ipx_lock 		ipx_lock
1089  *	ipx_mphead		ipx_lock		ipx_lock
1090  *	ipx_mptail		ipx_lock		ipx_lock
1091  *	ipx_ipsq		write once		write once
1092  *	ips_ipsq_queued		ipx_lock		ipx_lock
1093  *	ipx_waitfor		ipsq or ipx_lock	ipsq + ipx_lock
1094  *	ipx_reentry_cnt		ipsq or ipx_lock	ipsq + ipx_lock
1095  *	ipx_current_done	ipsq			ipsq
1096  *	ipx_current_ioctl	ipsq			ipsq
1097  *	ipx_current_ipif	ipsq or ipx_lock	ipsq + ipx_lock
1098  *	ipx_pending_ipif	ipsq or ipx_lock	ipsq + ipx_lock
1099  *	ipx_pending_mp		ipsq or ipx_lock	ipsq + ipx_lock
1100  *	ipx_forced		ipsq			ipsq
1101  *	ipx_depth		ipsq			ipsq
1102  *	ipx_stack		ipsq			ipsq
1103  */
1104 typedef struct ipxop_s {
1105 	kmutex_t	ipx_lock;	/* see above */
1106 	kthread_t	*ipx_writer;  	/* current owner */
1107 	mblk_t		*ipx_mphead;	/* messages tied to this op */
1108 	mblk_t		*ipx_mptail;
1109 	struct ipsq_s	*ipx_ipsq;	/* associated ipsq */
1110 	boolean_t	ipx_ipsq_queued; /* ipsq using xop has queued op */
1111 	int		ipx_waitfor;	/* waiting; values encoded below */
1112 	int		ipx_reentry_cnt;
1113 	boolean_t	ipx_current_done;  /* is the current operation done? */
1114 	int		ipx_current_ioctl; /* current ioctl, or 0 if no ioctl */
1115 	ipif_t		*ipx_current_ipif; /* ipif for current op */
1116 	ipif_t		*ipx_pending_ipif; /* ipif for ipx_pending_mp */
1117 	mblk_t 		*ipx_pending_mp;   /* current ioctl mp while waiting */
1118 	boolean_t	ipx_forced; 			/* debugging aid */
1119 #ifdef DEBUG
1120 	int		ipx_depth;			/* debugging aid */
1121 #define	IPX_STACK_DEPTH	15
1122 	pc_t		ipx_stack[IPX_STACK_DEPTH];	/* debugging aid */
1123 #endif
1124 } ipxop_t;
1125 
1126 typedef struct ipsq_s {
1127 	kmutex_t ipsq_lock;		/* see above */
1128 	mblk_t	*ipsq_switch_mp;	/* op to handle right after switch */
1129 	mblk_t	*ipsq_xopq_mphead;	/* list of excl ops (mostly ioctls) */
1130 	mblk_t	*ipsq_xopq_mptail;
1131 	struct phyint	*ipsq_phyint;	/* associated phyint */
1132 	struct ipsq_s	*ipsq_next;	/* next ipsq sharing ipsq_xop */
1133 	struct ipxop_s	*ipsq_xop;	/* current xop synchronization info */
1134 	struct ipxop_s	*ipsq_swxop;	/* switch xop to on ipsq_exit() */
1135 	struct ipxop_s	ipsq_ownxop;	/* our own xop (may not be in-use) */
1136 	ip_stack_t	*ipsq_ipst;	/* does not have a netstack_hold */
1137 } ipsq_t;
1138 
1139 /*
1140  * ipx_waitfor values:
1141  */
1142 enum {
1143 	IPIF_DOWN = 1,	/* ipif_down() waiting for refcnts to drop */
1144 	ILL_DOWN,	/* ill_down() waiting for refcnts to drop */
1145 	IPIF_FREE,	/* ipif_free() waiting for refcnts to drop */
1146 	ILL_FREE	/* ill unplumb waiting for refcnts to drop */
1147 };
1148 
1149 /* Operation types for ipsq_try_enter() */
1150 #define	CUR_OP 0	/* request writer within current operation */
1151 #define	NEW_OP 1	/* request writer for a new operation */
1152 #define	SWITCH_OP 2	/* request writer once IPSQ XOP switches */
1153 
1154 /*
1155  * Kstats tracked on each IPMP meta-interface.  Order here must match
1156  * ipmp_kstats[] in ip/ipmp.c.
1157  */
1158 enum {
1159 	IPMP_KSTAT_OBYTES,	IPMP_KSTAT_OBYTES64,	IPMP_KSTAT_RBYTES,
1160 	IPMP_KSTAT_RBYTES64,	IPMP_KSTAT_OPACKETS,	IPMP_KSTAT_OPACKETS64,
1161 	IPMP_KSTAT_OERRORS,	IPMP_KSTAT_IPACKETS,	IPMP_KSTAT_IPACKETS64,
1162 	IPMP_KSTAT_IERRORS,	IPMP_KSTAT_MULTIRCV,	IPMP_KSTAT_MULTIXMT,
1163 	IPMP_KSTAT_BRDCSTRCV,	IPMP_KSTAT_BRDCSTXMT,	IPMP_KSTAT_LINK_UP,
1164 	IPMP_KSTAT_MAX		/* keep last */
1165 };
1166 
1167 /*
1168  * phyint represents state that is common to both IPv4 and IPv6 interfaces.
1169  * There is a separate ill_t representing IPv4 and IPv6 which has a
1170  * backpointer to the phyint structure for accessing common state.
1171  */
1172 typedef struct phyint {
1173 	struct ill_s	*phyint_illv4;
1174 	struct ill_s	*phyint_illv6;
1175 	uint_t		phyint_ifindex;		/* SIOCSLIFINDEX */
1176 	uint64_t	phyint_flags;
1177 	avl_node_t	phyint_avl_by_index;	/* avl tree by index */
1178 	avl_node_t	phyint_avl_by_name;	/* avl tree by name */
1179 	kmutex_t	phyint_lock;
1180 	struct ipsq_s	*phyint_ipsq;		/* back pointer to ipsq */
1181 	struct ipmp_grp_s *phyint_grp;		/* associated IPMP group */
1182 	char		phyint_name[LIFNAMSIZ];	/* physical interface name */
1183 	uint64_t	phyint_kstats0[IPMP_KSTAT_MAX];	/* baseline kstats */
1184 } phyint_t;
1185 
1186 #define	CACHE_ALIGN_SIZE 64
1187 #define	CACHE_ALIGN(align_struct)	P2ROUNDUP(sizeof (struct align_struct),\
1188 							CACHE_ALIGN_SIZE)
1189 struct _phyint_list_s_ {
1190 	avl_tree_t	phyint_list_avl_by_index;	/* avl tree by index */
1191 	avl_tree_t	phyint_list_avl_by_name;	/* avl tree by name */
1192 };
1193 
1194 typedef union phyint_list_u {
1195 	struct	_phyint_list_s_ phyint_list_s;
1196 	char	phyint_list_filler[CACHE_ALIGN(_phyint_list_s_)];
1197 } phyint_list_t;
1198 
1199 #define	phyint_list_avl_by_index	phyint_list_s.phyint_list_avl_by_index
1200 #define	phyint_list_avl_by_name		phyint_list_s.phyint_list_avl_by_name
1201 
1202 /*
1203  * Fragmentation hash bucket
1204  */
1205 typedef struct ipfb_s {
1206 	struct ipf_s	*ipfb_ipf;	/* List of ... */
1207 	size_t		ipfb_count;	/* Count of bytes used by frag(s) */
1208 	kmutex_t	ipfb_lock;	/* Protect all ipf in list */
1209 	uint_t		ipfb_frag_pkts; /* num of distinct fragmented pkts */
1210 } ipfb_t;
1211 
1212 /*
1213  * IRE bucket structure. Usually there is an array of such structures,
1214  * each pointing to a linked list of ires. irb_refcnt counts the number
1215  * of walkers of a given hash bucket. Usually the reference count is
1216  * bumped up if the walker wants no IRES to be DELETED while walking the
1217  * list. Bumping up does not PREVENT ADDITION. This allows walking a given
1218  * hash bucket without stumbling up on a free pointer.
1219  *
1220  * irb_t structures in ip_ftable are dynamically allocated and freed.
1221  * In order to identify the irb_t structures that can be safely kmem_free'd
1222  * we need to ensure that
1223  *  - the irb_refcnt is quiescent, indicating no other walkers,
1224  *  - no other threads or ire's are holding references to the irb,
1225  *	i.e., irb_nire == 0,
1226  *  - there are no active ire's in the bucket, i.e., irb_ire_cnt == 0
1227  */
1228 typedef struct irb {
1229 	struct ire_s	*irb_ire;	/* First ire in this bucket */
1230 					/* Should be first in this struct */
1231 	krwlock_t	irb_lock;	/* Protect this bucket */
1232 	uint_t		irb_refcnt;	/* Protected by irb_lock */
1233 	uchar_t		irb_marks;	/* CONDEMNED ires in this bucket ? */
1234 #define	IRB_MARK_CONDEMNED	0x0001	/* Contains some IRE_IS_CONDEMNED */
1235 #define	IRB_MARK_DYNAMIC	0x0002	/* Dynamically allocated */
1236 	/* Once IPv6 uses radix then IRB_MARK_DYNAMIC will be always be set */
1237 	uint_t		irb_ire_cnt;	/* Num of active IRE in this bucket */
1238 	int		irb_nire;	/* Num of ftable ire's that ref irb */
1239 	ip_stack_t	*irb_ipst;	/* Does not have a netstack_hold */
1240 } irb_t;
1241 
1242 #define	IRB2RT(irb)	(rt_t *)((caddr_t)(irb) - offsetof(rt_t, rt_irb))
1243 
1244 /* Forward declarations */
1245 struct dce_s;
1246 typedef struct dce_s dce_t;
1247 struct ire_s;
1248 typedef struct ire_s ire_t;
1249 struct ncec_s;
1250 typedef struct ncec_s ncec_t;
1251 struct nce_s;
1252 typedef struct nce_s nce_t;
1253 struct ip_recv_attr_s;
1254 typedef struct ip_recv_attr_s ip_recv_attr_t;
1255 struct ip_xmit_attr_s;
1256 typedef struct ip_xmit_attr_s ip_xmit_attr_t;
1257 
1258 struct tsol_ire_gw_secattr_s;
1259 typedef struct tsol_ire_gw_secattr_s tsol_ire_gw_secattr_t;
1260 
1261 /*
1262  * This is a structure for a one-element route cache that is passed
1263  * by reference between ip_input and ill_inputfn.
1264  */
1265 typedef struct {
1266 	ire_t		*rtc_ire;
1267 	ipaddr_t	rtc_ipaddr;
1268 	in6_addr_t	rtc_ip6addr;
1269 } rtc_t;
1270 
1271 /*
1272  * Note: Temporarily use 64 bits, and will probably go back to 32 bits after
1273  * more cleanup work is done.
1274  */
1275 typedef uint64_t iaflags_t;
1276 
1277 /* The ill input function pointer type */
1278 typedef void (*pfillinput_t)(mblk_t *, void *, void *, ip_recv_attr_t *,
1279     rtc_t *);
1280 
1281 /* The ire receive function pointer type */
1282 typedef void (*pfirerecv_t)(ire_t *, mblk_t *, void *, ip_recv_attr_t *);
1283 
1284 /* The ire send and postfrag function pointer types */
1285 typedef int (*pfiresend_t)(ire_t *, mblk_t *, void *,
1286     ip_xmit_attr_t *, uint32_t *);
1287 typedef int (*pfirepostfrag_t)(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
1288     zoneid_t, zoneid_t, uintptr_t *);
1289 
1290 
1291 #define	IP_V4_G_HEAD	0
1292 #define	IP_V6_G_HEAD	1
1293 
1294 #define	MAX_G_HEADS	2
1295 
1296 /*
1297  * unpadded ill_if structure
1298  */
1299 struct 	_ill_if_s_ {
1300 	union ill_if_u	*illif_next;
1301 	union ill_if_u	*illif_prev;
1302 	avl_tree_t	illif_avl_by_ppa;	/* AVL tree sorted on ppa */
1303 	vmem_t		*illif_ppa_arena;	/* ppa index space */
1304 	uint16_t	illif_mcast_v1;		/* hints for		  */
1305 	uint16_t	illif_mcast_v2;		/* [igmp|mld]_slowtimo	  */
1306 	int		illif_name_len;		/* name length */
1307 	char		illif_name[LIFNAMSIZ];	/* name of interface type */
1308 };
1309 
1310 /* cache aligned ill_if structure */
1311 typedef union 	ill_if_u {
1312 	struct  _ill_if_s_ ill_if_s;
1313 	char 	illif_filler[CACHE_ALIGN(_ill_if_s_)];
1314 } ill_if_t;
1315 
1316 #define	illif_next		ill_if_s.illif_next
1317 #define	illif_prev		ill_if_s.illif_prev
1318 #define	illif_avl_by_ppa	ill_if_s.illif_avl_by_ppa
1319 #define	illif_ppa_arena		ill_if_s.illif_ppa_arena
1320 #define	illif_mcast_v1		ill_if_s.illif_mcast_v1
1321 #define	illif_mcast_v2		ill_if_s.illif_mcast_v2
1322 #define	illif_name		ill_if_s.illif_name
1323 #define	illif_name_len		ill_if_s.illif_name_len
1324 
1325 typedef struct ill_walk_context_s {
1326 	int	ctx_current_list; /* current list being searched */
1327 	int	ctx_last_list;	 /* last list to search */
1328 } ill_walk_context_t;
1329 
1330 /*
1331  * ill_g_heads structure, one for IPV4 and one for IPV6
1332  */
1333 struct _ill_g_head_s_ {
1334 	ill_if_t	*ill_g_list_head;
1335 	ill_if_t	*ill_g_list_tail;
1336 };
1337 
1338 typedef union ill_g_head_u {
1339 	struct _ill_g_head_s_ ill_g_head_s;
1340 	char	ill_g_head_filler[CACHE_ALIGN(_ill_g_head_s_)];
1341 } ill_g_head_t;
1342 
1343 #define	ill_g_list_head	ill_g_head_s.ill_g_list_head
1344 #define	ill_g_list_tail	ill_g_head_s.ill_g_list_tail
1345 
1346 #define	IP_V4_ILL_G_LIST(ipst)	\
1347 	(ipst)->ips_ill_g_heads[IP_V4_G_HEAD].ill_g_list_head
1348 #define	IP_V6_ILL_G_LIST(ipst)	\
1349 	(ipst)->ips_ill_g_heads[IP_V6_G_HEAD].ill_g_list_head
1350 #define	IP_VX_ILL_G_LIST(i, ipst)	\
1351 	(ipst)->ips_ill_g_heads[i].ill_g_list_head
1352 
1353 #define	ILL_START_WALK_V4(ctx_ptr, ipst)	\
1354 	ill_first(IP_V4_G_HEAD, IP_V4_G_HEAD, ctx_ptr, ipst)
1355 #define	ILL_START_WALK_V6(ctx_ptr, ipst)	\
1356 	ill_first(IP_V6_G_HEAD, IP_V6_G_HEAD, ctx_ptr, ipst)
1357 #define	ILL_START_WALK_ALL(ctx_ptr, ipst)	\
1358 	ill_first(MAX_G_HEADS, MAX_G_HEADS, ctx_ptr, ipst)
1359 
1360 /*
1361  * Capabilities, possible flags for ill_capabilities.
1362  */
1363 #define	ILL_CAPAB_LSO		0x04		/* Large Send Offload */
1364 #define	ILL_CAPAB_HCKSUM	0x08		/* Hardware checksumming */
1365 #define	ILL_CAPAB_ZEROCOPY	0x10		/* Zero-copy */
1366 #define	ILL_CAPAB_DLD		0x20		/* DLD capabilities */
1367 #define	ILL_CAPAB_DLD_POLL	0x40		/* Polling */
1368 #define	ILL_CAPAB_DLD_DIRECT	0x80		/* Direct function call */
1369 
1370 /*
1371  * Per-ill Hardware Checksumming capbilities.
1372  */
1373 typedef struct ill_hcksum_capab_s ill_hcksum_capab_t;
1374 
1375 /*
1376  * Per-ill Zero-copy capabilities.
1377  */
1378 typedef struct ill_zerocopy_capab_s ill_zerocopy_capab_t;
1379 
1380 /*
1381  * DLD capbilities.
1382  */
1383 typedef struct ill_dld_capab_s ill_dld_capab_t;
1384 
1385 /*
1386  * Per-ill polling resource map.
1387  */
1388 typedef struct ill_rx_ring ill_rx_ring_t;
1389 
1390 /*
1391  * Per-ill Large Send Offload capabilities.
1392  */
1393 typedef struct ill_lso_capab_s ill_lso_capab_t;
1394 
1395 /* The following are ill_state_flags */
1396 #define	ILL_LL_SUBNET_PENDING	0x01	/* Waiting for DL_INFO_ACK from drv */
1397 #define	ILL_CONDEMNED		0x02	/* No more new ref's to the ILL */
1398 #define	ILL_DL_UNBIND_IN_PROGRESS	0x04	/* UNBIND_REQ is sent */
1399 #define	ILL_DOWN_IN_PROGRESS	0x08	/* ILL is going down - no new nce's */
1400 #define	ILL_LL_BIND_PENDING	0x0020	/* XXX Reuse ILL_LL_SUBNET_PENDING ? */
1401 #define	ILL_LL_UP		0x0040
1402 #define	ILL_LL_DOWN		0x0080
1403 
1404 /* Is this an ILL whose source address is used by other ILL's ? */
1405 #define	IS_USESRC_ILL(ill)			\
1406 	(((ill)->ill_usesrc_ifindex == 0) &&	\
1407 	((ill)->ill_usesrc_grp_next != NULL))
1408 
1409 /* Is this a client/consumer of the usesrc ILL ? */
1410 #define	IS_USESRC_CLI_ILL(ill)			\
1411 	(((ill)->ill_usesrc_ifindex != 0) &&	\
1412 	((ill)->ill_usesrc_grp_next != NULL))
1413 
1414 /* Is this an virtual network interface (vni) ILL ? */
1415 #define	IS_VNI(ill)							\
1416 	(((ill)->ill_phyint->phyint_flags & (PHYI_LOOPBACK|PHYI_VIRTUAL)) == \
1417 	PHYI_VIRTUAL)
1418 
1419 /* Is this a loopback ILL? */
1420 #define	IS_LOOPBACK(ill) \
1421 	((ill)->ill_phyint->phyint_flags & PHYI_LOOPBACK)
1422 
1423 /* Is this an IPMP meta-interface ILL? */
1424 #define	IS_IPMP(ill)							\
1425 	((ill)->ill_phyint->phyint_flags & PHYI_IPMP)
1426 
1427 /* Is this ILL under an IPMP meta-interface? (aka "in a group?") */
1428 #define	IS_UNDER_IPMP(ill)						\
1429 	((ill)->ill_grp != NULL && !IS_IPMP(ill))
1430 
1431 /* Is ill1 in the same illgrp as ill2? */
1432 #define	IS_IN_SAME_ILLGRP(ill1, ill2)					\
1433 	((ill1)->ill_grp != NULL && ((ill1)->ill_grp == (ill2)->ill_grp))
1434 
1435 /* Is ill1 on the same LAN as ill2? */
1436 #define	IS_ON_SAME_LAN(ill1, ill2)					\
1437 	((ill1) == (ill2) || IS_IN_SAME_ILLGRP(ill1, ill2))
1438 
1439 #define	ILL_OTHER(ill)							\
1440 	((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :		\
1441 	    (ill)->ill_phyint->phyint_illv6)
1442 
1443 /*
1444  * IPMP group ILL state structure -- up to two per IPMP group (V4 and V6).
1445  * Created when the V4 and/or V6 IPMP meta-interface is I_PLINK'd.  It is
1446  * guaranteed to persist while there are interfaces of that type in the group.
1447  * In general, most fields are accessed outside of the IPSQ (e.g., in the
1448  * datapath), and thus use locks in addition to the IPSQ for protection.
1449  *
1450  * synchronization:		read			write
1451  *
1452  *	ig_if			ipsq or ill_g_lock	ipsq and ill_g_lock
1453  *	ig_actif		ipsq or ipmp_lock	ipsq and ipmp_lock
1454  *	ig_nactif		ipsq or ipmp_lock	ipsq and ipmp_lock
1455  *	ig_next_ill		ipsq or ipmp_lock	ipsq and ipmp_lock
1456  *	ig_ipmp_ill		write once		write once
1457  *	ig_cast_ill		ipsq or ipmp_lock	ipsq and ipmp_lock
1458  *	ig_arpent		ipsq			ipsq
1459  *	ig_mtu			ipsq			ipsq
1460  */
1461 typedef struct ipmp_illgrp_s {
1462 	list_t		ig_if; 		/* list of all interfaces */
1463 	list_t		ig_actif;	/* list of active interfaces */
1464 	uint_t		ig_nactif;	/* number of active interfaces */
1465 	struct ill_s	*ig_next_ill;	/* next active interface to use */
1466 	struct ill_s	*ig_ipmp_ill;	/* backpointer to IPMP meta-interface */
1467 	struct ill_s	*ig_cast_ill;	/* nominated ill for multi/broadcast */
1468 	list_t		ig_arpent;	/* list of ARP entries */
1469 	uint_t		ig_mtu;		/* ig_ipmp_ill->ill_max_mtu */
1470 } ipmp_illgrp_t;
1471 
1472 /*
1473  * IPMP group state structure -- one per IPMP group.  Created when the
1474  * IPMP meta-interface is plumbed; it is guaranteed to persist while there
1475  * are interfaces in it.
1476  *
1477  * ipmp_grp_t synchronization:		read			write
1478  *
1479  *	gr_name				ipmp_lock		ipmp_lock
1480  *	gr_ifname			write once		write once
1481  *	gr_mactype			ipmp_lock		ipmp_lock
1482  *	gr_phyint			write once		write once
1483  *	gr_nif				ipmp_lock		ipmp_lock
1484  *	gr_nactif			ipsq			ipsq
1485  *	gr_v4				ipmp_lock		ipmp_lock
1486  *	gr_v6				ipmp_lock		ipmp_lock
1487  *	gr_nv4				ipmp_lock		ipmp_lock
1488  *	gr_nv6				ipmp_lock		ipmp_lock
1489  *	gr_pendv4			ipmp_lock		ipmp_lock
1490  *	gr_pendv6			ipmp_lock		ipmp_lock
1491  *	gr_linkdownmp			ipsq			ipsq
1492  *	gr_ksp				ipmp_lock		ipmp_lock
1493  *	gr_kstats0			atomic			atomic
1494  */
1495 typedef struct ipmp_grp_s {
1496 	char		gr_name[LIFGRNAMSIZ];	/* group name */
1497 	char		gr_ifname[LIFNAMSIZ];	/* interface name */
1498 	t_uscalar_t	gr_mactype;	/* DLPI mactype of group */
1499 	phyint_t	*gr_phyint;	/* IPMP group phyint */
1500 	uint_t		gr_nif;		/* number of interfaces in group */
1501 	uint_t		gr_nactif; 	/* number of active interfaces */
1502 	ipmp_illgrp_t	*gr_v4;		/* V4 group information */
1503 	ipmp_illgrp_t	*gr_v6;		/* V6 group information */
1504 	uint_t		gr_nv4;		/* number of ills in V4 group */
1505 	uint_t		gr_nv6;		/* number of ills in V6 group */
1506 	uint_t		gr_pendv4; 	/* number of pending ills in V4 group */
1507 	uint_t		gr_pendv6; 	/* number of pending ills in V6 group */
1508 	mblk_t		*gr_linkdownmp;	/* message used to bring link down */
1509 	kstat_t		*gr_ksp;	/* group kstat pointer */
1510 	uint64_t	gr_kstats0[IPMP_KSTAT_MAX]; /* baseline group kstats */
1511 } ipmp_grp_t;
1512 
1513 /*
1514  * IPMP ARP entry -- one per SIOCS*ARP entry tied to the group.  Used to keep
1515  * ARP up-to-date as the active set of interfaces in the group changes.
1516  */
1517 typedef struct ipmp_arpent_s {
1518 	ipaddr_t	ia_ipaddr; 	/* IP address for this entry */
1519 	boolean_t	ia_proxyarp; 	/* proxy ARP entry? */
1520 	boolean_t	ia_notified; 	/* ARP notified about this entry? */
1521 	list_node_t	ia_node; 	/* next ARP entry in list */
1522 	uint16_t	ia_flags;	/* nce_flags for the address */
1523 	size_t		ia_lladdr_len;
1524 	uchar_t		*ia_lladdr;
1525 } ipmp_arpent_t;
1526 
1527 struct arl_s;
1528 
1529 /*
1530  * Per-ill capabilities.
1531  */
1532 struct ill_hcksum_capab_s {
1533 	uint_t	ill_hcksum_version;	/* interface version */
1534 	uint_t	ill_hcksum_txflags;	/* capabilities on transmit */
1535 };
1536 
1537 struct ill_zerocopy_capab_s {
1538 	uint_t	ill_zerocopy_version;	/* interface version */
1539 	uint_t	ill_zerocopy_flags;	/* capabilities */
1540 };
1541 
1542 struct ill_lso_capab_s {
1543 	uint_t	ill_lso_flags;		/* capabilities */
1544 	uint_t	ill_lso_max;		/* maximum size of payload */
1545 };
1546 
1547 /*
1548  * IP Lower level Structure.
1549  * Instance data structure in ip_open when there is a device below us.
1550  */
1551 typedef struct ill_s {
1552 	pfillinput_t ill_inputfn;	/* Fast input function selector */
1553 	ill_if_t *ill_ifptr;		/* pointer to interface type */
1554 	queue_t	*ill_rq;		/* Read queue. */
1555 	queue_t	*ill_wq;		/* Write queue. */
1556 
1557 	int	ill_error;		/* Error value sent up by device. */
1558 
1559 	ipif_t	*ill_ipif;		/* Interface chain for this ILL. */
1560 
1561 	uint_t	ill_ipif_up_count;	/* Number of IPIFs currently up. */
1562 	uint_t	ill_max_frag;		/* Max IDU from DLPI. */
1563 	uint_t	ill_current_frag;	/* Current IDU from DLPI. */
1564 	uint_t	ill_mtu;		/* User-specified MTU; SIOCSLIFMTU */
1565 	char	*ill_name;		/* Our name. */
1566 	uint_t	ill_ipif_dup_count;	/* Number of duplicate addresses. */
1567 	uint_t	ill_name_length;	/* Name length, incl. terminator. */
1568 	char	*ill_ndd_name;		/* Name + ":ip?_forwarding" for NDD. */
1569 	uint_t	ill_net_type;		/* IRE_IF_RESOLVER/IRE_IF_NORESOLVER. */
1570 	/*
1571 	 * Physical Point of Attachment num.  If DLPI style 1 provider
1572 	 * then this is derived from the devname.
1573 	 */
1574 	uint_t	ill_ppa;
1575 	t_uscalar_t	ill_sap;
1576 	t_scalar_t	ill_sap_length;	/* Including sign (for position) */
1577 	uint_t	ill_phys_addr_length;	/* Excluding the sap. */
1578 	uint_t	ill_bcast_addr_length;	/* Only set when the DL provider */
1579 					/* supports broadcast. */
1580 	t_uscalar_t	ill_mactype;
1581 	uint8_t	*ill_frag_ptr;		/* Reassembly state. */
1582 	timeout_id_t ill_frag_timer_id; /* timeout id for the frag timer */
1583 	ipfb_t	*ill_frag_hash_tbl;	/* Fragment hash list head. */
1584 
1585 	krwlock_t ill_mcast_lock;	/* Protects multicast state */
1586 	kmutex_t ill_mcast_serializer;	/* Serialize across ilg and ilm state */
1587 	ilm_t	*ill_ilm;		/* Multicast membership for ill */
1588 	uint_t	ill_global_timer;	/* for IGMPv3/MLDv2 general queries */
1589 	int	ill_mcast_type;		/* type of router which is querier */
1590 					/* on this interface */
1591 	uint16_t ill_mcast_v1_time;	/* # slow timeouts since last v1 qry */
1592 	uint16_t ill_mcast_v2_time;	/* # slow timeouts since last v2 qry */
1593 	uint8_t	ill_mcast_v1_tset;	/* 1 => timer is set; 0 => not set */
1594 	uint8_t	ill_mcast_v2_tset;	/* 1 => timer is set; 0 => not set */
1595 
1596 	uint8_t	ill_mcast_rv;		/* IGMPv3/MLDv2 robustness variable */
1597 	int	ill_mcast_qi;		/* IGMPv3/MLDv2 query interval var */
1598 
1599 	/*
1600 	 * All non-NULL cells between 'ill_first_mp_to_free' and
1601 	 * 'ill_last_mp_to_free' are freed in ill_delete.
1602 	 */
1603 #define	ill_first_mp_to_free	ill_bcast_mp
1604 	mblk_t	*ill_bcast_mp;		/* DLPI header for broadcasts. */
1605 	mblk_t	*ill_unbind_mp;		/* unbind mp from ill_dl_up() */
1606 	mblk_t	*ill_promiscoff_mp;	/* for ill_leave_allmulti() */
1607 	mblk_t	*ill_dlpi_deferred;	/* b_next chain of control messages */
1608 	mblk_t	*ill_dest_addr_mp;	/* mblk which holds ill_dest_addr */
1609 	mblk_t	*ill_replumb_mp;	/* replumb mp from ill_replumb() */
1610 	mblk_t	*ill_phys_addr_mp;	/* mblk which holds ill_phys_addr */
1611 	mblk_t	*ill_mcast_deferred;	/* b_next chain of IGMP/MLD packets */
1612 #define	ill_last_mp_to_free	ill_mcast_deferred
1613 
1614 	cred_t	*ill_credp;		/* opener's credentials */
1615 	uint8_t	*ill_phys_addr;		/* ill_phys_addr_mp->b_rptr + off */
1616 	uint8_t *ill_dest_addr;		/* ill_dest_addr_mp->b_rptr + off */
1617 
1618 	uint_t	ill_state_flags;	/* see ILL_* flags above */
1619 
1620 	/* Following bit fields protected by ipsq_t */
1621 	uint_t
1622 		ill_needs_attach : 1,
1623 		ill_reserved : 1,
1624 		ill_isv6 : 1,
1625 		ill_dlpi_style_set : 1,
1626 
1627 		ill_ifname_pending : 1,
1628 		ill_logical_down : 1,
1629 		ill_dl_up : 1,
1630 		ill_up_ipifs : 1,
1631 
1632 		ill_note_link : 1,	/* supports link-up notification */
1633 		ill_capab_reneg : 1, /* capability renegotiation to be done */
1634 		ill_dld_capab_inprog : 1, /* direct dld capab call in prog */
1635 		ill_need_recover_multicast : 1,
1636 
1637 		ill_replumbing : 1,
1638 		ill_arl_dlpi_pending : 1,
1639 
1640 		ill_pad_to_bit_31 : 18;
1641 
1642 	/* Following bit fields protected by ill_lock */
1643 	uint_t
1644 		ill_fragtimer_executing : 1,
1645 		ill_fragtimer_needrestart : 1,
1646 		ill_manual_token : 1,	/* system won't override ill_token */
1647 		ill_manual_linklocal : 1, /* system won't auto-conf linklocal */
1648 
1649 		ill_pad_bit_31 : 28;
1650 
1651 	/*
1652 	 * Used in SIOCSIFMUXID and SIOCGIFMUXID for 'ifconfig unplumb'.
1653 	 */
1654 	int	ill_muxid;		/* muxid returned from plink */
1655 
1656 	/* Used for IP frag reassembly throttling on a per ILL basis.  */
1657 	uint_t	ill_ipf_gen;		/* Generation of next fragment queue */
1658 	uint_t	ill_frag_count;		/* Count of all reassembly mblk bytes */
1659 	uint_t	ill_frag_free_num_pkts;	 /* num of fragmented packets to free */
1660 	clock_t	ill_last_frag_clean_time; /* time when frag's were pruned */
1661 	int	ill_type;		/* From <net/if_types.h> */
1662 	uint_t	ill_dlpi_multicast_state;	/* See below IDS_* */
1663 	uint_t	ill_dlpi_fastpath_state;	/* See below IDS_* */
1664 
1665 	/*
1666 	 * Capabilities related fields.
1667 	 */
1668 	uint_t  ill_dlpi_capab_state;	/* State of capability query, IDCS_* */
1669 	uint_t	ill_capab_pending_cnt;
1670 	uint64_t ill_capabilities;	/* Enabled capabilities, ILL_CAPAB_* */
1671 	ill_hcksum_capab_t *ill_hcksum_capab; /* H/W cksumming capabilities */
1672 	ill_zerocopy_capab_t *ill_zerocopy_capab; /* Zero-copy capabilities */
1673 	ill_dld_capab_t *ill_dld_capab; /* DLD capabilities */
1674 	ill_lso_capab_t	*ill_lso_capab;	/* Large Segment Offload capabilities */
1675 	mblk_t	*ill_capab_reset_mp;	/* Preallocated mblk for capab reset */
1676 
1677 	uint8_t	ill_max_hops;	/* Maximum hops for any logical interface */
1678 	uint_t	ill_user_mtu;	/* User-specified MTU via SIOCSLIFLNKINFO */
1679 	uint32_t ill_reachable_time;	/* Value for ND algorithm in msec */
1680 	uint32_t ill_reachable_retrans_time; /* Value for ND algorithm msec */
1681 	uint_t	ill_max_buf;		/* Max # of req to buffer for ND */
1682 	in6_addr_t	ill_token;	/* IPv6 interface id */
1683 	in6_addr_t	ill_dest_token;	/* Destination IPv6 interface id */
1684 	uint_t		ill_token_length;
1685 	uint32_t	ill_xmit_count;		/* ndp max multicast xmits */
1686 	mib2_ipIfStatsEntry_t	*ill_ip_mib;	/* ver indep. interface mib */
1687 	mib2_ipv6IfIcmpEntry_t	*ill_icmp6_mib;	/* Per interface mib */
1688 
1689 	phyint_t		*ill_phyint;
1690 	uint64_t		ill_flags;
1691 
1692 	kmutex_t	ill_lock;	/* Please see table below */
1693 	/*
1694 	 * The ill_nd_lla* fields handle the link layer address option
1695 	 * from neighbor discovery. This is used for external IPv6
1696 	 * address resolution.
1697 	 */
1698 	mblk_t		*ill_nd_lla_mp;	/* mblk which holds ill_nd_lla */
1699 	uint8_t		*ill_nd_lla;	/* Link Layer Address */
1700 	uint_t		ill_nd_lla_len;	/* Link Layer Address length */
1701 	/*
1702 	 * We have 4 phys_addr_req's sent down. This field keeps track
1703 	 * of which one is pending.
1704 	 */
1705 	t_uscalar_t	ill_phys_addr_pend; /* which dl_phys_addr_req pending */
1706 	/*
1707 	 * Used to save errors that occur during plumbing
1708 	 */
1709 	uint_t		ill_ifname_pending_err;
1710 	avl_node_t	ill_avl_byppa; /* avl node based on ppa */
1711 	list_t		ill_nce; /* pointer to nce_s list */
1712 	uint_t		ill_refcnt;	/* active refcnt by threads */
1713 	uint_t		ill_ire_cnt;	/* ires associated with this ill */
1714 	kcondvar_t	ill_cv;
1715 	uint_t		ill_ncec_cnt;	/* ncecs associated with this ill */
1716 	uint_t		ill_nce_cnt;	/* nces associated with this ill */
1717 	uint_t		ill_waiters;	/* threads waiting in ipsq_enter */
1718 	/*
1719 	 * Contains the upper read queue pointer of the module immediately
1720 	 * beneath IP.  This field allows IP to validate sub-capability
1721 	 * acknowledgments coming up from downstream.
1722 	 */
1723 	queue_t		*ill_lmod_rq;	/* read queue pointer of module below */
1724 	uint_t		ill_lmod_cnt;	/* number of modules beneath IP */
1725 	ip_m_t		*ill_media;	/* media specific params/functions */
1726 	t_uscalar_t	ill_dlpi_pending; /* Last DLPI primitive issued */
1727 	uint_t		ill_usesrc_ifindex; /* use src addr from this ILL */
1728 	struct ill_s	*ill_usesrc_grp_next; /* Next ILL in the usesrc group */
1729 	boolean_t	ill_trace_disable;	/* True when alloc fails */
1730 	zoneid_t	ill_zoneid;
1731 	ip_stack_t	*ill_ipst;	/* Corresponds to a netstack_hold */
1732 	uint32_t	ill_dhcpinit;	/* IP_DHCPINIT_IFs for ill */
1733 	void		*ill_flownotify_mh; /* Tx flow ctl, mac cb handle */
1734 	uint_t		ill_ilm_cnt;    /* ilms referencing this ill */
1735 	uint_t		ill_ipallmulti_cnt; /* ip_join_allmulti() calls */
1736 	ilm_t		*ill_ipallmulti_ilm;
1737 
1738 	mblk_t		*ill_saved_ire_mp; /* Allocated for each extra IRE */
1739 					/* with ire_ill set so they can */
1740 					/* survive the ill going down and up. */
1741 	kmutex_t	ill_saved_ire_lock; /* Protects ill_saved_ire_mp, cnt */
1742 	uint_t		ill_saved_ire_cnt;	/* # entries */
1743 	struct arl_ill_common_s    *ill_common;
1744 	ire_t		*ill_ire_multicast; /* IRE_MULTICAST for ill */
1745 	clock_t		ill_defend_start;   /* start of 1 hour period */
1746 	uint_t		ill_defend_count;   /* # of announce/defends per ill */
1747 	/*
1748 	 * IPMP fields.
1749 	 */
1750 	ipmp_illgrp_t	*ill_grp;	/* IPMP group information */
1751 	list_node_t	ill_actnode; 	/* next active ill in group */
1752 	list_node_t	ill_grpnode;	/* next ill in group */
1753 	ipif_t		*ill_src_ipif;	/* source address selection rotor */
1754 	ipif_t		*ill_move_ipif;	/* ipif awaiting move to new ill */
1755 	boolean_t	ill_nom_cast;	/* nominated for mcast/bcast */
1756 	uint_t		ill_bound_cnt;	/* # of data addresses bound to ill */
1757 	ipif_t		*ill_bound_ipif; /* ipif chain bound to ill */
1758 	timeout_id_t	ill_refresh_tid; /* ill refresh retry timeout id */
1759 
1760 	uint32_t	ill_mrouter_cnt; /* mrouter allmulti joins */
1761 } ill_t;
1762 
1763 /*
1764  * ILL_FREE_OK() means that there are no incoming pointer references
1765  * to the ill.
1766  */
1767 #define	ILL_FREE_OK(ill)					\
1768 	((ill)->ill_ire_cnt == 0 && (ill)->ill_ilm_cnt == 0 &&	\
1769 	(ill)->ill_ncec_cnt == 0 && (ill)->ill_nce_cnt == 0)
1770 
1771 /*
1772  * An ipif/ill can be marked down only when the ire and ncec references
1773  * to that ipif/ill goes to zero. ILL_DOWN_OK() is a necessary condition
1774  * quiescence checks. See comments above IPIF_DOWN_OK for details
1775  * on why ires and nces are selectively considered for this macro.
1776  */
1777 #define	ILL_DOWN_OK(ill)					\
1778 	(ill->ill_ire_cnt == 0 && ill->ill_ncec_cnt == 0 &&	\
1779 	ill->ill_nce_cnt == 0)
1780 
1781 /*
1782  * The following table lists the protection levels of the various members
1783  * of the ill_t. Same notation as that used for ipif_t above is used.
1784  *
1785  *				Write			Read
1786  *
1787  * ill_ifptr			ill_g_lock + s		Write once
1788  * ill_rq			ipsq			Write once
1789  * ill_wq			ipsq			Write once
1790  *
1791  * ill_error			ipsq			None
1792  * ill_ipif			ill_g_lock + ipsq	ill_g_lock OR ipsq
1793  * ill_ipif_up_count		ill_lock + ipsq		ill_lock OR ipsq
1794  * ill_max_frag			ill_lock		ill_lock
1795  * ill_current_frag		ill_lock		ill_lock
1796  *
1797  * ill_name			ill_g_lock + ipsq	Write once
1798  * ill_name_length		ill_g_lock + ipsq	Write once
1799  * ill_ndd_name			ipsq			Write once
1800  * ill_net_type			ipsq			Write once
1801  * ill_ppa			ill_g_lock + ipsq	Write once
1802  * ill_sap			ipsq + down ill		Write once
1803  * ill_sap_length		ipsq + down ill		Write once
1804  * ill_phys_addr_length		ipsq + down ill		Write once
1805  *
1806  * ill_bcast_addr_length	ipsq			ipsq
1807  * ill_mactype			ipsq			ipsq
1808  * ill_frag_ptr			ipsq			ipsq
1809  *
1810  * ill_frag_timer_id		ill_lock		ill_lock
1811  * ill_frag_hash_tbl		ipsq			up ill
1812  * ill_ilm			ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1813  * ill_global_timer		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1814  * ill_mcast_type		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1815  * ill_mcast_v1_time		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1816  * ill_mcast_v2_time		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1817  * ill_mcast_v1_tset		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1818  * ill_mcast_v2_tset		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1819  * ill_mcast_rv			ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1820  * ill_mcast_qi			ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1821  *
1822  * ill_down_mp			ipsq			ipsq
1823  * ill_dlpi_deferred		ill_lock		ill_lock
1824  * ill_dlpi_pending		ipsq + ill_lock		ipsq or ill_lock or
1825  *							absence of ipsq writer.
1826  * ill_phys_addr_mp		ipsq + down ill		only when ill is up
1827  * ill_mcast_deferred		ill_lock		ill_lock
1828  * ill_phys_addr		ipsq + down ill		only when ill is up
1829  * ill_dest_addr_mp		ipsq + down ill		only when ill is up
1830  * ill_dest_addr		ipsq + down ill		only when ill is up
1831  *
1832  * ill_state_flags		ill_lock		ill_lock
1833  * exclusive bit flags		ipsq_t			ipsq_t
1834  * shared bit flags		ill_lock		ill_lock
1835  *
1836  * ill_muxid			ipsq			Not atomic
1837  *
1838  * ill_ipf_gen			Not atomic
1839  * ill_frag_count		atomics			atomics
1840  * ill_type			ipsq + down ill		only when ill is up
1841  * ill_dlpi_multicast_state	ill_lock		ill_lock
1842  * ill_dlpi_fastpath_state	ill_lock		ill_lock
1843  * ill_dlpi_capab_state		ipsq			ipsq
1844  * ill_max_hops			ipsq			Not atomic
1845  *
1846  * ill_mtu			ill_lock		None
1847  *
1848  * ill_user_mtu			ipsq + ill_lock		ill_lock
1849  * ill_reachable_time		ipsq + ill_lock		ill_lock
1850  * ill_reachable_retrans_time	ipsq + ill_lock		ill_lock
1851  * ill_max_buf			ipsq + ill_lock		ill_lock
1852  *
1853  * Next 2 fields need ill_lock because of the get ioctls. They should not
1854  * report partially updated results without executing in the ipsq.
1855  * ill_token			ipsq + ill_lock		ill_lock
1856  * ill_token_length		ipsq + ill_lock		ill_lock
1857  * ill_dest_token		ipsq + down ill		only when ill is up
1858  * ill_xmit_count		ipsq + down ill		write once
1859  * ill_ip6_mib			ipsq + down ill		only when ill is up
1860  * ill_icmp6_mib		ipsq + down ill		only when ill is up
1861  *
1862  * ill_phyint			ipsq, ill_g_lock, ill_lock	Any of them
1863  * ill_flags			ill_lock		ill_lock
1864  * ill_nd_lla_mp		ipsq + down ill		only when ill is up
1865  * ill_nd_lla			ipsq + down ill		only when ill is up
1866  * ill_nd_lla_len		ipsq + down ill		only when ill is up
1867  * ill_phys_addr_pend		ipsq + down ill		only when ill is up
1868  * ill_ifname_pending_err	ipsq			ipsq
1869  * ill_avl_byppa		ipsq, ill_g_lock	write once
1870  *
1871  * ill_fastpath_list		ill_lock		ill_lock
1872  * ill_refcnt			ill_lock		ill_lock
1873  * ill_ire_cnt			ill_lock		ill_lock
1874  * ill_cv			ill_lock		ill_lock
1875  * ill_ncec_cnt			ill_lock		ill_lock
1876  * ill_nce_cnt			ill_lock		ill_lock
1877  * ill_ilm_cnt			ill_lock		ill_lock
1878  * ill_src_ipif			ill_g_lock		ill_g_lock
1879  * ill_trace			ill_lock		ill_lock
1880  * ill_usesrc_grp_next		ill_g_usesrc_lock	ill_g_usesrc_lock
1881  * ill_dhcpinit			atomics			atomics
1882  * ill_flownotify_mh		write once		write once
1883  * ill_capab_pending_cnt	ipsq			ipsq
1884  * ill_ipallmulti_cnt		ill_lock		ill_lock
1885  * ill_ipallmulti_ilm		ill_lock		ill_lock
1886  * ill_saved_ire_mp		ill_saved_ire_lock	ill_saved_ire_lock
1887  * ill_saved_ire_cnt		ill_saved_ire_lock	ill_saved_ire_lock
1888  * ill_arl			???			???
1889  * ill_ire_multicast		ipsq + quiescent	none
1890  * ill_bound_ipif		ipsq			ipsq
1891  * ill_actnode			ipsq + ipmp_lock	ipsq OR ipmp_lock
1892  * ill_grpnode			ipsq + ill_g_lock	ipsq OR ill_g_lock
1893  * ill_src_ipif			ill_g_lock		ill_g_lock
1894  * ill_move_ipif		ipsq			ipsq
1895  * ill_nom_cast			ipsq			ipsq OR advisory
1896  * ill_refresh_tid		ill_lock		ill_lock
1897  * ill_grp (for IPMP ill)	write once		write once
1898  * ill_grp (for underlying ill)	ipsq + ill_g_lock	ipsq OR ill_g_lock
1899  * ill_mrouter_cnt		atomics			atomics
1900  *
1901  * NOTE: It's OK to make heuristic decisions on an underlying interface
1902  *	 by using IS_UNDER_IPMP() or comparing ill_grp's raw pointer value.
1903  */
1904 
1905 /*
1906  * For ioctl restart mechanism see ip_reprocess_ioctl()
1907  */
1908 struct ip_ioctl_cmd_s;
1909 
1910 typedef	int (*ifunc_t)(ipif_t *, struct sockaddr_in *, queue_t *, mblk_t *,
1911     struct ip_ioctl_cmd_s *, void *);
1912 
1913 typedef struct ip_ioctl_cmd_s {
1914 	int	ipi_cmd;
1915 	size_t	ipi_copyin_size;
1916 	uint_t	ipi_flags;
1917 	uint_t	ipi_cmd_type;
1918 	ifunc_t	ipi_func;
1919 	ifunc_t	ipi_func_restart;
1920 } ip_ioctl_cmd_t;
1921 
1922 /*
1923  * ipi_cmd_type:
1924  *
1925  * IF_CMD		1	old style ifreq cmd
1926  * LIF_CMD		2	new style lifreq cmd
1927  * ARP_CMD		3	arpreq cmd
1928  * XARP_CMD		4	xarpreq cmd
1929  * MSFILT_CMD		5	multicast source filter cmd
1930  * MISC_CMD		6	misc cmd (not a more specific one above)
1931  */
1932 
1933 enum { IF_CMD = 1, LIF_CMD, ARP_CMD, XARP_CMD, MSFILT_CMD, MISC_CMD };
1934 
1935 #define	IPI_DONTCARE	0	/* For ioctl encoded values that don't matter */
1936 
1937 /* Flag values in ipi_flags */
1938 #define	IPI_PRIV	0x1	/* Root only command */
1939 #define	IPI_MODOK	0x2	/* Permitted on mod instance of IP */
1940 #define	IPI_WR		0x4	/* Need to grab writer access */
1941 #define	IPI_GET_CMD	0x8	/* branch to mi_copyout on success */
1942 /*	unused		0x10	*/
1943 #define	IPI_NULL_BCONT	0x20	/* ioctl has not data and hence no b_cont */
1944 
1945 extern ip_ioctl_cmd_t	ip_ndx_ioctl_table[];
1946 extern ip_ioctl_cmd_t	ip_misc_ioctl_table[];
1947 extern int ip_ndx_ioctl_count;
1948 extern int ip_misc_ioctl_count;
1949 
1950 /* Passed down by ARP to IP during I_PLINK/I_PUNLINK */
1951 typedef struct ipmx_s {
1952 	char	ipmx_name[LIFNAMSIZ];		/* if name */
1953 	uint_t
1954 		ipmx_arpdev_stream : 1,		/* This is the arp stream */
1955 		ipmx_notused : 31;
1956 } ipmx_t;
1957 
1958 /*
1959  * State for detecting if a driver supports certain features.
1960  * Support for DL_ENABMULTI_REQ uses ill_dlpi_multicast_state.
1961  * Support for DLPI M_DATA fastpath uses ill_dlpi_fastpath_state.
1962  */
1963 #define	IDS_UNKNOWN	0	/* No DLPI request sent */
1964 #define	IDS_INPROGRESS	1	/* DLPI request sent */
1965 #define	IDS_OK		2	/* DLPI request completed successfully */
1966 #define	IDS_FAILED	3	/* DLPI request failed */
1967 
1968 /* Support for DL_CAPABILITY_REQ uses ill_dlpi_capab_state. */
1969 enum {
1970 	IDCS_UNKNOWN,
1971 	IDCS_PROBE_SENT,
1972 	IDCS_OK,
1973 	IDCS_RESET_SENT,
1974 	IDCS_RENEG,
1975 	IDCS_FAILED
1976 };
1977 
1978 /* Named Dispatch Parameter Management Structure */
1979 typedef struct ipparam_s {
1980 	uint_t	ip_param_min;
1981 	uint_t	ip_param_max;
1982 	uint_t	ip_param_value;
1983 	char	*ip_param_name;
1984 } ipparam_t;
1985 
1986 /* Extended NDP Management Structure */
1987 typedef struct ipndp_s {
1988 	ndgetf_t	ip_ndp_getf;
1989 	ndsetf_t	ip_ndp_setf;
1990 	caddr_t		ip_ndp_data;
1991 	char		*ip_ndp_name;
1992 } ipndp_t;
1993 
1994 /* IXA Notification types */
1995 typedef enum {
1996 	IXAN_LSO,	/* LSO capability change */
1997 	IXAN_PMTU,	/* PMTU change */
1998 	IXAN_ZCOPY	/* ZEROCOPY capability change */
1999 } ixa_notify_type_t;
2000 
2001 typedef uint_t ixa_notify_arg_t;
2002 
2003 typedef	void	(*ixa_notify_t)(void *, ip_xmit_attr_t *ixa, ixa_notify_type_t,
2004     ixa_notify_arg_t);
2005 
2006 /*
2007  * Attribute flags that are common to the transmit and receive attributes
2008  */
2009 #define	IAF_IS_IPV4		0x80000000	/* ipsec_*_v4 */
2010 #define	IAF_TRUSTED_ICMP	0x40000000	/* ipsec_*_icmp_loopback */
2011 #define	IAF_NO_LOOP_ZONEID_SET	0x20000000	/* Zone that shouldn't have */
2012 						/* a copy */
2013 #define	IAF_LOOPBACK_COPY	0x10000000	/* For multi and broadcast */
2014 
2015 #define	IAF_MASK		0xf0000000	/* Flags that are common */
2016 
2017 /*
2018  * Transmit side attributes used between the transport protocols and IP as
2019  * well as inside IP. It is also used to cache information in the conn_t i.e.
2020  * replaces conn_ire and the IPsec caching in the conn_t.
2021  */
2022 struct ip_xmit_attr_s {
2023 	iaflags_t	ixa_flags;	/* IXAF_*. See below */
2024 
2025 	uint32_t	ixa_free_flags;	/* IXA_FREE_*. See below */
2026 	uint32_t	ixa_refcnt;	/* Using atomics */
2027 
2028 	/*
2029 	 * Always initialized independently of ixa_flags settings.
2030 	 * Used by ip_xmit so we keep them up front for cache locality.
2031 	 */
2032 	uint32_t	ixa_xmit_hint;	/* For ECMP and GLD TX ring fanout */
2033 	uint_t		ixa_pktlen;	/* Always set. For frag and stats */
2034 	zoneid_t	ixa_zoneid;	/* Assumed always set */
2035 
2036 	/* Always set for conn_ip_output(); might be stale */
2037 	/*
2038 	 * Since TCP keeps the conn_t around past the process going away
2039 	 * we need to use the "notr" (e.g, ire_refhold_notr) for ixa_ire,
2040 	 * ixa_nce, and ixa_dce.
2041 	 */
2042 	ire_t		*ixa_ire;	/* Forwarding table entry */
2043 	uint_t		ixa_ire_generation;
2044 	nce_t		*ixa_nce;	/* Neighbor cache entry */
2045 	dce_t		*ixa_dce;	/* Destination cache entry */
2046 	uint_t		ixa_dce_generation;
2047 	uint_t		ixa_src_generation;	/* If IXAF_VERIFY_SOURCE */
2048 
2049 	uint32_t	ixa_src_preferences;	/* prefs for src addr select */
2050 	uint32_t	ixa_pmtu;		/* IXAF_VERIFY_PMTU */
2051 
2052 	/* Set by ULP if IXAF_VERIFY_PMTU; otherwise set by IP */
2053 	uint32_t	ixa_fragsize;
2054 
2055 	int8_t		ixa_use_min_mtu;	/* IXAF_USE_MIN_MTU values */
2056 
2057 	pfirepostfrag_t	ixa_postfragfn;		/* Set internally in IP */
2058 
2059 	in6_addr_t	ixa_nexthop_v6;		/* IXAF_NEXTHOP_SET */
2060 #define	ixa_nexthop_v4	V4_PART_OF_V6(ixa_nexthop_v6)
2061 
2062 	zoneid_t	ixa_no_loop_zoneid;	/* IXAF_NO_LOOP_ZONEID_SET */
2063 
2064 	uint_t		ixa_scopeid;		/* For IPv6 link-locals */
2065 
2066 	uint_t		ixa_broadcast_ttl;	/* IXAF_BROACAST_TTL_SET */
2067 
2068 	uint_t		ixa_multicast_ttl;	/* Assumed set for multicast */
2069 	uint_t		ixa_multicast_ifindex;	/* Assumed set for multicast */
2070 	ipaddr_t	ixa_multicast_ifaddr;	/* Assumed set for multicast */
2071 
2072 	int		ixa_raw_cksum_offset;	/* If IXAF_SET_RAW_CKSUM */
2073 
2074 	uint32_t	ixa_ident;		/* For IPv6 fragment header */
2075 
2076 	/*
2077 	 * Cached LSO information.
2078 	 */
2079 	ill_lso_capab_t	ixa_lso_capab;		/* Valid when IXAF_LSO_CAPAB */
2080 
2081 	uint64_t	ixa_ipsec_policy_gen;	/* Generation from iph_gen */
2082 	/*
2083 	 * The following IPsec fields are only initialized when
2084 	 * IXAF_IPSEC_SECURE is set. Otherwise they contain garbage.
2085 	 */
2086 	ipsec_latch_t	*ixa_ipsec_latch;	/* Just the ids */
2087 	struct ipsa_s 	*ixa_ipsec_ah_sa;	/* Hard reference SA for AH */
2088 	struct ipsa_s 	*ixa_ipsec_esp_sa;	/* Hard reference SA for ESP */
2089 	struct ipsec_policy_s 	*ixa_ipsec_policy; /* why are we here? */
2090 	struct ipsec_action_s	*ixa_ipsec_action; /* For reflected packets */
2091 	ipsa_ref_t	ixa_ipsec_ref[2];	/* Soft reference to SA */
2092 						/* 0: ESP, 1: AH */
2093 
2094 	/*
2095 	 * The selectors here are potentially different than the SPD rule's
2096 	 * selectors, and we need to have both available for IKEv2.
2097 	 *
2098 	 * NOTE: "Source" and "Dest" are w.r.t. outbound datagrams.  Ports can
2099 	 *	 be zero, and the protocol number is needed to make the ports
2100 	 *	 significant.
2101 	 */
2102 	uint16_t ixa_ipsec_src_port;	/* Source port number of d-gram. */
2103 	uint16_t ixa_ipsec_dst_port;	/* Destination port number of d-gram. */
2104 	uint8_t  ixa_ipsec_icmp_type;	/* ICMP type of d-gram */
2105 	uint8_t  ixa_ipsec_icmp_code;	/* ICMP code of d-gram */
2106 
2107 	sa_family_t ixa_ipsec_inaf;	/* Inner address family */
2108 #define	IXA_MAX_ADDRLEN 4	/* Max addr len. (in 32-bit words) */
2109 	uint32_t ixa_ipsec_insrc[IXA_MAX_ADDRLEN];	/* Inner src address */
2110 	uint32_t ixa_ipsec_indst[IXA_MAX_ADDRLEN];	/* Inner dest address */
2111 	uint8_t  ixa_ipsec_insrcpfx;	/* Inner source prefix */
2112 	uint8_t  ixa_ipsec_indstpfx;	/* Inner destination prefix */
2113 
2114 	uint8_t ixa_ipsec_proto;	/* IP protocol number for d-gram. */
2115 
2116 	/* Always initialized independently of ixa_flags settings */
2117 	uint_t		ixa_ifindex;	/* Assumed always set */
2118 	uint16_t	ixa_ip_hdr_length; /* Points to ULP header */
2119 	uint8_t		ixa_protocol;	/* Protocol number for ULP cksum */
2120 	ts_label_t	*ixa_tsl;	/* Always set. NULL if not TX */
2121 	ip_stack_t	*ixa_ipst;	/* Always set */
2122 	uint32_t	ixa_extra_ident; /* Set if LSO */
2123 	cred_t		*ixa_cred;	/* For getpeerucred */
2124 	pid_t		ixa_cpid;	/* For getpeerucred */
2125 
2126 #ifdef DEBUG
2127 	kthread_t	*ixa_curthread;	/* For serialization assert */
2128 #endif
2129 	squeue_t	*ixa_sqp;	/* Set from conn_sqp as a hint */
2130 	uintptr_t	ixa_cookie;	/* cookie to use for tx flow control */
2131 
2132 	/*
2133 	 * Must be set by ULP if any of IXAF_VERIFY_LSO, IXAF_VERIFY_PMTU,
2134 	 * or IXAF_VERIFY_ZCOPY is set.
2135 	 */
2136 	ixa_notify_t	ixa_notify;	/* Registered upcall notify function */
2137 	void		*ixa_notify_cookie; /* ULP cookie for ixa_notify */
2138 };
2139 
2140 /*
2141  * Flags to indicate which transmit attributes are set.
2142  * Split into "xxx_SET" ones which indicate that the "xxx" field it set, and
2143  * single flags.
2144  */
2145 #define	IXAF_REACH_CONF		0x00000001	/* Reachability confirmation */
2146 #define	IXAF_BROADCAST_TTL_SET	0x00000002	/* ixa_broadcast_ttl valid */
2147 #define	IXAF_SET_SOURCE		0x00000004	/* Replace if broadcast */
2148 #define	IXAF_USE_MIN_MTU	0x00000008	/* IPV6_USE_MIN_MTU */
2149 
2150 #define	IXAF_DONTFRAG		0x00000010	/* IP*_DONTFRAG */
2151 #define	IXAF_VERIFY_PMTU	0x00000020	/* ixa_pmtu/ixa_fragsize set */
2152 #define	IXAF_PMTU_DISCOVERY	0x00000040	/* Create/use PMTU state */
2153 #define	IXAF_MULTICAST_LOOP	0x00000080	/* IP_MULTICAST_LOOP */
2154 
2155 #define	IXAF_IPSEC_SECURE	0x00000100	/* Need IPsec processing */
2156 #define	IXAF_UCRED_TSL		0x00000200	/* ixa_tsl from SCM_UCRED */
2157 #define	IXAF_DONTROUTE		0x00000400	/* SO_DONTROUTE */
2158 #define	IXAF_NO_IPSEC		0x00000800	/* Ignore policy */
2159 
2160 #define	IXAF_PMTU_TOO_SMALL	0x00001000	/* PMTU too small */
2161 #define	IXAF_SET_ULP_CKSUM	0x00002000	/* Calculate ULP checksum */
2162 #define	IXAF_VERIFY_SOURCE	0x00004000	/* Check that source is ok */
2163 #define	IXAF_NEXTHOP_SET	0x00008000	/* ixa_nexthop set */
2164 
2165 #define	IXAF_PMTU_IPV4_DF	0x00010000	/* Set IPv4 DF */
2166 #define	IXAF_NO_DEV_FLOW_CTL	0x00020000	/* Protocol needs no flow ctl */
2167 #define	IXAF_NO_TTL_CHANGE	0x00040000	/* Internal to IP */
2168 #define	IXAF_IPV6_ADD_FRAGHDR	0x00080000	/* Add fragment header */
2169 
2170 #define	IXAF_IPSEC_TUNNEL	0x00100000	/* Tunnel mode */
2171 #define	IXAF_NO_PFHOOK		0x00200000	/* Skip xmit pfhook */
2172 #define	IXAF_NO_TRACE		0x00400000	/* When back from ARP/ND */
2173 #define	IXAF_SCOPEID_SET	0x00800000	/* ixa_scopeid set */
2174 
2175 #define	IXAF_MULTIRT_MULTICAST	0x01000000	/* MULTIRT for multicast */
2176 #define	IXAF_NO_HW_CKSUM	0x02000000	/* Force software cksum */
2177 #define	IXAF_SET_RAW_CKSUM	0x04000000	/* Use ixa_raw_cksum_offset */
2178 #define	IXAF_IPSEC_GLOBAL_POLICY 0x08000000	/* Policy came from global */
2179 
2180 /* Note the following uses bits 0x10000000 through 0x80000000 */
2181 #define	IXAF_IS_IPV4		IAF_IS_IPV4
2182 #define	IXAF_TRUSTED_ICMP	IAF_TRUSTED_ICMP
2183 #define	IXAF_NO_LOOP_ZONEID_SET	IAF_NO_LOOP_ZONEID_SET
2184 #define	IXAF_LOOPBACK_COPY	IAF_LOOPBACK_COPY
2185 
2186 /* Note: use the upper 32 bits */
2187 #define	IXAF_VERIFY_LSO		0x100000000	/* Check LSO capability */
2188 #define	IXAF_LSO_CAPAB		0x200000000	/* Capable of LSO */
2189 #define	IXAF_VERIFY_ZCOPY	0x400000000	/* Check Zero Copy capability */
2190 #define	IXAF_ZCOPY_CAPAB	0x800000000	/* Capable of ZEROCOPY */
2191 
2192 /*
2193  * The normal flags for sending packets e.g., icmp errors
2194  */
2195 #define	IXAF_BASIC_SIMPLE_V4	(IXAF_SET_ULP_CKSUM | IXAF_IS_IPV4)
2196 #define	IXAF_BASIC_SIMPLE_V6	(IXAF_SET_ULP_CKSUM)
2197 
2198 /*
2199  * Normally these fields do not have a hold. But in some cases they do, for
2200  * instance when we've gone through ip_*_attr_to/from_mblk.
2201  * We use ixa_free_flags to indicate that they have a hold and need to be
2202  * released on cleanup.
2203  */
2204 #define	IXA_FREE_CRED		0x00000001	/* ixa_cred needs to be rele */
2205 #define	IXA_FREE_TSL		0x00000002	/* ixa_tsl needs to be rele */
2206 
2207 /*
2208  * Simplistic way to set the ixa_xmit_hint for locally generated traffic
2209  * and forwarded traffic. The shift amount are based on the size of the
2210  * structs to discard the low order bits which don't have much if any variation
2211  * (coloring in kmem_cache_alloc might provide some variation).
2212  *
2213  * Basing the locally generated hint on the address of the conn_t means that
2214  * the packets from the same socket/connection do not get reordered.
2215  * Basing the hint for forwarded traffic on the ill_ring_t means that
2216  * packets from the same NIC+ring are likely to use the same outbound ring
2217  * hence we get low contention on the ring in the transmitting driver.
2218  */
2219 #define	CONN_TO_XMIT_HINT(connp)	((uint32_t)(((uintptr_t)connp) >> 11))
2220 #define	ILL_RING_TO_XMIT_HINT(ring)	((uint32_t)(((uintptr_t)ring) >> 7))
2221 
2222 /*
2223  * IP set Destination Flags used by function ip_set_destination,
2224  * ip_attr_connect, and conn_connect.
2225  */
2226 #define	IPDF_ALLOW_MCBC		0x1	/* Allow multi/broadcast */
2227 #define	IPDF_VERIFY_DST		0x2	/* Verify destination addr */
2228 #define	IPDF_SELECT_SRC		0x4	/* Select source address */
2229 #define	IPDF_LSO		0x8	/* Try LSO */
2230 #define	IPDF_IPSEC		0x10	/* Set IPsec policy */
2231 #define	IPDF_ZONE_IS_GLOBAL	0x20	/* From conn_zone_is_global */
2232 #define	IPDF_ZCOPY		0x40	/* Try ZEROCOPY */
2233 #define	IPDF_UNIQUE_DCE		0x80	/* Get a per-destination DCE */
2234 
2235 /*
2236  * Receive side attributes used between the transport protocols and IP as
2237  * well as inside IP.
2238  */
2239 struct ip_recv_attr_s {
2240 	iaflags_t	ira_flags;	/* See below */
2241 
2242 	uint32_t	ira_free_flags;	/* IRA_FREE_*. See below */
2243 
2244 	/*
2245 	 * This is a hint for TCP SYN packets.
2246 	 * Always initialized independently of ira_flags settings
2247 	 */
2248 	squeue_t	*ira_sqp;
2249 	ill_rx_ring_t	*ira_ring;	/* Internal to IP */
2250 
2251 	/* For ip_accept_tcp when IRAF_TARGET_SQP is set */
2252 	squeue_t	*ira_target_sqp;
2253 	mblk_t		*ira_target_sqp_mp;
2254 
2255 	/* Always initialized independently of ira_flags settings */
2256 	uint32_t	ira_xmit_hint;	/* For ECMP and GLD TX ring fanout */
2257 	zoneid_t	ira_zoneid;	/* ALL_ZONES unless local delivery */
2258 	uint_t		ira_pktlen;	/* Always set. For frag and stats */
2259 	uint16_t	ira_ip_hdr_length; /* Points to ULP header */
2260 	uint8_t		ira_protocol;	/* Protocol number for ULP cksum */
2261 	uint_t		ira_rifindex;	/* Received ifindex */
2262 	uint_t		ira_ruifindex;	/* Received upper ifindex */
2263 	ts_label_t	*ira_tsl;	/* Always set. NULL if not TX */
2264 	/*
2265 	 * ira_rill and ira_ill is set inside IP, but not when conn_recv is
2266 	 * called; ULPs should use ira_ruifindex instead.
2267 	 */
2268 	ill_t		*ira_rill;	/* ill where packet came */
2269 	ill_t		*ira_ill;	/* ill where IP address hosted */
2270 	cred_t		*ira_cred;	/* For getpeerucred */
2271 	pid_t		ira_cpid;	/* For getpeerucred */
2272 
2273 	/* Used when IRAF_VERIFIED_SRC is set; this source was ok */
2274 	ipaddr_t	ira_verified_src;
2275 
2276 	/*
2277 	 * The following IPsec fields are only initialized when
2278 	 * IRAF_IPSEC_SECURE is set. Otherwise they contain garbage.
2279 	 */
2280 	struct ipsec_action_s *ira_ipsec_action; /* how we made it in.. */
2281 	struct ipsa_s 	*ira_ipsec_ah_sa;	/* SA for AH */
2282 	struct ipsa_s 	*ira_ipsec_esp_sa;	/* SA for ESP */
2283 
2284 	ipaddr_t	ira_mroute_tunnel;	/* IRAF_MROUTE_TUNNEL_SET */
2285 
2286 	zoneid_t	ira_no_loop_zoneid;	/* IRAF_NO_LOOP_ZONEID_SET */
2287 
2288 	uint32_t	ira_esp_udp_ports;	/* IRAF_ESP_UDP_PORTS */
2289 
2290 	/*
2291 	 * For IP_RECVSLLA and ip_ndp_conflict/find_solicitation.
2292 	 * Same size as max for sockaddr_dl
2293 	 */
2294 #define	IRA_L2SRC_SIZE	244
2295 	uint8_t		ira_l2src[IRA_L2SRC_SIZE];	/* If IRAF_L2SRC_SET */
2296 
2297 	/*
2298 	 * Local handle that we use to do lazy setting of ira_l2src.
2299 	 * We defer setting l2src until needed but we do before any
2300 	 * ip_input pullupmsg or copymsg.
2301 	 */
2302 	struct mac_header_info_s *ira_mhip;	/* Could be NULL */
2303 };
2304 
2305 /*
2306  * Flags to indicate which receive attributes are set.
2307  */
2308 #define	IRAF_SYSTEM_LABELED	0x00000001	/* is_system_labeled() */
2309 #define	IRAF_IPV4_OPTIONS	0x00000002	/* Performance */
2310 #define	IRAF_MULTICAST		0x00000004	/* Was multicast at L3 */
2311 #define	IRAF_BROADCAST		0x00000008	/* Was broadcast at L3 */
2312 #define	IRAF_MULTIBROADCAST	(IRAF_MULTICAST|IRAF_BROADCAST)
2313 
2314 #define	IRAF_LOOPBACK		0x00000010	/* Looped back by IP */
2315 #define	IRAF_VERIFY_IP_CKSUM	0x00000020	/* Need to verify IP */
2316 #define	IRAF_VERIFY_ULP_CKSUM	0x00000040	/* Need to verify TCP,UDP,etc */
2317 #define	IRAF_SCTP_CSUM_ERR	0x00000080	/* sctp pkt has failed chksum */
2318 
2319 #define	IRAF_IPSEC_SECURE	0x00000100	/* Passed AH and/or ESP */
2320 #define	IRAF_DHCP_UNICAST	0x00000200
2321 #define	IRAF_IPSEC_DECAPS	0x00000400	/* Was packet decapsulated */
2322 					/* from a matching inner packet? */
2323 #define	IRAF_TARGET_SQP		0x00000800	/* ira_target_sqp is set */
2324 #define	IRAF_VERIFIED_SRC	0x00001000	/* ira_verified_src set */
2325 #define	IRAF_RSVP		0x00002000	/* RSVP packet for rsvpd */
2326 #define	IRAF_MROUTE_TUNNEL_SET	0x00004000	/* From ip_mroute_decap */
2327 #define	IRAF_PIM_REGISTER	0x00008000	/* From register_mforward */
2328 
2329 #define	IRAF_TX_MAC_EXEMPTABLE	0x00010000	/* Allow MAC_EXEMPT readdown */
2330 #define	IRAF_TX_SHARED_ADDR	0x00020000	/* Arrived on ALL_ZONES addr */
2331 #define	IRAF_ESP_UDP_PORTS	0x00040000	/* NAT-traversal packet */
2332 #define	IRAF_NO_HW_CKSUM	0x00080000	/* Force software cksum */
2333 
2334 #define	IRAF_ICMP_ERROR		0x00100000	/* Send to conn_recvicmp */
2335 #define	IRAF_ROUTER_ALERT	0x00200000	/* IPv6 router alert */
2336 #define	IRAF_L2SRC_SET		0x00400000	/* ira_l2src has been set */
2337 #define	IRAF_L2SRC_LOOPBACK	0x00800000	/* Came from us */
2338 
2339 #define	IRAF_L2DST_MULTICAST	0x01000000	/* Multicast at L2 */
2340 #define	IRAF_L2DST_BROADCAST	0x02000000	/* Broadcast at L2 */
2341 /* Unused 0x04000000 */
2342 /* Unused 0x08000000 */
2343 
2344 /* Below starts with 0x10000000 */
2345 #define	IRAF_IS_IPV4		IAF_IS_IPV4
2346 #define	IRAF_TRUSTED_ICMP	IAF_TRUSTED_ICMP
2347 #define	IRAF_NO_LOOP_ZONEID_SET	IAF_NO_LOOP_ZONEID_SET
2348 #define	IRAF_LOOPBACK_COPY	IAF_LOOPBACK_COPY
2349 
2350 /*
2351  * Normally these fields do not have a hold. But in some cases they do, for
2352  * instance when we've gone through ip_*_attr_to/from_mblk.
2353  * We use ira_free_flags to indicate that they have a hold and need to be
2354  * released on cleanup.
2355  */
2356 #define	IRA_FREE_CRED		0x00000001	/* ira_cred needs to be rele */
2357 #define	IRA_FREE_TSL		0x00000002	/* ira_tsl needs to be rele */
2358 
2359 /*
2360  * Optional destination cache entry for path MTU information,
2361  * and ULP metrics.
2362  */
2363 struct dce_s {
2364 	uint_t		dce_generation;	/* Changed since cached? */
2365 	uint_t		dce_flags;	/* See below */
2366 	uint_t		dce_ipversion;	/* IPv4/IPv6 version */
2367 	uint32_t	dce_pmtu;	/* Path MTU if DCEF_PMTU */
2368 	uint32_t	dce_ident;	/* Per destination IP ident. */
2369 	iulp_t		dce_uinfo;	/* Metrics if DCEF_UINFO */
2370 
2371 	struct dce_s	*dce_next;
2372 	struct dce_s	**dce_ptpn;
2373 	struct dcb_s	*dce_bucket;
2374 
2375 	union {
2376 		in6_addr_t	dceu_v6addr;
2377 		ipaddr_t	dceu_v4addr;
2378 	} dce_u;
2379 #define	dce_v4addr	dce_u.dceu_v4addr
2380 #define	dce_v6addr	dce_u.dceu_v6addr
2381 	/* Note that for IPv6+IPMP we use the ifindex for the upper interface */
2382 	uint_t		dce_ifindex;	/* For IPv6 link-locals */
2383 
2384 	kmutex_t	dce_lock;
2385 	uint_t		dce_refcnt;
2386 	uint64_t	dce_last_change_time;	/* Path MTU. In seconds */
2387 
2388 	ip_stack_t	*dce_ipst;	/* Does not have a netstack_hold */
2389 };
2390 
2391 /*
2392  * Values for dce_generation.
2393  *
2394  * If a DCE has DCE_GENERATION_CONDEMNED, the last dce_refrele should delete
2395  * it.
2396  *
2397  * DCE_GENERATION_VERIFY is never stored in dce_generation but it is
2398  * stored in places that cache DCE (such as ixa_dce_generation).
2399  * It is used as a signal that the cache is stale and needs to be reverified.
2400  */
2401 #define	DCE_GENERATION_CONDEMNED	0
2402 #define	DCE_GENERATION_VERIFY		1
2403 #define	DCE_GENERATION_INITIAL		2
2404 #define	DCE_IS_CONDEMNED(dce) \
2405 	((dce)->dce_generation == DCE_GENERATION_CONDEMNED)
2406 
2407 
2408 /*
2409  * Values for ips_src_generation.
2410  *
2411  * SRC_GENERATION_VERIFY is never stored in ips_src_generation but it is
2412  * stored in places that cache IREs (ixa_src_generation). It is used as a
2413  * signal that the cache is stale and needs to be reverified.
2414  */
2415 #define	SRC_GENERATION_VERIFY		0
2416 #define	SRC_GENERATION_INITIAL		1
2417 
2418 /*
2419  * The kernel stores security attributes of all gateways in a database made
2420  * up of one or more tsol_gcdb_t elements.  Each tsol_gcdb_t contains the
2421  * security-related credentials of the gateway.  More than one gateways may
2422  * share entries in the database.
2423  *
2424  * The tsol_gc_t structure represents the gateway to credential association,
2425  * and refers to an entry in the database.  One or more tsol_gc_t entities are
2426  * grouped together to form one or more tsol_gcgrp_t, each representing the
2427  * list of security attributes specific to the gateway.  A gateway may be
2428  * associated with at most one credentials group.
2429  */
2430 struct tsol_gcgrp_s;
2431 
2432 extern uchar_t	ip6opt_ls;	/* TX IPv6 enabler */
2433 
2434 /*
2435  * Gateway security credential record.
2436  */
2437 typedef struct tsol_gcdb_s {
2438 	uint_t		gcdb_refcnt;	/* reference count */
2439 	struct rtsa_s	gcdb_attr;	/* security attributes */
2440 #define	gcdb_mask	gcdb_attr.rtsa_mask
2441 #define	gcdb_doi	gcdb_attr.rtsa_doi
2442 #define	gcdb_slrange	gcdb_attr.rtsa_slrange
2443 } tsol_gcdb_t;
2444 
2445 /*
2446  * Gateway to credential association.
2447  */
2448 typedef struct tsol_gc_s {
2449 	uint_t		gc_refcnt;	/* reference count */
2450 	struct tsol_gcgrp_s *gc_grp;	/* pointer to group */
2451 	struct tsol_gc_s *gc_prev;	/* previous in list */
2452 	struct tsol_gc_s *gc_next;	/* next in list */
2453 	tsol_gcdb_t	*gc_db;		/* pointer to actual credentials */
2454 } tsol_gc_t;
2455 
2456 /*
2457  * Gateway credentials group address.
2458  */
2459 typedef struct tsol_gcgrp_addr_s {
2460 	int		ga_af;		/* address family */
2461 	in6_addr_t	ga_addr;	/* IPv4 mapped or IPv6 address */
2462 } tsol_gcgrp_addr_t;
2463 
2464 /*
2465  * Gateway credentials group.
2466  */
2467 typedef struct tsol_gcgrp_s {
2468 	uint_t		gcgrp_refcnt;	/* reference count */
2469 	krwlock_t	gcgrp_rwlock;	/* lock to protect following */
2470 	uint_t		gcgrp_count;	/* number of credentials */
2471 	tsol_gc_t	*gcgrp_head;	/* first credential in list */
2472 	tsol_gc_t	*gcgrp_tail;	/* last credential in list */
2473 	tsol_gcgrp_addr_t gcgrp_addr;	/* next-hop gateway address */
2474 } tsol_gcgrp_t;
2475 
2476 extern kmutex_t gcgrp_lock;
2477 
2478 #define	GC_REFRELE(p) {				\
2479 	ASSERT((p)->gc_grp != NULL);		\
2480 	rw_enter(&(p)->gc_grp->gcgrp_rwlock, RW_WRITER); \
2481 	ASSERT((p)->gc_refcnt > 0);		\
2482 	if (--((p)->gc_refcnt) == 0)		\
2483 		gc_inactive(p);			\
2484 	else					\
2485 		rw_exit(&(p)->gc_grp->gcgrp_rwlock); \
2486 }
2487 
2488 #define	GCGRP_REFHOLD(p) {			\
2489 	mutex_enter(&gcgrp_lock);		\
2490 	++((p)->gcgrp_refcnt);			\
2491 	ASSERT((p)->gcgrp_refcnt != 0);		\
2492 	mutex_exit(&gcgrp_lock);		\
2493 }
2494 
2495 #define	GCGRP_REFRELE(p) {			\
2496 	mutex_enter(&gcgrp_lock);		\
2497 	ASSERT((p)->gcgrp_refcnt > 0);		\
2498 	if (--((p)->gcgrp_refcnt) == 0)		\
2499 		gcgrp_inactive(p);		\
2500 	ASSERT(MUTEX_HELD(&gcgrp_lock));	\
2501 	mutex_exit(&gcgrp_lock);		\
2502 }
2503 
2504 /*
2505  * IRE gateway security attributes structure, pointed to by tsol_ire_gw_secattr
2506  */
2507 struct tsol_tnrhc;
2508 
2509 struct tsol_ire_gw_secattr_s {
2510 	kmutex_t	igsa_lock;	/* lock to protect following */
2511 	struct tsol_tnrhc *igsa_rhc;	/* host entry for gateway */
2512 	tsol_gc_t	*igsa_gc;	/* for prefix IREs */
2513 };
2514 
2515 void irb_refrele_ftable(irb_t *);
2516 
2517 extern struct kmem_cache *rt_entry_cache;
2518 
2519 typedef struct ire4 {
2520 	ipaddr_t ire4_mask;		/* Mask for matching this IRE. */
2521 	ipaddr_t ire4_addr;		/* Address this IRE represents. */
2522 	ipaddr_t ire4_gateway_addr;	/* Gateway including for IRE_ONLINK */
2523 	ipaddr_t ire4_setsrc_addr;	/* RTF_SETSRC */
2524 } ire4_t;
2525 
2526 typedef struct ire6 {
2527 	in6_addr_t ire6_mask;		/* Mask for matching this IRE. */
2528 	in6_addr_t ire6_addr;		/* Address this IRE represents. */
2529 	in6_addr_t ire6_gateway_addr;	/* Gateway including for IRE_ONLINK */
2530 	in6_addr_t ire6_setsrc_addr;	/* RTF_SETSRC */
2531 } ire6_t;
2532 
2533 typedef union ire_addr {
2534 	ire6_t	ire6_u;
2535 	ire4_t	ire4_u;
2536 } ire_addr_u_t;
2537 
2538 /*
2539  * Internet Routing Entry
2540  * When we have multiple identical IREs we logically add them by manipulating
2541  * ire_identical_ref and ire_delete first decrements
2542  * that and when it reaches 1 we know it is the last IRE.
2543  * "identical" is defined as being the same for:
2544  * ire_addr, ire_netmask, ire_gateway, ire_ill, ire_zoneid, and ire_type
2545  * For instance, multiple IRE_BROADCASTs for the same subnet number are
2546  * viewed as identical, and so are the IRE_INTERFACEs when there are
2547  * multiple logical interfaces (on the same ill) with the same subnet prefix.
2548  */
2549 struct ire_s {
2550 	struct	ire_s	*ire_next;	/* The hash chain must be first. */
2551 	struct	ire_s	**ire_ptpn;	/* Pointer to previous next. */
2552 	uint32_t	ire_refcnt;	/* Number of references */
2553 	ill_t		*ire_ill;
2554 	uint32_t	ire_identical_ref; /* IRE_INTERFACE, IRE_BROADCAST */
2555 	uchar_t		ire_ipversion;	/* IPv4/IPv6 version */
2556 	ushort_t	ire_type;	/* Type of IRE */
2557 	uint_t		ire_generation;	/* Generation including CONDEMNED */
2558 	uint_t	ire_ib_pkt_count;	/* Inbound packets for ire_addr */
2559 	uint_t	ire_ob_pkt_count;	/* Outbound packets to ire_addr */
2560 	time_t	ire_create_time;	/* Time (in secs) IRE was created. */
2561 	uint32_t	ire_flags;	/* flags related to route (RTF_*) */
2562 	/*
2563 	 * ire_testhidden is TRUE for INTERFACE IREs of IS_UNDER_IPMP(ill)
2564 	 * interfaces
2565 	 */
2566 	boolean_t	ire_testhidden;
2567 	pfirerecv_t	ire_recvfn;	/* Receive side handling */
2568 	pfiresend_t	ire_sendfn;	/* Send side handling */
2569 	pfirepostfrag_t	ire_postfragfn;	/* Bottom end of send handling */
2570 
2571 	uint_t		ire_masklen;	/* # bits in ire_mask{,_v6} */
2572 	ire_addr_u_t	ire_u;		/* IPv4/IPv6 address info. */
2573 
2574 	irb_t		*ire_bucket;	/* Hash bucket when ire_ptphn is set */
2575 	kmutex_t	ire_lock;
2576 	clock_t		ire_last_used_time;	/* For IRE_LOCAL reception */
2577 	tsol_ire_gw_secattr_t *ire_gw_secattr; /* gateway security attributes */
2578 	zoneid_t	ire_zoneid;
2579 
2580 	/*
2581 	 * Cached information of where to send packets that match this route.
2582 	 * The ire_dep_* information is used to determine when ire_nce_cache
2583 	 * needs to be updated.
2584 	 * ire_nce_cache is the fastpath for the Neighbor Cache Entry
2585 	 * for IPv6; arp info for IPv4
2586 	 * Since this is a cache setup and torn down independently of
2587 	 * applications we need to use nce_ref{rele,hold}_notr for it.
2588 	 */
2589 	nce_t		*ire_nce_cache;
2590 
2591 	/*
2592 	 * Quick check whether the ire_type and ire_masklen indicates
2593 	 * that the IRE can have ire_nce_cache set i.e., whether it is
2594 	 * IRE_ONLINK and for a single destination.
2595 	 */
2596 	boolean_t	ire_nce_capable;
2597 
2598 	/*
2599 	 * Dependency tracking so we can safely cache IRE and NCE pointers
2600 	 * in offlink and onlink IREs.
2601 	 * These are locked under the ips_ire_dep_lock rwlock. Write held
2602 	 * when modifying the linkage.
2603 	 * ire_dep_parent (Also chain towards IRE for nexthop)
2604 	 * ire_dep_parent_generation: ire_generation of ire_dep_parent
2605 	 * ire_dep_children (From parent to first child)
2606 	 * ire_dep_sib_next (linked list of siblings)
2607 	 * ire_dep_sib_ptpn (linked list of siblings)
2608 	 *
2609 	 * The parent has a ire_refhold on each child, and each child has
2610 	 * an ire_refhold on its parent.
2611 	 * Since ire_dep_parent is a cache setup and torn down independently of
2612 	 * applications we need to use ire_ref{rele,hold}_notr for it.
2613 	 */
2614 	ire_t		*ire_dep_parent;
2615 	ire_t		*ire_dep_children;
2616 	ire_t		*ire_dep_sib_next;
2617 	ire_t		**ire_dep_sib_ptpn;	/* Pointer to previous next */
2618 	uint_t		ire_dep_parent_generation;
2619 
2620 	uint_t		ire_badcnt;	/* Number of times ND_UNREACHABLE */
2621 	uint64_t	ire_last_badcnt;	/* In seconds */
2622 
2623 	/* ire_defense* and ire_last_used_time are only used on IRE_LOCALs */
2624 	uint_t		ire_defense_count;	/* number of ARP conflicts */
2625 	uint_t		ire_defense_time;	/* last time defended (secs) */
2626 
2627 	boolean_t	ire_trace_disable;	/* True when alloc fails */
2628 	ip_stack_t	*ire_ipst;	/* Does not have a netstack_hold */
2629 	iulp_t		ire_metrics;
2630 };
2631 
2632 /* IPv4 compatibility macros */
2633 #define	ire_mask		ire_u.ire4_u.ire4_mask
2634 #define	ire_addr		ire_u.ire4_u.ire4_addr
2635 #define	ire_gateway_addr	ire_u.ire4_u.ire4_gateway_addr
2636 #define	ire_setsrc_addr		ire_u.ire4_u.ire4_setsrc_addr
2637 
2638 #define	ire_mask_v6		ire_u.ire6_u.ire6_mask
2639 #define	ire_addr_v6		ire_u.ire6_u.ire6_addr
2640 #define	ire_gateway_addr_v6	ire_u.ire6_u.ire6_gateway_addr
2641 #define	ire_setsrc_addr_v6	ire_u.ire6_u.ire6_setsrc_addr
2642 
2643 /*
2644  * Values for ire_generation.
2645  *
2646  * If an IRE is marked with IRE_IS_CONDEMNED, the last walker of
2647  * the bucket should delete this IRE from this bucket.
2648  *
2649  * IRE_GENERATION_VERIFY is never stored in ire_generation but it is
2650  * stored in places that cache IREs (such as ixa_ire_generation and
2651  * ire_dep_parent_generation). It is used as a signal that the cache is
2652  * stale and needs to be reverified.
2653  */
2654 #define	IRE_GENERATION_CONDEMNED	0
2655 #define	IRE_GENERATION_VERIFY		1
2656 #define	IRE_GENERATION_INITIAL		2
2657 #define	IRE_IS_CONDEMNED(ire) \
2658 	((ire)->ire_generation == IRE_GENERATION_CONDEMNED)
2659 
2660 /* Convenient typedefs for sockaddrs */
2661 typedef	struct sockaddr_in	sin_t;
2662 typedef	struct sockaddr_in6	sin6_t;
2663 
2664 /* Name/Value Descriptor. */
2665 typedef struct nv_s {
2666 	uint64_t nv_value;
2667 	char	*nv_name;
2668 } nv_t;
2669 
2670 #define	ILL_FRAG_HASH(s, i) \
2671 	((ntohl(s) ^ ((i) ^ ((i) >> 8))) % ILL_FRAG_HASH_TBL_COUNT)
2672 
2673 /*
2674  * The MAX number of allowed fragmented packets per hash bucket
2675  * calculation is based on the most common mtu size of 1500. This limit
2676  * will work well for other mtu sizes as well.
2677  */
2678 #define	COMMON_IP_MTU 1500
2679 #define	MAX_FRAG_MIN 10
2680 #define	MAX_FRAG_PKTS(ipst)	\
2681 	MAX(MAX_FRAG_MIN, (2 * (ipst->ips_ip_reass_queue_bytes / \
2682 	    (COMMON_IP_MTU * ILL_FRAG_HASH_TBL_COUNT))))
2683 
2684 /*
2685  * Maximum dups allowed per packet.
2686  */
2687 extern uint_t ip_max_frag_dups;
2688 
2689 /*
2690  * Per-packet information for received packets and transmitted.
2691  * Used by the transport protocols when converting between the packet
2692  * and ancillary data and socket options.
2693  *
2694  * Note: This private data structure and related IPPF_* constant
2695  * definitions are exposed to enable compilation of some debugging tools
2696  * like lsof which use struct tcp_t in <inet/tcp.h>. This is intended to be
2697  * a temporary hack and long term alternate interfaces should be defined
2698  * to support the needs of such tools and private definitions moved to
2699  * private headers.
2700  */
2701 struct ip_pkt_s {
2702 	uint_t		ipp_fields;		/* Which fields are valid */
2703 	in6_addr_t	ipp_addr;		/* pktinfo src/dst addr */
2704 #define	ipp_addr_v4	V4_PART_OF_V6(ipp_addr)
2705 	uint_t		ipp_unicast_hops;	/* IPV6_UNICAST_HOPS, IP_TTL */
2706 	uint_t		ipp_hoplimit;		/* IPV6_HOPLIMIT */
2707 	uint_t		ipp_hopoptslen;
2708 	uint_t		ipp_rthdrdstoptslen;
2709 	uint_t		ipp_rthdrlen;
2710 	uint_t		ipp_dstoptslen;
2711 	uint_t		ipp_fraghdrlen;
2712 	ip6_hbh_t	*ipp_hopopts;
2713 	ip6_dest_t	*ipp_rthdrdstopts;
2714 	ip6_rthdr_t	*ipp_rthdr;
2715 	ip6_dest_t	*ipp_dstopts;
2716 	ip6_frag_t	*ipp_fraghdr;
2717 	uint8_t		ipp_tclass;		/* IPV6_TCLASS */
2718 	uint8_t		ipp_type_of_service;	/* IP_TOS */
2719 	uint_t		ipp_ipv4_options_len;	/* Len of IPv4 options */
2720 	uint8_t		*ipp_ipv4_options;	/* Ptr to IPv4 options */
2721 	uint_t		ipp_label_len_v4;	/* Len of TX label for IPv4 */
2722 	uint8_t		*ipp_label_v4;		/* TX label for IPv4 */
2723 	uint_t		ipp_label_len_v6;	/* Len of TX label for IPv6 */
2724 	uint8_t		*ipp_label_v6;		/* TX label for IPv6 */
2725 };
2726 typedef struct ip_pkt_s ip_pkt_t;
2727 
2728 extern void ip_pkt_free(ip_pkt_t *);	/* free storage inside ip_pkt_t */
2729 extern ipaddr_t ip_pkt_source_route_v4(const ip_pkt_t *);
2730 extern in6_addr_t *ip_pkt_source_route_v6(const ip_pkt_t *);
2731 extern int ip_pkt_copy(ip_pkt_t *, ip_pkt_t *, int);
2732 extern void ip_pkt_source_route_reverse_v4(ip_pkt_t *);
2733 
2734 /* ipp_fields values */
2735 #define	IPPF_ADDR		0x0001	/* Part of in6_pktinfo: src/dst addr */
2736 #define	IPPF_HOPLIMIT		0x0002	/* Overrides unicast and multicast */
2737 #define	IPPF_TCLASS		0x0004	/* Overrides class in sin6_flowinfo */
2738 
2739 #define	IPPF_HOPOPTS		0x0010	/* ipp_hopopts set */
2740 #define	IPPF_RTHDR		0x0020	/* ipp_rthdr set */
2741 #define	IPPF_RTHDRDSTOPTS	0x0040	/* ipp_rthdrdstopts set */
2742 #define	IPPF_DSTOPTS		0x0080	/* ipp_dstopts set */
2743 
2744 #define	IPPF_IPV4_OPTIONS	0x0100	/* ipp_ipv4_options set */
2745 #define	IPPF_LABEL_V4		0x0200	/* ipp_label_v4 set */
2746 #define	IPPF_LABEL_V6		0x0400	/* ipp_label_v6 set */
2747 
2748 #define	IPPF_FRAGHDR		0x0800	/* Used for IPsec receive side */
2749 
2750 /*
2751  * Data structure which is passed to conn_opt_get/set.
2752  * The conn_t is included even though it can be inferred from queue_t.
2753  * setsockopt and getsockopt use conn_ixa and conn_xmit_ipp. However,
2754  * when handling ancillary data we use separate ixa and ipps.
2755  */
2756 typedef struct conn_opt_arg_s {
2757 	conn_t		*coa_connp;
2758 	ip_xmit_attr_t	*coa_ixa;
2759 	ip_pkt_t	*coa_ipp;
2760 	boolean_t	coa_ancillary;	/* Ancillary data and not setsockopt */
2761 	uint_t		coa_changed;	/* See below */
2762 } conn_opt_arg_t;
2763 
2764 /*
2765  * Flags for what changed.
2766  * If we want to be more efficient in the future we can have more fine
2767  * grained flags e.g., a flag for just IP_TOS changing.
2768  * For now we either call ip_set_destination (for "route changed")
2769  * and/or conn_build_hdr_template/conn_prepend_hdr (for "header changed").
2770  */
2771 #define	COA_HEADER_CHANGED	0x0001
2772 #define	COA_ROUTE_CHANGED	0x0002
2773 #define	COA_RCVBUF_CHANGED	0x0004	/* SO_RCVBUF */
2774 #define	COA_SNDBUF_CHANGED	0x0008	/* SO_SNDBUF */
2775 #define	COA_WROFF_CHANGED	0x0010	/* Header size changed */
2776 #define	COA_ICMP_BIND_NEEDED	0x0020
2777 #define	COA_OOBINLINE_CHANGED	0x0040
2778 
2779 #define	TCP_PORTS_OFFSET	0
2780 #define	UDP_PORTS_OFFSET	0
2781 
2782 /*
2783  * lookups return the ill/ipif only if the flags are clear OR Iam writer.
2784  * ill / ipif lookup functions increment the refcnt on the ill / ipif only
2785  * after calling these macros. This ensures that the refcnt on the ipif or
2786  * ill will eventually drop down to zero.
2787  */
2788 #define	ILL_LOOKUP_FAILED	1	/* Used as error code */
2789 #define	IPIF_LOOKUP_FAILED	2	/* Used as error code */
2790 
2791 #define	ILL_CAN_LOOKUP(ill)						\
2792 	(!((ill)->ill_state_flags & ILL_CONDEMNED) ||			\
2793 	IAM_WRITER_ILL(ill))
2794 
2795 #define	ILL_IS_CONDEMNED(ill)	\
2796 	((ill)->ill_state_flags & ILL_CONDEMNED)
2797 
2798 #define	IPIF_CAN_LOOKUP(ipif)	\
2799 	(!((ipif)->ipif_state_flags & IPIF_CONDEMNED) || \
2800 	IAM_WRITER_IPIF(ipif))
2801 
2802 #define	IPIF_IS_CONDEMNED(ipif)	\
2803 	((ipif)->ipif_state_flags & IPIF_CONDEMNED)
2804 
2805 #define	IPIF_IS_CHANGING(ipif)	\
2806 	((ipif)->ipif_state_flags & IPIF_CHANGING)
2807 
2808 /* Macros used to assert that this thread is a writer */
2809 #define	IAM_WRITER_IPSQ(ipsq)	((ipsq)->ipsq_xop->ipx_writer == curthread)
2810 #define	IAM_WRITER_ILL(ill)	IAM_WRITER_IPSQ((ill)->ill_phyint->phyint_ipsq)
2811 #define	IAM_WRITER_IPIF(ipif)	IAM_WRITER_ILL((ipif)->ipif_ill)
2812 
2813 /*
2814  * Grab ill locks in the proper order. The order is highest addressed
2815  * ill is locked first.
2816  */
2817 #define	GRAB_ILL_LOCKS(ill_1, ill_2)				\
2818 {								\
2819 	if ((ill_1) > (ill_2)) {				\
2820 		if (ill_1 != NULL)				\
2821 			mutex_enter(&(ill_1)->ill_lock);	\
2822 		if (ill_2 != NULL)				\
2823 			mutex_enter(&(ill_2)->ill_lock);	\
2824 	} else {						\
2825 		if (ill_2 != NULL)				\
2826 			mutex_enter(&(ill_2)->ill_lock);	\
2827 		if (ill_1 != NULL && ill_1 != ill_2)		\
2828 			mutex_enter(&(ill_1)->ill_lock);	\
2829 	}							\
2830 }
2831 
2832 #define	RELEASE_ILL_LOCKS(ill_1, ill_2)		\
2833 {						\
2834 	if (ill_1 != NULL)			\
2835 		mutex_exit(&(ill_1)->ill_lock);	\
2836 	if (ill_2 != NULL && ill_2 != ill_1)	\
2837 		mutex_exit(&(ill_2)->ill_lock);	\
2838 }
2839 
2840 /* Get the other protocol instance ill */
2841 #define	ILL_OTHER(ill)						\
2842 	((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :	\
2843 	    (ill)->ill_phyint->phyint_illv6)
2844 
2845 /* ioctl command info: Ioctl properties extracted and stored in here */
2846 typedef struct cmd_info_s
2847 {
2848 	ipif_t  *ci_ipif;	/* ipif associated with [l]ifreq ioctl's */
2849 	sin_t	*ci_sin;	/* the sin struct passed down */
2850 	sin6_t	*ci_sin6;	/* the sin6_t struct passed down */
2851 	struct lifreq *ci_lifr;	/* the lifreq struct passed down */
2852 } cmd_info_t;
2853 
2854 extern struct kmem_cache *ire_cache;
2855 
2856 extern ipaddr_t	ip_g_all_ones;
2857 
2858 extern uint_t	ip_loopback_mtu;	/* /etc/system */
2859 extern uint_t	ip_loopback_mtuplus;
2860 extern uint_t	ip_loopback_mtu_v6plus;
2861 
2862 extern vmem_t *ip_minor_arena_sa;
2863 extern vmem_t *ip_minor_arena_la;
2864 
2865 /*
2866  * ip_g_forward controls IP forwarding.  It takes two values:
2867  *	0: IP_FORWARD_NEVER	Don't forward packets ever.
2868  *	1: IP_FORWARD_ALWAYS	Forward packets for elsewhere.
2869  *
2870  * RFC1122 says there must be a configuration switch to control forwarding,
2871  * but that the default MUST be to not forward packets ever.  Implicit
2872  * control based on configuration of multiple interfaces MUST NOT be
2873  * implemented (Section 3.1).  SunOS 4.1 did provide the "automatic" capability
2874  * and, in fact, it was the default.  That capability is now provided in the
2875  * /etc/rc2.d/S69inet script.
2876  */
2877 
2878 #define	ips_ip_respond_to_address_mask_broadcast ips_param_arr[0].ip_param_value
2879 #define	ips_ip_g_resp_to_echo_bcast	ips_param_arr[1].ip_param_value
2880 #define	ips_ip_g_resp_to_echo_mcast	ips_param_arr[2].ip_param_value
2881 #define	ips_ip_g_resp_to_timestamp	ips_param_arr[3].ip_param_value
2882 #define	ips_ip_g_resp_to_timestamp_bcast ips_param_arr[4].ip_param_value
2883 #define	ips_ip_g_send_redirects		ips_param_arr[5].ip_param_value
2884 #define	ips_ip_g_forward_directed_bcast	ips_param_arr[6].ip_param_value
2885 #define	ips_ip_mrtdebug			ips_param_arr[7].ip_param_value
2886 #define	ips_ip_ire_reclaim_fraction	ips_param_arr[8].ip_param_value
2887 #define	ips_ip_nce_reclaim_fraction	ips_param_arr[9].ip_param_value
2888 #define	ips_ip_dce_reclaim_fraction	ips_param_arr[10].ip_param_value
2889 #define	ips_ip_def_ttl			ips_param_arr[11].ip_param_value
2890 #define	ips_ip_forward_src_routed	ips_param_arr[12].ip_param_value
2891 #define	ips_ip_wroff_extra		ips_param_arr[13].ip_param_value
2892 #define	ips_ip_pathmtu_interval		ips_param_arr[14].ip_param_value
2893 #define	ips_ip_icmp_return		ips_param_arr[15].ip_param_value
2894 #define	ips_ip_path_mtu_discovery	ips_param_arr[16].ip_param_value
2895 #define	ips_ip_pmtu_min			ips_param_arr[17].ip_param_value
2896 #define	ips_ip_ignore_redirect		ips_param_arr[18].ip_param_value
2897 #define	ips_ip_arp_icmp_error		ips_param_arr[19].ip_param_value
2898 #define	ips_ip_broadcast_ttl		ips_param_arr[20].ip_param_value
2899 #define	ips_ip_icmp_err_interval	ips_param_arr[21].ip_param_value
2900 #define	ips_ip_icmp_err_burst		ips_param_arr[22].ip_param_value
2901 #define	ips_ip_reass_queue_bytes	ips_param_arr[23].ip_param_value
2902 #define	ips_ip_strict_dst_multihoming	ips_param_arr[24].ip_param_value
2903 #define	ips_ip_addrs_per_if		ips_param_arr[25].ip_param_value
2904 #define	ips_ipsec_override_persocket_policy ips_param_arr[26].ip_param_value
2905 #define	ips_icmp_accept_clear_messages	ips_param_arr[27].ip_param_value
2906 #define	ips_igmp_accept_clear_messages	ips_param_arr[28].ip_param_value
2907 
2908 /* IPv6 configuration knobs */
2909 #define	ips_delay_first_probe_time	ips_param_arr[29].ip_param_value
2910 #define	ips_max_unicast_solicit		ips_param_arr[30].ip_param_value
2911 #define	ips_ipv6_def_hops		ips_param_arr[31].ip_param_value
2912 #define	ips_ipv6_icmp_return		ips_param_arr[32].ip_param_value
2913 #define	ips_ipv6_forward_src_routed	ips_param_arr[33].ip_param_value
2914 #define	ips_ipv6_resp_echo_mcast	ips_param_arr[34].ip_param_value
2915 #define	ips_ipv6_send_redirects		ips_param_arr[35].ip_param_value
2916 #define	ips_ipv6_ignore_redirect	ips_param_arr[36].ip_param_value
2917 #define	ips_ipv6_strict_dst_multihoming	ips_param_arr[37].ip_param_value
2918 #define	ips_src_check			ips_param_arr[38].ip_param_value
2919 #define	ips_ipsec_policy_log_interval	ips_param_arr[39].ip_param_value
2920 #define	ips_pim_accept_clear_messages	ips_param_arr[40].ip_param_value
2921 #define	ips_ip_ndp_unsolicit_interval	ips_param_arr[41].ip_param_value
2922 #define	ips_ip_ndp_unsolicit_count	ips_param_arr[42].ip_param_value
2923 #define	ips_ipv6_ignore_home_address_opt ips_param_arr[43].ip_param_value
2924 
2925 /* Misc IP configuration knobs */
2926 #define	ips_ip_policy_mask		ips_param_arr[44].ip_param_value
2927 #define	ips_ip_ecmp_behavior		ips_param_arr[45].ip_param_value
2928 #define	ips_ip_multirt_ttl  		ips_param_arr[46].ip_param_value
2929 #define	ips_ip_ire_badcnt_lifetime	ips_param_arr[47].ip_param_value
2930 #define	ips_ip_max_temp_idle		ips_param_arr[48].ip_param_value
2931 #define	ips_ip_max_temp_defend		ips_param_arr[49].ip_param_value
2932 #define	ips_ip_max_defend		ips_param_arr[50].ip_param_value
2933 #define	ips_ip_defend_interval		ips_param_arr[51].ip_param_value
2934 #define	ips_ip_dup_recovery		ips_param_arr[52].ip_param_value
2935 #define	ips_ip_restrict_interzone_loopback ips_param_arr[53].ip_param_value
2936 #define	ips_ip_lso_outbound		ips_param_arr[54].ip_param_value
2937 #define	ips_igmp_max_version		ips_param_arr[55].ip_param_value
2938 #define	ips_mld_max_version		ips_param_arr[56].ip_param_value
2939 #define	ips_ipv6_drop_inbound_icmpv6	ips_param_arr[57].ip_param_value
2940 #define	ips_arp_probe_delay		ips_param_arr[58].ip_param_value
2941 #define	ips_arp_fastprobe_delay		ips_param_arr[59].ip_param_value
2942 #define	ips_arp_probe_interval		ips_param_arr[60].ip_param_value
2943 #define	ips_arp_fastprobe_interval	ips_param_arr[61].ip_param_value
2944 #define	ips_arp_probe_count		ips_param_arr[62].ip_param_value
2945 #define	ips_arp_fastprobe_count		ips_param_arr[63].ip_param_value
2946 #define	ips_ipv4_dad_announce_interval	ips_param_arr[64].ip_param_value
2947 #define	ips_ipv6_dad_announce_interval	ips_param_arr[65].ip_param_value
2948 #define	ips_arp_defend_interval		ips_param_arr[66].ip_param_value
2949 #define	ips_arp_defend_rate		ips_param_arr[67].ip_param_value
2950 #define	ips_ndp_defend_interval		ips_param_arr[68].ip_param_value
2951 #define	ips_ndp_defend_rate		ips_param_arr[69].ip_param_value
2952 #define	ips_arp_defend_period		ips_param_arr[70].ip_param_value
2953 #define	ips_ndp_defend_period		ips_param_arr[71].ip_param_value
2954 #define	ips_ipv4_icmp_return_pmtu	ips_param_arr[72].ip_param_value
2955 #define	ips_ipv6_icmp_return_pmtu	ips_param_arr[73].ip_param_value
2956 #define	ips_ip_arp_publish_count	ips_param_arr[74].ip_param_value
2957 #define	ips_ip_arp_publish_interval	ips_param_arr[75].ip_param_value
2958 
2959 extern int	dohwcksum;	/* use h/w cksum if supported by the h/w */
2960 #ifdef ZC_TEST
2961 extern int	noswcksum;
2962 #endif
2963 
2964 extern char	ipif_loopback_name[];
2965 
2966 extern nv_t	*ire_nv_tbl;
2967 
2968 extern struct module_info ip_mod_info;
2969 
2970 #define	HOOKS4_INTERESTED_PHYSICAL_IN(ipst)	\
2971 	((ipst)->ips_ip4_physical_in_event.he_interested)
2972 #define	HOOKS6_INTERESTED_PHYSICAL_IN(ipst)	\
2973 	((ipst)->ips_ip6_physical_in_event.he_interested)
2974 #define	HOOKS4_INTERESTED_PHYSICAL_OUT(ipst)	\
2975 	((ipst)->ips_ip4_physical_out_event.he_interested)
2976 #define	HOOKS6_INTERESTED_PHYSICAL_OUT(ipst)	\
2977 	((ipst)->ips_ip6_physical_out_event.he_interested)
2978 #define	HOOKS4_INTERESTED_FORWARDING(ipst)	\
2979 	((ipst)->ips_ip4_forwarding_event.he_interested)
2980 #define	HOOKS6_INTERESTED_FORWARDING(ipst)	\
2981 	((ipst)->ips_ip6_forwarding_event.he_interested)
2982 #define	HOOKS4_INTERESTED_LOOPBACK_IN(ipst)	\
2983 	((ipst)->ips_ip4_loopback_in_event.he_interested)
2984 #define	HOOKS6_INTERESTED_LOOPBACK_IN(ipst)	\
2985 	((ipst)->ips_ip6_loopback_in_event.he_interested)
2986 #define	HOOKS4_INTERESTED_LOOPBACK_OUT(ipst)	\
2987 	((ipst)->ips_ip4_loopback_out_event.he_interested)
2988 #define	HOOKS6_INTERESTED_LOOPBACK_OUT(ipst)	\
2989 	((ipst)->ips_ip6_loopback_out_event.he_interested)
2990 /*
2991  * Hooks marcos used inside of ip
2992  * The callers use the above INTERESTED macros first, hence
2993  * the he_interested check is superflous.
2994  */
2995 #define	FW_HOOKS(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst, _err) \
2996 	if ((_hook).he_interested) {					\
2997 		hook_pkt_event_t info;					\
2998 									\
2999 		_NOTE(CONSTCOND)					\
3000 		ASSERT((_ilp != NULL) || (_olp != NULL));		\
3001 									\
3002 		FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);		\
3003 		FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);		\
3004 		info.hpe_protocol = ipst->ips_ipv4_net_data;		\
3005 		info.hpe_hdr = _iph;					\
3006 		info.hpe_mp = &(_fm);					\
3007 		info.hpe_mb = _m;					\
3008 		info.hpe_flags = _llm;					\
3009 		_err = hook_run(ipst->ips_ipv4_net_data->netd_hooks,	\
3010 		    _event, (hook_data_t)&info);			\
3011 		if (_err != 0) {					\
3012 			ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3013 			    (_hook).he_name, (void *)_fm, (void *)_m));	\
3014 			if (_fm != NULL) {				\
3015 				freemsg(_fm);				\
3016 				_fm = NULL;				\
3017 			}						\
3018 			_iph = NULL;					\
3019 			_m = NULL;					\
3020 		} else {						\
3021 			_iph = info.hpe_hdr;				\
3022 			_m = info.hpe_mb;				\
3023 		}							\
3024 	}
3025 
3026 #define	FW_HOOKS6(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst, _err) \
3027 	if ((_hook).he_interested) {					\
3028 		hook_pkt_event_t info;					\
3029 									\
3030 		_NOTE(CONSTCOND)					\
3031 		ASSERT((_ilp != NULL) || (_olp != NULL));		\
3032 									\
3033 		FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);		\
3034 		FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);		\
3035 		info.hpe_protocol = ipst->ips_ipv6_net_data;		\
3036 		info.hpe_hdr = _iph;					\
3037 		info.hpe_mp = &(_fm);					\
3038 		info.hpe_mb = _m;					\
3039 		info.hpe_flags = _llm;					\
3040 		_err = hook_run(ipst->ips_ipv6_net_data->netd_hooks,	\
3041 		    _event, (hook_data_t)&info);			\
3042 		if (_err != 0) {					\
3043 			ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3044 			    (_hook).he_name, (void *)_fm, (void *)_m));	\
3045 			if (_fm != NULL) {				\
3046 				freemsg(_fm);				\
3047 				_fm = NULL;				\
3048 			}						\
3049 			_iph = NULL;					\
3050 			_m = NULL;					\
3051 		} else {						\
3052 			_iph = info.hpe_hdr;				\
3053 			_m = info.hpe_mb;				\
3054 		}							\
3055 	}
3056 
3057 #define	FW_SET_ILL_INDEX(fp, ill)					\
3058 	_NOTE(CONSTCOND)						\
3059 	if ((ill) == NULL || (ill)->ill_phyint == NULL) {		\
3060 		(fp) = 0;						\
3061 		_NOTE(CONSTCOND)					\
3062 	} else if (IS_UNDER_IPMP(ill)) {				\
3063 		(fp) = ipmp_ill_get_ipmp_ifindex(ill);			\
3064 	} else {							\
3065 		(fp) = (ill)->ill_phyint->phyint_ifindex;		\
3066 	}
3067 
3068 /*
3069  * Network byte order macros
3070  */
3071 #ifdef	_BIG_ENDIAN
3072 #define	N_IN_CLASSA_NET		IN_CLASSA_NET
3073 #define	N_IN_CLASSD_NET		IN_CLASSD_NET
3074 #define	N_INADDR_UNSPEC_GROUP	INADDR_UNSPEC_GROUP
3075 #define	N_IN_LOOPBACK_NET	(ipaddr_t)0x7f000000U
3076 #else /* _BIG_ENDIAN */
3077 #define	N_IN_CLASSA_NET		(ipaddr_t)0x000000ffU
3078 #define	N_IN_CLASSD_NET		(ipaddr_t)0x000000f0U
3079 #define	N_INADDR_UNSPEC_GROUP	(ipaddr_t)0x000000e0U
3080 #define	N_IN_LOOPBACK_NET	(ipaddr_t)0x0000007fU
3081 #endif /* _BIG_ENDIAN */
3082 #define	CLASSD(addr)	(((addr) & N_IN_CLASSD_NET) == N_INADDR_UNSPEC_GROUP)
3083 #define	CLASSE(addr)	(((addr) & N_IN_CLASSD_NET) == N_IN_CLASSD_NET)
3084 #define	IP_LOOPBACK_ADDR(addr)			\
3085 	(((addr) & N_IN_CLASSA_NET == N_IN_LOOPBACK_NET))
3086 
3087 extern int	ip_debug;
3088 extern uint_t	ip_thread_data;
3089 extern krwlock_t ip_thread_rwlock;
3090 extern list_t	ip_thread_list;
3091 
3092 #ifdef IP_DEBUG
3093 #include <sys/debug.h>
3094 #include <sys/promif.h>
3095 
3096 #define	ip0dbg(a)	printf a
3097 #define	ip1dbg(a)	if (ip_debug > 2) printf a
3098 #define	ip2dbg(a)	if (ip_debug > 3) printf a
3099 #define	ip3dbg(a)	if (ip_debug > 4) printf a
3100 #else
3101 #define	ip0dbg(a)	/* */
3102 #define	ip1dbg(a)	/* */
3103 #define	ip2dbg(a)	/* */
3104 #define	ip3dbg(a)	/* */
3105 #endif	/* IP_DEBUG */
3106 
3107 /* Default MAC-layer address string length for mac_colon_addr */
3108 #define	MAC_STR_LEN	128
3109 
3110 struct	mac_header_info_s;
3111 
3112 extern void	ill_frag_timer(void *);
3113 extern ill_t	*ill_first(int, int, ill_walk_context_t *, ip_stack_t *);
3114 extern ill_t	*ill_next(ill_walk_context_t *, ill_t *);
3115 extern void	ill_frag_timer_start(ill_t *);
3116 extern void	ill_nic_event_dispatch(ill_t *, lif_if_t, nic_event_t,
3117     nic_event_data_t, size_t);
3118 extern mblk_t	*ip_carve_mp(mblk_t **, ssize_t);
3119 extern mblk_t	*ip_dlpi_alloc(size_t, t_uscalar_t);
3120 extern mblk_t	*ip_dlnotify_alloc(uint_t, uint_t);
3121 extern char	*ip_dot_addr(ipaddr_t, char *);
3122 extern const char *mac_colon_addr(const uint8_t *, size_t, char *, size_t);
3123 extern void	ip_lwput(queue_t *, mblk_t *);
3124 extern boolean_t icmp_err_rate_limit(ip_stack_t *);
3125 extern void	icmp_frag_needed(mblk_t *, int, ip_recv_attr_t *);
3126 extern mblk_t	*icmp_inbound_v4(mblk_t *, ip_recv_attr_t *);
3127 extern void	icmp_time_exceeded(mblk_t *, uint8_t, ip_recv_attr_t *);
3128 extern void	icmp_unreachable(mblk_t *, uint8_t, ip_recv_attr_t *);
3129 extern boolean_t ip_ipsec_policy_inherit(conn_t *, conn_t *, ip_recv_attr_t *);
3130 extern void	*ip_pullup(mblk_t *, ssize_t, ip_recv_attr_t *);
3131 extern void	ip_setl2src(mblk_t *, ip_recv_attr_t *, ill_t *);
3132 extern mblk_t	*ip_check_and_align_header(mblk_t *, uint_t, ip_recv_attr_t *);
3133 extern mblk_t	*ip_check_length(mblk_t *, uchar_t *, ssize_t, uint_t, uint_t,
3134     ip_recv_attr_t *);
3135 extern mblk_t	*ip_check_optlen(mblk_t *, ipha_t *, uint_t, uint_t,
3136     ip_recv_attr_t *);
3137 extern mblk_t	*ip_fix_dbref(mblk_t *, ip_recv_attr_t *);
3138 extern uint_t	ip_cksum(mblk_t *, int, uint32_t);
3139 extern int	ip_close(queue_t *, int);
3140 extern uint16_t	ip_csum_hdr(ipha_t *);
3141 extern void	ip_forward_xmit_v4(nce_t *, ill_t *, mblk_t *, ipha_t *,
3142     ip_recv_attr_t *, uint32_t, uint32_t);
3143 extern boolean_t ip_forward_options(mblk_t *, ipha_t *, ill_t *,
3144     ip_recv_attr_t *);
3145 extern int	ip_fragment_v4(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
3146     uint32_t, zoneid_t, zoneid_t, pfirepostfrag_t postfragfn,
3147     uintptr_t *cookie);
3148 extern void	ip_proto_not_sup(mblk_t *, ip_recv_attr_t *);
3149 extern void	ip_ire_g_fini(void);
3150 extern void	ip_ire_g_init(void);
3151 extern void	ip_ire_fini(ip_stack_t *);
3152 extern void	ip_ire_init(ip_stack_t *);
3153 extern void	ip_mdata_to_mhi(ill_t *, mblk_t *, struct mac_header_info_s *);
3154 extern int	ip_openv4(queue_t *q, dev_t *devp, int flag, int sflag,
3155 		    cred_t *credp);
3156 extern int	ip_openv6(queue_t *q, dev_t *devp, int flag, int sflag,
3157 		    cred_t *credp);
3158 extern int	ip_reassemble(mblk_t *, ipf_t *, uint_t, boolean_t, ill_t *,
3159     size_t);
3160 extern void	ip_rput(queue_t *, mblk_t *);
3161 extern void	ip_input(ill_t *, ill_rx_ring_t *, mblk_t *,
3162     struct mac_header_info_s *);
3163 extern void	ip_input_v6(ill_t *, ill_rx_ring_t *, mblk_t *,
3164     struct mac_header_info_s *);
3165 extern mblk_t	*ip_input_common_v4(ill_t *, ill_rx_ring_t *, mblk_t *,
3166     struct mac_header_info_s *, squeue_t *, mblk_t **, uint_t *);
3167 extern mblk_t	*ip_input_common_v6(ill_t *, ill_rx_ring_t *, mblk_t *,
3168     struct mac_header_info_s *, squeue_t *, mblk_t **, uint_t *);
3169 extern void	ill_input_full_v4(mblk_t *, void *, void *,
3170     ip_recv_attr_t *, rtc_t *);
3171 extern void	ill_input_short_v4(mblk_t *, void *, void *,
3172     ip_recv_attr_t *, rtc_t *);
3173 extern void	ill_input_full_v6(mblk_t *, void *, void *,
3174     ip_recv_attr_t *, rtc_t *);
3175 extern void	ill_input_short_v6(mblk_t *, void *, void *,
3176     ip_recv_attr_t *, rtc_t *);
3177 extern ipaddr_t	ip_input_options(ipha_t *, ipaddr_t, mblk_t *,
3178     ip_recv_attr_t *, int *);
3179 extern boolean_t ip_input_local_options(mblk_t *, ipha_t *, ip_recv_attr_t *);
3180 extern mblk_t	*ip_input_fragment(mblk_t *, ipha_t *, ip_recv_attr_t *);
3181 extern mblk_t	*ip_input_fragment_v6(mblk_t *, ip6_t *, ip6_frag_t *, uint_t,
3182     ip_recv_attr_t *);
3183 extern void	ip_input_post_ipsec(mblk_t *, ip_recv_attr_t *);
3184 extern void	ip_fanout_v4(mblk_t *, ipha_t *, ip_recv_attr_t *);
3185 extern void	ip_fanout_v6(mblk_t *, ip6_t *, ip_recv_attr_t *);
3186 extern void	ip_fanout_proto_conn(conn_t *, mblk_t *, ipha_t *, ip6_t *,
3187     ip_recv_attr_t *);
3188 extern void	ip_fanout_proto_v4(mblk_t *, ipha_t *, ip_recv_attr_t *);
3189 extern void	ip_fanout_send_icmp_v4(mblk_t *, uint_t, uint_t,
3190     ip_recv_attr_t *);
3191 extern void	ip_fanout_udp_conn(conn_t *, mblk_t *, ipha_t *, ip6_t *,
3192     ip_recv_attr_t *);
3193 extern void	ip_fanout_udp_multi_v4(mblk_t *, ipha_t *, uint16_t, uint16_t,
3194     ip_recv_attr_t *);
3195 extern mblk_t	*zero_spi_check(mblk_t *, ip_recv_attr_t *);
3196 extern void	ip_build_hdrs_v4(uchar_t *, uint_t, const ip_pkt_t *, uint8_t);
3197 extern int	ip_find_hdr_v4(ipha_t *, ip_pkt_t *, boolean_t);
3198 extern int	ip_total_hdrs_len_v4(const ip_pkt_t *);
3199 
3200 extern mblk_t	*ip_accept_tcp(ill_t *, ill_rx_ring_t *, squeue_t *,
3201     mblk_t *, mblk_t **, uint_t *cnt);
3202 extern void	ip_rput_dlpi(ill_t *, mblk_t *);
3203 extern void	ip_rput_notdata(ill_t *, mblk_t *);
3204 
3205 extern void	ip_mib2_add_ip_stats(mib2_ipIfStatsEntry_t *,
3206 		    mib2_ipIfStatsEntry_t *);
3207 extern void	ip_mib2_add_icmp6_stats(mib2_ipv6IfIcmpEntry_t *,
3208 		    mib2_ipv6IfIcmpEntry_t *);
3209 extern void	ip_rput_other(ipsq_t *, queue_t *, mblk_t *, void *);
3210 extern ire_t	*ip_check_multihome(void *, ire_t *, ill_t *);
3211 extern void	ip_send_potential_redirect_v4(mblk_t *, ipha_t *, ire_t *,
3212     ip_recv_attr_t *);
3213 extern int	ip_set_destination_v4(ipaddr_t *, ipaddr_t, ipaddr_t,
3214     ip_xmit_attr_t *, iulp_t *, uint32_t, uint_t);
3215 extern int	ip_set_destination_v6(in6_addr_t *, const in6_addr_t *,
3216     const in6_addr_t *, ip_xmit_attr_t *, iulp_t *, uint32_t, uint_t);
3217 
3218 extern int	ip_output_simple(mblk_t *, ip_xmit_attr_t *);
3219 extern int	ip_output_simple_v4(mblk_t *, ip_xmit_attr_t *);
3220 extern int	ip_output_simple_v6(mblk_t *, ip_xmit_attr_t *);
3221 extern int	ip_output_options(mblk_t *, ipha_t *, ip_xmit_attr_t *,
3222     ill_t *);
3223 extern void	ip_output_local_options(ipha_t *, ip_stack_t *);
3224 
3225 extern ip_xmit_attr_t *conn_get_ixa(conn_t *, boolean_t);
3226 extern ip_xmit_attr_t *conn_get_ixa_tryhard(conn_t *, boolean_t);
3227 extern ip_xmit_attr_t *conn_replace_ixa(conn_t *, ip_xmit_attr_t *);
3228 extern ip_xmit_attr_t *conn_get_ixa_exclusive(conn_t *);
3229 extern ip_xmit_attr_t *ip_xmit_attr_duplicate(ip_xmit_attr_t *);
3230 extern void	ip_xmit_attr_replace_tsl(ip_xmit_attr_t *, ts_label_t *);
3231 extern void	ip_xmit_attr_restore_tsl(ip_xmit_attr_t *, cred_t *);
3232 boolean_t	ip_recv_attr_replace_label(ip_recv_attr_t *, ts_label_t *);
3233 extern void	ixa_inactive(ip_xmit_attr_t *);
3234 extern void	ixa_refrele(ip_xmit_attr_t *);
3235 extern boolean_t ixa_check_drain_insert(conn_t *, ip_xmit_attr_t *);
3236 extern void	ixa_cleanup(ip_xmit_attr_t *);
3237 extern void	ira_cleanup(ip_recv_attr_t *, boolean_t);
3238 extern void	ixa_safe_copy(ip_xmit_attr_t *, ip_xmit_attr_t *);
3239 
3240 extern int	conn_ip_output(mblk_t *, ip_xmit_attr_t *);
3241 extern boolean_t ip_output_verify_local(ip_xmit_attr_t *);
3242 extern mblk_t	*ip_output_process_local(mblk_t *, ip_xmit_attr_t *, boolean_t,
3243     boolean_t, conn_t *);
3244 
3245 extern int	conn_opt_get(conn_opt_arg_t *, t_scalar_t, t_scalar_t,
3246     uchar_t *);
3247 extern int	conn_opt_set(conn_opt_arg_t *, t_scalar_t, t_scalar_t, uint_t,
3248     uchar_t *, boolean_t, cred_t *);
3249 extern boolean_t	conn_same_as_last_v4(conn_t *, sin_t *);
3250 extern boolean_t	conn_same_as_last_v6(conn_t *, sin6_t *);
3251 extern int	conn_update_label(const conn_t *, const ip_xmit_attr_t *,
3252     const in6_addr_t *, ip_pkt_t *);
3253 
3254 extern int	ip_opt_set_multicast_group(conn_t *, t_scalar_t,
3255     uchar_t *, boolean_t, boolean_t);
3256 extern int	ip_opt_set_multicast_sources(conn_t *, t_scalar_t,
3257     uchar_t *, boolean_t, boolean_t);
3258 extern int	conn_getsockname(conn_t *, struct sockaddr *, uint_t *);
3259 extern int	conn_getpeername(conn_t *, struct sockaddr *, uint_t *);
3260 
3261 extern int	conn_build_hdr_template(conn_t *, uint_t, uint_t,
3262     const in6_addr_t *, const in6_addr_t *, uint32_t);
3263 extern mblk_t	*conn_prepend_hdr(ip_xmit_attr_t *, const ip_pkt_t *,
3264     const in6_addr_t *, const in6_addr_t *, uint8_t, uint32_t, uint_t,
3265     mblk_t *, uint_t, uint_t, uint32_t *, int *);
3266 extern void	ip_attr_newdst(ip_xmit_attr_t *);
3267 extern void	ip_attr_nexthop(const ip_pkt_t *, const ip_xmit_attr_t *,
3268     const in6_addr_t *, in6_addr_t *);
3269 extern int	conn_connect(conn_t *, iulp_t *, uint32_t);
3270 extern int	ip_attr_connect(const conn_t *, ip_xmit_attr_t *,
3271     const in6_addr_t *, const in6_addr_t *, const in6_addr_t *, in_port_t,
3272     in6_addr_t *, iulp_t *, uint32_t);
3273 extern int	conn_inherit_parent(conn_t *, conn_t *);
3274 
3275 extern void	conn_ixa_cleanup(conn_t *connp, void *arg);
3276 
3277 extern boolean_t conn_wantpacket(conn_t *, ip_recv_attr_t *, ipha_t *);
3278 extern uint_t	ip_type_v4(ipaddr_t, ip_stack_t *);
3279 extern uint_t	ip_type_v6(const in6_addr_t *, ip_stack_t *);
3280 
3281 extern void	ip_wput_nondata(queue_t *, mblk_t *);
3282 extern void	ip_wsrv(queue_t *);
3283 extern char	*ip_nv_lookup(nv_t *, int);
3284 extern boolean_t ip_local_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
3285 extern boolean_t ip_remote_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
3286 extern ipaddr_t ip_massage_options(ipha_t *, netstack_t *);
3287 extern ipaddr_t ip_net_mask(ipaddr_t);
3288 extern void	arp_bringup_done(ill_t *, int);
3289 extern void	arp_replumb_done(ill_t *, int);
3290 
3291 extern struct qinit iprinitv6;
3292 
3293 extern void	ipmp_init(ip_stack_t *);
3294 extern void	ipmp_destroy(ip_stack_t *);
3295 extern ipmp_grp_t *ipmp_grp_create(const char *, phyint_t *);
3296 extern void	ipmp_grp_destroy(ipmp_grp_t *);
3297 extern void	ipmp_grp_info(const ipmp_grp_t *, lifgroupinfo_t *);
3298 extern int	ipmp_grp_rename(ipmp_grp_t *, const char *);
3299 extern ipmp_grp_t *ipmp_grp_lookup(const char *, ip_stack_t *);
3300 extern int	ipmp_grp_vet_phyint(ipmp_grp_t *, phyint_t *);
3301 extern ipmp_illgrp_t *ipmp_illgrp_create(ill_t *);
3302 extern void	ipmp_illgrp_destroy(ipmp_illgrp_t *);
3303 extern ill_t	*ipmp_illgrp_add_ipif(ipmp_illgrp_t *, ipif_t *);
3304 extern void	ipmp_illgrp_del_ipif(ipmp_illgrp_t *, ipif_t *);
3305 extern ill_t	*ipmp_illgrp_next_ill(ipmp_illgrp_t *);
3306 extern ill_t	*ipmp_illgrp_hold_next_ill(ipmp_illgrp_t *);
3307 extern ill_t	*ipmp_illgrp_hold_cast_ill(ipmp_illgrp_t *);
3308 extern ill_t	*ipmp_illgrp_ipmp_ill(ipmp_illgrp_t *);
3309 extern void	ipmp_illgrp_refresh_mtu(ipmp_illgrp_t *);
3310 extern ipmp_arpent_t *ipmp_illgrp_create_arpent(ipmp_illgrp_t *,
3311     boolean_t, ipaddr_t, uchar_t *, size_t, uint16_t);
3312 extern void	ipmp_illgrp_destroy_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3313 extern ipmp_arpent_t *ipmp_illgrp_lookup_arpent(ipmp_illgrp_t *, ipaddr_t *);
3314 extern void	ipmp_illgrp_refresh_arpent(ipmp_illgrp_t *);
3315 extern void	ipmp_illgrp_mark_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3316 extern ill_t	*ipmp_illgrp_find_ill(ipmp_illgrp_t *, uchar_t *, uint_t);
3317 extern void	ipmp_illgrp_link_grp(ipmp_illgrp_t *, ipmp_grp_t *);
3318 extern int	ipmp_illgrp_unlink_grp(ipmp_illgrp_t *);
3319 extern uint_t	ipmp_ill_get_ipmp_ifindex(const ill_t *);
3320 extern void	ipmp_ill_join_illgrp(ill_t *, ipmp_illgrp_t *);
3321 extern void	ipmp_ill_leave_illgrp(ill_t *);
3322 extern ill_t	*ipmp_ill_hold_ipmp_ill(ill_t *);
3323 extern boolean_t ipmp_ill_is_active(ill_t *);
3324 extern void	ipmp_ill_refresh_active(ill_t *);
3325 extern void	ipmp_phyint_join_grp(phyint_t *, ipmp_grp_t *);
3326 extern void	ipmp_phyint_leave_grp(phyint_t *);
3327 extern void	ipmp_phyint_refresh_active(phyint_t *);
3328 extern ill_t	*ipmp_ipif_bound_ill(const ipif_t *);
3329 extern ill_t	*ipmp_ipif_hold_bound_ill(const ipif_t *);
3330 extern boolean_t ipmp_ipif_is_dataaddr(const ipif_t *);
3331 extern boolean_t ipmp_ipif_is_stubaddr(const ipif_t *);
3332 extern boolean_t ipmp_packet_is_probe(mblk_t *, ill_t *);
3333 extern ill_t	*ipmp_ill_get_xmit_ill(ill_t *, boolean_t);
3334 extern void	ipmp_ncec_flush_nce(ncec_t *);
3335 extern void	ipmp_ncec_fastpath(ncec_t *, ill_t *);
3336 
3337 extern void	conn_drain_insert(conn_t *, idl_tx_list_t *);
3338 extern void	conn_setqfull(conn_t *, boolean_t *);
3339 extern void	conn_clrqfull(conn_t *, boolean_t *);
3340 extern int	conn_ipsec_length(conn_t *);
3341 extern ipaddr_t	ip_get_dst(ipha_t *);
3342 extern uint_t	ip_get_pmtu(ip_xmit_attr_t *);
3343 extern uint_t	ip_get_base_mtu(ill_t *, ire_t *);
3344 extern mblk_t *ip_output_attach_policy(mblk_t *, ipha_t *, ip6_t *,
3345     const conn_t *, ip_xmit_attr_t *);
3346 extern int	ipsec_out_extra_length(ip_xmit_attr_t *);
3347 extern int	ipsec_out_process(mblk_t *, ip_xmit_attr_t *);
3348 extern int	ip_output_post_ipsec(mblk_t *, ip_xmit_attr_t *);
3349 extern void	ipsec_out_to_in(ip_xmit_attr_t *, ill_t *ill,
3350     ip_recv_attr_t *);
3351 
3352 extern void	ire_cleanup(ire_t *);
3353 extern void	ire_inactive(ire_t *);
3354 extern boolean_t irb_inactive(irb_t *);
3355 extern ire_t	*ire_unlink(irb_t *);
3356 
3357 #ifdef DEBUG
3358 extern	boolean_t th_trace_ref(const void *, ip_stack_t *);
3359 extern	void	th_trace_unref(const void *);
3360 extern	void	th_trace_cleanup(const void *, boolean_t);
3361 extern	void	ire_trace_ref(ire_t *);
3362 extern	void	ire_untrace_ref(ire_t *);
3363 #endif
3364 
3365 extern int	ip_srcid_insert(const in6_addr_t *, zoneid_t, ip_stack_t *);
3366 extern int	ip_srcid_remove(const in6_addr_t *, zoneid_t, ip_stack_t *);
3367 extern void	ip_srcid_find_id(uint_t, in6_addr_t *, zoneid_t, netstack_t *);
3368 extern uint_t	ip_srcid_find_addr(const in6_addr_t *, zoneid_t, netstack_t *);
3369 
3370 extern uint8_t	ipoptp_next(ipoptp_t *);
3371 extern uint8_t	ipoptp_first(ipoptp_t *, ipha_t *);
3372 extern int	ip_opt_get_user(conn_t *, uchar_t *);
3373 extern int	ipsec_req_from_conn(conn_t *, ipsec_req_t *, int);
3374 extern int	ip_snmp_get(queue_t *q, mblk_t *mctl, int level);
3375 extern int	ip_snmp_set(queue_t *q, int, int, uchar_t *, int);
3376 extern void	ip_process_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3377 extern void	ip_quiesce_conn(conn_t *);
3378 extern  void    ip_reprocess_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3379 extern void	ip_ioctl_finish(queue_t *, mblk_t *, int, int, ipsq_t *);
3380 
3381 extern boolean_t ip_cmpbuf(const void *, uint_t, boolean_t, const void *,
3382     uint_t);
3383 extern boolean_t ip_allocbuf(void **, uint_t *, boolean_t, const void *,
3384     uint_t);
3385 extern void	ip_savebuf(void **, uint_t *, boolean_t, const void *, uint_t);
3386 
3387 extern boolean_t	ipsq_pending_mp_cleanup(ill_t *, conn_t *);
3388 extern void	conn_ioctl_cleanup(conn_t *);
3389 
3390 extern void	ip_unbind(conn_t *);
3391 
3392 extern void tnet_init(void);
3393 extern void tnet_fini(void);
3394 
3395 /*
3396  * Hook functions to enable cluster networking
3397  * On non-clustered systems these vectors must always be NULL.
3398  */
3399 extern int (*cl_inet_isclusterwide)(netstackid_t stack_id, uint8_t protocol,
3400     sa_family_t addr_family, uint8_t *laddrp, void *args);
3401 extern uint32_t (*cl_inet_ipident)(netstackid_t stack_id, uint8_t protocol,
3402     sa_family_t addr_family, uint8_t *laddrp, uint8_t *faddrp,
3403     void *args);
3404 extern int (*cl_inet_connect2)(netstackid_t stack_id, uint8_t protocol,
3405     boolean_t is_outgoing, sa_family_t addr_family, uint8_t *laddrp,
3406     in_port_t lport, uint8_t *faddrp, in_port_t fport, void *args);
3407 extern void (*cl_inet_getspi)(netstackid_t, uint8_t, uint8_t *, size_t,
3408     void *);
3409 extern void (*cl_inet_getspi)(netstackid_t stack_id, uint8_t protocol,
3410     uint8_t *ptr, size_t len, void *args);
3411 extern int (*cl_inet_checkspi)(netstackid_t stack_id, uint8_t protocol,
3412     uint32_t spi, void *args);
3413 extern void (*cl_inet_deletespi)(netstackid_t stack_id, uint8_t protocol,
3414     uint32_t spi, void *args);
3415 extern void (*cl_inet_idlesa)(netstackid_t, uint8_t, uint32_t,
3416     sa_family_t, in6_addr_t, in6_addr_t, void *);
3417 
3418 
3419 /* Hooks for CGTP (multirt routes) filtering module */
3420 #define	CGTP_FILTER_REV_1	1
3421 #define	CGTP_FILTER_REV_2	2
3422 #define	CGTP_FILTER_REV_3	3
3423 #define	CGTP_FILTER_REV		CGTP_FILTER_REV_3
3424 
3425 /* cfo_filter and cfo_filter_v6 hooks return values */
3426 #define	CGTP_IP_PKT_NOT_CGTP	0
3427 #define	CGTP_IP_PKT_PREMIUM	1
3428 #define	CGTP_IP_PKT_DUPLICATE	2
3429 
3430 /* Version 3 of the filter interface */
3431 typedef struct cgtp_filter_ops {
3432 	int	cfo_filter_rev;			/* CGTP_FILTER_REV_3 */
3433 	int	(*cfo_change_state)(netstackid_t, int);
3434 	int	(*cfo_add_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t,
3435 		    ipaddr_t, ipaddr_t);
3436 	int	(*cfo_del_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t);
3437 	int	(*cfo_add_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *,
3438 		    in6_addr_t *, in6_addr_t *);
3439 	int	(*cfo_del_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *);
3440 	int	(*cfo_filter)(netstackid_t, uint_t, mblk_t *);
3441 	int	(*cfo_filter_v6)(netstackid_t, uint_t, ip6_t *,
3442 		    ip6_frag_t *);
3443 } cgtp_filter_ops_t;
3444 
3445 #define	CGTP_MCAST_SUCCESS	1
3446 
3447 /*
3448  * The separate CGTP module needs this global symbol so that it
3449  * can check the version and determine whether to use the old or the new
3450  * version of the filtering interface.
3451  */
3452 extern int	ip_cgtp_filter_rev;
3453 
3454 extern int	ip_cgtp_filter_supported(void);
3455 extern int	ip_cgtp_filter_register(netstackid_t, cgtp_filter_ops_t *);
3456 extern int	ip_cgtp_filter_unregister(netstackid_t);
3457 extern int	ip_cgtp_filter_is_registered(netstackid_t);
3458 
3459 /*
3460  * rr_ring_state cycles in the order shown below from RR_FREE through
3461  * RR_FREE_IN_PROG and  back to RR_FREE.
3462  */
3463 typedef enum {
3464 	RR_FREE,			/* Free slot */
3465 	RR_SQUEUE_UNBOUND,		/* Ring's squeue is unbound */
3466 	RR_SQUEUE_BIND_INPROG,		/* Ring's squeue bind in progress */
3467 	RR_SQUEUE_BOUND,		/* Ring's squeue bound to cpu */
3468 	RR_FREE_INPROG			/* Ring is being freed */
3469 } ip_ring_state_t;
3470 
3471 #define	ILL_MAX_RINGS		256	/* Max num of rx rings we can manage */
3472 #define	ILL_POLLING		0x01	/* Polling in use */
3473 
3474 /*
3475  * These functions pointer types are exported by the mac/dls layer.
3476  * we need to duplicate the definitions here because we cannot
3477  * include mac/dls header files here.
3478  */
3479 typedef boolean_t		(*ip_mac_intr_disable_t)(void *);
3480 typedef void			(*ip_mac_intr_enable_t)(void *);
3481 typedef ip_mac_tx_cookie_t	(*ip_dld_tx_t)(void *, mblk_t *,
3482     uint64_t, uint16_t);
3483 typedef	void			(*ip_flow_enable_t)(void *, ip_mac_tx_cookie_t);
3484 typedef void			*(*ip_dld_callb_t)(void *,
3485     ip_flow_enable_t, void *);
3486 typedef boolean_t		(*ip_dld_fctl_t)(void *, ip_mac_tx_cookie_t);
3487 typedef int			(*ip_capab_func_t)(void *, uint_t,
3488     void *, uint_t);
3489 
3490 /*
3491  * POLLING README
3492  * sq_get_pkts() is called to pick packets from softring in poll mode. It
3493  * calls rr_rx to get the chain and process it with rr_ip_accept.
3494  * rr_rx = mac_soft_ring_poll() to pick packets
3495  * rr_ip_accept = ip_accept_tcp() to process packets
3496  */
3497 
3498 /*
3499  * XXX: With protocol, service specific squeues, they will have
3500  * specific acceptor functions.
3501  */
3502 typedef	mblk_t *(*ip_mac_rx_t)(void *, size_t);
3503 typedef mblk_t *(*ip_accept_t)(ill_t *, ill_rx_ring_t *,
3504     squeue_t *, mblk_t *, mblk_t **, uint_t *);
3505 
3506 /*
3507  * rr_intr_enable, rr_intr_disable, rr_rx_handle, rr_rx:
3508  * May be accessed while in the squeue AND after checking that SQS_POLL_CAPAB
3509  * is set.
3510  *
3511  * rr_ring_state: Protected by ill_lock.
3512  */
3513 struct ill_rx_ring {
3514 	ip_mac_intr_disable_t	rr_intr_disable; /* Interrupt disabling func */
3515 	ip_mac_intr_enable_t	rr_intr_enable;	/* Interrupt enabling func */
3516 	void			*rr_intr_handle; /* Handle interrupt funcs */
3517 	ip_mac_rx_t		rr_rx;		/* Driver receive function */
3518 	ip_accept_t		rr_ip_accept;	/* IP accept function */
3519 	void			*rr_rx_handle;	/* Handle for Rx ring */
3520 	squeue_t		*rr_sqp; /* Squeue the ring is bound to */
3521 	ill_t			*rr_ill;	/* back pointer to ill */
3522 	ip_ring_state_t		rr_ring_state;	/* State of this ring */
3523 };
3524 
3525 /*
3526  * IP - DLD direct function call capability
3527  * Suffixes, df - dld function, dh - dld handle,
3528  * cf - client (IP) function, ch - client handle
3529  */
3530 typedef struct ill_dld_direct_s {		/* DLD provided driver Tx */
3531 	ip_dld_tx_t		idd_tx_df;	/* str_mdata_fastpath_put */
3532 	void			*idd_tx_dh;	/* dld_str_t *dsp */
3533 	ip_dld_callb_t		idd_tx_cb_df;	/* mac_tx_srs_notify */
3534 	void			*idd_tx_cb_dh;	/* mac_client_handle_t *mch */
3535 	ip_dld_fctl_t		idd_tx_fctl_df;	/* mac_tx_is_flow_blocked */
3536 	void			*idd_tx_fctl_dh;	/* mac_client_handle */
3537 } ill_dld_direct_t;
3538 
3539 /* IP - DLD polling capability */
3540 typedef struct ill_dld_poll_s {
3541 	ill_rx_ring_t		idp_ring_tbl[ILL_MAX_RINGS];
3542 } ill_dld_poll_t;
3543 
3544 /* Describes ill->ill_dld_capab */
3545 struct ill_dld_capab_s {
3546 	ip_capab_func_t		idc_capab_df;	/* dld_capab_func */
3547 	void			*idc_capab_dh;	/* dld_str_t *dsp */
3548 	ill_dld_direct_t	idc_direct;
3549 	ill_dld_poll_t		idc_poll;
3550 };
3551 
3552 /*
3553  * IP squeues exports
3554  */
3555 extern boolean_t 	ip_squeue_fanout;
3556 
3557 #define	IP_SQUEUE_GET(hint) ip_squeue_random(hint)
3558 
3559 extern void ip_squeue_init(void (*)(squeue_t *));
3560 extern squeue_t	*ip_squeue_random(uint_t);
3561 extern squeue_t *ip_squeue_get(ill_rx_ring_t *);
3562 extern squeue_t *ip_squeue_getfree(pri_t);
3563 extern int ip_squeue_cpu_move(squeue_t *, processorid_t);
3564 extern void *ip_squeue_add_ring(ill_t *, void *);
3565 extern void ip_squeue_bind_ring(ill_t *, ill_rx_ring_t *, processorid_t);
3566 extern void ip_squeue_clean_ring(ill_t *, ill_rx_ring_t *);
3567 extern void ip_squeue_quiesce_ring(ill_t *, ill_rx_ring_t *);
3568 extern void ip_squeue_restart_ring(ill_t *, ill_rx_ring_t *);
3569 extern void ip_squeue_clean_all(ill_t *);
3570 extern boolean_t	ip_source_routed(ipha_t *, ip_stack_t *);
3571 
3572 extern void tcp_wput(queue_t *, mblk_t *);
3573 
3574 extern int	ip_fill_mtuinfo(conn_t *, ip_xmit_attr_t *,
3575     struct ip6_mtuinfo *);
3576 extern hook_t *ipobs_register_hook(netstack_t *, pfv_t);
3577 extern void ipobs_unregister_hook(netstack_t *, hook_t *);
3578 extern void ipobs_hook(mblk_t *, int, zoneid_t, zoneid_t, const ill_t *,
3579     ip_stack_t *);
3580 typedef void    (*ipsq_func_t)(ipsq_t *, queue_t *, mblk_t *, void *);
3581 
3582 extern void	dce_g_init(void);
3583 extern void	dce_g_destroy(void);
3584 extern void	dce_stack_init(ip_stack_t *);
3585 extern void	dce_stack_destroy(ip_stack_t *);
3586 extern void	dce_cleanup(uint_t, ip_stack_t *);
3587 extern dce_t	*dce_get_default(ip_stack_t *);
3588 extern dce_t	*dce_lookup_pkt(mblk_t *, ip_xmit_attr_t *, uint_t *);
3589 extern dce_t	*dce_lookup_v4(ipaddr_t, ip_stack_t *, uint_t *);
3590 extern dce_t	*dce_lookup_v6(const in6_addr_t *, uint_t, ip_stack_t *,
3591     uint_t *);
3592 extern dce_t	*dce_lookup_and_add_v4(ipaddr_t, ip_stack_t *);
3593 extern dce_t	*dce_lookup_and_add_v6(const in6_addr_t *, uint_t,
3594     ip_stack_t *);
3595 extern int	dce_update_uinfo_v4(ipaddr_t, iulp_t *, ip_stack_t *);
3596 extern int	dce_update_uinfo_v6(const in6_addr_t *, uint_t, iulp_t *,
3597     ip_stack_t *);
3598 extern int	dce_update_uinfo(const in6_addr_t *, uint_t, iulp_t *,
3599     ip_stack_t *);
3600 extern void	dce_increment_generation(dce_t *);
3601 extern void	dce_increment_all_generations(boolean_t, ip_stack_t *);
3602 extern void	dce_refrele(dce_t *);
3603 extern void	dce_refhold(dce_t *);
3604 extern void	dce_refrele_notr(dce_t *);
3605 extern void	dce_refhold_notr(dce_t *);
3606 mblk_t		*ip_snmp_get_mib2_ip_dce(queue_t *, mblk_t *, ip_stack_t *ipst);
3607 
3608 extern ip_laddr_t ip_laddr_verify_v4(ipaddr_t, zoneid_t,
3609     ip_stack_t *, boolean_t);
3610 extern ip_laddr_t ip_laddr_verify_v6(const in6_addr_t *, zoneid_t,
3611     ip_stack_t *, boolean_t, uint_t);
3612 extern int	ip_laddr_fanout_insert(conn_t *);
3613 
3614 extern boolean_t ip_verify_src(mblk_t *, ip_xmit_attr_t *, uint_t *);
3615 extern int	ip_verify_ire(mblk_t *, ip_xmit_attr_t *);
3616 
3617 extern mblk_t	*ip_xmit_attr_to_mblk(ip_xmit_attr_t *);
3618 extern boolean_t ip_xmit_attr_from_mblk(mblk_t *, ip_xmit_attr_t *);
3619 extern mblk_t	*ip_xmit_attr_free_mblk(mblk_t *);
3620 extern mblk_t	*ip_recv_attr_to_mblk(ip_recv_attr_t *);
3621 extern boolean_t ip_recv_attr_from_mblk(mblk_t *, ip_recv_attr_t *);
3622 extern mblk_t	*ip_recv_attr_free_mblk(mblk_t *);
3623 extern boolean_t ip_recv_attr_is_mblk(mblk_t *);
3624 
3625 /*
3626  * Squeue tags. Tags only need to be unique when the callback function is the
3627  * same to distinguish between different calls, but we use unique tags for
3628  * convenience anyway.
3629  */
3630 #define	SQTAG_IP_INPUT			1
3631 #define	SQTAG_TCP_INPUT_ICMP_ERR	2
3632 #define	SQTAG_TCP6_INPUT_ICMP_ERR	3
3633 #define	SQTAG_IP_TCP_INPUT		4
3634 #define	SQTAG_IP6_TCP_INPUT		5
3635 #define	SQTAG_IP_TCP_CLOSE		6
3636 #define	SQTAG_TCP_OUTPUT		7
3637 #define	SQTAG_TCP_TIMER			8
3638 #define	SQTAG_TCP_TIMEWAIT		9
3639 #define	SQTAG_TCP_ACCEPT_FINISH		10
3640 #define	SQTAG_TCP_ACCEPT_FINISH_Q0	11
3641 #define	SQTAG_TCP_ACCEPT_PENDING	12
3642 #define	SQTAG_TCP_LISTEN_DISCON		13
3643 #define	SQTAG_TCP_CONN_REQ_1		14
3644 #define	SQTAG_TCP_EAGER_BLOWOFF		15
3645 #define	SQTAG_TCP_EAGER_CLEANUP		16
3646 #define	SQTAG_TCP_EAGER_CLEANUP_Q0	17
3647 #define	SQTAG_TCP_CONN_IND		18
3648 #define	SQTAG_TCP_RSRV			19
3649 #define	SQTAG_TCP_ABORT_BUCKET		20
3650 #define	SQTAG_TCP_REINPUT		21
3651 #define	SQTAG_TCP_REINPUT_EAGER		22
3652 #define	SQTAG_TCP_INPUT_MCTL		23
3653 #define	SQTAG_TCP_RPUTOTHER		24
3654 #define	SQTAG_IP_PROTO_AGAIN		25
3655 #define	SQTAG_IP_FANOUT_TCP		26
3656 #define	SQTAG_IPSQ_CLEAN_RING		27
3657 #define	SQTAG_TCP_WPUT_OTHER		28
3658 #define	SQTAG_TCP_CONN_REQ_UNBOUND	29
3659 #define	SQTAG_TCP_SEND_PENDING		30
3660 #define	SQTAG_BIND_RETRY		31
3661 #define	SQTAG_UDP_FANOUT		32
3662 #define	SQTAG_UDP_INPUT			33
3663 #define	SQTAG_UDP_WPUT			34
3664 #define	SQTAG_UDP_OUTPUT		35
3665 #define	SQTAG_TCP_KSSL_INPUT		36
3666 #define	SQTAG_TCP_DROP_Q0		37
3667 #define	SQTAG_TCP_CONN_REQ_2		38
3668 #define	SQTAG_IP_INPUT_RX_RING		39
3669 #define	SQTAG_SQUEUE_CHANGE		40
3670 #define	SQTAG_CONNECT_FINISH		41
3671 #define	SQTAG_SYNCHRONOUS_OP		42
3672 #define	SQTAG_TCP_SHUTDOWN_OUTPUT	43
3673 #define	SQTAG_TCP_IXA_CLEANUP		44
3674 
3675 #endif	/* _KERNEL */
3676 
3677 #ifdef	__cplusplus
3678 }
3679 #endif
3680 
3681 #endif	/* _INET_IP_H */
3682