2 * Copyright (C) 2012 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * @(#)ip_compat.h 1.8 1/14/96
10 #ifndef __IP_COMPAT_H__
11 #define __IP_COMPAT_H__
25 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
35 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
37 #if (defined(SOLARIS2) && (SOLARIS2 >= 8))
42 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
43 !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
46 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \
47 !defined(_KERNEL) && !defined(USE_INET6)
50 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 106140000) && \
52 (!defined(IPFILTER_LKM) || (__NetBSD_Version__ >= 399000100))
53 # define IPFILTER_M_IPFILTER
55 #if !defined(USE_INET6)
56 # if defined(OpenBSD) && (OpenBSD >= 200206) && \
57 !defined(_KERNEL) && !defined(USE_INET6)
63 # if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6))
66 # if defined(HPUXREV) && (HPUXREV >= 1111)
71 #if defined(BSD) && (BSD < 199103) && defined(__osf__)
76 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
78 # if !defined(_KERNEL)
79 # define bzero(a,b) memset(a,0,b)
81 # define bcopy(a,b,c) memmove(b,a,c)
87 # define LIFNAMSIZ IF_NAMESIZE
90 # define LIFNAMSIZ IFNAMSIZ
97 #if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
99 u_char ether_addr_octet[6];
103 #if defined(__sgi) && !defined(IPFILTER_LKM)
105 # define IPL_EXTERN(ep) ipfilter##ep
107 # define IPL_EXTERN(ep) ipfilter/**/ep
111 # define IPL_EXTERN(ep) ipl##ep
113 # define IPL_EXTERN(ep) ipl/**/ep
118 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
129 # include <sys/uio.h>
136 #define NETBSD_GE_REV(x) (defined(__NetBSD_Version__) && \
137 (__NetBSD_Version__ >= (x)))
138 #define NETBSD_GT_REV(x) (defined(__NetBSD_Version__) && \
139 (__NetBSD_Version__ > (x)))
140 #define NETBSD_LT_REV(x) (defined(__NetBSD_Version__) && \
141 (__NetBSD_Version__ < (x)))
142 #define FREEBSD_GE_REV(x) (defined(__FreeBSD_version) && \
143 (__FreeBSD_version >= (x)))
144 #define FREEBSD_GT_REV(x) (defined(__FreeBSD_version) && \
145 (__FreeBSD_version > (x)))
146 #define FREEBSD_LT_REV(x) (defined(__FreeBSD_version) && \
147 (__FreeBSD_version < (x)))
148 #define BSDOS_GE_REV(x) (defined(_BSDI_VERSION) && \
149 (_BSDI_VERSION >= (x)))
150 #define BSDOS_GT_REV(x) (defined(_BSDI_VERSION) && \
151 (_BSDI_VERSION > (x)))
152 #define BSDOS_LT_REV(x) (defined(_BSDI_VERSION) && \
153 (_BSDI_VERSION < (x)))
154 #define OPENBSD_GE_REV(x) (defined(OpenBSD) && (OpenBSD >= (x)))
155 #define OPENBSD_GT_REV(x) (defined(OpenBSD) && (OpenBSD > (x)))
156 #define OPENBSD_LT_REV(x) (defined(OpenBSD) && (OpenBSD < (x)))
157 #define BSD_GE_YEAR(x) (defined(BSD) && (BSD >= (x)))
158 #define BSD_GT_YEAR(x) (defined(BSD) && (BSD > (x)))
159 #define BSD_LT_YEAR(x) (defined(BSD) && (BSD < (x)))
162 /* ----------------------------------------------------------------------- */
164 /* ----------------------------------------------------------------------- */
167 # include <sys/cmn_err.h>
168 # include <sys/isa_defs.h>
169 # include <sys/stream.h>
170 # include <sys/ioccom.h>
171 # include <sys/sysmacros.h>
172 # include <sys/kmem.h>
174 # include <sys/procset.h>
175 # include <sys/proc.h>
176 # include <sys/devops.h>
177 # include <sys/ddi_impldefs.h>
178 # include <sys/sdt.h>
181 * because Solaris 2 defines these in two places :-/
187 # endif /* _KERNEL */
190 # include <netinet/ip6.h>
191 # include <netinet/icmp6.h>
194 # include <inet/common.h>
195 /* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */
202 # define _SYS_PROMIF_H
207 # include <inet/mib2.h>
208 # include <inet/ip.h>
210 # if !defined(_SYS_NETI_H)
211 # include <inet/ip_ire.h>
214 # define SNPRINTF snprintf
216 # include <inet/ip_if.h>
217 # define ipif_local_addr ipif_lcl_addr
218 /* Only defined in private include file */
219 # ifndef V4_PART_OF_V6
220 # define V4_PART_OF_V6(v6) v6.s6_addr32[3]
226 # endif /* SOLARIS2 >= 8 */
229 # include <sys/atomic.h>
230 typedef uint8_t u_int8_t;
231 typedef uint32_t u_32_t;
233 typedef unsigned char u_int8_t;
234 typedef unsigned int u_32_t;
238 # define USE_QUAD_T 1
239 # define U_QUAD_T uint64_t
240 # define QUAD_T int64_t
244 # define NEED_LOCAL_RAND 1
245 # define KRWLOCK_T krwlock_t
246 # define KMUTEX_T kmutex_t
247 # if !defined(FW_HOOKS)
253 # define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1)
254 # define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1)
256 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
257 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
258 # endif /* SOLARIS2 == 6 */
259 # define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1)
260 # define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1)
261 # define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1)
262 # define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1)
264 # define ATOMIC_INC(x) { mutex_enter(&softc->ipf_rw); (x)++; \
265 mutex_exit(&softc->ipf_rw); }
266 # define ATOMIC_DEC(x) { mutex_enter(&softc->ipf_rw); (x)--; \
267 mutex_exit(&softc->ipf_rw); }
268 # endif /* SOLARIS2 >= 6 */
270 # define MUTEX_ENTER(x) mutex_enter(&(x)->ipf_lk)
271 # define READ_ENTER(x) rw_enter(&(x)->ipf_lk, RW_READER)
272 # define WRITE_ENTER(x) rw_enter(&(x)->ipf_lk, RW_WRITER)
273 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
274 # define RWLOCK_INIT(x, y) rw_init(&(x)->ipf_lk, (y), \
276 # define RWLOCK_EXIT(x) rw_exit(&(x)->ipf_lk)
277 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
278 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, (y), \
280 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk)
281 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
282 # define MUTEX_EXIT(x) mutex_exit(&(x)->ipf_lk)
283 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
284 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
285 # define BCOPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
286 # define BCOPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
287 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
288 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
289 # define KFREES(x,s) kmem_free((char *)(x), (s))
290 # define SPL_SCHED(x) ;
291 # define SPL_NET(x) ;
292 # define SPL_IMP(x) ;
296 # define ntohs(x) (x)
297 # define ntohl(x) (x)
298 # define htons(x) (x)
299 # define htonl(x) (x)
301 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
302 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
303 # define GET_MINOR(x) getminor(x)
304 extern void *get_unit __P((void *, char *, int));
305 # define GETIFP(n, v) get_unit(softc, n, v)
306 # if defined(INSTANCES)
307 # include <sys/hook.h>
308 # include <sys/neti.h>
309 typedef struct qpktinfo {
310 void *qpi_real; /* the real one on the STREAM */
311 void *qpi_ill; /* COPIED */
314 void *qpi_data; /* where layer 3 header starts */
316 int qpi_flags; /* COPIED */
319 #define QF_MULTICAST 0x0001
320 #define QF_BROADCAST 0x0002
322 typedef struct qifpkt {
323 struct qifpkt *qp_next;
324 char qp_ifname[LIFNAMSIZ];
330 # define COPYIFNAME(v, x,b) \
333 net_getifname(softc->ipf_nd_v4, \
337 net_getifname(softc->ipf_nd_v6, \
342 # define GETIFMTU_4(x) net_getmtu(softc->ipf_nd_v4, (phy_if_t)x, 0)
343 # define GETIFMTU_6(x) net_getmtu(softc->ipf_nd_v6, (phy_if_t)x, 0)
344 # define GET_SOFTC(x) ipf_find_softc(x)
346 # define FASTROUTE_RECURSION 1
347 # define GET_SOFTC(x) &ipfmain
348 # define GETIFMTU_4(x) ((qif_t *)x)->qf_max_frag
349 # define GETIFMTU_6(x) ((qif_t *)x)->qf_max_frag
350 # define IFNAME(x) ((qif_t *)x)->qf_name
351 # define COPYIFNAME(v, x, b) \
352 (void) strncpy(b, ((qif_t *)x)->qf_name, \
355 # define GETKTIME(x) uniqtime((struct timeval *)x)
356 # define MSGDSIZE(m) msgdsize(m)
357 # define M_LEN(m) ((m)->b_wptr - (m)->b_rptr)
358 # define M_ADJ(m,x) adjmsg(m, x)
359 # define M_COPY(x) dupmsg((x))
360 # define MTOD(m,t) ((t)((m)->b_rptr))
361 # define MTYPE(m) ((m)->b_datap->db_type)
362 # define FREE_MB_T(m) freemsg(m)
363 # define ALLOC_MB_T(m,l) (m) = allocmbt(l)
364 # define PREP_MB_T(f,m) ipf_prependmbt(f, m)
365 # define M_DUP(m) copymsg(m)
366 # define m_next b_cont
367 # define IPF_PANIC(x,y) if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
369 extern void mb_copydata __P((mblk_t *, size_t, size_t, char *));
370 extern void mb_copyback __P((mblk_t *, size_t, size_t, char *));
371 # endif /* _KERNEL */
375 # define ALIGN32(ptr) (ptr ? 0L : 0L)
376 # define ALIGN16(ptr) (ptr ? 0L : 0L)
378 # define ALIGN32(ptr) (ptr)
379 # define ALIGN16(ptr) (ptr)
384 typedef struct uio uio_t;
386 typedef int ioctlcmd_t;
388 # define OS_RECOGNISED 1
392 /* ----------------------------------------------------------------------- */
394 /* ----------------------------------------------------------------------- */
397 # include <sys/sysmacros.h>
398 # include <sys/spinlock.h>
399 # include <sys/lock.h>
400 # include <sys/stream.h>
402 # include <netinet/if_ether.h>
403 # include <netinet/ip6.h>
404 # include <netinet/icmp6.h>
405 typedef struct ip6_hdr ip6_t;
409 # define FASTROUTE_RECURSION 1
410 # define SNPRINTF sprintf
411 # if (HPUXREV >= 1111)
414 # include <machine/sys/user.h>
415 # include <sys/kthread_iface.h>
416 # define READ_COLLISION 0x01
418 typedef struct iplog_select_s {
419 kthread_t *read_waiter;
425 # define GETKTIME(x) uniqtime((struct timeval *)x)
428 # include "kern_svcs.h"
430 # include <sys/kern_svcs.h>
435 # include <sys/reg.h>
436 # include "../netinet/ip_info.h"
438 * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
439 * are available. Attempting to use them actually results in unresolved
440 * symbols when it comes time to load the module.
441 * This has been fixed! Yipee!
445 # define ATOMIC_INCL(x) lock_and_incr_int64(&softc->ipf_rw.ipf_lk, &(x), 1)
446 # define ATOMIC_DECL(x) lock_and_incr_int64(&softc->ipf_rw.ipf_lk, &(x), -1)
448 # define ATOMIC_INCL(x) lock_and_incr_int32(&softc->ipf_rw.ipf_lk, &(x), 1)
449 # define ATOMIC_DECL(x) lock_and_incr_int32(&softc->ipf_rw.ipf_lk, &(x), -1)
451 # define ATOMIC_INC64(x) lock_and_incr_int64(&softc->ipf_rw.ipf_lk, &(x), 1)
452 # define ATOMIC_INC32(x) lock_and_incr_int32(&softc->ipf_rw.ipf_lk, &(x), 1)
453 # define ATOMIC_DEC64(x) lock_and_incr_int64(&softc->ipf_rw.ipf_lk, &(x), -1)
454 # define ATOMIC_DEC32(x) lock_and_incr_int32(&softc->ipf_rw.ipf_lk, &(x), -1)
456 # define ATOMIC_INC64(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
457 MUTEX_EXIT(&softc->ipf_rw); }
458 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
459 MUTEX_EXIT(&softc->ipf_rw); }
460 # define ATOMIC_INC32(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
461 MUTEX_EXIT(&softc->ipf_rw); }
462 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
463 MUTEX_EXIT(&softc->ipf_rw); }
464 # define ATOMIC_INCL(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
465 MUTEX_EXIT(&softc->ipf_rw); }
466 # define ATOMIC_DECL(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
467 MUTEX_EXIT(&softc->ipf_rw); }
468 # define ATOMIC_INC(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
469 MUTEX_EXIT(&softc->ipf_rw); }
470 # define ATOMIC_DEC(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
471 MUTEX_EXIT(&softc->ipf_rw); }
473 # define ip_cksum ip_csuma
474 # define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c)
476 # define MUTEX_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, (y))
477 # define MUTEX_ENTER(x) spinlock(&(x)->ipf_lk)
478 # define MUTEX_EXIT(x) spinunlock(&(x)->ipf_lk);
479 # define MUTEX_DESTROY(x)
480 # define MUTEX_NUKE(x) bzero((char *)(x), sizeof(*(x)))
481 # define KMUTEX_T lock_t
482 # define kmutex_t lock_t /* for pfil.h */
483 # define krwlock_t lock_t /* for pfil.h */
485 * The read-write lock implementation in HP-UX 11.0 is crippled - it can
486 * only be used by threads working in a user context!
487 * This has been fixed! Yipee! (Or at least it does in 11.00, not 11.11..)
490 # define MUTEX_DOWNGRADE(x) lock_write_to_read(x)
491 # define KRWLOCK_T struct rw_lock
492 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
493 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
495 # define RWLOCK_INIT(x, y) rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
497 # define RWLOCK_INIT(x, y) lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
499 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
501 # define KRWLOCK_T lock_t
502 # define KMUTEX_T lock_t
503 # define READ_ENTER(x) MUTEX_ENTER(x)
504 # define WRITE_ENTER(x) MUTEX_ENTER(x)
505 # define MUTEX_DOWNGRADE(x)
506 # define RWLOCK_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, y)
507 # define RWLOCK_EXIT(x) MUTEX_EXIT(x)
509 # define RW_DESTROY(x)
510 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
511 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
512 # define SPL_SCHED(x) ;
513 # define SPL_NET(x) ;
514 # define SPL_IMP(x) ;
517 extern void *get_unit __P((char *, int));
518 # define GETIFP(n, v) get_unit(n, v)
519 # define GETIFMTU_4(x) ((ill_t *)x)->ill_mtu
520 # define GETIFMTU_6(x) ((ill_t *)x)->ill_mtu
521 # define IFNAME(x, b) ((ill_t *)x)->ill_name
522 # define COPYIFNAME(v, x, b) \
523 (void) strncpy(b, ((qif_t *)x)->qf_name, \
525 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
526 # define SLEEP(id, n) { lock_t *_l = get_sleep_lock((caddr_t)id); \
527 sleep(id, PZERO+1); \
530 # define WAKEUP(id,x) { lock_t *_l = get_sleep_lock((caddr_t)id); \
534 # define POLLWAKEUP(x) ;
535 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
536 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
537 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
538 # define KFREES(x,s) kmem_free((char *)(x), (s))
539 # define MSGDSIZE(m) msgdsize(m)
540 # define M_ADJ(m,x) adjmsg(m, x)
541 # define M_LEN(m) ((m)->b_wptr - (m)->b_rptr)
542 # define M_COPY(m) copymsg((m))
543 # define M_DUP(m) dupmsg(m)
544 # define MTOD(m,t) ((t)((m)->b_rptr))
545 # define MTYPE(m) ((m)->b_datap->db_type)
546 # define FREE_MB_T(m) freemsg(m)
547 # define m_next b_cont
548 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
556 typedef unsigned char uchar_t;
558 # ifndef _SYS_STREAM_INCLUDED
559 typedef char * mblk_t;
560 typedef void * queue_t;
561 typedef u_long ulong;
563 # include <netinet/ip_info.h>
565 # endif /* _KERNEL */
568 # define ALIGN32(ptr) (ptr ? 0L : 0L)
569 # define ALIGN16(ptr) (ptr ? 0L : 0L)
571 # define ALIGN32(ptr) (ptr)
572 # define ALIGN16(ptr) (ptr)
575 typedef struct uio uio_t;
576 typedef int ioctlcmd_t;
578 typedef unsigned int u_32_t;
581 # define OS_RECOGNISED 1
585 /* ----------------------------------------------------------------------- */
587 /* ----------------------------------------------------------------------- */
591 typedef struct uio uio_t;
593 typedef int ioctlcmd_t;
594 typedef u_int32_t u_32_t;
602 # include <sys/ksynch.h>
603 # define IPF_LOCK_PL plhi
604 # include <sys/sema.h>
612 # define KMUTEX_T mutex_t
614 # define KMUTEX_T kmutex_t
615 # define KRWLOCK_T kmutex_t
619 # define NEED_LOCAL_RAND 1
620 # define ATOMIC_INC(x) { MUTEX_ENTER(&softc->ipf_rw); \
621 (x)++; MUTEX_EXIT(&softc->ipf_rw); }
622 # define ATOMIC_DEC(x) { MUTEX_ENTER(&softc->ipf_rw); \
623 (x)--; MUTEX_EXIT(&softc->ipf_rw); }
626 # include <sys/atomic_ops.h>
627 # define ATOMIC_INCL(x) atomicAddUlong(&(x), 1)
628 # define ATOMIC_INC64(x) atomicAddUint64(&(x), 1)
629 # define ATOMIC_INC32(x) atomicAddUint(&(x), 1)
630 # define ATOMIC_DECL(x) atomicAddUlong(&(x), -1)
631 # define ATOMIC_DEC64(x) atomicAddUint64(&(x), -1)
632 # define ATOMIC_DEC32(x) atomicAddUint(&(x), -1)
634 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, \
637 # define MUTEX_ENTER(x) mutex_lock(&(x)->ipf_lk, 0)
639 # define MUTEX_EXIT(x) mutex_unlock(&(x)->ipf_lk)
640 # undef MUTEX_DESTROY
641 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk)
642 # define MUTEX_DOWNGRADE(x) mrdemote(&(x)->ipf_lk)
643 # define KRWLOCK_T mrlock_t
644 # define RWLOCK_INIT(x, y) mrinit(&(x)->ipf_lk, y)
646 # define RW_DESTROY(x) mrfree(&(x)->ipf_lk)
647 # define READ_ENTER(x) RW_RDLOCK(&(x)->ipf_lk)
648 # define WRITE_ENTER(x) RW_WRLOCK(&(x)->ipf_lk)
649 # define RWLOCK_EXIT(x) RW_UNLOCK(&(x)->ipf_lk)
651 # define READ_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
652 # define WRITE_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
653 # define MUTEX_DOWNGRADE(x) ;
654 # define RWLOCK_EXIT(x) MUTEX_EXIT(&(x)->ipf_lk)
655 # define MUTEX_EXIT(x) UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
656 # define MUTEX_INIT(x,y) (x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
657 # define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->ipf_lk.l)
658 # define MUTEX_ENTER(x) (x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
661 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
662 # define FREE_MB_T(m) m_freem(m)
663 # define MTOD(m,t) mtod(m,t)
664 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
665 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
666 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
667 # define SLEEP(id, n) sleep((id), PZERO+1)
668 # define WAKEUP(id,x) wakeup(id+x)
669 # define POLLWAKEUP(x) ;
670 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
671 # define KFREES(x,s) kmem_free((char *)(x), (s))
672 # define GETIFP(n,v) ifunit(n)
673 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
674 # define GETIFMTU_6(x) ((struct ifnet *)x)->if_mtu
675 # include <sys/kmem.h>
676 # include <sys/ddi.h>
677 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
678 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
679 # define GET_MINOR(x) getminor(x)
681 # define SPL_IMP(x) (x) = splimp()
682 # define SPL_NET(x) (x) = splnet()
683 # define SPL_SCHED(x) (x) = splsched()
684 # define SPL_X(x) (void) splx(x)
685 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
686 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
687 # define MSGDSIZE(m) mbufchainlen(m)
688 # define M_ADJ(m,x) m_adj(m, x)
689 # define M_LEN(x) (x)->m_len
690 # define M_COPY(m) m_copy((m), 0, M_COPYALL)
691 # define GETKTIME(x) microtime((struct timeval *)x)
692 # define IFNAME(x) ((struct ifnet *)x)->if_name
693 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
694 typedef struct mbuf mb_t;
698 # undef MUTEX_DESTROY
699 # endif /* _KERNEL */
701 # define OS_RECOGNISED 1
705 /* ----------------------------------------------------------------------- */
707 /* ----------------------------------------------------------------------- */
711 # include <kern/lock.h>
712 # include <sys/sysmacros.h>
715 # define NEED_LOCAL_RAND 1
716 # define KMUTEX_T simple_lock_data_t
717 # define KRWLOCK_T lock_data_t
718 # include <net/net_globals.h>
720 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
721 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
722 # define MUTEX_DOWNGRADE(x) lock_write_to_read(&(x)->ipf_lk)
723 # define RWLOCK_INIT(x, y) lock_init(&(x)->ipf_lk, TRUE)
724 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
725 # define RW_DESTROY(x) lock_terminate(&(x)->ipf_lk)
726 # define MUTEX_ENTER(x) simple_lock(&(x)->ipf_lk)
727 # define MUTEX_INIT(x, y) simple_lock_init(&(x)->ipf_lk)
728 # define MUTEX_DESTROY(x) simple_lock_terminate(&(x)->ipf_lk)
729 # define MUTEX_EXIT(x) simple_unlock(&(x)->ipf_lk)
730 # define MUTEX_NUKE(x) bzero(x, sizeof(*(x)))
731 # define ATOMIC_INC64(x) atomic_incq((uint64_t*)&(x))
732 # define ATOMIC_DEC64(x) atomic_decq((uint64_t*)&(x))
733 # define ATOMIC_INC32(x) atomic_incl((uint32_t*)&(x))
734 # define ATOMIC_DEC32(x) atomic_decl((uint32_t*)&(x))
735 # define ATOMIC_INCL(x) atomic_incl((uint32_t*)&(x))
736 # define ATOMIC_DECL(x) atomic_decl((uint32_t*)&(x))
737 # define ATOMIC_INC(x) { simple_lock(&softc->ipf_rw); (x)++; \
738 simple_unlock(&softc->ipf_rw); }
739 # define ATOMIC_DEC(x) { simple_lock(&softc->ipf_rw); (x)--; \
740 simple_unlock(&softc->ipf_rw); }
741 # define SPL_SCHED(x) ;
742 # define SPL_NET(x) ;
743 # define SPL_IMP(x) ;
746 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a, b, d)
747 # define FREE_MB_T(m) m_freem(m)
748 # define MTOD(m,t) mtod(m,t)
749 # define GETIFP(n, v) ifunit(n)
750 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
751 # define GETIFMTU_6(x) ((struct ifnet *)x)->if_mtu
752 # define GET_MINOR getminor
753 # define WAKEUP(id,x) wakeup(id + x)
754 # define POLLWAKEUP(x) ;
755 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
756 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
757 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
758 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFILT, \
759 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
760 # define KFREE(x) FREE((x), M_PFILT)
761 # define KFREES(x,s) FREE((x), M_PFILT)
762 # define MSGDSIZE(m) mbufchainlen(m)
763 # define M_LEN(m) (m)->m_len
764 # define M_ADJ(m,x) m_adj(m, x)
765 # define M_COPY(m) m_copy((m), 0, M_COPYALL)
766 # define M_DUP(m) m_copy((m), 0, M_COPYALL)
767 # define GETKTIME(x) microtime((struct timeval *)x)
768 # define IFNAME(x) ((struct ifnet *)x)->if_name
769 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
770 # define selinfo sel_queue
771 typedef struct mbuf mb_t;
772 # endif /* _KERNEL */
774 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
775 # define IP_V(x) ((x)->ip_vhl >> 4)
776 # define IP_HL(x) ((x)->ip_vhl & 0xf)
777 # define IP_V_A(x,y) (x)->ip_vhl |= (((y) << 4) & 0xf0)
778 # define IP_HL_A(x,y) (x)->ip_vhl |= ((y) & 0xf)
779 # define TCP_X2(x) ((x)->th_xoff & 0xf)
780 # define TCP_X2_A(x,y) (x)->th_xoff |= ((y) & 0xf)
781 # define TCP_OFF(x) ((x)->th_xoff >> 4)
782 # define TCP_OFF_A(x,y) (x)->th_xoff |= (((y) << 4) & 0xf0)
785 # define ip6_vfc ip6_vcf
789 * These are from's Solaris' #defines for little endian.
791 #define IP6F_MORE_FRAG 0x0100
792 #define IP6F_RESERVED_MASK 0x0600
793 #define IP6F_OFF_MASK 0xf8ff
800 typedef int ioctlcmd_t;
802 * Really, any arch where sizeof(long) != sizeof(int).
804 typedef unsigned int u_32_t;
807 # define OS_RECOGNISED 1
810 /* ----------------------------------------------------------------------- */
812 /* ----------------------------------------------------------------------- */
814 # define HAS_SYS_MD5_H 1
815 # if (NetBSD >= 199905) && !defined(IPFILTER_LKM) && defined(_KERNEL)
816 # if (__NetBSD_Version__ < 399001400)
817 # include "opt_ipfilter_log.h"
819 # include "opt_ipfilter.h"
822 # if defined(_KERNEL)
823 # include <sys/systm.h>
824 # include <sys/malloc.h>
825 # if (__NetBSD_Version__ > 500000000)
826 # include <sys/kauth.h>
830 # include <stdbool.h>
832 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
833 # include "bpfilter.h"
834 # if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
835 # include "opt_inet.h"
840 # if (__NetBSD_Version__ >= 105000000)
841 # define HAVE_M_PULLDOWN 1
845 # if (__NetBSD_Version__ >= 499000000)
846 typedef char * caddr_t;
848 # include <sys/rwlock.h>
849 # define USE_MUTEXES 1
850 # define KMUTEX_T kmutex_t
851 # define KRWLOCK_T krwlock_t
852 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk)
853 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
854 # define MUTEX_ENTER(x) mutex_enter(&(x)->ipf_lk)
855 # define MUTEX_EXIT(x) mutex_exit(&(x)->ipf_lk)
856 # define MUTEX_INIT(x,y) mutex_init(&(x)->ipf_lk, MUTEX_DRIVER,\
858 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
859 # define READ_ENTER(x) rw_enter(&(x)->ipf_lk, RW_READER)
860 # define RWLOCK_INIT(x, y) rw_init(&(x)->ipf_lk)
861 # define RWLOCK_EXIT(x) rw_exit(&(x)->ipf_lk)
862 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
863 # define WRITE_ENTER(x) rw_enter(&(x)->ipf_lk, RW_WRITER)
864 # define SPL_SCHED(x) ;
865 # define SPL_NET(x) ;
866 # define SPL_IMP(x) ;
872 # if (__NetBSD_Version__ >= 399001400)
873 # include <sys/selinfo.h> /* Not in NetBSD 3.1 */
874 # define PROC_T struct lwp
875 # define KFREE(a) free((a), _M_IPF)
876 # define KFREES(a, b) free((a), _M_IPF)
877 # define KMALLOC(a, b) (a) = (b)malloc(sizeof (*(a)), \
879 # define KMALLOCS(a, b, c) (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
881 # define PROC_T struct proc
883 # define MSGDSIZE(m) mbufchainlen(m)
884 # define M_LEN(m) (m)->m_len
885 # define M_ADJ(m,x) m_adj(m, x)
886 # define M_COPY(x) m_copy((x), 0, M_COPYALL)
887 # define GETKTIME(x) microtime((struct timeval *)x)
888 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
889 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
890 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
891 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 499004900))
892 # define POLLWAKEUP(x) selnotify(softc->ipf_selwait+x, 0, 0)
894 typedef struct mbuf mb_t;
895 # endif /* _KERNEL */
896 # if (NetBSD <= 1991011) && (NetBSD >= 199606)
897 # define IFNAME(x) ((struct ifnet *)x)->if_xname
898 # define COPYIFNAME(v, x, b) \
900 ((struct ifnet *)x)->if_xname, \
903 # define IFNAME(x) ((struct ifnet *)x)->if_name
905 typedef struct uio uio_t;
906 typedef u_long ioctlcmd_t;
908 typedef u_int32_t u_32_t;
911 # define OS_RECOGNISED 1
912 #endif /* __NetBSD__ */
915 /* ----------------------------------------------------------------------- */
917 /* ----------------------------------------------------------------------- */
919 # if (__FreeBSD_version < 400000)
920 # define NEED_LOCAL_RAND 1
922 # if defined(_KERNEL)
923 # if (__FreeBSD_version >= 500000)
924 # include "opt_bpf.h"
926 # if defined(__FreeBSD_version) && (__FreeBSD_version >= 500000)
927 # include "opt_inet6.h"
929 # if defined(INET6) && !defined(USE_INET6)
934 # if defined(_KERNEL)
935 # include <netinet/ip_var.h>
936 # if (__FreeBSD_version >= 500024)
937 # if (__FreeBSD_version >= 500043)
938 # define p_cred td_ucred
939 # define p_uid td_ucred->cr_ruid
941 # define p_cred t_proc->p_cred
942 # define p_uid t_proc->p_cred->p_ruid
945 # define p_uid p_cred->p_ruid
946 # endif /* __FreeBSD_version >= 500024 */
948 # if (__FreeBSD_version >= 400000)
950 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
951 * There may be other, safe, kernels but this is not extensively tested yet.
953 # define HAVE_M_PULLDOWN
955 # if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
956 # include "opt_ipfilter.h"
958 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
959 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
961 # if (__FreeBSD_version >= 500043)
965 # include <inttypes.h>
966 # endif /* _KERNEL */
968 # if (__FreeBSD_version >= 700000)
969 # include <sys/selinfo.h>
971 # if (__FreeBSD_version >= 500043)
972 # include <sys/mutex.h>
973 # if (__FreeBSD_version >= 700014)
974 # define KRWLOCK_FILL_SZ 36
975 # define KMUTEX_FILL_SZ 24
976 # include <sys/rwlock.h>
978 # define KMUTEX_T struct mtx
979 # define KRWLOCK_T struct rwlock
980 # define READ_ENTER(x) rw_rlock(&(x)->ipf_lk)
981 # define WRITE_ENTER(x) rw_wlock(&(x)->ipf_lk)
982 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
983 # define RWLOCK_INIT(x,y) rw_init(&(x)->ipf_lk, (y))
984 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
985 # define RWLOCK_EXIT(x) do { \
986 if (rw_wowned(&(x)->ipf_lk)) \
987 rw_wunlock(&(x)->ipf_lk); \
989 rw_runlock(&(x)->ipf_lk); \
995 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
996 * for what we want to use them for, despite testing showing they work -
997 * with a WITNESS kernel, it generates LOR messages.
999 # if (__FreeBSD_version < 700000)
1001 # define KMUTEX_T struct mtx
1002 # define KRWLOCK_T struct mtx
1003 # define READ_ENTER(x) mtx_lock(&(x)->ipf_lk)
1004 # define WRITE_ENTER(x) mtx_lock(&(x)->ipf_lk)
1005 # define RWLOCK_EXIT(x) mtx_unlock(&(x)->ipf_lk)
1006 # define MUTEX_DOWNGRADE(x) ;
1007 # define RWLOCK_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
1009 # define RW_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
1013 # define KRWLOCK_T struct sx
1014 # define KMUTEX_T struct mtx
1015 # define READ_ENTER(x) sx_slock(&(x)->ipf_lk)
1016 # define WRITE_ENTER(x) sx_xlock(&(x)->ipf_lk)
1017 # define MUTEX_DOWNGRADE(x) sx_downgrade(&(x)->ipf_lk)
1018 # define RWLOCK_INIT(x, y) sx_init(&(x)->ipf_lk, (y))
1019 # define RW_DESTROY(x) sx_destroy(&(x)->ipf_lk)
1021 # define RWLOCK_EXIT(x) sx_unlock(&(x)->ipf_lk)
1023 # define RWLOCK_EXIT(x) do { \
1024 if ((x)->ipf_lk.sx_cnt < 0) \
1025 sx_xunlock(&(x)->ipf_lk); \
1027 sx_sunlock(&(x)->ipf_lk); \
1035 # if (__FreeBSD_version >= 501113)
1036 # include <net/if_var.h>
1037 # define IFNAME(x) ((struct ifnet *)x)->if_xname
1038 # define COPYIFNAME(v, x, b) \
1040 ((struct ifnet *)x)->if_xname, \
1043 # if (__FreeBSD_version >= 500043)
1045 # define IFNAME(x) ((struct ifnet *)x)->if_name
1049 # define GETKTIME(x) microtime((struct timeval *)x)
1051 # if (__FreeBSD_version >= 500002)
1052 # include <netinet/in_systm.h>
1053 # include <netinet/ip.h>
1054 # include <machine/in_cksum.h>
1057 # if (__FreeBSD_version >= 500043)
1058 # define USE_MUTEXES
1059 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk)
1060 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk)
1061 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
1063 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
1064 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
1066 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
1067 * for what we want to use them for, despite testing showing they work -
1068 * with a WITNESS kernel, it generates LOR messages.
1070 # include <machine/atomic.h>
1071 # define ATOMIC_INC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)++; \
1072 mtx_unlock(&softc->ipf_rw.ipf_lk); }
1073 # define ATOMIC_DEC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)--; \
1074 mtx_unlock(&softc->ipf_rw.ipf_lk); }
1075 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
1076 # define ATOMIC_INC64(x) ATOMIC_INC(x)
1077 # define ATOMIC_INC32(x) atomic_add_32((u_int *)&(x), 1)
1078 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
1079 # define ATOMIC_DEC64(x) ATOMIC_DEC(x)
1080 # define ATOMIC_DEC32(x) atomic_add_32((u_int *)&(x), -1)
1082 # define SPL_NET(x) ;
1083 # define SPL_IMP(x) ;
1084 # define SPL_SCHED(x) ;
1085 extern int in_cksum __P((struct mbuf *, int));
1087 # define SPL_SCHED(x) x = splhigh()
1088 # endif /* __FreeBSD_version >= 500043 */
1089 # if (__FreeBSD_version >= 500024)
1090 # define GET_MINOR dev2unit
1092 # define MSGDSIZE(m) mbufchainlen(m)
1093 # define M_LEN(m) (m)->m_len
1094 # define M_ADJ(m,x) m_adj(m, x)
1095 # define M_COPY(x) m_copy((x), 0, M_COPYALL)
1096 # define M_DUP(m) m_dup(m, M_NOWAIT)
1097 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1098 typedef struct mbuf mb_t;
1099 # endif /* _KERNEL */
1101 # if __FreeBSD__ < 3
1102 # include <machine/spl.h>
1104 # if __FreeBSD__ == 3
1105 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
1106 # define ACTUALLY_LKM_NOT_KERNEL
1111 # if (__FreeBSD_version >= 300000)
1112 typedef u_long ioctlcmd_t;
1114 typedef int ioctlcmd_t;
1116 typedef struct uio uio_t;
1117 typedef int minor_t;
1118 typedef u_int32_t u_32_t;
1121 # define OS_RECOGNISED 1
1122 #endif /* __FreeBSD__ */
1125 /* ----------------------------------------------------------------------- */
1127 /* ----------------------------------------------------------------------- */
1134 # if !defined(IPFILTER_LKM)
1135 # include "bpfilter.h"
1137 # if (OpenBSD >= 200311)
1138 # define SNPRINTF snprintf
1139 # if defined(USE_INET6)
1140 # include "netinet6/in6_var.h"
1141 # include "netinet6/nd6.h"
1144 # if (OpenBSD >= 200012)
1145 # define HAVE_M_PULLDOWN 1
1147 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
1148 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
1149 # define GETKTIME(x) microtime((struct timeval *)x)
1150 # define MSGDSIZE(m) mbufchainlen(m)
1151 # define M_LEN(m) (m)->m_len
1152 # define M_ADJ(m,x) m_adj(m, x)
1153 # define M_COPY(m) m_copy((m), 0, M_COPYALL)
1154 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1155 typedef struct mbuf mb_t;
1156 # endif /* _KERNEL */
1157 # if (OpenBSD >= 199603)
1158 # define IFNAME(x, b) ((struct ifnet *)x)->if_xname
1159 # define COPYIFNAME(v, x, b) \
1161 ((struct ifnet *)x)->if_xname, \
1164 # define IFNAME(x) ((struct ifnet *)x)->if_name
1166 typedef struct uio uio_t;
1167 typedef u_long ioctlcmd_t;
1168 typedef int minor_t;
1169 typedef u_int32_t u_32_t;
1172 # define OS_RECOGNISED 1
1173 #endif /* __OpenBSD__ */
1176 /* ----------------------------------------------------------------------- */
1178 /* ----------------------------------------------------------------------- */
1179 #ifdef _BSDI_VERSION
1185 # define GETKTIME(x) microtime((struct timeval *)x)
1186 # define MSGDSIZE(m) mbufchainlen(m)
1187 # define M_LEN(m) (m)->m_len
1188 # define M_ADJ(m,x) m_adj(m, x)
1189 # define M_COPY(m) m_copy((m), 0, M_COPYALL)
1190 # define IFNAME(x) ((struct ifnet *)x)->if_name
1191 typedef struct mbuf mb_t;
1192 # endif /* _KERNEL */
1194 # if (_BSDI_VERSION >= 199701)
1195 typedef u_long ioctlcmd_t;
1197 typedef int ioctlcmd_t;
1199 typedef u_int32_t u_32_t;
1202 #endif /* _BSDI_VERSION */
1205 /* ----------------------------------------------------------------------- */
1207 /* ----------------------------------------------------------------------- */
1208 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1210 # include <sys/kmem_alloc.h>
1211 # define GETKTIME(x) uniqtime((struct timeval *)x)
1212 # define MSGDSIZE(m) mbufchainlen(m)
1213 # define M_LEN(m) (m)->m_len
1214 # define M_ADJ(m,x) m_adj(m, x)
1215 # define M_COPY(m) m_copy((m), 0, M_COPYALL)
1216 # define IFNAME(x) ((struct ifnet *)x)->if_name
1217 # define GETIFP(n, v) ifunit(n, IFNAMSIZ)
1218 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
1219 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
1220 # define KFREES(x,s) kmem_free((char *)(x), (s))
1221 # define SLEEP(id, n) sleep((id), PZERO+1)
1222 # define WAKEUP(id,x) wakeup(id + x)
1223 # define POLLWAKEUP(x) ;
1224 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1225 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1227 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
1228 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
1230 typedef struct mbuf mb_t;
1233 typedef struct uio uio_t;
1234 typedef int ioctlcmd_t;
1235 typedef int minor_t;
1236 typedef unsigned int u_32_t;
1239 # define OS_RECOGNISED 1
1241 #endif /* SunOS 4 */
1243 /* ----------------------------------------------------------------------- */
1245 /* ----------------------------------------------------------------------- */
1246 #if defined(linux) && !defined(OS_RECOGNISED)
1247 # include <linux/version.h>
1248 # if (LINUX >= 20600) && defined(_KERNEL)
1249 # define HDR_T_PRIVATE 1
1260 # include <asm/byteorder.h>
1261 # ifdef __LITTLE_ENDIAN
1262 # define BIG_ENDIAN 0
1263 # define LITTLE_ENDIAN 1
1264 # define BYTE_ORDER LITTLE_ENDIAN
1266 # define BIG_ENDIAN 1
1267 # define LITTLE_ENDIAN 0
1268 # define BYTE_ORDER BIG_ENDIAN
1270 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1271 # define COPYIN(a,b,c) copy_from_user((caddr_t)(b), (caddr_t)(a), (c))
1272 # define COPYOUT(a,b,c) copy_to_user((caddr_t)(b), (caddr_t)(a), (c))
1273 # define FREE_MB_T(m) kfree_skb(m)
1274 # define GETKTIME(x) do_gettimeofday((struct timeval *)x)
1275 # define POLLWAKEUP(x) ;
1276 # ifdef wait_event_interruptible
1277 # define SLEEP(x,s) wait_event_interruptible((*(x##_linux)), 0)
1279 # define SLEEP(x,s) 0, interruptible_sleep_on(x##_linux)
1281 # define WAKEUP(x,y) wake_up(x##_linux + y)
1282 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1283 # define USE_MUTEXES
1284 # define KRWLOCK_T rwlock_t
1285 # define KMUTEX_T spinlock_t
1286 # define MUTEX_INIT(x,y) spin_lock_init(&(x)->ipf_lk)
1287 # define MUTEX_ENTER(x) spin_lock_bh(&(x)->ipf_lk)
1288 # define MUTEX_EXIT(x) spin_unlock_bh(&(x)->ipf_lk)
1289 # define MUTEX_DESTROY(x) do { } while (0)
1290 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1291 # define READ_ENTER(x) ipf_read_enter(x)
1292 # define WRITE_ENTER(x) ipf_write_enter(x)
1293 # define RWLOCK_INIT(x,y) ipf_rw_init(x, y)
1294 # define RW_DESTROY(x) do { } while (0)
1295 # define RWLOCK_EXIT(x) ipf_rw_exit(x)
1296 # define MUTEX_DOWNGRADE(x) ipf_rw_downgrade(x)
1297 # define ATOMIC_INCL(x) atomic_long_inc((atomic_long_t *)&(x))
1298 # define ATOMIC_DECL(x) atomic_long_dec((atomic_long_t *)&(x))
1299 # define ATOMIC_INC32(x) atomic_inc((atomic_t *)&(x))
1300 # define ATOMIC_DEC32(x) atomic_dec((atomic_t *)&(x))
1301 # ifdef CONFIG_X86_32
1302 # define ATOMIC_INC64(x) do { MUTEX_ENTER(&softc->ipf_rw); \
1304 MUTEX_EXIT(&softc->ipf_rw); \
1306 # define ATOMIC_DEC64(x) do { MUTEX_ENTER(&softc->ipf_rw); \
1308 MUTEX_EXIT(&softc->ipf_rw); \
1311 # define ATOMIC_INC64(x) atomic64_inc((atomic64_t *)&(x))
1312 # define ATOMIC_DEC64(x) atomic64_dec((atomic64_t *)&(x))
1314 # define U_QUAD_T u_int64_t
1315 # define QUAD_T int64_t
1316 # define SPL_SCHED(x) do { } while (0)
1317 # define SPL_IMP(x) do { } while (0)
1318 # define SPL_NET(x) do { } while (0)
1319 # define SPL_X(x) do { } while (0)
1320 # define IFNAME(x) ((struct net_device*)x)->name
1321 typedef struct sk_buff mb_t;
1322 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1323 extern void m_copyback __P((mb_t *, int, int, caddr_t));
1324 extern void m_adj __P((mb_t *, int));
1325 extern mb_t *m_pullup __P((mb_t *, int));
1326 # define mbuf sk_buff
1328 # define mtod(m, t) ((t)(m)->data)
1329 # define m_adj(m, x) skb_trim((m), (m)->len + (x))
1330 # define m_data data
1332 # define m_next next
1333 # define M_COPY(m) skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1335 # define MSGDSIZE(m) (m)->len
1336 # define M_LEN(m) (m)->len
1337 # define M_ADJ(m,x) m_adj(m, x)
1338 # define M_DUP(m) skb_copy((m), in_interrupt() ? GFP_ATOMIC : \
1340 # define PREP_MB_T(f, m) do { \
1341 (m)->next = *(f)->fin_mp; \
1342 *(fin)->fin_mp = (m); \
1345 # define ALLOC_MB_T(m,l) (m) = alloc_skb((l), \
1346 in_interrupt() ? GFP_ATOMIC : \
1349 # define splnet(x) ;
1350 # define printf printk
1351 # define bcopy(s,d,z) memmove(d, s, z)
1352 # define bzero(s,z) memset(s, 0, z)
1353 # define bcmp(a,b,z) memcmp(a, b, z)
1354 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
1355 # define ipf_random random32
1356 # define arc4random random32
1358 # include <linux/random.h>
1359 # define ipf_random get_random_int
1360 # define arc4random get_random_int
1363 # define ifnet net_device
1364 # define if_xname name
1365 # define if_unit ifindex
1367 # define KMALLOC(x,t) (x) = (t)kmalloc(sizeof(*(x)), \
1368 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1369 # define KFREE(x) kfree(x)
1370 # define KMALLOCS(x,t,s) (x) = (t)kmalloc((s), \
1371 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1372 # define KFREES(x,s) kfree(x)
1374 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
1375 # define f_uid f_owner.uid
1376 # define GETIFP(n,v) dev_get_by_name(&init_net, n)
1378 # define GETIFP(n,v) dev_get_by_name(n)
1380 # define GETIFMTU_4(x) ((struct net_device *)x)->mtu
1381 # define GETIFMTU_6(x) ((struct net_device *)x)->mtu
1384 # include <net/ethernet.h>
1389 # ifndef _NET_ROUTE_H
1395 char if_xname[IFNAMSIZ];
1397 int (* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1398 struct ifaddr *if_addrlist;
1400 # define IFNAME(x) ((struct ifnet *)x)->if_xname
1402 # endif /* _KERNEL */
1404 # define COPYIFNAME(v, x, b) \
1406 ((struct ifnet *)x)->if_xname, \
1409 # include <linux/fs.h>
1410 # define FWRITE FMODE_WRITE
1411 # define FREAD FMODE_READ
1413 # define __USE_MISC 1
1414 # define __FAVOR_BSD 1
1416 typedef struct uio {
1417 struct iovec *uio_iov;
1426 extern int uiomove __P((caddr_t, size_t, int, struct uio *));
1429 # define UIO_WRITE 2
1431 # if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)) && !defined(_KERNEL)
1432 typedef int fmode_t;
1435 typedef u_long ioctlcmd_t;
1436 typedef int minor_t;
1437 typedef u_int32_t u_32_t;
1440 # define OS_RECOGNISED 1
1445 /* ----------------------------------------------------------------------- */
1447 /* ----------------------------------------------------------------------- */
1451 # include <sys/lock.h>
1452 # include <sys/sysmacros.h>
1455 # define rw_read_locked(x) 0
1456 # include <net/net_globals.h>
1457 # include <net/net_malloc.h>
1458 # define KMUTEX_T simple_lock_t
1459 # define KRWLOCK_T complex_lock_t
1460 # define USE_MUTEXES 1
1462 # define READ_ENTER(x) lock_read((x)->ipf_lk)
1463 # define WRITE_ENTER(x) lock_write((x)->ipf_lk)
1464 # define MUTEX_DOWNGRADE(x) lock_write_to_read((x)->ipf_lk)
1465 # define RWLOCK_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1468 lock_init((x)->ipf_lk, TRUE)
1469 # define RWLOCK_EXIT(x) lock_done((x)->ipf_lk)
1470 # define RW_DESTROY(x) lock_free(&(x)->ipf_lk)
1471 # define MUTEX_ENTER(x) simple_lock((x)->ipf_lk)
1472 # define MUTEX_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1475 simple_lock_init((x)->ipf_lk)
1476 # define MUTEX_DESTROY(x) lock_free(&(x)->ipf_lk)
1477 # define MUTEX_EXIT(x) simple_unlock((x)->ipf_lk)
1478 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1479 # define ATOMIC_INC64(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
1480 MUTEX_EXIT(&softc->ipf_rw); }
1481 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
1482 MUTEX_EXIT(&softc->ipf_rw); }
1483 # define ATOMIC_INC32(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
1484 MUTEX_EXIT(&softc->ipf_rw); }
1485 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
1486 MUTEX_EXIT(&softc->ipf_rw); }
1487 # define ATOMIC_INCL(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
1488 MUTEX_EXIT(&softc->ipf_rw); }
1489 # define ATOMIC_DECL(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
1490 MUTEX_EXIT(&softc->ipf_rw); }
1491 # define ATOMIC_INC(x) { MUTEX_ENTER(&softc->ipf_rw); (x)++; \
1492 MUTEX_EXIT(&softc->ipf_rw); }
1493 # define ATOMIC_DEC(x) { MUTEX_ENTER(&softc->ipf_rw); (x)--; \
1494 MUTEX_EXIT(&softc->ipf_rw); }
1495 # define SPL_SCHED(x) x = splsched()
1496 # define SPL_NET(x) x = splnet()
1497 # define SPL_IMP(x) x = splimp()
1499 # define SPL_X(x) splx(x)
1500 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1501 extern void* getifp __P((char *, int));
1502 # define GETIFP(n, v) getifp(n, v)
1503 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
1504 # define GETIFMTU_6(x) ((struct ifnet *)x)->if_mtu
1505 # define GET_MINOR minor
1506 # define SLEEP(id, n) sleepx((id), PZERO+1, 0)
1507 # define WAKEUP(id,x) wakeup(id)
1508 # define POLLWAKEUP(x) ;
1509 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
1510 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
1511 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1512 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, \
1513 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1514 # define KFREE(x) FREE((x), M_TEMP)
1515 # define KFREES(x,s) FREE((x), M_TEMP)
1516 # define MSGDSIZE(m) mbufchainlen(m)
1517 # define M_LEN(m) (m)->m_len
1518 # define M_ADJ(m,x) m_adj(m, x)
1519 # define M_COPY(m) m_copy((m), 0, M_COPYALL)
1520 # define GETKTIME(x)
1521 # define IPF_PANIC(x,y)
1522 typedef struct mbuf mb_t;
1523 # endif /* _KERNEL */
1526 * These are from's Solaris' #defines for little endian.
1528 #if !defined(IP6F_MORE_FRAG)
1529 # define IP6F_MORE_FRAG 0x0100
1531 #if !defined(IP6F_RESERVED_MASK)
1532 # define IP6F_RESERVED_MASK 0x0600
1534 #if !defined(IP6F_OFF_MASK)
1535 # define IP6F_OFF_MASK 0xf8ff
1543 typedef int ioctlcmd_t;
1544 typedef int minor_t;
1546 * Really, any arch where sizeof(long) != sizeof(int).
1548 typedef unsigned int u_32_t;
1551 # define OS_RECOGNISED 1
1555 #ifndef OS_RECOGNISED
1556 #error ip_compat.h does not recognise this platform/OS.
1560 /* ----------------------------------------------------------------------- */
1562 /* ----------------------------------------------------------------------- */
1563 #ifndef OS_RECOGNISED
1567 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1570 #if !defined(IPFILTER_BPF)
1571 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
1572 (defined(NBPFILTER) && (NBPFILTER > 0))
1573 # define IPFILTER_BPF
1578 * Userland locking primitives
1580 #if !defined(KMUTEX_FILL_SZ)
1581 # define KMUTEX_FILL_SZ 1
1583 #if !defined(KRWLOCK_FILL_SZ)
1584 # define KRWLOCK_FILL_SZ 1
1605 char _fill[KMUTEX_FILL_SZ];
1609 const char *ipf_lname;
1616 char _fill[KRWLOCK_FILL_SZ];
1620 const char *ipf_lname;
1629 #define ipf_lk ipf_lkun_s.ipf_slk
1630 #define ipf_lname ipf_lkun_s.ipf_lname
1631 #define ipf_isr ipf_lkun_s.ipf_sr
1632 #define ipf_isw ipf_lkun_s.ipf_sw
1633 #define ipf_magic ipf_lkun_s.ipf_magic
1635 #if !defined(__GNUC__) || \
1636 (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1641 # define INLINE __inline__
1644 #if defined(linux) && defined(_KERNEL)
1645 extern void ipf_read_enter __P((ipfrwlock_t *));
1646 extern void ipf_write_enter __P((ipfrwlock_t *));
1647 extern void ipf_rw_exit __P((ipfrwlock_t *));
1648 extern void ipf_rw_init __P((ipfrwlock_t *, char *));
1649 extern void ipf_rw_downgrade __P((ipfrwlock_t *));
1653 * In a non-kernel environment, there are a lot of macros that need to be
1654 * filled in to be null-ops or to point to some compatibility function,
1655 * somewhere in userland.
1658 typedef struct mb_s {
1659 struct mb_s *mb_next;
1664 u_long mb_buf[2048];
1667 # define m_next mb_next
1669 # define m_len mb_len
1671 # define m_flags mb_flags
1673 # define m_data mb_data
1675 # define M_MCAST 0x01
1677 # define M_BCAST 0x02
1679 # define M_MBCAST 0x04
1680 # define MSGDSIZE(m) msgdsize(m)
1681 # define M_LEN(m) (m)->mb_len
1682 # define M_ADJ(m,x) (m)->mb_len += x
1683 # define M_COPY(m) dupmbt(m)
1684 # define M_DUP(m) dupmbt(m)
1685 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL)
1686 # define MTOD(m, t) ((t)(m)->mb_data)
1687 # define FREE_MB_T(m) freembt(m)
1688 # define ALLOC_MB_T(m,l) (m) = allocmbt(l)
1689 # define PREP_MB_T(f, m) do { \
1690 (m)->mb_next = *(f)->fin_mp; \
1691 *(fin)->fin_mp = (m); \
1694 # define SLEEP(x,y) 1;
1695 # define WAKEUP(x,y) ;
1696 # define POLLWAKEUP(y) ;
1697 # define IPF_PANIC(x,y) ;
1698 # define PANIC(x,y) ;
1699 # define SPL_SCHED(x) ;
1700 # define SPL_NET(x) ;
1701 # define SPL_IMP(x) ;
1703 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
1704 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
1705 # define KFREE(x) free(x)
1706 # define KFREES(x,s) free(x)
1707 # define GETIFP(x, v) get_unit(x,v)
1708 # define GETIFMTU_4(x) 2048
1709 # define GETIFMTU_6(x) 2048
1710 # define COPYIN(a,b,c) bcopywrap((a), (b), (c))
1711 # define COPYOUT(a,b,c) bcopywrap((a), (b), (c))
1712 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \
1714 # define COPYBACK(m, o, l, b) bcopy((b), \
1715 MTOD((mb_t *)m, char *) + (o), \
1717 # define UIOMOVE(a,b,c,d) ipfuiomove((caddr_t)a,b,c,d)
1718 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1719 extern int ipfuiomove __P((caddr_t, int, int, struct uio *));
1720 extern int bcopywrap __P((void *, void *, size_t));
1721 extern mb_t *allocmbt __P((size_t));
1722 extern mb_t *dupmbt __P((mb_t *));
1723 extern void freembt __P((mb_t *));
1725 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu, \
1727 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \
1729 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu, \
1731 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y, \
1733 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
1735 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \
1737 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \
1739 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y)
1740 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu)
1741 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu)
1742 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \
1746 # define USE_MUTEXES 1
1748 extern void eMmutex_destroy __P((eMmutex_t *, char *, int));
1749 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1750 extern void eMmutex_exit __P((eMmutex_t *, char *, int));
1751 extern void eMmutex_init __P((eMmutex_t *, char *, char *, int));
1752 extern void eMrwlock_destroy __P((eMrwlock_t *));
1753 extern void eMrwlock_exit __P((eMrwlock_t *));
1754 extern void eMrwlock_init __P((eMrwlock_t *, char *));
1755 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1756 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1757 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1761 extern mb_t *allocmbt(size_t);
1763 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1766 # define IP_OFFMASK 0x1fff
1771 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1774 #if !defined(__amd64__) && BSD_GT_YEAR(199306)
1776 # define U_QUAD_T u_quad_t
1777 # define QUAD_T quad_t
1778 #else /* BSD > 199306 */
1779 # if !defined(U_QUAD_T)
1780 # define U_QUAD_T u_long
1781 # define QUAD_T long
1783 #endif /* BSD > 199306 */
1787 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1788 defined(__osf__) || defined(linux)
1789 # include <netinet/ip6.h>
1790 # include <netinet/icmp6.h>
1791 # if !defined(linux)
1792 # if defined(_KERNEL) && !defined(__osf__)
1793 # include <netinet6/ip6_var.h>
1796 typedef struct ip6_hdr ip6_t;
1801 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
1804 #if defined(_KERNEL)
1805 # if defined(MENTAT) && !defined(INSTANCES)
1806 # define COPYDATA mb_copydata
1807 # define COPYBACK mb_copyback
1809 # define COPYDATA m_copydata
1810 # define COPYBACK m_copyback
1812 # if BSD_GE_YEAR(199306) || defined(__FreeBSD__)
1813 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1814 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1815 defined(_BSDI_VERSION)
1818 # if !defined(__FreeBSD__) || FREEBSD_GE_REV(300000)
1819 # if NETBSD_GE_REV(105180000) || OPENBSD_GE_REV(200111)
1820 # include <uvm/uvm_extern.h>
1822 # include <vm/vm_extern.h>
1823 extern vm_map_t kmem_map;
1825 # include <sys/proc.h>
1826 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1827 # include <vm/vm_kern.h>
1828 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1830 # ifdef IPFILTER_M_IPFILTER
1831 # include <sys/malloc.h>
1832 MALLOC_DECLARE(M_IPFILTER);
1833 # define _M_IPF M_IPFILTER
1834 # else /* IPFILTER_M_IPFILTER */
1836 # define _M_IPF M_PFIL
1839 # define _M_IPF M_IPFILTER
1841 # define _M_IPF M_TEMP
1842 # endif /* M_IPFILTER */
1843 # endif /* M_PFIL */
1844 # endif /* IPFILTER_M_IPFILTER */
1845 # if !defined(KMALLOC)
1846 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1848 # if !defined(KMALLOCS)
1849 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1851 # if !defined(KFREE)
1852 # define KFREE(x) FREE((x), _M_IPF)
1854 # if !defined(KFREES)
1855 # define KFREES(x,s) FREE((x), _M_IPF)
1857 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,d)
1858 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
1859 # define WAKEUP(id,x) wakeup(id+x)
1860 # if !defined(POLLWAKEUP)
1861 # define POLLWAKEUP(x) selwakeup(softc->ipf_selwait+x)
1863 # define GETIFP(n, v) ifunit(n)
1864 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
1865 # define GETIFMTU_6(x) ((struct ifnet *)x)->if_mtu
1866 # endif /* (Free)BSD */
1868 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
1869 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1870 OPENBSD_GE_REV(200006)
1871 # define SPL_NET(x) x = splsoftnet()
1873 # define SPL_IMP(x) x = splimp()
1874 # define SPL_NET(x) x = splnet()
1875 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1876 # if !defined(SPL_SCHED)
1877 # define SPL_SCHED(x) x = splsched()
1879 # define SPL_X(x) (void) splx(x)
1880 # endif /* !USE_MUTEXES */
1883 # define FREE_MB_T(m) m_freem(m)
1887 # define ALLOC_MB_T(m,l) do { \
1888 MGETHDR((m), M_DONTWAIT, MT_HEADER); \
1889 if ((m) != NULL) { \
1891 (m)->m_pkthdr.len = (l); \
1895 # define ALLOC_MB_T(m,l) do { \
1896 MGET((m), M_DONTWAIT, MT_HEADER); \
1897 if ((m) != NULL) { \
1899 (m)->m_pkthdr.len = (l); \
1905 # define PREP_MB_T(f, m) do { \
1906 mb_t *_o = *(f)->fin_mp; \
1908 *(fin)->fin_mp = (m); \
1909 if (_o->m_flags & M_PKTHDR) { \
1910 (m)->m_pkthdr.len += \
1912 (m)->m_pkthdr.rcvif = \
1913 _o->m_pkthdr.rcvif; \
1919 # define M_DUP(m) m_dup(m, 0, M_COPYALL, 0)
1921 # define M_DUP(m) m_dup(m)
1926 # define MTOD(m,t) mtod(m,t)
1930 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1931 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1935 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
1937 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1941 # define GET_MINOR(x) minor(x)
1943 # define PANIC(x,y) if (x) panic y
1944 #endif /* _KERNEL */
1946 #if !defined(IFNAME) && !defined(_KERNEL)
1947 # define IFNAME(x) get_ifname((struct ifnet *)x)
1950 # define NEED_FRGETIFNAME
1951 extern char *ipf_getifname __P((struct ifnet *, char *));
1952 # define COPYIFNAME(v, x, b) \
1953 ipf_getifname((struct ifnet *)x, b)
1960 # define ASSERT(x) do { if (!(x)) abort(); } while (0)
1965 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1966 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1970 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1971 * would mean all normal code that walks through strings needed casts. Yuck.
1973 #define ISALNUM(x) isalnum((u_char)(x))
1974 #define ISALPHA(x) isalpha((u_char)(x))
1975 #define ISDIGIT(x) isdigit((u_char)(x))
1976 #define ISSPACE(x) isspace((u_char)(x))
1977 #define ISUPPER(x) isupper((u_char)(x))
1978 #define ISXDIGIT(x) isxdigit((u_char)(x))
1979 #define ISLOWER(x) islower((u_char)(x))
1980 #define TOUPPER(x) toupper((u_char)(x))
1981 #define TOLOWER(x) tolower((u_char)(x))
1984 * If mutexes aren't being used, turn all the mutex functions into null-ops.
1986 #if !defined(USE_MUTEXES)
1991 # undef MUTEX_DESTROY
1992 # define MUTEX_ENTER(x) ;
1993 # define READ_ENTER(x) ;
1994 # define WRITE_ENTER(x) ;
1995 # define MUTEX_DOWNGRADE(x) ;
1996 # define RWLOCK_INIT(x, y) ;
1997 # define RWLOCK_EXIT(x) ;
1998 # define RW_DESTROY(x) ;
1999 # define MUTEX_EXIT(x) ;
2000 # define MUTEX_INIT(x,y) ;
2001 # define MUTEX_DESTROY(x) ;
2002 # define MUTEX_NUKE(x) ;
2003 #endif /* !USE_MUTEXES */
2005 # define ATOMIC_INC(x) (x)++
2006 # define ATOMIC_DEC(x) (x)--
2009 #if defined(USE_SPL) && defined(_KERNEL)
2010 # define SPL_INT(x) int x
2016 * If there are no atomic operations for bit sizes defined, define them to all
2017 * use a generic one that works for all sizes.
2020 # define ATOMIC_INCL ATOMIC_INC
2021 # define ATOMIC_INC64 ATOMIC_INC
2022 # define ATOMIC_INC32 ATOMIC_INC
2023 # define ATOMIC_DECL ATOMIC_DEC
2024 # define ATOMIC_DEC64 ATOMIC_DEC
2025 # define ATOMIC_DEC32 ATOMIC_DEC
2028 #ifndef HDR_T_PRIVATE
2029 typedef struct tcphdr tcphdr_t;
2030 typedef struct udphdr udphdr_t;
2032 typedef struct icmp icmphdr_t;
2033 typedef struct ip ip_t;
2034 typedef struct ether_header ether_header_t;
2035 typedef struct tcpiphdr tcpiphdr_t;
2038 # define FR_GROUPLEN 16
2042 # define offsetof(t,m) (size_t)((&((t *)0L)->m))
2045 # define stsizeof(t,m) sizeof(((t *)0L)->m)
2049 * This set of macros has been brought about because on Tru64 it is not
2050 * possible to easily assign or examine values in a structure that are
2054 # define IP_V(x) (x)->ip_v
2057 # define IP_V_A(x,y) (x)->ip_v = (y)
2060 # define IP_HL(x) (x)->ip_hl
2063 # define IP_HL_A(x,y) (x)->ip_hl = ((y) & 0xf)
2066 # define TCP_X2(x) (x)->th_x2
2069 # define TCP_X2_A(x,y) (x)->th_x2 = (y)
2072 # define TCP_OFF(x) (x)->th_off
2075 # define TCP_OFF_A(x,y) (x)->th_off = (y)
2077 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
2081 * XXX - This is one of those *awful* hacks which nobody likes
2089 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
2092 #if BSD_GE_YEAR(199306) && !defined(m_act)
2093 # define m_act m_nextpkt
2097 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
2101 * 00000001 - (Reserved 4)
2102 * 00111101 - Top Secret
2104 * 10010110 - Confidential
2105 * 01100110 - (Reserved 3)
2106 * 11001100 - (Reserved 2)
2107 * 10101011 - Unclassified
2108 * 11110001 - (Reserved 1)
2110 #define IPSO_CLASS_RES4 0x01
2111 #define IPSO_CLASS_TOPS 0x3d
2112 #define IPSO_CLASS_SECR 0x5a
2113 #define IPSO_CLASS_CONF 0x96
2114 #define IPSO_CLASS_RES3 0x66
2115 #define IPSO_CLASS_RES2 0xcc
2116 #define IPSO_CLASS_UNCL 0xab
2117 #define IPSO_CLASS_RES1 0xf1
2119 #define IPSO_AUTH_GENSER 0x80
2120 #define IPSO_AUTH_ESI 0x40
2121 #define IPSO_AUTH_SCI 0x20
2122 #define IPSO_AUTH_NSA 0x10
2123 #define IPSO_AUTH_DOE 0x08
2124 #define IPSO_AUTH_UN 0x06
2125 #define IPSO_AUTH_FTE 0x01
2128 * IP option #defines
2133 #define IPOPT_ZSU 10 /* ZSU */
2135 #define IPOPT_MTUP 11 /* MTUP */
2137 #define IPOPT_MTUR 12 /* MTUR */
2139 #define IPOPT_ENCODE 15 /* ENCODE */
2143 #define IPOPT_TR 82 /* TR */
2144 #undef IPOPT_SECURITY
2145 #define IPOPT_SECURITY 130
2147 #define IPOPT_LSRR 131
2149 #define IPOPT_E_SEC 133 /* E-SEC */
2151 #define IPOPT_CIPSO 134 /* CIPSO */
2153 #define IPOPT_SATID 136
2155 # define IPOPT_SID IPOPT_SATID
2158 #define IPOPT_SSRR 137
2160 #define IPOPT_ADDEXT 147 /* ADDEXT */
2162 #define IPOPT_VISA 142 /* VISA */
2164 #define IPOPT_IMITD 144 /* IMITD */
2166 #define IPOPT_EIP 145 /* EIP */
2167 #undef IPOPT_RTRALRT
2168 #define IPOPT_RTRALRT 148 /* RTRALRT */
2170 #define IPOPT_SDB 149
2172 #define IPOPT_NSAPA 150
2174 #define IPOPT_DPS 151
2176 #define IPOPT_UMP 152
2178 #define IPOPT_FINN 205 /* FINN */
2180 #define IPOPT_AH 256+IPPROTO_AH
2183 # define TCPOPT_EOL 0
2186 # define TCPOPT_NOP 1
2188 #ifndef TCPOPT_MAXSEG
2189 # define TCPOPT_MAXSEG 2
2191 #ifndef TCPOLEN_MAXSEG
2192 # define TCPOLEN_MAXSEG 4
2194 #ifndef TCPOPT_WINDOW
2195 # define TCPOPT_WINDOW 3
2197 #ifndef TCPOLEN_WINDOW
2198 # define TCPOLEN_WINDOW 3
2200 #ifndef TCPOPT_SACK_PERMITTED
2201 # define TCPOPT_SACK_PERMITTED 4
2203 #ifndef TCPOLEN_SACK_PERMITTED
2204 # define TCPOLEN_SACK_PERMITTED 2
2207 # define TCPOPT_SACK 5
2209 #ifndef TCPOPT_TIMESTAMP
2210 # define TCPOPT_TIMESTAMP 8
2214 # define ICMP_MINLEN 8
2216 #ifndef ICMP_ECHOREPLY
2217 # define ICMP_ECHOREPLY 0
2219 #ifndef ICMP_UNREACH
2220 # define ICMP_UNREACH 3
2222 #ifndef ICMP_UNREACH_NET
2223 # define ICMP_UNREACH_NET 0
2225 #ifndef ICMP_UNREACH_HOST
2226 # define ICMP_UNREACH_HOST 1
2228 #ifndef ICMP_UNREACH_PROTOCOL
2229 # define ICMP_UNREACH_PROTOCOL 2
2231 #ifndef ICMP_UNREACH_PORT
2232 # define ICMP_UNREACH_PORT 3
2234 #ifndef ICMP_UNREACH_NEEDFRAG
2235 # define ICMP_UNREACH_NEEDFRAG 4
2237 #ifndef ICMP_UNREACH_SRCFAIL
2238 # define ICMP_UNREACH_SRCFAIL 5
2240 #ifndef ICMP_UNREACH_NET_UNKNOWN
2241 # define ICMP_UNREACH_NET_UNKNOWN 6
2243 #ifndef ICMP_UNREACH_HOST_UNKNOWN
2244 # define ICMP_UNREACH_HOST_UNKNOWN 7
2246 #ifndef ICMP_UNREACH_ISOLATED
2247 # define ICMP_UNREACH_ISOLATED 8
2249 #ifndef ICMP_UNREACH_NET_PROHIB
2250 # define ICMP_UNREACH_NET_PROHIB 9
2252 #ifndef ICMP_UNREACH_HOST_PROHIB
2253 # define ICMP_UNREACH_HOST_PROHIB 10
2255 #ifndef ICMP_UNREACH_TOSNET
2256 # define ICMP_UNREACH_TOSNET 11
2258 #ifndef ICMP_UNREACH_TOSHOST
2259 # define ICMP_UNREACH_TOSHOST 12
2261 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
2262 # define ICMP_UNREACH_ADMIN_PROHIBIT 13
2264 #ifndef ICMP_UNREACH_FILTER
2265 # define ICMP_UNREACH_FILTER 13
2267 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
2268 # define ICMP_UNREACH_HOST_PRECEDENCE 14
2270 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
2271 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
2273 #ifndef ICMP_SOURCEQUENCH
2274 # define ICMP_SOURCEQUENCH 4
2276 #ifndef ICMP_REDIRECT_NET
2277 # define ICMP_REDIRECT_NET 0
2279 #ifndef ICMP_REDIRECT_HOST
2280 # define ICMP_REDIRECT_HOST 1
2282 #ifndef ICMP_REDIRECT_TOSNET
2283 # define ICMP_REDIRECT_TOSNET 2
2285 #ifndef ICMP_REDIRECT_TOSHOST
2286 # define ICMP_REDIRECT_TOSHOST 3
2288 #ifndef ICMP_ALTHOSTADDR
2289 # define ICMP_ALTHOSTADDR 6
2291 #ifndef ICMP_TIMXCEED
2292 # define ICMP_TIMXCEED 11
2294 #ifndef ICMP_TIMXCEED_INTRANS
2295 # define ICMP_TIMXCEED_INTRANS 0
2297 #ifndef ICMP_TIMXCEED_REASS
2298 # define ICMP_TIMXCEED_REASS 1
2300 #ifndef ICMP_PARAMPROB
2301 # define ICMP_PARAMPROB 12
2303 #ifndef ICMP_PARAMPROB_ERRATPTR
2304 # define ICMP_PARAMPROB_ERRATPTR 0
2306 #ifndef ICMP_PARAMPROB_OPTABSENT
2307 # define ICMP_PARAMPROB_OPTABSENT 1
2309 #ifndef ICMP_PARAMPROB_LENGTH
2310 # define ICMP_PARAMPROB_LENGTH 2
2313 # define ICMP_TSTAMP 13
2315 #ifndef ICMP_TSTAMPREPLY
2316 # define ICMP_TSTAMPREPLY 14
2319 # define ICMP_IREQ 15
2321 #ifndef ICMP_IREQREPLY
2322 # define ICMP_IREQREPLY 16
2324 #ifndef ICMP_MASKREQ
2325 # define ICMP_MASKREQ 17
2327 #ifndef ICMP_MASKREPLY
2328 # define ICMP_MASKREPLY 18
2330 #ifndef ICMP_TRACEROUTE
2331 # define ICMP_TRACEROUTE 30
2333 #ifndef ICMP_DATACONVERR
2334 # define ICMP_DATACONVERR 31
2336 #ifndef ICMP_MOBILE_REDIRECT
2337 # define ICMP_MOBILE_REDIRECT 32
2339 #ifndef ICMP_IPV6_WHEREAREYOU
2340 # define ICMP_IPV6_WHEREAREYOU 33
2342 #ifndef ICMP_IPV6_IAMHERE
2343 # define ICMP_IPV6_IAMHERE 34
2345 #ifndef ICMP_MOBILE_REGREQUEST
2346 # define ICMP_MOBILE_REGREQUEST 35
2348 #ifndef ICMP_MOBILE_REGREPLY
2349 # define ICMP_MOBILE_REGREPLY 36
2352 # define ICMP_SKIP 39
2354 #ifndef ICMP_PHOTURIS
2355 # define ICMP_PHOTURIS 40
2357 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
2358 # define ICMP_PHOTURIS_UNKNOWN_INDEX 1
2360 #ifndef ICMP_PHOTURIS_AUTH_FAILED
2361 # define ICMP_PHOTURIS_AUTH_FAILED 2
2363 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
2364 # define ICMP_PHOTURIS_DECRYPT_FAILED 3
2367 # define IPVERSION 4
2369 #ifndef IPOPT_MINOFF
2370 # define IPOPT_MINOFF 4
2372 #ifndef IPOPT_COPIED
2373 # define IPOPT_COPIED(x) ((x)&0x80)
2376 # define IPOPT_EOL 0
2379 # define IPOPT_NOP 1
2382 # define IP_MF ((u_short)0x2000)
2384 #ifndef ETHERTYPE_IP
2385 # define ETHERTYPE_IP ((u_short)0x0800)
2388 # define TH_FIN 0x01
2391 # define TH_SYN 0x02
2394 # define TH_RST 0x04
2397 # define TH_PUSH 0x08
2400 # define TH_ACK 0x10
2403 # define TH_URG 0x20
2406 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK)
2409 # define IPOPT_EOL 0
2412 # define IPOPT_NOP 1
2418 # define IPOPT_TS 68
2420 #ifndef IPOPT_SECURITY
2421 # define IPOPT_SECURITY 130
2424 # define IPOPT_LSRR 131
2427 # define IPOPT_SATID 136
2430 # define IPOPT_SSRR 137
2432 #ifndef IPOPT_SECUR_UNCLASS
2433 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
2435 #ifndef IPOPT_SECUR_CONFID
2436 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
2438 #ifndef IPOPT_SECUR_EFTO
2439 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
2441 #ifndef IPOPT_SECUR_MMMM
2442 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
2444 #ifndef IPOPT_SECUR_RESTR
2445 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
2447 #ifndef IPOPT_SECUR_SECRET
2448 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
2450 #ifndef IPOPT_SECUR_TOPSECRET
2451 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
2454 # define IPOPT_OLEN 1
2456 #ifndef IPPROTO_HOPOPTS
2457 # define IPPROTO_HOPOPTS 0
2459 #ifndef IPPROTO_IPIP
2460 # define IPPROTO_IPIP 4
2462 #ifndef IPPROTO_ENCAP
2463 # define IPPROTO_ENCAP 98
2465 #ifndef IPPROTO_IPV6
2466 # define IPPROTO_IPV6 41
2468 #ifndef IPPROTO_ROUTING
2469 # define IPPROTO_ROUTING 43
2471 #ifndef IPPROTO_FRAGMENT
2472 # define IPPROTO_FRAGMENT 44
2475 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
2478 # define IPPROTO_ESP 50
2481 # define IPPROTO_AH 51
2483 #ifndef IPPROTO_ICMPV6
2484 # define IPPROTO_ICMPV6 58
2486 #ifndef IPPROTO_NONE
2487 # define IPPROTO_NONE 59
2489 #ifndef IPPROTO_DSTOPTS
2490 # define IPPROTO_DSTOPTS 60
2492 #ifndef IPPROTO_MOBILITY
2493 # define IPPROTO_MOBILITY 135
2496 #ifndef ICMP_ROUTERADVERT
2497 # define ICMP_ROUTERADVERT 9
2499 #ifndef ICMP_ROUTERSOLICIT
2500 # define ICMP_ROUTERSOLICIT 10
2502 #ifndef ICMP6_DST_UNREACH
2503 # define ICMP6_DST_UNREACH 1
2505 #ifndef ICMP6_PACKET_TOO_BIG
2506 # define ICMP6_PACKET_TOO_BIG 2
2508 #ifndef ICMP6_TIME_EXCEEDED
2509 # define ICMP6_TIME_EXCEEDED 3
2511 #ifndef ICMP6_PARAM_PROB
2512 # define ICMP6_PARAM_PROB 4
2515 #ifndef ICMP6_ECHO_REQUEST
2516 # define ICMP6_ECHO_REQUEST 128
2518 #ifndef ICMP6_ECHO_REPLY
2519 # define ICMP6_ECHO_REPLY 129
2521 #ifndef ICMP6_MEMBERSHIP_QUERY
2522 # define ICMP6_MEMBERSHIP_QUERY 130
2524 #ifndef MLD6_LISTENER_QUERY
2525 # define MLD6_LISTENER_QUERY 130
2527 #ifndef ICMP6_MEMBERSHIP_REPORT
2528 # define ICMP6_MEMBERSHIP_REPORT 131
2530 #ifndef MLD6_LISTENER_REPORT
2531 # define MLD6_LISTENER_REPORT 131
2533 #ifndef ICMP6_MEMBERSHIP_REDUCTION
2534 # define ICMP6_MEMBERSHIP_REDUCTION 132
2536 #ifndef MLD6_LISTENER_DONE
2537 # define MLD6_LISTENER_DONE 132
2539 #ifndef ND_ROUTER_SOLICIT
2540 # define ND_ROUTER_SOLICIT 133
2542 #ifndef ND_ROUTER_ADVERT
2543 # define ND_ROUTER_ADVERT 134
2545 #ifndef ND_NEIGHBOR_SOLICIT
2546 # define ND_NEIGHBOR_SOLICIT 135
2548 #ifndef ND_NEIGHBOR_ADVERT
2549 # define ND_NEIGHBOR_ADVERT 136
2552 # define ND_REDIRECT 137
2554 #ifndef ICMP6_ROUTER_RENUMBERING
2555 # define ICMP6_ROUTER_RENUMBERING 138
2557 #ifndef ICMP6_WRUREQUEST
2558 # define ICMP6_WRUREQUEST 139
2560 #ifndef ICMP6_WRUREPLY
2561 # define ICMP6_WRUREPLY 140
2563 #ifndef ICMP6_FQDN_QUERY
2564 # define ICMP6_FQDN_QUERY 139
2566 #ifndef ICMP6_FQDN_REPLY
2567 # define ICMP6_FQDN_REPLY 140
2569 #ifndef ICMP6_NI_QUERY
2570 # define ICMP6_NI_QUERY 139
2572 #ifndef ICMP6_NI_REPLY
2573 # define ICMP6_NI_REPLY 140
2575 #ifndef MLD6_MTRACE_RESP
2576 # define MLD6_MTRACE_RESP 200
2579 # define MLD6_MTRACE 201
2581 #ifndef ICMP6_HADISCOV_REQUEST
2582 # define ICMP6_HADISCOV_REQUEST 202
2584 #ifndef ICMP6_HADISCOV_REPLY
2585 # define ICMP6_HADISCOV_REPLY 203
2587 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
2588 # define ICMP6_MOBILEPREFIX_SOLICIT 204
2590 #ifndef ICMP6_MOBILEPREFIX_ADVERT
2591 # define ICMP6_MOBILEPREFIX_ADVERT 205
2593 #ifndef ICMP6_MAXTYPE
2594 # define ICMP6_MAXTYPE 205
2597 #ifndef ICMP6_DST_UNREACH_NOROUTE
2598 # define ICMP6_DST_UNREACH_NOROUTE 0
2600 #ifndef ICMP6_DST_UNREACH_ADMIN
2601 # define ICMP6_DST_UNREACH_ADMIN 1
2603 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
2604 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
2606 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
2607 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
2609 #ifndef ICMP6_DST_UNREACH_ADDR
2610 # define ICMP6_DST_UNREACH_ADDR 3
2612 #ifndef ICMP6_DST_UNREACH_NOPORT
2613 # define ICMP6_DST_UNREACH_NOPORT 4
2615 #ifndef ICMP6_TIME_EXCEED_TRANSIT
2616 # define ICMP6_TIME_EXCEED_TRANSIT 0
2618 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
2619 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
2622 #ifndef ICMP6_NI_SUCCESS
2623 # define ICMP6_NI_SUCCESS 0
2625 #ifndef ICMP6_NI_REFUSED
2626 # define ICMP6_NI_REFUSED 1
2628 #ifndef ICMP6_NI_UNKNOWN
2629 # define ICMP6_NI_UNKNOWN 2
2632 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
2633 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
2635 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
2636 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
2638 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2639 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
2642 #ifndef ICMP6_PARAMPROB_HEADER
2643 # define ICMP6_PARAMPROB_HEADER 0
2645 #ifndef ICMP6_PARAMPROB_NEXTHEADER
2646 # define ICMP6_PARAMPROB_NEXTHEADER 1
2648 #ifndef ICMP6_PARAMPROB_OPTION
2649 # define ICMP6_PARAMPROB_OPTION 2
2652 #ifndef ICMP6_NI_SUBJ_IPV6
2653 # define ICMP6_NI_SUBJ_IPV6 0
2655 #ifndef ICMP6_NI_SUBJ_FQDN
2656 # define ICMP6_NI_SUBJ_FQDN 1
2658 #ifndef ICMP6_NI_SUBJ_IPV4
2659 # define ICMP6_NI_SUBJ_IPV4 2
2662 #ifndef MLD_MTRACE_RESP
2663 # define MLD_MTRACE_RESP 200
2666 # define MLD_MTRACE 201
2668 #ifndef MLD6_MTRACE_RESP
2669 # define MLD6_MTRACE_RESP MLD_MTRACE_RESP
2672 # define MLD6_MTRACE MLD_MTRACE
2675 #if !defined(IPV6_FLOWINFO_MASK)
2676 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
2677 # define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
2679 # if(BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
2680 # define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
2681 # endif /* LITTLE_ENDIAN */
2684 #if !defined(IPV6_FLOWLABEL_MASK)
2685 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
2686 # define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
2688 # if (BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
2689 # define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
2690 # endif /* LITTLE_ENDIAN */
2695 * ECN is a new addition to TCP - RFC 2481
2698 # define TH_ECN 0x40
2701 # define TH_CWR 0x80
2703 #define TH_ECNALL (TH_ECN|TH_CWR)
2708 #define IPF_TCPS_LISTEN 0 /* listening for connection */
2709 #define IPF_TCPS_SYN_SENT 1 /* active, have sent syn */
2710 #define IPF_TCPS_SYN_RECEIVED 2 /* have send and received syn */
2711 #define IPF_TCPS_HALF_ESTAB 3 /* for connections not fully "up" */
2712 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2713 #define IPF_TCPS_ESTABLISHED 4 /* established */
2714 #define IPF_TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
2715 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2716 #define IPF_TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
2717 #define IPF_TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
2718 #define IPF_TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
2719 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2720 #define IPF_TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
2721 #define IPF_TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
2722 #define IPF_TCPS_CLOSED 11 /* closed */
2723 #define IPF_TCP_NSTATES 12
2727 #undef ICMP_MAX_UNREACH
2728 #define ICMP_MAX_UNREACH 14
2730 #define ICMP_MAXTYPE 18
2737 # define LOG_FTP (11<<3)
2739 #ifndef LOG_AUTHPRIV
2740 # define LOG_AUTHPRIV (10<<3)
2743 # define LOG_AUDIT (13<<3)
2746 # define LOG_NTP (12<<3)
2748 #ifndef LOG_SECURITY
2749 # define LOG_SECURITY (13<<3)
2752 # define LOG_LFMT (14<<3)
2755 # define LOG_CONSOLE (14<<3)
2759 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2760 * another IP header and then 64 bits of data, totalling 56. Of course,
2761 * the last 64 bits is dependent on that being available.
2763 #define ICMPERR_ICMPHLEN 8
2764 #define ICMPERR_IPICMPHLEN (20 + 8)
2765 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
2766 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
2767 #define ICMP6ERR_MINPKTLEN (40 + 8)
2768 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
2771 # define MIN(a,b) (((a)<(b))?(a):(b))
2775 # undef IPFILTER_BPF
2779 # define DPRINT(x) printf x
2785 # define AF_INET6 26
2790 # define DT(_n) DTRACE_PROBE(_n)
2791 # define DT1(_n,_a,_b) DTRACE_PROBE1(_n,_a,_b)
2792 # define DT2(_n,_a,_b,_c,_d) DTRACE_PROBE2(_n,_a,_b,_c,_d)
2793 # define DT3(_n,_a,_b,_c,_d,_e,_f) \
2794 DTRACE_PROBE3(_n,_a,_b,_c,_d,_e,_f)
2795 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h) \
2796 DTRACE_PROBE4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
2799 # define DT1(_n,_a,_b)
2800 # define DT2(_n,_a,_b,_c,_d)
2801 # define DT3(_n,_a,_b,_c,_d,_e,_f)
2802 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
2806 # define DT1(_n,_a,_b)
2807 # define DT2(_n,_a,_b,_c,_d)
2808 # define DT3(_n,_a,_b,_c,_d,_e,_f)
2809 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
2812 struct ip6_routing {
2813 u_char ip6r_nxt; /* next header */
2814 u_char ip6r_len; /* length in units of 8 octets */
2815 u_char ip6r_type; /* always zero */
2816 u_char ip6r_segleft; /* segments left */
2817 u_32_t ip6r_reserved; /* reserved field */
2820 #endif /* __IP_COMPAT_H__ */