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