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