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