xref: /titanic_50/usr/src/uts/common/inet/ip.h (revision 01ef659d9b1ead333ef0adc346e7051f7eae7520)
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 <sys/multidata.h>
59 #include <sys/list.h>
60 #include <net/radix.h>
61 #include <sys/modhash.h>
62 
63 #ifdef DEBUG
64 #define	CONN_DEBUG
65 #endif
66 
67 #define	IP_DEBUG
68 /*
69  * The mt-streams(9F) flags for the IP module; put here so that other
70  * "drivers" that are actually IP (e.g., ICMP, UDP) can use the same set
71  * of flags.
72  */
73 #define	IP_DEVMTFLAGS D_MP
74 #endif	/* _KERNEL */
75 
76 #define	IP_MOD_NAME	"ip"
77 #define	IP_DEV_NAME	"/dev/ip"
78 #define	IP6_DEV_NAME	"/dev/ip6"
79 
80 #define	UDP_MOD_NAME	"udp"
81 #define	UDP_DEV_NAME	"/dev/udp"
82 #define	UDP6_DEV_NAME	"/dev/udp6"
83 
84 #define	TCP_MOD_NAME	"tcp"
85 #define	TCP_DEV_NAME	"/dev/tcp"
86 #define	TCP6_DEV_NAME	"/dev/tcp6"
87 
88 #define	SCTP_MOD_NAME	"sctp"
89 
90 #ifndef	_IPADDR_T
91 #define	_IPADDR_T
92 typedef uint32_t ipaddr_t;
93 #endif
94 
95 /* Number of bits in an address */
96 #define	IP_ABITS		32
97 #define	IPV6_ABITS		128
98 
99 #define	IP_HOST_MASK		(ipaddr_t)0xffffffffU
100 
101 #define	IP_CSUM(mp, off, sum)		(~ip_cksum(mp, off, sum) & 0xFFFF)
102 #define	IP_CSUM_PARTIAL(mp, off, sum)	ip_cksum(mp, off, sum)
103 #define	IP_BCSUM_PARTIAL(bp, len, sum)	bcksum(bp, len, sum)
104 #define	IP_MD_CSUM(pd, off, sum)	(~ip_md_cksum(pd, off, sum) & 0xffff)
105 #define	IP_MD_CSUM_PARTIAL(pd, off, sum) ip_md_cksum(pd, off, sum)
106 
107 /*
108  * Flag to IP write side to indicate that the appln has sent in a pre-built
109  * IP header. Stored in ipha_ident (which is otherwise zero).
110  */
111 #define	IP_HDR_INCLUDED			0xFFFF
112 
113 #define	ILL_FRAG_HASH_TBL_COUNT	((unsigned int)64)
114 #define	ILL_FRAG_HASH_TBL_SIZE	(ILL_FRAG_HASH_TBL_COUNT * sizeof (ipfb_t))
115 
116 #define	IPV4_ADDR_LEN			4
117 #define	IP_ADDR_LEN			IPV4_ADDR_LEN
118 #define	IP_ARP_PROTO_TYPE		0x0800
119 
120 #define	IPV4_VERSION			4
121 #define	IP_VERSION			IPV4_VERSION
122 #define	IP_SIMPLE_HDR_LENGTH_IN_WORDS	5
123 #define	IP_SIMPLE_HDR_LENGTH		20
124 #define	IP_MAX_HDR_LENGTH		60
125 
126 #define	IP_MAX_OPT_LENGTH (IP_MAX_HDR_LENGTH-IP_SIMPLE_HDR_LENGTH)
127 
128 #define	IP_MIN_MTU			(IP_MAX_HDR_LENGTH + 8)	/* 68 bytes */
129 
130 /*
131  * XXX IP_MAXPACKET is defined in <netinet/ip.h> as well. At some point the
132  * 2 files should be cleaned up to remove all redundant definitions.
133  */
134 #define	IP_MAXPACKET			65535
135 #define	IP_SIMPLE_HDR_VERSION \
136 	((IP_VERSION << 4) | IP_SIMPLE_HDR_LENGTH_IN_WORDS)
137 
138 #define	UDPH_SIZE			8
139 
140 /* Leave room for ip_newroute to tack on the src and target addresses */
141 #define	OK_RESOLVER_MP(mp)						\
142 	((mp) && ((mp)->b_wptr - (mp)->b_rptr) >= (2 * IP_ADDR_LEN))
143 
144 /*
145  * Constants and type definitions to support IP IOCTL commands
146  */
147 #define	IP_IOCTL			(('i'<<8)|'p')
148 #define	IP_IOC_IRE_DELETE		4
149 #define	IP_IOC_IRE_DELETE_NO_REPLY	5
150 #define	IP_IOC_IRE_ADVISE_NO_REPLY	6
151 #define	IP_IOC_RTS_REQUEST		7
152 
153 /* Common definitions used by IP IOCTL data structures */
154 typedef struct ipllcmd_s {
155 	uint_t	ipllc_cmd;
156 	uint_t	ipllc_name_offset;
157 	uint_t	ipllc_name_length;
158 } ipllc_t;
159 
160 /* IP IRE Change Command Structure. */
161 typedef struct ipic_s {
162 	ipllc_t	ipic_ipllc;
163 	uint_t	ipic_ire_type;
164 	uint_t	ipic_max_frag;
165 	uint_t	ipic_addr_offset;
166 	uint_t	ipic_addr_length;
167 	uint_t	ipic_mask_offset;
168 	uint_t	ipic_mask_length;
169 	uint_t	ipic_src_addr_offset;
170 	uint_t	ipic_src_addr_length;
171 	uint_t	ipic_ll_hdr_offset;
172 	uint_t	ipic_ll_hdr_length;
173 	uint_t	ipic_gateway_addr_offset;
174 	uint_t	ipic_gateway_addr_length;
175 	clock_t	ipic_rtt;
176 	uint32_t ipic_ssthresh;
177 	clock_t	ipic_rtt_sd;
178 	uchar_t ipic_ire_marks;
179 } ipic_t;
180 
181 #define	ipic_cmd		ipic_ipllc.ipllc_cmd
182 #define	ipic_ll_name_length	ipic_ipllc.ipllc_name_length
183 #define	ipic_ll_name_offset	ipic_ipllc.ipllc_name_offset
184 
185 /* IP IRE Delete Command Structure. */
186 typedef struct ipid_s {
187 	ipllc_t	ipid_ipllc;
188 	uint_t	ipid_ire_type;
189 	uint_t	ipid_addr_offset;
190 	uint_t	ipid_addr_length;
191 	uint_t	ipid_mask_offset;
192 	uint_t	ipid_mask_length;
193 } ipid_t;
194 
195 #define	ipid_cmd		ipid_ipllc.ipllc_cmd
196 
197 #ifdef _KERNEL
198 /*
199  * Temporary state for ip options parser.
200  */
201 typedef struct ipoptp_s
202 {
203 	uint8_t		*ipoptp_next;	/* next option to look at */
204 	uint8_t		*ipoptp_end;	/* end of options */
205 	uint8_t		*ipoptp_cur;	/* start of current option */
206 	uint8_t		ipoptp_len;	/* length of current option */
207 	uint32_t	ipoptp_flags;
208 } ipoptp_t;
209 
210 /*
211  * Flag(s) for ipoptp_flags
212  */
213 #define	IPOPTP_ERROR	0x00000001
214 #endif	/* _KERNEL */
215 
216 /* Controls forwarding of IP packets, set via ndd */
217 #define	IP_FORWARD_NEVER	0
218 #define	IP_FORWARD_ALWAYS	1
219 
220 #define	WE_ARE_FORWARDING(ipst)	((ipst)->ips_ip_g_forward == IP_FORWARD_ALWAYS)
221 
222 #define	IPH_HDR_LENGTH(ipha)						\
223 	((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length & 0xF) << 2)
224 
225 #define	IPH_HDR_VERSION(ipha)						\
226 	((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length) >> 4)
227 
228 #ifdef _KERNEL
229 /*
230  * IP reassembly macros.  We hide starting and ending offsets in b_next and
231  * b_prev of messages on the reassembly queue.	The messages are chained using
232  * b_cont.  These macros are used in ip_reassemble() so we don't have to see
233  * the ugly casts and assignments.
234  * Note that the offsets are <= 64k i.e. a uint_t is sufficient to represent
235  * them.
236  */
237 #define	IP_REASS_START(mp)		((uint_t)(uintptr_t)((mp)->b_next))
238 #define	IP_REASS_SET_START(mp, u)	\
239 	((mp)->b_next = (mblk_t *)(uintptr_t)(u))
240 #define	IP_REASS_END(mp)		((uint_t)(uintptr_t)((mp)->b_prev))
241 #define	IP_REASS_SET_END(mp, u)		\
242 	((mp)->b_prev = (mblk_t *)(uintptr_t)(u))
243 
244 #define	IP_REASS_COMPLETE	0x1
245 #define	IP_REASS_PARTIAL	0x2
246 #define	IP_REASS_FAILED		0x4
247 
248 /*
249  * Test to determine whether this is a module instance of IP or a
250  * driver instance of IP.
251  */
252 #define	CONN_Q(q)	(WR(q)->q_next == NULL)
253 
254 #define	Q_TO_CONN(q)	((conn_t *)(q)->q_ptr)
255 #define	Q_TO_TCP(q)	(Q_TO_CONN((q))->conn_tcp)
256 #define	Q_TO_UDP(q)	(Q_TO_CONN((q))->conn_udp)
257 #define	Q_TO_ICMP(q)	(Q_TO_CONN((q))->conn_icmp)
258 #define	Q_TO_RTS(q)	(Q_TO_CONN((q))->conn_rts)
259 
260 /*
261  * The following two macros are used by IP to get the appropriate
262  * wq and rq for a conn. If it is a TCP conn, then we need
263  * tcp_wq/tcp_rq else, conn_wq/conn_rq. IP can use conn_wq and conn_rq
264  * from a conn directly if it knows that the conn is not TCP.
265  */
266 #define	CONNP_TO_WQ(connp)	\
267 	(IPCL_IS_TCP(connp) ? (connp)->conn_tcp->tcp_wq : (connp)->conn_wq)
268 
269 #define	CONNP_TO_RQ(connp)	RD(CONNP_TO_WQ(connp))
270 
271 #define	GRAB_CONN_LOCK(q)	{				\
272 	if (q != NULL && CONN_Q(q))				\
273 		mutex_enter(&(Q_TO_CONN(q))->conn_lock);	\
274 }
275 
276 #define	RELEASE_CONN_LOCK(q)	{				\
277 	if (q != NULL && CONN_Q(q))				\
278 		mutex_exit(&(Q_TO_CONN(q))->conn_lock);		\
279 }
280 
281 /* "Congestion controlled" protocol */
282 #define	IP_FLOW_CONTROLLED_ULP(p)   ((p) == IPPROTO_TCP || (p) == IPPROTO_SCTP)
283 
284 /*
285  * Complete the pending operation. Usually an ioctl. Can also
286  * be a bind or option management request that got enqueued
287  * in an ipsq_t. Called on completion of the operation.
288  */
289 #define	CONN_OPER_PENDING_DONE(connp)	{			\
290 	mutex_enter(&(connp)->conn_lock);			\
291 	(connp)->conn_oper_pending_ill = NULL;			\
292 	cv_broadcast(&(connp)->conn_refcv);			\
293 	mutex_exit(&(connp)->conn_lock);			\
294 	CONN_DEC_REF(connp);					\
295 }
296 
297 /*
298  * Flags for the various ip_fanout_* routines.
299  */
300 #define	IP_FF_SEND_ICMP		0x01	/* Send an ICMP error */
301 #define	IP_FF_HDR_COMPLETE	0x02	/* Call ip_hdr_complete if error */
302 #define	IP_FF_CKSUM		0x04	/* Recompute ipha_cksum if error */
303 #define	IP_FF_RAWIP		0x08	/* Use rawip mib variable */
304 #define	IP_FF_SRC_QUENCH	0x10	/* OK to send ICMP_SOURCE_QUENCH */
305 #define	IP_FF_SYN_ADDIRE	0x20	/* Add IRE if TCP syn packet */
306 #define	IP_FF_IPINFO		0x80	/* Used for both V4 and V6 */
307 #define	IP_FF_SEND_SLLA		0x100	/* Send source link layer info ? */
308 #define	IPV6_REACHABILITY_CONFIRMATION	0x200	/* Flags for ip_xmit_v6 */
309 #define	IP_FF_NO_MCAST_LOOP	0x400	/* No multicasts for sending zone */
310 
311 /*
312  * Following flags are used by IPQoS to determine if policy processing is
313  * required.
314  */
315 #define	IP6_NO_IPPOLICY		0x800	/* Don't do IPQoS processing */
316 #define	IP6_IN_LLMCAST		0x1000	/* Multicast */
317 
318 #define	IP_FF_LOOPBACK		0x2000	/* Loopback fanout */
319 #define	IP_FF_SCTP_CSUM_ERR	0x4000	/* sctp pkt has failed chksum */
320 
321 #ifndef	IRE_DB_TYPE
322 #define	IRE_DB_TYPE	M_SIG
323 #endif
324 
325 #ifndef	IRE_DB_REQ_TYPE
326 #define	IRE_DB_REQ_TYPE	M_PCSIG
327 #endif
328 
329 #ifndef	IRE_ARPRESOLVE_TYPE
330 #define	IRE_ARPRESOLVE_TYPE	M_EVENT
331 #endif
332 
333 /*
334  * Values for squeue switch:
335  */
336 
337 #define	IP_SQUEUE_ENTER_NODRAIN	1
338 #define	IP_SQUEUE_ENTER	2
339 /*
340  * This is part of the interface between Transport provider and
341  * IP which can be used to set policy information. This is usually
342  * accompanied with O_T_BIND_REQ/T_BIND_REQ.ip_bind assumes that
343  * only IPSEC_POLICY_SET is there when it is found in the chain.
344  * The information contained is an struct ipsec_req_t. On success
345  * or failure, either the T_BIND_ACK or the T_ERROR_ACK is returned.
346  * IPSEC_POLICY_SET is never returned.
347  */
348 #define	IPSEC_POLICY_SET	M_SETOPTS
349 
350 #define	IRE_IS_LOCAL(ire)	((ire != NULL) && \
351 				((ire)->ire_type & (IRE_LOCAL | IRE_LOOPBACK)))
352 
353 #define	IRE_IS_TARGET(ire)	((ire != NULL) && \
354 				((ire)->ire_type != IRE_BROADCAST))
355 
356 /* IP Fragmentation Reassembly Header */
357 typedef struct ipf_s {
358 	struct ipf_s	*ipf_hash_next;
359 	struct ipf_s	**ipf_ptphn;	/* Pointer to previous hash next. */
360 	uint32_t	ipf_ident;	/* Ident to match. */
361 	uint8_t		ipf_protocol;	/* Protocol to match. */
362 	uchar_t		ipf_last_frag_seen : 1;	/* Last fragment seen ? */
363 	time_t		ipf_timestamp;	/* Reassembly start time. */
364 	mblk_t		*ipf_mp;	/* mblk we live in. */
365 	mblk_t		*ipf_tail_mp;	/* Frag queue tail pointer. */
366 	int		ipf_hole_cnt;	/* Number of holes (hard-case). */
367 	int		ipf_end;	/* Tail end offset (0 -> hard-case). */
368 	uint_t		ipf_gen;	/* Frag queue generation */
369 	size_t		ipf_count;	/* Count of bytes used by frag */
370 	uint_t		ipf_nf_hdr_len; /* Length of nonfragmented header */
371 	in6_addr_t	ipf_v6src;	/* IPv6 source address */
372 	in6_addr_t	ipf_v6dst;	/* IPv6 dest address */
373 	uint_t		ipf_prev_nexthdr_offset; /* Offset for nexthdr value */
374 	uint8_t		ipf_ecn;	/* ECN info for the fragments */
375 	uint8_t		ipf_num_dups;	/* Number of times dup frags recvd */
376 	uint16_t	ipf_checksum_flags; /* Hardware checksum flags */
377 	uint32_t	ipf_checksum;	/* Partial checksum of fragment data */
378 } ipf_t;
379 
380 /*
381  * IPv4 Fragments
382  */
383 #define	IS_V4_FRAGMENT(ipha_fragment_offset_and_flags)			\
384 	(((ntohs(ipha_fragment_offset_and_flags) & IPH_OFFSET) != 0) ||	\
385 	((ntohs(ipha_fragment_offset_and_flags) & IPH_MF) != 0))
386 
387 #define	ipf_src	V4_PART_OF_V6(ipf_v6src)
388 #define	ipf_dst	V4_PART_OF_V6(ipf_v6dst)
389 
390 typedef enum {
391 	IB_PKT = 0x01,
392 	OB_PKT = 0x02
393 } ip_pkt_t;
394 
395 #define	UPDATE_IB_PKT_COUNT(ire)\
396 	{ \
397 	(ire)->ire_ib_pkt_count++; \
398 	if ((ire)->ire_ipif != NULL) { \
399 		/* \
400 		 * forwarding packet \
401 		 */ \
402 		if ((ire)->ire_type & (IRE_LOCAL|IRE_BROADCAST)) \
403 			atomic_add_32(&(ire)->ire_ipif->ipif_ib_pkt_count, 1);\
404 		else \
405 			atomic_add_32(&(ire)->ire_ipif->ipif_fo_pkt_count, 1);\
406 	} \
407 	}
408 
409 #define	UPDATE_OB_PKT_COUNT(ire)\
410 	{ \
411 	(ire)->ire_ob_pkt_count++;\
412 	if ((ire)->ire_ipif != NULL) { \
413 		atomic_add_32(&(ire)->ire_ipif->ipif_ob_pkt_count, 1); \
414 	} \
415 	}
416 
417 #define	IP_RPUT_LOCAL(q, mp, ipha, ire, recv_ill) \
418 { \
419 	switch (ipha->ipha_protocol) { \
420 		case IPPROTO_UDP: \
421 			ip_udp_input(q, mp, ipha, ire, recv_ill); \
422 			break; \
423 		default: \
424 			ip_proto_input(q, mp, ipha, ire, recv_ill, 0); \
425 			break; \
426 	} \
427 }
428 
429 /*
430  * NCE_EXPIRED is TRUE when we have a non-permanent nce that was
431  * found to be REACHABLE more than ip_ire_arp_interval ms ago.
432  * This macro is used to age existing nce_t entries. The
433  * nce's will get cleaned up in the following circumstances:
434  * - ip_ire_trash_reclaim will free nce's using ndp_cache_reclaim
435  *    when memory is low,
436  * - ip_arp_news, when updates are received.
437  * - if the nce is NCE_EXPIRED(), it will deleted, so that a new
438  *   arp request will need to be triggered from an ND_INITIAL nce.
439  *
440  * Note that the nce state transition follows the pattern:
441  *	ND_INITIAL -> ND_INCOMPLETE -> ND_REACHABLE
442  * after which the nce is deleted when it has expired.
443  *
444  * nce_last is the timestamp that indicates when the nce_res_mp in the
445  * nce_t was last updated to a valid link-layer address.  nce_last gets
446  * modified/updated :
447  *  - when the nce is created
448  *  - every time we get a sane arp response for the nce.
449  */
450 #define	NCE_EXPIRED(nce, ipst)	(nce->nce_last > 0 &&	\
451 	    ((nce->nce_flags & NCE_F_PERMANENT) == 0) &&	\
452 	    ((TICK_TO_MSEC(lbolt64) - nce->nce_last) > 		\
453 		(ipst)->ips_ip_ire_arp_interval))
454 
455 #endif /* _KERNEL */
456 
457 /* ICMP types */
458 #define	ICMP_ECHO_REPLY			0
459 #define	ICMP_DEST_UNREACHABLE		3
460 #define	ICMP_SOURCE_QUENCH		4
461 #define	ICMP_REDIRECT			5
462 #define	ICMP_ECHO_REQUEST		8
463 #define	ICMP_ROUTER_ADVERTISEMENT	9
464 #define	ICMP_ROUTER_SOLICITATION	10
465 #define	ICMP_TIME_EXCEEDED		11
466 #define	ICMP_PARAM_PROBLEM		12
467 #define	ICMP_TIME_STAMP_REQUEST		13
468 #define	ICMP_TIME_STAMP_REPLY		14
469 #define	ICMP_INFO_REQUEST		15
470 #define	ICMP_INFO_REPLY			16
471 #define	ICMP_ADDRESS_MASK_REQUEST	17
472 #define	ICMP_ADDRESS_MASK_REPLY		18
473 
474 /* ICMP_TIME_EXCEEDED codes */
475 #define	ICMP_TTL_EXCEEDED		0
476 #define	ICMP_REASSEMBLY_TIME_EXCEEDED	1
477 
478 /* ICMP_DEST_UNREACHABLE codes */
479 #define	ICMP_NET_UNREACHABLE		0
480 #define	ICMP_HOST_UNREACHABLE		1
481 #define	ICMP_PROTOCOL_UNREACHABLE	2
482 #define	ICMP_PORT_UNREACHABLE		3
483 #define	ICMP_FRAGMENTATION_NEEDED	4
484 #define	ICMP_SOURCE_ROUTE_FAILED	5
485 #define	ICMP_DEST_NET_UNKNOWN		6
486 #define	ICMP_DEST_HOST_UNKNOWN		7
487 #define	ICMP_SRC_HOST_ISOLATED		8
488 #define	ICMP_DEST_NET_UNREACH_ADMIN	9
489 #define	ICMP_DEST_HOST_UNREACH_ADMIN	10
490 #define	ICMP_DEST_NET_UNREACH_TOS	11
491 #define	ICMP_DEST_HOST_UNREACH_TOS	12
492 
493 /* ICMP Header Structure */
494 typedef struct icmph_s {
495 	uint8_t		icmph_type;
496 	uint8_t		icmph_code;
497 	uint16_t	icmph_checksum;
498 	union {
499 		struct { /* ECHO request/response structure */
500 			uint16_t	u_echo_ident;
501 			uint16_t	u_echo_seqnum;
502 		} u_echo;
503 		struct { /* Destination unreachable structure */
504 			uint16_t	u_du_zero;
505 			uint16_t	u_du_mtu;
506 		} u_du;
507 		struct { /* Parameter problem structure */
508 			uint8_t		u_pp_ptr;
509 			uint8_t		u_pp_rsvd[3];
510 		} u_pp;
511 		struct { /* Redirect structure */
512 			ipaddr_t	u_rd_gateway;
513 		} u_rd;
514 	} icmph_u;
515 } icmph_t;
516 
517 #define	icmph_echo_ident	icmph_u.u_echo.u_echo_ident
518 #define	icmph_echo_seqnum	icmph_u.u_echo.u_echo_seqnum
519 #define	icmph_du_zero		icmph_u.u_du.u_du_zero
520 #define	icmph_du_mtu		icmph_u.u_du.u_du_mtu
521 #define	icmph_pp_ptr		icmph_u.u_pp.u_pp_ptr
522 #define	icmph_rd_gateway	icmph_u.u_rd.u_rd_gateway
523 
524 #define	ICMPH_SIZE	8
525 
526 /*
527  * Minimum length of transport layer header included in an ICMP error
528  * message for it to be considered valid.
529  */
530 #define	ICMP_MIN_TP_HDR_LEN	8
531 
532 /* Aligned IP header */
533 typedef struct ipha_s {
534 	uint8_t		ipha_version_and_hdr_length;
535 	uint8_t		ipha_type_of_service;
536 	uint16_t	ipha_length;
537 	uint16_t	ipha_ident;
538 	uint16_t	ipha_fragment_offset_and_flags;
539 	uint8_t		ipha_ttl;
540 	uint8_t		ipha_protocol;
541 	uint16_t	ipha_hdr_checksum;
542 	ipaddr_t	ipha_src;
543 	ipaddr_t	ipha_dst;
544 } ipha_t;
545 
546 /*
547  * IP Flags
548  *
549  * Some of these constant names are copied for the DTrace IP provider in
550  * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
551  * in sync.
552  */
553 #define	IPH_DF		0x4000	/* Don't fragment */
554 #define	IPH_MF		0x2000	/* More fragments to come */
555 #define	IPH_OFFSET	0x1FFF	/* Where the offset lives */
556 #define	IPH_FRAG_HDR	0x8000	/* IPv6 don't fragment bit */
557 
558 /* ECN code points for IPv4 TOS byte and IPv6 traffic class octet. */
559 #define	IPH_ECN_NECT	0x0	/* Not ECN-Capable Transport */
560 #define	IPH_ECN_ECT1	0x1	/* ECN-Capable Transport, ECT(1) */
561 #define	IPH_ECN_ECT0	0x2	/* ECN-Capable Transport, ECT(0) */
562 #define	IPH_ECN_CE	0x3	/* ECN-Congestion Experienced (CE) */
563 
564 struct ill_s;
565 
566 typedef	boolean_t ip_v6intfid_func_t(struct ill_s *, in6_addr_t *);
567 typedef	boolean_t ip_v6mapinfo_func_t(uint_t, uint8_t *, uint8_t *, uint32_t *,
568     in6_addr_t *);
569 typedef boolean_t ip_v4mapinfo_func_t(uint_t, uint8_t *, uint8_t *, uint32_t *,
570     ipaddr_t *);
571 
572 /* IP Mac info structure */
573 typedef struct ip_m_s {
574 	t_uscalar_t		ip_m_mac_type;	/* From <sys/dlpi.h> */
575 	int			ip_m_type;	/* From <net/if_types.h> */
576 	ip_v4mapinfo_func_t	*ip_m_v4mapinfo;
577 	ip_v6mapinfo_func_t	*ip_m_v6mapinfo;
578 	ip_v6intfid_func_t	*ip_m_v6intfid;
579 } ip_m_t;
580 
581 /*
582  * The following functions attempt to reduce the link layer dependency
583  * of the IP stack. The current set of link specific operations are:
584  * a. map from IPv4 class D (224.0/4) multicast address range to the link
585  * layer multicast address range.
586  * b. map from IPv6 multicast address range (ff00::/8) to the link
587  * layer multicast address range.
588  * c. derive the default IPv6 interface identifier from the interface.
589  * d. derive the default IPv6 destination interface identifier from
590  * the interface (point-to-point only).
591  */
592 #define	MEDIA_V4MINFO(ip_m, plen, bphys, maddr, hwxp, v4ptr) \
593 	(((ip_m)->ip_m_v4mapinfo != NULL) && \
594 	(*(ip_m)->ip_m_v4mapinfo)(plen, bphys, maddr, hwxp, v4ptr))
595 #define	MEDIA_V6MINFO(ip_m, plen, bphys, maddr, hwxp, v6ptr) \
596 	(((ip_m)->ip_m_v6mapinfo != NULL) && \
597 	(*(ip_m)->ip_m_v6mapinfo)(plen, bphys, maddr, hwxp, v6ptr))
598 #define	MEDIA_V6INTFID(ip_m, ill, v6ptr) \
599 	(((ip_m)->ip_m_v6intfid != NULL) && \
600 	(*(ip_m)->ip_m_v6intfid)(ill, v6ptr))
601 #define	MEDIA_V6DESTINTFID(ip_m, ill, v6ptr) \
602 	(((ip_m)->ip_m_v6destintfid != NULL) && \
603 	(*(ip_m)->ip_m_v6destintfid)(ill, v6ptr))
604 
605 /* Router entry types */
606 #define	IRE_BROADCAST		0x0001	/* Route entry for broadcast address */
607 #define	IRE_DEFAULT		0x0002	/* Route entry for default gateway */
608 #define	IRE_LOCAL		0x0004	/* Route entry for local address */
609 #define	IRE_LOOPBACK		0x0008	/* Route entry for loopback address */
610 #define	IRE_PREFIX		0x0010	/* Route entry for prefix routes */
611 #define	IRE_CACHE		0x0020	/* Cached Route entry */
612 #define	IRE_IF_NORESOLVER	0x0040	/* Route entry for local interface */
613 					/* net without any address mapping. */
614 #define	IRE_IF_RESOLVER		0x0080	/* Route entry for local interface */
615 					/* net with resolver. */
616 #define	IRE_HOST		0x0100	/* Host route entry */
617 #define	IRE_HOST_REDIRECT	0x0200	/* only used for T_SVR4_OPTMGMT_REQ */
618 
619 #define	IRE_INTERFACE		(IRE_IF_NORESOLVER | IRE_IF_RESOLVER)
620 #define	IRE_OFFSUBNET		(IRE_DEFAULT | IRE_PREFIX | IRE_HOST)
621 #define	IRE_CACHETABLE		(IRE_CACHE | IRE_BROADCAST | IRE_LOCAL | \
622 				IRE_LOOPBACK)
623 #define	IRE_FORWARDTABLE	(IRE_INTERFACE | IRE_OFFSUBNET)
624 
625 /*
626  * If an IRE is marked with IRE_MARK_CONDEMNED, the last walker of
627  * the bucket should delete this IRE from this bucket.
628  */
629 #define	IRE_MARK_CONDEMNED	0x0001
630 
631 /*
632  * An IRE with IRE_MARK_PMTU has ire_max_frag set from an ICMP error.
633  */
634 #define	IRE_MARK_PMTU		0x0002
635 
636 /*
637  * An IRE with IRE_MARK_TESTHIDDEN is used by in.mpathd for test traffic.  It
638  * can only be looked up by requesting MATCH_IRE_MARK_TESTHIDDEN.
639  */
640 #define	IRE_MARK_TESTHIDDEN	0x0004
641 
642 /*
643  * An IRE with IRE_MARK_NOADD is created in ip_newroute_ipif when the outgoing
644  * interface is specified by e.g. IP_PKTINFO.  The IRE is not added to the IRE
645  * cache table.
646  */
647 #define	IRE_MARK_NOADD		0x0008	/* Mark not to add ire in cache */
648 
649 /*
650  * IRE marked with IRE_MARK_TEMPORARY means that this IRE has been used
651  * either for forwarding a packet or has not been used for sending
652  * traffic on TCP connections terminated on this system.  In both
653  * cases, this IRE is the first to go when IRE is being cleaned up.
654  */
655 #define	IRE_MARK_TEMPORARY	0x0010
656 
657 /*
658  * IRE marked with IRE_MARK_USESRC_CHECK means that while adding an IRE with
659  * this mark, additional atomic checks need to be performed. For eg: by the
660  * time an IRE_CACHE is created, sent up to ARP and then comes back to IP; the
661  * usesrc grouping could have changed in which case we want to fail adding
662  * the IRE_CACHE entry
663  */
664 #define	IRE_MARK_USESRC_CHECK	0x0020
665 
666 /*
667  * IRE_MARK_PRIVATE_ADDR is used for IP_NEXTHOP. When IP_NEXTHOP is set, the
668  * routing table lookup for the destination is bypassed and the packet is
669  * sent directly to the specified nexthop. The associated IRE_CACHE entries
670  * should be marked with IRE_MARK_PRIVATE_ADDR flag so that they don't show up
671  * in regular ire cache lookups.
672  */
673 #define	IRE_MARK_PRIVATE_ADDR	0x0040
674 
675 /*
676  * When we send an ARP resolution query for the nexthop gateway's ire,
677  * we use esballoc to create the ire_t in the AR_ENTRY_QUERY mblk
678  * chain, and mark its ire_marks with IRE_MARK_UNCACHED. This flag
679  * indicates that information from ARP has not been transferred to a
680  * permanent IRE_CACHE entry. The flag is reset only when the
681  * information is successfully transferred to an ire_cache entry (in
682  * ire_add()). Attempting to free the AR_ENTRY_QUERY mblk chain prior
683  * to ire_add (e.g., from arp, or from ip`ip_wput_nondata) will
684  * require that the resources (incomplete ire_cache and/or nce) must
685  * be cleaned up. The free callback routine (ire_freemblk()) checks
686  * for IRE_MARK_UNCACHED to see if any resources that are pinned down
687  * will need to be cleaned up or not.
688  */
689 
690 #define	IRE_MARK_UNCACHED	0x0080
691 
692 /*
693  * The comment below (and for other netstack_t references) refers
694  * to the fact that we only do netstack_hold in particular cases,
695  * such as the references from open streams (ill_t and conn_t's
696  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
697  * ire_t's when an ill goes away.
698  */
699 typedef struct ire_expire_arg_s {
700 	int		iea_flush_flag;
701 	ip_stack_t	*iea_ipst;	/* Does not have a netstack_hold */
702 } ire_expire_arg_t;
703 
704 /* Flags with ire_expire routine */
705 #define	FLUSH_ARP_TIME		0x0001	/* ARP info potentially stale timer */
706 #define	FLUSH_REDIRECT_TIME	0x0002	/* Redirects potentially stale */
707 #define	FLUSH_MTU_TIME		0x0004	/* Include path MTU per RFC 1191 */
708 
709 /* Arguments to ire_flush_cache() */
710 #define	IRE_FLUSH_DELETE	0
711 #define	IRE_FLUSH_ADD		1
712 
713 /*
714  * Open/close synchronization flags.
715  * These are kept in a separate field in the conn and the synchronization
716  * depends on the atomic 32 bit access to that field.
717  */
718 #define	CONN_CLOSING		0x01	/* ip_close waiting for ip_wsrv */
719 #define	CONN_IPSEC_LOAD_WAIT	0x02	/* waiting for load */
720 #define	CONN_CONDEMNED		0x04	/* conn is closing, no more refs */
721 #define	CONN_INCIPIENT		0x08	/* conn not yet visible, no refs */
722 #define	CONN_QUIESCED		0x10	/* conn is now quiescent */
723 
724 /* Used to check connection state flags before caching the IRE */
725 #define	CONN_CACHE_IRE(connp)	\
726 	(!((connp)->conn_state_flags & (CONN_CLOSING|CONN_CONDEMNED)))
727 
728 /*
729  * Parameter to ip_output giving the identity of the caller.
730  * IP_WSRV means the packet was enqueued in the STREAMS queue
731  * due to flow control and is now being reprocessed in the context of
732  * the STREAMS service procedure, consequent to flow control relief.
733  * IRE_SEND means the packet is being reprocessed consequent to an
734  * ire cache creation and addition and this may or may not be happening
735  * in the service procedure context. Anything other than the above 2
736  * cases is identified as IP_WPUT. Most commonly this is the case of
737  * packets coming down from the application.
738  */
739 #ifdef _KERNEL
740 #define	IP_WSRV			1	/* Called from ip_wsrv */
741 #define	IP_WPUT			2	/* Called from ip_wput */
742 #define	IRE_SEND		3	/* Called from ire_send */
743 
744 /*
745  * Extra structures need for per-src-addr filtering (IGMPv3/MLDv2)
746  */
747 #define	MAX_FILTER_SIZE	64
748 
749 typedef struct slist_s {
750 	int		sl_numsrc;
751 	in6_addr_t	sl_addr[MAX_FILTER_SIZE];
752 } slist_t;
753 
754 /*
755  * Following struct is used to maintain retransmission state for
756  * a multicast group.  One rtx_state_t struct is an in-line field
757  * of the ilm_t struct; the slist_ts in the rtx_state_t struct are
758  * alloc'd as needed.
759  */
760 typedef struct rtx_state_s {
761 	uint_t		rtx_timer;	/* retrans timer */
762 	int		rtx_cnt;	/* retrans count */
763 	int		rtx_fmode_cnt;	/* retrans count for fmode change */
764 	slist_t		*rtx_allow;
765 	slist_t		*rtx_block;
766 } rtx_state_t;
767 
768 /*
769  * Used to construct list of multicast address records that will be
770  * sent in a single listener report.
771  */
772 typedef struct mrec_s {
773 	struct mrec_s	*mrec_next;
774 	uint8_t		mrec_type;
775 	uint8_t		mrec_auxlen;	/* currently unused */
776 	in6_addr_t	mrec_group;
777 	slist_t		mrec_srcs;
778 } mrec_t;
779 
780 /* Group membership list per upper conn */
781 /*
782  * XXX add ilg info for ifaddr/ifindex.
783  * XXX can we make ilg survive an ifconfig unplumb + plumb
784  * by setting the ipif/ill to NULL and recover that later?
785  *
786  * ilg_ipif is used by IPv4 as multicast groups are joined using an interface
787  * address (ipif).
788  * ilg_ill is used by IPv6 as multicast groups are joined using an interface
789  * index (phyint->phyint_ifindex).
790  * ilg_ill is NULL for IPv4 and ilg_ipif is NULL for IPv6.
791  *
792  * ilg records the state of multicast memberships of a socket end point.
793  * ilm records the state of multicast memberships with the driver and is
794  * maintained per interface.
795  *
796  * There is no direct link between a given ilg and ilm. If the
797  * application has joined a group G with ifindex I, we will have
798  * an ilg with ilg_v6group and ilg_ill. There will be a corresponding
799  * ilm with ilm_ill/ilm_v6addr recording the multicast membership.
800  * To delete the membership:
801  *
802  *	a) Search for ilg matching on G and I with ilg_v6group
803  *	   and ilg_ill. Delete ilg_ill.
804  *	b) Search the corresponding ilm matching on G and I with
805  *	   ilm_v6addr and ilm_ill. Delete ilm.
806  *
807  * For IPv4 the only difference is that we look using ipifs, not ills.
808  */
809 
810 /*
811  * The ilg_t and ilm_t members are protected by ipsq. They can be changed only
812  * by a thread executing in the ipsq. In other words add/delete of a
813  * multicast group has to execute in the ipsq.
814  */
815 #define	ILG_DELETED	0x1		/* ilg_flags */
816 typedef struct ilg_s {
817 	in6_addr_t	ilg_v6group;
818 	struct ipif_s	*ilg_ipif;	/* Logical interface we are member on */
819 	struct ill_s	*ilg_ill;	/* Used by IPv6 */
820 	uint_t		ilg_flags;
821 	mcast_record_t	ilg_fmode;	/* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
822 	slist_t		*ilg_filter;
823 } ilg_t;
824 
825 /*
826  * Multicast address list entry for ill.
827  * ilm_ipif is used by IPv4 as multicast groups are joined using ipif.
828  * ilm_ill is used by IPv6 as multicast groups are joined using ill.
829  * ilm_ill is NULL for IPv4 and ilm_ipif is NULL for IPv6.
830  *
831  * The comment below (and for other netstack_t references) refers
832  * to the fact that we only do netstack_hold in particular cases,
833  * such as the references from open streams (ill_t and conn_t's
834  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
835  * ire_t's when an ill goes away.
836  */
837 #define	ILM_DELETED	0x1		/* ilm_flags */
838 typedef struct ilm_s {
839 	in6_addr_t	ilm_v6addr;
840 	int		ilm_refcnt;
841 	uint_t		ilm_timer;	/* IGMP/MLD query resp timer, in msec */
842 	struct ipif_s	*ilm_ipif;	/* Back pointer to ipif for IPv4 */
843 	struct ilm_s	*ilm_next;	/* Linked list for each ill */
844 	uint_t		ilm_state;	/* state of the membership */
845 	struct ill_s	*ilm_ill;	/* Back pointer to ill for IPv6 */
846 	uint_t		ilm_flags;
847 	boolean_t	ilm_notify_driver; /* Need to notify the driver */
848 	zoneid_t	ilm_zoneid;
849 	int		ilm_no_ilg_cnt;	/* number of joins w/ no ilg */
850 	mcast_record_t	ilm_fmode;	/* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
851 	slist_t		*ilm_filter;	/* source filter list */
852 	slist_t		*ilm_pendsrcs;	/* relevant src addrs for pending req */
853 	rtx_state_t	ilm_rtx;	/* SCR retransmission state */
854 	ip_stack_t	*ilm_ipst;	/* Does not have a netstack_hold */
855 } ilm_t;
856 
857 #define	ilm_addr	V4_PART_OF_V6(ilm_v6addr)
858 
859 typedef struct ilm_walker {
860 	struct ill_s	*ilw_ill;	/* associated ill */
861 	struct ill_s	*ilw_ipmp_ill; 	/* associated ipmp ill (if any) */
862 	struct ill_s	*ilw_walk_ill; 	/* current ill being walked */
863 } ilm_walker_t;
864 
865 /*
866  * Soft reference to an IPsec SA.
867  *
868  * On relative terms, conn's can be persistent (living as long as the
869  * processes which create them), while SA's are ephemeral (dying when
870  * they hit their time-based or byte-based lifetimes).
871  *
872  * We could hold a hard reference to an SA from an ipsec_latch_t,
873  * but this would cause expired SA's to linger for a potentially
874  * unbounded time.
875  *
876  * Instead, we remember the hash bucket number and bucket generation
877  * in addition to the pointer.  The bucket generation is incremented on
878  * each deletion.
879  */
880 typedef struct ipsa_ref_s
881 {
882 	struct ipsa_s	*ipsr_sa;
883 	struct isaf_s	*ipsr_bucket;
884 	uint64_t	ipsr_gen;
885 } ipsa_ref_t;
886 
887 /*
888  * IPsec "latching" state.
889  *
890  * In the presence of IPsec policy, fully-bound conn's bind a connection
891  * to more than just the 5-tuple, but also a specific IPsec action and
892  * identity-pair.
893  *
894  * As an optimization, we also cache soft references to IPsec SA's
895  * here so that we can fast-path around most of the work needed for
896  * outbound IPsec SA selection.
897  *
898  * Were it not for TCP's detached connections, this state would be
899  * in-line in conn_t; instead, this is in a separate structure so it
900  * can be handed off to TCP when a connection is detached.
901  */
902 typedef struct ipsec_latch_s
903 {
904 	kmutex_t	ipl_lock;
905 	uint32_t	ipl_refcnt;
906 
907 	uint64_t	ipl_unique;
908 	struct ipsec_policy_s	*ipl_in_policy; /* latched policy (in) */
909 	struct ipsec_policy_s	*ipl_out_policy; /* latched policy (out) */
910 	struct ipsec_action_s	*ipl_in_action;	/* latched action (in) */
911 	struct ipsec_action_s	*ipl_out_action; /* latched action (out) */
912 	cred_t		*ipl_local_id;
913 	struct ipsid_s	*ipl_local_cid;
914 	struct ipsid_s	*ipl_remote_cid;
915 	unsigned int
916 			ipl_out_action_latched : 1,
917 			ipl_in_action_latched : 1,
918 			ipl_out_policy_latched : 1,
919 			ipl_in_policy_latched : 1,
920 
921 			ipl_ids_latched : 1,
922 
923 			ipl_pad_to_bit_31 : 27;
924 
925 	ipsa_ref_t	ipl_ref[2]; /* 0: ESP, 1: AH */
926 
927 } ipsec_latch_t;
928 
929 #define	IPLATCH_REFHOLD(ipl) { \
930 	atomic_add_32(&(ipl)->ipl_refcnt, 1);		\
931 	ASSERT((ipl)->ipl_refcnt != 0);			\
932 }
933 
934 #define	IPLATCH_REFRELE(ipl, ns) {				\
935 	ASSERT((ipl)->ipl_refcnt != 0);				\
936 	membar_exit();						\
937 	if (atomic_add_32_nv(&(ipl)->ipl_refcnt, -1) == 0)	\
938 		iplatch_free(ipl, ns);			\
939 }
940 
941 /*
942  * peer identity structure.
943  */
944 
945 typedef struct conn_s conn_t;
946 
947 /*
948  * The old IP client structure "ipc_t" is gone. All the data is stored in the
949  * connection structure "conn_t" now. The mapping of old and new fields looks
950  * like this:
951  *
952  * ipc_ulp			conn_ulp
953  * ipc_rq			conn_rq
954  * ipc_wq			conn_wq
955  *
956  * ipc_laddr			conn_src
957  * ipc_faddr			conn_rem
958  * ipc_v6laddr			conn_srcv6
959  * ipc_v6faddr			conn_remv6
960  *
961  * ipc_lport			conn_lport
962  * ipc_fport			conn_fport
963  * ipc_ports			conn_ports
964  *
965  * ipc_policy			conn_policy
966  * ipc_latch			conn_latch
967  *
968  * ipc_irc_lock			conn_lock
969  * ipc_ire_cache		conn_ire_cache
970  *
971  * ipc_state_flags		conn_state_flags
972  * ipc_outgoing_ill		conn_outgoing_ill
973  *
974  * ipc_dontroute 		conn_dontroute
975  * ipc_loopback 		conn_loopback
976  * ipc_broadcast		conn_broadcast
977  * ipc_reuseaddr		conn_reuseaddr
978  *
979  * ipc_multicast_loop		conn_multicast_loop
980  * ipc_multi_router		conn_multi_router
981  * ipc_draining 		conn_draining
982  *
983  * ipc_did_putbq		conn_did_putbq
984  * ipc_unspec_src		conn_unspec_src
985  * ipc_policy_cached		conn_policy_cached
986  *
987  * ipc_in_enforce_policy 	conn_in_enforce_policy
988  * ipc_out_enforce_policy 	conn_out_enforce_policy
989  * ipc_af_isv6			conn_af_isv6
990  * ipc_pkt_isv6			conn_pkt_isv6
991  *
992  * ipc_ipv6_recvpktinfo		conn_ipv6_recvpktinfo
993  *
994  * ipc_ipv6_recvhoplimit	conn_ipv6_recvhoplimit
995  * ipc_ipv6_recvhopopts		conn_ipv6_recvhopopts
996  * ipc_ipv6_recvdstopts		conn_ipv6_recvdstopts
997  *
998  * ipc_ipv6_recvrthdr 		conn_ipv6_recvrthdr
999  * ipc_ipv6_recvrtdstopts	conn_ipv6_recvrtdstopts
1000  * ipc_fully_bound		conn_fully_bound
1001  *
1002  * ipc_recvif			conn_recvif
1003  *
1004  * ipc_recvslla 		conn_recvslla
1005  * ipc_acking_unbind 		conn_acking_unbind
1006  * ipc_pad_to_bit_31 		conn_pad_to_bit_31
1007  *
1008  * ipc_proto			conn_proto
1009  * ipc_incoming_ill		conn_incoming_ill
1010  * ipc_pending_ill		conn_pending_ill
1011  * ipc_unbind_mp		conn_unbind_mp
1012  * ipc_ilg			conn_ilg
1013  * ipc_ilg_allocated		conn_ilg_allocated
1014  * ipc_ilg_inuse		conn_ilg_inuse
1015  * ipc_ilg_walker_cnt		conn_ilg_walker_cnt
1016  * ipc_refcv			conn_refcv
1017  * ipc_multicast_ipif		conn_multicast_ipif
1018  * ipc_multicast_ill		conn_multicast_ill
1019  * ipc_drain_next		conn_drain_next
1020  * ipc_drain_prev		conn_drain_prev
1021  * ipc_idl			conn_idl
1022  */
1023 
1024 /*
1025  * This is used to match an inbound/outbound datagram with policy.
1026  */
1027 typedef	struct ipsec_selector {
1028 	in6_addr_t	ips_local_addr_v6;
1029 	in6_addr_t	ips_remote_addr_v6;
1030 	uint16_t	ips_local_port;
1031 	uint16_t	ips_remote_port;
1032 	uint8_t		ips_icmp_type;
1033 	uint8_t		ips_icmp_code;
1034 	uint8_t		ips_protocol;
1035 	uint8_t		ips_isv4 : 1,
1036 			ips_is_icmp_inv_acq: 1;
1037 } ipsec_selector_t;
1038 
1039 /*
1040  * Note that we put v4 addresses in the *first* 32-bit word of the
1041  * selector rather than the last to simplify the prefix match/mask code
1042  * in spd.c
1043  */
1044 #define	ips_local_addr_v4 ips_local_addr_v6.s6_addr32[0]
1045 #define	ips_remote_addr_v4 ips_remote_addr_v6.s6_addr32[0]
1046 
1047 /* Values used in IP by IPSEC Code */
1048 #define		IPSEC_OUTBOUND		B_TRUE
1049 #define		IPSEC_INBOUND		B_FALSE
1050 
1051 /*
1052  * There are two variants in policy failures. The packet may come in
1053  * secure when not needed (IPSEC_POLICY_???_NOT_NEEDED) or it may not
1054  * have the desired level of protection (IPSEC_POLICY_MISMATCH).
1055  */
1056 #define	IPSEC_POLICY_NOT_NEEDED		0
1057 #define	IPSEC_POLICY_MISMATCH		1
1058 #define	IPSEC_POLICY_AUTH_NOT_NEEDED	2
1059 #define	IPSEC_POLICY_ENCR_NOT_NEEDED	3
1060 #define	IPSEC_POLICY_SE_NOT_NEEDED	4
1061 #define	IPSEC_POLICY_MAX		5	/* Always max + 1. */
1062 
1063 /*
1064  * Folowing macro is used whenever the code does not know whether there
1065  * is a M_CTL present in the front and it needs to examine the actual mp
1066  * i.e the IP header. As a M_CTL message could be in the front, this
1067  * extracts the packet into mp and the M_CTL mp into first_mp. If M_CTL
1068  * mp is not present, both first_mp and mp point to the same message.
1069  */
1070 #define	EXTRACT_PKT_MP(mp, first_mp, mctl_present)	\
1071 	(first_mp) = (mp);				\
1072 	if ((mp)->b_datap->db_type == M_CTL) {		\
1073 		(mp) = (mp)->b_cont;			\
1074 		(mctl_present) = B_TRUE;		\
1075 	} else {					\
1076 		(mctl_present) = B_FALSE;		\
1077 	}
1078 
1079 /*
1080  * Check with IPSEC inbound policy if
1081  *
1082  * 1) per-socket policy is present - indicated by conn_in_enforce_policy.
1083  * 2) Or if we have not cached policy on the conn and the global policy is
1084  *    non-empty.
1085  */
1086 #define	CONN_INBOUND_POLICY_PRESENT(connp, ipss)	\
1087 	((connp)->conn_in_enforce_policy ||		\
1088 	(!((connp)->conn_policy_cached) && 		\
1089 	(ipss)->ipsec_inbound_v4_policy_present))
1090 
1091 #define	CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss)	\
1092 	((connp)->conn_in_enforce_policy ||		\
1093 	(!(connp)->conn_policy_cached &&		\
1094 	(ipss)->ipsec_inbound_v6_policy_present))
1095 
1096 #define	CONN_OUTBOUND_POLICY_PRESENT(connp, ipss)	\
1097 	((connp)->conn_out_enforce_policy ||		\
1098 	(!((connp)->conn_policy_cached) &&		\
1099 	(ipss)->ipsec_outbound_v4_policy_present))
1100 
1101 #define	CONN_OUTBOUND_POLICY_PRESENT_V6(connp, ipss)	\
1102 	((connp)->conn_out_enforce_policy ||		\
1103 	(!(connp)->conn_policy_cached &&		\
1104 	(ipss)->ipsec_outbound_v6_policy_present))
1105 
1106 /*
1107  * Information cached in IRE for upper layer protocol (ULP).
1108  *
1109  * Notice that ire_max_frag is not included in the iulp_t structure, which
1110  * it may seem that it should.  But ire_max_frag cannot really be cached.  It
1111  * is fixed for each interface.  For MTU found by PMTUd, we may want to cache
1112  * it.  But currently, we do not do that.
1113  */
1114 typedef struct iulp_s {
1115 	boolean_t	iulp_set;	/* Is any metric set? */
1116 	uint32_t	iulp_ssthresh;	/* Slow start threshold (TCP). */
1117 	clock_t		iulp_rtt;	/* Guestimate in millisecs. */
1118 	clock_t		iulp_rtt_sd;	/* Cached value of RTT variance. */
1119 	uint32_t	iulp_spipe;	/* Send pipe size. */
1120 	uint32_t	iulp_rpipe;	/* Receive pipe size. */
1121 	uint32_t	iulp_rtomax;	/* Max round trip timeout. */
1122 	uint32_t	iulp_sack;	/* Use SACK option (TCP)? */
1123 	uint32_t
1124 		iulp_tstamp_ok : 1,	/* Use timestamp option (TCP)? */
1125 		iulp_wscale_ok : 1,	/* Use window scale option (TCP)? */
1126 		iulp_ecn_ok : 1,	/* Enable ECN (for TCP)? */
1127 		iulp_pmtud_ok : 1,	/* Enable PMTUd? */
1128 
1129 		iulp_not_used : 28;
1130 } iulp_t;
1131 
1132 /* Zero iulp_t. */
1133 extern const iulp_t ire_uinfo_null;
1134 
1135 /*
1136  * The conn drain list structure (idl_t).
1137  * The list is protected by idl_lock. Each conn_t inserted in the list
1138  * points back at this idl_t using conn_idl. IP primes the draining of the
1139  * conns queued in these lists, by qenabling the 1st conn of each list. This
1140  * occurs when STREAMS backenables ip_wsrv on the IP module. Each conn instance
1141  * of ip_wsrv successively qenables the next conn in the list.
1142  * idl_lock protects all other members of idl_t and conn_drain_next
1143  * and conn_drain_prev of conn_t. The conn_lock protects IPCF_DRAIN_DISABLED
1144  * flag of the conn_t and conn_idl.
1145  *
1146  * The conn drain list, idl_t, itself is part of tx cookie list structure.
1147  * A tx cookie list points to a blocked Tx ring and contains the list of
1148  * all conn's that are blocked due to the flow-controlled Tx ring (via
1149  * the idl drain list). Note that a link can have multiple Tx rings. The
1150  * drain list will store the conn's blocked due to Tx ring being flow
1151  * controlled.
1152  */
1153 
1154 typedef uintptr_t ip_mac_tx_cookie_t;
1155 typedef	struct idl_s idl_t;
1156 typedef	struct idl_tx_list_s idl_tx_list_t;
1157 
1158 struct idl_tx_list_s {
1159 	ip_mac_tx_cookie_t	txl_cookie;
1160 	kmutex_t		txl_lock;	/* Lock for this list */
1161 	idl_t			*txl_drain_list;
1162 	int			txl_drain_index;
1163 };
1164 
1165 struct idl_s {
1166 	conn_t		*idl_conn;		/* Head of drain list */
1167 	kmutex_t	idl_lock;		/* Lock for this list */
1168 	conn_t		*idl_conn_draining;	/* conn that is draining */
1169 	uint32_t
1170 		idl_repeat : 1,			/* Last conn must re-enable */
1171 						/* drain list again */
1172 		idl_unused : 31;
1173 	idl_tx_list_t	*idl_itl;
1174 };
1175 
1176 #define	CONN_DRAIN_LIST_LOCK(connp)	(&((connp)->conn_idl->idl_lock))
1177 /*
1178  * Interface route structure which holds the necessary information to recreate
1179  * routes that are tied to an interface (namely where ire_ipif != NULL).
1180  * These routes which were initially created via a routing socket or via the
1181  * SIOCADDRT ioctl may be gateway routes (RTF_GATEWAY being set) or may be
1182  * traditional interface routes.  When an interface comes back up after being
1183  * marked down, this information will be used to recreate the routes.  These
1184  * are part of an mblk_t chain that hangs off of the IPIF (ipif_saved_ire_mp).
1185  */
1186 typedef struct ifrt_s {
1187 	ushort_t	ifrt_type;		/* Type of IRE */
1188 	in6_addr_t	ifrt_v6addr;		/* Address IRE represents. */
1189 	in6_addr_t	ifrt_v6gateway_addr;	/* Gateway if IRE_OFFSUBNET */
1190 	in6_addr_t	ifrt_v6src_addr;	/* Src addr if RTF_SETSRC */
1191 	in6_addr_t	ifrt_v6mask;		/* Mask for matching IRE. */
1192 	uint32_t	ifrt_flags;		/* flags related to route */
1193 	uint_t		ifrt_max_frag;		/* MTU (next hop or path). */
1194 	iulp_t		ifrt_iulp_info;		/* Cached IRE ULP info. */
1195 } ifrt_t;
1196 
1197 #define	ifrt_addr		V4_PART_OF_V6(ifrt_v6addr)
1198 #define	ifrt_gateway_addr	V4_PART_OF_V6(ifrt_v6gateway_addr)
1199 #define	ifrt_src_addr		V4_PART_OF_V6(ifrt_v6src_addr)
1200 #define	ifrt_mask		V4_PART_OF_V6(ifrt_v6mask)
1201 
1202 /* Number of IP addresses that can be hosted on a physical interface */
1203 #define	MAX_ADDRS_PER_IF	8192
1204 /*
1205  * Number of Source addresses to be considered for source address
1206  * selection. Used by ipif_select_source[_v6].
1207  */
1208 #define	MAX_IPIF_SELECT_SOURCE	50
1209 
1210 #ifdef IP_DEBUG
1211 /*
1212  * Trace refholds and refreles for debugging.
1213  */
1214 #define	TR_STACK_DEPTH	14
1215 typedef struct tr_buf_s {
1216 	int	tr_depth;
1217 	clock_t	tr_time;
1218 	pc_t	tr_stack[TR_STACK_DEPTH];
1219 } tr_buf_t;
1220 
1221 typedef struct th_trace_s {
1222 	int		th_refcnt;
1223 	uint_t		th_trace_lastref;
1224 	kthread_t	*th_id;
1225 #define	TR_BUF_MAX	38
1226 	tr_buf_t	th_trbuf[TR_BUF_MAX];
1227 } th_trace_t;
1228 
1229 typedef struct th_hash_s {
1230 	list_node_t	thh_link;
1231 	mod_hash_t	*thh_hash;
1232 	ip_stack_t	*thh_ipst;
1233 } th_hash_t;
1234 #endif
1235 
1236 /* The following are ipif_state_flags */
1237 #define	IPIF_CONDEMNED		0x1	/* The ipif is being removed */
1238 #define	IPIF_CHANGING		0x2	/* A critcal ipif field is changing */
1239 #define	IPIF_SET_LINKLOCAL	0x10	/* transient flag during bringup */
1240 #define	IPIF_ZERO_SOURCE	0x20	/* transient flag during bringup */
1241 
1242 /* IP interface structure, one per local address */
1243 typedef struct ipif_s {
1244 	struct	ipif_s	*ipif_next;
1245 	struct	ill_s	*ipif_ill;	/* Back pointer to our ill */
1246 	int	ipif_id;		/* Logical unit number */
1247 	uint_t	ipif_mtu;		/* Starts at ipif_ill->ill_max_frag */
1248 	in6_addr_t ipif_v6lcl_addr;	/* Local IP address for this if. */
1249 	in6_addr_t ipif_v6src_addr;	/* Source IP address for this if. */
1250 	in6_addr_t ipif_v6subnet;	/* Subnet prefix for this if. */
1251 	in6_addr_t ipif_v6net_mask;	/* Net mask for this interface. */
1252 	in6_addr_t ipif_v6brd_addr;	/* Broadcast addr for this interface. */
1253 	in6_addr_t ipif_v6pp_dst_addr;	/* Point-to-point dest address. */
1254 	uint64_t ipif_flags;		/* Interface flags. */
1255 	uint_t	ipif_metric;		/* BSD if metric, for compatibility. */
1256 	uint_t	ipif_ire_type;		/* IRE_LOCAL or IRE_LOOPBACK */
1257 	mblk_t	*ipif_arp_del_mp;	/* Allocated at time arp comes up, to */
1258 					/* prevent awkward out of mem */
1259 					/* condition later */
1260 	mblk_t	*ipif_saved_ire_mp;	/* Allocated for each extra */
1261 					/* IRE_IF_NORESOLVER/IRE_IF_RESOLVER */
1262 					/* on this interface so that they */
1263 					/* can survive ifconfig down. */
1264 	kmutex_t ipif_saved_ire_lock;	/* Protects ipif_saved_ire_mp */
1265 
1266 	mrec_t	*ipif_igmp_rpt;		/* List of group memberships which */
1267 					/* will be reported on.  Used when */
1268 					/* handling an igmp timeout.	   */
1269 
1270 	/*
1271 	 * The packet counts in the ipif contain the sum of the
1272 	 * packet counts in dead IREs that were affiliated with
1273 	 * this ipif.
1274 	 */
1275 	uint_t	ipif_fo_pkt_count;	/* Forwarded thru our dead IREs */
1276 	uint_t	ipif_ib_pkt_count;	/* Inbound packets for our dead IREs */
1277 	uint_t	ipif_ob_pkt_count;	/* Outbound packets to our dead IREs */
1278 	/* Exclusive bit fields, protected by ipsq_t */
1279 	unsigned int
1280 		ipif_multicast_up : 1,	/* ipif_multicast_up() successful */
1281 		ipif_was_up : 1,	/* ipif was up before */
1282 		ipif_addr_ready : 1,	/* DAD is done */
1283 		ipif_was_dup : 1,	/* DAD had failed */
1284 
1285 		ipif_joined_allhosts : 1, /* allhosts joined */
1286 		ipif_added_nce : 1,	/* nce added for local address */
1287 		ipif_pad_to_31 : 26;
1288 
1289 	uint_t	ipif_seqid;		/* unique index across all ills */
1290 	uint_t	ipif_state_flags;	/* See IPIF_* flag defs above */
1291 	uint_t	ipif_refcnt;		/* active consistent reader cnt */
1292 
1293 	/* Number of ire's and ilm's referencing this ipif */
1294 	uint_t	ipif_ire_cnt;
1295 	uint_t	ipif_ilm_cnt;
1296 
1297 	uint_t  ipif_saved_ire_cnt;
1298 	zoneid_t ipif_zoneid;		/* zone ID number */
1299 	timeout_id_t ipif_recovery_id;	/* Timer for DAD recovery */
1300 	boolean_t ipif_trace_disable;	/* True when alloc fails */
1301 	/*
1302 	 * For an IPMP interface, ipif_bound_ill tracks the ill whose hardware
1303 	 * information this ipif is associated with via ARP/NDP.  We can use
1304 	 * an ill pointer (rather than an index) because only ills that are
1305 	 * part of a group will be pointed to, and an ill cannot disappear
1306 	 * while it's in a group.
1307 	 */
1308 	struct ill_s	*ipif_bound_ill;
1309 	struct ipif_s	*ipif_bound_next; /* bound ipif chain */
1310 	boolean_t	ipif_bound;	 /* B_TRUE if we successfully bound */
1311 } ipif_t;
1312 
1313 /*
1314  * IPIF_FREE_OK() means that there are no incoming references
1315  * to the ipif. Incoming refs would prevent the ipif from being freed.
1316  */
1317 #define	IPIF_FREE_OK(ipif)	\
1318 	((ipif)->ipif_ire_cnt == 0 && (ipif)->ipif_ilm_cnt == 0)
1319 /*
1320  * IPIF_DOWN_OK() determines whether the incoming pointer reference counts
1321  * would permit the ipif to be considered quiescent. In order for
1322  * an ipif or ill to be considered quiescent, the ire and nce references
1323  * to that ipif/ill must be zero.
1324  *
1325  * We do not require the ilm references to go to zero for quiescence
1326  * because the quiescence checks are done to ensure that
1327  * outgoing packets do not use addresses from the ipif/ill after it
1328  * has been marked down, and incoming packets to addresses on a
1329  * queiscent interface are rejected. This implies that all the
1330  * ire/nce's using that source address need to be deleted and future
1331  * creation of any ires using that source address must be prevented.
1332  * Similarly incoming unicast packets destined to the 'down' address
1333  * will not be accepted once that ire is gone. However incoming
1334  * multicast packets are not destined to the downed address.
1335  * They are only related to the ill in question. Furthermore
1336  * the current API behavior allows applications to join or leave
1337  * multicast groups, i.e., IP_ADD_MEMBERSHIP / LEAVE_MEMBERSHIP, using a
1338  * down address. Therefore the ilm references are not included in
1339  * the _DOWN_OK macros.
1340  */
1341 #define	IPIF_DOWN_OK(ipif)		((ipif)->ipif_ire_cnt == 0)
1342 
1343 /*
1344  * The following table lists the protection levels of the various members
1345  * of the ipif_t. The following notation is used.
1346  *
1347  * Write once - Written to only once at the time of bringing up
1348  * the interface and can be safely read after the bringup without any lock.
1349  *
1350  * ipsq - Need to execute in the ipsq to perform the indicated access.
1351  *
1352  * ill_lock - Need to hold this mutex to perform the indicated access.
1353  *
1354  * ill_g_lock - Need to hold this rw lock as reader/writer for read access or
1355  * write access respectively.
1356  *
1357  * down ill - Written to only when the ill is down (i.e all ipifs are down)
1358  * up ill - Read only when the ill is up (i.e. at least 1 ipif is up)
1359  *
1360  *		 Table of ipif_t members and their protection
1361  *
1362  * ipif_next		ipsq + ill_lock +	ipsq OR ill_lock OR
1363  *			ill_g_lock		ill_g_lock
1364  * ipif_ill		ipsq + down ipif	write once
1365  * ipif_id		ipsq + down ipif	write once
1366  * ipif_mtu		ipsq
1367  * ipif_v6lcl_addr	ipsq + down ipif	up ipif
1368  * ipif_v6src_addr	ipsq + down ipif	up ipif
1369  * ipif_v6subnet	ipsq + down ipif	up ipif
1370  * ipif_v6net_mask	ipsq + down ipif	up ipif
1371  *
1372  * ipif_v6brd_addr
1373  * ipif_v6pp_dst_addr
1374  * ipif_flags		ill_lock		ill_lock
1375  * ipif_metric
1376  * ipif_ire_type	ipsq + down ill		up ill
1377  *
1378  * ipif_arp_del_mp	ipsq			ipsq
1379  * ipif_saved_ire_mp	ipif_saved_ire_lock	ipif_saved_ire_lock
1380  * ipif_igmp_rpt	ipsq			ipsq
1381  *
1382  * ipif_fo_pkt_count	Approx
1383  * ipif_ib_pkt_count	Approx
1384  * ipif_ob_pkt_count	Approx
1385  *
1386  * bit fields		ill_lock		ill_lock
1387  *
1388  * ipif_seqid		ipsq			Write once
1389  *
1390  * ipif_state_flags	ill_lock		ill_lock
1391  * ipif_refcnt		ill_lock		ill_lock
1392  * ipif_ire_cnt		ill_lock		ill_lock
1393  * ipif_ilm_cnt		ill_lock		ill_lock
1394  * ipif_saved_ire_cnt
1395  *
1396  * ipif_bound_ill	ipsq + ipmp_lock	ipsq OR ipmp_lock
1397  * ipif_bound_next	ipsq			ipsq
1398  * ipif_bound		ipsq			ipsq
1399  */
1400 
1401 #define	IP_TR_HASH(tid)	((((uintptr_t)tid) >> 6) & (IP_TR_HASH_MAX - 1))
1402 
1403 #ifdef DEBUG
1404 #define	IPIF_TRACE_REF(ipif)	ipif_trace_ref(ipif)
1405 #define	ILL_TRACE_REF(ill)	ill_trace_ref(ill)
1406 #define	IPIF_UNTRACE_REF(ipif)	ipif_untrace_ref(ipif)
1407 #define	ILL_UNTRACE_REF(ill)	ill_untrace_ref(ill)
1408 #else
1409 #define	IPIF_TRACE_REF(ipif)
1410 #define	ILL_TRACE_REF(ill)
1411 #define	IPIF_UNTRACE_REF(ipif)
1412 #define	ILL_UNTRACE_REF(ill)
1413 #endif
1414 
1415 /* IPv4 compatibility macros */
1416 #define	ipif_lcl_addr		V4_PART_OF_V6(ipif_v6lcl_addr)
1417 #define	ipif_src_addr		V4_PART_OF_V6(ipif_v6src_addr)
1418 #define	ipif_subnet		V4_PART_OF_V6(ipif_v6subnet)
1419 #define	ipif_net_mask		V4_PART_OF_V6(ipif_v6net_mask)
1420 #define	ipif_brd_addr		V4_PART_OF_V6(ipif_v6brd_addr)
1421 #define	ipif_pp_dst_addr	V4_PART_OF_V6(ipif_v6pp_dst_addr)
1422 
1423 /* Macros for easy backreferences to the ill. */
1424 #define	ipif_wq			ipif_ill->ill_wq
1425 #define	ipif_rq			ipif_ill->ill_rq
1426 #define	ipif_net_type		ipif_ill->ill_net_type
1427 #define	ipif_ipif_up_count	ipif_ill->ill_ipif_up_count
1428 #define	ipif_type		ipif_ill->ill_type
1429 #define	ipif_isv6		ipif_ill->ill_isv6
1430 
1431 #define	SIOCLIFADDR_NDX 112	/* ndx of SIOCLIFADDR in the ndx ioctl table */
1432 
1433 /*
1434  * mode value for ip_ioctl_finish for finishing an ioctl
1435  */
1436 #define	CONN_CLOSE	1		/* No mi_copy */
1437 #define	COPYOUT		2		/* do an mi_copyout if needed */
1438 #define	NO_COPYOUT	3		/* do an mi_copy_done */
1439 #define	IPI2MODE(ipi)	((ipi)->ipi_flags & IPI_GET_CMD ? COPYOUT : NO_COPYOUT)
1440 
1441 /*
1442  * The IP-MT design revolves around the serialization objects ipsq_t (IPSQ)
1443  * and ipxop_t (exclusive operation or "xop").  Becoming "writer" on an IPSQ
1444  * ensures that no other threads can become "writer" on any IPSQs sharing that
1445  * IPSQ's xop until the writer thread is done.
1446  *
1447  * Each phyint points to one IPSQ that remains fixed over the phyint's life.
1448  * Each IPSQ points to one xop that can change over the IPSQ's life.  If a
1449  * phyint is *not* in an IPMP group, then its IPSQ will refer to the IPSQ's
1450  * "own" xop (ipsq_ownxop).  If a phyint *is* part of an IPMP group, then its
1451  * IPSQ will refer to the "group" xop, which is shorthand for the xop of the
1452  * IPSQ of the IPMP meta-interface's phyint.  Thus, all phyints that are part
1453  * of the same IPMP group will have their IPSQ's point to the group xop, and
1454  * thus becoming "writer" on any phyint in the group will prevent any other
1455  * writer on any other phyint in the group.  All IPSQs sharing the same xop
1456  * are chained together through ipsq_next (in the degenerate common case,
1457  * ipsq_next simply refers to itself).  Note that the group xop is guaranteed
1458  * to exist at least as long as there are members in the group, since the IPMP
1459  * meta-interface can only be destroyed if the group is empty.
1460  *
1461  * Incoming exclusive operation requests are enqueued on the IPSQ they arrived
1462  * on rather than the xop.  This makes switching xop's (as would happen when a
1463  * phyint leaves an IPMP group) simple, because after the phyint leaves the
1464  * group, any operations enqueued on its IPSQ can be safely processed with
1465  * respect to its new xop, and any operations enqueued on the IPSQs of its
1466  * former group can be processed with respect to their existing group xop.
1467  * Even so, switching xops is a subtle dance; see ipsq_dq() for details.
1468  *
1469  * An IPSQ's "own" xop is embedded within the IPSQ itself since they have have
1470  * identical lifetimes, and because doing so simplifies pointer management.
1471  * While each phyint and IPSQ point to each other, it is not possible to free
1472  * the IPSQ when the phyint is freed, since we may still *inside* the IPSQ
1473  * when the phyint is being freed.  Thus, ipsq_phyint is set to NULL when the
1474  * phyint is freed, and the IPSQ free is later done in ipsq_exit().
1475  *
1476  * ipsq_t synchronization:	read			write
1477  *
1478  *	ipsq_xopq_mphead	ipx_lock		ipx_lock
1479  *	ipsq_xopq_mptail	ipx_lock		ipx_lock
1480  *	ipsq_xop_switch_mp	ipsq_lock		ipsq_lock
1481  *	ipsq_phyint		write once		write once
1482  *	ipsq_next		RW_READER ill_g_lock	RW_WRITER ill_g_lock
1483  *	ipsq_xop 		ipsq_lock or ipsq	ipsq_lock + ipsq
1484  *	ipsq_swxop		ipsq			ipsq
1485  * 	ipsq_ownxop		see ipxop_t		see ipxop_t
1486  *	ipsq_ipst		write once		write once
1487  *
1488  * ipxop_t synchronization:     read			write
1489  *
1490  *	ipx_writer  		ipx_lock		ipx_lock
1491  *	ipx_xop_queued		ipx_lock 		ipx_lock
1492  *	ipx_mphead		ipx_lock		ipx_lock
1493  *	ipx_mptail		ipx_lock		ipx_lock
1494  *	ipx_ipsq		write once		write once
1495  *	ips_ipsq_queued		ipx_lock		ipx_lock
1496  *	ipx_waitfor		ipsq or ipx_lock	ipsq + ipx_lock
1497  *	ipx_reentry_cnt		ipsq or ipx_lock	ipsq + ipx_lock
1498  *	ipx_current_done	ipsq			ipsq
1499  *	ipx_current_ioctl	ipsq			ipsq
1500  *	ipx_current_ipif	ipsq or ipx_lock	ipsq + ipx_lock
1501  *	ipx_pending_ipif	ipsq or ipx_lock	ipsq + ipx_lock
1502  *	ipx_pending_mp		ipsq or ipx_lock	ipsq + ipx_lock
1503  *	ipx_forced		ipsq			ipsq
1504  *	ipx_depth		ipsq			ipsq
1505  *	ipx_stack		ipsq			ipsq
1506  */
1507 typedef struct ipxop_s {
1508 	kmutex_t	ipx_lock;	/* see above */
1509 	kthread_t	*ipx_writer;  	/* current owner */
1510 	mblk_t		*ipx_mphead;	/* messages tied to this op */
1511 	mblk_t		*ipx_mptail;
1512 	struct ipsq_s	*ipx_ipsq;	/* associated ipsq */
1513 	boolean_t	ipx_ipsq_queued; /* ipsq using xop has queued op */
1514 	int		ipx_waitfor;	/* waiting; values encoded below */
1515 	int		ipx_reentry_cnt;
1516 	boolean_t	ipx_current_done;  /* is the current operation done? */
1517 	int		ipx_current_ioctl; /* current ioctl, or 0 if no ioctl */
1518 	ipif_t		*ipx_current_ipif; /* ipif for current op */
1519 	ipif_t		*ipx_pending_ipif; /* ipif for ipsq_pending_mp */
1520 	mblk_t 		*ipx_pending_mp;   /* current ioctl mp while waiting */
1521 	boolean_t	ipx_forced; 			/* debugging aid */
1522 #ifdef DEBUG
1523 	int		ipx_depth;			/* debugging aid */
1524 #define	IPX_STACK_DEPTH	15
1525 	pc_t		ipx_stack[IPX_STACK_DEPTH];	/* debugging aid */
1526 #endif
1527 } ipxop_t;
1528 
1529 typedef struct ipsq_s {
1530 	kmutex_t ipsq_lock;		/* see above */
1531 	mblk_t	*ipsq_switch_mp;	/* op to handle right after switch */
1532 	mblk_t	*ipsq_xopq_mphead;	/* list of excl ops (mostly ioctls) */
1533 	mblk_t	*ipsq_xopq_mptail;
1534 	struct phyint	*ipsq_phyint;	/* associated phyint */
1535 	struct ipsq_s	*ipsq_next;	/* next ipsq sharing ipsq_xop */
1536 	struct ipxop_s	*ipsq_xop;	/* current xop synchronization info */
1537 	struct ipxop_s	*ipsq_swxop;	/* switch xop to on ipsq_exit() */
1538 	struct ipxop_s	ipsq_ownxop;	/* our own xop (may not be in-use) */
1539 	ip_stack_t	*ipsq_ipst;	/* does not have a netstack_hold */
1540 } ipsq_t;
1541 
1542 /*
1543  * ipx_waitfor values:
1544  */
1545 enum {
1546 	IPIF_DOWN = 1,	/* ipif_down() waiting for refcnts to drop */
1547 	ILL_DOWN,	/* ill_down() waiting for refcnts to drop */
1548 	IPIF_FREE,	/* ipif_free() waiting for refcnts to drop */
1549 	ILL_FREE	/* ill unplumb waiting for refcnts to drop */
1550 };
1551 
1552 /* Operation types for ipsq_try_enter() */
1553 #define	CUR_OP 0	/* request writer within current operation */
1554 #define	NEW_OP 1	/* request writer for a new operation */
1555 #define	SWITCH_OP 2	/* request writer once IPSQ XOP switches */
1556 
1557 /*
1558  * Kstats tracked on each IPMP meta-interface.  Order here must match
1559  * ipmp_kstats[] in ip/ipmp.c.
1560  */
1561 enum {
1562 	IPMP_KSTAT_OBYTES,	IPMP_KSTAT_OBYTES64,	IPMP_KSTAT_RBYTES,
1563 	IPMP_KSTAT_RBYTES64,	IPMP_KSTAT_OPACKETS,	IPMP_KSTAT_OPACKETS64,
1564 	IPMP_KSTAT_OERRORS,	IPMP_KSTAT_IPACKETS,	IPMP_KSTAT_IPACKETS64,
1565 	IPMP_KSTAT_IERRORS,	IPMP_KSTAT_MULTIRCV,	IPMP_KSTAT_MULTIXMT,
1566 	IPMP_KSTAT_BRDCSTRCV,	IPMP_KSTAT_BRDCSTXMT,	IPMP_KSTAT_LINK_UP,
1567 	IPMP_KSTAT_MAX		/* keep last */
1568 };
1569 
1570 /*
1571  * phyint represents state that is common to both IPv4 and IPv6 interfaces.
1572  * There is a separate ill_t representing IPv4 and IPv6 which has a
1573  * backpointer to the phyint structure for accessing common state.
1574  */
1575 typedef struct phyint {
1576 	struct ill_s	*phyint_illv4;
1577 	struct ill_s	*phyint_illv6;
1578 	uint_t		phyint_ifindex;		/* SIOCSLIFINDEX */
1579 	uint64_t	phyint_flags;
1580 	avl_node_t	phyint_avl_by_index;	/* avl tree by index */
1581 	avl_node_t	phyint_avl_by_name;	/* avl tree by name */
1582 	kmutex_t	phyint_lock;
1583 	struct ipsq_s	*phyint_ipsq;		/* back pointer to ipsq */
1584 	struct ipmp_grp_s *phyint_grp;		/* associated IPMP group */
1585 	char		phyint_name[LIFNAMSIZ];	/* physical interface name */
1586 	uint64_t	phyint_kstats0[IPMP_KSTAT_MAX];	/* baseline kstats */
1587 } phyint_t;
1588 
1589 #define	CACHE_ALIGN_SIZE 64
1590 #define	CACHE_ALIGN(align_struct)	P2ROUNDUP(sizeof (struct align_struct),\
1591 							CACHE_ALIGN_SIZE)
1592 struct _phyint_list_s_ {
1593 	avl_tree_t	phyint_list_avl_by_index;	/* avl tree by index */
1594 	avl_tree_t	phyint_list_avl_by_name;	/* avl tree by name */
1595 };
1596 
1597 typedef union phyint_list_u {
1598 	struct	_phyint_list_s_ phyint_list_s;
1599 	char	phyint_list_filler[CACHE_ALIGN(_phyint_list_s_)];
1600 } phyint_list_t;
1601 
1602 #define	phyint_list_avl_by_index	phyint_list_s.phyint_list_avl_by_index
1603 #define	phyint_list_avl_by_name		phyint_list_s.phyint_list_avl_by_name
1604 
1605 /*
1606  * Fragmentation hash bucket
1607  */
1608 typedef struct ipfb_s {
1609 	struct ipf_s	*ipfb_ipf;	/* List of ... */
1610 	size_t		ipfb_count;	/* Count of bytes used by frag(s) */
1611 	kmutex_t	ipfb_lock;	/* Protect all ipf in list */
1612 	uint_t		ipfb_frag_pkts; /* num of distinct fragmented pkts */
1613 } ipfb_t;
1614 
1615 /*
1616  * IRE bucket structure. Usually there is an array of such structures,
1617  * each pointing to a linked list of ires. irb_refcnt counts the number
1618  * of walkers of a given hash bucket. Usually the reference count is
1619  * bumped up if the walker wants no IRES to be DELETED while walking the
1620  * list. Bumping up does not PREVENT ADDITION. This allows walking a given
1621  * hash bucket without stumbling up on a free pointer.
1622  *
1623  * irb_t structures in ip_ftable are dynamically allocated and freed.
1624  * In order to identify the irb_t structures that can be safely kmem_free'd
1625  * we need to ensure that
1626  *  - the irb_refcnt is quiescent, indicating no other walkers,
1627  *  - no other threads or ire's are holding references to the irb,
1628  *	i.e., irb_nire == 0,
1629  *  - there are no active ire's in the bucket, i.e., irb_ire_cnt == 0
1630  */
1631 typedef struct irb {
1632 	struct ire_s	*irb_ire;	/* First ire in this bucket */
1633 					/* Should be first in this struct */
1634 	krwlock_t	irb_lock;	/* Protect this bucket */
1635 	uint_t		irb_refcnt;	/* Protected by irb_lock */
1636 	uchar_t		irb_marks;	/* CONDEMNED ires in this bucket ? */
1637 #define	IRB_MARK_CONDEMNED	0x0001
1638 #define	IRB_MARK_FTABLE		0x0002
1639 	uint_t		irb_ire_cnt;	/* Num of active IRE in this bucket */
1640 	uint_t		irb_tmp_ire_cnt; /* Num of temporary IRE */
1641 	struct ire_s	*irb_rr_origin;	/* origin for round-robin */
1642 	int		irb_nire;	/* Num of ftable ire's that ref irb */
1643 	ip_stack_t	*irb_ipst;	/* Does not have a netstack_hold */
1644 } irb_t;
1645 
1646 #define	IRB2RT(irb)	(rt_t *)((caddr_t)(irb) - offsetof(rt_t, rt_irb))
1647 
1648 /* The following are return values of ip_xmit_v4() */
1649 typedef enum {
1650 	SEND_PASSED = 0,	 /* sent packet out on wire */
1651 	SEND_FAILED,	 /* sending of packet failed */
1652 	LOOKUP_IN_PROGRESS, /* ire cache found, ARP resolution in progress */
1653 	LLHDR_RESLV_FAILED  /* macaddr resl of onlink dst or nexthop failed */
1654 } ipxmit_state_t;
1655 
1656 #define	IP_V4_G_HEAD	0
1657 #define	IP_V6_G_HEAD	1
1658 
1659 #define	MAX_G_HEADS	2
1660 
1661 /*
1662  * unpadded ill_if structure
1663  */
1664 struct 	_ill_if_s_ {
1665 	union ill_if_u	*illif_next;
1666 	union ill_if_u	*illif_prev;
1667 	avl_tree_t	illif_avl_by_ppa;	/* AVL tree sorted on ppa */
1668 	vmem_t		*illif_ppa_arena;	/* ppa index space */
1669 	uint16_t	illif_mcast_v1;		/* hints for		  */
1670 	uint16_t	illif_mcast_v2;		/* [igmp|mld]_slowtimo	  */
1671 	int		illif_name_len;		/* name length */
1672 	char		illif_name[LIFNAMSIZ];	/* name of interface type */
1673 };
1674 
1675 /* cache aligned ill_if structure */
1676 typedef union 	ill_if_u {
1677 	struct  _ill_if_s_ ill_if_s;
1678 	char 	illif_filler[CACHE_ALIGN(_ill_if_s_)];
1679 } ill_if_t;
1680 
1681 #define	illif_next		ill_if_s.illif_next
1682 #define	illif_prev		ill_if_s.illif_prev
1683 #define	illif_avl_by_ppa	ill_if_s.illif_avl_by_ppa
1684 #define	illif_ppa_arena		ill_if_s.illif_ppa_arena
1685 #define	illif_mcast_v1		ill_if_s.illif_mcast_v1
1686 #define	illif_mcast_v2		ill_if_s.illif_mcast_v2
1687 #define	illif_name		ill_if_s.illif_name
1688 #define	illif_name_len		ill_if_s.illif_name_len
1689 
1690 typedef struct ill_walk_context_s {
1691 	int	ctx_current_list; /* current list being searched */
1692 	int	ctx_last_list;	 /* last list to search */
1693 } ill_walk_context_t;
1694 
1695 /*
1696  * ill_g_heads structure, one for IPV4 and one for IPV6
1697  */
1698 struct _ill_g_head_s_ {
1699 	ill_if_t	*ill_g_list_head;
1700 	ill_if_t	*ill_g_list_tail;
1701 };
1702 
1703 typedef union ill_g_head_u {
1704 	struct _ill_g_head_s_ ill_g_head_s;
1705 	char	ill_g_head_filler[CACHE_ALIGN(_ill_g_head_s_)];
1706 } ill_g_head_t;
1707 
1708 #define	ill_g_list_head	ill_g_head_s.ill_g_list_head
1709 #define	ill_g_list_tail	ill_g_head_s.ill_g_list_tail
1710 
1711 #define	IP_V4_ILL_G_LIST(ipst)	\
1712 	(ipst)->ips_ill_g_heads[IP_V4_G_HEAD].ill_g_list_head
1713 #define	IP_V6_ILL_G_LIST(ipst)	\
1714 	(ipst)->ips_ill_g_heads[IP_V6_G_HEAD].ill_g_list_head
1715 #define	IP_VX_ILL_G_LIST(i, ipst)	\
1716 	(ipst)->ips_ill_g_heads[i].ill_g_list_head
1717 
1718 #define	ILL_START_WALK_V4(ctx_ptr, ipst)	\
1719 	ill_first(IP_V4_G_HEAD, IP_V4_G_HEAD, ctx_ptr, ipst)
1720 #define	ILL_START_WALK_V6(ctx_ptr, ipst)	\
1721 	ill_first(IP_V6_G_HEAD, IP_V6_G_HEAD, ctx_ptr, ipst)
1722 #define	ILL_START_WALK_ALL(ctx_ptr, ipst)	\
1723 	ill_first(MAX_G_HEADS, MAX_G_HEADS, ctx_ptr, ipst)
1724 
1725 /*
1726  * Capabilities, possible flags for ill_capabilities.
1727  */
1728 
1729 #define	ILL_CAPAB_AH		0x01		/* IPsec AH acceleration */
1730 #define	ILL_CAPAB_ESP		0x02		/* IPsec ESP acceleration */
1731 #define	ILL_CAPAB_MDT		0x04		/* Multidata Transmit */
1732 #define	ILL_CAPAB_HCKSUM	0x08		/* Hardware checksumming */
1733 #define	ILL_CAPAB_ZEROCOPY	0x10		/* Zero-copy */
1734 #define	ILL_CAPAB_DLD		0x20		/* DLD capabilities */
1735 #define	ILL_CAPAB_DLD_POLL	0x40		/* Polling */
1736 #define	ILL_CAPAB_DLD_DIRECT	0x80		/* Direct function call */
1737 #define	ILL_CAPAB_DLD_LSO	0x100		/* Large Segment Offload */
1738 
1739 /*
1740  * Per-ill Multidata Transmit capabilities.
1741  */
1742 typedef struct ill_mdt_capab_s ill_mdt_capab_t;
1743 
1744 /*
1745  * Per-ill IPsec capabilities.
1746  */
1747 typedef struct ill_ipsec_capab_s ill_ipsec_capab_t;
1748 
1749 /*
1750  * Per-ill Hardware Checksumming capbilities.
1751  */
1752 typedef struct ill_hcksum_capab_s ill_hcksum_capab_t;
1753 
1754 /*
1755  * Per-ill Zero-copy capabilities.
1756  */
1757 typedef struct ill_zerocopy_capab_s ill_zerocopy_capab_t;
1758 
1759 /*
1760  * DLD capbilities.
1761  */
1762 typedef struct ill_dld_capab_s ill_dld_capab_t;
1763 
1764 /*
1765  * Per-ill polling resource map.
1766  */
1767 typedef struct ill_rx_ring ill_rx_ring_t;
1768 
1769 /*
1770  * Per-ill Large Segment Offload capabilities.
1771  */
1772 typedef struct ill_lso_capab_s ill_lso_capab_t;
1773 
1774 /* The following are ill_state_flags */
1775 #define	ILL_LL_SUBNET_PENDING	0x01	/* Waiting for DL_INFO_ACK from drv */
1776 #define	ILL_CONDEMNED		0x02	/* No more new ref's to the ILL */
1777 #define	ILL_CHANGING		0x04	/* ILL not globally visible */
1778 #define	ILL_DL_UNBIND_IN_PROGRESS	0x08	/* UNBIND_REQ is sent */
1779 
1780 /* Is this an ILL whose source address is used by other ILL's ? */
1781 #define	IS_USESRC_ILL(ill)			\
1782 	(((ill)->ill_usesrc_ifindex == 0) &&	\
1783 	((ill)->ill_usesrc_grp_next != NULL))
1784 
1785 /* Is this a client/consumer of the usesrc ILL ? */
1786 #define	IS_USESRC_CLI_ILL(ill)			\
1787 	(((ill)->ill_usesrc_ifindex != 0) &&	\
1788 	((ill)->ill_usesrc_grp_next != NULL))
1789 
1790 /* Is this an virtual network interface (vni) ILL ? */
1791 #define	IS_VNI(ill)							     \
1792 	(((ill) != NULL) &&						     \
1793 	(((ill)->ill_phyint->phyint_flags & (PHYI_LOOPBACK|PHYI_VIRTUAL)) == \
1794 	PHYI_VIRTUAL))
1795 
1796 /* Is this a loopback ILL? */
1797 #define	IS_LOOPBACK(ill) \
1798 	((ill)->ill_phyint->phyint_flags & PHYI_LOOPBACK)
1799 
1800 /* Is this an IPMP meta-interface ILL? */
1801 #define	IS_IPMP(ill)							\
1802 	((ill)->ill_phyint->phyint_flags & PHYI_IPMP)
1803 
1804 /* Is this ILL under an IPMP meta-interface? (aka "in a group?") */
1805 #define	IS_UNDER_IPMP(ill)						\
1806 	((ill)->ill_grp != NULL && !IS_IPMP(ill))
1807 
1808 /* Is ill1 in the same illgrp as ill2? */
1809 #define	IS_IN_SAME_ILLGRP(ill1, ill2)					\
1810 	((ill1)->ill_grp != NULL && ((ill1)->ill_grp == (ill2)->ill_grp))
1811 
1812 /* Is ill1 on the same LAN as ill2? */
1813 #define	IS_ON_SAME_LAN(ill1, ill2)					\
1814 	((ill1) == (ill2) || IS_IN_SAME_ILLGRP(ill1, ill2))
1815 
1816 #define	ILL_OTHER(ill)							\
1817 	((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :		\
1818 	    (ill)->ill_phyint->phyint_illv6)
1819 
1820 /*
1821  * IPMP group ILL state structure -- up to two per IPMP group (V4 and V6).
1822  * Created when the V4 and/or V6 IPMP meta-interface is I_PLINK'd.  It is
1823  * guaranteed to persist while there are interfaces of that type in the group.
1824  * In general, most fields are accessed outside of the IPSQ (e.g., in the
1825  * datapath), and thus use locks in addition to the IPSQ for protection.
1826  *
1827  * synchronization:		read			write
1828  *
1829  *	ig_if			ipsq or ill_g_lock	ipsq and ill_g_lock
1830  *	ig_actif		ipsq or ipmp_lock	ipsq and ipmp_lock
1831  *	ig_nactif		ipsq or ipmp_lock	ipsq and ipmp_lock
1832  *	ig_next_ill		ipsq or ipmp_lock	ipsq and ipmp_lock
1833  *	ig_ipmp_ill		write once		write once
1834  *	ig_cast_ill		ipsq or ipmp_lock	ipsq and ipmp_lock
1835  *	ig_arpent		ipsq			ipsq
1836  *	ig_mtu			ipsq			ipsq
1837  */
1838 typedef struct ipmp_illgrp_s {
1839 	list_t		ig_if; 		/* list of all interfaces */
1840 	list_t		ig_actif;	/* list of active interfaces */
1841 	uint_t		ig_nactif;	/* number of active interfaces */
1842 	struct ill_s	*ig_next_ill;	/* next active interface to use */
1843 	struct ill_s	*ig_ipmp_ill;	/* backpointer to IPMP meta-interface */
1844 	struct ill_s	*ig_cast_ill;	/* nominated ill for multi/broadcast */
1845 	list_t		ig_arpent;	/* list of ARP entries */
1846 	uint_t		ig_mtu;		/* ig_ipmp_ill->ill_max_mtu */
1847 } ipmp_illgrp_t;
1848 
1849 /*
1850  * IPMP group state structure -- one per IPMP group.  Created when the
1851  * IPMP meta-interface is plumbed; it is guaranteed to persist while there
1852  * are interfaces in it.
1853  *
1854  * ipmp_grp_t synchronization:		read			write
1855  *
1856  *	gr_name				ipmp_lock		ipmp_lock
1857  *	gr_ifname			write once		write once
1858  *	gr_mactype			ipmp_lock		ipmp_lock
1859  *	gr_phyint			write once		write once
1860  *	gr_nif				ipmp_lock		ipmp_lock
1861  *	gr_nactif			ipsq			ipsq
1862  *	gr_v4				ipmp_lock		ipmp_lock
1863  *	gr_v6				ipmp_lock		ipmp_lock
1864  *	gr_nv4				ipmp_lock		ipmp_lock
1865  *	gr_nv6				ipmp_lock		ipmp_lock
1866  *	gr_pendv4			ipmp_lock		ipmp_lock
1867  *	gr_pendv6			ipmp_lock		ipmp_lock
1868  *	gr_linkdownmp			ipsq			ipsq
1869  *	gr_ksp				ipmp_lock		ipmp_lock
1870  *	gr_kstats0			atomic			atomic
1871  */
1872 typedef struct ipmp_grp_s {
1873 	char		gr_name[LIFGRNAMSIZ];	/* group name */
1874 	char		gr_ifname[LIFNAMSIZ];	/* interface name */
1875 	t_uscalar_t	gr_mactype;	/* DLPI mactype of group */
1876 	phyint_t	*gr_phyint;	/* IPMP group phyint */
1877 	uint_t		gr_nif;		/* number of interfaces in group */
1878 	uint_t		gr_nactif; 	/* number of active interfaces */
1879 	ipmp_illgrp_t	*gr_v4;		/* V4 group information */
1880 	ipmp_illgrp_t	*gr_v6;		/* V6 group information */
1881 	uint_t		gr_nv4;		/* number of ills in V4 group */
1882 	uint_t		gr_nv6;		/* number of ills in V6 group */
1883 	uint_t		gr_pendv4; 	/* number of pending ills in V4 group */
1884 	uint_t		gr_pendv6; 	/* number of pending ills in V6 group */
1885 	mblk_t		*gr_linkdownmp;	/* message used to bring link down */
1886 	kstat_t		*gr_ksp;	/* group kstat pointer */
1887 	uint64_t	gr_kstats0[IPMP_KSTAT_MAX]; /* baseline group kstats */
1888 } ipmp_grp_t;
1889 
1890 /*
1891  * IPMP ARP entry -- one per SIOCS*ARP entry tied to the group.  Used to keep
1892  * ARP up-to-date as the active set of interfaces in the group changes.
1893  */
1894 typedef struct ipmp_arpent_s {
1895 	mblk_t		*ia_area_mp;	/* AR_ENTRY_ADD pointer */
1896 	ipaddr_t	ia_ipaddr; 	/* IP address for this entry */
1897 	boolean_t	ia_proxyarp; 	/* proxy ARP entry? */
1898 	boolean_t	ia_notified; 	/* ARP notified about this entry? */
1899 	list_node_t	ia_node; 	/* next ARP entry in list */
1900 } ipmp_arpent_t;
1901 
1902 /*
1903  * IP Lower level Structure.
1904  * Instance data structure in ip_open when there is a device below us.
1905  */
1906 typedef struct ill_s {
1907 	ill_if_t *ill_ifptr;		/* pointer to interface type */
1908 	queue_t	*ill_rq;		/* Read queue. */
1909 	queue_t	*ill_wq;		/* Write queue. */
1910 
1911 	int	ill_error;		/* Error value sent up by device. */
1912 
1913 	ipif_t	*ill_ipif;		/* Interface chain for this ILL. */
1914 
1915 	uint_t	ill_ipif_up_count;	/* Number of IPIFs currently up. */
1916 	uint_t	ill_max_frag;		/* Max IDU from DLPI. */
1917 	char	*ill_name;		/* Our name. */
1918 	uint_t	ill_ipif_dup_count;	/* Number of duplicate addresses. */
1919 	uint_t	ill_name_length;	/* Name length, incl. terminator. */
1920 	char	*ill_ndd_name;		/* Name + ":ip?_forwarding" for NDD. */
1921 	uint_t	ill_net_type;		/* IRE_IF_RESOLVER/IRE_IF_NORESOLVER. */
1922 	/*
1923 	 * Physical Point of Attachment num.  If DLPI style 1 provider
1924 	 * then this is derived from the devname.
1925 	 */
1926 	uint_t	ill_ppa;
1927 	t_uscalar_t	ill_sap;
1928 	t_scalar_t	ill_sap_length;	/* Including sign (for position) */
1929 	uint_t	ill_phys_addr_length;	/* Excluding the sap. */
1930 	uint_t	ill_bcast_addr_length;	/* Only set when the DL provider */
1931 					/* supports broadcast. */
1932 	t_uscalar_t	ill_mactype;
1933 	uint8_t	*ill_frag_ptr;		/* Reassembly state. */
1934 	timeout_id_t ill_frag_timer_id; /* timeout id for the frag timer */
1935 	ipfb_t	*ill_frag_hash_tbl;	/* Fragment hash list head. */
1936 	ipif_t	*ill_pending_ipif;	/* IPIF waiting for DL operation. */
1937 
1938 	ilm_t	*ill_ilm;		/* Multicast membership for ill */
1939 	uint_t	ill_global_timer;	/* for IGMPv3/MLDv2 general queries */
1940 	int	ill_mcast_type;		/* type of router which is querier */
1941 					/* on this interface */
1942 	uint16_t ill_mcast_v1_time;	/* # slow timeouts since last v1 qry */
1943 	uint16_t ill_mcast_v2_time;	/* # slow timeouts since last v2 qry */
1944 	uint8_t	ill_mcast_v1_tset;	/* 1 => timer is set; 0 => not set */
1945 	uint8_t	ill_mcast_v2_tset;	/* 1 => timer is set; 0 => not set */
1946 
1947 	uint8_t	ill_mcast_rv;		/* IGMPv3/MLDv2 robustness variable */
1948 	int	ill_mcast_qi;		/* IGMPv3/MLDv2 query interval var */
1949 
1950 	mblk_t	*ill_pending_mp;	/* IOCTL/DLPI awaiting completion. */
1951 	/*
1952 	 * All non-NULL cells between 'ill_first_mp_to_free' and
1953 	 * 'ill_last_mp_to_free' are freed in ill_delete.
1954 	 */
1955 #define	ill_first_mp_to_free	ill_bcast_mp
1956 	mblk_t	*ill_bcast_mp;		/* DLPI header for broadcasts. */
1957 	mblk_t	*ill_resolver_mp;	/* Resolver template. */
1958 	mblk_t	*ill_unbind_mp;		/* unbind mp from ill_dl_up() */
1959 	mblk_t	*ill_promiscoff_mp;	/* for ill_leave_allmulti() */
1960 	mblk_t	*ill_dlpi_deferred;	/* b_next chain of control messages */
1961 	mblk_t	*ill_ardeact_mp;	/* deact mp from ipmp_ill_activate() */
1962 	mblk_t	*ill_replumb_mp;	/* replumb mp from ill_replumb() */
1963 	mblk_t	*ill_phys_addr_mp;	/* mblk which holds ill_phys_addr */
1964 #define	ill_last_mp_to_free	ill_phys_addr_mp
1965 
1966 	cred_t	*ill_credp;		/* opener's credentials */
1967 	uint8_t	*ill_phys_addr;		/* ill_phys_addr_mp->b_rptr + off */
1968 
1969 	uint_t	ill_state_flags;	/* see ILL_* flags above */
1970 
1971 	/* Following bit fields protected by ipsq_t */
1972 	uint_t
1973 		ill_needs_attach : 1,
1974 		ill_reserved : 1,
1975 		ill_isv6 : 1,
1976 		ill_dlpi_style_set : 1,
1977 
1978 		ill_ifname_pending : 1,
1979 		ill_join_allmulti : 1,
1980 		ill_logical_down : 1,
1981 		ill_is_6to4tun : 1,	/* Interface is a 6to4 tunnel */
1982 
1983 		ill_dl_up : 1,
1984 		ill_up_ipifs : 1,
1985 		ill_note_link : 1,	/* supports link-up notification */
1986 		ill_capab_reneg : 1, /* capability renegotiation to be done */
1987 		ill_dld_capab_inprog : 1, /* direct dld capab call in prog */
1988 		ill_need_recover_multicast : 1,
1989 		ill_pad_to_bit_31 : 18;
1990 
1991 	/* Following bit fields protected by ill_lock */
1992 	uint_t
1993 		ill_fragtimer_executing : 1,
1994 		ill_fragtimer_needrestart : 1,
1995 		ill_ilm_cleanup_reqd : 1,
1996 		ill_arp_closing : 1,
1997 
1998 		ill_arp_bringup_pending : 1,
1999 		ill_arp_extend : 1,	/* ARP has DAD extensions */
2000 		ill_pad_bit_31 : 26;
2001 
2002 	/*
2003 	 * Used in SIOCSIFMUXID and SIOCGIFMUXID for 'ifconfig unplumb'.
2004 	 */
2005 	int	ill_arp_muxid;		/* muxid returned from plink for arp */
2006 	int	ill_ip_muxid;		/* muxid returned from plink for ip */
2007 
2008 	/* Used for IP frag reassembly throttling on a per ILL basis.  */
2009 	uint_t	ill_ipf_gen;		/* Generation of next fragment queue */
2010 	uint_t	ill_frag_count;		/* Count of all reassembly mblk bytes */
2011 	uint_t	ill_frag_free_num_pkts;	 /* num of fragmented packets to free */
2012 	clock_t	ill_last_frag_clean_time; /* time when frag's were pruned */
2013 	int	ill_type;		/* From <net/if_types.h> */
2014 	uint_t	ill_dlpi_multicast_state;	/* See below IDS_* */
2015 	uint_t	ill_dlpi_fastpath_state;	/* See below IDS_* */
2016 
2017 	/*
2018 	 * Capabilities related fields.
2019 	 */
2020 	uint_t  ill_dlpi_capab_state;	/* State of capability query, IDCS_* */
2021 	uint_t	ill_capab_pending_cnt;
2022 	uint64_t ill_capabilities;	/* Enabled capabilities, ILL_CAPAB_* */
2023 	ill_mdt_capab_t	*ill_mdt_capab;	/* Multidata Transmit capabilities */
2024 	ill_ipsec_capab_t *ill_ipsec_capab_ah;	/* IPsec AH capabilities */
2025 	ill_ipsec_capab_t *ill_ipsec_capab_esp;	/* IPsec ESP capabilities */
2026 	ill_hcksum_capab_t *ill_hcksum_capab; /* H/W cksumming capabilities */
2027 	ill_zerocopy_capab_t *ill_zerocopy_capab; /* Zero-copy capabilities */
2028 	ill_dld_capab_t *ill_dld_capab; /* DLD capabilities */
2029 	ill_lso_capab_t	*ill_lso_capab;	/* Large Segment Offload capabilities */
2030 	mblk_t	*ill_capab_reset_mp;	/* Preallocated mblk for capab reset */
2031 
2032 	/*
2033 	 * New fields for IPv6
2034 	 */
2035 	uint8_t	ill_max_hops;	/* Maximum hops for any logical interface */
2036 	uint_t	ill_max_mtu;	/* Maximum MTU for any logical interface */
2037 	uint_t	ill_user_mtu;	/* User-specified MTU via SIOCSLIFLNKINFO */
2038 	uint32_t ill_reachable_time;	/* Value for ND algorithm in msec */
2039 	uint32_t ill_reachable_retrans_time; /* Value for ND algorithm msec */
2040 	uint_t	ill_max_buf;		/* Max # of req to buffer for ND */
2041 	in6_addr_t	ill_token;
2042 	uint_t		ill_token_length;
2043 	uint32_t	ill_xmit_count;		/* ndp max multicast xmits */
2044 	mib2_ipIfStatsEntry_t	*ill_ip_mib;	/* ver indep. interface mib */
2045 	mib2_ipv6IfIcmpEntry_t	*ill_icmp6_mib;	/* Per interface mib */
2046 	/*
2047 	 * Following two mblks are allocated common to all
2048 	 * the ipifs when the first interface is coming up.
2049 	 * It is sent up to arp when the last ipif is coming
2050 	 * down.
2051 	 */
2052 	mblk_t			*ill_arp_down_mp;
2053 	mblk_t			*ill_arp_del_mapping_mp;
2054 	/*
2055 	 * Used for implementing IFF_NOARP. As IFF_NOARP is used
2056 	 * to turn off for all the logicals, it is here instead
2057 	 * of the ipif.
2058 	 */
2059 	mblk_t			*ill_arp_on_mp;
2060 
2061 	phyint_t		*ill_phyint;
2062 	uint64_t		ill_flags;
2063 
2064 	kmutex_t	ill_lock;	/* Please see table below */
2065 	/*
2066 	 * The ill_nd_lla* fields handle the link layer address option
2067 	 * from neighbor discovery. This is used for external IPv6
2068 	 * address resolution.
2069 	 */
2070 	mblk_t		*ill_nd_lla_mp;	/* mblk which holds ill_nd_lla */
2071 	uint8_t		*ill_nd_lla;	/* Link Layer Address */
2072 	uint_t		ill_nd_lla_len;	/* Link Layer Address length */
2073 	/*
2074 	 * We now have 3 phys_addr_req's sent down. This field keeps track
2075 	 * of which one is pending.
2076 	 */
2077 	t_uscalar_t	ill_phys_addr_pend; /* which dl_phys_addr_req pending */
2078 	/*
2079 	 * Used to save errors that occur during plumbing
2080 	 */
2081 	uint_t		ill_ifname_pending_err;
2082 	avl_node_t	ill_avl_byppa; /* avl node based on ppa */
2083 	void		*ill_fastpath_list; /* both ire and nce hang off this */
2084 	uint_t		ill_refcnt;	/* active refcnt by threads */
2085 	uint_t		ill_ire_cnt;	/* ires associated with this ill */
2086 	kcondvar_t	ill_cv;
2087 	uint_t		ill_ilm_walker_cnt;	/* snmp ilm walkers */
2088 	uint_t		ill_nce_cnt;	/* nces associated with this ill */
2089 	uint_t		ill_waiters;	/* threads waiting in ipsq_enter */
2090 	/*
2091 	 * Contains the upper read queue pointer of the module immediately
2092 	 * beneath IP.  This field allows IP to validate sub-capability
2093 	 * acknowledgments coming up from downstream.
2094 	 */
2095 	queue_t		*ill_lmod_rq;	/* read queue pointer of module below */
2096 	uint_t		ill_lmod_cnt;	/* number of modules beneath IP */
2097 	ip_m_t		*ill_media;	/* media specific params/functions */
2098 	t_uscalar_t	ill_dlpi_pending; /* Last DLPI primitive issued */
2099 	uint_t		ill_usesrc_ifindex; /* use src addr from this ILL */
2100 	struct ill_s	*ill_usesrc_grp_next; /* Next ILL in the usesrc group */
2101 	boolean_t	ill_trace_disable;	/* True when alloc fails */
2102 	zoneid_t	ill_zoneid;
2103 	ip_stack_t	*ill_ipst;	/* Corresponds to a netstack_hold */
2104 	uint32_t	ill_dhcpinit;	/* IP_DHCPINIT_IFs for ill */
2105 	void		*ill_flownotify_mh; /* Tx flow ctl, mac cb handle */
2106 	uint_t		ill_ilm_cnt;    /* ilms referencing this ill */
2107 	uint_t		ill_ipallmulti_cnt; /* ip_join_allmulti() calls */
2108 	/*
2109 	 * IPMP fields.
2110 	 */
2111 	ipmp_illgrp_t	*ill_grp;	/* IPMP group information */
2112 	list_node_t	ill_actnode; 	/* next active ill in group */
2113 	list_node_t	ill_grpnode;	/* next ill in group */
2114 	ipif_t		*ill_src_ipif;	/* source address selection rotor */
2115 	ipif_t		*ill_move_ipif;	/* ipif awaiting move to new ill */
2116 	boolean_t	ill_nom_cast;	/* nominated for mcast/bcast */
2117 	uint_t		ill_bound_cnt;	/* # of data addresses bound to ill */
2118 	ipif_t		*ill_bound_ipif; /* ipif chain bound to ill */
2119 	timeout_id_t	ill_refresh_tid; /* ill refresh retry timeout id */
2120 } ill_t;
2121 
2122 /*
2123  * ILL_FREE_OK() means that there are no incoming pointer references
2124  * to the ill.
2125  */
2126 #define	ILL_FREE_OK(ill)					\
2127 	((ill)->ill_ire_cnt == 0 && (ill)->ill_ilm_cnt == 0 &&	\
2128 	(ill)->ill_nce_cnt == 0)
2129 
2130 /*
2131  * An ipif/ill can be marked down only when the ire and nce references
2132  * to that ipif/ill goes to zero. ILL_DOWN_OK() is a necessary condition
2133  * quiescence checks. See comments above IPIF_DOWN_OK for details
2134  * on why ires and nces are selectively considered for this macro.
2135  */
2136 #define	ILL_DOWN_OK(ill)	(ill->ill_ire_cnt == 0 && ill->ill_nce_cnt == 0)
2137 
2138 /*
2139  * The following table lists the protection levels of the various members
2140  * of the ill_t. Same notation as that used for ipif_t above is used.
2141  *
2142  *				Write			Read
2143  *
2144  * ill_ifptr			ill_g_lock + s		Write once
2145  * ill_rq			ipsq			Write once
2146  * ill_wq			ipsq			Write once
2147  *
2148  * ill_error			ipsq			None
2149  * ill_ipif			ill_g_lock + ipsq	ill_g_lock OR ipsq
2150  * ill_ipif_up_count		ill_lock + ipsq		ill_lock OR ipsq
2151  * ill_max_frag			ipsq			Write once
2152  *
2153  * ill_name			ill_g_lock + ipsq	Write once
2154  * ill_name_length		ill_g_lock + ipsq	Write once
2155  * ill_ndd_name			ipsq			Write once
2156  * ill_net_type			ipsq			Write once
2157  * ill_ppa			ill_g_lock + ipsq	Write once
2158  * ill_sap			ipsq + down ill		Write once
2159  * ill_sap_length		ipsq + down ill		Write once
2160  * ill_phys_addr_length		ipsq + down ill		Write once
2161  *
2162  * ill_bcast_addr_length	ipsq			ipsq
2163  * ill_mactype			ipsq			ipsq
2164  * ill_frag_ptr			ipsq			ipsq
2165  *
2166  * ill_frag_timer_id		ill_lock		ill_lock
2167  * ill_frag_hash_tbl		ipsq			up ill
2168  * ill_ilm			ipsq + ill_lock		ill_lock
2169  * ill_mcast_type		ill_lock		ill_lock
2170  * ill_mcast_v1_time		ill_lock		ill_lock
2171  * ill_mcast_v2_time		ill_lock		ill_lock
2172  * ill_mcast_v1_tset		ill_lock		ill_lock
2173  * ill_mcast_v2_tset		ill_lock		ill_lock
2174  * ill_mcast_rv			ill_lock		ill_lock
2175  * ill_mcast_qi			ill_lock		ill_lock
2176  * ill_pending_mp		ill_lock		ill_lock
2177  *
2178  * ill_bcast_mp			ipsq			ipsq
2179  * ill_resolver_mp		ipsq			only when ill is up
2180  * ill_down_mp			ipsq			ipsq
2181  * ill_dlpi_deferred		ill_lock		ill_lock
2182  * ill_dlpi_pending		ill_lock		ill_lock
2183  * ill_phys_addr_mp		ipsq + down ill		only when ill is up
2184  * ill_phys_addr		ipsq + down ill		only when ill is up
2185  *
2186  * ill_state_flags		ill_lock		ill_lock
2187  * exclusive bit flags		ipsq_t			ipsq_t
2188  * shared bit flags		ill_lock		ill_lock
2189  *
2190  * ill_arp_muxid		ipsq			Not atomic
2191  * ill_ip_muxid			ipsq			Not atomic
2192  *
2193  * ill_ipf_gen			Not atomic
2194  * ill_frag_count		atomics			atomics
2195  * ill_type			ipsq + down ill		only when ill is up
2196  * ill_dlpi_multicast_state	ill_lock		ill_lock
2197  * ill_dlpi_fastpath_state	ill_lock		ill_lock
2198  * ill_dlpi_capab_state		ipsq			ipsq
2199  * ill_max_hops			ipsq			Not atomic
2200  *
2201  * ill_max_mtu
2202  *
2203  * ill_user_mtu			ipsq + ill_lock		ill_lock
2204  * ill_reachable_time		ipsq + ill_lock		ill_lock
2205  * ill_reachable_retrans_time	ipsq + ill_lock		ill_lock
2206  * ill_max_buf			ipsq + ill_lock		ill_lock
2207  *
2208  * Next 2 fields need ill_lock because of the get ioctls. They should not
2209  * report partially updated results without executing in the ipsq.
2210  * ill_token			ipsq + ill_lock		ill_lock
2211  * ill_token_length		ipsq + ill_lock		ill_lock
2212  * ill_xmit_count		ipsq + down ill		write once
2213  * ill_ip6_mib			ipsq + down ill		only when ill is up
2214  * ill_icmp6_mib		ipsq + down ill		only when ill is up
2215  * ill_arp_down_mp		ipsq			ipsq
2216  * ill_arp_del_mapping_mp	ipsq			ipsq
2217  * ill_arp_on_mp		ipsq			ipsq
2218  *
2219  * ill_phyint			ipsq, ill_g_lock, ill_lock	Any of them
2220  * ill_flags			ill_lock		ill_lock
2221  * ill_nd_lla_mp		ipsq + down ill		only when ill is up
2222  * ill_nd_lla			ipsq + down ill		only when ill is up
2223  * ill_nd_lla_len		ipsq + down ill		only when ill is up
2224  * ill_phys_addr_pend		ipsq + down ill		only when ill is up
2225  * ill_ifname_pending_err	ipsq			ipsq
2226  * ill_avl_byppa		ipsq, ill_g_lock	write once
2227  *
2228  * ill_fastpath_list		ill_lock		ill_lock
2229  * ill_refcnt			ill_lock		ill_lock
2230  * ill_ire_cnt			ill_lock		ill_lock
2231  * ill_cv			ill_lock		ill_lock
2232  * ill_ilm_walker_cnt		ill_lock		ill_lock
2233  * ill_nce_cnt			ill_lock		ill_lock
2234  * ill_ilm_cnt			ill_lock		ill_lock
2235  * ill_src_ipif			ill_g_lock		ill_g_lock
2236  * ill_trace			ill_lock		ill_lock
2237  * ill_usesrc_grp_next		ill_g_usesrc_lock	ill_g_usesrc_lock
2238  * ill_dhcpinit			atomics			atomics
2239  * ill_flownotify_mh		write once		write once
2240  * ill_capab_pending_cnt	ipsq			ipsq
2241  *
2242  * ill_bound_cnt		ipsq			ipsq
2243  * ill_bound_ipif		ipsq			ipsq
2244  * ill_actnode			ipsq + ipmp_lock	ipsq OR ipmp_lock
2245  * ill_grpnode			ipsq + ill_g_lock	ipsq OR ill_g_lock
2246  * ill_src_ipif			ill_g_lock		ill_g_lock
2247  * ill_move_ipif		ipsq			ipsq
2248  * ill_nom_cast			ipsq			ipsq OR advisory
2249  * ill_refresh_tid		ill_lock		ill_lock
2250  * ill_grp (for IPMP ill)	write once		write once
2251  * ill_grp (for underlying ill)	ipsq + ill_g_lock	ipsq OR ill_g_lock
2252  *
2253  * NOTE: It's OK to make heuristic decisions on an underlying interface
2254  *	 by using IS_UNDER_IPMP() or comparing ill_grp's raw pointer value.
2255  */
2256 
2257 /*
2258  * For ioctl restart mechanism see ip_reprocess_ioctl()
2259  */
2260 struct ip_ioctl_cmd_s;
2261 
2262 typedef	int (*ifunc_t)(ipif_t *, struct sockaddr_in *, queue_t *, mblk_t *,
2263     struct ip_ioctl_cmd_s *, void *);
2264 
2265 typedef struct ip_ioctl_cmd_s {
2266 	int	ipi_cmd;
2267 	size_t	ipi_copyin_size;
2268 	uint_t	ipi_flags;
2269 	uint_t	ipi_cmd_type;
2270 	ifunc_t	ipi_func;
2271 	ifunc_t	ipi_func_restart;
2272 } ip_ioctl_cmd_t;
2273 
2274 /*
2275  * ipi_cmd_type:
2276  *
2277  * IF_CMD		1	old style ifreq cmd
2278  * LIF_CMD		2	new style lifreq cmd
2279  * TUN_CMD		3	tunnel related
2280  * ARP_CMD		4	arpreq cmd
2281  * XARP_CMD		5	xarpreq cmd
2282  * MSFILT_CMD		6	multicast source filter cmd
2283  * MISC_CMD		7	misc cmd (not a more specific one above)
2284  */
2285 
2286 enum { IF_CMD = 1, LIF_CMD, TUN_CMD, ARP_CMD, XARP_CMD, MSFILT_CMD, MISC_CMD };
2287 
2288 #define	IPI_DONTCARE	0	/* For ioctl encoded values that don't matter */
2289 
2290 /* Flag values in ipi_flags */
2291 #define	IPI_PRIV	0x1	/* Root only command */
2292 #define	IPI_MODOK	0x2	/* Permitted on mod instance of IP */
2293 #define	IPI_WR		0x4	/* Need to grab writer access */
2294 #define	IPI_GET_CMD	0x8	/* branch to mi_copyout on success */
2295 /*	unused		0x10	*/
2296 #define	IPI_NULL_BCONT	0x20	/* ioctl has not data and hence no b_cont */
2297 #define	IPI_PASS_DOWN	0x40	/* pass this ioctl down when a module only */
2298 
2299 extern ip_ioctl_cmd_t	ip_ndx_ioctl_table[];
2300 extern ip_ioctl_cmd_t	ip_misc_ioctl_table[];
2301 extern int ip_ndx_ioctl_count;
2302 extern int ip_misc_ioctl_count;
2303 
2304 /* Passed down by ARP to IP during I_PLINK/I_PUNLINK */
2305 typedef struct ipmx_s {
2306 	char	ipmx_name[LIFNAMSIZ];		/* if name */
2307 	uint_t
2308 		ipmx_arpdev_stream : 1,		/* This is the arp stream */
2309 		ipmx_notused : 31;
2310 } ipmx_t;
2311 
2312 /*
2313  * State for detecting if a driver supports certain features.
2314  * Support for DL_ENABMULTI_REQ uses ill_dlpi_multicast_state.
2315  * Support for DLPI M_DATA fastpath uses ill_dlpi_fastpath_state.
2316  */
2317 #define	IDS_UNKNOWN	0	/* No DLPI request sent */
2318 #define	IDS_INPROGRESS	1	/* DLPI request sent */
2319 #define	IDS_OK		2	/* DLPI request completed successfully */
2320 #define	IDS_FAILED	3	/* DLPI request failed */
2321 
2322 /* Support for DL_CAPABILITY_REQ uses ill_dlpi_capab_state. */
2323 enum {
2324 	IDCS_UNKNOWN,
2325 	IDCS_PROBE_SENT,
2326 	IDCS_OK,
2327 	IDCS_RESET_SENT,
2328 	IDCS_RENEG,
2329 	IDCS_FAILED
2330 };
2331 
2332 /* Named Dispatch Parameter Management Structure */
2333 typedef struct ipparam_s {
2334 	uint_t	ip_param_min;
2335 	uint_t	ip_param_max;
2336 	uint_t	ip_param_value;
2337 	char	*ip_param_name;
2338 } ipparam_t;
2339 
2340 /* Extended NDP Management Structure */
2341 typedef struct ipndp_s {
2342 	ndgetf_t	ip_ndp_getf;
2343 	ndsetf_t	ip_ndp_setf;
2344 	caddr_t		ip_ndp_data;
2345 	char		*ip_ndp_name;
2346 } ipndp_t;
2347 
2348 /*
2349  * The kernel stores security attributes of all gateways in a database made
2350  * up of one or more tsol_gcdb_t elements.  Each tsol_gcdb_t contains the
2351  * security-related credentials of the gateway.  More than one gateways may
2352  * share entries in the database.
2353  *
2354  * The tsol_gc_t structure represents the gateway to credential association,
2355  * and refers to an entry in the database.  One or more tsol_gc_t entities are
2356  * grouped together to form one or more tsol_gcgrp_t, each representing the
2357  * list of security attributes specific to the gateway.  A gateway may be
2358  * associated with at most one credentials group.
2359  */
2360 struct tsol_gcgrp_s;
2361 
2362 extern uchar_t	ip6opt_ls;	/* TX IPv6 enabler */
2363 
2364 /*
2365  * Gateway security credential record.
2366  */
2367 typedef struct tsol_gcdb_s {
2368 	uint_t		gcdb_refcnt;	/* reference count */
2369 	struct rtsa_s	gcdb_attr;	/* security attributes */
2370 #define	gcdb_mask	gcdb_attr.rtsa_mask
2371 #define	gcdb_doi	gcdb_attr.rtsa_doi
2372 #define	gcdb_slrange	gcdb_attr.rtsa_slrange
2373 } tsol_gcdb_t;
2374 
2375 /*
2376  * Gateway to credential association.
2377  */
2378 typedef struct tsol_gc_s {
2379 	uint_t		gc_refcnt;	/* reference count */
2380 	struct tsol_gcgrp_s *gc_grp;	/* pointer to group */
2381 	struct tsol_gc_s *gc_prev;	/* previous in list */
2382 	struct tsol_gc_s *gc_next;	/* next in list */
2383 	tsol_gcdb_t	*gc_db;		/* pointer to actual credentials */
2384 } tsol_gc_t;
2385 
2386 /*
2387  * Gateway credentials group address.
2388  */
2389 typedef struct tsol_gcgrp_addr_s {
2390 	int		ga_af;		/* address family */
2391 	in6_addr_t	ga_addr;	/* IPv4 mapped or IPv6 address */
2392 } tsol_gcgrp_addr_t;
2393 
2394 /*
2395  * Gateway credentials group.
2396  */
2397 typedef struct tsol_gcgrp_s {
2398 	uint_t		gcgrp_refcnt;	/* reference count */
2399 	krwlock_t	gcgrp_rwlock;	/* lock to protect following */
2400 	uint_t		gcgrp_count;	/* number of credentials */
2401 	tsol_gc_t	*gcgrp_head;	/* first credential in list */
2402 	tsol_gc_t	*gcgrp_tail;	/* last credential in list */
2403 	tsol_gcgrp_addr_t gcgrp_addr;	/* next-hop gateway address */
2404 } tsol_gcgrp_t;
2405 
2406 extern kmutex_t gcgrp_lock;
2407 
2408 #define	GC_REFRELE(p) {				\
2409 	ASSERT((p)->gc_grp != NULL);		\
2410 	rw_enter(&(p)->gc_grp->gcgrp_rwlock, RW_WRITER); \
2411 	ASSERT((p)->gc_refcnt > 0);		\
2412 	if (--((p)->gc_refcnt) == 0)		\
2413 		gc_inactive(p);			\
2414 	else					\
2415 		rw_exit(&(p)->gc_grp->gcgrp_rwlock); \
2416 }
2417 
2418 #define	GCGRP_REFHOLD(p) {			\
2419 	mutex_enter(&gcgrp_lock);		\
2420 	++((p)->gcgrp_refcnt);			\
2421 	ASSERT((p)->gcgrp_refcnt != 0);		\
2422 	mutex_exit(&gcgrp_lock);		\
2423 }
2424 
2425 #define	GCGRP_REFRELE(p) {			\
2426 	mutex_enter(&gcgrp_lock);		\
2427 	ASSERT((p)->gcgrp_refcnt > 0);		\
2428 	if (--((p)->gcgrp_refcnt) == 0)		\
2429 		gcgrp_inactive(p);		\
2430 	ASSERT(MUTEX_HELD(&gcgrp_lock));	\
2431 	mutex_exit(&gcgrp_lock);		\
2432 }
2433 
2434 /*
2435  * IRE gateway security attributes structure, pointed to by tsol_ire_gw_secattr
2436  */
2437 struct tsol_tnrhc;
2438 
2439 typedef struct tsol_ire_gw_secattr_s {
2440 	kmutex_t	igsa_lock;	/* lock to protect following */
2441 	struct tsol_tnrhc *igsa_rhc;	/* host entry for gateway */
2442 	tsol_gc_t	*igsa_gc;	/* for prefix IREs */
2443 	tsol_gcgrp_t	*igsa_gcgrp;	/* for cache IREs */
2444 } tsol_ire_gw_secattr_t;
2445 
2446 /*
2447  * Following are the macros to increment/decrement the reference
2448  * count of the IREs and IRBs (ire bucket).
2449  *
2450  * 1) We bump up the reference count of an IRE to make sure that
2451  *    it does not get deleted and freed while we are using it.
2452  *    Typically all the lookup functions hold the bucket lock,
2453  *    and look for the IRE. If it finds an IRE, it bumps up the
2454  *    reference count before dropping the lock. Sometimes we *may* want
2455  *    to bump up the reference count after we *looked* up i.e without
2456  *    holding the bucket lock. So, the IRE_REFHOLD macro does not assert
2457  *    on the bucket lock being held. Any thread trying to delete from
2458  *    the hash bucket can still do so but cannot free the IRE if
2459  *    ire_refcnt is not 0.
2460  *
2461  * 2) We bump up the reference count on the bucket where the IRE resides
2462  *    (IRB), when we want to prevent the IREs getting deleted from a given
2463  *    hash bucket. This makes life easier for ire_walk type functions which
2464  *    wants to walk the IRE list, call a function, but needs to drop
2465  *    the bucket lock to prevent recursive rw_enters. While the
2466  *    lock is dropped, the list could be changed by other threads or
2467  *    the same thread could end up deleting the ire or the ire pointed by
2468  *    ire_next. IRE_REFHOLDing the ire or ire_next is not sufficient as
2469  *    a delete will still remove the ire from the bucket while we have
2470  *    dropped the lock and hence the ire_next would be NULL. Thus, we
2471  *    need a mechanism to prevent deletions from a given bucket.
2472  *
2473  *    To prevent deletions, we bump up the reference count on the
2474  *    bucket. If the bucket is held, ire_delete just marks IRE_MARK_CONDEMNED
2475  *    both on the ire's ire_marks and the bucket's irb_marks. When the
2476  *    reference count on the bucket drops to zero, all the CONDEMNED ires
2477  *    are deleted. We don't have to bump up the reference count on the
2478  *    bucket if we are walking the bucket and never have to drop the bucket
2479  *    lock. Note that IRB_REFHOLD does not prevent addition of new ires
2480  *    in the list. It is okay because addition of new ires will not cause
2481  *    ire_next to point to freed memory. We do IRB_REFHOLD only when
2482  *    all of the 3 conditions are true :
2483  *
2484  *    1) The code needs to walk the IRE bucket from start to end.
2485  *    2) It may have to drop the bucket lock sometimes while doing (1)
2486  *    3) It does not want any ires to be deleted meanwhile.
2487  */
2488 
2489 /*
2490  * Bump up the reference count on the IRE. We cannot assert that the
2491  * bucket lock is being held as it is legal to bump up the reference
2492  * count after the first lookup has returned the IRE without
2493  * holding the lock. Currently ip_wput does this for caching IRE_CACHEs.
2494  */
2495 
2496 #ifdef DEBUG
2497 #define	IRE_UNTRACE_REF(ire)	ire_untrace_ref(ire);
2498 #define	IRE_TRACE_REF(ire)	ire_trace_ref(ire);
2499 #else
2500 #define	IRE_UNTRACE_REF(ire)
2501 #define	IRE_TRACE_REF(ire)
2502 #endif
2503 
2504 #define	IRE_REFHOLD_NOTR(ire) {				\
2505 	atomic_add_32(&(ire)->ire_refcnt, 1);		\
2506 	ASSERT((ire)->ire_refcnt != 0);			\
2507 }
2508 
2509 #define	IRE_REFHOLD(ire) {				\
2510 	IRE_REFHOLD_NOTR(ire);				\
2511 	IRE_TRACE_REF(ire);				\
2512 }
2513 
2514 #define	IRE_REFHOLD_LOCKED(ire)	{			\
2515 	IRE_TRACE_REF(ire);				\
2516 	(ire)->ire_refcnt++;				\
2517 }
2518 
2519 /*
2520  * Decrement the reference count on the IRE.
2521  * In architectures e.g sun4u, where atomic_add_32_nv is just
2522  * a cas, we need to maintain the right memory barrier semantics
2523  * as that of mutex_exit i.e all the loads and stores should complete
2524  * before the cas is executed. membar_exit() does that here.
2525  *
2526  * NOTE : This macro is used only in places where we want performance.
2527  *	  To avoid bloating the code, we use the function "ire_refrele"
2528  *	  which essentially calls the macro.
2529  */
2530 #define	IRE_REFRELE_NOTR(ire) {					\
2531 	ASSERT((ire)->ire_refcnt != 0);				\
2532 	membar_exit();						\
2533 	if (atomic_add_32_nv(&(ire)->ire_refcnt, -1) == 0)	\
2534 		ire_inactive(ire);				\
2535 }
2536 
2537 #define	IRE_REFRELE(ire) {					\
2538 	if (ire->ire_bucket != NULL) {				\
2539 		IRE_UNTRACE_REF(ire);				\
2540 	}							\
2541 	IRE_REFRELE_NOTR(ire);					\
2542 }
2543 
2544 /*
2545  * Bump up the reference count on the hash bucket - IRB to
2546  * prevent ires from being deleted in this bucket.
2547  */
2548 #define	IRB_REFHOLD(irb) {				\
2549 	rw_enter(&(irb)->irb_lock, RW_WRITER);		\
2550 	(irb)->irb_refcnt++;				\
2551 	ASSERT((irb)->irb_refcnt != 0);			\
2552 	rw_exit(&(irb)->irb_lock);			\
2553 }
2554 #define	IRB_REFHOLD_LOCKED(irb) {			\
2555 	ASSERT(RW_WRITE_HELD(&(irb)->irb_lock));	\
2556 	(irb)->irb_refcnt++;				\
2557 	ASSERT((irb)->irb_refcnt != 0);			\
2558 }
2559 
2560 void irb_refrele_ftable(irb_t *);
2561 /*
2562  * Note: when IRB_MARK_FTABLE (i.e., IRE_CACHETABLE entry), the irb_t
2563  * is statically allocated, so that when the irb_refcnt goes to 0,
2564  * we simply clean up the ire list and continue.
2565  */
2566 #define	IRB_REFRELE(irb) {				\
2567 	if ((irb)->irb_marks & IRB_MARK_FTABLE) {	\
2568 		irb_refrele_ftable((irb));		\
2569 	} else {					\
2570 		rw_enter(&(irb)->irb_lock, RW_WRITER);		\
2571 		ASSERT((irb)->irb_refcnt != 0);			\
2572 		if (--(irb)->irb_refcnt	== 0 &&			\
2573 		    ((irb)->irb_marks & IRE_MARK_CONDEMNED)) {	\
2574 			ire_t *ire_list;			\
2575 								\
2576 			ire_list = ire_unlink(irb);		\
2577 			rw_exit(&(irb)->irb_lock);		\
2578 			ASSERT(ire_list != NULL);		\
2579 			ire_cleanup(ire_list);			\
2580 		} else {					\
2581 			rw_exit(&(irb)->irb_lock);		\
2582 		}						\
2583 	}							\
2584 }
2585 
2586 extern struct kmem_cache *rt_entry_cache;
2587 
2588 /*
2589  * Lock the fast path mp for access, since the fp_mp can be deleted
2590  * due a DL_NOTE_FASTPATH_FLUSH in the case of IRE_BROADCAST
2591  */
2592 
2593 #define	LOCK_IRE_FP_MP(ire) {				\
2594 		if ((ire)->ire_type == IRE_BROADCAST)	\
2595 			mutex_enter(&ire->ire_nce->nce_lock);	\
2596 	}
2597 #define	UNLOCK_IRE_FP_MP(ire) {				\
2598 		if ((ire)->ire_type == IRE_BROADCAST)	\
2599 			mutex_exit(&ire->ire_nce->nce_lock);	\
2600 	}
2601 
2602 typedef struct ire4 {
2603 	ipaddr_t ire4_src_addr;		/* Source address to use. */
2604 	ipaddr_t ire4_mask;		/* Mask for matching this IRE. */
2605 	ipaddr_t ire4_addr;		/* Address this IRE represents. */
2606 	ipaddr_t ire4_gateway_addr;	/* Gateway if IRE_CACHE/IRE_OFFSUBNET */
2607 	ipaddr_t ire4_cmask;		/* Mask from parent prefix route */
2608 } ire4_t;
2609 
2610 typedef struct ire6 {
2611 	in6_addr_t ire6_src_addr;	/* Source address to use. */
2612 	in6_addr_t ire6_mask;		/* Mask for matching this IRE. */
2613 	in6_addr_t ire6_addr;		/* Address this IRE represents. */
2614 	in6_addr_t ire6_gateway_addr;	/* Gateway if IRE_CACHE/IRE_OFFSUBNET */
2615 	in6_addr_t ire6_cmask;		/* Mask from parent prefix route */
2616 } ire6_t;
2617 
2618 typedef union ire_addr {
2619 	ire6_t	ire6_u;
2620 	ire4_t	ire4_u;
2621 } ire_addr_u_t;
2622 
2623 /* Internet Routing Entry */
2624 typedef struct ire_s {
2625 	struct	ire_s	*ire_next;	/* The hash chain must be first. */
2626 	struct	ire_s	**ire_ptpn;	/* Pointer to previous next. */
2627 	uint32_t	ire_refcnt;	/* Number of references */
2628 	mblk_t		*ire_mp;	/* Non-null if allocated as mblk */
2629 	queue_t		*ire_rfq;	/* recv from this queue */
2630 	queue_t		*ire_stq;	/* send to this queue */
2631 	union {
2632 		uint_t	*max_fragp;	/* Used only during ire creation */
2633 		uint_t	max_frag;	/* MTU (next hop or path). */
2634 	} imf_u;
2635 #define	ire_max_frag	imf_u.max_frag
2636 #define	ire_max_fragp	imf_u.max_fragp
2637 	uint32_t	ire_frag_flag;	/* IPH_DF or zero. */
2638 	uint32_t	ire_ident;	/* Per IRE IP ident. */
2639 	uint32_t	ire_tire_mark;	/* Used for reclaim of unused. */
2640 	uchar_t		ire_ipversion;	/* IPv4/IPv6 version */
2641 	uchar_t		ire_marks;	/* IRE_MARK_CONDEMNED etc. */
2642 	ushort_t	ire_type;	/* Type of IRE */
2643 	uint_t	ire_ib_pkt_count;	/* Inbound packets for ire_addr */
2644 	uint_t	ire_ob_pkt_count;	/* Outbound packets to ire_addr */
2645 	uint_t	ire_ll_hdr_length;	/* Non-zero if we do M_DATA prepends */
2646 	time_t	ire_create_time;	/* Time (in secs) IRE was created. */
2647 	uint32_t	ire_phandle;	/* Associate prefix IREs to cache */
2648 	uint32_t	ire_ihandle;	/* Associate interface IREs to cache */
2649 	ipif_t		*ire_ipif;	/* the interface that this ire uses */
2650 	uint32_t	ire_flags;	/* flags related to route (RTF_*) */
2651 	uint_t ire_ipsec_overhead;	/* IPSEC overhead */
2652 	/*
2653 	 * Neighbor Cache Entry for IPv6; arp info for IPv4
2654 	 */
2655 	struct	nce_s	*ire_nce;
2656 	uint_t		ire_masklen;	/* # bits in ire_mask{,_v6} */
2657 	ire_addr_u_t	ire_u;		/* IPv4/IPv6 address info. */
2658 
2659 	irb_t		*ire_bucket;	/* Hash bucket when ire_ptphn is set */
2660 	iulp_t		ire_uinfo;	/* Upper layer protocol info. */
2661 	/*
2662 	 * Protects ire_uinfo, ire_max_frag, and ire_frag_flag.
2663 	 */
2664 	kmutex_t	ire_lock;
2665 	uint_t		ire_ipif_seqid; /* ipif_seqid of ire_ipif */
2666 	uint_t		ire_ipif_ifindex; /* ifindex associated with ipif */
2667 	clock_t		ire_last_used_time;	/* Last used time */
2668 	tsol_ire_gw_secattr_t *ire_gw_secattr; /* gateway security attributes */
2669 	zoneid_t	ire_zoneid;	/* for local address discrimination */
2670 	/*
2671 	 * ire's that are embedded inside mblk_t and sent to the external
2672 	 * resolver use the ire_stq_ifindex to track the ifindex of the
2673 	 * ire_stq, so that the ill (if it exists) can be correctly recovered
2674 	 * for cleanup in the esbfree routine when arp failure occurs.
2675 	 * Similarly, the ire_stackid is used to recover the ip_stack_t.
2676 	 */
2677 	uint_t		ire_stq_ifindex;
2678 	netstackid_t	ire_stackid;
2679 	uint_t		ire_defense_count;	/* number of ARP conflicts */
2680 	uint_t		ire_defense_time;	/* last time defended (secs) */
2681 	boolean_t	ire_trace_disable;	/* True when alloc fails */
2682 	ip_stack_t	*ire_ipst;	/* Does not have a netstack_hold */
2683 } ire_t;
2684 
2685 /* IPv4 compatibility macros */
2686 #define	ire_src_addr		ire_u.ire4_u.ire4_src_addr
2687 #define	ire_mask		ire_u.ire4_u.ire4_mask
2688 #define	ire_addr		ire_u.ire4_u.ire4_addr
2689 #define	ire_gateway_addr	ire_u.ire4_u.ire4_gateway_addr
2690 #define	ire_cmask		ire_u.ire4_u.ire4_cmask
2691 
2692 #define	ire_src_addr_v6		ire_u.ire6_u.ire6_src_addr
2693 #define	ire_mask_v6		ire_u.ire6_u.ire6_mask
2694 #define	ire_addr_v6		ire_u.ire6_u.ire6_addr
2695 #define	ire_gateway_addr_v6	ire_u.ire6_u.ire6_gateway_addr
2696 #define	ire_cmask_v6		ire_u.ire6_u.ire6_cmask
2697 
2698 /* Convenient typedefs for sockaddrs */
2699 typedef	struct sockaddr_in	sin_t;
2700 typedef	struct sockaddr_in6	sin6_t;
2701 
2702 /* Address structure used for internal bind with IP */
2703 typedef struct ipa_conn_s {
2704 	ipaddr_t	ac_laddr;
2705 	ipaddr_t	ac_faddr;
2706 	uint16_t	ac_fport;
2707 	uint16_t	ac_lport;
2708 } ipa_conn_t;
2709 
2710 typedef struct ipa6_conn_s {
2711 	in6_addr_t	ac6_laddr;
2712 	in6_addr_t	ac6_faddr;
2713 	uint16_t	ac6_fport;
2714 	uint16_t	ac6_lport;
2715 } ipa6_conn_t;
2716 
2717 /*
2718  * Using ipa_conn_x_t or ipa6_conn_x_t allows us to modify the behavior of IP's
2719  * bind handler.
2720  */
2721 typedef struct ipa_conn_extended_s {
2722 	uint64_t	acx_flags;
2723 	ipa_conn_t	acx_conn;
2724 } ipa_conn_x_t;
2725 
2726 typedef struct ipa6_conn_extended_s {
2727 	uint64_t	ac6x_flags;
2728 	ipa6_conn_t	ac6x_conn;
2729 } ipa6_conn_x_t;
2730 
2731 /* flag values for ipa_conn_x_t and ipa6_conn_x_t. */
2732 #define	ACX_VERIFY_DST	0x1ULL	/* verify destination address is reachable */
2733 
2734 /* Name/Value Descriptor. */
2735 typedef struct nv_s {
2736 	uint64_t nv_value;
2737 	char	*nv_name;
2738 } nv_t;
2739 
2740 #define	ILL_FRAG_HASH(s, i) \
2741 	((ntohl(s) ^ ((i) ^ ((i) >> 8))) % ILL_FRAG_HASH_TBL_COUNT)
2742 
2743 /*
2744  * The MAX number of allowed fragmented packets per hash bucket
2745  * calculation is based on the most common mtu size of 1500. This limit
2746  * will work well for other mtu sizes as well.
2747  */
2748 #define	COMMON_IP_MTU 1500
2749 #define	MAX_FRAG_MIN 10
2750 #define	MAX_FRAG_PKTS(ipst)	\
2751 	MAX(MAX_FRAG_MIN, (2 * (ipst->ips_ip_reass_queue_bytes / \
2752 	    (COMMON_IP_MTU * ILL_FRAG_HASH_TBL_COUNT))))
2753 
2754 /*
2755  * Maximum dups allowed per packet.
2756  */
2757 extern uint_t ip_max_frag_dups;
2758 
2759 /*
2760  * Per-packet information for received packets and transmitted.
2761  * Used by the transport protocols when converting between the packet
2762  * and ancillary data and socket options.
2763  *
2764  * Note: This private data structure and related IPPF_* constant
2765  * definitions are exposed to enable compilation of some debugging tools
2766  * like lsof which use struct tcp_t in <inet/tcp.h>. This is intended to be
2767  * a temporary hack and long term alternate interfaces should be defined
2768  * to support the needs of such tools and private definitions moved to
2769  * private headers.
2770  */
2771 struct ip6_pkt_s {
2772 	uint_t		ipp_fields;		/* Which fields are valid */
2773 	uint_t		ipp_sticky_ignored;	/* sticky fields to ignore */
2774 	uint_t		ipp_ifindex;		/* pktinfo ifindex */
2775 	in6_addr_t	ipp_addr;		/* pktinfo src/dst addr */
2776 	uint_t		ipp_unicast_hops;	/* IPV6_UNICAST_HOPS */
2777 	uint_t		ipp_multicast_hops;	/* IPV6_MULTICAST_HOPS */
2778 	uint_t		ipp_hoplimit;		/* IPV6_HOPLIMIT */
2779 	uint_t		ipp_hopoptslen;
2780 	uint_t		ipp_rtdstoptslen;
2781 	uint_t		ipp_rthdrlen;
2782 	uint_t		ipp_dstoptslen;
2783 	uint_t		ipp_pathmtulen;
2784 	uint_t		ipp_fraghdrlen;
2785 	ip6_hbh_t	*ipp_hopopts;
2786 	ip6_dest_t	*ipp_rtdstopts;
2787 	ip6_rthdr_t	*ipp_rthdr;
2788 	ip6_dest_t	*ipp_dstopts;
2789 	ip6_frag_t	*ipp_fraghdr;
2790 	struct ip6_mtuinfo *ipp_pathmtu;
2791 	in6_addr_t	ipp_nexthop;		/* Transmit only */
2792 	uint8_t		ipp_tclass;
2793 	int8_t		ipp_use_min_mtu;
2794 };
2795 typedef struct ip6_pkt_s ip6_pkt_t;
2796 
2797 extern void ip6_pkt_free(ip6_pkt_t *);	/* free storage inside ip6_pkt_t */
2798 
2799 /*
2800  * This struct is used by ULP_opt_set() functions to return value of IPv4
2801  * ancillary options. Currently this is only used by udp and icmp and only
2802  * IP_PKTINFO option is supported.
2803  */
2804 typedef struct ip4_pkt_s {
2805 	uint_t		ip4_ill_index;	/* interface index */
2806 	ipaddr_t	ip4_addr;	/* source address */
2807 } ip4_pkt_t;
2808 
2809 /*
2810  * Used by ULP's to pass options info to ip_output
2811  * currently only IP_PKTINFO is supported.
2812  */
2813 typedef struct ip_opt_info_s {
2814 	uint_t ip_opt_ill_index;
2815 	uint_t ip_opt_flags;
2816 } ip_opt_info_t;
2817 
2818 /*
2819  * value for ip_opt_flags
2820  */
2821 #define	IP_VERIFY_SRC	0x1
2822 
2823 /*
2824  * This structure is used to convey information from IP and the ULP.
2825  * Currently used for the IP_RECVSLLA, IP_RECVIF and IP_RECVPKTINFO options.
2826  * The type of information field is set to IN_PKTINFO (i.e inbound pkt info)
2827  */
2828 typedef struct ip_pktinfo {
2829 	uint32_t		ip_pkt_ulp_type;	/* type of info sent */
2830 	uint32_t		ip_pkt_flags;	/* what is sent up by IP */
2831 	uint32_t		ip_pkt_ifindex;	/* inbound interface index */
2832 	struct sockaddr_dl	ip_pkt_slla;	/* has source link layer addr */
2833 	struct in_addr		ip_pkt_match_addr; /* matched address */
2834 } ip_pktinfo_t;
2835 
2836 /*
2837  * flags to tell UDP what IP is sending; in_pkt_flags
2838  */
2839 #define	IPF_RECVIF	0x01	/* inbound interface index */
2840 #define	IPF_RECVSLLA	0x02	/* source link layer address */
2841 /*
2842  * Inbound interface index + matched address.
2843  * Used only by IPV4.
2844  */
2845 #define	IPF_RECVADDR	0x04
2846 
2847 /* ipp_fields values */
2848 #define	IPPF_IFINDEX	0x0001	/* Part of in6_pktinfo: ifindex */
2849 #define	IPPF_ADDR	0x0002	/* Part of in6_pktinfo: src/dst addr */
2850 #define	IPPF_SCOPE_ID	0x0004	/* Add xmit ip6i_t for sin6_scope_id */
2851 #define	IPPF_NO_CKSUM	0x0008	/* Add xmit ip6i_t for IP6I_NO_*_CKSUM */
2852 
2853 #define	IPPF_RAW_CKSUM	0x0010	/* Add xmit ip6i_t for IP6I_RAW_CHECKSUM */
2854 #define	IPPF_HOPLIMIT	0x0020
2855 #define	IPPF_HOPOPTS	0x0040
2856 #define	IPPF_RTHDR	0x0080
2857 
2858 #define	IPPF_RTDSTOPTS	0x0100
2859 #define	IPPF_DSTOPTS	0x0200
2860 #define	IPPF_NEXTHOP	0x0400
2861 #define	IPPF_PATHMTU	0x0800
2862 
2863 #define	IPPF_TCLASS	0x1000
2864 #define	IPPF_DONTFRAG	0x2000
2865 #define	IPPF_USE_MIN_MTU	0x04000
2866 #define	IPPF_MULTICAST_HOPS	0x08000
2867 
2868 #define	IPPF_UNICAST_HOPS	0x10000
2869 #define	IPPF_FRAGHDR		0x20000
2870 
2871 #define	IPPF_HAS_IP6I \
2872 	(IPPF_IFINDEX|IPPF_ADDR|IPPF_NEXTHOP|IPPF_SCOPE_ID| \
2873 	IPPF_NO_CKSUM|IPPF_RAW_CKSUM|IPPF_HOPLIMIT|IPPF_DONTFRAG| \
2874 	IPPF_USE_MIN_MTU|IPPF_MULTICAST_HOPS|IPPF_UNICAST_HOPS)
2875 
2876 #define	TCP_PORTS_OFFSET	0
2877 #define	UDP_PORTS_OFFSET	0
2878 
2879 /*
2880  * lookups return the ill/ipif only if the flags are clear OR Iam writer.
2881  * ill / ipif lookup functions increment the refcnt on the ill / ipif only
2882  * after calling these macros. This ensures that the refcnt on the ipif or
2883  * ill will eventually drop down to zero.
2884  */
2885 #define	ILL_LOOKUP_FAILED	1	/* Used as error code */
2886 #define	IPIF_LOOKUP_FAILED	2	/* Used as error code */
2887 
2888 #define	ILL_CAN_LOOKUP(ill)						\
2889 	(!((ill)->ill_state_flags & (ILL_CONDEMNED | ILL_CHANGING)) ||	\
2890 	IAM_WRITER_ILL(ill))
2891 
2892 #define	ILL_CAN_WAIT(ill, q)	\
2893 	(((q) != NULL) && !((ill)->ill_state_flags & (ILL_CONDEMNED)))
2894 
2895 #define	IPIF_CAN_LOOKUP(ipif)	\
2896 	(!((ipif)->ipif_state_flags & (IPIF_CONDEMNED | IPIF_CHANGING)) || \
2897 	IAM_WRITER_IPIF(ipif))
2898 
2899 /*
2900  * If the parameter 'q' is NULL, the caller is not interested in wait and
2901  * restart of the operation if the ILL or IPIF cannot be looked up when it is
2902  * marked as 'CHANGING'. Typically a thread that tries to send out data  will
2903  * end up passing NULLs as the last 4 parameters to ill_lookup_on_ifindex and
2904  * in this case 'q' is NULL
2905  */
2906 #define	IPIF_CAN_WAIT(ipif, q)	\
2907 	(((q) != NULL) && !((ipif)->ipif_state_flags & (IPIF_CONDEMNED)))
2908 
2909 #define	IPIF_CAN_LOOKUP_WALKER(ipif)					\
2910 	(!((ipif)->ipif_state_flags & (IPIF_CONDEMNED)) ||		\
2911 	IAM_WRITER_IPIF(ipif))
2912 
2913 #define	ILL_UNMARK_CHANGING(ill)                                \
2914 	(ill)->ill_state_flags &= ~ILL_CHANGING;
2915 
2916 /* Macros used to assert that this thread is a writer */
2917 #define	IAM_WRITER_IPSQ(ipsq)	((ipsq)->ipsq_xop->ipx_writer == curthread)
2918 #define	IAM_WRITER_ILL(ill)	IAM_WRITER_IPSQ((ill)->ill_phyint->phyint_ipsq)
2919 #define	IAM_WRITER_IPIF(ipif)	IAM_WRITER_ILL((ipif)->ipif_ill)
2920 
2921 /*
2922  * Grab ill locks in the proper order. The order is highest addressed
2923  * ill is locked first.
2924  */
2925 #define	GRAB_ILL_LOCKS(ill_1, ill_2)				\
2926 {								\
2927 	if ((ill_1) > (ill_2)) {				\
2928 		if (ill_1 != NULL)				\
2929 			mutex_enter(&(ill_1)->ill_lock);	\
2930 		if (ill_2 != NULL)				\
2931 			mutex_enter(&(ill_2)->ill_lock);	\
2932 	} else {						\
2933 		if (ill_2 != NULL)				\
2934 			mutex_enter(&(ill_2)->ill_lock);	\
2935 		if (ill_1 != NULL && ill_1 != ill_2)		\
2936 			mutex_enter(&(ill_1)->ill_lock);	\
2937 	}							\
2938 }
2939 
2940 #define	RELEASE_ILL_LOCKS(ill_1, ill_2)		\
2941 {						\
2942 	if (ill_1 != NULL)			\
2943 		mutex_exit(&(ill_1)->ill_lock); \
2944 	if (ill_2 != NULL && ill_2 != ill_1)	\
2945 		mutex_exit(&(ill_2)->ill_lock); \
2946 }
2947 
2948 /* Get the other protocol instance ill */
2949 #define	ILL_OTHER(ill)						\
2950 	((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :	\
2951 	    (ill)->ill_phyint->phyint_illv6)
2952 
2953 /* ioctl command info: Ioctl properties extracted and stored in here */
2954 typedef struct cmd_info_s
2955 {
2956 	ipif_t  *ci_ipif;	/* ipif associated with [l]ifreq ioctl's */
2957 	sin_t	*ci_sin;	/* the sin struct passed down */
2958 	sin6_t	*ci_sin6;	/* the sin6_t struct passed down */
2959 	struct lifreq *ci_lifr;	/* the lifreq struct passed down */
2960 } cmd_info_t;
2961 
2962 /*
2963  * List of AH and ESP IPsec acceleration capable ills
2964  */
2965 typedef struct ipsec_capab_ill_s {
2966 	uint_t ill_index;
2967 	boolean_t ill_isv6;
2968 	struct ipsec_capab_ill_s *next;
2969 } ipsec_capab_ill_t;
2970 
2971 extern struct kmem_cache *ire_cache;
2972 
2973 extern ipaddr_t	ip_g_all_ones;
2974 
2975 extern	uint_t	ip_loopback_mtu;	/* /etc/system */
2976 
2977 extern vmem_t *ip_minor_arena_sa;
2978 extern vmem_t *ip_minor_arena_la;
2979 
2980 /*
2981  * ip_g_forward controls IP forwarding.  It takes two values:
2982  *	0: IP_FORWARD_NEVER	Don't forward packets ever.
2983  *	1: IP_FORWARD_ALWAYS	Forward packets for elsewhere.
2984  *
2985  * RFC1122 says there must be a configuration switch to control forwarding,
2986  * but that the default MUST be to not forward packets ever.  Implicit
2987  * control based on configuration of multiple interfaces MUST NOT be
2988  * implemented (Section 3.1).  SunOS 4.1 did provide the "automatic" capability
2989  * and, in fact, it was the default.  That capability is now provided in the
2990  * /etc/rc2.d/S69inet script.
2991  */
2992 
2993 #define	ips_ip_respond_to_address_mask_broadcast ips_param_arr[0].ip_param_value
2994 #define	ips_ip_g_resp_to_echo_bcast	ips_param_arr[1].ip_param_value
2995 #define	ips_ip_g_resp_to_echo_mcast	ips_param_arr[2].ip_param_value
2996 #define	ips_ip_g_resp_to_timestamp	ips_param_arr[3].ip_param_value
2997 #define	ips_ip_g_resp_to_timestamp_bcast ips_param_arr[4].ip_param_value
2998 #define	ips_ip_g_send_redirects		ips_param_arr[5].ip_param_value
2999 #define	ips_ip_g_forward_directed_bcast	ips_param_arr[6].ip_param_value
3000 #define	ips_ip_mrtdebug			ips_param_arr[7].ip_param_value
3001 #define	ips_ip_timer_interval		ips_param_arr[8].ip_param_value
3002 #define	ips_ip_ire_arp_interval		ips_param_arr[9].ip_param_value
3003 #define	ips_ip_ire_redir_interval	ips_param_arr[10].ip_param_value
3004 #define	ips_ip_def_ttl			ips_param_arr[11].ip_param_value
3005 #define	ips_ip_forward_src_routed	ips_param_arr[12].ip_param_value
3006 #define	ips_ip_wroff_extra		ips_param_arr[13].ip_param_value
3007 #define	ips_ip_ire_pathmtu_interval	ips_param_arr[14].ip_param_value
3008 #define	ips_ip_icmp_return		ips_param_arr[15].ip_param_value
3009 #define	ips_ip_path_mtu_discovery	ips_param_arr[16].ip_param_value
3010 #define	ips_ip_ignore_delete_time	ips_param_arr[17].ip_param_value
3011 #define	ips_ip_ignore_redirect		ips_param_arr[18].ip_param_value
3012 #define	ips_ip_output_queue		ips_param_arr[19].ip_param_value
3013 #define	ips_ip_broadcast_ttl		ips_param_arr[20].ip_param_value
3014 #define	ips_ip_icmp_err_interval	ips_param_arr[21].ip_param_value
3015 #define	ips_ip_icmp_err_burst		ips_param_arr[22].ip_param_value
3016 #define	ips_ip_reass_queue_bytes	ips_param_arr[23].ip_param_value
3017 #define	ips_ip_strict_dst_multihoming	ips_param_arr[24].ip_param_value
3018 #define	ips_ip_addrs_per_if		ips_param_arr[25].ip_param_value
3019 #define	ips_ipsec_override_persocket_policy ips_param_arr[26].ip_param_value
3020 #define	ips_icmp_accept_clear_messages	ips_param_arr[27].ip_param_value
3021 #define	ips_igmp_accept_clear_messages	ips_param_arr[28].ip_param_value
3022 
3023 /* IPv6 configuration knobs */
3024 #define	ips_delay_first_probe_time	ips_param_arr[29].ip_param_value
3025 #define	ips_max_unicast_solicit		ips_param_arr[30].ip_param_value
3026 #define	ips_ipv6_def_hops		ips_param_arr[31].ip_param_value
3027 #define	ips_ipv6_icmp_return		ips_param_arr[32].ip_param_value
3028 #define	ips_ipv6_forward_src_routed	ips_param_arr[33].ip_param_value
3029 #define	ips_ipv6_resp_echo_mcast	ips_param_arr[34].ip_param_value
3030 #define	ips_ipv6_send_redirects		ips_param_arr[35].ip_param_value
3031 #define	ips_ipv6_ignore_redirect	ips_param_arr[36].ip_param_value
3032 #define	ips_ipv6_strict_dst_multihoming	ips_param_arr[37].ip_param_value
3033 #define	ips_ip_ire_reclaim_fraction	ips_param_arr[38].ip_param_value
3034 #define	ips_ipsec_policy_log_interval	ips_param_arr[39].ip_param_value
3035 #define	ips_pim_accept_clear_messages	ips_param_arr[40].ip_param_value
3036 #define	ips_ip_ndp_unsolicit_interval	ips_param_arr[41].ip_param_value
3037 #define	ips_ip_ndp_unsolicit_count	ips_param_arr[42].ip_param_value
3038 #define	ips_ipv6_ignore_home_address_opt ips_param_arr[43].ip_param_value
3039 
3040 /* Misc IP configuration knobs */
3041 #define	ips_ip_policy_mask		ips_param_arr[44].ip_param_value
3042 #define	ips_ip_multirt_resolution_interval ips_param_arr[45].ip_param_value
3043 #define	ips_ip_multirt_ttl  		ips_param_arr[46].ip_param_value
3044 #define	ips_ip_multidata_outbound	ips_param_arr[47].ip_param_value
3045 #define	ips_ip_ndp_defense_interval	ips_param_arr[48].ip_param_value
3046 #define	ips_ip_max_temp_idle		ips_param_arr[49].ip_param_value
3047 #define	ips_ip_max_temp_defend		ips_param_arr[50].ip_param_value
3048 #define	ips_ip_max_defend		ips_param_arr[51].ip_param_value
3049 #define	ips_ip_defend_interval		ips_param_arr[52].ip_param_value
3050 #define	ips_ip_dup_recovery		ips_param_arr[53].ip_param_value
3051 #define	ips_ip_restrict_interzone_loopback ips_param_arr[54].ip_param_value
3052 #define	ips_ip_lso_outbound		ips_param_arr[55].ip_param_value
3053 #define	ips_igmp_max_version		ips_param_arr[56].ip_param_value
3054 #define	ips_mld_max_version		ips_param_arr[57].ip_param_value
3055 #define	ips_ip_pmtu_min			ips_param_arr[58].ip_param_value
3056 #define	ips_ipv6_drop_inbound_icmpv6	ips_param_arr[59].ip_param_value
3057 
3058 extern int	dohwcksum;	/* use h/w cksum if supported by the h/w */
3059 #ifdef ZC_TEST
3060 extern int	noswcksum;
3061 #endif
3062 
3063 extern char	ipif_loopback_name[];
3064 
3065 extern nv_t	*ire_nv_tbl;
3066 
3067 extern struct module_info ip_mod_info;
3068 
3069 #define	HOOKS4_INTERESTED_PHYSICAL_IN(ipst)	\
3070 	((ipst)->ips_ip4_physical_in_event.he_interested)
3071 #define	HOOKS6_INTERESTED_PHYSICAL_IN(ipst)	\
3072 	((ipst)->ips_ip6_physical_in_event.he_interested)
3073 #define	HOOKS4_INTERESTED_PHYSICAL_OUT(ipst)	\
3074 	((ipst)->ips_ip4_physical_out_event.he_interested)
3075 #define	HOOKS6_INTERESTED_PHYSICAL_OUT(ipst)	\
3076 	((ipst)->ips_ip6_physical_out_event.he_interested)
3077 #define	HOOKS4_INTERESTED_FORWARDING(ipst)	\
3078 	((ipst)->ips_ip4_forwarding_event.he_interested)
3079 #define	HOOKS6_INTERESTED_FORWARDING(ipst)	\
3080 	((ipst)->ips_ip6_forwarding_event.he_interested)
3081 #define	HOOKS4_INTERESTED_LOOPBACK_IN(ipst)	\
3082 	((ipst)->ips_ip4_loopback_in_event.he_interested)
3083 #define	HOOKS6_INTERESTED_LOOPBACK_IN(ipst)	\
3084 	((ipst)->ips_ip6_loopback_in_event.he_interested)
3085 #define	HOOKS4_INTERESTED_LOOPBACK_OUT(ipst)	\
3086 	((ipst)->ips_ip4_loopback_out_event.he_interested)
3087 #define	HOOKS6_INTERESTED_LOOPBACK_OUT(ipst)	\
3088 	((ipst)->ips_ip6_loopback_out_event.he_interested)
3089 
3090 /*
3091  * Hooks macros used inside of ip
3092  */
3093 #define	FW_HOOKS(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst)	\
3094 									\
3095 	if ((_hook).he_interested) {	\
3096 		hook_pkt_event_t info;					\
3097 									\
3098 		_NOTE(CONSTCOND)					\
3099 		ASSERT((_ilp != NULL) || (_olp != NULL));		\
3100 									\
3101 		FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);		\
3102 		FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);		\
3103 		info.hpe_protocol = ipst->ips_ipv4_net_data;		\
3104 		info.hpe_hdr = _iph;					\
3105 		info.hpe_mp = &(_fm);					\
3106 		info.hpe_mb = _m;					\
3107 		info.hpe_flags = _llm;					\
3108 		if (hook_run(ipst->ips_ipv4_net_data->netd_hooks,	\
3109 		    _event, (hook_data_t)&info) != 0) {			\
3110 			ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3111 			    (_hook).he_name, (void *)_fm, (void *)_m));	\
3112 			freemsg(_fm);					\
3113 			_fm = NULL;					\
3114 			_iph = NULL;					\
3115 			_m = NULL;					\
3116 		} else {						\
3117 			_iph = info.hpe_hdr;				\
3118 			_m = info.hpe_mb;				\
3119 		}							\
3120 	}
3121 
3122 #define	FW_HOOKS6(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst)	\
3123 									\
3124 	if ((_hook).he_interested) {	\
3125 		hook_pkt_event_t info;					\
3126 									\
3127 		_NOTE(CONSTCOND)					\
3128 		ASSERT((_ilp != NULL) || (_olp != NULL));		\
3129 									\
3130 		FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);		\
3131 		FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);		\
3132 		info.hpe_protocol = ipst->ips_ipv6_net_data;		\
3133 		info.hpe_hdr = _iph;					\
3134 		info.hpe_mp = &(_fm);					\
3135 		info.hpe_mb = _m;					\
3136 		info.hpe_flags = _llm;					\
3137 		if (hook_run(ipst->ips_ipv6_net_data->netd_hooks,	\
3138 		    _event, (hook_data_t)&info) != 0) {			\
3139 			ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3140 			    (_hook).he_name, (void *)_fm, (void *)_m));	\
3141 			freemsg(_fm);					\
3142 			_fm = NULL;					\
3143 			_iph = NULL;					\
3144 			_m = NULL;					\
3145 		} else {						\
3146 			_iph = info.hpe_hdr;				\
3147 			_m = info.hpe_mb;				\
3148 		}							\
3149 	}
3150 
3151 #define	FW_SET_ILL_INDEX(fp, ill)					\
3152 	_NOTE(CONSTCOND)						\
3153 	if ((ill) == NULL || (ill)->ill_phyint == NULL) {		\
3154 		(fp) = 0;						\
3155 		_NOTE(CONSTCOND)					\
3156 	} else if (IS_UNDER_IPMP(ill)) {				\
3157 		(fp) = ipmp_ill_get_ipmp_ifindex(ill);			\
3158 	} else {							\
3159 		(fp) = (ill)->ill_phyint->phyint_ifindex;		\
3160 	}
3161 
3162 /*
3163  * Network byte order macros
3164  */
3165 #ifdef	_BIG_ENDIAN
3166 #define	N_IN_CLASSA_NET		IN_CLASSA_NET
3167 #define	N_IN_CLASSD_NET		IN_CLASSD_NET
3168 #define	N_INADDR_UNSPEC_GROUP	INADDR_UNSPEC_GROUP
3169 #define	N_IN_LOOPBACK_NET	(ipaddr_t)0x7f000000U
3170 #else /* _BIG_ENDIAN */
3171 #define	N_IN_CLASSA_NET		(ipaddr_t)0x000000ffU
3172 #define	N_IN_CLASSD_NET		(ipaddr_t)0x000000f0U
3173 #define	N_INADDR_UNSPEC_GROUP	(ipaddr_t)0x000000e0U
3174 #define	N_IN_LOOPBACK_NET	(ipaddr_t)0x0000007fU
3175 #endif /* _BIG_ENDIAN */
3176 #define	CLASSD(addr)	(((addr) & N_IN_CLASSD_NET) == N_INADDR_UNSPEC_GROUP)
3177 #define	CLASSE(addr)	(((addr) & N_IN_CLASSD_NET) == N_IN_CLASSD_NET)
3178 #define	IP_LOOPBACK_ADDR(addr)			\
3179 	(((addr) & N_IN_CLASSA_NET == N_IN_LOOPBACK_NET))
3180 
3181 #ifdef DEBUG
3182 /* IPsec HW acceleration debugging support */
3183 
3184 #define	IPSECHW_CAPAB		0x0001	/* capability negotiation */
3185 #define	IPSECHW_SADB		0x0002	/* SADB exchange */
3186 #define	IPSECHW_PKT		0x0004	/* general packet flow */
3187 #define	IPSECHW_PKTIN		0x0008	/* driver in pkt processing details */
3188 #define	IPSECHW_PKTOUT		0x0010	/* driver out pkt processing details */
3189 
3190 #define	IPSECHW_DEBUG(f, x)	if (ipsechw_debug & (f)) { (void) printf x; }
3191 #define	IPSECHW_CALL(f, r, x)	if (ipsechw_debug & (f)) { (void) r x; }
3192 
3193 extern uint32_t ipsechw_debug;
3194 #else
3195 #define	IPSECHW_DEBUG(f, x)	{}
3196 #define	IPSECHW_CALL(f, r, x)	{}
3197 #endif
3198 
3199 extern int	ip_debug;
3200 extern uint_t	ip_thread_data;
3201 extern krwlock_t ip_thread_rwlock;
3202 extern list_t	ip_thread_list;
3203 
3204 #ifdef IP_DEBUG
3205 #include <sys/debug.h>
3206 #include <sys/promif.h>
3207 
3208 #define	ip0dbg(a)	printf a
3209 #define	ip1dbg(a)	if (ip_debug > 2) printf a
3210 #define	ip2dbg(a)	if (ip_debug > 3) printf a
3211 #define	ip3dbg(a)	if (ip_debug > 4) printf a
3212 #else
3213 #define	ip0dbg(a)	/* */
3214 #define	ip1dbg(a)	/* */
3215 #define	ip2dbg(a)	/* */
3216 #define	ip3dbg(a)	/* */
3217 #endif	/* IP_DEBUG */
3218 
3219 /* Default MAC-layer address string length for mac_colon_addr */
3220 #define	MAC_STR_LEN	128
3221 
3222 struct	ipsec_out_s;
3223 
3224 struct	mac_header_info_s;
3225 
3226 extern void	ill_frag_timer(void *);
3227 extern ill_t	*ill_first(int, int, ill_walk_context_t *, ip_stack_t *);
3228 extern ill_t	*ill_next(ill_walk_context_t *, ill_t *);
3229 extern void	ill_frag_timer_start(ill_t *);
3230 extern void	ill_nic_event_dispatch(ill_t *, lif_if_t, nic_event_t,
3231     nic_event_data_t, size_t);
3232 extern mblk_t	*ip_carve_mp(mblk_t **, ssize_t);
3233 extern mblk_t	*ip_dlpi_alloc(size_t, t_uscalar_t);
3234 extern mblk_t	*ip_dlnotify_alloc(uint_t, uint_t);
3235 extern char	*ip_dot_addr(ipaddr_t, char *);
3236 extern const char *mac_colon_addr(const uint8_t *, size_t, char *, size_t);
3237 extern void	ip_lwput(queue_t *, mblk_t *);
3238 extern boolean_t icmp_err_rate_limit(ip_stack_t *);
3239 extern void	icmp_time_exceeded(queue_t *, mblk_t *, uint8_t, zoneid_t,
3240     ip_stack_t *);
3241 extern void	icmp_unreachable(queue_t *, mblk_t *, uint8_t, zoneid_t,
3242     ip_stack_t *);
3243 extern mblk_t	*ip_add_info(mblk_t *, ill_t *, uint_t, zoneid_t, ip_stack_t *);
3244 cred_t		*ip_best_cred(mblk_t *, conn_t *, pid_t *);
3245 extern mblk_t	*ip_bind_v4(queue_t *, mblk_t *, conn_t *);
3246 extern	boolean_t ip_bind_ipsec_policy_set(conn_t *, mblk_t *);
3247 extern	int	ip_bind_laddr_v4(conn_t *, mblk_t **, uint8_t, ipaddr_t,
3248     uint16_t, boolean_t);
3249 extern	int	ip_proto_bind_laddr_v4(conn_t *, mblk_t **, uint8_t, ipaddr_t,
3250     uint16_t, boolean_t);
3251 extern	int	ip_proto_bind_connected_v4(conn_t *, mblk_t **,
3252     uint8_t, ipaddr_t *, uint16_t, ipaddr_t, uint16_t, boolean_t, boolean_t,
3253     cred_t *);
3254 extern	int	ip_bind_connected_v4(conn_t *, mblk_t **, uint8_t, ipaddr_t *,
3255     uint16_t, ipaddr_t, uint16_t, boolean_t, boolean_t, cred_t *);
3256 extern uint_t	ip_cksum(mblk_t *, int, uint32_t);
3257 extern int	ip_close(queue_t *, int);
3258 extern uint16_t	ip_csum_hdr(ipha_t *);
3259 extern void	ip_proto_not_sup(queue_t *, mblk_t *, uint_t, zoneid_t,
3260     ip_stack_t *);
3261 extern void	ip_ire_g_fini(void);
3262 extern void	ip_ire_g_init(void);
3263 extern void	ip_ire_fini(ip_stack_t *);
3264 extern void	ip_ire_init(ip_stack_t *);
3265 extern int	ip_openv4(queue_t *q, dev_t *devp, int flag, int sflag,
3266 		    cred_t *credp);
3267 extern int	ip_openv6(queue_t *q, dev_t *devp, int flag, int sflag,
3268 		    cred_t *credp);
3269 extern int	ip_reassemble(mblk_t *, ipf_t *, uint_t, boolean_t, ill_t *,
3270     size_t);
3271 extern int	ip_opt_set_ill(conn_t *, int, boolean_t, boolean_t,
3272     int, int, mblk_t *);
3273 extern void	ip_rput(queue_t *, mblk_t *);
3274 extern void	ip_input(ill_t *, ill_rx_ring_t *, mblk_t *,
3275     struct mac_header_info_s *);
3276 extern mblk_t	*ip_accept_tcp(ill_t *, ill_rx_ring_t *, squeue_t *,
3277     mblk_t *, mblk_t **, uint_t *cnt);
3278 extern void	ip_rput_dlpi(queue_t *, mblk_t *);
3279 extern void	ip_rput_forward(ire_t *, ipha_t *, mblk_t *, ill_t *);
3280 extern void	ip_rput_forward_multicast(ipaddr_t, mblk_t *, ipif_t *);
3281 
3282 extern void	ip_mib2_add_ip_stats(mib2_ipIfStatsEntry_t *,
3283 		    mib2_ipIfStatsEntry_t *);
3284 extern void	ip_mib2_add_icmp6_stats(mib2_ipv6IfIcmpEntry_t *,
3285 		    mib2_ipv6IfIcmpEntry_t *);
3286 extern void	ip_udp_input(queue_t *, mblk_t *, ipha_t *, ire_t *, ill_t *);
3287 extern void	ip_proto_input(queue_t *, mblk_t *, ipha_t *, ire_t *, ill_t *,
3288     uint32_t);
3289 extern void	ip_rput_other(ipsq_t *, queue_t *, mblk_t *, void *);
3290 extern ire_t	*ip_check_multihome(void *, ire_t *, ill_t *);
3291 extern void	ip_setpktversion(conn_t *, boolean_t, boolean_t, ip_stack_t *);
3292 extern void	ip_trash_ire_reclaim(void *);
3293 extern void	ip_trash_timer_expire(void *);
3294 extern void	ip_wput(queue_t *, mblk_t *);
3295 extern void	ip_output(void *, mblk_t *, void *, int);
3296 extern void	ip_output_options(void *, mblk_t *, void *, int,
3297     ip_opt_info_t *);
3298 
3299 extern void	ip_wput_ire(queue_t *, mblk_t *, ire_t *, conn_t *, int,
3300 		    zoneid_t);
3301 extern void	ip_wput_local(queue_t *, ill_t *, ipha_t *, mblk_t *, ire_t *,
3302 		    int, zoneid_t);
3303 extern void	ip_wput_multicast(queue_t *, mblk_t *, ipif_t *, zoneid_t);
3304 extern void	ip_wput_nondata(ipsq_t *, queue_t *, mblk_t *, void *);
3305 extern void	ip_wsrv(queue_t *);
3306 extern char	*ip_nv_lookup(nv_t *, int);
3307 extern boolean_t ip_local_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
3308 extern boolean_t ip_remote_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
3309 extern ipaddr_t ip_massage_options(ipha_t *, netstack_t *);
3310 extern ipaddr_t ip_net_mask(ipaddr_t);
3311 extern void	ip_newroute(queue_t *, mblk_t *, ipaddr_t, conn_t *, zoneid_t,
3312 		    ip_stack_t *);
3313 extern ipxmit_state_t	ip_xmit_v4(mblk_t *, ire_t *, struct ipsec_out_s *,
3314     boolean_t, conn_t *);
3315 extern int	ip_hdr_complete(ipha_t *, zoneid_t, ip_stack_t *);
3316 
3317 extern struct qinit iprinitv6;
3318 extern struct qinit ipwinitv6;
3319 
3320 extern void	ipmp_init(ip_stack_t *);
3321 extern void	ipmp_destroy(ip_stack_t *);
3322 extern ipmp_grp_t *ipmp_grp_create(const char *, phyint_t *);
3323 extern void	ipmp_grp_destroy(ipmp_grp_t *);
3324 extern void	ipmp_grp_info(const ipmp_grp_t *, lifgroupinfo_t *);
3325 extern int	ipmp_grp_rename(ipmp_grp_t *, const char *);
3326 extern ipmp_grp_t *ipmp_grp_lookup(const char *, ip_stack_t *);
3327 extern int	ipmp_grp_vet_phyint(ipmp_grp_t *, phyint_t *);
3328 extern ipmp_illgrp_t *ipmp_illgrp_create(ill_t *);
3329 extern void	ipmp_illgrp_destroy(ipmp_illgrp_t *);
3330 extern ill_t	*ipmp_illgrp_add_ipif(ipmp_illgrp_t *, ipif_t *);
3331 extern void	ipmp_illgrp_del_ipif(ipmp_illgrp_t *, ipif_t *);
3332 extern ill_t	*ipmp_illgrp_next_ill(ipmp_illgrp_t *);
3333 extern ill_t	*ipmp_illgrp_hold_next_ill(ipmp_illgrp_t *);
3334 extern ill_t	*ipmp_illgrp_cast_ill(ipmp_illgrp_t *);
3335 extern ill_t	*ipmp_illgrp_hold_cast_ill(ipmp_illgrp_t *);
3336 extern ill_t	*ipmp_illgrp_ipmp_ill(ipmp_illgrp_t *);
3337 extern void	ipmp_illgrp_refresh_mtu(ipmp_illgrp_t *);
3338 extern ipmp_arpent_t *ipmp_illgrp_create_arpent(ipmp_illgrp_t *, mblk_t *,
3339     boolean_t);
3340 extern void	ipmp_illgrp_destroy_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3341 extern ipmp_arpent_t *ipmp_illgrp_lookup_arpent(ipmp_illgrp_t *, ipaddr_t *);
3342 extern void	ipmp_illgrp_refresh_arpent(ipmp_illgrp_t *);
3343 extern void	ipmp_illgrp_mark_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3344 extern ill_t	*ipmp_illgrp_find_ill(ipmp_illgrp_t *, uchar_t *, uint_t);
3345 extern void	ipmp_illgrp_link_grp(ipmp_illgrp_t *, ipmp_grp_t *);
3346 extern int	ipmp_illgrp_unlink_grp(ipmp_illgrp_t *);
3347 extern uint_t	ipmp_ill_get_ipmp_ifindex(const ill_t *);
3348 extern void	ipmp_ill_join_illgrp(ill_t *, ipmp_illgrp_t *);
3349 extern void	ipmp_ill_leave_illgrp(ill_t *);
3350 extern ill_t	*ipmp_ill_hold_ipmp_ill(ill_t *);
3351 extern boolean_t ipmp_ill_is_active(ill_t *);
3352 extern void	ipmp_ill_refresh_active(ill_t *);
3353 extern void	ipmp_phyint_join_grp(phyint_t *, ipmp_grp_t *);
3354 extern void	ipmp_phyint_leave_grp(phyint_t *);
3355 extern void	ipmp_phyint_refresh_active(phyint_t *);
3356 extern ill_t	*ipmp_ipif_bound_ill(const ipif_t *);
3357 extern ill_t	*ipmp_ipif_hold_bound_ill(const ipif_t *);
3358 extern boolean_t ipmp_ipif_is_dataaddr(const ipif_t *);
3359 extern boolean_t ipmp_ipif_is_stubaddr(const ipif_t *);
3360 
3361 extern void	conn_drain_insert(conn_t *, idl_tx_list_t *);
3362 extern int	conn_ipsec_length(conn_t *);
3363 extern void	ip_wput_ipsec_out(queue_t *, mblk_t *, ipha_t *, ill_t *,
3364     ire_t *);
3365 extern ipaddr_t	ip_get_dst(ipha_t *);
3366 extern int	ipsec_out_extra_length(mblk_t *);
3367 extern int	ipsec_in_extra_length(mblk_t *);
3368 extern mblk_t	*ipsec_in_alloc(boolean_t, netstack_t *);
3369 extern boolean_t ipsec_in_is_secure(mblk_t *);
3370 extern void	ipsec_out_process(queue_t *, mblk_t *, ire_t *, uint_t);
3371 extern void	ipsec_out_to_in(mblk_t *);
3372 extern void	ip_fanout_proto_again(mblk_t *, ill_t *, ill_t *, ire_t *);
3373 
3374 extern void	ire_cleanup(ire_t *);
3375 extern void	ire_inactive(ire_t *);
3376 extern boolean_t irb_inactive(irb_t *);
3377 extern ire_t	*ire_unlink(irb_t *);
3378 
3379 #ifdef DEBUG
3380 extern	boolean_t th_trace_ref(const void *, ip_stack_t *);
3381 extern	void	th_trace_unref(const void *);
3382 extern	void	th_trace_cleanup(const void *, boolean_t);
3383 extern	void	ire_trace_ref(ire_t *);
3384 extern	void	ire_untrace_ref(ire_t *);
3385 #endif
3386 
3387 extern int	ip_srcid_insert(const in6_addr_t *, zoneid_t, ip_stack_t *);
3388 extern int	ip_srcid_remove(const in6_addr_t *, zoneid_t, ip_stack_t *);
3389 extern void	ip_srcid_find_id(uint_t, in6_addr_t *, zoneid_t, netstack_t *);
3390 extern uint_t	ip_srcid_find_addr(const in6_addr_t *, zoneid_t, netstack_t *);
3391 
3392 extern uint8_t	ipoptp_next(ipoptp_t *);
3393 extern uint8_t	ipoptp_first(ipoptp_t *, ipha_t *);
3394 extern int	ip_opt_get_user(const ipha_t *, uchar_t *);
3395 extern int	ipsec_req_from_conn(conn_t *, ipsec_req_t *, int);
3396 extern int	ip_snmp_get(queue_t *q, mblk_t *mctl, int level);
3397 extern int	ip_snmp_set(queue_t *q, int, int, uchar_t *, int);
3398 extern void	ip_process_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3399 extern void	ip_quiesce_conn(conn_t *);
3400 extern  void    ip_reprocess_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3401 extern void	ip_restart_optmgmt(ipsq_t *, queue_t *, mblk_t *, void *);
3402 extern void	ip_ioctl_finish(queue_t *, mblk_t *, int, int, ipsq_t *);
3403 
3404 extern boolean_t ip_cmpbuf(const void *, uint_t, boolean_t, const void *,
3405     uint_t);
3406 extern boolean_t ip_allocbuf(void **, uint_t *, boolean_t, const void *,
3407     uint_t);
3408 extern void	ip_savebuf(void **, uint_t *, boolean_t, const void *, uint_t);
3409 
3410 extern boolean_t	ipsq_pending_mp_cleanup(ill_t *, conn_t *);
3411 extern void	conn_ioctl_cleanup(conn_t *);
3412 extern ill_t	*conn_get_held_ill(conn_t *, ill_t **, int *);
3413 
3414 struct tcp_stack;
3415 extern void ip_xmit_reset_serialize(mblk_t *, int, zoneid_t, struct tcp_stack *,
3416     conn_t *);
3417 
3418 struct multidata_s;
3419 struct pdesc_s;
3420 
3421 extern mblk_t	*ip_mdinfo_alloc(ill_mdt_capab_t *);
3422 extern mblk_t	*ip_mdinfo_return(ire_t *, conn_t *, char *, ill_mdt_capab_t *);
3423 extern mblk_t	*ip_lsoinfo_alloc(ill_lso_capab_t *);
3424 extern mblk_t	*ip_lsoinfo_return(ire_t *, conn_t *, char *,
3425     ill_lso_capab_t *);
3426 extern uint_t	ip_md_cksum(struct pdesc_s *, int, uint_t);
3427 extern boolean_t ip_md_addr_attr(struct multidata_s *, struct pdesc_s *,
3428 			const mblk_t *);
3429 extern boolean_t ip_md_hcksum_attr(struct multidata_s *, struct pdesc_s *,
3430 			uint32_t, uint32_t, uint32_t, uint32_t);
3431 extern boolean_t ip_md_zcopy_attr(struct multidata_s *, struct pdesc_s *,
3432 			uint_t);
3433 extern	void	ip_unbind(conn_t *connp);
3434 
3435 extern void tnet_init(void);
3436 extern void tnet_fini(void);
3437 
3438 /* Hooks for CGTP (multirt routes) filtering module */
3439 #define	CGTP_FILTER_REV_1	1
3440 #define	CGTP_FILTER_REV_2	2
3441 #define	CGTP_FILTER_REV_3	3
3442 #define	CGTP_FILTER_REV		CGTP_FILTER_REV_3
3443 
3444 /* cfo_filter and cfo_filter_v6 hooks return values */
3445 #define	CGTP_IP_PKT_NOT_CGTP	0
3446 #define	CGTP_IP_PKT_PREMIUM	1
3447 #define	CGTP_IP_PKT_DUPLICATE	2
3448 
3449 /* Version 3 of the filter interface */
3450 typedef struct cgtp_filter_ops {
3451 	int	cfo_filter_rev;			/* CGTP_FILTER_REV_3 */
3452 	int	(*cfo_change_state)(netstackid_t, int);
3453 	int	(*cfo_add_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t,
3454 		    ipaddr_t, ipaddr_t);
3455 	int	(*cfo_del_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t);
3456 	int	(*cfo_add_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *,
3457 		    in6_addr_t *, in6_addr_t *);
3458 	int	(*cfo_del_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *);
3459 	int	(*cfo_filter)(netstackid_t, uint_t, mblk_t *);
3460 	int	(*cfo_filter_v6)(netstackid_t, uint_t, ip6_t *,
3461 		    ip6_frag_t *);
3462 } cgtp_filter_ops_t;
3463 
3464 #define	CGTP_MCAST_SUCCESS	1
3465 
3466 /*
3467  * The separate CGTP module needs this global symbol so that it
3468  * can check the version and determine whether to use the old or the new
3469  * version of the filtering interface.
3470  */
3471 extern int	ip_cgtp_filter_rev;
3472 
3473 extern int	ip_cgtp_filter_supported(void);
3474 extern int	ip_cgtp_filter_register(netstackid_t, cgtp_filter_ops_t *);
3475 extern int	ip_cgtp_filter_unregister(netstackid_t);
3476 extern int	ip_cgtp_filter_is_registered(netstackid_t);
3477 
3478 /* Flags for ire_multirt_lookup() */
3479 
3480 #define	MULTIRT_USESTAMP	0x0001
3481 #define	MULTIRT_SETSTAMP	0x0002
3482 #define	MULTIRT_CACHEGW		0x0004
3483 
3484 /* Debug stuff for multirt route resolution. */
3485 #if defined(DEBUG) && !defined(__lint)
3486 /* Our "don't send, rather drop" flag. */
3487 #define	MULTIRT_DEBUG_FLAG	0x8000
3488 
3489 #define	MULTIRT_TRACE(x)	ip2dbg(x)
3490 
3491 #define	MULTIRT_DEBUG_TAG(mblk)	\
3492 	do { \
3493 		ASSERT(mblk != NULL); \
3494 		MULTIRT_TRACE(("%s[%d]: tagging mblk %p, tag was %d\n", \
3495 		__FILE__, __LINE__, \
3496 		(void *)(mblk), (mblk)->b_flag & MULTIRT_DEBUG_FLAG)); \
3497 		(mblk)->b_flag |= MULTIRT_DEBUG_FLAG; \
3498 	} while (0)
3499 
3500 #define	MULTIRT_DEBUG_UNTAG(mblk) \
3501 	do { \
3502 		ASSERT(mblk != NULL); \
3503 		MULTIRT_TRACE(("%s[%d]: untagging mblk %p, tag was %d\n", \
3504 		__FILE__, __LINE__, \
3505 		(void *)(mblk), (mblk)->b_flag & MULTIRT_DEBUG_FLAG)); \
3506 		(mblk)->b_flag &= ~MULTIRT_DEBUG_FLAG; \
3507 	} while (0)
3508 
3509 #define	MULTIRT_DEBUG_TAGGED(mblk) \
3510 	(((mblk)->b_flag & MULTIRT_DEBUG_FLAG) ? B_TRUE : B_FALSE)
3511 #else
3512 #define	MULTIRT_DEBUG_TAG(mblk)		ASSERT(mblk != NULL)
3513 #define	MULTIRT_DEBUG_UNTAG(mblk)	ASSERT(mblk != NULL)
3514 #define	MULTIRT_DEBUG_TAGGED(mblk)	B_FALSE
3515 #endif
3516 
3517 /*
3518  * IP observability hook support
3519  */
3520 
3521 /*
3522  * ipobs_hooktype_t describes the hook types supported
3523  * by the ip module. IPOBS_HOOK_LOCAL refers to packets
3524  * which are looped back internally within the ip module.
3525  */
3526 
3527 typedef enum ipobs_hook_type {
3528 	IPOBS_HOOK_LOCAL,
3529 	IPOBS_HOOK_OUTBOUND,
3530 	IPOBS_HOOK_INBOUND
3531 } ipobs_hook_type_t;
3532 
3533 typedef void ipobs_cbfunc_t(mblk_t *);
3534 
3535 typedef struct ipobs_cb {
3536 	ipobs_cbfunc_t	*ipobs_cbfunc;
3537 	list_node_t	ipobs_cbnext;
3538 } ipobs_cb_t;
3539 
3540 /*
3541  * This structure holds the data passed back from the ip module to
3542  * observability consumers.
3543  *
3544  * ihd_mp	  Pointer to the IP packet.
3545  * ihd_zsrc	  Source zoneid; set to ALL_ZONES when unknown.
3546  * ihd_zdst	  Destination zoneid; set to ALL_ZONES when unknown.
3547  * ihd_htype	  IPobs hook type, see above for the defined types.
3548  * ihd_ipver	  IP version of the packet.
3549  * ihd_ifindex	  Interface index that the packet was received/sent over.
3550  *		  For local packets, this is the index of the interface
3551  *		  associated with the local destination address.
3552  * ihd_grifindex  IPMP group interface index (zero unless ihd_ifindex
3553  *		  is an IPMP underlying interface).
3554  * ihd_stack	  Netstack the packet is from.
3555  */
3556 typedef struct ipobs_hook_data {
3557 	mblk_t			*ihd_mp;
3558 	zoneid_t		ihd_zsrc;
3559 	zoneid_t		ihd_zdst;
3560 	ipobs_hook_type_t	ihd_htype;
3561 	uint16_t		ihd_ipver;
3562 	uint64_t		ihd_ifindex;
3563 	uint64_t 		ihd_grifindex;
3564 	netstack_t		*ihd_stack;
3565 } ipobs_hook_data_t;
3566 
3567 /*
3568  * Per-ILL Multidata Transmit capabilities.
3569  */
3570 struct ill_mdt_capab_s {
3571 	uint_t ill_mdt_version;  /* interface version */
3572 	uint_t ill_mdt_on;	 /* on/off switch for MDT on this ILL */
3573 	uint_t ill_mdt_hdr_head; /* leading header fragment extra space */
3574 	uint_t ill_mdt_hdr_tail; /* trailing header fragment extra space */
3575 	uint_t ill_mdt_max_pld;	 /* maximum payload buffers per Multidata */
3576 	uint_t ill_mdt_span_limit; /* maximum payload span per packet */
3577 };
3578 
3579 struct ill_hcksum_capab_s {
3580 	uint_t	ill_hcksum_version;	/* interface version */
3581 	uint_t	ill_hcksum_txflags;	/* capabilities on transmit */
3582 };
3583 
3584 struct ill_zerocopy_capab_s {
3585 	uint_t	ill_zerocopy_version;	/* interface version */
3586 	uint_t	ill_zerocopy_flags;	/* capabilities */
3587 };
3588 
3589 struct ill_lso_capab_s {
3590 	uint_t	ill_lso_on;		/* on/off switch for LSO on this ILL */
3591 	uint_t	ill_lso_flags;		/* capabilities */
3592 	uint_t	ill_lso_max;		/* maximum size of payload */
3593 };
3594 
3595 /*
3596  * rr_ring_state cycles in the order shown below from RR_FREE through
3597  * RR_FREE_IN_PROG and  back to RR_FREE.
3598  */
3599 typedef enum {
3600 	RR_FREE,			/* Free slot */
3601 	RR_SQUEUE_UNBOUND,		/* Ring's squeue is unbound */
3602 	RR_SQUEUE_BIND_INPROG,		/* Ring's squeue bind in progress */
3603 	RR_SQUEUE_BOUND,		/* Ring's squeue bound to cpu */
3604 	RR_FREE_INPROG			/* Ring is being freed */
3605 } ip_ring_state_t;
3606 
3607 #define	ILL_MAX_RINGS		256	/* Max num of rx rings we can manage */
3608 #define	ILL_POLLING		0x01	/* Polling in use */
3609 
3610 /*
3611  * These functions pointer types are exported by the mac/dls layer.
3612  * we need to duplicate the definitions here because we cannot
3613  * include mac/dls header files here.
3614  */
3615 typedef boolean_t		(*ip_mac_intr_disable_t)(void *);
3616 typedef void			(*ip_mac_intr_enable_t)(void *);
3617 typedef ip_mac_tx_cookie_t	(*ip_dld_tx_t)(void *, mblk_t *,
3618     uint64_t, uint16_t);
3619 typedef	void			(*ip_flow_enable_t)(void *, ip_mac_tx_cookie_t);
3620 typedef void			*(*ip_dld_callb_t)(void *,
3621     ip_flow_enable_t, void *);
3622 typedef boolean_t		(*ip_dld_fctl_t)(void *, ip_mac_tx_cookie_t);
3623 typedef int			(*ip_capab_func_t)(void *, uint_t,
3624     void *, uint_t);
3625 
3626 /*
3627  * POLLING README
3628  * sq_get_pkts() is called to pick packets from softring in poll mode. It
3629  * calls rr_rx to get the chain and process it with rr_ip_accept.
3630  * rr_rx = mac_soft_ring_poll() to pick packets
3631  * rr_ip_accept = ip_accept_tcp() to process packets
3632  */
3633 
3634 /*
3635  * XXX: With protocol, service specific squeues, they will have
3636  * specific acceptor functions.
3637  */
3638 typedef	mblk_t *(*ip_mac_rx_t)(void *, size_t);
3639 typedef mblk_t *(*ip_accept_t)(ill_t *, ill_rx_ring_t *,
3640     squeue_t *, mblk_t *, mblk_t **, uint_t *);
3641 
3642 /*
3643  * rr_intr_enable, rr_intr_disable, rr_rx_handle, rr_rx:
3644  * May be accessed while in the squeue AND after checking that SQS_POLL_CAPAB
3645  * is set.
3646  *
3647  * rr_ring_state: Protected by ill_lock.
3648  */
3649 struct ill_rx_ring {
3650 	ip_mac_intr_disable_t	rr_intr_disable; /* Interrupt disabling func */
3651 	ip_mac_intr_enable_t	rr_intr_enable;	/* Interrupt enabling func */
3652 	void			*rr_intr_handle; /* Handle interrupt funcs */
3653 	ip_mac_rx_t		rr_rx;		/* Driver receive function */
3654 	ip_accept_t		rr_ip_accept;	/* IP accept function */
3655 	void			*rr_rx_handle;	/* Handle for Rx ring */
3656 	squeue_t		*rr_sqp; /* Squeue the ring is bound to */
3657 	ill_t			*rr_ill;	/* back pointer to ill */
3658 	ip_ring_state_t		rr_ring_state;	/* State of this ring */
3659 };
3660 
3661 /*
3662  * IP - DLD direct function call capability
3663  * Suffixes, df - dld function, dh - dld handle,
3664  * cf - client (IP) function, ch - client handle
3665  */
3666 typedef struct ill_dld_direct_s {		/* DLD provided driver Tx */
3667 	ip_dld_tx_t		idd_tx_df;	/* str_mdata_fastpath_put */
3668 	void			*idd_tx_dh;	/* dld_str_t *dsp */
3669 	ip_dld_callb_t		idd_tx_cb_df;	/* mac_tx_srs_notify */
3670 	void			*idd_tx_cb_dh;	/* mac_client_handle_t *mch */
3671 	ip_dld_fctl_t		idd_tx_fctl_df;	/* mac_tx_is_flow_blocked */
3672 	void			*idd_tx_fctl_dh;	/* mac_client_handle */
3673 } ill_dld_direct_t;
3674 
3675 /* IP - DLD polling capability */
3676 typedef struct ill_dld_poll_s {
3677 	ill_rx_ring_t		idp_ring_tbl[ILL_MAX_RINGS];
3678 } ill_dld_poll_t;
3679 
3680 /* Describes ill->ill_dld_capab */
3681 struct ill_dld_capab_s {
3682 	ip_capab_func_t		idc_capab_df;	/* dld_capab_func */
3683 	void			*idc_capab_dh;	/* dld_str_t *dsp */
3684 	ill_dld_direct_t	idc_direct;
3685 	ill_dld_poll_t		idc_poll;
3686 };
3687 
3688 /*
3689  * IP squeues exports
3690  */
3691 extern boolean_t 	ip_squeue_fanout;
3692 
3693 #define	IP_SQUEUE_GET(hint) ip_squeue_random(hint)
3694 
3695 extern void ip_squeue_init(void (*)(squeue_t *));
3696 extern squeue_t	*ip_squeue_random(uint_t);
3697 extern squeue_t *ip_squeue_get(ill_rx_ring_t *);
3698 extern squeue_t *ip_squeue_getfree(pri_t);
3699 extern int ip_squeue_cpu_move(squeue_t *, processorid_t);
3700 extern void *ip_squeue_add_ring(ill_t *, void *);
3701 extern void ip_squeue_bind_ring(ill_t *, ill_rx_ring_t *, processorid_t);
3702 extern void ip_squeue_clean_ring(ill_t *, ill_rx_ring_t *);
3703 extern void ip_squeue_quiesce_ring(ill_t *, ill_rx_ring_t *);
3704 extern void ip_squeue_restart_ring(ill_t *, ill_rx_ring_t *);
3705 extern void ip_squeue_clean_all(ill_t *);
3706 
3707 extern void tcp_wput(queue_t *, mblk_t *);
3708 
3709 extern int	ip_fill_mtuinfo(struct in6_addr *, in_port_t,
3710 	struct ip6_mtuinfo *, netstack_t *);
3711 extern	ipif_t *conn_get_held_ipif(conn_t *, ipif_t **, int *);
3712 extern void ipobs_register_hook(netstack_t *, ipobs_cbfunc_t *);
3713 extern void ipobs_unregister_hook(netstack_t *, ipobs_cbfunc_t *);
3714 extern void ipobs_hook(mblk_t *, int, zoneid_t, zoneid_t, const ill_t *, int,
3715     uint32_t, ip_stack_t *);
3716 typedef void    (*ipsq_func_t)(ipsq_t *, queue_t *, mblk_t *, void *);
3717 
3718 /*
3719  * Squeue tags. Tags only need to be unique when the callback function is the
3720  * same to distinguish between different calls, but we use unique tags for
3721  * convenience anyway.
3722  */
3723 #define	SQTAG_IP_INPUT			1
3724 #define	SQTAG_TCP_INPUT_ICMP_ERR	2
3725 #define	SQTAG_TCP6_INPUT_ICMP_ERR	3
3726 #define	SQTAG_IP_TCP_INPUT		4
3727 #define	SQTAG_IP6_TCP_INPUT		5
3728 #define	SQTAG_IP_TCP_CLOSE		6
3729 #define	SQTAG_TCP_OUTPUT		7
3730 #define	SQTAG_TCP_TIMER			8
3731 #define	SQTAG_TCP_TIMEWAIT		9
3732 #define	SQTAG_TCP_ACCEPT_FINISH		10
3733 #define	SQTAG_TCP_ACCEPT_FINISH_Q0	11
3734 #define	SQTAG_TCP_ACCEPT_PENDING	12
3735 #define	SQTAG_TCP_LISTEN_DISCON		13
3736 #define	SQTAG_TCP_CONN_REQ_1		14
3737 #define	SQTAG_TCP_EAGER_BLOWOFF		15
3738 #define	SQTAG_TCP_EAGER_CLEANUP		16
3739 #define	SQTAG_TCP_EAGER_CLEANUP_Q0	17
3740 #define	SQTAG_TCP_CONN_IND		18
3741 #define	SQTAG_TCP_RSRV			19
3742 #define	SQTAG_TCP_ABORT_BUCKET		20
3743 #define	SQTAG_TCP_REINPUT		21
3744 #define	SQTAG_TCP_REINPUT_EAGER		22
3745 #define	SQTAG_TCP_INPUT_MCTL		23
3746 #define	SQTAG_TCP_RPUTOTHER		24
3747 #define	SQTAG_IP_PROTO_AGAIN		25
3748 #define	SQTAG_IP_FANOUT_TCP		26
3749 #define	SQTAG_IPSQ_CLEAN_RING		27
3750 #define	SQTAG_TCP_WPUT_OTHER		28
3751 #define	SQTAG_TCP_CONN_REQ_UNBOUND	29
3752 #define	SQTAG_TCP_SEND_PENDING		30
3753 #define	SQTAG_BIND_RETRY		31
3754 #define	SQTAG_UDP_FANOUT		32
3755 #define	SQTAG_UDP_INPUT			33
3756 #define	SQTAG_UDP_WPUT			34
3757 #define	SQTAG_UDP_OUTPUT		35
3758 #define	SQTAG_TCP_KSSL_INPUT		36
3759 #define	SQTAG_TCP_DROP_Q0		37
3760 #define	SQTAG_TCP_CONN_REQ_2		38
3761 #define	SQTAG_IP_INPUT_RX_RING		39
3762 #define	SQTAG_SQUEUE_CHANGE		40
3763 #define	SQTAG_CONNECT_FINISH		41
3764 #define	SQTAG_SYNCHRONOUS_OP		42
3765 #define	SQTAG_TCP_SHUTDOWN_OUTPUT	43
3766 #define	SQTAG_XMIT_EARLY_RESET		44
3767 
3768 #define	NOT_OVER_IP(ip_wq)	\
3769 	(ip_wq->q_next != NULL ||	\
3770 	    (ip_wq->q_qinfo->qi_minfo->mi_idname) == NULL ||	\
3771 	    strcmp(ip_wq->q_qinfo->qi_minfo->mi_idname,	\
3772 	    IP_MOD_NAME) != 0 ||	\
3773 	    ip_wq->q_qinfo->qi_minfo->mi_idnum != IP_MOD_ID)
3774 
3775 #define	PROTO_FLOW_CNTRLD(connp)	(connp->conn_flow_cntrld)
3776 #endif	/* _KERNEL */
3777 
3778 #ifdef	__cplusplus
3779 }
3780 #endif
3781 
3782 #endif	/* _INET_IP_H */
3783