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