1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright (C) 1999-2001, 2003 by Darren Reed. 23 * 24 * See the IPFILTER.LICENCE file for details on licencing. 25 * 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 27 * Use is subject to license terms. 28 */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifndef __IP_COMPAT_H__ 33 #define __IP_COMPAT_H__ 34 35 #ifndef __P 36 # ifdef __STDC__ 37 # define __P(x) x 38 # else 39 # define __P(x) () 40 # endif 41 #endif 42 #ifndef __STDC__ 43 # undef const 44 # define const 45 #endif 46 47 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__) 48 # undef KERNEL 49 # undef _KERNEL 50 # undef __KERNEL__ 51 # define KERNEL 52 # define _KERNEL 53 # define __KERNEL__ 54 #endif 55 56 #ifndef SOLARIS 57 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 58 #endif 59 #if (SOLARIS2 >= 8) && (SOLARIS2 < 10) 60 # ifndef USE_INET6 61 # define USE_INET6 62 # endif 63 #endif 64 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \ 65 !defined(_KERNEL) 66 # define USE_INET6 67 #endif 68 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \ 69 !defined(_KERNEL) 70 # define USE_INET6 71 #endif 72 #if defined(OpenBSD) && (OpenBSD >= 200206) && !defined(_KERNEL) 73 # define USE_INET6 74 #endif 75 #if defined(__osf__) 76 # define USE_INET6 77 #endif 78 79 #if defined(BSD) && (BSD < 199103) && defined(__osf__) 80 # undef BSD 81 # define BSD 199103 82 #endif 83 84 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi) 85 # define index strchr 86 # if !defined(_KERNEL) 87 # define bzero(a,b) memset(a,0,b) 88 # define bcmp memcmp 89 # define bcopy(a,b,c) memmove(b,a,c) 90 # endif 91 #endif 92 93 #ifndef LIFNAMSIZ 94 # ifdef IF_NAMESIZE 95 # define LIFNAMSIZ IF_NAMESIZE 96 # else 97 # ifdef IFNAMSIZ 98 # define LIFNAMSIZ IFNAMSIZ 99 # else 100 # define LIFNAMSIZ 16 101 # endif 102 # endif 103 #endif 104 105 #if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux) 106 struct ether_addr { 107 u_char ether_addr_octet[6]; 108 }; 109 #endif 110 111 #if defined(__sgi) && !defined(IPFILTER_LKM) 112 # ifdef __STDC__ 113 # define IPL_EXTERN(ep) ipfilter##ep 114 # else 115 # define IPL_EXTERN(ep) ipfilter/**/ep 116 # endif 117 #else 118 # ifdef __STDC__ 119 # define IPL_EXTERN(ep) ipl##ep 120 # else 121 # define IPL_EXTERN(ep) ipl/**/ep 122 # endif 123 #endif 124 125 /* 126 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD. 127 */ 128 #ifndef _KERNEL 129 # define ADD_KERNEL 130 # define _KERNEL 131 # define KERNEL 132 #endif 133 #ifdef __OpenBSD__ 134 struct file; 135 #endif 136 #include <sys/uio.h> 137 #ifdef ADD_KERNEL 138 # undef _KERNEL 139 # undef KERNEL 140 #endif 141 142 143 /* ----------------------------------------------------------------------- */ 144 /* S O L A R I S */ 145 /* ----------------------------------------------------------------------- */ 146 #if SOLARIS 147 # define MENTAT 1 148 # include <sys/cmn_err.h> 149 # include <sys/isa_defs.h> 150 # include <sys/stream.h> 151 # include <sys/ioccom.h> 152 # include <sys/sysmacros.h> 153 # include <sys/kmem.h> 154 # if SOLARIS2 >= 10 155 # include <sys/procset.h> 156 # include <sys/proc.h> 157 # include <sys/devops.h> 158 # include <sys/ddi_impldefs.h> 159 # endif 160 /* 161 * because Solaris 2 defines these in two places :-/ 162 */ 163 # ifndef KERNEL 164 # define _KERNEL 165 # undef RES_INIT 166 # endif /* _KERNEL */ 167 168 # if SOLARIS2 >= 8 169 # include <netinet/ip6.h> 170 # include <netinet/icmp6.h> 171 # endif 172 173 # include <inet/common.h> 174 /* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */ 175 # undef IPOPT_EOL 176 # undef IPOPT_NOP 177 # undef IPOPT_LSRR 178 # undef IPOPT_RR 179 # undef IPOPT_SSRR 180 # include <inet/ip.h> 181 # undef COPYOUT 182 # include <inet/ip_ire.h> 183 # ifndef KERNEL 184 # undef _KERNEL 185 # endif 186 # if SOLARIS2 >= 8 187 # include <inet/ip_if.h> 188 # include <inet/ip6.h> 189 # define ipif_local_addr ipif_lcl_addr 190 /* Only defined in private include file */ 191 # ifndef V4_PART_OF_V6 192 # define V4_PART_OF_V6(v6) v6.s6_addr32[3] 193 # endif 194 struct ip6_ext { 195 u_char ip6e_nxt; 196 u_char ip6e_len; 197 }; 198 # endif /* SOLARIS2 >= 8 */ 199 200 # if SOLARIS2 >= 6 201 # include <sys/atomic.h> 202 typedef uint32_t u_32_t; 203 # else 204 typedef unsigned int u_32_t; 205 # endif 206 # define U_32_T 1 207 208 # ifdef _KERNEL 209 # define KRWLOCK_T krwlock_t 210 # define KMUTEX_T kmutex_t 211 # include "pfil.h" 212 # include "qif.h" 213 # if SOLARIS2 >= 6 214 # if SOLARIS2 == 6 215 # define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1) 216 # define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1) 217 # else 218 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1) 219 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1) 220 # endif /* SOLARIS2 == 6 */ 221 # define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1) 222 # define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1) 223 # define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1) 224 # define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1) 225 # define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1) 226 # define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1) 227 # else 228 # define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \ 229 mutex_exit(&ipf_rw); } 230 # define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \ 231 mutex_exit(&ipf_rw); } 232 # endif /* SOLARIS2 >= 6 */ 233 # define USE_MUTEXES 234 # define MUTEX_ENTER(x) mutex_enter(&(x)->ipf_lk) 235 # define READ_ENTER(x) rw_enter(&(x)->ipf_lk, RW_READER) 236 # define WRITE_ENTER(x) rw_enter(&(x)->ipf_lk, RW_WRITER) 237 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk) 238 # if SOLARIS2 >= 6 239 # define RWLOCK_INIT(x, y) rw_init(&(x)->ipf_lk, NULL, \ 240 RW_DRIVER, NULL) 241 # else 242 # define RWLOCK_INIT(x, y) rw_init(&(x)->ipf_lk, (y), \ 243 RW_DRIVER, NULL) 244 # endif /* SOLARIS2 >= 6 */ 245 246 # define RWLOCK_EXIT(x) rw_exit(&(x)->ipf_lk) 247 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk) 248 249 # if SOLARIS2 >= 6 250 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, NULL, \ 251 MUTEX_DRIVER, NULL) 252 # else 253 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, (y), \ 254 MUTEX_DRIVER, NULL) 255 # endif /* SOLARIS2 >= 6 */ 256 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk) 257 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 258 # define MUTEX_EXIT(x) mutex_exit(&(x)->ipf_lk) 259 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 260 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 261 # define BCOPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 262 # define BCOPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 263 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 264 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 265 # define KFREES(x,s) kmem_free((char *)(x), (s)) 266 # define SPL_NET(x) ; 267 # define SPL_IMP(x) ; 268 # undef SPL_X 269 # define SPL_X(x) ; 270 # ifdef sparc 271 # define ntohs(x) (x) 272 # define ntohl(x) (x) 273 # define htons(x) (x) 274 # define htonl(x) (x) 275 # endif /* sparc */ 276 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 277 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 278 # define GET_MINOR(x) getminor(x) 279 #ifndef IRE_ILL_CN 280 extern ill_t *get_unit __P((char *, int)); 281 # define GETIFP(n, v) get_unit(n, v) 282 # define IFNAME(x) ((ill_t *)x)->ill_name 283 # define COPYIFNAME(x, b) \ 284 strncpy(b, ((ill_t *)x)->ill_name, LIFNAMSIZ) 285 #else 286 extern kmutex_t s_ill_g_head_lock; 287 extern struct s_ill_s *s_ill_g_head; /* ILL List Head */ 288 extern s_ill_t *get_unit __P((char *, int)); 289 # define GETIFP(n, v) get_unit(n, v) 290 # define IFNAME(x) ((s_ill_t *)x)->ill_name 291 # define COPYIFNAME(x, b) \ 292 strncpy(b, ((s_ill_t *)x)->ill_name, LIFNAMSIZ) 293 #endif /* IRE_ILL_CN */ 294 # define GETKTIME(x) uniqtime((struct timeval *)x) 295 # define MSGDSIZE(x) msgdsize(x) 296 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr) 297 # define M_DUPLICATE(x) dupmsg((x)) 298 # define MTOD(m,t) (t)((m)->b_rptr) 299 # define MTYPE(m) ((m)->b_datap->db_type) 300 # define FREE_MB_T(m) freemsg(m) 301 # define CACHE_HASH(x) (((qif_t *)(x)->fin_qif)->qf_num & 7) 302 # define IPF_PANIC(x,y) if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); } 303 typedef mblk_t mb_t; 304 # endif /* _KERNEL */ 305 306 # if (SOLARIS2 >= 7) 307 # ifdef lint 308 # define ALIGN32(ptr) (ptr ? 0L : 0L) 309 # define ALIGN16(ptr) (ptr ? 0L : 0L) 310 # else 311 # define ALIGN32(ptr) (ptr) 312 # define ALIGN16(ptr) (ptr) 313 # endif 314 # endif 315 316 317 # define OS_RECOGNISED 1 318 319 #endif /* SOLARIS */ 320 321 /* ----------------------------------------------------------------------- */ 322 /* H P U X */ 323 /* ----------------------------------------------------------------------- */ 324 #ifdef __hpux 325 # define MENTAT 1 326 # include <sys/sysmacros.h> 327 # include <sys/spinlock.h> 328 # include <sys/lock.h> 329 # include <sys/stream.h> 330 331 # ifdef _KERNEL 332 333 # define GETKTIME(x) uniqtime((struct timeval *)x) 334 335 # if HPUXREV == 1111 336 # include "kern_svcs.h" 337 # else 338 # include <sys/kern_svcs.h> 339 # endif 340 # undef ti_flags 341 # undef TCP_NODELAY 342 # undef TCP_MAXSEG 343 # include <sys/reg.h> 344 # include "../netinet/ip_info.h" 345 /* 346 * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions 347 * are available. Attempting to use them actually results in unresolved 348 * symbols when it comes time to load the module. 349 */ 350 # if 0 351 # ifdef __LP64__ 352 # define ATOMIC_INCL(x) lock_and_incr_int64(&ipf_rw, x, 1) 353 # define ATOMIC_DECL(x) lock_and_incr_int64(&ipf_rw, x, -1) 354 # else 355 # define ATOMIC_INCL(x) lock_and_incr_int32(&ipf_rw, x, 1) 356 # define ATOMIC_DECL(x) lock_and_incr_int32(&ipf_rw, x, -1) 357 # endif 358 # define ATOMIC_INC64(x) lock_and_incr_int64(&ipf_rw, x, 1) 359 # define ATOMIC_INC32(x) lock_and_incr_int32(&ipf_rw, x, 1) 360 # define ATOMIC_INC16(x) lock_and_incr_int16(&ipf_rw, x, 1) 361 # define ATOMIC_DEC64(x) lock_and_incr_int64(&ipf_rw, x, -1) 362 # define ATOMIC_DEC32(x) lock_and_incr_int32(&ipf_rw, x, -1) 363 # define ATOMIC_DEC16(x) lock_and_incr_int16(&ipf_rw, x, -1) 364 # else /* 0 */ 365 # define ATOMIC_INC(x) { spinlock(&ipf_rw); (x)++; \ 366 spinunlock(&ipf_rw); } 367 # define ATOMIC_DEC(x) { spinlock(&ipf_rw); (x)--; \ 368 spinunlock(&ipf_rw); } 369 # endif 370 # define ip_cksum ip_csuma 371 # define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c) 372 # define USE_MUTEXES 373 # define MUTEX_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, (y)) 374 # define MUTEX_ENTER(x) spinlock(&(x)->ipf_lk) 375 # define MUTEX_EXIT(x) spinunlock(&(x)->ipf_lk) 376 # define MUTEX_DESTROY(x) 377 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 378 /* 379 * The read-write lock implementation in HP-UX 11.0 is crippled - it can 380 * only be used by threads working in a user context! 381 */ 382 # if 0 383 # define MUTEX_DOWNGRADE(x) lock_write_to_read(x) 384 # define KRWLOCK_T struct rwlock 385 # define READ_ENTER(x) lock_read(&(x)->ipf_lk) 386 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk) 387 # define RWLOCK_INIT(x, y) lock_init3(&(x)->ipf_lk, 0, 1, 0, y) 388 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk) 389 # else 390 # define KRWLOCK_T lock_t 391 # define KMUTEX_T lock_t 392 # define kmutex_t lock_t /* for pfil.h */ 393 # define krwlock_t lock_t /* for pfil.h */ 394 # define READ_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk) 395 # define WRITE_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk) 396 # define MUTEX_DOWNGRADE(x) 397 # define RWLOCK_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, y) 398 # define RWLOCK_EXIT(x) spinunlock(&(x)->ipf_lk) 399 # endif 400 # define RW_DESTROY(x) 401 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 402 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 403 # if HPUXREV > 1100 404 # define BCOPYIN(a,b,c) memcpy((caddr_t)(a), (caddr_t)(b), (c)) 405 # define BCOPYOUT(a,b,c) memcpy((caddr_t)(a), (caddr_t)(b), (c)) 406 # else 407 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 408 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 409 # endif 410 # define SPL_NET(x) ; 411 # define SPL_IMP(x) ; 412 # undef SPL_X 413 # define SPL_X(x) ; 414 extern ifinfo_t *get_unit __P((char *, int)); 415 # define GETIFP(n, v) get_unit(n, v) 416 # define IFNAME(x, b) ((ifinfo_t *)x)->ifi_name 417 # define COPYIFNAME(x, b) \ 418 strncpy(b, ((ifinfo_t *)x)->ifi_name, \ 419 LIFNAMSIZ) 420 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 421 # define SLEEP(id, n) { lock_t *_l = get_sleep_lock((caddr_t)id); \ 422 sleep(id, PZERO+1); \ 423 spinunlock(_l); \ 424 } 425 # define WAKEUP(id) { lock_t *_l = get_sleep_lock((caddr_t)id); \ 426 wakeup(id); \ 427 spinunlock(_l); \ 428 } 429 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT) 430 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_IOSYS, M_NOWAIT) 431 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 432 # define KFREES(x,s) kmem_free((char *)(x), (s)) 433 # define MSGDSIZE(x) msgdsize(x) 434 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr) 435 # define M_DUPLICATE(x) dupmsg((x)) 436 # define MTOD(m,t) (t)((m)->b_rptr) 437 # define MTYPE(m) ((m)->b_datap->db_type) 438 # define FREE_MB_T(m) freemsg(m) 439 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 440 typedef mblk_t mb_t; 441 442 # define CACHE_HASH(x) (((qif_t *)(x)->fin_qif)->qf_num & 7) 443 444 # include "pfil.h" 445 # include "qif.h" 446 447 # else /* _KERNEL */ 448 449 typedef unsigned char uchar_t; 450 451 # ifndef _SYS_STREAM_INCLUDED 452 typedef char * mblk_t; 453 typedef void * queue_t; 454 typedef u_long ulong; 455 # endif 456 # include <netinet/ip_info.h> 457 458 # endif /* _KERNEL */ 459 460 # ifdef lint 461 # define ALIGN32(ptr) (ptr ? 0L : 0L) 462 # define ALIGN16(ptr) (ptr ? 0L : 0L) 463 # else 464 # define ALIGN32(ptr) (ptr) 465 # define ALIGN16(ptr) (ptr) 466 # endif 467 468 typedef int minor_t; 469 typedef unsigned int u_32_t; 470 # define U_32_T 1 471 472 # define OS_RECOGNISED 1 473 474 #endif /* __hpux */ 475 476 /* ----------------------------------------------------------------------- */ 477 /* I R I X */ 478 /* ----------------------------------------------------------------------- */ 479 #ifdef __sgi 480 # undef MENTAT 481 typedef u_int32_t u_32_t; 482 # define U_32_T 1 483 484 # ifdef INET6 485 # define USE_INET6 486 # endif 487 488 # define hz HZ 489 # include <sys/ksynch.h> 490 # define IPF_LOCK_PL plhi 491 # include <sys/sema.h> 492 # undef kmutex_t 493 typedef struct { 494 lock_t *l; 495 int pl; 496 } kmutex_t; 497 498 # ifdef MUTEX_INIT 499 # define KMUTEX_T mutex_t 500 # else 501 # define KMUTEX_T kmutex_t 502 # define KRWLOCK_T kmutex_t 503 # endif 504 505 # ifdef _KERNEL 506 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ 507 (x)++; MUTEX_EXIT(&ipf_rw); } 508 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ 509 (x)--; MUTEX_EXIT(&ipf_rw); } 510 # define USE_MUTEXES 511 # ifdef MUTEX_INIT 512 # include <sys/atomic_ops.h> 513 # define ATOMIC_INCL(x) atomicAddUlong(&(x), 1) 514 # define ATOMIC_INC64(x) atomicAddUint64(&(x), 1) 515 # define ATOMIC_INC32(x) atomicAddUint(&(x), 1) 516 # define ATOMIC_INC16 ATOMIC_INC 517 # define ATOMIC_DECL(x) atomicAddUlong(&(x), -1) 518 # define ATOMIC_DEC64(x) atomicAddUint64(&(x), -1) 519 # define ATOMIC_DEC32(x) atomicAddUint(&(x), -1) 520 # define ATOMIC_DEC16 ATOMIC_DEC 521 # undef MUTEX_INIT 522 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, 523 MUTEX_DEFAULT, y) 524 # undef MUTEX_ENTER 525 # define MUTEX_ENTER(x) mutex_lock(&(x)->ipf_lk, 0) 526 # undef MUTEX_EXIT 527 # define MUTEX_EXIT(x) mutex_unlock(&(x)->ipf_lk) 528 # undef MUTEX_DESTROY 529 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk) 530 # define MUTEX_DOWNGRADE(x) mrdemote(&(x)->ipf_lk) 531 # define KRWLOCK_T mrlock_t 532 # define RWLOCK_INIT(x, y) mrinit(&(x)->ipf_lk, y) 533 # undef RW_DESTROY 534 # define RW_DESTROY(x) mrfree(&(x)->ipf_lk) 535 # define READ_ENTER(x) RW_RDLOCK(&(x)->ipf_lk) 536 # define WRITE_ENTER(x) RW_WRLOCK(&(x)->ipf_lk) 537 # define RWLOCK_EXIT(x) RW_UNLOCK(&(x)->ipf_lk) 538 # else 539 # define READ_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk) 540 # define WRITE_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk) 541 # define MUTEX_DOWNGRADE(x) ; 542 # define RWLOCK_EXIT(x) MUTEX_EXIT(&(x)->ipf_lk) 543 # define MUTEX_EXIT(x) UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl); 544 # define MUTEX_INIT(x,y) (x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP) 545 # define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->ipf_lk.l) 546 # define MUTEX_ENTER(x) (x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \ 547 IPF_LOCK_PL); 548 # endif 549 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 550 # define FREE_MB_T(m) m_freem(m) 551 # define MTOD(m,t) mtod(m,t) 552 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 553 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 554 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 555 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 556 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 557 # define SLEEP(id, n) sleep((id), PZERO+1) 558 # define WAKEUP(id) wakeup(id) 559 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 560 # define KFREES(x,s) kmem_free((char *)(x), (s)) 561 # define GETIFP(n,v) ifunit(n) 562 # include <sys/kmem.h> 563 # include <sys/ddi.h> 564 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 565 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 566 # define GET_MINOR(x) getminor(x) 567 # define SPL_IMP(x) (x) = splimp() 568 # define SPL_NET(x) (x) = splnet() 569 # define SPL_X(x) (void) splx(x) 570 extern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 571 extern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 572 # define MSGDSIZE(x) mbufchainlen(x) 573 # define M_LEN(x) (x)->m_len 574 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 575 # define GETKTIME(x) microtime((struct timeval *)x) 576 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 577 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 578 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 579 typedef struct mbuf mb_t; 580 # endif /* _KERNEL */ 581 582 # define OS_RECOGNISED 1 583 584 #endif /* __sgi */ 585 586 /* ----------------------------------------------------------------------- */ 587 /* T R U 6 4 */ 588 /* ----------------------------------------------------------------------- */ 589 #ifdef __osf__ 590 # undef MENTAT 591 /* 592 * Really, any arch where sizeof(long) != sizeof(int). 593 */ 594 typedef unsigned int u_32_t; 595 # define U_32_T 1 596 597 # include <kern/lock.h> 598 # include <sys/sysmacros.h> 599 600 # ifdef _KERNEL 601 # define KMUTEX_T simple_lock_data_t 602 # define KRWLOCK_T lock_data_t 603 # include <net/net_globals.h> 604 # define USE_MUTEXES 605 # define READ_ENTER(x) lock_read(&(x)->ipf_lk) 606 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk) 607 # define MUTEX_DOWNGRADE(x) lock_write_to_read(&(x)->ipf_lk) 608 # define RWLOCK_INIT(x, y) lock_init(&(x)->ipf_lk, TRUE) 609 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk) 610 # define RW_DESTROY(x) lock_terminate(&(x)->ipf_lk) 611 # define MUTEX_ENTER(x) simple_lock(&(x)->ipf_lk) 612 # define MUTEX_INIT(x, y) simple_lock_init(&(x)->ipf_lk) 613 # define MUTEX_DESTROY(x) simple_lock_terminate(&(x)->ipf_lk) 614 # define MUTEX_EXIT(x) simple_unlock(&(x)->ipf_lk) 615 # define MUTEX_NUKE(x) bzero(x, sizeof(*(x))) 616 # define ATOMIC_INC64(x) atomic_incq((uint64_t*)&(x)) 617 # define ATOMIC_DEC64(x) atomic_decq((uint64_t*)&(x)) 618 # define ATOMIC_INC32(x) atomic_incl((uint32_t*)&(x)) 619 # define ATOMIC_DEC32(x) atomic_decl((uint32_t*)&(x)) 620 # define ATOMIC_INC16(x) { simple_lock(&ipf_rw); (x)++; \ 621 simple_unlock(&ipf_rw); } 622 # define ATOMIC_DEC16(x) { simple_lock(&ipf_rw); (x)--; \ 623 simple_unlock(&ipf_rw); } 624 # define ATOMIC_INCL(x) atomic_incl((uint32_t*)&(x)) 625 # define ATOMIC_DECL(x) atomic_decl((uint32_t*)&(x)) 626 # define ATOMIC_INC(x) { simple_lock(&ipf_rw); (x)++; \ 627 simple_unlock(&ipf_rw); } 628 # define ATOMIC_DEC(x) { simple_lock(&ipf_rw); (x)--; \ 629 simple_unlock(&ipf_rw); } 630 # define SPL_NET(x) ; 631 # define SPL_IMP(x) ; 632 # undef SPL_X 633 # define SPL_X(x) ; 634 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a, b, d) 635 # define FREE_MB_T(m) m_freem(m) 636 # define MTOD(m,t) mtod(m,t) 637 # define GETIFP(n, v) ifunit(n) 638 # define GET_MINOR getminor 639 # define WAKEUP wakeup 640 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 641 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 642 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 643 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 644 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT) 645 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFILT, M_NOWAIT) 646 # define KFREE(x) FREE((x), M_PFILT) 647 # define KFREES(x,s) FREE((x), M_PFILT) 648 # define MSGDSIZE(x) (x)->m_pkthdr.len 649 # define M_LEN(x) (x)->m_len 650 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 651 # define GETKTIME(x) microtime((struct timeval *)x) 652 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 653 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 654 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 655 typedef struct mbuf mb_t; 656 # endif /* _KERNEL */ 657 658 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1)) 659 # define IP_V(x) ((x)->ip_vhl >> 4) 660 # define IP_HL(x) ((x)->ip_vhl & 0xf) 661 # define IP_V_A(x,y) (x)->ip_vhl |= (((y) << 4) & 0xf0) 662 # define IP_HL_A(x,y) (x)->ip_vhl |= ((y) & 0xf) 663 # define TCP_OFF(x) ((x)->th_xoff >> 4) 664 # define TCP_OFF_A(x,y) (x)->th_xoff = ((y) << 4) 665 # endif 666 667 /* 668 * These are from's Solaris' #defines for little endian. 669 */ 670 #define IP6F_MORE_FRAG 0x0100 671 #define IP6F_RESERVED_MASK 0x0600 672 #define IP6F_OFF_MASK 0xf8ff 673 674 struct ip6_ext { 675 u_char ip6e_nxt; 676 u_char ip6e_len; 677 }; 678 679 # define OS_RECOGNISED 1 680 #endif /* __osf__ */ 681 682 /* ----------------------------------------------------------------------- */ 683 /* N E T B S D */ 684 /* ----------------------------------------------------------------------- */ 685 #ifdef __NetBSD__ 686 # if defined(_KERNEL) && !defined(IPFILTER_LKM) 687 # if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000) 688 # include "opt_inet.h" 689 # endif 690 # ifdef INET6 691 # define USE_INET6 692 # endif 693 # endif 694 695 # ifdef _KERNEL 696 # define MSGDSIZE(x) (x)->m_pkthdr.len 697 # define M_LEN(x) (x)->m_len 698 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 699 # define GETKTIME(x) microtime((struct timeval *)x) 700 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 701 typedef struct mbuf mb_t; 702 # endif /* _KERNEL */ 703 # if (NetBSD <= 1991011) && (NetBSD >= 199606) 704 # define IFNAME(x) ((struct ifnet *)x)->if_xname 705 # define COPYIFNAME(x, b) \ 706 strncpy(b, ((struct ifnet *)x)->if_xname, \ 707 LIFNAMSIZ) 708 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7) 709 # else 710 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 711 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 712 # endif 713 714 typedef int minor_t; 715 typedef u_int32_t u_32_t; 716 # define U_32_T 1 717 718 719 # define OS_RECOGNISED 1 720 #endif /* __NetBSD__ */ 721 722 723 /* ----------------------------------------------------------------------- */ 724 /* F R E E B S D */ 725 /* ----------------------------------------------------------------------- */ 726 #ifdef __FreeBSD__ 727 # if defined(_KERNEL) && !defined(IPFILTER_LKM) && !defined(KLD_MODULE) 728 # if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) 729 # include "opt_inet6.h" 730 # endif 731 # ifdef INET6 732 #error foo 733 # define USE_INET6 734 # endif 735 # endif 736 737 # if defined(_KERNEL) /* XXX When *isn't* this defined? */ 738 # if (__FreeBSD_version >= 500043) 739 # include "opt_pfil.h" 740 # endif /* __FreeBSD_version */ 741 # ifdef PFIL_HOOKS 742 # define NETBSD_PF 743 # endif /* PFIL_HOOKS */ 744 # endif /* _KERNEL */ 745 746 # if (__FreeBSD_version >= 500043) 747 # include <sys/mutex.h> 748 # define KMUTEX_T struct mtx 749 # define KRWLOCK_T struct mtx 750 # endif 751 752 # ifdef _KERNEL 753 # define GETKTIME(x) microtime((struct timeval *)x) 754 755 # if (__FreeBSD_version >= 500002) 756 # include <netinet/in_systm.h> 757 # include <netinet/ip.h> 758 # include <machine/in_cksum.h> 759 # endif 760 761 # if (__FreeBSD_version >= 500043) 762 # define USE_MUTEXES 763 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk) 764 # define READ_ENTER(x) mtx_lock(&(x)->ipf_lk) 765 # define WRITE_ENTER(x) mtx_lock(&(x)->ipf_lk) 766 # define MUTEX_DOWNGRADE(x) ; 767 # define RWLOCK_INIT(x, y) mtx_init(&(x)->ipf_lk, (y), NULL, \ 768 MTX_DEF) 769 # define RW_DESTROY(x) mtx_destroy(&(x)->ipf_lk) 770 # define RWLOCK_EXIT(x) mtx_unlock(&(x)->ipf_lk) 771 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk) 772 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\ 773 MTX_DEF) 774 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk) 775 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 776 # include <machine/atomic.h> 777 # define ATOMIC_INC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)++; \ 778 mtx_unlock(&ipf_rw.ipf_lk); } 779 # define ATOMIC_DEC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)--; \ 780 mtx_unlock(&ipf_rw.ipf_lk); } 781 # if 0 782 # define ATOMIC_INCL(x) atomic_add_long(x, 1) 783 # define ATOMIC_INC64(x) atomic_add_(x, 1) 784 # define ATOMIC_INC32(x) atomic_add_(x, 1) 785 # define ATOMIC_INC16(x) atomic_add_short(x, 1) 786 # define ATOMIC_DECL(x) atomic_subtrct_long(x, -1) 787 # define ATOMIC_DEC64(x) atomic_subtrct_(x, -1) 788 # define ATOMIC_DEC32(x) atomic_subtrct_(x, -1) 789 # define ATOMIC_DEC16(x) atomic_subtrct_short(x, -1) 790 # endif 791 # define SPL_X(x) ; 792 # define SPL_NET(x) ; 793 # define SPL_IMP(x) ; 794 extern int in_cksum __P((struct mbuf *, int)); 795 # endif /* __FreeBSD_version >= 500043 */ 796 # define MSGDSIZE(x) (x)->m_pkthdr.len 797 # define M_LEN(x) (x)->m_len 798 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 799 # if (__FreeBSD_version >= 500043) 800 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index) & 7) 801 # else 802 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 803 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 804 # endif 805 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 806 typedef struct mbuf mb_t; 807 # endif /* _KERNEL */ 808 809 # if __FreeBSD__ < 3 810 # include <machine/spl.h> 811 # else 812 # if __FreeBSD__ == 3 813 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL) 814 # define ACTUALLY_LKM_NOT_KERNEL 815 # endif 816 # endif 817 # endif 818 819 typedef int minor_t; 820 typedef u_int32_t u_32_t; 821 # define U_32_T 1 822 823 # define OS_RECOGNISED 1 824 #endif /* __FreeBSD__ */ 825 826 827 /* ----------------------------------------------------------------------- */ 828 /* O P E N B S D */ 829 /* ----------------------------------------------------------------------- */ 830 #ifdef __OpenBSD__ 831 # ifdef INET6 832 # define USE_INET6 833 # endif 834 835 # ifdef _KERNEL 836 # define GETKTIME(x) microtime((struct timeval *)x) 837 # define MSGDSIZE(x) (x)->m_pkthdr.len 838 # define M_LEN(x) (x)->m_len 839 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 840 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 841 typedef struct mbuf mb_t; 842 # endif /* _KERNEL */ 843 # if (OpenBSD >= 199603) 844 # define IFNAME(x, b) ((struct ifnet *)x)->if_xname 845 # define COPYIFNAME(x, b) \ 846 strncpy(b, ((struct ifnet *)x)->if_xname, \ 847 LIFNAMSIZ) 848 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7) 849 # else 850 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 851 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 852 # endif 853 854 typedef int minor_t; 855 typedef u_int32_t u_32_t; 856 # define U_32_T 1 857 858 # define OS_RECOGNISED 1 859 #endif /* __OpenBSD__ */ 860 861 862 /* ----------------------------------------------------------------------- */ 863 /* B S D O S */ 864 /* ----------------------------------------------------------------------- */ 865 #ifdef _BSDI_VERSION 866 # ifdef INET6 867 # define USE_INET6 868 # endif 869 870 # ifdef _KERNEL 871 # define GETKTIME(x) microtime((struct timeval *)x) 872 # define MSGDSIZE(x) (x)->m_pkthdr.len 873 # define M_LEN(x) (x)->m_len 874 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 875 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 876 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 877 typedef struct mbuf mb_t; 878 # endif /* _KERNEL */ 879 880 typedef u_int32_t u_32_t; 881 # define U_32_T 1 882 883 #endif /* _BSDI_VERSION */ 884 885 886 /* ----------------------------------------------------------------------- */ 887 /* S U N O S 4 */ 888 /* ----------------------------------------------------------------------- */ 889 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */ 890 # ifdef _KERNEL 891 # include <sys/kmem_alloc.h> 892 # define GETKTIME(x) uniqtime((struct timeval *)x) 893 # define MSGDSIZE(x) mbufchainlen(x) 894 # define M_LEN(x) (x)->m_len 895 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 896 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 897 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 898 # define GETIFP(n, v) ifunit(n, IFNAMSIZ) 899 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 900 # define KFREES(x,s) kmem_free((char *)(x), (s)) 901 # define SLEEP(id, n) sleep((id), PZERO+1) 902 # define WAKEUP(id) wakeup(id) 903 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 904 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 905 906 extern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 907 extern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 908 909 typedef struct mbuf mb_t; 910 # endif 911 912 typedef int minor_t; 913 typedef unsigned int u_32_t; 914 # define U_32_T 1 915 916 # define OS_RECOGNISED 1 917 918 #endif /* SunOS 4 */ 919 920 921 #ifndef OS_RECOGNISED 922 #error ip_compat.h does not recognise this platform/OS. 923 #endif 924 925 /* ----------------------------------------------------------------------- */ 926 /* G E N E R I C */ 927 /* ----------------------------------------------------------------------- */ 928 #ifndef OS_RECOGNISED 929 #endif 930 931 /* 932 * Userland locking primitives 933 */ 934 typedef struct { 935 u_int eMm_magic; 936 int eMm_held; 937 char *eMm_owner; 938 int eMm_heldat; 939 char *eMm_heldin; 940 } eMmutex_t; 941 942 typedef struct { 943 u_int eMrw_magic; 944 int eMrw_read; 945 int eMrw_write; 946 char *eMrw_owner; 947 int eMrw_heldat; 948 char *eMrw_heldin; 949 } eMrwlock_t; 950 951 typedef union { 952 #ifdef KMUTEX_T 953 KMUTEX_T ipf_lk; 954 #endif 955 eMmutex_t ipf_emu; 956 } ipfmutex_t; 957 958 typedef union { 959 #ifdef KRWLOCK_T 960 KRWLOCK_T ipf_lk; 961 #endif 962 eMrwlock_t ipf_emu; 963 } ipfrwlock_t; 964 965 #ifndef _KERNEL 966 typedef struct mb_s { 967 struct mb_s *mb_next; 968 int mb_len; 969 u_long mb_buf[2048]; 970 } mb_t; 971 # define MSGDSIZE(x) (x)->mb_len /* XXX - from ipt.c */ 972 # define M_LEN(x) (x)->mb_len 973 # define M_DUPLICATE(x) (x) 974 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL) 975 # define MTOD(m, t) (t)((m)->mb_buf) 976 # define FREE_MB_T(x) 977 # ifndef CACHE_HASH 978 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 979 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 980 # endif 981 982 # if 0 983 # define KMUTEX_T eMmutex_t 984 # endif 985 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu) 986 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \ 987 __FILE__, __LINE__) 988 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu) 989 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y) 990 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 991 992 # if 0 993 # define KRWLOCK_T eMrwlock_t 994 # endif 995 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \ 996 __FILE__, __LINE__) 997 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \ 998 __FILE__, __LINE__) 999 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y) 1000 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu) 1001 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu) 1002 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \ 1003 __FILE__, \ 1004 __LINE__) 1005 1006 # define USE_MUTEXES 1 1007 1008 extern void eMmutex_destroy __P((eMmutex_t *)); 1009 extern void eMmutex_enter __P((eMmutex_t *, char *, int)); 1010 extern void eMmutex_exit __P((eMmutex_t *)); 1011 extern void eMmutex_init __P((eMmutex_t *, char *)); 1012 extern void eMrwlock_destroy __P((eMrwlock_t *)); 1013 extern void eMrwlock_exit __P((eMrwlock_t *)); 1014 extern void eMrwlock_init __P((eMrwlock_t *, char *)); 1015 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int)); 1016 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int)); 1017 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int)); 1018 1019 #endif 1020 1021 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8) 1022 1023 # ifndef IP_OFFMASK 1024 # define IP_OFFMASK 0x1fff 1025 # endif 1026 1027 #if BSD > 199306 1028 # define USE_QUAD_T 1029 # define U_QUAD_T u_quad_t 1030 # define QUAD_T quad_t 1031 #else /* BSD > 199306 */ 1032 # define U_QUAD_T u_long 1033 # define QUAD_T long 1034 #endif /* BSD > 199306 */ 1035 1036 1037 #ifdef USE_INET6 1038 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \ 1039 defined(__osf__) 1040 # include <netinet/ip6.h> 1041 # include <netinet/icmp6.h> 1042 # if defined(_KERNEL) && !defined(__osf__) 1043 # include <netinet6/ip6_var.h> 1044 # endif 1045 typedef struct ip6_hdr ip6_t; 1046 # endif 1047 #endif 1048 1049 #ifndef MAX 1050 # define MAX(a,b) (((a) > (b)) ? (a) : (b)) 1051 #endif 1052 1053 #if defined(_KERNEL) 1054 # ifdef MENTAT 1055 # define COPYDATA mb_copydata 1056 # define COPYBACK mb_copyback 1057 # else 1058 # define COPYDATA m_copydata 1059 # define COPYBACK m_copyback 1060 # endif 1061 #else 1062 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \ 1063 (b), (l)) 1064 # define COPYBACK(m, o, l, b) bcopy((b), \ 1065 MTOD((mb_t *)m, char *) + (o), \ 1066 (l)) 1067 #endif 1068 1069 #ifdef _KERNEL 1070 # if (BSD >= 199306) || defined(__FreeBSD__) 1071 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \ 1072 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \ 1073 defined(_BSDI_VERSION) 1074 # include <vm/vm.h> 1075 # endif 1076 # if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \ 1077 (__FreeBSD_version >= 300000)) 1078 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \ 1079 (defined(OpenBSD) && (OpenBSD >= 200111)) 1080 # include <uvm/uvm_extern.h> 1081 # else 1082 # include <vm/vm_extern.h> 1083 extern vm_map_t kmem_map; 1084 # endif 1085 # include <sys/proc.h> 1086 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */ 1087 # include <vm/vm_kern.h> 1088 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */ 1089 1090 # ifdef IPFILTER_M_IPFILTER 1091 # include <sys/malloc.h> 1092 MALLOC_DECLARE(M_IPFILTER); 1093 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_IPFILTER, \ 1094 M_NOWAIT) 1095 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_IPFILTER, \ 1096 M_NOWAIT) 1097 # define KFREE(x) FREE((x), M_IPFILTER) 1098 # define KFREES(x,s) FREE((x), M_IPFILTER) 1099 # else /* IPFILTER_M_IPFILTER */ 1100 # ifdef M_PFIL 1101 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT) 1102 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT) 1103 # define KFREE(x) FREE((x), M_PFIL) 1104 # define KFREES(x,s) FREE((x), M_PFIL) 1105 # else /* M_PFIL */ 1106 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT) 1107 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT) 1108 # define KFREE(x) FREE((x), M_TEMP) 1109 # define KFREES(x,s) FREE((x), M_TEMP) 1110 # endif /* M_PFIL */ 1111 # endif /* IPFILTER_M_IPFILTER */ 1112 # define UIOMOVE(a,b,c,d) uiomove(a,b,d) 1113 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0) 1114 # define WAKEUP(id) wakeup(id) 1115 # define GETIFP(n, v) ifunit(n) 1116 # endif /* (Free)BSD */ 1117 1118 # if !defined(USE_MUTEXES) 1119 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \ 1120 (defined(OpenBSD) && (OpenBSD >= 200006)) 1121 # define SPL_NET(x) x = splsoftnet() 1122 # else 1123 # define SPL_IMP(x) x = splimp() 1124 # define SPL_NET(x) x = splnet() 1125 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */ 1126 # define SPL_X(x) (void) splx(x) 1127 # endif /* !USE_MUTEXES */ 1128 1129 # ifndef FREE_MB_T 1130 # define FREE_MB_T(m) m_freem(m) 1131 # endif 1132 1133 # ifndef MTOD 1134 # define MTOD(m,t) mtod(m,t) 1135 # endif 1136 1137 # ifndef COPYIN 1138 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1139 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1140 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1141 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1142 # endif 1143 1144 # ifndef KMALLOC 1145 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \ 1146 KMEM_NOSLEEP) 1147 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP) 1148 # endif 1149 1150 # ifndef GET_MINOR 1151 # define GET_MINOR(x) minor(x) 1152 # endif 1153 # define PANIC(x,y) /* if (x) panic y */ 1154 #else /* _KERNEL */ 1155 # define SLEEP(x,y) 1; 1156 # define WAKEUP(x) ; 1157 # define IPF_PANIC(x,y) ; 1158 # define PANIC(x,y) ; 1159 # define SPL_NET(x) ; 1160 # define SPL_IMP(x) ; 1161 # define SPL_X(x) ; 1162 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a)) 1163 # define KMALLOCS(a,b,c) (a) = (b)malloc(c) 1164 # define KFREE(x) free(x) 1165 # define KFREES(x,s) free(x) 1166 # define GETIFP(x, v) get_unit(x,v) 1167 # define COPYIN(a,b,c) (bcopy((a), (b), (c)), 0) 1168 # define COPYOUT(a,b,c) (bcopy((a), (b), (c)), 0) 1169 # define BCOPYIN(a,b,c) (bcopy((a), (b), (c)), 0) 1170 # define BCOPYOUT(a,b,c) (bcopy((a), (b), (c)), 0) 1171 # define UIOMOVE(a,b,c,d) ipfuiomove(a,b,c,d) 1172 extern void m_copydata __P((mb_t *, int, int, caddr_t)); 1173 extern int ipfuiomove __P((caddr_t, int, int, struct uio *)); 1174 #endif /* _KERNEL */ 1175 1176 #ifndef IFNAME 1177 # define IFNAME(x) ((struct ifnet *)x)->if_name 1178 #endif 1179 #ifndef COPYIFNAME 1180 # define NEED_FRGETIFNAME 1181 extern char *fr_getifname __P((struct ifnet *, char *)); 1182 # define COPYIFNAME(x, b) \ 1183 fr_getifname((struct ifnet *)x, b) 1184 #endif 1185 1186 1187 #if !defined(USE_MUTEXES) 1188 # define USE_SPL 1 1189 # undef RW_DESTROY 1190 # undef MUTEX_INIT 1191 # undef MUTEX_NUKE 1192 # undef MUTEX_DESTROY 1193 # define MUTEX_ENTER(x) ; 1194 # define READ_ENTER(x) ; 1195 # define WRITE_ENTER(x) ; 1196 # define MUTEX_DOWNGRADE(x) ; 1197 # define RWLOCK_INIT(x, y) ; 1198 # define RWLOCK_EXIT(x) ; 1199 # define RW_DESTROY(x) ; 1200 # define MUTEX_EXIT(x) ; 1201 # define MUTEX_INIT(x,y) ; 1202 # define MUTEX_DESTROY(x) ; 1203 # define MUTEX_NUKE(x) ; 1204 #endif /* !USE_MUTEXES */ 1205 #ifndef ATOMIC_INC 1206 # define ATOMIC_INC(x) (x)++ 1207 # define ATOMIC_DEC(x) (x)-- 1208 #endif 1209 1210 /* 1211 * Build some macros and #defines to enable the same code to compile anywhere 1212 * Well, that's the idea, anyway :-) 1213 */ 1214 #ifndef ATOMIC_INCL 1215 # define ATOMIC_INCL ATOMIC_INC 1216 # define ATOMIC_INC64 ATOMIC_INC 1217 # define ATOMIC_INC32 ATOMIC_INC 1218 # define ATOMIC_INC16 ATOMIC_INC 1219 # define ATOMIC_DECL ATOMIC_DEC 1220 # define ATOMIC_DEC64 ATOMIC_DEC 1221 # define ATOMIC_DEC32 ATOMIC_DEC 1222 # define ATOMIC_DEC16 ATOMIC_DEC 1223 #endif 1224 1225 typedef struct tcphdr tcphdr_t; 1226 typedef struct udphdr udphdr_t; 1227 typedef struct icmp icmphdr_t; 1228 typedef struct ip ip_t; 1229 typedef struct ether_header ether_header_t; 1230 typedef struct tcpiphdr tcpiphdr_t; 1231 1232 #ifndef FR_GROUPLEN 1233 # define FR_GROUPLEN 16 1234 #endif 1235 1236 #ifdef offsetof 1237 # undef offsetof 1238 #endif 1239 #ifndef offsetof 1240 # define offsetof(t,m) (int)((&((t *)0L)->m)) 1241 #endif 1242 1243 #ifndef IP_V 1244 # define IP_V(x) (x)->ip_v 1245 #endif 1246 #ifndef IP_V_A 1247 # define IP_V_A(x,y) (x)->ip_v = (y) 1248 #endif 1249 #ifndef IP_HL 1250 # define IP_HL(x) (x)->ip_hl 1251 #endif 1252 #ifndef IP_HL_A 1253 # define IP_HL_A(x,y) (x)->ip_hl = (y) 1254 #endif 1255 #ifndef TCP_OFF 1256 # define TCP_OFF(x) (x)->th_off 1257 #endif 1258 #ifndef TCP_OFF_A 1259 # define TCP_OFF_A(x,y) (x)->th_off = (y) 1260 #endif 1261 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h))) 1262 1263 1264 /* 1265 * XXX - This is one of those *awful* hacks which nobody likes 1266 */ 1267 #ifdef ultrix 1268 #define A_A 1269 #else 1270 #define A_A & 1271 #endif 1272 1273 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\ 1274 TH_ECN|TH_CWR) 1275 1276 #if (BSD >= 199306) && !defined(m_act) 1277 # define m_act m_nextpkt 1278 #endif 1279 1280 /* 1281 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108. 1282 * 1283 * Basic Option 1284 * 1285 * 00000001 - (Reserved 4) 1286 * 00111101 - Top Secret 1287 * 01011010 - Secret 1288 * 10010110 - Confidential 1289 * 01100110 - (Reserved 3) 1290 * 11001100 - (Reserved 2) 1291 * 10101011 - Unclassified 1292 * 11110001 - (Reserved 1) 1293 */ 1294 #define IPSO_CLASS_RES4 0x01 1295 #define IPSO_CLASS_TOPS 0x3d 1296 #define IPSO_CLASS_SECR 0x5a 1297 #define IPSO_CLASS_CONF 0x96 1298 #define IPSO_CLASS_RES3 0x66 1299 #define IPSO_CLASS_RES2 0xcc 1300 #define IPSO_CLASS_UNCL 0xab 1301 #define IPSO_CLASS_RES1 0xf1 1302 1303 #define IPSO_AUTH_GENSER 0x80 1304 #define IPSO_AUTH_ESI 0x40 1305 #define IPSO_AUTH_SCI 0x20 1306 #define IPSO_AUTH_NSA 0x10 1307 #define IPSO_AUTH_DOE 0x08 1308 #define IPSO_AUTH_UN 0x06 1309 #define IPSO_AUTH_FTE 0x01 1310 1311 /* 1312 * IP option #defines 1313 */ 1314 #undef IPOPT_RR 1315 #define IPOPT_RR 7 1316 #define IPOPT_ZSU 10 /* ZSU */ 1317 #define IPOPT_MTUP 11 /* MTUP */ 1318 #define IPOPT_MTUR 12 /* MTUR */ 1319 #define IPOPT_ENCODE 15 /* ENCODE */ 1320 #undef IPOPT_TS 1321 #define IPOPT_TS 68 1322 #define IPOPT_TR 82 /* TR */ 1323 #undef IPOPT_SECURITY 1324 #define IPOPT_SECURITY 130 1325 #undef IPOPT_LSRR 1326 #define IPOPT_LSRR 131 1327 #define IPOPT_E_SEC 133 /* E-SEC */ 1328 #undef IPOPT_CIPSO 1329 #define IPOPT_CIPSO 134 /* CIPSO */ 1330 #undef IPOPT_SATID 1331 #define IPOPT_SATID 136 1332 #ifndef IPOPT_SID 1333 # define IPOPT_SID IPOPT_SATID 1334 #endif 1335 #undef IPOPT_SSRR 1336 #define IPOPT_SSRR 137 1337 #define IPOPT_ADDEXT 147 /* ADDEXT */ 1338 #define IPOPT_VISA 142 /* VISA */ 1339 #define IPOPT_IMITD 144 /* IMITD */ 1340 #define IPOPT_EIP 145 /* EIP */ 1341 #define IPOPT_RTRALRT 148 /* RTRALRT */ 1342 #define IPOPT_SDB 149 1343 #define IPOPT_NSAPA 150 1344 #define IPOPT_DPS 151 1345 #define IPOPT_UMP 152 1346 #define IPOPT_FINN 205 /* FINN */ 1347 1348 #ifndef TCPOPT_EOL 1349 # define TCPOPT_EOL 0 1350 #endif 1351 #ifndef TCPOPT_NOP 1352 # define TCPOPT_NOP 1 1353 #endif 1354 #ifndef TCPOPT_MAXSEG 1355 # define TCPOPT_MAXSEG 2 1356 #endif 1357 #ifndef TCPOLEN_MAXSEG 1358 # define TCPOLEN_MAXSEG 4 1359 #endif 1360 #ifndef TCPOPT_WINDOW 1361 # define TCPOPT_WINDOW 3 1362 #endif 1363 #ifndef TCPOLEN_WINDOW 1364 # define TCPOLEN_WINDOW 3 1365 #endif 1366 #ifndef TCPOPT_SACK_PERMITTED 1367 # define TCPOPT_SACK_PERMITTED 4 1368 #endif 1369 #ifndef TCPOLEN_SACK_PERMITTED 1370 # define TCPOLEN_SACK_PERMITTED 2 1371 #endif 1372 #ifndef TCPOPT_SACK 1373 # define TCPOPT_SACK 5 1374 #endif 1375 #ifndef TCPOPT_TIMESTAMP 1376 # define TCPOPT_TIMESTAMP 8 1377 #endif 1378 1379 #ifndef ICMP_MINLEN 1380 # define ICMP_MINLEN 8 1381 #endif 1382 #ifndef ICMP_ECHOREPLY 1383 # define ICMP_ECHOREPLY 0 1384 #endif 1385 #ifndef ICMP_UNREACH 1386 # define ICMP_UNREACH 3 1387 #endif 1388 #ifndef ICMP_UNREACH_NET 1389 # define ICMP_UNREACH_NET 0 1390 #endif 1391 #ifndef ICMP_UNREACH_HOST 1392 # define ICMP_UNREACH_HOST 1 1393 #endif 1394 #ifndef ICMP_UNREACH_PROTOCOL 1395 # define ICMP_UNREACH_PROTOCOL 2 1396 #endif 1397 #ifndef ICMP_UNREACH_PORT 1398 # define ICMP_UNREACH_PORT 3 1399 #endif 1400 #ifndef ICMP_UNREACH_NEEDFRAG 1401 # define ICMP_UNREACH_NEEDFRAG 4 1402 #endif 1403 #ifndef ICMP_UNREACH_SRCFAIL 1404 # define ICMP_UNREACH_SRCFAIL 5 1405 #endif 1406 #ifndef ICMP_UNREACH_NET_UNKNOWN 1407 # define ICMP_UNREACH_NET_UNKNOWN 6 1408 #endif 1409 #ifndef ICMP_UNREACH_HOST_UNKNOWN 1410 # define ICMP_UNREACH_HOST_UNKNOWN 7 1411 #endif 1412 #ifndef ICMP_UNREACH_ISOLATED 1413 # define ICMP_UNREACH_ISOLATED 8 1414 #endif 1415 #ifndef ICMP_UNREACH_NET_PROHIB 1416 # define ICMP_UNREACH_NET_PROHIB 9 1417 #endif 1418 #ifndef ICMP_UNREACH_HOST_PROHIB 1419 # define ICMP_UNREACH_HOST_PROHIB 10 1420 #endif 1421 #ifndef ICMP_UNREACH_TOSNET 1422 # define ICMP_UNREACH_TOSNET 11 1423 #endif 1424 #ifndef ICMP_UNREACH_TOSHOST 1425 # define ICMP_UNREACH_TOSHOST 12 1426 #endif 1427 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT 1428 # define ICMP_UNREACH_ADMIN_PROHIBIT 13 1429 #endif 1430 #ifndef ICMP_UNREACH_FILTER 1431 # define ICMP_UNREACH_FILTER 13 1432 #endif 1433 #ifndef ICMP_UNREACH_HOST_PRECEDENCE 1434 # define ICMP_UNREACH_HOST_PRECEDENCE 14 1435 #endif 1436 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF 1437 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 1438 #endif 1439 #ifndef ICMP_SOURCEQUENCH 1440 # define ICMP_SOURCEQUENCH 4 1441 #endif 1442 #ifndef ICMP_REDIRECT_NET 1443 # define ICMP_REDIRECT_NET 0 1444 #endif 1445 #ifndef ICMP_REDIRECT_HOST 1446 # define ICMP_REDIRECT_HOST 1 1447 #endif 1448 #ifndef ICMP_REDIRECT_TOSNET 1449 # define ICMP_REDIRECT_TOSNET 2 1450 #endif 1451 #ifndef ICMP_REDIRECT_TOSHOST 1452 # define ICMP_REDIRECT_TOSHOST 3 1453 #endif 1454 #ifndef ICMP_ALTHOSTADDR 1455 # define ICMP_ALTHOSTADDR 6 1456 #endif 1457 #ifndef ICMP_TIMXCEED 1458 # define ICMP_TIMXCEED 11 1459 #endif 1460 #ifndef ICMP_TIMXCEED_INTRANS 1461 # define ICMP_TIMXCEED_INTRANS 0 1462 #endif 1463 #ifndef ICMP_TIMXCEED_REASS 1464 # define ICMP_TIMXCEED_REASS 1 1465 #endif 1466 #ifndef ICMP_PARAMPROB 1467 # define ICMP_PARAMPROB 12 1468 #endif 1469 #ifndef ICMP_PARAMPROB_ERRATPTR 1470 # define ICMP_PARAMPROB_ERRATPTR 0 1471 #endif 1472 #ifndef ICMP_PARAMPROB_OPTABSENT 1473 # define ICMP_PARAMPROB_OPTABSENT 1 1474 #endif 1475 #ifndef ICMP_PARAMPROB_LENGTH 1476 # define ICMP_PARAMPROB_LENGTH 2 1477 #endif 1478 #ifndef ICMP_TSTAMP 1479 # define ICMP_TSTAMP 13 1480 #endif 1481 #ifndef ICMP_TSTAMPREPLY 1482 # define ICMP_TSTAMPREPLY 14 1483 #endif 1484 #ifndef ICMP_IREQ 1485 # define ICMP_IREQ 15 1486 #endif 1487 #ifndef ICMP_IREQREPLY 1488 # define ICMP_IREQREPLY 16 1489 #endif 1490 #ifndef ICMP_MASKREQ 1491 # define ICMP_MASKREQ 17 1492 #endif 1493 #ifndef ICMP_MASKREPLY 1494 # define ICMP_MASKREPLY 18 1495 #endif 1496 #ifndef ICMP_TRACEROUTE 1497 # define ICMP_TRACEROUTE 30 1498 #endif 1499 #ifndef ICMP_DATACONVERR 1500 # define ICMP_DATACONVERR 31 1501 #endif 1502 #ifndef ICMP_MOBILE_REDIRECT 1503 # define ICMP_MOBILE_REDIRECT 32 1504 #endif 1505 #ifndef ICMP_IPV6_WHEREAREYOU 1506 # define ICMP_IPV6_WHEREAREYOU 33 1507 #endif 1508 #ifndef ICMP_IPV6_IAMHERE 1509 # define ICMP_IPV6_IAMHERE 34 1510 #endif 1511 #ifndef ICMP_MOBILE_REGREQUEST 1512 # define ICMP_MOBILE_REGREQUEST 35 1513 #endif 1514 #ifndef ICMP_MOBILE_REGREPLY 1515 # define ICMP_MOBILE_REGREPLY 36 1516 #endif 1517 #ifndef ICMP_SKIP 1518 # define ICMP_SKIP 39 1519 #endif 1520 #ifndef ICMP_PHOTURIS 1521 # define ICMP_PHOTURIS 40 1522 #endif 1523 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX 1524 # define ICMP_PHOTURIS_UNKNOWN_INDEX 1 1525 #endif 1526 #ifndef ICMP_PHOTURIS_AUTH_FAILED 1527 # define ICMP_PHOTURIS_AUTH_FAILED 2 1528 #endif 1529 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED 1530 # define ICMP_PHOTURIS_DECRYPT_FAILED 3 1531 #endif 1532 #ifndef IPVERSION 1533 # define IPVERSION 4 1534 #endif 1535 #ifndef IPOPT_MINOFF 1536 # define IPOPT_MINOFF 4 1537 #endif 1538 #ifndef IPOPT_COPIED 1539 # define IPOPT_COPIED(x) ((x)&0x80) 1540 #endif 1541 #ifndef IPOPT_EOL 1542 # define IPOPT_EOL 0 1543 #endif 1544 #ifndef IPOPT_NOP 1545 # define IPOPT_NOP 1 1546 #endif 1547 #ifndef IP_MF 1548 # define IP_MF ((u_short)0x2000) 1549 #endif 1550 #ifndef ETHERTYPE_IP 1551 # define ETHERTYPE_IP ((u_short)0x0800) 1552 #endif 1553 #ifndef TH_FIN 1554 # define TH_FIN 0x01 1555 #endif 1556 #ifndef TH_SYN 1557 # define TH_SYN 0x02 1558 #endif 1559 #ifndef TH_RST 1560 # define TH_RST 0x04 1561 #endif 1562 #ifndef TH_PUSH 1563 # define TH_PUSH 0x08 1564 #endif 1565 #ifndef TH_ACK 1566 # define TH_ACK 0x10 1567 #endif 1568 #ifndef TH_URG 1569 # define TH_URG 0x20 1570 #endif 1571 #undef TH_ACKMASK 1572 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK) 1573 1574 #ifndef IPOPT_EOL 1575 # define IPOPT_EOL 0 1576 #endif 1577 #ifndef IPOPT_NOP 1578 # define IPOPT_NOP 1 1579 #endif 1580 #ifndef IPOPT_RR 1581 # define IPOPT_RR 7 1582 #endif 1583 #ifndef IPOPT_TS 1584 # define IPOPT_TS 68 1585 #endif 1586 #ifndef IPOPT_SECURITY 1587 # define IPOPT_SECURITY 130 1588 #endif 1589 #ifndef IPOPT_LSRR 1590 # define IPOPT_LSRR 131 1591 #endif 1592 #ifndef IPOPT_SATID 1593 # define IPOPT_SATID 136 1594 #endif 1595 #ifndef IPOPT_SSRR 1596 # define IPOPT_SSRR 137 1597 #endif 1598 #ifndef IPOPT_SECUR_UNCLASS 1599 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000) 1600 #endif 1601 #ifndef IPOPT_SECUR_CONFID 1602 # define IPOPT_SECUR_CONFID ((u_short)0xf135) 1603 #endif 1604 #ifndef IPOPT_SECUR_EFTO 1605 # define IPOPT_SECUR_EFTO ((u_short)0x789a) 1606 #endif 1607 #ifndef IPOPT_SECUR_MMMM 1608 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d) 1609 #endif 1610 #ifndef IPOPT_SECUR_RESTR 1611 # define IPOPT_SECUR_RESTR ((u_short)0xaf13) 1612 #endif 1613 #ifndef IPOPT_SECUR_SECRET 1614 # define IPOPT_SECUR_SECRET ((u_short)0xd788) 1615 #endif 1616 #ifndef IPOPT_SECUR_TOPSECRET 1617 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) 1618 #endif 1619 #ifndef IPOPT_OLEN 1620 # define IPOPT_OLEN 1 1621 #endif 1622 #ifndef IPPROTO_HOPOPTS 1623 # define IPPROTO_HOPOPTS 0 1624 #endif 1625 #ifndef IPPROTO_ENCAP 1626 # define IPPROTO_ENCAP 4 1627 #endif 1628 #ifndef IPPROTO_IPV6 1629 # define IPPROTO_IPV6 41 1630 #endif 1631 #ifndef IPPROTO_ROUTING 1632 # define IPPROTO_ROUTING 43 1633 #endif 1634 #ifndef IPPROTO_FRAGMENT 1635 # define IPPROTO_FRAGMENT 44 1636 #endif 1637 #ifndef IPPROTO_GRE 1638 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */ 1639 #endif 1640 #ifndef IPPROTO_ESP 1641 # define IPPROTO_ESP 50 1642 #endif 1643 #ifndef IPPROTO_AH 1644 # define IPPROTO_AH 51 1645 #endif 1646 #ifndef IPPROTO_ICMPV6 1647 # define IPPROTO_ICMPV6 58 1648 #endif 1649 #ifndef IPPROTO_NONE 1650 # define IPPROTO_NONE 59 1651 #endif 1652 #ifndef IPPROTO_DSTOPTS 1653 # define IPPROTO_DSTOPTS 60 1654 #endif 1655 #ifndef IPPROTO_FRAGMENT 1656 # define IPPROTO_FRAGMENT 44 1657 #endif 1658 #ifndef ICMP_ROUTERADVERT 1659 # define ICMP_ROUTERADVERT 9 1660 #endif 1661 #ifndef ICMP_ROUTERSOLICIT 1662 # define ICMP_ROUTERSOLICIT 10 1663 #endif 1664 #ifndef ICMP6_DST_UNREACH 1665 # define ICMP6_DST_UNREACH 1 1666 #endif 1667 #ifndef ICMP6_PACKET_TOO_BIG 1668 # define ICMP6_PACKET_TOO_BIG 2 1669 #endif 1670 #ifndef ICMP6_TIME_EXCEEDED 1671 # define ICMP6_TIME_EXCEEDED 3 1672 #endif 1673 #ifndef ICMP6_PARAM_PROB 1674 # define ICMP6_PARAM_PROB 4 1675 #endif 1676 1677 #ifndef ICMP6_ECHO_REQUEST 1678 # define ICMP6_ECHO_REQUEST 128 1679 #endif 1680 #ifndef ICMP6_ECHO_REPLY 1681 # define ICMP6_ECHO_REPLY 129 1682 #endif 1683 #ifndef ICMP6_MEMBERSHIP_QUERY 1684 # define ICMP6_MEMBERSHIP_QUERY 130 1685 #endif 1686 #ifndef MLD6_LISTENER_QUERY 1687 # define MLD6_LISTENER_QUERY 130 1688 #endif 1689 #ifndef ICMP6_MEMBERSHIP_REPORT 1690 # define ICMP6_MEMBERSHIP_REPORT 131 1691 #endif 1692 #ifndef MLD6_LISTENER_REPORT 1693 # define MLD6_LISTENER_REPORT 131 1694 #endif 1695 #ifndef ICMP6_MEMBERSHIP_REDUCTION 1696 # define ICMP6_MEMBERSHIP_REDUCTION 132 1697 #endif 1698 #ifndef MLD6_LISTENER_DONE 1699 # define MLD6_LISTENER_DONE 132 1700 #endif 1701 #ifndef ND_ROUTER_SOLICIT 1702 # define ND_ROUTER_SOLICIT 133 1703 #endif 1704 #ifndef ND_ROUTER_ADVERT 1705 # define ND_ROUTER_ADVERT 134 1706 #endif 1707 #ifndef ND_NEIGHBOR_SOLICIT 1708 # define ND_NEIGHBOR_SOLICIT 135 1709 #endif 1710 #ifndef ND_NEIGHBOR_ADVERT 1711 # define ND_NEIGHBOR_ADVERT 136 1712 #endif 1713 #ifndef ND_REDIRECT 1714 # define ND_REDIRECT 137 1715 #endif 1716 #ifndef ICMP6_ROUTER_RENUMBERING 1717 # define ICMP6_ROUTER_RENUMBERING 138 1718 #endif 1719 #ifndef ICMP6_WRUREQUEST 1720 # define ICMP6_WRUREQUEST 139 1721 #endif 1722 #ifndef ICMP6_WRUREPLY 1723 # define ICMP6_WRUREPLY 140 1724 #endif 1725 #ifndef ICMP6_FQDN_QUERY 1726 # define ICMP6_FQDN_QUERY 139 1727 #endif 1728 #ifndef ICMP6_FQDN_REPLY 1729 # define ICMP6_FQDN_REPLY 140 1730 #endif 1731 #ifndef ICMP6_NI_QUERY 1732 # define ICMP6_NI_QUERY 139 1733 #endif 1734 #ifndef ICMP6_NI_REPLY 1735 # define ICMP6_NI_REPLY 140 1736 #endif 1737 #ifndef MLD6_MTRACE_RESP 1738 # define MLD6_MTRACE_RESP 200 1739 #endif 1740 #ifndef MLD6_MTRACE 1741 # define MLD6_MTRACE 201 1742 #endif 1743 #ifndef ICMP6_HADISCOV_REQUEST 1744 # define ICMP6_HADISCOV_REQUEST 202 1745 #endif 1746 #ifndef ICMP6_HADISCOV_REPLY 1747 # define ICMP6_HADISCOV_REPLY 203 1748 #endif 1749 #ifndef ICMP6_MOBILEPREFIX_SOLICIT 1750 # define ICMP6_MOBILEPREFIX_SOLICIT 204 1751 #endif 1752 #ifndef ICMP6_MOBILEPREFIX_ADVERT 1753 # define ICMP6_MOBILEPREFIX_ADVERT 205 1754 #endif 1755 #ifndef ICMP6_MAXTYPE 1756 # define ICMP6_MAXTYPE 205 1757 #endif 1758 1759 #ifndef ICMP6_DST_UNREACH_NOROUTE 1760 # define ICMP6_DST_UNREACH_NOROUTE 0 1761 #endif 1762 #ifndef ICMP6_DST_UNREACH_ADMIN 1763 # define ICMP6_DST_UNREACH_ADMIN 1 1764 #endif 1765 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR 1766 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 1767 #endif 1768 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE 1769 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2 1770 #endif 1771 #ifndef ICMP6_DST_UNREACH_ADDR 1772 # define ICMP6_DST_UNREACH_ADDR 3 1773 #endif 1774 #ifndef ICMP6_DST_UNREACH_NOPORT 1775 # define ICMP6_DST_UNREACH_NOPORT 4 1776 #endif 1777 #ifndef ICMP6_TIME_EXCEED_TRANSIT 1778 # define ICMP6_TIME_EXCEED_TRANSIT 0 1779 #endif 1780 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY 1781 # define ICMP6_TIME_EXCEED_REASSEMBLY 1 1782 #endif 1783 1784 #ifndef ICMP6_NI_SUCCESS 1785 # define ICMP6_NI_SUCCESS 0 1786 #endif 1787 #ifndef ICMP6_NI_REFUSED 1788 # define ICMP6_NI_REFUSED 1 1789 #endif 1790 #ifndef ICMP6_NI_UNKNOWN 1791 # define ICMP6_NI_UNKNOWN 2 1792 #endif 1793 1794 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND 1795 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0 1796 #endif 1797 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT 1798 # define ICMP6_ROUTER_RENUMBERING_RESULT 1 1799 #endif 1800 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 1801 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255 1802 #endif 1803 1804 #ifndef ICMP6_PARAMPROB_HEADER 1805 # define ICMP6_PARAMPROB_HEADER 0 1806 #endif 1807 #ifndef ICMP6_PARAMPROB_NEXTHEADER 1808 # define ICMP6_PARAMPROB_NEXTHEADER 1 1809 #endif 1810 #ifndef ICMP6_PARAMPROB_OPTION 1811 # define ICMP6_PARAMPROB_OPTION 2 1812 #endif 1813 1814 #ifndef ICMP6_NI_SUBJ_IPV6 1815 # define ICMP6_NI_SUBJ_IPV6 0 1816 #endif 1817 #ifndef ICMP6_NI_SUBJ_FQDN 1818 # define ICMP6_NI_SUBJ_FQDN 1 1819 #endif 1820 #ifndef ICMP6_NI_SUBJ_IPV4 1821 # define ICMP6_NI_SUBJ_IPV4 2 1822 #endif 1823 1824 /* 1825 * ECN is a new addition to TCP - RFC 2481 1826 */ 1827 #ifndef TH_ECN 1828 # define TH_ECN 0x40 1829 #endif 1830 #ifndef TH_CWR 1831 # define TH_CWR 0x80 1832 #endif 1833 #define TH_ECNALL (TH_ECN|TH_CWR) 1834 1835 /* 1836 * TCP States 1837 */ 1838 #define IPF_TCPS_CLOSED 0 /* closed */ 1839 #define IPF_TCPS_LISTEN 1 /* listening for connection */ 1840 #define IPF_TCPS_SYN_SENT 2 /* active, have sent syn */ 1841 #define IPF_TCPS_SYN_RECEIVED 3 /* have send and received syn */ 1842 #define IPF_TCPS_HALF_ESTAB 4 /* for connections not fully "up" */ 1843 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */ 1844 #define IPF_TCPS_ESTABLISHED 5 /* established */ 1845 #define IPF_TCPS_CLOSE_WAIT 6 /* rcvd fin, waiting for close */ 1846 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */ 1847 #define IPF_TCPS_FIN_WAIT_1 7 /* have closed, sent fin */ 1848 #define IPF_TCPS_CLOSING 8 /* closed xchd FIN; await FIN ACK */ 1849 #define IPF_TCPS_LAST_ACK 9 /* had fin and close; await FIN ACK */ 1850 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */ 1851 #define IPF_TCPS_FIN_WAIT_2 10 /* have closed, fin is acked */ 1852 #define IPF_TCPS_TIME_WAIT 11 /* in 2*msl quiet wait after close */ 1853 #define IPF_TCP_NSTATES 12 1854 1855 #define TCP_MSL 120 1856 1857 #undef ICMP_MAX_UNREACH 1858 #define ICMP_MAX_UNREACH 14 1859 #undef ICMP_MAXTYPE 1860 #define ICMP_MAXTYPE 18 1861 1862 #ifndef IFNAMSIZ 1863 #define IFNAMSIZ 16 1864 #endif 1865 1866 #ifndef LOG_FTP 1867 # define LOG_FTP (11<<3) 1868 #endif 1869 #ifndef LOG_AUTHPRIV 1870 # define LOG_AUTHPRIV (10<<3) 1871 #endif 1872 #ifndef LOG_AUDIT 1873 # define LOG_AUDIT (13<<3) 1874 #endif 1875 #ifndef LOG_NTP 1876 # define LOG_NTP (12<<3) 1877 #endif 1878 #ifndef LOG_SECURITY 1879 # define LOG_SECURITY (13<<3) 1880 #endif 1881 #ifndef LOG_LFMT 1882 # define LOG_LFMT (14<<3) 1883 #endif 1884 #ifndef LOG_CONSOLE 1885 # define LOG_CONSOLE (14<<3) 1886 #endif 1887 1888 /* 1889 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data, 1890 * another IP header and then 64 bits of data, totalling 56. Of course, 1891 * the last 64 bits is dependant on that being available. 1892 */ 1893 #define ICMPERR_ICMPHLEN 8 1894 #define ICMPERR_IPICMPHLEN (20 + 8) 1895 #define ICMPERR_MINPKTLEN (20 + 8 + 20) 1896 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8) 1897 #define ICMP6ERR_MINPKTLEN (40 + 8) 1898 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40) 1899 1900 #ifdef __GNUC__ 1901 # define INLINE __inline__ 1902 #else 1903 # ifndef INLINE 1904 # define INLINE 1905 # endif 1906 #endif 1907 1908 #ifndef MIN 1909 # define MIN(a,b) (((a)<(b))?(a):(b)) 1910 #endif 1911 1912 #endif /* __IP_COMPAT_H__ */ 1913