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