xref: /freebsd/sys/netpfil/ipfilter/netinet/ip_compat.h (revision 347dd0539f3a75fdf2128dd4620ca99e96f311e9)
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  * Id: ip_compat.h,v 2.142.2.57 2007/10/10 09:51:42 darrenr Exp $
6  */
7 
8 #ifndef	__IP_COMPAT_H__
9 #define	__IP_COMPAT_H__
10 
11 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
12 # undef	KERNEL
13 # undef	_KERNEL
14 # undef 	__KERNEL__
15 # define	KERNEL
16 # define	_KERNEL
17 # define 	__KERNEL__
18 #endif
19 
20 #ifndef	SOLARIS
21 # if defined(sun) && defined(__SVR4)
22 #  define	SOLARIS		1
23 # else
24 #  define	SOLARIS		0
25 # endif
26 #endif
27 
28 
29 #if defined(__SVR4)
30 # define index   strchr
31 # if !defined(_KERNEL)
32 #  define	bzero(a,b)	memset(a,0,b)
33 #  define	bcmp		memcmp
34 #  define	bcopy(a,b,c)	memmove(b,a,c)
35 # endif
36 #endif
37 
38 #ifndef LIFNAMSIZ
39 # ifdef IF_NAMESIZE
40 #  define	LIFNAMSIZ	IF_NAMESIZE
41 # else
42 #  ifdef	IFNAMSIZ
43 #   define	LIFNAMSIZ	IFNAMSIZ
44 #  else
45 #   define	LIFNAMSIZ	16
46 #  endif
47 # endif
48 #endif
49 
50 
51 #  define IPL_EXTERN(ep) ipl##ep
52 
53 /*
54  * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
55  */
56 #ifndef _KERNEL
57 # define ADD_KERNEL
58 # define _KERNEL
59 # define KERNEL
60 #endif
61 #include <sys/uio.h>
62 #ifdef ADD_KERNEL
63 # undef _KERNEL
64 # undef KERNEL
65 #endif
66 
67 #define	NETBSD_GE_REV(x)	(defined(__NetBSD_Version__) && \
68 				 (__NetBSD_Version__ >= (x)))
69 #define	NETBSD_GT_REV(x)	(defined(__NetBSD_Version__) && \
70 				 (__NetBSD_Version__ > (x)))
71 #define	NETBSD_LT_REV(x)	(defined(__NetBSD_Version__) && \
72 				 (__NetBSD_Version__ < (x)))
73 
74 
75 /* ----------------------------------------------------------------------- */
76 /*                                F R E E B S D                            */
77 /* ----------------------------------------------------------------------- */
78 #define HAS_SYS_MD5_H	1
79 #if defined(_KERNEL)
80 # include "opt_bpf.h"
81 # include "opt_inet6.h"
82 # if defined(INET6) && !defined(USE_INET6)
83 #  define USE_INET6
84 # endif
85 #else
86 # if !defined(USE_INET6) && !defined(NOINET6)
87 #  define	USE_INET6
88 # endif
89 #endif
90 
91 #if defined(_KERNEL)
92 # include <netinet/ip_var.h>
93 # define	p_cred	td_ucred
94 # define	p_uid	td_ucred->cr_ruid
95 
96 /*
97  * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
98  * There may be other, safe, kernels but this is not extensively tested yet.
99  */
100 # define HAVE_M_PULLDOWN
101 # if !defined(IPFILTER_LKM) && defined(__FreeBSD__)
102 #  include "opt_ipfilter.h"
103 # endif
104 # define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
105 # define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
106 
107 #else
108 # include <inttypes.h>
109 #endif /* _KERNEL */
110 
111 #include <sys/selinfo.h>
112 #include <sys/lock.h>
113 #include <sys/malloc.h>
114 #include <sys/mutex.h>
115 #define	KRWLOCK_FILL_SZ		56
116 #define	KMUTEX_FILL_SZ		56
117 #include <sys/rwlock.h>
118 #define	KMUTEX_T		struct mtx
119 #define	KRWLOCK_T		struct rwlock
120 
121 #ifdef _KERNEL
122 # define	READ_ENTER(x)		rw_rlock(&(x)->ipf_lk)
123 # define	WRITE_ENTER(x)		rw_wlock(&(x)->ipf_lk)
124 # define	MUTEX_DOWNGRADE(x)	rw_downgrade(&(x)->ipf_lk)
125 # define	MUTEX_TRY_UPGRADE(x)	rw_try_upgrade(&(x)->ipf_lk)
126 # define	RWLOCK_INIT(x,y)	rw_init(&(x)->ipf_lk, (y))
127 # define	RW_DESTROY(x)		rw_destroy(&(x)->ipf_lk)
128 # define	RWLOCK_EXIT(x)		do { \
129 					    if (rw_wowned(&(x)->ipf_lk)) \
130 					    	rw_wunlock(&(x)->ipf_lk); \
131 					    else \
132 						rw_runlock(&(x)->ipf_lk); \
133 					} while (0)
134 # include <net/if_var.h>
135 # include <net/if_private.h>
136 # define	GETKTIME(x)	microtime((struct timeval *)x)
137 # define	if_addrlist	if_addrhead
138 
139 # include <netinet/in_systm.h>
140 # include <netinet/ip.h>
141 # include <machine/in_cksum.h>
142 
143 # define	USE_MUTEXES
144 # define	MUTEX_ENTER(x)		mtx_lock(&(x)->ipf_lk)
145 # define	MUTEX_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
146 # define	MUTEX_INIT(x,y)		mtx_init(&(x)->ipf_lk, (y), NULL,\
147 						 MTX_DEF)
148 # define	MUTEX_DESTROY(x)	mtx_destroy(&(x)->ipf_lk)
149 # define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
150 /*
151  * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
152  * for what we want to use them for, despite testing showing they work -
153  * with a WITNESS kernel, it generates LOR messages.
154  */
155 # include <machine/atomic.h>
156 # define	ATOMIC_INC(x)		{ mtx_lock(&softc->ipf_rw.ipf_lk); (x)++; \
157 					  mtx_unlock(&softc->ipf_rw.ipf_lk); }
158 # define	ATOMIC_DEC(x)		{ mtx_lock(&softc->ipf_rw.ipf_lk); (x)--; \
159 					  mtx_unlock(&softc->ipf_rw.ipf_lk); }
160 # define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
161 # define	ATOMIC_INC64(x)		ATOMIC_INC(x)
162 # define	ATOMIC_INC32(x)		atomic_add_32((u_int *)&(x), 1)
163 # define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
164 # define	ATOMIC_DEC64(x)		ATOMIC_DEC(x)
165 # define	ATOMIC_DEC32(x)		atomic_add_32((u_int *)&(x), -1)
166 # define	SPL_X(x)	;
167 # define	SPL_NET(x)	;
168 # define	SPL_IMP(x)	;
169 # define	SPL_SCHED(x)	;
170 # define	GET_MINOR		dev2unit
171 # define	MSGDSIZE(m)	mbufchainlen(m)
172 # define	M_LEN(m)	(m)->m_len
173 # define	M_ADJ(m,x)	m_adj(m, x)
174 # define	M_COPY(x)	m_copym((x), 0, M_COPYALL, M_NOWAIT)
175 # define	M_DUP(m)	m_dup(m, M_NOWAIT)
176 # define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
177 typedef struct mbuf mb_t;
178 
179 #else	/* !_KERNEL */
180 # ifndef _NET_IF_VAR_H_
181 /*
182  * Userland emulation of struct ifnet.
183  */
184 struct route;
185 struct mbuf;
186 struct ifnet {
187 	char			if_xname[IFNAMSIZ];
188 	STAILQ_HEAD(, ifaddr)	if_addrlist;
189 	int	(*if_output)(struct ifnet *, struct mbuf *,
190 	    const struct sockaddr *, struct route *);
191 };
192 # endif /* _NET_IF_VAR_H_ */
193 #endif /* _KERNEL */
194 
195 #define	IFNAME(x)	((struct ifnet *)x)->if_xname
196 #define	COPYIFNAME(v, x, b) \
197 			(void) strncpy(b, \
198 			       ((struct ifnet *)x)->if_xname, \
199 			       LIFNAMSIZ)
200 
201 typedef	u_long		ioctlcmd_t;
202 typedef	struct uio	uio_t;
203 typedef	int		minor_t;
204 typedef	u_int32_t	u_32_t;
205 # define	U_32_T	1
206 
207 
208 /* ----------------------------------------------------------------------- */
209 /*                           G E N E R I C                                 */
210 /* ----------------------------------------------------------------------- */
211 
212 /*
213  * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
214  * filter rules.
215  */
216 #if !defined(IPFILTER_BPF)
217 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
218      (defined(NBPFILTER) && (NBPFILTER > 0))
219 #  define	IPFILTER_BPF
220 # endif
221 #endif
222 
223 /*
224  * Userland locking primitives
225  */
226 #ifndef _KERNEL
227 # if !defined(KMUTEX_FILL_SZ)
228 #  define	KMUTEX_FILL_SZ	1
229 # endif
230 # if !defined(KRWLOCK_FILL_SZ)
231 #  define	KRWLOCK_FILL_SZ	1
232 # endif
233 #endif
234 
235 typedef	struct	{
236 	char	*eMm_owner;
237 	char	*eMm_heldin;
238 	u_int	eMm_magic;
239 	int	eMm_held;
240 	int	eMm_heldat;
241 } eMmutex_t;
242 
243 typedef	struct	{
244 	char	*eMrw_owner;
245 	char	*eMrw_heldin;
246 	u_int	eMrw_magic;
247 	short	eMrw_read;
248 	short	eMrw_write;
249 	int	eMrw_heldat;
250 } eMrwlock_t;
251 
252 typedef union {
253 	char	_fill[KMUTEX_FILL_SZ];
254 #ifdef KMUTEX_T
255 	struct	{
256 		KMUTEX_T	ipf_slk;
257 		const char	*ipf_lname;
258 	} ipf_lkun_s;
259 #endif
260 	eMmutex_t	ipf_emu;
261 } ipfmutex_t;
262 
263 typedef union {
264 	char	_fill[KRWLOCK_FILL_SZ];
265 #ifdef KRWLOCK_T
266 	struct	{
267 		KRWLOCK_T	ipf_slk;
268 		const char	*ipf_lname;
269 		int		ipf_sr;
270 		int		ipf_sw;
271 		u_int		ipf_magic;
272 	} ipf_lkun_s;
273 #endif
274 	eMrwlock_t	ipf_emu;
275 } ipfrwlock_t;
276 
277 #define	ipf_lk		ipf_lkun_s.ipf_slk
278 #define	ipf_lname	ipf_lkun_s.ipf_lname
279 #define	ipf_isr		ipf_lkun_s.ipf_sr
280 #define	ipf_isw		ipf_lkun_s.ipf_sw
281 #define	ipf_magic	ipf_lkun_s.ipf_magic
282 
283 #if defined(__FreeBSD__) && defined(_KERNEL)
284      CTASSERT(sizeof(ipfrwlock_t) == KRWLOCK_FILL_SZ);
285      CTASSERT(sizeof(ipfmutex_t) == KMUTEX_FILL_SZ);
286 #endif
287 
288 
289 /*
290  * In a non-kernel environment, there are a lot of macros that need to be
291  * filled in to be null-ops or to point to some compatibility function,
292  * somewhere in userland.
293  */
294 #ifndef _KERNEL
295 typedef	struct	mb_s	{
296 	struct	mb_s	*mb_next;
297 	char		*mb_data;
298 	void		*mb_ifp;
299 	int		mb_len;
300 	int		mb_flags;
301 	u_long		mb_buf[2048];
302 } mb_t;
303 # undef		m_next
304 # define	m_next		mb_next
305 # undef		m_len
306 # define	m_len		mb_len
307 # undef		m_flags
308 # define	m_flags		mb_flags
309 # undef		m_data
310 # define	m_data		mb_data
311 # undef		M_MCAST
312 # define	M_MCAST		0x01
313 # undef		M_BCAST
314 # define	M_BCAST		0x02
315 # undef		M_MBCAST
316 # define	M_MBCAST	0x04
317 # define	MSGDSIZE(m)	msgdsize(m)
318 # define	M_LEN(m)	(m)->mb_len
319 # define	M_ADJ(m,x)	(m)->mb_len += x
320 # define	M_COPY(m)	dupmbt(m)
321 # define	M_DUP(m)	dupmbt(m)
322 # define	GETKTIME(x)	gettimeofday((struct timeval *)(x), NULL)
323 # define	MTOD(m, t)	((t)(m)->mb_data)
324 # define	FREE_MB_T(m)	freembt(m)
325 # define	ALLOC_MB_T(m,l)	(m) = allocmbt(l)
326 # define	PREP_MB_T(f, m)	do { \
327 						(m)->mb_next = *(f)->fin_mp; \
328 						*(fin)->fin_mp = (m); \
329 						(f)->fin_m = (m); \
330 					} while (0)
331 # define	SLEEP(x,y)	1;
332 # define	WAKEUP(x,y)	;
333 # define	POLLWAKEUP(y)	;
334 # define	IPF_PANIC(x,y)	;
335 # define	PANIC(x,y)	;
336 # define	SPL_SCHED(x)	;
337 # define	SPL_NET(x)	;
338 # define	SPL_IMP(x)	;
339 # define	SPL_X(x)	;
340 # define	KMALLOC(a,b)	(a) = (b)malloc(sizeof(*a))
341 # define	KMALLOCS(a,b,c)	(a) = (b)malloc(c)
342 # define	KFREE(x)	free(x)
343 # define	KFREES(x,s)	free(x)
344 # define	GETIFP(x, v)	get_unit(x,v)
345 # define	GETIFMTU_4(x)	2048
346 # define	GETIFMTU_6(x)	2048
347 # define	COPYIN(a,b,c)	bcopywrap((a), (b), (c))
348 # define	COPYOUT(a,b,c)	bcopywrap((a), (b), (c))
349 # define	COPYDATA(m, o, l, b)	bcopy(MTOD((mb_t *)m, char *) + (o), \
350 					      (b), (l))
351 # define	COPYBACK(m, o, l, b)	bcopy((b), \
352 					      MTOD((mb_t *)m, char *) + (o), \
353 					      (l))
354 # define	UIOMOVE(a,b,c,d)	ipfuiomove((caddr_t)a,b,c,d)
355 extern	void	m_copydata(mb_t *, int, int, caddr_t);
356 extern	int	ipfuiomove(caddr_t, int, int, struct uio *);
357 extern	int	bcopywrap(void *, void *, size_t);
358 extern	mb_t	*allocmbt(size_t);
359 extern	mb_t	*dupmbt(mb_t *);
360 extern	void	freembt(mb_t *);
361 
362 # define	MUTEX_DESTROY(x)	eMmutex_destroy(&(x)->ipf_emu, \
363 							__FILE__, __LINE__)
364 # define	MUTEX_ENTER(x)		eMmutex_enter(&(x)->ipf_emu, \
365 						      __FILE__, __LINE__)
366 # define	MUTEX_EXIT(x)		eMmutex_exit(&(x)->ipf_emu, \
367 						     __FILE__, __LINE__)
368 # define	MUTEX_INIT(x,y)		eMmutex_init(&(x)->ipf_emu, y, \
369 						     __FILE__, __LINE__)
370 # define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
371 
372 # define	MUTEX_DOWNGRADE(x)	eMrwlock_downgrade(&(x)->ipf_emu, \
373 							   __FILE__, __LINE__)
374 # define	MUTEX_TRY_UPGRADE(x)	eMrwlock_try_upgrade(&(x)->ipf_emu, \
375 							   __FILE__, __LINE__)
376 # define	READ_ENTER(x)		eMrwlock_read_enter(&(x)->ipf_emu, \
377 							    __FILE__, __LINE__)
378 # define	RWLOCK_INIT(x, y)	eMrwlock_init(&(x)->ipf_emu, y)
379 # define	RWLOCK_EXIT(x)		eMrwlock_exit(&(x)->ipf_emu)
380 # define	RW_DESTROY(x)		eMrwlock_destroy(&(x)->ipf_emu)
381 # define	WRITE_ENTER(x)		eMrwlock_write_enter(&(x)->ipf_emu, \
382 							     __FILE__, \
383 							     __LINE__)
384 
385 # define	USE_MUTEXES		1
386 
387 extern void eMmutex_destroy(eMmutex_t *, char *, int);
388 extern void eMmutex_enter(eMmutex_t *, char *, int);
389 extern void eMmutex_exit(eMmutex_t *, char *, int);
390 extern void eMmutex_init(eMmutex_t *, char *, char *, int);
391 extern void eMrwlock_destroy(eMrwlock_t *);
392 extern void eMrwlock_exit(eMrwlock_t *);
393 extern void eMrwlock_init(eMrwlock_t *, char *);
394 extern void eMrwlock_read_enter(eMrwlock_t *, char *, int);
395 extern void eMrwlock_write_enter(eMrwlock_t *, char *, int);
396 extern void eMrwlock_downgrade(eMrwlock_t *, char *, int);
397 
398 #endif
399 
400 extern	mb_t	*allocmbt(size_t);
401 
402 #define	MAX_IPV4HDR	((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
403 
404 #ifndef	IP_OFFMASK
405 # define	IP_OFFMASK	0x1fff
406 #endif
407 
408 
409 /*
410  * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
411  * object.
412  */
413 #if !defined(__amd64__) && !SOLARIS
414 # define	USE_QUAD_T
415 # define	U_QUAD_T	unsigned long long
416 # define	QUAD_T		long long
417 #else /* BSD  */
418 # if !defined(U_QUAD_T)
419 #  define	U_QUAD_T	u_long
420 #  define	QUAD_T		long
421 # endif
422 #endif /* BSD */
423 
424 
425 #ifdef	USE_INET6
426 # if defined(__NetBSD__) || defined(__FreeBSD__)
427 #  include <netinet/ip6.h>
428 #  include <netinet/icmp6.h>
429 #   if defined(_KERNEL)
430 #    include <netinet6/ip6_var.h>
431 #   endif
432 typedef	struct ip6_hdr	ip6_t;
433 # endif
434 #endif
435 
436 #ifndef	MAX
437 # define	MAX(a,b)	(((a) > (b)) ? (a) : (b))
438 #endif
439 
440 #if defined(_KERNEL)
441 # if SOLARIS && !defined(INSTANCES)
442 #  define	COPYDATA	mb_copydata
443 #  define	COPYBACK	mb_copyback
444 # else
445 #  define	COPYDATA	m_copydata
446 #  define	COPYBACK	m_copyback
447 # endif
448 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
449       defined(__FreeBSD__)
450 #  include <vm/vm.h>
451 # endif
452 # if NETBSD_GE_REV(105180000)
453 #  include <uvm/uvm_extern.h>
454 # else
455 #  include <vm/vm_extern.h>
456 extern  vm_map_t        kmem_map;
457 # endif
458 # include <sys/proc.h>
459 
460 # ifdef IPFILTER_M_IPFILTER
461 #  include <sys/malloc.h>
462 MALLOC_DECLARE(M_IPFILTER);
463 #  define	_M_IPF		M_IPFILTER
464 # else /* IPFILTER_M_IPFILTER */
465 #  ifdef M_PFIL
466 #   define	_M_IPF		M_PFIL
467 #  else
468 #   ifdef M_IPFILTER
469 #    define	_M_IPF		M_IPFILTER
470 #   else
471 #    define	_M_IPF		M_TEMP
472 #   endif /* M_IPFILTER */
473 #  endif /* M_PFIL */
474 # endif /* IPFILTER_M_IPFILTER */
475 # if !defined(KMALLOC)
476 #  define	KMALLOC(a, b)		(a) = (b)malloc(sizeof(*(a)), _M_IPF, M_NOWAIT)
477 # endif
478 # if !defined(KMALLOCS)
479 #  define	KMALLOCS(a, b, c)	(a) = (b)malloc((c), _M_IPF, M_NOWAIT)
480 # endif
481 # if !defined(KFREE)
482 #  define	KFREE(x)	free((x), _M_IPF)
483 # endif
484 # if !defined(KFREES)
485 #  define	KFREES(x,s)	free((x), _M_IPF)
486 # endif
487 # define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,d)
488 # define	SLEEP(id, n)	tsleep((id), PPAUSE|PCATCH, n, 0)
489 # define	WAKEUP(id,x)	wakeup(id+x)
490 # if !defined(POLLWAKEUP)
491 #  define	POLLWAKEUP(x)	selwakeup(softc->ipf_selwait+x)
492 # endif
493 # define	GETIFP(n, v)	ifunit(n)
494 # define	GETIFMTU_4(x)	((struct ifnet *)x)->if_mtu
495 # define	GETIFMTU_6(x)	((struct ifnet *)x)->if_mtu
496 
497 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
498 #  define	SPL_IMP(x)	x = splimp()
499 #  define	SPL_NET(x)	x = splnet()
500 #  if !defined(SPL_SCHED)
501 #   define	SPL_SCHED(x)	x = splsched()
502 #  endif
503 #  define	SPL_X(x)	(void) splx(x)
504 # endif /* !USE_MUTEXES */
505 
506 # ifndef FREE_MB_T
507 #  define	FREE_MB_T(m)	m_freem(m)
508 # endif
509 # ifndef ALLOC_MB_T
510 #  ifdef MGETHDR
511 #   define	ALLOC_MB_T(m,l)	do { \
512 					MGETHDR((m), M_NOWAIT, MT_HEADER); \
513 					if ((m) != NULL) { \
514 						(m)->m_len = (l); \
515 						(m)->m_pkthdr.len = (l); \
516 					} \
517 				} while (0)
518 #  else
519 #   define	ALLOC_MB_T(m,l)	do { \
520 					MGET((m), M_NOWAIT, MT_HEADER); \
521 					if ((m) != NULL) { \
522 						(m)->m_len = (l); \
523 						(m)->m_pkthdr.len = (l); \
524 					} \
525 				} while (0)
526 #  endif
527 # endif
528 # ifndef PREP_MB_T
529 #  define	PREP_MB_T(f, m)	do { \
530 						mb_t *_o = *(f)->fin_mp; \
531 						(m)->m_next = _o; \
532 						*(fin)->fin_mp = (m); \
533 						if (_o->m_flags & M_PKTHDR) { \
534 							(m)->m_pkthdr.len += \
535 							    _o->m_pkthdr.len; \
536 							(m)->m_pkthdr.rcvif = \
537 							  _o->m_pkthdr.rcvif; \
538 						} \
539 					} while (0)
540 # endif
541 # ifndef M_DUP
542 #  ifdef M_COPYALL
543 #   define	M_DUP(m)	m_dup(m, 0, M_COPYALL, 0)
544 #  else
545 #   define	M_DUP(m)	m_dup(m)
546 #  endif
547 # endif
548 
549 # ifndef MTOD
550 #  define	MTOD(m,t)	mtod(m,t)
551 # endif
552 
553 # ifndef COPYIN
554 #  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
555 #  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
556 # endif
557 
558 # if SOLARIS && !defined(KMALLOC)
559 #  define	KMALLOC(a,b)	(a) = (b)new_kmem_alloc(sizeof(*(a)), \
560 							KMEM_NOSLEEP)
561 #  define	KMALLOCS(a,b,c)	(a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
562 # endif
563 
564 # ifndef	GET_MINOR
565 #  define	GET_MINOR(x)	dev2unit(x)
566 # endif
567 # define	PANIC(x,y)	if (x) panic y
568 #endif /* _KERNEL */
569 
570 #if !defined(IFNAME) && !defined(_KERNEL)
571 # define	IFNAME(x)	get_ifname((struct ifnet *)x)
572 #endif
573 #ifndef	COPYIFNAME
574 # define	NEED_FRGETIFNAME
575 extern	char	*ipf_getifname(struct ifnet *, char *);
576 # define	COPYIFNAME(v, x, b) \
577 				ipf_getifname((struct ifnet *)x, b)
578 #endif
579 
580 #ifndef ASSERT
581 # ifdef _KERNEL
582 #  define	ASSERT(x)
583 # else
584 #  define	ASSERT(x)	do { if (!(x)) abort(); } while (0)
585 # endif
586 #endif
587 
588 #ifndef BCOPYIN
589 #  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
590 #  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
591 #endif
592 
593 /*
594  * Because the ctype(3) posix definition, if used "safely" in code everywhere,
595  * would mean all normal code that walks through strings needed casts.  Yuck.
596  */
597 #define	ISALNUM(x)	isalnum((u_char)(x))
598 #define	ISALPHA(x)	isalpha((u_char)(x))
599 #define	ISDIGIT(x)	isdigit((u_char)(x))
600 #define	ISSPACE(x)	isspace((u_char)(x))
601 #define	ISUPPER(x)	isupper((u_char)(x))
602 #define	ISXDIGIT(x)	isxdigit((u_char)(x))
603 #define	ISLOWER(x)	islower((u_char)(x))
604 #define	TOUPPER(x)	toupper((u_char)(x))
605 #define	TOLOWER(x)	tolower((u_char)(x))
606 
607 /*
608  * If mutexes aren't being used, turn all the mutex functions into null-ops.
609  */
610 #if !defined(USE_MUTEXES)
611 # define	USE_SPL			1
612 # undef		RW_DESTROY
613 # undef		MUTEX_INIT
614 # undef		MUTEX_NUKE
615 # undef		MUTEX_DESTROY
616 # define	MUTEX_ENTER(x)		;
617 # define	READ_ENTER(x)		;
618 # define	WRITE_ENTER(x)		;
619 # define	MUTEX_DOWNGRADE(x)	;
620 # define	MUTEX_TRY_UPGRADE(x)	;
621 # define	RWLOCK_INIT(x, y)	;
622 # define	RWLOCK_EXIT(x)		;
623 # define	RW_DESTROY(x)		;
624 # define	MUTEX_EXIT(x)		;
625 # define	MUTEX_INIT(x,y)		;
626 # define	MUTEX_DESTROY(x)	;
627 # define	MUTEX_NUKE(x)		;
628 #endif /* !USE_MUTEXES */
629 #ifndef	ATOMIC_INC
630 # define	ATOMIC_INC(x)		(x)++
631 # define	ATOMIC_DEC(x)		(x)--
632 #endif
633 
634 #if defined(USE_SPL) && defined(_KERNEL)
635 # define	SPL_INT(x)	int x
636 #else
637 # define	SPL_INT(x)
638 #endif
639 
640 /*
641  * If there are no atomic operations for bit sizes defined, define them to all
642  * use a generic one that works for all sizes.
643  */
644 #ifndef	ATOMIC_INCL
645 # define	ATOMIC_INCL		ATOMIC_INC
646 # define	ATOMIC_INC64		ATOMIC_INC
647 # define	ATOMIC_INC32		ATOMIC_INC
648 # define	ATOMIC_DECL		ATOMIC_DEC
649 # define	ATOMIC_DEC64		ATOMIC_DEC
650 # define	ATOMIC_DEC32		ATOMIC_DEC
651 #endif
652 
653 #ifndef HDR_T_PRIVATE
654 typedef	struct	tcphdr	tcphdr_t;
655 typedef	struct	udphdr	udphdr_t;
656 #endif
657 typedef	struct	icmp	icmphdr_t;
658 typedef	struct	ip	ip_t;
659 typedef	struct	ether_header	ether_header_t;
660 typedef	struct	tcpiphdr	tcpiphdr_t;
661 
662 #ifndef	FR_GROUPLEN
663 # define	FR_GROUPLEN	16
664 #endif
665 
666 #ifndef offsetof
667 # define offsetof(t,m) (size_t)((&((t *)0L)->m))
668 #endif
669 #ifndef stsizeof
670 # define stsizeof(t,m)	sizeof(((t *)0L)->m)
671 #endif
672 
673 /*
674  * This set of macros has been brought about because on Tru64 it is not
675  * possible to easily assign or examine values in a structure that are
676  * bit fields.
677  */
678 #ifndef IP_V
679 # define	IP_V(x)		(x)->ip_v
680 #endif
681 #ifndef	IP_V_A
682 # define	IP_V_A(x,y)	(x)->ip_v = (y)
683 #endif
684 #ifndef	IP_HL
685 # define	IP_HL(x)	(x)->ip_hl
686 #endif
687 #ifndef	IP_HL_A
688 # define	IP_HL_A(x,y)	(x)->ip_hl = ((y) & 0xf)
689 #endif
690 #ifndef	TCP_OFF
691 # define	TCP_OFF(x)	(x)->th_off
692 #endif
693 #ifndef	TCP_OFF_A
694 # define	TCP_OFF_A(x,y)	(x)->th_off = (y)
695 #endif
696 #define	IPMINLEN(i, h)	((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
697 
698 #if !SOLARIS && !defined(m_act)
699 # define	m_act	m_nextpkt
700 #endif
701 
702 /*
703  * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
704  *
705  * Basic Option
706  *
707  * 00000001   -   (Reserved 4)
708  * 00111101   -   Top Secret
709  * 01011010   -   Secret
710  * 10010110   -   Confidential
711  * 01100110   -   (Reserved 3)
712  * 11001100   -   (Reserved 2)
713  * 10101011   -   Unclassified
714  * 11110001   -   (Reserved 1)
715  */
716 #define	IPSO_CLASS_RES4		0x01
717 #define	IPSO_CLASS_TOPS		0x3d
718 #define	IPSO_CLASS_SECR		0x5a
719 #define	IPSO_CLASS_CONF		0x96
720 #define	IPSO_CLASS_RES3		0x66
721 #define	IPSO_CLASS_RES2		0xcc
722 #define	IPSO_CLASS_UNCL		0xab
723 #define	IPSO_CLASS_RES1		0xf1
724 
725 #define	IPSO_AUTH_GENSER	0x80
726 #define	IPSO_AUTH_ESI		0x40
727 #define	IPSO_AUTH_SCI		0x20
728 #define	IPSO_AUTH_NSA		0x10
729 #define	IPSO_AUTH_DOE		0x08
730 #define	IPSO_AUTH_UN		0x06
731 #define	IPSO_AUTH_FTE		0x01
732 
733 /*
734  * IP option #defines
735  */
736 #undef	IPOPT_RR
737 #define	IPOPT_RR	7
738 #undef	IPOPT_ZSU
739 #define	IPOPT_ZSU	10	/* ZSU */
740 #undef	IPOPT_MTUP
741 #define	IPOPT_MTUP	11	/* MTUP */
742 #undef	IPOPT_MTUR
743 #define	IPOPT_MTUR	12	/* MTUR */
744 #undef	IPOPT_ENCODE
745 #define	IPOPT_ENCODE	15	/* ENCODE */
746 #undef	IPOPT_TS
747 #define	IPOPT_TS	68
748 #undef	IPOPT_TR
749 #define	IPOPT_TR	82	/* TR */
750 #undef	IPOPT_SECURITY
751 #define	IPOPT_SECURITY	130
752 #undef	IPOPT_LSRR
753 #define	IPOPT_LSRR	131
754 #undef	IPOPT_E_SEC
755 #define	IPOPT_E_SEC	133	/* E-SEC */
756 #undef	IPOPT_CIPSO
757 #define	IPOPT_CIPSO	134	/* CIPSO */
758 #undef	IPOPT_SATID
759 #define	IPOPT_SATID	136
760 #ifndef	IPOPT_SID
761 # define	IPOPT_SID	IPOPT_SATID
762 #endif
763 #undef	IPOPT_SSRR
764 #define	IPOPT_SSRR	137
765 #undef	IPOPT_ADDEXT
766 #define	IPOPT_ADDEXT	147	/* ADDEXT */
767 #undef	IPOPT_VISA
768 #define	IPOPT_VISA	142	/* VISA */
769 #undef	IPOPT_IMITD
770 #define	IPOPT_IMITD	144	/* IMITD */
771 #undef	IPOPT_EIP
772 #define	IPOPT_EIP	145	/* EIP */
773 #undef	IPOPT_RTRALRT
774 #define	IPOPT_RTRALRT	148	/* RTRALRT */
775 #undef	IPOPT_SDB
776 #define	IPOPT_SDB	149
777 #undef	IPOPT_NSAPA
778 #define	IPOPT_NSAPA	150
779 #undef	IPOPT_DPS
780 #define	IPOPT_DPS	151
781 #undef	IPOPT_UMP
782 #define	IPOPT_UMP	152
783 #undef	IPOPT_FINN
784 #define	IPOPT_FINN	205	/* FINN */
785 #undef	IPOPT_AH
786 #define	IPOPT_AH	256+IPPROTO_AH
787 
788 #define	ICMP_UNREACH_ADMIN_PROHIBIT	ICMP_UNREACH_FILTER_PROHIB
789 #define	ICMP_UNREACH_FILTER	ICMP_UNREACH_FILTER_PROHIB
790 
791 #ifndef	IPVERSION
792 # define	IPVERSION	4
793 #endif
794 #ifndef	IPOPT_MINOFF
795 # define	IPOPT_MINOFF	4
796 #endif
797 #ifndef	IPOPT_COPIED
798 # define	IPOPT_COPIED(x)	((x)&0x80)
799 #endif
800 #ifndef	IPOPT_EOL
801 # define	IPOPT_EOL	0
802 #endif
803 #ifndef	IPOPT_NOP
804 # define	IPOPT_NOP	1
805 #endif
806 #ifndef	IP_MF
807 # define	IP_MF	((u_short)0x2000)
808 #endif
809 #ifndef	ETHERTYPE_IP
810 # define	ETHERTYPE_IP	((u_short)0x0800)
811 #endif
812 #ifndef	TH_FIN
813 # define	TH_FIN	0x01
814 #endif
815 #ifndef	TH_SYN
816 # define	TH_SYN	0x02
817 #endif
818 #ifndef	TH_RST
819 # define	TH_RST	0x04
820 #endif
821 #ifndef	TH_PUSH
822 # define	TH_PUSH	0x08
823 #endif
824 #ifndef	TH_ACK
825 # define	TH_ACK	0x10
826 #endif
827 #ifndef	TH_URG
828 # define	TH_URG	0x20
829 #endif
830 #undef	TH_ACKMASK
831 #define	TH_ACKMASK	(TH_FIN|TH_SYN|TH_RST|TH_ACK)
832 
833 #ifndef	IPOPT_EOL
834 # define	IPOPT_EOL	0
835 #endif
836 #ifndef	IPOPT_NOP
837 # define	IPOPT_NOP	1
838 #endif
839 #ifndef	IPOPT_RR
840 # define	IPOPT_RR	7
841 #endif
842 #ifndef	IPOPT_TS
843 # define	IPOPT_TS	68
844 #endif
845 #ifndef	IPOPT_SECURITY
846 # define	IPOPT_SECURITY	130
847 #endif
848 #ifndef	IPOPT_LSRR
849 # define	IPOPT_LSRR	131
850 #endif
851 #ifndef	IPOPT_SATID
852 # define	IPOPT_SATID	136
853 #endif
854 #ifndef	IPOPT_SSRR
855 # define	IPOPT_SSRR	137
856 #endif
857 #ifndef	IPOPT_SECUR_UNCLASS
858 # define	IPOPT_SECUR_UNCLASS	((u_short)0x0000)
859 #endif
860 #ifndef	IPOPT_SECUR_CONFID
861 # define	IPOPT_SECUR_CONFID	((u_short)0xf135)
862 #endif
863 #ifndef	IPOPT_SECUR_EFTO
864 # define	IPOPT_SECUR_EFTO	((u_short)0x789a)
865 #endif
866 #ifndef	IPOPT_SECUR_MMMM
867 # define	IPOPT_SECUR_MMMM	((u_short)0xbc4d)
868 #endif
869 #ifndef	IPOPT_SECUR_RESTR
870 # define	IPOPT_SECUR_RESTR	((u_short)0xaf13)
871 #endif
872 #ifndef	IPOPT_SECUR_SECRET
873 # define	IPOPT_SECUR_SECRET	((u_short)0xd788)
874 #endif
875 #ifndef IPOPT_SECUR_TOPSECRET
876 # define	IPOPT_SECUR_TOPSECRET	((u_short)0x6bc5)
877 #endif
878 #ifndef IPOPT_OLEN
879 # define	IPOPT_OLEN	1
880 #endif
881 #ifndef	IPPROTO_HOPOPTS
882 # define	IPPROTO_HOPOPTS	0
883 #endif
884 #ifndef	IPPROTO_IPIP
885 # define	IPPROTO_IPIP	4
886 #endif
887 #ifndef	IPPROTO_ENCAP
888 # define	IPPROTO_ENCAP	98
889 #endif
890 #ifndef	IPPROTO_IPV6
891 # define	IPPROTO_IPV6	41
892 #endif
893 #ifndef	IPPROTO_ROUTING
894 # define	IPPROTO_ROUTING	43
895 #endif
896 #ifndef	IPPROTO_FRAGMENT
897 # define	IPPROTO_FRAGMENT	44
898 #endif
899 #ifndef	IPPROTO_GRE
900 # define	IPPROTO_GRE	47	/* GRE encaps RFC 1701 */
901 #endif
902 #ifndef	IPPROTO_ESP
903 # define	IPPROTO_ESP	50
904 #endif
905 #ifndef	IPPROTO_AH
906 # define	IPPROTO_AH	51
907 #endif
908 #ifndef	IPPROTO_ICMPV6
909 # define	IPPROTO_ICMPV6	58
910 #endif
911 #ifndef	IPPROTO_NONE
912 # define	IPPROTO_NONE	59
913 #endif
914 #ifndef	IPPROTO_DSTOPTS
915 # define	IPPROTO_DSTOPTS	60
916 #endif
917 #ifndef	IPPROTO_MOBILITY
918 # define	IPPROTO_MOBILITY	135
919 #endif
920 
921 #ifndef	ICMP_ROUTERADVERT
922 # define	ICMP_ROUTERADVERT	9
923 #endif
924 #ifndef	ICMP_ROUTERSOLICIT
925 # define	ICMP_ROUTERSOLICIT	10
926 #endif
927 #ifndef	ICMP6_DST_UNREACH
928 # define	ICMP6_DST_UNREACH	1
929 #endif
930 #ifndef	ICMP6_PACKET_TOO_BIG
931 # define	ICMP6_PACKET_TOO_BIG	2
932 #endif
933 #ifndef	ICMP6_TIME_EXCEEDED
934 # define	ICMP6_TIME_EXCEEDED	3
935 #endif
936 #ifndef	ICMP6_PARAM_PROB
937 # define	ICMP6_PARAM_PROB	4
938 #endif
939 
940 #ifndef	ICMP6_ECHO_REQUEST
941 # define	ICMP6_ECHO_REQUEST	128
942 #endif
943 #ifndef	ICMP6_ECHO_REPLY
944 # define	ICMP6_ECHO_REPLY	129
945 #endif
946 #ifndef	ICMP6_MEMBERSHIP_QUERY
947 # define	ICMP6_MEMBERSHIP_QUERY	130
948 #endif
949 #ifndef	MLD6_LISTENER_QUERY
950 # define	MLD6_LISTENER_QUERY	130
951 #endif
952 #ifndef	ICMP6_MEMBERSHIP_REPORT
953 # define	ICMP6_MEMBERSHIP_REPORT	131
954 #endif
955 #ifndef	MLD6_LISTENER_REPORT
956 # define	MLD6_LISTENER_REPORT	131
957 #endif
958 #ifndef	ICMP6_MEMBERSHIP_REDUCTION
959 # define	ICMP6_MEMBERSHIP_REDUCTION	132
960 #endif
961 #ifndef	MLD6_LISTENER_DONE
962 # define	MLD6_LISTENER_DONE	132
963 #endif
964 #ifndef	ND_ROUTER_SOLICIT
965 # define	ND_ROUTER_SOLICIT	133
966 #endif
967 #ifndef	ND_ROUTER_ADVERT
968 # define	ND_ROUTER_ADVERT	134
969 #endif
970 #ifndef	ND_NEIGHBOR_SOLICIT
971 # define	ND_NEIGHBOR_SOLICIT	135
972 #endif
973 #ifndef	ND_NEIGHBOR_ADVERT
974 # define	ND_NEIGHBOR_ADVERT	136
975 #endif
976 #ifndef	ND_REDIRECT
977 # define	ND_REDIRECT	137
978 #endif
979 #ifndef	ICMP6_ROUTER_RENUMBERING
980 # define	ICMP6_ROUTER_RENUMBERING	138
981 #endif
982 #ifndef	ICMP6_WRUREQUEST
983 # define	ICMP6_WRUREQUEST	139
984 #endif
985 #ifndef	ICMP6_WRUREPLY
986 # define	ICMP6_WRUREPLY		140
987 #endif
988 #ifndef	ICMP6_FQDN_QUERY
989 # define	ICMP6_FQDN_QUERY	139
990 #endif
991 #ifndef	ICMP6_FQDN_REPLY
992 # define	ICMP6_FQDN_REPLY	140
993 #endif
994 #ifndef	ICMP6_NI_QUERY
995 # define	ICMP6_NI_QUERY		139
996 #endif
997 #ifndef	ICMP6_NI_REPLY
998 # define	ICMP6_NI_REPLY		140
999 #endif
1000 #ifndef	MLD6_MTRACE_RESP
1001 # define	MLD6_MTRACE_RESP	200
1002 #endif
1003 #ifndef	MLD6_MTRACE
1004 # define	MLD6_MTRACE		201
1005 #endif
1006 #ifndef	ICMP6_HADISCOV_REQUEST
1007 # define	ICMP6_HADISCOV_REQUEST	202
1008 #endif
1009 #ifndef	ICMP6_HADISCOV_REPLY
1010 # define	ICMP6_HADISCOV_REPLY	203
1011 #endif
1012 #ifndef	ICMP6_MOBILEPREFIX_SOLICIT
1013 # define	ICMP6_MOBILEPREFIX_SOLICIT	204
1014 #endif
1015 #ifndef	ICMP6_MOBILEPREFIX_ADVERT
1016 # define	ICMP6_MOBILEPREFIX_ADVERT	205
1017 #endif
1018 #ifndef	ICMP6_MAXTYPE
1019 # define	ICMP6_MAXTYPE		205
1020 #endif
1021 
1022 #ifndef	ICMP6_DST_UNREACH_NOROUTE
1023 # define	ICMP6_DST_UNREACH_NOROUTE	0
1024 #endif
1025 #ifndef	ICMP6_DST_UNREACH_ADMIN
1026 # define	ICMP6_DST_UNREACH_ADMIN		1
1027 #endif
1028 #ifndef	ICMP6_DST_UNREACH_NOTNEIGHBOR
1029 # define	ICMP6_DST_UNREACH_NOTNEIGHBOR	2
1030 #endif
1031 #ifndef	ICMP6_DST_UNREACH_BEYONDSCOPE
1032 # define	ICMP6_DST_UNREACH_BEYONDSCOPE	2
1033 #endif
1034 #ifndef	ICMP6_DST_UNREACH_ADDR
1035 # define	ICMP6_DST_UNREACH_ADDR		3
1036 #endif
1037 #ifndef	ICMP6_DST_UNREACH_NOPORT
1038 # define	ICMP6_DST_UNREACH_NOPORT	4
1039 #endif
1040 #ifndef	ICMP6_TIME_EXCEED_TRANSIT
1041 # define	ICMP6_TIME_EXCEED_TRANSIT	0
1042 #endif
1043 #ifndef	ICMP6_TIME_EXCEED_REASSEMBLY
1044 # define	ICMP6_TIME_EXCEED_REASSEMBLY	1
1045 #endif
1046 
1047 #ifndef	ICMP6_NI_SUCCESS
1048 # define	ICMP6_NI_SUCCESS	0
1049 #endif
1050 #ifndef	ICMP6_NI_REFUSED
1051 # define	ICMP6_NI_REFUSED	1
1052 #endif
1053 #ifndef	ICMP6_NI_UNKNOWN
1054 # define	ICMP6_NI_UNKNOWN	2
1055 #endif
1056 
1057 #ifndef	ICMP6_ROUTER_RENUMBERING_COMMAND
1058 # define	ICMP6_ROUTER_RENUMBERING_COMMAND	0
1059 #endif
1060 #ifndef	ICMP6_ROUTER_RENUMBERING_RESULT
1061 # define	ICMP6_ROUTER_RENUMBERING_RESULT	1
1062 #endif
1063 #ifndef	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1064 # define	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET	255
1065 #endif
1066 
1067 #ifndef	ICMP6_PARAMPROB_HEADER
1068 # define	ICMP6_PARAMPROB_HEADER	0
1069 #endif
1070 #ifndef	ICMP6_PARAMPROB_NEXTHEADER
1071 # define	ICMP6_PARAMPROB_NEXTHEADER	1
1072 #endif
1073 #ifndef	ICMP6_PARAMPROB_OPTION
1074 # define	ICMP6_PARAMPROB_OPTION	2
1075 #endif
1076 
1077 #ifndef	ICMP6_NI_SUBJ_IPV6
1078 # define	ICMP6_NI_SUBJ_IPV6	0
1079 #endif
1080 #ifndef	ICMP6_NI_SUBJ_FQDN
1081 # define	ICMP6_NI_SUBJ_FQDN	1
1082 #endif
1083 #ifndef	ICMP6_NI_SUBJ_IPV4
1084 # define	ICMP6_NI_SUBJ_IPV4	2
1085 #endif
1086 
1087 #ifndef	MLD_MTRACE_RESP
1088 # define	MLD_MTRACE_RESP		200
1089 #endif
1090 #ifndef	MLD_MTRACE
1091 # define	MLD_MTRACE		201
1092 #endif
1093 #ifndef	MLD6_MTRACE_RESP
1094 # define	MLD6_MTRACE_RESP	MLD_MTRACE_RESP
1095 #endif
1096 #ifndef	MLD6_MTRACE
1097 # define	MLD6_MTRACE		MLD_MTRACE
1098 #endif
1099 
1100 #if !defined(IPV6_FLOWINFO_MASK)
1101 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1102 #  define IPV6_FLOWINFO_MASK	0x0fffffff	/* flow info (28 bits) */
1103 # else
1104 #  if(BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1105 #   define IPV6_FLOWINFO_MASK	0xffffff0f	/* flow info (28 bits) */
1106 #  endif /* LITTLE_ENDIAN */
1107 # endif
1108 #endif
1109 #if !defined(IPV6_FLOWLABEL_MASK)
1110 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1111 #  define IPV6_FLOWLABEL_MASK	0x000fffff	/* flow label (20 bits) */
1112 # else
1113 #  if (BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1114 #   define IPV6_FLOWLABEL_MASK	0xffff0f00	/* flow label (20 bits) */
1115 #  endif /* LITTLE_ENDIAN */
1116 # endif
1117 #endif
1118 
1119 /*
1120  * ECN is a new addition to TCP - RFC 2481
1121  */
1122 #ifndef TH_ECN
1123 # define	TH_ECN	0x40
1124 #endif
1125 #ifndef TH_CWR
1126 # define	TH_CWR	0x80
1127 #endif
1128 #ifndef TH_AE
1129 # define	TH_AE	0x100
1130 #endif
1131 #define	TH_ECNALL	(TH_ECN|TH_CWR|TH_AE)
1132 
1133 /*
1134  * TCP States
1135  */
1136 #define IPF_TCPS_LISTEN		0	/* listening for connection */
1137 #define IPF_TCPS_SYN_SENT	1	/* active, have sent syn */
1138 #define IPF_TCPS_SYN_RECEIVED	2	/* have send and received syn */
1139 #define IPF_TCPS_HALF_ESTAB	3	/* for connections not fully "up" */
1140 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
1141 #define IPF_TCPS_ESTABLISHED	4	/* established */
1142 #define IPF_TCPS_CLOSE_WAIT	5	/* rcvd fin, waiting for close */
1143 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
1144 #define IPF_TCPS_FIN_WAIT_1	6	/* have closed, sent fin */
1145 #define IPF_TCPS_CLOSING	7	/* closed xchd FIN; await FIN ACK */
1146 #define IPF_TCPS_LAST_ACK	8	/* had fin and close; await FIN ACK */
1147 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
1148 #define IPF_TCPS_FIN_WAIT_2	9	/* have closed, fin is acked */
1149 #define IPF_TCPS_TIME_WAIT	10	/* in 2*msl quiet wait after close */
1150 #define IPF_TCPS_CLOSED		11	/* closed */
1151 #define IPF_TCP_NSTATES		12
1152 
1153 #define	TCP_MSL			120
1154 
1155 #undef	ICMP_MAX_UNREACH
1156 #define	ICMP_MAX_UNREACH	14
1157 #undef	ICMP_MAXTYPE
1158 #define	ICMP_MAXTYPE		18
1159 
1160 #ifndef	LOG_FTP
1161 # define	LOG_FTP		(11<<3)
1162 #endif
1163 #ifndef	LOG_AUTHPRIV
1164 # define	LOG_AUTHPRIV	(10<<3)
1165 #endif
1166 #ifndef	LOG_AUDIT
1167 # define	LOG_AUDIT	(13<<3)
1168 #endif
1169 #ifndef	LOG_NTP
1170 # define	LOG_NTP		(12<<3)
1171 #endif
1172 #ifndef	LOG_SECURITY
1173 # define	LOG_SECURITY	(13<<3)
1174 #endif
1175 #ifndef	LOG_LFMT
1176 # define	LOG_LFMT	(14<<3)
1177 #endif
1178 #ifndef	LOG_CONSOLE
1179 # define	LOG_CONSOLE	(14<<3)
1180 #endif
1181 
1182 /*
1183  * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1184  * another IP header and then 64 bits of data, totalling 56.  Of course,
1185  * the last 64 bits is dependent on that being available.
1186  */
1187 #define	ICMPERR_ICMPHLEN	8
1188 #define	ICMPERR_IPICMPHLEN	(20 + 8)
1189 #define	ICMPERR_MINPKTLEN	(20 + 8 + 20)
1190 #define	ICMPERR_MAXPKTLEN	(20 + 8 + 20 + 8)
1191 #define ICMP6ERR_MINPKTLEN	(40 + 8)
1192 #define ICMP6ERR_IPICMPHLEN	(40 + 8 + 40)
1193 
1194 #ifndef MIN
1195 # define	MIN(a,b)	(((a)<(b))?(a):(b))
1196 #endif
1197 
1198 #ifdef RESCUE
1199 # undef IPFILTER_BPF
1200 #endif
1201 
1202 #ifdef IPF_DEBUG
1203 # define	DPRINT(x)	printf x
1204 #else
1205 # define	DPRINT(x)
1206 #endif
1207 
1208 #if defined(DTRACE_PROBE) && defined(_KERNEL)
1209 # define	DT(_n)			DTRACE_PROBE(_n)
1210 # define	DT1(_n,_a,_b)		DTRACE_PROBE1(_n,_a,_b)
1211 # define	DT2(_n,_a,_b,_c,_d)	DTRACE_PROBE2(_n,_a,_b,_c,_d)
1212 # define	DT3(_n,_a,_b,_c,_d,_e,_f)	\
1213 					DTRACE_PROBE3(_n,_a,_b,_c,_d,_e,_f)
1214 # define	DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h) \
1215 				DTRACE_PROBE4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1216 # define	DT5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j) \
1217 				DTRACE_PROBE5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j)
1218 #else
1219 # define	DT(_n)
1220 # define	DT1(_n,_a,_b)
1221 # define	DT2(_n,_a,_b,_c,_d)
1222 # define	DT3(_n,_a,_b,_c,_d,_e,_f)
1223 # define	DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1224 # define	DT5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j)
1225 #endif
1226 
1227 struct ip6_routing {
1228 	u_char	ip6r_nxt;	/* next header */
1229 	u_char	ip6r_len;	/* length in units of 8 octets */
1230 	u_char	ip6r_type;	/* always zero */
1231 	u_char	ip6r_segleft;	/* segments left */
1232 	u_32_t	ip6r_reserved;	/* reserved field */
1233 };
1234 
1235 #endif	/* __IP_COMPAT_H__ */
1236