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