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