xref: /titanic_41/usr/src/uts/common/inet/ipclassifier.h (revision 986c3e858c71d3da2429d82e3ca17e44988f94b3)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_INET_IPCLASSIFIER_H
27 #define	_INET_IPCLASSIFIER_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <inet/common.h>
36 #include <inet/ip.h>
37 #include <inet/mi.h>
38 #include <inet/tcp.h>
39 #include <inet/ip6.h>
40 #include <netinet/in.h>		/* for IPPROTO_* constants */
41 #include <sys/sdt.h>
42 
43 typedef void (*edesc_spf)(void *, mblk_t *, void *, int);
44 typedef void (*edesc_rpf)(void *, mblk_t *, void *);
45 
46 /*
47  * ==============================
48  * =	The CONNECTION		=
49  * ==============================
50  */
51 
52 /*
53  * The connection structure contains the common information/flags/ref needed.
54  * Implementation will keep the connection struct, the layers (with their
55  * respective data for event i.e. tcp_t if event was tcp_input) all in one
56  * contiguous memory location.
57  */
58 
59 /* Conn Flags */
60 #define	IPCL_UDPMOD		0x00020000	/* Is UDP module instance */
61 #define	IPCL_TCPMOD		0x00040000	/* Is TCP module instance */
62 #define	IPCL_FULLY_BOUND	0x00080000	/* Bound to correct squeue */
63 #define	IPCL_CHECK_POLICY	0x00100000	/* Needs policy checking */
64 #define	IPCL_SOCKET		0x00200000	/* Sockfs connection */
65 #define	IPCL_ACCEPTOR		0x00400000	/* Sockfs priv acceptor */
66 #define	IPCL_CL_LISTENER	0x00800000	/* Cluster listener */
67 #define	IPCL_EAGER		0x01000000	/* Incoming connection */
68 #define	IPCL_UDP		0x02000000	/* A UDP connection */
69 #define	IPCL_TCP6		0x04000000	/* A TCP6 connection */
70 #define	IPCL_TCP4		0x08000000	/* A TCP connection */
71 #define	IPCL_CONNECTED		0x40000000	/* Conn in connected table */
72 #define	IPCL_BOUND		0x80000000	/* Conn in bind table */
73 
74 /* Flags identifying the type of conn */
75 #define	IPCL_TCPCONN		0x00000001	/* Flag to indicate cache */
76 #define	IPCL_SCTPCONN		0x00000002
77 #define	IPCL_IPCCONN		0x00000004
78 #define	IPCL_ISV6		0x00000008	/* Is a V6 connection */
79 
80 /* Conn Masks */
81 #define	IPCL_TCP		(IPCL_TCP4|IPCL_TCP6)
82 #define	IPCL_REMOVED		0x00000020
83 #define	IPCL_REUSED		0x00000040
84 
85 #define	IPCL_IS_TCP4(connp)						\
86 	(((connp)->conn_flags & IPCL_TCP4))
87 
88 #define	IPCL_IS_TCP4_CONNECTED_NO_POLICY(connp)				\
89 	(((connp)->conn_flags &						\
90 		(IPCL_TCP4|IPCL_CONNECTED|IPCL_CHECK_POLICY|IPCL_TCP6))	\
91 		== (IPCL_TCP4|IPCL_CONNECTED))
92 
93 #define	IPCL_IS_CONNECTED(connp)					\
94 	((connp)->conn_flags & IPCL_CONNECTED)
95 
96 #define	IPCL_IS_BOUND(connp)						\
97 	((connp)->conn_flags & IPCL_BOUND)
98 
99 #define	IPCL_IS_TCP4_BOUND(connp)					\
100 	(((connp)->conn_flags &						\
101 		(IPCL_TCP4|IPCL_BOUND|IPCL_TCP6)) ==			\
102 		(IPCL_TCP4|IPCL_BOUND))
103 
104 #define	IPCL_IS_FULLY_BOUND(connp)					\
105 	((connp)->conn_flags & IPCL_FULLY_BOUND)
106 
107 #define	IPCL_IS_TCP(connp)						\
108 	((connp)->conn_flags & (IPCL_TCP4|IPCL_TCP6))
109 
110 /*
111  * IPCL_UDP is set on the conn when udp is directly above ip;
112  * this flag is cleared the moment udp is popped.
113  */
114 #define	IPCL_IS_UDP(connp)						\
115 	((connp)->conn_flags & IPCL_UDP)
116 
117 #define	IPCL_IS_IPTUN(connp)						\
118 	((connp)->conn_ulp == IPPROTO_ENCAP || \
119 	(connp)->conn_ulp == IPPROTO_IPV6)
120 
121 typedef struct connf_s connf_t;
122 typedef struct
123 {
124 	int	ctb_depth;
125 #define	IP_STACK_DEPTH	15
126 	pc_t	ctb_stack[IP_STACK_DEPTH];
127 } conn_trace_t;
128 
129 struct conn_s {
130 	kmutex_t	conn_lock;
131 	uint32_t	conn_ref;		/* Reference counter */
132 	uint_t		conn_state_flags;	/* IP state flags */
133 	ire_t		*conn_ire_cache; 	/* outbound ire cache */
134 	uint32_t	conn_flags;		/* Conn Flags */
135 	unsigned int
136 		conn_on_sqp : 1,		/* Conn is being processed */
137 		conn_dontroute : 1,		/* SO_DONTROUTE state */
138 		conn_loopback : 1,		/* SO_LOOPBACK state */
139 		conn_broadcast : 1,		/* SO_BROADCAST state */
140 
141 		conn_reuseaddr : 1,		/* SO_REUSEADDR state */
142 		conn_multicast_loop : 1,	/* IP_MULTICAST_LOOP */
143 		conn_multi_router : 1,		/* Wants all multicast pkts */
144 		conn_draining : 1,		/* ip_wsrv running */
145 
146 		conn_did_putbq : 1,		/* ip_wput did a putbq */
147 		conn_unspec_src : 1,		/* IP_UNSPEC_SRC */
148 		conn_policy_cached : 1,		/* Is policy cached/latched ? */
149 		conn_in_enforce_policy : 1,	/* Enforce Policy on inbound */
150 
151 		conn_out_enforce_policy : 1,	/* Enforce Policy on outbound */
152 		conn_af_isv6 : 1,		/* ip address family ver 6 */
153 		conn_pkt_isv6 : 1,		/* ip packet format ver 6 */
154 		conn_ipv6_recvpktinfo : 1,	/* IPV6_RECVPKTINFO option */
155 
156 		conn_ipv6_recvhoplimit : 1,	/* IPV6_RECVHOPLIMIT option */
157 		conn_ipv6_recvhopopts : 1,	/* IPV6_RECVHOPOPTS option */
158 		conn_ipv6_recvdstopts : 1,	/* IPV6_RECVDSTOPTS option */
159 		conn_ipv6_recvrthdr : 1,	/* IPV6_RECVRTHDR option */
160 
161 		conn_ipv6_recvrtdstopts : 1,	/* IPV6_RECVRTHDRDSTOPTS */
162 		conn_ipv6_v6only : 1,		/* IPV6_V6ONLY */
163 		conn_ipv6_recvtclass : 1,	/* IPV6_RECVTCLASS */
164 		conn_ipv6_recvpathmtu : 1,	/* IPV6_RECVPATHMTU */
165 
166 		conn_pathmtu_valid : 1,		/* The cached mtu is valid. */
167 		conn_ipv6_dontfrag : 1,		/* IPV6_DONTFRAG */
168 		conn_fully_bound : 1,		/* Fully bound connection */
169 		conn_recvif : 1,		/* IP_RECVIF option */
170 
171 		conn_recvslla : 1,		/* IP_RECVSLLA option */
172 		conn_mdt_ok : 1,		/* MDT is permitted */
173 		conn_nexthop_set : 1,
174 		conn_allzones : 1;		/* SO_ALLZONES */
175 
176 	tcp_t		*conn_tcp;		/* Pointer to the tcp struct */
177 	struct udp_s	*conn_udp;		/* Pointer to the udp struct */
178 
179 	squeue_t	*conn_sqp;		/* Squeue for processing */
180 	edesc_rpf	conn_recv;		/* Pointer to recv routine */
181 	void		*conn_pad1;
182 
183 	ill_t		*conn_xmit_if_ill;	/* Outbound ill */
184 	ill_t		*conn_nofailover_ill;	/* Failover ill */
185 	ipsec_latch_t	*conn_latch;		/* latched state */
186 	ill_t		*conn_outgoing_ill;	/* IP{,V6}_BOUND_IF */
187 	edesc_spf	conn_send;		/* Pointer to send routine */
188 	queue_t		*conn_rq;		/* Read queue */
189 	queue_t		*conn_wq;		/* Write queue */
190 	dev_t		conn_dev;		/* Minor number */
191 
192 	cred_t		*conn_cred;		/* Credentials */
193 	connf_t		*conn_g_fanout;		/* Global Hash bucket head */
194 	struct conn_s	*conn_g_next;		/* Global Hash chain next */
195 	struct conn_s	*conn_g_prev;		/* Global Hash chain prev */
196 	struct ipsec_policy_head_s *conn_policy; /* Configured policy */
197 	in6_addr_t	conn_bound_source_v6;
198 #define	conn_bound_source	V4_PART_OF_V6(conn_bound_source_v6)
199 	void		*conn_void[1];
200 
201 	connf_t		*conn_fanout;		/* Hash bucket we're part of */
202 	struct conn_s	*conn_next;		/* Hash chain next */
203 	struct conn_s	*conn_prev;		/* Hash chain prev */
204 	struct {
205 		in6_addr_t connua_laddr;	/* Local address */
206 		in6_addr_t connua_faddr;	/* Remote address */
207 	} connua_v6addr;
208 #define	conn_src	V4_PART_OF_V6(connua_v6addr.connua_laddr)
209 #define	conn_rem	V4_PART_OF_V6(connua_v6addr.connua_faddr)
210 #define	conn_srcv6	connua_v6addr.connua_laddr
211 #define	conn_remv6	connua_v6addr.connua_faddr
212 	union {
213 		/* Used for classifier match performance */
214 		uint32_t		conn_ports2;
215 		struct {
216 			in_port_t	tcpu_fport;	/* Remote port */
217 			in_port_t	tcpu_lport;	/* Local port */
218 		} tcpu_ports;
219 	} u_port;
220 #define	conn_fport	u_port.tcpu_ports.tcpu_fport
221 #define	conn_lport	u_port.tcpu_ports.tcpu_lport
222 #define	conn_ports	u_port.conn_ports2
223 #define	conn_upq	conn_rq
224 	uint8_t		conn_ulp;		/* protocol type */
225 	uint8_t		conn_unused_byte;
226 	kcondvar_t	conn_cv;
227 
228 	uint_t		conn_proto;		/* SO_PROTOTYPE state */
229 	ill_t		*conn_incoming_ill;	/* IP{,V6}_BOUND_IF */
230 	ill_t		*conn_outgoing_pill;	/* IP{,V6}_BOUND_PIF */
231 	ill_t		*conn_oper_pending_ill; /* pending shared ioctl */
232 	ill_t		*conn_xioctl_pending_ill; /* pending excl ioctl */
233 
234 	/* this is used only when an unbind is in progress.. */
235 	struct sq_s	*conn_pending_sq; /* waiting for ioctl on sq */
236 	ilg_t	*conn_ilg;		/* Group memberships */
237 	int	conn_ilg_allocated;	/* Number allocated */
238 	int	conn_ilg_inuse;		/* Number currently used */
239 	int	conn_ilg_walker_cnt;	/* No of ilg walkers */
240 	/* XXXX get rid of this, once ilg_delete_all is fixed */
241 	kcondvar_t	conn_refcv;
242 
243 	struct ipif_s	*conn_multicast_ipif;	/* IP_MULTICAST_IF */
244 	ill_t		*conn_multicast_ill;	/* IPV6_MULTICAST_IF */
245 	int		conn_orig_bound_ifindex; /* BOUND_IF before MOVE */
246 	int		conn_orig_multicast_ifindex;
247 						/* IPv6 MC IF before MOVE */
248 	int		conn_orig_xmit_ifindex; /* IP_XMIT_IF before move */
249 	struct conn_s 	*conn_drain_next;	/* Next conn in drain list */
250 	struct conn_s	*conn_drain_prev;	/* Prev conn in drain list */
251 	idl_t		*conn_idl;		/* Ptr to the drain list head */
252 	mblk_t		*conn_ipsec_opt_mp;	/* ipsec option mblk */
253 	uint32_t	conn_src_preferences;	/* prefs for src addr select */
254 	/* mtuinfo from IPV6_PACKET_TOO_BIG conditional on conn_pathmtu_valid */
255 	struct ip6_mtuinfo mtuinfo;
256 	zoneid_t	conn_zoneid;		/* zone connection is in */
257 	in6_addr_t	conn_nexthop_v6;	/* nexthop IP address */
258 #define	conn_nexthop_v4	V4_PART_OF_V6(conn_nexthop_v6)
259 	cred_t		*conn_peercred;		/* Peer credentials, if any */
260 
261 	unsigned int
262 		conn_ulp_labeled : 1,		/* ULP label is synced */
263 		conn_mlp_type : 2,		/* mlp_type_t; tsol/tndb.h */
264 		conn_anon_mlp : 1,		/* user wants anon MLP */
265 
266 		conn_anon_port : 1,		/* user bound anonymously */
267 		conn_mac_exempt : 1,		/* unlabeled with loose MAC */
268 		conn_spare : 26;
269 
270 #ifdef CONN_DEBUG
271 #define	CONN_TRACE_MAX	10
272 	int		conn_trace_last;	/* ndx of last used tracebuf */
273 	conn_trace_t	conn_trace_buf[CONN_TRACE_MAX];
274 #endif
275 };
276 
277 #define	CONN_CRED(connp) ((connp)->conn_peercred == NULL ? \
278 	(connp)->conn_cred : (connp)->conn_peercred)
279 #define	BEST_CRED(mp, connp) ((DB_CRED(mp) != NULL &&	\
280 	crgetlabel(DB_CRED(mp)) != NULL) ? DB_CRED(mp) : CONN_CRED(connp))
281 
282 /*
283  * connf_t - connection fanout data.
284  *
285  * The hash tables and their linkage (conn_t.{hashnextp, hashprevp} are
286  * protected by the per-bucket lock. Each conn_t inserted in the list
287  * points back at the connf_t that heads the bucket.
288  */
289 
290 struct connf_s {
291 	struct conn_s	*connf_head;
292 	kmutex_t	connf_lock;
293 };
294 
295 #define	CONN_INC_REF(connp)	{				\
296 	DTRACE_PROBE1(conn__inc__ref, conn_t *, connp);		\
297 	mutex_enter(&(connp)->conn_lock);			\
298 	ASSERT(conn_trace_ref(connp));				\
299 	(connp)->conn_ref++;					\
300 	ASSERT((connp)->conn_ref != 0);				\
301 	mutex_exit(&(connp)->conn_lock);			\
302 }
303 
304 #define	CONN_INC_REF_LOCKED(connp)	{			\
305 	DTRACE_PROBE1(conn__inc__ref, conn_t *, connp);		\
306 	ASSERT(MUTEX_HELD(&(connp)->conn_lock));	 	\
307 	ASSERT(conn_trace_ref(connp));				\
308 	(connp)->conn_ref++;					\
309 	ASSERT((connp)->conn_ref != 0);				\
310 }
311 
312 #define	CONN_DEC_REF(connp)	{					\
313 	DTRACE_PROBE1(conn__dec__ref, conn_t *, connp);			\
314 	mutex_enter(&(connp)->conn_lock);				\
315 	if ((connp)->conn_ref <= 0)					\
316 		cmn_err(CE_PANIC, "CONN_DEC_REF: connp(%p) has ref "	\
317 			"= %d\n", (void *)(connp), (connp)->conn_ref);	\
318 	ASSERT(conn_untrace_ref(connp));				\
319 	(connp)->conn_ref--;						\
320 	if ((connp)->conn_ref == 0) {					\
321 		/* Refcnt can't increase again, safe to drop lock */	\
322 		mutex_exit(&(connp)->conn_lock);			\
323 		ipcl_conn_destroy(connp);				\
324 	} else {							\
325 		cv_broadcast(&(connp)->conn_cv);			\
326 		mutex_exit(&(connp)->conn_lock);			\
327 	}								\
328 }
329 
330 /*
331  * For use with subsystems within ip which use ALL_ZONES as a wildcard
332  */
333 #define	IPCL_ZONEID(connp)						\
334 	((connp)->conn_allzones ? ALL_ZONES : (connp)->conn_zoneid)
335 
336 /*
337  * For matching between a conn_t and a zoneid.
338  */
339 #define	IPCL_ZONE_MATCH(connp, zoneid) 					\
340 	(((connp)->conn_allzones) ||					\
341 	    ((zoneid) == ALL_ZONES) ||					\
342 	    (connp)->conn_zoneid == (zoneid))
343 
344 
345 #define	_IPCL_V4_MATCH(v6addr, v4addr)	\
346 	(V4_PART_OF_V6((v6addr)) == (v4addr) && IN6_IS_ADDR_V4MAPPED(&(v6addr)))
347 
348 #define	_IPCL_V4_MATCH_ANY(addr)	\
349 	(IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) || IN6_IS_ADDR_UNSPECIFIED(&(addr)))
350 
351 
352 /*
353  * IPCL_PROTO_MATCH() only matches conns with the specified zoneid, while
354  * IPCL_PROTO_MATCH_V6() can match other conns in the multicast case, see
355  * ip_fanout_proto().
356  */
357 #define	IPCL_PROTO_MATCH(connp, protocol, ipha, ill,			\
358     fanout_flags, zoneid)						\
359 	((((connp)->conn_src == INADDR_ANY) ||				\
360 	(((connp)->conn_src == ((ipha)->ipha_dst)) &&			\
361 	    (((connp)->conn_rem == INADDR_ANY) ||			\
362 	((connp)->conn_rem == ((ipha)->ipha_src))))) &&			\
363 	IPCL_ZONE_MATCH(connp, zoneid) &&				\
364 	(conn_wantpacket((connp), (ill), (ipha), (fanout_flags), 	\
365 	    (zoneid)) || ((protocol) == IPPROTO_PIM) ||			\
366 	    ((protocol) == IPPROTO_RSVP)))
367 
368 #define	IPCL_PROTO_MATCH_V6(connp, protocol, ip6h, ill,			   \
369     fanout_flags, zoneid)						   \
370 	((IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) ||		   \
371 	(IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &((ip6h)->ip6_dst)) &&   \
372 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) ||		   \
373 	IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &((ip6h)->ip6_src))))) && \
374 	(conn_wantpacket_v6((connp), (ill), (ip6h),			   \
375 	(fanout_flags), (zoneid)) || ((protocol) == IPPROTO_RSVP)))
376 
377 #define	IPCL_CONN_HASH(src, ports)					\
378 	((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^	\
379 	((ports) >> 8) ^ (ports)) % ipcl_conn_fanout_size)
380 
381 #define	IPCL_CONN_HASH_V6(src, ports)			\
382 	IPCL_CONN_HASH(V4_PART_OF_V6((src)), (ports))
383 
384 #define	IPCL_CONN_MATCH(connp, proto, src, dst, ports)			\
385 	((connp)->conn_ulp == (proto) &&				\
386 		(connp)->conn_ports == (ports) &&      			\
387 		_IPCL_V4_MATCH((connp)->conn_remv6, (src)) &&		\
388 		_IPCL_V4_MATCH((connp)->conn_srcv6, (dst)) &&		\
389 		!(connp)->conn_ipv6_v6only)
390 
391 #define	IPCL_CONN_MATCH_V6(connp, proto, src, dst, ports)		\
392 	((connp)->conn_ulp == (proto) &&				\
393 		(connp)->conn_ports == (ports) &&      			\
394 		IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(src)) &&	\
395 		IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(dst)))
396 
397 #define	IPCL_CONN_INIT(connp, protocol, src, rem, ports) {		\
398 	(connp)->conn_ulp = protocol;					\
399 	IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6);		\
400 	IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6);		\
401 	(connp)->conn_ports = ports;					\
402 }
403 
404 #define	IPCL_CONN_INIT_V6(connp, protocol, src, rem, ports) {		\
405 	(connp)->conn_ulp = protocol;					\
406 	(connp)->conn_srcv6 = src;					\
407 	(connp)->conn_remv6 = rem;					\
408 	(connp)->conn_ports = ports;					\
409 }
410 
411 #define	IPCL_PORT_HASH(port, size) \
412 	((((port) >> 8) ^ (port)) & ((size) - 1))
413 
414 #define	IPCL_BIND_HASH(lport)	IPCL_PORT_HASH(lport, ipcl_bind_fanout_size)
415 
416 #define	IPCL_BIND_MATCH(connp, proto, laddr, lport)			\
417 	((connp)->conn_ulp == (proto) &&				\
418 		(connp)->conn_lport == (lport) &&			\
419 		(_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) ||		\
420 		_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr))) &&	\
421 		!(connp)->conn_ipv6_v6only)
422 
423 #define	IPCL_BIND_MATCH_V6(connp, proto, laddr, lport)			\
424 	((connp)->conn_ulp == (proto) &&				\
425 		(connp)->conn_lport == (lport) &&			\
426 		(IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) ||	\
427 		IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6)))
428 
429 #define	IPCL_UDP_MATCH(connp, lport, laddr, fport, faddr)		\
430 	(((connp)->conn_lport == (lport)) &&				\
431 	((_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) ||			\
432 	(_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)) &&		\
433 	(_IPCL_V4_MATCH_ANY((connp)->conn_remv6) ||			\
434 	(_IPCL_V4_MATCH((connp)->conn_remv6, (faddr)) &&		\
435 	(connp)->conn_fport == (fport)))))) &&				\
436 	!(connp)->conn_ipv6_v6only)
437 
438 #define	IPCL_UDP_MATCH_V6(connp, lport, laddr, fport, faddr)	\
439 	(((connp)->conn_lport == (lport)) &&			\
440 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) ||	\
441 	(IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) &&	\
442 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) ||	\
443 	(IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(faddr)) &&	\
444 	(connp)->conn_fport == (fport))))))
445 
446 #define	IPCL_TCP_EAGER_INIT(connp, protocol, src, rem, ports) {		\
447 	(connp)->conn_flags |= (IPCL_TCP4|IPCL_EAGER);			\
448 	(connp)->conn_ulp = protocol;					\
449 	IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6);		\
450 	IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6);		\
451 	(connp)->conn_ports = ports;					\
452 	(connp)->conn_send = ip_output;					\
453 	(connp)->conn_sqp = IP_SQUEUE_GET(lbolt);			\
454 }
455 
456 #define	IPCL_TCP_EAGER_INIT_V6(connp, protocol, src, rem, ports) {	\
457 	(connp)->conn_flags |= (IPCL_TCP6|IPCL_EAGER);			\
458 	(connp)->conn_ulp = protocol;					\
459 	(connp)->conn_srcv6 = src;					\
460 	(connp)->conn_remv6 = rem;					\
461 	(connp)->conn_ports = ports;					\
462 	(connp)->conn_send = ip_output_v6;				\
463 	(connp)->conn_sqp = IP_SQUEUE_GET(lbolt);			\
464 }
465 
466 #define	ipcl_proto_search(protocol)					\
467 	(ipcl_proto_fanout[(protocol)].connf_head)
468 
469 #define	IPCL_UDP_HASH(lport)	IPCL_PORT_HASH(lport, ipcl_udp_fanout_size)
470 
471 #define	CONN_G_HASH_SIZE	1024
472 
473 /* Raw socket hash function. */
474 #define	IPCL_RAW_HASH(lport)	IPCL_PORT_HASH(lport, ipcl_raw_fanout_size)
475 
476 /*
477  * This is similar to IPCL_BIND_MATCH except that the local port check
478  * is changed to a wildcard port check.
479  */
480 #define	IPCL_RAW_MATCH(connp, proto, laddr)			\
481 	((connp)->conn_ulp == (proto) &&			\
482 	(connp)->conn_lport == 0 &&				\
483 	(_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) ||		\
484 	_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr))))
485 
486 #define	IPCL_RAW_MATCH_V6(connp, proto, laddr)			\
487 	((connp)->conn_ulp == (proto) &&			\
488 	(connp)->conn_lport == 0 &&				\
489 	(IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) ||	\
490 	IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr))))
491 
492 /* hash tables */
493 extern connf_t	rts_clients;
494 extern connf_t	*ipcl_conn_fanout;
495 extern connf_t	*ipcl_bind_fanout;
496 extern connf_t	ipcl_proto_fanout[IPPROTO_MAX + 1];
497 extern connf_t	ipcl_proto_fanout_v6[IPPROTO_MAX + 1];
498 extern connf_t	*ipcl_udp_fanout;
499 extern connf_t	*ipcl_globalhash_fanout;
500 extern connf_t	*ipcl_raw_fanout;
501 extern uint_t	ipcl_conn_fanout_size;
502 extern uint_t	ipcl_bind_fanout_size;
503 extern uint_t	ipcl_udp_fanout_size;
504 extern uint_t	ipcl_raw_fanout_size;
505 
506 /* Function prototypes */
507 extern void ipcl_init(void);
508 extern void ipcl_destroy(void);
509 extern conn_t *ipcl_conn_create(uint32_t, int);
510 extern void ipcl_conn_destroy(conn_t *);
511 
512 void ipcl_hash_insert_connected(connf_t *, conn_t *);
513 void ipcl_hash_insert_bound(connf_t *, conn_t *);
514 void ipcl_hash_insert_wildcard(connf_t *, conn_t *);
515 void ipcl_hash_remove(conn_t *);
516 void ipcl_hash_remove_locked(conn_t *connp, connf_t *connfp);
517 
518 extern int	ipcl_bind_insert(conn_t *, uint8_t, ipaddr_t, uint16_t);
519 extern int	ipcl_bind_insert_v6(conn_t *, uint8_t, const in6_addr_t *,
520 		    uint16_t);
521 extern int	ipcl_conn_insert(conn_t *, uint8_t, ipaddr_t, ipaddr_t,
522 		    uint32_t);
523 extern int	ipcl_conn_insert_v6(conn_t *, uint8_t, const in6_addr_t *,
524 		    const in6_addr_t *, uint32_t, uint_t);
525 extern conn_t	*ipcl_get_next_conn(connf_t *, conn_t *, uint32_t);
526 
527 void ipcl_proto_insert(conn_t *, uint8_t);
528 void ipcl_proto_insert_v6(conn_t *, uint8_t);
529 conn_t *ipcl_classify_v4(mblk_t *, uint8_t, uint_t, zoneid_t);
530 conn_t *ipcl_classify_v6(mblk_t *, uint8_t, uint_t, zoneid_t);
531 conn_t *ipcl_classify(mblk_t *, zoneid_t);
532 conn_t *ipcl_classify_raw(mblk_t *, uint8_t, zoneid_t, uint32_t, ipha_t *);
533 void	ipcl_globalhash_insert(conn_t *);
534 void	ipcl_globalhash_remove(conn_t *);
535 void	ipcl_walk(pfv_t, void *);
536 conn_t	*ipcl_tcp_lookup_reversed_ipv4(ipha_t *, tcph_t *, int);
537 conn_t	*ipcl_tcp_lookup_reversed_ipv6(ip6_t *, tcpha_t *, int, uint_t);
538 conn_t	*ipcl_lookup_listener_v4(uint16_t, ipaddr_t, zoneid_t);
539 conn_t	*ipcl_lookup_listener_v6(uint16_t, in6_addr_t *, uint_t, zoneid_t);
540 int	conn_trace_ref(conn_t *);
541 int	conn_untrace_ref(conn_t *);
542 conn_t *ipcl_conn_tcp_lookup_reversed_ipv4(conn_t *, ipha_t *, tcph_t *);
543 conn_t *ipcl_conn_tcp_lookup_reversed_ipv6(conn_t *, ip6_t *, tcph_t *);
544 #ifdef	__cplusplus
545 }
546 #endif
547 
548 #endif	/* _INET_IPCLASSIFIER_H */
549