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