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