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