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