xref: /illumos-gate/usr/src/uts/common/inet/ip.h (revision 59927d31)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55dddb8baSkcpoon  * Common Development and Distribution License (the "License").
65dddb8baSkcpoon  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215dddb8baSkcpoon 
227c478bd9Sstevel@tonic-gate /*
23*59927d31SYuri Pankov  * Copyright (c) 1990 Mentat Inc.
241f19738eSmeem  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
257c6d7024SJerry Jelinek  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
26*59927d31SYuri Pankov  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_INET_IP_H
307c478bd9Sstevel@tonic-gate #define	_INET_IP_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h>
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
397c478bd9Sstevel@tonic-gate #include <inet/nd.h>
407c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
417c478bd9Sstevel@tonic-gate #include <net/if_dl.h>
427c478bd9Sstevel@tonic-gate #include <net/if.h>
437c478bd9Sstevel@tonic-gate #include <netinet/ip.h>
447c478bd9Sstevel@tonic-gate #include <netinet/igmp.h>
45381a2a9aSdr #include <sys/neti.h>
46381a2a9aSdr #include <sys/hook.h>
47381a2a9aSdr #include <sys/hook_event.h>
48381a2a9aSdr #include <sys/hook_impl.h>
49f4b3ec61Sdh #include <inet/ip_stack.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #ifdef _KERNEL
527c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
537c478bd9Sstevel@tonic-gate #include <sys/avl.h>
54da14cebeSEric Cheng #include <sys/list.h>
557c478bd9Sstevel@tonic-gate #include <sys/vmem.h>
567c478bd9Sstevel@tonic-gate #include <sys/squeue.h>
5745916cd2Sjpk #include <net/route.h>
587c478bd9Sstevel@tonic-gate #include <sys/systm.h>
59c793af95Ssangeeta #include <net/radix.h>
606a8288c7Scarlsonj #include <sys/modhash.h>
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #ifdef DEBUG
637c478bd9Sstevel@tonic-gate #define	CONN_DEBUG
647c478bd9Sstevel@tonic-gate #endif
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate #define	IP_DEBUG
677c478bd9Sstevel@tonic-gate /*
687c478bd9Sstevel@tonic-gate  * The mt-streams(9F) flags for the IP module; put here so that other
697c478bd9Sstevel@tonic-gate  * "drivers" that are actually IP (e.g., ICMP, UDP) can use the same set
707c478bd9Sstevel@tonic-gate  * of flags.
717c478bd9Sstevel@tonic-gate  */
727c478bd9Sstevel@tonic-gate #define	IP_DEVMTFLAGS D_MP
73ff550d0eSmasputra #endif	/* _KERNEL */
74ff550d0eSmasputra 
75ff550d0eSmasputra #define	IP_MOD_NAME	"ip"
76ff550d0eSmasputra #define	IP_DEV_NAME	"/dev/ip"
77ff550d0eSmasputra #define	IP6_DEV_NAME	"/dev/ip6"
78ff550d0eSmasputra 
79ff550d0eSmasputra #define	UDP_MOD_NAME	"udp"
80ff550d0eSmasputra #define	UDP_DEV_NAME	"/dev/udp"
81ff550d0eSmasputra #define	UDP6_DEV_NAME	"/dev/udp6"
82ff550d0eSmasputra 
83ff550d0eSmasputra #define	TCP_MOD_NAME	"tcp"
84ff550d0eSmasputra #define	TCP_DEV_NAME	"/dev/tcp"
85ff550d0eSmasputra #define	TCP6_DEV_NAME	"/dev/tcp6"
8677c67f2fSkcpoon 
8777c67f2fSkcpoon #define	SCTP_MOD_NAME	"sctp"
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #ifndef	_IPADDR_T
907c478bd9Sstevel@tonic-gate #define	_IPADDR_T
917c478bd9Sstevel@tonic-gate typedef uint32_t ipaddr_t;
927c478bd9Sstevel@tonic-gate #endif
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /* Number of bits in an address */
957c478bd9Sstevel@tonic-gate #define	IP_ABITS		32
96bd670b35SErik Nordmark #define	IPV4_ABITS		IP_ABITS
977c478bd9Sstevel@tonic-gate #define	IPV6_ABITS		128
987f125a53SRavi Chandra Nallan #define	IP_MAX_HW_LEN	40
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate #define	IP_HOST_MASK		(ipaddr_t)0xffffffffU
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate #define	IP_CSUM(mp, off, sum)		(~ip_cksum(mp, off, sum) & 0xFFFF)
1037c478bd9Sstevel@tonic-gate #define	IP_CSUM_PARTIAL(mp, off, sum)	ip_cksum(mp, off, sum)
1047c478bd9Sstevel@tonic-gate #define	IP_BCSUM_PARTIAL(bp, len, sum)	bcksum(bp, len, sum)
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define	ILL_FRAG_HASH_TBL_COUNT	((unsigned int)64)
1077c478bd9Sstevel@tonic-gate #define	ILL_FRAG_HASH_TBL_SIZE	(ILL_FRAG_HASH_TBL_COUNT * sizeof (ipfb_t))
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate #define	IPV4_ADDR_LEN			4
1107c478bd9Sstevel@tonic-gate #define	IP_ADDR_LEN			IPV4_ADDR_LEN
1117c478bd9Sstevel@tonic-gate #define	IP_ARP_PROTO_TYPE		0x0800
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate #define	IPV4_VERSION			4
1147c478bd9Sstevel@tonic-gate #define	IP_VERSION			IPV4_VERSION
1157c478bd9Sstevel@tonic-gate #define	IP_SIMPLE_HDR_LENGTH_IN_WORDS	5
1167c478bd9Sstevel@tonic-gate #define	IP_SIMPLE_HDR_LENGTH		20
1177c478bd9Sstevel@tonic-gate #define	IP_MAX_HDR_LENGTH		60
1187c478bd9Sstevel@tonic-gate 
11945916cd2Sjpk #define	IP_MAX_OPT_LENGTH (IP_MAX_HDR_LENGTH-IP_SIMPLE_HDR_LENGTH)
12045916cd2Sjpk 
1217c478bd9Sstevel@tonic-gate #define	IP_MIN_MTU			(IP_MAX_HDR_LENGTH + 8)	/* 68 bytes */
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*
1247c478bd9Sstevel@tonic-gate  * XXX IP_MAXPACKET is defined in <netinet/ip.h> as well. At some point the
1257c478bd9Sstevel@tonic-gate  * 2 files should be cleaned up to remove all redundant definitions.
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate #define	IP_MAXPACKET			65535
1287c478bd9Sstevel@tonic-gate #define	IP_SIMPLE_HDR_VERSION \
1297c478bd9Sstevel@tonic-gate 	((IP_VERSION << 4) | IP_SIMPLE_HDR_LENGTH_IN_WORDS)
1307c478bd9Sstevel@tonic-gate 
13145916cd2Sjpk #define	UDPH_SIZE			8
13245916cd2Sjpk 
1337c478bd9Sstevel@tonic-gate /*
1347c478bd9Sstevel@tonic-gate  * Constants and type definitions to support IP IOCTL commands
1357c478bd9Sstevel@tonic-gate  */
1367c478bd9Sstevel@tonic-gate #define	IP_IOCTL			(('i'<<8)|'p')
1377c478bd9Sstevel@tonic-gate #define	IP_IOC_IRE_DELETE		4
1387c478bd9Sstevel@tonic-gate #define	IP_IOC_IRE_DELETE_NO_REPLY	5
1397c478bd9Sstevel@tonic-gate #define	IP_IOC_RTS_REQUEST		7
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /* Common definitions used by IP IOCTL data structures */
1427c478bd9Sstevel@tonic-gate typedef struct ipllcmd_s {
1437c478bd9Sstevel@tonic-gate 	uint_t	ipllc_cmd;
1447c478bd9Sstevel@tonic-gate 	uint_t	ipllc_name_offset;
1457c478bd9Sstevel@tonic-gate 	uint_t	ipllc_name_length;
1467c478bd9Sstevel@tonic-gate } ipllc_t;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* IP IRE Delete Command Structure. */
1497c478bd9Sstevel@tonic-gate typedef struct ipid_s {
1507c478bd9Sstevel@tonic-gate 	ipllc_t	ipid_ipllc;
1517c478bd9Sstevel@tonic-gate 	uint_t	ipid_ire_type;
1527c478bd9Sstevel@tonic-gate 	uint_t	ipid_addr_offset;
1537c478bd9Sstevel@tonic-gate 	uint_t	ipid_addr_length;
1547c478bd9Sstevel@tonic-gate 	uint_t	ipid_mask_offset;
1557c478bd9Sstevel@tonic-gate 	uint_t	ipid_mask_length;
1567c478bd9Sstevel@tonic-gate } ipid_t;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #define	ipid_cmd		ipid_ipllc.ipllc_cmd
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * Temporary state for ip options parser.
1637c478bd9Sstevel@tonic-gate  */
1647c478bd9Sstevel@tonic-gate typedef struct ipoptp_s
1657c478bd9Sstevel@tonic-gate {
1667c478bd9Sstevel@tonic-gate 	uint8_t		*ipoptp_next;	/* next option to look at */
1677c478bd9Sstevel@tonic-gate 	uint8_t		*ipoptp_end;	/* end of options */
1687c478bd9Sstevel@tonic-gate 	uint8_t		*ipoptp_cur;	/* start of current option */
1697c478bd9Sstevel@tonic-gate 	uint8_t		ipoptp_len;	/* length of current option */
1707c478bd9Sstevel@tonic-gate 	uint32_t	ipoptp_flags;
1717c478bd9Sstevel@tonic-gate } ipoptp_t;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * Flag(s) for ipoptp_flags
1757c478bd9Sstevel@tonic-gate  */
1767c478bd9Sstevel@tonic-gate #define	IPOPTP_ERROR	0x00000001
1777c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1787c478bd9Sstevel@tonic-gate 
1796e91bba0SGirish Moodalbail /* Controls forwarding of IP packets, set via ipadm(1M)/ndd(1M) */
1807c478bd9Sstevel@tonic-gate #define	IP_FORWARD_NEVER	0
1817c478bd9Sstevel@tonic-gate #define	IP_FORWARD_ALWAYS	1
1827c478bd9Sstevel@tonic-gate 
1836e91bba0SGirish Moodalbail #define	WE_ARE_FORWARDING(ipst)	((ipst)->ips_ip_forwarding == IP_FORWARD_ALWAYS)
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate #define	IPH_HDR_LENGTH(ipha)						\
1867c478bd9Sstevel@tonic-gate 	((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length & 0xF) << 2)
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate #define	IPH_HDR_VERSION(ipha)						\
1897c478bd9Sstevel@tonic-gate 	((int)(((ipha_t *)ipha)->ipha_version_and_hdr_length) >> 4)
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1927c478bd9Sstevel@tonic-gate /*
1937c478bd9Sstevel@tonic-gate  * IP reassembly macros.  We hide starting and ending offsets in b_next and
1947c478bd9Sstevel@tonic-gate  * b_prev of messages on the reassembly queue.	The messages are chained using
1957c478bd9Sstevel@tonic-gate  * b_cont.  These macros are used in ip_reassemble() so we don't have to see
1967c478bd9Sstevel@tonic-gate  * the ugly casts and assignments.
1977c478bd9Sstevel@tonic-gate  * Note that the offsets are <= 64k i.e. a uint_t is sufficient to represent
1987c478bd9Sstevel@tonic-gate  * them.
1997c478bd9Sstevel@tonic-gate  */
2007c478bd9Sstevel@tonic-gate #define	IP_REASS_START(mp)		((uint_t)(uintptr_t)((mp)->b_next))
2017c478bd9Sstevel@tonic-gate #define	IP_REASS_SET_START(mp, u)	\
2027c478bd9Sstevel@tonic-gate 	((mp)->b_next = (mblk_t *)(uintptr_t)(u))
2037c478bd9Sstevel@tonic-gate #define	IP_REASS_END(mp)		((uint_t)(uintptr_t)((mp)->b_prev))
2047c478bd9Sstevel@tonic-gate #define	IP_REASS_SET_END(mp, u)		\
2057c478bd9Sstevel@tonic-gate 	((mp)->b_prev = (mblk_t *)(uintptr_t)(u))
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate #define	IP_REASS_COMPLETE	0x1
2087c478bd9Sstevel@tonic-gate #define	IP_REASS_PARTIAL	0x2
2097c478bd9Sstevel@tonic-gate #define	IP_REASS_FAILED		0x4
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate /*
2127c478bd9Sstevel@tonic-gate  * Test to determine whether this is a module instance of IP or a
2137c478bd9Sstevel@tonic-gate  * driver instance of IP.
2147c478bd9Sstevel@tonic-gate  */
2157c478bd9Sstevel@tonic-gate #define	CONN_Q(q)	(WR(q)->q_next == NULL)
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate #define	Q_TO_CONN(q)	((conn_t *)(q)->q_ptr)
2187c478bd9Sstevel@tonic-gate #define	Q_TO_TCP(q)	(Q_TO_CONN((q))->conn_tcp)
219ff550d0eSmasputra #define	Q_TO_UDP(q)	(Q_TO_CONN((q))->conn_udp)
220fc80c0dfSnordmark #define	Q_TO_ICMP(q)	(Q_TO_CONN((q))->conn_icmp)
221fc80c0dfSnordmark #define	Q_TO_RTS(q)	(Q_TO_CONN((q))->conn_rts)
2227c478bd9Sstevel@tonic-gate 
223bd670b35SErik Nordmark #define	CONNP_TO_WQ(connp)	((connp)->conn_wq)
224bd670b35SErik Nordmark #define	CONNP_TO_RQ(connp)	((connp)->conn_rq)
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #define	GRAB_CONN_LOCK(q)	{				\
2277c478bd9Sstevel@tonic-gate 	if (q != NULL && CONN_Q(q))				\
2287c478bd9Sstevel@tonic-gate 		mutex_enter(&(Q_TO_CONN(q))->conn_lock);	\
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate #define	RELEASE_CONN_LOCK(q)	{				\
2327c478bd9Sstevel@tonic-gate 	if (q != NULL && CONN_Q(q))				\
2337c478bd9Sstevel@tonic-gate 		mutex_exit(&(Q_TO_CONN(q))->conn_lock);		\
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate 
236838a4ffaSBrian Ruthven /*
237838a4ffaSBrian Ruthven  * Ref counter macros for ioctls. This provides a guard for TCP to stop
238838a4ffaSBrian Ruthven  * tcp_close from removing the rq/wq whilst an ioctl is still in flight on the
239838a4ffaSBrian Ruthven  * stream. The ioctl could have been queued on e.g. an ipsq. tcp_close will wait
240838a4ffaSBrian Ruthven  * until the ioctlref count is zero before proceeding.
241838a4ffaSBrian Ruthven  * Ideally conn_oper_pending_ill would be used for this purpose. However, in the
242838a4ffaSBrian Ruthven  * case where an ioctl is aborted or interrupted, it can be cleared prematurely.
243838a4ffaSBrian Ruthven  * There are also some race possibilities between ip and the stream head which
244838a4ffaSBrian Ruthven  * can also end up with conn_oper_pending_ill being cleared prematurely. So, to
245838a4ffaSBrian Ruthven  * avoid these situations, we use a dedicated ref counter for ioctls which is
246838a4ffaSBrian Ruthven  * used in addition to and in parallel with the normal conn_ref count.
247838a4ffaSBrian Ruthven  */
248838a4ffaSBrian Ruthven #define	CONN_INC_IOCTLREF_LOCKED(connp)	{			\
249838a4ffaSBrian Ruthven 	ASSERT(MUTEX_HELD(&(connp)->conn_lock));		\
250838a4ffaSBrian Ruthven 	DTRACE_PROBE1(conn__inc__ioctlref, conn_t *, (connp));	\
251838a4ffaSBrian Ruthven 	(connp)->conn_ioctlref++;				\
252838a4ffaSBrian Ruthven 	mutex_exit(&(connp)->conn_lock);			\
253838a4ffaSBrian Ruthven }
254838a4ffaSBrian Ruthven 
255838a4ffaSBrian Ruthven #define	CONN_INC_IOCTLREF(connp)	{			\
256838a4ffaSBrian Ruthven 	mutex_enter(&(connp)->conn_lock);			\
257838a4ffaSBrian Ruthven 	CONN_INC_IOCTLREF_LOCKED(connp);			\
258838a4ffaSBrian Ruthven }
259838a4ffaSBrian Ruthven 
260838a4ffaSBrian Ruthven #define	CONN_DEC_IOCTLREF(connp)	{			\
261838a4ffaSBrian Ruthven 	mutex_enter(&(connp)->conn_lock);			\
262838a4ffaSBrian Ruthven 	DTRACE_PROBE1(conn__dec__ioctlref, conn_t *, (connp));	\
263838a4ffaSBrian Ruthven 	/* Make sure conn_ioctlref will not underflow. */	\
264838a4ffaSBrian Ruthven 	ASSERT((connp)->conn_ioctlref != 0);			\
265838a4ffaSBrian Ruthven 	if ((--(connp)->conn_ioctlref == 0) &&			\
266838a4ffaSBrian Ruthven 	    ((connp)->conn_state_flags & CONN_CLOSING)) {	\
267838a4ffaSBrian Ruthven 		cv_broadcast(&(connp)->conn_cv);		\
268838a4ffaSBrian Ruthven 	}							\
269838a4ffaSBrian Ruthven 	mutex_exit(&(connp)->conn_lock);			\
270838a4ffaSBrian Ruthven }
271838a4ffaSBrian Ruthven 
272838a4ffaSBrian Ruthven 
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * Complete the pending operation. Usually an ioctl. Can also
2757c478bd9Sstevel@tonic-gate  * be a bind or option management request that got enqueued
2767c478bd9Sstevel@tonic-gate  * in an ipsq_t. Called on completion of the operation.
2777c478bd9Sstevel@tonic-gate  */
2787c478bd9Sstevel@tonic-gate #define	CONN_OPER_PENDING_DONE(connp)	{			\
2797c478bd9Sstevel@tonic-gate 	mutex_enter(&(connp)->conn_lock);			\
2807c478bd9Sstevel@tonic-gate 	(connp)->conn_oper_pending_ill = NULL;			\
2817c478bd9Sstevel@tonic-gate 	cv_broadcast(&(connp)->conn_refcv);			\
2827c478bd9Sstevel@tonic-gate 	mutex_exit(&(connp)->conn_lock);			\
2837c478bd9Sstevel@tonic-gate 	CONN_DEC_REF(connp);					\
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate /*
2877c478bd9Sstevel@tonic-gate  * Values for squeue switch:
2887c478bd9Sstevel@tonic-gate  */
2897c478bd9Sstevel@tonic-gate #define	IP_SQUEUE_ENTER_NODRAIN	1
2907c478bd9Sstevel@tonic-gate #define	IP_SQUEUE_ENTER	2
291bd670b35SErik Nordmark #define	IP_SQUEUE_FILL 3
2927c478bd9Sstevel@tonic-gate 
293bd670b35SErik Nordmark extern int ip_squeue_flag;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /* IP Fragmentation Reassembly Header */
2967c478bd9Sstevel@tonic-gate typedef struct ipf_s {
2977c478bd9Sstevel@tonic-gate 	struct ipf_s	*ipf_hash_next;
2987c478bd9Sstevel@tonic-gate 	struct ipf_s	**ipf_ptphn;	/* Pointer to previous hash next. */
2997c478bd9Sstevel@tonic-gate 	uint32_t	ipf_ident;	/* Ident to match. */
3007c478bd9Sstevel@tonic-gate 	uint8_t		ipf_protocol;	/* Protocol to match. */
3017c478bd9Sstevel@tonic-gate 	uchar_t		ipf_last_frag_seen : 1;	/* Last fragment seen ? */
3027c478bd9Sstevel@tonic-gate 	time_t		ipf_timestamp;	/* Reassembly start time. */
3037c478bd9Sstevel@tonic-gate 	mblk_t		*ipf_mp;	/* mblk we live in. */
3047c478bd9Sstevel@tonic-gate 	mblk_t		*ipf_tail_mp;	/* Frag queue tail pointer. */
3057c478bd9Sstevel@tonic-gate 	int		ipf_hole_cnt;	/* Number of holes (hard-case). */
3067c478bd9Sstevel@tonic-gate 	int		ipf_end;	/* Tail end offset (0 -> hard-case). */
3077c478bd9Sstevel@tonic-gate 	uint_t		ipf_gen;	/* Frag queue generation */
3087c478bd9Sstevel@tonic-gate 	size_t		ipf_count;	/* Count of bytes used by frag */
3097c478bd9Sstevel@tonic-gate 	uint_t		ipf_nf_hdr_len; /* Length of nonfragmented header */
3107c478bd9Sstevel@tonic-gate 	in6_addr_t	ipf_v6src;	/* IPv6 source address */
3117c478bd9Sstevel@tonic-gate 	in6_addr_t	ipf_v6dst;	/* IPv6 dest address */
3127c478bd9Sstevel@tonic-gate 	uint_t		ipf_prev_nexthdr_offset; /* Offset for nexthdr value */
3137c478bd9Sstevel@tonic-gate 	uint8_t		ipf_ecn;	/* ECN info for the fragments */
3147c478bd9Sstevel@tonic-gate 	uint8_t		ipf_num_dups;	/* Number of times dup frags recvd */
315ff550d0eSmasputra 	uint16_t	ipf_checksum_flags; /* Hardware checksum flags */
316ff550d0eSmasputra 	uint32_t	ipf_checksum;	/* Partial checksum of fragment data */
3177c478bd9Sstevel@tonic-gate } ipf_t;
3187c478bd9Sstevel@tonic-gate 
319da14cebeSEric Cheng /*
320da14cebeSEric Cheng  * IPv4 Fragments
321da14cebeSEric Cheng  */
322da14cebeSEric Cheng #define	IS_V4_FRAGMENT(ipha_fragment_offset_and_flags)			\
323da14cebeSEric Cheng 	(((ntohs(ipha_fragment_offset_and_flags) & IPH_OFFSET) != 0) ||	\
324da14cebeSEric Cheng 	((ntohs(ipha_fragment_offset_and_flags) & IPH_MF) != 0))
325da14cebeSEric Cheng 
3267c478bd9Sstevel@tonic-gate #define	ipf_src	V4_PART_OF_V6(ipf_v6src)
3277c478bd9Sstevel@tonic-gate #define	ipf_dst	V4_PART_OF_V6(ipf_v6dst)
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate /* ICMP types */
3327c478bd9Sstevel@tonic-gate #define	ICMP_ECHO_REPLY			0
3337c478bd9Sstevel@tonic-gate #define	ICMP_DEST_UNREACHABLE		3
3347c478bd9Sstevel@tonic-gate #define	ICMP_SOURCE_QUENCH		4
3357c478bd9Sstevel@tonic-gate #define	ICMP_REDIRECT			5
3367c478bd9Sstevel@tonic-gate #define	ICMP_ECHO_REQUEST		8
3377c478bd9Sstevel@tonic-gate #define	ICMP_ROUTER_ADVERTISEMENT	9
3387c478bd9Sstevel@tonic-gate #define	ICMP_ROUTER_SOLICITATION	10
3397c478bd9Sstevel@tonic-gate #define	ICMP_TIME_EXCEEDED		11
3407c478bd9Sstevel@tonic-gate #define	ICMP_PARAM_PROBLEM		12
3417c478bd9Sstevel@tonic-gate #define	ICMP_TIME_STAMP_REQUEST		13
3427c478bd9Sstevel@tonic-gate #define	ICMP_TIME_STAMP_REPLY		14
3437c478bd9Sstevel@tonic-gate #define	ICMP_INFO_REQUEST		15
3447c478bd9Sstevel@tonic-gate #define	ICMP_INFO_REPLY			16
3457c478bd9Sstevel@tonic-gate #define	ICMP_ADDRESS_MASK_REQUEST	17
3467c478bd9Sstevel@tonic-gate #define	ICMP_ADDRESS_MASK_REPLY		18
3477c478bd9Sstevel@tonic-gate 
3482b24ab6bSSebastien Roy /* Evaluates to true if the ICMP type is an ICMP error */
3492b24ab6bSSebastien Roy #define	ICMP_IS_ERROR(type)	(		\
3502b24ab6bSSebastien Roy 	(type) == ICMP_DEST_UNREACHABLE ||	\
3512b24ab6bSSebastien Roy 	(type) == ICMP_SOURCE_QUENCH ||		\
3522b24ab6bSSebastien Roy 	(type) == ICMP_TIME_EXCEEDED ||		\
3532b24ab6bSSebastien Roy 	(type) == ICMP_PARAM_PROBLEM)
3542b24ab6bSSebastien Roy 
3557c478bd9Sstevel@tonic-gate /* ICMP_TIME_EXCEEDED codes */
3567c478bd9Sstevel@tonic-gate #define	ICMP_TTL_EXCEEDED		0
3577c478bd9Sstevel@tonic-gate #define	ICMP_REASSEMBLY_TIME_EXCEEDED	1
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate /* ICMP_DEST_UNREACHABLE codes */
3607c478bd9Sstevel@tonic-gate #define	ICMP_NET_UNREACHABLE		0
3617c478bd9Sstevel@tonic-gate #define	ICMP_HOST_UNREACHABLE		1
3627c478bd9Sstevel@tonic-gate #define	ICMP_PROTOCOL_UNREACHABLE	2
3637c478bd9Sstevel@tonic-gate #define	ICMP_PORT_UNREACHABLE		3
3647c478bd9Sstevel@tonic-gate #define	ICMP_FRAGMENTATION_NEEDED	4
3657c478bd9Sstevel@tonic-gate #define	ICMP_SOURCE_ROUTE_FAILED	5
3667c478bd9Sstevel@tonic-gate #define	ICMP_DEST_NET_UNKNOWN		6
3677c478bd9Sstevel@tonic-gate #define	ICMP_DEST_HOST_UNKNOWN		7
3687c478bd9Sstevel@tonic-gate #define	ICMP_SRC_HOST_ISOLATED		8
3697c478bd9Sstevel@tonic-gate #define	ICMP_DEST_NET_UNREACH_ADMIN	9
3707c478bd9Sstevel@tonic-gate #define	ICMP_DEST_HOST_UNREACH_ADMIN	10
3717c478bd9Sstevel@tonic-gate #define	ICMP_DEST_NET_UNREACH_TOS	11
3727c478bd9Sstevel@tonic-gate #define	ICMP_DEST_HOST_UNREACH_TOS	12
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /* ICMP Header Structure */
3757c478bd9Sstevel@tonic-gate typedef struct icmph_s {
3767c478bd9Sstevel@tonic-gate 	uint8_t		icmph_type;
3777c478bd9Sstevel@tonic-gate 	uint8_t		icmph_code;
3787c478bd9Sstevel@tonic-gate 	uint16_t	icmph_checksum;
3797c478bd9Sstevel@tonic-gate 	union {
3807c478bd9Sstevel@tonic-gate 		struct { /* ECHO request/response structure */
3817c478bd9Sstevel@tonic-gate 			uint16_t	u_echo_ident;
3827c478bd9Sstevel@tonic-gate 			uint16_t	u_echo_seqnum;
3837c478bd9Sstevel@tonic-gate 		} u_echo;
3847c478bd9Sstevel@tonic-gate 		struct { /* Destination unreachable structure */
3857c478bd9Sstevel@tonic-gate 			uint16_t	u_du_zero;
3867c478bd9Sstevel@tonic-gate 			uint16_t	u_du_mtu;
3877c478bd9Sstevel@tonic-gate 		} u_du;
3887c478bd9Sstevel@tonic-gate 		struct { /* Parameter problem structure */
3897c478bd9Sstevel@tonic-gate 			uint8_t		u_pp_ptr;
3907c478bd9Sstevel@tonic-gate 			uint8_t		u_pp_rsvd[3];
3917c478bd9Sstevel@tonic-gate 		} u_pp;
3927c478bd9Sstevel@tonic-gate 		struct { /* Redirect structure */
3937c478bd9Sstevel@tonic-gate 			ipaddr_t	u_rd_gateway;
3947c478bd9Sstevel@tonic-gate 		} u_rd;
3957c478bd9Sstevel@tonic-gate 	} icmph_u;
3967c478bd9Sstevel@tonic-gate } icmph_t;
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate #define	icmph_echo_ident	icmph_u.u_echo.u_echo_ident
3997c478bd9Sstevel@tonic-gate #define	icmph_echo_seqnum	icmph_u.u_echo.u_echo_seqnum
4007c478bd9Sstevel@tonic-gate #define	icmph_du_zero		icmph_u.u_du.u_du_zero
4017c478bd9Sstevel@tonic-gate #define	icmph_du_mtu		icmph_u.u_du.u_du_mtu
4027c478bd9Sstevel@tonic-gate #define	icmph_pp_ptr		icmph_u.u_pp.u_pp_ptr
4037c478bd9Sstevel@tonic-gate #define	icmph_rd_gateway	icmph_u.u_rd.u_rd_gateway
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate #define	ICMPH_SIZE	8
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate /*
4087c478bd9Sstevel@tonic-gate  * Minimum length of transport layer header included in an ICMP error
4097c478bd9Sstevel@tonic-gate  * message for it to be considered valid.
4107c478bd9Sstevel@tonic-gate  */
4117c478bd9Sstevel@tonic-gate #define	ICMP_MIN_TP_HDR_LEN	8
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate /* Aligned IP header */
4147c478bd9Sstevel@tonic-gate typedef struct ipha_s {
4157c478bd9Sstevel@tonic-gate 	uint8_t		ipha_version_and_hdr_length;
4167c478bd9Sstevel@tonic-gate 	uint8_t		ipha_type_of_service;
4177c478bd9Sstevel@tonic-gate 	uint16_t	ipha_length;
4187c478bd9Sstevel@tonic-gate 	uint16_t	ipha_ident;
4197c478bd9Sstevel@tonic-gate 	uint16_t	ipha_fragment_offset_and_flags;
4207c478bd9Sstevel@tonic-gate 	uint8_t		ipha_ttl;
4217c478bd9Sstevel@tonic-gate 	uint8_t		ipha_protocol;
4227c478bd9Sstevel@tonic-gate 	uint16_t	ipha_hdr_checksum;
4237c478bd9Sstevel@tonic-gate 	ipaddr_t	ipha_src;
4247c478bd9Sstevel@tonic-gate 	ipaddr_t	ipha_dst;
4257c478bd9Sstevel@tonic-gate } ipha_t;
4267c478bd9Sstevel@tonic-gate 
42710e6dadfSbrendan /*
42810e6dadfSbrendan  * IP Flags
42910e6dadfSbrendan  *
43010e6dadfSbrendan  * Some of these constant names are copied for the DTrace IP provider in
43110e6dadfSbrendan  * usr/src/lib/libdtrace/common/{ip.d.in, ip.sed.in}, which should be kept
43210e6dadfSbrendan  * in sync.
43310e6dadfSbrendan  */
4347c478bd9Sstevel@tonic-gate #define	IPH_DF		0x4000	/* Don't fragment */
4357c478bd9Sstevel@tonic-gate #define	IPH_MF		0x2000	/* More fragments to come */
4367c478bd9Sstevel@tonic-gate #define	IPH_OFFSET	0x1FFF	/* Where the offset lives */
437bd670b35SErik Nordmark 
438bd670b35SErik Nordmark /* Byte-order specific values */
439bd670b35SErik Nordmark #ifdef	_BIG_ENDIAN
440bd670b35SErik Nordmark #define	IPH_DF_HTONS	0x4000	/* Don't fragment */
441bd670b35SErik Nordmark #define	IPH_MF_HTONS	0x2000	/* More fragments to come */
442bd670b35SErik Nordmark #define	IPH_OFFSET_HTONS 0x1FFF	/* Where the offset lives */
443bd670b35SErik Nordmark #else
444bd670b35SErik Nordmark #define	IPH_DF_HTONS	0x0040	/* Don't fragment */
445bd670b35SErik Nordmark #define	IPH_MF_HTONS	0x0020	/* More fragments to come */
446bd670b35SErik Nordmark #define	IPH_OFFSET_HTONS 0xFF1F	/* Where the offset lives */
447bd670b35SErik Nordmark #endif
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /* ECN code points for IPv4 TOS byte and IPv6 traffic class octet. */
4507924222fSmeem #define	IPH_ECN_NECT	0x0	/* Not ECN-Capable Transport */
4517c478bd9Sstevel@tonic-gate #define	IPH_ECN_ECT1	0x1	/* ECN-Capable Transport, ECT(1) */
4527c478bd9Sstevel@tonic-gate #define	IPH_ECN_ECT0	0x2	/* ECN-Capable Transport, ECT(0) */
4537c478bd9Sstevel@tonic-gate #define	IPH_ECN_CE	0x3	/* ECN-Congestion Experienced (CE) */
4547c478bd9Sstevel@tonic-gate 
455e11c3f44Smeem struct ill_s;
456e11c3f44Smeem 
4572b24ab6bSSebastien Roy typedef	void ip_v6intfid_func_t(struct ill_s *, in6_addr_t *);
458bd670b35SErik Nordmark typedef void ip_v6mapinfo_func_t(struct ill_s *, uchar_t *, uchar_t *);
459bd670b35SErik Nordmark typedef void ip_v4mapinfo_func_t(struct ill_s *, uchar_t *, uchar_t *);
460e11c3f44Smeem 
4617c478bd9Sstevel@tonic-gate /* IP Mac info structure */
4627c478bd9Sstevel@tonic-gate typedef struct ip_m_s {
463e11c3f44Smeem 	t_uscalar_t		ip_m_mac_type;	/* From <sys/dlpi.h> */
464e11c3f44Smeem 	int			ip_m_type;	/* From <net/if_types.h> */
4652b24ab6bSSebastien Roy 	t_uscalar_t		ip_m_ipv4sap;
4662b24ab6bSSebastien Roy 	t_uscalar_t		ip_m_ipv6sap;
467bd670b35SErik Nordmark 	ip_v4mapinfo_func_t	*ip_m_v4mapping;
468bd670b35SErik Nordmark 	ip_v6mapinfo_func_t	*ip_m_v6mapping;
469e11c3f44Smeem 	ip_v6intfid_func_t	*ip_m_v6intfid;
4702b24ab6bSSebastien Roy 	ip_v6intfid_func_t	*ip_m_v6destintfid;
4717c478bd9Sstevel@tonic-gate } ip_m_t;
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate /*
4747c478bd9Sstevel@tonic-gate  * The following functions attempt to reduce the link layer dependency
4757c478bd9Sstevel@tonic-gate  * of the IP stack. The current set of link specific operations are:
476bd670b35SErik Nordmark  * a. map from IPv4 class D (224.0/4) multicast address range or the
477bd670b35SErik Nordmark  * IPv6 multicast address range (ff00::/8) to the link layer multicast
478bd670b35SErik Nordmark  * address.
479bd670b35SErik Nordmark  * b. derive the default IPv6 interface identifier from the interface.
480bd670b35SErik Nordmark  * c. derive the default IPv6 destination interface identifier from
481e11c3f44Smeem  * the interface (point-to-point only).
4827c478bd9Sstevel@tonic-gate  */
483bd670b35SErik Nordmark extern	void ip_mcast_mapping(struct ill_s *, uchar_t *, uchar_t *);
4842b24ab6bSSebastien Roy /* ip_m_v6*intfid return void and are never NULL */
4852b24ab6bSSebastien Roy #define	MEDIA_V6INTFID(ip_m, ill, v6ptr) (ip_m)->ip_m_v6intfid(ill, v6ptr)
486e11c3f44Smeem #define	MEDIA_V6DESTINTFID(ip_m, ill, v6ptr) \
4872b24ab6bSSebastien Roy 	(ip_m)->ip_m_v6destintfid(ill, v6ptr)
4887c478bd9Sstevel@tonic-gate 
4897c478bd9Sstevel@tonic-gate /* Router entry types */
4907c478bd9Sstevel@tonic-gate #define	IRE_BROADCAST		0x0001	/* Route entry for broadcast address */
4917c478bd9Sstevel@tonic-gate #define	IRE_DEFAULT		0x0002	/* Route entry for default gateway */
4927c478bd9Sstevel@tonic-gate #define	IRE_LOCAL		0x0004	/* Route entry for local address */
4937c478bd9Sstevel@tonic-gate #define	IRE_LOOPBACK		0x0008	/* Route entry for loopback address */
4947c478bd9Sstevel@tonic-gate #define	IRE_PREFIX		0x0010	/* Route entry for prefix routes */
495bd670b35SErik Nordmark #ifndef _KERNEL
496bd670b35SErik Nordmark /* Keep so user-level still compiles */
4977c478bd9Sstevel@tonic-gate #define	IRE_CACHE		0x0020	/* Cached Route entry */
498bd670b35SErik Nordmark #endif
4997c478bd9Sstevel@tonic-gate #define	IRE_IF_NORESOLVER	0x0040	/* Route entry for local interface */
5007c478bd9Sstevel@tonic-gate 					/* net without any address mapping. */
5017c478bd9Sstevel@tonic-gate #define	IRE_IF_RESOLVER		0x0080	/* Route entry for local interface */
5027c478bd9Sstevel@tonic-gate 					/* net with resolver. */
5037c478bd9Sstevel@tonic-gate #define	IRE_HOST		0x0100	/* Host route entry */
504bd670b35SErik Nordmark /* Keep so user-level still compiles */
5056bdb8e66Sdd #define	IRE_HOST_REDIRECT	0x0200	/* only used for T_SVR4_OPTMGMT_REQ */
506bd670b35SErik Nordmark #define	IRE_IF_CLONE		0x0400	/* Per host clone of IRE_IF */
507bd670b35SErik Nordmark #define	IRE_MULTICAST		0x0800	/* Special - not in table */
508bd670b35SErik Nordmark #define	IRE_NOROUTE		0x1000	/* Special - not in table */
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate #define	IRE_INTERFACE		(IRE_IF_NORESOLVER | IRE_IF_RESOLVER)
51143d18f1cSpriyanka 
512bd670b35SErik Nordmark #define	IRE_IF_ALL		(IRE_IF_NORESOLVER | IRE_IF_RESOLVER | \
513bd670b35SErik Nordmark 				    IRE_IF_CLONE)
514bd670b35SErik Nordmark #define	IRE_OFFSUBNET		(IRE_DEFAULT | IRE_PREFIX | IRE_HOST)
515bd670b35SErik Nordmark #define	IRE_OFFLINK		IRE_OFFSUBNET
516c793af95Ssangeeta /*
517bd670b35SErik Nordmark  * Note that we view IRE_NOROUTE as ONLINK since we can "send" to them without
518bd670b35SErik Nordmark  * going through a router; the result of sending will be an error/icmp error.
519c793af95Ssangeeta  */
520bd670b35SErik Nordmark #define	IRE_ONLINK		(IRE_IF_ALL|IRE_LOCAL|IRE_LOOPBACK| \
521bd670b35SErik Nordmark 				    IRE_BROADCAST|IRE_MULTICAST|IRE_NOROUTE)
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate /* Arguments to ire_flush_cache() */
5247c478bd9Sstevel@tonic-gate #define	IRE_FLUSH_DELETE	0
5257c478bd9Sstevel@tonic-gate #define	IRE_FLUSH_ADD		1
526bd670b35SErik Nordmark #define	IRE_FLUSH_GWCHANGE	2
5277c478bd9Sstevel@tonic-gate 
5289e3469d3SErik Nordmark /*
5299e3469d3SErik Nordmark  * Flags to ire_route_recursive
5309e3469d3SErik Nordmark  */
5319e3469d3SErik Nordmark #define	IRR_NONE		0
5329e3469d3SErik Nordmark #define	IRR_ALLOCATE		1	/* OK to allocate IRE_IF_CLONE */
5339e3469d3SErik Nordmark #define	IRR_INCOMPLETE		2	/* OK to return incomplete chain */
5349e3469d3SErik Nordmark 
5357c478bd9Sstevel@tonic-gate /*
5367c478bd9Sstevel@tonic-gate  * Open/close synchronization flags.
5377c478bd9Sstevel@tonic-gate  * These are kept in a separate field in the conn and the synchronization
5387c478bd9Sstevel@tonic-gate  * depends on the atomic 32 bit access to that field.
5397c478bd9Sstevel@tonic-gate  */
5407c478bd9Sstevel@tonic-gate #define	CONN_CLOSING		0x01	/* ip_close waiting for ip_wsrv */
541bd670b35SErik Nordmark #define	CONN_CONDEMNED		0x02	/* conn is closing, no more refs */
542bd670b35SErik Nordmark #define	CONN_INCIPIENT		0x04	/* conn not yet visible, no refs */
543bd670b35SErik Nordmark #define	CONN_QUIESCED		0x08	/* conn is now quiescent */
544bd670b35SErik Nordmark #define	CONN_UPDATE_ILL		0x10	/* conn_update_ill in progress */
545bd670b35SErik Nordmark 
546bd670b35SErik Nordmark /*
547bd670b35SErik Nordmark  * Flags for dce_flags field. Specifies which information has been set.
548bd670b35SErik Nordmark  * dce_ident is always present, but the other ones are identified by the flags.
5497c478bd9Sstevel@tonic-gate  */
550bd670b35SErik Nordmark #define	DCEF_DEFAULT		0x0001	/* Default DCE - no pmtu or uinfo */
551bd670b35SErik Nordmark #define	DCEF_PMTU		0x0002	/* Different than interface MTU */
552bd670b35SErik Nordmark #define	DCEF_UINFO		0x0004	/* dce_uinfo set */
553bd670b35SErik Nordmark #define	DCEF_TOO_SMALL_PMTU	0x0008	/* Smaller than IPv4/IPv6 MIN */
5547c478bd9Sstevel@tonic-gate 
555bd670b35SErik Nordmark #ifdef _KERNEL
5567c478bd9Sstevel@tonic-gate /*
5577c478bd9Sstevel@tonic-gate  * Extra structures need for per-src-addr filtering (IGMPv3/MLDv2)
5587c478bd9Sstevel@tonic-gate  */
5597c478bd9Sstevel@tonic-gate #define	MAX_FILTER_SIZE	64
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate typedef struct slist_s {
5627c478bd9Sstevel@tonic-gate 	int		sl_numsrc;
5637c478bd9Sstevel@tonic-gate 	in6_addr_t	sl_addr[MAX_FILTER_SIZE];
5647c478bd9Sstevel@tonic-gate } slist_t;
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate /*
5677c478bd9Sstevel@tonic-gate  * Following struct is used to maintain retransmission state for
5687c478bd9Sstevel@tonic-gate  * a multicast group.  One rtx_state_t struct is an in-line field
5697c478bd9Sstevel@tonic-gate  * of the ilm_t struct; the slist_ts in the rtx_state_t struct are
5707c478bd9Sstevel@tonic-gate  * alloc'd as needed.
5717c478bd9Sstevel@tonic-gate  */
5727c478bd9Sstevel@tonic-gate typedef struct rtx_state_s {
5737c478bd9Sstevel@tonic-gate 	uint_t		rtx_timer;	/* retrans timer */
5747c478bd9Sstevel@tonic-gate 	int		rtx_cnt;	/* retrans count */
5757c478bd9Sstevel@tonic-gate 	int		rtx_fmode_cnt;	/* retrans count for fmode change */
5767c478bd9Sstevel@tonic-gate 	slist_t		*rtx_allow;
5777c478bd9Sstevel@tonic-gate 	slist_t		*rtx_block;
5787c478bd9Sstevel@tonic-gate } rtx_state_t;
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate /*
5817c478bd9Sstevel@tonic-gate  * Used to construct list of multicast address records that will be
5827c478bd9Sstevel@tonic-gate  * sent in a single listener report.
5837c478bd9Sstevel@tonic-gate  */
5847c478bd9Sstevel@tonic-gate typedef struct mrec_s {
5857c478bd9Sstevel@tonic-gate 	struct mrec_s	*mrec_next;
5867c478bd9Sstevel@tonic-gate 	uint8_t		mrec_type;
5877c478bd9Sstevel@tonic-gate 	uint8_t		mrec_auxlen;	/* currently unused */
5887c478bd9Sstevel@tonic-gate 	in6_addr_t	mrec_group;
5897c478bd9Sstevel@tonic-gate 	slist_t		mrec_srcs;
5907c478bd9Sstevel@tonic-gate } mrec_t;
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate /* Group membership list per upper conn */
593bd670b35SErik Nordmark 
5947c478bd9Sstevel@tonic-gate /*
595bd670b35SErik Nordmark  * We record the multicast information from the socket option in
596bd670b35SErik Nordmark  * ilg_ifaddr/ilg_ifindex. This allows rejoining the group in the case when
597bd670b35SErik Nordmark  * the ifaddr (or ifindex) disappears and later reappears, potentially on
598bd670b35SErik Nordmark  * a different ill. The IPv6 multicast socket options and ioctls all specify
599bd670b35SErik Nordmark  * the interface using an ifindex. For IPv4 some socket options/ioctls use
600bd670b35SErik Nordmark  * the interface address and others use the index. We record here the method
601bd670b35SErik Nordmark  * that was actually used (and leave the other of ilg_ifaddr or ilg_ifindex)
602bd670b35SErik Nordmark  * at zero so that we can rejoin the way the application intended.
6037c478bd9Sstevel@tonic-gate  *
604bd670b35SErik Nordmark  * We track the ill on which we will or already have joined an ilm using
605bd670b35SErik Nordmark  * ilg_ill. When we have succeeded joining the ilm and have a refhold on it
606bd670b35SErik Nordmark  * then we set ilg_ilm. Thus intentionally there is a window where ilg_ill is
607bd670b35SErik Nordmark  * set and ilg_ilm is not set. This allows clearing ilg_ill as a signal that
608bd670b35SErik Nordmark  * the ill is being unplumbed and the ilm should be discarded.
6097c478bd9Sstevel@tonic-gate  *
6107c478bd9Sstevel@tonic-gate  * ilg records the state of multicast memberships of a socket end point.
6117c478bd9Sstevel@tonic-gate  * ilm records the state of multicast memberships with the driver and is
6127c478bd9Sstevel@tonic-gate  * maintained per interface.
6137c478bd9Sstevel@tonic-gate  *
614bd670b35SErik Nordmark  * The ilg state is protected by conn_ilg_lock.
615bd670b35SErik Nordmark  * The ilg will not be freed until ilg_refcnt drops to zero.
6167c478bd9Sstevel@tonic-gate  */
6177c478bd9Sstevel@tonic-gate typedef struct ilg_s {
618bd670b35SErik Nordmark 	struct ilg_s	*ilg_next;
619bd670b35SErik Nordmark 	struct ilg_s	**ilg_ptpn;
620bd670b35SErik Nordmark 	struct conn_s	*ilg_connp;	/* Back pointer to get lock */
6217c478bd9Sstevel@tonic-gate 	in6_addr_t	ilg_v6group;
622bd670b35SErik Nordmark 	ipaddr_t	ilg_ifaddr;	/* For some IPv4 cases */
623bd670b35SErik Nordmark 	uint_t		ilg_ifindex;	/* IPv6 and some other IPv4 cases */
624bd670b35SErik Nordmark 	struct ill_s	*ilg_ill;	/* Where ilm is joined. No refhold */
625bd670b35SErik Nordmark 	struct ilm_s	*ilg_ilm;	/* With ilm_refhold */
626bd670b35SErik Nordmark 	uint_t		ilg_refcnt;
6277c478bd9Sstevel@tonic-gate 	mcast_record_t	ilg_fmode;	/* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
6287c478bd9Sstevel@tonic-gate 	slist_t		*ilg_filter;
629bd670b35SErik Nordmark 	boolean_t	ilg_condemned;	/* Conceptually deleted */
6307c478bd9Sstevel@tonic-gate } ilg_t;
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate /*
6337924222fSmeem  * Multicast address list entry for ill.
634bd670b35SErik Nordmark  * ilm_ill is used by IPv4 and IPv6
635bd670b35SErik Nordmark  *
636bd670b35SErik Nordmark  * The ilm state (and other multicast state on the ill) is protected by
637bd670b35SErik Nordmark  * ill_mcast_lock. Operations that change state on both an ilg and ilm
638bd670b35SErik Nordmark  * in addition use ill_mcast_serializer to ensure that we can't have
639bd670b35SErik Nordmark  * interleaving between e.g., add and delete operations for the same conn_t,
640f1c454b4SSowmini Varadhan  * group, and ill. The ill_mcast_serializer is also used to ensure that
641f1c454b4SSowmini Varadhan  * multicast group joins do not occur on an interface that is in the process
642f1c454b4SSowmini Varadhan  * of joining an IPMP group.
643f4b3ec61Sdh  *
644f4b3ec61Sdh  * The comment below (and for other netstack_t references) refers
645f4b3ec61Sdh  * to the fact that we only do netstack_hold in particular cases,
646bd670b35SErik Nordmark  * such as the references from open endpoints (ill_t and conn_t's
647f4b3ec61Sdh  * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
648f4b3ec61Sdh  * ire_t's when an ill goes away.
6497c478bd9Sstevel@tonic-gate  */
6507c478bd9Sstevel@tonic-gate typedef struct ilm_s {
6517c478bd9Sstevel@tonic-gate 	in6_addr_t	ilm_v6addr;
6527c478bd9Sstevel@tonic-gate 	int		ilm_refcnt;
6537c478bd9Sstevel@tonic-gate 	uint_t		ilm_timer;	/* IGMP/MLD query resp timer, in msec */
6547c478bd9Sstevel@tonic-gate 	struct ilm_s	*ilm_next;	/* Linked list for each ill */
6557c478bd9Sstevel@tonic-gate 	uint_t		ilm_state;	/* state of the membership */
656bd670b35SErik Nordmark 	struct ill_s	*ilm_ill;	/* Back pointer to ill - ill_ilm_cnt */
6577c478bd9Sstevel@tonic-gate 	zoneid_t	ilm_zoneid;
6587c478bd9Sstevel@tonic-gate 	int		ilm_no_ilg_cnt;	/* number of joins w/ no ilg */
6597c478bd9Sstevel@tonic-gate 	mcast_record_t	ilm_fmode;	/* MODE_IS_INCLUDE/MODE_IS_EXCLUDE */
6607c478bd9Sstevel@tonic-gate 	slist_t		*ilm_filter;	/* source filter list */
6617c478bd9Sstevel@tonic-gate 	slist_t		*ilm_pendsrcs;	/* relevant src addrs for pending req */
6627c478bd9Sstevel@tonic-gate 	rtx_state_t	ilm_rtx;	/* SCR retransmission state */
663bd670b35SErik Nordmark 	ipaddr_t	ilm_ifaddr;	/* For IPv4 netstat */
664f4b3ec61Sdh 	ip_stack_t	*ilm_ipst;	/* Does not have a netstack_hold */
6657c478bd9Sstevel@tonic-gate } ilm_t;
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate #define	ilm_addr	V4_PART_OF_V6(ilm_v6addr)
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate /*
6707c478bd9Sstevel@tonic-gate  * Soft reference to an IPsec SA.
6717c478bd9Sstevel@tonic-gate  *
6727924222fSmeem  * On relative terms, conn's can be persistent (living as long as the
6737c478bd9Sstevel@tonic-gate  * processes which create them), while SA's are ephemeral (dying when
6747c478bd9Sstevel@tonic-gate  * they hit their time-based or byte-based lifetimes).
6757c478bd9Sstevel@tonic-gate  *
6767c478bd9Sstevel@tonic-gate  * We could hold a hard reference to an SA from an ipsec_latch_t,
6777c478bd9Sstevel@tonic-gate  * but this would cause expired SA's to linger for a potentially
6787c478bd9Sstevel@tonic-gate  * unbounded time.
6797c478bd9Sstevel@tonic-gate  *
6807c478bd9Sstevel@tonic-gate  * Instead, we remember the hash bucket number and bucket generation
6817c478bd9Sstevel@tonic-gate  * in addition to the pointer.  The bucket generation is incremented on
6827c478bd9Sstevel@tonic-gate  * each deletion.
6837c478bd9Sstevel@tonic-gate  */
6847c478bd9Sstevel@tonic-gate typedef struct ipsa_ref_s
6857c478bd9Sstevel@tonic-gate {
6867c478bd9Sstevel@tonic-gate 	struct ipsa_s	*ipsr_sa;
6877c478bd9Sstevel@tonic-gate 	struct isaf_s	*ipsr_bucket;
6887c478bd9Sstevel@tonic-gate 	uint64_t	ipsr_gen;
6897c478bd9Sstevel@tonic-gate } ipsa_ref_t;
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate /*
6927c478bd9Sstevel@tonic-gate  * IPsec "latching" state.
6937c478bd9Sstevel@tonic-gate  *
6947c478bd9Sstevel@tonic-gate  * In the presence of IPsec policy, fully-bound conn's bind a connection
6957c478bd9Sstevel@tonic-gate  * to more than just the 5-tuple, but also a specific IPsec action and
6967c478bd9Sstevel@tonic-gate  * identity-pair.
697bd670b35SErik Nordmark  * The identity pair is accessed from both the receive and transmit side
698bd670b35SErik Nordmark  * hence it is maintained in the ipsec_latch_t structure. conn_latch and
699bd670b35SErik Nordmark  * ixa_ipsec_latch points to it.
700bd670b35SErik Nordmark  * The policy and actions are stored in conn_latch_in_policy and
701bd670b35SErik Nordmark  * conn_latch_in_action for the inbound side, and in ixa_ipsec_policy and
702bd670b35SErik Nordmark  * ixa_ipsec_action for the transmit side.
703bd670b35SErik Nordmark  *
704bd670b35SErik Nordmark  * As an optimization, we also cache soft references to IPsec SA's in
705bd670b35SErik Nordmark  * ip_xmit_attr_t so that we can fast-path around most of the work needed for
7067c478bd9Sstevel@tonic-gate  * outbound IPsec SA selection.
7077c478bd9Sstevel@tonic-gate  */
7087c478bd9Sstevel@tonic-gate typedef struct ipsec_latch_s
7097c478bd9Sstevel@tonic-gate {
7107c478bd9Sstevel@tonic-gate 	kmutex_t	ipl_lock;
7117c478bd9Sstevel@tonic-gate 	uint32_t	ipl_refcnt;
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 	struct ipsid_s	*ipl_local_cid;
7147c478bd9Sstevel@tonic-gate 	struct ipsid_s	*ipl_remote_cid;
7157c478bd9Sstevel@tonic-gate 	unsigned int
7167c478bd9Sstevel@tonic-gate 			ipl_ids_latched : 1,
7177c478bd9Sstevel@tonic-gate 
718bd670b35SErik Nordmark 			ipl_pad_to_bit_31 : 31;
7197c478bd9Sstevel@tonic-gate } ipsec_latch_t;
7207c478bd9Sstevel@tonic-gate 
7217c478bd9Sstevel@tonic-gate #define	IPLATCH_REFHOLD(ipl) { \
7227c478bd9Sstevel@tonic-gate 	atomic_add_32(&(ipl)->ipl_refcnt, 1);		\
7237c478bd9Sstevel@tonic-gate 	ASSERT((ipl)->ipl_refcnt != 0);			\
7247c478bd9Sstevel@tonic-gate }
7257c478bd9Sstevel@tonic-gate 
726bd670b35SErik Nordmark #define	IPLATCH_REFRELE(ipl) {				\
7277c478bd9Sstevel@tonic-gate 	ASSERT((ipl)->ipl_refcnt != 0);				\
7287c478bd9Sstevel@tonic-gate 	membar_exit();						\
7297c478bd9Sstevel@tonic-gate 	if (atomic_add_32_nv(&(ipl)->ipl_refcnt, -1) == 0)	\
730bd670b35SErik Nordmark 		iplatch_free(ipl);				\
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate /*
7347c478bd9Sstevel@tonic-gate  * peer identity structure.
7357c478bd9Sstevel@tonic-gate  */
7367c478bd9Sstevel@tonic-gate typedef struct conn_s conn_t;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate /*
7397924222fSmeem  * This is used to match an inbound/outbound datagram with policy.
7407c478bd9Sstevel@tonic-gate  */
7417c478bd9Sstevel@tonic-gate typedef	struct ipsec_selector {
7427c478bd9Sstevel@tonic-gate 	in6_addr_t	ips_local_addr_v6;
7437c478bd9Sstevel@tonic-gate 	in6_addr_t	ips_remote_addr_v6;
7447c478bd9Sstevel@tonic-gate 	uint16_t	ips_local_port;
7457c478bd9Sstevel@tonic-gate 	uint16_t	ips_remote_port;
7467c478bd9Sstevel@tonic-gate 	uint8_t		ips_icmp_type;
7477c478bd9Sstevel@tonic-gate 	uint8_t		ips_icmp_code;
7487c478bd9Sstevel@tonic-gate 	uint8_t		ips_protocol;
7497c478bd9Sstevel@tonic-gate 	uint8_t		ips_isv4 : 1,
7507c478bd9Sstevel@tonic-gate 			ips_is_icmp_inv_acq: 1;
7517c478bd9Sstevel@tonic-gate } ipsec_selector_t;
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate /*
7547c478bd9Sstevel@tonic-gate  * Note that we put v4 addresses in the *first* 32-bit word of the
7557c478bd9Sstevel@tonic-gate  * selector rather than the last to simplify the prefix match/mask code
7567c478bd9Sstevel@tonic-gate  * in spd.c
7577c478bd9Sstevel@tonic-gate  */
7587c478bd9Sstevel@tonic-gate #define	ips_local_addr_v4 ips_local_addr_v6.s6_addr32[0]
7597c478bd9Sstevel@tonic-gate #define	ips_remote_addr_v4 ips_remote_addr_v6.s6_addr32[0]
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate /* Values used in IP by IPSEC Code */
7627c478bd9Sstevel@tonic-gate #define		IPSEC_OUTBOUND		B_TRUE
7637c478bd9Sstevel@tonic-gate #define		IPSEC_INBOUND		B_FALSE
7647c478bd9Sstevel@tonic-gate 
7657c478bd9Sstevel@tonic-gate /*
7667c478bd9Sstevel@tonic-gate  * There are two variants in policy failures. The packet may come in
7677c478bd9Sstevel@tonic-gate  * secure when not needed (IPSEC_POLICY_???_NOT_NEEDED) or it may not
7687c478bd9Sstevel@tonic-gate  * have the desired level of protection (IPSEC_POLICY_MISMATCH).
7697c478bd9Sstevel@tonic-gate  */
7707c478bd9Sstevel@tonic-gate #define	IPSEC_POLICY_NOT_NEEDED		0
7717c478bd9Sstevel@tonic-gate #define	IPSEC_POLICY_MISMATCH		1
7727c478bd9Sstevel@tonic-gate #define	IPSEC_POLICY_AUTH_NOT_NEEDED	2
7737c478bd9Sstevel@tonic-gate #define	IPSEC_POLICY_ENCR_NOT_NEEDED	3
7747c478bd9Sstevel@tonic-gate #define	IPSEC_POLICY_SE_NOT_NEEDED	4
7757c478bd9Sstevel@tonic-gate #define	IPSEC_POLICY_MAX		5	/* Always max + 1. */
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate /*
7787c478bd9Sstevel@tonic-gate  * Check with IPSEC inbound policy if
7797c478bd9Sstevel@tonic-gate  *
7807c478bd9Sstevel@tonic-gate  * 1) per-socket policy is present - indicated by conn_in_enforce_policy.
7817c478bd9Sstevel@tonic-gate  * 2) Or if we have not cached policy on the conn and the global policy is
7827c478bd9Sstevel@tonic-gate  *    non-empty.
7837c478bd9Sstevel@tonic-gate  */
784f4b3ec61Sdh #define	CONN_INBOUND_POLICY_PRESENT(connp, ipss)	\
785f4b3ec61Sdh 	((connp)->conn_in_enforce_policy ||		\
786f4b3ec61Sdh 	(!((connp)->conn_policy_cached) && 		\
787f4b3ec61Sdh 	(ipss)->ipsec_inbound_v4_policy_present))
7887c478bd9Sstevel@tonic-gate 
789f4b3ec61Sdh #define	CONN_INBOUND_POLICY_PRESENT_V6(connp, ipss)	\
790f4b3ec61Sdh 	((connp)->conn_in_enforce_policy ||		\
791f4b3ec61Sdh 	(!(connp)->conn_policy_cached &&		\
792f4b3ec61Sdh 	(ipss)->ipsec_inbound_v6_policy_present))
7937c478bd9Sstevel@tonic-gate 
794f4b3ec61Sdh #define	CONN_OUTBOUND_POLICY_PRESENT(connp, ipss)	\
795f4b3ec61Sdh 	((connp)->conn_out_enforce_policy ||		\
796f4b3ec61Sdh 	(!((connp)->conn_policy_cached) &&		\
797f4b3ec61Sdh 	(ipss)->ipsec_outbound_v4_policy_present))
7987c478bd9Sstevel@tonic-gate 
799f4b3ec61Sdh #define	CONN_OUTBOUND_POLICY_PRESENT_V6(connp, ipss)	\
800f4b3ec61Sdh 	((connp)->conn_out_enforce_policy ||		\
801f4b3ec61Sdh 	(!(connp)->conn_policy_cached &&		\
802f4b3ec61Sdh 	(ipss)->ipsec_outbound_v6_policy_present))
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate /*
8057c478bd9Sstevel@tonic-gate  * Information cached in IRE for upper layer protocol (ULP).
8067c478bd9Sstevel@tonic-gate  */
8077c478bd9Sstevel@tonic-gate typedef struct iulp_s {
8087c478bd9Sstevel@tonic-gate 	boolean_t	iulp_set;	/* Is any metric set? */
8097c478bd9Sstevel@tonic-gate 	uint32_t	iulp_ssthresh;	/* Slow start threshold (TCP). */
8107c478bd9Sstevel@tonic-gate 	clock_t		iulp_rtt;	/* Guestimate in millisecs. */
8117c478bd9Sstevel@tonic-gate 	clock_t		iulp_rtt_sd;	/* Cached value of RTT variance. */
8127c478bd9Sstevel@tonic-gate 	uint32_t	iulp_spipe;	/* Send pipe size. */
8137c478bd9Sstevel@tonic-gate 	uint32_t	iulp_rpipe;	/* Receive pipe size. */
8147c478bd9Sstevel@tonic-gate 	uint32_t	iulp_rtomax;	/* Max round trip timeout. */
8157c478bd9Sstevel@tonic-gate 	uint32_t	iulp_sack;	/* Use SACK option (TCP)? */
816bd670b35SErik Nordmark 	uint32_t	iulp_mtu;	/* Setable with routing sockets */
817bd670b35SErik Nordmark 
8187c478bd9Sstevel@tonic-gate 	uint32_t
8197c478bd9Sstevel@tonic-gate 		iulp_tstamp_ok : 1,	/* Use timestamp option (TCP)? */
8207c478bd9Sstevel@tonic-gate 		iulp_wscale_ok : 1,	/* Use window scale option (TCP)? */
8217c478bd9Sstevel@tonic-gate 		iulp_ecn_ok : 1,	/* Enable ECN (for TCP)? */
8227c478bd9Sstevel@tonic-gate 		iulp_pmtud_ok : 1,	/* Enable PMTUd? */
8237c478bd9Sstevel@tonic-gate 
824bd670b35SErik Nordmark 		/* These three are passed out by ip_set_destination */
825bd670b35SErik Nordmark 		iulp_localnet: 1,	/* IRE_ONLINK */
826bd670b35SErik Nordmark 		iulp_loopback: 1,	/* IRE_LOOPBACK */
827bd670b35SErik Nordmark 		iulp_local: 1,		/* IRE_LOCAL */
8287c478bd9Sstevel@tonic-gate 
829bd670b35SErik Nordmark 		iulp_not_used : 25;
830bd670b35SErik Nordmark } iulp_t;
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate /*
8333344d750Smeem  * The conn drain list structure (idl_t), protected by idl_lock.  Each conn_t
8343344d750Smeem  * inserted in the list points back at this idl_t using conn_idl, and is
8353344d750Smeem  * chained by conn_drain_next and conn_drain_prev, which are also protected by
8363344d750Smeem  * idl_lock.  When flow control is relieved, either ip_wsrv() (STREAMS) or
8373344d750Smeem  * ill_flow_enable() (non-STREAMS) will call conn_drain().
838ae6aa22aSVenugopal Iyer  *
839ae6aa22aSVenugopal Iyer  * The conn drain list, idl_t, itself is part of tx cookie list structure.
840ae6aa22aSVenugopal Iyer  * A tx cookie list points to a blocked Tx ring and contains the list of
841ae6aa22aSVenugopal Iyer  * all conn's that are blocked due to the flow-controlled Tx ring (via
842ae6aa22aSVenugopal Iyer  * the idl drain list). Note that a link can have multiple Tx rings. The
843ae6aa22aSVenugopal Iyer  * drain list will store the conn's blocked due to Tx ring being flow
844ae6aa22aSVenugopal Iyer  * controlled.
8457c478bd9Sstevel@tonic-gate  */
846ae6aa22aSVenugopal Iyer 
847ae6aa22aSVenugopal Iyer typedef uintptr_t ip_mac_tx_cookie_t;
848ae6aa22aSVenugopal Iyer typedef	struct idl_s idl_t;
849ae6aa22aSVenugopal Iyer typedef	struct idl_tx_list_s idl_tx_list_t;
850ae6aa22aSVenugopal Iyer 
851ae6aa22aSVenugopal Iyer struct idl_tx_list_s {
852ae6aa22aSVenugopal Iyer 	ip_mac_tx_cookie_t	txl_cookie;
853ae6aa22aSVenugopal Iyer 	kmutex_t		txl_lock;	/* Lock for this list */
854ae6aa22aSVenugopal Iyer 	idl_t			*txl_drain_list;
855ae6aa22aSVenugopal Iyer 	int			txl_drain_index;
856ae6aa22aSVenugopal Iyer };
857ae6aa22aSVenugopal Iyer 
858ae6aa22aSVenugopal Iyer struct idl_s {
8597c478bd9Sstevel@tonic-gate 	conn_t		*idl_conn;		/* Head of drain list */
8607c478bd9Sstevel@tonic-gate 	kmutex_t	idl_lock;		/* Lock for this list */
861ae6aa22aSVenugopal Iyer 	idl_tx_list_t	*idl_itl;
862ae6aa22aSVenugopal Iyer };
8637c478bd9Sstevel@tonic-gate 
8647c478bd9Sstevel@tonic-gate /*
8657c478bd9Sstevel@tonic-gate  * Interface route structure which holds the necessary information to recreate
866bd670b35SErik Nordmark  * routes that are tied to an interface i.e. have ire_ill set.
867bd670b35SErik Nordmark  *
8687c478bd9Sstevel@tonic-gate  * These routes which were initially created via a routing socket or via the
8697c478bd9Sstevel@tonic-gate  * SIOCADDRT ioctl may be gateway routes (RTF_GATEWAY being set) or may be
870bd670b35SErik Nordmark  * traditional interface routes.  When an ill comes back up after being
871bd670b35SErik Nordmark  * down, this information will be used to recreate the routes.  These
872bd670b35SErik Nordmark  * are part of an mblk_t chain that hangs off of the ILL (ill_saved_ire_mp).
8737c478bd9Sstevel@tonic-gate  */
8747c478bd9Sstevel@tonic-gate typedef struct ifrt_s {
8757c478bd9Sstevel@tonic-gate 	ushort_t	ifrt_type;		/* Type of IRE */
8767c478bd9Sstevel@tonic-gate 	in6_addr_t	ifrt_v6addr;		/* Address IRE represents. */
877bd670b35SErik Nordmark 	in6_addr_t	ifrt_v6gateway_addr;	/* Gateway if IRE_OFFLINK */
878bd670b35SErik Nordmark 	in6_addr_t	ifrt_v6setsrc_addr;	/* Src addr if RTF_SETSRC */
8797c478bd9Sstevel@tonic-gate 	in6_addr_t	ifrt_v6mask;		/* Mask for matching IRE. */
8807c478bd9Sstevel@tonic-gate 	uint32_t	ifrt_flags;		/* flags related to route */
881bd670b35SErik Nordmark 	iulp_t		ifrt_metrics;		/* Routing socket metrics */
882bd670b35SErik Nordmark 	zoneid_t	ifrt_zoneid;		/* zoneid for route */
8837c478bd9Sstevel@tonic-gate } ifrt_t;
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate #define	ifrt_addr		V4_PART_OF_V6(ifrt_v6addr)
8867c478bd9Sstevel@tonic-gate #define	ifrt_gateway_addr	V4_PART_OF_V6(ifrt_v6gateway_addr)
8877c478bd9Sstevel@tonic-gate #define	ifrt_mask		V4_PART_OF_V6(ifrt_v6mask)
888bd670b35SErik Nordmark #define	ifrt_setsrc_addr	V4_PART_OF_V6(ifrt_v6setsrc_addr)
8897c478bd9Sstevel@tonic-gate 
8907c478bd9Sstevel@tonic-gate /* Number of IP addresses that can be hosted on a physical interface */
8917c478bd9Sstevel@tonic-gate #define	MAX_ADDRS_PER_IF	8192
8927c478bd9Sstevel@tonic-gate /*
8937c478bd9Sstevel@tonic-gate  * Number of Source addresses to be considered for source address
894bd670b35SErik Nordmark  * selection. Used by ipif_select_source_v4/v6.
8957c478bd9Sstevel@tonic-gate  */
8967c478bd9Sstevel@tonic-gate #define	MAX_IPIF_SELECT_SOURCE	50
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate #ifdef IP_DEBUG
8997c478bd9Sstevel@tonic-gate /*
9007924222fSmeem  * Trace refholds and refreles for debugging.
9017c478bd9Sstevel@tonic-gate  */
9026a8288c7Scarlsonj #define	TR_STACK_DEPTH	14
9037c478bd9Sstevel@tonic-gate typedef struct tr_buf_s {
9047c478bd9Sstevel@tonic-gate 	int	tr_depth;
9056a8288c7Scarlsonj 	clock_t	tr_time;
9066a8288c7Scarlsonj 	pc_t	tr_stack[TR_STACK_DEPTH];
9077c478bd9Sstevel@tonic-gate } tr_buf_t;
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate typedef struct th_trace_s {
9106a8288c7Scarlsonj 	int		th_refcnt;
9116a8288c7Scarlsonj 	uint_t		th_trace_lastref;
9127c478bd9Sstevel@tonic-gate 	kthread_t	*th_id;
9137c478bd9Sstevel@tonic-gate #define	TR_BUF_MAX	38
9146a8288c7Scarlsonj 	tr_buf_t	th_trbuf[TR_BUF_MAX];
9157c478bd9Sstevel@tonic-gate } th_trace_t;
9166a8288c7Scarlsonj 
9176a8288c7Scarlsonj typedef struct th_hash_s {
9186a8288c7Scarlsonj 	list_node_t	thh_link;
9196a8288c7Scarlsonj 	mod_hash_t	*thh_hash;
9206a8288c7Scarlsonj 	ip_stack_t	*thh_ipst;
9216a8288c7Scarlsonj } th_hash_t;
9227c478bd9Sstevel@tonic-gate #endif
9237c478bd9Sstevel@tonic-gate 
9247c478bd9Sstevel@tonic-gate /* The following are ipif_state_flags */
9257c478bd9Sstevel@tonic-gate #define	IPIF_CONDEMNED		0x1	/* The ipif is being removed */
9267c478bd9Sstevel@tonic-gate #define	IPIF_CHANGING		0x2	/* A critcal ipif field is changing */
9277c478bd9Sstevel@tonic-gate #define	IPIF_SET_LINKLOCAL	0x10	/* transient flag during bringup */
9287c478bd9Sstevel@tonic-gate 
9297c478bd9Sstevel@tonic-gate /* IP interface structure, one per local address */
9307c478bd9Sstevel@tonic-gate typedef struct ipif_s {
9317c478bd9Sstevel@tonic-gate 	struct	ipif_s	*ipif_next;
9327c478bd9Sstevel@tonic-gate 	struct	ill_s	*ipif_ill;	/* Back pointer to our ill */
9337c478bd9Sstevel@tonic-gate 	int	ipif_id;		/* Logical unit number */
9347c478bd9Sstevel@tonic-gate 	in6_addr_t ipif_v6lcl_addr;	/* Local IP address for this if. */
9357c478bd9Sstevel@tonic-gate 	in6_addr_t ipif_v6subnet;	/* Subnet prefix for this if. */
9367c478bd9Sstevel@tonic-gate 	in6_addr_t ipif_v6net_mask;	/* Net mask for this interface. */
9377c478bd9Sstevel@tonic-gate 	in6_addr_t ipif_v6brd_addr;	/* Broadcast addr for this interface. */
9387c478bd9Sstevel@tonic-gate 	in6_addr_t ipif_v6pp_dst_addr;	/* Point-to-point dest address. */
9397c478bd9Sstevel@tonic-gate 	uint64_t ipif_flags;		/* Interface flags. */
9407c478bd9Sstevel@tonic-gate 	uint_t	ipif_ire_type;		/* IRE_LOCAL or IRE_LOOPBACK */
9417c478bd9Sstevel@tonic-gate 
9427c478bd9Sstevel@tonic-gate 	/*
943bd670b35SErik Nordmark 	 * The packet count in the ipif contain the sum of the
944bd670b35SErik Nordmark 	 * packet counts in dead IRE_LOCAL/LOOPBACK for this ipif.
9457c478bd9Sstevel@tonic-gate 	 */
9467c478bd9Sstevel@tonic-gate 	uint_t	ipif_ib_pkt_count;	/* Inbound packets for our dead IREs */
947bd670b35SErik Nordmark 
9487c478bd9Sstevel@tonic-gate 	/* Exclusive bit fields, protected by ipsq_t */
9497c478bd9Sstevel@tonic-gate 	unsigned int
9507c478bd9Sstevel@tonic-gate 		ipif_was_up : 1,	/* ipif was up before */
95169bb4bb4Scarlsonj 		ipif_addr_ready : 1,	/* DAD is done */
95269bb4bb4Scarlsonj 		ipif_was_dup : 1,	/* DAD had failed */
9533efde6d0SSowmini Varadhan 		ipif_added_nce : 1,	/* nce added for local address */
954bd670b35SErik Nordmark 
955bd670b35SErik Nordmark 		ipif_pad_to_31 : 28;
956bd670b35SErik Nordmark 
957bd670b35SErik Nordmark 	ilm_t	*ipif_allhosts_ilm;	/* For all-nodes join */
958bd670b35SErik Nordmark 	ilm_t	*ipif_solmulti_ilm;	/* For IPv6 solicited multicast join */
9597c478bd9Sstevel@tonic-gate 
9607c478bd9Sstevel@tonic-gate 	uint_t	ipif_seqid;		/* unique index across all ills */
9617c478bd9Sstevel@tonic-gate 	uint_t	ipif_state_flags;	/* See IPIF_* flag defs above */
9627c478bd9Sstevel@tonic-gate 	uint_t	ipif_refcnt;		/* active consistent reader cnt */
963968d2fd1Ssowmini 
964968d2fd1Ssowmini 	zoneid_t ipif_zoneid;		/* zone ID number */
96569bb4bb4Scarlsonj 	timeout_id_t ipif_recovery_id;	/* Timer for DAD recovery */
9666a8288c7Scarlsonj 	boolean_t ipif_trace_disable;	/* True when alloc fails */
967e11c3f44Smeem 	/*
968e11c3f44Smeem 	 * For an IPMP interface, ipif_bound_ill tracks the ill whose hardware
969e11c3f44Smeem 	 * information this ipif is associated with via ARP/NDP.  We can use
970e11c3f44Smeem 	 * an ill pointer (rather than an index) because only ills that are
971e11c3f44Smeem 	 * part of a group will be pointed to, and an ill cannot disappear
972e11c3f44Smeem 	 * while it's in a group.
973e11c3f44Smeem 	 */
974bd670b35SErik Nordmark 	struct ill_s    *ipif_bound_ill;
975bd670b35SErik Nordmark 	struct ipif_s   *ipif_bound_next; /* bound ipif chain */
976bd670b35SErik Nordmark 	boolean_t	ipif_bound;	/* B_TRUE if we successfully bound */
9777c478bd9Sstevel@tonic-gate 
978bd670b35SErik Nordmark 	struct ire_s	*ipif_ire_local; /* Our IRE_LOCAL or LOOPBACK */
9790e0e37a8SErik Nordmark 	struct ire_s	*ipif_ire_if;	 /* Our IRE_INTERFACE */
980bd670b35SErik Nordmark } ipif_t;
981968d2fd1Ssowmini 
9827c478bd9Sstevel@tonic-gate /*
9837c478bd9Sstevel@tonic-gate  * The following table lists the protection levels of the various members
9847c478bd9Sstevel@tonic-gate  * of the ipif_t. The following notation is used.
9857c478bd9Sstevel@tonic-gate  *
9867c478bd9Sstevel@tonic-gate  * Write once - Written to only once at the time of bringing up
9877c478bd9Sstevel@tonic-gate  * the interface and can be safely read after the bringup without any lock.
9887c478bd9Sstevel@tonic-gate  *
9897c478bd9Sstevel@tonic-gate  * ipsq - Need to execute in the ipsq to perform the indicated access.
9907c478bd9Sstevel@tonic-gate  *
9917c478bd9Sstevel@tonic-gate  * ill_lock - Need to hold this mutex to perform the indicated access.
9927c478bd9Sstevel@tonic-gate  *
9937c478bd9Sstevel@tonic-gate  * ill_g_lock - Need to hold this rw lock as reader/writer for read access or
9947c478bd9Sstevel@tonic-gate  * write access respectively.
9957c478bd9Sstevel@tonic-gate  *
9967c478bd9Sstevel@tonic-gate  * down ill - Written to only when the ill is down (i.e all ipifs are down)
9977c478bd9Sstevel@tonic-gate  * up ill - Read only when the ill is up (i.e. at least 1 ipif is up)
9987c478bd9Sstevel@tonic-gate  *
9997c478bd9Sstevel@tonic-gate  *		 Table of ipif_t members and their protection
10007c478bd9Sstevel@tonic-gate  *
10018df01f76Smeem  * ipif_next		ipsq + ill_lock +	ipsq OR ill_lock OR
10028df01f76Smeem  *			ill_g_lock		ill_g_lock
1003b051ecf6Smeem  * ipif_ill		ipsq + down ipif	write once
1004b051ecf6Smeem  * ipif_id		ipsq + down ipif	write once
1005b051ecf6Smeem  * ipif_v6lcl_addr	ipsq + down ipif	up ipif
1006b051ecf6Smeem  * ipif_v6subnet	ipsq + down ipif	up ipif
1007b051ecf6Smeem  * ipif_v6net_mask	ipsq + down ipif	up ipif
10087c478bd9Sstevel@tonic-gate  *
10097c478bd9Sstevel@tonic-gate  * ipif_v6brd_addr
10107c478bd9Sstevel@tonic-gate  * ipif_v6pp_dst_addr
10117c478bd9Sstevel@tonic-gate  * ipif_flags		ill_lock		ill_lock
10127c478bd9Sstevel@tonic-gate  * ipif_ire_type	ipsq + down ill		up ill
10137c478bd9Sstevel@tonic-gate  *
10147c478bd9Sstevel@tonic-gate  * ipif_ib_pkt_count	Approx
10157c478bd9Sstevel@tonic-gate  *
10167c478bd9Sstevel@tonic-gate  * bit fields		ill_lock		ill_lock
10177c478bd9Sstevel@tonic-gate  *
1018bd670b35SErik Nordmark  * ipif_allhosts_ilm	ipsq			ipsq
1019bd670b35SErik Nordmark  * ipif_solmulti_ilm	ipsq			ipsq
1020bd670b35SErik Nordmark  *
10217c478bd9Sstevel@tonic-gate  * ipif_seqid		ipsq			Write once
10227c478bd9Sstevel@tonic-gate  *
10237c478bd9Sstevel@tonic-gate  * ipif_state_flags	ill_lock		ill_lock
10247c478bd9Sstevel@tonic-gate  * ipif_refcnt		ill_lock		ill_lock
1025e11c3f44Smeem  * ipif_bound_ill	ipsq + ipmp_lock	ipsq OR ipmp_lock
1026e11c3f44Smeem  * ipif_bound_next	ipsq			ipsq
1027e11c3f44Smeem  * ipif_bound		ipsq			ipsq
1028bd670b35SErik Nordmark  *
1029bd670b35SErik Nordmark  * ipif_ire_local	ipsq + ips_ill_g_lock	ipsq OR ips_ill_g_lock
10300e0e37a8SErik Nordmark  * ipif_ire_if		ipsq + ips_ill_g_lock	ipsq OR ips_ill_g_lock
1031bd670b35SErik Nordmark  */
1032bd670b35SErik Nordmark 
1033bd670b35SErik Nordmark /*
1034bd670b35SErik Nordmark  * Return values from ip_laddr_verify_{v4,v6}
10357c478bd9Sstevel@tonic-gate  */
1036bd670b35SErik Nordmark typedef enum { IPVL_UNICAST_UP, IPVL_UNICAST_DOWN, IPVL_MCAST, IPVL_BCAST,
1037bd670b35SErik Nordmark 	    IPVL_BAD} ip_laddr_t;
1038bd670b35SErik Nordmark 
10397c478bd9Sstevel@tonic-gate 
10407c478bd9Sstevel@tonic-gate #define	IP_TR_HASH(tid)	((((uintptr_t)tid) >> 6) & (IP_TR_HASH_MAX - 1))
10417c478bd9Sstevel@tonic-gate 
10426a8288c7Scarlsonj #ifdef DEBUG
10437c478bd9Sstevel@tonic-gate #define	IPIF_TRACE_REF(ipif)	ipif_trace_ref(ipif)
10447c478bd9Sstevel@tonic-gate #define	ILL_TRACE_REF(ill)	ill_trace_ref(ill)
10457c478bd9Sstevel@tonic-gate #define	IPIF_UNTRACE_REF(ipif)	ipif_untrace_ref(ipif)
10467c478bd9Sstevel@tonic-gate #define	ILL_UNTRACE_REF(ill)	ill_untrace_ref(ill)
10477c478bd9Sstevel@tonic-gate #else
10487c478bd9Sstevel@tonic-gate #define	IPIF_TRACE_REF(ipif)
10497c478bd9Sstevel@tonic-gate #define	ILL_TRACE_REF(ill)
10507c478bd9Sstevel@tonic-gate #define	IPIF_UNTRACE_REF(ipif)
10517c478bd9Sstevel@tonic-gate #define	ILL_UNTRACE_REF(ill)
10527c478bd9Sstevel@tonic-gate #endif
10537c478bd9Sstevel@tonic-gate 
10547924222fSmeem /* IPv4 compatibility macros */
10557c478bd9Sstevel@tonic-gate #define	ipif_lcl_addr		V4_PART_OF_V6(ipif_v6lcl_addr)
10567c478bd9Sstevel@tonic-gate #define	ipif_subnet		V4_PART_OF_V6(ipif_v6subnet)
10577c478bd9Sstevel@tonic-gate #define	ipif_net_mask		V4_PART_OF_V6(ipif_v6net_mask)
10587c478bd9Sstevel@tonic-gate #define	ipif_brd_addr		V4_PART_OF_V6(ipif_v6brd_addr)
10597c478bd9Sstevel@tonic-gate #define	ipif_pp_dst_addr	V4_PART_OF_V6(ipif_v6pp_dst_addr)
10607c478bd9Sstevel@tonic-gate 
10617c478bd9Sstevel@tonic-gate /* Macros for easy backreferences to the ill. */
10627c478bd9Sstevel@tonic-gate #define	ipif_isv6		ipif_ill->ill_isv6
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate #define	SIOCLIFADDR_NDX 112	/* ndx of SIOCLIFADDR in the ndx ioctl table */
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate /*
10677c478bd9Sstevel@tonic-gate  * mode value for ip_ioctl_finish for finishing an ioctl
10687c478bd9Sstevel@tonic-gate  */
10697c478bd9Sstevel@tonic-gate #define	CONN_CLOSE	1		/* No mi_copy */
10707c478bd9Sstevel@tonic-gate #define	COPYOUT		2		/* do an mi_copyout if needed */
10717c478bd9Sstevel@tonic-gate #define	NO_COPYOUT	3		/* do an mi_copy_done */
1072b051ecf6Smeem #define	IPI2MODE(ipi)	((ipi)->ipi_flags & IPI_GET_CMD ? COPYOUT : NO_COPYOUT)
10737c478bd9Sstevel@tonic-gate 
10747c478bd9Sstevel@tonic-gate /*
1075e11c3f44Smeem  * The IP-MT design revolves around the serialization objects ipsq_t (IPSQ)
1076e11c3f44Smeem  * and ipxop_t (exclusive operation or "xop").  Becoming "writer" on an IPSQ
1077e11c3f44Smeem  * ensures that no other threads can become "writer" on any IPSQs sharing that
1078e11c3f44Smeem  * IPSQ's xop until the writer thread is done.
1079e11c3f44Smeem  *
1080e11c3f44Smeem  * Each phyint points to one IPSQ that remains fixed over the phyint's life.
1081e11c3f44Smeem  * Each IPSQ points to one xop that can change over the IPSQ's life.  If a
1082e11c3f44Smeem  * phyint is *not* in an IPMP group, then its IPSQ will refer to the IPSQ's
1083e11c3f44Smeem  * "own" xop (ipsq_ownxop).  If a phyint *is* part of an IPMP group, then its
1084e11c3f44Smeem  * IPSQ will refer to the "group" xop, which is shorthand for the xop of the
1085e11c3f44Smeem  * IPSQ of the IPMP meta-interface's phyint.  Thus, all phyints that are part
1086e11c3f44Smeem  * of the same IPMP group will have their IPSQ's point to the group xop, and
1087e11c3f44Smeem  * thus becoming "writer" on any phyint in the group will prevent any other
1088e11c3f44Smeem  * writer on any other phyint in the group.  All IPSQs sharing the same xop
1089e11c3f44Smeem  * are chained together through ipsq_next (in the degenerate common case,
1090e11c3f44Smeem  * ipsq_next simply refers to itself).  Note that the group xop is guaranteed
1091e11c3f44Smeem  * to exist at least as long as there are members in the group, since the IPMP
1092e11c3f44Smeem  * meta-interface can only be destroyed if the group is empty.
1093e11c3f44Smeem  *
1094e11c3f44Smeem  * Incoming exclusive operation requests are enqueued on the IPSQ they arrived
1095e11c3f44Smeem  * on rather than the xop.  This makes switching xop's (as would happen when a
1096e11c3f44Smeem  * phyint leaves an IPMP group) simple, because after the phyint leaves the
1097e11c3f44Smeem  * group, any operations enqueued on its IPSQ can be safely processed with
1098e11c3f44Smeem  * respect to its new xop, and any operations enqueued on the IPSQs of its
1099e11c3f44Smeem  * former group can be processed with respect to their existing group xop.
1100e11c3f44Smeem  * Even so, switching xops is a subtle dance; see ipsq_dq() for details.
1101e11c3f44Smeem  *
1102e11c3f44Smeem  * An IPSQ's "own" xop is embedded within the IPSQ itself since they have have
1103e11c3f44Smeem  * identical lifetimes, and because doing so simplifies pointer management.
1104e11c3f44Smeem  * While each phyint and IPSQ point to each other, it is not possible to free
1105e11c3f44Smeem  * the IPSQ when the phyint is freed, since we may still *inside* the IPSQ
1106e11c3f44Smeem  * when the phyint is being freed.  Thus, ipsq_phyint is set to NULL when the
1107e11c3f44Smeem  * phyint is freed, and the IPSQ free is later done in ipsq_exit().
1108e11c3f44Smeem  *
1109e11c3f44Smeem  * ipsq_t synchronization:	read			write
1110e11c3f44Smeem  *
1111e11c3f44Smeem  *	ipsq_xopq_mphead	ipx_lock		ipx_lock
1112e11c3f44Smeem  *	ipsq_xopq_mptail	ipx_lock		ipx_lock
1113e11c3f44Smeem  *	ipsq_xop_switch_mp	ipsq_lock		ipsq_lock
1114e11c3f44Smeem  *	ipsq_phyint		write once		write once
1115e11c3f44Smeem  *	ipsq_next		RW_READER ill_g_lock	RW_WRITER ill_g_lock
1116e11c3f44Smeem  *	ipsq_xop 		ipsq_lock or ipsq	ipsq_lock + ipsq
1117e11c3f44Smeem  *	ipsq_swxop		ipsq			ipsq
1118e11c3f44Smeem  * 	ipsq_ownxop		see ipxop_t		see ipxop_t
1119e11c3f44Smeem  *	ipsq_ipst		write once		write once
1120e11c3f44Smeem  *
1121e11c3f44Smeem  * ipxop_t synchronization:     read			write
1122e11c3f44Smeem  *
1123e11c3f44Smeem  *	ipx_writer  		ipx_lock		ipx_lock
1124e11c3f44Smeem  *	ipx_xop_queued		ipx_lock 		ipx_lock
1125e11c3f44Smeem  *	ipx_mphead		ipx_lock		ipx_lock
1126e11c3f44Smeem  *	ipx_mptail		ipx_lock		ipx_lock
1127e11c3f44Smeem  *	ipx_ipsq		write once		write once
1128e11c3f44Smeem  *	ips_ipsq_queued		ipx_lock		ipx_lock
1129e11c3f44Smeem  *	ipx_waitfor		ipsq or ipx_lock	ipsq + ipx_lock
1130e11c3f44Smeem  *	ipx_reentry_cnt		ipsq or ipx_lock	ipsq + ipx_lock
1131e11c3f44Smeem  *	ipx_current_done	ipsq			ipsq
1132e11c3f44Smeem  *	ipx_current_ioctl	ipsq			ipsq
1133e11c3f44Smeem  *	ipx_current_ipif	ipsq or ipx_lock	ipsq + ipx_lock
1134e11c3f44Smeem  *	ipx_pending_ipif	ipsq or ipx_lock	ipsq + ipx_lock
1135e11c3f44Smeem  *	ipx_pending_mp		ipsq or ipx_lock	ipsq + ipx_lock
1136e11c3f44Smeem  *	ipx_forced		ipsq			ipsq
1137e11c3f44Smeem  *	ipx_depth		ipsq			ipsq
1138e11c3f44Smeem  *	ipx_stack		ipsq			ipsq
1139e11c3f44Smeem  */
1140e11c3f44Smeem typedef struct ipxop_s {
1141e11c3f44Smeem 	kmutex_t	ipx_lock;	/* see above */
1142e11c3f44Smeem 	kthread_t	*ipx_writer;  	/* current owner */
1143e11c3f44Smeem 	mblk_t		*ipx_mphead;	/* messages tied to this op */
1144e11c3f44Smeem 	mblk_t		*ipx_mptail;
1145e11c3f44Smeem 	struct ipsq_s	*ipx_ipsq;	/* associated ipsq */
1146e11c3f44Smeem 	boolean_t	ipx_ipsq_queued; /* ipsq using xop has queued op */
1147e11c3f44Smeem 	int		ipx_waitfor;	/* waiting; values encoded below */
1148e11c3f44Smeem 	int		ipx_reentry_cnt;
1149e11c3f44Smeem 	boolean_t	ipx_current_done;  /* is the current operation done? */
1150e11c3f44Smeem 	int		ipx_current_ioctl; /* current ioctl, or 0 if no ioctl */
1151e11c3f44Smeem 	ipif_t		*ipx_current_ipif; /* ipif for current op */
1152bd670b35SErik Nordmark 	ipif_t		*ipx_pending_ipif; /* ipif for ipx_pending_mp */
1153e11c3f44Smeem 	mblk_t 		*ipx_pending_mp;   /* current ioctl mp while waiting */
1154e11c3f44Smeem 	boolean_t	ipx_forced; 			/* debugging aid */
11556a8288c7Scarlsonj #ifdef DEBUG
1156e11c3f44Smeem 	int		ipx_depth;			/* debugging aid */
1157e11c3f44Smeem #define	IPX_STACK_DEPTH	15
1158e11c3f44Smeem 	pc_t		ipx_stack[IPX_STACK_DEPTH];	/* debugging aid */
11597c478bd9Sstevel@tonic-gate #endif
1160e11c3f44Smeem } ipxop_t;
11617c478bd9Sstevel@tonic-gate 
1162e11c3f44Smeem typedef struct ipsq_s {
1163e11c3f44Smeem 	kmutex_t ipsq_lock;		/* see above */
1164e11c3f44Smeem 	mblk_t	*ipsq_switch_mp;	/* op to handle right after switch */
1165e11c3f44Smeem 	mblk_t	*ipsq_xopq_mphead;	/* list of excl ops (mostly ioctls) */
1166e11c3f44Smeem 	mblk_t	*ipsq_xopq_mptail;
1167e11c3f44Smeem 	struct phyint	*ipsq_phyint;	/* associated phyint */
1168e11c3f44Smeem 	struct ipsq_s	*ipsq_next;	/* next ipsq sharing ipsq_xop */
1169e11c3f44Smeem 	struct ipxop_s	*ipsq_xop;	/* current xop synchronization info */
1170e11c3f44Smeem 	struct ipxop_s	*ipsq_swxop;	/* switch xop to on ipsq_exit() */
1171e11c3f44Smeem 	struct ipxop_s	ipsq_ownxop;	/* our own xop (may not be in-use) */
1172e11c3f44Smeem 	ip_stack_t	*ipsq_ipst;	/* does not have a netstack_hold */
1173e11c3f44Smeem } ipsq_t;
11747c478bd9Sstevel@tonic-gate 
11757c478bd9Sstevel@tonic-gate /*
1176e11c3f44Smeem  * ipx_waitfor values:
11777c478bd9Sstevel@tonic-gate  */
1178e11c3f44Smeem enum {
1179e11c3f44Smeem 	IPIF_DOWN = 1,	/* ipif_down() waiting for refcnts to drop */
1180e11c3f44Smeem 	ILL_DOWN,	/* ill_down() waiting for refcnts to drop */
1181e11c3f44Smeem 	IPIF_FREE,	/* ipif_free() waiting for refcnts to drop */
1182e11c3f44Smeem 	ILL_FREE	/* ill unplumb waiting for refcnts to drop */
1183e11c3f44Smeem };
11847c478bd9Sstevel@tonic-gate 
1185e11c3f44Smeem /* Operation types for ipsq_try_enter() */
1186e11c3f44Smeem #define	CUR_OP 0	/* request writer within current operation */
1187e11c3f44Smeem #define	NEW_OP 1	/* request writer for a new operation */
1188e11c3f44Smeem #define	SWITCH_OP 2	/* request writer once IPSQ XOP switches */
11897c478bd9Sstevel@tonic-gate 
1190e11c3f44Smeem /*
1191e11c3f44Smeem  * Kstats tracked on each IPMP meta-interface.  Order here must match
1192e11c3f44Smeem  * ipmp_kstats[] in ip/ipmp.c.
1193e11c3f44Smeem  */
1194e11c3f44Smeem enum {
1195e11c3f44Smeem 	IPMP_KSTAT_OBYTES,	IPMP_KSTAT_OBYTES64,	IPMP_KSTAT_RBYTES,
1196e11c3f44Smeem 	IPMP_KSTAT_RBYTES64,	IPMP_KSTAT_OPACKETS,	IPMP_KSTAT_OPACKETS64,
1197e11c3f44Smeem 	IPMP_KSTAT_OERRORS,	IPMP_KSTAT_IPACKETS,	IPMP_KSTAT_IPACKETS64,
1198e11c3f44Smeem 	IPMP_KSTAT_IERRORS,	IPMP_KSTAT_MULTIRCV,	IPMP_KSTAT_MULTIXMT,
1199e11c3f44Smeem 	IPMP_KSTAT_BRDCSTRCV,	IPMP_KSTAT_BRDCSTXMT,	IPMP_KSTAT_LINK_UP,
1200e11c3f44Smeem 	IPMP_KSTAT_MAX		/* keep last */
1201e11c3f44Smeem };
12027c478bd9Sstevel@tonic-gate 
12037c478bd9Sstevel@tonic-gate /*
12047c478bd9Sstevel@tonic-gate  * phyint represents state that is common to both IPv4 and IPv6 interfaces.
12057c478bd9Sstevel@tonic-gate  * There is a separate ill_t representing IPv4 and IPv6 which has a
12067924222fSmeem  * backpointer to the phyint structure for accessing common state.
12077c478bd9Sstevel@tonic-gate  */
12087c478bd9Sstevel@tonic-gate typedef struct phyint {
12097c478bd9Sstevel@tonic-gate 	struct ill_s	*phyint_illv4;
12107c478bd9Sstevel@tonic-gate 	struct ill_s	*phyint_illv6;
1211e11c3f44Smeem 	uint_t		phyint_ifindex;		/* SIOCSLIFINDEX */
12127c478bd9Sstevel@tonic-gate 	uint64_t	phyint_flags;
12137c478bd9Sstevel@tonic-gate 	avl_node_t	phyint_avl_by_index;	/* avl tree by index */
12147c478bd9Sstevel@tonic-gate 	avl_node_t	phyint_avl_by_name;	/* avl tree by name */
12157c478bd9Sstevel@tonic-gate 	kmutex_t	phyint_lock;
12167c478bd9Sstevel@tonic-gate 	struct ipsq_s	*phyint_ipsq;		/* back pointer to ipsq */
1217e11c3f44Smeem 	struct ipmp_grp_s *phyint_grp;		/* associated IPMP group */
1218e11c3f44Smeem 	char		phyint_name[LIFNAMSIZ];	/* physical interface name */
1219e11c3f44Smeem 	uint64_t	phyint_kstats0[IPMP_KSTAT_MAX];	/* baseline kstats */
12207c478bd9Sstevel@tonic-gate } phyint_t;
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate #define	CACHE_ALIGN_SIZE 64
12237c478bd9Sstevel@tonic-gate #define	CACHE_ALIGN(align_struct)	P2ROUNDUP(sizeof (struct align_struct),\
12247c478bd9Sstevel@tonic-gate 							CACHE_ALIGN_SIZE)
12257c478bd9Sstevel@tonic-gate struct _phyint_list_s_ {
12267c478bd9Sstevel@tonic-gate 	avl_tree_t	phyint_list_avl_by_index;	/* avl tree by index */
12277c478bd9Sstevel@tonic-gate 	avl_tree_t	phyint_list_avl_by_name;	/* avl tree by name */
12287c478bd9Sstevel@tonic-gate };
12297c478bd9Sstevel@tonic-gate 
12307c478bd9Sstevel@tonic-gate typedef union phyint_list_u {
12317c478bd9Sstevel@tonic-gate 	struct	_phyint_list_s_ phyint_list_s;
12327c478bd9Sstevel@tonic-gate 	char	phyint_list_filler[CACHE_ALIGN(_phyint_list_s_)];
12337c478bd9Sstevel@tonic-gate } phyint_list_t;
12347c478bd9Sstevel@tonic-gate 
12357c478bd9Sstevel@tonic-gate #define	phyint_list_avl_by_index	phyint_list_s.phyint_list_avl_by_index
12367c478bd9Sstevel@tonic-gate #define	phyint_list_avl_by_name		phyint_list_s.phyint_list_avl_by_name
12377c478bd9Sstevel@tonic-gate 
12387c478bd9Sstevel@tonic-gate /*
12397c478bd9Sstevel@tonic-gate  * Fragmentation hash bucket
12407c478bd9Sstevel@tonic-gate  */
12417c478bd9Sstevel@tonic-gate typedef struct ipfb_s {
12427c478bd9Sstevel@tonic-gate 	struct ipf_s	*ipfb_ipf;	/* List of ... */
12437c478bd9Sstevel@tonic-gate 	size_t		ipfb_count;	/* Count of bytes used by frag(s) */
12447c478bd9Sstevel@tonic-gate 	kmutex_t	ipfb_lock;	/* Protect all ipf in list */
12457c478bd9Sstevel@tonic-gate 	uint_t		ipfb_frag_pkts; /* num of distinct fragmented pkts */
12467c478bd9Sstevel@tonic-gate } ipfb_t;
12477c478bd9Sstevel@tonic-gate 
12487c478bd9Sstevel@tonic-gate /*
12497c478bd9Sstevel@tonic-gate  * IRE bucket structure. Usually there is an array of such structures,
12507c478bd9Sstevel@tonic-gate  * each pointing to a linked list of ires. irb_refcnt counts the number
12517c478bd9Sstevel@tonic-gate  * of walkers of a given hash bucket. Usually the reference count is
12527c478bd9Sstevel@tonic-gate  * bumped up if the walker wants no IRES to be DELETED while walking the
12537c478bd9Sstevel@tonic-gate  * list. Bumping up does not PREVENT ADDITION. This allows walking a given
12547c478bd9Sstevel@tonic-gate  * hash bucket without stumbling up on a free pointer.
1255c793af95Ssangeeta  *
1256c793af95Ssangeeta  * irb_t structures in ip_ftable are dynamically allocated and freed.
12573173664eSapersson  * In order to identify the irb_t structures that can be safely kmem_free'd
1258c793af95Ssangeeta  * we need to ensure that
1259c793af95Ssangeeta  *  - the irb_refcnt is quiescent, indicating no other walkers,
1260c793af95Ssangeeta  *  - no other threads or ire's are holding references to the irb,
1261c793af95Ssangeeta  *	i.e., irb_nire == 0,
1262c793af95Ssangeeta  *  - there are no active ire's in the bucket, i.e., irb_ire_cnt == 0
12637c478bd9Sstevel@tonic-gate  */
12647c478bd9Sstevel@tonic-gate typedef struct irb {
12657c478bd9Sstevel@tonic-gate 	struct ire_s	*irb_ire;	/* First ire in this bucket */
12667c478bd9Sstevel@tonic-gate 					/* Should be first in this struct */
12677c478bd9Sstevel@tonic-gate 	krwlock_t	irb_lock;	/* Protect this bucket */
12687c478bd9Sstevel@tonic-gate 	uint_t		irb_refcnt;	/* Protected by irb_lock */
12697c478bd9Sstevel@tonic-gate 	uchar_t		irb_marks;	/* CONDEMNED ires in this bucket ? */
1270bd670b35SErik Nordmark #define	IRB_MARK_CONDEMNED	0x0001	/* Contains some IRE_IS_CONDEMNED */
1271bd670b35SErik Nordmark #define	IRB_MARK_DYNAMIC	0x0002	/* Dynamically allocated */
1272bd670b35SErik Nordmark 	/* Once IPv6 uses radix then IRB_MARK_DYNAMIC will be always be set */
1273c793af95Ssangeeta 	uint_t		irb_ire_cnt;	/* Num of active IRE in this bucket */
1274c793af95Ssangeeta 	int		irb_nire;	/* Num of ftable ire's that ref irb */
1275f4b3ec61Sdh 	ip_stack_t	*irb_ipst;	/* Does not have a netstack_hold */
12767c478bd9Sstevel@tonic-gate } irb_t;
12777c478bd9Sstevel@tonic-gate 
12787f125a53SRavi Chandra Nallan /*
12797f125a53SRavi Chandra Nallan  * This is the structure used to store the multicast physical addresses
12807f125a53SRavi Chandra Nallan  * that an interface has joined.
12817f125a53SRavi Chandra Nallan  * The refcnt keeps track of the number of multicast IP addresses mapping
12827f125a53SRavi Chandra Nallan  * to a physical multicast address.
12837f125a53SRavi Chandra Nallan  */
12847f125a53SRavi Chandra Nallan typedef struct multiphysaddr_s {
12857f125a53SRavi Chandra Nallan 	struct	multiphysaddr_s  *mpa_next;
12867f125a53SRavi Chandra Nallan 	char	mpa_addr[IP_MAX_HW_LEN];
12877f125a53SRavi Chandra Nallan 	int	mpa_refcnt;
12887f125a53SRavi Chandra Nallan } multiphysaddr_t;
12897f125a53SRavi Chandra Nallan 
1290c793af95Ssangeeta #define	IRB2RT(irb)	(rt_t *)((caddr_t)(irb) - offsetof(rt_t, rt_irb))
1291c793af95Ssangeeta 
1292bd670b35SErik Nordmark /* Forward declarations */
1293bd670b35SErik Nordmark struct dce_s;
1294bd670b35SErik Nordmark typedef struct dce_s dce_t;
1295bd670b35SErik Nordmark struct ire_s;
1296bd670b35SErik Nordmark typedef struct ire_s ire_t;
1297bd670b35SErik Nordmark struct ncec_s;
1298bd670b35SErik Nordmark typedef struct ncec_s ncec_t;
1299bd670b35SErik Nordmark struct nce_s;
1300bd670b35SErik Nordmark typedef struct nce_s nce_t;
1301bd670b35SErik Nordmark struct ip_recv_attr_s;
1302bd670b35SErik Nordmark typedef struct ip_recv_attr_s ip_recv_attr_t;
1303bd670b35SErik Nordmark struct ip_xmit_attr_s;
1304bd670b35SErik Nordmark typedef struct ip_xmit_attr_s ip_xmit_attr_t;
1305bd670b35SErik Nordmark 
1306bd670b35SErik Nordmark struct tsol_ire_gw_secattr_s;
1307bd670b35SErik Nordmark typedef struct tsol_ire_gw_secattr_s tsol_ire_gw_secattr_t;
1308bd670b35SErik Nordmark 
1309bd670b35SErik Nordmark /*
1310bd670b35SErik Nordmark  * This is a structure for a one-element route cache that is passed
1311bd670b35SErik Nordmark  * by reference between ip_input and ill_inputfn.
1312bd670b35SErik Nordmark  */
1313bd670b35SErik Nordmark typedef struct {
1314bd670b35SErik Nordmark 	ire_t		*rtc_ire;
1315bd670b35SErik Nordmark 	ipaddr_t	rtc_ipaddr;
1316bd670b35SErik Nordmark 	in6_addr_t	rtc_ip6addr;
1317bd670b35SErik Nordmark } rtc_t;
1318bd670b35SErik Nordmark 
1319bd670b35SErik Nordmark /*
1320bd670b35SErik Nordmark  * Note: Temporarily use 64 bits, and will probably go back to 32 bits after
1321bd670b35SErik Nordmark  * more cleanup work is done.
1322bd670b35SErik Nordmark  */
1323bd670b35SErik Nordmark typedef uint64_t iaflags_t;
1324bd670b35SErik Nordmark 
1325bd670b35SErik Nordmark /* The ill input function pointer type */
1326bd670b35SErik Nordmark typedef void (*pfillinput_t)(mblk_t *, void *, void *, ip_recv_attr_t *,
1327bd670b35SErik Nordmark     rtc_t *);
1328bd670b35SErik Nordmark 
1329bd670b35SErik Nordmark /* The ire receive function pointer type */
1330bd670b35SErik Nordmark typedef void (*pfirerecv_t)(ire_t *, mblk_t *, void *, ip_recv_attr_t *);
1331bd670b35SErik Nordmark 
1332bd670b35SErik Nordmark /* The ire send and postfrag function pointer types */
1333bd670b35SErik Nordmark typedef int (*pfiresend_t)(ire_t *, mblk_t *, void *,
1334bd670b35SErik Nordmark     ip_xmit_attr_t *, uint32_t *);
1335bd670b35SErik Nordmark typedef int (*pfirepostfrag_t)(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
1336bd670b35SErik Nordmark     zoneid_t, zoneid_t, uintptr_t *);
1337bd670b35SErik Nordmark 
1338c793af95Ssangeeta 
13397c478bd9Sstevel@tonic-gate #define	IP_V4_G_HEAD	0
13407c478bd9Sstevel@tonic-gate #define	IP_V6_G_HEAD	1
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate #define	MAX_G_HEADS	2
13437c478bd9Sstevel@tonic-gate 
13447c478bd9Sstevel@tonic-gate /*
13457c478bd9Sstevel@tonic-gate  * unpadded ill_if structure
13467c478bd9Sstevel@tonic-gate  */
13477c478bd9Sstevel@tonic-gate struct 	_ill_if_s_ {
13487c478bd9Sstevel@tonic-gate 	union ill_if_u	*illif_next;
13497c478bd9Sstevel@tonic-gate 	union ill_if_u	*illif_prev;
13507c478bd9Sstevel@tonic-gate 	avl_tree_t	illif_avl_by_ppa;	/* AVL tree sorted on ppa */
13517c478bd9Sstevel@tonic-gate 	vmem_t		*illif_ppa_arena;	/* ppa index space */
13527c478bd9Sstevel@tonic-gate 	uint16_t	illif_mcast_v1;		/* hints for		  */
13537c478bd9Sstevel@tonic-gate 	uint16_t	illif_mcast_v2;		/* [igmp|mld]_slowtimo	  */
13547c478bd9Sstevel@tonic-gate 	int		illif_name_len;		/* name length */
13557c478bd9Sstevel@tonic-gate 	char		illif_name[LIFNAMSIZ];	/* name of interface type */
13567c478bd9Sstevel@tonic-gate };
13577c478bd9Sstevel@tonic-gate 
13587c478bd9Sstevel@tonic-gate /* cache aligned ill_if structure */
13597c478bd9Sstevel@tonic-gate typedef union 	ill_if_u {
13607c478bd9Sstevel@tonic-gate 	struct  _ill_if_s_ ill_if_s;
13617c478bd9Sstevel@tonic-gate 	char 	illif_filler[CACHE_ALIGN(_ill_if_s_)];
13627c478bd9Sstevel@tonic-gate } ill_if_t;
13637c478bd9Sstevel@tonic-gate 
13647c478bd9Sstevel@tonic-gate #define	illif_next		ill_if_s.illif_next
13657c478bd9Sstevel@tonic-gate #define	illif_prev		ill_if_s.illif_prev
13667c478bd9Sstevel@tonic-gate #define	illif_avl_by_ppa	ill_if_s.illif_avl_by_ppa
13677c478bd9Sstevel@tonic-gate #define	illif_ppa_arena		ill_if_s.illif_ppa_arena
13687c478bd9Sstevel@tonic-gate #define	illif_mcast_v1		ill_if_s.illif_mcast_v1
13697c478bd9Sstevel@tonic-gate #define	illif_mcast_v2		ill_if_s.illif_mcast_v2
13707c478bd9Sstevel@tonic-gate #define	illif_name		ill_if_s.illif_name
13717c478bd9Sstevel@tonic-gate #define	illif_name_len		ill_if_s.illif_name_len
13727c478bd9Sstevel@tonic-gate 
13737c478bd9Sstevel@tonic-gate typedef struct ill_walk_context_s {
13747c478bd9Sstevel@tonic-gate 	int	ctx_current_list; /* current list being searched */
13757c478bd9Sstevel@tonic-gate 	int	ctx_last_list;	 /* last list to search */
13767c478bd9Sstevel@tonic-gate } ill_walk_context_t;
13777c478bd9Sstevel@tonic-gate 
13787c478bd9Sstevel@tonic-gate /*
1379f4b3ec61Sdh  * ill_g_heads structure, one for IPV4 and one for IPV6
13807c478bd9Sstevel@tonic-gate  */
13817c478bd9Sstevel@tonic-gate struct _ill_g_head_s_ {
13827c478bd9Sstevel@tonic-gate 	ill_if_t	*ill_g_list_head;
13837c478bd9Sstevel@tonic-gate 	ill_if_t	*ill_g_list_tail;
13847c478bd9Sstevel@tonic-gate };
13857c478bd9Sstevel@tonic-gate 
13867c478bd9Sstevel@tonic-gate typedef union ill_g_head_u {
13877c478bd9Sstevel@tonic-gate 	struct _ill_g_head_s_ ill_g_head_s;
13887c478bd9Sstevel@tonic-gate 	char	ill_g_head_filler[CACHE_ALIGN(_ill_g_head_s_)];
13897c478bd9Sstevel@tonic-gate } ill_g_head_t;
13907c478bd9Sstevel@tonic-gate 
13917c478bd9Sstevel@tonic-gate #define	ill_g_list_head	ill_g_head_s.ill_g_list_head
13927c478bd9Sstevel@tonic-gate #define	ill_g_list_tail	ill_g_head_s.ill_g_list_tail
13937c478bd9Sstevel@tonic-gate 
1394f4b3ec61Sdh #define	IP_V4_ILL_G_LIST(ipst)	\
1395f4b3ec61Sdh 	(ipst)->ips_ill_g_heads[IP_V4_G_HEAD].ill_g_list_head
1396f4b3ec61Sdh #define	IP_V6_ILL_G_LIST(ipst)	\
1397f4b3ec61Sdh 	(ipst)->ips_ill_g_heads[IP_V6_G_HEAD].ill_g_list_head
1398f4b3ec61Sdh #define	IP_VX_ILL_G_LIST(i, ipst)	\
1399f4b3ec61Sdh 	(ipst)->ips_ill_g_heads[i].ill_g_list_head
14007c478bd9Sstevel@tonic-gate 
1401f4b3ec61Sdh #define	ILL_START_WALK_V4(ctx_ptr, ipst)	\
1402f4b3ec61Sdh 	ill_first(IP_V4_G_HEAD, IP_V4_G_HEAD, ctx_ptr, ipst)
1403f4b3ec61Sdh #define	ILL_START_WALK_V6(ctx_ptr, ipst)	\
1404f4b3ec61Sdh 	ill_first(IP_V6_G_HEAD, IP_V6_G_HEAD, ctx_ptr, ipst)
1405f4b3ec61Sdh #define	ILL_START_WALK_ALL(ctx_ptr, ipst)	\
1406f4b3ec61Sdh 	ill_first(MAX_G_HEADS, MAX_G_HEADS, ctx_ptr, ipst)
14077c478bd9Sstevel@tonic-gate 
14087c478bd9Sstevel@tonic-gate /*
14097c478bd9Sstevel@tonic-gate  * Capabilities, possible flags for ill_capabilities.
14107c478bd9Sstevel@tonic-gate  */
1411bd670b35SErik Nordmark #define	ILL_CAPAB_LSO		0x04		/* Large Send Offload */
14127c478bd9Sstevel@tonic-gate #define	ILL_CAPAB_HCKSUM	0x08		/* Hardware checksumming */
14137c478bd9Sstevel@tonic-gate #define	ILL_CAPAB_ZEROCOPY	0x10		/* Zero-copy */
1414da14cebeSEric Cheng #define	ILL_CAPAB_DLD		0x20		/* DLD capabilities */
1415da14cebeSEric Cheng #define	ILL_CAPAB_DLD_POLL	0x40		/* Polling */
1416da14cebeSEric Cheng #define	ILL_CAPAB_DLD_DIRECT	0x80		/* Direct function call */
14177c478bd9Sstevel@tonic-gate 
14187c478bd9Sstevel@tonic-gate /*
14197c478bd9Sstevel@tonic-gate  * Per-ill Hardware Checksumming capbilities.
14207c478bd9Sstevel@tonic-gate  */
14217c478bd9Sstevel@tonic-gate typedef struct ill_hcksum_capab_s ill_hcksum_capab_t;
14227c478bd9Sstevel@tonic-gate 
14237c478bd9Sstevel@tonic-gate /*
14247c478bd9Sstevel@tonic-gate  * Per-ill Zero-copy capabilities.
14257c478bd9Sstevel@tonic-gate  */
14267c478bd9Sstevel@tonic-gate typedef struct ill_zerocopy_capab_s ill_zerocopy_capab_t;
14277c478bd9Sstevel@tonic-gate 
14287c478bd9Sstevel@tonic-gate /*
1429da14cebeSEric Cheng  * DLD capbilities.
14307c478bd9Sstevel@tonic-gate  */
1431da14cebeSEric Cheng typedef struct ill_dld_capab_s ill_dld_capab_t;
14327c478bd9Sstevel@tonic-gate 
14337c478bd9Sstevel@tonic-gate /*
14347c478bd9Sstevel@tonic-gate  * Per-ill polling resource map.
14357c478bd9Sstevel@tonic-gate  */
14367c478bd9Sstevel@tonic-gate typedef struct ill_rx_ring ill_rx_ring_t;
14377c478bd9Sstevel@tonic-gate 
14388347601bSyl /*
1439bd670b35SErik Nordmark  * Per-ill Large Send Offload capabilities.
14408347601bSyl  */
14418347601bSyl typedef struct ill_lso_capab_s ill_lso_capab_t;
14428347601bSyl 
14437c478bd9Sstevel@tonic-gate /* The following are ill_state_flags */
14447c478bd9Sstevel@tonic-gate #define	ILL_LL_SUBNET_PENDING	0x01	/* Waiting for DL_INFO_ACK from drv */
14457c478bd9Sstevel@tonic-gate #define	ILL_CONDEMNED		0x02	/* No more new ref's to the ILL */
1446bd670b35SErik Nordmark #define	ILL_DL_UNBIND_IN_PROGRESS	0x04	/* UNBIND_REQ is sent */
14472ea22bf7SSowmini Varadhan /*
14482ea22bf7SSowmini Varadhan  * ILL_DOWN_IN_PROGRESS is set to ensure the following:
14492ea22bf7SSowmini Varadhan  * - no packets are sent to the driver after the DL_UNBIND_REQ is sent,
14502ea22bf7SSowmini Varadhan  * - no longstanding references will be acquired on objects that are being
14512ea22bf7SSowmini Varadhan  *   brought down.
14522ea22bf7SSowmini Varadhan  */
14532ea22bf7SSowmini Varadhan #define	ILL_DOWN_IN_PROGRESS	0x08
14547c478bd9Sstevel@tonic-gate 
14557c478bd9Sstevel@tonic-gate /* Is this an ILL whose source address is used by other ILL's ? */
14567c478bd9Sstevel@tonic-gate #define	IS_USESRC_ILL(ill)			\
14577c478bd9Sstevel@tonic-gate 	(((ill)->ill_usesrc_ifindex == 0) &&	\
14585dddb8baSkcpoon 	((ill)->ill_usesrc_grp_next != NULL))
14597c478bd9Sstevel@tonic-gate 
14607c478bd9Sstevel@tonic-gate /* Is this a client/consumer of the usesrc ILL ? */
14617c478bd9Sstevel@tonic-gate #define	IS_USESRC_CLI_ILL(ill)			\
14627c478bd9Sstevel@tonic-gate 	(((ill)->ill_usesrc_ifindex != 0) &&	\
14635dddb8baSkcpoon 	((ill)->ill_usesrc_grp_next != NULL))
14647c478bd9Sstevel@tonic-gate 
14657c478bd9Sstevel@tonic-gate /* Is this an virtual network interface (vni) ILL ? */
1466bd670b35SErik Nordmark #define	IS_VNI(ill)							\
1467c793af95Ssangeeta 	(((ill)->ill_phyint->phyint_flags & (PHYI_LOOPBACK|PHYI_VIRTUAL)) == \
1468bd670b35SErik Nordmark 	PHYI_VIRTUAL)
14697c478bd9Sstevel@tonic-gate 
147048de1bd2Skcpoon /* Is this a loopback ILL? */
147148de1bd2Skcpoon #define	IS_LOOPBACK(ill) \
147248de1bd2Skcpoon 	((ill)->ill_phyint->phyint_flags & PHYI_LOOPBACK)
147348de1bd2Skcpoon 
1474e11c3f44Smeem /* Is this an IPMP meta-interface ILL? */
1475e11c3f44Smeem #define	IS_IPMP(ill)							\
1476e11c3f44Smeem 	((ill)->ill_phyint->phyint_flags & PHYI_IPMP)
1477e11c3f44Smeem 
1478e11c3f44Smeem /* Is this ILL under an IPMP meta-interface? (aka "in a group?") */
1479e11c3f44Smeem #define	IS_UNDER_IPMP(ill)						\
1480e11c3f44Smeem 	((ill)->ill_grp != NULL && !IS_IPMP(ill))
1481e11c3f44Smeem 
1482e11c3f44Smeem /* Is ill1 in the same illgrp as ill2? */
1483e11c3f44Smeem #define	IS_IN_SAME_ILLGRP(ill1, ill2)					\
1484e11c3f44Smeem 	((ill1)->ill_grp != NULL && ((ill1)->ill_grp == (ill2)->ill_grp))
1485e11c3f44Smeem 
1486e11c3f44Smeem /* Is ill1 on the same LAN as ill2? */
1487e11c3f44Smeem #define	IS_ON_SAME_LAN(ill1, ill2)					\
1488e11c3f44Smeem 	((ill1) == (ill2) || IS_IN_SAME_ILLGRP(ill1, ill2))
1489e11c3f44Smeem 
1490e11c3f44Smeem #define	ILL_OTHER(ill)							\
1491e11c3f44Smeem 	((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :		\
1492e11c3f44Smeem 	    (ill)->ill_phyint->phyint_illv6)
1493e11c3f44Smeem 
1494e11c3f44Smeem /*
1495e11c3f44Smeem  * IPMP group ILL state structure -- up to two per IPMP group (V4 and V6).
1496e11c3f44Smeem  * Created when the V4 and/or V6 IPMP meta-interface is I_PLINK'd.  It is
1497e11c3f44Smeem  * guaranteed to persist while there are interfaces of that type in the group.
1498e11c3f44Smeem  * In general, most fields are accessed outside of the IPSQ (e.g., in the
1499e11c3f44Smeem  * datapath), and thus use locks in addition to the IPSQ for protection.
1500e11c3f44Smeem  *
1501e11c3f44Smeem  * synchronization:		read			write
1502e11c3f44Smeem  *
1503e11c3f44Smeem  *	ig_if			ipsq or ill_g_lock	ipsq and ill_g_lock
1504e11c3f44Smeem  *	ig_actif		ipsq or ipmp_lock	ipsq and ipmp_lock
1505e11c3f44Smeem  *	ig_nactif		ipsq or ipmp_lock	ipsq and ipmp_lock
1506e11c3f44Smeem  *	ig_next_ill		ipsq or ipmp_lock	ipsq and ipmp_lock
1507e11c3f44Smeem  *	ig_ipmp_ill		write once		write once
1508e11c3f44Smeem  *	ig_cast_ill		ipsq or ipmp_lock	ipsq and ipmp_lock
1509e11c3f44Smeem  *	ig_arpent		ipsq			ipsq
1510e11c3f44Smeem  *	ig_mtu			ipsq			ipsq
15111eee170aSErik Nordmark  *	ig_mc_mtu		ipsq			ipsq
1512e11c3f44Smeem  */
1513e11c3f44Smeem typedef struct ipmp_illgrp_s {
1514e11c3f44Smeem 	list_t		ig_if; 		/* list of all interfaces */
1515e11c3f44Smeem 	list_t		ig_actif;	/* list of active interfaces */
1516e11c3f44Smeem 	uint_t		ig_nactif;	/* number of active interfaces */
1517e11c3f44Smeem 	struct ill_s	*ig_next_ill;	/* next active interface to use */
1518e11c3f44Smeem 	struct ill_s	*ig_ipmp_ill;	/* backpointer to IPMP meta-interface */
1519e11c3f44Smeem 	struct ill_s	*ig_cast_ill;	/* nominated ill for multi/broadcast */
1520e11c3f44Smeem 	list_t		ig_arpent;	/* list of ARP entries */
15211eee170aSErik Nordmark 	uint_t		ig_mtu;		/* ig_ipmp_ill->ill_mtu */
15221eee170aSErik Nordmark 	uint_t		ig_mc_mtu;	/* ig_ipmp_ill->ill_mc_mtu */
1523e11c3f44Smeem } ipmp_illgrp_t;
1524e11c3f44Smeem 
1525e11c3f44Smeem /*
1526e11c3f44Smeem  * IPMP group state structure -- one per IPMP group.  Created when the
1527e11c3f44Smeem  * IPMP meta-interface is plumbed; it is guaranteed to persist while there
1528e11c3f44Smeem  * are interfaces in it.
1529e11c3f44Smeem  *
1530e11c3f44Smeem  * ipmp_grp_t synchronization:		read			write
1531e11c3f44Smeem  *
1532e11c3f44Smeem  *	gr_name				ipmp_lock		ipmp_lock
1533e11c3f44Smeem  *	gr_ifname			write once		write once
1534e11c3f44Smeem  *	gr_mactype			ipmp_lock		ipmp_lock
1535e11c3f44Smeem  *	gr_phyint			write once		write once
1536e11c3f44Smeem  *	gr_nif				ipmp_lock		ipmp_lock
1537e11c3f44Smeem  *	gr_nactif			ipsq			ipsq
1538e11c3f44Smeem  *	gr_v4				ipmp_lock		ipmp_lock
1539e11c3f44Smeem  *	gr_v6				ipmp_lock		ipmp_lock
1540e11c3f44Smeem  *	gr_nv4				ipmp_lock		ipmp_lock
1541e11c3f44Smeem  *	gr_nv6				ipmp_lock		ipmp_lock
1542e11c3f44Smeem  *	gr_pendv4			ipmp_lock		ipmp_lock
1543e11c3f44Smeem  *	gr_pendv6			ipmp_lock		ipmp_lock
1544e11c3f44Smeem  *	gr_linkdownmp			ipsq			ipsq
1545e11c3f44Smeem  *	gr_ksp				ipmp_lock		ipmp_lock
1546e11c3f44Smeem  *	gr_kstats0			atomic			atomic
1547e11c3f44Smeem  */
1548e11c3f44Smeem typedef struct ipmp_grp_s {
1549e11c3f44Smeem 	char		gr_name[LIFGRNAMSIZ];	/* group name */
1550e11c3f44Smeem 	char		gr_ifname[LIFNAMSIZ];	/* interface name */
1551e11c3f44Smeem 	t_uscalar_t	gr_mactype;	/* DLPI mactype of group */
1552e11c3f44Smeem 	phyint_t	*gr_phyint;	/* IPMP group phyint */
1553e11c3f44Smeem 	uint_t		gr_nif;		/* number of interfaces in group */
1554e11c3f44Smeem 	uint_t		gr_nactif; 	/* number of active interfaces */
1555e11c3f44Smeem 	ipmp_illgrp_t	*gr_v4;		/* V4 group information */
1556e11c3f44Smeem 	ipmp_illgrp_t	*gr_v6;		/* V6 group information */
1557e11c3f44Smeem 	uint_t		gr_nv4;		/* number of ills in V4 group */
1558e11c3f44Smeem 	uint_t		gr_nv6;		/* number of ills in V6 group */
1559e11c3f44Smeem 	uint_t		gr_pendv4; 	/* number of pending ills in V4 group */
1560e11c3f44Smeem 	uint_t		gr_pendv6; 	/* number of pending ills in V6 group */
1561e11c3f44Smeem 	mblk_t		*gr_linkdownmp;	/* message used to bring link down */
1562e11c3f44Smeem 	kstat_t		*gr_ksp;	/* group kstat pointer */
1563e11c3f44Smeem 	uint64_t	gr_kstats0[IPMP_KSTAT_MAX]; /* baseline group kstats */
1564e11c3f44Smeem } ipmp_grp_t;
1565e11c3f44Smeem 
1566e11c3f44Smeem /*
1567e11c3f44Smeem  * IPMP ARP entry -- one per SIOCS*ARP entry tied to the group.  Used to keep
1568e11c3f44Smeem  * ARP up-to-date as the active set of interfaces in the group changes.
1569e11c3f44Smeem  */
1570e11c3f44Smeem typedef struct ipmp_arpent_s {
1571e11c3f44Smeem 	ipaddr_t	ia_ipaddr; 	/* IP address for this entry */
1572e11c3f44Smeem 	boolean_t	ia_proxyarp; 	/* proxy ARP entry? */
1573e11c3f44Smeem 	boolean_t	ia_notified; 	/* ARP notified about this entry? */
1574e11c3f44Smeem 	list_node_t	ia_node; 	/* next ARP entry in list */
1575bd670b35SErik Nordmark 	uint16_t	ia_flags;	/* nce_flags for the address */
1576bd670b35SErik Nordmark 	size_t		ia_lladdr_len;
1577bd670b35SErik Nordmark 	uchar_t		*ia_lladdr;
1578e11c3f44Smeem } ipmp_arpent_t;
1579e11c3f44Smeem 
1580bd670b35SErik Nordmark struct arl_s;
1581bd670b35SErik Nordmark 
1582bd670b35SErik Nordmark /*
1583bd670b35SErik Nordmark  * Per-ill capabilities.
1584bd670b35SErik Nordmark  */
1585bd670b35SErik Nordmark struct ill_hcksum_capab_s {
1586bd670b35SErik Nordmark 	uint_t	ill_hcksum_version;	/* interface version */
1587bd670b35SErik Nordmark 	uint_t	ill_hcksum_txflags;	/* capabilities on transmit */
1588bd670b35SErik Nordmark };
1589bd670b35SErik Nordmark 
1590bd670b35SErik Nordmark struct ill_zerocopy_capab_s {
1591bd670b35SErik Nordmark 	uint_t	ill_zerocopy_version;	/* interface version */
1592bd670b35SErik Nordmark 	uint_t	ill_zerocopy_flags;	/* capabilities */
1593bd670b35SErik Nordmark };
1594bd670b35SErik Nordmark 
1595bd670b35SErik Nordmark struct ill_lso_capab_s {
1596bd670b35SErik Nordmark 	uint_t	ill_lso_flags;		/* capabilities */
1597bd670b35SErik Nordmark 	uint_t	ill_lso_max;		/* maximum size of payload */
1598bd670b35SErik Nordmark };
1599bd670b35SErik Nordmark 
16007c478bd9Sstevel@tonic-gate /*
16017c478bd9Sstevel@tonic-gate  * IP Lower level Structure.
16027c478bd9Sstevel@tonic-gate  * Instance data structure in ip_open when there is a device below us.
16037c478bd9Sstevel@tonic-gate  */
16047c478bd9Sstevel@tonic-gate typedef struct ill_s {
1605bd670b35SErik Nordmark 	pfillinput_t ill_inputfn;	/* Fast input function selector */
16067c478bd9Sstevel@tonic-gate 	ill_if_t *ill_ifptr;		/* pointer to interface type */
16077c478bd9Sstevel@tonic-gate 	queue_t	*ill_rq;		/* Read queue. */
16087c478bd9Sstevel@tonic-gate 	queue_t	*ill_wq;		/* Write queue. */
16097c478bd9Sstevel@tonic-gate 
16107c478bd9Sstevel@tonic-gate 	int	ill_error;		/* Error value sent up by device. */
16117c478bd9Sstevel@tonic-gate 
16127c478bd9Sstevel@tonic-gate 	ipif_t	*ill_ipif;		/* Interface chain for this ILL. */
16137c478bd9Sstevel@tonic-gate 
16147c478bd9Sstevel@tonic-gate 	uint_t	ill_ipif_up_count;	/* Number of IPIFs currently up. */
16157c478bd9Sstevel@tonic-gate 	uint_t	ill_max_frag;		/* Max IDU from DLPI. */
1616bd670b35SErik Nordmark 	uint_t	ill_current_frag;	/* Current IDU from DLPI. */
1617bd670b35SErik Nordmark 	uint_t	ill_mtu;		/* User-specified MTU; SIOCSLIFMTU */
16181eee170aSErik Nordmark 	uint_t	ill_mc_mtu;		/* MTU for multi/broadcast */
16196e91bba0SGirish Moodalbail 	uint_t	ill_metric;		/* BSD if metric, for compatibility. */
16207c478bd9Sstevel@tonic-gate 	char	*ill_name;		/* Our name. */
162169bb4bb4Scarlsonj 	uint_t	ill_ipif_dup_count;	/* Number of duplicate addresses. */
16227c478bd9Sstevel@tonic-gate 	uint_t	ill_name_length;	/* Name length, incl. terminator. */
16237c478bd9Sstevel@tonic-gate 	uint_t	ill_net_type;		/* IRE_IF_RESOLVER/IRE_IF_NORESOLVER. */
16247c478bd9Sstevel@tonic-gate 	/*
16257c478bd9Sstevel@tonic-gate 	 * Physical Point of Attachment num.  If DLPI style 1 provider
16267c478bd9Sstevel@tonic-gate 	 * then this is derived from the devname.
16277c478bd9Sstevel@tonic-gate 	 */
16287c478bd9Sstevel@tonic-gate 	uint_t	ill_ppa;
16297c478bd9Sstevel@tonic-gate 	t_uscalar_t	ill_sap;
16307c478bd9Sstevel@tonic-gate 	t_scalar_t	ill_sap_length;	/* Including sign (for position) */
16317c478bd9Sstevel@tonic-gate 	uint_t	ill_phys_addr_length;	/* Excluding the sap. */
16327c478bd9Sstevel@tonic-gate 	uint_t	ill_bcast_addr_length;	/* Only set when the DL provider */
16337c478bd9Sstevel@tonic-gate 					/* supports broadcast. */
16347c478bd9Sstevel@tonic-gate 	t_uscalar_t	ill_mactype;
16357c478bd9Sstevel@tonic-gate 	uint8_t	*ill_frag_ptr;		/* Reassembly state. */
16367c478bd9Sstevel@tonic-gate 	timeout_id_t ill_frag_timer_id; /* timeout id for the frag timer */
16377c478bd9Sstevel@tonic-gate 	ipfb_t	*ill_frag_hash_tbl;	/* Fragment hash list head. */
16387c478bd9Sstevel@tonic-gate 
1639bd670b35SErik Nordmark 	krwlock_t ill_mcast_lock;	/* Protects multicast state */
1640bd670b35SErik Nordmark 	kmutex_t ill_mcast_serializer;	/* Serialize across ilg and ilm state */
16417924222fSmeem 	ilm_t	*ill_ilm;		/* Multicast membership for ill */
16427c478bd9Sstevel@tonic-gate 	uint_t	ill_global_timer;	/* for IGMPv3/MLDv2 general queries */
16437c478bd9Sstevel@tonic-gate 	int	ill_mcast_type;		/* type of router which is querier */
16447c478bd9Sstevel@tonic-gate 					/* on this interface */
16457c478bd9Sstevel@tonic-gate 	uint16_t ill_mcast_v1_time;	/* # slow timeouts since last v1 qry */
16467c478bd9Sstevel@tonic-gate 	uint16_t ill_mcast_v2_time;	/* # slow timeouts since last v2 qry */
16477c478bd9Sstevel@tonic-gate 	uint8_t	ill_mcast_v1_tset;	/* 1 => timer is set; 0 => not set */
16487c478bd9Sstevel@tonic-gate 	uint8_t	ill_mcast_v2_tset;	/* 1 => timer is set; 0 => not set */
16497c478bd9Sstevel@tonic-gate 
16507c478bd9Sstevel@tonic-gate 	uint8_t	ill_mcast_rv;		/* IGMPv3/MLDv2 robustness variable */
16517c478bd9Sstevel@tonic-gate 	int	ill_mcast_qi;		/* IGMPv3/MLDv2 query interval var */
16527c478bd9Sstevel@tonic-gate 
16537c478bd9Sstevel@tonic-gate 	/*
16547c478bd9Sstevel@tonic-gate 	 * All non-NULL cells between 'ill_first_mp_to_free' and
16557c478bd9Sstevel@tonic-gate 	 * 'ill_last_mp_to_free' are freed in ill_delete.
16567c478bd9Sstevel@tonic-gate 	 */
16577c478bd9Sstevel@tonic-gate #define	ill_first_mp_to_free	ill_bcast_mp
16587c478bd9Sstevel@tonic-gate 	mblk_t	*ill_bcast_mp;		/* DLPI header for broadcasts. */
16597c478bd9Sstevel@tonic-gate 	mblk_t	*ill_unbind_mp;		/* unbind mp from ill_dl_up() */
1660b127ac41SPhilip Kirk 	mblk_t	*ill_promiscoff_mp;	/* for ill_leave_allmulti() */
16617c478bd9Sstevel@tonic-gate 	mblk_t	*ill_dlpi_deferred;	/* b_next chain of control messages */
16622b24ab6bSSebastien Roy 	mblk_t	*ill_dest_addr_mp;	/* mblk which holds ill_dest_addr */
16635d460eafSCathy Zhou 	mblk_t	*ill_replumb_mp;	/* replumb mp from ill_replumb() */
16647c478bd9Sstevel@tonic-gate 	mblk_t	*ill_phys_addr_mp;	/* mblk which holds ill_phys_addr */
1665bd670b35SErik Nordmark 	mblk_t	*ill_mcast_deferred;	/* b_next chain of IGMP/MLD packets */
1666bd670b35SErik Nordmark #define	ill_last_mp_to_free	ill_mcast_deferred
16677c478bd9Sstevel@tonic-gate 
16687c478bd9Sstevel@tonic-gate 	cred_t	*ill_credp;		/* opener's credentials */
16697c478bd9Sstevel@tonic-gate 	uint8_t	*ill_phys_addr;		/* ill_phys_addr_mp->b_rptr + off */
16702b24ab6bSSebastien Roy 	uint8_t *ill_dest_addr;		/* ill_dest_addr_mp->b_rptr + off */
16717c478bd9Sstevel@tonic-gate 
16727c478bd9Sstevel@tonic-gate 	uint_t	ill_state_flags;	/* see ILL_* flags above */
16737c478bd9Sstevel@tonic-gate 
16747c478bd9Sstevel@tonic-gate 	/* Following bit fields protected by ipsq_t */
16757c478bd9Sstevel@tonic-gate 	uint_t
16767c478bd9Sstevel@tonic-gate 		ill_needs_attach : 1,
16777c478bd9Sstevel@tonic-gate 		ill_reserved : 1,
16787c478bd9Sstevel@tonic-gate 		ill_isv6 : 1,
16797c478bd9Sstevel@tonic-gate 		ill_dlpi_style_set : 1,
16807c478bd9Sstevel@tonic-gate 
16817c478bd9Sstevel@tonic-gate 		ill_ifname_pending : 1,
16827c478bd9Sstevel@tonic-gate 		ill_logical_down : 1,
16837c478bd9Sstevel@tonic-gate 		ill_dl_up : 1,
16847c478bd9Sstevel@tonic-gate 		ill_up_ipifs : 1,
1685bd670b35SErik Nordmark 
168669bb4bb4Scarlsonj 		ill_note_link : 1,	/* supports link-up notification */
16878fb46f24Syz 		ill_capab_reneg : 1, /* capability renegotiation to be done */
1688da14cebeSEric Cheng 		ill_dld_capab_inprog : 1, /* direct dld capab call in prog */
1689b127ac41SPhilip Kirk 		ill_need_recover_multicast : 1,
1690bd670b35SErik Nordmark 
1691bd670b35SErik Nordmark 		ill_replumbing : 1,
1692bd670b35SErik Nordmark 		ill_arl_dlpi_pending : 1,
1693f1c454b4SSowmini Varadhan 		ill_grp_pending : 1,
1694bd670b35SErik Nordmark 
1695f1c454b4SSowmini Varadhan 		ill_pad_to_bit_31 : 17;
16967c478bd9Sstevel@tonic-gate 
16977c478bd9Sstevel@tonic-gate 	/* Following bit fields protected by ill_lock */
16987c478bd9Sstevel@tonic-gate 	uint_t
16997c478bd9Sstevel@tonic-gate 		ill_fragtimer_executing : 1,
17007c478bd9Sstevel@tonic-gate 		ill_fragtimer_needrestart : 1,
17012b24ab6bSSebastien Roy 		ill_manual_token : 1,	/* system won't override ill_token */
17026e91bba0SGirish Moodalbail 		/*
17036e91bba0SGirish Moodalbail 		 * ill_manual_linklocal : system will not change the
17046e91bba0SGirish Moodalbail 		 * linklocal whenever ill_token changes.
17056e91bba0SGirish Moodalbail 		 */
17066e91bba0SGirish Moodalbail 		ill_manual_linklocal : 1,
17072b24ab6bSSebastien Roy 
1708792bd779SSebastien Roy 		ill_manual_dst_linklocal : 1, /* same for pt-pt dst linklocal */
1709792bd779SSebastien Roy 
1710792bd779SSebastien Roy 		ill_pad_bit_31 : 27;
17117c478bd9Sstevel@tonic-gate 
17127c478bd9Sstevel@tonic-gate 	/*
17137c478bd9Sstevel@tonic-gate 	 * Used in SIOCSIFMUXID and SIOCGIFMUXID for 'ifconfig unplumb'.
17147c478bd9Sstevel@tonic-gate 	 */
1715bd670b35SErik Nordmark 	int	ill_muxid;		/* muxid returned from plink */
17167c478bd9Sstevel@tonic-gate 
17170a5d959fSgeorges 	/* Used for IP frag reassembly throttling on a per ILL basis.  */
17187c478bd9Sstevel@tonic-gate 	uint_t	ill_ipf_gen;		/* Generation of next fragment queue */
17190a5d959fSgeorges 	uint_t	ill_frag_count;		/* Count of all reassembly mblk bytes */
17207c478bd9Sstevel@tonic-gate 	uint_t	ill_frag_free_num_pkts;	 /* num of fragmented packets to free */
17217c478bd9Sstevel@tonic-gate 	clock_t	ill_last_frag_clean_time; /* time when frag's were pruned */
17227c478bd9Sstevel@tonic-gate 	int	ill_type;		/* From <net/if_types.h> */
17234d876314Sja 	uint_t	ill_dlpi_multicast_state;	/* See below IDS_* */
17244d876314Sja 	uint_t	ill_dlpi_fastpath_state;	/* See below IDS_* */
17257c478bd9Sstevel@tonic-gate 
17267c478bd9Sstevel@tonic-gate 	/*
17277c478bd9Sstevel@tonic-gate 	 * Capabilities related fields.
17287c478bd9Sstevel@tonic-gate 	 */
1729da14cebeSEric Cheng 	uint_t  ill_dlpi_capab_state;	/* State of capability query, IDCS_* */
1730da14cebeSEric Cheng 	uint_t	ill_capab_pending_cnt;
17317c478bd9Sstevel@tonic-gate 	uint64_t ill_capabilities;	/* Enabled capabilities, ILL_CAPAB_* */
17327c478bd9Sstevel@tonic-gate 	ill_hcksum_capab_t *ill_hcksum_capab; /* H/W cksumming capabilities */
17337c478bd9Sstevel@tonic-gate 	ill_zerocopy_capab_t *ill_zerocopy_capab; /* Zero-copy capabilities */
1734da14cebeSEric Cheng 	ill_dld_capab_t *ill_dld_capab; /* DLD capabilities */
1735da14cebeSEric Cheng 	ill_lso_capab_t	*ill_lso_capab;	/* Large Segment Offload capabilities */
1736da14cebeSEric Cheng 	mblk_t	*ill_capab_reset_mp;	/* Preallocated mblk for capab reset */
17377c478bd9Sstevel@tonic-gate 
17387c478bd9Sstevel@tonic-gate 	uint8_t	ill_max_hops;	/* Maximum hops for any logical interface */
1739e11c3f44Smeem 	uint_t	ill_user_mtu;	/* User-specified MTU via SIOCSLIFLNKINFO */
17407c478bd9Sstevel@tonic-gate 	uint32_t ill_reachable_time;	/* Value for ND algorithm in msec */
17417c478bd9Sstevel@tonic-gate 	uint32_t ill_reachable_retrans_time; /* Value for ND algorithm msec */
17427c478bd9Sstevel@tonic-gate 	uint_t	ill_max_buf;		/* Max # of req to buffer for ND */
17432b24ab6bSSebastien Roy 	in6_addr_t	ill_token;	/* IPv6 interface id */
17442b24ab6bSSebastien Roy 	in6_addr_t	ill_dest_token;	/* Destination IPv6 interface id */
17457c478bd9Sstevel@tonic-gate 	uint_t		ill_token_length;
17467c478bd9Sstevel@tonic-gate 	uint32_t	ill_xmit_count;		/* ndp max multicast xmits */
17473173664eSapersson 	mib2_ipIfStatsEntry_t	*ill_ip_mib;	/* ver indep. interface mib */
17487c478bd9Sstevel@tonic-gate 	mib2_ipv6IfIcmpEntry_t	*ill_icmp6_mib;	/* Per interface mib */
17497c478bd9Sstevel@tonic-gate 
17507c478bd9Sstevel@tonic-gate 	phyint_t		*ill_phyint;
17517c478bd9Sstevel@tonic-gate 	uint64_t		ill_flags;
17527c478bd9Sstevel@tonic-gate 
17537c478bd9Sstevel@tonic-gate 	kmutex_t	ill_lock;	/* Please see table below */
17547c478bd9Sstevel@tonic-gate 	/*
17557c478bd9Sstevel@tonic-gate 	 * The ill_nd_lla* fields handle the link layer address option
17567c478bd9Sstevel@tonic-gate 	 * from neighbor discovery. This is used for external IPv6
17577c478bd9Sstevel@tonic-gate 	 * address resolution.
17587c478bd9Sstevel@tonic-gate 	 */
17597c478bd9Sstevel@tonic-gate 	mblk_t		*ill_nd_lla_mp;	/* mblk which holds ill_nd_lla */
17607c478bd9Sstevel@tonic-gate 	uint8_t		*ill_nd_lla;	/* Link Layer Address */
17617c478bd9Sstevel@tonic-gate 	uint_t		ill_nd_lla_len;	/* Link Layer Address length */
17627c478bd9Sstevel@tonic-gate 	/*
17632b24ab6bSSebastien Roy 	 * We have 4 phys_addr_req's sent down. This field keeps track
17647c478bd9Sstevel@tonic-gate 	 * of which one is pending.
17657c478bd9Sstevel@tonic-gate 	 */
17667c478bd9Sstevel@tonic-gate 	t_uscalar_t	ill_phys_addr_pend; /* which dl_phys_addr_req pending */
17677c478bd9Sstevel@tonic-gate 	/*
17687c478bd9Sstevel@tonic-gate 	 * Used to save errors that occur during plumbing
17697c478bd9Sstevel@tonic-gate 	 */
17707c478bd9Sstevel@tonic-gate 	uint_t		ill_ifname_pending_err;
17717c478bd9Sstevel@tonic-gate 	avl_node_t	ill_avl_byppa; /* avl node based on ppa */
1772bd670b35SErik Nordmark 	list_t		ill_nce; /* pointer to nce_s list */
17737c478bd9Sstevel@tonic-gate 	uint_t		ill_refcnt;	/* active refcnt by threads */
1774384ad179Ssowmini 	uint_t		ill_ire_cnt;	/* ires associated with this ill */
17757c478bd9Sstevel@tonic-gate 	kcondvar_t	ill_cv;
1776bd670b35SErik Nordmark 	uint_t		ill_ncec_cnt;	/* ncecs associated with this ill */
1777384ad179Ssowmini 	uint_t		ill_nce_cnt;	/* nces associated with this ill */
17787c478bd9Sstevel@tonic-gate 	uint_t		ill_waiters;	/* threads waiting in ipsq_enter */
17797c478bd9Sstevel@tonic-gate 	/*
17807c478bd9Sstevel@tonic-gate 	 * Contains the upper read queue pointer of the module immediately
17817c478bd9Sstevel@tonic-gate 	 * beneath IP.  This field allows IP to validate sub-capability
17827c478bd9Sstevel@tonic-gate 	 * acknowledgments coming up from downstream.
17837c478bd9Sstevel@tonic-gate 	 */
17847c478bd9Sstevel@tonic-gate 	queue_t		*ill_lmod_rq;	/* read queue pointer of module below */
17857c478bd9Sstevel@tonic-gate 	uint_t		ill_lmod_cnt;	/* number of modules beneath IP */
17867c478bd9Sstevel@tonic-gate 	ip_m_t		*ill_media;	/* media specific params/functions */
17877c478bd9Sstevel@tonic-gate 	t_uscalar_t	ill_dlpi_pending; /* Last DLPI primitive issued */
17887c478bd9Sstevel@tonic-gate 	uint_t		ill_usesrc_ifindex; /* use src addr from this ILL */
17897c478bd9Sstevel@tonic-gate 	struct ill_s	*ill_usesrc_grp_next; /* Next ILL in the usesrc group */
17907c478bd9Sstevel@tonic-gate 	boolean_t	ill_trace_disable;	/* True when alloc fails */
1791f4b3ec61Sdh 	zoneid_t	ill_zoneid;
1792f4b3ec61Sdh 	ip_stack_t	*ill_ipst;	/* Corresponds to a netstack_hold */
1793e704a8f2Smeem 	uint32_t	ill_dhcpinit;	/* IP_DHCPINIT_IFs for ill */
1794da14cebeSEric Cheng 	void		*ill_flownotify_mh; /* Tx flow ctl, mac cb handle */
1795384ad179Ssowmini 	uint_t		ill_ilm_cnt;    /* ilms referencing this ill */
1796b127ac41SPhilip Kirk 	uint_t		ill_ipallmulti_cnt; /* ip_join_allmulti() calls */
1797bd670b35SErik Nordmark 	ilm_t		*ill_ipallmulti_ilm;
1798bd670b35SErik Nordmark 
1799bd670b35SErik Nordmark 	mblk_t		*ill_saved_ire_mp; /* Allocated for each extra IRE */
1800bd670b35SErik Nordmark 					/* with ire_ill set so they can */
1801bd670b35SErik Nordmark 					/* survive the ill going down and up. */
1802bd670b35SErik Nordmark 	kmutex_t	ill_saved_ire_lock; /* Protects ill_saved_ire_mp, cnt */
1803bd670b35SErik Nordmark 	uint_t		ill_saved_ire_cnt;	/* # entries */
1804bd670b35SErik Nordmark 	struct arl_ill_common_s    *ill_common;
1805bd670b35SErik Nordmark 	ire_t		*ill_ire_multicast; /* IRE_MULTICAST for ill */
1806bd670b35SErik Nordmark 	clock_t		ill_defend_start;   /* start of 1 hour period */
1807bd670b35SErik Nordmark 	uint_t		ill_defend_count;   /* # of announce/defends per ill */
1808e11c3f44Smeem 	/*
1809e11c3f44Smeem 	 * IPMP fields.
1810e11c3f44Smeem 	 */
1811e11c3f44Smeem 	ipmp_illgrp_t	*ill_grp;	/* IPMP group information */
1812e11c3f44Smeem 	list_node_t	ill_actnode; 	/* next active ill in group */
1813e11c3f44Smeem 	list_node_t	ill_grpnode;	/* next ill in group */
1814e11c3f44Smeem 	ipif_t		*ill_src_ipif;	/* source address selection rotor */
1815e11c3f44Smeem 	ipif_t		*ill_move_ipif;	/* ipif awaiting move to new ill */
1816e11c3f44Smeem 	boolean_t	ill_nom_cast;	/* nominated for mcast/bcast */
1817e11c3f44Smeem 	uint_t		ill_bound_cnt;	/* # of data addresses bound to ill */
1818e11c3f44Smeem 	ipif_t		*ill_bound_ipif; /* ipif chain bound to ill */
1819e11c3f44Smeem 	timeout_id_t	ill_refresh_tid; /* ill refresh retry timeout id */
1820bd670b35SErik Nordmark 
1821bd670b35SErik Nordmark 	uint32_t	ill_mrouter_cnt; /* mrouter allmulti joins */
1822550b6e40SSowmini Varadhan 	uint32_t	ill_allowed_ips_cnt;
1823550b6e40SSowmini Varadhan 	in6_addr_t	*ill_allowed_ips;
18247f125a53SRavi Chandra Nallan 
18257f125a53SRavi Chandra Nallan 	/* list of multicast physical addresses joined on this ill */
18267f125a53SRavi Chandra Nallan 	multiphysaddr_t *ill_mphysaddr_list;
18277c478bd9Sstevel@tonic-gate } ill_t;
18287c478bd9Sstevel@tonic-gate 
1829968d2fd1Ssowmini /*
1830384ad179Ssowmini  * ILL_FREE_OK() means that there are no incoming pointer references
1831968d2fd1Ssowmini  * to the ill.
1832968d2fd1Ssowmini  */
1833968d2fd1Ssowmini #define	ILL_FREE_OK(ill)					\
1834384ad179Ssowmini 	((ill)->ill_ire_cnt == 0 && (ill)->ill_ilm_cnt == 0 &&	\
1835bd670b35SErik Nordmark 	(ill)->ill_ncec_cnt == 0 && (ill)->ill_nce_cnt == 0)
1836968d2fd1Ssowmini 
1837968d2fd1Ssowmini /*
1838bd670b35SErik Nordmark  * An ipif/ill can be marked down only when the ire and ncec references
1839968d2fd1Ssowmini  * to that ipif/ill goes to zero. ILL_DOWN_OK() is a necessary condition
1840968d2fd1Ssowmini  * quiescence checks. See comments above IPIF_DOWN_OK for details
1841968d2fd1Ssowmini  * on why ires and nces are selectively considered for this macro.
1842968d2fd1Ssowmini  */
1843bd670b35SErik Nordmark #define	ILL_DOWN_OK(ill)					\
1844bd670b35SErik Nordmark 	(ill->ill_ire_cnt == 0 && ill->ill_ncec_cnt == 0 &&	\
1845bd670b35SErik Nordmark 	ill->ill_nce_cnt == 0)
1846968d2fd1Ssowmini 
18477c478bd9Sstevel@tonic-gate /*
18487c478bd9Sstevel@tonic-gate  * The following table lists the protection levels of the various members
18497c478bd9Sstevel@tonic-gate  * of the ill_t. Same notation as that used for ipif_t above is used.
18507c478bd9Sstevel@tonic-gate  *
18517c478bd9Sstevel@tonic-gate  *				Write			Read
18527c478bd9Sstevel@tonic-gate  *
18537c478bd9Sstevel@tonic-gate  * ill_ifptr			ill_g_lock + s		Write once
18547c478bd9Sstevel@tonic-gate  * ill_rq			ipsq			Write once
18557c478bd9Sstevel@tonic-gate  * ill_wq			ipsq			Write once
18567c478bd9Sstevel@tonic-gate  *
18577c478bd9Sstevel@tonic-gate  * ill_error			ipsq			None
18587c478bd9Sstevel@tonic-gate  * ill_ipif			ill_g_lock + ipsq	ill_g_lock OR ipsq
18598df01f76Smeem  * ill_ipif_up_count		ill_lock + ipsq		ill_lock OR ipsq
1860bd670b35SErik Nordmark  * ill_max_frag			ill_lock		ill_lock
1861bd670b35SErik Nordmark  * ill_current_frag		ill_lock		ill_lock
18627c478bd9Sstevel@tonic-gate  *
1863b051ecf6Smeem  * ill_name			ill_g_lock + ipsq	Write once
1864b051ecf6Smeem  * ill_name_length		ill_g_lock + ipsq	Write once
18657c478bd9Sstevel@tonic-gate  * ill_ndd_name			ipsq			Write once
18667c478bd9Sstevel@tonic-gate  * ill_net_type			ipsq			Write once
1867b051ecf6Smeem  * ill_ppa			ill_g_lock + ipsq	Write once
18687c478bd9Sstevel@tonic-gate  * ill_sap			ipsq + down ill		Write once
18697c478bd9Sstevel@tonic-gate  * ill_sap_length		ipsq + down ill		Write once
18707c478bd9Sstevel@tonic-gate  * ill_phys_addr_length		ipsq + down ill		Write once
18717c478bd9Sstevel@tonic-gate  *
18727c478bd9Sstevel@tonic-gate  * ill_bcast_addr_length	ipsq			ipsq
18737c478bd9Sstevel@tonic-gate  * ill_mactype			ipsq			ipsq
18747c478bd9Sstevel@tonic-gate  * ill_frag_ptr			ipsq			ipsq
18757c478bd9Sstevel@tonic-gate  *
18767c478bd9Sstevel@tonic-gate  * ill_frag_timer_id		ill_lock		ill_lock
18777c478bd9Sstevel@tonic-gate  * ill_frag_hash_tbl		ipsq			up ill
1878bd670b35SErik Nordmark  * ill_ilm			ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1879bd670b35SErik Nordmark  * ill_global_timer		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1880bd670b35SErik Nordmark  * ill_mcast_type		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1881bd670b35SErik Nordmark  * ill_mcast_v1_time		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1882bd670b35SErik Nordmark  * ill_mcast_v2_time		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1883bd670b35SErik Nordmark  * ill_mcast_v1_tset		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1884bd670b35SErik Nordmark  * ill_mcast_v2_tset		ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1885bd670b35SErik Nordmark  * ill_mcast_rv			ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1886bd670b35SErik Nordmark  * ill_mcast_qi			ill_mcast_lock(WRITER)	ill_mcast_lock(READER)
1887bd670b35SErik Nordmark  *
18887c478bd9Sstevel@tonic-gate  * ill_down_mp			ipsq			ipsq
18898df01f76Smeem  * ill_dlpi_deferred		ill_lock		ill_lock
18907571834aSThirumalai Srinivasan  * ill_dlpi_pending		ipsq + ill_lock		ipsq or ill_lock or
18917571834aSThirumalai Srinivasan  *							absence of ipsq writer.
1892b051ecf6Smeem  * ill_phys_addr_mp		ipsq + down ill		only when ill is up
1893bd670b35SErik Nordmark  * ill_mcast_deferred		ill_lock		ill_lock
1894b051ecf6Smeem  * ill_phys_addr		ipsq + down ill		only when ill is up
18952b24ab6bSSebastien Roy  * ill_dest_addr_mp		ipsq + down ill		only when ill is up
18962b24ab6bSSebastien Roy  * ill_dest_addr		ipsq + down ill		only when ill is up
18977c478bd9Sstevel@tonic-gate  *
18987c478bd9Sstevel@tonic-gate  * ill_state_flags		ill_lock		ill_lock
18997c478bd9Sstevel@tonic-gate  * exclusive bit flags		ipsq_t			ipsq_t
19007c478bd9Sstevel@tonic-gate  * shared bit flags		ill_lock		ill_lock
19017c478bd9Sstevel@tonic-gate  *
1902bd670b35SErik Nordmark  * ill_muxid			ipsq			Not atomic
19037c478bd9Sstevel@tonic-gate  *
19047c478bd9Sstevel@tonic-gate  * ill_ipf_gen			Not atomic
19050a5d959fSgeorges  * ill_frag_count		atomics			atomics
19067c478bd9Sstevel@tonic-gate  * ill_type			ipsq + down ill		only when ill is up
19077c478bd9Sstevel@tonic-gate  * ill_dlpi_multicast_state	ill_lock		ill_lock
19087c478bd9Sstevel@tonic-gate  * ill_dlpi_fastpath_state	ill_lock		ill_lock
1909da14cebeSEric Cheng  * ill_dlpi_capab_state		ipsq			ipsq
19107c478bd9Sstevel@tonic-gate  * ill_max_hops			ipsq			Not atomic
19117c478bd9Sstevel@tonic-gate  *
1912bd670b35SErik Nordmark  * ill_mtu			ill_lock		None
19131eee170aSErik Nordmark  * ill_mc_mtu			ill_lock		None
19147c478bd9Sstevel@tonic-gate  *
1915e11c3f44Smeem  * ill_user_mtu			ipsq + ill_lock		ill_lock
19167c478bd9Sstevel@tonic-gate  * ill_reachable_time		ipsq + ill_lock		ill_lock
1917b051ecf6Smeem  * ill_reachable_retrans_time	ipsq + ill_lock		ill_lock
19187c478bd9Sstevel@tonic-gate  * ill_max_buf			ipsq + ill_lock		ill_lock
19197c478bd9Sstevel@tonic-gate  *
19207c478bd9Sstevel@tonic-gate  * Next 2 fields need ill_lock because of the get ioctls. They should not
19217c478bd9Sstevel@tonic-gate  * report partially updated results without executing in the ipsq.
19227c478bd9Sstevel@tonic-gate  * ill_token			ipsq + ill_lock		ill_lock
19237c478bd9Sstevel@tonic-gate  * ill_token_length		ipsq + ill_lock		ill_lock
19242b24ab6bSSebastien Roy  * ill_dest_token		ipsq + down ill		only when ill is up
19257c478bd9Sstevel@tonic-gate  * ill_xmit_count		ipsq + down ill		write once
19267c478bd9Sstevel@tonic-gate  * ill_ip6_mib			ipsq + down ill		only when ill is up
19277c478bd9Sstevel@tonic-gate  * ill_icmp6_mib		ipsq + down ill		only when ill is up
19287c478bd9Sstevel@tonic-gate  *
19297c478bd9Sstevel@tonic-gate  * ill_phyint			ipsq, ill_g_lock, ill_lock	Any of them
19307c478bd9Sstevel@tonic-gate  * ill_flags			ill_lock		ill_lock
1931b051ecf6Smeem  * ill_nd_lla_mp		ipsq + down ill		only when ill is up
1932b051ecf6Smeem  * ill_nd_lla			ipsq + down ill		only when ill is up
1933b051ecf6Smeem  * ill_nd_lla_len		ipsq + down ill		only when ill is up
19347c478bd9Sstevel@tonic-gate  * ill_phys_addr_pend		ipsq + down ill		only when ill is up
19357c478bd9Sstevel@tonic-gate  * ill_ifname_pending_err	ipsq			ipsq
1936b051ecf6Smeem  * ill_avl_byppa		ipsq, ill_g_lock	write once
19377c478bd9Sstevel@tonic-gate  *
19387c478bd9Sstevel@tonic-gate  * ill_fastpath_list		ill_lock		ill_lock
19397c478bd9Sstevel@tonic-gate  * ill_refcnt			ill_lock		ill_lock
1940384ad179Ssowmini  * ill_ire_cnt			ill_lock		ill_lock
19417c478bd9Sstevel@tonic-gate  * ill_cv			ill_lock		ill_lock
1942bd670b35SErik Nordmark  * ill_ncec_cnt			ill_lock		ill_lock
1943384ad179Ssowmini  * ill_nce_cnt			ill_lock		ill_lock
1944384ad179Ssowmini  * ill_ilm_cnt			ill_lock		ill_lock
1945e11c3f44Smeem  * ill_src_ipif			ill_g_lock		ill_g_lock
19467c478bd9Sstevel@tonic-gate  * ill_trace			ill_lock		ill_lock
19477c478bd9Sstevel@tonic-gate  * ill_usesrc_grp_next		ill_g_usesrc_lock	ill_g_usesrc_lock
1948e704a8f2Smeem  * ill_dhcpinit			atomics			atomics
1949da14cebeSEric Cheng  * ill_flownotify_mh		write once		write once
1950da14cebeSEric Cheng  * ill_capab_pending_cnt	ipsq			ipsq
1951bd670b35SErik Nordmark  * ill_ipallmulti_cnt		ill_lock		ill_lock
1952bd670b35SErik Nordmark  * ill_ipallmulti_ilm		ill_lock		ill_lock
1953bd670b35SErik Nordmark  * ill_saved_ire_mp		ill_saved_ire_lock	ill_saved_ire_lock
1954bd670b35SErik Nordmark  * ill_saved_ire_cnt		ill_saved_ire_lock	ill_saved_ire_lock
1955bd670b35SErik Nordmark  * ill_arl			???			???
1956bd670b35SErik Nordmark  * ill_ire_multicast		ipsq + quiescent	none
1957e11c3f44Smeem  * ill_bound_ipif		ipsq			ipsq
1958e11c3f44Smeem  * ill_actnode			ipsq + ipmp_lock	ipsq OR ipmp_lock
1959e11c3f44Smeem  * ill_grpnode			ipsq + ill_g_lock	ipsq OR ill_g_lock
1960e11c3f44Smeem  * ill_src_ipif			ill_g_lock		ill_g_lock
1961e11c3f44Smeem  * ill_move_ipif		ipsq			ipsq
1962e11c3f44Smeem  * ill_nom_cast			ipsq			ipsq OR advisory
1963e11c3f44Smeem  * ill_refresh_tid		ill_lock		ill_lock
1964e11c3f44Smeem  * ill_grp (for IPMP ill)	write once		write once
1965e11c3f44Smeem  * ill_grp (for underlying ill)	ipsq + ill_g_lock	ipsq OR ill_g_lock
1966f1c454b4SSowmini Varadhan  * ill_grp_pending		ill_mcast_serializer	ill_mcast_serializer
1967bd670b35SErik Nordmark  * ill_mrouter_cnt		atomics			atomics
19687f125a53SRavi Chandra Nallan  * ill_mphysaddr_list	ill_lock		ill_lock
1969e11c3f44Smeem  *
1970e11c3f44Smeem  * NOTE: It's OK to make heuristic decisions on an underlying interface
1971e11c3f44Smeem  *	 by using IS_UNDER_IPMP() or comparing ill_grp's raw pointer value.
19727c478bd9Sstevel@tonic-gate  */
19737c478bd9Sstevel@tonic-gate 
19747c478bd9Sstevel@tonic-gate /*
19757c478bd9Sstevel@tonic-gate  * For ioctl restart mechanism see ip_reprocess_ioctl()
19767c478bd9Sstevel@tonic-gate  */
19777c478bd9Sstevel@tonic-gate struct ip_ioctl_cmd_s;
19787c478bd9Sstevel@tonic-gate 
19797c478bd9Sstevel@tonic-gate typedef	int (*ifunc_t)(ipif_t *, struct sockaddr_in *, queue_t *, mblk_t *,
19807c478bd9Sstevel@tonic-gate     struct ip_ioctl_cmd_s *, void *);
19817c478bd9Sstevel@tonic-gate 
19827c478bd9Sstevel@tonic-gate typedef struct ip_ioctl_cmd_s {
19837c478bd9Sstevel@tonic-gate 	int	ipi_cmd;
19847c478bd9Sstevel@tonic-gate 	size_t	ipi_copyin_size;
19857c478bd9Sstevel@tonic-gate 	uint_t	ipi_flags;
19867c478bd9Sstevel@tonic-gate 	uint_t	ipi_cmd_type;
19877c478bd9Sstevel@tonic-gate 	ifunc_t	ipi_func;
19887c478bd9Sstevel@tonic-gate 	ifunc_t	ipi_func_restart;
19897c478bd9Sstevel@tonic-gate } ip_ioctl_cmd_t;
19907c478bd9Sstevel@tonic-gate 
19917c478bd9Sstevel@tonic-gate /*
19927c478bd9Sstevel@tonic-gate  * ipi_cmd_type:
19937c478bd9Sstevel@tonic-gate  *
19947c478bd9Sstevel@tonic-gate  * IF_CMD		1	old style ifreq cmd
19957c478bd9Sstevel@tonic-gate  * LIF_CMD		2	new style lifreq cmd
19962b24ab6bSSebastien Roy  * ARP_CMD		3	arpreq cmd
19972b24ab6bSSebastien Roy  * XARP_CMD		4	xarpreq cmd
19982b24ab6bSSebastien Roy  * MSFILT_CMD		5	multicast source filter cmd
19992b24ab6bSSebastien Roy  * MISC_CMD		6	misc cmd (not a more specific one above)
20007c478bd9Sstevel@tonic-gate  */
20017c478bd9Sstevel@tonic-gate 
20022b24ab6bSSebastien Roy enum { IF_CMD = 1, LIF_CMD, ARP_CMD, XARP_CMD, MSFILT_CMD, MISC_CMD };
20037c478bd9Sstevel@tonic-gate 
20047c478bd9Sstevel@tonic-gate #define	IPI_DONTCARE	0	/* For ioctl encoded values that don't matter */
20057c478bd9Sstevel@tonic-gate 
20067c478bd9Sstevel@tonic-gate /* Flag values in ipi_flags */
200798e93c29Smeem #define	IPI_PRIV	0x1	/* Root only command */
200898e93c29Smeem #define	IPI_MODOK	0x2	/* Permitted on mod instance of IP */
200998e93c29Smeem #define	IPI_WR		0x4	/* Need to grab writer access */
201098e93c29Smeem #define	IPI_GET_CMD	0x8	/* branch to mi_copyout on success */
2011e11c3f44Smeem /*	unused		0x10	*/
20127c478bd9Sstevel@tonic-gate #define	IPI_NULL_BCONT	0x20	/* ioctl has not data and hence no b_cont */
20137c478bd9Sstevel@tonic-gate 
20147c478bd9Sstevel@tonic-gate extern ip_ioctl_cmd_t	ip_ndx_ioctl_table[];
20157c478bd9Sstevel@tonic-gate extern ip_ioctl_cmd_t	ip_misc_ioctl_table[];
20167c478bd9Sstevel@tonic-gate extern int ip_ndx_ioctl_count;
20177c478bd9Sstevel@tonic-gate extern int ip_misc_ioctl_count;
20187c478bd9Sstevel@tonic-gate 
20197c478bd9Sstevel@tonic-gate /* Passed down by ARP to IP during I_PLINK/I_PUNLINK */
20207c478bd9Sstevel@tonic-gate typedef struct ipmx_s {
20217c478bd9Sstevel@tonic-gate 	char	ipmx_name[LIFNAMSIZ];		/* if name */
20227c478bd9Sstevel@tonic-gate 	uint_t
20237c478bd9Sstevel@tonic-gate 		ipmx_arpdev_stream : 1,		/* This is the arp stream */
20247c478bd9Sstevel@tonic-gate 		ipmx_notused : 31;
20257c478bd9Sstevel@tonic-gate } ipmx_t;
20267c478bd9Sstevel@tonic-gate 
20277c478bd9Sstevel@tonic-gate /*
20287c478bd9Sstevel@tonic-gate  * State for detecting if a driver supports certain features.
20297c478bd9Sstevel@tonic-gate  * Support for DL_ENABMULTI_REQ uses ill_dlpi_multicast_state.
20307c478bd9Sstevel@tonic-gate  * Support for DLPI M_DATA fastpath uses ill_dlpi_fastpath_state.
20317c478bd9Sstevel@tonic-gate  */
20324d876314Sja #define	IDS_UNKNOWN	0	/* No DLPI request sent */
20334d876314Sja #define	IDS_INPROGRESS	1	/* DLPI request sent */
20344d876314Sja #define	IDS_OK		2	/* DLPI request completed successfully */
20354d876314Sja #define	IDS_FAILED	3	/* DLPI request failed */
20367c478bd9Sstevel@tonic-gate 
2037da14cebeSEric Cheng /* Support for DL_CAPABILITY_REQ uses ill_dlpi_capab_state. */
2038da14cebeSEric Cheng enum {
2039da14cebeSEric Cheng 	IDCS_UNKNOWN,
2040da14cebeSEric Cheng 	IDCS_PROBE_SENT,
2041da14cebeSEric Cheng 	IDCS_OK,
2042da14cebeSEric Cheng 	IDCS_RESET_SENT,
2043da14cebeSEric Cheng 	IDCS_RENEG,
2044da14cebeSEric Cheng 	IDCS_FAILED
2045da14cebeSEric Cheng };
2046da14cebeSEric Cheng 
20477c478bd9Sstevel@tonic-gate /* Extended NDP Management Structure */
20487c478bd9Sstevel@tonic-gate typedef struct ipndp_s {
20497c478bd9Sstevel@tonic-gate 	ndgetf_t	ip_ndp_getf;
20507c478bd9Sstevel@tonic-gate 	ndsetf_t	ip_ndp_setf;
20517c478bd9Sstevel@tonic-gate 	caddr_t		ip_ndp_data;
20527c478bd9Sstevel@tonic-gate 	char		*ip_ndp_name;
20537c478bd9Sstevel@tonic-gate } ipndp_t;
20547c478bd9Sstevel@tonic-gate 
2055bd670b35SErik Nordmark /* IXA Notification types */
2056bd670b35SErik Nordmark typedef enum {
2057bd670b35SErik Nordmark 	IXAN_LSO,	/* LSO capability change */
2058bd670b35SErik Nordmark 	IXAN_PMTU,	/* PMTU change */
2059bd670b35SErik Nordmark 	IXAN_ZCOPY	/* ZEROCOPY capability change */
2060bd670b35SErik Nordmark } ixa_notify_type_t;
2061bd670b35SErik Nordmark 
2062bd670b35SErik Nordmark typedef uint_t ixa_notify_arg_t;
2063bd670b35SErik Nordmark 
2064bd670b35SErik Nordmark typedef	void	(*ixa_notify_t)(void *, ip_xmit_attr_t *ixa, ixa_notify_type_t,
2065bd670b35SErik Nordmark     ixa_notify_arg_t);
2066bd670b35SErik Nordmark 
2067bd670b35SErik Nordmark /*
2068bd670b35SErik Nordmark  * Attribute flags that are common to the transmit and receive attributes
2069bd670b35SErik Nordmark  */
2070bd670b35SErik Nordmark #define	IAF_IS_IPV4		0x80000000	/* ipsec_*_v4 */
2071bd670b35SErik Nordmark #define	IAF_TRUSTED_ICMP	0x40000000	/* ipsec_*_icmp_loopback */
2072bd670b35SErik Nordmark #define	IAF_NO_LOOP_ZONEID_SET	0x20000000	/* Zone that shouldn't have */
2073bd670b35SErik Nordmark 						/* a copy */
2074bd670b35SErik Nordmark #define	IAF_LOOPBACK_COPY	0x10000000	/* For multi and broadcast */
2075bd670b35SErik Nordmark 
2076bd670b35SErik Nordmark #define	IAF_MASK		0xf0000000	/* Flags that are common */
2077bd670b35SErik Nordmark 
2078bd670b35SErik Nordmark /*
2079bd670b35SErik Nordmark  * Transmit side attributes used between the transport protocols and IP as
2080bd670b35SErik Nordmark  * well as inside IP. It is also used to cache information in the conn_t i.e.
2081bd670b35SErik Nordmark  * replaces conn_ire and the IPsec caching in the conn_t.
2082bd670b35SErik Nordmark  */
2083bd670b35SErik Nordmark struct ip_xmit_attr_s {
2084bd670b35SErik Nordmark 	iaflags_t	ixa_flags;	/* IXAF_*. See below */
2085bd670b35SErik Nordmark 
2086bd670b35SErik Nordmark 	uint32_t	ixa_free_flags;	/* IXA_FREE_*. See below */
2087bd670b35SErik Nordmark 	uint32_t	ixa_refcnt;	/* Using atomics */
2088bd670b35SErik Nordmark 
2089bd670b35SErik Nordmark 	/*
2090bd670b35SErik Nordmark 	 * Always initialized independently of ixa_flags settings.
2091bd670b35SErik Nordmark 	 * Used by ip_xmit so we keep them up front for cache locality.
2092bd670b35SErik Nordmark 	 */
2093bd670b35SErik Nordmark 	uint32_t	ixa_xmit_hint;	/* For ECMP and GLD TX ring fanout */
2094bd670b35SErik Nordmark 	uint_t		ixa_pktlen;	/* Always set. For frag and stats */
2095bd670b35SErik Nordmark 	zoneid_t	ixa_zoneid;	/* Assumed always set */
2096bd670b35SErik Nordmark 
2097bd670b35SErik Nordmark 	/* Always set for conn_ip_output(); might be stale */
2098bd670b35SErik Nordmark 	/*
2099bd670b35SErik Nordmark 	 * Since TCP keeps the conn_t around past the process going away
2100bd670b35SErik Nordmark 	 * we need to use the "notr" (e.g, ire_refhold_notr) for ixa_ire,
2101bd670b35SErik Nordmark 	 * ixa_nce, and ixa_dce.
2102bd670b35SErik Nordmark 	 */
2103bd670b35SErik Nordmark 	ire_t		*ixa_ire;	/* Forwarding table entry */
2104bd670b35SErik Nordmark 	uint_t		ixa_ire_generation;
2105bd670b35SErik Nordmark 	nce_t		*ixa_nce;	/* Neighbor cache entry */
2106bd670b35SErik Nordmark 	dce_t		*ixa_dce;	/* Destination cache entry */
2107bd670b35SErik Nordmark 	uint_t		ixa_dce_generation;
2108bd670b35SErik Nordmark 	uint_t		ixa_src_generation;	/* If IXAF_VERIFY_SOURCE */
2109bd670b35SErik Nordmark 
2110bd670b35SErik Nordmark 	uint32_t	ixa_src_preferences;	/* prefs for src addr select */
2111bd670b35SErik Nordmark 	uint32_t	ixa_pmtu;		/* IXAF_VERIFY_PMTU */
2112bd670b35SErik Nordmark 
2113bd670b35SErik Nordmark 	/* Set by ULP if IXAF_VERIFY_PMTU; otherwise set by IP */
2114bd670b35SErik Nordmark 	uint32_t	ixa_fragsize;
2115bd670b35SErik Nordmark 
2116bd670b35SErik Nordmark 	int8_t		ixa_use_min_mtu;	/* IXAF_USE_MIN_MTU values */
2117bd670b35SErik Nordmark 
2118bd670b35SErik Nordmark 	pfirepostfrag_t	ixa_postfragfn;		/* Set internally in IP */
2119bd670b35SErik Nordmark 
2120bd670b35SErik Nordmark 	in6_addr_t	ixa_nexthop_v6;		/* IXAF_NEXTHOP_SET */
2121bd670b35SErik Nordmark #define	ixa_nexthop_v4	V4_PART_OF_V6(ixa_nexthop_v6)
2122bd670b35SErik Nordmark 
2123bd670b35SErik Nordmark 	zoneid_t	ixa_no_loop_zoneid;	/* IXAF_NO_LOOP_ZONEID_SET */
2124bd670b35SErik Nordmark 
2125bd670b35SErik Nordmark 	uint_t		ixa_scopeid;		/* For IPv6 link-locals */
2126bd670b35SErik Nordmark 
2127bd670b35SErik Nordmark 	uint_t		ixa_broadcast_ttl;	/* IXAF_BROACAST_TTL_SET */
2128bd670b35SErik Nordmark 
2129bd670b35SErik Nordmark 	uint_t		ixa_multicast_ttl;	/* Assumed set for multicast */
2130bd670b35SErik Nordmark 	uint_t		ixa_multicast_ifindex;	/* Assumed set for multicast */
2131bd670b35SErik Nordmark 	ipaddr_t	ixa_multicast_ifaddr;	/* Assumed set for multicast */
2132bd670b35SErik Nordmark 
2133bd670b35SErik Nordmark 	int		ixa_raw_cksum_offset;	/* If IXAF_SET_RAW_CKSUM */
2134bd670b35SErik Nordmark 
2135bd670b35SErik Nordmark 	uint32_t	ixa_ident;		/* For IPv6 fragment header */
2136bd670b35SErik Nordmark 
21379cd928feSAlan Maguire 	uint64_t	ixa_conn_id;		/* Used by DTrace */
2138bd670b35SErik Nordmark 	/*
2139bd670b35SErik Nordmark 	 * Cached LSO information.
2140bd670b35SErik Nordmark 	 */
2141bd670b35SErik Nordmark 	ill_lso_capab_t	ixa_lso_capab;		/* Valid when IXAF_LSO_CAPAB */
2142bd670b35SErik Nordmark 
2143bd670b35SErik Nordmark 	uint64_t	ixa_ipsec_policy_gen;	/* Generation from iph_gen */
2144bd670b35SErik Nordmark 	/*
2145bd670b35SErik Nordmark 	 * The following IPsec fields are only initialized when
2146bd670b35SErik Nordmark 	 * IXAF_IPSEC_SECURE is set. Otherwise they contain garbage.
2147bd670b35SErik Nordmark 	 */
2148bd670b35SErik Nordmark 	ipsec_latch_t	*ixa_ipsec_latch;	/* Just the ids */
2149bd670b35SErik Nordmark 	struct ipsa_s 	*ixa_ipsec_ah_sa;	/* Hard reference SA for AH */
2150bd670b35SErik Nordmark 	struct ipsa_s 	*ixa_ipsec_esp_sa;	/* Hard reference SA for ESP */
2151bd670b35SErik Nordmark 	struct ipsec_policy_s 	*ixa_ipsec_policy; /* why are we here? */
2152bd670b35SErik Nordmark 	struct ipsec_action_s	*ixa_ipsec_action; /* For reflected packets */
2153bd670b35SErik Nordmark 	ipsa_ref_t	ixa_ipsec_ref[2];	/* Soft reference to SA */
2154bd670b35SErik Nordmark 						/* 0: ESP, 1: AH */
2155bd670b35SErik Nordmark 
2156bd670b35SErik Nordmark 	/*
2157bd670b35SErik Nordmark 	 * The selectors here are potentially different than the SPD rule's
2158bd670b35SErik Nordmark 	 * selectors, and we need to have both available for IKEv2.
2159bd670b35SErik Nordmark 	 *
2160bd670b35SErik Nordmark 	 * NOTE: "Source" and "Dest" are w.r.t. outbound datagrams.  Ports can
2161bd670b35SErik Nordmark 	 *	 be zero, and the protocol number is needed to make the ports
2162bd670b35SErik Nordmark 	 *	 significant.
2163bd670b35SErik Nordmark 	 */
2164bd670b35SErik Nordmark 	uint16_t ixa_ipsec_src_port;	/* Source port number of d-gram. */
2165bd670b35SErik Nordmark 	uint16_t ixa_ipsec_dst_port;	/* Destination port number of d-gram. */
2166bd670b35SErik Nordmark 	uint8_t  ixa_ipsec_icmp_type;	/* ICMP type of d-gram */
2167bd670b35SErik Nordmark 	uint8_t  ixa_ipsec_icmp_code;	/* ICMP code of d-gram */
2168bd670b35SErik Nordmark 
2169bd670b35SErik Nordmark 	sa_family_t ixa_ipsec_inaf;	/* Inner address family */
2170bd670b35SErik Nordmark #define	IXA_MAX_ADDRLEN 4	/* Max addr len. (in 32-bit words) */
2171bd670b35SErik Nordmark 	uint32_t ixa_ipsec_insrc[IXA_MAX_ADDRLEN];	/* Inner src address */
2172bd670b35SErik Nordmark 	uint32_t ixa_ipsec_indst[IXA_MAX_ADDRLEN];	/* Inner dest address */
2173bd670b35SErik Nordmark 	uint8_t  ixa_ipsec_insrcpfx;	/* Inner source prefix */
2174bd670b35SErik Nordmark 	uint8_t  ixa_ipsec_indstpfx;	/* Inner destination prefix */
2175bd670b35SErik Nordmark 
2176bd670b35SErik Nordmark 	uint8_t ixa_ipsec_proto;	/* IP protocol number for d-gram. */
2177bd670b35SErik Nordmark 
2178bd670b35SErik Nordmark 	/* Always initialized independently of ixa_flags settings */
2179bd670b35SErik Nordmark 	uint_t		ixa_ifindex;	/* Assumed always set */
2180bd670b35SErik Nordmark 	uint16_t	ixa_ip_hdr_length; /* Points to ULP header */
2181bd670b35SErik Nordmark 	uint8_t		ixa_protocol;	/* Protocol number for ULP cksum */
2182bd670b35SErik Nordmark 	ts_label_t	*ixa_tsl;	/* Always set. NULL if not TX */
2183bd670b35SErik Nordmark 	ip_stack_t	*ixa_ipst;	/* Always set */
2184bd670b35SErik Nordmark 	uint32_t	ixa_extra_ident; /* Set if LSO */
2185bd670b35SErik Nordmark 	cred_t		*ixa_cred;	/* For getpeerucred */
2186bd670b35SErik Nordmark 	pid_t		ixa_cpid;	/* For getpeerucred */
2187bd670b35SErik Nordmark 
2188bd670b35SErik Nordmark #ifdef DEBUG
2189bd670b35SErik Nordmark 	kthread_t	*ixa_curthread;	/* For serialization assert */
2190bd670b35SErik Nordmark #endif
2191bd670b35SErik Nordmark 	squeue_t	*ixa_sqp;	/* Set from conn_sqp as a hint */
2192bd670b35SErik Nordmark 	uintptr_t	ixa_cookie;	/* cookie to use for tx flow control */
2193bd670b35SErik Nordmark 
2194bd670b35SErik Nordmark 	/*
2195bd670b35SErik Nordmark 	 * Must be set by ULP if any of IXAF_VERIFY_LSO, IXAF_VERIFY_PMTU,
2196bd670b35SErik Nordmark 	 * or IXAF_VERIFY_ZCOPY is set.
2197bd670b35SErik Nordmark 	 */
2198bd670b35SErik Nordmark 	ixa_notify_t	ixa_notify;	/* Registered upcall notify function */
2199bd670b35SErik Nordmark 	void		*ixa_notify_cookie; /* ULP cookie for ixa_notify */
22007c6d7024SJerry Jelinek 
22017c6d7024SJerry Jelinek 	uint_t		ixa_tcpcleanup;	/* Used by conn_ixa_cleanup */
2202bd670b35SErik Nordmark };
2203bd670b35SErik Nordmark 
2204bd670b35SErik Nordmark /*
2205bd670b35SErik Nordmark  * Flags to indicate which transmit attributes are set.
2206bd670b35SErik Nordmark  * Split into "xxx_SET" ones which indicate that the "xxx" field it set, and
2207bd670b35SErik Nordmark  * single flags.
2208bd670b35SErik Nordmark  */
2209bd670b35SErik Nordmark #define	IXAF_REACH_CONF		0x00000001	/* Reachability confirmation */
2210bd670b35SErik Nordmark #define	IXAF_BROADCAST_TTL_SET	0x00000002	/* ixa_broadcast_ttl valid */
2211bd670b35SErik Nordmark #define	IXAF_SET_SOURCE		0x00000004	/* Replace if broadcast */
2212bd670b35SErik Nordmark #define	IXAF_USE_MIN_MTU	0x00000008	/* IPV6_USE_MIN_MTU */
2213bd670b35SErik Nordmark 
2214bd670b35SErik Nordmark #define	IXAF_DONTFRAG		0x00000010	/* IP*_DONTFRAG */
2215bd670b35SErik Nordmark #define	IXAF_VERIFY_PMTU	0x00000020	/* ixa_pmtu/ixa_fragsize set */
2216bd670b35SErik Nordmark #define	IXAF_PMTU_DISCOVERY	0x00000040	/* Create/use PMTU state */
2217bd670b35SErik Nordmark #define	IXAF_MULTICAST_LOOP	0x00000080	/* IP_MULTICAST_LOOP */
2218bd670b35SErik Nordmark 
2219bd670b35SErik Nordmark #define	IXAF_IPSEC_SECURE	0x00000100	/* Need IPsec processing */
2220bd670b35SErik Nordmark #define	IXAF_UCRED_TSL		0x00000200	/* ixa_tsl from SCM_UCRED */
2221bd670b35SErik Nordmark #define	IXAF_DONTROUTE		0x00000400	/* SO_DONTROUTE */
2222bd670b35SErik Nordmark #define	IXAF_NO_IPSEC		0x00000800	/* Ignore policy */
2223bd670b35SErik Nordmark 
2224bd670b35SErik Nordmark #define	IXAF_PMTU_TOO_SMALL	0x00001000	/* PMTU too small */
2225bd670b35SErik Nordmark #define	IXAF_SET_ULP_CKSUM	0x00002000	/* Calculate ULP checksum */
2226bd670b35SErik Nordmark #define	IXAF_VERIFY_SOURCE	0x00004000	/* Check that source is ok */
2227bd670b35SErik Nordmark #define	IXAF_NEXTHOP_SET	0x00008000	/* ixa_nexthop set */
2228bd670b35SErik Nordmark 
2229bd670b35SErik Nordmark #define	IXAF_PMTU_IPV4_DF	0x00010000	/* Set IPv4 DF */
2230bd670b35SErik Nordmark #define	IXAF_NO_DEV_FLOW_CTL	0x00020000	/* Protocol needs no flow ctl */
2231bd670b35SErik Nordmark #define	IXAF_NO_TTL_CHANGE	0x00040000	/* Internal to IP */
2232bd670b35SErik Nordmark #define	IXAF_IPV6_ADD_FRAGHDR	0x00080000	/* Add fragment header */
2233bd670b35SErik Nordmark 
2234bd670b35SErik Nordmark #define	IXAF_IPSEC_TUNNEL	0x00100000	/* Tunnel mode */
2235bd670b35SErik Nordmark #define	IXAF_NO_PFHOOK		0x00200000	/* Skip xmit pfhook */
2236bd670b35SErik Nordmark #define	IXAF_NO_TRACE		0x00400000	/* When back from ARP/ND */
2237bd670b35SErik Nordmark #define	IXAF_SCOPEID_SET	0x00800000	/* ixa_scopeid set */
2238bd670b35SErik Nordmark 
2239bd670b35SErik Nordmark #define	IXAF_MULTIRT_MULTICAST	0x01000000	/* MULTIRT for multicast */
2240bd670b35SErik Nordmark #define	IXAF_NO_HW_CKSUM	0x02000000	/* Force software cksum */
2241bd670b35SErik Nordmark #define	IXAF_SET_RAW_CKSUM	0x04000000	/* Use ixa_raw_cksum_offset */
2242bd670b35SErik Nordmark #define	IXAF_IPSEC_GLOBAL_POLICY 0x08000000	/* Policy came from global */
2243bd670b35SErik Nordmark 
2244bd670b35SErik Nordmark /* Note the following uses bits 0x10000000 through 0x80000000 */
2245bd670b35SErik Nordmark #define	IXAF_IS_IPV4		IAF_IS_IPV4
2246bd670b35SErik Nordmark #define	IXAF_TRUSTED_ICMP	IAF_TRUSTED_ICMP
2247bd670b35SErik Nordmark #define	IXAF_NO_LOOP_ZONEID_SET	IAF_NO_LOOP_ZONEID_SET
2248bd670b35SErik Nordmark #define	IXAF_LOOPBACK_COPY	IAF_LOOPBACK_COPY
2249bd670b35SErik Nordmark 
2250bd670b35SErik Nordmark /* Note: use the upper 32 bits */
2251bd670b35SErik Nordmark #define	IXAF_VERIFY_LSO		0x100000000	/* Check LSO capability */
2252bd670b35SErik Nordmark #define	IXAF_LSO_CAPAB		0x200000000	/* Capable of LSO */
2253bd670b35SErik Nordmark #define	IXAF_VERIFY_ZCOPY	0x400000000	/* Check Zero Copy capability */
2254bd670b35SErik Nordmark #define	IXAF_ZCOPY_CAPAB	0x800000000	/* Capable of ZEROCOPY */
2255bd670b35SErik Nordmark 
2256bd670b35SErik Nordmark /*
2257bd670b35SErik Nordmark  * The normal flags for sending packets e.g., icmp errors
2258bd670b35SErik Nordmark  */
225944b099c4SSowmini Varadhan #define	IXAF_BASIC_SIMPLE_V4	\
226044b099c4SSowmini Varadhan 	(IXAF_SET_ULP_CKSUM | IXAF_IS_IPV4 | IXAF_VERIFY_SOURCE)
226144b099c4SSowmini Varadhan #define	IXAF_BASIC_SIMPLE_V6	(IXAF_SET_ULP_CKSUM | IXAF_VERIFY_SOURCE)
2262bd670b35SErik Nordmark 
2263bd670b35SErik Nordmark /*
2264bd670b35SErik Nordmark  * Normally these fields do not have a hold. But in some cases they do, for
2265bd670b35SErik Nordmark  * instance when we've gone through ip_*_attr_to/from_mblk.
2266bd670b35SErik Nordmark  * We use ixa_free_flags to indicate that they have a hold and need to be
2267bd670b35SErik Nordmark  * released on cleanup.
2268bd670b35SErik Nordmark  */
2269bd670b35SErik Nordmark #define	IXA_FREE_CRED		0x00000001	/* ixa_cred needs to be rele */
2270bd670b35SErik Nordmark #define	IXA_FREE_TSL		0x00000002	/* ixa_tsl needs to be rele */
2271bd670b35SErik Nordmark 
22727c6d7024SJerry Jelinek /*
22737c6d7024SJerry Jelinek  * Trivial state machine used to synchronize IXA cleanup for TCP connections.
22747c6d7024SJerry Jelinek  * See conn_ixa_cleanup().
22757c6d7024SJerry Jelinek  */
22767c6d7024SJerry Jelinek #define	IXATC_IDLE		0x00000000
22777c6d7024SJerry Jelinek #define	IXATC_INPROGRESS	0x00000001
22787c6d7024SJerry Jelinek #define	IXATC_COMPLETE		0x00000002
22797c6d7024SJerry Jelinek 
2280bd670b35SErik Nordmark /*
2281bd670b35SErik Nordmark  * Simplistic way to set the ixa_xmit_hint for locally generated traffic
2282bd670b35SErik Nordmark  * and forwarded traffic. The shift amount are based on the size of the
2283bd670b35SErik Nordmark  * structs to discard the low order bits which don't have much if any variation
2284bd670b35SErik Nordmark  * (coloring in kmem_cache_alloc might provide some variation).
2285bd670b35SErik Nordmark  *
2286bd670b35SErik Nordmark  * Basing the locally generated hint on the address of the conn_t means that
2287bd670b35SErik Nordmark  * the packets from the same socket/connection do not get reordered.
2288bd670b35SErik Nordmark  * Basing the hint for forwarded traffic on the ill_ring_t means that
2289bd670b35SErik Nordmark  * packets from the same NIC+ring are likely to use the same outbound ring
2290bd670b35SErik Nordmark  * hence we get low contention on the ring in the transmitting driver.
2291bd670b35SErik Nordmark  */
2292bd670b35SErik Nordmark #define	CONN_TO_XMIT_HINT(connp)	((uint32_t)(((uintptr_t)connp) >> 11))
2293bd670b35SErik Nordmark #define	ILL_RING_TO_XMIT_HINT(ring)	((uint32_t)(((uintptr_t)ring) >> 7))
2294bd670b35SErik Nordmark 
2295bd670b35SErik Nordmark /*
2296bd670b35SErik Nordmark  * IP set Destination Flags used by function ip_set_destination,
2297bd670b35SErik Nordmark  * ip_attr_connect, and conn_connect.
2298bd670b35SErik Nordmark  */
2299bd670b35SErik Nordmark #define	IPDF_ALLOW_MCBC		0x1	/* Allow multi/broadcast */
2300bd670b35SErik Nordmark #define	IPDF_VERIFY_DST		0x2	/* Verify destination addr */
2301bd670b35SErik Nordmark #define	IPDF_SELECT_SRC		0x4	/* Select source address */
2302bd670b35SErik Nordmark #define	IPDF_LSO		0x8	/* Try LSO */
2303bd670b35SErik Nordmark #define	IPDF_IPSEC		0x10	/* Set IPsec policy */
2304bd670b35SErik Nordmark #define	IPDF_ZONE_IS_GLOBAL	0x20	/* From conn_zone_is_global */
2305bd670b35SErik Nordmark #define	IPDF_ZCOPY		0x40	/* Try ZEROCOPY */
2306bd670b35SErik Nordmark #define	IPDF_UNIQUE_DCE		0x80	/* Get a per-destination DCE */
2307bd670b35SErik Nordmark 
2308bd670b35SErik Nordmark /*
2309bd670b35SErik Nordmark  * Receive side attributes used between the transport protocols and IP as
2310bd670b35SErik Nordmark  * well as inside IP.
2311bd670b35SErik Nordmark  */
2312bd670b35SErik Nordmark struct ip_recv_attr_s {
2313bd670b35SErik Nordmark 	iaflags_t	ira_flags;	/* See below */
2314bd670b35SErik Nordmark 
2315bd670b35SErik Nordmark 	uint32_t	ira_free_flags;	/* IRA_FREE_*. See below */
2316bd670b35SErik Nordmark 
2317bd670b35SErik Nordmark 	/*
2318bd670b35SErik Nordmark 	 * This is a hint for TCP SYN packets.
2319bd670b35SErik Nordmark 	 * Always initialized independently of ira_flags settings
2320bd670b35SErik Nordmark 	 */
2321bd670b35SErik Nordmark 	squeue_t	*ira_sqp;
2322bd670b35SErik Nordmark 	ill_rx_ring_t	*ira_ring;	/* Internal to IP */
2323bd670b35SErik Nordmark 
2324bd670b35SErik Nordmark 	/* For ip_accept_tcp when IRAF_TARGET_SQP is set */
2325bd670b35SErik Nordmark 	squeue_t	*ira_target_sqp;
2326bd670b35SErik Nordmark 	mblk_t		*ira_target_sqp_mp;
2327bd670b35SErik Nordmark 
2328bd670b35SErik Nordmark 	/* Always initialized independently of ira_flags settings */
2329bd670b35SErik Nordmark 	uint32_t	ira_xmit_hint;	/* For ECMP and GLD TX ring fanout */
2330bd670b35SErik Nordmark 	zoneid_t	ira_zoneid;	/* ALL_ZONES unless local delivery */
2331bd670b35SErik Nordmark 	uint_t		ira_pktlen;	/* Always set. For frag and stats */
2332bd670b35SErik Nordmark 	uint16_t	ira_ip_hdr_length; /* Points to ULP header */
2333bd670b35SErik Nordmark 	uint8_t		ira_protocol;	/* Protocol number for ULP cksum */
2334bd670b35SErik Nordmark 	uint_t		ira_rifindex;	/* Received ifindex */
2335bd670b35SErik Nordmark 	uint_t		ira_ruifindex;	/* Received upper ifindex */
2336bd670b35SErik Nordmark 	ts_label_t	*ira_tsl;	/* Always set. NULL if not TX */
2337bd670b35SErik Nordmark 	/*
2338bd670b35SErik Nordmark 	 * ira_rill and ira_ill is set inside IP, but not when conn_recv is
2339bd670b35SErik Nordmark 	 * called; ULPs should use ira_ruifindex instead.
2340bd670b35SErik Nordmark 	 */
2341bd670b35SErik Nordmark 	ill_t		*ira_rill;	/* ill where packet came */
2342bd670b35SErik Nordmark 	ill_t		*ira_ill;	/* ill where IP address hosted */
2343bd670b35SErik Nordmark 	cred_t		*ira_cred;	/* For getpeerucred */
2344bd670b35SErik Nordmark 	pid_t		ira_cpid;	/* For getpeerucred */
2345bd670b35SErik Nordmark 
2346bd670b35SErik Nordmark 	/* Used when IRAF_VERIFIED_SRC is set; this source was ok */
2347bd670b35SErik Nordmark 	ipaddr_t	ira_verified_src;
2348bd670b35SErik Nordmark 
2349bd670b35SErik Nordmark 	/*
2350bd670b35SErik Nordmark 	 * The following IPsec fields are only initialized when
2351bd670b35SErik Nordmark 	 * IRAF_IPSEC_SECURE is set. Otherwise they contain garbage.
2352bd670b35SErik Nordmark 	 */
2353bd670b35SErik Nordmark 	struct ipsec_action_s *ira_ipsec_action; /* how we made it in.. */
2354bd670b35SErik Nordmark 	struct ipsa_s 	*ira_ipsec_ah_sa;	/* SA for AH */
2355bd670b35SErik Nordmark 	struct ipsa_s 	*ira_ipsec_esp_sa;	/* SA for ESP */
2356bd670b35SErik Nordmark 
2357bd670b35SErik Nordmark 	ipaddr_t	ira_mroute_tunnel;	/* IRAF_MROUTE_TUNNEL_SET */
2358bd670b35SErik Nordmark 
2359bd670b35SErik Nordmark 	zoneid_t	ira_no_loop_zoneid;	/* IRAF_NO_LOOP_ZONEID_SET */
2360bd670b35SErik Nordmark 
2361bd670b35SErik Nordmark 	uint32_t	ira_esp_udp_ports;	/* IRAF_ESP_UDP_PORTS */
2362bd670b35SErik Nordmark 
2363bd670b35SErik Nordmark 	/*
2364bd670b35SErik Nordmark 	 * For IP_RECVSLLA and ip_ndp_conflict/find_solicitation.
2365bd670b35SErik Nordmark 	 * Same size as max for sockaddr_dl
2366bd670b35SErik Nordmark 	 */
2367bd670b35SErik Nordmark #define	IRA_L2SRC_SIZE	244
2368bd670b35SErik Nordmark 	uint8_t		ira_l2src[IRA_L2SRC_SIZE];	/* If IRAF_L2SRC_SET */
2369bd670b35SErik Nordmark 
2370bd670b35SErik Nordmark 	/*
2371bd670b35SErik Nordmark 	 * Local handle that we use to do lazy setting of ira_l2src.
2372bd670b35SErik Nordmark 	 * We defer setting l2src until needed but we do before any
2373bd670b35SErik Nordmark 	 * ip_input pullupmsg or copymsg.
2374bd670b35SErik Nordmark 	 */
2375bd670b35SErik Nordmark 	struct mac_header_info_s *ira_mhip;	/* Could be NULL */
2376bd670b35SErik Nordmark };
2377bd670b35SErik Nordmark 
2378bd670b35SErik Nordmark /*
2379bd670b35SErik Nordmark  * Flags to indicate which receive attributes are set.
2380bd670b35SErik Nordmark  */
2381bd670b35SErik Nordmark #define	IRAF_SYSTEM_LABELED	0x00000001	/* is_system_labeled() */
2382bd670b35SErik Nordmark #define	IRAF_IPV4_OPTIONS	0x00000002	/* Performance */
2383bd670b35SErik Nordmark #define	IRAF_MULTICAST		0x00000004	/* Was multicast at L3 */
2384bd670b35SErik Nordmark #define	IRAF_BROADCAST		0x00000008	/* Was broadcast at L3 */
2385bd670b35SErik Nordmark #define	IRAF_MULTIBROADCAST	(IRAF_MULTICAST|IRAF_BROADCAST)
2386bd670b35SErik Nordmark 
2387bd670b35SErik Nordmark #define	IRAF_LOOPBACK		0x00000010	/* Looped back by IP */
2388bd670b35SErik Nordmark #define	IRAF_VERIFY_IP_CKSUM	0x00000020	/* Need to verify IP */
2389bd670b35SErik Nordmark #define	IRAF_VERIFY_ULP_CKSUM	0x00000040	/* Need to verify TCP,UDP,etc */
2390bd670b35SErik Nordmark #define	IRAF_SCTP_CSUM_ERR	0x00000080	/* sctp pkt has failed chksum */
2391bd670b35SErik Nordmark 
2392bd670b35SErik Nordmark #define	IRAF_IPSEC_SECURE	0x00000100	/* Passed AH and/or ESP */
2393bd670b35SErik Nordmark #define	IRAF_DHCP_UNICAST	0x00000200
2394bd670b35SErik Nordmark #define	IRAF_IPSEC_DECAPS	0x00000400	/* Was packet decapsulated */
2395bd670b35SErik Nordmark 					/* from a matching inner packet? */
2396bd670b35SErik Nordmark #define	IRAF_TARGET_SQP		0x00000800	/* ira_target_sqp is set */
2397bd670b35SErik Nordmark #define	IRAF_VERIFIED_SRC	0x00001000	/* ira_verified_src set */
2398bd670b35SErik Nordmark #define	IRAF_RSVP		0x00002000	/* RSVP packet for rsvpd */
2399bd670b35SErik Nordmark #define	IRAF_MROUTE_TUNNEL_SET	0x00004000	/* From ip_mroute_decap */
2400bd670b35SErik Nordmark #define	IRAF_PIM_REGISTER	0x00008000	/* From register_mforward */
2401bd670b35SErik Nordmark 
2402bd670b35SErik Nordmark #define	IRAF_TX_MAC_EXEMPTABLE	0x00010000	/* Allow MAC_EXEMPT readdown */
2403bd670b35SErik Nordmark #define	IRAF_TX_SHARED_ADDR	0x00020000	/* Arrived on ALL_ZONES addr */
2404bd670b35SErik Nordmark #define	IRAF_ESP_UDP_PORTS	0x00040000	/* NAT-traversal packet */
2405bd670b35SErik Nordmark #define	IRAF_NO_HW_CKSUM	0x00080000	/* Force software cksum */
2406bd670b35SErik Nordmark 
2407bd670b35SErik Nordmark #define	IRAF_ICMP_ERROR		0x00100000	/* Send to conn_recvicmp */
2408bd670b35SErik Nordmark #define	IRAF_ROUTER_ALERT	0x00200000	/* IPv6 router alert */
2409bd670b35SErik Nordmark #define	IRAF_L2SRC_SET		0x00400000	/* ira_l2src has been set */
2410bd670b35SErik Nordmark #define	IRAF_L2SRC_LOOPBACK	0x00800000	/* Came from us */
2411bd670b35SErik Nordmark 
2412bd670b35SErik Nordmark #define	IRAF_L2DST_MULTICAST	0x01000000	/* Multicast at L2 */
2413bd670b35SErik Nordmark #define	IRAF_L2DST_BROADCAST	0x02000000	/* Broadcast at L2 */
2414bd670b35SErik Nordmark /* Unused 0x04000000 */
2415bd670b35SErik Nordmark /* Unused 0x08000000 */
2416bd670b35SErik Nordmark 
2417bd670b35SErik Nordmark /* Below starts with 0x10000000 */
2418bd670b35SErik Nordmark #define	IRAF_IS_IPV4		IAF_IS_IPV4
2419bd670b35SErik Nordmark #define	IRAF_TRUSTED_ICMP	IAF_TRUSTED_ICMP
2420bd670b35SErik Nordmark #define	IRAF_NO_LOOP_ZONEID_SET	IAF_NO_LOOP_ZONEID_SET
2421bd670b35SErik Nordmark #define	IRAF_LOOPBACK_COPY	IAF_LOOPBACK_COPY
2422bd670b35SErik Nordmark 
2423bd670b35SErik Nordmark /*
2424bd670b35SErik Nordmark  * Normally these fields do not have a hold. But in some cases they do, for
2425bd670b35SErik Nordmark  * instance when we've gone through ip_*_attr_to/from_mblk.
2426bd670b35SErik Nordmark  * We use ira_free_flags to indicate that they have a hold and need to be
2427bd670b35SErik Nordmark  * released on cleanup.
2428bd670b35SErik Nordmark  */
2429bd670b35SErik Nordmark #define	IRA_FREE_CRED		0x00000001	/* ira_cred needs to be rele */
2430bd670b35SErik Nordmark #define	IRA_FREE_TSL		0x00000002	/* ira_tsl needs to be rele */
2431bd670b35SErik Nordmark 
2432bd670b35SErik Nordmark /*
2433bd670b35SErik Nordmark  * Optional destination cache entry for path MTU information,
2434bd670b35SErik Nordmark  * and ULP metrics.
2435bd670b35SErik Nordmark  */
2436bd670b35SErik Nordmark struct dce_s {
2437bd670b35SErik Nordmark 	uint_t		dce_generation;	/* Changed since cached? */
2438bd670b35SErik Nordmark 	uint_t		dce_flags;	/* See below */
2439bd670b35SErik Nordmark 	uint_t		dce_ipversion;	/* IPv4/IPv6 version */
2440bd670b35SErik Nordmark 	uint32_t	dce_pmtu;	/* Path MTU if DCEF_PMTU */
2441bd670b35SErik Nordmark 	uint32_t	dce_ident;	/* Per destination IP ident. */
2442bd670b35SErik Nordmark 	iulp_t		dce_uinfo;	/* Metrics if DCEF_UINFO */
2443bd670b35SErik Nordmark 
2444bd670b35SErik Nordmark 	struct dce_s	*dce_next;
2445bd670b35SErik Nordmark 	struct dce_s	**dce_ptpn;
2446bd670b35SErik Nordmark 	struct dcb_s	*dce_bucket;
2447bd670b35SErik Nordmark 
2448bd670b35SErik Nordmark 	union {
2449bd670b35SErik Nordmark 		in6_addr_t	dceu_v6addr;
2450bd670b35SErik Nordmark 		ipaddr_t	dceu_v4addr;
2451bd670b35SErik Nordmark 	} dce_u;
2452bd670b35SErik Nordmark #define	dce_v4addr	dce_u.dceu_v4addr
2453bd670b35SErik Nordmark #define	dce_v6addr	dce_u.dceu_v6addr
2454bd670b35SErik Nordmark 	/* Note that for IPv6+IPMP we use the ifindex for the upper interface */
2455bd670b35SErik Nordmark 	uint_t		dce_ifindex;	/* For IPv6 link-locals */
2456bd670b35SErik Nordmark 
2457bd670b35SErik Nordmark 	kmutex_t	dce_lock;
2458bd670b35SErik Nordmark 	uint_t		dce_refcnt;
2459bd670b35SErik Nordmark 	uint64_t	dce_last_change_time;	/* Path MTU. In seconds */
2460bd670b35SErik Nordmark 
2461bd670b35SErik Nordmark 	ip_stack_t	*dce_ipst;	/* Does not have a netstack_hold */
2462bd670b35SErik Nordmark };
2463bd670b35SErik Nordmark 
2464bd670b35SErik Nordmark /*
2465bd670b35SErik Nordmark  * Values for dce_generation.
2466bd670b35SErik Nordmark  *
2467bd670b35SErik Nordmark  * If a DCE has DCE_GENERATION_CONDEMNED, the last dce_refrele should delete
2468bd670b35SErik Nordmark  * it.
2469bd670b35SErik Nordmark  *
2470bd670b35SErik Nordmark  * DCE_GENERATION_VERIFY is never stored in dce_generation but it is
2471bd670b35SErik Nordmark  * stored in places that cache DCE (such as ixa_dce_generation).
2472bd670b35SErik Nordmark  * It is used as a signal that the cache is stale and needs to be reverified.
2473bd670b35SErik Nordmark  */
2474bd670b35SErik Nordmark #define	DCE_GENERATION_CONDEMNED	0
2475bd670b35SErik Nordmark #define	DCE_GENERATION_VERIFY		1
2476bd670b35SErik Nordmark #define	DCE_GENERATION_INITIAL		2
2477bd670b35SErik Nordmark #define	DCE_IS_CONDEMNED(dce) \
2478bd670b35SErik Nordmark 	((dce)->dce_generation == DCE_GENERATION_CONDEMNED)
2479bd670b35SErik Nordmark 
2480bd670b35SErik Nordmark 
2481bd670b35SErik Nordmark /*
2482bd670b35SErik Nordmark  * Values for ips_src_generation.
2483bd670b35SErik Nordmark  *
2484bd670b35SErik Nordmark  * SRC_GENERATION_VERIFY is never stored in ips_src_generation but it is
2485bd670b35SErik Nordmark  * stored in places that cache IREs (ixa_src_generation). It is used as a
2486bd670b35SErik Nordmark  * signal that the cache is stale and needs to be reverified.
2487bd670b35SErik Nordmark  */
2488bd670b35SErik Nordmark #define	SRC_GENERATION_VERIFY		0
2489bd670b35SErik Nordmark #define	SRC_GENERATION_INITIAL		1
2490bd670b35SErik Nordmark 
249145916cd2Sjpk /*
249245916cd2Sjpk  * The kernel stores security attributes of all gateways in a database made
249345916cd2Sjpk  * up of one or more tsol_gcdb_t elements.  Each tsol_gcdb_t contains the
249445916cd2Sjpk  * security-related credentials of the gateway.  More than one gateways may
249545916cd2Sjpk  * share entries in the database.
249645916cd2Sjpk  *
249745916cd2Sjpk  * The tsol_gc_t structure represents the gateway to credential association,
249845916cd2Sjpk  * and refers to an entry in the database.  One or more tsol_gc_t entities are
249945916cd2Sjpk  * grouped together to form one or more tsol_gcgrp_t, each representing the
250045916cd2Sjpk  * list of security attributes specific to the gateway.  A gateway may be
250145916cd2Sjpk  * associated with at most one credentials group.
250245916cd2Sjpk  */
250345916cd2Sjpk struct tsol_gcgrp_s;
250445916cd2Sjpk 
250545916cd2Sjpk extern uchar_t	ip6opt_ls;	/* TX IPv6 enabler */
250645916cd2Sjpk 
250745916cd2Sjpk /*
250845916cd2Sjpk  * Gateway security credential record.
250945916cd2Sjpk  */
251045916cd2Sjpk typedef struct tsol_gcdb_s {
251145916cd2Sjpk 	uint_t		gcdb_refcnt;	/* reference count */
251245916cd2Sjpk 	struct rtsa_s	gcdb_attr;	/* security attributes */
251345916cd2Sjpk #define	gcdb_mask	gcdb_attr.rtsa_mask
251445916cd2Sjpk #define	gcdb_doi	gcdb_attr.rtsa_doi
251545916cd2Sjpk #define	gcdb_slrange	gcdb_attr.rtsa_slrange
251645916cd2Sjpk } tsol_gcdb_t;
251745916cd2Sjpk 
251845916cd2Sjpk /*
251945916cd2Sjpk  * Gateway to credential association.
252045916cd2Sjpk  */
252145916cd2Sjpk typedef struct tsol_gc_s {
252245916cd2Sjpk 	uint_t		gc_refcnt;	/* reference count */
252345916cd2Sjpk 	struct tsol_gcgrp_s *gc_grp;	/* pointer to group */
252445916cd2Sjpk 	struct tsol_gc_s *gc_prev;	/* previous in list */
252545916cd2Sjpk 	struct tsol_gc_s *gc_next;	/* next in list */
252645916cd2Sjpk 	tsol_gcdb_t	*gc_db;		/* pointer to actual credentials */
252745916cd2Sjpk } tsol_gc_t;
252845916cd2Sjpk 
252945916cd2Sjpk /*
253045916cd2Sjpk  * Gateway credentials group address.
253145916cd2Sjpk  */
253245916cd2Sjpk typedef struct tsol_gcgrp_addr_s {
253345916cd2Sjpk 	int		ga_af;		/* address family */
253445916cd2Sjpk 	in6_addr_t	ga_addr;	/* IPv4 mapped or IPv6 address */
253545916cd2Sjpk } tsol_gcgrp_addr_t;
253645916cd2Sjpk 
253745916cd2Sjpk /*
253845916cd2Sjpk  * Gateway credentials group.
253945916cd2Sjpk  */
254045916cd2Sjpk typedef struct tsol_gcgrp_s {
254145916cd2Sjpk 	uint_t		gcgrp_refcnt;	/* reference count */
254245916cd2Sjpk 	krwlock_t	gcgrp_rwlock;	/* lock to protect following */
254345916cd2Sjpk 	uint_t		gcgrp_count;	/* number of credentials */
254445916cd2Sjpk 	tsol_gc_t	*gcgrp_head;	/* first credential in list */
254545916cd2Sjpk 	tsol_gc_t	*gcgrp_tail;	/* last credential in list */
254645916cd2Sjpk 	tsol_gcgrp_addr_t gcgrp_addr;	/* next-hop gateway address */
254745916cd2Sjpk } tsol_gcgrp_t;
254845916cd2Sjpk 
254945916cd2Sjpk extern kmutex_t gcgrp_lock;
255045916cd2Sjpk 
255145916cd2Sjpk #define	GC_REFRELE(p) {				\
255245916cd2Sjpk 	ASSERT((p)->gc_grp != NULL);		\
255345916cd2Sjpk 	rw_enter(&(p)->gc_grp->gcgrp_rwlock, RW_WRITER); \
255445916cd2Sjpk 	ASSERT((p)->gc_refcnt > 0);		\
255545916cd2Sjpk 	if (--((p)->gc_refcnt) == 0)		\
255645916cd2Sjpk 		gc_inactive(p);			\
255745916cd2Sjpk 	else					\
255845916cd2Sjpk 		rw_exit(&(p)->gc_grp->gcgrp_rwlock); \
255945916cd2Sjpk }
256045916cd2Sjpk 
256145916cd2Sjpk #define	GCGRP_REFHOLD(p) {			\
256245916cd2Sjpk 	mutex_enter(&gcgrp_lock);		\
256345916cd2Sjpk 	++((p)->gcgrp_refcnt);			\
256445916cd2Sjpk 	ASSERT((p)->gcgrp_refcnt != 0);		\
256545916cd2Sjpk 	mutex_exit(&gcgrp_lock);		\
256645916cd2Sjpk }
256745916cd2Sjpk 
256845916cd2Sjpk #define	GCGRP_REFRELE(p) {			\
256945916cd2Sjpk 	mutex_enter(&gcgrp_lock);		\
257045916cd2Sjpk 	ASSERT((p)->gcgrp_refcnt > 0);		\
257145916cd2Sjpk 	if (--((p)->gcgrp_refcnt) == 0)		\
257245916cd2Sjpk 		gcgrp_inactive(p);		\
257345916cd2Sjpk 	ASSERT(MUTEX_HELD(&gcgrp_lock));	\
257445916cd2Sjpk 	mutex_exit(&gcgrp_lock);		\
257545916cd2Sjpk }
257645916cd2Sjpk 
257745916cd2Sjpk /*
257845916cd2Sjpk  * IRE gateway security attributes structure, pointed to by tsol_ire_gw_secattr
257945916cd2Sjpk  */
258045916cd2Sjpk struct tsol_tnrhc;
258145916cd2Sjpk 
2582bd670b35SErik Nordmark struct tsol_ire_gw_secattr_s {
258345916cd2Sjpk 	kmutex_t	igsa_lock;	/* lock to protect following */
258445916cd2Sjpk 	struct tsol_tnrhc *igsa_rhc;	/* host entry for gateway */
258545916cd2Sjpk 	tsol_gc_t	*igsa_gc;	/* for prefix IREs */
2586bd670b35SErik Nordmark };
25877c478bd9Sstevel@tonic-gate 
2588c793af95Ssangeeta void irb_refrele_ftable(irb_t *);
25897c478bd9Sstevel@tonic-gate 
2590c793af95Ssangeeta extern struct kmem_cache *rt_entry_cache;
2591c793af95Ssangeeta 
25927c478bd9Sstevel@tonic-gate typedef struct ire4 {
25937c478bd9Sstevel@tonic-gate 	ipaddr_t ire4_mask;		/* Mask for matching this IRE. */
25947c478bd9Sstevel@tonic-gate 	ipaddr_t ire4_addr;		/* Address this IRE represents. */
2595bd670b35SErik Nordmark 	ipaddr_t ire4_gateway_addr;	/* Gateway including for IRE_ONLINK */
2596bd670b35SErik Nordmark 	ipaddr_t ire4_setsrc_addr;	/* RTF_SETSRC */
25977c478bd9Sstevel@tonic-gate } ire4_t;
25987c478bd9Sstevel@tonic-gate 
25997c478bd9Sstevel@tonic-gate typedef struct ire6 {
26007c478bd9Sstevel@tonic-gate 	in6_addr_t ire6_mask;		/* Mask for matching this IRE. */
26017c478bd9Sstevel@tonic-gate 	in6_addr_t ire6_addr;		/* Address this IRE represents. */
2602bd670b35SErik Nordmark 	in6_addr_t ire6_gateway_addr;	/* Gateway including for IRE_ONLINK */
2603bd670b35SErik Nordmark 	in6_addr_t ire6_setsrc_addr;	/* RTF_SETSRC */
26047c478bd9Sstevel@tonic-gate } ire6_t;
26057c478bd9Sstevel@tonic-gate 
26067c478bd9Sstevel@tonic-gate typedef union ire_addr {
26077c478bd9Sstevel@tonic-gate 	ire6_t	ire6_u;
26087c478bd9Sstevel@tonic-gate 	ire4_t	ire4_u;
26097c478bd9Sstevel@tonic-gate } ire_addr_u_t;
26107c478bd9Sstevel@tonic-gate 
2611bd670b35SErik Nordmark /*
2612bd670b35SErik Nordmark  * Internet Routing Entry
2613bd670b35SErik Nordmark  * When we have multiple identical IREs we logically add them by manipulating
2614bd670b35SErik Nordmark  * ire_identical_ref and ire_delete first decrements
2615bd670b35SErik Nordmark  * that and when it reaches 1 we know it is the last IRE.
2616bd670b35SErik Nordmark  * "identical" is defined as being the same for:
2617bd670b35SErik Nordmark  * ire_addr, ire_netmask, ire_gateway, ire_ill, ire_zoneid, and ire_type
2618bd670b35SErik Nordmark  * For instance, multiple IRE_BROADCASTs for the same subnet number are
2619bd670b35SErik Nordmark  * viewed as identical, and so are the IRE_INTERFACEs when there are
2620bd670b35SErik Nordmark  * multiple logical interfaces (on the same ill) with the same subnet prefix.
2621bd670b35SErik Nordmark  */
2622bd670b35SErik Nordmark struct ire_s {
26237c478bd9Sstevel@tonic-gate 	struct	ire_s	*ire_next;	/* The hash chain must be first. */
26247c478bd9Sstevel@tonic-gate 	struct	ire_s	**ire_ptpn;	/* Pointer to previous next. */
26257c478bd9Sstevel@tonic-gate 	uint32_t	ire_refcnt;	/* Number of references */
2626bd670b35SErik Nordmark 	ill_t		*ire_ill;
2627bd670b35SErik Nordmark 	uint32_t	ire_identical_ref; /* IRE_INTERFACE, IRE_BROADCAST */
26287c478bd9Sstevel@tonic-gate 	uchar_t		ire_ipversion;	/* IPv4/IPv6 version */
26297c478bd9Sstevel@tonic-gate 	ushort_t	ire_type;	/* Type of IRE */
2630bd670b35SErik Nordmark 	uint_t		ire_generation;	/* Generation including CONDEMNED */
26317c478bd9Sstevel@tonic-gate 	uint_t	ire_ib_pkt_count;	/* Inbound packets for ire_addr */
26327c478bd9Sstevel@tonic-gate 	uint_t	ire_ob_pkt_count;	/* Outbound packets to ire_addr */
26337c478bd9Sstevel@tonic-gate 	time_t	ire_create_time;	/* Time (in secs) IRE was created. */
26347c478bd9Sstevel@tonic-gate 	uint32_t	ire_flags;	/* flags related to route (RTF_*) */
2635c793af95Ssangeeta 	/*
2636bd670b35SErik Nordmark 	 * ire_testhidden is TRUE for INTERFACE IREs of IS_UNDER_IPMP(ill)
2637bd670b35SErik Nordmark 	 * interfaces
2638c793af95Ssangeeta 	 */
2639bd670b35SErik Nordmark 	boolean_t	ire_testhidden;
2640bd670b35SErik Nordmark 	pfirerecv_t	ire_recvfn;	/* Receive side handling */
2641bd670b35SErik Nordmark 	pfiresend_t	ire_sendfn;	/* Send side handling */
2642bd670b35SErik Nordmark 	pfirepostfrag_t	ire_postfragfn;	/* Bottom end of send handling */
2643bd670b35SErik Nordmark 
26447c478bd9Sstevel@tonic-gate 	uint_t		ire_masklen;	/* # bits in ire_mask{,_v6} */
26457c478bd9Sstevel@tonic-gate 	ire_addr_u_t	ire_u;		/* IPv4/IPv6 address info. */
26467c478bd9Sstevel@tonic-gate 
26477c478bd9Sstevel@tonic-gate 	irb_t		*ire_bucket;	/* Hash bucket when ire_ptphn is set */
26487c478bd9Sstevel@tonic-gate 	kmutex_t	ire_lock;
2649bd670b35SErik Nordmark 	clock_t		ire_last_used_time;	/* For IRE_LOCAL reception */
265045916cd2Sjpk 	tsol_ire_gw_secattr_t *ire_gw_secattr; /* gateway security attributes */
2651bd670b35SErik Nordmark 	zoneid_t	ire_zoneid;
2652bd670b35SErik Nordmark 
2653bd670b35SErik Nordmark 	/*
2654bd670b35SErik Nordmark 	 * Cached information of where to send packets that match this route.
2655bd670b35SErik Nordmark 	 * The ire_dep_* information is used to determine when ire_nce_cache
2656bd670b35SErik Nordmark 	 * needs to be updated.
2657bd670b35SErik Nordmark 	 * ire_nce_cache is the fastpath for the Neighbor Cache Entry
2658bd670b35SErik Nordmark 	 * for IPv6; arp info for IPv4
2659bd670b35SErik Nordmark 	 * Since this is a cache setup and torn down independently of
2660bd670b35SErik Nordmark 	 * applications we need to use nce_ref{rele,hold}_notr for it.
2661bd670b35SErik Nordmark 	 */
2662bd670b35SErik Nordmark 	nce_t		*ire_nce_cache;
2663bd670b35SErik Nordmark 
2664bd670b35SErik Nordmark 	/*
2665bd670b35SErik Nordmark 	 * Quick check whether the ire_type and ire_masklen indicates
2666bd670b35SErik Nordmark 	 * that the IRE can have ire_nce_cache set i.e., whether it is
2667bd670b35SErik Nordmark 	 * IRE_ONLINK and for a single destination.
2668bd670b35SErik Nordmark 	 */
2669bd670b35SErik Nordmark 	boolean_t	ire_nce_capable;
2670bd670b35SErik Nordmark 
2671c793af95Ssangeeta 	/*
2672bd670b35SErik Nordmark 	 * Dependency tracking so we can safely cache IRE and NCE pointers
2673bd670b35SErik Nordmark 	 * in offlink and onlink IREs.
2674bd670b35SErik Nordmark 	 * These are locked under the ips_ire_dep_lock rwlock. Write held
2675bd670b35SErik Nordmark 	 * when modifying the linkage.
2676bd670b35SErik Nordmark 	 * ire_dep_parent (Also chain towards IRE for nexthop)
2677bd670b35SErik Nordmark 	 * ire_dep_parent_generation: ire_generation of ire_dep_parent
2678bd670b35SErik Nordmark 	 * ire_dep_children (From parent to first child)
2679bd670b35SErik Nordmark 	 * ire_dep_sib_next (linked list of siblings)
2680bd670b35SErik Nordmark 	 * ire_dep_sib_ptpn (linked list of siblings)
2681bd670b35SErik Nordmark 	 *
2682bd670b35SErik Nordmark 	 * The parent has a ire_refhold on each child, and each child has
2683bd670b35SErik Nordmark 	 * an ire_refhold on its parent.
2684bd670b35SErik Nordmark 	 * Since ire_dep_parent is a cache setup and torn down independently of
2685bd670b35SErik Nordmark 	 * applications we need to use ire_ref{rele,hold}_notr for it.
2686c793af95Ssangeeta 	 */
2687bd670b35SErik Nordmark 	ire_t		*ire_dep_parent;
2688bd670b35SErik Nordmark 	ire_t		*ire_dep_children;
2689bd670b35SErik Nordmark 	ire_t		*ire_dep_sib_next;
2690bd670b35SErik Nordmark 	ire_t		**ire_dep_sib_ptpn;	/* Pointer to previous next */
2691bd670b35SErik Nordmark 	uint_t		ire_dep_parent_generation;
2692bd670b35SErik Nordmark 
2693bd670b35SErik Nordmark 	uint_t		ire_badcnt;	/* Number of times ND_UNREACHABLE */
2694bd670b35SErik Nordmark 	uint64_t	ire_last_badcnt;	/* In seconds */
2695bd670b35SErik Nordmark 
2696bd670b35SErik Nordmark 	/* ire_defense* and ire_last_used_time are only used on IRE_LOCALs */
269769bb4bb4Scarlsonj 	uint_t		ire_defense_count;	/* number of ARP conflicts */
269869bb4bb4Scarlsonj 	uint_t		ire_defense_time;	/* last time defended (secs) */
2699bd670b35SErik Nordmark 
270069bb4bb4Scarlsonj 	boolean_t	ire_trace_disable;	/* True when alloc fails */
27016a8288c7Scarlsonj 	ip_stack_t	*ire_ipst;	/* Does not have a netstack_hold */
2702bd670b35SErik Nordmark 	iulp_t		ire_metrics;
270344b099c4SSowmini Varadhan 	/*
270444b099c4SSowmini Varadhan 	 * default and prefix routes that are added without explicitly
270544b099c4SSowmini Varadhan 	 * specifying the interface are termed "unbound" routes, and will
270644b099c4SSowmini Varadhan 	 * have ire_unbound set to true.
270744b099c4SSowmini Varadhan 	 */
270844b099c4SSowmini Varadhan 	boolean_t	ire_unbound;
2709bd670b35SErik Nordmark };
27107c478bd9Sstevel@tonic-gate 
27117924222fSmeem /* IPv4 compatibility macros */
27127c478bd9Sstevel@tonic-gate #define	ire_mask		ire_u.ire4_u.ire4_mask
27137c478bd9Sstevel@tonic-gate #define	ire_addr		ire_u.ire4_u.ire4_addr
27147c478bd9Sstevel@tonic-gate #define	ire_gateway_addr	ire_u.ire4_u.ire4_gateway_addr
2715bd670b35SErik Nordmark #define	ire_setsrc_addr		ire_u.ire4_u.ire4_setsrc_addr
27167c478bd9Sstevel@tonic-gate 
27177c478bd9Sstevel@tonic-gate #define	ire_mask_v6		ire_u.ire6_u.ire6_mask
27187c478bd9Sstevel@tonic-gate #define	ire_addr_v6		ire_u.ire6_u.ire6_addr
27197c478bd9Sstevel@tonic-gate #define	ire_gateway_addr_v6	ire_u.ire6_u.ire6_gateway_addr
2720bd670b35SErik Nordmark #define	ire_setsrc_addr_v6	ire_u.ire6_u.ire6_setsrc_addr
27217c478bd9Sstevel@tonic-gate 
27227c478bd9Sstevel@tonic-gate /*
2723bd670b35SErik Nordmark  * Values for ire_generation.
2724bd670b35SErik Nordmark  *
2725bd670b35SErik Nordmark  * If an IRE is marked with IRE_IS_CONDEMNED, the last walker of
2726bd670b35SErik Nordmark  * the bucket should delete this IRE from this bucket.
2727bd670b35SErik Nordmark  *
2728bd670b35SErik Nordmark  * IRE_GENERATION_VERIFY is never stored in ire_generation but it is
2729bd670b35SErik Nordmark  * stored in places that cache IREs (such as ixa_ire_generation and
2730bd670b35SErik Nordmark  * ire_dep_parent_generation). It is used as a signal that the cache is
2731bd670b35SErik Nordmark  * stale and needs to be reverified.
27327c478bd9Sstevel@tonic-gate  */
2733bd670b35SErik Nordmark #define	IRE_GENERATION_CONDEMNED	0
2734bd670b35SErik Nordmark #define	IRE_GENERATION_VERIFY		1
2735bd670b35SErik Nordmark #define	IRE_GENERATION_INITIAL		2
2736bd670b35SErik Nordmark #define	IRE_IS_CONDEMNED(ire) \
2737bd670b35SErik Nordmark 	((ire)->ire_generation == IRE_GENERATION_CONDEMNED)
27387c478bd9Sstevel@tonic-gate 
2739bd670b35SErik Nordmark /* Convenient typedefs for sockaddrs */
2740bd670b35SErik Nordmark typedef	struct sockaddr_in	sin_t;
2741bd670b35SErik Nordmark typedef	struct sockaddr_in6	sin6_t;
27427c478bd9Sstevel@tonic-gate 
27437c478bd9Sstevel@tonic-gate /* Name/Value Descriptor. */
27447c478bd9Sstevel@tonic-gate typedef struct nv_s {
27457c478bd9Sstevel@tonic-gate 	uint64_t nv_value;
27467c478bd9Sstevel@tonic-gate 	char	*nv_name;
27477c478bd9Sstevel@tonic-gate } nv_t;
27487c478bd9Sstevel@tonic-gate 
27497c478bd9Sstevel@tonic-gate #define	ILL_FRAG_HASH(s, i) \
27507c478bd9Sstevel@tonic-gate 	((ntohl(s) ^ ((i) ^ ((i) >> 8))) % ILL_FRAG_HASH_TBL_COUNT)
27517c478bd9Sstevel@tonic-gate 
27527c478bd9Sstevel@tonic-gate /*
27537c478bd9Sstevel@tonic-gate  * The MAX number of allowed fragmented packets per hash bucket
27547c478bd9Sstevel@tonic-gate  * calculation is based on the most common mtu size of 1500. This limit
27557c478bd9Sstevel@tonic-gate  * will work well for other mtu sizes as well.
27567c478bd9Sstevel@tonic-gate  */
27577c478bd9Sstevel@tonic-gate #define	COMMON_IP_MTU 1500
27587c478bd9Sstevel@tonic-gate #define	MAX_FRAG_MIN 10
2759f4b3ec61Sdh #define	MAX_FRAG_PKTS(ipst)	\
2760f4b3ec61Sdh 	MAX(MAX_FRAG_MIN, (2 * (ipst->ips_ip_reass_queue_bytes / \
27617c478bd9Sstevel@tonic-gate 	    (COMMON_IP_MTU * ILL_FRAG_HASH_TBL_COUNT))))
27627c478bd9Sstevel@tonic-gate 
27637c478bd9Sstevel@tonic-gate /*
27647c478bd9Sstevel@tonic-gate  * Maximum dups allowed per packet.
27657c478bd9Sstevel@tonic-gate  */
27667c478bd9Sstevel@tonic-gate extern uint_t ip_max_frag_dups;
27677c478bd9Sstevel@tonic-gate 
27687c478bd9Sstevel@tonic-gate /*
27697c478bd9Sstevel@tonic-gate  * Per-packet information for received packets and transmitted.
27707c478bd9Sstevel@tonic-gate  * Used by the transport protocols when converting between the packet
27717c478bd9Sstevel@tonic-gate  * and ancillary data and socket options.
27727c478bd9Sstevel@tonic-gate  *
27737c478bd9Sstevel@tonic-gate  * Note: This private data structure and related IPPF_* constant
27747c478bd9Sstevel@tonic-gate  * definitions are exposed to enable compilation of some debugging tools
27757c478bd9Sstevel@tonic-gate  * like lsof which use struct tcp_t in <inet/tcp.h>. This is intended to be
27767c478bd9Sstevel@tonic-gate  * a temporary hack and long term alternate interfaces should be defined
27777c478bd9Sstevel@tonic-gate  * to support the needs of such tools and private definitions moved to
27787c478bd9Sstevel@tonic-gate  * private headers.
27797c478bd9Sstevel@tonic-gate  */
2780bd670b35SErik Nordmark struct ip_pkt_s {
27817c478bd9Sstevel@tonic-gate 	uint_t		ipp_fields;		/* Which fields are valid */
27827c478bd9Sstevel@tonic-gate 	in6_addr_t	ipp_addr;		/* pktinfo src/dst addr */
2783bd670b35SErik Nordmark #define	ipp_addr_v4	V4_PART_OF_V6(ipp_addr)
2784bd670b35SErik Nordmark 	uint_t		ipp_unicast_hops;	/* IPV6_UNICAST_HOPS, IP_TTL */
2785b3d0fa4fSseb 	uint_t		ipp_hoplimit;		/* IPV6_HOPLIMIT */
27867c478bd9Sstevel@tonic-gate 	uint_t		ipp_hopoptslen;
2787bd670b35SErik Nordmark 	uint_t		ipp_rthdrdstoptslen;
27887c478bd9Sstevel@tonic-gate 	uint_t		ipp_rthdrlen;
27897c478bd9Sstevel@tonic-gate 	uint_t		ipp_dstoptslen;
27908810c16bSdanmcd 	uint_t		ipp_fraghdrlen;
27917c478bd9Sstevel@tonic-gate 	ip6_hbh_t	*ipp_hopopts;
2792bd670b35SErik Nordmark 	ip6_dest_t	*ipp_rthdrdstopts;
27937c478bd9Sstevel@tonic-gate 	ip6_rthdr_t	*ipp_rthdr;
27947c478bd9Sstevel@tonic-gate 	ip6_dest_t	*ipp_dstopts;
27958810c16bSdanmcd 	ip6_frag_t	*ipp_fraghdr;
2796bd670b35SErik Nordmark 	uint8_t		ipp_tclass;		/* IPV6_TCLASS */
2797bd670b35SErik Nordmark 	uint8_t		ipp_type_of_service;	/* IP_TOS */
2798bd670b35SErik Nordmark 	uint_t		ipp_ipv4_options_len;	/* Len of IPv4 options */
2799bd670b35SErik Nordmark 	uint8_t		*ipp_ipv4_options;	/* Ptr to IPv4 options */
2800bd670b35SErik Nordmark 	uint_t		ipp_label_len_v4;	/* Len of TX label for IPv4 */
2801bd670b35SErik Nordmark 	uint8_t		*ipp_label_v4;		/* TX label for IPv4 */
2802bd670b35SErik Nordmark 	uint_t		ipp_label_len_v6;	/* Len of TX label for IPv6 */
2803bd670b35SErik Nordmark 	uint8_t		*ipp_label_v6;		/* TX label for IPv6 */
28047c478bd9Sstevel@tonic-gate };
2805bd670b35SErik Nordmark typedef struct ip_pkt_s ip_pkt_t;
280619a30e1aSrshoaib 
2807bd670b35SErik Nordmark extern void ip_pkt_free(ip_pkt_t *);	/* free storage inside ip_pkt_t */
2808bd670b35SErik Nordmark extern ipaddr_t ip_pkt_source_route_v4(const ip_pkt_t *);
2809bd670b35SErik Nordmark extern in6_addr_t *ip_pkt_source_route_v6(const ip_pkt_t *);
2810bd670b35SErik Nordmark extern int ip_pkt_copy(ip_pkt_t *, ip_pkt_t *, int);
2811bd670b35SErik Nordmark extern void ip_pkt_source_route_reverse_v4(ip_pkt_t *);
28127c478bd9Sstevel@tonic-gate 
28137c478bd9Sstevel@tonic-gate /* ipp_fields values */
2814bd670b35SErik Nordmark #define	IPPF_ADDR		0x0001	/* Part of in6_pktinfo: src/dst addr */
2815bd670b35SErik Nordmark #define	IPPF_HOPLIMIT		0x0002	/* Overrides unicast and multicast */
2816bd670b35SErik Nordmark #define	IPPF_TCLASS		0x0004	/* Overrides class in sin6_flowinfo */
2817bd670b35SErik Nordmark 
2818bd670b35SErik Nordmark #define	IPPF_HOPOPTS		0x0010	/* ipp_hopopts set */
2819bd670b35SErik Nordmark #define	IPPF_RTHDR		0x0020	/* ipp_rthdr set */
2820bd670b35SErik Nordmark #define	IPPF_RTHDRDSTOPTS	0x0040	/* ipp_rthdrdstopts set */
2821bd670b35SErik Nordmark #define	IPPF_DSTOPTS		0x0080	/* ipp_dstopts set */
2822bd670b35SErik Nordmark 
2823bd670b35SErik Nordmark #define	IPPF_IPV4_OPTIONS	0x0100	/* ipp_ipv4_options set */
2824bd670b35SErik Nordmark #define	IPPF_LABEL_V4		0x0200	/* ipp_label_v4 set */
2825bd670b35SErik Nordmark #define	IPPF_LABEL_V6		0x0400	/* ipp_label_v6 set */
2826bd670b35SErik Nordmark 
2827bd670b35SErik Nordmark #define	IPPF_FRAGHDR		0x0800	/* Used for IPsec receive side */
2828bd670b35SErik Nordmark 
2829bd670b35SErik Nordmark /*
2830bd670b35SErik Nordmark  * Data structure which is passed to conn_opt_get/set.
2831bd670b35SErik Nordmark  * The conn_t is included even though it can be inferred from queue_t.
2832bd670b35SErik Nordmark  * setsockopt and getsockopt use conn_ixa and conn_xmit_ipp. However,
2833bd670b35SErik Nordmark  * when handling ancillary data we use separate ixa and ipps.
2834bd670b35SErik Nordmark  */
2835bd670b35SErik Nordmark typedef struct conn_opt_arg_s {
2836bd670b35SErik Nordmark 	conn_t		*coa_connp;
2837bd670b35SErik Nordmark 	ip_xmit_attr_t	*coa_ixa;
2838bd670b35SErik Nordmark 	ip_pkt_t	*coa_ipp;
2839bd670b35SErik Nordmark 	boolean_t	coa_ancillary;	/* Ancillary data and not setsockopt */
2840bd670b35SErik Nordmark 	uint_t		coa_changed;	/* See below */
2841bd670b35SErik Nordmark } conn_opt_arg_t;
2842bd670b35SErik Nordmark 
2843bd670b35SErik Nordmark /*
2844bd670b35SErik Nordmark  * Flags for what changed.
2845bd670b35SErik Nordmark  * If we want to be more efficient in the future we can have more fine
2846bd670b35SErik Nordmark  * grained flags e.g., a flag for just IP_TOS changing.
2847bd670b35SErik Nordmark  * For now we either call ip_set_destination (for "route changed")
2848bd670b35SErik Nordmark  * and/or conn_build_hdr_template/conn_prepend_hdr (for "header changed").
2849bd670b35SErik Nordmark  */
2850bd670b35SErik Nordmark #define	COA_HEADER_CHANGED	0x0001
2851bd670b35SErik Nordmark #define	COA_ROUTE_CHANGED	0x0002
2852bd670b35SErik Nordmark #define	COA_RCVBUF_CHANGED	0x0004	/* SO_RCVBUF */
2853bd670b35SErik Nordmark #define	COA_SNDBUF_CHANGED	0x0008	/* SO_SNDBUF */
2854bd670b35SErik Nordmark #define	COA_WROFF_CHANGED	0x0010	/* Header size changed */
2855bd670b35SErik Nordmark #define	COA_ICMP_BIND_NEEDED	0x0020
2856bd670b35SErik Nordmark #define	COA_OOBINLINE_CHANGED	0x0040
28577c478bd9Sstevel@tonic-gate 
28587c478bd9Sstevel@tonic-gate #define	TCP_PORTS_OFFSET	0
28597c478bd9Sstevel@tonic-gate #define	UDP_PORTS_OFFSET	0
28607c478bd9Sstevel@tonic-gate 
28617c478bd9Sstevel@tonic-gate /*
28627c478bd9Sstevel@tonic-gate  * lookups return the ill/ipif only if the flags are clear OR Iam writer.
28637c478bd9Sstevel@tonic-gate  * ill / ipif lookup functions increment the refcnt on the ill / ipif only
28647c478bd9Sstevel@tonic-gate  * after calling these macros. This ensures that the refcnt on the ipif or
28657c478bd9Sstevel@tonic-gate  * ill will eventually drop down to zero.
28667c478bd9Sstevel@tonic-gate  */
28677c478bd9Sstevel@tonic-gate #define	ILL_LOOKUP_FAILED	1	/* Used as error code */
28687c478bd9Sstevel@tonic-gate #define	IPIF_LOOKUP_FAILED	2	/* Used as error code */
28697c478bd9Sstevel@tonic-gate 
28700f1702c5SYu Xiangning #define	ILL_CAN_LOOKUP(ill)						\
2871bd670b35SErik Nordmark 	(!((ill)->ill_state_flags & ILL_CONDEMNED) ||			\
28727c478bd9Sstevel@tonic-gate 	IAM_WRITER_ILL(ill))
28737c478bd9Sstevel@tonic-gate 
2874bd670b35SErik Nordmark #define	ILL_IS_CONDEMNED(ill)	\
2875bd670b35SErik Nordmark 	((ill)->ill_state_flags & ILL_CONDEMNED)
28767c478bd9Sstevel@tonic-gate 
28770f1702c5SYu Xiangning #define	IPIF_CAN_LOOKUP(ipif)	\
2878bd670b35SErik Nordmark 	(!((ipif)->ipif_state_flags & IPIF_CONDEMNED) || \
28797c478bd9Sstevel@tonic-gate 	IAM_WRITER_IPIF(ipif))
28807c478bd9Sstevel@tonic-gate 
2881bd670b35SErik Nordmark #define	IPIF_IS_CONDEMNED(ipif)	\
2882bd670b35SErik Nordmark 	((ipif)->ipif_state_flags & IPIF_CONDEMNED)
28837c478bd9Sstevel@tonic-gate 
2884bd670b35SErik Nordmark #define	IPIF_IS_CHANGING(ipif)	\
2885bd670b35SErik Nordmark 	((ipif)->ipif_state_flags & IPIF_CHANGING)
28867c478bd9Sstevel@tonic-gate 
28877924222fSmeem /* Macros used to assert that this thread is a writer */
2888e11c3f44Smeem #define	IAM_WRITER_IPSQ(ipsq)	((ipsq)->ipsq_xop->ipx_writer == curthread)
28897924222fSmeem #define	IAM_WRITER_ILL(ill)	IAM_WRITER_IPSQ((ill)->ill_phyint->phyint_ipsq)
28907924222fSmeem #define	IAM_WRITER_IPIF(ipif)	IAM_WRITER_ILL((ipif)->ipif_ill)
28917c478bd9Sstevel@tonic-gate 
28927c478bd9Sstevel@tonic-gate /*
28937c478bd9Sstevel@tonic-gate  * Grab ill locks in the proper order. The order is highest addressed
28947c478bd9Sstevel@tonic-gate  * ill is locked first.
28957c478bd9Sstevel@tonic-gate  */
28967c478bd9Sstevel@tonic-gate #define	GRAB_ILL_LOCKS(ill_1, ill_2)				\
28977c478bd9Sstevel@tonic-gate {								\
28987c478bd9Sstevel@tonic-gate 	if ((ill_1) > (ill_2)) {				\
28997c478bd9Sstevel@tonic-gate 		if (ill_1 != NULL)				\
29007c478bd9Sstevel@tonic-gate 			mutex_enter(&(ill_1)->ill_lock);	\
29017c478bd9Sstevel@tonic-gate 		if (ill_2 != NULL)				\
29027c478bd9Sstevel@tonic-gate 			mutex_enter(&(ill_2)->ill_lock);	\
29037c478bd9Sstevel@tonic-gate 	} else {						\
29047c478bd9Sstevel@tonic-gate 		if (ill_2 != NULL)				\
29057c478bd9Sstevel@tonic-gate 			mutex_enter(&(ill_2)->ill_lock);	\
29067c478bd9Sstevel@tonic-gate 		if (ill_1 != NULL && ill_1 != ill_2)		\
29077c478bd9Sstevel@tonic-gate 			mutex_enter(&(ill_1)->ill_lock);	\
29087c478bd9Sstevel@tonic-gate 	}							\
29097c478bd9Sstevel@tonic-gate }
29107c478bd9Sstevel@tonic-gate 
29117c478bd9Sstevel@tonic-gate #define	RELEASE_ILL_LOCKS(ill_1, ill_2)		\
29127c478bd9Sstevel@tonic-gate {						\
29137c478bd9Sstevel@tonic-gate 	if (ill_1 != NULL)			\
2914bd670b35SErik Nordmark 		mutex_exit(&(ill_1)->ill_lock);	\
29157c478bd9Sstevel@tonic-gate 	if (ill_2 != NULL && ill_2 != ill_1)	\
2916bd670b35SErik Nordmark 		mutex_exit(&(ill_2)->ill_lock);	\
29177c478bd9Sstevel@tonic-gate }
29187c478bd9Sstevel@tonic-gate 
29197c478bd9Sstevel@tonic-gate /* Get the other protocol instance ill */
29207c478bd9Sstevel@tonic-gate #define	ILL_OTHER(ill)						\
29217c478bd9Sstevel@tonic-gate 	((ill)->ill_isv6 ? (ill)->ill_phyint->phyint_illv4 :	\
29227c478bd9Sstevel@tonic-gate 	    (ill)->ill_phyint->phyint_illv6)
29237c478bd9Sstevel@tonic-gate 
29247c478bd9Sstevel@tonic-gate /* ioctl command info: Ioctl properties extracted and stored in here */
29257c478bd9Sstevel@tonic-gate typedef struct cmd_info_s
29267c478bd9Sstevel@tonic-gate {
29277c478bd9Sstevel@tonic-gate 	ipif_t  *ci_ipif;	/* ipif associated with [l]ifreq ioctl's */
29287c478bd9Sstevel@tonic-gate 	sin_t	*ci_sin;	/* the sin struct passed down */
29297c478bd9Sstevel@tonic-gate 	sin6_t	*ci_sin6;	/* the sin6_t struct passed down */
29307c478bd9Sstevel@tonic-gate 	struct lifreq *ci_lifr;	/* the lifreq struct passed down */
29317c478bd9Sstevel@tonic-gate } cmd_info_t;
29327c478bd9Sstevel@tonic-gate 
29337c478bd9Sstevel@tonic-gate extern struct kmem_cache *ire_cache;
29347c478bd9Sstevel@tonic-gate 
29357c478bd9Sstevel@tonic-gate extern ipaddr_t	ip_g_all_ones;
29367c478bd9Sstevel@tonic-gate 
2937bd670b35SErik Nordmark extern uint_t	ip_loopback_mtu;	/* /etc/system */
2938bd670b35SErik Nordmark extern uint_t	ip_loopback_mtuplus;
2939bd670b35SErik Nordmark extern uint_t	ip_loopback_mtu_v6plus;
29407c478bd9Sstevel@tonic-gate 
2941aa92d85bSgt extern vmem_t *ip_minor_arena_sa;
2942aa92d85bSgt extern vmem_t *ip_minor_arena_la;
29437c478bd9Sstevel@tonic-gate 
2944f4b3ec61Sdh /*
2945f4b3ec61Sdh  * ip_g_forward controls IP forwarding.  It takes two values:
2946f4b3ec61Sdh  *	0: IP_FORWARD_NEVER	Don't forward packets ever.
2947f4b3ec61Sdh  *	1: IP_FORWARD_ALWAYS	Forward packets for elsewhere.
2948f4b3ec61Sdh  *
2949f4b3ec61Sdh  * RFC1122 says there must be a configuration switch to control forwarding,
2950f4b3ec61Sdh  * but that the default MUST be to not forward packets ever.  Implicit
2951f4b3ec61Sdh  * control based on configuration of multiple interfaces MUST NOT be
2952f4b3ec61Sdh  * implemented (Section 3.1).  SunOS 4.1 did provide the "automatic" capability
2953f4b3ec61Sdh  * and, in fact, it was the default.  That capability is now provided in the
2954f4b3ec61Sdh  * /etc/rc2.d/S69inet script.
2955f4b3ec61Sdh  */
2956f4b3ec61Sdh 
29576e91bba0SGirish Moodalbail #define	ips_ip_respond_to_address_mask_broadcast \
29586e91bba0SGirish Moodalbail 					ips_propinfo_tbl[0].prop_cur_bval
29596e91bba0SGirish Moodalbail #define	ips_ip_g_resp_to_echo_bcast	ips_propinfo_tbl[1].prop_cur_bval
29606e91bba0SGirish Moodalbail #define	ips_ip_g_resp_to_echo_mcast	ips_propinfo_tbl[2].prop_cur_bval
29616e91bba0SGirish Moodalbail #define	ips_ip_g_resp_to_timestamp	ips_propinfo_tbl[3].prop_cur_bval
29626e91bba0SGirish Moodalbail #define	ips_ip_g_resp_to_timestamp_bcast ips_propinfo_tbl[4].prop_cur_bval
29636e91bba0SGirish Moodalbail #define	ips_ip_g_send_redirects		ips_propinfo_tbl[5].prop_cur_bval
29646e91bba0SGirish Moodalbail #define	ips_ip_g_forward_directed_bcast	ips_propinfo_tbl[6].prop_cur_bval
29656e91bba0SGirish Moodalbail #define	ips_ip_mrtdebug			ips_propinfo_tbl[7].prop_cur_uval
29666e91bba0SGirish Moodalbail #define	ips_ip_ire_reclaim_fraction	ips_propinfo_tbl[8].prop_cur_uval
29676e91bba0SGirish Moodalbail #define	ips_ip_nce_reclaim_fraction	ips_propinfo_tbl[9].prop_cur_uval
29686e91bba0SGirish Moodalbail #define	ips_ip_dce_reclaim_fraction	ips_propinfo_tbl[10].prop_cur_uval
29696e91bba0SGirish Moodalbail #define	ips_ip_def_ttl			ips_propinfo_tbl[11].prop_cur_uval
29706e91bba0SGirish Moodalbail #define	ips_ip_forward_src_routed	ips_propinfo_tbl[12].prop_cur_bval
29716e91bba0SGirish Moodalbail #define	ips_ip_wroff_extra		ips_propinfo_tbl[13].prop_cur_uval
29726e91bba0SGirish Moodalbail #define	ips_ip_pathmtu_interval		ips_propinfo_tbl[14].prop_cur_uval
29736e91bba0SGirish Moodalbail #define	ips_ip_icmp_return		ips_propinfo_tbl[15].prop_cur_uval
29746e91bba0SGirish Moodalbail #define	ips_ip_path_mtu_discovery	ips_propinfo_tbl[16].prop_cur_bval
29756e91bba0SGirish Moodalbail #define	ips_ip_pmtu_min			ips_propinfo_tbl[17].prop_cur_uval
29766e91bba0SGirish Moodalbail #define	ips_ip_ignore_redirect		ips_propinfo_tbl[18].prop_cur_bval
29776e91bba0SGirish Moodalbail #define	ips_ip_arp_icmp_error		ips_propinfo_tbl[19].prop_cur_bval
29786e91bba0SGirish Moodalbail #define	ips_ip_broadcast_ttl		ips_propinfo_tbl[20].prop_cur_uval
29796e91bba0SGirish Moodalbail #define	ips_ip_icmp_err_interval	ips_propinfo_tbl[21].prop_cur_uval
29806e91bba0SGirish Moodalbail #define	ips_ip_icmp_err_burst		ips_propinfo_tbl[22].prop_cur_uval
29816e91bba0SGirish Moodalbail #define	ips_ip_reass_queue_bytes	ips_propinfo_tbl[23].prop_cur_uval
29826e91bba0SGirish Moodalbail #define	ips_ip_strict_dst_multihoming	ips_propinfo_tbl[24].prop_cur_uval
29836e91bba0SGirish Moodalbail #define	ips_ip_addrs_per_if		ips_propinfo_tbl[25].prop_cur_uval
29846e91bba0SGirish Moodalbail #define	ips_ipsec_override_persocket_policy ips_propinfo_tbl[26].prop_cur_bval
29856e91bba0SGirish Moodalbail #define	ips_icmp_accept_clear_messages	ips_propinfo_tbl[27].prop_cur_bval
29866e91bba0SGirish Moodalbail #define	ips_igmp_accept_clear_messages	ips_propinfo_tbl[28].prop_cur_bval
298769bb4bb4Scarlsonj 
298869bb4bb4Scarlsonj /* IPv6 configuration knobs */
29896e91bba0SGirish Moodalbail #define	ips_delay_first_probe_time	ips_propinfo_tbl[29].prop_cur_uval
29906e91bba0SGirish Moodalbail #define	ips_max_unicast_solicit		ips_propinfo_tbl[30].prop_cur_uval
29916e91bba0SGirish Moodalbail #define	ips_ipv6_def_hops		ips_propinfo_tbl[31].prop_cur_uval
29926e91bba0SGirish Moodalbail #define	ips_ipv6_icmp_return		ips_propinfo_tbl[32].prop_cur_uval
29936e91bba0SGirish Moodalbail #define	ips_ipv6_forward_src_routed	ips_propinfo_tbl[33].prop_cur_bval
29946e91bba0SGirish Moodalbail #define	ips_ipv6_resp_echo_mcast	ips_propinfo_tbl[34].prop_cur_bval
29956e91bba0SGirish Moodalbail #define	ips_ipv6_send_redirects		ips_propinfo_tbl[35].prop_cur_bval
29966e91bba0SGirish Moodalbail #define	ips_ipv6_ignore_redirect	ips_propinfo_tbl[36].prop_cur_bval
29976e91bba0SGirish Moodalbail #define	ips_ipv6_strict_dst_multihoming	ips_propinfo_tbl[37].prop_cur_uval
29986e91bba0SGirish Moodalbail #define	ips_src_check			ips_propinfo_tbl[38].prop_cur_uval
29996e91bba0SGirish Moodalbail #define	ips_ipsec_policy_log_interval	ips_propinfo_tbl[39].prop_cur_uval
30006e91bba0SGirish Moodalbail #define	ips_pim_accept_clear_messages	ips_propinfo_tbl[40].prop_cur_bval
30016e91bba0SGirish Moodalbail #define	ips_ip_ndp_unsolicit_interval	ips_propinfo_tbl[41].prop_cur_uval
30026e91bba0SGirish Moodalbail #define	ips_ip_ndp_unsolicit_count	ips_propinfo_tbl[42].prop_cur_uval
30036e91bba0SGirish Moodalbail #define	ips_ipv6_ignore_home_address_opt ips_propinfo_tbl[43].prop_cur_bval
300416c9d76cSKacheong Poon 
300516c9d76cSKacheong Poon /* Misc IP configuration knobs */
30066e91bba0SGirish Moodalbail #define	ips_ip_policy_mask		ips_propinfo_tbl[44].prop_cur_uval
30076e91bba0SGirish Moodalbail #define	ips_ip_ecmp_behavior		ips_propinfo_tbl[45].prop_cur_uval
30086e91bba0SGirish Moodalbail #define	ips_ip_multirt_ttl  		ips_propinfo_tbl[46].prop_cur_uval
30096e91bba0SGirish Moodalbail #define	ips_ip_ire_badcnt_lifetime	ips_propinfo_tbl[47].prop_cur_uval
30106e91bba0SGirish Moodalbail #define	ips_ip_max_temp_idle		ips_propinfo_tbl[48].prop_cur_uval
30116e91bba0SGirish Moodalbail #define	ips_ip_max_temp_defend		ips_propinfo_tbl[49].prop_cur_uval
30126e91bba0SGirish Moodalbail #define	ips_ip_max_defend		ips_propinfo_tbl[50].prop_cur_uval
30136e91bba0SGirish Moodalbail #define	ips_ip_defend_interval		ips_propinfo_tbl[51].prop_cur_uval
30146e91bba0SGirish Moodalbail #define	ips_ip_dup_recovery		ips_propinfo_tbl[52].prop_cur_uval
30156e91bba0SGirish Moodalbail #define	ips_ip_restrict_interzone_loopback ips_propinfo_tbl[53].prop_cur_bval
30166e91bba0SGirish Moodalbail #define	ips_ip_lso_outbound		ips_propinfo_tbl[54].prop_cur_bval
30176e91bba0SGirish Moodalbail #define	ips_igmp_max_version		ips_propinfo_tbl[55].prop_cur_uval
30186e91bba0SGirish Moodalbail #define	ips_mld_max_version		ips_propinfo_tbl[56].prop_cur_uval
30196e91bba0SGirish Moodalbail #define	ips_ip_forwarding		ips_propinfo_tbl[57].prop_cur_bval
30206e91bba0SGirish Moodalbail #define	ips_ipv6_forwarding		ips_propinfo_tbl[58].prop_cur_bval
30216e91bba0SGirish Moodalbail #define	ips_ip_reassembly_timeout	ips_propinfo_tbl[59].prop_cur_uval
30226e91bba0SGirish Moodalbail #define	ips_ipv6_reassembly_timeout	ips_propinfo_tbl[60].prop_cur_uval
30236e91bba0SGirish Moodalbail #define	ips_ip_cgtp_filter		ips_propinfo_tbl[61].prop_cur_bval
30246e91bba0SGirish Moodalbail #define	ips_arp_probe_delay		ips_propinfo_tbl[62].prop_cur_uval
30256e91bba0SGirish Moodalbail #define	ips_arp_fastprobe_delay		ips_propinfo_tbl[63].prop_cur_uval
30266e91bba0SGirish Moodalbail #define	ips_arp_probe_interval		ips_propinfo_tbl[64].prop_cur_uval
30276e91bba0SGirish Moodalbail #define	ips_arp_fastprobe_interval	ips_propinfo_tbl[65].prop_cur_uval
30286e91bba0SGirish Moodalbail #define	ips_arp_probe_count		ips_propinfo_tbl[66].prop_cur_uval
30296e91bba0SGirish Moodalbail #define	ips_arp_fastprobe_count		ips_propinfo_tbl[67].prop_cur_uval
30306e91bba0SGirish Moodalbail #define	ips_ipv4_dad_announce_interval	ips_propinfo_tbl[68].prop_cur_uval
30316e91bba0SGirish Moodalbail #define	ips_ipv6_dad_announce_interval	ips_propinfo_tbl[69].prop_cur_uval
30326e91bba0SGirish Moodalbail #define	ips_arp_defend_interval		ips_propinfo_tbl[70].prop_cur_uval
30336e91bba0SGirish Moodalbail #define	ips_arp_defend_rate		ips_propinfo_tbl[71].prop_cur_uval
30346e91bba0SGirish Moodalbail #define	ips_ndp_defend_interval		ips_propinfo_tbl[72].prop_cur_uval
30356e91bba0SGirish Moodalbail #define	ips_ndp_defend_rate		ips_propinfo_tbl[73].prop_cur_uval
30366e91bba0SGirish Moodalbail #define	ips_arp_defend_period		ips_propinfo_tbl[74].prop_cur_uval
30376e91bba0SGirish Moodalbail #define	ips_ndp_defend_period		ips_propinfo_tbl[75].prop_cur_uval
30386e91bba0SGirish Moodalbail #define	ips_ipv4_icmp_return_pmtu	ips_propinfo_tbl[76].prop_cur_bval
30396e91bba0SGirish Moodalbail #define	ips_ipv6_icmp_return_pmtu	ips_propinfo_tbl[77].prop_cur_bval
30406e91bba0SGirish Moodalbail #define	ips_ip_arp_publish_count	ips_propinfo_tbl[78].prop_cur_uval
30416e91bba0SGirish Moodalbail #define	ips_ip_arp_publish_interval	ips_propinfo_tbl[79].prop_cur_uval
30426e91bba0SGirish Moodalbail #define	ips_ip_strict_src_multihoming	ips_propinfo_tbl[80].prop_cur_uval
30436e91bba0SGirish Moodalbail #define	ips_ipv6_strict_src_multihoming	ips_propinfo_tbl[81].prop_cur_uval
30446e91bba0SGirish Moodalbail #define	ips_ipv6_drop_inbound_icmpv6	ips_propinfo_tbl[82].prop_cur_bval
30457c6d7024SJerry Jelinek #define	ips_ip_dce_reclaim_threshold	ips_propinfo_tbl[83].prop_cur_uval
30467c478bd9Sstevel@tonic-gate 
30477c478bd9Sstevel@tonic-gate extern int	dohwcksum;	/* use h/w cksum if supported by the h/w */
30487c478bd9Sstevel@tonic-gate #ifdef ZC_TEST
30497c478bd9Sstevel@tonic-gate extern int	noswcksum;
30507c478bd9Sstevel@tonic-gate #endif
30517c478bd9Sstevel@tonic-gate 
30527c478bd9Sstevel@tonic-gate extern char	ipif_loopback_name[];
30537c478bd9Sstevel@tonic-gate 
30547c478bd9Sstevel@tonic-gate extern nv_t	*ire_nv_tbl;
30557c478bd9Sstevel@tonic-gate 
30567c478bd9Sstevel@tonic-gate extern struct module_info ip_mod_info;
30577c478bd9Sstevel@tonic-gate 
3058f4b3ec61Sdh #define	HOOKS4_INTERESTED_PHYSICAL_IN(ipst)	\
3059f4b3ec61Sdh 	((ipst)->ips_ip4_physical_in_event.he_interested)
3060f4b3ec61Sdh #define	HOOKS6_INTERESTED_PHYSICAL_IN(ipst)	\
3061f4b3ec61Sdh 	((ipst)->ips_ip6_physical_in_event.he_interested)
3062f4b3ec61Sdh #define	HOOKS4_INTERESTED_PHYSICAL_OUT(ipst)	\
3063f4b3ec61Sdh 	((ipst)->ips_ip4_physical_out_event.he_interested)
3064f4b3ec61Sdh #define	HOOKS6_INTERESTED_PHYSICAL_OUT(ipst)	\
3065f4b3ec61Sdh 	((ipst)->ips_ip6_physical_out_event.he_interested)
3066f4b3ec61Sdh #define	HOOKS4_INTERESTED_FORWARDING(ipst)	\
3067f4b3ec61Sdh 	((ipst)->ips_ip4_forwarding_event.he_interested)
3068f4b3ec61Sdh #define	HOOKS6_INTERESTED_FORWARDING(ipst)	\
3069f4b3ec61Sdh 	((ipst)->ips_ip6_forwarding_event.he_interested)
3070f4b3ec61Sdh #define	HOOKS4_INTERESTED_LOOPBACK_IN(ipst)	\
3071f4b3ec61Sdh 	((ipst)->ips_ip4_loopback_in_event.he_interested)
3072f4b3ec61Sdh #define	HOOKS6_INTERESTED_LOOPBACK_IN(ipst)	\
3073f4b3ec61Sdh 	((ipst)->ips_ip6_loopback_in_event.he_interested)
3074f4b3ec61Sdh #define	HOOKS4_INTERESTED_LOOPBACK_OUT(ipst)	\
3075f4b3ec61Sdh 	((ipst)->ips_ip4_loopback_out_event.he_interested)
3076f4b3ec61Sdh #define	HOOKS6_INTERESTED_LOOPBACK_OUT(ipst)	\
3077f4b3ec61Sdh 	((ipst)->ips_ip6_loopback_out_event.he_interested)
3078381a2a9aSdr /*
3079bd670b35SErik Nordmark  * Hooks marcos used inside of ip
3080bd670b35SErik Nordmark  * The callers use the above INTERESTED macros first, hence
3081bd670b35SErik Nordmark  * the he_interested check is superflous.
3082381a2a9aSdr  */
3083bd670b35SErik Nordmark #define	FW_HOOKS(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst, _err) \
3084bd670b35SErik Nordmark 	if ((_hook).he_interested) {					\
3085381a2a9aSdr 		hook_pkt_event_t info;					\
3086381a2a9aSdr 									\
3087381a2a9aSdr 		_NOTE(CONSTCOND)					\
3088381a2a9aSdr 		ASSERT((_ilp != NULL) || (_olp != NULL));		\
3089381a2a9aSdr 									\
3090e11c3f44Smeem 		FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);		\
3091e11c3f44Smeem 		FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);		\
30927ddc9b1aSDarren Reed 		info.hpe_protocol = ipst->ips_ipv4_net_data;		\
3093381a2a9aSdr 		info.hpe_hdr = _iph;					\
3094381a2a9aSdr 		info.hpe_mp = &(_fm);					\
3095381a2a9aSdr 		info.hpe_mb = _m;					\
30961b47e080Sdr 		info.hpe_flags = _llm;					\
3097bd670b35SErik Nordmark 		_err = hook_run(ipst->ips_ipv4_net_data->netd_hooks,	\
3098bd670b35SErik Nordmark 		    _event, (hook_data_t)&info);			\
3099bd670b35SErik Nordmark 		if (_err != 0) {					\
3100381a2a9aSdr 			ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3101381a2a9aSdr 			    (_hook).he_name, (void *)_fm, (void *)_m));	\
3102bd670b35SErik Nordmark 			if (_fm != NULL) {				\
3103bd670b35SErik Nordmark 				freemsg(_fm);				\
3104bd670b35SErik Nordmark 				_fm = NULL;				\
3105bd670b35SErik Nordmark 			}						\
3106381a2a9aSdr 			_iph = NULL;					\
3107381a2a9aSdr 			_m = NULL;					\
3108381a2a9aSdr 		} else {						\
3109381a2a9aSdr 			_iph = info.hpe_hdr;				\
3110381a2a9aSdr 			_m = info.hpe_mb;				\
3111381a2a9aSdr 		}							\
3112381a2a9aSdr 	}
3113381a2a9aSdr 
3114bd670b35SErik Nordmark #define	FW_HOOKS6(_hook, _event, _ilp, _olp, _iph, _fm, _m, _llm, ipst, _err) \
3115bd670b35SErik Nordmark 	if ((_hook).he_interested) {					\
3116381a2a9aSdr 		hook_pkt_event_t info;					\
3117381a2a9aSdr 									\
3118381a2a9aSdr 		_NOTE(CONSTCOND)					\
3119381a2a9aSdr 		ASSERT((_ilp != NULL) || (_olp != NULL));		\
3120381a2a9aSdr 									\
3121e11c3f44Smeem 		FW_SET_ILL_INDEX(info.hpe_ifp, (ill_t *)_ilp);		\
3122e11c3f44Smeem 		FW_SET_ILL_INDEX(info.hpe_ofp, (ill_t *)_olp);		\
31237ddc9b1aSDarren Reed 		info.hpe_protocol = ipst->ips_ipv6_net_data;		\
3124381a2a9aSdr 		info.hpe_hdr = _iph;					\
3125381a2a9aSdr 		info.hpe_mp = &(_fm);					\
3126381a2a9aSdr 		info.hpe_mb = _m;					\
31271b47e080Sdr 		info.hpe_flags = _llm;					\
3128bd670b35SErik Nordmark 		_err = hook_run(ipst->ips_ipv6_net_data->netd_hooks,	\
3129bd670b35SErik Nordmark 		    _event, (hook_data_t)&info);			\
3130bd670b35SErik Nordmark 		if (_err != 0) {					\
3131381a2a9aSdr 			ip2dbg(("%s hook dropped mblk chain %p hdr %p\n",\
3132381a2a9aSdr 			    (_hook).he_name, (void *)_fm, (void *)_m));	\
3133bd670b35SErik Nordmark 			if (_fm != NULL) {				\
3134bd670b35SErik Nordmark 				freemsg(_fm);				\
3135bd670b35SErik Nordmark 				_fm = NULL;				\
3136bd670b35SErik Nordmark 			}						\
3137381a2a9aSdr 			_iph = NULL;					\
3138381a2a9aSdr 			_m = NULL;					\
3139381a2a9aSdr 		} else {						\
3140381a2a9aSdr 			_iph = info.hpe_hdr;				\
3141381a2a9aSdr 			_m = info.hpe_mb;				\
3142381a2a9aSdr 		}							\
3143381a2a9aSdr 	}
3144381a2a9aSdr 
3145e11c3f44Smeem #define	FW_SET_ILL_INDEX(fp, ill)					\
3146e11c3f44Smeem 	_NOTE(CONSTCOND)						\
3147e11c3f44Smeem 	if ((ill) == NULL || (ill)->ill_phyint == NULL) {		\
3148e11c3f44Smeem 		(fp) = 0;						\
3149e11c3f44Smeem 		_NOTE(CONSTCOND)					\
3150e11c3f44Smeem 	} else if (IS_UNDER_IPMP(ill)) {				\
3151e11c3f44Smeem 		(fp) = ipmp_ill_get_ipmp_ifindex(ill);			\
3152e11c3f44Smeem 	} else {							\
3153e11c3f44Smeem 		(fp) = (ill)->ill_phyint->phyint_ifindex;		\
3154e11c3f44Smeem 	}
3155e11c3f44Smeem 
31567c478bd9Sstevel@tonic-gate /*
31577c478bd9Sstevel@tonic-gate  * Network byte order macros
31587c478bd9Sstevel@tonic-gate  */
31597c478bd9Sstevel@tonic-gate #ifdef	_BIG_ENDIAN
31602a9459bdSsangeeta #define	N_IN_CLASSA_NET		IN_CLASSA_NET
31617c478bd9Sstevel@tonic-gate #define	N_IN_CLASSD_NET		IN_CLASSD_NET
31627c478bd9Sstevel@tonic-gate #define	N_INADDR_UNSPEC_GROUP	INADDR_UNSPEC_GROUP
31632a9459bdSsangeeta #define	N_IN_LOOPBACK_NET	(ipaddr_t)0x7f000000U
31647c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */
31652a9459bdSsangeeta #define	N_IN_CLASSA_NET		(ipaddr_t)0x000000ffU
31667c478bd9Sstevel@tonic-gate #define	N_IN_CLASSD_NET		(ipaddr_t)0x000000f0U
31677c478bd9Sstevel@tonic-gate #define	N_INADDR_UNSPEC_GROUP	(ipaddr_t)0x000000e0U
31682a9459bdSsangeeta #define	N_IN_LOOPBACK_NET	(ipaddr_t)0x0000007fU
31697c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */
31707c478bd9Sstevel@tonic-gate #define	CLASSD(addr)	(((addr) & N_IN_CLASSD_NET) == N_INADDR_UNSPEC_GROUP)
31712a9459bdSsangeeta #define	CLASSE(addr)	(((addr) & N_IN_CLASSD_NET) == N_IN_CLASSD_NET)
3172c793af95Ssangeeta #define	IP_LOOPBACK_ADDR(addr)			\
31732a9459bdSsangeeta 	(((addr) & N_IN_CLASSA_NET == N_IN_LOOPBACK_NET))
3174c793af95Ssangeeta 
3175f4b3ec61Sdh extern int	ip_debug;
31766a8288c7Scarlsonj extern uint_t	ip_thread_data;
31776a8288c7Scarlsonj extern krwlock_t ip_thread_rwlock;
31786a8288c7Scarlsonj extern list_t	ip_thread_list;
3179f4b3ec61Sdh 
31807c478bd9Sstevel@tonic-gate #ifdef IP_DEBUG
31817c478bd9Sstevel@tonic-gate #include <sys/debug.h>
31827c478bd9Sstevel@tonic-gate #include <sys/promif.h>
31837c478bd9Sstevel@tonic-gate 
31847c478bd9Sstevel@tonic-gate #define	ip0dbg(a)	printf a
31857c478bd9Sstevel@tonic-gate #define	ip1dbg(a)	if (ip_debug > 2) printf a
31867c478bd9Sstevel@tonic-gate #define	ip2dbg(a)	if (ip_debug > 3) printf a
31877c478bd9Sstevel@tonic-gate #define	ip3dbg(a)	if (ip_debug > 4) printf a
31887c478bd9Sstevel@tonic-gate #else
31897c478bd9Sstevel@tonic-gate #define	ip0dbg(a)	/* */
31907c478bd9Sstevel@tonic-gate #define	ip1dbg(a)	/* */
31917c478bd9Sstevel@tonic-gate #define	ip2dbg(a)	/* */
31927c478bd9Sstevel@tonic-gate #define	ip3dbg(a)	/* */
31937c478bd9Sstevel@tonic-gate #endif	/* IP_DEBUG */
31947c478bd9Sstevel@tonic-gate 
319569bb4bb4Scarlsonj /* Default MAC-layer address string length for mac_colon_addr */
319669bb4bb4Scarlsonj #define	MAC_STR_LEN	128
319769bb4bb4Scarlsonj 
3198605445d5Sdg struct	mac_header_info_s;
3199605445d5Sdg 
32007c478bd9Sstevel@tonic-gate extern void	ill_frag_timer(void *);
3201f4b3ec61Sdh extern ill_t	*ill_first(int, int, ill_walk_context_t *, ip_stack_t *);
32027c478bd9Sstevel@tonic-gate extern ill_t	*ill_next(ill_walk_context_t *, ill_t *);
32037c478bd9Sstevel@tonic-gate extern void	ill_frag_timer_start(ill_t *);
3204b127ac41SPhilip Kirk extern void	ill_nic_event_dispatch(ill_t *, lif_if_t, nic_event_t,
3205b127ac41SPhilip Kirk     nic_event_data_t, size_t);
32067c478bd9Sstevel@tonic-gate extern mblk_t	*ip_carve_mp(mblk_t **, ssize_t);
32077c478bd9Sstevel@tonic-gate extern mblk_t	*ip_dlpi_alloc(size_t, t_uscalar_t);
3208e11c3f44Smeem extern mblk_t	*ip_dlnotify_alloc(uint_t, uint_t);
32091eee170aSErik Nordmark extern mblk_t	*ip_dlnotify_alloc2(uint_t, uint_t, uint_t);
32107c478bd9Sstevel@tonic-gate extern char	*ip_dot_addr(ipaddr_t, char *);
321169bb4bb4Scarlsonj extern const char *mac_colon_addr(const uint8_t *, size_t, char *, size_t);
32127c478bd9Sstevel@tonic-gate extern void	ip_lwput(queue_t *, mblk_t *);
3213f4b3ec61Sdh extern boolean_t icmp_err_rate_limit(ip_stack_t *);
3214bd670b35SErik Nordmark extern void	icmp_frag_needed(mblk_t *, int, ip_recv_attr_t *);
3215bd670b35SErik Nordmark extern mblk_t	*icmp_inbound_v4(mblk_t *, ip_recv_attr_t *);
3216bd670b35SErik Nordmark extern void	icmp_time_exceeded(mblk_t *, uint8_t, ip_recv_attr_t *);
3217bd670b35SErik Nordmark extern void	icmp_unreachable(mblk_t *, uint8_t, ip_recv_attr_t *);
3218bd670b35SErik Nordmark extern boolean_t ip_ipsec_policy_inherit(conn_t *, conn_t *, ip_recv_attr_t *);
3219bd670b35SErik Nordmark extern void	*ip_pullup(mblk_t *, ssize_t, ip_recv_attr_t *);
3220bd670b35SErik Nordmark extern void	ip_setl2src(mblk_t *, ip_recv_attr_t *, ill_t *);
3221bd670b35SErik Nordmark extern mblk_t	*ip_check_and_align_header(mblk_t *, uint_t, ip_recv_attr_t *);
3222bd670b35SErik Nordmark extern mblk_t	*ip_check_length(mblk_t *, uchar_t *, ssize_t, uint_t, uint_t,
3223bd670b35SErik Nordmark     ip_recv_attr_t *);
3224bd670b35SErik Nordmark extern mblk_t	*ip_check_optlen(mblk_t *, ipha_t *, uint_t, uint_t,
3225bd670b35SErik Nordmark     ip_recv_attr_t *);
3226bd670b35SErik Nordmark extern mblk_t	*ip_fix_dbref(mblk_t *, ip_recv_attr_t *);
32277c478bd9Sstevel@tonic-gate extern uint_t	ip_cksum(mblk_t *, int, uint32_t);
32287c478bd9Sstevel@tonic-gate extern int	ip_close(queue_t *, int);
32297c478bd9Sstevel@tonic-gate extern uint16_t	ip_csum_hdr(ipha_t *);
3230bd670b35SErik Nordmark extern void	ip_forward_xmit_v4(nce_t *, ill_t *, mblk_t *, ipha_t *,
3231bd670b35SErik Nordmark     ip_recv_attr_t *, uint32_t, uint32_t);
3232bd670b35SErik Nordmark extern boolean_t ip_forward_options(mblk_t *, ipha_t *, ill_t *,
3233bd670b35SErik Nordmark     ip_recv_attr_t *);
3234bd670b35SErik Nordmark extern int	ip_fragment_v4(mblk_t *, nce_t *, iaflags_t, uint_t, uint32_t,
3235bd670b35SErik Nordmark     uint32_t, zoneid_t, zoneid_t, pfirepostfrag_t postfragfn,
3236bd670b35SErik Nordmark     uintptr_t *cookie);
3237bd670b35SErik Nordmark extern void	ip_proto_not_sup(mblk_t *, ip_recv_attr_t *);
3238f4b3ec61Sdh extern void	ip_ire_g_fini(void);
3239f4b3ec61Sdh extern void	ip_ire_g_init(void);
3240f4b3ec61Sdh extern void	ip_ire_fini(ip_stack_t *);
3241f4b3ec61Sdh extern void	ip_ire_init(ip_stack_t *);
3242bd670b35SErik Nordmark extern void	ip_mdata_to_mhi(ill_t *, mblk_t *, struct mac_header_info_s *);
3243fc80c0dfSnordmark extern int	ip_openv4(queue_t *q, dev_t *devp, int flag, int sflag,
3244fc80c0dfSnordmark 		    cred_t *credp);
3245fc80c0dfSnordmark extern int	ip_openv6(queue_t *q, dev_t *devp, int flag, int sflag,
3246fc80c0dfSnordmark 		    cred_t *credp);
32477c478bd9Sstevel@tonic-gate extern int	ip_reassemble(mblk_t *, ipf_t *, uint_t, boolean_t, ill_t *,
32487c478bd9Sstevel@tonic-gate     size_t);
32497c478bd9Sstevel@tonic-gate extern void	ip_rput(queue_t *, mblk_t *);
3250605445d5Sdg extern void	ip_input(ill_t *, ill_rx_ring_t *, mblk_t *,
3251605445d5Sdg     struct mac_header_info_s *);
3252bd670b35SErik Nordmark extern void	ip_input_v6(ill_t *, ill_rx_ring_t *, mblk_t *,
3253bd670b35SErik Nordmark     struct mac_header_info_s *);
3254bd670b35SErik Nordmark extern mblk_t	*ip_input_common_v4(ill_t *, ill_rx_ring_t *, mblk_t *,
3255bd670b35SErik Nordmark     struct mac_header_info_s *, squeue_t *, mblk_t **, uint_t *);
3256bd670b35SErik Nordmark extern mblk_t	*ip_input_common_v6(ill_t *, ill_rx_ring_t *, mblk_t *,
3257bd670b35SErik Nordmark     struct mac_header_info_s *, squeue_t *, mblk_t **, uint_t *);
3258bd670b35SErik Nordmark extern void	ill_input_full_v4(mblk_t *, void *, void *,
3259bd670b35SErik Nordmark     ip_recv_attr_t *, rtc_t *);
3260bd670b35SErik Nordmark extern void	ill_input_short_v4(mblk_t *, void *, void *,
3261bd670b35SErik Nordmark     ip_recv_attr_t *, rtc_t *);
3262bd670b35SErik Nordmark extern void	ill_input_full_v6(mblk_t *, void *, void *,
3263bd670b35SErik Nordmark     ip_recv_attr_t *, rtc_t *);
3264bd670b35SErik Nordmark extern void	ill_input_short_v6(mblk_t *, void *, void *,
3265bd670b35SErik Nordmark     ip_recv_attr_t *, rtc_t *);
3266bd670b35SErik Nordmark extern ipaddr_t	ip_input_options(ipha_t *, ipaddr_t, mblk_t *,
3267bd670b35SErik Nordmark     ip_recv_attr_t *, int *);
3268bd670b35SErik Nordmark extern boolean_t ip_input_local_options(mblk_t *, ipha_t *, ip_recv_attr_t *);
3269bd670b35SErik Nordmark extern mblk_t	*ip_input_fragment(mblk_t *, ipha_t *, ip_recv_attr_t *);
3270bd670b35SErik Nordmark extern mblk_t	*ip_input_fragment_v6(mblk_t *, ip6_t *, ip6_frag_t *, uint_t,
3271bd670b35SErik Nordmark     ip_recv_attr_t *);
3272bd670b35SErik Nordmark extern void	ip_input_post_ipsec(mblk_t *, ip_recv_attr_t *);
3273bd670b35SErik Nordmark extern void	ip_fanout_v4(mblk_t *, ipha_t *, ip_recv_attr_t *);
3274bd670b35SErik Nordmark extern void	ip_fanout_v6(mblk_t *, ip6_t *, ip_recv_attr_t *);
3275bd670b35SErik Nordmark extern void	ip_fanout_proto_conn(conn_t *, mblk_t *, ipha_t *, ip6_t *,
3276bd670b35SErik Nordmark     ip_recv_attr_t *);
3277bd670b35SErik Nordmark extern void	ip_fanout_proto_v4(mblk_t *, ipha_t *, ip_recv_attr_t *);
3278bd670b35SErik Nordmark extern void	ip_fanout_send_icmp_v4(mblk_t *, uint_t, uint_t,
3279bd670b35SErik Nordmark     ip_recv_attr_t *);
3280bd670b35SErik Nordmark extern void	ip_fanout_udp_conn(conn_t *, mblk_t *, ipha_t *, ip6_t *,
3281bd670b35SErik Nordmark     ip_recv_attr_t *);
3282bd670b35SErik Nordmark extern void	ip_fanout_udp_multi_v4(mblk_t *, ipha_t *, uint16_t, uint16_t,
3283bd670b35SErik Nordmark     ip_recv_attr_t *);
3284bd670b35SErik Nordmark extern mblk_t	*zero_spi_check(mblk_t *, ip_recv_attr_t *);
3285bd670b35SErik Nordmark extern void	ip_build_hdrs_v4(uchar_t *, uint_t, const ip_pkt_t *, uint8_t);
3286bd670b35SErik Nordmark extern int	ip_find_hdr_v4(ipha_t *, ip_pkt_t *, boolean_t);
3287bd670b35SErik Nordmark extern int	ip_total_hdrs_len_v4(const ip_pkt_t *);
3288bd670b35SErik Nordmark 
3289da14cebeSEric Cheng extern mblk_t	*ip_accept_tcp(ill_t *, ill_rx_ring_t *, squeue_t *,
3290da14cebeSEric Cheng     mblk_t *, mblk_t **, uint_t *cnt);
3291bd670b35SErik Nordmark extern void	ip_rput_dlpi(ill_t *, mblk_t *);
3292bd670b35SErik Nordmark extern void	ip_rput_notdata(ill_t *, mblk_t *);
3293ff550d0eSmasputra 
32943173664eSapersson extern void	ip_mib2_add_ip_stats(mib2_ipIfStatsEntry_t *,
32953173664eSapersson 		    mib2_ipIfStatsEntry_t *);
32963173664eSapersson extern void	ip_mib2_add_icmp6_stats(mib2_ipv6IfIcmpEntry_t *,
32973173664eSapersson 		    mib2_ipv6IfIcmpEntry_t *);
32987c478bd9Sstevel@tonic-gate extern void	ip_rput_other(ipsq_t *, queue_t *, mblk_t *, void *);
329912dfe4f0Sja extern ire_t	*ip_check_multihome(void *, ire_t *, ill_t *);
3300bd670b35SErik Nordmark extern void	ip_send_potential_redirect_v4(mblk_t *, ipha_t *, ire_t *,
3301bd670b35SErik Nordmark     ip_recv_attr_t *);
3302bd670b35SErik Nordmark extern int	ip_set_destination_v4(ipaddr_t *, ipaddr_t, ipaddr_t,
3303bd670b35SErik Nordmark     ip_xmit_attr_t *, iulp_t *, uint32_t, uint_t);
3304bd670b35SErik Nordmark extern int	ip_set_destination_v6(in6_addr_t *, const in6_addr_t *,
3305bd670b35SErik Nordmark     const in6_addr_t *, ip_xmit_attr_t *, iulp_t *, uint32_t, uint_t);
3306bd670b35SErik Nordmark 
3307bd670b35SErik Nordmark extern int	ip_output_simple(mblk_t *, ip_xmit_attr_t *);
3308bd670b35SErik Nordmark extern int	ip_output_simple_v4(mblk_t *, ip_xmit_attr_t *);
3309bd670b35SErik Nordmark extern int	ip_output_simple_v6(mblk_t *, ip_xmit_attr_t *);
3310bd670b35SErik Nordmark extern int	ip_output_options(mblk_t *, ipha_t *, ip_xmit_attr_t *,
3311bd670b35SErik Nordmark     ill_t *);
3312bd670b35SErik Nordmark extern void	ip_output_local_options(ipha_t *, ip_stack_t *);
3313bd670b35SErik Nordmark 
3314bd670b35SErik Nordmark extern ip_xmit_attr_t *conn_get_ixa(conn_t *, boolean_t);
3315bd670b35SErik Nordmark extern ip_xmit_attr_t *conn_get_ixa_tryhard(conn_t *, boolean_t);
3316bd670b35SErik Nordmark extern ip_xmit_attr_t *conn_replace_ixa(conn_t *, ip_xmit_attr_t *);
3317bd670b35SErik Nordmark extern ip_xmit_attr_t *conn_get_ixa_exclusive(conn_t *);
3318bd670b35SErik Nordmark extern ip_xmit_attr_t *ip_xmit_attr_duplicate(ip_xmit_attr_t *);
3319bd670b35SErik Nordmark extern void	ip_xmit_attr_replace_tsl(ip_xmit_attr_t *, ts_label_t *);
3320bd670b35SErik Nordmark extern void	ip_xmit_attr_restore_tsl(ip_xmit_attr_t *, cred_t *);
3321bd670b35SErik Nordmark boolean_t	ip_recv_attr_replace_label(ip_recv_attr_t *, ts_label_t *);
3322bd670b35SErik Nordmark extern void	ixa_inactive(ip_xmit_attr_t *);
3323bd670b35SErik Nordmark extern void	ixa_refrele(ip_xmit_attr_t *);
3324bd670b35SErik Nordmark extern boolean_t ixa_check_drain_insert(conn_t *, ip_xmit_attr_t *);
3325bd670b35SErik Nordmark extern void	ixa_cleanup(ip_xmit_attr_t *);
3326bd670b35SErik Nordmark extern void	ira_cleanup(ip_recv_attr_t *, boolean_t);
3327bd670b35SErik Nordmark extern void	ixa_safe_copy(ip_xmit_attr_t *, ip_xmit_attr_t *);
3328bd670b35SErik Nordmark 
3329bd670b35SErik Nordmark extern int	conn_ip_output(mblk_t *, ip_xmit_attr_t *);
3330bd670b35SErik Nordmark extern boolean_t ip_output_verify_local(ip_xmit_attr_t *);
3331bd670b35SErik Nordmark extern mblk_t	*ip_output_process_local(mblk_t *, ip_xmit_attr_t *, boolean_t,
3332bd670b35SErik Nordmark     boolean_t, conn_t *);
3333bd670b35SErik Nordmark 
3334bd670b35SErik Nordmark extern int	conn_opt_get(conn_opt_arg_t *, t_scalar_t, t_scalar_t,
3335bd670b35SErik Nordmark     uchar_t *);
3336bd670b35SErik Nordmark extern int	conn_opt_set(conn_opt_arg_t *, t_scalar_t, t_scalar_t, uint_t,
3337bd670b35SErik Nordmark     uchar_t *, boolean_t, cred_t *);
3338bd670b35SErik Nordmark extern boolean_t	conn_same_as_last_v4(conn_t *, sin_t *);
3339bd670b35SErik Nordmark extern boolean_t	conn_same_as_last_v6(conn_t *, sin6_t *);
3340bd670b35SErik Nordmark extern int	conn_update_label(const conn_t *, const ip_xmit_attr_t *,
3341bd670b35SErik Nordmark     const in6_addr_t *, ip_pkt_t *);
3342bd670b35SErik Nordmark 
3343bd670b35SErik Nordmark extern int	ip_opt_set_multicast_group(conn_t *, t_scalar_t,
3344bd670b35SErik Nordmark     uchar_t *, boolean_t, boolean_t);
3345bd670b35SErik Nordmark extern int	ip_opt_set_multicast_sources(conn_t *, t_scalar_t,
3346bd670b35SErik Nordmark     uchar_t *, boolean_t, boolean_t);
3347bd670b35SErik Nordmark extern int	conn_getsockname(conn_t *, struct sockaddr *, uint_t *);
3348bd670b35SErik Nordmark extern int	conn_getpeername(conn_t *, struct sockaddr *, uint_t *);
3349bd670b35SErik Nordmark 
3350bd670b35SErik Nordmark extern int	conn_build_hdr_template(conn_t *, uint_t, uint_t,
3351bd670b35SErik Nordmark     const in6_addr_t *, const in6_addr_t *, uint32_t);
3352bd670b35SErik Nordmark extern mblk_t	*conn_prepend_hdr(ip_xmit_attr_t *, const ip_pkt_t *,
3353bd670b35SErik Nordmark     const in6_addr_t *, const in6_addr_t *, uint8_t, uint32_t, uint_t,
3354bd670b35SErik Nordmark     mblk_t *, uint_t, uint_t, uint32_t *, int *);
3355bd670b35SErik Nordmark extern void	ip_attr_newdst(ip_xmit_attr_t *);
3356bd670b35SErik Nordmark extern void	ip_attr_nexthop(const ip_pkt_t *, const ip_xmit_attr_t *,
3357bd670b35SErik Nordmark     const in6_addr_t *, in6_addr_t *);
3358bd670b35SErik Nordmark extern int	conn_connect(conn_t *, iulp_t *, uint32_t);
3359bd670b35SErik Nordmark extern int	ip_attr_connect(const conn_t *, ip_xmit_attr_t *,
3360bd670b35SErik Nordmark     const in6_addr_t *, const in6_addr_t *, const in6_addr_t *, in_port_t,
3361bd670b35SErik Nordmark     in6_addr_t *, iulp_t *, uint32_t);
3362bd670b35SErik Nordmark extern int	conn_inherit_parent(conn_t *, conn_t *);
3363bd670b35SErik Nordmark 
3364bd670b35SErik Nordmark extern void	conn_ixa_cleanup(conn_t *connp, void *arg);
3365bd670b35SErik Nordmark 
3366bd670b35SErik Nordmark extern boolean_t conn_wantpacket(conn_t *, ip_recv_attr_t *, ipha_t *);
3367bd670b35SErik Nordmark extern uint_t	ip_type_v4(ipaddr_t, ip_stack_t *);
3368bd670b35SErik Nordmark extern uint_t	ip_type_v6(const in6_addr_t *, ip_stack_t *);
3369bd670b35SErik Nordmark 
3370bd670b35SErik Nordmark extern void	ip_wput_nondata(queue_t *, mblk_t *);
33717c478bd9Sstevel@tonic-gate extern void	ip_wsrv(queue_t *);
33727c478bd9Sstevel@tonic-gate extern char	*ip_nv_lookup(nv_t *, int);
33737c478bd9Sstevel@tonic-gate extern boolean_t ip_local_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
33747c478bd9Sstevel@tonic-gate extern boolean_t ip_remote_addr_ok_v6(const in6_addr_t *, const in6_addr_t *);
3375f4b3ec61Sdh extern ipaddr_t ip_massage_options(ipha_t *, netstack_t *);
33767c478bd9Sstevel@tonic-gate extern ipaddr_t ip_net_mask(ipaddr_t);
3377bd670b35SErik Nordmark extern void	arp_bringup_done(ill_t *, int);
3378bd670b35SErik Nordmark extern void	arp_replumb_done(ill_t *, int);
33797c478bd9Sstevel@tonic-gate 
3380fc80c0dfSnordmark extern struct qinit iprinitv6;
33817c478bd9Sstevel@tonic-gate 
3382e11c3f44Smeem extern void	ipmp_init(ip_stack_t *);
3383e11c3f44Smeem extern void	ipmp_destroy(ip_stack_t *);
3384e11c3f44Smeem extern ipmp_grp_t *ipmp_grp_create(const char *, phyint_t *);
3385e11c3f44Smeem extern void	ipmp_grp_destroy(ipmp_grp_t *);
3386e11c3f44Smeem extern void	ipmp_grp_info(const ipmp_grp_t *, lifgroupinfo_t *);
3387e11c3f44Smeem extern int	ipmp_grp_rename(ipmp_grp_t *, const char *);
3388e11c3f44Smeem extern ipmp_grp_t *ipmp_grp_lookup(const char *, ip_stack_t *);
3389e11c3f44Smeem extern int	ipmp_grp_vet_phyint(ipmp_grp_t *, phyint_t *);
3390e11c3f44Smeem extern ipmp_illgrp_t *ipmp_illgrp_create(ill_t *);
3391e11c3f44Smeem extern void	ipmp_illgrp_destroy(ipmp_illgrp_t *);
3392e11c3f44Smeem extern ill_t	*ipmp_illgrp_add_ipif(ipmp_illgrp_t *, ipif_t *);
3393e11c3f44Smeem extern void	ipmp_illgrp_del_ipif(ipmp_illgrp_t *, ipif_t *);
3394e11c3f44Smeem extern ill_t	*ipmp_illgrp_next_ill(ipmp_illgrp_t *);
3395e11c3f44Smeem extern ill_t	*ipmp_illgrp_hold_next_ill(ipmp_illgrp_t *);
3396e11c3f44Smeem extern ill_t	*ipmp_illgrp_hold_cast_ill(ipmp_illgrp_t *);
3397e11c3f44Smeem extern ill_t	*ipmp_illgrp_ipmp_ill(ipmp_illgrp_t *);
3398e11c3f44Smeem extern void	ipmp_illgrp_refresh_mtu(ipmp_illgrp_t *);
3399bd670b35SErik Nordmark extern ipmp_arpent_t *ipmp_illgrp_create_arpent(ipmp_illgrp_t *,
3400bd670b35SErik Nordmark     boolean_t, ipaddr_t, uchar_t *, size_t, uint16_t);
3401e11c3f44Smeem extern void	ipmp_illgrp_destroy_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3402e11c3f44Smeem extern ipmp_arpent_t *ipmp_illgrp_lookup_arpent(ipmp_illgrp_t *, ipaddr_t *);
3403e11c3f44Smeem extern void	ipmp_illgrp_refresh_arpent(ipmp_illgrp_t *);
3404e11c3f44Smeem extern void	ipmp_illgrp_mark_arpent(ipmp_illgrp_t *, ipmp_arpent_t *);
3405e11c3f44Smeem extern ill_t	*ipmp_illgrp_find_ill(ipmp_illgrp_t *, uchar_t *, uint_t);
3406e11c3f44Smeem extern void	ipmp_illgrp_link_grp(ipmp_illgrp_t *, ipmp_grp_t *);
3407e11c3f44Smeem extern int	ipmp_illgrp_unlink_grp(ipmp_illgrp_t *);
3408e11c3f44Smeem extern uint_t	ipmp_ill_get_ipmp_ifindex(const ill_t *);
3409e11c3f44Smeem extern void	ipmp_ill_join_illgrp(ill_t *, ipmp_illgrp_t *);
3410e11c3f44Smeem extern void	ipmp_ill_leave_illgrp(ill_t *);
3411e11c3f44Smeem extern ill_t	*ipmp_ill_hold_ipmp_ill(ill_t *);
34121f19738eSmeem extern ill_t	*ipmp_ill_hold_xmit_ill(ill_t *, boolean_t);
3413e11c3f44Smeem extern boolean_t ipmp_ill_is_active(ill_t *);
3414e11c3f44Smeem extern void	ipmp_ill_refresh_active(ill_t *);
3415e11c3f44Smeem extern void	ipmp_phyint_join_grp(phyint_t *, ipmp_grp_t *);
3416e11c3f44Smeem extern void	ipmp_phyint_leave_grp(phyint_t *);
3417e11c3f44Smeem extern void	ipmp_phyint_refresh_active(phyint_t *);
3418e11c3f44Smeem extern ill_t	*ipmp_ipif_bound_ill(const ipif_t *);
3419e11c3f44Smeem extern ill_t	*ipmp_ipif_hold_bound_ill(const ipif_t *);
3420e11c3f44Smeem extern boolean_t ipmp_ipif_is_dataaddr(const ipif_t *);
3421e11c3f44Smeem extern boolean_t ipmp_ipif_is_stubaddr(const ipif_t *);
3422bd670b35SErik Nordmark extern boolean_t ipmp_packet_is_probe(mblk_t *, ill_t *);
34231f19738eSmeem extern void	ipmp_ncec_delete_nce(ncec_t *);
34241f19738eSmeem extern void	ipmp_ncec_refresh_nce(ncec_t *);
3425e11c3f44Smeem 
3426ae6aa22aSVenugopal Iyer extern void	conn_drain_insert(conn_t *, idl_tx_list_t *);
3427bd670b35SErik Nordmark extern void	conn_setqfull(conn_t *, boolean_t *);
3428bd670b35SErik Nordmark extern void	conn_clrqfull(conn_t *, boolean_t *);
3429ae6aa22aSVenugopal Iyer extern int	conn_ipsec_length(conn_t *);
34307c478bd9Sstevel@tonic-gate extern ipaddr_t	ip_get_dst(ipha_t *);
3431bd670b35SErik Nordmark extern uint_t	ip_get_pmtu(ip_xmit_attr_t *);
3432bd670b35SErik Nordmark extern uint_t	ip_get_base_mtu(ill_t *, ire_t *);
3433bd670b35SErik Nordmark extern mblk_t *ip_output_attach_policy(mblk_t *, ipha_t *, ip6_t *,
3434bd670b35SErik Nordmark     const conn_t *, ip_xmit_attr_t *);
3435bd670b35SErik Nordmark extern int	ipsec_out_extra_length(ip_xmit_attr_t *);
3436bd670b35SErik Nordmark extern int	ipsec_out_process(mblk_t *, ip_xmit_attr_t *);
3437bd670b35SErik Nordmark extern int	ip_output_post_ipsec(mblk_t *, ip_xmit_attr_t *);
3438bd670b35SErik Nordmark extern void	ipsec_out_to_in(ip_xmit_attr_t *, ill_t *ill,
3439bd670b35SErik Nordmark     ip_recv_attr_t *);
34407c478bd9Sstevel@tonic-gate 
34417c478bd9Sstevel@tonic-gate extern void	ire_cleanup(ire_t *);
34427c478bd9Sstevel@tonic-gate extern void	ire_inactive(ire_t *);
3443c793af95Ssangeeta extern boolean_t irb_inactive(irb_t *);
34447c478bd9Sstevel@tonic-gate extern ire_t	*ire_unlink(irb_t *);
34456a8288c7Scarlsonj 
34466a8288c7Scarlsonj #ifdef DEBUG
34476a8288c7Scarlsonj extern	boolean_t th_trace_ref(const void *, ip_stack_t *);
34486a8288c7Scarlsonj extern	void	th_trace_unref(const void *);
34496a8288c7Scarlsonj extern	void	th_trace_cleanup(const void *, boolean_t);
34506a8288c7Scarlsonj extern	void	ire_trace_ref(ire_t *);
34516a8288c7Scarlsonj extern	void	ire_untrace_ref(ire_t *);
34527c478bd9Sstevel@tonic-gate #endif
34537c478bd9Sstevel@tonic-gate 
3454f4b3ec61Sdh extern int	ip_srcid_insert(const in6_addr_t *, zoneid_t, ip_stack_t *);
3455f4b3ec61Sdh extern int	ip_srcid_remove(const in6_addr_t *, zoneid_t, ip_stack_t *);
3456f4b3ec61Sdh extern void	ip_srcid_find_id(uint_t, in6_addr_t *, zoneid_t, netstack_t *);
3457f4b3ec61Sdh extern uint_t	ip_srcid_find_addr(const in6_addr_t *, zoneid_t, netstack_t *);
34587c478bd9Sstevel@tonic-gate 
34597c478bd9Sstevel@tonic-gate extern uint8_t	ipoptp_next(ipoptp_t *);
34607c478bd9Sstevel@tonic-gate extern uint8_t	ipoptp_first(ipoptp_t *, ipha_t *);
3461bd670b35SErik Nordmark extern int	ip_opt_get_user(conn_t *, uchar_t *);
34627c478bd9Sstevel@tonic-gate extern int	ipsec_req_from_conn(conn_t *, ipsec_req_t *, int);
34636f773e29SBaban Kenkre extern int	ip_snmp_get(queue_t *q, mblk_t *mctl, int level, boolean_t);
34647c478bd9Sstevel@tonic-gate extern int	ip_snmp_set(queue_t *q, int, int, uchar_t *, int);
34657c478bd9Sstevel@tonic-gate extern void	ip_process_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3466ff550d0eSmasputra extern void	ip_quiesce_conn(conn_t *);
34677c478bd9Sstevel@tonic-gate extern  void    ip_reprocess_ioctl(ipsq_t *, queue_t *, mblk_t *, void *);
3468b051ecf6Smeem extern void	ip_ioctl_finish(queue_t *, mblk_t *, int, int, ipsq_t *);
34697c478bd9Sstevel@tonic-gate 
347045916cd2Sjpk extern boolean_t ip_cmpbuf(const void *, uint_t, boolean_t, const void *,
347145916cd2Sjpk     uint_t);
347245916cd2Sjpk extern boolean_t ip_allocbuf(void **, uint_t *, boolean_t, const void *,
347345916cd2Sjpk     uint_t);
347445916cd2Sjpk extern void	ip_savebuf(void **, uint_t *, boolean_t, const void *, uint_t);
347545916cd2Sjpk 
34767c478bd9Sstevel@tonic-gate extern boolean_t	ipsq_pending_mp_cleanup(ill_t *, conn_t *);
34777c478bd9Sstevel@tonic-gate extern void	conn_ioctl_cleanup(conn_t *);
3478bd670b35SErik Nordmark 
34792b24ab6bSSebastien Roy extern void	ip_unbind(conn_t *);
34807c478bd9Sstevel@tonic-gate 
348145916cd2Sjpk extern void tnet_init(void);
348245916cd2Sjpk extern void tnet_fini(void);
348345916cd2Sjpk 
3484bd670b35SErik Nordmark /*
3485bd670b35SErik Nordmark  * Hook functions to enable cluster networking
3486bd670b35SErik Nordmark  * On non-clustered systems these vectors must always be NULL.
3487bd670b35SErik Nordmark  */
3488bd670b35SErik Nordmark extern int (*cl_inet_isclusterwide)(netstackid_t stack_id, uint8_t protocol,
3489bd670b35SErik Nordmark     sa_family_t addr_family, uint8_t *laddrp, void *args);
3490bd670b35SErik Nordmark extern uint32_t (*cl_inet_ipident)(netstackid_t stack_id, uint8_t protocol,
3491bd670b35SErik Nordmark     sa_family_t addr_family, uint8_t *laddrp, uint8_t *faddrp,
3492bd670b35SErik Nordmark     void *args);
3493bd670b35SErik Nordmark extern int (*cl_inet_connect2)(netstackid_t stack_id, uint8_t protocol,
3494bd670b35SErik Nordmark     boolean_t is_outgoing, sa_family_t addr_family, uint8_t *laddrp,
3495bd670b35SErik Nordmark     in_port_t lport, uint8_t *faddrp, in_port_t fport, void *args);
3496bd670b35SErik Nordmark extern void (*cl_inet_getspi)(netstackid_t, uint8_t, uint8_t *, size_t,
3497bd670b35SErik Nordmark     void *);
3498bd670b35SErik Nordmark extern void (*cl_inet_getspi)(netstackid_t stack_id, uint8_t protocol,
3499bd670b35SErik Nordmark     uint8_t *ptr, size_t len, void *args);
3500bd670b35SErik Nordmark extern int (*cl_inet_checkspi)(netstackid_t stack_id, uint8_t protocol,
3501bd670b35SErik Nordmark     uint32_t spi, void *args);
3502bd670b35SErik Nordmark extern void (*cl_inet_deletespi)(netstackid_t stack_id, uint8_t protocol,
3503bd670b35SErik Nordmark     uint32_t spi, void *args);
3504bd670b35SErik Nordmark extern void (*cl_inet_idlesa)(netstackid_t, uint8_t, uint32_t,
3505bd670b35SErik Nordmark     sa_family_t, in6_addr_t, in6_addr_t, void *);
3506bd670b35SErik Nordmark 
3507bd670b35SErik Nordmark 
35087c478bd9Sstevel@tonic-gate /* Hooks for CGTP (multirt routes) filtering module */
35097c478bd9Sstevel@tonic-gate #define	CGTP_FILTER_REV_1	1
35107c478bd9Sstevel@tonic-gate #define	CGTP_FILTER_REV_2	2
3511655a42e2Snordmark #define	CGTP_FILTER_REV_3	3
3512655a42e2Snordmark #define	CGTP_FILTER_REV		CGTP_FILTER_REV_3
35137c478bd9Sstevel@tonic-gate 
3514655a42e2Snordmark /* cfo_filter and cfo_filter_v6 hooks return values */
35157c478bd9Sstevel@tonic-gate #define	CGTP_IP_PKT_NOT_CGTP	0
35167c478bd9Sstevel@tonic-gate #define	CGTP_IP_PKT_PREMIUM	1
35177c478bd9Sstevel@tonic-gate #define	CGTP_IP_PKT_DUPLICATE	2
35187c478bd9Sstevel@tonic-gate 
3519655a42e2Snordmark /* Version 3 of the filter interface */
35207c478bd9Sstevel@tonic-gate typedef struct cgtp_filter_ops {
3521655a42e2Snordmark 	int	cfo_filter_rev;			/* CGTP_FILTER_REV_3 */
3522655a42e2Snordmark 	int	(*cfo_change_state)(netstackid_t, int);
3523655a42e2Snordmark 	int	(*cfo_add_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t,
3524655a42e2Snordmark 		    ipaddr_t, ipaddr_t);
3525655a42e2Snordmark 	int	(*cfo_del_dest_v4)(netstackid_t, ipaddr_t, ipaddr_t);
3526655a42e2Snordmark 	int	(*cfo_add_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *,
3527655a42e2Snordmark 		    in6_addr_t *, in6_addr_t *);
3528655a42e2Snordmark 	int	(*cfo_del_dest_v6)(netstackid_t, in6_addr_t *, in6_addr_t *);
3529655a42e2Snordmark 	int	(*cfo_filter)(netstackid_t, uint_t, mblk_t *);
3530655a42e2Snordmark 	int	(*cfo_filter_v6)(netstackid_t, uint_t, ip6_t *,
3531655a42e2Snordmark 		    ip6_frag_t *);
35327c478bd9Sstevel@tonic-gate } cgtp_filter_ops_t;
35337c478bd9Sstevel@tonic-gate 
35347c478bd9Sstevel@tonic-gate #define	CGTP_MCAST_SUCCESS	1
35357c478bd9Sstevel@tonic-gate 
3536f4b3ec61Sdh /*
3537655a42e2Snordmark  * The separate CGTP module needs this global symbol so that it
3538655a42e2Snordmark  * can check the version and determine whether to use the old or the new
3539655a42e2Snordmark  * version of the filtering interface.
3540f4b3ec61Sdh  */
3541655a42e2Snordmark extern int	ip_cgtp_filter_rev;
35427c478bd9Sstevel@tonic-gate 
35437c478bd9Sstevel@tonic-gate extern int	ip_cgtp_filter_supported(void);
3544655a42e2Snordmark extern int	ip_cgtp_filter_register(netstackid_t, cgtp_filter_ops_t *);
3545655a42e2Snordmark extern int	ip_cgtp_filter_unregister(netstackid_t);
3546655a42e2Snordmark extern int	ip_cgtp_filter_is_registered(netstackid_t);
35477c478bd9Sstevel@tonic-gate 
3548da14cebeSEric Cheng /*
3549da14cebeSEric Cheng  * rr_ring_state cycles in the order shown below from RR_FREE through
3550da14cebeSEric Cheng  * RR_FREE_IN_PROG and  back to RR_FREE.
3551da14cebeSEric Cheng  */
3552da14cebeSEric Cheng typedef enum {
3553da14cebeSEric Cheng 	RR_FREE,			/* Free slot */
3554da14cebeSEric Cheng 	RR_SQUEUE_UNBOUND,		/* Ring's squeue is unbound */
3555da14cebeSEric Cheng 	RR_SQUEUE_BIND_INPROG,		/* Ring's squeue bind in progress */
3556da14cebeSEric Cheng 	RR_SQUEUE_BOUND,		/* Ring's squeue bound to cpu */
3557da14cebeSEric Cheng 	RR_FREE_INPROG			/* Ring is being freed */
3558da14cebeSEric Cheng } ip_ring_state_t;
35597c478bd9Sstevel@tonic-gate 
35607c478bd9Sstevel@tonic-gate #define	ILL_MAX_RINGS		256	/* Max num of rx rings we can manage */
35617c478bd9Sstevel@tonic-gate #define	ILL_POLLING		0x01	/* Polling in use */
35627c478bd9Sstevel@tonic-gate 
35637c478bd9Sstevel@tonic-gate /*
35644b46d1efSkrgopi  * These functions pointer types are exported by the mac/dls layer.
35654b46d1efSkrgopi  * we need to duplicate the definitions here because we cannot
35664b46d1efSkrgopi  * include mac/dls header files here.
35677c478bd9Sstevel@tonic-gate  */
3568efe28d82SRajagopal Kunhappan typedef boolean_t		(*ip_mac_intr_disable_t)(void *);
3569ae6aa22aSVenugopal Iyer typedef void			(*ip_mac_intr_enable_t)(void *);
3570ae6aa22aSVenugopal Iyer typedef ip_mac_tx_cookie_t	(*ip_dld_tx_t)(void *, mblk_t *,
3571ae6aa22aSVenugopal Iyer     uint64_t, uint16_t);
3572ae6aa22aSVenugopal Iyer typedef	void			(*ip_flow_enable_t)(void *, ip_mac_tx_cookie_t);
3573ae6aa22aSVenugopal Iyer typedef void			*(*ip_dld_callb_t)(void *,
3574ae6aa22aSVenugopal Iyer     ip_flow_enable_t, void *);
3575ae6aa22aSVenugopal Iyer typedef boolean_t		(*ip_dld_fctl_t)(void *, ip_mac_tx_cookie_t);
3576ae6aa22aSVenugopal Iyer typedef int			(*ip_capab_func_t)(void *, uint_t,
3577ae6aa22aSVenugopal Iyer     void *, uint_t);
35784b46d1efSkrgopi 
3579da14cebeSEric Cheng /*
3580da14cebeSEric Cheng  * POLLING README
3581da14cebeSEric Cheng  * sq_get_pkts() is called to pick packets from softring in poll mode. It
3582da14cebeSEric Cheng  * calls rr_rx to get the chain and process it with rr_ip_accept.
3583da14cebeSEric Cheng  * rr_rx = mac_soft_ring_poll() to pick packets
3584da14cebeSEric Cheng  * rr_ip_accept = ip_accept_tcp() to process packets
3585da14cebeSEric Cheng  */
35867c478bd9Sstevel@tonic-gate 
3587da14cebeSEric Cheng /*
3588da14cebeSEric Cheng  * XXX: With protocol, service specific squeues, they will have
3589da14cebeSEric Cheng  * specific acceptor functions.
3590da14cebeSEric Cheng  */
3591da14cebeSEric Cheng typedef	mblk_t *(*ip_mac_rx_t)(void *, size_t);
3592da14cebeSEric Cheng typedef mblk_t *(*ip_accept_t)(ill_t *, ill_rx_ring_t *,
3593da14cebeSEric Cheng     squeue_t *, mblk_t *, mblk_t **, uint_t *);
3594da14cebeSEric Cheng 
3595da14cebeSEric Cheng /*
3596da14cebeSEric Cheng  * rr_intr_enable, rr_intr_disable, rr_rx_handle, rr_rx:
3597da14cebeSEric Cheng  * May be accessed while in the squeue AND after checking that SQS_POLL_CAPAB
3598da14cebeSEric Cheng  * is set.
3599da14cebeSEric Cheng  *
3600da14cebeSEric Cheng  * rr_ring_state: Protected by ill_lock.
3601da14cebeSEric Cheng  */
36027c478bd9Sstevel@tonic-gate struct ill_rx_ring {
3603da14cebeSEric Cheng 	ip_mac_intr_disable_t	rr_intr_disable; /* Interrupt disabling func */
3604da14cebeSEric Cheng 	ip_mac_intr_enable_t	rr_intr_enable;	/* Interrupt enabling func */
3605da14cebeSEric Cheng 	void			*rr_intr_handle; /* Handle interrupt funcs */
3606da14cebeSEric Cheng 	ip_mac_rx_t		rr_rx;		/* Driver receive function */
3607da14cebeSEric Cheng 	ip_accept_t		rr_ip_accept;	/* IP accept function */
3608da14cebeSEric Cheng 	void			*rr_rx_handle;	/* Handle for Rx ring */
36097c478bd9Sstevel@tonic-gate 	squeue_t		*rr_sqp; /* Squeue the ring is bound to */
3610da14cebeSEric Cheng 	ill_t			*rr_ill;	/* back pointer to ill */
3611da14cebeSEric Cheng 	ip_ring_state_t		rr_ring_state;	/* State of this ring */
36127c478bd9Sstevel@tonic-gate };
36137c478bd9Sstevel@tonic-gate 
3614da14cebeSEric Cheng /*
3615da14cebeSEric Cheng  * IP - DLD direct function call capability
3616da14cebeSEric Cheng  * Suffixes, df - dld function, dh - dld handle,
3617da14cebeSEric Cheng  * cf - client (IP) function, ch - client handle
3618da14cebeSEric Cheng  */
3619da14cebeSEric Cheng typedef struct ill_dld_direct_s {		/* DLD provided driver Tx */
3620da14cebeSEric Cheng 	ip_dld_tx_t		idd_tx_df;	/* str_mdata_fastpath_put */
3621da14cebeSEric Cheng 	void			*idd_tx_dh;	/* dld_str_t *dsp */
3622da14cebeSEric Cheng 	ip_dld_callb_t		idd_tx_cb_df;	/* mac_tx_srs_notify */
3623da14cebeSEric Cheng 	void			*idd_tx_cb_dh;	/* mac_client_handle_t *mch */
3624ae6aa22aSVenugopal Iyer 	ip_dld_fctl_t		idd_tx_fctl_df;	/* mac_tx_is_flow_blocked */
3625ae6aa22aSVenugopal Iyer 	void			*idd_tx_fctl_dh;	/* mac_client_handle */
3626da14cebeSEric Cheng } ill_dld_direct_t;
3627da14cebeSEric Cheng 
3628da14cebeSEric Cheng /* IP - DLD polling capability */
3629da14cebeSEric Cheng typedef struct ill_dld_poll_s {
3630da14cebeSEric Cheng 	ill_rx_ring_t		idp_ring_tbl[ILL_MAX_RINGS];
3631da14cebeSEric Cheng } ill_dld_poll_t;
3632da14cebeSEric Cheng 
3633da14cebeSEric Cheng /* Describes ill->ill_dld_capab */
3634da14cebeSEric Cheng struct ill_dld_capab_s {
3635da14cebeSEric Cheng 	ip_capab_func_t		idc_capab_df;	/* dld_capab_func */
3636da14cebeSEric Cheng 	void			*idc_capab_dh;	/* dld_str_t *dsp */
3637da14cebeSEric Cheng 	ill_dld_direct_t	idc_direct;
3638da14cebeSEric Cheng 	ill_dld_poll_t		idc_poll;
36397c478bd9Sstevel@tonic-gate };
36407c478bd9Sstevel@tonic-gate 
36417c478bd9Sstevel@tonic-gate /*
36427c478bd9Sstevel@tonic-gate  * IP squeues exports
36437c478bd9Sstevel@tonic-gate  */
36447c478bd9Sstevel@tonic-gate extern boolean_t 	ip_squeue_fanout;
36457c478bd9Sstevel@tonic-gate 
3646da14cebeSEric Cheng #define	IP_SQUEUE_GET(hint) ip_squeue_random(hint)
36477c478bd9Sstevel@tonic-gate 
36487c478bd9Sstevel@tonic-gate extern void ip_squeue_init(void (*)(squeue_t *));
36497c478bd9Sstevel@tonic-gate extern squeue_t	*ip_squeue_random(uint_t);
36507c478bd9Sstevel@tonic-gate extern squeue_t *ip_squeue_get(ill_rx_ring_t *);
3651da14cebeSEric Cheng extern squeue_t *ip_squeue_getfree(pri_t);
3652da14cebeSEric Cheng extern int ip_squeue_cpu_move(squeue_t *, processorid_t);
3653da14cebeSEric Cheng extern void *ip_squeue_add_ring(ill_t *, void *);
3654da14cebeSEric Cheng extern void ip_squeue_bind_ring(ill_t *, ill_rx_ring_t *, processorid_t);
3655da14cebeSEric Cheng extern void ip_squeue_clean_ring(ill_t *, ill_rx_ring_t *);
3656da14cebeSEric Cheng extern void ip_squeue_quiesce_ring(ill_t *, ill_rx_ring_t *);
3657da14cebeSEric Cheng extern void ip_squeue_restart_ring(ill_t *, ill_rx_ring_t *);
36588df01f76Smeem extern void ip_squeue_clean_all(ill_t *);
3659bd670b35SErik Nordmark extern boolean_t	ip_source_routed(ipha_t *, ip_stack_t *);
3660ff550d0eSmasputra 
3661ff550d0eSmasputra extern void tcp_wput(queue_t *, mblk_t *);
36627c478bd9Sstevel@tonic-gate 
3663bd670b35SErik Nordmark extern int	ip_fill_mtuinfo(conn_t *, ip_xmit_attr_t *,
3664bd670b35SErik Nordmark     struct ip6_mtuinfo *);
36650a0e9771SDarren Reed extern hook_t *ipobs_register_hook(netstack_t *, pfv_t);
36660a0e9771SDarren Reed extern void ipobs_unregister_hook(netstack_t *, hook_t *);
36670a0e9771SDarren Reed extern void ipobs_hook(mblk_t *, int, zoneid_t, zoneid_t, const ill_t *,
36680a0e9771SDarren Reed     ip_stack_t *);
3669ff550d0eSmasputra typedef void    (*ipsq_func_t)(ipsq_t *, queue_t *, mblk_t *, void *);
36707c478bd9Sstevel@tonic-gate 
3671bd670b35SErik Nordmark extern void	dce_g_init(void);
3672bd670b35SErik Nordmark extern void	dce_g_destroy(void);
3673bd670b35SErik Nordmark extern void	dce_stack_init(ip_stack_t *);
3674bd670b35SErik Nordmark extern void	dce_stack_destroy(ip_stack_t *);
3675bd670b35SErik Nordmark extern void	dce_cleanup(uint_t, ip_stack_t *);
3676bd670b35SErik Nordmark extern dce_t	*dce_get_default(ip_stack_t *);
3677bd670b35SErik Nordmark extern dce_t	*dce_lookup_pkt(mblk_t *, ip_xmit_attr_t *, uint_t *);
3678bd670b35SErik Nordmark extern dce_t	*dce_lookup_v4(ipaddr_t, ip_stack_t *, uint_t *);
3679bd670b35SErik Nordmark extern dce_t	*dce_lookup_v6(const in6_addr_t *, uint_t, ip_stack_t *,
3680bd670b35SErik Nordmark     uint_t *);
3681bd670b35SErik Nordmark extern dce_t	*dce_lookup_and_add_v4(ipaddr_t, ip_stack_t *);
3682bd670b35SErik Nordmark extern dce_t	*dce_lookup_and_add_v6(const in6_addr_t *, uint_t,
3683bd670b35SErik Nordmark     ip_stack_t *);
3684bd670b35SErik Nordmark extern int	dce_update_uinfo_v4(ipaddr_t, iulp_t *, ip_stack_t *);
3685bd670b35SErik Nordmark extern int	dce_update_uinfo_v6(const in6_addr_t *, uint_t, iulp_t *,
3686bd670b35SErik Nordmark     ip_stack_t *);
3687bd670b35SErik Nordmark extern int	dce_update_uinfo(const in6_addr_t *, uint_t, iulp_t *,
3688bd670b35SErik Nordmark     ip_stack_t *);
3689bd670b35SErik Nordmark extern void	dce_increment_generation(dce_t *);
3690bd670b35SErik Nordmark extern void	dce_increment_all_generations(boolean_t, ip_stack_t *);
3691bd670b35SErik Nordmark extern void	dce_refrele(dce_t *);
3692bd670b35SErik Nordmark extern void	dce_refhold(dce_t *);
3693bd670b35SErik Nordmark extern void	dce_refrele_notr(dce_t *);
3694bd670b35SErik Nordmark extern void	dce_refhold_notr(dce_t *);
3695bd670b35SErik Nordmark mblk_t		*ip_snmp_get_mib2_ip_dce(queue_t *, mblk_t *, ip_stack_t *ipst);
3696bd670b35SErik Nordmark 
3697bd670b35SErik Nordmark extern ip_laddr_t ip_laddr_verify_v4(ipaddr_t, zoneid_t,
3698bd670b35SErik Nordmark     ip_stack_t *, boolean_t);
3699bd670b35SErik Nordmark extern ip_laddr_t ip_laddr_verify_v6(const in6_addr_t *, zoneid_t,
3700bd670b35SErik Nordmark     ip_stack_t *, boolean_t, uint_t);
3701bd670b35SErik Nordmark extern int	ip_laddr_fanout_insert(conn_t *);
3702bd670b35SErik Nordmark 
3703bd670b35SErik Nordmark extern boolean_t ip_verify_src(mblk_t *, ip_xmit_attr_t *, uint_t *);
3704bd670b35SErik Nordmark extern int	ip_verify_ire(mblk_t *, ip_xmit_attr_t *);
3705bd670b35SErik Nordmark 
3706bd670b35SErik Nordmark extern mblk_t	*ip_xmit_attr_to_mblk(ip_xmit_attr_t *);
3707bd670b35SErik Nordmark extern boolean_t ip_xmit_attr_from_mblk(mblk_t *, ip_xmit_attr_t *);
3708bd670b35SErik Nordmark extern mblk_t	*ip_xmit_attr_free_mblk(mblk_t *);
3709bd670b35SErik Nordmark extern mblk_t	*ip_recv_attr_to_mblk(ip_recv_attr_t *);
3710bd670b35SErik Nordmark extern boolean_t ip_recv_attr_from_mblk(mblk_t *, ip_recv_attr_t *);
3711bd670b35SErik Nordmark extern mblk_t	*ip_recv_attr_free_mblk(mblk_t *);
3712bd670b35SErik Nordmark extern boolean_t ip_recv_attr_is_mblk(mblk_t *);
3713bd670b35SErik Nordmark 
3714*59927d31SYuri Pankov #ifdef __PRAGMA_REDEFINE_EXTNAME
3715*59927d31SYuri Pankov #pragma redefine_extname inet_pton _inet_pton
3716*59927d31SYuri Pankov #else /* __PRAGMA_REDEFINE_EXTNAME */
3717*59927d31SYuri Pankov #define	inet_pton _inet_pton
3718*59927d31SYuri Pankov #endif /* __PRAGMA_REDEFINE_EXTNAME */
3719*59927d31SYuri Pankov 
3720*59927d31SYuri Pankov extern char	*inet_ntop(int, const void *, char *, int);
3721*59927d31SYuri Pankov extern int	inet_pton(int, char *, void *);
3722*59927d31SYuri Pankov 
37237c478bd9Sstevel@tonic-gate /*
37247c478bd9Sstevel@tonic-gate  * Squeue tags. Tags only need to be unique when the callback function is the
37257c478bd9Sstevel@tonic-gate  * same to distinguish between different calls, but we use unique tags for
37267c478bd9Sstevel@tonic-gate  * convenience anyway.
37277c478bd9Sstevel@tonic-gate  */
37287c478bd9Sstevel@tonic-gate #define	SQTAG_IP_INPUT			1
37297c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_INPUT_ICMP_ERR	2
37307c478bd9Sstevel@tonic-gate #define	SQTAG_TCP6_INPUT_ICMP_ERR	3
37317c478bd9Sstevel@tonic-gate #define	SQTAG_IP_TCP_INPUT		4
37327c478bd9Sstevel@tonic-gate #define	SQTAG_IP6_TCP_INPUT		5
37337c478bd9Sstevel@tonic-gate #define	SQTAG_IP_TCP_CLOSE		6
37347c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_OUTPUT		7
37357c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_TIMER			8
37367c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_TIMEWAIT		9
37377c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_ACCEPT_FINISH		10
37387c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_ACCEPT_FINISH_Q0	11
37397c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_ACCEPT_PENDING	12
37407c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_LISTEN_DISCON		13
37410163a147Sjprakash #define	SQTAG_TCP_CONN_REQ_1		14
37427c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_EAGER_BLOWOFF		15
37437c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_EAGER_CLEANUP		16
37447c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_EAGER_CLEANUP_Q0	17
37457c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_CONN_IND		18
37467c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_RSRV			19
37477c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_ABORT_BUCKET		20
37487c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_REINPUT		21
37497c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_REINPUT_EAGER		22
37507c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_INPUT_MCTL		23
37517c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_RPUTOTHER		24
37527c478bd9Sstevel@tonic-gate #define	SQTAG_IP_PROTO_AGAIN		25
37537c478bd9Sstevel@tonic-gate #define	SQTAG_IP_FANOUT_TCP		26
37547c478bd9Sstevel@tonic-gate #define	SQTAG_IPSQ_CLEAN_RING		27
37557c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_WPUT_OTHER		28
37567c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_CONN_REQ_UNBOUND	29
37577c478bd9Sstevel@tonic-gate #define	SQTAG_TCP_SEND_PENDING		30
3758ff550d0eSmasputra #define	SQTAG_BIND_RETRY		31
3759ff550d0eSmasputra #define	SQTAG_UDP_FANOUT		32
3760ff550d0eSmasputra #define	SQTAG_UDP_INPUT			33
3761ff550d0eSmasputra #define	SQTAG_UDP_WPUT			34
3762ff550d0eSmasputra #define	SQTAG_UDP_OUTPUT		35
3763c28749e9Skais #define	SQTAG_TCP_KSSL_INPUT		36
3764866ba9ddSjprakash #define	SQTAG_TCP_DROP_Q0		37
37650163a147Sjprakash #define	SQTAG_TCP_CONN_REQ_2		38
3766da14cebeSEric Cheng #define	SQTAG_IP_INPUT_RX_RING		39
3767da14cebeSEric Cheng #define	SQTAG_SQUEUE_CHANGE		40
3768da14cebeSEric Cheng #define	SQTAG_CONNECT_FINISH		41
37690f1702c5SYu Xiangning #define	SQTAG_SYNCHRONOUS_OP		42
37700f1702c5SYu Xiangning #define	SQTAG_TCP_SHUTDOWN_OUTPUT	43
3771bd670b35SErik Nordmark #define	SQTAG_TCP_IXA_CLEANUP		44
37726b7506c7SErik Nordmark #define	SQTAG_TCP_SEND_SYNACK		45
377319a30e1aSrshoaib 
3774721fffe3SKacheong Poon extern sin_t	sin_null;	/* Zero address for quick clears */
3775721fffe3SKacheong Poon extern sin6_t	sin6_null;	/* Zero address for quick clears */
3776721fffe3SKacheong Poon 
37777c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
37787c478bd9Sstevel@tonic-gate 
37797c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
37807c478bd9Sstevel@tonic-gate }
37817c478bd9Sstevel@tonic-gate #endif
37827c478bd9Sstevel@tonic-gate 
37837c478bd9Sstevel@tonic-gate #endif	/* _INET_IP_H */
3784