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