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