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