xref: /titanic_51/usr/src/uts/common/inet/ipclassifier.h (revision 5d3b8cb7141cfa596d20cdc5043b8a6df635938d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ee4701baSericheng  * Common Development and Distribution License (the "License").
6ee4701baSericheng  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22bfcb55b8SRao Shoaib  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_INET_IPCLASSIFIER_H
277c478bd9Sstevel@tonic-gate #define	_INET_IPCLASSIFIER_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <inet/common.h>
347c478bd9Sstevel@tonic-gate #include <inet/ip.h>
357c478bd9Sstevel@tonic-gate #include <inet/mi.h>
367c478bd9Sstevel@tonic-gate #include <inet/tcp.h>
377c478bd9Sstevel@tonic-gate #include <inet/ip6.h>
387c478bd9Sstevel@tonic-gate #include <netinet/in.h>		/* for IPPROTO_* constants */
397c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
400f1702c5SYu Xiangning #include <sys/socket_proto.h>
410f1702c5SYu Xiangning #include <sys/sunddi.h>
420f1702c5SYu Xiangning #include <sys/sunldi.h>
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate typedef void (*edesc_spf)(void *, mblk_t *, void *, int);
457c478bd9Sstevel@tonic-gate typedef void (*edesc_rpf)(void *, mblk_t *, void *);
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * ==============================
497c478bd9Sstevel@tonic-gate  * =	The CONNECTION		=
507c478bd9Sstevel@tonic-gate  * ==============================
517c478bd9Sstevel@tonic-gate  */
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * The connection structure contains the common information/flags/ref needed.
557c478bd9Sstevel@tonic-gate  * Implementation will keep the connection struct, the layers (with their
567c478bd9Sstevel@tonic-gate  * respective data for event i.e. tcp_t if event was tcp_input) all in one
577c478bd9Sstevel@tonic-gate  * contiguous memory location.
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* Conn Flags */
61fc80c0dfSnordmark /* Unused			0x00020000 */
62fc80c0dfSnordmark /* Unused			0x00040000 */
637c478bd9Sstevel@tonic-gate #define	IPCL_FULLY_BOUND	0x00080000	/* Bound to correct squeue */
64ff550d0eSmasputra #define	IPCL_CHECK_POLICY	0x00100000	/* Needs policy checking */
65ff550d0eSmasputra #define	IPCL_SOCKET		0x00200000	/* Sockfs connection */
66ff550d0eSmasputra #define	IPCL_ACCEPTOR		0x00400000	/* Sockfs priv acceptor */
67ff550d0eSmasputra #define	IPCL_CL_LISTENER	0x00800000	/* Cluster listener */
68ff550d0eSmasputra #define	IPCL_EAGER		0x01000000	/* Incoming connection */
69fc80c0dfSnordmark /* Unused			0x02000000 */
70fc80c0dfSnordmark #define	IPCL_TCP6		0x04000000	/* AF_INET6 TCP */
71fc80c0dfSnordmark #define	IPCL_TCP4		0x08000000	/* IPv4 packet format TCP */
72fc80c0dfSnordmark /* Unused			0x10000000 */
73fc80c0dfSnordmark /* Unused			0x20000000 */
74ff550d0eSmasputra #define	IPCL_CONNECTED		0x40000000	/* Conn in connected table */
75ff550d0eSmasputra #define	IPCL_BOUND		0x80000000	/* Conn in bind table */
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /* Flags identifying the type of conn */
78fc80c0dfSnordmark #define	IPCL_TCPCONN		0x00000001	/* From tcp_conn_cache */
79fc80c0dfSnordmark #define	IPCL_SCTPCONN		0x00000002	/* From sctp_conn_cache */
80fc80c0dfSnordmark #define	IPCL_IPCCONN		0x00000004	/* From ip_conn_cache */
81fc80c0dfSnordmark #define	IPCL_UDPCONN		0x00000008	/* From udp_conn_cache */
82fc80c0dfSnordmark #define	IPCL_RAWIPCONN		0x00000010	/* From rawip_conn_cache */
83fc80c0dfSnordmark #define	IPCL_RTSCONN		0x00000020	/* From rts_conn_cache */
842b24ab6bSSebastien Roy /* Unused			0x00000040 */
852b24ab6bSSebastien Roy #define	IPCL_IPTUN		0x00000080	/* iptun module above us */
860f1702c5SYu Xiangning #define	IPCL_NONSTR		0x00001000	/* A non-STREAMS socket */
870f1702c5SYu Xiangning #define	IPCL_IN_SQUEUE		0x10000000	/* Waiting squeue to finish */
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /* Conn Masks */
907c478bd9Sstevel@tonic-gate #define	IPCL_TCP		(IPCL_TCP4|IPCL_TCP6)
91fc80c0dfSnordmark #define	IPCL_REMOVED		0x00000100
92fc80c0dfSnordmark #define	IPCL_REUSED		0x00000200
937c478bd9Sstevel@tonic-gate 
94fc80c0dfSnordmark /* The packet format is IPv4; could be an AF_INET or AF_INET6 socket */
957c478bd9Sstevel@tonic-gate #define	IPCL_IS_TCP4(connp)						\
967c478bd9Sstevel@tonic-gate 	(((connp)->conn_flags & IPCL_TCP4))
977c478bd9Sstevel@tonic-gate 
98fc80c0dfSnordmark /* Connected AF_INET with no IPsec policy */
997c478bd9Sstevel@tonic-gate #define	IPCL_IS_TCP4_CONNECTED_NO_POLICY(connp)				\
1007c478bd9Sstevel@tonic-gate 	(((connp)->conn_flags &						\
1017c478bd9Sstevel@tonic-gate 		(IPCL_TCP4|IPCL_CONNECTED|IPCL_CHECK_POLICY|IPCL_TCP6))	\
1027c478bd9Sstevel@tonic-gate 		== (IPCL_TCP4|IPCL_CONNECTED))
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	IPCL_IS_CONNECTED(connp)					\
1057c478bd9Sstevel@tonic-gate 	((connp)->conn_flags & IPCL_CONNECTED)
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate #define	IPCL_IS_BOUND(connp)						\
1087c478bd9Sstevel@tonic-gate 	((connp)->conn_flags & IPCL_BOUND)
1097c478bd9Sstevel@tonic-gate 
110fc80c0dfSnordmark /* AF_INET TCP that is bound */
1117c478bd9Sstevel@tonic-gate #define	IPCL_IS_TCP4_BOUND(connp)					\
1127c478bd9Sstevel@tonic-gate 	(((connp)->conn_flags &						\
1137c478bd9Sstevel@tonic-gate 		(IPCL_TCP4|IPCL_BOUND|IPCL_TCP6)) ==			\
1147c478bd9Sstevel@tonic-gate 		(IPCL_TCP4|IPCL_BOUND))
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate #define	IPCL_IS_FULLY_BOUND(connp)					\
1177c478bd9Sstevel@tonic-gate 	((connp)->conn_flags & IPCL_FULLY_BOUND)
1187c478bd9Sstevel@tonic-gate 
119ff550d0eSmasputra /*
120fc80c0dfSnordmark  * Can't use conn_protocol since we need to tell difference
121fc80c0dfSnordmark  * between a real TCP socket and a SOCK_RAW, IPPROTO_TCP.
122ff550d0eSmasputra  */
123fc80c0dfSnordmark #define	IPCL_IS_TCP(connp)						\
124fc80c0dfSnordmark 	((connp)->conn_flags & IPCL_TCPCONN)
125ff550d0eSmasputra 
126fc80c0dfSnordmark #define	IPCL_IS_SCTP(connp)						\
127fc80c0dfSnordmark 	((connp)->conn_flags & IPCL_SCTPCONN)
128fc80c0dfSnordmark 
129fc80c0dfSnordmark #define	IPCL_IS_UDP(connp)						\
130fc80c0dfSnordmark 	((connp)->conn_flags & IPCL_UDPCONN)
131fc80c0dfSnordmark 
132fc80c0dfSnordmark #define	IPCL_IS_RAWIP(connp)						\
133fc80c0dfSnordmark 	((connp)->conn_flags & IPCL_RAWIPCONN)
134fc80c0dfSnordmark 
135fc80c0dfSnordmark #define	IPCL_IS_RTS(connp)						\
136fc80c0dfSnordmark 	((connp)->conn_flags & IPCL_RTSCONN)
137fc80c0dfSnordmark 
1387c478bd9Sstevel@tonic-gate #define	IPCL_IS_IPTUN(connp)						\
1392b24ab6bSSebastien Roy 	((connp)->conn_flags & IPCL_IPTUN)
1407c478bd9Sstevel@tonic-gate 
1410f1702c5SYu Xiangning #define	IPCL_IS_NONSTR(connp)	((connp)->conn_flags & IPCL_NONSTR)
1420f1702c5SYu Xiangning 
1437c478bd9Sstevel@tonic-gate typedef struct connf_s connf_t;
144f4b3ec61Sdh155122 
1457c478bd9Sstevel@tonic-gate typedef struct
1467c478bd9Sstevel@tonic-gate {
1477c478bd9Sstevel@tonic-gate 	int	ctb_depth;
1486a8288c7Scarlsonj #define	CONN_STACK_DEPTH	15
1496a8288c7Scarlsonj 	pc_t	ctb_stack[CONN_STACK_DEPTH];
1507c478bd9Sstevel@tonic-gate } conn_trace_t;
1517c478bd9Sstevel@tonic-gate 
1520f1702c5SYu Xiangning typedef struct ip_helper_minor_info_s {
1530f1702c5SYu Xiangning 	dev_t	ip_minfo_dev;		/* Device */
1540f1702c5SYu Xiangning 	vmem_t	*ip_minfo_arena;	/* Arena */
1550f1702c5SYu Xiangning } ip_helper_minfo_t;
1560f1702c5SYu Xiangning 
1570f1702c5SYu Xiangning /*
1580f1702c5SYu Xiangning  * ip helper stream info
1590f1702c5SYu Xiangning  */
1600f1702c5SYu Xiangning typedef struct ip_helper_stream_info_s {
16119a8a986SRao Shoaib 	ldi_handle_t		iphs_handle;
16219a8a986SRao Shoaib 	queue_t 		*iphs_rq;
16319a8a986SRao Shoaib 	queue_t 		*iphs_wq;
16419a8a986SRao Shoaib 	ip_helper_minfo_t	*iphs_minfo;
1650f1702c5SYu Xiangning } ip_helper_stream_info_t;
1660f1702c5SYu Xiangning 
167fc80c0dfSnordmark /*
168*5d3b8cb7SBill Sommerfeld  * Mandatory Access Control mode, in conn_t's conn_mac_mode field.
169*5d3b8cb7SBill Sommerfeld  * 	CONN_MAC_DEFAULT: strict enforcement of MAC.
170*5d3b8cb7SBill Sommerfeld  * 	CONN_MAC_AWARE:   allows communications between unlabeled systems
171*5d3b8cb7SBill Sommerfeld  *			  and privileged daemons
172*5d3b8cb7SBill Sommerfeld  *	CONN_MAC_IMPLICIT: allows communications without explicit labels
173*5d3b8cb7SBill Sommerfeld  *		           on the wire with privileged daemons.
174*5d3b8cb7SBill Sommerfeld  *
175*5d3b8cb7SBill Sommerfeld  * CONN_MAC_IMPLICIT is intended specifically for labeled IPsec key management
176*5d3b8cb7SBill Sommerfeld  * in networks which don't pass CIPSO-labeled packets.
177*5d3b8cb7SBill Sommerfeld  */
178*5d3b8cb7SBill Sommerfeld #define	CONN_MAC_DEFAULT 0
179*5d3b8cb7SBill Sommerfeld #define	CONN_MAC_AWARE 1
180*5d3b8cb7SBill Sommerfeld #define	CONN_MAC_IMPLICIT 2
181*5d3b8cb7SBill Sommerfeld 
182*5d3b8cb7SBill Sommerfeld /*
183fc80c0dfSnordmark  * The initial fields in the conn_t are setup by the kmem_cache constructor,
184fc80c0dfSnordmark  * and are preserved when it is freed. Fields after that are bzero'ed when
185fc80c0dfSnordmark  * the conn_t is freed.
186fc80c0dfSnordmark  */
1877c478bd9Sstevel@tonic-gate struct conn_s {
1887c478bd9Sstevel@tonic-gate 	kmutex_t	conn_lock;
1897c478bd9Sstevel@tonic-gate 	uint32_t	conn_ref;		/* Reference counter */
1907c478bd9Sstevel@tonic-gate 	uint32_t	conn_flags;		/* Conn Flags */
191fc80c0dfSnordmark 
192fc80c0dfSnordmark 
193fc80c0dfSnordmark 	union {
194fc80c0dfSnordmark 		tcp_t		*cp_tcp;	/* Pointer to the tcp struct */
195fc80c0dfSnordmark 		struct udp_s	*cp_udp;	/* Pointer to the udp struct */
196fc80c0dfSnordmark 		struct icmp_s	*cp_icmp;	/* Pointer to rawip struct */
197fc80c0dfSnordmark 		struct rts_s	*cp_rts;	/* Pointer to rts struct */
1982b24ab6bSSebastien Roy 		struct iptun_s	*cp_iptun;	/* Pointer to iptun_t */
199fc80c0dfSnordmark 		void		*cp_priv;
200fc80c0dfSnordmark 	} conn_proto_priv;
201fc80c0dfSnordmark #define	conn_tcp	conn_proto_priv.cp_tcp
202fc80c0dfSnordmark #define	conn_udp	conn_proto_priv.cp_udp
203fc80c0dfSnordmark #define	conn_icmp	conn_proto_priv.cp_icmp
204fc80c0dfSnordmark #define	conn_rts	conn_proto_priv.cp_rts
2052b24ab6bSSebastien Roy #define	conn_iptun	conn_proto_priv.cp_iptun
206fc80c0dfSnordmark #define	conn_priv	conn_proto_priv.cp_priv
207fc80c0dfSnordmark 
208fc80c0dfSnordmark 	kcondvar_t	conn_cv;
209fc80c0dfSnordmark 	uint8_t		conn_ulp;		/* protocol type */
210fc80c0dfSnordmark 
211fc80c0dfSnordmark 	edesc_rpf	conn_recv;		/* Pointer to recv routine */
212fc80c0dfSnordmark 
213fc80c0dfSnordmark 	/* Fields after this are bzero'ed when the conn_t is freed. */
214fc80c0dfSnordmark 
215fc80c0dfSnordmark 	squeue_t	*conn_sqp;		/* Squeue for processing */
216fc80c0dfSnordmark 	uint_t		conn_state_flags;	/* IP state flags */
217fc80c0dfSnordmark #define	conn_start_clr	conn_state_flags
218fc80c0dfSnordmark 
219fc80c0dfSnordmark 	ire_t		*conn_ire_cache; 	/* outbound ire cache */
2207c478bd9Sstevel@tonic-gate 	unsigned int
2217c478bd9Sstevel@tonic-gate 		conn_on_sqp : 1,		/* Conn is being processed */
2227c478bd9Sstevel@tonic-gate 		conn_dontroute : 1,		/* SO_DONTROUTE state */
2237c478bd9Sstevel@tonic-gate 		conn_loopback : 1,		/* SO_LOOPBACK state */
2247c478bd9Sstevel@tonic-gate 		conn_broadcast : 1,		/* SO_BROADCAST state */
2257c478bd9Sstevel@tonic-gate 
22645916cd2Sjpk 		conn_reuseaddr : 1,		/* SO_REUSEADDR state */
2277c478bd9Sstevel@tonic-gate 		conn_multicast_loop : 1,	/* IP_MULTICAST_LOOP */
2287c478bd9Sstevel@tonic-gate 		conn_multi_router : 1,		/* Wants all multicast pkts */
2297c478bd9Sstevel@tonic-gate 		conn_draining : 1,		/* ip_wsrv running */
2307c478bd9Sstevel@tonic-gate 
23145916cd2Sjpk 		conn_did_putbq : 1,		/* ip_wput did a putbq */
2327c478bd9Sstevel@tonic-gate 		conn_unspec_src : 1,		/* IP_UNSPEC_SRC */
2337c478bd9Sstevel@tonic-gate 		conn_policy_cached : 1,		/* Is policy cached/latched ? */
2347c478bd9Sstevel@tonic-gate 		conn_in_enforce_policy : 1,	/* Enforce Policy on inbound */
2357c478bd9Sstevel@tonic-gate 
23645916cd2Sjpk 		conn_out_enforce_policy : 1,	/* Enforce Policy on outbound */
2377c478bd9Sstevel@tonic-gate 		conn_af_isv6 : 1,		/* ip address family ver 6 */
2387c478bd9Sstevel@tonic-gate 		conn_pkt_isv6 : 1,		/* ip packet format ver 6 */
23919a30e1aSrshoaib 		conn_ip_recvpktinfo : 1,	/* IPV*_RECVPKTINFO option */
2407c478bd9Sstevel@tonic-gate 
24145916cd2Sjpk 		conn_ipv6_recvhoplimit : 1,	/* IPV6_RECVHOPLIMIT option */
2427c478bd9Sstevel@tonic-gate 		conn_ipv6_recvhopopts : 1,	/* IPV6_RECVHOPOPTS option */
2437c478bd9Sstevel@tonic-gate 		conn_ipv6_recvdstopts : 1,	/* IPV6_RECVDSTOPTS option */
2447c478bd9Sstevel@tonic-gate 		conn_ipv6_recvrthdr : 1,	/* IPV6_RECVRTHDR option */
24545916cd2Sjpk 
2467c478bd9Sstevel@tonic-gate 		conn_ipv6_recvrtdstopts : 1,	/* IPV6_RECVRTHDRDSTOPTS */
2477c478bd9Sstevel@tonic-gate 		conn_ipv6_v6only : 1,		/* IPV6_V6ONLY */
2487c478bd9Sstevel@tonic-gate 		conn_ipv6_recvtclass : 1,	/* IPV6_RECVTCLASS */
2497c478bd9Sstevel@tonic-gate 		conn_ipv6_recvpathmtu : 1,	/* IPV6_RECVPATHMTU */
25045916cd2Sjpk 
2517c478bd9Sstevel@tonic-gate 		conn_pathmtu_valid : 1,		/* The cached mtu is valid. */
2527c478bd9Sstevel@tonic-gate 		conn_ipv6_dontfrag : 1,		/* IPV6_DONTFRAG */
2537c478bd9Sstevel@tonic-gate 		conn_fully_bound : 1,		/* Fully bound connection */
2547c478bd9Sstevel@tonic-gate 		conn_recvif : 1,		/* IP_RECVIF option */
25545916cd2Sjpk 
2567c478bd9Sstevel@tonic-gate 		conn_recvslla : 1,		/* IP_RECVSLLA option */
2577c478bd9Sstevel@tonic-gate 		conn_mdt_ok : 1,		/* MDT is permitted */
25843d18f1cSpriyanka 		conn_nexthop_set : 1,
259da14cebeSEric Cheng 		conn_allzones : 1;		/* SO_ALLZONES */
2608347601bSyl150051 
261da14cebeSEric Cheng 	unsigned int
2628347601bSyl150051 		conn_lso_ok : 1;		/* LSO is usable */
263ae6aa22aSVenugopal Iyer 	boolean_t conn_direct_blocked;		/* conn is flow-controlled */
2647c478bd9Sstevel@tonic-gate 
265da14cebeSEric Cheng 	squeue_t	*conn_initial_sqp;	/* Squeue at open time */
266da14cebeSEric Cheng 	squeue_t	*conn_final_sqp;	/* Squeue after connect */
267e704a8f2Smeem 	ill_t		*conn_dhcpinit_ill;	/* IP_DHCPINIT_IF */
2687c478bd9Sstevel@tonic-gate 	ipsec_latch_t	*conn_latch;		/* latched state */
2697c478bd9Sstevel@tonic-gate 	ill_t		*conn_outgoing_ill;	/* IP{,V6}_BOUND_IF */
2707c478bd9Sstevel@tonic-gate 	edesc_spf	conn_send;		/* Pointer to send routine */
2717c478bd9Sstevel@tonic-gate 	queue_t		*conn_rq;		/* Read queue */
2727c478bd9Sstevel@tonic-gate 	queue_t		*conn_wq;		/* Write queue */
2737c478bd9Sstevel@tonic-gate 	dev_t		conn_dev;		/* Minor number */
274aa92d85bSgt145670 	vmem_t		*conn_minor_arena;	/* Minor arena */
2750f1702c5SYu Xiangning 	ip_helper_stream_info_t *conn_helper_info;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	cred_t		*conn_cred;		/* Credentials */
2787c478bd9Sstevel@tonic-gate 	connf_t		*conn_g_fanout;		/* Global Hash bucket head */
2797c478bd9Sstevel@tonic-gate 	struct conn_s	*conn_g_next;		/* Global Hash chain next */
2807c478bd9Sstevel@tonic-gate 	struct conn_s	*conn_g_prev;		/* Global Hash chain prev */
2817c478bd9Sstevel@tonic-gate 	struct ipsec_policy_head_s *conn_policy; /* Configured policy */
2827c478bd9Sstevel@tonic-gate 	in6_addr_t	conn_bound_source_v6;
2837c478bd9Sstevel@tonic-gate #define	conn_bound_source	V4_PART_OF_V6(conn_bound_source_v6)
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate 	connf_t		*conn_fanout;		/* Hash bucket we're part of */
2867c478bd9Sstevel@tonic-gate 	struct conn_s	*conn_next;		/* Hash chain next */
2877c478bd9Sstevel@tonic-gate 	struct conn_s	*conn_prev;		/* Hash chain prev */
2887c478bd9Sstevel@tonic-gate 	struct {
2897c478bd9Sstevel@tonic-gate 		in6_addr_t connua_laddr;	/* Local address */
2907c478bd9Sstevel@tonic-gate 		in6_addr_t connua_faddr;	/* Remote address */
2917c478bd9Sstevel@tonic-gate 	} connua_v6addr;
2927c478bd9Sstevel@tonic-gate #define	conn_src	V4_PART_OF_V6(connua_v6addr.connua_laddr)
2937c478bd9Sstevel@tonic-gate #define	conn_rem	V4_PART_OF_V6(connua_v6addr.connua_faddr)
2947c478bd9Sstevel@tonic-gate #define	conn_srcv6	connua_v6addr.connua_laddr
2957c478bd9Sstevel@tonic-gate #define	conn_remv6	connua_v6addr.connua_faddr
2967c478bd9Sstevel@tonic-gate 	union {
2977c478bd9Sstevel@tonic-gate 		/* Used for classifier match performance */
2987c478bd9Sstevel@tonic-gate 		uint32_t		conn_ports2;
2997c478bd9Sstevel@tonic-gate 		struct {
3007c478bd9Sstevel@tonic-gate 			in_port_t	tcpu_fport;	/* Remote port */
3017c478bd9Sstevel@tonic-gate 			in_port_t	tcpu_lport;	/* Local port */
3027c478bd9Sstevel@tonic-gate 		} tcpu_ports;
3037c478bd9Sstevel@tonic-gate 	} u_port;
3047c478bd9Sstevel@tonic-gate #define	conn_fport	u_port.tcpu_ports.tcpu_fport
3057c478bd9Sstevel@tonic-gate #define	conn_lport	u_port.tcpu_ports.tcpu_lport
3067c478bd9Sstevel@tonic-gate #define	conn_ports	u_port.conn_ports2
3077c478bd9Sstevel@tonic-gate #define	conn_upq	conn_rq
3087c478bd9Sstevel@tonic-gate 	uint8_t		conn_unused_byte;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 	uint_t		conn_proto;		/* SO_PROTOTYPE state */
3117c478bd9Sstevel@tonic-gate 	ill_t		*conn_incoming_ill;	/* IP{,V6}_BOUND_IF */
3127c478bd9Sstevel@tonic-gate 	ill_t		*conn_oper_pending_ill; /* pending shared ioctl */
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	ilg_t	*conn_ilg;		/* Group memberships */
3157c478bd9Sstevel@tonic-gate 	int	conn_ilg_allocated;	/* Number allocated */
3167c478bd9Sstevel@tonic-gate 	int	conn_ilg_inuse;		/* Number currently used */
3177c478bd9Sstevel@tonic-gate 	int	conn_ilg_walker_cnt;	/* No of ilg walkers */
3187c478bd9Sstevel@tonic-gate 	/* XXXX get rid of this, once ilg_delete_all is fixed */
3197c478bd9Sstevel@tonic-gate 	kcondvar_t	conn_refcv;
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	struct ipif_s	*conn_multicast_ipif;	/* IP_MULTICAST_IF */
3227c478bd9Sstevel@tonic-gate 	ill_t		*conn_multicast_ill;	/* IPV6_MULTICAST_IF */
3237c478bd9Sstevel@tonic-gate 	struct	conn_s	*conn_drain_next;	/* Next conn in drain list */
3247c478bd9Sstevel@tonic-gate 	struct	conn_s	*conn_drain_prev;	/* Prev conn in drain list */
3257c478bd9Sstevel@tonic-gate 	idl_t		*conn_idl;		/* Ptr to the drain list head */
3267c478bd9Sstevel@tonic-gate 	mblk_t		*conn_ipsec_opt_mp;	/* ipsec option mblk */
3277c478bd9Sstevel@tonic-gate 	uint32_t	conn_src_preferences;	/* prefs for src addr select */
3287c478bd9Sstevel@tonic-gate 	/* mtuinfo from IPV6_PACKET_TOO_BIG conditional on conn_pathmtu_valid */
3297c478bd9Sstevel@tonic-gate 	struct ip6_mtuinfo mtuinfo;
3307c478bd9Sstevel@tonic-gate 	zoneid_t	conn_zoneid;		/* zone connection is in */
33143d18f1cSpriyanka 	in6_addr_t	conn_nexthop_v6;	/* nexthop IP address */
332a7107231Smeem 	uchar_t		conn_broadcast_ttl; 	/* IP_BROADCAST_TTL */
33343d18f1cSpriyanka #define	conn_nexthop_v4	V4_PART_OF_V6(conn_nexthop_v6)
3345f9878b0Sken Powell - Sun Microsystem 	cred_t		*conn_effective_cred;	/* Effective TX credentials */
335e11c3f44Smeem 	int		conn_rtaware; 		/* RT_AWARE sockopt value */
3360f1702c5SYu Xiangning 	kcondvar_t	conn_sq_cv;		/* For non-STREAMS socket IO */
3370f1702c5SYu Xiangning 	kthread_t	*conn_sq_caller;	/* Caller of squeue sync ops */
3380f1702c5SYu Xiangning 	sock_upcalls_t	*conn_upcalls;		/* Upcalls to sockfs */
3390f1702c5SYu Xiangning 	sock_upper_handle_t conn_upper_handle;	/* Upper handle: sonode * */
3400f1702c5SYu Xiangning 
34145916cd2Sjpk 	unsigned int
34245916cd2Sjpk 		conn_ulp_labeled : 1,		/* ULP label is synced */
34345916cd2Sjpk 		conn_mlp_type : 2,		/* mlp_type_t; tsol/tndb.h */
34445916cd2Sjpk 		conn_anon_mlp : 1,		/* user wants anon MLP */
34545916cd2Sjpk 
34645916cd2Sjpk 		conn_anon_port : 1,		/* user bound anonymously */
347*5d3b8cb7SBill Sommerfeld 		conn_mac_mode : 2,		/* normal/loose/implicit MAC */
34845916cd2Sjpk 		conn_spare : 26;
3490f1702c5SYu Xiangning 
3500f1702c5SYu Xiangning 	boolean_t	conn_flow_cntrld;
351f4b3ec61Sdh155122 	netstack_t	*conn_netstack;	/* Corresponds to a netstack_hold */
3527c478bd9Sstevel@tonic-gate #ifdef CONN_DEBUG
3537c478bd9Sstevel@tonic-gate #define	CONN_TRACE_MAX	10
3547c478bd9Sstevel@tonic-gate 	int		conn_trace_last;	/* ndx of last used tracebuf */
3557c478bd9Sstevel@tonic-gate 	conn_trace_t	conn_trace_buf[CONN_TRACE_MAX];
3567c478bd9Sstevel@tonic-gate #endif
3577c478bd9Sstevel@tonic-gate };
3587c478bd9Sstevel@tonic-gate 
359de8c4a14SErik Nordmark /*
360de8c4a14SErik Nordmark  * These two macros are used by TX. First priority is SCM_UCRED having
3615f9878b0Sken Powell - Sun Microsystem  * set the label in the mblk. Second priority is the open credentials with
3625f9878b0Sken Powell - Sun Microsystem  * peer's label (aka conn_effective_cred). Last priority is the open
3635f9878b0Sken Powell - Sun Microsystem  * credentials. BEST_CRED takes all three into account in the above order.
364de8c4a14SErik Nordmark  * CONN_CRED is for connection-oriented cases when we don't need to look
365de8c4a14SErik Nordmark  * at the mblk.
366de8c4a14SErik Nordmark  */
3675f9878b0Sken Powell - Sun Microsystem #define	CONN_CRED(connp) ((connp)->conn_effective_cred == NULL ? \
3685f9878b0Sken Powell - Sun Microsystem 	(connp)->conn_cred : (connp)->conn_effective_cred)
3695f9878b0Sken Powell - Sun Microsystem #define	BEST_CRED(mp, connp, pidp) ip_best_cred(mp, connp, pidp)
37045916cd2Sjpk 
3717c478bd9Sstevel@tonic-gate /*
3727c478bd9Sstevel@tonic-gate  * connf_t - connection fanout data.
3737c478bd9Sstevel@tonic-gate  *
3747c478bd9Sstevel@tonic-gate  * The hash tables and their linkage (conn_t.{hashnextp, hashprevp} are
3757c478bd9Sstevel@tonic-gate  * protected by the per-bucket lock. Each conn_t inserted in the list
3767c478bd9Sstevel@tonic-gate  * points back at the connf_t that heads the bucket.
3777c478bd9Sstevel@tonic-gate  */
3787c478bd9Sstevel@tonic-gate struct connf_s {
3797c478bd9Sstevel@tonic-gate 	struct conn_s	*connf_head;
3807c478bd9Sstevel@tonic-gate 	kmutex_t	connf_lock;
3817c478bd9Sstevel@tonic-gate };
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate #define	CONN_INC_REF(connp)	{				\
3847c478bd9Sstevel@tonic-gate 	mutex_enter(&(connp)->conn_lock);			\
385866ba9ddSjprakash 	DTRACE_PROBE1(conn__inc__ref, conn_t *, connp);		\
3867c478bd9Sstevel@tonic-gate 	ASSERT(conn_trace_ref(connp));				\
3877c478bd9Sstevel@tonic-gate 	(connp)->conn_ref++;					\
3887c478bd9Sstevel@tonic-gate 	ASSERT((connp)->conn_ref != 0);				\
3897c478bd9Sstevel@tonic-gate 	mutex_exit(&(connp)->conn_lock);			\
3907c478bd9Sstevel@tonic-gate }
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate #define	CONN_INC_REF_LOCKED(connp)	{			\
3937c478bd9Sstevel@tonic-gate 	DTRACE_PROBE1(conn__inc__ref, conn_t *, connp);		\
3947c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(connp)->conn_lock));	 	\
3957c478bd9Sstevel@tonic-gate 	ASSERT(conn_trace_ref(connp));				\
3967c478bd9Sstevel@tonic-gate 	(connp)->conn_ref++;					\
3977c478bd9Sstevel@tonic-gate 	ASSERT((connp)->conn_ref != 0);				\
3987c478bd9Sstevel@tonic-gate }
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate #define	CONN_DEC_REF(connp)	{					\
4017c478bd9Sstevel@tonic-gate 	mutex_enter(&(connp)->conn_lock);				\
402866ba9ddSjprakash 	DTRACE_PROBE1(conn__dec__ref, conn_t *, connp);			\
403866ba9ddSjprakash 	/*								\
404866ba9ddSjprakash 	 * The squeue framework always does a CONN_DEC_REF after return	\
405866ba9ddSjprakash 	 * from TCP. Hence the refcnt must be at least 2 if conn_on_sqp	\
406866ba9ddSjprakash 	 * is B_TRUE and conn_ref is being decremented. This is to	\
407866ba9ddSjprakash 	 * account for the mblk being currently processed.		\
408866ba9ddSjprakash 	 */								\
4092b24ab6bSSebastien Roy 	if ((connp)->conn_ref == 0 ||					\
410866ba9ddSjprakash 	    ((connp)->conn_ref == 1 && (connp)->conn_on_sqp))		\
4117c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "CONN_DEC_REF: connp(%p) has ref "	\
4127c478bd9Sstevel@tonic-gate 			"= %d\n", (void *)(connp), (connp)->conn_ref);	\
4137c478bd9Sstevel@tonic-gate 	ASSERT(conn_untrace_ref(connp));				\
4147c478bd9Sstevel@tonic-gate 	(connp)->conn_ref--;						\
4157c478bd9Sstevel@tonic-gate 	if ((connp)->conn_ref == 0) {					\
4167c478bd9Sstevel@tonic-gate 		/* Refcnt can't increase again, safe to drop lock */	\
4177c478bd9Sstevel@tonic-gate 		mutex_exit(&(connp)->conn_lock);			\
4187c478bd9Sstevel@tonic-gate 		ipcl_conn_destroy(connp);				\
4197c478bd9Sstevel@tonic-gate 	} else {							\
4207c478bd9Sstevel@tonic-gate 		cv_broadcast(&(connp)->conn_cv);			\
4217c478bd9Sstevel@tonic-gate 		mutex_exit(&(connp)->conn_lock);			\
4227c478bd9Sstevel@tonic-gate 	}								\
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate 
4255d0bc3edSsommerfe /*
4265d0bc3edSsommerfe  * For use with subsystems within ip which use ALL_ZONES as a wildcard
4275d0bc3edSsommerfe  */
4285d0bc3edSsommerfe #define	IPCL_ZONEID(connp)						\
4295d0bc3edSsommerfe 	((connp)->conn_allzones ? ALL_ZONES : (connp)->conn_zoneid)
4305d0bc3edSsommerfe 
4315d0bc3edSsommerfe /*
4325d0bc3edSsommerfe  * For matching between a conn_t and a zoneid.
4335d0bc3edSsommerfe  */
4345d0bc3edSsommerfe #define	IPCL_ZONE_MATCH(connp, zoneid) 					\
4355d0bc3edSsommerfe 	(((connp)->conn_allzones) ||					\
4365d0bc3edSsommerfe 	    ((zoneid) == ALL_ZONES) ||					\
4375d0bc3edSsommerfe 	    (connp)->conn_zoneid == (zoneid))
4385d0bc3edSsommerfe 
439*5d3b8cb7SBill Sommerfeld /*
440*5d3b8cb7SBill Sommerfeld  * On a labeled system, we must treat bindings to ports
441*5d3b8cb7SBill Sommerfeld  * on shared IP addresses by sockets with MAC exemption
442*5d3b8cb7SBill Sommerfeld  * privilege as being in all zones, as there's
443*5d3b8cb7SBill Sommerfeld  * otherwise no way to identify the right receiver.
444*5d3b8cb7SBill Sommerfeld  */
445*5d3b8cb7SBill Sommerfeld 
446*5d3b8cb7SBill Sommerfeld #define	IPCL_CONNS_MAC(conn1, conn2)					\
447*5d3b8cb7SBill Sommerfeld 	(((conn1)->conn_mac_mode != CONN_MAC_DEFAULT) ||		\
448*5d3b8cb7SBill Sommerfeld 	((conn2)->conn_mac_mode != CONN_MAC_DEFAULT))
449*5d3b8cb7SBill Sommerfeld 
450*5d3b8cb7SBill Sommerfeld #define	IPCL_BIND_ZONE_MATCH(conn1, conn2)				\
451*5d3b8cb7SBill Sommerfeld 	(IPCL_CONNS_MAC(conn1, conn2) ||				\
452*5d3b8cb7SBill Sommerfeld 	IPCL_ZONE_MATCH(conn1, conn2->conn_zoneid) ||			\
453*5d3b8cb7SBill Sommerfeld 	IPCL_ZONE_MATCH(conn2, conn1->conn_zoneid))
454*5d3b8cb7SBill Sommerfeld 
4555d0bc3edSsommerfe 
4567c478bd9Sstevel@tonic-gate #define	_IPCL_V4_MATCH(v6addr, v4addr)	\
4577c478bd9Sstevel@tonic-gate 	(V4_PART_OF_V6((v6addr)) == (v4addr) && IN6_IS_ADDR_V4MAPPED(&(v6addr)))
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate #define	_IPCL_V4_MATCH_ANY(addr)	\
4607c478bd9Sstevel@tonic-gate 	(IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) || IN6_IS_ADDR_UNSPECIFIED(&(addr)))
4617c478bd9Sstevel@tonic-gate 
4625d0bc3edSsommerfe 
4637c478bd9Sstevel@tonic-gate /*
4647c478bd9Sstevel@tonic-gate  * IPCL_PROTO_MATCH() only matches conns with the specified zoneid, while
4657c478bd9Sstevel@tonic-gate  * IPCL_PROTO_MATCH_V6() can match other conns in the multicast case, see
4667c478bd9Sstevel@tonic-gate  * ip_fanout_proto().
4677c478bd9Sstevel@tonic-gate  */
4687c478bd9Sstevel@tonic-gate #define	IPCL_PROTO_MATCH(connp, protocol, ipha, ill,			\
4697c478bd9Sstevel@tonic-gate     fanout_flags, zoneid)						\
4707c478bd9Sstevel@tonic-gate 	((((connp)->conn_src == INADDR_ANY) ||				\
4717c478bd9Sstevel@tonic-gate 	(((connp)->conn_src == ((ipha)->ipha_dst)) &&			\
4727c478bd9Sstevel@tonic-gate 	    (((connp)->conn_rem == INADDR_ANY) ||			\
4737c478bd9Sstevel@tonic-gate 	((connp)->conn_rem == ((ipha)->ipha_src))))) &&			\
4745d0bc3edSsommerfe 	IPCL_ZONE_MATCH(connp, zoneid) &&				\
4755d0bc3edSsommerfe 	(conn_wantpacket((connp), (ill), (ipha), (fanout_flags), 	\
4765d0bc3edSsommerfe 	    (zoneid)) || ((protocol) == IPPROTO_PIM) ||			\
4777c478bd9Sstevel@tonic-gate 	    ((protocol) == IPPROTO_RSVP)))
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate #define	IPCL_PROTO_MATCH_V6(connp, protocol, ip6h, ill,			   \
4807c478bd9Sstevel@tonic-gate     fanout_flags, zoneid)						   \
4817c478bd9Sstevel@tonic-gate 	((IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) ||		   \
4827c478bd9Sstevel@tonic-gate 	(IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &((ip6h)->ip6_dst)) &&   \
4837c478bd9Sstevel@tonic-gate 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) ||		   \
4847c478bd9Sstevel@tonic-gate 	IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &((ip6h)->ip6_src))))) && \
4857c478bd9Sstevel@tonic-gate 	(conn_wantpacket_v6((connp), (ill), (ip6h),			   \
4867c478bd9Sstevel@tonic-gate 	(fanout_flags), (zoneid)) || ((protocol) == IPPROTO_RSVP)))
4877c478bd9Sstevel@tonic-gate 
488f4b3ec61Sdh155122 #define	IPCL_CONN_HASH(src, ports, ipst)				\
4897c478bd9Sstevel@tonic-gate 	((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^	\
490f4b3ec61Sdh155122 	((ports) >> 8) ^ (ports)) % (ipst)->ips_ipcl_conn_fanout_size)
4917c478bd9Sstevel@tonic-gate 
492f4b3ec61Sdh155122 #define	IPCL_CONN_HASH_V6(src, ports, ipst)				\
493f4b3ec61Sdh155122 	IPCL_CONN_HASH(V4_PART_OF_V6((src)), (ports), (ipst))
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate #define	IPCL_CONN_MATCH(connp, proto, src, dst, ports)			\
4967c478bd9Sstevel@tonic-gate 	((connp)->conn_ulp == (proto) &&				\
4977c478bd9Sstevel@tonic-gate 		(connp)->conn_ports == (ports) &&      			\
4987c478bd9Sstevel@tonic-gate 		_IPCL_V4_MATCH((connp)->conn_remv6, (src)) &&		\
4997c478bd9Sstevel@tonic-gate 		_IPCL_V4_MATCH((connp)->conn_srcv6, (dst)) &&		\
5007c478bd9Sstevel@tonic-gate 		!(connp)->conn_ipv6_v6only)
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate #define	IPCL_CONN_MATCH_V6(connp, proto, src, dst, ports)		\
5037c478bd9Sstevel@tonic-gate 	((connp)->conn_ulp == (proto) &&				\
5047c478bd9Sstevel@tonic-gate 		(connp)->conn_ports == (ports) &&      			\
5057c478bd9Sstevel@tonic-gate 		IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(src)) &&	\
5067c478bd9Sstevel@tonic-gate 		IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(dst)))
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate #define	IPCL_CONN_INIT(connp, protocol, src, rem, ports) {		\
5097c478bd9Sstevel@tonic-gate 	(connp)->conn_ulp = protocol;					\
5107c478bd9Sstevel@tonic-gate 	IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6);		\
5117c478bd9Sstevel@tonic-gate 	IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6);		\
5127c478bd9Sstevel@tonic-gate 	(connp)->conn_ports = ports;					\
5137c478bd9Sstevel@tonic-gate }
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate #define	IPCL_CONN_INIT_V6(connp, protocol, src, rem, ports) {		\
5167c478bd9Sstevel@tonic-gate 	(connp)->conn_ulp = protocol;					\
5177c478bd9Sstevel@tonic-gate 	(connp)->conn_srcv6 = src;					\
5187c478bd9Sstevel@tonic-gate 	(connp)->conn_remv6 = rem;					\
5197c478bd9Sstevel@tonic-gate 	(connp)->conn_ports = ports;					\
5207c478bd9Sstevel@tonic-gate }
5217c478bd9Sstevel@tonic-gate 
522ee4701baSericheng #define	IPCL_PORT_HASH(port, size) \
523ee4701baSericheng 	((((port) >> 8) ^ (port)) & ((size) - 1))
524ee4701baSericheng 
525f4b3ec61Sdh155122 #define	IPCL_BIND_HASH(lport, ipst)					\
526f4b3ec61Sdh155122 	((unsigned)(((lport) >> 8) ^ (lport)) % \
527f4b3ec61Sdh155122 	    (ipst)->ips_ipcl_bind_fanout_size)
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate #define	IPCL_BIND_MATCH(connp, proto, laddr, lport)			\
5307c478bd9Sstevel@tonic-gate 	((connp)->conn_ulp == (proto) &&				\
5317c478bd9Sstevel@tonic-gate 		(connp)->conn_lport == (lport) &&			\
5327c478bd9Sstevel@tonic-gate 		(_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) ||		\
5337c478bd9Sstevel@tonic-gate 		_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr))) &&	\
5347c478bd9Sstevel@tonic-gate 		!(connp)->conn_ipv6_v6only)
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate #define	IPCL_BIND_MATCH_V6(connp, proto, laddr, lport)			\
5377c478bd9Sstevel@tonic-gate 	((connp)->conn_ulp == (proto) &&				\
5387c478bd9Sstevel@tonic-gate 		(connp)->conn_lport == (lport) &&			\
5397c478bd9Sstevel@tonic-gate 		(IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) ||	\
5407c478bd9Sstevel@tonic-gate 		IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6)))
5417c478bd9Sstevel@tonic-gate 
5427c478bd9Sstevel@tonic-gate #define	IPCL_UDP_MATCH(connp, lport, laddr, fport, faddr)		\
5437c478bd9Sstevel@tonic-gate 	(((connp)->conn_lport == (lport)) &&				\
5447c478bd9Sstevel@tonic-gate 	((_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) ||			\
5457c478bd9Sstevel@tonic-gate 	(_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)) &&		\
5467c478bd9Sstevel@tonic-gate 	(_IPCL_V4_MATCH_ANY((connp)->conn_remv6) ||			\
5477c478bd9Sstevel@tonic-gate 	(_IPCL_V4_MATCH((connp)->conn_remv6, (faddr)) &&		\
5487c478bd9Sstevel@tonic-gate 	(connp)->conn_fport == (fport)))))) &&				\
5497c478bd9Sstevel@tonic-gate 	!(connp)->conn_ipv6_v6only)
5507c478bd9Sstevel@tonic-gate 
5517c478bd9Sstevel@tonic-gate #define	IPCL_UDP_MATCH_V6(connp, lport, laddr, fport, faddr)	\
5527c478bd9Sstevel@tonic-gate 	(((connp)->conn_lport == (lport)) &&			\
5537c478bd9Sstevel@tonic-gate 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) ||	\
5547c478bd9Sstevel@tonic-gate 	(IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) &&	\
5557c478bd9Sstevel@tonic-gate 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) ||	\
5567c478bd9Sstevel@tonic-gate 	(IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(faddr)) &&	\
5577c478bd9Sstevel@tonic-gate 	(connp)->conn_fport == (fport))))))
5587c478bd9Sstevel@tonic-gate 
5592b24ab6bSSebastien Roy #define	IPCL_IPTUN_HASH(laddr, faddr)					\
5602b24ab6bSSebastien Roy 	((ntohl(laddr) ^ ((ntohl(faddr) << 24) | (ntohl(faddr) >> 8))) % \
5612b24ab6bSSebastien Roy 	ipcl_iptun_fanout_size)
5622b24ab6bSSebastien Roy 
5632b24ab6bSSebastien Roy #define	IPCL_IPTUN_HASH_V6(laddr, faddr)				\
5642b24ab6bSSebastien Roy 	IPCL_IPTUN_HASH((laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^	\
5652b24ab6bSSebastien Roy 	    (faddr)->s6_addr32[2] ^ (faddr)->s6_addr32[3],		\
5662b24ab6bSSebastien Roy 	    (faddr)->s6_addr32[0] ^ (faddr)->s6_addr32[1] ^		\
5672b24ab6bSSebastien Roy 	    (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3])
5682b24ab6bSSebastien Roy 
5692b24ab6bSSebastien Roy #define	IPCL_IPTUN_MATCH(connp, laddr, faddr)			\
5702b24ab6bSSebastien Roy 	(_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)) &&	\
5712b24ab6bSSebastien Roy 	_IPCL_V4_MATCH((connp)->conn_remv6, (faddr)))
5722b24ab6bSSebastien Roy 
5732b24ab6bSSebastien Roy #define	IPCL_IPTUN_MATCH_V6(connp, laddr, faddr)		\
5742b24ab6bSSebastien Roy 	(IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, (laddr)) &&	\
5752b24ab6bSSebastien Roy 	IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, (faddr)))
5762b24ab6bSSebastien Roy 
5777c478bd9Sstevel@tonic-gate #define	IPCL_TCP_EAGER_INIT(connp, protocol, src, rem, ports) {		\
5787c478bd9Sstevel@tonic-gate 	(connp)->conn_flags |= (IPCL_TCP4|IPCL_EAGER);			\
5797c478bd9Sstevel@tonic-gate 	IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6);		\
5807c478bd9Sstevel@tonic-gate 	IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6);		\
5817c478bd9Sstevel@tonic-gate 	(connp)->conn_ports = ports;					\
5827c478bd9Sstevel@tonic-gate 	(connp)->conn_send = ip_output;					\
5837c478bd9Sstevel@tonic-gate 	(connp)->conn_sqp = IP_SQUEUE_GET(lbolt);			\
584da14cebeSEric Cheng 	(connp)->conn_initial_sqp = (connp)->conn_sqp;			\
5857c478bd9Sstevel@tonic-gate }
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate #define	IPCL_TCP_EAGER_INIT_V6(connp, protocol, src, rem, ports) {	\
5882b24ab6bSSebastien Roy 	(connp)->conn_flags |= (IPCL_TCP6|IPCL_EAGER);			\
5897c478bd9Sstevel@tonic-gate 	(connp)->conn_srcv6 = src;					\
5907c478bd9Sstevel@tonic-gate 	(connp)->conn_remv6 = rem;					\
5917c478bd9Sstevel@tonic-gate 	(connp)->conn_ports = ports;					\
5927c478bd9Sstevel@tonic-gate 	(connp)->conn_send = ip_output_v6;				\
5937c478bd9Sstevel@tonic-gate 	(connp)->conn_sqp = IP_SQUEUE_GET(lbolt);			\
594da14cebeSEric Cheng 	(connp)->conn_initial_sqp = (connp)->conn_sqp;			\
5957c478bd9Sstevel@tonic-gate }
5967c478bd9Sstevel@tonic-gate 
597f4b3ec61Sdh155122 #define	IPCL_UDP_HASH(lport, ipst)	\
598f4b3ec61Sdh155122 	IPCL_PORT_HASH(lport, (ipst)->ips_ipcl_udp_fanout_size)
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate #define	CONN_G_HASH_SIZE	1024
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate /* Raw socket hash function. */
603f4b3ec61Sdh155122 #define	IPCL_RAW_HASH(lport, ipst)	\
604f4b3ec61Sdh155122 	IPCL_PORT_HASH(lport, (ipst)->ips_ipcl_raw_fanout_size)
6057c478bd9Sstevel@tonic-gate 
6067c0c0508Skcpoon /*
6077c0c0508Skcpoon  * This is similar to IPCL_BIND_MATCH except that the local port check
6087c0c0508Skcpoon  * is changed to a wildcard port check.
6097c0c0508Skcpoon  */
6107c0c0508Skcpoon #define	IPCL_RAW_MATCH(connp, proto, laddr)			\
6117c0c0508Skcpoon 	((connp)->conn_ulp == (proto) &&			\
6127c0c0508Skcpoon 	(connp)->conn_lport == 0 &&				\
6137c0c0508Skcpoon 	(_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) ||		\
6147c0c0508Skcpoon 	_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr))))
6157c0c0508Skcpoon 
6167c0c0508Skcpoon #define	IPCL_RAW_MATCH_V6(connp, proto, laddr)			\
6177c0c0508Skcpoon 	((connp)->conn_ulp == (proto) &&			\
6187c0c0508Skcpoon 	(connp)->conn_lport == 0 &&				\
6197c0c0508Skcpoon 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) ||	\
6207c0c0508Skcpoon 	IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr))))
6217c0c0508Skcpoon 
6227c478bd9Sstevel@tonic-gate /* Function prototypes */
623f4b3ec61Sdh155122 extern void ipcl_g_init(void);
624f4b3ec61Sdh155122 extern void ipcl_init(ip_stack_t *);
625f4b3ec61Sdh155122 extern void ipcl_g_destroy(void);
626f4b3ec61Sdh155122 extern void ipcl_destroy(ip_stack_t *);
627f4b3ec61Sdh155122 extern conn_t *ipcl_conn_create(uint32_t, int, netstack_t *);
6287c478bd9Sstevel@tonic-gate extern void ipcl_conn_destroy(conn_t *);
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate void ipcl_hash_insert_wildcard(connf_t *, conn_t *);
6317c478bd9Sstevel@tonic-gate void ipcl_hash_remove(conn_t *);
6327c478bd9Sstevel@tonic-gate void ipcl_hash_remove_locked(conn_t *connp, connf_t *connfp);
6337c478bd9Sstevel@tonic-gate 
6347c478bd9Sstevel@tonic-gate extern int	ipcl_bind_insert(conn_t *, uint8_t, ipaddr_t, uint16_t);
6357c478bd9Sstevel@tonic-gate extern int	ipcl_bind_insert_v6(conn_t *, uint8_t, const in6_addr_t *,
6367c478bd9Sstevel@tonic-gate 		    uint16_t);
6377c478bd9Sstevel@tonic-gate extern int	ipcl_conn_insert(conn_t *, uint8_t, ipaddr_t, ipaddr_t,
6387c478bd9Sstevel@tonic-gate 		    uint32_t);
6397c478bd9Sstevel@tonic-gate extern int	ipcl_conn_insert_v6(conn_t *, uint8_t, const in6_addr_t *,
6407c478bd9Sstevel@tonic-gate 		    const in6_addr_t *, uint32_t, uint_t);
641ff550d0eSmasputra extern conn_t	*ipcl_get_next_conn(connf_t *, conn_t *, uint32_t);
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate void ipcl_proto_insert(conn_t *, uint8_t);
6447c478bd9Sstevel@tonic-gate void ipcl_proto_insert_v6(conn_t *, uint8_t);
645f4b3ec61Sdh155122 conn_t *ipcl_classify_v4(mblk_t *, uint8_t, uint_t, zoneid_t, ip_stack_t *);
646f4b3ec61Sdh155122 conn_t *ipcl_classify_v6(mblk_t *, uint8_t, uint_t, zoneid_t, ip_stack_t *);
647f4b3ec61Sdh155122 conn_t *ipcl_classify(mblk_t *, zoneid_t, ip_stack_t *);
648f4b3ec61Sdh155122 conn_t *ipcl_classify_raw(mblk_t *, uint8_t, zoneid_t, uint32_t, ipha_t *,
649f4b3ec61Sdh155122 	    ip_stack_t *);
6502b24ab6bSSebastien Roy conn_t *ipcl_iptun_classify_v4(ipaddr_t *, ipaddr_t *, ip_stack_t *);
6512b24ab6bSSebastien Roy conn_t *ipcl_iptun_classify_v6(in6_addr_t *, in6_addr_t *, ip_stack_t *);
6527c478bd9Sstevel@tonic-gate void	ipcl_globalhash_insert(conn_t *);
6537c478bd9Sstevel@tonic-gate void	ipcl_globalhash_remove(conn_t *);
654f4b3ec61Sdh155122 void	ipcl_walk(pfv_t, void *, ip_stack_t *);
655f4b3ec61Sdh155122 conn_t	*ipcl_tcp_lookup_reversed_ipv4(ipha_t *, tcph_t *, int, ip_stack_t *);
656f4b3ec61Sdh155122 conn_t	*ipcl_tcp_lookup_reversed_ipv6(ip6_t *, tcpha_t *, int, uint_t,
657f4b3ec61Sdh155122 	    ip_stack_t *);
658f4b3ec61Sdh155122 conn_t	*ipcl_lookup_listener_v4(uint16_t, ipaddr_t, zoneid_t, ip_stack_t *);
659f4b3ec61Sdh155122 conn_t	*ipcl_lookup_listener_v6(uint16_t, in6_addr_t *, uint_t, zoneid_t,
660f4b3ec61Sdh155122 	    ip_stack_t *);
6617c478bd9Sstevel@tonic-gate int	conn_trace_ref(conn_t *);
6627c478bd9Sstevel@tonic-gate int	conn_untrace_ref(conn_t *);
663fc80c0dfSnordmark void	ipcl_conn_cleanup(conn_t *);
664f4b3ec61Sdh155122 conn_t *ipcl_conn_tcp_lookup_reversed_ipv4(conn_t *, ipha_t *, tcph_t *,
665f4b3ec61Sdh155122 	    ip_stack_t *);
666f4b3ec61Sdh155122 conn_t *ipcl_conn_tcp_lookup_reversed_ipv6(conn_t *, ip6_t *, tcph_t *,
667f4b3ec61Sdh155122 	    ip_stack_t *);
6680f1702c5SYu Xiangning 
6690f1702c5SYu Xiangning extern int ip_create_helper_stream(conn_t *connp, ldi_ident_t li);
670bfcb55b8SRao Shoaib extern void ip_free_helper_stream(conn_t *connp);
6710f1702c5SYu Xiangning 
6720f1702c5SYu Xiangning extern int ip_get_options(conn_t *, int, int, void *, t_uscalar_t *, cred_t *);
6730f1702c5SYu Xiangning extern int ip_set_options(conn_t *, int, int, const void *, t_uscalar_t,
6740f1702c5SYu Xiangning     cred_t *);
6750f1702c5SYu Xiangning 
6767c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
6777c478bd9Sstevel@tonic-gate }
6787c478bd9Sstevel@tonic-gate #endif
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate #endif	/* _INET_IPCLASSIFIER_H */
681