2 * Copyright (C) 2012 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
5 * Id: ip_compat.h,v 2.142.2.57 2007/10/10 09:51:42 darrenr Exp $
8 #ifndef __IP_COMPAT_H__
9 #define __IP_COMPAT_H__
11 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
21 # if defined(sun) && defined(__SVR4)
31 # if !defined(_KERNEL)
32 # define bzero(a,b) memset(a,0,b)
34 # define bcopy(a,b,c) memmove(b,a,c)
40 # define LIFNAMSIZ IF_NAMESIZE
43 # define LIFNAMSIZ IFNAMSIZ
51 # define IPL_EXTERN(ep) ipl##ep
54 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
67 #define NETBSD_GE_REV(x) (defined(__NetBSD_Version__) && \
68 (__NetBSD_Version__ >= (x)))
69 #define NETBSD_GT_REV(x) (defined(__NetBSD_Version__) && \
70 (__NetBSD_Version__ > (x)))
71 #define NETBSD_LT_REV(x) (defined(__NetBSD_Version__) && \
72 (__NetBSD_Version__ < (x)))
75 /* ----------------------------------------------------------------------- */
77 /* ----------------------------------------------------------------------- */
78 #define HAS_SYS_MD5_H 1
81 # include "opt_inet6.h"
82 # if defined(INET6) && !defined(USE_INET6)
86 # if !defined(USE_INET6) && !defined(NOINET6)
92 # include <netinet/ip_var.h>
93 # define p_cred td_ucred
94 # define p_uid td_ucred->cr_ruid
97 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
98 * There may be other, safe, kernels but this is not extensively tested yet.
100 # define HAVE_M_PULLDOWN
101 # if !defined(IPFILTER_LKM) && defined(__FreeBSD__)
102 # include "opt_ipfilter.h"
104 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
105 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
108 # include <inttypes.h>
111 #include <sys/selinfo.h>
112 #include <sys/lock.h>
113 #include <sys/malloc.h>
114 #include <sys/mutex.h>
115 #define KRWLOCK_FILL_SZ 56
116 #define KMUTEX_FILL_SZ 56
117 #include <sys/rwlock.h>
118 #define KMUTEX_T struct mtx
119 #define KRWLOCK_T struct rwlock
122 # define READ_ENTER(x) rw_rlock(&(x)->ipf_lk)
123 # define WRITE_ENTER(x) rw_wlock(&(x)->ipf_lk)
124 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
125 # define MUTEX_TRY_UPGRADE(x) rw_try_upgrade(&(x)->ipf_lk)
126 # define RWLOCK_INIT(x,y) rw_init(&(x)->ipf_lk, (y))
127 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
128 # define RWLOCK_EXIT(x) do { \
129 if (rw_wowned(&(x)->ipf_lk)) \
130 rw_wunlock(&(x)->ipf_lk); \
132 rw_runlock(&(x)->ipf_lk); \
134 # include <net/if_var.h>
135 # include <net/if_private.h>
136 # define GETKTIME(x) microtime((struct timeval *)x)
137 # define if_addrlist if_addrhead
139 # include <netinet/in_systm.h>
140 # include <netinet/ip.h>
141 # include <machine/in_cksum.h>
144 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk)
145 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk)
146 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
148 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
149 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
151 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
152 * for what we want to use them for, despite testing showing they work -
153 * with a WITNESS kernel, it generates LOR messages.
155 # include <machine/atomic.h>
156 # define ATOMIC_INC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)++; \
157 mtx_unlock(&softc->ipf_rw.ipf_lk); }
158 # define ATOMIC_DEC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)--; \
159 mtx_unlock(&softc->ipf_rw.ipf_lk); }
160 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
161 # define ATOMIC_INC64(x) ATOMIC_INC(x)
162 # define ATOMIC_INC32(x) atomic_add_32((u_int *)&(x), 1)
163 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
164 # define ATOMIC_DEC64(x) ATOMIC_DEC(x)
165 # define ATOMIC_DEC32(x) atomic_add_32((u_int *)&(x), -1)
167 # define SPL_NET(x) ;
168 # define SPL_IMP(x) ;
169 # define SPL_SCHED(x) ;
170 # define GET_MINOR dev2unit
171 # define MSGDSIZE(m) mbufchainlen(m)
172 # define M_LEN(m) (m)->m_len
173 # define M_ADJ(m,x) m_adj(m, x)
174 # define M_COPY(x) m_copym((x), 0, M_COPYALL, M_NOWAIT)
175 # define M_DUP(m) m_dup(m, M_NOWAIT)
176 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
177 typedef struct mbuf mb_t;
180 # ifndef _NET_IF_VAR_H_
182 * Userland emulation of struct ifnet.
187 char if_xname[IFNAMSIZ];
188 STAILQ_HEAD(, ifaddr) if_addrlist;
189 int (*if_output)(struct ifnet *, struct mbuf *,
190 const struct sockaddr *, struct route *);
192 # endif /* _NET_IF_VAR_H_ */
195 #define IFNAME(x) ((struct ifnet *)x)->if_xname
196 #define COPYIFNAME(v, x, b) \
198 ((struct ifnet *)x)->if_xname, \
201 typedef u_long ioctlcmd_t;
202 typedef struct uio uio_t;
204 typedef u_int32_t u_32_t;
208 /* ----------------------------------------------------------------------- */
210 /* ----------------------------------------------------------------------- */
213 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
216 #if !defined(IPFILTER_BPF)
217 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
218 (defined(NBPFILTER) && (NBPFILTER > 0))
219 # define IPFILTER_BPF
224 * Userland locking primitives
227 # if !defined(KMUTEX_FILL_SZ)
228 # define KMUTEX_FILL_SZ 1
230 # if !defined(KRWLOCK_FILL_SZ)
231 # define KRWLOCK_FILL_SZ 1
253 char _fill[KMUTEX_FILL_SZ];
257 const char *ipf_lname;
264 char _fill[KRWLOCK_FILL_SZ];
268 const char *ipf_lname;
277 #define ipf_lk ipf_lkun_s.ipf_slk
278 #define ipf_lname ipf_lkun_s.ipf_lname
279 #define ipf_isr ipf_lkun_s.ipf_sr
280 #define ipf_isw ipf_lkun_s.ipf_sw
281 #define ipf_magic ipf_lkun_s.ipf_magic
283 #if defined(__FreeBSD__) && defined(_KERNEL)
284 CTASSERT(sizeof(ipfrwlock_t) == KRWLOCK_FILL_SZ);
285 CTASSERT(sizeof(ipfmutex_t) == KMUTEX_FILL_SZ);
290 * In a non-kernel environment, there are a lot of macros that need to be
291 * filled in to be null-ops or to point to some compatibility function,
292 * somewhere in userland.
295 typedef struct mb_s {
296 struct mb_s *mb_next;
304 # define m_next mb_next
306 # define m_len mb_len
308 # define m_flags mb_flags
310 # define m_data mb_data
312 # define M_MCAST 0x01
314 # define M_BCAST 0x02
316 # define M_MBCAST 0x04
317 # define MSGDSIZE(m) msgdsize(m)
318 # define M_LEN(m) (m)->mb_len
319 # define M_ADJ(m,x) (m)->mb_len += x
320 # define M_COPY(m) dupmbt(m)
321 # define M_DUP(m) dupmbt(m)
322 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL)
323 # define MTOD(m, t) ((t)(m)->mb_data)
324 # define FREE_MB_T(m) freembt(m)
325 # define ALLOC_MB_T(m,l) (m) = allocmbt(l)
326 # define PREP_MB_T(f, m) do { \
327 (m)->mb_next = *(f)->fin_mp; \
328 *(fin)->fin_mp = (m); \
331 # define SLEEP(x,y) 1;
332 # define WAKEUP(x,y) ;
333 # define POLLWAKEUP(y) ;
334 # define IPF_PANIC(x,y) ;
335 # define PANIC(x,y) ;
336 # define SPL_SCHED(x) ;
337 # define SPL_NET(x) ;
338 # define SPL_IMP(x) ;
340 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
341 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
342 # define KFREE(x) free(x)
343 # define KFREES(x,s) free(x)
344 # define GETIFP(x, v) get_unit(x,v)
345 # define GETIFMTU_4(x) 2048
346 # define GETIFMTU_6(x) 2048
347 # define COPYIN(a,b,c) bcopywrap((a), (b), (c))
348 # define COPYOUT(a,b,c) bcopywrap((a), (b), (c))
349 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \
351 # define COPYBACK(m, o, l, b) bcopy((b), \
352 MTOD((mb_t *)m, char *) + (o), \
354 # define UIOMOVE(a,b,c,d) ipfuiomove((caddr_t)a,b,c,d)
355 extern void m_copydata(mb_t *, int, int, caddr_t);
356 extern int ipfuiomove(caddr_t, int, int, struct uio *);
357 extern int bcopywrap(void *, void *, size_t);
358 extern mb_t *allocmbt(size_t);
359 extern mb_t *dupmbt(mb_t *);
360 extern void freembt(mb_t *);
362 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu, \
364 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \
366 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu, \
368 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y, \
370 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
372 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \
374 # define MUTEX_TRY_UPGRADE(x) eMrwlock_try_upgrade(&(x)->ipf_emu, \
376 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \
378 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y)
379 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu)
380 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu)
381 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \
385 # define USE_MUTEXES 1
387 extern void eMmutex_destroy(eMmutex_t *, char *, int);
388 extern void eMmutex_enter(eMmutex_t *, char *, int);
389 extern void eMmutex_exit(eMmutex_t *, char *, int);
390 extern void eMmutex_init(eMmutex_t *, char *, char *, int);
391 extern void eMrwlock_destroy(eMrwlock_t *);
392 extern void eMrwlock_exit(eMrwlock_t *);
393 extern void eMrwlock_init(eMrwlock_t *, char *);
394 extern void eMrwlock_read_enter(eMrwlock_t *, char *, int);
395 extern void eMrwlock_write_enter(eMrwlock_t *, char *, int);
396 extern void eMrwlock_downgrade(eMrwlock_t *, char *, int);
400 extern mb_t *allocmbt(size_t);
402 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
405 # define IP_OFFMASK 0x1fff
410 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
413 #if !defined(__amd64__) && !SOLARIS
415 # define U_QUAD_T unsigned long long
416 # define QUAD_T long long
418 # if !defined(U_QUAD_T)
419 # define U_QUAD_T u_long
426 # if defined(__NetBSD__) || defined(__FreeBSD__)
427 # include <netinet/ip6.h>
428 # include <netinet/icmp6.h>
429 # if defined(_KERNEL)
430 # include <netinet6/ip6_var.h>
432 typedef struct ip6_hdr ip6_t;
437 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
441 # if SOLARIS && !defined(INSTANCES)
442 # define COPYDATA mb_copydata
443 # define COPYBACK mb_copyback
445 # define COPYDATA m_copydata
446 # define COPYBACK m_copyback
448 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
452 # if NETBSD_GE_REV(105180000)
453 # include <uvm/uvm_extern.h>
455 # include <vm/vm_extern.h>
456 extern vm_map_t kmem_map;
458 # include <sys/proc.h>
460 # ifdef IPFILTER_M_IPFILTER
461 # include <sys/malloc.h>
462 MALLOC_DECLARE(M_IPFILTER);
463 # define _M_IPF M_IPFILTER
464 # else /* IPFILTER_M_IPFILTER */
466 # define _M_IPF M_PFIL
469 # define _M_IPF M_IPFILTER
471 # define _M_IPF M_TEMP
472 # endif /* M_IPFILTER */
474 # endif /* IPFILTER_M_IPFILTER */
475 # if !defined(KMALLOC)
476 # define KMALLOC(a, b) (a) = (b)malloc(sizeof(*(a)), _M_IPF, M_NOWAIT)
478 # if !defined(KMALLOCS)
479 # define KMALLOCS(a, b, c) (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
482 # define KFREE(x) free((x), _M_IPF)
484 # if !defined(KFREES)
485 # define KFREES(x,s) free((x), _M_IPF)
487 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,d)
488 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
489 # define WAKEUP(id,x) wakeup(id+x)
490 # if !defined(POLLWAKEUP)
491 # define POLLWAKEUP(x) selwakeup(softc->ipf_selwait+x)
493 # define GETIFP(n, v) ifunit(n)
494 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
495 # define GETIFMTU_6(x) ((struct ifnet *)x)->if_mtu
497 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
498 # define SPL_IMP(x) x = splimp()
499 # define SPL_NET(x) x = splnet()
500 # if !defined(SPL_SCHED)
501 # define SPL_SCHED(x) x = splsched()
503 # define SPL_X(x) (void) splx(x)
504 # endif /* !USE_MUTEXES */
507 # define FREE_MB_T(m) m_freem(m)
511 # define ALLOC_MB_T(m,l) do { \
512 MGETHDR((m), M_NOWAIT, MT_HEADER); \
515 (m)->m_pkthdr.len = (l); \
519 # define ALLOC_MB_T(m,l) do { \
520 MGET((m), M_NOWAIT, MT_HEADER); \
523 (m)->m_pkthdr.len = (l); \
529 # define PREP_MB_T(f, m) do { \
530 mb_t *_o = *(f)->fin_mp; \
532 *(fin)->fin_mp = (m); \
533 if (_o->m_flags & M_PKTHDR) { \
534 (m)->m_pkthdr.len += \
536 (m)->m_pkthdr.rcvif = \
537 _o->m_pkthdr.rcvif; \
543 # define M_DUP(m) m_dup(m, 0, M_COPYALL, 0)
545 # define M_DUP(m) m_dup(m)
550 # define MTOD(m,t) mtod(m,t)
554 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
555 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
558 # if SOLARIS && !defined(KMALLOC)
559 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
561 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
565 # define GET_MINOR(x) dev2unit(x)
567 # define PANIC(x,y) if (x) panic y
570 #if !defined(IFNAME) && !defined(_KERNEL)
571 # define IFNAME(x) get_ifname((struct ifnet *)x)
574 # define NEED_FRGETIFNAME
575 extern char *ipf_getifname(struct ifnet *, char *);
576 # define COPYIFNAME(v, x, b) \
577 ipf_getifname((struct ifnet *)x, b)
584 # define ASSERT(x) do { if (!(x)) abort(); } while (0)
589 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
590 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
594 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
595 * would mean all normal code that walks through strings needed casts. Yuck.
597 #define ISALNUM(x) isalnum((u_char)(x))
598 #define ISALPHA(x) isalpha((u_char)(x))
599 #define ISDIGIT(x) isdigit((u_char)(x))
600 #define ISSPACE(x) isspace((u_char)(x))
601 #define ISUPPER(x) isupper((u_char)(x))
602 #define ISXDIGIT(x) isxdigit((u_char)(x))
603 #define ISLOWER(x) islower((u_char)(x))
604 #define TOUPPER(x) toupper((u_char)(x))
605 #define TOLOWER(x) tolower((u_char)(x))
608 * If mutexes aren't being used, turn all the mutex functions into null-ops.
610 #if !defined(USE_MUTEXES)
615 # undef MUTEX_DESTROY
616 # define MUTEX_ENTER(x) ;
617 # define READ_ENTER(x) ;
618 # define WRITE_ENTER(x) ;
619 # define MUTEX_DOWNGRADE(x) ;
620 # define MUTEX_TRY_UPGRADE(x) ;
621 # define RWLOCK_INIT(x, y) ;
622 # define RWLOCK_EXIT(x) ;
623 # define RW_DESTROY(x) ;
624 # define MUTEX_EXIT(x) ;
625 # define MUTEX_INIT(x,y) ;
626 # define MUTEX_DESTROY(x) ;
627 # define MUTEX_NUKE(x) ;
628 #endif /* !USE_MUTEXES */
630 # define ATOMIC_INC(x) (x)++
631 # define ATOMIC_DEC(x) (x)--
634 #if defined(USE_SPL) && defined(_KERNEL)
635 # define SPL_INT(x) int x
641 * If there are no atomic operations for bit sizes defined, define them to all
642 * use a generic one that works for all sizes.
645 # define ATOMIC_INCL ATOMIC_INC
646 # define ATOMIC_INC64 ATOMIC_INC
647 # define ATOMIC_INC32 ATOMIC_INC
648 # define ATOMIC_DECL ATOMIC_DEC
649 # define ATOMIC_DEC64 ATOMIC_DEC
650 # define ATOMIC_DEC32 ATOMIC_DEC
653 #ifndef HDR_T_PRIVATE
654 typedef struct tcphdr tcphdr_t;
655 typedef struct udphdr udphdr_t;
657 typedef struct icmp icmphdr_t;
658 typedef struct ip ip_t;
659 typedef struct ether_header ether_header_t;
660 typedef struct tcpiphdr tcpiphdr_t;
663 # define FR_GROUPLEN 16
667 # define offsetof(t,m) (size_t)((&((t *)0L)->m))
670 # define stsizeof(t,m) sizeof(((t *)0L)->m)
674 * This set of macros has been brought about because on Tru64 it is not
675 * possible to easily assign or examine values in a structure that are
679 # define IP_V(x) (x)->ip_v
682 # define IP_V_A(x,y) (x)->ip_v = (y)
685 # define IP_HL(x) (x)->ip_hl
688 # define IP_HL_A(x,y) (x)->ip_hl = ((y) & 0xf)
691 # define TCP_OFF(x) (x)->th_off
694 # define TCP_OFF_A(x,y) (x)->th_off = (y)
696 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
698 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
701 #if !SOLARIS && !defined(m_act)
702 # define m_act m_nextpkt
706 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
710 * 00000001 - (Reserved 4)
711 * 00111101 - Top Secret
713 * 10010110 - Confidential
714 * 01100110 - (Reserved 3)
715 * 11001100 - (Reserved 2)
716 * 10101011 - Unclassified
717 * 11110001 - (Reserved 1)
719 #define IPSO_CLASS_RES4 0x01
720 #define IPSO_CLASS_TOPS 0x3d
721 #define IPSO_CLASS_SECR 0x5a
722 #define IPSO_CLASS_CONF 0x96
723 #define IPSO_CLASS_RES3 0x66
724 #define IPSO_CLASS_RES2 0xcc
725 #define IPSO_CLASS_UNCL 0xab
726 #define IPSO_CLASS_RES1 0xf1
728 #define IPSO_AUTH_GENSER 0x80
729 #define IPSO_AUTH_ESI 0x40
730 #define IPSO_AUTH_SCI 0x20
731 #define IPSO_AUTH_NSA 0x10
732 #define IPSO_AUTH_DOE 0x08
733 #define IPSO_AUTH_UN 0x06
734 #define IPSO_AUTH_FTE 0x01
742 #define IPOPT_ZSU 10 /* ZSU */
744 #define IPOPT_MTUP 11 /* MTUP */
746 #define IPOPT_MTUR 12 /* MTUR */
748 #define IPOPT_ENCODE 15 /* ENCODE */
752 #define IPOPT_TR 82 /* TR */
753 #undef IPOPT_SECURITY
754 #define IPOPT_SECURITY 130
756 #define IPOPT_LSRR 131
758 #define IPOPT_E_SEC 133 /* E-SEC */
760 #define IPOPT_CIPSO 134 /* CIPSO */
762 #define IPOPT_SATID 136
764 # define IPOPT_SID IPOPT_SATID
767 #define IPOPT_SSRR 137
769 #define IPOPT_ADDEXT 147 /* ADDEXT */
771 #define IPOPT_VISA 142 /* VISA */
773 #define IPOPT_IMITD 144 /* IMITD */
775 #define IPOPT_EIP 145 /* EIP */
777 #define IPOPT_RTRALRT 148 /* RTRALRT */
779 #define IPOPT_SDB 149
781 #define IPOPT_NSAPA 150
783 #define IPOPT_DPS 151
785 #define IPOPT_UMP 152
787 #define IPOPT_FINN 205 /* FINN */
789 #define IPOPT_AH 256+IPPROTO_AH
791 #define ICMP_UNREACH_ADMIN_PROHIBIT ICMP_UNREACH_FILTER_PROHIB
792 #define ICMP_UNREACH_FILTER ICMP_UNREACH_FILTER_PROHIB
798 # define IPOPT_MINOFF 4
801 # define IPOPT_COPIED(x) ((x)&0x80)
810 # define IP_MF ((u_short)0x2000)
813 # define ETHERTYPE_IP ((u_short)0x0800)
825 # define TH_PUSH 0x08
834 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK)
848 #ifndef IPOPT_SECURITY
849 # define IPOPT_SECURITY 130
852 # define IPOPT_LSRR 131
855 # define IPOPT_SATID 136
858 # define IPOPT_SSRR 137
860 #ifndef IPOPT_SECUR_UNCLASS
861 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
863 #ifndef IPOPT_SECUR_CONFID
864 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
866 #ifndef IPOPT_SECUR_EFTO
867 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
869 #ifndef IPOPT_SECUR_MMMM
870 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
872 #ifndef IPOPT_SECUR_RESTR
873 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
875 #ifndef IPOPT_SECUR_SECRET
876 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
878 #ifndef IPOPT_SECUR_TOPSECRET
879 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
882 # define IPOPT_OLEN 1
884 #ifndef IPPROTO_HOPOPTS
885 # define IPPROTO_HOPOPTS 0
888 # define IPPROTO_IPIP 4
890 #ifndef IPPROTO_ENCAP
891 # define IPPROTO_ENCAP 98
894 # define IPPROTO_IPV6 41
896 #ifndef IPPROTO_ROUTING
897 # define IPPROTO_ROUTING 43
899 #ifndef IPPROTO_FRAGMENT
900 # define IPPROTO_FRAGMENT 44
903 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
906 # define IPPROTO_ESP 50
909 # define IPPROTO_AH 51
911 #ifndef IPPROTO_ICMPV6
912 # define IPPROTO_ICMPV6 58
915 # define IPPROTO_NONE 59
917 #ifndef IPPROTO_DSTOPTS
918 # define IPPROTO_DSTOPTS 60
920 #ifndef IPPROTO_MOBILITY
921 # define IPPROTO_MOBILITY 135
924 #ifndef ICMP_ROUTERADVERT
925 # define ICMP_ROUTERADVERT 9
927 #ifndef ICMP_ROUTERSOLICIT
928 # define ICMP_ROUTERSOLICIT 10
930 #ifndef ICMP6_DST_UNREACH
931 # define ICMP6_DST_UNREACH 1
933 #ifndef ICMP6_PACKET_TOO_BIG
934 # define ICMP6_PACKET_TOO_BIG 2
936 #ifndef ICMP6_TIME_EXCEEDED
937 # define ICMP6_TIME_EXCEEDED 3
939 #ifndef ICMP6_PARAM_PROB
940 # define ICMP6_PARAM_PROB 4
943 #ifndef ICMP6_ECHO_REQUEST
944 # define ICMP6_ECHO_REQUEST 128
946 #ifndef ICMP6_ECHO_REPLY
947 # define ICMP6_ECHO_REPLY 129
949 #ifndef ICMP6_MEMBERSHIP_QUERY
950 # define ICMP6_MEMBERSHIP_QUERY 130
952 #ifndef MLD6_LISTENER_QUERY
953 # define MLD6_LISTENER_QUERY 130
955 #ifndef ICMP6_MEMBERSHIP_REPORT
956 # define ICMP6_MEMBERSHIP_REPORT 131
958 #ifndef MLD6_LISTENER_REPORT
959 # define MLD6_LISTENER_REPORT 131
961 #ifndef ICMP6_MEMBERSHIP_REDUCTION
962 # define ICMP6_MEMBERSHIP_REDUCTION 132
964 #ifndef MLD6_LISTENER_DONE
965 # define MLD6_LISTENER_DONE 132
967 #ifndef ND_ROUTER_SOLICIT
968 # define ND_ROUTER_SOLICIT 133
970 #ifndef ND_ROUTER_ADVERT
971 # define ND_ROUTER_ADVERT 134
973 #ifndef ND_NEIGHBOR_SOLICIT
974 # define ND_NEIGHBOR_SOLICIT 135
976 #ifndef ND_NEIGHBOR_ADVERT
977 # define ND_NEIGHBOR_ADVERT 136
980 # define ND_REDIRECT 137
982 #ifndef ICMP6_ROUTER_RENUMBERING
983 # define ICMP6_ROUTER_RENUMBERING 138
985 #ifndef ICMP6_WRUREQUEST
986 # define ICMP6_WRUREQUEST 139
988 #ifndef ICMP6_WRUREPLY
989 # define ICMP6_WRUREPLY 140
991 #ifndef ICMP6_FQDN_QUERY
992 # define ICMP6_FQDN_QUERY 139
994 #ifndef ICMP6_FQDN_REPLY
995 # define ICMP6_FQDN_REPLY 140
997 #ifndef ICMP6_NI_QUERY
998 # define ICMP6_NI_QUERY 139
1000 #ifndef ICMP6_NI_REPLY
1001 # define ICMP6_NI_REPLY 140
1003 #ifndef MLD6_MTRACE_RESP
1004 # define MLD6_MTRACE_RESP 200
1007 # define MLD6_MTRACE 201
1009 #ifndef ICMP6_HADISCOV_REQUEST
1010 # define ICMP6_HADISCOV_REQUEST 202
1012 #ifndef ICMP6_HADISCOV_REPLY
1013 # define ICMP6_HADISCOV_REPLY 203
1015 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
1016 # define ICMP6_MOBILEPREFIX_SOLICIT 204
1018 #ifndef ICMP6_MOBILEPREFIX_ADVERT
1019 # define ICMP6_MOBILEPREFIX_ADVERT 205
1021 #ifndef ICMP6_MAXTYPE
1022 # define ICMP6_MAXTYPE 205
1025 #ifndef ICMP6_DST_UNREACH_NOROUTE
1026 # define ICMP6_DST_UNREACH_NOROUTE 0
1028 #ifndef ICMP6_DST_UNREACH_ADMIN
1029 # define ICMP6_DST_UNREACH_ADMIN 1
1031 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
1032 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
1034 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
1035 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
1037 #ifndef ICMP6_DST_UNREACH_ADDR
1038 # define ICMP6_DST_UNREACH_ADDR 3
1040 #ifndef ICMP6_DST_UNREACH_NOPORT
1041 # define ICMP6_DST_UNREACH_NOPORT 4
1043 #ifndef ICMP6_TIME_EXCEED_TRANSIT
1044 # define ICMP6_TIME_EXCEED_TRANSIT 0
1046 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
1047 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
1050 #ifndef ICMP6_NI_SUCCESS
1051 # define ICMP6_NI_SUCCESS 0
1053 #ifndef ICMP6_NI_REFUSED
1054 # define ICMP6_NI_REFUSED 1
1056 #ifndef ICMP6_NI_UNKNOWN
1057 # define ICMP6_NI_UNKNOWN 2
1060 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
1061 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
1063 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
1064 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
1066 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1067 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
1070 #ifndef ICMP6_PARAMPROB_HEADER
1071 # define ICMP6_PARAMPROB_HEADER 0
1073 #ifndef ICMP6_PARAMPROB_NEXTHEADER
1074 # define ICMP6_PARAMPROB_NEXTHEADER 1
1076 #ifndef ICMP6_PARAMPROB_OPTION
1077 # define ICMP6_PARAMPROB_OPTION 2
1080 #ifndef ICMP6_NI_SUBJ_IPV6
1081 # define ICMP6_NI_SUBJ_IPV6 0
1083 #ifndef ICMP6_NI_SUBJ_FQDN
1084 # define ICMP6_NI_SUBJ_FQDN 1
1086 #ifndef ICMP6_NI_SUBJ_IPV4
1087 # define ICMP6_NI_SUBJ_IPV4 2
1090 #ifndef MLD_MTRACE_RESP
1091 # define MLD_MTRACE_RESP 200
1094 # define MLD_MTRACE 201
1096 #ifndef MLD6_MTRACE_RESP
1097 # define MLD6_MTRACE_RESP MLD_MTRACE_RESP
1100 # define MLD6_MTRACE MLD_MTRACE
1103 #if !defined(IPV6_FLOWINFO_MASK)
1104 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1105 # define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
1107 # if(BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1108 # define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
1109 # endif /* LITTLE_ENDIAN */
1112 #if !defined(IPV6_FLOWLABEL_MASK)
1113 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1114 # define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
1116 # if (BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1117 # define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
1118 # endif /* LITTLE_ENDIAN */
1123 * ECN is a new addition to TCP - RFC 2481
1126 # define TH_ECN 0x40
1129 # define TH_CWR 0x80
1131 #define TH_ECNALL (TH_ECN|TH_CWR)
1136 #define IPF_TCPS_LISTEN 0 /* listening for connection */
1137 #define IPF_TCPS_SYN_SENT 1 /* active, have sent syn */
1138 #define IPF_TCPS_SYN_RECEIVED 2 /* have send and received syn */
1139 #define IPF_TCPS_HALF_ESTAB 3 /* for connections not fully "up" */
1140 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
1141 #define IPF_TCPS_ESTABLISHED 4 /* established */
1142 #define IPF_TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
1143 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
1144 #define IPF_TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
1145 #define IPF_TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
1146 #define IPF_TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
1147 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
1148 #define IPF_TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
1149 #define IPF_TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
1150 #define IPF_TCPS_CLOSED 11 /* closed */
1151 #define IPF_TCP_NSTATES 12
1155 #undef ICMP_MAX_UNREACH
1156 #define ICMP_MAX_UNREACH 14
1158 #define ICMP_MAXTYPE 18
1161 # define LOG_FTP (11<<3)
1163 #ifndef LOG_AUTHPRIV
1164 # define LOG_AUTHPRIV (10<<3)
1167 # define LOG_AUDIT (13<<3)
1170 # define LOG_NTP (12<<3)
1172 #ifndef LOG_SECURITY
1173 # define LOG_SECURITY (13<<3)
1176 # define LOG_LFMT (14<<3)
1179 # define LOG_CONSOLE (14<<3)
1183 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1184 * another IP header and then 64 bits of data, totalling 56. Of course,
1185 * the last 64 bits is dependent on that being available.
1187 #define ICMPERR_ICMPHLEN 8
1188 #define ICMPERR_IPICMPHLEN (20 + 8)
1189 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
1190 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
1191 #define ICMP6ERR_MINPKTLEN (40 + 8)
1192 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
1195 # define MIN(a,b) (((a)<(b))?(a):(b))
1199 # undef IPFILTER_BPF
1203 # define DPRINT(x) printf x
1208 #if defined(DTRACE_PROBE) && defined(_KERNEL)
1209 # define DT(_n) DTRACE_PROBE(_n)
1210 # define DT1(_n,_a,_b) DTRACE_PROBE1(_n,_a,_b)
1211 # define DT2(_n,_a,_b,_c,_d) DTRACE_PROBE2(_n,_a,_b,_c,_d)
1212 # define DT3(_n,_a,_b,_c,_d,_e,_f) \
1213 DTRACE_PROBE3(_n,_a,_b,_c,_d,_e,_f)
1214 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h) \
1215 DTRACE_PROBE4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1216 # define DT5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j) \
1217 DTRACE_PROBE5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j)
1220 # define DT1(_n,_a,_b)
1221 # define DT2(_n,_a,_b,_c,_d)
1222 # define DT3(_n,_a,_b,_c,_d,_e,_f)
1223 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1224 # define DT5(_n,_a,_b,_c,_d,_e,_f,_g,_h,_i,_j)
1227 struct ip6_routing {
1228 u_char ip6r_nxt; /* next header */
1229 u_char ip6r_len; /* length in units of 8 octets */
1230 u_char ip6r_type; /* always zero */
1231 u_char ip6r_segleft; /* segments left */
1232 u_32_t ip6r_reserved; /* reserved field */
1235 #endif /* __IP_COMPAT_H__ */