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