ip_compat.h (139255) | ip_compat.h (145522) |
---|---|
1/* $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_compat.h 145522 2005-04-25 18:43:14Z darrenr $ */ 2 |
|
1/* | 3/* |
2 * Copyright (C) 1993-2001 by Darren Reed. | 4 * 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 | 5 * 6 * See the IPFILTER.LICENCE file for details on licencing. 7 * 8 * @(#)ip_compat.h 1.8 1/14/96 |
7 * $Id: ip_compat.h,v 2.26.2.9 2001/01/14 14:58:01 darrenr Exp $ 8 * $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_compat.h 139255 2004-12-24 09:14:26Z darrenr $ | 9 * $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_compat.h 145522 2005-04-25 18:43:14Z darrenr $ 10 * Id: ip_compat.h,v 2.142.2.25 2005/03/28 09:33:36 darrenr Exp |
9 */ 10 11#ifndef __IP_COMPAT_H__ 12#define __IP_COMPAT_H__ 13 14#ifndef __P 15# ifdef __STDC__ 16# define __P(x) x 17# else 18# define __P(x) () 19# endif 20#endif 21#ifndef __STDC__ 22# undef const 23# define const 24#endif 25 | 11 */ 12 13#ifndef __IP_COMPAT_H__ 14#define __IP_COMPAT_H__ 15 16#ifndef __P 17# ifdef __STDC__ 18# define __P(x) x 19# else 20# define __P(x) () 21# endif 22#endif 23#ifndef __STDC__ 24# undef const 25# define const 26#endif 27 |
26#ifndef SOLARIS 27#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 28#endif 29#if SOLARIS 30# if !defined(SOLARIS2) 31# define SOLARIS2 3 /* Pick an old version */ 32# endif 33# if SOLARIS2 >= 8 34# ifndef USE_INET6 35# define USE_INET6 36# endif 37# else 38# undef USE_INET6 39# endif 40#endif 41#if defined(sun) && !(defined(__svr4__) || defined(__SVR4)) 42# undef USE_INET6 43#endif 44 | |
45#if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__) 46# undef KERNEL 47# undef _KERNEL 48# undef __KERNEL__ 49# define KERNEL 50# define _KERNEL 51# define __KERNEL__ 52#endif 53 | 28#if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__) 29# undef KERNEL 30# undef _KERNEL 31# undef __KERNEL__ 32# define KERNEL 33# define _KERNEL 34# define __KERNEL__ 35#endif 36 |
37#ifndef SOLARIS 38#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 39#endif 40#if SOLARIS2 >= 8 41# ifndef USE_INET6 42# define USE_INET6 43# endif 44#endif 45#if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \ 46 !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6) 47# define USE_INET6 48#endif 49#if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \ 50 !defined(_KERNEL) && !defined(USE_INET6) 51# define USE_INET6 52# define IPFILTER_M_IPFILTER 53#endif 54#if defined(OpenBSD) && (OpenBSD >= 200206) && \ 55 !defined(_KERNEL) && !defined(USE_INET6) 56# define USE_INET6 57#endif 58#if defined(__osf__) 59# define USE_INET6 60#endif 61#if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6)) 62# define USE_INET6 63#endif 64#if defined(HPUXREV) && (HPUXREV >= 1111) 65# define USE_INET6 66#endif 67 68#if defined(BSD) && (BSD < 199103) && defined(__osf__) 69# undef BSD 70# define BSD 199103 71#endif 72 |
|
54#if defined(__SVR4) || defined(__svr4__) || defined(__sgi) | 73#if defined(__SVR4) || defined(__svr4__) || defined(__sgi) |
55#define index strchr 56# if !defined(KERNEL) | 74# define index strchr 75# if !defined(_KERNEL) |
57# define bzero(a,b) memset(a,0,b) 58# define bcmp memcmp 59# define bcopy(a,b,c) memmove(b,a,c) 60# endif 61#endif 62 | 76# define bzero(a,b) memset(a,0,b) 77# define bcmp memcmp 78# define bcopy(a,b,c) memmove(b,a,c) 79# endif 80#endif 81 |
63#ifndef offsetof 64#define offsetof(t,m) (int)((&((t *)0L)->m)) 65#endif 66 67#if defined(__sgi) || defined(bsdi) 68struct ether_addr { 69 u_char ether_addr_octet[6]; 70}; 71#endif 72 73#ifndef LIFNAMSIZ 74# ifdef IF_NAMESIZE | 82#ifndef LIFNAMSIZ 83# ifdef IF_NAMESIZE |
75# define LIFNAMSIZ IF_NAMESIZE 76# else 77# ifdef IFNAMSIZ 78# define LIFNAMSIZ IFNAMSIZ 79# else 80# define LIFNAMSIZ 16 81# endif 82# endif 83#endif 84 | 84# define LIFNAMSIZ IF_NAMESIZE 85# else 86# ifdef IFNAMSIZ 87# define LIFNAMSIZ IFNAMSIZ 88# else 89# define LIFNAMSIZ 16 90# endif 91# endif 92#endif 93 |
94#if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux) 95struct ether_addr { 96 u_char ether_addr_octet[6]; 97}; 98#endif 99 |
|
85#if defined(__sgi) && !defined(IPFILTER_LKM) 86# ifdef __STDC__ 87# define IPL_EXTERN(ep) ipfilter##ep 88# else 89# define IPL_EXTERN(ep) ipfilter/**/ep 90# endif 91#else 92# ifdef __STDC__ 93# define IPL_EXTERN(ep) ipl##ep 94# else 95# define IPL_EXTERN(ep) ipl/**/ep 96# endif 97#endif 98 | 100#if defined(__sgi) && !defined(IPFILTER_LKM) 101# ifdef __STDC__ 102# define IPL_EXTERN(ep) ipfilter##ep 103# else 104# define IPL_EXTERN(ep) ipfilter/**/ep 105# endif 106#else 107# ifdef __STDC__ 108# define IPL_EXTERN(ep) ipl##ep 109# else 110# define IPL_EXTERN(ep) ipl/**/ep 111# endif 112#endif 113 |
99#ifdef __sgi 100# include <sys/debug.h> 101#endif 102 103#ifdef linux 104# include <sys/sysmacros.h> 105#endif 106 | |
107/* 108 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD. 109 */ | 114/* 115 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD. 116 */ |
110#ifndef _KERNEL 111# define ADD_KERNEL 112# define _KERNEL 113# define KERNEL 114#endif 115#ifdef __OpenBSD__ | 117#ifndef linux 118# ifndef _KERNEL 119# define ADD_KERNEL 120# define _KERNEL 121# define KERNEL 122# endif 123# ifdef __OpenBSD__ |
116struct file; | 124struct file; |
125# endif 126# include <sys/uio.h> 127# ifdef ADD_KERNEL 128# undef _KERNEL 129# undef KERNEL 130# endif |
|
117#endif | 131#endif |
118#include <sys/uio.h> 119#ifdef ADD_KERNEL 120# undef _KERNEL 121# undef KERNEL 122#endif | |
123 | 132 |
124#if SOLARIS 125# define MTYPE(m) ((m)->b_datap->db_type) 126# if SOLARIS2 >= 4 127# include <sys/isa_defs.h> 128# endif | 133 134/* ----------------------------------------------------------------------- */ 135/* S O L A R I S */ 136/* ----------------------------------------------------------------------- */ 137#if SOLARIS 138# define MENTAT 1 139# include <sys/cmn_err.h> 140# include <sys/isa_defs.h> 141# include <sys/stream.h> |
129# include <sys/ioccom.h> 130# include <sys/sysmacros.h> 131# include <sys/kmem.h> | 142# include <sys/ioccom.h> 143# include <sys/sysmacros.h> 144# include <sys/kmem.h> |
145# if SOLARIS2 >= 10 146# include <sys/procset.h> 147# include <sys/proc.h> 148# include <sys/devops.h> 149# include <sys/ddi_impldefs.h> 150# endif |
|
132/* 133 * because Solaris 2 defines these in two places :-/ 134 */ | 151/* 152 * because Solaris 2 defines these in two places :-/ 153 */ |
154# ifndef KERNEL 155# define _KERNEL 156# undef RES_INIT 157# endif /* _KERNEL */ 158 159# if SOLARIS2 >= 8 160# include <netinet/ip6.h> 161# include <netinet/icmp6.h> 162# endif 163 164# include <inet/common.h> 165/* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */ |
|
135# undef IPOPT_EOL 136# undef IPOPT_NOP 137# undef IPOPT_LSRR 138# undef IPOPT_RR 139# undef IPOPT_SSRR | 166# undef IPOPT_EOL 167# undef IPOPT_NOP 168# undef IPOPT_LSRR 169# undef IPOPT_RR 170# undef IPOPT_SSRR |
171# ifdef i386 172# define _SYS_PROMIF_H 173# endif 174# include <inet/ip.h> 175# undef COPYOUT 176# include <inet/ip_ire.h> |
|
140# ifndef KERNEL | 177# ifndef KERNEL |
141# define _KERNEL 142# undef RES_INIT 143# if SOLARIS2 >= 8 144# include <netinet/ip6.h> 145# endif 146# include <inet/common.h> 147# include <inet/ip.h> 148# include <inet/ip_ire.h> | |
149# undef _KERNEL | 178# undef _KERNEL |
150# else /* _KERNEL */ 151# if SOLARIS2 >= 8 152# include <netinet/ip6.h> 153# endif 154# include <inet/common.h> 155# include <inet/ip.h> 156# include <inet/ip_ire.h> 157# endif /* _KERNEL */ | 179# endif |
158# if SOLARIS2 >= 8 | 180# if SOLARIS2 >= 8 |
181# define SNPRINTF snprintf 182 |
|
159# include <inet/ip_if.h> | 183# include <inet/ip_if.h> |
160# include <netinet/ip6.h> | |
161# define ipif_local_addr ipif_lcl_addr 162/* Only defined in private include file */ 163# ifndef V4_PART_OF_V6 164# define V4_PART_OF_V6(v6) v6.s6_addr32[3] 165# endif | 184# define ipif_local_addr ipif_lcl_addr 185/* Only defined in private include file */ 186# ifndef V4_PART_OF_V6 187# define V4_PART_OF_V6(v6) v6.s6_addr32[3] 188# endif |
189struct ip6_ext { 190 u_char ip6e_nxt; 191 u_char ip6e_len; 192}; 193# endif /* SOLARIS2 >= 8 */ 194 195# if SOLARIS2 >= 6 196# include <sys/atomic.h> 197typedef uint32_t u_32_t; 198# else 199typedef unsigned int u_32_t; |
|
166# endif | 200# endif |
167# define M_BLEN(m) ((m)->b_wptr - (m)->b_rptr) | 201# define U_32_T 1 |
168 | 202 |
169typedef struct qif { 170 struct qif *qf_next; 171 ill_t *qf_ill; 172 kmutex_t qf_lock; 173 void *qf_iptr; 174 void *qf_optr; 175 queue_t *qf_in; 176 queue_t *qf_out; 177 void *qf_data; /* layer 3 header pointer */ 178 struct qinit *qf_wqinfo; 179 struct qinit *qf_rqinfo; 180 struct qinit qf_wqinit; 181 struct qinit qf_rqinit; 182 mblk_t *qf_m; /* These three fields are for passing data up from */ 183 queue_t *qf_q; /* fr_qin and fr_qout to the packet processing. */ 184 size_t qf_off; 185 size_t qf_len; /* this field is used for in ipfr_fastroute */ 186 char qf_name[LIFNAMSIZ]; 187 /* 188 * in case the ILL has disappeared... 189 */ 190 size_t qf_hl; /* header length */ 191 int qf_sap; 192# if SOLARIS2 >= 8 193 int qf_tunoff; /* tunnel offset */ 194#endif 195 size_t qf_incnt; 196 size_t qf_outcnt; 197} qif_t; 198#else /* SOLARIS */ 199# if !defined(__sgi) 200typedef int minor_t; | 203# ifdef _KERNEL 204# define KRWLOCK_T krwlock_t 205# define KMUTEX_T kmutex_t 206# include "qif.h" 207# include "pfil.h" 208# if SOLARIS2 >= 6 209# if SOLARIS2 == 6 210# define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1) 211# define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1) 212# else 213# define ATOMIC_INCL(x) atomic_add_long(&(x), 1) 214# define ATOMIC_DECL(x) atomic_add_long(&(x), -1) 215# endif /* SOLARIS2 == 6 */ 216# define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1) 217# define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1) 218# define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1) 219# define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1) 220# define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1) 221# define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1) 222# else 223# define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \ 224 mutex_exit(&ipf_rw); } 225# define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \ 226 mutex_exit(&ipf_rw); } 227# endif /* SOLARIS2 >= 6 */ 228# define USE_MUTEXES 229# define MUTEX_ENTER(x) mutex_enter(&(x)->ipf_lk) 230# define READ_ENTER(x) rw_enter(&(x)->ipf_lk, RW_READER) 231# define WRITE_ENTER(x) rw_enter(&(x)->ipf_lk, RW_WRITER) 232# define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk) 233# define RWLOCK_INIT(x, y) rw_init(&(x)->ipf_lk, (y), \ 234 RW_DRIVER, NULL) 235# define RWLOCK_EXIT(x) rw_exit(&(x)->ipf_lk) 236# define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk) 237# define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, (y), \ 238 MUTEX_DRIVER, NULL) 239# define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk) 240# define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 241# define MUTEX_EXIT(x) mutex_exit(&(x)->ipf_lk) 242# define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 243# define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 244# define BCOPYIN(a,b,c) (void) copyin((caddr_t)(a), (caddr_t)(b), (c)) 245# define BCOPYOUT(a,b,c) (void) copyout((caddr_t)(a), (caddr_t)(b), (c)) 246# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 247# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 248# define KFREES(x,s) kmem_free((char *)(x), (s)) 249# define SPL_NET(x) ; 250# define SPL_IMP(x) ; 251# undef SPL_X 252# define SPL_X(x) ; 253# ifdef sparc 254# define ntohs(x) (x) 255# define ntohl(x) (x) 256# define htons(x) (x) 257# define htonl(x) (x) 258# endif /* sparc */ 259# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 260# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 261# define GET_MINOR(x) getminor(x) 262extern void *get_unit __P((char *, int)); 263# define GETIFP(n, v) get_unit(n, v) 264# define IFNAME(x) ((qif_t *)x)->qf_name 265# define COPYIFNAME(x, b) \ 266 (void) strncpy(b, ((qif_t *)x)->qf_name, \ 267 LIFNAMSIZ) 268# define GETKTIME(x) uniqtime((struct timeval *)x) 269# define MSGDSIZE(x) msgdsize(x) 270# define M_LEN(x) ((x)->b_wptr - (x)->b_rptr) 271# define M_DUPLICATE(x) dupmsg((x)) 272# define MTOD(m,t) ((t)((m)->b_rptr)) 273# define MTYPE(m) ((m)->b_datap->db_type) 274# define FREE_MB_T(m) freemsg(m) 275# define m_next b_cont 276# define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7) 277# define IPF_PANIC(x,y) if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); } 278typedef mblk_t mb_t; 279# endif /* _KERNEL */ 280 281# if (SOLARIS2 >= 7) 282# ifdef lint 283# define ALIGN32(ptr) (ptr ? 0L : 0L) 284# define ALIGN16(ptr) (ptr ? 0L : 0L) 285# else 286# define ALIGN32(ptr) (ptr) 287# define ALIGN16(ptr) (ptr) 288# endif |
201# endif | 289# endif |
290 291# if SOLARIS2 < 6 292typedef struct uio uio_t; 293# endif 294typedef int ioctlcmd_t; 295 296# define OS_RECOGNISED 1 297 |
|
202#endif /* SOLARIS */ | 298#endif /* SOLARIS */ |
203#define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h))) | |
204 | 299 |
205#ifndef IP_OFFMASK 206#define IP_OFFMASK 0x1fff 207#endif | 300/* ----------------------------------------------------------------------- */ 301/* H P U X */ 302/* ----------------------------------------------------------------------- */ 303#ifdef __hpux 304# define MENTAT 1 305# include <sys/sysmacros.h> 306# include <sys/spinlock.h> 307# include <sys/lock.h> 308# include <sys/stream.h> 309# ifdef USE_INET6 310# include <netinet/if_ether.h> 311# include <netinet/ip6.h> 312# include <netinet/icmp6.h> 313typedef struct ip6_hdr ip6_t; 314# endif |
208 | 315 |
209#if BSD > 199306 210# define USE_QUAD_T 211# define U_QUAD_T u_quad_t 212# define QUAD_T quad_t 213#else /* BSD > 199306 */ 214# define U_QUAD_T u_long 215# define QUAD_T long 216#endif /* BSD > 199306 */ | 316# ifdef _KERNEL 317# define SNPRINTF sprintf 318# if (HPUXREV >= 1111) 319# define IPL_SELECT 320# ifdef IPL_SELECT 321# include <machine/sys/user.h> 322# include <sys/kthread_iface.h> 323# define READ_COLLISION 0x01 |
217 | 324 |
325typedef struct iplog_select_s { 326 kthread_t *read_waiter; 327 int state; 328} iplog_select_t; 329# endif 330# endif |
|
218 | 331 |
219#if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL)) 220# include <sys/param.h> 221# ifndef __FreeBSD_version 222# ifdef IPFILTER_LKM 223# include <osreldate.h> | 332# define GETKTIME(x) uniqtime((struct timeval *)x) 333 334# if HPUXREV == 1111 335# include "kern_svcs.h" |
224# else | 336# else |
225# include <sys/osreldate.h> | 337# include <sys/kern_svcs.h> |
226# endif | 338# endif |
339# undef ti_flags 340# undef TCP_NODELAY 341# undef TCP_MAXSEG 342# include <sys/reg.h> 343# include "../netinet/ip_info.h" 344/* 345 * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions 346 * are available. Attempting to use them actually results in unresolved 347 * symbols when it comes time to load the module. 348 * This has been fixed! Yipee! 349 */ 350# if 1 351# ifdef __LP64__ 352# define ATOMIC_INCL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1) 353# define ATOMIC_DECL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1) 354# else 355# define ATOMIC_INCL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1) 356# define ATOMIC_DECL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1) 357# endif 358# define ATOMIC_INC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1) 359# define ATOMIC_INC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1) 360# define ATOMIC_INC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1) 361# define ATOMIC_DEC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1) 362# define ATOMIC_DEC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1) 363# define ATOMIC_DEC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1) 364# else /* 0 */ 365# define ATOMIC_INC64(x) { MUTEX_ENTER(&ipf_rw); (x)++; \ 366 MUTEX_EXIT(&ipf_rw); } 367# define ATOMIC_DEC64(x) { MUTEX_ENTER(&ipf_rw); (x)--; \ 368 MUTEX_EXIT(&ipf_rw); } 369# define ATOMIC_INC32(x) { MUTEX_ENTER(&ipf_rw); (x)++; \ 370 MUTEX_EXIT(&ipf_rw); } 371# define ATOMIC_DEC32(x) { MUTEX_ENTER(&ipf_rw); (x)--; \ 372 MUTEX_EXIT(&ipf_rw); } 373# define ATOMIC_INCL(x) { MUTEX_ENTER(&ipf_rw); (x)++; \ 374 MUTEX_EXIT(&ipf_rw); } 375# define ATOMIC_DECL(x) { MUTEX_ENTER(&ipf_rw); (x)--; \ 376 MUTEX_EXIT(&ipf_rw); } 377# define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); (x)++; \ 378 MUTEX_EXIT(&ipf_rw); } 379# define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); (x)--; \ 380 MUTEX_EXIT(&ipf_rw); } 381# endif 382# define ip_cksum ip_csuma 383# define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c) 384# define USE_MUTEXES 385# define MUTEX_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, (y)) 386# define MUTEX_ENTER(x) spinlock(&(x)->ipf_lk) 387# define MUTEX_EXIT(x) spinunlock(&(x)->ipf_lk); 388# define MUTEX_DESTROY(x) 389# define MUTEX_NUKE(x) bzero((char *)(x), sizeof(*(x))) 390# define KMUTEX_T lock_t 391# define kmutex_t lock_t /* for pfil.h */ 392# define krwlock_t lock_t /* for pfil.h */ 393/* 394 * The read-write lock implementation in HP-UX 11.0 is crippled - it can 395 * only be used by threads working in a user context! 396 * This has been fixed! Yipee! (Or at least it does in 11.00, not 11.11..) 397 */ 398# if HPUXREV < 1111 399# define MUTEX_DOWNGRADE(x) lock_write_to_read(x) 400# define KRWLOCK_T struct rw_lock 401# define READ_ENTER(x) lock_read(&(x)->ipf_lk) 402# define WRITE_ENTER(x) lock_write(&(x)->ipf_lk) 403# if HPUXREV >= 1111 404# define RWLOCK_INIT(x, y) rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y) 405# else 406# define RWLOCK_INIT(x, y) lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y) 407# endif 408# define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk) 409# else 410# define KRWLOCK_T lock_t 411# define KMUTEX_T lock_t 412# define READ_ENTER(x) MUTEX_ENTER(x) 413# define WRITE_ENTER(x) MUTEX_ENTER(x) 414# define MUTEX_DOWNGRADE(x) 415# define RWLOCK_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, y) 416# define RWLOCK_EXIT(x) MUTEX_EXIT(x) 417# endif 418# define RW_DESTROY(x) 419# define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 420# define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 421# if HPUXREV >= 1111 422# define BCOPYIN(a,b,c) 0; bcopy((caddr_t)(a), (caddr_t)(b), (c)) 423# define BCOPYOUT(a,b,c) 0; bcopy((caddr_t)(a), (caddr_t)(b), (c)) 424# else 425# define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 426# define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 427# endif 428# define SPL_NET(x) ; 429# define SPL_IMP(x) ; 430# undef SPL_X 431# define SPL_X(x) ; 432extern void *get_unit __P((char *, int)); 433# define GETIFP(n, v) get_unit(n, v) 434# define IFNAME(x, b) ((ill_t *)x)->ill_name 435# define COPYIFNAME(x, b) \ 436 (void) strncpy(b, ((qif_t *)x)->qf_name, \ 437 LIFNAMSIZ) 438# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 439# define SLEEP(id, n) { lock_t *_l = get_sleep_lock((caddr_t)id); \ 440 sleep(id, PZERO+1); \ 441 spinunlock(_l); \ 442 } 443# define WAKEUP(id,x) { lock_t *_l = get_sleep_lock((caddr_t)id); \ 444 wakeup(id + x); \ 445 spinunlock(_l); \ 446 } 447# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT) 448# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_IOSYS, M_NOWAIT) 449# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 450# define KFREES(x,s) kmem_free((char *)(x), (s)) 451# define MSGDSIZE(x) msgdsize(x) 452# define M_LEN(x) ((x)->b_wptr - (x)->b_rptr) 453# define M_DUPLICATE(x) dupmsg((x)) 454# define MTOD(m,t) ((t)((m)->b_rptr)) 455# define MTYPE(m) ((m)->b_datap->db_type) 456# define FREE_MB_T(m) freemsg(m) 457# define m_next b_cont 458# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 459typedef mblk_t mb_t; 460 461# define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7) 462 463# include "qif.h" 464# include "pfil.h" 465 466# else /* _KERNEL */ 467 468typedef unsigned char uchar_t; 469 470# ifndef _SYS_STREAM_INCLUDED 471typedef char * mblk_t; 472typedef void * queue_t; 473typedef u_long ulong; 474# endif 475# include <netinet/ip_info.h> 476 477# endif /* _KERNEL */ 478 479# ifdef lint 480# define ALIGN32(ptr) (ptr ? 0L : 0L) 481# define ALIGN16(ptr) (ptr ? 0L : 0L) 482# else 483# define ALIGN32(ptr) (ptr) 484# define ALIGN16(ptr) (ptr) |
|
227# endif | 485# endif |
228# ifdef IPFILTER_LKM 229# define ACTUALLY_LKM_NOT_KERNEL | 486 487typedef struct uio uio_t; 488typedef int ioctlcmd_t; 489typedef int minor_t; 490typedef unsigned int u_32_t; 491# define U_32_T 1 492 493# define OS_RECOGNISED 1 494 495#endif /* __hpux */ 496 497/* ----------------------------------------------------------------------- */ 498/* I R I X */ 499/* ----------------------------------------------------------------------- */ 500#ifdef __sgi 501# undef MENTAT 502# if IRIX < 60500 503typedef struct uio uio_t; |
230# endif | 504# endif |
231# if defined(__FreeBSD_version) && (__FreeBSD_version < 300000) 232# include <machine/spl.h> | 505typedef int ioctlcmd_t; 506typedef u_int32_t u_32_t; 507# define U_32_T 1 508 509# ifdef INET6 510# define USE_INET6 511# endif 512 513# define hz HZ 514# include <sys/ksynch.h> 515# define IPF_LOCK_PL plhi 516# include <sys/sema.h> 517# undef kmutex_t 518typedef struct { 519 lock_t *l; 520 int pl; 521} kmutex_t; 522 523# ifdef MUTEX_INIT 524# define KMUTEX_T mutex_t |
233# else | 525# else |
234# if (__FreeBSD_version >= 300000) && (__FreeBSD_version < 400000) 235# if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL) 236# define ACTUALLY_LKM_NOT_KERNEL 237# endif | 526# define KMUTEX_T kmutex_t 527# define KRWLOCK_T kmutex_t 528# endif 529 530# ifdef _KERNEL 531# define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ 532 (x)++; MUTEX_EXIT(&ipf_rw); } 533# define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ 534 (x)--; MUTEX_EXIT(&ipf_rw); } 535# define USE_MUTEXES 536# ifdef MUTEX_INIT 537# include <sys/atomic_ops.h> 538# define ATOMIC_INCL(x) atomicAddUlong(&(x), 1) 539# define ATOMIC_INC64(x) atomicAddUint64(&(x), 1) 540# define ATOMIC_INC32(x) atomicAddUint(&(x), 1) 541# define ATOMIC_INC16 ATOMIC_INC 542# define ATOMIC_DECL(x) atomicAddUlong(&(x), -1) 543# define ATOMIC_DEC64(x) atomicAddUint64(&(x), -1) 544# define ATOMIC_DEC32(x) atomicAddUint(&(x), -1) 545# define ATOMIC_DEC16 ATOMIC_DEC 546# undef MUTEX_INIT 547# define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, \ 548 MUTEX_DEFAULT, y) 549# undef MUTEX_ENTER 550# define MUTEX_ENTER(x) mutex_lock(&(x)->ipf_lk, 0) 551# undef MUTEX_EXIT 552# define MUTEX_EXIT(x) mutex_unlock(&(x)->ipf_lk) 553# undef MUTEX_DESTROY 554# define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk) 555# define MUTEX_DOWNGRADE(x) mrdemote(&(x)->ipf_lk) 556# define KRWLOCK_T mrlock_t 557# define RWLOCK_INIT(x, y) mrinit(&(x)->ipf_lk, y) 558# undef RW_DESTROY 559# define RW_DESTROY(x) mrfree(&(x)->ipf_lk) 560# define READ_ENTER(x) RW_RDLOCK(&(x)->ipf_lk) 561# define WRITE_ENTER(x) RW_WRLOCK(&(x)->ipf_lk) 562# define RWLOCK_EXIT(x) RW_UNLOCK(&(x)->ipf_lk) 563# else 564# define READ_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk) 565# define WRITE_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk) 566# define MUTEX_DOWNGRADE(x) ; 567# define RWLOCK_EXIT(x) MUTEX_EXIT(&(x)->ipf_lk) 568# define MUTEX_EXIT(x) UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl); 569# define MUTEX_INIT(x,y) (x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP) 570# define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->ipf_lk.l) 571# define MUTEX_ENTER(x) (x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \ 572 IPF_LOCK_PL); |
238# endif | 573# endif |
574# define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 575# define FREE_MB_T(m) m_freem(m) 576# define MTOD(m,t) mtod(m,t) 577# define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 578# define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 579# define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 580# define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 581# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 582# define SLEEP(id, n) sleep((id), PZERO+1) 583# define WAKEUP(id,x) wakeup(id+x) 584# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 585# define KFREES(x,s) kmem_free((char *)(x), (s)) 586# define GETIFP(n,v) ifunit(n) 587# include <sys/kmem.h> 588# include <sys/ddi.h> 589# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 590# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 591# define GET_MINOR(x) getminor(x) 592# define USE_SPL 1 593# define SPL_IMP(x) (x) = splimp() 594# define SPL_NET(x) (x) = splnet() 595# define SPL_X(x) (void) splx(x) 596extern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 597extern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 598# define MSGDSIZE(x) mbufchainlen(x) 599# define M_LEN(x) (x)->m_len 600# define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 601# define GETKTIME(x) microtime((struct timeval *)x) 602# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 603 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 604# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 605typedef struct mbuf mb_t; 606# else 607# undef RW_DESTROY 608# undef MUTEX_INIT 609# undef MUTEX_DESTROY 610# endif /* _KERNEL */ 611 612# define OS_RECOGNISED 1 613 614#endif /* __sgi */ 615 616/* ----------------------------------------------------------------------- */ 617/* T R U 6 4 */ 618/* ----------------------------------------------------------------------- */ 619#ifdef __osf__ 620# undef MENTAT 621 622# include <kern/lock.h> 623# include <sys/sysmacros.h> 624 625# ifdef _KERNEL 626# define KMUTEX_T simple_lock_data_t 627# define KRWLOCK_T lock_data_t 628# include <net/net_globals.h> 629# define USE_MUTEXES 630# define READ_ENTER(x) lock_read(&(x)->ipf_lk) 631# define WRITE_ENTER(x) lock_write(&(x)->ipf_lk) 632# define MUTEX_DOWNGRADE(x) lock_write_to_read(&(x)->ipf_lk) 633# define RWLOCK_INIT(x, y) lock_init(&(x)->ipf_lk, TRUE) 634# define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk) 635# define RW_DESTROY(x) lock_terminate(&(x)->ipf_lk) 636# define MUTEX_ENTER(x) simple_lock(&(x)->ipf_lk) 637# define MUTEX_INIT(x, y) simple_lock_init(&(x)->ipf_lk) 638# define MUTEX_DESTROY(x) simple_lock_terminate(&(x)->ipf_lk) 639# define MUTEX_EXIT(x) simple_unlock(&(x)->ipf_lk) 640# define MUTEX_NUKE(x) bzero(x, sizeof(*(x))) 641# define ATOMIC_INC64(x) atomic_incq((uint64_t*)&(x)) 642# define ATOMIC_DEC64(x) atomic_decq((uint64_t*)&(x)) 643# define ATOMIC_INC32(x) atomic_incl((uint32_t*)&(x)) 644# define ATOMIC_DEC32(x) atomic_decl((uint32_t*)&(x)) 645# define ATOMIC_INC16(x) { simple_lock(&ipf_rw); (x)++; \ 646 simple_unlock(&ipf_rw); } 647# define ATOMIC_DEC16(x) { simple_lock(&ipf_rw); (x)--; \ 648 simple_unlock(&ipf_rw); } 649# define ATOMIC_INCL(x) atomic_incl((uint32_t*)&(x)) 650# define ATOMIC_DECL(x) atomic_decl((uint32_t*)&(x)) 651# define ATOMIC_INC(x) { simple_lock(&ipf_rw); (x)++; \ 652 simple_unlock(&ipf_rw); } 653# define ATOMIC_DEC(x) { simple_lock(&ipf_rw); (x)--; \ 654 simple_unlock(&ipf_rw); } 655# define SPL_NET(x) ; 656# define SPL_IMP(x) ; 657# undef SPL_X 658# define SPL_X(x) ; 659# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a, b, d) 660# define FREE_MB_T(m) m_freem(m) 661# define MTOD(m,t) mtod(m,t) 662# define GETIFP(n, v) ifunit(n) 663# define GET_MINOR getminor 664# define WAKEUP(id,x) wakeup(id + x) 665# define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 666# define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 667# define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 668# define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 669# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT) 670# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFILT, \ 671 ((c) > 4096) ? M_WAITOK : M_NOWAIT) 672# define KFREE(x) FREE((x), M_PFILT) 673# define KFREES(x,s) FREE((x), M_PFILT) 674# define MSGDSIZE(x) mbufchainlen(x) 675# define M_LEN(x) (x)->m_len 676# define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 677# define GETKTIME(x) microtime((struct timeval *)x) 678# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 679 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 680# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 681typedef struct mbuf mb_t; 682# endif /* _KERNEL */ 683 684# if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1)) 685# define IP_V(x) ((x)->ip_vhl >> 4) 686# define IP_HL(x) ((x)->ip_vhl & 0xf) 687# define IP_V_A(x,y) (x)->ip_vhl |= (((y) << 4) & 0xf0) 688# define IP_HL_A(x,y) (x)->ip_vhl |= ((y) & 0xf) 689# define TCP_X2(x) ((x)->th_xoff & 0xf) 690# define TCP_X2_A(x,y) (x)->th_xoff |= ((y) & 0xf) 691# define TCP_OFF(x) ((x)->th_xoff >> 4) 692# define TCP_OFF_A(x,y) (x)->th_xoff |= (((y) << 4) & 0xf0) |
|
239# endif | 693# endif |
240#endif /* __FreeBSD__ && KERNEL */ | |
241 | 694 |
242#if defined(__FreeBSD_version) && (__FreeBSD_version >= 500000) && \ 243 defined(_KERNEL) 244# include <machine/in_cksum.h> 245#endif | 695/* 696 * These are from's Solaris' #defines for little endian. 697 */ 698#define IP6F_MORE_FRAG 0x0100 699#define IP6F_RESERVED_MASK 0x0600 700#define IP6F_OFF_MASK 0xf8ff |
246 | 701 |
702struct ip6_ext { 703 u_char ip6e_nxt; 704 u_char ip6e_len; 705}; 706 707typedef int ioctlcmd_t; |
|
247/* | 708/* |
248 * These operating systems already take care of the problem for us. | 709 * Really, any arch where sizeof(long) != sizeof(int). |
249 */ | 710 */ |
250#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \ 251 defined(__sgi) 252typedef u_int32_t u_32_t; | 711typedef unsigned int u_32_t; 712# define U_32_T 1 713 714# define OS_RECOGNISED 1 715#endif /* __osf__ */ 716 717/* ----------------------------------------------------------------------- */ 718/* N E T B S D */ 719/* ----------------------------------------------------------------------- */ 720#ifdef __NetBSD__ |
253# if defined(_KERNEL) && !defined(IPFILTER_LKM) | 721# if defined(_KERNEL) && !defined(IPFILTER_LKM) |
722# include "bpfilter.h" |
|
254# if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000) 255# include "opt_inet.h" 256# endif | 723# if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000) 724# include "opt_inet.h" 725# endif |
257# if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \ 258 !defined(KLD_MODULE) 259# include "opt_inet6.h" 260# endif | |
261# ifdef INET6 | 726# ifdef INET6 |
262# define USE_INET6 263# endif | 727# define USE_INET6 728# endif 729# if (__NetBSD_Version__ >= 105000000) 730# define HAVE_M_PULLDOWN 1 731# endif |
264# endif | 732# endif |
265# if !defined(_KERNEL) && !defined(IPFILTER_LKM) && !defined(USE_INET6) 266# if (defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \ 267 !defined(NOINET6)) || \ 268 (defined(OpenBSD) && (OpenBSD >= 200111)) || \ 269 (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000)) | 733 734# ifdef _KERNEL 735# define MSGDSIZE(x) mbufchainlen(x) 736# define M_LEN(x) (x)->m_len 737# define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 738# define GETKTIME(x) microtime((struct timeval *)x) 739# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 740# define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 741# define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 742# define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 743# define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 744typedef struct mbuf mb_t; 745# endif /* _KERNEL */ 746# if (NetBSD <= 1991011) && (NetBSD >= 199606) 747# define IFNAME(x) ((struct ifnet *)x)->if_xname 748# define COPYIFNAME(x, b) \ 749 (void) strncpy(b, \ 750 ((struct ifnet *)x)->if_xname, \ 751 LIFNAMSIZ) 752# define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7) 753# else 754# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 755 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 756# endif 757 758typedef struct uio uio_t; 759typedef u_long ioctlcmd_t; 760typedef int minor_t; 761typedef u_int32_t u_32_t; 762# define U_32_T 1 763 764# define OS_RECOGNISED 1 765#endif /* __NetBSD__ */ 766 767 768/* ----------------------------------------------------------------------- */ 769/* F R E E B S D */ 770/* ----------------------------------------------------------------------- */ 771#ifdef __FreeBSD__ 772# if defined(_KERNEL) && !defined(IPFILTER_LKM) && !defined(KLD_MODULE) 773# if (__FreeBSD_version >= 500000) 774# include "opt_bpf.h" 775# else 776# include "bpf.h" 777# endif 778# if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) 779# include "opt_inet6.h" 780# endif 781# if defined(INET6) && !defined(USE_INET6) |
270# define USE_INET6 271# endif 272# endif | 782# define USE_INET6 783# endif 784# endif |
273#else | 785 786# if defined(_KERNEL) 787# if (__FreeBSD_version >= 400000) |
274/* | 788/* |
275 * Really, any arch where sizeof(long) != sizeof(int). | 789 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy. 790 * There may be other, safe, kernels but this is not extensively tested yet. |
276 */ | 791 */ |
277# if defined(__alpha__) || defined(__alpha) || defined(_LP64) 278typedef unsigned int u_32_t; 279# else 280# if SOLARIS2 >= 6 281typedef uint32_t u_32_t; | 792# define HAVE_M_PULLDOWN 793# endif 794# if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000) 795# include "opt_ipfilter.h" 796# endif 797# define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 798# define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 799# define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 800# define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 801 802# if (__FreeBSD_version >= 500043) 803# define NETBSD_PF 804# endif 805# endif /* _KERNEL */ 806 807# if (__FreeBSD_version >= 500043) 808# include <sys/mutex.h> 809# include <sys/sx.h> 810/* 811 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface 812 * for what we want to use them for, despite testing showing they work - 813 * with a WITNESS kernel, it generates LOR messages. 814 */ 815# define KMUTEX_T struct mtx 816# if 1 817# define KRWLOCK_T struct mtx |
282# else | 818# else |
283typedef unsigned int u_32_t; | 819# define KRWLOCK_T struct sx |
284# endif 285# endif | 820# endif 821# endif |
286#endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */ | |
287 | 822 |
288#ifdef USE_INET6 289# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 290# include <netinet/ip6.h> 291# ifdef _KERNEL 292# include <netinet6/ip6_var.h> | 823# if (__FreeBSD_version >= 501113) 824# include <net/if_var.h> 825# define IFNAME(x) ((struct ifnet *)x)->if_xname 826# define COPYIFNAME(x, b) \ 827 (void) strncpy(b, \ 828 ((struct ifnet *)x)->if_xname, \ 829 LIFNAMSIZ) 830# endif 831# if (__FreeBSD_version >= 500043) 832# define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index) & 7) 833# else 834# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 835 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 836# endif 837 838# ifdef _KERNEL 839# define GETKTIME(x) microtime((struct timeval *)x) 840 841# if (__FreeBSD_version >= 500002) 842# include <netinet/in_systm.h> 843# include <netinet/ip.h> 844# include <machine/in_cksum.h> |
293# endif | 845# endif |
294typedef struct ip6_hdr ip6_t; | 846 847# if (__FreeBSD_version >= 500043) 848# define USE_MUTEXES 849# define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk) 850# define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk) 851# define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\ 852 MTX_DEF) 853# define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk) 854# define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 855/* 856 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface 857 * for what we want to use them for, despite testing showing they work - 858 * with a WITNESS kernel, it generates LOR messages. 859 */ 860# if 1 861# define READ_ENTER(x) mtx_lock(&(x)->ipf_lk) 862# define WRITE_ENTER(x) mtx_lock(&(x)->ipf_lk) 863# define RWLOCK_EXIT(x) mtx_unlock(&(x)->ipf_lk) 864# define MUTEX_DOWNGRADE(x) ; 865# define RWLOCK_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\ 866 MTX_DEF) 867# define RW_DESTROY(x) mtx_destroy(&(x)->ipf_lk) 868# else 869# define READ_ENTER(x) sx_slock(&(x)->ipf_lk) 870# define WRITE_ENTER(x) sx_xlock(&(x)->ipf_lk) 871# define MUTEX_DOWNGRADE(x) sx_downgrade(&(x)->ipf_lk) 872# define RWLOCK_INIT(x, y) sx_init(&(x)->ipf_lk, (y)) 873# define RW_DESTROY(x) sx_destroy(&(x)->ipf_lk) 874# ifdef sx_unlock 875# define RWLOCK_EXIT(x) sx_unlock(x) 876# else 877# define RWLOCK_EXIT(x) do { \ 878 if ((x)->ipf_lk.sx_cnt < 0) \ 879 sx_xunlock(&(x)->ipf_lk); \ 880 else \ 881 sx_sunlock(&(x)->ipf_lk); \ 882 } while (0) 883# endif 884# endif 885# include <machine/atomic.h> 886# define ATOMIC_INC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)++; \ 887 mtx_unlock(&ipf_rw.ipf_lk); } 888# define ATOMIC_DEC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)--; \ 889 mtx_unlock(&ipf_rw.ipf_lk); } 890# define ATOMIC_INCL(x) atomic_add_long(&(x), 1) 891# define ATOMIC_INC64(x) ATOMIC_INC(x) 892# define ATOMIC_INC32(x) atomic_add_32(&(x), 1) 893# define ATOMIC_INC16(x) atomic_add_16(&(x), 1) 894# define ATOMIC_DECL(x) atomic_add_long(&(x), -1) 895# define ATOMIC_DEC64(x) ATOMIC_DEC(x) 896# define ATOMIC_DEC32(x) atomic_add_32(&(x), -1) 897# define ATOMIC_DEC16(x) atomic_add_16(&(x), -1) 898# define SPL_X(x) ; 899# define SPL_NET(x) ; 900# define SPL_IMP(x) ; 901extern int in_cksum __P((struct mbuf *, int)); 902# endif /* __FreeBSD_version >= 500043 */ 903# define MSGDSIZE(x) mbufchainlen(x) 904# define M_LEN(x) (x)->m_len 905# define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 906# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 907typedef struct mbuf mb_t; 908# endif /* _KERNEL */ 909 910# if __FreeBSD__ < 3 911# include <machine/spl.h> 912# else 913# if __FreeBSD__ == 3 914# if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL) 915# define ACTUALLY_LKM_NOT_KERNEL 916# endif 917# endif |
295# endif | 918# endif |
296# include <netinet/icmp6.h> 297union i6addr { 298 u_32_t i6[4]; 299 struct in_addr in4; 300 struct in6_addr in6; | 919 920# if (__FreeBSD_version >= 300000) 921typedef u_long ioctlcmd_t; 922# else 923typedef int ioctlcmd_t; 924# endif 925typedef struct uio uio_t; 926typedef int minor_t; 927typedef u_int32_t u_32_t; 928# define U_32_T 1 929 930# define OS_RECOGNISED 1 931#endif /* __FreeBSD__ */ 932 933 934/* ----------------------------------------------------------------------- */ 935/* O P E N B S D */ 936/* ----------------------------------------------------------------------- */ 937#ifdef __OpenBSD__ 938# ifdef INET6 939# define USE_INET6 940# endif 941 942# ifdef _KERNEL 943# if !defined(IPFILTER_LKM) 944# include "bpfilter.h" 945# endif 946# if (OpenBSD >= 200311) 947# define SNPRINTF snprintf 948# if defined(USE_INET6) 949# include "netinet6/in6_var.h" 950# include "netinet6/nd6.h" 951# endif 952# endif 953# if (OpenBSD >= 200012) 954# define HAVE_M_PULLDOWN 1 955# endif 956# define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 957# define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 958# define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 959# define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 960# define GETKTIME(x) microtime((struct timeval *)x) 961# define MSGDSIZE(x) mbufchainlen(x) 962# define M_LEN(x) (x)->m_len 963# define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 964# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 965typedef struct mbuf mb_t; 966# endif /* _KERNEL */ 967# if (OpenBSD >= 199603) 968# define IFNAME(x, b) ((struct ifnet *)x)->if_xname 969# define COPYIFNAME(x, b) \ 970 (void) strncpy(b, \ 971 ((struct ifnet *)x)->if_xname, \ 972 LIFNAMSIZ) 973# define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7) 974# else 975# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 976 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 977# endif 978 979typedef struct uio uio_t; 980typedef u_long ioctlcmd_t; 981typedef int minor_t; 982typedef u_int32_t u_32_t; 983# define U_32_T 1 984 985# define OS_RECOGNISED 1 986#endif /* __OpenBSD__ */ 987 988 989/* ----------------------------------------------------------------------- */ 990/* B S D O S */ 991/* ----------------------------------------------------------------------- */ 992#ifdef _BSDI_VERSION 993# ifdef INET6 994# define USE_INET6 995# endif 996 997# ifdef _KERNEL 998# define GETKTIME(x) microtime((struct timeval *)x) 999# define MSGDSIZE(x) mbufchainlen(x) 1000# define M_LEN(x) (x)->m_len 1001# define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 1002# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 1003 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 1004typedef struct mbuf mb_t; 1005# endif /* _KERNEL */ 1006 1007# if (_BSDI_VERSION >= 199701) 1008typedef u_long ioctlcmd_t; 1009# else 1010typedef int ioctlcmd_t; 1011# endif 1012typedef u_int32_t u_32_t; 1013# define U_32_T 1 1014 1015#endif /* _BSDI_VERSION */ 1016 1017 1018/* ----------------------------------------------------------------------- */ 1019/* S U N O S 4 */ 1020/* ----------------------------------------------------------------------- */ 1021#if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */ 1022# ifdef _KERNEL 1023# include <sys/kmem_alloc.h> 1024# define GETKTIME(x) uniqtime((struct timeval *)x) 1025# define MSGDSIZE(x) mbufchainlen(x) 1026# define M_LEN(x) (x)->m_len 1027# define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL) 1028# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 1029 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 1030# define GETIFP(n, v) ifunit(n, IFNAMSIZ) 1031# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 1032# define KFREES(x,s) kmem_free((char *)(x), (s)) 1033# define SLEEP(id, n) sleep((id), PZERO+1) 1034# define WAKEUP(id,x) wakeup(id + x) 1035# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 1036# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 1037 1038extern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 1039extern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 1040 1041typedef struct mbuf mb_t; 1042# endif 1043 1044typedef struct uio uio_t; 1045typedef int ioctlcmd_t; 1046typedef int minor_t; 1047typedef unsigned int u_32_t; 1048# define U_32_T 1 1049 1050# define OS_RECOGNISED 1 1051 1052#endif /* SunOS 4 */ 1053 1054/* ----------------------------------------------------------------------- */ 1055/* L I N U X */ 1056/* ----------------------------------------------------------------------- */ 1057#if defined(linux) && !defined(OS_RECOGNISED) 1058#include <linux/config.h> 1059#include <linux/version.h> 1060# if LINUX >= 20600 1061# define HDR_T_PRIVATE 1 1062# endif 1063# undef USE_INET6 1064# ifdef USE_INET6 1065struct ip6_ext { 1066 u_char ip6e_nxt; 1067 u_char ip6e_len; |
301}; | 1068}; |
302#else 303union i6addr { 304 u_32_t i6[4]; 305 struct in_addr in4; | 1069# endif 1070 1071# ifdef _KERNEL 1072# define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); } 1073# define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 1074# define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c)) 1075# define COPYIN(a,b,c) copy_from_user((caddr_t)(b), (caddr_t)(a), (c)) 1076# define COPYOUT(a,b,c) copy_to_user((caddr_t)(b), (caddr_t)(a), (c)) 1077# define FREE_MB_T(m) kfree_skb(m) 1078# define GETKTIME(x) do_gettimeofday((struct timeval *)x) 1079# define SLEEP(x,s) 0, interruptible_sleep_on(x##_linux) 1080# define WAKEUP(x,y) wake_up(x##_linux + y) 1081# define UIOMOVE(a,b,c,d) uiomove(a,b,c,d) 1082# define USE_MUTEXES 1083# define KRWLOCK_T rwlock_t 1084# define KMUTEX_T spinlock_t 1085# define MUTEX_INIT(x,y) spin_lock_init(&(x)->ipf_lk) 1086# define MUTEX_ENTER(x) spin_lock(&(x)->ipf_lk) 1087# define MUTEX_EXIT(x) spin_unlock(&(x)->ipf_lk) 1088# define MUTEX_DESTROY(x) do { } while (0) 1089# define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk)) 1090# define READ_ENTER(x) ipf_read_enter(x) 1091# define WRITE_ENTER(x) ipf_write_enter(x) 1092# define RWLOCK_INIT(x,y) rwlock_init(&(x)->ipf_lk) 1093# define RW_DESTROY(x) do { } while (0) 1094# define RWLOCK_EXIT(x) ipf_rw_exit(x) 1095# define MUTEX_DOWNGRADE(x) ipf_rw_downgrade(x) 1096# define ATOMIC_INCL(x) MUTEX_ENTER(&ipf_rw); (x)++; \ 1097 MUTEX_EXIT(&ipf_rw) 1098# define ATOMIC_DECL(x) MUTEX_ENTER(&ipf_rw); (x)--; \ 1099 MUTEX_EXIT(&ipf_rw) 1100# define ATOMIC_INC64(x) MUTEX_ENTER(&ipf_rw); (x)++; \ 1101 MUTEX_EXIT(&ipf_rw) 1102# define ATOMIC_INC32(x) MUTEX_ENTER(&ipf_rw); (x)++; \ 1103 MUTEX_EXIT(&ipf_rw) 1104# define ATOMIC_INC16(x) MUTEX_ENTER(&ipf_rw); (x)++; \ 1105 MUTEX_EXIT(&ipf_rw) 1106# define ATOMIC_DEC64(x) MUTEX_ENTER(&ipf_rw); (x)--; \ 1107 MUTEX_EXIT(&ipf_rw) 1108# define ATOMIC_DEC32(x) MUTEX_ENTER(&ipf_rw); (x)--; \ 1109 MUTEX_EXIT(&ipf_rw) 1110# define ATOMIC_DEC16(x) MUTEX_ENTER(&ipf_rw); (x)--; \ 1111 MUTEX_EXIT(&ipf_rw) 1112# define SPL_IMP(x) do { } while (0) 1113# define SPL_NET(x) do { } while (0) 1114# define SPL_X(x) do { } while (0) 1115# define IFNAME(x) ((struct net_device*)x)->name 1116# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 1117 ((struct net_device *)fin->fin_ifp)->ifindex) & 7) 1118typedef struct sk_buff mb_t; 1119extern void m_copydata __P((mb_t *, int, int, caddr_t)); 1120extern void m_copyback __P((mb_t *, int, int, caddr_t)); 1121extern void m_adj __P((mb_t *, int)); 1122extern mb_t *m_pullup __P((mb_t *, int)); 1123# define mbuf sk_buff 1124 1125# define mtod(m, t) ((t)(m)->data) 1126# define m_len len 1127# define m_next next 1128# define M_DUPLICATE(m) skb_clone((m), in_interrupt() ? GFP_ATOMIC : \ 1129 GFP_KERNEL) 1130# define MSGDSIZE(m) (m)->len 1131# define M_LEN(m) (m)->len 1132 1133# define splnet(x) ; 1134# define printf printk 1135# define bcopy(s,d,z) memmove(d, s, z) 1136# define bzero(s,z) memset(s, 0, z) 1137# define bcmp(a,b,z) memcmp(a, b, z) 1138 1139# define ifnet net_device 1140# define if_xname name 1141# define if_unit ifindex 1142 1143# define KMALLOC(x,t) (x) = (t)kmalloc(sizeof(*(x)), \ 1144 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL) 1145# define KFREE(x) kfree(x) 1146# define KMALLOCS(x,t,s) (x) = (t)kmalloc((s), \ 1147 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL) 1148# define KFREES(x,s) kfree(x) 1149 1150# define GETIFP(n,v) dev_get_by_name(n) 1151 1152# else 1153# include <net/ethernet.h> 1154 1155struct mbuf { |
306}; | 1156}; |
1157 1158# ifndef _NET_ROUTE_H 1159struct rtentry { 1160}; 1161# endif 1162 1163struct ifnet { 1164 char if_xname[IFNAMSIZ]; 1165 int if_unit; 1166 int (* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *)); 1167 struct ifaddr *if_addrlist; 1168}; 1169# define IFNAME(x) ((struct ifnet *)x)->if_xname 1170 1171# endif /* _KERNEL */ 1172 1173# define COPYIFNAME(x, b) \ 1174 (void) strncpy(b, \ 1175 ((struct ifnet *)x)->if_xname, \ 1176 LIFNAMSIZ) 1177 1178# include <linux/fs.h> 1179# define FWRITE FMODE_WRITE 1180# define FREAD FMODE_READ 1181 1182# define __USE_MISC 1 1183# define __FAVOR_BSD 1 1184 1185typedef struct uio { 1186 struct iovec *uio_iov; 1187 void *uio_file; 1188 char *uio_buf; 1189 int uio_iovcnt; 1190 int uio_offset; 1191 size_t uio_resid; 1192 int uio_rw; 1193} uio_t; 1194 1195extern int uiomove __P((caddr_t, size_t, int, struct uio *)); 1196 1197# define UIO_READ 1 1198# define UIO_WRITE 2 1199 1200typedef u_long ioctlcmd_t; 1201typedef int minor_t; 1202typedef u_int32_t u_32_t; 1203# define U_32_T 1 1204 1205# define OS_RECOGNISED 1 1206 |
|
307#endif 308 | 1207#endif 1208 |
309#define IP6CMP(a,b) bcmp((char *)&(a), (char *)&(b), sizeof(a)) 310#define IP6EQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) == 0) 311#define IP6NEQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) != 0) 312#define IP6_ISZERO(a) ((((union i6addr *)(a))->i6[0] | \ 313 ((union i6addr *)(a))->i6[1] | \ 314 ((union i6addr *)(a))->i6[2] | \ 315 ((union i6addr *)(a))->i6[3]) == 0) 316#define IP6_NOTZERO(a) ((((union i6addr *)(a))->i6[0] | \ 317 ((union i6addr *)(a))->i6[1] | \ 318 ((union i6addr *)(a))->i6[2] | \ 319 ((union i6addr *)(a))->i6[3]) != 0) | |
320 | 1209 |
1210#ifndef OS_RECOGNISED 1211#error ip_compat.h does not recognise this platform/OS. 1212#endif 1213 1214 1215/* ----------------------------------------------------------------------- */ 1216/* G E N E R I C */ 1217/* ----------------------------------------------------------------------- */ 1218#ifndef OS_RECOGNISED 1219#endif 1220 1221/* 1222 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in 1223 * filter rules. 1224 */ 1225#if !defined(IPFILTER_BPF) && ((NBPF > 0) || (NBPFILTER > 0)) 1226# define IPFILTER_BPF 1227#endif 1228 1229/* 1230 * Userland locking primitives 1231 */ 1232typedef struct { 1233 char *eMm_owner; 1234 char *eMm_heldin; 1235 u_int eMm_magic; 1236 int eMm_held; 1237 int eMm_heldat; 1238#ifdef __hpux 1239 char eMm_fill[8]; 1240#endif 1241} eMmutex_t; 1242 1243typedef struct { 1244 char *eMrw_owner; 1245 char *eMrw_heldin; 1246 u_int eMrw_magic; 1247 short eMrw_read; 1248 short eMrw_write; 1249 int eMrw_heldat; 1250#ifdef __hpux 1251 char eMm_fill[24]; 1252#endif 1253} eMrwlock_t; 1254 1255typedef union { 1256#ifdef KMUTEX_T 1257 struct { 1258 KMUTEX_T ipf_slk; 1259 char *ipf_lname; 1260 } ipf_lkun_s; 1261#endif 1262 eMmutex_t ipf_emu; 1263} ipfmutex_t; 1264 1265typedef union { 1266#ifdef KRWLOCK_T 1267 struct { 1268 KRWLOCK_T ipf_slk; 1269 char *ipf_lname; 1270 int ipf_sr; 1271 int ipf_sw; 1272 u_int ipf_magic; 1273 } ipf_lkun_s; 1274#endif 1275 eMrwlock_t ipf_emu; 1276} ipfrwlock_t; 1277 1278#define ipf_lk ipf_lkun_s.ipf_slk 1279#define ipf_lname ipf_lkun_s.ipf_lname 1280#define ipf_isr ipf_lkun_s.ipf_sr 1281#define ipf_isw ipf_lkun_s.ipf_sw 1282#define ipf_magic ipf_lkun_s.ipf_magic 1283 1284#if !defined(__GNUC__) || \ 1285 (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000)) 1286# ifndef INLINE 1287# define INLINE 1288# endif 1289#else 1290# define INLINE __inline__ 1291#endif 1292 1293#if defined(linux) && defined(_KERNEL) 1294extern INLINE void ipf_read_enter __P((ipfrwlock_t *)); 1295extern INLINE void ipf_write_enter __P((ipfrwlock_t *)); 1296extern INLINE void ipf_rw_exit __P((ipfrwlock_t *)); 1297extern INLINE void ipf_rw_downgrade __P((ipfrwlock_t *)); 1298#endif 1299 1300/* 1301 * In a non-kernel environment, there are a lot of macros that need to be 1302 * filled in to be null-ops or to point to some compatibility function, 1303 * somewhere in userland. 1304 */ 1305#ifndef _KERNEL 1306typedef struct mb_s { 1307 struct mb_s *mb_next; 1308 int mb_len; 1309 u_long mb_buf[2048]; 1310} mb_t; 1311# undef m_next 1312# define m_next mb_next 1313# define MSGDSIZE(x) (x)->mb_len /* XXX - from ipt.c */ 1314# define M_LEN(x) (x)->mb_len 1315# define M_DUPLICATE(x) (x) 1316# define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL) 1317# define MTOD(m, t) ((t)(m)->mb_buf) 1318# define FREE_MB_T(x) 1319# define SLEEP(x,y) 1; 1320# define WAKEUP(x,y) ; 1321# define IPF_PANIC(x,y) ; 1322# define PANIC(x,y) ; 1323# define SPL_NET(x) ; 1324# define SPL_IMP(x) ; 1325# define SPL_X(x) ; 1326# define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a)) 1327# define KMALLOCS(a,b,c) (a) = (b)malloc(c) 1328# define KFREE(x) free(x) 1329# define KFREES(x,s) free(x) 1330# define GETIFP(x, v) get_unit(x,v) 1331# define COPYIN(a,b,c) (bcopy((a), (b), (c)), 0) 1332# define COPYOUT(a,b,c) (bcopy((a), (b), (c)), 0) 1333# define BCOPYIN(a,b,c) (bcopy((a), (b), (c)), 0) 1334# define BCOPYOUT(a,b,c) (bcopy((a), (b), (c)), 0) 1335# define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \ 1336 (b), (l)) 1337# define COPYBACK(m, o, l, b) bcopy((b), \ 1338 MTOD((mb_t *)m, char *) + (o), \ 1339 (l)) 1340# define UIOMOVE(a,b,c,d) ipfuiomove(a,b,c,d) 1341extern void m_copydata __P((mb_t *, int, int, caddr_t)); 1342extern int ipfuiomove __P((caddr_t, int, int, struct uio *)); 1343# ifndef CACHE_HASH 1344# define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \ 1345 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7) 1346# endif 1347 1348# define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu) 1349# define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \ 1350 __FILE__, __LINE__) 1351# define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu) 1352# define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y) 1353# define MUTEX_NUKE(x) bzero((x), sizeof(*(x))) 1354 1355# define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \ 1356 __FILE__, __LINE__) 1357# define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \ 1358 __FILE__, __LINE__) 1359# define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y) 1360# define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu) 1361# define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu) 1362# define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \ 1363 __FILE__, \ 1364 __LINE__) 1365 1366# define USE_MUTEXES 1 1367 1368extern void eMmutex_destroy __P((eMmutex_t *)); 1369extern void eMmutex_enter __P((eMmutex_t *, char *, int)); 1370extern void eMmutex_exit __P((eMmutex_t *)); 1371extern void eMmutex_init __P((eMmutex_t *, char *)); 1372extern void eMrwlock_destroy __P((eMrwlock_t *)); 1373extern void eMrwlock_exit __P((eMrwlock_t *)); 1374extern void eMrwlock_init __P((eMrwlock_t *, char *)); 1375extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int)); 1376extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int)); 1377extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int)); 1378 1379#endif 1380 1381#define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8) 1382 1383#ifndef IP_OFFMASK 1384# define IP_OFFMASK 0x1fff 1385#endif 1386 1387 1388/* 1389 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized 1390 * object. 1391 */ 1392#if BSD > 199306 1393# define USE_QUAD_T 1394# define U_QUAD_T u_quad_t 1395# define QUAD_T quad_t 1396#else /* BSD > 199306 */ 1397# define U_QUAD_T u_long 1398# define QUAD_T long 1399#endif /* BSD > 199306 */ 1400 1401 1402#ifdef USE_INET6 1403# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \ 1404 defined(__osf__) || defined(linux) 1405# include <netinet/ip6.h> 1406# include <netinet/icmp6.h> 1407# if !defined(linux) 1408# if defined(_KERNEL) && !defined(__osf__) 1409# include <netinet6/ip6_var.h> 1410# endif 1411# endif 1412typedef struct ip6_hdr ip6_t; 1413# endif 1414#endif 1415 |
|
321#ifndef MAX | 1416#ifndef MAX |
322#define MAX(a,b) (((a) > (b)) ? (a) : (b)) | 1417# define MAX(a,b) (((a) > (b)) ? (a) : (b)) |
323#endif 324 | 1418#endif 1419 |
1420#if defined(_KERNEL) 1421# ifdef MENTAT 1422# define COPYDATA mb_copydata 1423# define COPYBACK mb_copyback 1424# else 1425# define COPYDATA m_copydata 1426# define COPYBACK m_copyback 1427# endif 1428# if (BSD >= 199306) || defined(__FreeBSD__) 1429# if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \ 1430 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \ 1431 defined(_BSDI_VERSION) 1432# include <vm/vm.h> 1433# endif 1434# if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \ 1435 (__FreeBSD_version >= 300000)) 1436# if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \ 1437 (defined(OpenBSD) && (OpenBSD >= 200111)) 1438# include <uvm/uvm_extern.h> 1439# else 1440# include <vm/vm_extern.h> 1441extern vm_map_t kmem_map; 1442# endif 1443# include <sys/proc.h> 1444# else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */ 1445# include <vm/vm_kern.h> 1446# endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */ 1447 1448# ifdef IPFILTER_M_IPFILTER 1449# include <sys/malloc.h> 1450MALLOC_DECLARE(M_IPFILTER); 1451# define _M_IPF M_IPFILTER 1452# else /* IPFILTER_M_IPFILTER */ 1453# ifdef M_PFIL 1454# define _M_IPF M_PFIL 1455# else 1456# ifdef M_IPFILTER 1457# define _M_IPF M_IPFILTER 1458# else 1459# define _M_IPF M_TEMP 1460# endif /* M_IPFILTER */ 1461# endif /* M_PFIL */ 1462# endif /* IPFILTER_M_IPFILTER */ 1463# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT) 1464# define KMALLOCS(a, b, c) MALLOC((a), b, (c), _M_IPF, M_NOWAIT) 1465# define KFREE(x) FREE((x), _M_IPF) 1466# define KFREES(x,s) FREE((x), _M_IPF) 1467# define UIOMOVE(a,b,c,d) uiomove(a,b,d) 1468# define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0) 1469# define WAKEUP(id,x) wakeup(id+x) 1470# define GETIFP(n, v) ifunit(n) 1471# endif /* (Free)BSD */ 1472 1473# if !defined(USE_MUTEXES) && !defined(SPL_NET) 1474# if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \ 1475 (defined(OpenBSD) && (OpenBSD >= 200006)) 1476# define SPL_NET(x) x = splsoftnet() 1477# else 1478# define SPL_IMP(x) x = splimp() 1479# define SPL_NET(x) x = splnet() 1480# endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */ 1481# define SPL_X(x) (void) splx(x) 1482# endif /* !USE_MUTEXES */ 1483 1484# ifndef FREE_MB_T 1485# define FREE_MB_T(m) m_freem(m) 1486# endif 1487 1488# ifndef MTOD 1489# define MTOD(m,t) mtod(m,t) 1490# endif 1491 1492# ifndef COPYIN 1493# define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1494# define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1495# define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1496# define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0) 1497# endif 1498 1499# ifndef KMALLOC 1500# define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \ 1501 KMEM_NOSLEEP) 1502# define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP) 1503# endif 1504 1505# ifndef GET_MINOR 1506# define GET_MINOR(x) minor(x) 1507# endif 1508# define PANIC(x,y) if (x) panic y 1509#endif /* _KERNEL */ 1510 1511#ifndef IFNAME 1512# define IFNAME(x) ((struct ifnet *)x)->if_name 1513#endif 1514#ifndef COPYIFNAME 1515# define NEED_FRGETIFNAME 1516extern char *fr_getifname __P((struct ifnet *, char *)); 1517# define COPYIFNAME(x, b) \ 1518 fr_getifname((struct ifnet *)x, b) 1519#endif 1520 1521#ifndef ASSERT 1522# define ASSERT(x) 1523#endif 1524 |
|
325/* | 1525/* |
1526 * Because the ctype(3) posix definition, if used "safely" in code everywhere, 1527 * would mean all normal code that walks through strings needed casts. Yuck. 1528 */ 1529#define ISALNUM(x) isalnum((u_char)(x)) 1530#define ISALPHA(x) isalpha((u_char)(x)) 1531#define ISASCII(x) isascii((u_char)(x)) 1532#define ISDIGIT(x) isdigit((u_char)(x)) 1533#define ISPRINT(x) isprint((u_char)(x)) 1534#define ISSPACE(x) isspace((u_char)(x)) 1535#define ISUPPER(x) isupper((u_char)(x)) 1536#define ISXDIGIT(x) isxdigit((u_char)(x)) 1537#define ISLOWER(x) islower((u_char)(x)) 1538#define TOUPPER(x) toupper((u_char)(x)) 1539#define TOLOWER(x) tolower((u_char)(x)) 1540 1541/* 1542 * If mutexes aren't being used, turn all the mutex functions into null-ops. 1543 */ 1544#if !defined(USE_MUTEXES) 1545# define USE_SPL 1 1546# undef RW_DESTROY 1547# undef MUTEX_INIT 1548# undef MUTEX_NUKE 1549# undef MUTEX_DESTROY 1550# define MUTEX_ENTER(x) ; 1551# define READ_ENTER(x) ; 1552# define WRITE_ENTER(x) ; 1553# define MUTEX_DOWNGRADE(x) ; 1554# define RWLOCK_INIT(x, y) ; 1555# define RWLOCK_EXIT(x) ; 1556# define RW_DESTROY(x) ; 1557# define MUTEX_EXIT(x) ; 1558# define MUTEX_INIT(x,y) ; 1559# define MUTEX_DESTROY(x) ; 1560# define MUTEX_NUKE(x) ; 1561#endif /* !USE_MUTEXES */ 1562#ifndef ATOMIC_INC 1563# define ATOMIC_INC(x) (x)++ 1564# define ATOMIC_DEC(x) (x)-- 1565#endif 1566 1567/* 1568 * If there are no atomic operations for bit sizes defined, define them to all 1569 * use a generic one that works for all sizes. 1570 */ 1571#ifndef ATOMIC_INCL 1572# define ATOMIC_INCL ATOMIC_INC 1573# define ATOMIC_INC64 ATOMIC_INC 1574# define ATOMIC_INC32 ATOMIC_INC 1575# define ATOMIC_INC16 ATOMIC_INC 1576# define ATOMIC_DECL ATOMIC_DEC 1577# define ATOMIC_DEC64 ATOMIC_DEC 1578# define ATOMIC_DEC32 ATOMIC_DEC 1579# define ATOMIC_DEC16 ATOMIC_DEC 1580#endif 1581 1582#ifndef HDR_T_PRIVATE 1583typedef struct tcphdr tcphdr_t; 1584typedef struct udphdr udphdr_t; 1585#endif 1586typedef struct icmp icmphdr_t; 1587typedef struct ip ip_t; 1588typedef struct ether_header ether_header_t; 1589typedef struct tcpiphdr tcpiphdr_t; 1590 1591#ifndef FR_GROUPLEN 1592# define FR_GROUPLEN 16 1593#endif 1594 1595#ifdef offsetof 1596# undef offsetof 1597#endif 1598#ifndef offsetof 1599# define offsetof(t,m) (int)((&((t *)0L)->m)) 1600#endif 1601 1602/* 1603 * This set of macros has been brought about because on Tru64 it is not 1604 * possible to easily assign or examine values in a structure that are 1605 * bit fields. 1606 */ 1607#ifndef IP_V 1608# define IP_V(x) (x)->ip_v 1609#endif 1610#ifndef IP_V_A 1611# define IP_V_A(x,y) (x)->ip_v = (y) 1612#endif 1613#ifndef IP_HL 1614# define IP_HL(x) (x)->ip_hl 1615#endif 1616#ifndef IP_HL_A 1617# define IP_HL_A(x,y) (x)->ip_hl = (y) 1618#endif 1619#ifndef TCP_X2 1620# define TCP_X2(x) (x)->th_x2 1621#endif 1622#ifndef TCP_X2_A 1623# define TCP_X2_A(x,y) (x)->th_x2 = (y) 1624#endif 1625#ifndef TCP_OFF 1626# define TCP_OFF(x) (x)->th_off 1627#endif 1628#ifndef TCP_OFF_A 1629# define TCP_OFF_A(x,y) (x)->th_off = (y) 1630#endif 1631#define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h))) 1632 1633 1634/* 1635 * XXX - This is one of those *awful* hacks which nobody likes 1636 */ 1637#ifdef ultrix 1638#define A_A 1639#else 1640#define A_A & 1641#endif 1642 1643#define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\ 1644 TH_ECN|TH_CWR) 1645 1646#if (BSD >= 199306) && !defined(m_act) 1647# define m_act m_nextpkt 1648#endif 1649 1650/* |
|
326 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108. 327 * 328 * Basic Option 329 * 330 * 00000001 - (Reserved 4) 331 * 00111101 - Top Secret 332 * 01011010 - Secret 333 * 10010110 - Confidential --- 17 unchanged lines hidden (view full) --- 351#define IPSO_AUTH_NSA 0x10 352#define IPSO_AUTH_DOE 0x08 353#define IPSO_AUTH_UN 0x06 354#define IPSO_AUTH_FTE 0x01 355 356/* 357 * IP option #defines 358 */ | 1651 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108. 1652 * 1653 * Basic Option 1654 * 1655 * 00000001 - (Reserved 4) 1656 * 00111101 - Top Secret 1657 * 01011010 - Secret 1658 * 10010110 - Confidential --- 17 unchanged lines hidden (view full) --- 1676#define IPSO_AUTH_NSA 0x10 1677#define IPSO_AUTH_DOE 0x08 1678#define IPSO_AUTH_UN 0x06 1679#define IPSO_AUTH_FTE 0x01 1680 1681/* 1682 * IP option #defines 1683 */ |
359/*#define IPOPT_RR 7 */ | 1684#undef IPOPT_RR 1685#define IPOPT_RR 7 1686#undef IPOPT_ZSU |
360#define IPOPT_ZSU 10 /* ZSU */ | 1687#define IPOPT_ZSU 10 /* ZSU */ |
1688#undef IPOPT_MTUP |
|
361#define IPOPT_MTUP 11 /* MTUP */ | 1689#define IPOPT_MTUP 11 /* MTUP */ |
1690#undef IPOPT_MTUR |
|
362#define IPOPT_MTUR 12 /* MTUR */ | 1691#define IPOPT_MTUR 12 /* MTUR */ |
1692#undef IPOPT_ENCODE |
|
363#define IPOPT_ENCODE 15 /* ENCODE */ | 1693#define IPOPT_ENCODE 15 /* ENCODE */ |
364/*#define IPOPT_TS 68 */ | 1694#undef IPOPT_TS 1695#define IPOPT_TS 68 1696#undef IPOPT_TR |
365#define IPOPT_TR 82 /* TR */ | 1697#define IPOPT_TR 82 /* TR */ |
366/*#define IPOPT_SECURITY 130 */ 367/*#define IPOPT_LSRR 131 */ | 1698#undef IPOPT_SECURITY 1699#define IPOPT_SECURITY 130 1700#undef IPOPT_LSRR 1701#define IPOPT_LSRR 131 1702#undef IPOPT_E_SEC |
368#define IPOPT_E_SEC 133 /* E-SEC */ | 1703#define IPOPT_E_SEC 133 /* E-SEC */ |
1704#undef IPOPT_CIPSO |
|
369#define IPOPT_CIPSO 134 /* CIPSO */ | 1705#define IPOPT_CIPSO 134 /* CIPSO */ |
370/*#define IPOPT_SATID 136 */ | 1706#undef IPOPT_SATID 1707#define IPOPT_SATID 136 |
371#ifndef IPOPT_SID 372# define IPOPT_SID IPOPT_SATID 373#endif | 1708#ifndef IPOPT_SID 1709# define IPOPT_SID IPOPT_SATID 1710#endif |
374/*#define IPOPT_SSRR 137 */ | 1711#undef IPOPT_SSRR 1712#define IPOPT_SSRR 137 1713#undef IPOPT_ADDEXT |
375#define IPOPT_ADDEXT 147 /* ADDEXT */ | 1714#define IPOPT_ADDEXT 147 /* ADDEXT */ |
1715#undef IPOPT_VISA |
|
376#define IPOPT_VISA 142 /* VISA */ | 1716#define IPOPT_VISA 142 /* VISA */ |
1717#undef IPOPT_IMITD |
|
377#define IPOPT_IMITD 144 /* IMITD */ | 1718#define IPOPT_IMITD 144 /* IMITD */ |
1719#undef IPOPT_EIP |
|
378#define IPOPT_EIP 145 /* EIP */ | 1720#define IPOPT_EIP 145 /* EIP */ |
1721#undef IPOPT_RTRALRT 1722#define IPOPT_RTRALRT 148 /* RTRALRT */ 1723#undef IPOPT_SDB 1724#define IPOPT_SDB 149 1725#undef IPOPT_NSAPA 1726#define IPOPT_NSAPA 150 1727#undef IPOPT_DPS 1728#define IPOPT_DPS 151 1729#undef IPOPT_UMP 1730#define IPOPT_UMP 152 1731#undef IPOPT_FINN |
|
379#define IPOPT_FINN 205 /* FINN */ 380 | 1732#define IPOPT_FINN 205 /* FINN */ 1733 |
381#ifndef TCPOPT_WSCALE 382# define TCPOPT_WSCALE 3 | 1734#ifndef TCPOPT_EOL 1735# define TCPOPT_EOL 0 |
383#endif | 1736#endif |
384 385/* 386 * Build some macros and #defines to enable the same code to compile anywhere 387 * Well, that's the idea, anyway :-) 388 */ 389#if SOLARIS 390typedef mblk_t mb_t; 391# if SOLARIS2 >= 7 392# ifdef lint 393# define ALIGN32(ptr) (ptr ? 0L : 0L) 394# define ALIGN16(ptr) (ptr ? 0L : 0L) 395# else 396# define ALIGN32(ptr) (ptr) 397# define ALIGN16(ptr) (ptr) 398# endif 399# endif 400#else 401typedef struct mbuf mb_t; 402#endif /* SOLARIS */ 403 404#if !SOLARIS || (SOLARIS2 < 6) || !defined(KERNEL) 405# define ATOMIC_INCL ATOMIC_INC 406# define ATOMIC_INC64 ATOMIC_INC 407# define ATOMIC_INC32 ATOMIC_INC 408# define ATOMIC_INC16 ATOMIC_INC 409# define ATOMIC_DECL ATOMIC_DEC 410# define ATOMIC_DEC64 ATOMIC_DEC 411# define ATOMIC_DEC32 ATOMIC_DEC 412# define ATOMIC_DEC16 ATOMIC_DEC | 1737#ifndef TCPOPT_NOP 1738# define TCPOPT_NOP 1 |
413#endif | 1739#endif |
414#ifdef __sgi 415# define hz HZ 416# include <sys/ksynch.h> 417# define IPF_LOCK_PL plhi 418# include <sys/sema.h> 419#undef kmutex_t 420typedef struct { 421 lock_t *l; 422 int pl; 423} kmutex_t; 424# undef MUTEX_INIT 425# undef MUTEX_DESTROY | 1740#ifndef TCPOPT_MAXSEG 1741# define TCPOPT_MAXSEG 2 |
426#endif | 1742#endif |
427#if defined(__FreeBSD_version) && (__FreeBSD_version >= 500043) 428# include <sys/mutex.h> 429# include <sys/sx.h> 430# include <machine/atomic.h> 431# define USE_MUTEX 1 432# define kmutex_t struct mtx 433# define KRWLOCK_T struct sx 434# define NETBSD_PF | 1743#ifndef TCPOLEN_MAXSEG 1744# define TCPOLEN_MAXSEG 4 |
435#endif | 1745#endif |
436#ifdef KERNEL 437# if SOLARIS 438# if SOLARIS2 >= 6 439# include <sys/atomic.h> 440# if SOLARIS2 == 6 441# define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1) 442# define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1) 443# else 444# define ATOMIC_INCL(x) atomic_add_long(&(x), 1) 445# define ATOMIC_DECL(x) atomic_add_long(&(x), -1) 446# endif 447# define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1) 448# define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1) 449# define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1) 450# define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1) 451# define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1) 452# define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1) 453# else 454# define IRE_CACHE IRE_ROUTE 455# define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \ 456 mutex_exit(&ipf_rw); } 457# define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \ 458 mutex_exit(&ipf_rw); } 459# endif 460# define MUTEX_ENTER(x) mutex_enter(x) 461# define USE_MUTEX 1 462# if 1 463# define KRWLOCK_T krwlock_t 464# define READ_ENTER(x) rw_enter(x, RW_READER) 465# define WRITE_ENTER(x) rw_enter(x, RW_WRITER) 466# define RW_UPGRADE(x) { if (rw_tryupgrade(x) == 0) { \ 467 rw_exit(x); \ 468 rw_enter(x, RW_WRITER); } \ 469 } 470# define MUTEX_DOWNGRADE(x) rw_downgrade(x) 471# define RWLOCK_INIT(x, y, z) rw_init((x), (y), RW_DRIVER, (z)) 472# define RWLOCK_EXIT(x) rw_exit(x) 473# define RW_DESTROY(x) rw_destroy(x) 474# else 475# define KRWLOCK_T kmutex_t 476# define READ_ENTER(x) mutex_enter(x) 477# define WRITE_ENTER(x) mutex_enter(x) 478# define MUTEX_DOWNGRADE(x) ; 479# define RWLOCK_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z)) 480# define RWLOCK_EXIT(x) mutex_exit(x) 481# define RW_DESTROY(x) mutex_destroy(x) 482# endif 483# define MUTEX_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z)) 484# define MUTEX_DESTROY(x) mutex_destroy(x) 485# define MUTEX_EXIT(x) mutex_exit(x) 486# define MTOD(m,t) (t)((m)->b_rptr) 487# define IRCOPY(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 488# define IWCOPY(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 489# define IRCOPYPTR ircopyptr 490# define IWCOPYPTR iwcopyptr 491# define FREE_MB_T(m) freemsg(m) 492# define SPL_NET(x) ; 493# define SPL_IMP(x) ; 494# undef SPL_X 495# define SPL_X(x) ; 496# ifdef sparc 497# define ntohs(x) (x) 498# define ntohl(x) (x) 499# define htons(x) (x) 500# define htonl(x) (x) 501# endif /* sparc */ 502# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 503# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 504# define GET_MINOR(x) getminor(x) 505extern ill_t *get_unit __P((char *, int)); 506# define GETUNIT(n, v) get_unit(n, v) 507# define IFNAME(x) ((ill_t *)x)->ill_name 508# else /* SOLARIS */ 509# if defined(__sgi) 510# define USE_MUTEX 1 511# define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ 512 (x)++; MUTEX_EXIT(&ipf_rw); } 513# define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ 514 (x)--; MUTEX_EXIT(&ipf_rw); } 515# define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL); 516# define KRWLOCK_T kmutex_t 517# define READ_ENTER(x) MUTEX_ENTER(x) 518# define WRITE_ENTER(x) MUTEX_ENTER(x) 519# define RW_UPGRADE(x) ; 520# define MUTEX_DOWNGRADE(x) ; 521# define RWLOCK_EXIT(x) MUTEX_EXIT(x) 522# define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl); 523# define MUTEX_INIT(x,y,z) (x)->l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP) 524# define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->l) 525# else /* __sgi */ 526# if defined(__FreeBSD_version) && (__FreeBSD_version >= 500043) 527# include <sys/mutex.h> 528# include <sys/sx.h> 529# include <machine/atomic.h> 530# define USE_MUTEX 1 531# define kmutex_t struct mtx 532# define KRWLOCK_T struct sx 533# define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ 534 (x)++; MUTEX_EXIT(&ipf_rw); } 535# define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ 536 (x)--; MUTEX_EXIT(&ipf_rw); } 537# define MUTEX_ENTER(x) mtx_lock(x) 538# define READ_ENTER(x) sx_slock(x) 539# define WRITE_ENTER(x) sx_xlock(x) 540# define RW_UPGRADE(x) ; 541# define MUTEX_DOWNGRADE(x) sx_downgrade(x) 542# define RWLOCK_INIT(x, y, z) sx_init((x), (y)) 543# define RWLOCK_EXIT(x) do { \ 544 if ((x)->sx_cnt < 0) \ 545 sx_xunlock(x); \ 546 else \ 547 sx_sunlock(x); \ 548 } while (0) 549# define MUTEX_EXIT(x) mtx_unlock(x) 550# define MUTEX_INIT(x,y,z) mtx_init((x), (y), NULL, MTX_DEF) 551# define MUTEX_DESTROY(x) mtx_destroy(x) 552# else 553# define ATOMIC_INC(x) (x)++ 554# define ATOMIC_DEC(x) (x)-- 555# define MUTEX_ENTER(x) ; 556# define READ_ENTER(x) ; 557# define WRITE_ENTER(x) ; 558# define RW_UPGRADE(x) ; 559# define MUTEX_DOWNGRADE(x) ; 560# define RWLOCK_EXIT(x) ; 561# define MUTEX_EXIT(x) ; 562# define MUTEX_INIT(x,y,z) ; 563# define MUTEX_DESTROY(x) ; 564# endif 565# endif /* __sgi */ 566# ifndef linux 567# define FREE_MB_T(m) m_freem(m) 568# define MTOD(m,t) mtod(m,t) 569# define M_BLEN(m) (m)->m_len 570# define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 571# define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 572# define IRCOPYPTR ircopyptr 573# define IWCOPYPTR iwcopyptr 574# endif /* !linux */ 575# endif /* SOLARIS */ | 1746#ifndef TCPOPT_WINDOW 1747# define TCPOPT_WINDOW 3 1748#endif 1749#ifndef TCPOLEN_WINDOW 1750# define TCPOLEN_WINDOW 3 1751#endif 1752#ifndef TCPOPT_SACK_PERMITTED 1753# define TCPOPT_SACK_PERMITTED 4 1754#endif 1755#ifndef TCPOLEN_SACK_PERMITTED 1756# define TCPOLEN_SACK_PERMITTED 2 1757#endif 1758#ifndef TCPOPT_SACK 1759# define TCPOPT_SACK 5 1760#endif 1761#ifndef TCPOPT_TIMESTAMP 1762# define TCPOPT_TIMESTAMP 8 1763#endif |
576 | 1764 |
577# ifdef sun 578# if !SOLARIS 579# include <sys/time.h> 580# include <sys/kmem_alloc.h> 581# define GETUNIT(n, v) ifunit(n, IFNAMSIZ) 582# define IFNAME(x) ((struct ifnet *)x)->if_name 583# endif 584# else 585# ifndef linux 586# define GETUNIT(n, v) ifunit(n) 587# if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ 588 (defined(OpenBSD) && (OpenBSD >= 199603)) || \ 589 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) 590# define IFNAME(x) ((struct ifnet *)x)->if_xname 591# else 592# define USE_GETIFNAME 1 593# define IFNAME(x) get_ifname((struct ifnet *)x) 594extern char *get_ifname __P((struct ifnet *)); 595# endif 596# endif 597# endif /* sun */ 598 599# if defined(sun) && !defined(linux) || defined(__sgi) 600# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 601# define SLEEP(id, n) sleep((id), PZERO+1) 602# define WAKEUP(id) wakeup(id) 603# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 604# define KFREES(x,s) kmem_free((char *)(x), (s)) 605# if !SOLARIS 606extern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 607extern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 608# endif 609# ifdef __sgi 610# include <sys/kmem.h> 611# include <sys/ddi.h> 612# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 613# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 614# define GET_MINOR(x) getminor(x) 615# else 616# if !SOLARIS 617# define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \ 618 KMEM_NOSLEEP) 619# define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP) 620# endif /* SOLARIS */ 621# endif /* __sgi */ 622# endif /* sun && !linux */ 623# ifndef GET_MINOR 624# define GET_MINOR(x) minor(x) 625# endif 626# if (BSD >= 199306) || defined(__FreeBSD__) 627# if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \ 628 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \ 629 defined(_BSDI_VERSION) 630# include <vm/vm.h> 631# endif 632# if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \ 633 (__FreeBSD_version >= 300000)) 634# if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \ 635 (defined(OpenBSD) && (OpenBSD >= 200111)) 636# include <uvm/uvm_extern.h> 637# else 638# include <vm/vm_extern.h> 639extern vm_map_t kmem_map; 640# endif 641# include <sys/proc.h> 642# else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */ 643# include <vm/vm_kern.h> 644# endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */ 645# ifdef M_PFIL 646# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT) 647# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT) 648# define KFREE(x) FREE((x), M_PFIL) 649# define KFREES(x,s) FREE((x), M_PFIL) 650# else 651# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT) 652# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT) 653# define KFREE(x) FREE((x), M_TEMP) 654# define KFREES(x,s) FREE((x), M_TEMP) 655# endif /* M_PFIL */ 656# define UIOMOVE(a,b,c,d) uiomove(a,b,d) 657# define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0) 658# define WAKEUP(id) wakeup(id) 659# endif /* BSD */ 660# if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \ 661 (defined(OpenBSD) && (OpenBSD >= 200006)) 662# define SPL_NET(x) x = splsoftnet() 663# define SPL_X(x) (void) splx(x) 664# else 665# if !SOLARIS && !defined(linux) 666# define SPL_IMP(x) x = splimp() 667# define SPL_NET(x) x = splnet() 668# define SPL_X(x) (void) splx(x) 669# endif 670# endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */ 671# define PANIC(x,y) if (x) panic y 672#else /* KERNEL */ 673# define SLEEP(x,y) 1 674# define WAKEUP(x) ; 675# define PANIC(x,y) ; 676# define ATOMIC_INC(x) (x)++ 677# define ATOMIC_DEC(x) (x)-- 678# define MUTEX_ENTER(x) ; 679# define READ_ENTER(x) ; 680# define MUTEX_INIT(x,y,z) ; 681# define MUTEX_DESTROY(x) ; 682# define WRITE_ENTER(x) ; 683# define RW_UPGRADE(x) ; 684# define MUTEX_DOWNGRADE(x) ; 685# define RWLOCK_EXIT(x) ; 686# define MUTEX_EXIT(x) ; 687# define SPL_NET(x) ; 688# define SPL_IMP(x) ; 689# undef SPL_X 690# define SPL_X(x) ; 691# define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a)) 692# define KMALLOCS(a,b,c) (a) = (b)malloc(c) 693# define KFREE(x) free(x) 694# define KFREES(x,s) free(x) 695# define FREE_MB_T(x) ; 696# define GETUNIT(x, v) get_unit(x,v) 697# define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 698# define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 699# define IRCOPYPTR ircopyptr 700# define IWCOPYPTR iwcopyptr 701# define IFNAME(x) get_ifname((struct ifnet *)x) 702# define UIOMOVE(a,b,c,d) ipfuiomove(a,b,c,d) 703# include <sys/time.h> 704extern void m_copydata __P((mb_t *, int, int, caddr_t)); 705extern int ipfuiomove __P((caddr_t, int, int, struct uio *)); 706#endif /* KERNEL */ 707 708/* 709 * These #ifdef's are here mainly for linux, but who knows, they may 710 * not be in other places or maybe one day linux will grow up and some 711 * of these will turn up there too. 712 */ | |
713#ifndef ICMP_MINLEN 714# define ICMP_MINLEN 8 715#endif 716#ifndef ICMP_ECHOREPLY 717# define ICMP_ECHOREPLY 0 718#endif 719#ifndef ICMP_UNREACH 720# define ICMP_UNREACH 3 --- 35 unchanged lines hidden (view full) --- 756# define ICMP_UNREACH_TOSNET 11 757#endif 758#ifndef ICMP_UNREACH_TOSHOST 759# define ICMP_UNREACH_TOSHOST 12 760#endif 761#ifndef ICMP_UNREACH_ADMIN_PROHIBIT 762# define ICMP_UNREACH_ADMIN_PROHIBIT 13 763#endif | 1765#ifndef ICMP_MINLEN 1766# define ICMP_MINLEN 8 1767#endif 1768#ifndef ICMP_ECHOREPLY 1769# define ICMP_ECHOREPLY 0 1770#endif 1771#ifndef ICMP_UNREACH 1772# define ICMP_UNREACH 3 --- 35 unchanged lines hidden (view full) --- 1808# define ICMP_UNREACH_TOSNET 11 1809#endif 1810#ifndef ICMP_UNREACH_TOSHOST 1811# define ICMP_UNREACH_TOSHOST 12 1812#endif 1813#ifndef ICMP_UNREACH_ADMIN_PROHIBIT 1814# define ICMP_UNREACH_ADMIN_PROHIBIT 13 1815#endif |
1816#ifndef ICMP_UNREACH_FILTER 1817# define ICMP_UNREACH_FILTER 13 1818#endif |
|
764#ifndef ICMP_UNREACH_HOST_PRECEDENCE 765# define ICMP_UNREACH_HOST_PRECEDENCE 14 766#endif 767#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF 768# define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 769#endif 770#ifndef ICMP_SOURCEQUENCH 771# define ICMP_SOURCEQUENCH 4 --- 122 unchanged lines hidden (view full) --- 894# define TH_PUSH 0x08 895#endif 896#ifndef TH_ACK 897# define TH_ACK 0x10 898#endif 899#ifndef TH_URG 900# define TH_URG 0x20 901#endif | 1819#ifndef ICMP_UNREACH_HOST_PRECEDENCE 1820# define ICMP_UNREACH_HOST_PRECEDENCE 14 1821#endif 1822#ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF 1823# define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 1824#endif 1825#ifndef ICMP_SOURCEQUENCH 1826# define ICMP_SOURCEQUENCH 4 --- 122 unchanged lines hidden (view full) --- 1949# define TH_PUSH 0x08 1950#endif 1951#ifndef TH_ACK 1952# define TH_ACK 0x10 1953#endif 1954#ifndef TH_URG 1955# define TH_URG 0x20 1956#endif |
1957#undef TH_ACKMASK 1958#define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK) 1959 |
|
902#ifndef IPOPT_EOL 903# define IPOPT_EOL 0 904#endif 905#ifndef IPOPT_NOP 906# define IPOPT_NOP 1 907#endif 908#ifndef IPOPT_RR 909# define IPOPT_RR 7 --- 32 unchanged lines hidden (view full) --- 942# define IPOPT_SECUR_SECRET ((u_short)0xd788) 943#endif 944#ifndef IPOPT_SECUR_TOPSECRET 945# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) 946#endif 947#ifndef IPOPT_OLEN 948# define IPOPT_OLEN 1 949#endif | 1960#ifndef IPOPT_EOL 1961# define IPOPT_EOL 0 1962#endif 1963#ifndef IPOPT_NOP 1964# define IPOPT_NOP 1 1965#endif 1966#ifndef IPOPT_RR 1967# define IPOPT_RR 7 --- 32 unchanged lines hidden (view full) --- 2000# define IPOPT_SECUR_SECRET ((u_short)0xd788) 2001#endif 2002#ifndef IPOPT_SECUR_TOPSECRET 2003# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) 2004#endif 2005#ifndef IPOPT_OLEN 2006# define IPOPT_OLEN 1 2007#endif |
2008#ifndef IPPROTO_HOPOPTS 2009# define IPPROTO_HOPOPTS 0 2010#endif 2011#ifndef IPPROTO_ENCAP 2012# define IPPROTO_ENCAP 4 2013#endif 2014#ifndef IPPROTO_IPV6 2015# define IPPROTO_IPV6 41 2016#endif 2017#ifndef IPPROTO_ROUTING 2018# define IPPROTO_ROUTING 43 2019#endif 2020#ifndef IPPROTO_FRAGMENT 2021# define IPPROTO_FRAGMENT 44 2022#endif |
|
950#ifndef IPPROTO_GRE 951# define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */ 952#endif 953#ifndef IPPROTO_ESP 954# define IPPROTO_ESP 50 955#endif | 2023#ifndef IPPROTO_GRE 2024# define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */ 2025#endif 2026#ifndef IPPROTO_ESP 2027# define IPPROTO_ESP 50 2028#endif |
2029#ifndef IPPROTO_AH 2030# define IPPROTO_AH 51 2031#endif |
|
956#ifndef IPPROTO_ICMPV6 957# define IPPROTO_ICMPV6 58 958#endif | 2032#ifndef IPPROTO_ICMPV6 2033# define IPPROTO_ICMPV6 58 2034#endif |
959 960#ifdef linux 961#include <linux/in_systm.h> 962/* 963 * TCP States 964 */ 965#define TCPS_CLOSED 0 /* closed */ 966#define TCPS_LISTEN 1 /* listening for connection */ 967#define TCPS_SYN_SENT 2 /* active, have sent syn */ 968#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ 969/* states < TCPS_ESTABLISHED are those where connections not established */ 970#define TCPS_ESTABLISHED 4 /* established */ 971#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 972/* states > TCPS_CLOSE_WAIT are those where user has closed */ 973#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 974#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 975#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 976/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 977#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 978#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 979 980/* 981 * file flags. 982 */ 983#ifdef WRITE 984#define FWRITE WRITE 985#define FREAD READ 986#else 987#define FWRITE _IOC_WRITE 988#define FREAD _IOC_READ | 2035#ifndef IPPROTO_NONE 2036# define IPPROTO_NONE 59 |
989#endif | 2037#endif |
990/* 991 * mbuf related problems. 992 */ 993#define mtod(m,t) (t)((m)->data) 994#define m_len len 995#define m_next next 996 997#ifdef IP_DF 998#undef IP_DF | 2038#ifndef IPPROTO_DSTOPTS 2039# define IPPROTO_DSTOPTS 60 |
999#endif | 2040#endif |
1000#define IP_DF 0x4000 1001 1002typedef struct { 1003 __u16 th_sport; 1004 __u16 th_dport; 1005 __u32 th_seq; 1006 __u32 th_ack; 1007# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 1008 defined(__vax__) 1009 __u8 th_res:4; 1010 __u8 th_off:4; 1011#else 1012 __u8 th_off:4; 1013 __u8 th_res:4; | 2041#ifndef IPPROTO_FRAGMENT 2042# define IPPROTO_FRAGMENT 44 |
1014#endif | 2043#endif |
1015 __u8 th_flags; 1016 __u16 th_win; 1017 __u16 th_sum; 1018 __u16 th_urp; 1019} tcphdr_t; 1020 1021typedef struct { 1022 __u16 uh_sport; 1023 __u16 uh_dport; 1024 __u16 uh_ulen; 1025 __u16 uh_sum; 1026} udphdr_t; 1027 1028typedef struct { 1029# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 1030 defined(__vax__) 1031 __u8 ip_hl:4; 1032 __u8 ip_v:4; 1033# else 1034 __u8 ip_v:4; 1035 __u8 ip_hl:4; 1036# endif 1037 __u8 ip_tos; 1038 __u16 ip_len; 1039 __u16 ip_id; 1040 __u16 ip_off; 1041 __u8 ip_ttl; 1042 __u8 ip_p; 1043 __u16 ip_sum; 1044 struct in_addr ip_src; 1045 struct in_addr ip_dst; 1046} ip_t; 1047 1048/* 1049 * Structure of an icmp header. 1050 */ 1051typedef struct icmp { 1052 __u8 icmp_type; /* type of message, see below */ 1053 __u8 icmp_code; /* type sub code */ 1054 __u16 icmp_cksum; /* ones complement cksum of struct */ 1055 union { 1056 __u8 ih_pptr; /* ICMP_PARAMPROB */ 1057 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 1058 struct ih_idseq { 1059 __u16 icd_id; 1060 __u16 icd_seq; 1061 } ih_idseq; 1062 int ih_void; 1063 } icmp_hun; 1064# define icmp_pptr icmp_hun.ih_pptr 1065# define icmp_gwaddr icmp_hun.ih_gwaddr 1066# define icmp_id icmp_hun.ih_idseq.icd_id 1067# define icmp_seq icmp_hun.ih_idseq.icd_seq 1068# define icmp_void icmp_hun.ih_void 1069 union { 1070 struct id_ts { 1071 n_time its_otime; 1072 n_time its_rtime; 1073 n_time its_ttime; 1074 } id_ts; 1075 struct id_ip { 1076 ip_t idi_ip; 1077 /* options and then 64 bits of data */ 1078 } id_ip; 1079 u_long id_mask; 1080 char id_data[1]; 1081 } icmp_dun; 1082# define icmp_otime icmp_dun.id_ts.its_otime 1083# define icmp_rtime icmp_dun.id_ts.its_rtime 1084# define icmp_ttime icmp_dun.id_ts.its_ttime 1085# define icmp_ip icmp_dun.id_ip.idi_ip 1086# define icmp_mask icmp_dun.id_mask 1087# define icmp_data icmp_dun.id_data 1088} icmphdr_t; 1089 1090# ifndef LINUX_IPOVLY 1091# define LINUX_IPOVLY 1092struct ipovly { 1093 caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 1094 u_char ih_x1; /* (unused) */ 1095 u_char ih_pr; /* protocol */ 1096 short ih_len; /* protocol length */ 1097 struct in_addr ih_src; /* source internet address */ 1098 struct in_addr ih_dst; /* destination internet address */ 1099}; 1100# endif 1101 1102typedef struct { 1103 __u8 ether_dhost[6]; 1104 __u8 ether_shost[6]; 1105 __u16 ether_type; 1106} ether_header_t; 1107 1108typedef struct uio { 1109 int uio_resid; 1110 int uio_rw; 1111 caddr_t uio_buf; 1112} uio_t; 1113 1114# define UIO_READ 0 1115# define UIO_WRITE 1 1116# define UIOMOVE(a, b, c, d) uiomove(a,b,c,d) 1117 1118/* 1119 * For masking struct ifnet onto struct device 1120 */ 1121# define if_name name 1122 1123# ifdef KERNEL 1124# define GETUNIT(x, v) dev_get(x) 1125# define FREE_MB_T(m) kfree_skb(m, FREE_WRITE) 1126# define uniqtime do_gettimeofday 1127# undef INT_MAX 1128# undef UINT_MAX 1129# undef LONG_MAX 1130# undef ULONG_MAX 1131# include <linux/netdevice.h> 1132# define SPL_X(x) 1133# define SPL_NET(x) 1134# define SPL_IMP(x) 1135 1136# define bcmp(a,b,c) memcmp(a,b,c) 1137# define bcopy(a,b,c) memcpy(b,a,c) 1138# define bzero(a,c) memset(a,0,c) 1139 1140# define UNITNAME(n) dev_get((n)) 1141 1142# define KMALLOC(a,b) (a) = (b)kmalloc(sizeof(*(a)), GFP_ATOMIC) 1143# define KMALLOCS(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC) 1144# define KFREE(x) kfree_s((x), sizeof(*(x))) 1145# define KFREES(x,s) kfree_s((x), (s)) 1146#define IRCOPY(const void *a, void *b, size_t c) { \ 1147 int error; \ 1148 1149 error = verify_area(VERIFY_READ, a ,c); \ 1150 if (!error) \ 1151 memcpy_fromfs(b, a, c); \ 1152 return error; \ 1153} 1154static inline int IWCOPY(const void *a, void *b, size_t c) 1155{ 1156 int error; 1157 1158 error = verify_area(VERIFY_WRITE, b, c); 1159 if (!error) 1160 memcpy_tofs(b, a, c); 1161 return error; 1162} 1163static inline int IRCOPYPTR(const void *a, void *b, size_t c) { 1164 caddr_t ca; 1165 int error; 1166 1167 error = verify_area(VERIFY_READ, a ,sizeof(ca)); 1168 if (!error) { 1169 memcpy_fromfs(ca, a, sizeof(ca)); 1170 error = verify_area(VERIFY_READ, ca , c); 1171 if (!error) 1172 memcpy_fromfs(b, ca, c); 1173 } 1174 return error; 1175} 1176static inline int IWCOPYPTR(const void *a, void *b, size_t c) { 1177 caddr_t ca; 1178 int error; 1179 1180 1181 error = verify_area(VERIFY_READ, b ,sizeof(ca)); 1182 if (!error) { 1183 memcpy_fromfs(ca, b, sizeof(ca)); 1184 error = verify_area(VERIFY_WRITE, ca, c); 1185 if (!error) 1186 memcpy_tofs(ca, a, c); 1187 } 1188 return error; 1189} 1190# else 1191# define __KERNEL__ 1192# undef INT_MAX 1193# undef UINT_MAX 1194# undef LONG_MAX 1195# undef ULONG_MAX 1196# define s8 __s8 1197# define u8 __u8 1198# define s16 __s16 1199# define u16 __u16 1200# define s32 __s32 1201# define u32 __u32 1202# include <linux/netdevice.h> 1203# undef __KERNEL__ 1204# endif 1205# define ifnet device 1206#else 1207typedef struct tcphdr tcphdr_t; 1208typedef struct udphdr udphdr_t; 1209typedef struct icmp icmphdr_t; 1210typedef struct ip ip_t; 1211typedef struct ether_header ether_header_t; 1212#endif /* linux */ 1213typedef struct tcpiphdr tcpiphdr_t; 1214 1215#if defined(hpux) || defined(linux) 1216struct ether_addr { 1217 char ether_addr_octet[6]; 1218}; 1219#endif 1220 1221/* 1222 * XXX - This is one of those *awful* hacks which nobody likes 1223 */ 1224#ifdef ultrix 1225#define A_A 1226#else 1227#define A_A & 1228#endif 1229 1230#if (BSD >= 199306) && !defined(m_act) 1231# define m_act m_nextpkt 1232#endif 1233 | |
1234#ifndef ICMP_ROUTERADVERT 1235# define ICMP_ROUTERADVERT 9 1236#endif 1237#ifndef ICMP_ROUTERSOLICIT 1238# define ICMP_ROUTERSOLICIT 10 1239#endif | 2044#ifndef ICMP_ROUTERADVERT 2045# define ICMP_ROUTERADVERT 9 2046#endif 2047#ifndef ICMP_ROUTERSOLICIT 2048# define ICMP_ROUTERSOLICIT 10 2049#endif |
1240#undef ICMP_MAX_UNREACH 1241#define ICMP_MAX_UNREACH 14 1242#undef ICMP_MAXTYPE 1243#define ICMP_MAXTYPE 18 1244/* 1245 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data, 1246 * another IP header and then 64 bits of data, totalling 56. Of course, 1247 * the last 64 bits is dependant on that being available. 1248 */ 1249#define ICMPERR_ICMPHLEN 8 1250#define ICMPERR_IPICMPHLEN (20 + 8) 1251#define ICMPERR_MINPKTLEN (20 + 8 + 20) 1252#define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8) 1253#define ICMP6_MINLEN 8 1254#define ICMP6ERR_IPICMPHLEN (40 + 8) 1255#define ICMP6ERR_MINPKTLEN (40 + 8 + 40) 1256 | |
1257#ifndef ICMP6_DST_UNREACH 1258# define ICMP6_DST_UNREACH 1 1259#endif 1260#ifndef ICMP6_PACKET_TOO_BIG 1261# define ICMP6_PACKET_TOO_BIG 2 1262#endif 1263#ifndef ICMP6_TIME_EXCEEDED 1264# define ICMP6_TIME_EXCEEDED 3 --- 155 unchanged lines hidden (view full) --- 1420#ifndef TH_ECN 1421# define TH_ECN 0x40 1422#endif 1423#ifndef TH_CWR 1424# define TH_CWR 0x80 1425#endif 1426#define TH_ECNALL (TH_ECN|TH_CWR) 1427 | 2050#ifndef ICMP6_DST_UNREACH 2051# define ICMP6_DST_UNREACH 1 2052#endif 2053#ifndef ICMP6_PACKET_TOO_BIG 2054# define ICMP6_PACKET_TOO_BIG 2 2055#endif 2056#ifndef ICMP6_TIME_EXCEEDED 2057# define ICMP6_TIME_EXCEEDED 3 --- 155 unchanged lines hidden (view full) --- 2213#ifndef TH_ECN 2214# define TH_ECN 0x40 2215#endif 2216#ifndef TH_CWR 2217# define TH_CWR 0x80 2218#endif 2219#define TH_ECNALL (TH_ECN|TH_CWR) 2220 |
1428#define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECN|TH_CWR) | 2221/* 2222 * TCP States 2223 */ 2224#define IPF_TCPS_CLOSED 0 /* closed */ 2225#define IPF_TCPS_LISTEN 1 /* listening for connection */ 2226#define IPF_TCPS_SYN_SENT 2 /* active, have sent syn */ 2227#define IPF_TCPS_SYN_RECEIVED 3 /* have send and received syn */ 2228#define IPF_TCPS_HALF_ESTAB 4 /* for connections not fully "up" */ 2229/* states < IPF_TCPS_ESTABLISHED are those where connections not established */ 2230#define IPF_TCPS_ESTABLISHED 5 /* established */ 2231#define IPF_TCPS_CLOSE_WAIT 6 /* rcvd fin, waiting for close */ 2232/* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */ 2233#define IPF_TCPS_FIN_WAIT_1 7 /* have closed, sent fin */ 2234#define IPF_TCPS_CLOSING 8 /* closed xchd FIN; await FIN ACK */ 2235#define IPF_TCPS_LAST_ACK 9 /* had fin and close; await FIN ACK */ 2236/* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */ 2237#define IPF_TCPS_FIN_WAIT_2 10 /* have closed, fin is acked */ 2238#define IPF_TCPS_TIME_WAIT 11 /* in 2*msl quiet wait after close */ 2239#define IPF_TCP_NSTATES 12 |
1429 | 2240 |
2241#define TCP_MSL 120 2242 2243#undef ICMP_MAX_UNREACH 2244#define ICMP_MAX_UNREACH 14 2245#undef ICMP_MAXTYPE 2246#define ICMP_MAXTYPE 18 2247 2248#ifndef IFNAMSIZ 2249#define IFNAMSIZ 16 2250#endif 2251 2252#ifndef LOG_FTP 2253# define LOG_FTP (11<<3) 2254#endif 2255#ifndef LOG_AUTHPRIV 2256# define LOG_AUTHPRIV (10<<3) 2257#endif 2258#ifndef LOG_AUDIT 2259# define LOG_AUDIT (13<<3) 2260#endif 2261#ifndef LOG_NTP 2262# define LOG_NTP (12<<3) 2263#endif 2264#ifndef LOG_SECURITY 2265# define LOG_SECURITY (13<<3) 2266#endif 2267#ifndef LOG_LFMT 2268# define LOG_LFMT (14<<3) 2269#endif 2270#ifndef LOG_CONSOLE 2271# define LOG_CONSOLE (14<<3) 2272#endif 2273 2274/* 2275 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data, 2276 * another IP header and then 64 bits of data, totalling 56. Of course, 2277 * the last 64 bits is dependant on that being available. 2278 */ 2279#define ICMPERR_ICMPHLEN 8 2280#define ICMPERR_IPICMPHLEN (20 + 8) 2281#define ICMPERR_MINPKTLEN (20 + 8 + 20) 2282#define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8) 2283#define ICMP6ERR_MINPKTLEN (40 + 8) 2284#define ICMP6ERR_IPICMPHLEN (40 + 8 + 40) 2285 2286#ifndef MIN 2287# define MIN(a,b) (((a)<(b))?(a):(b)) 2288#endif 2289 2290#ifdef IPF_DEBUG 2291# define DPRINT(x) printf x 2292#else 2293# define DPRINT(x) 2294#endif 2295 |
|
1430#endif /* __IP_COMPAT_H__ */ | 2296#endif /* __IP_COMPAT_H__ */ |