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