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