Attachment 'ip_compat.h'

Download

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

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2017-12-16 08:10:08, 69.4 KB) [[attachment:ip_compat.h]]
  • [get | view] (2017-12-16 08:10:17, 49.1 KB) [[attachment:ip_fil.h]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.