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