ip_compat.h revision 342607
1139804Simp/*
21541Srgrimes * Copyright (C) 2012 by Darren Reed.
31541Srgrimes *
41541Srgrimes * See the IPFILTER.LICENCE file for details on licencing.
51541Srgrimes *
61541Srgrimes * @(#)ip_compat.h	1.8 1/14/96
71541Srgrimes * $FreeBSD: stable/11/sys/contrib/ipfilter/netinet/ip_compat.h 342607 2018-12-30 04:37:49Z cy $
81541Srgrimes * Id: ip_compat.h,v 2.142.2.57 2007/10/10 09:51:42 darrenr Exp $
91541Srgrimes */
101541Srgrimes
111541Srgrimes#ifndef	__IP_COMPAT_H__
121541Srgrimes#define	__IP_COMPAT_H__
131541Srgrimes
141541Srgrimes#ifndef	__P
151541Srgrimes# ifdef	__STDC__
161541Srgrimes#  define	__P(x)  x
171541Srgrimes# else
181541Srgrimes#  define	__P(x)  ()
191541Srgrimes# endif
201541Srgrimes#endif
211541Srgrimes#ifndef	__STDC__
221541Srgrimes# undef		const
231541Srgrimes# define	const
241541Srgrimes#endif
251541Srgrimes
261541Srgrimes#if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
271541Srgrimes# undef	KERNEL
281541Srgrimes# undef	_KERNEL
291541Srgrimes# undef 	__KERNEL__
301541Srgrimes# define	KERNEL
311541Srgrimes# define	_KERNEL
32116182Sobrien# define 	__KERNEL__
33116182Sobrien#endif
34116182Sobrien
3577572Sobrien#ifndef	SOLARIS
36113490Ssilby# if defined(sun) && (defined(__svr4__) || defined(__SVR4))
37178674Sjulian#  define	SOLARIS		1
38101007Srwatson# else
391541Srgrimes#  define	SOLARIS		0
401541Srgrimes# endif
4176166Smarkm#endif
42125296Ssilby
4376166Smarkm
4432036Sbde#if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
451541Srgrimes# define index   strchr
4623081Swollman# if !defined(_KERNEL)
471541Srgrimes#  define	bzero(a,b)	memset(a,0,b)
481541Srgrimes#  define	bcmp		memcmp
49125296Ssilby#  define	bcopy(a,b,c)	memmove(b,a,c)
5076166Smarkm# endif
519759Sbde#endif
529759Sbde
539759Sbde#ifndef LIFNAMSIZ
549759Sbde# ifdef IF_NAMESIZE
55116455Ssilby#  define	LIFNAMSIZ	IF_NAMESIZE
56112777Ssilby# else
57112777Ssilby#  ifdef	IFNAMSIZ
58112777Ssilby#   define	LIFNAMSIZ	IFNAMSIZ
59112777Ssilby#  else
60113490Ssilby#   define	LIFNAMSIZ	16
61113490Ssilby#  endif
621541Srgrimes# endif
6366475Sbmilekic#endif
6466475Sbmilekic
6566475Sbmilekic#if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
66155820Sandrestruct  ether_addr {
67155820Sandre        u_char  ether_addr_octet[6];
68155820Sandre};
69155820Sandre#endif
70155820Sandre
71155820Sandre# ifdef __STDC__
72155820Sandre#  define IPL_EXTERN(ep) ipl##ep
73155820Sandre# else
74116455Ssilby#  define IPL_EXTERN(ep) ipl/**/ep
75112777Ssilby# endif
76112777Ssilby
77112777Ssilby/*
78112777Ssilby * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
79112777Ssilby */
80112777Ssilby# ifndef _KERNEL
81112777Ssilby#  define ADD_KERNEL
82112777Ssilby#  define _KERNEL
83113490Ssilby#  define KERNEL
84113490Ssilby# endif
85113490Ssilby# include <sys/uio.h>
8675112Sbmilekic# ifdef ADD_KERNEL
871541Srgrimes#  undef _KERNEL
88129906Sbmilekic#  undef KERNEL
89129906Sbmilekic# endif
90129906Sbmilekic
91129906Sbmilekic#define	NETBSD_GE_REV(x)	(defined(__NetBSD_Version__) && \
92129906Sbmilekic				 (__NetBSD_Version__ >= (x)))
93129906Sbmilekic#define	NETBSD_GT_REV(x)	(defined(__NetBSD_Version__) && \
94129906Sbmilekic				 (__NetBSD_Version__ > (x)))
95163915Sandre#define	NETBSD_LT_REV(x)	(defined(__NetBSD_Version__) && \
96129906Sbmilekic				 (__NetBSD_Version__ < (x)))
97163915Sandre#define	FREEBSD_GE_REV(x)	(defined(__FreeBSD_version) && \
98129906Sbmilekic				 (__FreeBSD_version >= (x)))
99163915Sandre#define	FREEBSD_GT_REV(x)	(defined(__FreeBSD_version) && \
100129906Sbmilekic				 (__FreeBSD_version > (x)))
101163915Sandre#define	FREEBSD_LT_REV(x)	(defined(__FreeBSD_version) && \
102163915Sandre				 (__FreeBSD_version < (x)))
103129906Sbmilekic#define	BSDOS_GE_REV(x)		(defined(_BSDI_VERSION) && \
104163915Sandre				 (_BSDI_VERSION >= (x)))
105163915Sandre#define	BSDOS_GT_REV(x)		(defined(_BSDI_VERSION) && \
106163915Sandre				 (_BSDI_VERSION > (x)))
107129906Sbmilekic#define	BSDOS_LT_REV(x)		(defined(_BSDI_VERSION) && \
108163915Sandre				 (_BSDI_VERSION < (x)))
109163915Sandre#define	OPENBSD_GE_REV(x)	(defined(OpenBSD) && (OpenBSD >= (x)))
110163915Sandre#define	OPENBSD_GT_REV(x)	(defined(OpenBSD) && (OpenBSD > (x)))
111163915Sandre#define	OPENBSD_LT_REV(x)	(defined(OpenBSD) && (OpenBSD < (x)))
112163915Sandre#define	BSD_GE_YEAR(x)		(defined(BSD) && (BSD >= (x)))
113163915Sandre#define	BSD_GT_YEAR(x)		(defined(BSD) && (BSD > (x)))
114163915Sandre#define	BSD_LT_YEAR(x)		(defined(BSD) && (BSD < (x)))
115163915Sandre
116163915Sandre
117129906Sbmilekic/* ----------------------------------------------------------------------- */
118163915Sandre/*                                F R E E B S D                            */
119163915Sandre/* ----------------------------------------------------------------------- */
120163915Sandre# define HAS_SYS_MD5_H	1
121163915Sandre# if defined(_KERNEL)
122163915Sandre#   include "opt_bpf.h"
123163915Sandre#   include "opt_inet6.h"
124163915Sandre#  if defined(INET6) && !defined(USE_INET6)
125163915Sandre#   define USE_INET6
126163915Sandre#  endif
127163915Sandre# else
128163915Sandre#  if !defined(USE_INET6) && !defined(NOINET6)
129163915Sandre#   define	USE_INET6
130163915Sandre#  endif
131163915Sandre# endif
132163915Sandre
133163915Sandre# if defined(_KERNEL)
134163915Sandre#  include <netinet/ip_var.h>
135163915Sandre#    define	p_cred	td_ucred
136129906Sbmilekic#    define	p_uid	td_ucred->cr_ruid
137163915Sandre
138163915Sandre/*
139129906Sbmilekic * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
140163915Sandre * There may be other, safe, kernels but this is not extensively tested yet.
141163915Sandre */
142163915Sandre#   define HAVE_M_PULLDOWN
143163915Sandre#  if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
144163915Sandre#   include "opt_ipfilter.h"
145163915Sandre#  endif
146163915Sandre#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
147163915Sandre#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
148163915Sandre
149163915Sandre# else
150129906Sbmilekic#  include <inttypes.h>
151129906Sbmilekic# endif /* _KERNEL */
152129906Sbmilekic
153129906Sbmilekic#  include <sys/selinfo.h>
154129906Sbmilekic#  include <sys/lock.h>
155129906Sbmilekic#  include <sys/malloc.h>
156129906Sbmilekic#  include <sys/mutex.h>
157129906Sbmilekic#    define	KRWLOCK_FILL_SZ		56
158129906Sbmilekic#    define	KMUTEX_FILL_SZ		56
159129906Sbmilekic#   include <sys/rwlock.h>
160129906Sbmilekic#   define	KMUTEX_T		struct mtx
161129906Sbmilekic#   define	KRWLOCK_T		struct rwlock
162129906Sbmilekic
163129906Sbmilekic#ifdef _KERNEL
164210226Strasz#    define	READ_ENTER(x)		rw_rlock(&(x)->ipf_lk)
165129906Sbmilekic#    define	WRITE_ENTER(x)		rw_wlock(&(x)->ipf_lk)
166129906Sbmilekic#    define	MUTEX_DOWNGRADE(x)	rw_downgrade(&(x)->ipf_lk)
167129906Sbmilekic#    define	MUTEX_TRY_UPGRADE(x)	rw_try_upgrade(&(x)->ipf_lk)
168129906Sbmilekic#    define	RWLOCK_INIT(x,y)	rw_init(&(x)->ipf_lk, (y))
169129906Sbmilekic#    define	RW_DESTROY(x)		rw_destroy(&(x)->ipf_lk)
170129906Sbmilekic#    define	RWLOCK_EXIT(x)		do { \
171129906Sbmilekic					    if (rw_wowned(&(x)->ipf_lk)) \
172129906Sbmilekic					    	rw_wunlock(&(x)->ipf_lk); \
173129906Sbmilekic					    else \
174129906Sbmilekic						rw_runlock(&(x)->ipf_lk); \
175129906Sbmilekic					} while (0)
176129906Sbmilekic#  include <net/if_var.h>
177129906Sbmilekic#  define	GETKTIME(x)	microtime((struct timeval *)x)
178129906Sbmilekic
179129906Sbmilekic#   include <netinet/in_systm.h>
180129906Sbmilekic#   include <netinet/ip.h>
181129906Sbmilekic#   include <machine/in_cksum.h>
182129906Sbmilekic
183129906Sbmilekic#   define	USE_MUTEXES
184129906Sbmilekic#   define	MUTEX_ENTER(x)		mtx_lock(&(x)->ipf_lk)
185129906Sbmilekic#   define	MUTEX_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
186129906Sbmilekic#   define	MUTEX_INIT(x,y)		mtx_init(&(x)->ipf_lk, (y), NULL,\
187175872Sphk						 MTX_DEF)
188129906Sbmilekic#   define	MUTEX_DESTROY(x)	mtx_destroy(&(x)->ipf_lk)
189151976Sandre#   define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
190129906Sbmilekic/*
191151976Sandre * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
192151976Sandre * for what we want to use them for, despite testing showing they work -
193129906Sbmilekic * with a WITNESS kernel, it generates LOR messages.
194129906Sbmilekic */
195129906Sbmilekic#   include <machine/atomic.h>
196129906Sbmilekic#   define	ATOMIC_INC(x)		{ mtx_lock(&softc->ipf_rw.ipf_lk); (x)++; \
197129906Sbmilekic					  mtx_unlock(&softc->ipf_rw.ipf_lk); }
198129906Sbmilekic#   define	ATOMIC_DEC(x)		{ mtx_lock(&softc->ipf_rw.ipf_lk); (x)--; \
199129906Sbmilekic					  mtx_unlock(&softc->ipf_rw.ipf_lk); }
200175872Sphk#   define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
201175872Sphk#   define	ATOMIC_INC64(x)		ATOMIC_INC(x)
202129906Sbmilekic#   define	ATOMIC_INC32(x)		atomic_add_32((u_int *)&(x), 1)
203129906Sbmilekic#   define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
204129906Sbmilekic#   define	ATOMIC_DEC64(x)		ATOMIC_DEC(x)
205129906Sbmilekic#   define	ATOMIC_DEC32(x)		atomic_add_32((u_int *)&(x), -1)
206129906Sbmilekic#   define	SPL_X(x)	;
207129906Sbmilekic#   define	SPL_NET(x)	;
208151976Sandre#   define	SPL_IMP(x)	;
209129906Sbmilekic#   define	SPL_SCHED(x)	;
210129906Sbmilekic#   define	GET_MINOR		dev2unit
211129906Sbmilekic#  define	MSGDSIZE(m)	mbufchainlen(m)
212129906Sbmilekic#  define	M_LEN(m)	(m)->m_len
213172463Skmacy#  define	M_ADJ(m,x)	m_adj(m, x)
214172463Skmacy#  define	M_COPY(x)	m_copy((x), 0, M_COPYALL)
215151976Sandre#  define	M_DUP(m)	m_dup(m, M_NOWAIT)
216151976Sandre#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
217129906Sbmilekictypedef struct mbuf mb_t;
218172463Skmacy
219172463Skmacy#else	/* !_KERNEL */
220172463Skmacy#ifndef _NET_IF_VAR_H_
221172463Skmacy/*
222172463Skmacy * Userland emulation of struct ifnet.
223172463Skmacy */
224151976Sandrestruct route;
225151976Sandrestruct mbuf;
226162515Srrsstruct ifnet {
227151976Sandre	char			if_xname[IFNAMSIZ];
228152101Sandre	TAILQ_HEAD(, ifaddr)	if_addrlist;
229152035Sandre	int	(*if_output)(struct ifnet *, struct mbuf *,
230152035Sandre	    const struct sockaddr *, struct route *);
231151976Sandre};
232151976Sandre#endif /* _NET_IF_VAR_H_ */
233152101Sandre#endif /* _KERNEL */
234152101Sandre
235130289Sbmilekic#  define	IFNAME(x)	((struct ifnet *)x)->if_xname
236155780Sandre#  define	COPYIFNAME(v, x, b) \
237155780Sandre				(void) strncpy(b, \
238153232Sandre					       ((struct ifnet *)x)->if_xname, \
239151976Sandre					       LIFNAMSIZ)
240151976Sandre
241151976Sandretypedef	u_long		ioctlcmd_t;
242151976Sandretypedef	struct uio	uio_t;
243151976Sandretypedef	int		minor_t;
244151976Sandretypedef	u_int32_t	u_32_t;
245151976Sandre# define	U_32_T	1
246151976Sandre
247151976Sandre
248151976Sandre/* ----------------------------------------------------------------------- */
249151976Sandre/*                           G E N E R I C                                 */
250151976Sandre/* ----------------------------------------------------------------------- */
251151976Sandre
252151976Sandre/*
253151976Sandre * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
254151976Sandre * filter rules.
255151976Sandre */
256175872Sphk#if !defined(IPFILTER_BPF)
257175872Sphk# if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
258151976Sandre     (defined(NBPFILTER) && (NBPFILTER > 0))
259151976Sandre#  define	IPFILTER_BPF
260151976Sandre# endif
261151976Sandre#endif
262141668Sbmilekic
263141668Sbmilekic/*
264172463Skmacy * Userland locking primitives
265172463Skmacy */
266172463Skmacy#ifndef _KERNEL
267151976Sandre#if !defined(KMUTEX_FILL_SZ)
268151976Sandre# define	KMUTEX_FILL_SZ	1
269151976Sandre#endif
270151976Sandre#if !defined(KRWLOCK_FILL_SZ)
271151976Sandre# define	KRWLOCK_FILL_SZ	1
272151976Sandre#endif
273175872Sphk#endif
274175872Sphk
275151976Sandretypedef	struct	{
276151976Sandre	char	*eMm_owner;
277151976Sandre	char	*eMm_heldin;
278151976Sandre	u_int	eMm_magic;
279130357Sbmilekic	int	eMm_held;
280129906Sbmilekic	int	eMm_heldat;
281129906Sbmilekic} eMmutex_t;
282129906Sbmilekic
283218909Sbrucectypedef	struct	{
284151976Sandre	char	*eMrw_owner;
285151976Sandre	char	*eMrw_heldin;
286151976Sandre	u_int	eMrw_magic;
287151976Sandre	short	eMrw_read;
288151976Sandre	short	eMrw_write;
289151976Sandre	int	eMrw_heldat;
290151976Sandre} eMrwlock_t;
291151976Sandre
292151976Sandretypedef union {
293151976Sandre	char	_fill[KMUTEX_FILL_SZ];
294151976Sandre#ifdef KMUTEX_T
295151976Sandre	struct	{
296151976Sandre		KMUTEX_T	ipf_slk;
297151976Sandre		const char	*ipf_lname;
298151976Sandre	} ipf_lkun_s;
299175872Sphk#endif
300175872Sphk	eMmutex_t	ipf_emu;
301151976Sandre} ipfmutex_t;
302151976Sandre
303151976Sandretypedef union {
304151976Sandre	char	_fill[KRWLOCK_FILL_SZ];
305209964Scperciva#ifdef KRWLOCK_T
306151976Sandre	struct	{
307151976Sandre		KRWLOCK_T	ipf_slk;
308151976Sandre		const char	*ipf_lname;
309149598Sandre		int		ipf_sr;
310149647Sandre		int		ipf_sw;
311149647Sandre		u_int		ipf_magic;
312149598Sandre	} ipf_lkun_s;
313149598Sandre#endif
314149647Sandre	eMrwlock_t	ipf_emu;
315149598Sandre} ipfrwlock_t;
316149598Sandre
317149598Sandre#define	ipf_lk		ipf_lkun_s.ipf_slk
318149598Sandre#define	ipf_lname	ipf_lkun_s.ipf_lname
319149598Sandre#define	ipf_isr		ipf_lkun_s.ipf_sr
320149598Sandre#define	ipf_isw		ipf_lkun_s.ipf_sw
321149598Sandre#define	ipf_magic	ipf_lkun_s.ipf_magic
322149598Sandre
323149598Sandre#if !defined(__GNUC__) || \
324194643Sandre    (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
325194643Sandre# ifndef	INLINE
326194643Sandre#  define	INLINE
327194643Sandre# endif
328149598Sandre#else
329194643Sandre# define	INLINE	__inline__
330194643Sandre#endif
331149598Sandre
332149598Sandre#if defined(__FreeBSD_version) && defined(_KERNEL)
333149598Sandre     CTASSERT(sizeof(ipfrwlock_t) == KRWLOCK_FILL_SZ);
334149598Sandre     CTASSERT(sizeof(ipfmutex_t) == KMUTEX_FILL_SZ);
335149648Sandre#endif
336149648Sandre
337149648Sandre
338149648Sandre/*
339149648Sandre * In a non-kernel environment, there are a lot of macros that need to be
340149599Sandre * filled in to be null-ops or to point to some compatibility function,
341149599Sandre * somewhere in userland.
342149599Sandre */
343149599Sandre#ifndef _KERNEL
344149599Sandretypedef	struct	mb_s	{
345149599Sandre	struct	mb_s	*mb_next;
346149599Sandre	char		*mb_data;
347149599Sandre	void		*mb_ifp;
348168734Skmacy	int		mb_len;
349168734Skmacy	int		mb_flags;
350168734Skmacy	u_long		mb_buf[2048];
351168734Skmacy} mb_t;
352168734Skmacy# undef		m_next
353149599Sandre# define	m_next		mb_next
354149648Sandre# undef		m_len
355149599Sandre# define	m_len		mb_len
356149599Sandre# undef		m_flags
357149599Sandre# define	m_flags		mb_flags
358149599Sandre# undef		m_data
359149599Sandre# define	m_data		mb_data
360149648Sandre# undef		M_MCAST
361149648Sandre# define	M_MCAST		0x01
362149599Sandre# undef		M_BCAST
363149599Sandre# define	M_BCAST		0x02
364149648Sandre# undef		M_MBCAST
365149599Sandre# define	M_MBCAST	0x04
366149599Sandre# define	MSGDSIZE(m)	msgdsize(m)
367149599Sandre# define	M_LEN(m)	(m)->mb_len
368149599Sandre# define	M_ADJ(m,x)	(m)->mb_len += x
369149599Sandre# define	M_COPY(m)	dupmbt(m)
370149599Sandre# define	M_DUP(m)	dupmbt(m)
371149648Sandre# define	GETKTIME(x)	gettimeofday((struct timeval *)(x), NULL)
372149599Sandre# define	MTOD(m, t)	((t)(m)->mb_data)
373149599Sandre# define	FREE_MB_T(m)	freembt(m)
374149599Sandre# define	ALLOC_MB_T(m,l)	(m) = allocmbt(l)
375149599Sandre# define	PREP_MB_T(f, m)	do { \
376149599Sandre						(m)->mb_next = *(f)->fin_mp; \
377149599Sandre						*(fin)->fin_mp = (m); \
378149648Sandre						(f)->fin_m = (m); \
379149599Sandre					} while (0)
380149599Sandre# define	SLEEP(x,y)	1;
381149599Sandre# define	WAKEUP(x,y)	;
382149599Sandre# define	POLLWAKEUP(y)	;
383149599Sandre# define	IPF_PANIC(x,y)	;
384149599Sandre# define	PANIC(x,y)	;
385149599Sandre# define	SPL_SCHED(x)	;
386149599Sandre# define	SPL_NET(x)	;
387149599Sandre# define	SPL_IMP(x)	;
388149599Sandre# define	SPL_X(x)	;
389149599Sandre# define	KMALLOC(a,b)	(a) = (b)malloc(sizeof(*a))
390149599Sandre# define	KMALLOCS(a,b,c)	(a) = (b)malloc(c)
391149599Sandre# define	KFREE(x)	free(x)
392149599Sandre# define	KFREES(x,s)	free(x)
393149599Sandre# define	GETIFP(x, v)	get_unit(x,v)
394149599Sandre# define	GETIFMTU_4(x)	2048
395149599Sandre# define	GETIFMTU_6(x)	2048
396149648Sandre# define	COPYIN(a,b,c)	bcopywrap((a), (b), (c))
397149599Sandre# define	COPYOUT(a,b,c)	bcopywrap((a), (b), (c))
398149599Sandre# define	COPYDATA(m, o, l, b)	bcopy(MTOD((mb_t *)m, char *) + (o), \
399149599Sandre					      (b), (l))
400149599Sandre# define	COPYBACK(m, o, l, b)	bcopy((b), \
401149599Sandre					      MTOD((mb_t *)m, char *) + (o), \
402149599Sandre					      (l))
403149599Sandre# define	UIOMOVE(a,b,c,d)	ipfuiomove((caddr_t)a,b,c,d)
404149599Sandreextern	void	m_copydata __P((mb_t *, int, int, caddr_t));
405149599Sandreextern	int	ipfuiomove __P((caddr_t, int, int, struct uio *));
406149599Sandreextern	int	bcopywrap __P((void *, void *, size_t));
407149599Sandreextern	mb_t	*allocmbt __P((size_t));
408149599Sandreextern	mb_t	*dupmbt __P((mb_t *));
409149599Sandreextern	void	freembt __P((mb_t *));
410149648Sandre
411149648Sandre# define	MUTEX_DESTROY(x)	eMmutex_destroy(&(x)->ipf_emu, \
412149599Sandre							__FILE__, __LINE__)
413149648Sandre# define	MUTEX_ENTER(x)		eMmutex_enter(&(x)->ipf_emu, \
414149599Sandre						      __FILE__, __LINE__)
415149599Sandre# define	MUTEX_EXIT(x)		eMmutex_exit(&(x)->ipf_emu, \
416149599Sandre						     __FILE__, __LINE__)
417149648Sandre# define	MUTEX_INIT(x,y)		eMmutex_init(&(x)->ipf_emu, y, \
418149648Sandre						     __FILE__, __LINE__)
419149599Sandre# define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
420149599Sandre
421149599Sandre# define	MUTEX_DOWNGRADE(x)	eMrwlock_downgrade(&(x)->ipf_emu, \
422149599Sandre							   __FILE__, __LINE__)
423149599Sandre# define	MUTEX_TRY_UPGRADE(x)	eMrwlock_try_upgrade(&(x)->ipf_emu, \
424108466Ssam							   __FILE__, __LINE__)
425100960Srwatson# define	READ_ENTER(x)		eMrwlock_read_enter(&(x)->ipf_emu, \
426100960Srwatson							    __FILE__, __LINE__)
427100960Srwatson# define	RWLOCK_INIT(x, y)	eMrwlock_init(&(x)->ipf_emu, y)
428108466Ssam# define	RWLOCK_EXIT(x)		eMrwlock_exit(&(x)->ipf_emu)
429100960Srwatson# define	RW_DESTROY(x)		eMrwlock_destroy(&(x)->ipf_emu)
430100960Srwatson# define	WRITE_ENTER(x)		eMrwlock_write_enter(&(x)->ipf_emu, \
431100960Srwatson							     __FILE__, \
432108466Ssam							     __LINE__)
433113255Sdes
434113487Srwatson# define	USE_MUTEXES		1
435108466Ssam
436108466Ssamextern void eMmutex_destroy __P((eMmutex_t *, char *, int));
437100960Srwatsonextern void eMmutex_enter __P((eMmutex_t *, char *, int));
438101007Srwatsonextern void eMmutex_exit __P((eMmutex_t *, char *, int));
439113487Srwatsonextern void eMmutex_init __P((eMmutex_t *, char *, char *, int));
440113487Srwatsonextern void eMrwlock_destroy __P((eMrwlock_t *));
441113487Srwatsonextern void eMrwlock_exit __P((eMrwlock_t *));
442101007Srwatsonextern void eMrwlock_init __P((eMrwlock_t *, char *));
443113487Srwatsonextern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
444101007Srwatsonextern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
445143302Ssamextern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
446143302Ssam
447143302Ssam#endif
448108466Ssam
449108466Ssamextern	mb_t	*allocmbt(size_t);
450108466Ssam
451108466Ssam#define	MAX_IPV4HDR	((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
452108466Ssam
453108466Ssam#ifndef	IP_OFFMASK
454108466Ssam# define	IP_OFFMASK	0x1fff
455108466Ssam#endif
456108466Ssam
457108466Ssam
458108466Ssam/*
459108466Ssam * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
460108466Ssam * object.
461108466Ssam */
462108466Ssam#if !defined(__amd64__) && BSD_GT_YEAR(199306)
463108466Ssam# define	USE_QUAD_T
464108466Ssam# define	U_QUAD_T	unsigned long long
465108466Ssam# define	QUAD_T		long long
466108466Ssam#else /* BSD > 199306 */
467108466Ssam# if !defined(U_QUAD_T)
468108466Ssam#  define	U_QUAD_T	u_long
469108466Ssam#  define	QUAD_T		long
470113255Sdes# endif
471113487Srwatson#endif /* BSD > 199306 */
472108466Ssam
473108466Ssam
474132488Salfred#ifdef	USE_INET6
475108466Ssam# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
476108466Ssam     defined(__osf__) || defined(linux)
477113487Srwatson#  include <netinet/ip6.h>
478108466Ssam#  include <netinet/icmp6.h>
479112733Ssilby#   if defined(_KERNEL) && !defined(__osf__)
480112733Ssilby#    include <netinet6/ip6_var.h>
481112733Ssilby#   endif
482100960Srwatsontypedef	struct ip6_hdr	ip6_t;
483108466Ssam# endif
484113480Srwatson#endif
485100960Srwatson
486100960Srwatson#ifndef	MAX
487100960Srwatson# define	MAX(a,b)	(((a) > (b)) ? (a) : (b))
4881541Srgrimes#endif
4891541Srgrimes
4901541Srgrimes#if defined(_KERNEL)
4911541Srgrimes# if defined(MENTAT) && !defined(INSTANCES)
4921541Srgrimes#  define	COPYDATA	mb_copydata
49372356Sbmilekic#  define	COPYBACK	mb_copyback
4941541Srgrimes# else
4951541Srgrimes#  define	COPYDATA	m_copydata
4961541Srgrimes#  define	COPYBACK	m_copyback
497117770Ssilby# endif
498117770Ssilby#  if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
499117770Ssilby       defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
500117770Ssilby       defined(_BSDI_VERSION)
50172356Sbmilekic#   include <vm/vm.h>
5021541Srgrimes#  endif
50372356Sbmilekic#  if !defined(__FreeBSD__) || FREEBSD_GE_REV(300000)
5041541Srgrimes#   if NETBSD_GE_REV(105180000) || OPENBSD_GE_REV(200111)
505113487Srwatson#    include <uvm/uvm_extern.h>
506108466Ssam#   else
5071541Srgrimes#    include <vm/vm_extern.h>
5081541Srgrimesextern  vm_map_t        kmem_map;
509165447Srrs#   endif
510165447Srrs#   include <sys/proc.h>
511165447Srrs#  else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
512165447Srrs#   include <vm/vm_kern.h>
513165447Srrs#  endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
514165447Srrs
515165447Srrs#  ifdef IPFILTER_M_IPFILTER
5161541Srgrimes#    include <sys/malloc.h>
5171541SrgrimesMALLOC_DECLARE(M_IPFILTER);
5181541Srgrimes#    define	_M_IPF		M_IPFILTER
5191541Srgrimes#  else /* IPFILTER_M_IPFILTER */
5201541Srgrimes#   ifdef M_PFIL
5211541Srgrimes#    define	_M_IPF		M_PFIL
5221541Srgrimes#   else
523177599Sru#    ifdef M_IPFILTER
52454002Sarchie#     define	_M_IPF		M_IPFILTER
52554002Sarchie#    else
5261541Srgrimes#     define	_M_IPF		M_TEMP
5271541Srgrimes#    endif /* M_IPFILTER */
52872356Sbmilekic#   endif /* M_PFIL */
5291541Srgrimes#  endif /* IPFILTER_M_IPFILTER */
53072356Sbmilekic#  if !defined(KMALLOC)
53172356Sbmilekic#   define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
5321541Srgrimes#  endif
5331541Srgrimes#  if !defined(KMALLOCS)
5341541Srgrimes#   define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
53552201Salfred#  endif
53652201Salfred#  if !defined(KFREE)
537132488Salfred#   define	KFREE(x)	FREE((x), _M_IPF)
5381541Srgrimes#  endif
5391541Srgrimes#   if !defined(KFREES)
5401541Srgrimes#  define	KFREES(x,s)	FREE((x), _M_IPF)
54152201Salfred#  endif
5421541Srgrimes#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,d)
5431541Srgrimes#  define	SLEEP(id, n)	tsleep((id), PPAUSE|PCATCH, n, 0)
5441541Srgrimes#  define	WAKEUP(id,x)	wakeup(id+x)
5451541Srgrimes#  if !defined(POLLWAKEUP)
5461541Srgrimes#   define	POLLWAKEUP(x)	selwakeup(softc->ipf_selwait+x)
5471541Srgrimes#  endif
5481541Srgrimes#  define	GETIFP(n, v)	ifunit(n)
5491541Srgrimes#  define	GETIFMTU_4(x)	((struct ifnet *)x)->if_mtu
55072356Sbmilekic#  define	GETIFMTU_6(x)	((struct ifnet *)x)->if_mtu
55152201Salfred
55252201Salfred# if !defined(USE_MUTEXES) && !defined(SPL_NET)
5531541Srgrimes#  define	SPL_IMP(x)	x = splimp()
5541541Srgrimes#  define	SPL_NET(x)	x = splnet()
555117770Ssilby#  if !defined(SPL_SCHED)
556117770Ssilby#   define	SPL_SCHED(x)	x = splsched()
557117770Ssilby#  endif
558117770Ssilby#  define	SPL_X(x)	(void) splx(x)
5591541Srgrimes# endif /* !USE_MUTEXES */
56072356Sbmilekic
5611541Srgrimes# ifndef FREE_MB_T
5621541Srgrimes#  define	FREE_MB_T(m)	m_freem(m)
563108466Ssam# endif
564108466Ssam# ifndef ALLOC_MB_T
5651541Srgrimes#  ifdef MGETHDR
5661541Srgrimes#   define	ALLOC_MB_T(m,l)	do { \
5671541Srgrimes					MGETHDR((m), M_NOWAIT, MT_HEADER); \
5681541Srgrimes					if ((m) != NULL) { \
5691541Srgrimes						(m)->m_len = (l); \
5701541Srgrimes						(m)->m_pkthdr.len = (l); \
5711541Srgrimes					} \
5721541Srgrimes				} while (0)
5731541Srgrimes#  else
574151976Sandre#   define	ALLOC_MB_T(m,l)	do { \
5751541Srgrimes					MGET((m), M_NOWAIT, MT_HEADER); \
5761541Srgrimes					if ((m) != NULL) { \
577103569Sbmilekic						(m)->m_len = (l); \
5781541Srgrimes						(m)->m_pkthdr.len = (l); \
5791541Srgrimes					} \
5801541Srgrimes				} while (0)
5811541Srgrimes#  endif
5821541Srgrimes# endif
5831541Srgrimes# ifndef PREP_MB_T
58478592Sbmilekic#  define	PREP_MB_T(f, m)	do { \
58578592Sbmilekic						mb_t *_o = *(f)->fin_mp; \
58678592Sbmilekic						(m)->m_next = _o; \
5871541Srgrimes						*(fin)->fin_mp = (m); \
5881541Srgrimes						if (_o->m_flags & M_PKTHDR) { \
5891541Srgrimes							(m)->m_pkthdr.len += \
59078592Sbmilekic							    _o->m_pkthdr.len; \
59172356Sbmilekic							(m)->m_pkthdr.rcvif = \
5921541Srgrimes							  _o->m_pkthdr.rcvif; \
5931541Srgrimes						} \
5941541Srgrimes					} while (0)
595149602Sandre# endif
596149602Sandre# ifndef M_DUP
597149602Sandre#  ifdef M_COPYALL
598149602Sandre#   define	M_DUP(m)	m_dup(m, 0, M_COPYALL, 0)
599149602Sandre#  else
600149602Sandre#   define	M_DUP(m)	m_dup(m)
601149602Sandre#  endif
602149602Sandre# endif
603149602Sandre
604149602Sandre# ifndef MTOD
605149602Sandre#  define	MTOD(m,t)	mtod(m,t)
606149602Sandre# endif
607149602Sandre
608149602Sandre# ifndef COPYIN
609149602Sandre#  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
610149602Sandre#  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
611149602Sandre# endif
612149602Sandre
613149602Sandre# ifndef KMALLOC
614149602Sandre#  define	KMALLOC(a,b)	(a) = (b)new_kmem_alloc(sizeof(*(a)), \
615149602Sandre							KMEM_NOSLEEP)
616151976Sandre#  define	KMALLOCS(a,b,c)	(a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
617149602Sandre# endif
618151976Sandre
619149602Sandre# ifndef	GET_MINOR
620149602Sandre#  define	GET_MINOR(x)	dev2unit(x)
621149602Sandre# endif
622149602Sandre# define	PANIC(x,y)	if (x) panic y
623149602Sandre#endif /* _KERNEL */
624149602Sandre
625149602Sandre#if !defined(IFNAME) && !defined(_KERNEL)
626151976Sandre# define	IFNAME(x)	get_ifname((struct ifnet *)x)
627151976Sandre#endif
628151976Sandre#ifndef	COPYIFNAME
629151976Sandre# define	NEED_FRGETIFNAME
630151976Sandreextern	char	*ipf_getifname __P((struct ifnet *, char *));
631149602Sandre# define	COPYIFNAME(v, x, b) \
632149602Sandre				ipf_getifname((struct ifnet *)x, b)
633149602Sandre#endif
634149602Sandre
635149602Sandre#ifndef ASSERT
636149602Sandre# ifdef _KERNEL
637149602Sandre#  define	ASSERT(x)
638149602Sandre# else
639149602Sandre#  define	ASSERT(x)	do { if (!(x)) abort(); } while (0)
640151976Sandre# endif
641151976Sandre#endif
642151976Sandre
643151976Sandre#ifndef BCOPYIN
644151976Sandre#  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
645151976Sandre#  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
646151976Sandre#endif
647151976Sandre
648151976Sandre/*
649151976Sandre * Because the ctype(3) posix definition, if used "safely" in code everywhere,
650151976Sandre * would mean all normal code that walks through strings needed casts.  Yuck.
651151976Sandre */
652151976Sandre#define	ISALNUM(x)	isalnum((u_char)(x))
653151976Sandre#define	ISALPHA(x)	isalpha((u_char)(x))
654151976Sandre#define	ISDIGIT(x)	isdigit((u_char)(x))
655149602Sandre#define	ISSPACE(x)	isspace((u_char)(x))
656149602Sandre#define	ISUPPER(x)	isupper((u_char)(x))
657149602Sandre#define	ISXDIGIT(x)	isxdigit((u_char)(x))
658149602Sandre#define	ISLOWER(x)	islower((u_char)(x))
659149602Sandre#define	TOUPPER(x)	toupper((u_char)(x))
660149602Sandre#define	TOLOWER(x)	tolower((u_char)(x))
661149602Sandre
662149602Sandre/*
663149602Sandre * If mutexes aren't being used, turn all the mutex functions into null-ops.
664149602Sandre */
665149602Sandre#if !defined(USE_MUTEXES)
666149602Sandre# define	USE_SPL			1
667149602Sandre# undef		RW_DESTROY
668149602Sandre# undef		MUTEX_INIT
669149602Sandre# undef		MUTEX_NUKE
670149602Sandre# undef		MUTEX_DESTROY
671149602Sandre# define	MUTEX_ENTER(x)		;
672149602Sandre# define	READ_ENTER(x)		;
673149602Sandre# define	WRITE_ENTER(x)		;
674149602Sandre# define	MUTEX_DOWNGRADE(x)	;
675149602Sandre# define	MUTEX_TRY_UPGRADE(x)	;
676149602Sandre# define	RWLOCK_INIT(x, y)	;
677149602Sandre# define	RWLOCK_EXIT(x)		;
678149602Sandre# define	RW_DESTROY(x)		;
679149602Sandre# define	MUTEX_EXIT(x)		;
680149602Sandre# define	MUTEX_INIT(x,y)		;
681149602Sandre# define	MUTEX_DESTROY(x)	;
682149602Sandre# define	MUTEX_NUKE(x)		;
683149602Sandre#endif /* !USE_MUTEXES */
684149602Sandre#ifndef	ATOMIC_INC
685149602Sandre# define	ATOMIC_INC(x)		(x)++
686149602Sandre# define	ATOMIC_DEC(x)		(x)--
687149602Sandre#endif
688149602Sandre
689149602Sandre#if defined(USE_SPL) && defined(_KERNEL)
690149602Sandre# define	SPL_INT(x)	int x
691149602Sandre#else
692149602Sandre# define	SPL_INT(x)
693149602Sandre#endif
694149602Sandre
695149602Sandre/*
696149602Sandre * If there are no atomic operations for bit sizes defined, define them to all
697149602Sandre * use a generic one that works for all sizes.
698149602Sandre */
699149602Sandre#ifndef	ATOMIC_INCL
700149602Sandre# define	ATOMIC_INCL		ATOMIC_INC
701149602Sandre# define	ATOMIC_INC64		ATOMIC_INC
702149602Sandre# define	ATOMIC_INC32		ATOMIC_INC
703149602Sandre# define	ATOMIC_DECL		ATOMIC_DEC
704149602Sandre# define	ATOMIC_DEC64		ATOMIC_DEC
705149602Sandre# define	ATOMIC_DEC32		ATOMIC_DEC
706149602Sandre#endif
707149602Sandre
708149602Sandre#ifndef HDR_T_PRIVATE
709149602Sandretypedef	struct	tcphdr	tcphdr_t;
710149602Sandretypedef	struct	udphdr	udphdr_t;
711149602Sandre#endif
712149602Sandretypedef	struct	icmp	icmphdr_t;
713149602Sandretypedef	struct	ip	ip_t;
714149602Sandretypedef	struct	ether_header	ether_header_t;
715149602Sandretypedef	struct	tcpiphdr	tcpiphdr_t;
716149602Sandre
717149602Sandre#ifndef	FR_GROUPLEN
718149602Sandre# define	FR_GROUPLEN	16
719149602Sandre#endif
720149602Sandre
721149602Sandre#ifndef offsetof
722149602Sandre# define offsetof(t,m) (size_t)((&((t *)0L)->m))
723149602Sandre#endif
724149602Sandre#ifndef stsizeof
725149602Sandre# define stsizeof(t,m)	sizeof(((t *)0L)->m)
726149602Sandre#endif
727149602Sandre
728149602Sandre/*
729149602Sandre * This set of macros has been brought about because on Tru64 it is not
730149602Sandre * possible to easily assign or examine values in a structure that are
731149602Sandre * bit fields.
732149602Sandre */
733149602Sandre#ifndef IP_V
734149602Sandre# define	IP_V(x)		(x)->ip_v
735149602Sandre#endif
736149602Sandre#ifndef	IP_V_A
737149602Sandre# define	IP_V_A(x,y)	(x)->ip_v = (y)
738149602Sandre#endif
739149602Sandre#ifndef	IP_HL
740149602Sandre# define	IP_HL(x)	(x)->ip_hl
741149602Sandre#endif
742149602Sandre#ifndef	IP_HL_A
74315689Swollman# define	IP_HL_A(x,y)	(x)->ip_hl = ((y) & 0xf)
74415689Swollman#endif
74554002Sarchie#ifndef	TCP_X2
74654002Sarchie# define	TCP_X2(x)	(x)->th_x2
74772750Sluigi#endif
74872750Sluigi#ifndef	TCP_X2_A
74972750Sluigi# define	TCP_X2_A(x,y)	(x)->th_x2 = (y)
75015689Swollman#endif
75115689Swollman#ifndef	TCP_OFF
75272356Sbmilekic# define	TCP_OFF(x)	(x)->th_off
75315689Swollman#endif
75415689Swollman#ifndef	TCP_OFF_A
75515689Swollman# define	TCP_OFF_A(x,y)	(x)->th_off = (y)
756132488Salfred#endif
75715689Swollman#define	IPMINLEN(i, h)	((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
75815689Swollman
75972356Sbmilekic#define	TCPF_ALL	(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
76015689Swollman			 TH_ECN|TH_CWR)
76115689Swollman
762108466Ssam#if BSD_GE_YEAR(199306) && !defined(m_act)
763108466Ssam# define	m_act	m_nextpkt
76415689Swollman#endif
76515689Swollman
76615689Swollman/*
767151976Sandre * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
76815689Swollman *
76972750Sluigi * Basic Option
77015689Swollman *
77115689Swollman * 00000001   -   (Reserved 4)
77215689Swollman * 00111101   -   Top Secret
77315689Swollman * 01011010   -   Secret
77415689Swollman * 10010110   -   Confidential
77515689Swollman * 01100110   -   (Reserved 3)
77672356Sbmilekic * 11001100   -   (Reserved 2)
77715689Swollman * 10101011   -   Unclassified
77815689Swollman * 11110001   -   (Reserved 1)
77915689Swollman */
78015689Swollman#define	IPSO_CLASS_RES4		0x01
78115689Swollman#define	IPSO_CLASS_TOPS		0x3d
78215689Swollman#define	IPSO_CLASS_SECR		0x5a
78315689Swollman#define	IPSO_CLASS_CONF		0x96
78415689Swollman#define	IPSO_CLASS_RES3		0x66
785151976Sandre#define	IPSO_CLASS_RES2		0xcc
78615689Swollman#define	IPSO_CLASS_UNCL		0xab
78715689Swollman#define	IPSO_CLASS_RES1		0xf1
78815689Swollman
78915689Swollman#define	IPSO_AUTH_GENSER	0x80
79015689Swollman#define	IPSO_AUTH_ESI		0x40
79115689Swollman#define	IPSO_AUTH_SCI		0x20
79215689Swollman#define	IPSO_AUTH_NSA		0x10
79315689Swollman#define	IPSO_AUTH_DOE		0x08
79415689Swollman#define	IPSO_AUTH_UN		0x06
79578592Sbmilekic#define	IPSO_AUTH_FTE		0x01
79672356Sbmilekic
79715689Swollman/*
79815689Swollman * IP option #defines
79915689Swollman */
8001541Srgrimes#undef	IPOPT_RR
8011541Srgrimes#define	IPOPT_RR	7
8021541Srgrimes#undef	IPOPT_ZSU
8031549Srgrimes#define	IPOPT_ZSU	10	/* ZSU */
80481907Sjulian#undef	IPOPT_MTUP
8051541Srgrimes#define	IPOPT_MTUP	11	/* MTUP */
806103569Sbmilekic#undef	IPOPT_MTUR
8071541Srgrimes#define	IPOPT_MTUR	12	/* MTUR */
80852201Salfred#undef	IPOPT_ENCODE
80952201Salfred#define	IPOPT_ENCODE	15	/* ENCODE */
8101541Srgrimes#undef	IPOPT_TS
81152201Salfred#define	IPOPT_TS	68
8121541Srgrimes#undef	IPOPT_TR
8131541Srgrimes#define	IPOPT_TR	82	/* TR */
8141541Srgrimes#undef	IPOPT_SECURITY
8151541Srgrimes#define	IPOPT_SECURITY	130
8161541Srgrimes#undef	IPOPT_LSRR
8171541Srgrimes#define	IPOPT_LSRR	131
81852201Salfred#undef	IPOPT_E_SEC
8191541Srgrimes#define	IPOPT_E_SEC	133	/* E-SEC */
8201541Srgrimes#undef	IPOPT_CIPSO
8211541Srgrimes#define	IPOPT_CIPSO	134	/* CIPSO */
8221541Srgrimes#undef	IPOPT_SATID
8231541Srgrimes#define	IPOPT_SATID	136
8241541Srgrimes#ifndef	IPOPT_SID
8251541Srgrimes# define	IPOPT_SID	IPOPT_SATID
8261541Srgrimes#endif
8271541Srgrimes#undef	IPOPT_SSRR
8281541Srgrimes#define	IPOPT_SSRR	137
82954002Sarchie#undef	IPOPT_ADDEXT
83054002Sarchie#define	IPOPT_ADDEXT	147	/* ADDEXT */
83154002Sarchie#undef	IPOPT_VISA
83254002Sarchie#define	IPOPT_VISA	142	/* VISA */
83354002Sarchie#undef	IPOPT_IMITD
83472356Sbmilekic#define	IPOPT_IMITD	144	/* IMITD */
83554002Sarchie#undef	IPOPT_EIP
83654002Sarchie#define	IPOPT_EIP	145	/* EIP */
83754002Sarchie#undef	IPOPT_RTRALRT
83854002Sarchie#define	IPOPT_RTRALRT	148	/* RTRALRT */
839132488Salfred#undef	IPOPT_SDB
84054002Sarchie#define	IPOPT_SDB	149
84154002Sarchie#undef	IPOPT_NSAPA
84272356Sbmilekic#define	IPOPT_NSAPA	150
843113255Sdes#undef	IPOPT_DPS
84454002Sarchie#define	IPOPT_DPS	151
84554002Sarchie#undef	IPOPT_UMP
84654002Sarchie#define	IPOPT_UMP	152
84754002Sarchie#undef	IPOPT_FINN
84854002Sarchie#define	IPOPT_FINN	205	/* FINN */
84954002Sarchie#undef	IPOPT_AH
85054002Sarchie#define	IPOPT_AH	256+IPPROTO_AH
85154002Sarchie
85254002Sarchie#ifndef TCPOPT_EOL
853129906Sbmilekic# define TCPOPT_EOL		0
854129906Sbmilekic#endif
855129906Sbmilekic#ifndef TCPOPT_NOP
856129906Sbmilekic# define TCPOPT_NOP		1
857129906Sbmilekic#endif
858129906Sbmilekic#ifndef TCPOPT_MAXSEG
859129906Sbmilekic# define TCPOPT_MAXSEG		2
86054002Sarchie#endif
86154002Sarchie#ifndef TCPOLEN_MAXSEG
862129906Sbmilekic# define TCPOLEN_MAXSEG		4
863129906Sbmilekic#endif
864129906Sbmilekic#ifndef TCPOPT_WINDOW
865129906Sbmilekic# define TCPOPT_WINDOW		3
866108466Ssam#endif
867129906Sbmilekic#ifndef TCPOLEN_WINDOW
868153428Semaste# define TCPOLEN_WINDOW		3
869153428Semaste#endif
87054002Sarchie#ifndef TCPOPT_SACK_PERMITTED
87154002Sarchie# define TCPOPT_SACK_PERMITTED	4
87254002Sarchie#endif
87354002Sarchie#ifndef TCPOLEN_SACK_PERMITTED
87454002Sarchie# define TCPOLEN_SACK_PERMITTED	2
87554002Sarchie#endif
87654002Sarchie#ifndef TCPOPT_SACK
87754002Sarchie# define TCPOPT_SACK		5
87854002Sarchie#endif
87954002Sarchie#ifndef TCPOPT_TIMESTAMP
88054002Sarchie# define TCPOPT_TIMESTAMP	8
88154002Sarchie#endif
88254002Sarchie
88354002Sarchie#ifndef	ICMP_MINLEN
88454002Sarchie# define	ICMP_MINLEN	8
88554002Sarchie#endif
88654002Sarchie#ifndef	ICMP_ECHOREPLY
88754002Sarchie# define	ICMP_ECHOREPLY	0
88854002Sarchie#endif
88954002Sarchie#ifndef	ICMP_UNREACH
89054002Sarchie# define	ICMP_UNREACH	3
89154002Sarchie#endif
89254002Sarchie#ifndef	ICMP_UNREACH_NET
89387594Sobrien# define	ICMP_UNREACH_NET	0
89454002Sarchie#endif
89554002Sarchie#ifndef	ICMP_UNREACH_HOST
89654002Sarchie# define	ICMP_UNREACH_HOST	1
89754002Sarchie#endif
89854002Sarchie#ifndef	ICMP_UNREACH_PROTOCOL
89978592Sbmilekic# define	ICMP_UNREACH_PROTOCOL	2
90072356Sbmilekic#endif
90154002Sarchie#ifndef	ICMP_UNREACH_PORT
90254002Sarchie# define	ICMP_UNREACH_PORT	3
90354002Sarchie#endif
9041541Srgrimes#ifndef	ICMP_UNREACH_NEEDFRAG
9051541Srgrimes# define	ICMP_UNREACH_NEEDFRAG	4
9061541Srgrimes#endif
9071541Srgrimes#ifndef	ICMP_UNREACH_SRCFAIL
9081549Srgrimes# define	ICMP_UNREACH_SRCFAIL	5
90972356Sbmilekic#endif
9101541Srgrimes#ifndef	ICMP_UNREACH_NET_UNKNOWN
9111541Srgrimes# define	ICMP_UNREACH_NET_UNKNOWN	6
9121541Srgrimes#endif
9131541Srgrimes#ifndef	ICMP_UNREACH_HOST_UNKNOWN
9141541Srgrimes# define	ICMP_UNREACH_HOST_UNKNOWN	7
9151541Srgrimes#endif
9161541Srgrimes#ifndef	ICMP_UNREACH_ISOLATED
9171541Srgrimes# define	ICMP_UNREACH_ISOLATED	8
9181541Srgrimes#endif
9191541Srgrimes#ifndef	ICMP_UNREACH_NET_PROHIB
9201541Srgrimes# define	ICMP_UNREACH_NET_PROHIB	9
9211541Srgrimes#endif
9221541Srgrimes#ifndef	ICMP_UNREACH_HOST_PROHIB
9231541Srgrimes# define	ICMP_UNREACH_HOST_PROHIB	10
9241541Srgrimes#endif
9251541Srgrimes#ifndef	ICMP_UNREACH_TOSNET
9261541Srgrimes# define	ICMP_UNREACH_TOSNET	11
9271541Srgrimes#endif
9281549Srgrimes#ifndef	ICMP_UNREACH_TOSHOST
92972356Sbmilekic# define	ICMP_UNREACH_TOSHOST	12
9301541Srgrimes#endif
93172356Sbmilekic#ifndef	ICMP_UNREACH_ADMIN_PROHIBIT
93272356Sbmilekic# define	ICMP_UNREACH_ADMIN_PROHIBIT	13
93372356Sbmilekic#endif
9341541Srgrimes#ifndef	ICMP_UNREACH_FILTER
9351541Srgrimes# define	ICMP_UNREACH_FILTER	13
9361541Srgrimes#endif
9371541Srgrimes#ifndef	ICMP_UNREACH_HOST_PRECEDENCE
9381541Srgrimes# define	ICMP_UNREACH_HOST_PRECEDENCE	14
9391541Srgrimes#endif
9401541Srgrimes#ifndef	ICMP_UNREACH_PRECEDENCE_CUTOFF
9411541Srgrimes# define	ICMP_UNREACH_PRECEDENCE_CUTOFF	15
9421541Srgrimes#endif
9431541Srgrimes#ifndef	ICMP_SOURCEQUENCH
9441541Srgrimes# define	ICMP_SOURCEQUENCH	4
9451541Srgrimes#endif
9461541Srgrimes#ifndef	ICMP_REDIRECT_NET
9471541Srgrimes# define	ICMP_REDIRECT_NET	0
9481541Srgrimes#endif
9491541Srgrimes#ifndef	ICMP_REDIRECT_HOST
9501541Srgrimes# define	ICMP_REDIRECT_HOST	1
9511541Srgrimes#endif
9521541Srgrimes#ifndef	ICMP_REDIRECT_TOSNET
953207475Szec# define	ICMP_REDIRECT_TOSNET	2
9541541Srgrimes#endif
9551541Srgrimes#ifndef	ICMP_REDIRECT_TOSHOST
9561541Srgrimes# define	ICMP_REDIRECT_TOSHOST	3
9571541Srgrimes#endif
9581541Srgrimes#ifndef	ICMP_ALTHOSTADDR
9591541Srgrimes# define	ICMP_ALTHOSTADDR	6
9601541Srgrimes#endif
9611541Srgrimes#ifndef	ICMP_TIMXCEED
9621541Srgrimes# define	ICMP_TIMXCEED	11
9631541Srgrimes#endif
9641541Srgrimes#ifndef	ICMP_TIMXCEED_INTRANS
9651541Srgrimes# define	ICMP_TIMXCEED_INTRANS	0
9661541Srgrimes#endif
9671541Srgrimes#ifndef	ICMP_TIMXCEED_REASS
9681541Srgrimes# define		ICMP_TIMXCEED_REASS	1
9691541Srgrimes#endif
9701541Srgrimes#ifndef	ICMP_PARAMPROB
9711541Srgrimes# define	ICMP_PARAMPROB	12
9721541Srgrimes#endif
9731541Srgrimes#ifndef	ICMP_PARAMPROB_ERRATPTR
9741541Srgrimes# define	ICMP_PARAMPROB_ERRATPTR	0
9751541Srgrimes#endif
9761541Srgrimes#ifndef	ICMP_PARAMPROB_OPTABSENT
9771541Srgrimes# define	ICMP_PARAMPROB_OPTABSENT	1
9781541Srgrimes#endif
9791541Srgrimes#ifndef	ICMP_PARAMPROB_LENGTH
9801541Srgrimes# define	ICMP_PARAMPROB_LENGTH	2
9811541Srgrimes#endif
9821541Srgrimes#ifndef ICMP_TSTAMP
9831541Srgrimes# define	ICMP_TSTAMP	13
9841541Srgrimes#endif
9851541Srgrimes#ifndef ICMP_TSTAMPREPLY
9861541Srgrimes# define	ICMP_TSTAMPREPLY	14
9871541Srgrimes#endif
9881541Srgrimes#ifndef ICMP_IREQ
9891541Srgrimes# define	ICMP_IREQ	15
990142350Ssam#endif
991142350Ssam#ifndef ICMP_IREQREPLY
992142350Ssam# define	ICMP_IREQREPLY	16
993142350Ssam#endif
9941541Srgrimes#ifndef	ICMP_MASKREQ
9951541Srgrimes# define	ICMP_MASKREQ	17
9961541Srgrimes#endif
9971541Srgrimes#ifndef ICMP_MASKREPLY
9981541Srgrimes# define	ICMP_MASKREPLY	18
9991541Srgrimes#endif
10001541Srgrimes#ifndef	ICMP_TRACEROUTE
10011541Srgrimes# define	ICMP_TRACEROUTE	30
10021541Srgrimes#endif
10031541Srgrimes#ifndef	ICMP_DATACONVERR
10041541Srgrimes# define	ICMP_DATACONVERR	31
10051541Srgrimes#endif
10061541Srgrimes#ifndef	ICMP_MOBILE_REDIRECT
10071541Srgrimes# define	ICMP_MOBILE_REDIRECT	32
10081541Srgrimes#endif
10091541Srgrimes#ifndef	ICMP_IPV6_WHEREAREYOU
101072356Sbmilekic# define	ICMP_IPV6_WHEREAREYOU	33
10111541Srgrimes#endif
101272356Sbmilekic#ifndef	ICMP_IPV6_IAMHERE
101372356Sbmilekic# define	ICMP_IPV6_IAMHERE	34
10141541Srgrimes#endif
10151541Srgrimes#ifndef	ICMP_MOBILE_REGREQUEST
10161541Srgrimes# define	ICMP_MOBILE_REGREQUEST	35
10171541Srgrimes#endif
10181541Srgrimes#ifndef	ICMP_MOBILE_REGREPLY
10191541Srgrimes# define	ICMP_MOBILE_REGREPLY	36
10201541Srgrimes#endif
10211541Srgrimes#ifndef	ICMP_SKIP
10221541Srgrimes# define	ICMP_SKIP	39
10231541Srgrimes#endif
10241541Srgrimes#ifndef	ICMP_PHOTURIS
10251541Srgrimes# define	ICMP_PHOTURIS	40
10261541Srgrimes#endif
10271541Srgrimes#ifndef	ICMP_PHOTURIS_UNKNOWN_INDEX
10281541Srgrimes# define	ICMP_PHOTURIS_UNKNOWN_INDEX	1
10291541Srgrimes#endif
10301541Srgrimes#ifndef	ICMP_PHOTURIS_AUTH_FAILED
1031111119Simp# define	ICMP_PHOTURIS_AUTH_FAILED	2
103272356Sbmilekic#endif
10331541Srgrimes#ifndef	ICMP_PHOTURIS_DECRYPT_FAILED
10341541Srgrimes# define	ICMP_PHOTURIS_DECRYPT_FAILED	3
1035108466Ssam#endif
1036108466Ssam#ifndef	IPVERSION
10371541Srgrimes# define	IPVERSION	4
10381541Srgrimes#endif
10391541Srgrimes#ifndef	IPOPT_MINOFF
10401541Srgrimes# define	IPOPT_MINOFF	4
10411541Srgrimes#endif
1042103569Sbmilekic#ifndef	IPOPT_COPIED
10431541Srgrimes# define	IPOPT_COPIED(x)	((x)&0x80)
10441541Srgrimes#endif
10451541Srgrimes#ifndef	IPOPT_EOL
10461541Srgrimes# define	IPOPT_EOL	0
10471541Srgrimes#endif
10481541Srgrimes#ifndef	IPOPT_NOP
10491541Srgrimes# define	IPOPT_NOP	1
10501541Srgrimes#endif
10511541Srgrimes#ifndef	IP_MF
10521541Srgrimes# define	IP_MF	((u_short)0x2000)
10531541Srgrimes#endif
10541541Srgrimes#ifndef	ETHERTYPE_IP
10551541Srgrimes# define	ETHERTYPE_IP	((u_short)0x0800)
10561541Srgrimes#endif
10571541Srgrimes#ifndef	TH_FIN
10581541Srgrimes# define	TH_FIN	0x01
10591541Srgrimes#endif
106078592Sbmilekic#ifndef	TH_SYN
106172356Sbmilekic# define	TH_SYN	0x02
10621541Srgrimes#endif
10631541Srgrimes#ifndef	TH_RST
10641541Srgrimes# define	TH_RST	0x04
1065143761Sjmg#endif
1066143761Sjmg#ifndef	TH_PUSH
1067143761Sjmg# define	TH_PUSH	0x08
1068143761Sjmg#endif
1069143761Sjmg#ifndef	TH_ACK
1070143761Sjmg# define	TH_ACK	0x10
1071143761Sjmg#endif
1072143761Sjmg#ifndef	TH_URG
1073143761Sjmg# define	TH_URG	0x20
1074143761Sjmg#endif
1075143761Sjmg#undef	TH_ACKMASK
1076143761Sjmg#define	TH_ACKMASK	(TH_FIN|TH_SYN|TH_RST|TH_ACK)
1077143761Sjmg
1078143761Sjmg#ifndef	IPOPT_EOL
1079143761Sjmg# define	IPOPT_EOL	0
1080143761Sjmg#endif
1081143761Sjmg#ifndef	IPOPT_NOP
1082143761Sjmg# define	IPOPT_NOP	1
1083143761Sjmg#endif
1084143761Sjmg#ifndef	IPOPT_RR
1085143761Sjmg# define	IPOPT_RR	7
1086143761Sjmg#endif
1087143761Sjmg#ifndef	IPOPT_TS
1088143761Sjmg# define	IPOPT_TS	68
1089143761Sjmg#endif
1090143761Sjmg#ifndef	IPOPT_SECURITY
1091143761Sjmg# define	IPOPT_SECURITY	130
1092143761Sjmg#endif
1093143761Sjmg#ifndef	IPOPT_LSRR
1094143761Sjmg# define	IPOPT_LSRR	131
1095143761Sjmg#endif
1096143761Sjmg#ifndef	IPOPT_SATID
1097143761Sjmg# define	IPOPT_SATID	136
1098143761Sjmg#endif
1099143761Sjmg#ifndef	IPOPT_SSRR
1100143761Sjmg# define	IPOPT_SSRR	137
1101143761Sjmg#endif
1102143761Sjmg#ifndef	IPOPT_SECUR_UNCLASS
1103143761Sjmg# define	IPOPT_SECUR_UNCLASS	((u_short)0x0000)
1104143761Sjmg#endif
1105143761Sjmg#ifndef	IPOPT_SECUR_CONFID
1106143761Sjmg# define	IPOPT_SECUR_CONFID	((u_short)0xf135)
1107143761Sjmg#endif
1108143761Sjmg#ifndef	IPOPT_SECUR_EFTO
1109143761Sjmg# define	IPOPT_SECUR_EFTO	((u_short)0x789a)
1110143761Sjmg#endif
1111143761Sjmg#ifndef	IPOPT_SECUR_MMMM
1112143761Sjmg# define	IPOPT_SECUR_MMMM	((u_short)0xbc4d)
11131541Srgrimes#endif
11141541Srgrimes#ifndef	IPOPT_SECUR_RESTR
11151541Srgrimes# define	IPOPT_SECUR_RESTR	((u_short)0xaf13)
111697681Sarchie#endif
111797681Sarchie#ifndef	IPOPT_SECUR_SECRET
111897681Sarchie# define	IPOPT_SECUR_SECRET	((u_short)0xd788)
111997681Sarchie#endif
112097681Sarchie#ifndef IPOPT_SECUR_TOPSECRET
11211541Srgrimes# define	IPOPT_SECUR_TOPSECRET	((u_short)0x6bc5)
11221541Srgrimes#endif
112372356Sbmilekic#ifndef IPOPT_OLEN
11241541Srgrimes# define	IPOPT_OLEN	1
112572356Sbmilekic#endif
1126103569Sbmilekic#ifndef	IPPROTO_HOPOPTS
11271541Srgrimes# define	IPPROTO_HOPOPTS	0
1128132488Salfred#endif
11291541Srgrimes#ifndef	IPPROTO_IPIP
11301541Srgrimes# define	IPPROTO_IPIP	4
113172356Sbmilekic#endif
113272356Sbmilekic#ifndef	IPPROTO_ENCAP
11331541Srgrimes# define	IPPROTO_ENCAP	98
11341541Srgrimes#endif
11351541Srgrimes#ifndef	IPPROTO_IPV6
113672356Sbmilekic# define	IPPROTO_IPV6	41
113772356Sbmilekic#endif
11381541Srgrimes#ifndef	IPPROTO_ROUTING
11391541Srgrimes# define	IPPROTO_ROUTING	43
11401541Srgrimes#endif
11411541Srgrimes#ifndef	IPPROTO_FRAGMENT
11421541Srgrimes# define	IPPROTO_FRAGMENT	44
11431541Srgrimes#endif
11441541Srgrimes#ifndef	IPPROTO_GRE
11451541Srgrimes# define	IPPROTO_GRE	47	/* GRE encaps RFC 1701 */
11461541Srgrimes#endif
114772356Sbmilekic#ifndef	IPPROTO_ESP
11481541Srgrimes# define	IPPROTO_ESP	50
114972356Sbmilekic#endif
115094471Shsu#ifndef	IPPROTO_AH
115194471Shsu# define	IPPROTO_AH	51
11521541Srgrimes#endif
115394471Shsu#ifndef	IPPROTO_ICMPV6
11541541Srgrimes# define	IPPROTO_ICMPV6	58
11551541Srgrimes#endif
11561541Srgrimes#ifndef	IPPROTO_NONE
11571541Srgrimes# define	IPPROTO_NONE	59
115872356Sbmilekic#endif
11591541Srgrimes#ifndef	IPPROTO_DSTOPTS
11601541Srgrimes# define	IPPROTO_DSTOPTS	60
11611541Srgrimes#endif
116272356Sbmilekic#ifndef	IPPROTO_MOBILITY
116372356Sbmilekic# define	IPPROTO_MOBILITY	135
11641541Srgrimes#endif
11651541Srgrimes
11661541Srgrimes#ifndef	ICMP_ROUTERADVERT
11671541Srgrimes# define	ICMP_ROUTERADVERT	9
11681541Srgrimes#endif
1169151976Sandre#ifndef	ICMP_ROUTERSOLICIT
11701541Srgrimes# define	ICMP_ROUTERSOLICIT	10
11711541Srgrimes#endif
11721541Srgrimes#ifndef	ICMP6_DST_UNREACH
11731541Srgrimes# define	ICMP6_DST_UNREACH	1
11741541Srgrimes#endif
11751541Srgrimes#ifndef	ICMP6_PACKET_TOO_BIG
117672356Sbmilekic# define	ICMP6_PACKET_TOO_BIG	2
11771541Srgrimes#endif
11781541Srgrimes#ifndef	ICMP6_TIME_EXCEEDED
11791541Srgrimes# define	ICMP6_TIME_EXCEEDED	3
11801541Srgrimes#endif
118178508Sbmilekic#ifndef	ICMP6_PARAM_PROB
118278508Sbmilekic# define	ICMP6_PARAM_PROB	4
11831541Srgrimes#endif
11841541Srgrimes
118578508Sbmilekic#ifndef	ICMP6_ECHO_REQUEST
1186169624Srwatson# define	ICMP6_ECHO_REQUEST	128
11871541Srgrimes#endif
118872356Sbmilekic#ifndef	ICMP6_ECHO_REPLY
1189129906Sbmilekic# define	ICMP6_ECHO_REPLY	129
119078508Sbmilekic#endif
11911541Srgrimes#ifndef	ICMP6_MEMBERSHIP_QUERY
119278508Sbmilekic# define	ICMP6_MEMBERSHIP_QUERY	130
119378508Sbmilekic#endif
119478508Sbmilekic#ifndef	MLD6_LISTENER_QUERY
1195129906Sbmilekic# define	MLD6_LISTENER_QUERY	130
1196129906Sbmilekic#endif
1197129906Sbmilekic#ifndef	ICMP6_MEMBERSHIP_REPORT
1198129906Sbmilekic# define	ICMP6_MEMBERSHIP_REPORT	131
1199129906Sbmilekic#endif
1200129906Sbmilekic#ifndef	MLD6_LISTENER_REPORT
1201129906Sbmilekic# define	MLD6_LISTENER_REPORT	131
1202129906Sbmilekic#endif
12031541Srgrimes#ifndef	ICMP6_MEMBERSHIP_REDUCTION
1204129906Sbmilekic# define	ICMP6_MEMBERSHIP_REDUCTION	132
1205129906Sbmilekic#endif
1206129906Sbmilekic#ifndef	MLD6_LISTENER_DONE
1207129906Sbmilekic# define	MLD6_LISTENER_DONE	132
1208129906Sbmilekic#endif
1209129906Sbmilekic#ifndef	ND_ROUTER_SOLICIT
1210129906Sbmilekic# define	ND_ROUTER_SOLICIT	133
1211129906Sbmilekic#endif
1212129906Sbmilekic#ifndef	ND_ROUTER_ADVERT
1213129906Sbmilekic# define	ND_ROUTER_ADVERT	134
1214129906Sbmilekic#endif
1215129906Sbmilekic#ifndef	ND_NEIGHBOR_SOLICIT
1216129906Sbmilekic# define	ND_NEIGHBOR_SOLICIT	135
1217129906Sbmilekic#endif
1218129906Sbmilekic#ifndef	ND_NEIGHBOR_ADVERT
1219129906Sbmilekic# define	ND_NEIGHBOR_ADVERT	136
1220129906Sbmilekic#endif
1221129906Sbmilekic#ifndef	ND_REDIRECT
122272356Sbmilekic# define	ND_REDIRECT	137
12231541Srgrimes#endif
1224129906Sbmilekic#ifndef	ICMP6_ROUTER_RENUMBERING
12251541Srgrimes# define	ICMP6_ROUTER_RENUMBERING	138
12261541Srgrimes#endif
122778508Sbmilekic#ifndef	ICMP6_WRUREQUEST
122878508Sbmilekic# define	ICMP6_WRUREQUEST	139
122978508Sbmilekic#endif
123078508Sbmilekic#ifndef	ICMP6_WRUREPLY
123178508Sbmilekic# define	ICMP6_WRUREPLY		140
123278508Sbmilekic#endif
12331541Srgrimes#ifndef	ICMP6_FQDN_QUERY
1234103569Sbmilekic# define	ICMP6_FQDN_QUERY	139
12351541Srgrimes#endif
1236103569Sbmilekic#ifndef	ICMP6_FQDN_REPLY
123778508Sbmilekic# define	ICMP6_FQDN_REPLY	140
12381541Srgrimes#endif
12391541Srgrimes#ifndef	ICMP6_NI_QUERY
12401541Srgrimes# define	ICMP6_NI_QUERY		139
12411541Srgrimes#endif
12421541Srgrimes#ifndef	ICMP6_NI_REPLY
12431541Srgrimes# define	ICMP6_NI_REPLY		140
12443352Sphk#endif
12453352Sphk#ifndef	MLD6_MTRACE_RESP
12463352Sphk# define	MLD6_MTRACE_RESP	200
12473352Sphk#endif
12483352Sphk#ifndef	MLD6_MTRACE
12493352Sphk# define	MLD6_MTRACE		201
12503352Sphk#endif
1251128402Sluigi#ifndef	ICMP6_HADISCOV_REQUEST
12523352Sphk# define	ICMP6_HADISCOV_REQUEST	202
125372356Sbmilekic#endif
125472356Sbmilekic#ifndef	ICMP6_HADISCOV_REPLY
12553352Sphk# define	ICMP6_HADISCOV_REPLY	203
12563352Sphk#endif
125772356Sbmilekic#ifndef	ICMP6_MOBILEPREFIX_SOLICIT
12583352Sphk# define	ICMP6_MOBILEPREFIX_SOLICIT	204
12593352Sphk#endif
12603352Sphk#ifndef	ICMP6_MOBILEPREFIX_ADVERT
12613352Sphk# define	ICMP6_MOBILEPREFIX_ADVERT	205
126272356Sbmilekic#endif
1263129906Sbmilekic#ifndef	ICMP6_MAXTYPE
126472356Sbmilekic# define	ICMP6_MAXTYPE		205
12653352Sphk#endif
1266129906Sbmilekic
12673352Sphk#ifndef	ICMP6_DST_UNREACH_NOROUTE
12683352Sphk# define	ICMP6_DST_UNREACH_NOROUTE	0
12693352Sphk#endif
12703352Sphk#ifndef	ICMP6_DST_UNREACH_ADMIN
12713352Sphk# define	ICMP6_DST_UNREACH_ADMIN		1
12723352Sphk#endif
1273187409Smav#ifndef	ICMP6_DST_UNREACH_NOTNEIGHBOR
1274187409Smav# define	ICMP6_DST_UNREACH_NOTNEIGHBOR	2
1275187409Smav#endif
1276187409Smav#ifndef	ICMP6_DST_UNREACH_BEYONDSCOPE
12773352Sphk# define	ICMP6_DST_UNREACH_BEYONDSCOPE	2
1278103569Sbmilekic#endif
12793352Sphk#ifndef	ICMP6_DST_UNREACH_ADDR
12803352Sphk# define	ICMP6_DST_UNREACH_ADDR		3
12813352Sphk#endif
12823352Sphk#ifndef	ICMP6_DST_UNREACH_NOPORT
12833352Sphk# define	ICMP6_DST_UNREACH_NOPORT	4
12843352Sphk#endif
12853352Sphk#ifndef	ICMP6_TIME_EXCEED_TRANSIT
128672356Sbmilekic# define	ICMP6_TIME_EXCEED_TRANSIT	0
1287111119Simp#endif
128872356Sbmilekic#ifndef	ICMP6_TIME_EXCEED_REASSEMBLY
12893352Sphk# define	ICMP6_TIME_EXCEED_REASSEMBLY	1
12903352Sphk#endif
12913352Sphk
12923352Sphk#ifndef	ICMP6_NI_SUCCESS
12933352Sphk# define	ICMP6_NI_SUCCESS	0
12943352Sphk#endif
12953352Sphk#ifndef	ICMP6_NI_REFUSED
12963352Sphk# define	ICMP6_NI_REFUSED	1
12973352Sphk#endif
129852756Sphk#ifndef	ICMP6_NI_UNKNOWN
1299123557Sbms# define	ICMP6_NI_UNKNOWN	2
1300138541Ssam#endif
1301138541Ssam
1302138541Ssam#ifndef	ICMP6_ROUTER_RENUMBERING_COMMAND
1303138541Ssam# define	ICMP6_ROUTER_RENUMBERING_COMMAND	0
1304138541Ssam#endif
1305138541Ssam#ifndef	ICMP6_ROUTER_RENUMBERING_RESULT
1306138541Ssam# define	ICMP6_ROUTER_RENUMBERING_RESULT	1
1307138541Ssam#endif
1308138541Ssam#ifndef	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1309138541Ssam# define	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET	255
1310138541Ssam#endif
1311138541Ssam
1312138541Ssam#ifndef	ICMP6_PARAMPROB_HEADER
1313138541Ssam# define	ICMP6_PARAMPROB_HEADER	0
1314138541Ssam#endif
1315138541Ssam#ifndef	ICMP6_PARAMPROB_NEXTHEADER
1316138541Ssam# define	ICMP6_PARAMPROB_NEXTHEADER	1
1317138541Ssam#endif
1318138541Ssam#ifndef	ICMP6_PARAMPROB_OPTION
1319138541Ssam# define	ICMP6_PARAMPROB_OPTION	2
1320138541Ssam#endif
1321138541Ssam
1322138541Ssam#ifndef	ICMP6_NI_SUBJ_IPV6
1323138541Ssam# define	ICMP6_NI_SUBJ_IPV6	0
1324138541Ssam#endif
1325138541Ssam#ifndef	ICMP6_NI_SUBJ_FQDN
1326138541Ssam# define	ICMP6_NI_SUBJ_FQDN	1
1327138541Ssam#endif
1328138541Ssam#ifndef	ICMP6_NI_SUBJ_IPV4
1329138541Ssam# define	ICMP6_NI_SUBJ_IPV4	2
1330138541Ssam#endif
1331138541Ssam
1332138541Ssam#ifndef	MLD_MTRACE_RESP
1333138541Ssam# define	MLD_MTRACE_RESP		200
1334138541Ssam#endif
1335138894Ssam#ifndef	MLD_MTRACE
1336138894Ssam# define	MLD_MTRACE		201
1337138541Ssam#endif
1338138541Ssam#ifndef	MLD6_MTRACE_RESP
1339138541Ssam# define	MLD6_MTRACE_RESP	MLD_MTRACE_RESP
1340138541Ssam#endif
1341138541Ssam#ifndef	MLD6_MTRACE
1342138541Ssam# define	MLD6_MTRACE		MLD_MTRACE
1343138541Ssam#endif
1344138541Ssam
1345138541Ssam#if !defined(IPV6_FLOWINFO_MASK)
1346123557Sbms# if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1347123557Sbms#  define IPV6_FLOWINFO_MASK	0x0fffffff	/* flow info (28 bits) */
1348123557Sbms# else
1349123557Sbms#  if(BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1350123557Sbms#   define IPV6_FLOWINFO_MASK	0xffffff0f	/* flow info (28 bits) */
1351123564Sbms#  endif /* LITTLE_ENDIAN */
1352123557Sbms# endif
1353123564Sbms#endif
1354123557Sbms#if !defined(IPV6_FLOWLABEL_MASK)
1355123557Sbms# if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1356123557Sbms#  define IPV6_FLOWLABEL_MASK	0x000fffff	/* flow label (20 bits) */
1357123557Sbms# else
1358123557Sbms#  if (BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1359123557Sbms#   define IPV6_FLOWLABEL_MASK	0xffff0f00	/* flow label (20 bits) */
1360123557Sbms#  endif /* LITTLE_ENDIAN */
1361123557Sbms# endif
1362123557Sbms#endif
1363123557Sbms
1364123557Sbms/*
1365123557Sbms * ECN is a new addition to TCP - RFC 2481
1366123557Sbms */
1367123557Sbms#ifndef TH_ECN
1368123557Sbms# define	TH_ECN	0x40
1369123557Sbms#endif
1370123557Sbms#ifndef TH_CWR
1371123557Sbms# define	TH_CWR	0x80
1372123557Sbms#endif
1373123557Sbms#define	TH_ECNALL	(TH_ECN|TH_CWR)
1374123557Sbms
1375123557Sbms/*
1376123557Sbms * TCP States
1377123557Sbms */
1378123557Sbms#define IPF_TCPS_LISTEN		0	/* listening for connection */
1379123557Sbms#define IPF_TCPS_SYN_SENT	1	/* active, have sent syn */
1380123557Sbms#define IPF_TCPS_SYN_RECEIVED	2	/* have send and received syn */
1381123557Sbms#define IPF_TCPS_HALF_ESTAB	3	/* for connections not fully "up" */
1382123557Sbms/* states < IPF_TCPS_ESTABLISHED are those where connections not established */
1383123557Sbms#define IPF_TCPS_ESTABLISHED	4	/* established */
1384123557Sbms#define IPF_TCPS_CLOSE_WAIT	5	/* rcvd fin, waiting for close */
1385123557Sbms/* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
1386123564Sbms#define IPF_TCPS_FIN_WAIT_1	6	/* have closed, sent fin */
1387123557Sbms#define IPF_TCPS_CLOSING	7	/* closed xchd FIN; await FIN ACK */
1388123557Sbms#define IPF_TCPS_LAST_ACK	8	/* had fin and close; await FIN ACK */
1389123557Sbms/* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
1390123557Sbms#define IPF_TCPS_FIN_WAIT_2	9	/* have closed, fin is acked */
1391123557Sbms#define IPF_TCPS_TIME_WAIT	10	/* in 2*msl quiet wait after close */
1392123557Sbms#define IPF_TCPS_CLOSED		11	/* closed */
1393123557Sbms#define IPF_TCP_NSTATES		12
1394123564Sbms
1395123557Sbms#define	TCP_MSL			120
1396123557Sbms
1397123564Sbms#undef	ICMP_MAX_UNREACH
1398123564Sbms#define	ICMP_MAX_UNREACH	14
1399123564Sbms#undef	ICMP_MAXTYPE
1400123564Sbms#define	ICMP_MAXTYPE		18
1401123557Sbms
1402123557Sbms#ifndef	LOG_FTP
1403123557Sbms# define	LOG_FTP		(11<<3)
1404123557Sbms#endif
1405123557Sbms#ifndef	LOG_AUTHPRIV
140652756Sphk# define	LOG_AUTHPRIV	(10<<3)
1407135904Sjmg#endif
140852756Sphk#ifndef	LOG_AUDIT
140952756Sphk# define	LOG_AUDIT	(13<<3)
1410135904Sjmg#endif
141154906Seivind#ifndef	LOG_NTP
141252756Sphk# define	LOG_NTP		(12<<3)
1413230587Sken#endif
1414230587Sken#ifndef	LOG_SECURITY
1415230587Sken# define	LOG_SECURITY	(13<<3)
1416230587Sken#endif
1417230587Sken#ifndef	LOG_LFMT
1418135904Sjmg# define	LOG_LFMT	(14<<3)
1419135904Sjmg#endif
1420135904Sjmg#ifndef	LOG_CONSOLE
1421135904Sjmg# define	LOG_CONSOLE	(14<<3)
142252756Sphk#endif
1423135904Sjmg
1424135904Sjmg/*
1425135904Sjmg * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1426135904Sjmg * another IP header and then 64 bits of data, totalling 56.  Of course,
1427135904Sjmg * the last 64 bits is dependent on that being available.
1428135904Sjmg */
1429135904Sjmg#define	ICMPERR_ICMPHLEN	8
1430135904Sjmg#define	ICMPERR_IPICMPHLEN	(20 + 8)
1431135904Sjmg#define	ICMPERR_MINPKTLEN	(20 + 8 + 20)
1432156700Sjmg#define	ICMPERR_MAXPKTLEN	(20 + 8 + 20 + 8)
1433135904Sjmg#define ICMP6ERR_MINPKTLEN	(40 + 8)
1434135904Sjmg#define ICMP6ERR_IPICMPHLEN	(40 + 8 + 40)
143552756Sphk
143652756Sphk#ifndef MIN
1437135904Sjmg# define	MIN(a,b)	(((a)<(b))?(a):(b))
1438135904Sjmg#endif
143952756Sphk
144052756Sphk#ifdef RESCUE
1441103540Sphk# undef IPFILTER_BPF
1442103569Sbmilekic#endif
1443103540Sphk
1444103540Sphk#ifdef IPF_DEBUG
1445103569Sbmilekic# define	DPRINT(x)	printf x
1446103540Sphk#else
1447103544Sphk# define	DPRINT(x)
1448103544Sphk#endif
1449103544Sphk
1450103544Sphk#ifdef DTRACE_PROBE
1451103544Sphk# ifdef _KERNEL
1452103569Sbmilekic#  define	DT(_n)			DTRACE_PROBE(_n)
1453103544Sphk#  define	DT1(_n,_a,_b)		DTRACE_PROBE1(_n,_a,_b)
1454103544Sphk#  define	DT2(_n,_a,_b,_c,_d)	DTRACE_PROBE2(_n,_a,_b,_c,_d)
1455103544Sphk#  define	DT3(_n,_a,_b,_c,_d,_e,_f)	\
1456103569Sbmilekic					DTRACE_PROBE3(_n,_a,_b,_c,_d,_e,_f)
1457103544Sphk#  define	DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h) \
1458103544Sphk				DTRACE_PROBE4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1459103544Sphk# else
1460103540Sphk#  define	DT(_n)
1461103544Sphk#  define	DT1(_n,_a,_b)
1462103544Sphk#  define	DT2(_n,_a,_b,_c,_d)
1463103540Sphk#  define	DT3(_n,_a,_b,_c,_d,_e,_f)
1464103544Sphk#  define	DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1465103544Sphk# endif
1466103544Sphk#else
1467103540Sphk# define	DT(_n)
1468112777Ssilby# define	DT1(_n,_a,_b)
1469112777Ssilby# define	DT2(_n,_a,_b,_c,_d)
1470112777Ssilby# define	DT3(_n,_a,_b,_c,_d,_e,_f)
1471112777Ssilby# define	DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1472112777Ssilby#endif
1473112777Ssilby
1474112777Ssilbystruct ip6_routing {
1475112777Ssilby	u_char	ip6r_nxt;	/* next header */
1476112777Ssilby	u_char	ip6r_len;	/* length in units of 8 octets */
1477112777Ssilby	u_char	ip6r_type;	/* always zero */
1478112777Ssilby	u_char	ip6r_segleft;	/* segments left */
1479112777Ssilby	u_32_t	ip6r_reserved;	/* reserved field */
1480112777Ssilby};
1481112777Ssilby
1482112777Ssilby#endif	/* __IP_COMPAT_H__ */
1483125472Ssilby