xref: /illumos-gate/usr/src/uts/common/inet/ipf/netinet/ip_compat.h (revision 3d393ee6c37fa10ac512ed6d36109ad616dc7c1a)
1 /*
2  * Copyright (C) 1993-2001, 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * @(#)ip_compat.h	1.8 1/14/96
7  * $Id: ip_compat.h,v 2.142.2.30 2005/08/11 15:13:49 darrenr Exp $
8  *
9  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
10  * Use is subject to license terms.
11  */
12 
13 #ifndef	__IP_COMPAT_H__
14 #define	__IP_COMPAT_H__
15 
16 #ifndef	__P
17 # ifdef	__STDC__
18 #  define	__P(x)  x
19 # else
20 #  define	__P(x)  ()
21 # endif
22 #endif
23 #ifndef	__STDC__
24 # undef		const
25 # define	const
26 #endif
27 
28 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
29 # undef	KERNEL
30 # undef	_KERNEL
31 # undef 	__KERNEL__
32 # define	KERNEL
33 # define	_KERNEL
34 # define 	__KERNEL__
35 #endif
36 
37 #ifndef	SOLARIS
38 #define	SOLARIS	(defined(sun) && (defined(__svr4__) || defined(__SVR4)))
39 #endif
40 #if SOLARIS2 >= 8
41 # ifndef	USE_INET6
42 #  define	USE_INET6
43 # endif
44 #endif
45 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
46     !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
47 # define	USE_INET6
48 #endif
49 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \
50     !defined(_KERNEL) && !defined(USE_INET6)
51 # define	USE_INET6
52 # define	IPFILTER_M_IPFILTER
53 #endif
54 #if defined(OpenBSD) && (OpenBSD >= 200206) && \
55     !defined(_KERNEL) && !defined(USE_INET6)
56 # define	USE_INET6
57 #endif
58 #if defined(__osf__)
59 # define	USE_INET6
60 #endif
61 #if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6))
62 # define	USE_INET6
63 #endif
64 #if defined(HPUXREV) && (HPUXREV >= 1111)
65 # define	USE_INET6
66 #endif
67 
68 #if defined(BSD) && (BSD < 199103) && defined(__osf__)
69 # undef BSD
70 # define BSD 199103
71 #endif
72 
73 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
74 # define index   strchr
75 # if !defined(_KERNEL)
76 #  define	bzero(a,b)	memset(a,0,b)
77 #  define	bcmp		memcmp
78 #  define	bcopy(a,b,c)	memmove(b,a,c)
79 # endif
80 #endif
81 
82 #ifndef LIFNAMSIZ
83 # ifdef IF_NAMESIZE
84 #  define	LIFNAMSIZ	IF_NAMESIZE
85 # else
86 #  ifdef	IFNAMSIZ
87 #   define	LIFNAMSIZ	IFNAMSIZ
88 #  else
89 #   define	LIFNAMSIZ	16
90 #  endif
91 # endif
92 #endif
93 
94 #if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
95 struct  ether_addr {
96         u_char  ether_addr_octet[6];
97 };
98 #endif
99 
100 #if defined(__sgi) && !defined(IPFILTER_LKM)
101 # ifdef __STDC__
102 #  define IPL_EXTERN(ep) ipfilter##ep
103 # else
104 #  define IPL_EXTERN(ep) ipfilter/**/ep
105 # endif
106 #else
107 # ifdef __STDC__
108 #  define IPL_EXTERN(ep) ipl##ep
109 # else
110 #  define IPL_EXTERN(ep) ipl/**/ep
111 # endif
112 #endif
113 
114 /*
115  * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
116  */
117 #ifndef linux
118 # ifndef _KERNEL
119 #  define ADD_KERNEL
120 #  define _KERNEL
121 #  define KERNEL
122 # endif
123 # ifdef __OpenBSD__
124 struct file;
125 # endif
126 # include <sys/uio.h>
127 # ifdef ADD_KERNEL
128 #  undef _KERNEL
129 #  undef KERNEL
130 # endif
131 #endif
132 
133 
134 /* ----------------------------------------------------------------------- */
135 /*                                  S O L A R I S                          */
136 /* ----------------------------------------------------------------------- */
137 #if SOLARIS
138 # define	MENTAT	1
139 # include	<sys/cmn_err.h>
140 # include	<sys/isa_defs.h>
141 # include	<sys/stream.h>
142 # include	<sys/ioccom.h>
143 # include	<sys/sysmacros.h>
144 # include	<sys/kmem.h>
145 # if SOLARIS2 >= 10
146 #  include	<sys/procset.h>
147 #  include	<sys/proc.h>
148 #  include	<sys/devops.h>
149 #  include	<sys/ddi_impldefs.h>
150 #  include	<sys/neti.h>
151 # endif
152 
153 /*
154  * inet/ip.h would end up including radix.h with _KERNEL, which is not
155  * what the tools intend, so include radix.h first.
156  */
157 #if SOLARIS2 > 10
158 # include <net/radix.h>
159 #endif
160 /*
161  * because Solaris 2 defines these in two places :-/
162  */
163 # ifndef	KERNEL
164 #  define	ADD_KERNEL
165 #  define	_KERNEL
166 #  undef	RES_INIT
167 # endif /* _KERNEL */
168 
169 # if SOLARIS2 >= 8
170 #  include <netinet/ip6.h>
171 #  include <netinet/icmp6.h>
172 # endif
173 
174 # include <inet/common.h>
175 /* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */
176 # undef	IPOPT_EOL
177 # undef	IPOPT_NOP
178 # undef	IPOPT_LSRR
179 # undef	IPOPT_RR
180 # undef	IPOPT_SSRR
181 # ifdef i386
182 #  define _SYS_PROMIF_H
183 # endif
184 # ifdef ADD_KERNEL
185 #  undef _KERNEL
186 # endif
187 # include <inet/ip.h>
188 # undef COPYOUT
189 # include <inet/ip_ire.h>
190 # ifndef	KERNEL
191 #  undef	_KERNEL
192 # endif
193 # if SOLARIS2 >= 8
194 #  define SNPRINTF	snprintf
195 
196 #  include <inet/ip_if.h>
197 #  define	ipif_local_addr	ipif_lcl_addr
198 /* Only defined in private include file */
199 #  ifndef	V4_PART_OF_V6
200 #   define	V4_PART_OF_V6(v6)	v6.s6_addr32[3]
201 #  endif
202 struct ip6_ext {
203 	u_char	ip6e_nxt;
204 	u_char	ip6e_len;
205 };
206 # endif /* SOLARIS2 >= 8 */
207 
208 # ifdef FW_HOOKS
209 
210 #  define	SOLARIS_PFHOOKS	1
211 
212 typedef	struct	qpktinfo	{
213 	/* data that changes per-packet */
214 	void		*qpi_ill;	/* COPIED */
215 	mblk_t		*qpi_m;
216 	void		*qpi_data;	/* where layer 3 header starts */
217 	size_t		qpi_off;
218 	int		qpi_flags;	/* Uses FI_* flags */
219 } qpktinfo_t;
220 
221 extern void mb_copydata __P((mblk_t *, size_t , size_t, char *));
222 extern void mb_copyback __P((mblk_t *, size_t , size_t, char *));
223 # endif
224 
225 # if SOLARIS2 >= 6
226 #  include <sys/atomic.h>
227 typedef	uint32_t	u_32_t;
228 # else
229 typedef unsigned int	u_32_t;
230 # endif
231 # define	U_32_T	1
232 
233 # ifdef _KERNEL
234 #  define	KRWLOCK_T		krwlock_t
235 #  define	KMUTEX_T		kmutex_t
236 #  if SOLARIS2 >= 10
237 #   include <sys/sdt.h>
238 #  endif /* SOLARIS2 >= 10 */
239 #  if SOLARIS2 >= 6
240 #   if SOLARIS2 == 6
241 #    define	ATOMIC_INCL(x)		atomic_add_long((uint32_t*)&(x), 1)
242 #    define	ATOMIC_DECL(x)		atomic_add_long((uint32_t*)&(x), -1)
243 #   else
244 #    define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
245 #    define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
246 #   endif /* SOLARIS2 == 6 */
247 #   define	ATOMIC_INC64(x)		atomic_add_64((uint64_t*)&(x), 1)
248 #   define	ATOMIC_INC32(x)		atomic_add_32((uint32_t*)&(x), 1)
249 #   define	ATOMIC_INC16(x)		atomic_add_16((uint16_t*)&(x), 1)
250 #   define	ATOMIC_DEC64(x)		atomic_add_64((uint64_t*)&(x), -1)
251 #   define	ATOMIC_DEC32(x)		atomic_add_32((uint32_t*)&(x), -1)
252 #   define	ATOMIC_DEC16(x)		atomic_add_16((uint16_t*)&(x), -1)
253 #  else
254 #   define	ATOMIC_INC(x)		{ mutex_enter(&ipf_rw); (x)++; \
255 					  mutex_exit(&ipf_rw); }
256 #   define	ATOMIC_DEC(x)		{ mutex_enter(&ipf_rw); (x)--; \
257 					  mutex_exit(&ipf_rw); }
258 #  endif /* SOLARIS2 >= 6 */
259 #  define	USE_MUTEXES
260 #  define	MUTEX_ENTER(x)		mutex_enter(&(x)->ipf_lk)
261 #  define	READ_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_READER)
262 #  define	WRITE_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_WRITER)
263 #  define	MUTEX_DOWNGRADE(x)	rw_downgrade(&(x)->ipf_lk)
264 #  define	RWLOCK_INIT(x, y)	rw_init(&(x)->ipf_lk, (y),  \
265 						RW_DRIVER, NULL)
266 #  define	RWLOCK_EXIT(x)		rw_exit(&(x)->ipf_lk)
267 #  define	RW_DESTROY(x)		rw_destroy(&(x)->ipf_lk)
268 #  define	MUTEX_INIT(x, y)	mutex_init(&(x)->ipf_lk, (y), \
269 						   MUTEX_DRIVER, NULL)
270 #  define	MUTEX_DESTROY(x)	mutex_destroy(&(x)->ipf_lk)
271 #  define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
272 #  define	MUTEX_EXIT(x)		mutex_exit(&(x)->ipf_lk)
273 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
274 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
275 #  define	BCOPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
276 #  define	BCOPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
277 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
278 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
279 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
280 #  define	SPL_NET(x)	;
281 #  define	SPL_IMP(x)	;
282 #  undef	SPL_X
283 #  define	SPL_X(x)	;
284 #  ifdef sparc
285 #   define	ntohs(x)	(x)
286 #   define	ntohl(x)	(x)
287 #   define	htons(x)	(x)
288 #   define	htonl(x)	(x)
289 #  endif /* sparc */
290 #  define	KMALLOC(a,b)	(a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
291 #  define	KMALLOCS(a,b,c)	(a) = (b)kmem_alloc((c), KM_NOSLEEP)
292 #  define	GET_MINOR(x)	getminor(x)
293 /*extern	phy_if_t	get_unit __P((char *, int, ipf_stack_t *));*/
294 #  define	GETIFP(n, v, ifs)	(void *)get_unit(n, v, ifs)
295 #  define	IFNAME(x)	((ill_t *)x)->ill_name
296 #  define	COPYIFNAME(x, b, v)	(void) net_getifname(((v) == 4) ? \
297 					ifs->ifs_ipf_ipv4 : ifs->ifs_ipf_ipv6,\
298 					(phy_if_t)(x), (b), sizeof(b))
299 #  define	GETKTIME(x)	uniqtime((struct timeval *)x)
300 #  define	MSGDSIZE(x)	msgdsize(x)
301 #  define	M_LEN(x)	((x)->b_wptr - (x)->b_rptr)
302 #  define	M_DUPLICATE(x)	dupmsg((x))
303 #  define	MTOD(m,t)	((t)((m)->b_rptr))
304 #  define	MTYPE(m)	((m)->b_datap->db_type)
305 #  define	FREE_MB_T(m)	freemsg(m)
306 #  define	m_next		b_cont
307 #  define	CACHE_HASH(x)	(((phy_if_t)(x)->fin_ifp) & 7)
308 #  define	IPF_PANIC(x,y)	if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
309 typedef mblk_t mb_t;
310 # endif /* _KERNEL */
311 
312 # if (SOLARIS2 >= 7)
313 #  ifdef lint
314 #   define ALIGN32(ptr)    (ptr ? 0L : 0L)
315 #   define ALIGN16(ptr)    (ptr ? 0L : 0L)
316 #  else
317 #   define ALIGN32(ptr)    (ptr)
318 #   define ALIGN16(ptr)    (ptr)
319 #  endif
320 # endif
321 
322 # if SOLARIS2 < 6
323 typedef	struct uio	uio_t;
324 # endif
325 typedef	int		ioctlcmd_t;
326 typedef	uint8_t		u_int8_t;
327 
328 # define OS_RECOGNISED 1
329 
330 #endif /* SOLARIS */
331 
332 /* ----------------------------------------------------------------------- */
333 /*                                  H P U X                                */
334 /* ----------------------------------------------------------------------- */
335 #ifdef __hpux
336 # define	MENTAT	1
337 # include	<sys/sysmacros.h>
338 # include	<sys/spinlock.h>
339 # include	<sys/lock.h>
340 # include	<sys/stream.h>
341 # ifdef USE_INET6
342 #  include	<netinet/if_ether.h>
343 #  include	<netinet/ip6.h>
344 #  include	<netinet/icmp6.h>
345 typedef	struct	ip6_hdr	ip6_t;
346 # endif
347 
348 # ifdef _KERNEL
349 #  define SNPRINTF	sprintf
350 #  if (HPUXREV >= 1111)
351 #   define	IPL_SELECT
352 #   ifdef	IPL_SELECT
353 #    include	<machine/sys/user.h>
354 #    include	<sys/kthread_iface.h>
355 #    define	READ_COLLISION	0x01
356 
357 typedef	struct	iplog_select_s {
358 	kthread_t	*read_waiter;
359 	int		state;
360 } iplog_select_t;
361 #   endif
362 #  endif
363 
364 #  define	GETKTIME(x)	uniqtime((struct timeval *)x)
365 
366 #  if HPUXREV == 1111
367 #   include	"kern_svcs.h"
368 #  else
369 #   include	<sys/kern_svcs.h>
370 #  endif
371 #  undef	ti_flags
372 #  undef	TCP_NODELAY
373 #  undef	TCP_MAXSEG
374 #  include <sys/reg.h>
375 #  include "../netinet/ip_info.h"
376 /*
377  * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
378  * are available.  Attempting to use them actually results in unresolved
379  * symbols when it comes time to load the module.
380  * This has been fixed!  Yipee!
381  */
382 #  if 1
383 #   ifdef __LP64__
384 #    define	ATOMIC_INCL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
385 #    define	ATOMIC_DECL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
386 #   else
387 #    define	ATOMIC_INCL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
388 #    define	ATOMIC_DECL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
389 #   endif
390 #   define	ATOMIC_INC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
391 #   define	ATOMIC_INC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
392 #   define	ATOMIC_INC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
393 #   define	ATOMIC_DEC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
394 #   define	ATOMIC_DEC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
395 #   define	ATOMIC_DEC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
396 #  else /* 0 */
397 #   define	ATOMIC_INC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
398 					  MUTEX_EXIT(&ipf_rw); }
399 #   define	ATOMIC_DEC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
400 					  MUTEX_EXIT(&ipf_rw); }
401 #   define	ATOMIC_INC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
402 					  MUTEX_EXIT(&ipf_rw); }
403 #   define	ATOMIC_DEC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
404 					  MUTEX_EXIT(&ipf_rw); }
405 #   define	ATOMIC_INCL(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
406 					  MUTEX_EXIT(&ipf_rw); }
407 #   define	ATOMIC_DECL(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
408 					  MUTEX_EXIT(&ipf_rw); }
409 #   define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
410 					  MUTEX_EXIT(&ipf_rw); }
411 #   define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
412 					  MUTEX_EXIT(&ipf_rw); }
413 #  endif
414 #  define	ip_cksum		ip_csuma
415 #  define	memcpy(a,b,c)		bcopy((caddr_t)b, (caddr_t)a, c)
416 #  define	USE_MUTEXES
417 #  define	MUTEX_INIT(x, y)	initlock(&(x)->ipf_lk, 0, 0, (y))
418 #  define	MUTEX_ENTER(x)		spinlock(&(x)->ipf_lk)
419 #  define	MUTEX_EXIT(x)		spinunlock(&(x)->ipf_lk);
420 #  define	MUTEX_DESTROY(x)
421 #  define	MUTEX_NUKE(x)		bzero((char *)(x), sizeof(*(x)))
422 #  define	KMUTEX_T		lock_t
423 #  define	kmutex_t		lock_t		/* for pfil.h */
424 #  define	krwlock_t		lock_t		/* for pfil.h */
425 /*
426  * The read-write lock implementation in HP-UX 11.0 is crippled - it can
427  * only be used by threads working in a user context!
428  * This has been fixed!  Yipee! (Or at least it does in 11.00, not 11.11..)
429  */
430 #  if HPUXREV < 1111
431 #   define	MUTEX_DOWNGRADE(x)	lock_write_to_read(x)
432 #   define	KRWLOCK_T		struct rw_lock
433 #   define	READ_ENTER(x)		lock_read(&(x)->ipf_lk)
434 #   define	WRITE_ENTER(x)		lock_write(&(x)->ipf_lk)
435 #   if HPUXREV >= 1111
436 #    define	RWLOCK_INIT(x, y)	rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
437 #   else
438 #    define	RWLOCK_INIT(x, y)	lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
439 #   endif
440 #   define	RWLOCK_EXIT(x)		lock_done(&(x)->ipf_lk)
441 #  else
442 #   define	KRWLOCK_T		lock_t
443 #   define	KMUTEX_T		lock_t
444 #   define	READ_ENTER(x)		MUTEX_ENTER(x)
445 #   define	WRITE_ENTER(x)		MUTEX_ENTER(x)
446 #   define	MUTEX_DOWNGRADE(x)
447 #   define	RWLOCK_INIT(x, y)	initlock(&(x)->ipf_lk, 0, 0, y)
448 #   define	RWLOCK_EXIT(x)		MUTEX_EXIT(x)
449 #  endif
450 #  define	RW_DESTROY(x)
451 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
452 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
453 #  if HPUXREV >= 1111
454 #   define	BCOPYIN(a,b,c)	0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
455 #   define	BCOPYOUT(a,b,c)	0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
456 #  else
457 #   define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
458 #   define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
459 #  endif
460 #  define	SPL_NET(x)	;
461 #  define	SPL_IMP(x)	;
462 #  undef	SPL_X
463 #  define	SPL_X(x)	;
464 /*extern	void	*get_unit __P((char *, int, ipf_stack_t *));*/
465 #  define	GETIFP(n, v, ifs)	get_unit(n, v, ifs)
466 #  define	IFNAME(x, b)	((ill_t *)x)->ill_name
467 #  define	COPYIFNAME(x, b, v) \
468 				strncpy(b, ((ifinfo_t *)x)->ifi_name, \
469 					LIFNAMSIZ)
470 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
471 #  define	SLEEP(id, n)	{ lock_t *_l = get_sleep_lock((caddr_t)id); \
472 				  sleep(id, PZERO+1); \
473 				  spinunlock(_l); \
474 				}
475 #  define	WAKEUP(id,x)	{ lock_t *_l = get_sleep_lock((caddr_t)id); \
476 				  wakeup(id + x); \
477 				  spinunlock(_l); \
478 				}
479 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
480 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
481 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
482 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
483 #  define	MSGDSIZE(x)	msgdsize(x)
484 #  define	M_LEN(x)	((x)->b_wptr - (x)->b_rptr)
485 #  define	M_DUPLICATE(x)	dupmsg((x))
486 #  define	MTOD(m,t)	((t)((m)->b_rptr))
487 #  define	MTYPE(m)	((m)->b_datap->db_type)
488 #  define	FREE_MB_T(m)	freemsg(m)
489 #  define	m_next		b_cont
490 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
491 typedef mblk_t mb_t;
492 
493 #  define	CACHE_HASH(x)	(((phy_if_t)(x)->fin_ifp) & 7)
494 
495 #  include "qif.h"
496 #  include "pfil.h"
497 
498 # else /* _KERNEL */
499 
500 typedef	unsigned char uchar_t;
501 
502 #  ifndef	_SYS_STREAM_INCLUDED
503 typedef char * mblk_t;
504 typedef void * queue_t;
505 typedef	u_long ulong;
506 #  endif
507 #  include <netinet/ip_info.h>
508 
509 # endif /* _KERNEL */
510 
511 # ifdef lint
512 #  define ALIGN32(ptr)    (ptr ? 0L : 0L)
513 #  define ALIGN16(ptr)    (ptr ? 0L : 0L)
514 # else
515 #  define ALIGN32(ptr)    (ptr)
516 #  define ALIGN16(ptr)    (ptr)
517 # endif
518 
519 typedef	struct uio	uio_t;
520 typedef	int		ioctlcmd_t;
521 typedef	int		minor_t;
522 typedef unsigned int	u_32_t;
523 # define	U_32_T	1
524 
525 # define OS_RECOGNISED 1
526 
527 #endif /* __hpux */
528 
529 /* ----------------------------------------------------------------------- */
530 /*                                  I R I X                                */
531 /* ----------------------------------------------------------------------- */
532 #ifdef __sgi
533 # undef		MENTAT
534 # if IRIX < 60500
535 typedef	struct uio	uio_t;
536 # endif
537 typedef	int		ioctlcmd_t;
538 typedef u_int32_t       u_32_t;
539 # define	U_32_T	1
540 
541 # ifdef INET6
542 #  define USE_INET6
543 # endif
544 
545 # define  hz HZ
546 # include <sys/ksynch.h>
547 # define	IPF_LOCK_PL	plhi
548 # include <sys/sema.h>
549 # undef kmutex_t
550 typedef struct {
551 	lock_t *l;
552 	int pl;
553 } kmutex_t;
554 
555 # ifdef MUTEX_INIT
556 #  define	KMUTEX_T		mutex_t
557 # else
558 #  define	KMUTEX_T		kmutex_t
559 #  define	KRWLOCK_T		kmutex_t
560 # endif
561 
562 # ifdef _KERNEL
563 #  define	NEED_LOCAL_RAND	1
564 #  define	ipf_random		arc4random
565 #  define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); \
566 					  (x)++; MUTEX_EXIT(&ipf_rw); }
567 #  define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); \
568 					  (x)--; MUTEX_EXIT(&ipf_rw); }
569 #  define	USE_MUTEXES
570 #  ifdef MUTEX_INIT
571 #   include <sys/atomic_ops.h>
572 #   define	ATOMIC_INCL(x)		atomicAddUlong(&(x), 1)
573 #   define	ATOMIC_INC64(x)		atomicAddUint64(&(x), 1)
574 #   define	ATOMIC_INC32(x)		atomicAddUint(&(x), 1)
575 #   define	ATOMIC_INC16		ATOMIC_INC
576 #   define	ATOMIC_DECL(x)		atomicAddUlong(&(x), -1)
577 #   define	ATOMIC_DEC64(x)		atomicAddUint64(&(x), -1)
578 #   define	ATOMIC_DEC32(x)		atomicAddUint(&(x), -1)
579 #   define	ATOMIC_DEC16		ATOMIC_DEC
580 #   undef	MUTEX_INIT
581 #   define	MUTEX_INIT(x, y)	mutex_init(&(x)->ipf_lk,  \
582 						   MUTEX_DEFAULT, y)
583 #   undef	MUTEX_ENTER
584 #   define	MUTEX_ENTER(x)		mutex_lock(&(x)->ipf_lk, 0)
585 #   undef	MUTEX_EXIT
586 #   define	MUTEX_EXIT(x)		mutex_unlock(&(x)->ipf_lk)
587 #   undef	MUTEX_DESTROY
588 #   define	MUTEX_DESTROY(x)	mutex_destroy(&(x)->ipf_lk)
589 #   define	MUTEX_DOWNGRADE(x)	mrdemote(&(x)->ipf_lk)
590 #   define	KRWLOCK_T		mrlock_t
591 #   define	RWLOCK_INIT(x, y)	mrinit(&(x)->ipf_lk, y)
592 #   undef	RW_DESTROY
593 #   define	RW_DESTROY(x)		mrfree(&(x)->ipf_lk)
594 #   define	READ_ENTER(x)		RW_RDLOCK(&(x)->ipf_lk)
595 #   define	WRITE_ENTER(x)		RW_WRLOCK(&(x)->ipf_lk)
596 #   define	RWLOCK_EXIT(x)		RW_UNLOCK(&(x)->ipf_lk)
597 #  else
598 #   define	READ_ENTER(x)		MUTEX_ENTER(&(x)->ipf_lk)
599 #   define	WRITE_ENTER(x)		MUTEX_ENTER(&(x)->ipf_lk)
600 #   define	MUTEX_DOWNGRADE(x)	;
601 #   define	RWLOCK_EXIT(x)		MUTEX_EXIT(&(x)->ipf_lk)
602 #   define	MUTEX_EXIT(x)		UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
603 #   define	MUTEX_INIT(x,y)		(x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
604 #   define	MUTEX_DESTROY(x)	LOCK_DEALLOC((x)->ipf_lk.l)
605 #   define	MUTEX_ENTER(x)		(x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
606 							      IPF_LOCK_PL);
607 #  endif
608 #  define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
609 #  define	FREE_MB_T(m)	m_freem(m)
610 #  define	MTOD(m,t)	mtod(m,t)
611 #  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
612 #  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
613 #  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
614 #  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
615 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
616 #  define	SLEEP(id, n)	sleep((id), PZERO+1)
617 #  define	WAKEUP(id,x)	wakeup(id+x)
618 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
619 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
620 #  define	GETIFP(n,v, ifs)	ifunit(n)
621 #  include <sys/kmem.h>
622 #  include <sys/ddi.h>
623 #  define	KMALLOC(a,b)	(a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
624 #  define	KMALLOCS(a,b,c)	(a) = (b)kmem_alloc((c), KM_NOSLEEP)
625 #  define	GET_MINOR(x)	getminor(x)
626 #  define	USE_SPL		1
627 #  define	SPL_IMP(x)	(x) = splimp()
628 #  define	SPL_NET(x)	(x) = splnet()
629 #  define	SPL_X(x)	(void) splx(x)
630 extern	void	m_copydata __P((struct mbuf *, int, int, caddr_t));
631 extern	void	m_copyback __P((struct mbuf *, int, int, caddr_t));
632 #  define	MSGDSIZE(x)	mbufchainlen(x)
633 #  define	M_LEN(x)	(x)->m_len
634 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
635 #  define	GETKTIME(x)	microtime((struct timeval *)x)
636 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
637 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
638 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
639 typedef struct mbuf mb_t;
640 # else
641 #  undef RW_DESTROY
642 #  undef MUTEX_INIT
643 #  undef MUTEX_DESTROY
644 # endif /* _KERNEL */
645 
646 # define OS_RECOGNISED 1
647 
648 #endif /* __sgi */
649 
650 /* ----------------------------------------------------------------------- */
651 /*                                  T R U 6 4                              */
652 /* ----------------------------------------------------------------------- */
653 #ifdef __osf__
654 # undef		MENTAT
655 
656 # include <kern/lock.h>
657 # include <sys/sysmacros.h>
658 
659 # ifdef _KERNEL
660 #  define	NEED_LOCAL_RAND		1
661 #  define	ipf_random		arc4random
662 #  define	KMUTEX_T		simple_lock_data_t
663 #  define	KRWLOCK_T		lock_data_t
664 #  include <net/net_globals.h>
665 #  define	USE_MUTEXES
666 #  define	READ_ENTER(x)		lock_read(&(x)->ipf_lk)
667 #  define	WRITE_ENTER(x)		lock_write(&(x)->ipf_lk)
668 #  define	MUTEX_DOWNGRADE(x)	lock_write_to_read(&(x)->ipf_lk)
669 #  define	RWLOCK_INIT(x, y)	lock_init(&(x)->ipf_lk, TRUE)
670 #  define	RWLOCK_EXIT(x)		lock_done(&(x)->ipf_lk)
671 #  define	RW_DESTROY(x)		lock_terminate(&(x)->ipf_lk)
672 #  define	MUTEX_ENTER(x)		simple_lock(&(x)->ipf_lk)
673 #  define	MUTEX_INIT(x, y)	simple_lock_init(&(x)->ipf_lk)
674 #  define	MUTEX_DESTROY(x)	simple_lock_terminate(&(x)->ipf_lk)
675 #  define	MUTEX_EXIT(x)		simple_unlock(&(x)->ipf_lk)
676 #  define	MUTEX_NUKE(x)		bzero(x, sizeof(*(x)))
677 #  define	ATOMIC_INC64(x)		atomic_incq((uint64_t*)&(x))
678 #  define	ATOMIC_DEC64(x)		atomic_decq((uint64_t*)&(x))
679 #  define	ATOMIC_INC32(x)		atomic_incl((uint32_t*)&(x))
680 #  define	ATOMIC_DEC32(x)		atomic_decl((uint32_t*)&(x))
681 #  define	ATOMIC_INC16(x)		{ simple_lock(&ipf_rw); (x)++; \
682 					  simple_unlock(&ipf_rw); }
683 #  define	ATOMIC_DEC16(x)		{ simple_lock(&ipf_rw); (x)--; \
684 					  simple_unlock(&ipf_rw); }
685 #  define	ATOMIC_INCL(x)		atomic_incl((uint32_t*)&(x))
686 #  define	ATOMIC_DECL(x)		atomic_decl((uint32_t*)&(x))
687 #  define	ATOMIC_INC(x)		{ simple_lock(&ipf_rw); (x)++; \
688 					  simple_unlock(&ipf_rw); }
689 #  define	ATOMIC_DEC(x)		{ simple_lock(&ipf_rw); (x)--; \
690 					  simple_unlock(&ipf_rw); }
691 #  define	SPL_NET(x)		;
692 #  define	SPL_IMP(x)		;
693 #  undef	SPL_X
694 #  define	SPL_X(x)		;
695 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a, b, d)
696 #  define	FREE_MB_T(m)		m_freem(m)
697 #  define	MTOD(m,t)		mtod(m,t)
698 #  define	GETIFP(n, v, ifs)	ifunit(n)
699 #  define	GET_MINOR		getminor
700 #  define	WAKEUP(id,x)		wakeup(id + x)
701 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
702 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
703 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
704 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
705 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
706 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_PFILT, \
707 					    ((c) > 4096) ? M_WAITOK : M_NOWAIT)
708 #  define	KFREE(x)	FREE((x), M_PFILT)
709 #  define	KFREES(x,s)	FREE((x), M_PFILT)
710 #  define	MSGDSIZE(x)	mbufchainlen(x)
711 #  define	M_LEN(x)	(x)->m_len
712 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
713 #  define	GETKTIME(x)	microtime((struct timeval *)x)
714 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
715 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
716 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
717 typedef struct mbuf mb_t;
718 # endif /* _KERNEL */
719 
720 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
721 #  define	IP_V(x)		((x)->ip_vhl >> 4)
722 #  define	IP_HL(x)	((x)->ip_vhl & 0xf)
723 #  define	IP_V_A(x,y)	(x)->ip_vhl |= (((y) << 4) & 0xf0)
724 #  define	IP_HL_A(x,y)	(x)->ip_vhl |= ((y) & 0xf)
725 #  define	TCP_X2(x)	((x)->th_xoff & 0xf)
726 #  define	TCP_X2_A(x,y)	(x)->th_xoff |= ((y) & 0xf)
727 #  define	TCP_OFF(x)	((x)->th_xoff >> 4)
728 #  define	TCP_OFF_A(x,y)	(x)->th_xoff |= (((y) << 4) & 0xf0)
729 # endif
730 
731 /*
732  * These are from's Solaris' #defines for little endian.
733  */
734 #define	IP6F_MORE_FRAG		0x0100
735 #define	IP6F_RESERVED_MASK	0x0600
736 #define	IP6F_OFF_MASK		0xf8ff
737 
738 struct ip6_ext {
739 	u_char	ip6e_nxt;
740 	u_char	ip6e_len;
741 };
742 
743 typedef	int		ioctlcmd_t;
744 /*
745  * Really, any arch where sizeof(long) != sizeof(int).
746  */
747 typedef unsigned int    u_32_t;
748 # define	U_32_T	1
749 
750 # define OS_RECOGNISED 1
751 #endif /* __osf__ */
752 
753 /* ----------------------------------------------------------------------- */
754 /*                                  N E T B S D                            */
755 /* ----------------------------------------------------------------------- */
756 #ifdef __NetBSD__
757 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
758 #  include "bpfilter.h"
759 #  if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
760 #   include "opt_inet.h"
761 #  endif
762 #  ifdef INET6
763 #   define USE_INET6
764 #  endif
765 #  if (__NetBSD_Version__ >= 105000000)
766 #   define HAVE_M_PULLDOWN 1
767 #  endif
768 # endif
769 
770 # ifdef _KERNEL
771 #  define	MSGDSIZE(x)	mbufchainlen(x)
772 #  define	M_LEN(x)	(x)->m_len
773 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
774 #  define	GETKTIME(x)	microtime((struct timeval *)x)
775 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
776 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
777 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
778 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
779 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
780 typedef struct mbuf mb_t;
781 # endif /* _KERNEL */
782 # if (NetBSD <= 1991011) && (NetBSD >= 199606)
783 #  define	IFNAME(x)	((struct ifnet *)x)->if_xname
784 #  define	COPYIFNAME(x, b, v) \
785 				(void) strncpy(b, \
786 					       ((struct ifnet *)x)->if_xname, \
787 					       LIFNAMSIZ)
788 #  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index)&7)
789 # else
790 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
791 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
792 # endif
793 
794 typedef	struct uio	uio_t;
795 typedef	u_long		ioctlcmd_t;
796 typedef	int		minor_t;
797 typedef	u_int32_t	u_32_t;
798 # define	U_32_T	1
799 
800 # define OS_RECOGNISED 1
801 #endif /* __NetBSD__ */
802 
803 
804 /* ----------------------------------------------------------------------- */
805 /*                                F R E E B S D                            */
806 /* ----------------------------------------------------------------------- */
807 #ifdef __FreeBSD__
808 # if defined(_KERNEL)
809 #  if (__FreeBSD_version >= 500000)
810 #   include "opt_bpf.h"
811 #  else
812 #   include "bpf.h"
813 #  endif
814 #  if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)
815 #   include "opt_inet6.h"
816 #  endif
817 #  if defined(INET6) && !defined(USE_INET6)
818 #   define USE_INET6
819 #  endif
820 # endif
821 
822 # if defined(_KERNEL)
823 #  if (__FreeBSD_version >= 400000)
824 /*
825  * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
826  * There may be other, safe, kernels but this is not extensively tested yet.
827  */
828 #   define HAVE_M_PULLDOWN
829 #  endif
830 #  if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
831 #   include "opt_ipfilter.h"
832 #  endif
833 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
834 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
835 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
836 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
837 
838 #  if (__FreeBSD_version >= 500043)
839 #   define NETBSD_PF
840 #  endif
841 # endif /* _KERNEL */
842 
843 # if (__FreeBSD_version >= 500043)
844 #  include <sys/mutex.h>
845 #  include <sys/sx.h>
846 /*
847  * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
848  * for what we want to use them for, despite testing showing they work -
849  * with a WITNESS kernel, it generates LOR messages.
850  */
851 #  define	KMUTEX_T		struct mtx
852 #  if 1
853 #   define	KRWLOCK_T		struct mtx
854 #  else
855 #   define	KRWLOCK_T		struct sx
856 #  endif
857 # endif
858 
859 # if (__FreeBSD_version >= 501113)
860 #  include <net/if_var.h>
861 #  define	IFNAME(x)	((struct ifnet *)x)->if_xname
862 #  define	COPYIFNAME(x, b) \
863 				(void) strncpy(b, \
864 					       ((struct ifnet *)x)->if_xname, \
865 					       LIFNAMSIZ)
866 # endif
867 # if (__FreeBSD_version >= 500043)
868 #  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index) & 7)
869 # else
870 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
871 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
872 # endif
873 
874 # ifdef _KERNEL
875 #  define	GETKTIME(x)	microtime((struct timeval *)x)
876 
877 #  if (__FreeBSD_version >= 500002)
878 #   include <netinet/in_systm.h>
879 #   include <netinet/ip.h>
880 #   include <machine/in_cksum.h>
881 #  endif
882 
883 #  if (__FreeBSD_version >= 500043)
884 #   define	USE_MUTEXES
885 #   define	MUTEX_ENTER(x)		mtx_lock(&(x)->ipf_lk)
886 #   define	MUTEX_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
887 #   define	MUTEX_INIT(x,y)		mtx_init(&(x)->ipf_lk, (y), NULL,\
888 						 MTX_DEF)
889 #   define	MUTEX_DESTROY(x)	mtx_destroy(&(x)->ipf_lk)
890 #   define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
891 /*
892  * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
893  * for what we want to use them for, despite testing showing they work -
894  * with a WITNESS kernel, it generates LOR messages.
895  */
896 #   if 1
897 #    define	READ_ENTER(x)		mtx_lock(&(x)->ipf_lk)
898 #    define	WRITE_ENTER(x)		mtx_lock(&(x)->ipf_lk)
899 #    define	RWLOCK_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
900 #    define	MUTEX_DOWNGRADE(x)	;
901 #    define	RWLOCK_INIT(x,y)	mtx_init(&(x)->ipf_lk, (y), NULL,\
902 						 MTX_DEF)
903 #    define	RW_DESTROY(x)		mtx_destroy(&(x)->ipf_lk)
904 #   else
905 #    define	READ_ENTER(x)		sx_slock(&(x)->ipf_lk)
906 #    define	WRITE_ENTER(x)		sx_xlock(&(x)->ipf_lk)
907 #    define	MUTEX_DOWNGRADE(x)	sx_downgrade(&(x)->ipf_lk)
908 #    define	RWLOCK_INIT(x, y)	sx_init(&(x)->ipf_lk, (y))
909 #    define	RW_DESTROY(x)		sx_destroy(&(x)->ipf_lk)
910 #    ifdef sx_unlock
911 #     define	RWLOCK_EXIT(x)		sx_unlock(x)
912 #    else
913 #     define	RWLOCK_EXIT(x)		do { \
914 					    if ((x)->ipf_lk.sx_cnt < 0) \
915 						sx_xunlock(&(x)->ipf_lk); \
916 					    else \
917 						sx_sunlock(&(x)->ipf_lk); \
918 					} while (0)
919 #    endif
920 #   endif
921 #   include <machine/atomic.h>
922 #   define	ATOMIC_INC(x)		{ mtx_lock(&ipf_rw.ipf_lk); (x)++; \
923 					  mtx_unlock(&ipf_rw.ipf_lk); }
924 #   define	ATOMIC_DEC(x)		{ mtx_lock(&ipf_rw.ipf_lk); (x)--; \
925 					  mtx_unlock(&ipf_rw.ipf_lk); }
926 #   define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
927 #   define	ATOMIC_INC64(x)		ATOMIC_INC(x)
928 #   define	ATOMIC_INC32(x)		atomic_add_32(&(x), 1)
929 #   define	ATOMIC_INC16(x)		atomic_add_16(&(x), 1)
930 #   define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
931 #   define	ATOMIC_DEC64(x)		ATOMIC_DEC(x)
932 #   define	ATOMIC_DEC32(x)		atomic_add_32(&(x), -1)
933 #   define	ATOMIC_DEC16(x)		atomic_add_16(&(x), -1)
934 #   define	SPL_X(x)	;
935 #   define	SPL_NET(x)	;
936 #   define	SPL_IMP(x)	;
937 extern	int	in_cksum __P((struct mbuf *, int));
938 #  endif /* __FreeBSD_version >= 500043 */
939 #  define	MSGDSIZE(x)	mbufchainlen(x)
940 #  define	M_LEN(x)	(x)->m_len
941 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
942 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
943 typedef struct mbuf mb_t;
944 # endif /* _KERNEL */
945 
946 # if __FreeBSD__ < 3
947 #  include <machine/spl.h>
948 # else
949 #  if __FreeBSD__ == 3
950 #   if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
951 #    define	ACTUALLY_LKM_NOT_KERNEL
952 #   endif
953 #  endif
954 # endif
955 
956 # if (__FreeBSD_version >= 300000)
957 typedef	u_long		ioctlcmd_t;
958 # else
959 typedef	int		ioctlcmd_t;
960 # endif
961 typedef	struct uio	uio_t;
962 typedef	int		minor_t;
963 typedef	u_int32_t	u_32_t;
964 # define	U_32_T	1
965 
966 # define OS_RECOGNISED 1
967 #endif /* __FreeBSD__ */
968 
969 
970 /* ----------------------------------------------------------------------- */
971 /*                                O P E N B S D                            */
972 /* ----------------------------------------------------------------------- */
973 #ifdef __OpenBSD__
974 # ifdef INET6
975 #  define USE_INET6
976 # endif
977 
978 # ifdef _KERNEL
979 #  if !defined(IPFILTER_LKM)
980 #   include "bpfilter.h"
981 #  endif
982 #  if (OpenBSD >= 200311)
983 #   define SNPRINTF	snprintf
984 #   if defined(USE_INET6)
985 #    include "netinet6/in6_var.h"
986 #    include "netinet6/nd6.h"
987 #   endif
988 #  endif
989 #  if (OpenBSD >= 200012)
990 #   define HAVE_M_PULLDOWN 1
991 #  endif
992 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
993 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
994 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
995 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
996 #  define	GETKTIME(x)	microtime((struct timeval *)x)
997 #  define	MSGDSIZE(x)	mbufchainlen(x)
998 #  define	M_LEN(x)	(x)->m_len
999 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1000 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
1001 typedef struct mbuf mb_t;
1002 # endif /* _KERNEL */
1003 # if (OpenBSD >= 199603)
1004 #  define	IFNAME(x, b)	((struct ifnet *)x)->if_xname
1005 #  define	COPYIFNAME(x, b, v) \
1006 				(void) strncpy(b, \
1007 					       ((struct ifnet *)x)->if_xname, \
1008 					       LIFNAMSIZ)
1009 #  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index)&7)
1010 # else
1011 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1012 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1013 # endif
1014 
1015 typedef	struct uio	uio_t;
1016 typedef	u_long		ioctlcmd_t;
1017 typedef	int		minor_t;
1018 typedef	u_int32_t	u_32_t;
1019 # define	U_32_T	1
1020 
1021 # define OS_RECOGNISED 1
1022 #endif /* __OpenBSD__ */
1023 
1024 
1025 /* ----------------------------------------------------------------------- */
1026 /*                                B S D O S                                */
1027 /* ----------------------------------------------------------------------- */
1028 #ifdef _BSDI_VERSION
1029 # ifdef INET6
1030 #  define USE_INET6
1031 # endif
1032 
1033 # ifdef _KERNEL
1034 #  define	GETKTIME(x)	microtime((struct timeval *)x)
1035 #  define	MSGDSIZE(x)	mbufchainlen(x)
1036 #  define	M_LEN(x)	(x)->m_len
1037 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1038 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1039 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1040 typedef struct mbuf mb_t;
1041 # endif /* _KERNEL */
1042 
1043 # if (_BSDI_VERSION >= 199701)
1044 typedef	u_long		ioctlcmd_t;
1045 # else
1046 typedef	int		ioctlcmd_t;
1047 # endif
1048 typedef	u_int32_t	u_32_t;
1049 # define	U_32_T	1
1050 
1051 #endif /* _BSDI_VERSION */
1052 
1053 
1054 /* ----------------------------------------------------------------------- */
1055 /*                                  S U N O S 4                            */
1056 /* ----------------------------------------------------------------------- */
1057 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1058 # ifdef _KERNEL
1059 #  include	<sys/kmem_alloc.h>
1060 #  define	GETKTIME(x)	uniqtime((struct timeval *)x)
1061 #  define	MSGDSIZE(x)	mbufchainlen(x)
1062 #  define	M_LEN(x)	(x)->m_len
1063 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1064 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1065 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1066 #  define	GETIFP(n, v, ifs)	ifunit(n, IFNAMSIZ)
1067 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
1068 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
1069 #  define	SLEEP(id, n)	sleep((id), PZERO+1)
1070 #  define	WAKEUP(id,x)	wakeup(id + x)
1071 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
1072 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
1073 
1074 extern	void	m_copydata __P((struct mbuf *, int, int, caddr_t));
1075 extern	void	m_copyback __P((struct mbuf *, int, int, caddr_t));
1076 
1077 typedef struct mbuf mb_t;
1078 # endif
1079 
1080 typedef	struct uio	uio_t;
1081 typedef	int		ioctlcmd_t;
1082 typedef	int		minor_t;
1083 typedef	unsigned int	u_32_t;
1084 # define	U_32_T	1
1085 
1086 # define OS_RECOGNISED 1
1087 
1088 #endif /* SunOS 4 */
1089 
1090 /* ----------------------------------------------------------------------- */
1091 /*                            L I N U X                                    */
1092 /* ----------------------------------------------------------------------- */
1093 #if defined(linux) && !defined(OS_RECOGNISED)
1094 #include <linux/config.h>
1095 #include <linux/version.h>
1096 # if LINUX >= 20600
1097 #  define	 HDR_T_PRIVATE	1
1098 # endif
1099 # undef USE_INET6
1100 # ifdef USE_INET6
1101 struct ip6_ext {
1102 	u_char	ip6e_nxt;
1103 	u_char	ip6e_len;
1104 };
1105 # endif
1106 
1107 # ifdef _KERNEL
1108 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
1109 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1110 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1111 #  define	COPYIN(a,b,c)	copy_from_user((caddr_t)(b), (caddr_t)(a), (c))
1112 #  define	COPYOUT(a,b,c)	copy_to_user((caddr_t)(b), (caddr_t)(a), (c))
1113 #  define	FREE_MB_T(m)	kfree_skb(m)
1114 #  define	GETKTIME(x)	do_gettimeofday((struct timeval *)x)
1115 #  define	SLEEP(x,s)	0, interruptible_sleep_on(x##_linux)
1116 #  define	WAKEUP(x,y)	wake_up(x##_linux + y)
1117 #  define	UIOMOVE(a,b,c,d)	uiomove(a,b,c,d)
1118 #  define	USE_MUTEXES
1119 #  define	KRWLOCK_T		rwlock_t
1120 #  define	KMUTEX_T		spinlock_t
1121 #  define	MUTEX_INIT(x,y)		spin_lock_init(&(x)->ipf_lk)
1122 #  define	MUTEX_ENTER(x)		spin_lock(&(x)->ipf_lk)
1123 #  define	MUTEX_EXIT(x)		spin_unlock(&(x)->ipf_lk)
1124 #  define	MUTEX_DESTROY(x)	do { } while (0)
1125 #  define	MUTEX_NUKE(x)		bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1126 #  define	READ_ENTER(x)		ipf_read_enter(x)
1127 #  define	WRITE_ENTER(x)		ipf_write_enter(x)
1128 #  define	RWLOCK_INIT(x,y)	rwlock_init(&(x)->ipf_lk)
1129 #  define	RW_DESTROY(x)		do { } while (0)
1130 #  define	RWLOCK_EXIT(x)		ipf_rw_exit(x)
1131 #  define	MUTEX_DOWNGRADE(x)	ipf_rw_downgrade(x)
1132 #  define	ATOMIC_INCL(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1133 					MUTEX_EXIT(&ipf_rw)
1134 #  define	ATOMIC_DECL(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1135 					MUTEX_EXIT(&ipf_rw)
1136 #  define	ATOMIC_INC64(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1137 					MUTEX_EXIT(&ipf_rw)
1138 #  define	ATOMIC_INC32(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1139 					MUTEX_EXIT(&ipf_rw)
1140 #  define	ATOMIC_INC16(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1141 					MUTEX_EXIT(&ipf_rw)
1142 #  define	ATOMIC_DEC64(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1143 					MUTEX_EXIT(&ipf_rw)
1144 #  define	ATOMIC_DEC32(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1145 					MUTEX_EXIT(&ipf_rw)
1146 #  define	ATOMIC_DEC16(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1147 					MUTEX_EXIT(&ipf_rw)
1148 #  define	SPL_IMP(x)		do { } while (0)
1149 #  define	SPL_NET(x)		do { } while (0)
1150 #  define	SPL_X(x)		do { } while (0)
1151 #  define	IFNAME(x)		((struct net_device*)x)->name
1152 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1153 			  ((struct net_device *)fin->fin_ifp)->ifindex) & 7)
1154 typedef	struct	sk_buff	mb_t;
1155 extern	void	m_copydata __P((mb_t *, int, int, caddr_t));
1156 extern	void	m_copyback __P((mb_t *, int, int, caddr_t));
1157 extern	void	m_adj __P((mb_t *, int));
1158 extern	mb_t	*m_pullup __P((mb_t *, int));
1159 #  define	mbuf	sk_buff
1160 
1161 #  define	mtod(m, t)	((t)(m)->data)
1162 #  define	m_len		len
1163 #  define	m_next		next
1164 #  define	M_DUPLICATE(m)	skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1165 								GFP_KERNEL)
1166 #  define	MSGDSIZE(m)	(m)->len
1167 #  define	M_LEN(m)	(m)->len
1168 
1169 #  define	splnet(x)	;
1170 #  define	printf		printk
1171 #  define	bcopy(s,d,z)	memmove(d, s, z)
1172 #  define	bzero(s,z)	memset(s, 0, z)
1173 #  define	bcmp(a,b,z)	memcmp(a, b, z)
1174 
1175 #  define	ifnet		net_device
1176 #  define	if_xname	name
1177 #  define	if_unit		ifindex
1178 
1179 #  define	KMALLOC(x,t)	(x) = (t)kmalloc(sizeof(*(x)), \
1180 				    in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1181 #  define	KFREE(x)	kfree(x)
1182 #  define	KMALLOCS(x,t,s)	(x) = (t)kmalloc((s), \
1183 				    in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1184 #  define	KFREES(x,s)	kfree(x)
1185 
1186 #  define GETIFP(n,v)	dev_get_by_name(n)
1187 
1188 # else
1189 #  include <net/ethernet.h>
1190 
1191 struct mbuf {
1192 };
1193 
1194 #  ifndef _NET_ROUTE_H
1195 struct rtentry {
1196 };
1197 #  endif
1198 
1199 struct ifnet {
1200 	char	if_xname[IFNAMSIZ];
1201 	int	if_unit;
1202 	int	(* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1203 	struct	ifaddr	*if_addrlist;
1204 };
1205 # define	IFNAME(x)	((struct ifnet *)x)->if_xname
1206 
1207 # endif	/* _KERNEL */
1208 
1209 # define	COPYIFNAME(x, b) \
1210 				(void) strncpy(b, \
1211 					       ((struct ifnet *)x)->if_xname, \
1212 					       LIFNAMSIZ)
1213 
1214 # include <linux/fs.h>
1215 # define	FWRITE	FMODE_WRITE
1216 # define	FREAD	FMODE_READ
1217 
1218 # define	__USE_MISC	1
1219 # define	__FAVOR_BSD	1
1220 
1221 typedef	struct uio {
1222 	struct iovec	*uio_iov;
1223 	void	*uio_file;
1224 	char	*uio_buf;
1225 	int	uio_iovcnt;
1226 	int	uio_offset;
1227 	size_t	uio_resid;
1228 	int	uio_rw;
1229 } uio_t;
1230 
1231 extern	int	uiomove __P((caddr_t, size_t, int, struct uio *));
1232 
1233 # define	UIO_READ	1
1234 # define	UIO_WRITE	2
1235 
1236 typedef	u_long		ioctlcmd_t;
1237 typedef	int		minor_t;
1238 typedef u_int32_t 	u_32_t;
1239 # define	U_32_T	1
1240 
1241 # define OS_RECOGNISED 1
1242 
1243 #endif
1244 
1245 
1246 /* ----------------------------------------------------------------------- */
1247 /*                                    A I X                                */
1248 /* ----------------------------------------------------------------------- */
1249 #if defined(_AIX51)
1250 # undef		MENTAT
1251 
1252 # include <sys/lock.h>
1253 # include <sys/sysmacros.h>
1254 
1255 # ifdef _KERNEL
1256 #  define rw_read_locked(x)		0
1257 #  include <net/net_globals.h>
1258 #  include <net/net_malloc.h>
1259 #  define	KMUTEX_T		simple_lock_t
1260 #  define	KRWLOCK_T		complex_lock_t
1261 #  define	USE_MUTEXES		1
1262 #  define	USE_SPL			1
1263 #  define	READ_ENTER(x)		lock_read((x)->ipf_lk)
1264 #  define	WRITE_ENTER(x)		lock_write((x)->ipf_lk)
1265 #  define	MUTEX_DOWNGRADE(x)	lock_write_to_read((x)->ipf_lk)
1266 #  define	RWLOCK_INIT(x, y)	lock_alloc(&(x)->ipf_lk, \
1267 						   LOCK_ALLOC_PIN, \
1268 						   (u_short)y, 0); \
1269 					lock_init((x)->ipf_lk, TRUE)
1270 #  define	RWLOCK_EXIT(x)		lock_done((x)->ipf_lk)
1271 #  define	RW_DESTROY(x)		lock_free(&(x)->ipf_lk)
1272 #  define	MUTEX_ENTER(x)		simple_lock((x)->ipf_lk)
1273 #  define	MUTEX_INIT(x, y)	lock_alloc(&(x)->ipf_lk, \
1274 						   LOCK_ALLOC_PIN, \
1275 						   (u_short)y, 0); \
1276 					simple_lock_init((x)->ipf_lk)
1277 #  define	MUTEX_DESTROY(x)	lock_free(&(x)->ipf_lk)
1278 #  define	MUTEX_EXIT(x)		simple_unlock((x)->ipf_lk)
1279 #  define	MUTEX_NUKE(x)		bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1280 #   define	ATOMIC_INC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1281 					  MUTEX_EXIT(&ipf_rw); }
1282 #   define	ATOMIC_DEC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1283 					  MUTEX_EXIT(&ipf_rw); }
1284 #   define	ATOMIC_INC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1285 					  MUTEX_EXIT(&ipf_rw); }
1286 #   define	ATOMIC_DEC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1287 					  MUTEX_EXIT(&ipf_rw); }
1288 #   define	ATOMIC_INCL(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1289 					  MUTEX_EXIT(&ipf_rw); }
1290 #   define	ATOMIC_DECL(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1291 					  MUTEX_EXIT(&ipf_rw); }
1292 #   define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1293 					  MUTEX_EXIT(&ipf_rw); }
1294 #   define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1295 					  MUTEX_EXIT(&ipf_rw); }
1296 #  define	SPL_NET(x)		x = splnet()
1297 #  define	SPL_IMP(x)		x = splimp()
1298 #  undef	SPL_X
1299 #  define	SPL_X(x)		splx(x)
1300 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
1301 extern void* getifp __P((char *, int));
1302 #  define	GETIFP(n, v)		getifp(n, v)
1303 #  define	GET_MINOR		minor
1304 #  define	SLEEP(id, n)	sleepx((id), PZERO+1, 0)
1305 #  define	WAKEUP(id,x)	wakeup(id)
1306 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
1307 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
1308 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1309 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1310 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1311 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_TEMP, \
1312 					    ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1313 #  define	KFREE(x)	FREE((x), M_TEMP)
1314 #  define	KFREES(x,s)	FREE((x), M_TEMP)
1315 #  define	MSGDSIZE(x)	mbufchainlen(x)
1316 #  define	M_LEN(x)	(x)->m_len
1317 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1318 #  define	GETKTIME(x)
1319 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1320 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1321 #  define	IPF_PANIC(x,y)
1322 typedef struct mbuf mb_t;
1323 # endif /* _KERNEL */
1324 
1325 /*
1326  * These are from's Solaris' #defines for little endian.
1327  */
1328 #if !defined(IP6F_MORE_FRAG)
1329 # define	IP6F_MORE_FRAG		0x0100
1330 #endif
1331 #if !defined(IP6F_RESERVED_MASK)
1332 # define	IP6F_RESERVED_MASK	0x0600
1333 #endif
1334 #if !defined(IP6F_OFF_MASK)
1335 # define	IP6F_OFF_MASK		0xf8ff
1336 #endif
1337 
1338 struct ip6_ext {
1339 	u_char	ip6e_nxt;
1340 	u_char	ip6e_len;
1341 };
1342 
1343 typedef	int		ioctlcmd_t;
1344 typedef	int		minor_t;
1345 /*
1346  * Really, any arch where sizeof(long) != sizeof(int).
1347  */
1348 typedef unsigned int    u_32_t;
1349 # define	U_32_T	1
1350 
1351 # define OS_RECOGNISED 1
1352 #endif	/* _AIX51 */
1353 
1354 
1355 #ifndef	OS_RECOGNISED
1356 #error	ip_compat.h does not recognise this platform/OS.
1357 #endif
1358 
1359 
1360 /* ----------------------------------------------------------------------- */
1361 /*                           G E N E R I C                                 */
1362 /* ----------------------------------------------------------------------- */
1363 #ifndef OS_RECOGNISED
1364 #endif
1365 
1366 /*
1367  * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1368  * filter rules.
1369  */
1370 #if !defined(IPFILTER_BPF) && ((NBPF > 0) || (NBPFILTER > 0) || (DEV_BPF > 0))
1371 # define IPFILTER_BPF
1372 #endif
1373 
1374 /*
1375  * Userland locking primitives
1376  */
1377 typedef	struct	{
1378 	char	*eMm_owner;
1379 	char	*eMm_heldin;
1380 	u_int	eMm_magic;
1381 	int	eMm_held;
1382 	int	eMm_heldat;
1383 #ifdef __hpux
1384 	char	eMm_fill[8];
1385 #endif
1386 } eMmutex_t;
1387 
1388 typedef	struct	{
1389 	char	*eMrw_owner;
1390 	char	*eMrw_heldin;
1391 	u_int	eMrw_magic;
1392 	short	eMrw_read;
1393 	short	eMrw_write;
1394 	int	eMrw_heldat;
1395 #ifdef __hpux
1396 	char	eMm_fill[24];
1397 #endif
1398 } eMrwlock_t;
1399 
1400 typedef union {
1401 #ifdef KMUTEX_T
1402 	struct	{
1403 		KMUTEX_T	ipf_slk;
1404 		char		*ipf_lname;
1405 	} ipf_lkun_s;
1406 #endif
1407 	eMmutex_t	ipf_emu;
1408 } ipfmutex_t;
1409 
1410 typedef union {
1411 #ifdef KRWLOCK_T
1412 	struct	{
1413 		KRWLOCK_T	ipf_slk;
1414 		char		*ipf_lname;
1415 		int		ipf_sr;
1416 		int		ipf_sw;
1417 		u_int		ipf_magic;
1418 	} ipf_lkun_s;
1419 #endif
1420 	eMrwlock_t	ipf_emu;
1421 } ipfrwlock_t;
1422 
1423 #define	ipf_lk		ipf_lkun_s.ipf_slk
1424 #define	ipf_lname	ipf_lkun_s.ipf_lname
1425 #define	ipf_isr		ipf_lkun_s.ipf_sr
1426 #define	ipf_isw		ipf_lkun_s.ipf_sw
1427 #define	ipf_magic	ipf_lkun_s.ipf_magic
1428 
1429 #if !defined(__GNUC__) || \
1430     (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1431 # ifndef	INLINE
1432 #  define	INLINE
1433 # endif
1434 #else
1435 # define	INLINE	__inline__
1436 #endif
1437 
1438 #if defined(linux) && defined(_KERNEL)
1439 extern	INLINE	void	ipf_read_enter __P((ipfrwlock_t *));
1440 extern	INLINE	void	ipf_write_enter __P((ipfrwlock_t *));
1441 extern	INLINE	void	ipf_rw_exit __P((ipfrwlock_t *));
1442 extern	INLINE	void	ipf_rw_downgrade __P((ipfrwlock_t *));
1443 #endif
1444 
1445 /*
1446  * In a non-kernel environment, there are a lot of macros that need to be
1447  * filled in to be null-ops or to point to some compatibility function,
1448  * somewhere in userland.
1449  */
1450 #ifndef _KERNEL
1451 typedef	struct	mb_s	{
1452 	struct	mb_s	*mb_next;
1453 	int		mb_len;
1454 	u_long		mb_buf[2048];
1455 } mb_t;
1456 # undef		m_next
1457 # define	m_next		mb_next
1458 # define	MSGDSIZE(x)	(x)->mb_len	/* XXX - from ipt.c */
1459 # define	M_LEN(x)	(x)->mb_len
1460 # define	M_DUPLICATE(x)	(x)
1461 # define	GETKTIME(x)	gettimeofday((struct timeval *)(x), NULL)
1462 # undef		MTOD
1463 # define	MTOD(m, t)	((t)(m)->mb_buf)
1464 # define	FREE_MB_T(x)
1465 # define	SLEEP(x,y)	1;
1466 # define	WAKEUP(x,y)	;
1467 # define	IPF_PANIC(x,y)	;
1468 # define	PANIC(x,y)	;
1469 # define	SPL_NET(x)	;
1470 # define	SPL_IMP(x)	;
1471 # define	SPL_X(x)	;
1472 # define	KMALLOC(a,b)	(a) = (b)malloc(sizeof(*a))
1473 # define	KMALLOCS(a,b,c)	(a) = (b)malloc(c)
1474 # define	KFREE(x)	free(x)
1475 # define	KFREES(x,s)	free(x)
1476 # define	GETIFP(x, v, ifs)	get_unit(x,v, ifs)
1477 # define	COPYIN(a,b,c)	(bcopy((a), (b), (c)), 0)
1478 # define	COPYOUT(a,b,c)	(bcopy((a), (b), (c)), 0)
1479 # define	BCOPYIN(a,b,c)	(bcopy((a), (b), (c)), 0)
1480 # define	BCOPYOUT(a,b,c)	(bcopy((a), (b), (c)), 0)
1481 # define	COPYDATA(m, o, l, b)	bcopy(MTOD((mb_t *)m, char *) + (o), \
1482 					      (b), (l))
1483 # define	COPYBACK(m, o, l, b)	bcopy((b), \
1484 					      MTOD((mb_t *)m, char *) + (o), \
1485 					      (l))
1486 # define	UIOMOVE(a,b,c,d)	ipfuiomove(a,b,c,d)
1487 extern	void	m_copydata __P((mb_t *, int, int, caddr_t));
1488 extern	int	ipfuiomove __P((caddr_t, int, int, struct uio *));
1489 # ifndef CACHE_HASH
1490 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1491 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1492 # endif
1493 
1494 # define	MUTEX_DESTROY(x)	eMmutex_destroy(&(x)->ipf_emu)
1495 # define	MUTEX_ENTER(x)		eMmutex_enter(&(x)->ipf_emu, \
1496 						      __FILE__, __LINE__)
1497 # define	MUTEX_EXIT(x)		eMmutex_exit(&(x)->ipf_emu)
1498 # define	MUTEX_INIT(x,y)		eMmutex_init(&(x)->ipf_emu, y)
1499 # define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
1500 
1501 # define	MUTEX_DOWNGRADE(x)	eMrwlock_downgrade(&(x)->ipf_emu, \
1502 							   __FILE__, __LINE__)
1503 # define	READ_ENTER(x)		eMrwlock_read_enter(&(x)->ipf_emu, \
1504 							    __FILE__, __LINE__)
1505 # define	RWLOCK_INIT(x, y)	eMrwlock_init(&(x)->ipf_emu, y)
1506 # define	RWLOCK_EXIT(x)		eMrwlock_exit(&(x)->ipf_emu)
1507 # define	RW_DESTROY(x)		eMrwlock_destroy(&(x)->ipf_emu)
1508 # define	WRITE_ENTER(x)		eMrwlock_write_enter(&(x)->ipf_emu, \
1509 							     __FILE__, \
1510 							     __LINE__)
1511 
1512 # define	USE_MUTEXES		1
1513 
1514 extern void eMmutex_destroy __P((eMmutex_t *));
1515 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1516 extern void eMmutex_exit __P((eMmutex_t *));
1517 extern void eMmutex_init __P((eMmutex_t *, char *));
1518 extern void eMrwlock_destroy __P((eMrwlock_t *));
1519 extern void eMrwlock_exit __P((eMrwlock_t *));
1520 extern void eMrwlock_init __P((eMrwlock_t *, char *));
1521 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1522 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1523 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1524 
1525 #undef NET_IS_HCK_L3_FULL
1526 #define	NET_IS_HCK_L3_FULL(n, x) (0)
1527 #undef NET_IS_HCK_L3_PART
1528 #define	NET_IS_HCK_L3_PART(n, x) (0)
1529 #undef NET_IS_HCK_L4_FULL
1530 #define	NET_IS_HCK_L4_FULL(n, x) (0)
1531 #undef NET_IS_HCK_L4_PART
1532 #define	NET_IS_HCK_L4_PART(n, x) (0)
1533 
1534 #endif
1535 
1536 #define	MAX_IPV4HDR	((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1537 
1538 #ifndef	IP_OFFMASK
1539 # define	IP_OFFMASK	0x1fff
1540 #endif
1541 
1542 
1543 /*
1544  * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1545  * object.
1546  */
1547 #if	BSD > 199306
1548 # define	USE_QUAD_T
1549 # define	U_QUAD_T	u_quad_t
1550 # define	QUAD_T		quad_t
1551 #else /* BSD > 199306 */
1552 # define	U_QUAD_T	u_long
1553 # define	QUAD_T		long
1554 #endif /* BSD > 199306 */
1555 
1556 
1557 #ifdef	USE_INET6
1558 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1559      defined(__osf__) || defined(linux)
1560 #  include <netinet/ip6.h>
1561 #  include <netinet/icmp6.h>
1562 #  if !defined(linux)
1563 #   if defined(_KERNEL) && !defined(__osf__)
1564 #    include <netinet6/ip6_var.h>
1565 #   endif
1566 #  endif
1567 typedef	struct ip6_hdr	ip6_t;
1568 # endif
1569 #endif
1570 
1571 #ifndef	MAX
1572 # define	MAX(a,b)	(((a) > (b)) ? (a) : (b))
1573 #endif
1574 
1575 #if defined(_KERNEL)
1576 # ifdef MENTAT
1577 #  define	COPYDATA	mb_copydata
1578 #  define	COPYBACK	mb_copyback
1579 # else
1580 #  define	COPYDATA	m_copydata
1581 #  define	COPYBACK	m_copyback
1582 # endif
1583 # if (BSD >= 199306) || defined(__FreeBSD__)
1584 #  if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1585        defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1586        defined(_BSDI_VERSION)
1587 #   include <vm/vm.h>
1588 #  endif
1589 #  if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
1590       (__FreeBSD_version >= 300000))
1591 #   if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
1592        (defined(OpenBSD) && (OpenBSD >= 200111))
1593 #    include <uvm/uvm_extern.h>
1594 #   else
1595 #    include <vm/vm_extern.h>
1596 extern  vm_map_t        kmem_map;
1597 #   endif
1598 #   include <sys/proc.h>
1599 #  else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1600 #   include <vm/vm_kern.h>
1601 #  endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1602 
1603 #  ifdef IPFILTER_M_IPFILTER
1604 #    include <sys/malloc.h>
1605 MALLOC_DECLARE(M_IPFILTER);
1606 #    define	_M_IPF		M_IPFILTER
1607 #  else /* IPFILTER_M_IPFILTER */
1608 #   ifdef M_PFIL
1609 #    define	_M_IPF		M_PFIL
1610 #   else
1611 #    ifdef M_IPFILTER
1612 #     define	_M_IPF		M_IPFILTER
1613 #    else
1614 #     define	_M_IPF		M_TEMP
1615 #    endif /* M_IPFILTER */
1616 #   endif /* M_PFIL */
1617 #  endif /* IPFILTER_M_IPFILTER */
1618 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1619 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1620 #  define	KFREE(x)	FREE((x), _M_IPF)
1621 #  define	KFREES(x,s)	FREE((x), _M_IPF)
1622 #  define	UIOMOVE(a,b,c,d)	uiomove(a,b,d)
1623 #  define	SLEEP(id, n)	tsleep((id), PPAUSE|PCATCH, n, 0)
1624 #  define	WAKEUP(id,x)	wakeup(id+x)
1625 #  define	GETIFP(n, v, ifs)	ifunit(n)
1626 # endif /* (Free)BSD */
1627 
1628 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
1629 #  if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1630       (defined(OpenBSD) && (OpenBSD >= 200006))
1631 #   define	SPL_NET(x)	x = splsoftnet()
1632 #  else
1633 #   define	SPL_IMP(x)	x = splimp()
1634 #   define	SPL_NET(x)	x = splnet()
1635 #  endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1636 #  define	SPL_X(x)	(void) splx(x)
1637 # endif /* !USE_MUTEXES */
1638 
1639 # ifndef FREE_MB_T
1640 #  define	FREE_MB_T(m)	m_freem(m)
1641 # endif
1642 
1643 # ifndef MTOD
1644 #  define	MTOD(m,t)	mtod(m,t)
1645 # endif
1646 
1647 # ifndef COPYIN
1648 #  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1649 #  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1650 #  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1651 #  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1652 # endif
1653 
1654 # ifndef KMALLOC
1655 #  define	KMALLOC(a,b)	(a) = (b)new_kmem_alloc(sizeof(*(a)), \
1656 							KMEM_NOSLEEP)
1657 #  define	KMALLOCS(a,b,c)	(a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1658 # endif
1659 
1660 # ifndef	GET_MINOR
1661 #  define	GET_MINOR(x)	minor(x)
1662 # endif
1663 # define	PANIC(x,y)	if (x) panic y
1664 #endif /* _KERNEL */
1665 
1666 #ifndef	IFNAME
1667 # define	IFNAME(x)	((struct ifnet *)x)->if_name
1668 #endif
1669 #ifndef	COPYIFNAME
1670 # define	NEED_FRGETIFNAME
1671 extern	char	*fr_getifname __P((struct ifnet *, char *));
1672 # define	COPYIFNAME(x, b, v) \
1673 				fr_getifname((struct ifnet *)x, b)
1674 #endif
1675 
1676 #ifndef ASSERT
1677 # define	ASSERT(x)
1678 #endif
1679 
1680 /*
1681  * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1682  * would mean all normal code that walks through strings needed casts.  Yuck.
1683  */
1684 #define	ISALNUM(x)	isalnum((u_char)(x))
1685 #define	ISALPHA(x)	isalpha((u_char)(x))
1686 #define	ISASCII(x)	isascii((u_char)(x))
1687 #define	ISDIGIT(x)	isdigit((u_char)(x))
1688 #define	ISPRINT(x)	isprint((u_char)(x))
1689 #define	ISSPACE(x)	isspace((u_char)(x))
1690 #define	ISUPPER(x)	isupper((u_char)(x))
1691 #define	ISXDIGIT(x)	isxdigit((u_char)(x))
1692 #define	ISLOWER(x)	islower((u_char)(x))
1693 #define	TOUPPER(x)	toupper((u_char)(x))
1694 #define	TOLOWER(x)	tolower((u_char)(x))
1695 
1696 /*
1697  * If mutexes aren't being used, turn all the mutex functions into null-ops.
1698  */
1699 #if !defined(USE_MUTEXES)
1700 # define	USE_SPL			1
1701 # undef		RW_DESTROY
1702 # undef		MUTEX_INIT
1703 # undef		MUTEX_NUKE
1704 # undef		MUTEX_DESTROY
1705 # define	MUTEX_ENTER(x)		;
1706 # define	READ_ENTER(x)		;
1707 # define	WRITE_ENTER(x)		;
1708 # define	MUTEX_DOWNGRADE(x)	;
1709 # define	RWLOCK_INIT(x, y)	;
1710 # define	RWLOCK_EXIT(x)		;
1711 # define	RW_DESTROY(x)		;
1712 # define	MUTEX_EXIT(x)		;
1713 # define	MUTEX_INIT(x,y)		;
1714 # define	MUTEX_DESTROY(x)	;
1715 # define	MUTEX_NUKE(x)		;
1716 #endif /* !USE_MUTEXES */
1717 #ifndef	ATOMIC_INC
1718 # define	ATOMIC_INC(x)		(x)++
1719 # define	ATOMIC_DEC(x)		(x)--
1720 #endif
1721 
1722 #if defined(USE_SPL) && defined(_KERNEL)
1723 # define	SPL_INT(x)	int x
1724 #else
1725 # define	SPL_INT(x)
1726 #endif
1727 
1728 /*
1729  * If there are no atomic operations for bit sizes defined, define them to all
1730  * use a generic one that works for all sizes.
1731  */
1732 #ifndef	ATOMIC_INCL
1733 # define	ATOMIC_INCL		ATOMIC_INC
1734 # define	ATOMIC_INC64		ATOMIC_INC
1735 # define	ATOMIC_INC32		ATOMIC_INC
1736 # define	ATOMIC_INC16		ATOMIC_INC
1737 # define	ATOMIC_DECL		ATOMIC_DEC
1738 # define	ATOMIC_DEC64		ATOMIC_DEC
1739 # define	ATOMIC_DEC32		ATOMIC_DEC
1740 # define	ATOMIC_DEC16		ATOMIC_DEC
1741 #endif
1742 
1743 #ifndef HDR_T_PRIVATE
1744 typedef	struct	tcphdr	tcphdr_t;
1745 typedef	struct	udphdr	udphdr_t;
1746 #endif
1747 typedef	struct	icmp	icmphdr_t;
1748 typedef	struct	ip	ip_t;
1749 typedef	struct	ether_header	ether_header_t;
1750 typedef	struct	tcpiphdr	tcpiphdr_t;
1751 
1752 #ifndef	FR_GROUPLEN
1753 # define	FR_GROUPLEN	16
1754 #endif
1755 
1756 #ifdef offsetof
1757 # undef	offsetof
1758 #endif
1759 #ifndef offsetof
1760 # define offsetof(t,m) (int)((&((t *)0L)->m))
1761 #endif
1762 
1763 /*
1764  * This set of macros has been brought about because on Tru64 it is not
1765  * possible to easily assign or examine values in a structure that are
1766  * bit fields.
1767  */
1768 #ifndef IP_V
1769 # define	IP_V(x)		(x)->ip_v
1770 #endif
1771 #ifndef	IP_V_A
1772 # define	IP_V_A(x,y)	(x)->ip_v = (y)
1773 #endif
1774 #ifndef	IP_HL
1775 # define	IP_HL(x)	(x)->ip_hl
1776 #endif
1777 #ifndef	IP_HL_A
1778 # define	IP_HL_A(x,y)	(x)->ip_hl = (y)
1779 #endif
1780 #ifndef	TCP_X2
1781 # define	TCP_X2(x)	(x)->th_x2
1782 #endif
1783 #ifndef	TCP_X2_A
1784 # define	TCP_X2_A(x,y)	(x)->th_x2 = (y)
1785 #endif
1786 #ifndef	TCP_OFF
1787 # define	TCP_OFF(x)	(x)->th_off
1788 #endif
1789 #ifndef	TCP_OFF_A
1790 # define	TCP_OFF_A(x,y)	(x)->th_off = (y)
1791 #endif
1792 #define	IPMINLEN(i, h)	((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
1793 
1794 
1795 /*
1796  * XXX - This is one of those *awful* hacks which nobody likes
1797  */
1798 #ifdef	ultrix
1799 #define	A_A
1800 #else
1801 #define	A_A	&
1802 #endif
1803 
1804 #define	TCPF_ALL	(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
1805 			 TH_ECN|TH_CWR)
1806 
1807 #if (BSD >= 199306) && !defined(m_act)
1808 # define	m_act	m_nextpkt
1809 #endif
1810 
1811 /*
1812  * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
1813  *
1814  * Basic Option
1815  *
1816  * 00000001   -   (Reserved 4)
1817  * 00111101   -   Top Secret
1818  * 01011010   -   Secret
1819  * 10010110   -   Confidential
1820  * 01100110   -   (Reserved 3)
1821  * 11001100   -   (Reserved 2)
1822  * 10101011   -   Unclassified
1823  * 11110001   -   (Reserved 1)
1824  */
1825 #define	IPSO_CLASS_RES4		0x01
1826 #define	IPSO_CLASS_TOPS		0x3d
1827 #define	IPSO_CLASS_SECR		0x5a
1828 #define	IPSO_CLASS_CONF		0x96
1829 #define	IPSO_CLASS_RES3		0x66
1830 #define	IPSO_CLASS_RES2		0xcc
1831 #define	IPSO_CLASS_UNCL		0xab
1832 #define	IPSO_CLASS_RES1		0xf1
1833 
1834 #define	IPSO_AUTH_GENSER	0x80
1835 #define	IPSO_AUTH_ESI		0x40
1836 #define	IPSO_AUTH_SCI		0x20
1837 #define	IPSO_AUTH_NSA		0x10
1838 #define	IPSO_AUTH_DOE		0x08
1839 #define	IPSO_AUTH_UN		0x06
1840 #define	IPSO_AUTH_FTE		0x01
1841 
1842 /*
1843  * IP option #defines
1844  */
1845 #undef	IPOPT_RR
1846 #define	IPOPT_RR	7
1847 #undef	IPOPT_ZSU
1848 #define	IPOPT_ZSU	10	/* ZSU */
1849 #undef	IPOPT_MTUP
1850 #define	IPOPT_MTUP	11	/* MTUP */
1851 #undef	IPOPT_MTUR
1852 #define	IPOPT_MTUR	12	/* MTUR */
1853 #undef	IPOPT_ENCODE
1854 #define	IPOPT_ENCODE	15	/* ENCODE */
1855 #undef	IPOPT_TS
1856 #define	IPOPT_TS	68
1857 #undef	IPOPT_TR
1858 #define	IPOPT_TR	82	/* TR */
1859 #undef	IPOPT_SECURITY
1860 #define	IPOPT_SECURITY	130
1861 #undef	IPOPT_LSRR
1862 #define	IPOPT_LSRR	131
1863 #undef	IPOPT_E_SEC
1864 #define	IPOPT_E_SEC	133	/* E-SEC */
1865 #undef	IPOPT_CIPSO
1866 #define	IPOPT_CIPSO	134	/* CIPSO */
1867 #undef	IPOPT_SATID
1868 #define	IPOPT_SATID	136
1869 #ifndef	IPOPT_SID
1870 # define	IPOPT_SID	IPOPT_SATID
1871 #endif
1872 #undef	IPOPT_SSRR
1873 #define	IPOPT_SSRR	137
1874 #undef	IPOPT_ADDEXT
1875 #define	IPOPT_ADDEXT	147	/* ADDEXT */
1876 #undef	IPOPT_VISA
1877 #define	IPOPT_VISA	142	/* VISA */
1878 #undef	IPOPT_IMITD
1879 #define	IPOPT_IMITD	144	/* IMITD */
1880 #undef	IPOPT_EIP
1881 #define	IPOPT_EIP	145	/* EIP */
1882 #undef	IPOPT_RTRALRT
1883 #define	IPOPT_RTRALRT	148	/* RTRALRT */
1884 #undef	IPOPT_SDB
1885 #define	IPOPT_SDB	149
1886 #undef	IPOPT_NSAPA
1887 #define	IPOPT_NSAPA	150
1888 #undef	IPOPT_DPS
1889 #define	IPOPT_DPS	151
1890 #undef	IPOPT_UMP
1891 #define	IPOPT_UMP	152
1892 #undef	IPOPT_FINN
1893 #define	IPOPT_FINN	205	/* FINN */
1894 
1895 #ifndef TCPOPT_EOL
1896 # define TCPOPT_EOL		0
1897 #endif
1898 #ifndef TCPOPT_NOP
1899 # define TCPOPT_NOP		1
1900 #endif
1901 #ifndef TCPOPT_MAXSEG
1902 # define TCPOPT_MAXSEG		2
1903 #endif
1904 #ifndef TCPOLEN_MAXSEG
1905 # define TCPOLEN_MAXSEG		4
1906 #endif
1907 #ifndef TCPOPT_WINDOW
1908 # define TCPOPT_WINDOW		3
1909 #endif
1910 #ifndef TCPOLEN_WINDOW
1911 # define TCPOLEN_WINDOW		3
1912 #endif
1913 #ifndef TCPOPT_SACK_PERMITTED
1914 # define TCPOPT_SACK_PERMITTED	4
1915 #endif
1916 #ifndef TCPOLEN_SACK_PERMITTED
1917 # define TCPOLEN_SACK_PERMITTED	2
1918 #endif
1919 #ifndef TCPOPT_SACK
1920 # define TCPOPT_SACK		5
1921 #endif
1922 #ifndef TCPOPT_TIMESTAMP
1923 # define TCPOPT_TIMESTAMP	8
1924 #endif
1925 
1926 #ifndef	ICMP_MINLEN
1927 # define	ICMP_MINLEN	8
1928 #endif
1929 #ifndef	ICMP_ECHOREPLY
1930 # define	ICMP_ECHOREPLY	0
1931 #endif
1932 #ifndef	ICMP_UNREACH
1933 # define	ICMP_UNREACH	3
1934 #endif
1935 #ifndef	ICMP_UNREACH_NET
1936 # define	ICMP_UNREACH_NET	0
1937 #endif
1938 #ifndef	ICMP_UNREACH_HOST
1939 # define	ICMP_UNREACH_HOST	1
1940 #endif
1941 #ifndef	ICMP_UNREACH_PROTOCOL
1942 # define	ICMP_UNREACH_PROTOCOL	2
1943 #endif
1944 #ifndef	ICMP_UNREACH_PORT
1945 # define	ICMP_UNREACH_PORT	3
1946 #endif
1947 #ifndef	ICMP_UNREACH_NEEDFRAG
1948 # define	ICMP_UNREACH_NEEDFRAG	4
1949 #endif
1950 #ifndef	ICMP_UNREACH_SRCFAIL
1951 # define	ICMP_UNREACH_SRCFAIL	5
1952 #endif
1953 #ifndef	ICMP_UNREACH_NET_UNKNOWN
1954 # define	ICMP_UNREACH_NET_UNKNOWN	6
1955 #endif
1956 #ifndef	ICMP_UNREACH_HOST_UNKNOWN
1957 # define	ICMP_UNREACH_HOST_UNKNOWN	7
1958 #endif
1959 #ifndef	ICMP_UNREACH_ISOLATED
1960 # define	ICMP_UNREACH_ISOLATED	8
1961 #endif
1962 #ifndef	ICMP_UNREACH_NET_PROHIB
1963 # define	ICMP_UNREACH_NET_PROHIB	9
1964 #endif
1965 #ifndef	ICMP_UNREACH_HOST_PROHIB
1966 # define	ICMP_UNREACH_HOST_PROHIB	10
1967 #endif
1968 #ifndef	ICMP_UNREACH_TOSNET
1969 # define	ICMP_UNREACH_TOSNET	11
1970 #endif
1971 #ifndef	ICMP_UNREACH_TOSHOST
1972 # define	ICMP_UNREACH_TOSHOST	12
1973 #endif
1974 #ifndef	ICMP_UNREACH_ADMIN_PROHIBIT
1975 # define	ICMP_UNREACH_ADMIN_PROHIBIT	13
1976 #endif
1977 #ifndef	ICMP_UNREACH_FILTER
1978 # define	ICMP_UNREACH_FILTER	13
1979 #endif
1980 #ifndef	ICMP_UNREACH_HOST_PRECEDENCE
1981 # define	ICMP_UNREACH_HOST_PRECEDENCE	14
1982 #endif
1983 #ifndef	ICMP_UNREACH_PRECEDENCE_CUTOFF
1984 # define	ICMP_UNREACH_PRECEDENCE_CUTOFF	15
1985 #endif
1986 #ifndef	ICMP_SOURCEQUENCH
1987 # define	ICMP_SOURCEQUENCH	4
1988 #endif
1989 #ifndef	ICMP_REDIRECT_NET
1990 # define	ICMP_REDIRECT_NET	0
1991 #endif
1992 #ifndef	ICMP_REDIRECT_HOST
1993 # define	ICMP_REDIRECT_HOST	1
1994 #endif
1995 #ifndef	ICMP_REDIRECT_TOSNET
1996 # define	ICMP_REDIRECT_TOSNET	2
1997 #endif
1998 #ifndef	ICMP_REDIRECT_TOSHOST
1999 # define	ICMP_REDIRECT_TOSHOST	3
2000 #endif
2001 #ifndef	ICMP_ALTHOSTADDR
2002 # define	ICMP_ALTHOSTADDR	6
2003 #endif
2004 #ifndef	ICMP_TIMXCEED
2005 # define	ICMP_TIMXCEED	11
2006 #endif
2007 #ifndef	ICMP_TIMXCEED_INTRANS
2008 # define	ICMP_TIMXCEED_INTRANS	0
2009 #endif
2010 #ifndef	ICMP_TIMXCEED_REASS
2011 # define		ICMP_TIMXCEED_REASS	1
2012 #endif
2013 #ifndef	ICMP_PARAMPROB
2014 # define	ICMP_PARAMPROB	12
2015 #endif
2016 #ifndef	ICMP_PARAMPROB_ERRATPTR
2017 # define	ICMP_PARAMPROB_ERRATPTR	0
2018 #endif
2019 #ifndef	ICMP_PARAMPROB_OPTABSENT
2020 # define	ICMP_PARAMPROB_OPTABSENT	1
2021 #endif
2022 #ifndef	ICMP_PARAMPROB_LENGTH
2023 # define	ICMP_PARAMPROB_LENGTH	2
2024 #endif
2025 #ifndef ICMP_TSTAMP
2026 # define	ICMP_TSTAMP	13
2027 #endif
2028 #ifndef ICMP_TSTAMPREPLY
2029 # define	ICMP_TSTAMPREPLY	14
2030 #endif
2031 #ifndef ICMP_IREQ
2032 # define	ICMP_IREQ	15
2033 #endif
2034 #ifndef ICMP_IREQREPLY
2035 # define	ICMP_IREQREPLY	16
2036 #endif
2037 #ifndef	ICMP_MASKREQ
2038 # define	ICMP_MASKREQ	17
2039 #endif
2040 #ifndef ICMP_MASKREPLY
2041 # define	ICMP_MASKREPLY	18
2042 #endif
2043 #ifndef	ICMP_TRACEROUTE
2044 # define	ICMP_TRACEROUTE	30
2045 #endif
2046 #ifndef	ICMP_DATACONVERR
2047 # define	ICMP_DATACONVERR	31
2048 #endif
2049 #ifndef	ICMP_MOBILE_REDIRECT
2050 # define	ICMP_MOBILE_REDIRECT	32
2051 #endif
2052 #ifndef	ICMP_IPV6_WHEREAREYOU
2053 # define	ICMP_IPV6_WHEREAREYOU	33
2054 #endif
2055 #ifndef	ICMP_IPV6_IAMHERE
2056 # define	ICMP_IPV6_IAMHERE	34
2057 #endif
2058 #ifndef	ICMP_MOBILE_REGREQUEST
2059 # define	ICMP_MOBILE_REGREQUEST	35
2060 #endif
2061 #ifndef	ICMP_MOBILE_REGREPLY
2062 # define	ICMP_MOBILE_REGREPLY	36
2063 #endif
2064 #ifndef	ICMP_SKIP
2065 # define	ICMP_SKIP	39
2066 #endif
2067 #ifndef	ICMP_PHOTURIS
2068 # define	ICMP_PHOTURIS	40
2069 #endif
2070 #ifndef	ICMP_PHOTURIS_UNKNOWN_INDEX
2071 # define	ICMP_PHOTURIS_UNKNOWN_INDEX	1
2072 #endif
2073 #ifndef	ICMP_PHOTURIS_AUTH_FAILED
2074 # define	ICMP_PHOTURIS_AUTH_FAILED	2
2075 #endif
2076 #ifndef	ICMP_PHOTURIS_DECRYPT_FAILED
2077 # define	ICMP_PHOTURIS_DECRYPT_FAILED	3
2078 #endif
2079 #ifndef	IPVERSION
2080 # define	IPVERSION	4
2081 #endif
2082 #ifndef	IPOPT_MINOFF
2083 # define	IPOPT_MINOFF	4
2084 #endif
2085 #ifndef	IPOPT_COPIED
2086 # define	IPOPT_COPIED(x)	((x)&0x80)
2087 #endif
2088 #ifndef	IPOPT_EOL
2089 # define	IPOPT_EOL	0
2090 #endif
2091 #ifndef	IPOPT_NOP
2092 # define	IPOPT_NOP	1
2093 #endif
2094 #ifndef	IP_MF
2095 # define	IP_MF	((u_short)0x2000)
2096 #endif
2097 #ifndef	ETHERTYPE_IP
2098 # define	ETHERTYPE_IP	((u_short)0x0800)
2099 #endif
2100 #ifndef	TH_FIN
2101 # define	TH_FIN	0x01
2102 #endif
2103 #ifndef	TH_SYN
2104 # define	TH_SYN	0x02
2105 #endif
2106 #ifndef	TH_RST
2107 # define	TH_RST	0x04
2108 #endif
2109 #ifndef	TH_PUSH
2110 # define	TH_PUSH	0x08
2111 #endif
2112 #ifndef	TH_ACK
2113 # define	TH_ACK	0x10
2114 #endif
2115 #ifndef	TH_URG
2116 # define	TH_URG	0x20
2117 #endif
2118 #undef	TH_ACKMASK
2119 #define	TH_ACKMASK	(TH_FIN|TH_SYN|TH_RST|TH_ACK)
2120 
2121 #ifndef	IPOPT_EOL
2122 # define	IPOPT_EOL	0
2123 #endif
2124 #ifndef	IPOPT_NOP
2125 # define	IPOPT_NOP	1
2126 #endif
2127 #ifndef	IPOPT_RR
2128 # define	IPOPT_RR	7
2129 #endif
2130 #ifndef	IPOPT_TS
2131 # define	IPOPT_TS	68
2132 #endif
2133 #ifndef	IPOPT_SECURITY
2134 # define	IPOPT_SECURITY	130
2135 #endif
2136 #ifndef	IPOPT_LSRR
2137 # define	IPOPT_LSRR	131
2138 #endif
2139 #ifndef	IPOPT_SATID
2140 # define	IPOPT_SATID	136
2141 #endif
2142 #ifndef	IPOPT_SSRR
2143 # define	IPOPT_SSRR	137
2144 #endif
2145 #ifndef	IPOPT_SECUR_UNCLASS
2146 # define	IPOPT_SECUR_UNCLASS	((u_short)0x0000)
2147 #endif
2148 #ifndef	IPOPT_SECUR_CONFID
2149 # define	IPOPT_SECUR_CONFID	((u_short)0xf135)
2150 #endif
2151 #ifndef	IPOPT_SECUR_EFTO
2152 # define	IPOPT_SECUR_EFTO	((u_short)0x789a)
2153 #endif
2154 #ifndef	IPOPT_SECUR_MMMM
2155 # define	IPOPT_SECUR_MMMM	((u_short)0xbc4d)
2156 #endif
2157 #ifndef	IPOPT_SECUR_RESTR
2158 # define	IPOPT_SECUR_RESTR	((u_short)0xaf13)
2159 #endif
2160 #ifndef	IPOPT_SECUR_SECRET
2161 # define	IPOPT_SECUR_SECRET	((u_short)0xd788)
2162 #endif
2163 #ifndef IPOPT_SECUR_TOPSECRET
2164 # define	IPOPT_SECUR_TOPSECRET	((u_short)0x6bc5)
2165 #endif
2166 #ifndef IPOPT_OLEN
2167 # define	IPOPT_OLEN	1
2168 #endif
2169 #ifndef	IPPROTO_HOPOPTS
2170 # define	IPPROTO_HOPOPTS	0
2171 #endif
2172 #ifndef	IPPROTO_ENCAP
2173 # define	IPPROTO_ENCAP	4
2174 #endif
2175 #ifndef	IPPROTO_IPV6
2176 # define	IPPROTO_IPV6	41
2177 #endif
2178 #ifndef	IPPROTO_ROUTING
2179 # define	IPPROTO_ROUTING	43
2180 #endif
2181 #ifndef	IPPROTO_FRAGMENT
2182 # define	IPPROTO_FRAGMENT	44
2183 #endif
2184 #ifndef	IPPROTO_GRE
2185 # define	IPPROTO_GRE	47	/* GRE encaps RFC 1701 */
2186 #endif
2187 #ifndef	IPPROTO_ESP
2188 # define	IPPROTO_ESP	50
2189 #endif
2190 #ifndef	IPPROTO_AH
2191 # define	IPPROTO_AH	51
2192 #endif
2193 #ifndef	IPPROTO_ICMPV6
2194 # define	IPPROTO_ICMPV6	58
2195 #endif
2196 #ifndef	IPPROTO_NONE
2197 # define	IPPROTO_NONE	59
2198 #endif
2199 #ifndef	IPPROTO_DSTOPTS
2200 # define	IPPROTO_DSTOPTS	60
2201 #endif
2202 #ifndef	IPPROTO_FRAGMENT
2203 # define	IPPROTO_FRAGMENT	44
2204 #endif
2205 #ifndef	ICMP_ROUTERADVERT
2206 # define	ICMP_ROUTERADVERT	9
2207 #endif
2208 #ifndef	ICMP_ROUTERSOLICIT
2209 # define	ICMP_ROUTERSOLICIT	10
2210 #endif
2211 #ifndef	ICMP6_DST_UNREACH
2212 # define	ICMP6_DST_UNREACH	1
2213 #endif
2214 #ifndef	ICMP6_PACKET_TOO_BIG
2215 # define	ICMP6_PACKET_TOO_BIG	2
2216 #endif
2217 #ifndef	ICMP6_TIME_EXCEEDED
2218 # define	ICMP6_TIME_EXCEEDED	3
2219 #endif
2220 #ifndef	ICMP6_PARAM_PROB
2221 # define	ICMP6_PARAM_PROB	4
2222 #endif
2223 
2224 #ifndef	ICMP6_ECHO_REQUEST
2225 # define	ICMP6_ECHO_REQUEST	128
2226 #endif
2227 #ifndef	ICMP6_ECHO_REPLY
2228 # define	ICMP6_ECHO_REPLY	129
2229 #endif
2230 #ifndef	ICMP6_MEMBERSHIP_QUERY
2231 # define	ICMP6_MEMBERSHIP_QUERY	130
2232 #endif
2233 #ifndef	MLD6_LISTENER_QUERY
2234 # define	MLD6_LISTENER_QUERY	130
2235 #endif
2236 #ifndef	ICMP6_MEMBERSHIP_REPORT
2237 # define	ICMP6_MEMBERSHIP_REPORT	131
2238 #endif
2239 #ifndef	MLD6_LISTENER_REPORT
2240 # define	MLD6_LISTENER_REPORT	131
2241 #endif
2242 #ifndef	ICMP6_MEMBERSHIP_REDUCTION
2243 # define	ICMP6_MEMBERSHIP_REDUCTION	132
2244 #endif
2245 #ifndef	MLD6_LISTENER_DONE
2246 # define	MLD6_LISTENER_DONE	132
2247 #endif
2248 #ifndef	ND_ROUTER_SOLICIT
2249 # define	ND_ROUTER_SOLICIT	133
2250 #endif
2251 #ifndef	ND_ROUTER_ADVERT
2252 # define	ND_ROUTER_ADVERT	134
2253 #endif
2254 #ifndef	ND_NEIGHBOR_SOLICIT
2255 # define	ND_NEIGHBOR_SOLICIT	135
2256 #endif
2257 #ifndef	ND_NEIGHBOR_ADVERT
2258 # define	ND_NEIGHBOR_ADVERT	136
2259 #endif
2260 #ifndef	ND_REDIRECT
2261 # define	ND_REDIRECT	137
2262 #endif
2263 #ifndef	ICMP6_ROUTER_RENUMBERING
2264 # define	ICMP6_ROUTER_RENUMBERING	138
2265 #endif
2266 #ifndef	ICMP6_WRUREQUEST
2267 # define	ICMP6_WRUREQUEST	139
2268 #endif
2269 #ifndef	ICMP6_WRUREPLY
2270 # define	ICMP6_WRUREPLY		140
2271 #endif
2272 #ifndef	ICMP6_FQDN_QUERY
2273 # define	ICMP6_FQDN_QUERY	139
2274 #endif
2275 #ifndef	ICMP6_FQDN_REPLY
2276 # define	ICMP6_FQDN_REPLY	140
2277 #endif
2278 #ifndef	ICMP6_NI_QUERY
2279 # define	ICMP6_NI_QUERY		139
2280 #endif
2281 #ifndef	ICMP6_NI_REPLY
2282 # define	ICMP6_NI_REPLY		140
2283 #endif
2284 #ifndef	MLD6_MTRACE_RESP
2285 # define	MLD6_MTRACE_RESP	200
2286 #endif
2287 #ifndef	MLD6_MTRACE
2288 # define	MLD6_MTRACE		201
2289 #endif
2290 #ifndef	ICMP6_HADISCOV_REQUEST
2291 # define	ICMP6_HADISCOV_REQUEST	202
2292 #endif
2293 #ifndef	ICMP6_HADISCOV_REPLY
2294 # define	ICMP6_HADISCOV_REPLY	203
2295 #endif
2296 #ifndef	ICMP6_MOBILEPREFIX_SOLICIT
2297 # define	ICMP6_MOBILEPREFIX_SOLICIT	204
2298 #endif
2299 #ifndef	ICMP6_MOBILEPREFIX_ADVERT
2300 # define	ICMP6_MOBILEPREFIX_ADVERT	205
2301 #endif
2302 #ifndef	ICMP6_MAXTYPE
2303 # define	ICMP6_MAXTYPE		205
2304 #endif
2305 
2306 #ifndef	ICMP6_DST_UNREACH_NOROUTE
2307 # define	ICMP6_DST_UNREACH_NOROUTE	0
2308 #endif
2309 #ifndef	ICMP6_DST_UNREACH_ADMIN
2310 # define	ICMP6_DST_UNREACH_ADMIN		1
2311 #endif
2312 #ifndef	ICMP6_DST_UNREACH_NOTNEIGHBOR
2313 # define	ICMP6_DST_UNREACH_NOTNEIGHBOR	2
2314 #endif
2315 #ifndef	ICMP6_DST_UNREACH_BEYONDSCOPE
2316 # define	ICMP6_DST_UNREACH_BEYONDSCOPE	2
2317 #endif
2318 #ifndef	ICMP6_DST_UNREACH_ADDR
2319 # define	ICMP6_DST_UNREACH_ADDR		3
2320 #endif
2321 #ifndef	ICMP6_DST_UNREACH_NOPORT
2322 # define	ICMP6_DST_UNREACH_NOPORT	4
2323 #endif
2324 #ifndef	ICMP6_TIME_EXCEED_TRANSIT
2325 # define	ICMP6_TIME_EXCEED_TRANSIT	0
2326 #endif
2327 #ifndef	ICMP6_TIME_EXCEED_REASSEMBLY
2328 # define	ICMP6_TIME_EXCEED_REASSEMBLY	1
2329 #endif
2330 
2331 #ifndef	ICMP6_NI_SUCCESS
2332 # define	ICMP6_NI_SUCCESS	0
2333 #endif
2334 #ifndef	ICMP6_NI_REFUSED
2335 # define	ICMP6_NI_REFUSED	1
2336 #endif
2337 #ifndef	ICMP6_NI_UNKNOWN
2338 # define	ICMP6_NI_UNKNOWN	2
2339 #endif
2340 
2341 #ifndef	ICMP6_ROUTER_RENUMBERING_COMMAND
2342 # define	ICMP6_ROUTER_RENUMBERING_COMMAND	0
2343 #endif
2344 #ifndef	ICMP6_ROUTER_RENUMBERING_RESULT
2345 # define	ICMP6_ROUTER_RENUMBERING_RESULT	1
2346 #endif
2347 #ifndef	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2348 # define	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET	255
2349 #endif
2350 
2351 #ifndef	ICMP6_PARAMPROB_HEADER
2352 # define	ICMP6_PARAMPROB_HEADER	0
2353 #endif
2354 #ifndef	ICMP6_PARAMPROB_NEXTHEADER
2355 # define	ICMP6_PARAMPROB_NEXTHEADER	1
2356 #endif
2357 #ifndef	ICMP6_PARAMPROB_OPTION
2358 # define	ICMP6_PARAMPROB_OPTION	2
2359 #endif
2360 
2361 #ifndef	ICMP6_NI_SUBJ_IPV6
2362 # define	ICMP6_NI_SUBJ_IPV6	0
2363 #endif
2364 #ifndef	ICMP6_NI_SUBJ_FQDN
2365 # define	ICMP6_NI_SUBJ_FQDN	1
2366 #endif
2367 #ifndef	ICMP6_NI_SUBJ_IPV4
2368 # define	ICMP6_NI_SUBJ_IPV4	2
2369 #endif
2370 
2371 /*
2372  * ECN is a new addition to TCP - RFC 2481
2373  */
2374 #ifndef TH_ECN
2375 # define	TH_ECN	0x40
2376 #endif
2377 #ifndef TH_CWR
2378 # define	TH_CWR	0x80
2379 #endif
2380 #define	TH_ECNALL	(TH_ECN|TH_CWR)
2381 
2382 /*
2383  * TCP States
2384  */
2385 #define IPF_TCPS_CLOSED		0	/* closed */
2386 #define IPF_TCPS_LISTEN		1	/* listening for connection */
2387 #define IPF_TCPS_SYN_SENT	2	/* active, have sent syn */
2388 #define IPF_TCPS_SYN_RECEIVED	3	/* have send and received syn */
2389 #define IPF_TCPS_HALF_ESTAB	4	/* for connections not fully "up" */
2390 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2391 #define IPF_TCPS_ESTABLISHED	5	/* established */
2392 #define IPF_TCPS_CLOSE_WAIT	6	/* rcvd fin, waiting for close */
2393 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2394 #define IPF_TCPS_FIN_WAIT_1	7	/* have closed, sent fin */
2395 #define IPF_TCPS_CLOSING	8	/* closed xchd FIN; await FIN ACK */
2396 #define IPF_TCPS_LAST_ACK	9	/* had fin and close; await FIN ACK */
2397 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2398 #define IPF_TCPS_FIN_WAIT_2	10	/* have closed, fin is acked */
2399 #define IPF_TCPS_TIME_WAIT	11	/* in 2*msl quiet wait after close */
2400 #define IPF_TCP_NSTATES		12
2401 
2402 #define	TCP_MSL			120
2403 
2404 #undef	ICMP_MAX_UNREACH
2405 #define	ICMP_MAX_UNREACH	14
2406 #undef	ICMP_MAXTYPE
2407 #define	ICMP_MAXTYPE		18
2408 
2409 #ifndef	IFNAMSIZ
2410 #define	IFNAMSIZ		16
2411 #endif
2412 
2413 #ifndef	LOG_FTP
2414 # define	LOG_FTP		(11<<3)
2415 #endif
2416 #ifndef	LOG_AUTHPRIV
2417 # define	LOG_AUTHPRIV	(10<<3)
2418 #endif
2419 #ifndef	LOG_AUDIT
2420 # define	LOG_AUDIT	(13<<3)
2421 #endif
2422 #ifndef	LOG_NTP
2423 # define	LOG_NTP		(12<<3)
2424 #endif
2425 #ifndef	LOG_SECURITY
2426 # define	LOG_SECURITY	(13<<3)
2427 #endif
2428 #ifndef	LOG_LFMT
2429 # define	LOG_LFMT	(14<<3)
2430 #endif
2431 #ifndef	LOG_CONSOLE
2432 # define	LOG_CONSOLE	(14<<3)
2433 #endif
2434 
2435 /*
2436  * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2437  * another IP header and then 64 bits of data, totalling 56.  Of course,
2438  * the last 64 bits is dependent on that being available.
2439  */
2440 #define	ICMPERR_ICMPHLEN	8
2441 #define	ICMPERR_IPICMPHLEN	(20 + 8)
2442 #define	ICMPERR_MINPKTLEN	(20 + 8 + 20)
2443 #define	ICMPERR_MAXPKTLEN	(20 + 8 + 20 + 8)
2444 #define ICMP6ERR_MINPKTLEN	(40 + 8)
2445 #define ICMP6ERR_IPICMPHLEN	(40 + 8 + 40)
2446 
2447 #ifndef MIN
2448 # define	MIN(a,b)	(((a)<(b))?(a):(b))
2449 #endif
2450 
2451 #ifdef IPF_DEBUG
2452 # define	DPRINT(x)	printf x
2453 #else
2454 # define	DPRINT(x)
2455 #endif
2456 
2457 #ifdef RESCUE
2458 # undef IPFILTER_BPF
2459 #endif
2460 
2461 #ifndef DTRACE_PROBE
2462 # define DTRACE_PROBE(_x_)
2463 # define DTRACE_PROBE1(_x_, _t1_, _a1_)
2464 # define DTRACE_PROBE2(_x_, _t1_, _a1_, _t2_, _a2_)
2465 # define DTRACE_PROBE3(_x_, _t1_, _a1_, _t2_, _a2_, _t3_, _a3_)
2466 # define DTRACE_PROBE4(_x_, _t1_, _a1_, _t2_, _a2_, _t3_, _a3_, _t4_, _a4_)
2467 #endif
2468 
2469 #endif	/* __IP_COMPAT_H__ */
2470