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