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