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
8 * Id: ip_compat.h,v 2.142.2.57 2007/10/10 09:51:42 darrenr Exp $
11 #ifndef __IP_COMPAT_H__
12 #define __IP_COMPAT_H__
26 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
36 # if defined(sun) && defined(__SVR4)
46 # if !defined(_KERNEL)
47 # define bzero(a,b) memset(a,0,b)
49 # define bcopy(a,b,c) memmove(b,a,c)
55 # define LIFNAMSIZ IF_NAMESIZE
58 # define LIFNAMSIZ IFNAMSIZ
67 # define IPL_EXTERN(ep) ipl##ep
69 # define IPL_EXTERN(ep) ipl/**/ep
73 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
86 #define NETBSD_GE_REV(x) (defined(__NetBSD_Version__) && \
87 (__NetBSD_Version__ >= (x)))
88 #define NETBSD_GT_REV(x) (defined(__NetBSD_Version__) && \
89 (__NetBSD_Version__ > (x)))
90 #define NETBSD_LT_REV(x) (defined(__NetBSD_Version__) && \
91 (__NetBSD_Version__ < (x)))
92 #define FREEBSD_GE_REV(x) (defined(__FreeBSD_version) && \
93 (__FreeBSD_version >= (x)))
94 #define FREEBSD_GT_REV(x) (defined(__FreeBSD_version) && \
95 (__FreeBSD_version > (x)))
96 #define FREEBSD_LT_REV(x) (defined(__FreeBSD_version) && \
97 (__FreeBSD_version < (x)))
98 #define BSD_GE_YEAR(x) (defined(BSD) && (BSD >= (x)))
99 #define BSD_GT_YEAR(x) (defined(BSD) && (BSD > (x)))
100 #define BSD_LT_YEAR(x) (defined(BSD) && (BSD < (x)))
103 /* ----------------------------------------------------------------------- */
105 /* ----------------------------------------------------------------------- */
106 # define HAS_SYS_MD5_H 1
107 # if defined(_KERNEL)
108 # include "opt_bpf.h"
109 # include "opt_inet6.h"
110 # if defined(INET6) && !defined(USE_INET6)
114 # if !defined(USE_INET6) && !defined(NOINET6)
119 # if defined(_KERNEL)
120 # include <netinet/ip_var.h>
121 # define p_cred td_ucred
122 # define p_uid td_ucred->cr_ruid
125 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
126 * There may be other, safe, kernels but this is not extensively tested yet.
128 # define HAVE_M_PULLDOWN
129 # if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
130 # include "opt_ipfilter.h"
132 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
133 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
136 # include <inttypes.h>
137 # endif /* _KERNEL */
139 # include <sys/selinfo.h>
140 # include <sys/lock.h>
141 # include <sys/malloc.h>
142 # include <sys/mutex.h>
143 # define KRWLOCK_FILL_SZ 56
144 # define KMUTEX_FILL_SZ 56
145 # include <sys/rwlock.h>
146 # define KMUTEX_T struct mtx
147 # define KRWLOCK_T struct rwlock
150 # define READ_ENTER(x) rw_rlock(&(x)->ipf_lk)
151 # define WRITE_ENTER(x) rw_wlock(&(x)->ipf_lk)
152 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
153 # define MUTEX_TRY_UPGRADE(x) rw_try_upgrade(&(x)->ipf_lk)
154 # define RWLOCK_INIT(x,y) rw_init(&(x)->ipf_lk, (y))
155 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
156 # define RWLOCK_EXIT(x) do { \
157 if (rw_wowned(&(x)->ipf_lk)) \
158 rw_wunlock(&(x)->ipf_lk); \
160 rw_runlock(&(x)->ipf_lk); \
162 # include <net/if_var.h>
163 # define GETKTIME(x) microtime((struct timeval *)x)
164 # define if_addrlist if_addrhead
166 # include <netinet/in_systm.h>
167 # include <netinet/ip.h>
168 # include <machine/in_cksum.h>
171 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk)
172 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk)
173 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
175 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
176 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
178 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
179 * for what we want to use them for, despite testing showing they work -
180 * with a WITNESS kernel, it generates LOR messages.
182 # include <machine/atomic.h>
183 # define ATOMIC_INC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)++; \
184 mtx_unlock(&softc->ipf_rw.ipf_lk); }
185 # define ATOMIC_DEC(x) { mtx_lock(&softc->ipf_rw.ipf_lk); (x)--; \
186 mtx_unlock(&softc->ipf_rw.ipf_lk); }
187 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
188 # define ATOMIC_INC64(x) ATOMIC_INC(x)
189 # define ATOMIC_INC32(x) atomic_add_32((u_int *)&(x), 1)
190 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
191 # define ATOMIC_DEC64(x) ATOMIC_DEC(x)
192 # define ATOMIC_DEC32(x) atomic_add_32((u_int *)&(x), -1)
194 # define SPL_NET(x) ;
195 # define SPL_IMP(x) ;
196 # define SPL_SCHED(x) ;
197 # define GET_MINOR dev2unit
198 # define MSGDSIZE(m) mbufchainlen(m)
199 # define M_LEN(m) (m)->m_len
200 # define M_ADJ(m,x) m_adj(m, x)
201 # define M_COPY(x) m_copym((x), 0, M_COPYALL, M_NOWAIT)
202 # define M_DUP(m) m_dup(m, M_NOWAIT)
203 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
204 typedef struct mbuf mb_t;
207 #ifndef _NET_IF_VAR_H_
209 * Userland emulation of struct ifnet.
214 char if_xname[IFNAMSIZ];
215 STAILQ_HEAD(, ifaddr) if_addrlist;
216 int (*if_output)(struct ifnet *, struct mbuf *,
217 const struct sockaddr *, struct route *);
219 #endif /* _NET_IF_VAR_H_ */
222 # define IFNAME(x) ((struct ifnet *)x)->if_xname
223 # define COPYIFNAME(v, x, b) \
225 ((struct ifnet *)x)->if_xname, \
228 typedef u_long ioctlcmd_t;
229 typedef struct uio uio_t;
231 typedef u_int32_t u_32_t;
235 /* ----------------------------------------------------------------------- */
237 /* ----------------------------------------------------------------------- */
240 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
243 #if !defined(IPFILTER_BPF)
244 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
245 (defined(NBPFILTER) && (NBPFILTER > 0))
246 # define IPFILTER_BPF
251 * Userland locking primitives
254 #if !defined(KMUTEX_FILL_SZ)
255 # define KMUTEX_FILL_SZ 1
257 #if !defined(KRWLOCK_FILL_SZ)
258 # define KRWLOCK_FILL_SZ 1
280 char _fill[KMUTEX_FILL_SZ];
284 const char *ipf_lname;
291 char _fill[KRWLOCK_FILL_SZ];
295 const char *ipf_lname;
304 #define ipf_lk ipf_lkun_s.ipf_slk
305 #define ipf_lname ipf_lkun_s.ipf_lname
306 #define ipf_isr ipf_lkun_s.ipf_sr
307 #define ipf_isw ipf_lkun_s.ipf_sw
308 #define ipf_magic ipf_lkun_s.ipf_magic
310 #if !defined(__GNUC__) || defined(__FreeBSD_version)
315 # define INLINE __inline__
318 #if defined(__FreeBSD_version) && defined(_KERNEL)
319 CTASSERT(sizeof(ipfrwlock_t) == KRWLOCK_FILL_SZ);
320 CTASSERT(sizeof(ipfmutex_t) == KMUTEX_FILL_SZ);
325 * In a non-kernel environment, there are a lot of macros that need to be
326 * filled in to be null-ops or to point to some compatibility function,
327 * somewhere in userland.
330 typedef struct mb_s {
331 struct mb_s *mb_next;
339 # define m_next mb_next
341 # define m_len mb_len
343 # define m_flags mb_flags
345 # define m_data mb_data
347 # define M_MCAST 0x01
349 # define M_BCAST 0x02
351 # define M_MBCAST 0x04
352 # define MSGDSIZE(m) msgdsize(m)
353 # define M_LEN(m) (m)->mb_len
354 # define M_ADJ(m,x) (m)->mb_len += x
355 # define M_COPY(m) dupmbt(m)
356 # define M_DUP(m) dupmbt(m)
357 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL)
358 # define MTOD(m, t) ((t)(m)->mb_data)
359 # define FREE_MB_T(m) freembt(m)
360 # define ALLOC_MB_T(m,l) (m) = allocmbt(l)
361 # define PREP_MB_T(f, m) do { \
362 (m)->mb_next = *(f)->fin_mp; \
363 *(fin)->fin_mp = (m); \
366 # define SLEEP(x,y) 1;
367 # define WAKEUP(x,y) ;
368 # define POLLWAKEUP(y) ;
369 # define IPF_PANIC(x,y) ;
370 # define PANIC(x,y) ;
371 # define SPL_SCHED(x) ;
372 # define SPL_NET(x) ;
373 # define SPL_IMP(x) ;
375 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
376 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
377 # define KFREE(x) free(x)
378 # define KFREES(x,s) free(x)
379 # define GETIFP(x, v) get_unit(x,v)
380 # define GETIFMTU_4(x) 2048
381 # define GETIFMTU_6(x) 2048
382 # define COPYIN(a,b,c) bcopywrap((a), (b), (c))
383 # define COPYOUT(a,b,c) bcopywrap((a), (b), (c))
384 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \
386 # define COPYBACK(m, o, l, b) bcopy((b), \
387 MTOD((mb_t *)m, char *) + (o), \
389 # define UIOMOVE(a,b,c,d) ipfuiomove((caddr_t)a,b,c,d)
390 extern void m_copydata __P((mb_t *, int, int, caddr_t));
391 extern int ipfuiomove __P((caddr_t, int, int, struct uio *));
392 extern int bcopywrap __P((void *, void *, size_t));
393 extern mb_t *allocmbt __P((size_t));
394 extern mb_t *dupmbt __P((mb_t *));
395 extern void freembt __P((mb_t *));
397 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu, \
399 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \
401 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu, \
403 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y, \
405 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
407 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \
409 # define MUTEX_TRY_UPGRADE(x) eMrwlock_try_upgrade(&(x)->ipf_emu, \
411 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \
413 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y)
414 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu)
415 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu)
416 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \
420 # define USE_MUTEXES 1
422 extern void eMmutex_destroy __P((eMmutex_t *, char *, int));
423 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
424 extern void eMmutex_exit __P((eMmutex_t *, char *, int));
425 extern void eMmutex_init __P((eMmutex_t *, char *, char *, int));
426 extern void eMrwlock_destroy __P((eMrwlock_t *));
427 extern void eMrwlock_exit __P((eMrwlock_t *));
428 extern void eMrwlock_init __P((eMrwlock_t *, char *));
429 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
430 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
431 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
435 extern mb_t *allocmbt(size_t);
437 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
440 # define IP_OFFMASK 0x1fff
445 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
448 #if !defined(__amd64__) && BSD_GT_YEAR(199306)
450 # define U_QUAD_T unsigned long long
451 # define QUAD_T long long
452 #else /* BSD > 199306 */
453 # if !defined(U_QUAD_T)
454 # define U_QUAD_T u_long
457 #endif /* BSD > 199306 */
461 # if defined(__NetBSD__) || defined(__FreeBSD__)
462 # include <netinet/ip6.h>
463 # include <netinet/icmp6.h>
464 # if defined(_KERNEL)
465 # include <netinet6/ip6_var.h>
467 typedef struct ip6_hdr ip6_t;
472 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
476 # if defined(MENTAT) && !defined(INSTANCES)
477 # define COPYDATA mb_copydata
478 # define COPYBACK mb_copyback
480 # define COPYDATA m_copydata
481 # define COPYBACK m_copyback
483 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
487 # if NETBSD_GE_REV(105180000)
488 # include <uvm/uvm_extern.h>
490 # include <vm/vm_extern.h>
491 extern vm_map_t kmem_map;
493 # include <sys/proc.h>
495 # ifdef IPFILTER_M_IPFILTER
496 # include <sys/malloc.h>
497 MALLOC_DECLARE(M_IPFILTER);
498 # define _M_IPF M_IPFILTER
499 # else /* IPFILTER_M_IPFILTER */
501 # define _M_IPF M_PFIL
504 # define _M_IPF M_IPFILTER
506 # define _M_IPF M_TEMP
507 # endif /* M_IPFILTER */
509 # endif /* IPFILTER_M_IPFILTER */
510 # if !defined(KMALLOC)
511 # define KMALLOC(a, b) (a) = (b)malloc(sizeof(*(a)), _M_IPF, M_NOWAIT)
513 # if !defined(KMALLOCS)
514 # define KMALLOCS(a, b, c) (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
517 # define KFREE(x) free((x), _M_IPF)
519 # if !defined(KFREES)
520 # define KFREES(x,s) free((x), _M_IPF)
522 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,d)
523 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
524 # define WAKEUP(id,x) wakeup(id+x)
525 # if !defined(POLLWAKEUP)
526 # define POLLWAKEUP(x) selwakeup(softc->ipf_selwait+x)
528 # define GETIFP(n, v) ifunit(n)
529 # define GETIFMTU_4(x) ((struct ifnet *)x)->if_mtu
530 # define GETIFMTU_6(x) ((struct ifnet *)x)->if_mtu
532 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
533 # define SPL_IMP(x) x = splimp()
534 # define SPL_NET(x) x = splnet()
535 # if !defined(SPL_SCHED)
536 # define SPL_SCHED(x) x = splsched()
538 # define SPL_X(x) (void) splx(x)
539 # endif /* !USE_MUTEXES */
542 # define FREE_MB_T(m) m_freem(m)
546 # define ALLOC_MB_T(m,l) do { \
547 MGETHDR((m), M_NOWAIT, MT_HEADER); \
550 (m)->m_pkthdr.len = (l); \
554 # define ALLOC_MB_T(m,l) do { \
555 MGET((m), M_NOWAIT, MT_HEADER); \
558 (m)->m_pkthdr.len = (l); \
564 # define PREP_MB_T(f, m) do { \
565 mb_t *_o = *(f)->fin_mp; \
567 *(fin)->fin_mp = (m); \
568 if (_o->m_flags & M_PKTHDR) { \
569 (m)->m_pkthdr.len += \
571 (m)->m_pkthdr.rcvif = \
572 _o->m_pkthdr.rcvif; \
578 # define M_DUP(m) m_dup(m, 0, M_COPYALL, 0)
580 # define M_DUP(m) m_dup(m)
585 # define MTOD(m,t) mtod(m,t)
589 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
590 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
593 # if SOLARIS && !defined(KMALLOC)
594 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
596 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
600 # define GET_MINOR(x) dev2unit(x)
602 # define PANIC(x,y) if (x) panic y
605 #if !defined(IFNAME) && !defined(_KERNEL)
606 # define IFNAME(x) get_ifname((struct ifnet *)x)
609 # define NEED_FRGETIFNAME
610 extern char *ipf_getifname __P((struct ifnet *, char *));
611 # define COPYIFNAME(v, x, b) \
612 ipf_getifname((struct ifnet *)x, b)
619 # define ASSERT(x) do { if (!(x)) abort(); } while (0)
624 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
625 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
629 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
630 * would mean all normal code that walks through strings needed casts. Yuck.
632 #define ISALNUM(x) isalnum((u_char)(x))
633 #define ISALPHA(x) isalpha((u_char)(x))
634 #define ISDIGIT(x) isdigit((u_char)(x))
635 #define ISSPACE(x) isspace((u_char)(x))
636 #define ISUPPER(x) isupper((u_char)(x))
637 #define ISXDIGIT(x) isxdigit((u_char)(x))
638 #define ISLOWER(x) islower((u_char)(x))
639 #define TOUPPER(x) toupper((u_char)(x))
640 #define TOLOWER(x) tolower((u_char)(x))
643 * If mutexes aren't being used, turn all the mutex functions into null-ops.
645 #if !defined(USE_MUTEXES)
650 # undef MUTEX_DESTROY
651 # define MUTEX_ENTER(x) ;
652 # define READ_ENTER(x) ;
653 # define WRITE_ENTER(x) ;
654 # define MUTEX_DOWNGRADE(x) ;
655 # define MUTEX_TRY_UPGRADE(x) ;
656 # define RWLOCK_INIT(x, y) ;
657 # define RWLOCK_EXIT(x) ;
658 # define RW_DESTROY(x) ;
659 # define MUTEX_EXIT(x) ;
660 # define MUTEX_INIT(x,y) ;
661 # define MUTEX_DESTROY(x) ;
662 # define MUTEX_NUKE(x) ;
663 #endif /* !USE_MUTEXES */
665 # define ATOMIC_INC(x) (x)++
666 # define ATOMIC_DEC(x) (x)--
669 #if defined(USE_SPL) && defined(_KERNEL)
670 # define SPL_INT(x) int x
676 * If there are no atomic operations for bit sizes defined, define them to all
677 * use a generic one that works for all sizes.
680 # define ATOMIC_INCL ATOMIC_INC
681 # define ATOMIC_INC64 ATOMIC_INC
682 # define ATOMIC_INC32 ATOMIC_INC
683 # define ATOMIC_DECL ATOMIC_DEC
684 # define ATOMIC_DEC64 ATOMIC_DEC
685 # define ATOMIC_DEC32 ATOMIC_DEC
688 #ifndef HDR_T_PRIVATE
689 typedef struct tcphdr tcphdr_t;
690 typedef struct udphdr udphdr_t;
692 typedef struct icmp icmphdr_t;
693 typedef struct ip ip_t;
694 typedef struct ether_header ether_header_t;
695 typedef struct tcpiphdr tcpiphdr_t;
698 # define FR_GROUPLEN 16
702 # define offsetof(t,m) (size_t)((&((t *)0L)->m))
705 # define stsizeof(t,m) sizeof(((t *)0L)->m)
709 * This set of macros has been brought about because on Tru64 it is not
710 * possible to easily assign or examine values in a structure that are
714 # define IP_V(x) (x)->ip_v
717 # define IP_V_A(x,y) (x)->ip_v = (y)
720 # define IP_HL(x) (x)->ip_hl
723 # define IP_HL_A(x,y) (x)->ip_hl = ((y) & 0xf)
726 # define TCP_X2(x) (x)->th_x2
729 # define TCP_X2_A(x,y) (x)->th_x2 = (y)
732 # define TCP_OFF(x) (x)->th_off
735 # define TCP_OFF_A(x,y) (x)->th_off = (y)
737 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
739 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
742 #if BSD_GE_YEAR(199306) && !defined(m_act)
743 # define m_act m_nextpkt
747 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
751 * 00000001 - (Reserved 4)
752 * 00111101 - Top Secret
754 * 10010110 - Confidential
755 * 01100110 - (Reserved 3)
756 * 11001100 - (Reserved 2)
757 * 10101011 - Unclassified
758 * 11110001 - (Reserved 1)
760 #define IPSO_CLASS_RES4 0x01
761 #define IPSO_CLASS_TOPS 0x3d
762 #define IPSO_CLASS_SECR 0x5a
763 #define IPSO_CLASS_CONF 0x96
764 #define IPSO_CLASS_RES3 0x66
765 #define IPSO_CLASS_RES2 0xcc
766 #define IPSO_CLASS_UNCL 0xab
767 #define IPSO_CLASS_RES1 0xf1
769 #define IPSO_AUTH_GENSER 0x80
770 #define IPSO_AUTH_ESI 0x40
771 #define IPSO_AUTH_SCI 0x20
772 #define IPSO_AUTH_NSA 0x10
773 #define IPSO_AUTH_DOE 0x08
774 #define IPSO_AUTH_UN 0x06
775 #define IPSO_AUTH_FTE 0x01
783 #define IPOPT_ZSU 10 /* ZSU */
785 #define IPOPT_MTUP 11 /* MTUP */
787 #define IPOPT_MTUR 12 /* MTUR */
789 #define IPOPT_ENCODE 15 /* ENCODE */
793 #define IPOPT_TR 82 /* TR */
794 #undef IPOPT_SECURITY
795 #define IPOPT_SECURITY 130
797 #define IPOPT_LSRR 131
799 #define IPOPT_E_SEC 133 /* E-SEC */
801 #define IPOPT_CIPSO 134 /* CIPSO */
803 #define IPOPT_SATID 136
805 # define IPOPT_SID IPOPT_SATID
808 #define IPOPT_SSRR 137
810 #define IPOPT_ADDEXT 147 /* ADDEXT */
812 #define IPOPT_VISA 142 /* VISA */
814 #define IPOPT_IMITD 144 /* IMITD */
816 #define IPOPT_EIP 145 /* EIP */
818 #define IPOPT_RTRALRT 148 /* RTRALRT */
820 #define IPOPT_SDB 149
822 #define IPOPT_NSAPA 150
824 #define IPOPT_DPS 151
826 #define IPOPT_UMP 152
828 #define IPOPT_FINN 205 /* FINN */
830 #define IPOPT_AH 256+IPPROTO_AH
832 # define ICMP_UNREACH_ADMIN_PROHIBIT ICMP_UNREACH_FILTER_PROHIB
833 # define ICMP_UNREACH_FILTER ICMP_UNREACH_FILTER_PROHIB
839 # define IPOPT_MINOFF 4
842 # define IPOPT_COPIED(x) ((x)&0x80)
851 # define IP_MF ((u_short)0x2000)
854 # define ETHERTYPE_IP ((u_short)0x0800)
866 # define TH_PUSH 0x08
875 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK)
889 #ifndef IPOPT_SECURITY
890 # define IPOPT_SECURITY 130
893 # define IPOPT_LSRR 131
896 # define IPOPT_SATID 136
899 # define IPOPT_SSRR 137
901 #ifndef IPOPT_SECUR_UNCLASS
902 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
904 #ifndef IPOPT_SECUR_CONFID
905 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
907 #ifndef IPOPT_SECUR_EFTO
908 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
910 #ifndef IPOPT_SECUR_MMMM
911 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
913 #ifndef IPOPT_SECUR_RESTR
914 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
916 #ifndef IPOPT_SECUR_SECRET
917 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
919 #ifndef IPOPT_SECUR_TOPSECRET
920 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
923 # define IPOPT_OLEN 1
925 #ifndef IPPROTO_HOPOPTS
926 # define IPPROTO_HOPOPTS 0
929 # define IPPROTO_IPIP 4
931 #ifndef IPPROTO_ENCAP
932 # define IPPROTO_ENCAP 98
935 # define IPPROTO_IPV6 41
937 #ifndef IPPROTO_ROUTING
938 # define IPPROTO_ROUTING 43
940 #ifndef IPPROTO_FRAGMENT
941 # define IPPROTO_FRAGMENT 44
944 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
947 # define IPPROTO_ESP 50
950 # define IPPROTO_AH 51
952 #ifndef IPPROTO_ICMPV6
953 # define IPPROTO_ICMPV6 58
956 # define IPPROTO_NONE 59
958 #ifndef IPPROTO_DSTOPTS
959 # define IPPROTO_DSTOPTS 60
961 #ifndef IPPROTO_MOBILITY
962 # define IPPROTO_MOBILITY 135
965 #ifndef ICMP_ROUTERADVERT
966 # define ICMP_ROUTERADVERT 9
968 #ifndef ICMP_ROUTERSOLICIT
969 # define ICMP_ROUTERSOLICIT 10
971 #ifndef ICMP6_DST_UNREACH
972 # define ICMP6_DST_UNREACH 1
974 #ifndef ICMP6_PACKET_TOO_BIG
975 # define ICMP6_PACKET_TOO_BIG 2
977 #ifndef ICMP6_TIME_EXCEEDED
978 # define ICMP6_TIME_EXCEEDED 3
980 #ifndef ICMP6_PARAM_PROB
981 # define ICMP6_PARAM_PROB 4
984 #ifndef ICMP6_ECHO_REQUEST
985 # define ICMP6_ECHO_REQUEST 128
987 #ifndef ICMP6_ECHO_REPLY
988 # define ICMP6_ECHO_REPLY 129
990 #ifndef ICMP6_MEMBERSHIP_QUERY
991 # define ICMP6_MEMBERSHIP_QUERY 130
993 #ifndef MLD6_LISTENER_QUERY
994 # define MLD6_LISTENER_QUERY 130
996 #ifndef ICMP6_MEMBERSHIP_REPORT
997 # define ICMP6_MEMBERSHIP_REPORT 131
999 #ifndef MLD6_LISTENER_REPORT
1000 # define MLD6_LISTENER_REPORT 131
1002 #ifndef ICMP6_MEMBERSHIP_REDUCTION
1003 # define ICMP6_MEMBERSHIP_REDUCTION 132
1005 #ifndef MLD6_LISTENER_DONE
1006 # define MLD6_LISTENER_DONE 132
1008 #ifndef ND_ROUTER_SOLICIT
1009 # define ND_ROUTER_SOLICIT 133
1011 #ifndef ND_ROUTER_ADVERT
1012 # define ND_ROUTER_ADVERT 134
1014 #ifndef ND_NEIGHBOR_SOLICIT
1015 # define ND_NEIGHBOR_SOLICIT 135
1017 #ifndef ND_NEIGHBOR_ADVERT
1018 # define ND_NEIGHBOR_ADVERT 136
1021 # define ND_REDIRECT 137
1023 #ifndef ICMP6_ROUTER_RENUMBERING
1024 # define ICMP6_ROUTER_RENUMBERING 138
1026 #ifndef ICMP6_WRUREQUEST
1027 # define ICMP6_WRUREQUEST 139
1029 #ifndef ICMP6_WRUREPLY
1030 # define ICMP6_WRUREPLY 140
1032 #ifndef ICMP6_FQDN_QUERY
1033 # define ICMP6_FQDN_QUERY 139
1035 #ifndef ICMP6_FQDN_REPLY
1036 # define ICMP6_FQDN_REPLY 140
1038 #ifndef ICMP6_NI_QUERY
1039 # define ICMP6_NI_QUERY 139
1041 #ifndef ICMP6_NI_REPLY
1042 # define ICMP6_NI_REPLY 140
1044 #ifndef MLD6_MTRACE_RESP
1045 # define MLD6_MTRACE_RESP 200
1048 # define MLD6_MTRACE 201
1050 #ifndef ICMP6_HADISCOV_REQUEST
1051 # define ICMP6_HADISCOV_REQUEST 202
1053 #ifndef ICMP6_HADISCOV_REPLY
1054 # define ICMP6_HADISCOV_REPLY 203
1056 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
1057 # define ICMP6_MOBILEPREFIX_SOLICIT 204
1059 #ifndef ICMP6_MOBILEPREFIX_ADVERT
1060 # define ICMP6_MOBILEPREFIX_ADVERT 205
1062 #ifndef ICMP6_MAXTYPE
1063 # define ICMP6_MAXTYPE 205
1066 #ifndef ICMP6_DST_UNREACH_NOROUTE
1067 # define ICMP6_DST_UNREACH_NOROUTE 0
1069 #ifndef ICMP6_DST_UNREACH_ADMIN
1070 # define ICMP6_DST_UNREACH_ADMIN 1
1072 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
1073 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
1075 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
1076 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
1078 #ifndef ICMP6_DST_UNREACH_ADDR
1079 # define ICMP6_DST_UNREACH_ADDR 3
1081 #ifndef ICMP6_DST_UNREACH_NOPORT
1082 # define ICMP6_DST_UNREACH_NOPORT 4
1084 #ifndef ICMP6_TIME_EXCEED_TRANSIT
1085 # define ICMP6_TIME_EXCEED_TRANSIT 0
1087 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
1088 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
1091 #ifndef ICMP6_NI_SUCCESS
1092 # define ICMP6_NI_SUCCESS 0
1094 #ifndef ICMP6_NI_REFUSED
1095 # define ICMP6_NI_REFUSED 1
1097 #ifndef ICMP6_NI_UNKNOWN
1098 # define ICMP6_NI_UNKNOWN 2
1101 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
1102 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
1104 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
1105 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
1107 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1108 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
1111 #ifndef ICMP6_PARAMPROB_HEADER
1112 # define ICMP6_PARAMPROB_HEADER 0
1114 #ifndef ICMP6_PARAMPROB_NEXTHEADER
1115 # define ICMP6_PARAMPROB_NEXTHEADER 1
1117 #ifndef ICMP6_PARAMPROB_OPTION
1118 # define ICMP6_PARAMPROB_OPTION 2
1121 #ifndef ICMP6_NI_SUBJ_IPV6
1122 # define ICMP6_NI_SUBJ_IPV6 0
1124 #ifndef ICMP6_NI_SUBJ_FQDN
1125 # define ICMP6_NI_SUBJ_FQDN 1
1127 #ifndef ICMP6_NI_SUBJ_IPV4
1128 # define ICMP6_NI_SUBJ_IPV4 2
1131 #ifndef MLD_MTRACE_RESP
1132 # define MLD_MTRACE_RESP 200
1135 # define MLD_MTRACE 201
1137 #ifndef MLD6_MTRACE_RESP
1138 # define MLD6_MTRACE_RESP MLD_MTRACE_RESP
1141 # define MLD6_MTRACE MLD_MTRACE
1144 #if !defined(IPV6_FLOWINFO_MASK)
1145 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1146 # define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
1148 # if(BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1149 # define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
1150 # endif /* LITTLE_ENDIAN */
1153 #if !defined(IPV6_FLOWLABEL_MASK)
1154 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1155 # define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
1157 # if (BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1158 # define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
1159 # endif /* LITTLE_ENDIAN */
1164 * ECN is a new addition to TCP - RFC 2481
1167 # define TH_ECN 0x40
1170 # define TH_CWR 0x80
1172 #define TH_ECNALL (TH_ECN|TH_CWR)
1177 #define IPF_TCPS_LISTEN 0 /* listening for connection */
1178 #define IPF_TCPS_SYN_SENT 1 /* active, have sent syn */
1179 #define IPF_TCPS_SYN_RECEIVED 2 /* have send and received syn */
1180 #define IPF_TCPS_HALF_ESTAB 3 /* for connections not fully "up" */
1181 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
1182 #define IPF_TCPS_ESTABLISHED 4 /* established */
1183 #define IPF_TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
1184 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
1185 #define IPF_TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
1186 #define IPF_TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
1187 #define IPF_TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
1188 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
1189 #define IPF_TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
1190 #define IPF_TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
1191 #define IPF_TCPS_CLOSED 11 /* closed */
1192 #define IPF_TCP_NSTATES 12
1196 #undef ICMP_MAX_UNREACH
1197 #define ICMP_MAX_UNREACH 14
1199 #define ICMP_MAXTYPE 18
1202 # define LOG_FTP (11<<3)
1204 #ifndef LOG_AUTHPRIV
1205 # define LOG_AUTHPRIV (10<<3)
1208 # define LOG_AUDIT (13<<3)
1211 # define LOG_NTP (12<<3)
1213 #ifndef LOG_SECURITY
1214 # define LOG_SECURITY (13<<3)
1217 # define LOG_LFMT (14<<3)
1220 # define LOG_CONSOLE (14<<3)
1224 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1225 * another IP header and then 64 bits of data, totalling 56. Of course,
1226 * the last 64 bits is dependent on that being available.
1228 #define ICMPERR_ICMPHLEN 8
1229 #define ICMPERR_IPICMPHLEN (20 + 8)
1230 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
1231 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
1232 #define ICMP6ERR_MINPKTLEN (40 + 8)
1233 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
1236 # define MIN(a,b) (((a)<(b))?(a):(b))
1240 # undef IPFILTER_BPF
1244 # define DPRINT(x) printf x
1251 # define DT(_n) DTRACE_PROBE(_n)
1252 # define DT1(_n,_a,_b) DTRACE_PROBE1(_n,_a,_b)
1253 # define DT2(_n,_a,_b,_c,_d) DTRACE_PROBE2(_n,_a,_b,_c,_d)
1254 # define DT3(_n,_a,_b,_c,_d,_e,_f) \
1255 DTRACE_PROBE3(_n,_a,_b,_c,_d,_e,_f)
1256 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h) \
1257 DTRACE_PROBE4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1260 # define DT1(_n,_a,_b)
1261 # define DT2(_n,_a,_b,_c,_d)
1262 # define DT3(_n,_a,_b,_c,_d,_e,_f)
1263 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1267 # define DT1(_n,_a,_b)
1268 # define DT2(_n,_a,_b,_c,_d)
1269 # define DT3(_n,_a,_b,_c,_d,_e,_f)
1270 # define DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1273 struct ip6_routing {
1274 u_char ip6r_nxt; /* next header */
1275 u_char ip6r_len; /* length in units of 8 octets */
1276 u_char ip6r_type; /* always zero */
1277 u_char ip6r_segleft; /* segments left */
1278 u_32_t ip6r_reserved; /* reserved field */
1281 #endif /* __IP_COMPAT_H__ */