ip_compat.h revision 153882
1/*
2 * Copyright (C) 1993-2001, 2003 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: head/sys/contrib/ipfilter/netinet/ip_compat.h 153882 2005-12-30 11:55:37Z guido $
8 * Id: ip_compat.h,v 2.142.2.25 2005/03/28 09:33:36 darrenr Exp
9 */
10
11#ifndef	__IP_COMPAT_H__
12#define	__IP_COMPAT_H__
13
14#ifndef	__P
15# ifdef	__STDC__
16#  define	__P(x)  x
17# else
18#  define	__P(x)  ()
19# endif
20#endif
21#ifndef	__STDC__
22# undef		const
23# define	const
24#endif
25
26#if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
27# undef	KERNEL
28# undef	_KERNEL
29# undef 	__KERNEL__
30# define	KERNEL
31# define	_KERNEL
32# define 	__KERNEL__
33#endif
34
35#ifndef	SOLARIS
36#define	SOLARIS	(defined(sun) && (defined(__svr4__) || defined(__SVR4)))
37#endif
38#if defined(SOLARIS2) && SOLARIS2 >= 8
39# ifndef	USE_INET6
40#  define	USE_INET6
41# endif
42#endif
43#if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
44    !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
45# define	USE_INET6
46#endif
47#if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \
48    !defined(_KERNEL) && !defined(USE_INET6)
49# define	USE_INET6
50# define	IPFILTER_M_IPFILTER
51#endif
52#if defined(OpenBSD) && (OpenBSD >= 200206) && \
53    !defined(_KERNEL) && !defined(USE_INET6)
54# define	USE_INET6
55#endif
56#if defined(__osf__)
57# define	USE_INET6
58#endif
59#if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6))
60# define	USE_INET6
61#endif
62#if defined(HPUXREV) && (HPUXREV >= 1111)
63# define	USE_INET6
64#endif
65
66#if defined(BSD) && (BSD < 199103) && defined(__osf__)
67# undef BSD
68# define BSD 199103
69#endif
70
71#if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
72# define index   strchr
73# if !defined(_KERNEL)
74#  define	bzero(a,b)	memset(a,0,b)
75#  define	bcmp		memcmp
76#  define	bcopy(a,b,c)	memmove(b,a,c)
77# endif
78#endif
79
80#ifndef LIFNAMSIZ
81# ifdef IF_NAMESIZE
82#  define	LIFNAMSIZ	IF_NAMESIZE
83# else
84#  ifdef	IFNAMSIZ
85#   define	LIFNAMSIZ	IFNAMSIZ
86#  else
87#   define	LIFNAMSIZ	16
88#  endif
89# endif
90#endif
91
92#if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
93struct  ether_addr {
94        u_char  ether_addr_octet[6];
95};
96#endif
97
98#if defined(__sgi) && !defined(IPFILTER_LKM)
99# ifdef __STDC__
100#  define IPL_EXTERN(ep) ipfilter##ep
101# else
102#  define IPL_EXTERN(ep) ipfilter/**/ep
103# endif
104#else
105# ifdef __STDC__
106#  define IPL_EXTERN(ep) ipl##ep
107# else
108#  define IPL_EXTERN(ep) ipl/**/ep
109# endif
110#endif
111
112/*
113 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
114 */
115#ifndef linux
116# ifndef _KERNEL
117#  define ADD_KERNEL
118#  define _KERNEL
119#  define KERNEL
120# endif
121# ifdef __OpenBSD__
122struct file;
123# endif
124# include <sys/uio.h>
125# ifdef ADD_KERNEL
126#  undef _KERNEL
127#  undef KERNEL
128# endif
129#endif
130
131
132/* ----------------------------------------------------------------------- */
133/*                                  S O L A R I S                          */
134/* ----------------------------------------------------------------------- */
135#if SOLARIS
136# define	MENTAT	1
137# include	<sys/cmn_err.h>
138# include	<sys/isa_defs.h>
139# include	<sys/stream.h>
140# include	<sys/ioccom.h>
141# include	<sys/sysmacros.h>
142# include	<sys/kmem.h>
143# if defined(SOLARIS2) && SOLARIS2 >= 10
144#  include	<sys/procset.h>
145#  include	<sys/proc.h>
146#  include	<sys/devops.h>
147#  include	<sys/ddi_impldefs.h>
148# endif
149/*
150 * because Solaris 2 defines these in two places :-/
151 */
152# ifndef	KERNEL
153#  define	_KERNEL
154#  undef	RES_INIT
155# endif /* _KERNEL */
156
157# if defined(SOLARIS2) && SOLARIS2 >= 8
158#  include <netinet/ip6.h>
159#  include <netinet/icmp6.h>
160# endif
161
162# include <inet/common.h>
163/* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */
164# undef	IPOPT_EOL
165# undef	IPOPT_NOP
166# undef	IPOPT_LSRR
167# undef	IPOPT_RR
168# undef	IPOPT_SSRR
169# ifdef i386
170#  define _SYS_PROMIF_H
171# endif
172# include <inet/ip.h>
173# undef COPYOUT
174# include <inet/ip_ire.h>
175# ifndef	KERNEL
176#  undef	_KERNEL
177# endif
178# if defined(SOLARIS2) && SOLARIS2 >= 8
179#  define SNPRINTF	snprintf
180
181#  include <inet/ip_if.h>
182#  define	ipif_local_addr	ipif_lcl_addr
183/* Only defined in private include file */
184#  ifndef	V4_PART_OF_V6
185#   define	V4_PART_OF_V6(v6)	v6.s6_addr32[3]
186#  endif
187struct ip6_ext {
188	u_char	ip6e_nxt;
189	u_char	ip6e_len;
190};
191# endif /* SOLARIS2 >= 8 */
192
193# if defined(SOLARIS2) && SOLARIS2 >= 6
194#  include <sys/atomic.h>
195typedef	uint32_t	u_32_t;
196# else
197typedef unsigned int	u_32_t;
198# endif
199# define	U_32_T	1
200
201# ifdef _KERNEL
202#  define	KRWLOCK_T		krwlock_t
203#  define	KMUTEX_T		kmutex_t
204#  include "qif.h"
205#  include "pfil.h"
206#  if defined(SOLARIS2) && SOLARIS2 >= 6
207#   if SOLARIS2 == 6
208#    define	ATOMIC_INCL(x)		atomic_add_long((uint32_t*)&(x), 1)
209#    define	ATOMIC_DECL(x)		atomic_add_long((uint32_t*)&(x), -1)
210#   else
211#    define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
212#    define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
213#   endif /* SOLARIS2 == 6 */
214#   define	ATOMIC_INC64(x)		atomic_add_64((uint64_t*)&(x), 1)
215#   define	ATOMIC_INC32(x)		atomic_add_32((uint32_t*)&(x), 1)
216#   define	ATOMIC_INC16(x)		atomic_add_16((uint16_t*)&(x), 1)
217#   define	ATOMIC_DEC64(x)		atomic_add_64((uint64_t*)&(x), -1)
218#   define	ATOMIC_DEC32(x)		atomic_add_32((uint32_t*)&(x), -1)
219#   define	ATOMIC_DEC16(x)		atomic_add_16((uint16_t*)&(x), -1)
220#  else
221#   define	ATOMIC_INC(x)		{ mutex_enter(&ipf_rw); (x)++; \
222					  mutex_exit(&ipf_rw); }
223#   define	ATOMIC_DEC(x)		{ mutex_enter(&ipf_rw); (x)--; \
224					  mutex_exit(&ipf_rw); }
225#  endif /* SOLARIS2 >= 6 */
226#  define	USE_MUTEXES
227#  define	MUTEX_ENTER(x)		mutex_enter(&(x)->ipf_lk)
228#  define	READ_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_READER)
229#  define	WRITE_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_WRITER)
230#  define	MUTEX_DOWNGRADE(x)	rw_downgrade(&(x)->ipf_lk)
231#  define	RWLOCK_INIT(x, y)	rw_init(&(x)->ipf_lk, (y),  \
232						RW_DRIVER, NULL)
233#  define	RWLOCK_EXIT(x)		rw_exit(&(x)->ipf_lk)
234#  define	RW_DESTROY(x)		rw_destroy(&(x)->ipf_lk)
235#  define	MUTEX_INIT(x, y)	mutex_init(&(x)->ipf_lk, (y), \
236						   MUTEX_DRIVER, NULL)
237#  define	MUTEX_DESTROY(x)	mutex_destroy(&(x)->ipf_lk)
238#  define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
239#  define	MUTEX_EXIT(x)		mutex_exit(&(x)->ipf_lk)
240#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
241#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
242#  define	BCOPYIN(a,b,c)	(void) copyin((caddr_t)(a), (caddr_t)(b), (c))
243#  define	BCOPYOUT(a,b,c)	(void) copyout((caddr_t)(a), (caddr_t)(b), (c))
244#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
245#  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
246#  define	KFREES(x,s)	kmem_free((char *)(x), (s))
247#  define	SPL_NET(x)	;
248#  define	SPL_IMP(x)	;
249#  undef	SPL_X
250#  define	SPL_X(x)	;
251#  ifdef sparc
252#   define	ntohs(x)	(x)
253#   define	ntohl(x)	(x)
254#   define	htons(x)	(x)
255#   define	htonl(x)	(x)
256#  endif /* sparc */
257#  define	KMALLOC(a,b)	(a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
258#  define	KMALLOCS(a,b,c)	(a) = (b)kmem_alloc((c), KM_NOSLEEP)
259#  define	GET_MINOR(x)	getminor(x)
260extern	void	*get_unit __P((char *, int));
261#  define	GETIFP(n, v)	get_unit(n, v)
262#  define	IFNAME(x)	((qif_t *)x)->qf_name
263#  define	COPYIFNAME(x, b) \
264				(void) strncpy(b, ((qif_t *)x)->qf_name, \
265					       LIFNAMSIZ)
266#  define	GETKTIME(x)	uniqtime((struct timeval *)x)
267#  define	MSGDSIZE(x)	msgdsize(x)
268#  define	M_LEN(x)	((x)->b_wptr - (x)->b_rptr)
269#  define	M_DUPLICATE(x)	dupmsg((x))
270#  define	MTOD(m,t)	((t)((m)->b_rptr))
271#  define	MTYPE(m)	((m)->b_datap->db_type)
272#  define	FREE_MB_T(m)	freemsg(m)
273#  define	m_next		b_cont
274#  define	CACHE_HASH(x)	(((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
275#  define	IPF_PANIC(x,y)	if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
276typedef mblk_t mb_t;
277# endif /* _KERNEL */
278
279# if defined(SOLARIS2) && (SOLARIS2 >= 7)
280#  ifdef lint
281#   define ALIGN32(ptr)    (ptr ? 0L : 0L)
282#   define ALIGN16(ptr)    (ptr ? 0L : 0L)
283#  else
284#   define ALIGN32(ptr)    (ptr)
285#   define ALIGN16(ptr)    (ptr)
286#  endif
287# endif
288
289# if defined(SOLARIS2) && SOLARIS2 < 6
290typedef	struct uio	uio_t;
291# endif
292typedef	int		ioctlcmd_t;
293
294# define OS_RECOGNISED 1
295
296#endif /* SOLARIS */
297
298/* ----------------------------------------------------------------------- */
299/*                                  H P U X                                */
300/* ----------------------------------------------------------------------- */
301#ifdef __hpux
302# define	MENTAT	1
303# include	<sys/sysmacros.h>
304# include	<sys/spinlock.h>
305# include	<sys/lock.h>
306# include	<sys/stream.h>
307# ifdef USE_INET6
308#  include	<netinet/if_ether.h>
309#  include	<netinet/ip6.h>
310#  include	<netinet/icmp6.h>
311typedef	struct	ip6_hdr	ip6_t;
312# endif
313
314# ifdef _KERNEL
315#  define SNPRINTF	sprintf
316#  if (HPUXREV >= 1111)
317#   define	IPL_SELECT
318#   ifdef	IPL_SELECT
319#    include	<machine/sys/user.h>
320#    include	<sys/kthread_iface.h>
321#    define	READ_COLLISION	0x01
322
323typedef	struct	iplog_select_s {
324	kthread_t	*read_waiter;
325	int		state;
326} iplog_select_t;
327#   endif
328#  endif
329
330#  define	GETKTIME(x)	uniqtime((struct timeval *)x)
331
332#  if HPUXREV == 1111
333#   include	"kern_svcs.h"
334#  else
335#   include	<sys/kern_svcs.h>
336#  endif
337#  undef	ti_flags
338#  undef	TCP_NODELAY
339#  undef	TCP_MAXSEG
340#  include <sys/reg.h>
341#  include "../netinet/ip_info.h"
342/*
343 * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
344 * are available.  Attempting to use them actually results in unresolved
345 * symbols when it comes time to load the module.
346 * This has been fixed!  Yipee!
347 */
348#  if 1
349#   ifdef __LP64__
350#    define	ATOMIC_INCL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
351#    define	ATOMIC_DECL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
352#   else
353#    define	ATOMIC_INCL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
354#    define	ATOMIC_DECL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
355#   endif
356#   define	ATOMIC_INC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
357#   define	ATOMIC_INC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
358#   define	ATOMIC_INC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
359#   define	ATOMIC_DEC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
360#   define	ATOMIC_DEC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
361#   define	ATOMIC_DEC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
362#  else /* 0 */
363#   define	ATOMIC_INC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
364					  MUTEX_EXIT(&ipf_rw); }
365#   define	ATOMIC_DEC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
366					  MUTEX_EXIT(&ipf_rw); }
367#   define	ATOMIC_INC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
368					  MUTEX_EXIT(&ipf_rw); }
369#   define	ATOMIC_DEC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
370					  MUTEX_EXIT(&ipf_rw); }
371#   define	ATOMIC_INCL(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
372					  MUTEX_EXIT(&ipf_rw); }
373#   define	ATOMIC_DECL(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
374					  MUTEX_EXIT(&ipf_rw); }
375#   define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
376					  MUTEX_EXIT(&ipf_rw); }
377#   define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
378					  MUTEX_EXIT(&ipf_rw); }
379#  endif
380#  define	ip_cksum		ip_csuma
381#  define	memcpy(a,b,c)		bcopy((caddr_t)b, (caddr_t)a, c)
382#  define	USE_MUTEXES
383#  define	MUTEX_INIT(x, y)	initlock(&(x)->ipf_lk, 0, 0, (y))
384#  define	MUTEX_ENTER(x)		spinlock(&(x)->ipf_lk)
385#  define	MUTEX_EXIT(x)		spinunlock(&(x)->ipf_lk);
386#  define	MUTEX_DESTROY(x)
387#  define	MUTEX_NUKE(x)		bzero((char *)(x), sizeof(*(x)))
388#  define	KMUTEX_T		lock_t
389#  define	kmutex_t		lock_t		/* for pfil.h */
390#  define	krwlock_t		lock_t		/* for pfil.h */
391/*
392 * The read-write lock implementation in HP-UX 11.0 is crippled - it can
393 * only be used by threads working in a user context!
394 * This has been fixed!  Yipee! (Or at least it does in 11.00, not 11.11..)
395 */
396#  if HPUXREV < 1111
397#   define	MUTEX_DOWNGRADE(x)	lock_write_to_read(x)
398#   define	KRWLOCK_T		struct rw_lock
399#   define	READ_ENTER(x)		lock_read(&(x)->ipf_lk)
400#   define	WRITE_ENTER(x)		lock_write(&(x)->ipf_lk)
401#   if HPUXREV >= 1111
402#    define	RWLOCK_INIT(x, y)	rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
403#   else
404#    define	RWLOCK_INIT(x, y)	lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
405#   endif
406#   define	RWLOCK_EXIT(x)		lock_done(&(x)->ipf_lk)
407#  else
408#   define	KRWLOCK_T		lock_t
409#   define	KMUTEX_T		lock_t
410#   define	READ_ENTER(x)		MUTEX_ENTER(x)
411#   define	WRITE_ENTER(x)		MUTEX_ENTER(x)
412#   define	MUTEX_DOWNGRADE(x)
413#   define	RWLOCK_INIT(x, y)	initlock(&(x)->ipf_lk, 0, 0, y)
414#   define	RWLOCK_EXIT(x)		MUTEX_EXIT(x)
415#  endif
416#  define	RW_DESTROY(x)
417#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
418#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
419#  if HPUXREV >= 1111
420#   define	BCOPYIN(a,b,c)	0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
421#   define	BCOPYOUT(a,b,c)	0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
422#  else
423#   define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
424#   define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
425#  endif
426#  define	SPL_NET(x)	;
427#  define	SPL_IMP(x)	;
428#  undef	SPL_X
429#  define	SPL_X(x)	;
430extern	void	*get_unit __P((char *, int));
431#  define	GETIFP(n, v)	get_unit(n, v)
432#  define	IFNAME(x, b)	((ill_t *)x)->ill_name
433#  define	COPYIFNAME(x, b) \
434				(void) strncpy(b, ((qif_t *)x)->qf_name, \
435					       LIFNAMSIZ)
436#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
437#  define	SLEEP(id, n)	{ lock_t *_l = get_sleep_lock((caddr_t)id); \
438				  sleep(id, PZERO+1); \
439				  spinunlock(_l); \
440				}
441#  define	WAKEUP(id,x)	{ lock_t *_l = get_sleep_lock((caddr_t)id); \
442				  wakeup(id + x); \
443				  spinunlock(_l); \
444				}
445#  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
446#  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
447#  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
448#  define	KFREES(x,s)	kmem_free((char *)(x), (s))
449#  define	MSGDSIZE(x)	msgdsize(x)
450#  define	M_LEN(x)	((x)->b_wptr - (x)->b_rptr)
451#  define	M_DUPLICATE(x)	dupmsg((x))
452#  define	MTOD(m,t)	((t)((m)->b_rptr))
453#  define	MTYPE(m)	((m)->b_datap->db_type)
454#  define	FREE_MB_T(m)	freemsg(m)
455#  define	m_next		b_cont
456#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
457typedef mblk_t mb_t;
458
459#  define	CACHE_HASH(x)	(((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
460
461#  include "qif.h"
462#  include "pfil.h"
463
464# else /* _KERNEL */
465
466typedef	unsigned char uchar_t;
467
468#  ifndef	_SYS_STREAM_INCLUDED
469typedef char * mblk_t;
470typedef void * queue_t;
471typedef	u_long ulong;
472#  endif
473#  include <netinet/ip_info.h>
474
475# endif /* _KERNEL */
476
477# ifdef lint
478#  define ALIGN32(ptr)    (ptr ? 0L : 0L)
479#  define ALIGN16(ptr)    (ptr ? 0L : 0L)
480# else
481#  define ALIGN32(ptr)    (ptr)
482#  define ALIGN16(ptr)    (ptr)
483# endif
484
485typedef	struct uio	uio_t;
486typedef	int		ioctlcmd_t;
487typedef	int		minor_t;
488typedef unsigned int	u_32_t;
489# define	U_32_T	1
490
491# define OS_RECOGNISED 1
492
493#endif /* __hpux */
494
495/* ----------------------------------------------------------------------- */
496/*                                  I R I X                                */
497/* ----------------------------------------------------------------------- */
498#ifdef __sgi
499# undef		MENTAT
500# if IRIX < 60500
501typedef	struct uio	uio_t;
502# endif
503typedef	int		ioctlcmd_t;
504typedef u_int32_t       u_32_t;
505# define	U_32_T	1
506
507# ifdef INET6
508#  define USE_INET6
509# endif
510
511# define  hz HZ
512# include <sys/ksynch.h>
513# define	IPF_LOCK_PL	plhi
514# include <sys/sema.h>
515# undef kmutex_t
516typedef struct {
517	lock_t *l;
518	int pl;
519} kmutex_t;
520
521# ifdef MUTEX_INIT
522#  define	KMUTEX_T		mutex_t
523# else
524#  define	KMUTEX_T		kmutex_t
525#  define	KRWLOCK_T		kmutex_t
526# endif
527
528# ifdef _KERNEL
529#  define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); \
530					  (x)++; MUTEX_EXIT(&ipf_rw); }
531#  define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); \
532					  (x)--; MUTEX_EXIT(&ipf_rw); }
533#  define	USE_MUTEXES
534#  ifdef MUTEX_INIT
535#   include <sys/atomic_ops.h>
536#   define	ATOMIC_INCL(x)		atomicAddUlong(&(x), 1)
537#   define	ATOMIC_INC64(x)		atomicAddUint64(&(x), 1)
538#   define	ATOMIC_INC32(x)		atomicAddUint(&(x), 1)
539#   define	ATOMIC_INC16		ATOMIC_INC
540#   define	ATOMIC_DECL(x)		atomicAddUlong(&(x), -1)
541#   define	ATOMIC_DEC64(x)		atomicAddUint64(&(x), -1)
542#   define	ATOMIC_DEC32(x)		atomicAddUint(&(x), -1)
543#   define	ATOMIC_DEC16		ATOMIC_DEC
544#   undef	MUTEX_INIT
545#   define	MUTEX_INIT(x, y)	mutex_init(&(x)->ipf_lk,  \
546						   MUTEX_DEFAULT, y)
547#   undef	MUTEX_ENTER
548#   define	MUTEX_ENTER(x)		mutex_lock(&(x)->ipf_lk, 0)
549#   undef	MUTEX_EXIT
550#   define	MUTEX_EXIT(x)		mutex_unlock(&(x)->ipf_lk)
551#   undef	MUTEX_DESTROY
552#   define	MUTEX_DESTROY(x)	mutex_destroy(&(x)->ipf_lk)
553#   define	MUTEX_DOWNGRADE(x)	mrdemote(&(x)->ipf_lk)
554#   define	KRWLOCK_T		mrlock_t
555#   define	RWLOCK_INIT(x, y)	mrinit(&(x)->ipf_lk, y)
556#   undef	RW_DESTROY
557#   define	RW_DESTROY(x)		mrfree(&(x)->ipf_lk)
558#   define	READ_ENTER(x)		RW_RDLOCK(&(x)->ipf_lk)
559#   define	WRITE_ENTER(x)		RW_WRLOCK(&(x)->ipf_lk)
560#   define	RWLOCK_EXIT(x)		RW_UNLOCK(&(x)->ipf_lk)
561#  else
562#   define	READ_ENTER(x)		MUTEX_ENTER(&(x)->ipf_lk)
563#   define	WRITE_ENTER(x)		MUTEX_ENTER(&(x)->ipf_lk)
564#   define	MUTEX_DOWNGRADE(x)	;
565#   define	RWLOCK_EXIT(x)		MUTEX_EXIT(&(x)->ipf_lk)
566#   define	MUTEX_EXIT(x)		UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
567#   define	MUTEX_INIT(x,y)		(x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
568#   define	MUTEX_DESTROY(x)	LOCK_DEALLOC((x)->ipf_lk.l)
569#   define	MUTEX_ENTER(x)		(x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
570							      IPF_LOCK_PL);
571#  endif
572#  define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
573#  define	FREE_MB_T(m)	m_freem(m)
574#  define	MTOD(m,t)	mtod(m,t)
575#  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
576#  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
577#  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
578#  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
579#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
580#  define	SLEEP(id, n)	sleep((id), PZERO+1)
581#  define	WAKEUP(id,x)	wakeup(id+x)
582#  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
583#  define	KFREES(x,s)	kmem_free((char *)(x), (s))
584#  define	GETIFP(n,v)	ifunit(n)
585#  include <sys/kmem.h>
586#  include <sys/ddi.h>
587#  define	KMALLOC(a,b)	(a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
588#  define	KMALLOCS(a,b,c)	(a) = (b)kmem_alloc((c), KM_NOSLEEP)
589#  define	GET_MINOR(x)	getminor(x)
590#  define	USE_SPL		1
591#  define	SPL_IMP(x)	(x) = splimp()
592#  define	SPL_NET(x)	(x) = splnet()
593#  define	SPL_X(x)	(void) splx(x)
594extern	void	m_copydata __P((struct mbuf *, int, int, caddr_t));
595extern	void	m_copyback __P((struct mbuf *, int, int, caddr_t));
596#  define	MSGDSIZE(x)	mbufchainlen(x)
597#  define	M_LEN(x)	(x)->m_len
598#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
599#  define	GETKTIME(x)	microtime((struct timeval *)x)
600#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
601				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
602#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
603typedef struct mbuf mb_t;
604# else
605#  undef RW_DESTROY
606#  undef MUTEX_INIT
607#  undef MUTEX_DESTROY
608# endif /* _KERNEL */
609
610# define OS_RECOGNISED 1
611
612#endif /* __sgi */
613
614/* ----------------------------------------------------------------------- */
615/*                                  T R U 6 4                              */
616/* ----------------------------------------------------------------------- */
617#ifdef __osf__
618# undef		MENTAT
619
620# include <kern/lock.h>
621# include <sys/sysmacros.h>
622
623# ifdef _KERNEL
624#  define	KMUTEX_T		simple_lock_data_t
625#  define	KRWLOCK_T		lock_data_t
626#  include <net/net_globals.h>
627#  define	USE_MUTEXES
628#  define	READ_ENTER(x)		lock_read(&(x)->ipf_lk)
629#  define	WRITE_ENTER(x)		lock_write(&(x)->ipf_lk)
630#  define	MUTEX_DOWNGRADE(x)	lock_write_to_read(&(x)->ipf_lk)
631#  define	RWLOCK_INIT(x, y)	lock_init(&(x)->ipf_lk, TRUE)
632#  define	RWLOCK_EXIT(x)		lock_done(&(x)->ipf_lk)
633#  define	RW_DESTROY(x)		lock_terminate(&(x)->ipf_lk)
634#  define	MUTEX_ENTER(x)		simple_lock(&(x)->ipf_lk)
635#  define	MUTEX_INIT(x, y)	simple_lock_init(&(x)->ipf_lk)
636#  define	MUTEX_DESTROY(x)	simple_lock_terminate(&(x)->ipf_lk)
637#  define	MUTEX_EXIT(x)		simple_unlock(&(x)->ipf_lk)
638#  define	MUTEX_NUKE(x)		bzero(x, sizeof(*(x)))
639#  define	ATOMIC_INC64(x)		atomic_incq((uint64_t*)&(x))
640#  define	ATOMIC_DEC64(x)		atomic_decq((uint64_t*)&(x))
641#  define	ATOMIC_INC32(x)		atomic_incl((uint32_t*)&(x))
642#  define	ATOMIC_DEC32(x)		atomic_decl((uint32_t*)&(x))
643#  define	ATOMIC_INC16(x)		{ simple_lock(&ipf_rw); (x)++; \
644					  simple_unlock(&ipf_rw); }
645#  define	ATOMIC_DEC16(x)		{ simple_lock(&ipf_rw); (x)--; \
646					  simple_unlock(&ipf_rw); }
647#  define	ATOMIC_INCL(x)		atomic_incl((uint32_t*)&(x))
648#  define	ATOMIC_DECL(x)		atomic_decl((uint32_t*)&(x))
649#  define	ATOMIC_INC(x)		{ simple_lock(&ipf_rw); (x)++; \
650					  simple_unlock(&ipf_rw); }
651#  define	ATOMIC_DEC(x)		{ simple_lock(&ipf_rw); (x)--; \
652					  simple_unlock(&ipf_rw); }
653#  define	SPL_NET(x)		;
654#  define	SPL_IMP(x)		;
655#  undef	SPL_X
656#  define	SPL_X(x)		;
657#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a, b, d)
658#  define	FREE_MB_T(m)		m_freem(m)
659#  define	MTOD(m,t)		mtod(m,t)
660#  define	GETIFP(n, v)		ifunit(n)
661#  define	GET_MINOR		getminor
662#  define	WAKEUP(id,x)		wakeup(id + x)
663#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
664#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
665#  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
666#  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
667#  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
668#  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_PFILT, \
669					    ((c) > 4096) ? M_WAITOK : M_NOWAIT)
670#  define	KFREE(x)	FREE((x), M_PFILT)
671#  define	KFREES(x,s)	FREE((x), M_PFILT)
672#  define	MSGDSIZE(x)	mbufchainlen(x)
673#  define	M_LEN(x)	(x)->m_len
674#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
675#  define	GETKTIME(x)	microtime((struct timeval *)x)
676#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
677				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
678#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
679typedef struct mbuf mb_t;
680# endif /* _KERNEL */
681
682# if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
683#  define	IP_V(x)		((x)->ip_vhl >> 4)
684#  define	IP_HL(x)	((x)->ip_vhl & 0xf)
685#  define	IP_V_A(x,y)	(x)->ip_vhl |= (((y) << 4) & 0xf0)
686#  define	IP_HL_A(x,y)	(x)->ip_vhl |= ((y) & 0xf)
687#  define	TCP_X2(x)	((x)->th_xoff & 0xf)
688#  define	TCP_X2_A(x,y)	(x)->th_xoff |= ((y) & 0xf)
689#  define	TCP_OFF(x)	((x)->th_xoff >> 4)
690#  define	TCP_OFF_A(x,y)	(x)->th_xoff |= (((y) << 4) & 0xf0)
691# endif
692
693/*
694 * These are from's Solaris' #defines for little endian.
695 */
696#define	IP6F_MORE_FRAG		0x0100
697#define	IP6F_RESERVED_MASK	0x0600
698#define	IP6F_OFF_MASK		0xf8ff
699
700struct ip6_ext {
701	u_char	ip6e_nxt;
702	u_char	ip6e_len;
703};
704
705typedef	int		ioctlcmd_t;
706/*
707 * Really, any arch where sizeof(long) != sizeof(int).
708 */
709typedef unsigned int    u_32_t;
710# define	U_32_T	1
711
712# define OS_RECOGNISED 1
713#endif /* __osf__ */
714
715/* ----------------------------------------------------------------------- */
716/*                                  N E T B S D                            */
717/* ----------------------------------------------------------------------- */
718#ifdef __NetBSD__
719# if defined(_KERNEL) && !defined(IPFILTER_LKM)
720#  include "bpfilter.h"
721#  if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
722#   include "opt_inet.h"
723#  endif
724#  ifdef INET6
725#   define USE_INET6
726#  endif
727#  if (__NetBSD_Version__ >= 105000000)
728#   define HAVE_M_PULLDOWN 1
729#  endif
730# endif
731
732# ifdef _KERNEL
733#  define	MSGDSIZE(x)	mbufchainlen(x)
734#  define	M_LEN(x)	(x)->m_len
735#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
736#  define	GETKTIME(x)	microtime((struct timeval *)x)
737#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
738#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
739#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
740#  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
741#  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
742typedef struct mbuf mb_t;
743# endif /* _KERNEL */
744# if (NetBSD <= 1991011) && (NetBSD >= 199606)
745#  define	IFNAME(x)	((struct ifnet *)x)->if_xname
746#  define	COPYIFNAME(x, b) \
747				(void) strncpy(b, \
748					       ((struct ifnet *)x)->if_xname, \
749					       LIFNAMSIZ)
750#  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index)&7)
751# else
752#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
753				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
754# endif
755
756typedef	struct uio	uio_t;
757typedef	u_long		ioctlcmd_t;
758typedef	int		minor_t;
759typedef	u_int32_t	u_32_t;
760# define	U_32_T	1
761
762# define OS_RECOGNISED 1
763#endif /* __NetBSD__ */
764
765
766/* ----------------------------------------------------------------------- */
767/*                                F R E E B S D                            */
768/* ----------------------------------------------------------------------- */
769#ifdef __FreeBSD__
770# if defined(_KERNEL)
771#  if (__FreeBSD_version >= 500000)
772#   include "opt_bpf.h"
773#  else
774#   include "bpf.h"
775#  endif
776#  if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)
777#   include "opt_inet6.h"
778#  endif
779#  if defined(INET6) && !defined(USE_INET6)
780#   define USE_INET6
781#  endif
782# endif
783
784# if defined(_KERNEL)
785#  if (__FreeBSD_version >= 400000)
786/*
787 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
788 * There may be other, safe, kernels but this is not extensively tested yet.
789 */
790#   define HAVE_M_PULLDOWN
791#  endif
792#  if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
793#   include "opt_ipfilter.h"
794#  endif
795#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
796#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
797#  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
798#  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
799
800#  if (__FreeBSD_version >= 500043)
801#   define NETBSD_PF
802#  endif
803# endif /* _KERNEL */
804
805# if (__FreeBSD_version >= 500043)
806#  include <sys/mutex.h>
807#  include <sys/sx.h>
808/*
809 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
810 * for what we want to use them for, despite testing showing they work -
811 * with a WITNESS kernel, it generates LOR messages.
812 */
813#  define	KMUTEX_T		struct mtx
814#  if 1
815#   define	KRWLOCK_T		struct mtx
816#  else
817#   define	KRWLOCK_T		struct sx
818#  endif
819# endif
820
821# if (__FreeBSD_version >= 501113)
822#  include <net/if_var.h>
823#  define	IFNAME(x)	((struct ifnet *)x)->if_xname
824#  define	COPYIFNAME(x, b) \
825				(void) strncpy(b, \
826					       ((struct ifnet *)x)->if_xname, \
827					       LIFNAMSIZ)
828# endif
829# if (__FreeBSD_version >= 500043)
830#  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index) & 7)
831# else
832#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
833				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
834# endif
835
836# ifdef _KERNEL
837#  define	GETKTIME(x)	microtime((struct timeval *)x)
838
839#  if (__FreeBSD_version >= 500002)
840#   include <netinet/in_systm.h>
841#   include <netinet/ip.h>
842#   include <machine/in_cksum.h>
843#  endif
844
845#  if (__FreeBSD_version >= 500043)
846#   define	USE_MUTEXES
847#   define	MUTEX_ENTER(x)		mtx_lock(&(x)->ipf_lk)
848#   define	MUTEX_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
849#   define	MUTEX_INIT(x,y)		mtx_init(&(x)->ipf_lk, (y), NULL,\
850						 MTX_DEF)
851#   define	MUTEX_DESTROY(x)	mtx_destroy(&(x)->ipf_lk)
852#   define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
853/*
854 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
855 * for what we want to use them for, despite testing showing they work -
856 * with a WITNESS kernel, it generates LOR messages.
857 */
858#   if 1
859#    define	READ_ENTER(x)		mtx_lock(&(x)->ipf_lk)
860#    define	WRITE_ENTER(x)		mtx_lock(&(x)->ipf_lk)
861#    define	RWLOCK_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
862#    define	MUTEX_DOWNGRADE(x)	;
863#    define	RWLOCK_INIT(x,y)	mtx_init(&(x)->ipf_lk, (y), NULL,\
864						 MTX_DEF)
865#    define	RW_DESTROY(x)		mtx_destroy(&(x)->ipf_lk)
866#   else
867#    define	READ_ENTER(x)		sx_slock(&(x)->ipf_lk)
868#    define	WRITE_ENTER(x)		sx_xlock(&(x)->ipf_lk)
869#    define	MUTEX_DOWNGRADE(x)	sx_downgrade(&(x)->ipf_lk)
870#    define	RWLOCK_INIT(x, y)	sx_init(&(x)->ipf_lk, (y))
871#    define	RW_DESTROY(x)		sx_destroy(&(x)->ipf_lk)
872#    ifdef sx_unlock
873#     define	RWLOCK_EXIT(x)		sx_unlock(x)
874#    else
875#     define	RWLOCK_EXIT(x)		do { \
876					    if ((x)->ipf_lk.sx_cnt < 0) \
877						sx_xunlock(&(x)->ipf_lk); \
878					    else \
879						sx_sunlock(&(x)->ipf_lk); \
880					} while (0)
881#    endif
882#   endif
883#   include <machine/atomic.h>
884#   define	ATOMIC_INC(x)		{ mtx_lock(&ipf_rw.ipf_lk); (x)++; \
885					  mtx_unlock(&ipf_rw.ipf_lk); }
886#   define	ATOMIC_DEC(x)		{ mtx_lock(&ipf_rw.ipf_lk); (x)--; \
887					  mtx_unlock(&ipf_rw.ipf_lk); }
888#   define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
889#   define	ATOMIC_INC64(x)		ATOMIC_INC(x)
890#   define	ATOMIC_INC32(x)		atomic_add_32(&(x), 1)
891#   define	ATOMIC_INC16(x)		atomic_add_16(&(x), 1)
892#   define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
893#   define	ATOMIC_DEC64(x)		ATOMIC_DEC(x)
894#   define	ATOMIC_DEC32(x)		atomic_add_32(&(x), -1)
895#   define	ATOMIC_DEC16(x)		atomic_add_16(&(x), -1)
896#   define	SPL_X(x)	;
897#   define	SPL_NET(x)	;
898#   define	SPL_IMP(x)	;
899extern	int	in_cksum __P((struct mbuf *, int));
900#  endif /* __FreeBSD_version >= 500043 */
901#  define	MSGDSIZE(x)	mbufchainlen(x)
902#  define	M_LEN(x)	(x)->m_len
903#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
904#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
905typedef struct mbuf mb_t;
906# endif /* _KERNEL */
907
908# if __FreeBSD__ < 3
909#  include <machine/spl.h>
910# else
911#  if __FreeBSD__ == 3
912#   if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
913#    define	ACTUALLY_LKM_NOT_KERNEL
914#   endif
915#  endif
916# endif
917
918# if (__FreeBSD_version >= 300000)
919typedef	u_long		ioctlcmd_t;
920# else
921typedef	int		ioctlcmd_t;
922# endif
923typedef	struct uio	uio_t;
924typedef	int		minor_t;
925typedef	u_int32_t	u_32_t;
926# define	U_32_T	1
927
928# define OS_RECOGNISED 1
929#endif /* __FreeBSD__ */
930
931
932/* ----------------------------------------------------------------------- */
933/*                                O P E N B S D                            */
934/* ----------------------------------------------------------------------- */
935#ifdef __OpenBSD__
936# ifdef INET6
937#  define USE_INET6
938# endif
939
940# ifdef _KERNEL
941#  if !defined(IPFILTER_LKM)
942#   include "bpfilter.h"
943#  endif
944#  if (OpenBSD >= 200311)
945#   define SNPRINTF	snprintf
946#   if defined(USE_INET6)
947#    include "netinet6/in6_var.h"
948#    include "netinet6/nd6.h"
949#   endif
950#  endif
951#  if (OpenBSD >= 200012)
952#   define HAVE_M_PULLDOWN 1
953#  endif
954#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
955#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
956#  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
957#  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
958#  define	GETKTIME(x)	microtime((struct timeval *)x)
959#  define	MSGDSIZE(x)	mbufchainlen(x)
960#  define	M_LEN(x)	(x)->m_len
961#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
962#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
963typedef struct mbuf mb_t;
964# endif /* _KERNEL */
965# if (OpenBSD >= 199603)
966#  define	IFNAME(x, b)	((struct ifnet *)x)->if_xname
967#  define	COPYIFNAME(x, b) \
968				(void) strncpy(b, \
969					       ((struct ifnet *)x)->if_xname, \
970					       LIFNAMSIZ)
971#  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index)&7)
972# else
973#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
974				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
975# endif
976
977typedef	struct uio	uio_t;
978typedef	u_long		ioctlcmd_t;
979typedef	int		minor_t;
980typedef	u_int32_t	u_32_t;
981# define	U_32_T	1
982
983# define OS_RECOGNISED 1
984#endif /* __OpenBSD__ */
985
986
987/* ----------------------------------------------------------------------- */
988/*                                B S D O S                                */
989/* ----------------------------------------------------------------------- */
990#ifdef _BSDI_VERSION
991# ifdef INET6
992#  define USE_INET6
993# endif
994
995# ifdef _KERNEL
996#  define	GETKTIME(x)	microtime((struct timeval *)x)
997#  define	MSGDSIZE(x)	mbufchainlen(x)
998#  define	M_LEN(x)	(x)->m_len
999#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1000#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1001				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1002typedef struct mbuf mb_t;
1003# endif /* _KERNEL */
1004
1005# if (_BSDI_VERSION >= 199701)
1006typedef	u_long		ioctlcmd_t;
1007# else
1008typedef	int		ioctlcmd_t;
1009# endif
1010typedef	u_int32_t	u_32_t;
1011# define	U_32_T	1
1012
1013#endif /* _BSDI_VERSION */
1014
1015
1016/* ----------------------------------------------------------------------- */
1017/*                                  S U N O S 4                            */
1018/* ----------------------------------------------------------------------- */
1019#if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1020# ifdef _KERNEL
1021#  include	<sys/kmem_alloc.h>
1022#  define	GETKTIME(x)	uniqtime((struct timeval *)x)
1023#  define	MSGDSIZE(x)	mbufchainlen(x)
1024#  define	M_LEN(x)	(x)->m_len
1025#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1026#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1027				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1028#  define	GETIFP(n, v)	ifunit(n, IFNAMSIZ)
1029#  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
1030#  define	KFREES(x,s)	kmem_free((char *)(x), (s))
1031#  define	SLEEP(id, n)	sleep((id), PZERO+1)
1032#  define	WAKEUP(id,x)	wakeup(id + x)
1033#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
1034#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
1035
1036extern	void	m_copydata __P((struct mbuf *, int, int, caddr_t));
1037extern	void	m_copyback __P((struct mbuf *, int, int, caddr_t));
1038
1039typedef struct mbuf mb_t;
1040# endif
1041
1042typedef	struct uio	uio_t;
1043typedef	int		ioctlcmd_t;
1044typedef	int		minor_t;
1045typedef	unsigned int	u_32_t;
1046# define	U_32_T	1
1047
1048# define OS_RECOGNISED 1
1049
1050#endif /* SunOS 4 */
1051
1052/* ----------------------------------------------------------------------- */
1053/*                            L I N U X                                    */
1054/* ----------------------------------------------------------------------- */
1055#if defined(linux) && !defined(OS_RECOGNISED)
1056#include <linux/config.h>
1057#include <linux/version.h>
1058# if LINUX >= 20600
1059#  define	 HDR_T_PRIVATE	1
1060# endif
1061# undef USE_INET6
1062# ifdef USE_INET6
1063struct ip6_ext {
1064	u_char	ip6e_nxt;
1065	u_char	ip6e_len;
1066};
1067# endif
1068
1069# ifdef _KERNEL
1070#  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
1071#  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1072#  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1073#  define	COPYIN(a,b,c)	copy_from_user((caddr_t)(b), (caddr_t)(a), (c))
1074#  define	COPYOUT(a,b,c)	copy_to_user((caddr_t)(b), (caddr_t)(a), (c))
1075#  define	FREE_MB_T(m)	kfree_skb(m)
1076#  define	GETKTIME(x)	do_gettimeofday((struct timeval *)x)
1077#  define	SLEEP(x,s)	0, interruptible_sleep_on(x##_linux)
1078#  define	WAKEUP(x,y)	wake_up(x##_linux + y)
1079#  define	UIOMOVE(a,b,c,d)	uiomove(a,b,c,d)
1080#  define	USE_MUTEXES
1081#  define	KRWLOCK_T		rwlock_t
1082#  define	KMUTEX_T		spinlock_t
1083#  define	MUTEX_INIT(x,y)		spin_lock_init(&(x)->ipf_lk)
1084#  define	MUTEX_ENTER(x)		spin_lock(&(x)->ipf_lk)
1085#  define	MUTEX_EXIT(x)		spin_unlock(&(x)->ipf_lk)
1086#  define	MUTEX_DESTROY(x)	do { } while (0)
1087#  define	MUTEX_NUKE(x)		bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1088#  define	READ_ENTER(x)		ipf_read_enter(x)
1089#  define	WRITE_ENTER(x)		ipf_write_enter(x)
1090#  define	RWLOCK_INIT(x,y)	rwlock_init(&(x)->ipf_lk)
1091#  define	RW_DESTROY(x)		do { } while (0)
1092#  define	RWLOCK_EXIT(x)		ipf_rw_exit(x)
1093#  define	MUTEX_DOWNGRADE(x)	ipf_rw_downgrade(x)
1094#  define	ATOMIC_INCL(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1095					MUTEX_EXIT(&ipf_rw)
1096#  define	ATOMIC_DECL(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1097					MUTEX_EXIT(&ipf_rw)
1098#  define	ATOMIC_INC64(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1099					MUTEX_EXIT(&ipf_rw)
1100#  define	ATOMIC_INC32(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1101					MUTEX_EXIT(&ipf_rw)
1102#  define	ATOMIC_INC16(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1103					MUTEX_EXIT(&ipf_rw)
1104#  define	ATOMIC_DEC64(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1105					MUTEX_EXIT(&ipf_rw)
1106#  define	ATOMIC_DEC32(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1107					MUTEX_EXIT(&ipf_rw)
1108#  define	ATOMIC_DEC16(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1109					MUTEX_EXIT(&ipf_rw)
1110#  define	SPL_IMP(x)		do { } while (0)
1111#  define	SPL_NET(x)		do { } while (0)
1112#  define	SPL_X(x)		do { } while (0)
1113#  define	IFNAME(x)		((struct net_device*)x)->name
1114#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1115			  ((struct net_device *)fin->fin_ifp)->ifindex) & 7)
1116typedef	struct	sk_buff	mb_t;
1117extern	void	m_copydata __P((mb_t *, int, int, caddr_t));
1118extern	void	m_copyback __P((mb_t *, int, int, caddr_t));
1119extern	void	m_adj __P((mb_t *, int));
1120extern	mb_t	*m_pullup __P((mb_t *, int));
1121#  define	mbuf	sk_buff
1122
1123#  define	mtod(m, t)	((t)(m)->data)
1124#  define	m_data		data
1125#  define	m_len		len
1126#  define	m_next		next
1127#  define	M_DUPLICATE(m)	skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1128								GFP_KERNEL)
1129#  define	MSGDSIZE(m)	(m)->len
1130#  define	M_LEN(m)	(m)->len
1131
1132#  define	splnet(x)	;
1133#  define	printf		printk
1134#  define	bcopy(s,d,z)	memmove(d, s, z)
1135#  define	bzero(s,z)	memset(s, 0, z)
1136#  define	bcmp(a,b,z)	memcmp(a, b, z)
1137
1138#  define	ifnet		net_device
1139#  define	if_xname	name
1140#  define	if_unit		ifindex
1141
1142#  define	KMALLOC(x,t)	(x) = (t)kmalloc(sizeof(*(x)), \
1143				    in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1144#  define	KFREE(x)	kfree(x)
1145#  define	KMALLOCS(x,t,s)	(x) = (t)kmalloc((s), \
1146				    in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1147#  define	KFREES(x,s)	kfree(x)
1148
1149#  define GETIFP(n,v)	dev_get_by_name(n)
1150
1151# else
1152#  include <net/ethernet.h>
1153
1154struct mbuf {
1155};
1156
1157#  ifndef _NET_ROUTE_H
1158struct rtentry {
1159};
1160#  endif
1161
1162struct ifnet {
1163	char	if_xname[IFNAMSIZ];
1164	int	if_unit;
1165	int	(* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1166	struct	ifaddr	*if_addrlist;
1167};
1168# define	IFNAME(x)	((struct ifnet *)x)->if_xname
1169
1170# endif	/* _KERNEL */
1171
1172# define	COPYIFNAME(x, b) \
1173				(void) strncpy(b, \
1174					       ((struct ifnet *)x)->if_xname, \
1175					       LIFNAMSIZ)
1176
1177# include <linux/fs.h>
1178# define	FWRITE	FMODE_WRITE
1179# define	FREAD	FMODE_READ
1180
1181# define	__USE_MISC	1
1182# define	__FAVOR_BSD	1
1183
1184typedef	struct uio {
1185	struct iovec	*uio_iov;
1186	void	*uio_file;
1187	char	*uio_buf;
1188	int	uio_iovcnt;
1189	int	uio_offset;
1190	size_t	uio_resid;
1191	int	uio_rw;
1192} uio_t;
1193
1194extern	int	uiomove __P((caddr_t, size_t, int, struct uio *));
1195
1196# define	UIO_READ	1
1197# define	UIO_WRITE	2
1198
1199typedef	u_long		ioctlcmd_t;
1200typedef	int		minor_t;
1201typedef u_int32_t 	u_32_t;
1202# define	U_32_T	1
1203
1204# define OS_RECOGNISED 1
1205
1206#endif
1207
1208
1209/* ----------------------------------------------------------------------- */
1210/*                                    A I X                                */
1211/* ----------------------------------------------------------------------- */
1212#if defined(_AIX51)
1213# undef		MENTAT
1214
1215# include <sys/lock.h>
1216# include <sys/sysmacros.h>
1217
1218# ifdef _KERNEL
1219#  define rw_read_locked(x)		0
1220#  include <net/net_globals.h>
1221#  include <net/net_malloc.h>
1222#  define	KMUTEX_T		simple_lock_t
1223#  define	KRWLOCK_T		complex_lock_t
1224#  define	USE_MUTEXES		1
1225#  define	USE_SPL			1
1226#  define	READ_ENTER(x)		lock_read((x)->ipf_lk)
1227#  define	WRITE_ENTER(x)		lock_write((x)->ipf_lk)
1228#  define	MUTEX_DOWNGRADE(x)	lock_write_to_read((x)->ipf_lk)
1229#  define	RWLOCK_INIT(x, y)	lock_alloc(&(x)->ipf_lk, \
1230						   LOCK_ALLOC_PIN, \
1231						   (u_short)y, 0); \
1232					lock_init((x)->ipf_lk, TRUE)
1233#  define	RWLOCK_EXIT(x)		lock_done((x)->ipf_lk)
1234#  define	RW_DESTROY(x)		lock_free(&(x)->ipf_lk)
1235#  define	MUTEX_ENTER(x)		simple_lock((x)->ipf_lk)
1236#  define	MUTEX_INIT(x, y)	lock_alloc(&(x)->ipf_lk, \
1237						   LOCK_ALLOC_PIN, \
1238						   (u_short)y, 0); \
1239					simple_lock_init((x)->ipf_lk)
1240#  define	MUTEX_DESTROY(x)	lock_free(&(x)->ipf_lk)
1241#  define	MUTEX_EXIT(x)		simple_unlock((x)->ipf_lk)
1242#  define	MUTEX_NUKE(x)		bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1243#   define	ATOMIC_INC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1244					  MUTEX_EXIT(&ipf_rw); }
1245#   define	ATOMIC_DEC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1246					  MUTEX_EXIT(&ipf_rw); }
1247#   define	ATOMIC_INC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1248					  MUTEX_EXIT(&ipf_rw); }
1249#   define	ATOMIC_DEC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1250					  MUTEX_EXIT(&ipf_rw); }
1251#   define	ATOMIC_INCL(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1252					  MUTEX_EXIT(&ipf_rw); }
1253#   define	ATOMIC_DECL(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1254					  MUTEX_EXIT(&ipf_rw); }
1255#   define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1256					  MUTEX_EXIT(&ipf_rw); }
1257#   define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1258					  MUTEX_EXIT(&ipf_rw); }
1259#  define	SPL_NET(x)		x = splnet()
1260#  define	SPL_IMP(x)		x = splimp()
1261#  undef	SPL_X
1262#  define	SPL_X(x)		splx(x)
1263#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
1264extern void* getifp __P((char *, int));
1265#  define	GETIFP(n, v)		getifp(n, v)
1266#  define	GET_MINOR		minor
1267#  define	SLEEP(id, n)	sleepx((id), PZERO+1, 0)
1268#  define	WAKEUP(id,x)	wakeup(id)
1269#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
1270#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
1271#  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1272#  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1273#  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1274#  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_TEMP, \
1275					    ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1276#  define	KFREE(x)	FREE((x), M_TEMP)
1277#  define	KFREES(x,s)	FREE((x), M_TEMP)
1278#  define	MSGDSIZE(x)	mbufchainlen(x)
1279#  define	M_LEN(x)	(x)->m_len
1280#  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1281#  define	GETKTIME(x)
1282#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1283				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1284#  define	IPF_PANIC(x,y)
1285typedef struct mbuf mb_t;
1286# endif /* _KERNEL */
1287
1288/*
1289 * These are from's Solaris' #defines for little endian.
1290 */
1291#if !defined(IP6F_MORE_FRAG)
1292# define	IP6F_MORE_FRAG		0x0100
1293#endif
1294#if !defined(IP6F_RESERVED_MASK)
1295# define	IP6F_RESERVED_MASK	0x0600
1296#endif
1297#if !defined(IP6F_OFF_MASK)
1298# define	IP6F_OFF_MASK		0xf8ff
1299#endif
1300
1301struct ip6_ext {
1302	u_char	ip6e_nxt;
1303	u_char	ip6e_len;
1304};
1305
1306typedef	int		ioctlcmd_t;
1307typedef	int		minor_t;
1308/*
1309 * Really, any arch where sizeof(long) != sizeof(int).
1310 */
1311typedef unsigned int    u_32_t;
1312# define	U_32_T	1
1313
1314# define OS_RECOGNISED 1
1315#endif	/* _AIX51 */
1316
1317
1318#ifndef	OS_RECOGNISED
1319#error	ip_compat.h does not recognise this platform/OS.
1320#endif
1321
1322
1323/* ----------------------------------------------------------------------- */
1324/*                           G E N E R I C                                 */
1325/* ----------------------------------------------------------------------- */
1326#ifndef OS_RECOGNISED
1327#endif
1328
1329/*
1330 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1331 * filter rules.
1332 */
1333#if !defined(IPFILTER_BPF)
1334# if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
1335     (defined(NBPFILTER) && (NBPFILTER > 0))
1336#  define	IPFILTER_BPF
1337# endif
1338#endif
1339
1340/*
1341 * Userland locking primitives
1342 */
1343typedef	struct	{
1344	char	*eMm_owner;
1345	char	*eMm_heldin;
1346	u_int	eMm_magic;
1347	int	eMm_held;
1348	int	eMm_heldat;
1349#ifdef __hpux
1350	char	eMm_fill[8];
1351#endif
1352} eMmutex_t;
1353
1354typedef	struct	{
1355	char	*eMrw_owner;
1356	char	*eMrw_heldin;
1357	u_int	eMrw_magic;
1358	short	eMrw_read;
1359	short	eMrw_write;
1360	int	eMrw_heldat;
1361#ifdef __hpux
1362	char	eMm_fill[24];
1363#endif
1364} eMrwlock_t;
1365
1366typedef union {
1367#ifdef KMUTEX_T
1368	struct	{
1369		KMUTEX_T	ipf_slk;
1370		char		*ipf_lname;
1371	} ipf_lkun_s;
1372#endif
1373	eMmutex_t	ipf_emu;
1374} ipfmutex_t;
1375
1376typedef union {
1377#ifdef KRWLOCK_T
1378	struct	{
1379		KRWLOCK_T	ipf_slk;
1380		char		*ipf_lname;
1381		int		ipf_sr;
1382		int		ipf_sw;
1383		u_int		ipf_magic;
1384	} ipf_lkun_s;
1385#endif
1386	eMrwlock_t	ipf_emu;
1387} ipfrwlock_t;
1388
1389#define	ipf_lk		ipf_lkun_s.ipf_slk
1390#define	ipf_lname	ipf_lkun_s.ipf_lname
1391#define	ipf_isr		ipf_lkun_s.ipf_sr
1392#define	ipf_isw		ipf_lkun_s.ipf_sw
1393#define	ipf_magic	ipf_lkun_s.ipf_magic
1394
1395#if !defined(__GNUC__) || \
1396    (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1397# ifndef	INLINE
1398#  define	INLINE
1399# endif
1400#else
1401# define	INLINE	__inline__
1402#endif
1403
1404#if defined(linux) && defined(_KERNEL)
1405extern	void	ipf_read_enter __P((ipfrwlock_t *));
1406extern	void	ipf_write_enter __P((ipfrwlock_t *));
1407extern	void	ipf_rw_exit __P((ipfrwlock_t *));
1408extern	void	ipf_rw_downgrade __P((ipfrwlock_t *));
1409#endif
1410
1411/*
1412 * In a non-kernel environment, there are a lot of macros that need to be
1413 * filled in to be null-ops or to point to some compatibility function,
1414 * somewhere in userland.
1415 */
1416#ifndef _KERNEL
1417typedef	struct	mb_s	{
1418	struct	mb_s	*mb_next;
1419	int		mb_len;
1420	u_long		mb_buf[2048];
1421} mb_t;
1422# undef		m_next
1423# define	m_next		mb_next
1424# define	MSGDSIZE(x)	(x)->mb_len	/* XXX - from ipt.c */
1425# define	M_LEN(x)	(x)->mb_len
1426# define	M_DUPLICATE(x)	(x)
1427# define	GETKTIME(x)	gettimeofday((struct timeval *)(x), NULL)
1428# undef		MTOD
1429# define	MTOD(m, t)	((t)(m)->mb_buf)
1430# define	FREE_MB_T(x)
1431# define	SLEEP(x,y)	1;
1432# define	WAKEUP(x,y)	;
1433# define	IPF_PANIC(x,y)	;
1434# define	PANIC(x,y)	;
1435# define	SPL_NET(x)	;
1436# define	SPL_IMP(x)	;
1437# define	SPL_X(x)	;
1438# define	KMALLOC(a,b)	(a) = (b)malloc(sizeof(*a))
1439# define	KMALLOCS(a,b,c)	(a) = (b)malloc(c)
1440# define	KFREE(x)	free(x)
1441# define	KFREES(x,s)	free(x)
1442# define	GETIFP(x, v)	get_unit(x,v)
1443# define	COPYIN(a,b,c)	bcopywrap((a), (b), (c))
1444# define	COPYOUT(a,b,c)	bcopywrap((a), (b), (c))
1445# define	BCOPYIN(a,b,c)	(bcopy((a), (b), (c)), 0)
1446# define	BCOPYOUT(a,b,c)	(bcopy((a), (b), (c)), 0)
1447# define	COPYDATA(m, o, l, b)	bcopy(MTOD((mb_t *)m, char *) + (o), \
1448					      (b), (l))
1449# define	COPYBACK(m, o, l, b)	bcopy((b), \
1450					      MTOD((mb_t *)m, char *) + (o), \
1451					      (l))
1452# define	UIOMOVE(a,b,c,d)	ipfuiomove(a,b,c,d)
1453extern	void	m_copydata __P((mb_t *, int, int, caddr_t));
1454extern	int	ipfuiomove __P((caddr_t, int, int, struct uio *));
1455extern	int	bcopywrap __P((void *, void *, size_t));
1456# ifndef CACHE_HASH
1457#  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1458				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1459# endif
1460
1461# define	MUTEX_DESTROY(x)	eMmutex_destroy(&(x)->ipf_emu)
1462# define	MUTEX_ENTER(x)		eMmutex_enter(&(x)->ipf_emu, \
1463						      __FILE__, __LINE__)
1464# define	MUTEX_EXIT(x)		eMmutex_exit(&(x)->ipf_emu)
1465# define	MUTEX_INIT(x,y)		eMmutex_init(&(x)->ipf_emu, y)
1466# define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
1467
1468# define	MUTEX_DOWNGRADE(x)	eMrwlock_downgrade(&(x)->ipf_emu, \
1469							   __FILE__, __LINE__)
1470# define	READ_ENTER(x)		eMrwlock_read_enter(&(x)->ipf_emu, \
1471							    __FILE__, __LINE__)
1472# define	RWLOCK_INIT(x, y)	eMrwlock_init(&(x)->ipf_emu, y)
1473# define	RWLOCK_EXIT(x)		eMrwlock_exit(&(x)->ipf_emu)
1474# define	RW_DESTROY(x)		eMrwlock_destroy(&(x)->ipf_emu)
1475# define	WRITE_ENTER(x)		eMrwlock_write_enter(&(x)->ipf_emu, \
1476							     __FILE__, \
1477							     __LINE__)
1478
1479# define	USE_MUTEXES		1
1480
1481extern void eMmutex_destroy __P((eMmutex_t *));
1482extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1483extern void eMmutex_exit __P((eMmutex_t *));
1484extern void eMmutex_init __P((eMmutex_t *, char *));
1485extern void eMrwlock_destroy __P((eMrwlock_t *));
1486extern void eMrwlock_exit __P((eMrwlock_t *));
1487extern void eMrwlock_init __P((eMrwlock_t *, char *));
1488extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1489extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1490extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1491
1492#endif
1493
1494#define	MAX_IPV4HDR	((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1495
1496#ifndef	IP_OFFMASK
1497# define	IP_OFFMASK	0x1fff
1498#endif
1499
1500
1501/*
1502 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1503 * object.
1504 */
1505#if (BSD > 199306)
1506# define	USE_QUAD_T
1507# define	U_QUAD_T	unsigned long long
1508# define	QUAD_T		long long
1509#else /* BSD > 199306 */
1510# define	U_QUAD_T	u_long
1511# define	QUAD_T		long
1512#endif /* BSD > 199306 */
1513
1514
1515#ifdef	USE_INET6
1516# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1517     defined(__osf__) || defined(linux)
1518#  include <netinet/ip6.h>
1519#  include <netinet/icmp6.h>
1520#  if !defined(linux)
1521#   if defined(_KERNEL) && !defined(__osf__)
1522#    include <netinet6/ip6_var.h>
1523#   endif
1524#  endif
1525typedef	struct ip6_hdr	ip6_t;
1526# endif
1527#endif
1528
1529#ifndef	MAX
1530# define	MAX(a,b)	(((a) > (b)) ? (a) : (b))
1531#endif
1532
1533#if defined(_KERNEL)
1534# ifdef MENTAT
1535#  define	COPYDATA	mb_copydata
1536#  define	COPYBACK	mb_copyback
1537# else
1538#  define	COPYDATA	m_copydata
1539#  define	COPYBACK	m_copyback
1540# endif
1541# if (BSD >= 199306) || defined(__FreeBSD__)
1542#  if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1543       defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1544       defined(_BSDI_VERSION)
1545#   include <vm/vm.h>
1546#  endif
1547#  if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
1548      (__FreeBSD_version >= 300000))
1549#   if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
1550       (defined(OpenBSD) && (OpenBSD >= 200111))
1551#    include <uvm/uvm_extern.h>
1552#   else
1553#    include <vm/vm_extern.h>
1554extern  vm_map_t        kmem_map;
1555#   endif
1556#   include <sys/proc.h>
1557#  else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1558#   include <vm/vm_kern.h>
1559#  endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1560
1561#  ifdef IPFILTER_M_IPFILTER
1562#    include <sys/malloc.h>
1563MALLOC_DECLARE(M_IPFILTER);
1564#    define	_M_IPF		M_IPFILTER
1565#  else /* IPFILTER_M_IPFILTER */
1566#   ifdef M_PFIL
1567#    define	_M_IPF		M_PFIL
1568#   else
1569#    ifdef M_IPFILTER
1570#     define	_M_IPF		M_IPFILTER
1571#    else
1572#     define	_M_IPF		M_TEMP
1573#    endif /* M_IPFILTER */
1574#   endif /* M_PFIL */
1575#  endif /* IPFILTER_M_IPFILTER */
1576#  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1577#  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1578#  define	KFREE(x)	FREE((x), _M_IPF)
1579#  define	KFREES(x,s)	FREE((x), _M_IPF)
1580#  define	UIOMOVE(a,b,c,d)	uiomove(a,b,d)
1581#  define	SLEEP(id, n)	tsleep((id), PPAUSE|PCATCH, n, 0)
1582#  define	WAKEUP(id,x)	wakeup(id+x)
1583#  define	GETIFP(n, v)	ifunit(n)
1584# endif /* (Free)BSD */
1585
1586# if !defined(USE_MUTEXES) && !defined(SPL_NET)
1587#  if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1588      (defined(OpenBSD) && (OpenBSD >= 200006))
1589#   define	SPL_NET(x)	x = splsoftnet()
1590#  else
1591#   define	SPL_IMP(x)	x = splimp()
1592#   define	SPL_NET(x)	x = splnet()
1593#  endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1594#  define	SPL_X(x)	(void) splx(x)
1595# endif /* !USE_MUTEXES */
1596
1597# ifndef FREE_MB_T
1598#  define	FREE_MB_T(m)	m_freem(m)
1599# endif
1600
1601# ifndef MTOD
1602#  define	MTOD(m,t)	mtod(m,t)
1603# endif
1604
1605# ifndef COPYIN
1606#  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1607#  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1608#  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1609#  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1610# endif
1611
1612# ifndef KMALLOC
1613#  define	KMALLOC(a,b)	(a) = (b)new_kmem_alloc(sizeof(*(a)), \
1614							KMEM_NOSLEEP)
1615#  define	KMALLOCS(a,b,c)	(a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1616# endif
1617
1618# ifndef	GET_MINOR
1619#  define	GET_MINOR(x)	minor(x)
1620# endif
1621# define	PANIC(x,y)	if (x) panic y
1622#endif /* _KERNEL */
1623
1624#ifndef	IFNAME
1625# define	IFNAME(x)	((struct ifnet *)x)->if_name
1626#endif
1627#ifndef	COPYIFNAME
1628# define	NEED_FRGETIFNAME
1629extern	char	*fr_getifname __P((struct ifnet *, char *));
1630# define	COPYIFNAME(x, b) \
1631				fr_getifname((struct ifnet *)x, b)
1632#endif
1633
1634#ifndef ASSERT
1635# define	ASSERT(x)
1636#endif
1637
1638/*
1639 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1640 * would mean all normal code that walks through strings needed casts.  Yuck.
1641 */
1642#define	ISALNUM(x)	isalnum((u_char)(x))
1643#define	ISALPHA(x)	isalpha((u_char)(x))
1644#define	ISASCII(x)	isascii((u_char)(x))
1645#define	ISDIGIT(x)	isdigit((u_char)(x))
1646#define	ISPRINT(x)	isprint((u_char)(x))
1647#define	ISSPACE(x)	isspace((u_char)(x))
1648#define	ISUPPER(x)	isupper((u_char)(x))
1649#define	ISXDIGIT(x)	isxdigit((u_char)(x))
1650#define	ISLOWER(x)	islower((u_char)(x))
1651#define	TOUPPER(x)	toupper((u_char)(x))
1652#define	TOLOWER(x)	tolower((u_char)(x))
1653
1654/*
1655 * If mutexes aren't being used, turn all the mutex functions into null-ops.
1656 */
1657#if !defined(USE_MUTEXES)
1658# define	USE_SPL			1
1659# undef		RW_DESTROY
1660# undef		MUTEX_INIT
1661# undef		MUTEX_NUKE
1662# undef		MUTEX_DESTROY
1663# define	MUTEX_ENTER(x)		;
1664# define	READ_ENTER(x)		;
1665# define	WRITE_ENTER(x)		;
1666# define	MUTEX_DOWNGRADE(x)	;
1667# define	RWLOCK_INIT(x, y)	;
1668# define	RWLOCK_EXIT(x)		;
1669# define	RW_DESTROY(x)		;
1670# define	MUTEX_EXIT(x)		;
1671# define	MUTEX_INIT(x,y)		;
1672# define	MUTEX_DESTROY(x)	;
1673# define	MUTEX_NUKE(x)		;
1674#endif /* !USE_MUTEXES */
1675#ifndef	ATOMIC_INC
1676# define	ATOMIC_INC(x)		(x)++
1677# define	ATOMIC_DEC(x)		(x)--
1678#endif
1679
1680#if defined(USE_SPL) && defined(_KERNEL)
1681# define	SPL_INT(x)	int x
1682#else
1683# define	SPL_INT(x)
1684#endif
1685
1686/*
1687 * If there are no atomic operations for bit sizes defined, define them to all
1688 * use a generic one that works for all sizes.
1689 */
1690#ifndef	ATOMIC_INCL
1691# define	ATOMIC_INCL		ATOMIC_INC
1692# define	ATOMIC_INC64		ATOMIC_INC
1693# define	ATOMIC_INC32		ATOMIC_INC
1694# define	ATOMIC_INC16		ATOMIC_INC
1695# define	ATOMIC_DECL		ATOMIC_DEC
1696# define	ATOMIC_DEC64		ATOMIC_DEC
1697# define	ATOMIC_DEC32		ATOMIC_DEC
1698# define	ATOMIC_DEC16		ATOMIC_DEC
1699#endif
1700
1701#ifndef HDR_T_PRIVATE
1702typedef	struct	tcphdr	tcphdr_t;
1703typedef	struct	udphdr	udphdr_t;
1704#endif
1705typedef	struct	icmp	icmphdr_t;
1706typedef	struct	ip	ip_t;
1707typedef	struct	ether_header	ether_header_t;
1708typedef	struct	tcpiphdr	tcpiphdr_t;
1709
1710#ifndef	FR_GROUPLEN
1711# define	FR_GROUPLEN	16
1712#endif
1713
1714#ifdef offsetof
1715# undef	offsetof
1716#endif
1717#ifndef offsetof
1718# define offsetof(t,m) (int)((&((t *)0L)->m))
1719#endif
1720
1721/*
1722 * This set of macros has been brought about because on Tru64 it is not
1723 * possible to easily assign or examine values in a structure that are
1724 * bit fields.
1725 */
1726#ifndef IP_V
1727# define	IP_V(x)		(x)->ip_v
1728#endif
1729#ifndef	IP_V_A
1730# define	IP_V_A(x,y)	(x)->ip_v = (y)
1731#endif
1732#ifndef	IP_HL
1733# define	IP_HL(x)	(x)->ip_hl
1734#endif
1735#ifndef	IP_HL_A
1736# define	IP_HL_A(x,y)	(x)->ip_hl = (y)
1737#endif
1738#ifndef	TCP_X2
1739# define	TCP_X2(x)	(x)->th_x2
1740#endif
1741#ifndef	TCP_X2_A
1742# define	TCP_X2_A(x,y)	(x)->th_x2 = (y)
1743#endif
1744#ifndef	TCP_OFF
1745# define	TCP_OFF(x)	(x)->th_off
1746#endif
1747#ifndef	TCP_OFF_A
1748# define	TCP_OFF_A(x,y)	(x)->th_off = (y)
1749#endif
1750#define	IPMINLEN(i, h)	((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
1751
1752
1753/*
1754 * XXX - This is one of those *awful* hacks which nobody likes
1755 */
1756#ifdef	ultrix
1757#define	A_A
1758#else
1759#define	A_A	&
1760#endif
1761
1762#define	TCPF_ALL	(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
1763			 TH_ECN|TH_CWR)
1764
1765#if (BSD >= 199306) && !defined(m_act)
1766# define	m_act	m_nextpkt
1767#endif
1768
1769/*
1770 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
1771 *
1772 * Basic Option
1773 *
1774 * 00000001   -   (Reserved 4)
1775 * 00111101   -   Top Secret
1776 * 01011010   -   Secret
1777 * 10010110   -   Confidential
1778 * 01100110   -   (Reserved 3)
1779 * 11001100   -   (Reserved 2)
1780 * 10101011   -   Unclassified
1781 * 11110001   -   (Reserved 1)
1782 */
1783#define	IPSO_CLASS_RES4		0x01
1784#define	IPSO_CLASS_TOPS		0x3d
1785#define	IPSO_CLASS_SECR		0x5a
1786#define	IPSO_CLASS_CONF		0x96
1787#define	IPSO_CLASS_RES3		0x66
1788#define	IPSO_CLASS_RES2		0xcc
1789#define	IPSO_CLASS_UNCL		0xab
1790#define	IPSO_CLASS_RES1		0xf1
1791
1792#define	IPSO_AUTH_GENSER	0x80
1793#define	IPSO_AUTH_ESI		0x40
1794#define	IPSO_AUTH_SCI		0x20
1795#define	IPSO_AUTH_NSA		0x10
1796#define	IPSO_AUTH_DOE		0x08
1797#define	IPSO_AUTH_UN		0x06
1798#define	IPSO_AUTH_FTE		0x01
1799
1800/*
1801 * IP option #defines
1802 */
1803#undef	IPOPT_RR
1804#define	IPOPT_RR	7
1805#undef	IPOPT_ZSU
1806#define	IPOPT_ZSU	10	/* ZSU */
1807#undef	IPOPT_MTUP
1808#define	IPOPT_MTUP	11	/* MTUP */
1809#undef	IPOPT_MTUR
1810#define	IPOPT_MTUR	12	/* MTUR */
1811#undef	IPOPT_ENCODE
1812#define	IPOPT_ENCODE	15	/* ENCODE */
1813#undef	IPOPT_TS
1814#define	IPOPT_TS	68
1815#undef	IPOPT_TR
1816#define	IPOPT_TR	82	/* TR */
1817#undef	IPOPT_SECURITY
1818#define	IPOPT_SECURITY	130
1819#undef	IPOPT_LSRR
1820#define	IPOPT_LSRR	131
1821#undef	IPOPT_E_SEC
1822#define	IPOPT_E_SEC	133	/* E-SEC */
1823#undef	IPOPT_CIPSO
1824#define	IPOPT_CIPSO	134	/* CIPSO */
1825#undef	IPOPT_SATID
1826#define	IPOPT_SATID	136
1827#ifndef	IPOPT_SID
1828# define	IPOPT_SID	IPOPT_SATID
1829#endif
1830#undef	IPOPT_SSRR
1831#define	IPOPT_SSRR	137
1832#undef	IPOPT_ADDEXT
1833#define	IPOPT_ADDEXT	147	/* ADDEXT */
1834#undef	IPOPT_VISA
1835#define	IPOPT_VISA	142	/* VISA */
1836#undef	IPOPT_IMITD
1837#define	IPOPT_IMITD	144	/* IMITD */
1838#undef	IPOPT_EIP
1839#define	IPOPT_EIP	145	/* EIP */
1840#undef	IPOPT_RTRALRT
1841#define	IPOPT_RTRALRT	148	/* RTRALRT */
1842#undef	IPOPT_SDB
1843#define	IPOPT_SDB	149
1844#undef	IPOPT_NSAPA
1845#define	IPOPT_NSAPA	150
1846#undef	IPOPT_DPS
1847#define	IPOPT_DPS	151
1848#undef	IPOPT_UMP
1849#define	IPOPT_UMP	152
1850#undef	IPOPT_FINN
1851#define	IPOPT_FINN	205	/* FINN */
1852
1853#ifndef TCPOPT_EOL
1854# define TCPOPT_EOL		0
1855#endif
1856#ifndef TCPOPT_NOP
1857# define TCPOPT_NOP		1
1858#endif
1859#ifndef TCPOPT_MAXSEG
1860# define TCPOPT_MAXSEG		2
1861#endif
1862#ifndef TCPOLEN_MAXSEG
1863# define TCPOLEN_MAXSEG		4
1864#endif
1865#ifndef TCPOPT_WINDOW
1866# define TCPOPT_WINDOW		3
1867#endif
1868#ifndef TCPOLEN_WINDOW
1869# define TCPOLEN_WINDOW		3
1870#endif
1871#ifndef TCPOPT_SACK_PERMITTED
1872# define TCPOPT_SACK_PERMITTED	4
1873#endif
1874#ifndef TCPOLEN_SACK_PERMITTED
1875# define TCPOLEN_SACK_PERMITTED	2
1876#endif
1877#ifndef TCPOPT_SACK
1878# define TCPOPT_SACK		5
1879#endif
1880#ifndef TCPOPT_TIMESTAMP
1881# define TCPOPT_TIMESTAMP	8
1882#endif
1883
1884#ifndef	ICMP_MINLEN
1885# define	ICMP_MINLEN	8
1886#endif
1887#ifndef	ICMP_ECHOREPLY
1888# define	ICMP_ECHOREPLY	0
1889#endif
1890#ifndef	ICMP_UNREACH
1891# define	ICMP_UNREACH	3
1892#endif
1893#ifndef	ICMP_UNREACH_NET
1894# define	ICMP_UNREACH_NET	0
1895#endif
1896#ifndef	ICMP_UNREACH_HOST
1897# define	ICMP_UNREACH_HOST	1
1898#endif
1899#ifndef	ICMP_UNREACH_PROTOCOL
1900# define	ICMP_UNREACH_PROTOCOL	2
1901#endif
1902#ifndef	ICMP_UNREACH_PORT
1903# define	ICMP_UNREACH_PORT	3
1904#endif
1905#ifndef	ICMP_UNREACH_NEEDFRAG
1906# define	ICMP_UNREACH_NEEDFRAG	4
1907#endif
1908#ifndef	ICMP_UNREACH_SRCFAIL
1909# define	ICMP_UNREACH_SRCFAIL	5
1910#endif
1911#ifndef	ICMP_UNREACH_NET_UNKNOWN
1912# define	ICMP_UNREACH_NET_UNKNOWN	6
1913#endif
1914#ifndef	ICMP_UNREACH_HOST_UNKNOWN
1915# define	ICMP_UNREACH_HOST_UNKNOWN	7
1916#endif
1917#ifndef	ICMP_UNREACH_ISOLATED
1918# define	ICMP_UNREACH_ISOLATED	8
1919#endif
1920#ifndef	ICMP_UNREACH_NET_PROHIB
1921# define	ICMP_UNREACH_NET_PROHIB	9
1922#endif
1923#ifndef	ICMP_UNREACH_HOST_PROHIB
1924# define	ICMP_UNREACH_HOST_PROHIB	10
1925#endif
1926#ifndef	ICMP_UNREACH_TOSNET
1927# define	ICMP_UNREACH_TOSNET	11
1928#endif
1929#ifndef	ICMP_UNREACH_TOSHOST
1930# define	ICMP_UNREACH_TOSHOST	12
1931#endif
1932#ifndef	ICMP_UNREACH_ADMIN_PROHIBIT
1933# define	ICMP_UNREACH_ADMIN_PROHIBIT	13
1934#endif
1935#ifndef	ICMP_UNREACH_FILTER
1936# define	ICMP_UNREACH_FILTER	13
1937#endif
1938#ifndef	ICMP_UNREACH_HOST_PRECEDENCE
1939# define	ICMP_UNREACH_HOST_PRECEDENCE	14
1940#endif
1941#ifndef	ICMP_UNREACH_PRECEDENCE_CUTOFF
1942# define	ICMP_UNREACH_PRECEDENCE_CUTOFF	15
1943#endif
1944#ifndef	ICMP_SOURCEQUENCH
1945# define	ICMP_SOURCEQUENCH	4
1946#endif
1947#ifndef	ICMP_REDIRECT_NET
1948# define	ICMP_REDIRECT_NET	0
1949#endif
1950#ifndef	ICMP_REDIRECT_HOST
1951# define	ICMP_REDIRECT_HOST	1
1952#endif
1953#ifndef	ICMP_REDIRECT_TOSNET
1954# define	ICMP_REDIRECT_TOSNET	2
1955#endif
1956#ifndef	ICMP_REDIRECT_TOSHOST
1957# define	ICMP_REDIRECT_TOSHOST	3
1958#endif
1959#ifndef	ICMP_ALTHOSTADDR
1960# define	ICMP_ALTHOSTADDR	6
1961#endif
1962#ifndef	ICMP_TIMXCEED
1963# define	ICMP_TIMXCEED	11
1964#endif
1965#ifndef	ICMP_TIMXCEED_INTRANS
1966# define	ICMP_TIMXCEED_INTRANS	0
1967#endif
1968#ifndef	ICMP_TIMXCEED_REASS
1969# define		ICMP_TIMXCEED_REASS	1
1970#endif
1971#ifndef	ICMP_PARAMPROB
1972# define	ICMP_PARAMPROB	12
1973#endif
1974#ifndef	ICMP_PARAMPROB_ERRATPTR
1975# define	ICMP_PARAMPROB_ERRATPTR	0
1976#endif
1977#ifndef	ICMP_PARAMPROB_OPTABSENT
1978# define	ICMP_PARAMPROB_OPTABSENT	1
1979#endif
1980#ifndef	ICMP_PARAMPROB_LENGTH
1981# define	ICMP_PARAMPROB_LENGTH	2
1982#endif
1983#ifndef ICMP_TSTAMP
1984# define	ICMP_TSTAMP	13
1985#endif
1986#ifndef ICMP_TSTAMPREPLY
1987# define	ICMP_TSTAMPREPLY	14
1988#endif
1989#ifndef ICMP_IREQ
1990# define	ICMP_IREQ	15
1991#endif
1992#ifndef ICMP_IREQREPLY
1993# define	ICMP_IREQREPLY	16
1994#endif
1995#ifndef	ICMP_MASKREQ
1996# define	ICMP_MASKREQ	17
1997#endif
1998#ifndef ICMP_MASKREPLY
1999# define	ICMP_MASKREPLY	18
2000#endif
2001#ifndef	ICMP_TRACEROUTE
2002# define	ICMP_TRACEROUTE	30
2003#endif
2004#ifndef	ICMP_DATACONVERR
2005# define	ICMP_DATACONVERR	31
2006#endif
2007#ifndef	ICMP_MOBILE_REDIRECT
2008# define	ICMP_MOBILE_REDIRECT	32
2009#endif
2010#ifndef	ICMP_IPV6_WHEREAREYOU
2011# define	ICMP_IPV6_WHEREAREYOU	33
2012#endif
2013#ifndef	ICMP_IPV6_IAMHERE
2014# define	ICMP_IPV6_IAMHERE	34
2015#endif
2016#ifndef	ICMP_MOBILE_REGREQUEST
2017# define	ICMP_MOBILE_REGREQUEST	35
2018#endif
2019#ifndef	ICMP_MOBILE_REGREPLY
2020# define	ICMP_MOBILE_REGREPLY	36
2021#endif
2022#ifndef	ICMP_SKIP
2023# define	ICMP_SKIP	39
2024#endif
2025#ifndef	ICMP_PHOTURIS
2026# define	ICMP_PHOTURIS	40
2027#endif
2028#ifndef	ICMP_PHOTURIS_UNKNOWN_INDEX
2029# define	ICMP_PHOTURIS_UNKNOWN_INDEX	1
2030#endif
2031#ifndef	ICMP_PHOTURIS_AUTH_FAILED
2032# define	ICMP_PHOTURIS_AUTH_FAILED	2
2033#endif
2034#ifndef	ICMP_PHOTURIS_DECRYPT_FAILED
2035# define	ICMP_PHOTURIS_DECRYPT_FAILED	3
2036#endif
2037#ifndef	IPVERSION
2038# define	IPVERSION	4
2039#endif
2040#ifndef	IPOPT_MINOFF
2041# define	IPOPT_MINOFF	4
2042#endif
2043#ifndef	IPOPT_COPIED
2044# define	IPOPT_COPIED(x)	((x)&0x80)
2045#endif
2046#ifndef	IPOPT_EOL
2047# define	IPOPT_EOL	0
2048#endif
2049#ifndef	IPOPT_NOP
2050# define	IPOPT_NOP	1
2051#endif
2052#ifndef	IP_MF
2053# define	IP_MF	((u_short)0x2000)
2054#endif
2055#ifndef	ETHERTYPE_IP
2056# define	ETHERTYPE_IP	((u_short)0x0800)
2057#endif
2058#ifndef	TH_FIN
2059# define	TH_FIN	0x01
2060#endif
2061#ifndef	TH_SYN
2062# define	TH_SYN	0x02
2063#endif
2064#ifndef	TH_RST
2065# define	TH_RST	0x04
2066#endif
2067#ifndef	TH_PUSH
2068# define	TH_PUSH	0x08
2069#endif
2070#ifndef	TH_ACK
2071# define	TH_ACK	0x10
2072#endif
2073#ifndef	TH_URG
2074# define	TH_URG	0x20
2075#endif
2076#undef	TH_ACKMASK
2077#define	TH_ACKMASK	(TH_FIN|TH_SYN|TH_RST|TH_ACK)
2078
2079#ifndef	IPOPT_EOL
2080# define	IPOPT_EOL	0
2081#endif
2082#ifndef	IPOPT_NOP
2083# define	IPOPT_NOP	1
2084#endif
2085#ifndef	IPOPT_RR
2086# define	IPOPT_RR	7
2087#endif
2088#ifndef	IPOPT_TS
2089# define	IPOPT_TS	68
2090#endif
2091#ifndef	IPOPT_SECURITY
2092# define	IPOPT_SECURITY	130
2093#endif
2094#ifndef	IPOPT_LSRR
2095# define	IPOPT_LSRR	131
2096#endif
2097#ifndef	IPOPT_SATID
2098# define	IPOPT_SATID	136
2099#endif
2100#ifndef	IPOPT_SSRR
2101# define	IPOPT_SSRR	137
2102#endif
2103#ifndef	IPOPT_SECUR_UNCLASS
2104# define	IPOPT_SECUR_UNCLASS	((u_short)0x0000)
2105#endif
2106#ifndef	IPOPT_SECUR_CONFID
2107# define	IPOPT_SECUR_CONFID	((u_short)0xf135)
2108#endif
2109#ifndef	IPOPT_SECUR_EFTO
2110# define	IPOPT_SECUR_EFTO	((u_short)0x789a)
2111#endif
2112#ifndef	IPOPT_SECUR_MMMM
2113# define	IPOPT_SECUR_MMMM	((u_short)0xbc4d)
2114#endif
2115#ifndef	IPOPT_SECUR_RESTR
2116# define	IPOPT_SECUR_RESTR	((u_short)0xaf13)
2117#endif
2118#ifndef	IPOPT_SECUR_SECRET
2119# define	IPOPT_SECUR_SECRET	((u_short)0xd788)
2120#endif
2121#ifndef IPOPT_SECUR_TOPSECRET
2122# define	IPOPT_SECUR_TOPSECRET	((u_short)0x6bc5)
2123#endif
2124#ifndef IPOPT_OLEN
2125# define	IPOPT_OLEN	1
2126#endif
2127#ifndef	IPPROTO_HOPOPTS
2128# define	IPPROTO_HOPOPTS	0
2129#endif
2130#ifndef	IPPROTO_ENCAP
2131# define	IPPROTO_ENCAP	4
2132#endif
2133#ifndef	IPPROTO_IPV6
2134# define	IPPROTO_IPV6	41
2135#endif
2136#ifndef	IPPROTO_ROUTING
2137# define	IPPROTO_ROUTING	43
2138#endif
2139#ifndef	IPPROTO_FRAGMENT
2140# define	IPPROTO_FRAGMENT	44
2141#endif
2142#ifndef	IPPROTO_GRE
2143# define	IPPROTO_GRE	47	/* GRE encaps RFC 1701 */
2144#endif
2145#ifndef	IPPROTO_ESP
2146# define	IPPROTO_ESP	50
2147#endif
2148#ifndef	IPPROTO_AH
2149# define	IPPROTO_AH	51
2150#endif
2151#ifndef	IPPROTO_ICMPV6
2152# define	IPPROTO_ICMPV6	58
2153#endif
2154#ifndef	IPPROTO_NONE
2155# define	IPPROTO_NONE	59
2156#endif
2157#ifndef	IPPROTO_DSTOPTS
2158# define	IPPROTO_DSTOPTS	60
2159#endif
2160#ifndef	IPPROTO_MOBILITY
2161# define	IPPROTO_MOBILITY	135
2162#endif
2163
2164#ifndef	ICMP_ROUTERADVERT
2165# define	ICMP_ROUTERADVERT	9
2166#endif
2167#ifndef	ICMP_ROUTERSOLICIT
2168# define	ICMP_ROUTERSOLICIT	10
2169#endif
2170#ifndef	ICMP6_DST_UNREACH
2171# define	ICMP6_DST_UNREACH	1
2172#endif
2173#ifndef	ICMP6_PACKET_TOO_BIG
2174# define	ICMP6_PACKET_TOO_BIG	2
2175#endif
2176#ifndef	ICMP6_TIME_EXCEEDED
2177# define	ICMP6_TIME_EXCEEDED	3
2178#endif
2179#ifndef	ICMP6_PARAM_PROB
2180# define	ICMP6_PARAM_PROB	4
2181#endif
2182
2183#ifndef	ICMP6_ECHO_REQUEST
2184# define	ICMP6_ECHO_REQUEST	128
2185#endif
2186#ifndef	ICMP6_ECHO_REPLY
2187# define	ICMP6_ECHO_REPLY	129
2188#endif
2189#ifndef	ICMP6_MEMBERSHIP_QUERY
2190# define	ICMP6_MEMBERSHIP_QUERY	130
2191#endif
2192#ifndef	MLD6_LISTENER_QUERY
2193# define	MLD6_LISTENER_QUERY	130
2194#endif
2195#ifndef	ICMP6_MEMBERSHIP_REPORT
2196# define	ICMP6_MEMBERSHIP_REPORT	131
2197#endif
2198#ifndef	MLD6_LISTENER_REPORT
2199# define	MLD6_LISTENER_REPORT	131
2200#endif
2201#ifndef	ICMP6_MEMBERSHIP_REDUCTION
2202# define	ICMP6_MEMBERSHIP_REDUCTION	132
2203#endif
2204#ifndef	MLD6_LISTENER_DONE
2205# define	MLD6_LISTENER_DONE	132
2206#endif
2207#ifndef	ND_ROUTER_SOLICIT
2208# define	ND_ROUTER_SOLICIT	133
2209#endif
2210#ifndef	ND_ROUTER_ADVERT
2211# define	ND_ROUTER_ADVERT	134
2212#endif
2213#ifndef	ND_NEIGHBOR_SOLICIT
2214# define	ND_NEIGHBOR_SOLICIT	135
2215#endif
2216#ifndef	ND_NEIGHBOR_ADVERT
2217# define	ND_NEIGHBOR_ADVERT	136
2218#endif
2219#ifndef	ND_REDIRECT
2220# define	ND_REDIRECT	137
2221#endif
2222#ifndef	ICMP6_ROUTER_RENUMBERING
2223# define	ICMP6_ROUTER_RENUMBERING	138
2224#endif
2225#ifndef	ICMP6_WRUREQUEST
2226# define	ICMP6_WRUREQUEST	139
2227#endif
2228#ifndef	ICMP6_WRUREPLY
2229# define	ICMP6_WRUREPLY		140
2230#endif
2231#ifndef	ICMP6_FQDN_QUERY
2232# define	ICMP6_FQDN_QUERY	139
2233#endif
2234#ifndef	ICMP6_FQDN_REPLY
2235# define	ICMP6_FQDN_REPLY	140
2236#endif
2237#ifndef	ICMP6_NI_QUERY
2238# define	ICMP6_NI_QUERY		139
2239#endif
2240#ifndef	ICMP6_NI_REPLY
2241# define	ICMP6_NI_REPLY		140
2242#endif
2243#ifndef	MLD6_MTRACE_RESP
2244# define	MLD6_MTRACE_RESP	200
2245#endif
2246#ifndef	MLD6_MTRACE
2247# define	MLD6_MTRACE		201
2248#endif
2249#ifndef	ICMP6_HADISCOV_REQUEST
2250# define	ICMP6_HADISCOV_REQUEST	202
2251#endif
2252#ifndef	ICMP6_HADISCOV_REPLY
2253# define	ICMP6_HADISCOV_REPLY	203
2254#endif
2255#ifndef	ICMP6_MOBILEPREFIX_SOLICIT
2256# define	ICMP6_MOBILEPREFIX_SOLICIT	204
2257#endif
2258#ifndef	ICMP6_MOBILEPREFIX_ADVERT
2259# define	ICMP6_MOBILEPREFIX_ADVERT	205
2260#endif
2261#ifndef	ICMP6_MAXTYPE
2262# define	ICMP6_MAXTYPE		205
2263#endif
2264
2265#ifndef	ICMP6_DST_UNREACH_NOROUTE
2266# define	ICMP6_DST_UNREACH_NOROUTE	0
2267#endif
2268#ifndef	ICMP6_DST_UNREACH_ADMIN
2269# define	ICMP6_DST_UNREACH_ADMIN		1
2270#endif
2271#ifndef	ICMP6_DST_UNREACH_NOTNEIGHBOR
2272# define	ICMP6_DST_UNREACH_NOTNEIGHBOR	2
2273#endif
2274#ifndef	ICMP6_DST_UNREACH_BEYONDSCOPE
2275# define	ICMP6_DST_UNREACH_BEYONDSCOPE	2
2276#endif
2277#ifndef	ICMP6_DST_UNREACH_ADDR
2278# define	ICMP6_DST_UNREACH_ADDR		3
2279#endif
2280#ifndef	ICMP6_DST_UNREACH_NOPORT
2281# define	ICMP6_DST_UNREACH_NOPORT	4
2282#endif
2283#ifndef	ICMP6_TIME_EXCEED_TRANSIT
2284# define	ICMP6_TIME_EXCEED_TRANSIT	0
2285#endif
2286#ifndef	ICMP6_TIME_EXCEED_REASSEMBLY
2287# define	ICMP6_TIME_EXCEED_REASSEMBLY	1
2288#endif
2289
2290#ifndef	ICMP6_NI_SUCCESS
2291# define	ICMP6_NI_SUCCESS	0
2292#endif
2293#ifndef	ICMP6_NI_REFUSED
2294# define	ICMP6_NI_REFUSED	1
2295#endif
2296#ifndef	ICMP6_NI_UNKNOWN
2297# define	ICMP6_NI_UNKNOWN	2
2298#endif
2299
2300#ifndef	ICMP6_ROUTER_RENUMBERING_COMMAND
2301# define	ICMP6_ROUTER_RENUMBERING_COMMAND	0
2302#endif
2303#ifndef	ICMP6_ROUTER_RENUMBERING_RESULT
2304# define	ICMP6_ROUTER_RENUMBERING_RESULT	1
2305#endif
2306#ifndef	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2307# define	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET	255
2308#endif
2309
2310#ifndef	ICMP6_PARAMPROB_HEADER
2311# define	ICMP6_PARAMPROB_HEADER	0
2312#endif
2313#ifndef	ICMP6_PARAMPROB_NEXTHEADER
2314# define	ICMP6_PARAMPROB_NEXTHEADER	1
2315#endif
2316#ifndef	ICMP6_PARAMPROB_OPTION
2317# define	ICMP6_PARAMPROB_OPTION	2
2318#endif
2319
2320#ifndef	ICMP6_NI_SUBJ_IPV6
2321# define	ICMP6_NI_SUBJ_IPV6	0
2322#endif
2323#ifndef	ICMP6_NI_SUBJ_FQDN
2324# define	ICMP6_NI_SUBJ_FQDN	1
2325#endif
2326#ifndef	ICMP6_NI_SUBJ_IPV4
2327# define	ICMP6_NI_SUBJ_IPV4	2
2328#endif
2329
2330/*
2331 * ECN is a new addition to TCP - RFC 2481
2332 */
2333#ifndef TH_ECN
2334# define	TH_ECN	0x40
2335#endif
2336#ifndef TH_CWR
2337# define	TH_CWR	0x80
2338#endif
2339#define	TH_ECNALL	(TH_ECN|TH_CWR)
2340
2341/*
2342 * TCP States
2343 */
2344#define IPF_TCPS_CLOSED		0	/* closed */
2345#define IPF_TCPS_LISTEN		1	/* listening for connection */
2346#define IPF_TCPS_SYN_SENT	2	/* active, have sent syn */
2347#define IPF_TCPS_SYN_RECEIVED	3	/* have send and received syn */
2348#define IPF_TCPS_HALF_ESTAB	4	/* for connections not fully "up" */
2349/* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2350#define IPF_TCPS_ESTABLISHED	5	/* established */
2351#define IPF_TCPS_CLOSE_WAIT	6	/* rcvd fin, waiting for close */
2352/* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2353#define IPF_TCPS_FIN_WAIT_1	7	/* have closed, sent fin */
2354#define IPF_TCPS_CLOSING	8	/* closed xchd FIN; await FIN ACK */
2355#define IPF_TCPS_LAST_ACK	9	/* had fin and close; await FIN ACK */
2356/* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2357#define IPF_TCPS_FIN_WAIT_2	10	/* have closed, fin is acked */
2358#define IPF_TCPS_TIME_WAIT	11	/* in 2*msl quiet wait after close */
2359#define IPF_TCP_NSTATES		12
2360
2361#define	TCP_MSL			120
2362
2363#undef	ICMP_MAX_UNREACH
2364#define	ICMP_MAX_UNREACH	14
2365#undef	ICMP_MAXTYPE
2366#define	ICMP_MAXTYPE		18
2367
2368#ifndef	IFNAMSIZ
2369#define	IFNAMSIZ		16
2370#endif
2371
2372#ifndef	LOG_FTP
2373# define	LOG_FTP		(11<<3)
2374#endif
2375#ifndef	LOG_AUTHPRIV
2376# define	LOG_AUTHPRIV	(10<<3)
2377#endif
2378#ifndef	LOG_AUDIT
2379# define	LOG_AUDIT	(13<<3)
2380#endif
2381#ifndef	LOG_NTP
2382# define	LOG_NTP		(12<<3)
2383#endif
2384#ifndef	LOG_SECURITY
2385# define	LOG_SECURITY	(13<<3)
2386#endif
2387#ifndef	LOG_LFMT
2388# define	LOG_LFMT	(14<<3)
2389#endif
2390#ifndef	LOG_CONSOLE
2391# define	LOG_CONSOLE	(14<<3)
2392#endif
2393
2394/*
2395 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2396 * another IP header and then 64 bits of data, totalling 56.  Of course,
2397 * the last 64 bits is dependent on that being available.
2398 */
2399#define	ICMPERR_ICMPHLEN	8
2400#define	ICMPERR_IPICMPHLEN	(20 + 8)
2401#define	ICMPERR_MINPKTLEN	(20 + 8 + 20)
2402#define	ICMPERR_MAXPKTLEN	(20 + 8 + 20 + 8)
2403#define ICMP6ERR_MINPKTLEN	(40 + 8)
2404#define ICMP6ERR_IPICMPHLEN	(40 + 8 + 40)
2405
2406#ifndef MIN
2407# define	MIN(a,b)	(((a)<(b))?(a):(b))
2408#endif
2409
2410#ifdef IPF_DEBUG
2411# define	DPRINT(x)	printf x
2412#else
2413# define	DPRINT(x)
2414#endif
2415
2416#ifdef RESCUE
2417# undef IPFILTER_BPF
2418#endif
2419
2420#endif	/* __IP_COMPAT_H__ */
2421