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