]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/ipfilter/netinet/ip_compat.h
MFV r337744:
[FreeBSD/FreeBSD.git] / sys / contrib / ipfilter / netinet / ip_compat.h
1 /*
2  * Copyright (C) 2012 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * @(#)ip_compat.h      1.8 1/14/96
7  * $FreeBSD$
8  * Id: ip_compat.h,v 2.142.2.57 2007/10/10 09:51:42 darrenr Exp $
9  */
10
11 #ifndef __IP_COMPAT_H__
12 #define __IP_COMPAT_H__
13
14 #ifndef __P
15 # ifdef __STDC__
16 #  define       __P(x)  x
17 # else
18 #  define       __P(x)  ()
19 # endif
20 #endif
21 #ifndef __STDC__
22 # undef         const
23 # define        const
24 #endif
25
26 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
27 # undef KERNEL
28 # undef _KERNEL
29 # undef         __KERNEL__
30 # define        KERNEL
31 # define        _KERNEL
32 # define        __KERNEL__
33 #endif
34
35 #ifndef SOLARIS
36 # if defined(sun) && (defined(__svr4__) || defined(__SVR4))
37 #  define       SOLARIS         1
38 # else
39 #  define       SOLARIS         0
40 # endif
41 #endif
42
43
44 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
45 # define index   strchr
46 # if !defined(_KERNEL)
47 #  define       bzero(a,b)      memset(a,0,b)
48 #  define       bcmp            memcmp
49 #  define       bcopy(a,b,c)    memmove(b,a,c)
50 # endif
51 #endif
52
53 #ifndef LIFNAMSIZ
54 # ifdef IF_NAMESIZE
55 #  define       LIFNAMSIZ       IF_NAMESIZE
56 # else
57 #  ifdef        IFNAMSIZ
58 #   define      LIFNAMSIZ       IFNAMSIZ
59 #  else
60 #   define      LIFNAMSIZ       16
61 #  endif
62 # endif
63 #endif
64
65 #if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
66 struct  ether_addr {
67         u_char  ether_addr_octet[6];
68 };
69 #endif
70
71 # ifdef __STDC__
72 #  define IPL_EXTERN(ep) ipl##ep
73 # else
74 #  define IPL_EXTERN(ep) ipl/**/ep
75 # endif
76
77 /*
78  * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
79  */
80 # ifndef _KERNEL
81 #  define ADD_KERNEL
82 #  define _KERNEL
83 #  define KERNEL
84 # endif
85 # include <sys/uio.h>
86 # ifdef ADD_KERNEL
87 #  undef _KERNEL
88 #  undef KERNEL
89 # endif
90
91 #define NETBSD_GE_REV(x)        (defined(__NetBSD_Version__) && \
92                                  (__NetBSD_Version__ >= (x)))
93 #define NETBSD_GT_REV(x)        (defined(__NetBSD_Version__) && \
94                                  (__NetBSD_Version__ > (x)))
95 #define NETBSD_LT_REV(x)        (defined(__NetBSD_Version__) && \
96                                  (__NetBSD_Version__ < (x)))
97 #define FREEBSD_GE_REV(x)       (defined(__FreeBSD_version) && \
98                                  (__FreeBSD_version >= (x)))
99 #define FREEBSD_GT_REV(x)       (defined(__FreeBSD_version) && \
100                                  (__FreeBSD_version > (x)))
101 #define FREEBSD_LT_REV(x)       (defined(__FreeBSD_version) && \
102                                  (__FreeBSD_version < (x)))
103 #define BSDOS_GE_REV(x)         (defined(_BSDI_VERSION) && \
104                                  (_BSDI_VERSION >= (x)))
105 #define BSDOS_GT_REV(x)         (defined(_BSDI_VERSION) && \
106                                  (_BSDI_VERSION > (x)))
107 #define BSDOS_LT_REV(x)         (defined(_BSDI_VERSION) && \
108                                  (_BSDI_VERSION < (x)))
109 #define OPENBSD_GE_REV(x)       (defined(OpenBSD) && (OpenBSD >= (x)))
110 #define OPENBSD_GT_REV(x)       (defined(OpenBSD) && (OpenBSD > (x)))
111 #define OPENBSD_LT_REV(x)       (defined(OpenBSD) && (OpenBSD < (x)))
112 #define BSD_GE_YEAR(x)          (defined(BSD) && (BSD >= (x)))
113 #define BSD_GT_YEAR(x)          (defined(BSD) && (BSD > (x)))
114 #define BSD_LT_YEAR(x)          (defined(BSD) && (BSD < (x)))
115
116
117 /* ----------------------------------------------------------------------- */
118 /*                                F R E E B S D                            */
119 /* ----------------------------------------------------------------------- */
120 # define HAS_SYS_MD5_H  1
121 # if defined(_KERNEL)
122 #   include "opt_bpf.h"
123 #   include "opt_inet6.h"
124 #  if defined(INET6) && !defined(USE_INET6)
125 #   define USE_INET6
126 #  endif
127 # else
128 #  if !defined(USE_INET6) && !defined(NOINET6)
129 #   define      USE_INET6
130 #  endif
131 # endif
132
133 # if defined(_KERNEL)
134 #  include <netinet/ip_var.h>
135 #    define     p_cred  td_ucred
136 #    define     p_uid   td_ucred->cr_ruid
137
138 /*
139  * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
140  * There may be other, safe, kernels but this is not extensively tested yet.
141  */
142 #   define HAVE_M_PULLDOWN
143 #  if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
144 #   include "opt_ipfilter.h"
145 #  endif
146 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
147 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
148
149 #   define NETBSD_PF
150 # else
151 #  include <inttypes.h>
152 # endif /* _KERNEL */
153
154 #  include <sys/selinfo.h>
155 #  include <sys/lock.h>
156 #  include <sys/malloc.h>
157 #  include <sys/mutex.h>
158 #    define     KRWLOCK_FILL_SZ         56
159 #    define     KMUTEX_FILL_SZ          56
160 #   include <sys/rwlock.h>
161 #   define      KMUTEX_T                struct mtx
162 #   define      KRWLOCK_T               struct rwlock
163
164 #ifdef _KERNEL
165 #    define     READ_ENTER(x)           rw_rlock(&(x)->ipf_lk)
166 #    define     WRITE_ENTER(x)          rw_wlock(&(x)->ipf_lk)
167 #    define     MUTEX_DOWNGRADE(x)      rw_downgrade(&(x)->ipf_lk)
168 #    define     MUTEX_TRY_UPGRADE(x)    rw_try_upgrade(&(x)->ipf_lk)
169 #    define     RWLOCK_INIT(x,y)        rw_init(&(x)->ipf_lk, (y))
170 #    define     RW_DESTROY(x)           rw_destroy(&(x)->ipf_lk)
171 #    define     RWLOCK_EXIT(x)          do { \
172                                             if (rw_wowned(&(x)->ipf_lk)) \
173                                                 rw_wunlock(&(x)->ipf_lk); \
174                                             else \
175                                                 rw_runlock(&(x)->ipf_lk); \
176                                         } while (0)
177 #  include <net/if_var.h>
178 #  define       GETKTIME(x)     microtime((struct timeval *)x)
179 #  define       if_addrlist     if_addrhead
180
181 #   include <netinet/in_systm.h>
182 #   include <netinet/ip.h>
183 #   include <machine/in_cksum.h>
184
185 #   define      USE_MUTEXES
186 #   define      MUTEX_ENTER(x)          mtx_lock(&(x)->ipf_lk)
187 #   define      MUTEX_EXIT(x)           mtx_unlock(&(x)->ipf_lk)
188 #   define      MUTEX_INIT(x,y)         mtx_init(&(x)->ipf_lk, (y), NULL,\
189                                                  MTX_DEF)
190 #   define      MUTEX_DESTROY(x)        mtx_destroy(&(x)->ipf_lk)
191 #   define      MUTEX_NUKE(x)           bzero((x), sizeof(*(x)))
192 /*
193  * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
194  * for what we want to use them for, despite testing showing they work -
195  * with a WITNESS kernel, it generates LOR messages.
196  */
197 #   include <machine/atomic.h>
198 #   define      ATOMIC_INC(x)           { mtx_lock(&softc->ipf_rw.ipf_lk); (x)++; \
199                                           mtx_unlock(&softc->ipf_rw.ipf_lk); }
200 #   define      ATOMIC_DEC(x)           { mtx_lock(&softc->ipf_rw.ipf_lk); (x)--; \
201                                           mtx_unlock(&softc->ipf_rw.ipf_lk); }
202 #   define      ATOMIC_INCL(x)          atomic_add_long(&(x), 1)
203 #   define      ATOMIC_INC64(x)         ATOMIC_INC(x)
204 #   define      ATOMIC_INC32(x)         atomic_add_32((u_int *)&(x), 1)
205 #   define      ATOMIC_DECL(x)          atomic_add_long(&(x), -1)
206 #   define      ATOMIC_DEC64(x)         ATOMIC_DEC(x)
207 #   define      ATOMIC_DEC32(x)         atomic_add_32((u_int *)&(x), -1)
208 #   define      SPL_X(x)        ;
209 #   define      SPL_NET(x)      ;
210 #   define      SPL_IMP(x)      ;
211 #   define      SPL_SCHED(x)    ;
212 #   define      GET_MINOR               dev2unit
213 #  define       MSGDSIZE(m)     mbufchainlen(m)
214 #  define       M_LEN(m)        (m)->m_len
215 #  define       M_ADJ(m,x)      m_adj(m, x)
216 #  define       M_COPY(x)       m_copym((x), 0, M_COPYALL, M_NOWAIT)
217 #  define       M_DUP(m)        m_dup(m, M_NOWAIT)
218 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
219 typedef struct mbuf mb_t;
220
221 #else   /* !_KERNEL */
222 #ifndef _NET_IF_VAR_H_
223 /*
224  * Userland emulation of struct ifnet.
225  */
226 struct route;
227 struct mbuf;
228 struct ifnet {
229         char                    if_xname[IFNAMSIZ];
230         STAILQ_HEAD(, ifaddr)   if_addrlist;
231         int     (*if_output)(struct ifnet *, struct mbuf *,
232             const struct sockaddr *, struct route *);
233 };
234 #endif /* _NET_IF_VAR_H_ */
235 #endif /* _KERNEL */
236
237 #  define       IFNAME(x)       ((struct ifnet *)x)->if_xname
238 #  define       COPYIFNAME(v, x, b) \
239                                 (void) strncpy(b, \
240                                                ((struct ifnet *)x)->if_xname, \
241                                                LIFNAMSIZ)
242
243 typedef u_long          ioctlcmd_t;
244 typedef struct uio      uio_t;
245 typedef int             minor_t;
246 typedef u_int32_t       u_32_t;
247 # define        U_32_T  1
248
249
250 /* ----------------------------------------------------------------------- */
251 /*                           G E N E R I C                                 */
252 /* ----------------------------------------------------------------------- */
253
254 /*
255  * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
256  * filter rules.
257  */
258 #if !defined(IPFILTER_BPF)
259 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
260      (defined(NBPFILTER) && (NBPFILTER > 0))
261 #  define       IPFILTER_BPF
262 # endif
263 #endif
264
265 /*
266  * Userland locking primitives
267  */
268 #ifndef _KERNEL
269 #if !defined(KMUTEX_FILL_SZ)
270 # define        KMUTEX_FILL_SZ  1
271 #endif
272 #if !defined(KRWLOCK_FILL_SZ)
273 # define        KRWLOCK_FILL_SZ 1
274 #endif
275 #endif
276
277 typedef struct  {
278         char    *eMm_owner;
279         char    *eMm_heldin;
280         u_int   eMm_magic;
281         int     eMm_held;
282         int     eMm_heldat;
283 } eMmutex_t;
284
285 typedef struct  {
286         char    *eMrw_owner;
287         char    *eMrw_heldin;
288         u_int   eMrw_magic;
289         short   eMrw_read;
290         short   eMrw_write;
291         int     eMrw_heldat;
292 } eMrwlock_t;
293
294 typedef union {
295         char    _fill[KMUTEX_FILL_SZ];
296 #ifdef KMUTEX_T
297         struct  {
298                 KMUTEX_T        ipf_slk;
299                 const char      *ipf_lname;
300         } ipf_lkun_s;
301 #endif
302         eMmutex_t       ipf_emu;
303 } ipfmutex_t;
304
305 typedef union {
306         char    _fill[KRWLOCK_FILL_SZ];
307 #ifdef KRWLOCK_T
308         struct  {
309                 KRWLOCK_T       ipf_slk;
310                 const char      *ipf_lname;
311                 int             ipf_sr;
312                 int             ipf_sw;
313                 u_int           ipf_magic;
314         } ipf_lkun_s;
315 #endif
316         eMrwlock_t      ipf_emu;
317 } ipfrwlock_t;
318
319 #define ipf_lk          ipf_lkun_s.ipf_slk
320 #define ipf_lname       ipf_lkun_s.ipf_lname
321 #define ipf_isr         ipf_lkun_s.ipf_sr
322 #define ipf_isw         ipf_lkun_s.ipf_sw
323 #define ipf_magic       ipf_lkun_s.ipf_magic
324
325 #if !defined(__GNUC__) || \
326     (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
327 # ifndef        INLINE
328 #  define       INLINE
329 # endif
330 #else
331 # define        INLINE  __inline__
332 #endif
333
334 #if defined(__FreeBSD_version) && defined(_KERNEL)
335      CTASSERT(sizeof(ipfrwlock_t) == KRWLOCK_FILL_SZ);
336      CTASSERT(sizeof(ipfmutex_t) == KMUTEX_FILL_SZ);
337 #endif
338
339
340 /*
341  * In a non-kernel environment, there are a lot of macros that need to be
342  * filled in to be null-ops or to point to some compatibility function,
343  * somewhere in userland.
344  */
345 #ifndef _KERNEL
346 typedef struct  mb_s    {
347         struct  mb_s    *mb_next;
348         char            *mb_data;
349         void            *mb_ifp;
350         int             mb_len;
351         int             mb_flags;
352         u_long          mb_buf[2048];
353 } mb_t;
354 # undef         m_next
355 # define        m_next          mb_next
356 # undef         m_len
357 # define        m_len           mb_len
358 # undef         m_flags
359 # define        m_flags         mb_flags
360 # undef         m_data
361 # define        m_data          mb_data
362 # undef         M_MCAST
363 # define        M_MCAST         0x01
364 # undef         M_BCAST
365 # define        M_BCAST         0x02
366 # undef         M_MBCAST
367 # define        M_MBCAST        0x04
368 # define        MSGDSIZE(m)     msgdsize(m)
369 # define        M_LEN(m)        (m)->mb_len
370 # define        M_ADJ(m,x)      (m)->mb_len += x
371 # define        M_COPY(m)       dupmbt(m)
372 # define        M_DUP(m)        dupmbt(m)
373 # define        GETKTIME(x)     gettimeofday((struct timeval *)(x), NULL)
374 # define        MTOD(m, t)      ((t)(m)->mb_data)
375 # define        FREE_MB_T(m)    freembt(m)
376 # define        ALLOC_MB_T(m,l) (m) = allocmbt(l)
377 # define        PREP_MB_T(f, m) do { \
378                                                 (m)->mb_next = *(f)->fin_mp; \
379                                                 *(fin)->fin_mp = (m); \
380                                                 (f)->fin_m = (m); \
381                                         } while (0)
382 # define        SLEEP(x,y)      1;
383 # define        WAKEUP(x,y)     ;
384 # define        POLLWAKEUP(y)   ;
385 # define        IPF_PANIC(x,y)  ;
386 # define        PANIC(x,y)      ;
387 # define        SPL_SCHED(x)    ;
388 # define        SPL_NET(x)      ;
389 # define        SPL_IMP(x)      ;
390 # define        SPL_X(x)        ;
391 # define        KMALLOC(a,b)    (a) = (b)malloc(sizeof(*a))
392 # define        KMALLOCS(a,b,c) (a) = (b)malloc(c)
393 # define        KFREE(x)        free(x)
394 # define        KFREES(x,s)     free(x)
395 # define        GETIFP(x, v)    get_unit(x,v)
396 # define        GETIFMTU_4(x)   2048
397 # define        GETIFMTU_6(x)   2048
398 # define        COPYIN(a,b,c)   bcopywrap((a), (b), (c))
399 # define        COPYOUT(a,b,c)  bcopywrap((a), (b), (c))
400 # define        COPYDATA(m, o, l, b)    bcopy(MTOD((mb_t *)m, char *) + (o), \
401                                               (b), (l))
402 # define        COPYBACK(m, o, l, b)    bcopy((b), \
403                                               MTOD((mb_t *)m, char *) + (o), \
404                                               (l))
405 # define        UIOMOVE(a,b,c,d)        ipfuiomove((caddr_t)a,b,c,d)
406 extern  void    m_copydata __P((mb_t *, int, int, caddr_t));
407 extern  int     ipfuiomove __P((caddr_t, int, int, struct uio *));
408 extern  int     bcopywrap __P((void *, void *, size_t));
409 extern  mb_t    *allocmbt __P((size_t));
410 extern  mb_t    *dupmbt __P((mb_t *));
411 extern  void    freembt __P((mb_t *));
412
413 # define        MUTEX_DESTROY(x)        eMmutex_destroy(&(x)->ipf_emu, \
414                                                         __FILE__, __LINE__)
415 # define        MUTEX_ENTER(x)          eMmutex_enter(&(x)->ipf_emu, \
416                                                       __FILE__, __LINE__)
417 # define        MUTEX_EXIT(x)           eMmutex_exit(&(x)->ipf_emu, \
418                                                      __FILE__, __LINE__)
419 # define        MUTEX_INIT(x,y)         eMmutex_init(&(x)->ipf_emu, y, \
420                                                      __FILE__, __LINE__)
421 # define        MUTEX_NUKE(x)           bzero((x), sizeof(*(x)))
422
423 # define        MUTEX_DOWNGRADE(x)      eMrwlock_downgrade(&(x)->ipf_emu, \
424                                                            __FILE__, __LINE__)
425 # define        MUTEX_TRY_UPGRADE(x)    eMrwlock_try_upgrade(&(x)->ipf_emu, \
426                                                            __FILE__, __LINE__)
427 # define        READ_ENTER(x)           eMrwlock_read_enter(&(x)->ipf_emu, \
428                                                             __FILE__, __LINE__)
429 # define        RWLOCK_INIT(x, y)       eMrwlock_init(&(x)->ipf_emu, y)
430 # define        RWLOCK_EXIT(x)          eMrwlock_exit(&(x)->ipf_emu)
431 # define        RW_DESTROY(x)           eMrwlock_destroy(&(x)->ipf_emu)
432 # define        WRITE_ENTER(x)          eMrwlock_write_enter(&(x)->ipf_emu, \
433                                                              __FILE__, \
434                                                              __LINE__)
435
436 # define        USE_MUTEXES             1
437
438 extern void eMmutex_destroy __P((eMmutex_t *, char *, int));
439 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
440 extern void eMmutex_exit __P((eMmutex_t *, char *, int));
441 extern void eMmutex_init __P((eMmutex_t *, char *, char *, int));
442 extern void eMrwlock_destroy __P((eMrwlock_t *));
443 extern void eMrwlock_exit __P((eMrwlock_t *));
444 extern void eMrwlock_init __P((eMrwlock_t *, char *));
445 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
446 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
447 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
448
449 #endif
450
451 extern  mb_t    *allocmbt(size_t);
452
453 #define MAX_IPV4HDR     ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
454
455 #ifndef IP_OFFMASK
456 # define        IP_OFFMASK      0x1fff
457 #endif
458
459
460 /*
461  * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
462  * object.
463  */
464 #if !defined(__amd64__) && BSD_GT_YEAR(199306)
465 # define        USE_QUAD_T
466 # define        U_QUAD_T        unsigned long long
467 # define        QUAD_T          long long
468 #else /* BSD > 199306 */
469 # if !defined(U_QUAD_T)
470 #  define       U_QUAD_T        u_long
471 #  define       QUAD_T          long
472 # endif
473 #endif /* BSD > 199306 */
474
475
476 #ifdef  USE_INET6
477 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
478      defined(__osf__) || defined(linux)
479 #  include <netinet/ip6.h>
480 #  include <netinet/icmp6.h>
481 #   if defined(_KERNEL) && !defined(__osf__)
482 #    include <netinet6/ip6_var.h>
483 #   endif
484 typedef struct ip6_hdr  ip6_t;
485 # endif
486 #endif
487
488 #ifndef MAX
489 # define        MAX(a,b)        (((a) > (b)) ? (a) : (b))
490 #endif
491
492 #if defined(_KERNEL)
493 # if defined(MENTAT) && !defined(INSTANCES)
494 #  define       COPYDATA        mb_copydata
495 #  define       COPYBACK        mb_copyback
496 # else
497 #  define       COPYDATA        m_copydata
498 #  define       COPYBACK        m_copyback
499 # endif
500 #  if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
501        defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
502        defined(_BSDI_VERSION)
503 #   include <vm/vm.h>
504 #  endif
505 #  if !defined(__FreeBSD__) || FREEBSD_GE_REV(300000)
506 #   if NETBSD_GE_REV(105180000) || OPENBSD_GE_REV(200111)
507 #    include <uvm/uvm_extern.h>
508 #   else
509 #    include <vm/vm_extern.h>
510 extern  vm_map_t        kmem_map;
511 #   endif
512 #   include <sys/proc.h>
513 #  else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
514 #   include <vm/vm_kern.h>
515 #  endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
516
517 #  ifdef IPFILTER_M_IPFILTER
518 #    include <sys/malloc.h>
519 MALLOC_DECLARE(M_IPFILTER);
520 #    define     _M_IPF          M_IPFILTER
521 #  else /* IPFILTER_M_IPFILTER */
522 #   ifdef M_PFIL
523 #    define     _M_IPF          M_PFIL
524 #   else
525 #    ifdef M_IPFILTER
526 #     define    _M_IPF          M_IPFILTER
527 #    else
528 #     define    _M_IPF          M_TEMP
529 #    endif /* M_IPFILTER */
530 #   endif /* M_PFIL */
531 #  endif /* IPFILTER_M_IPFILTER */
532 #  if !defined(KMALLOC)
533 #   define      KMALLOC(a, b)           (a) = (b)malloc(sizeof(*(a)), _M_IPF, M_NOWAIT)
534 #  endif
535 #  if !defined(KMALLOCS)
536 #   define      KMALLOCS(a, b, c)       (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
537 #  endif
538 #  if !defined(KFREE)
539 #   define      KFREE(x)        free((x), _M_IPF)
540 #  endif
541 #   if !defined(KFREES)
542 #  define       KFREES(x,s)     free((x), _M_IPF)
543 #  endif
544 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,d)
545 #  define       SLEEP(id, n)    tsleep((id), PPAUSE|PCATCH, n, 0)
546 #  define       WAKEUP(id,x)    wakeup(id+x)
547 #  if !defined(POLLWAKEUP)
548 #   define      POLLWAKEUP(x)   selwakeup(softc->ipf_selwait+x)
549 #  endif
550 #  define       GETIFP(n, v)    ifunit(n)
551 #  define       GETIFMTU_4(x)   ((struct ifnet *)x)->if_mtu
552 #  define       GETIFMTU_6(x)   ((struct ifnet *)x)->if_mtu
553
554 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
555 #  define       SPL_IMP(x)      x = splimp()
556 #  define       SPL_NET(x)      x = splnet()
557 #  if !defined(SPL_SCHED)
558 #   define      SPL_SCHED(x)    x = splsched()
559 #  endif
560 #  define       SPL_X(x)        (void) splx(x)
561 # endif /* !USE_MUTEXES */
562
563 # ifndef FREE_MB_T
564 #  define       FREE_MB_T(m)    m_freem(m)
565 # endif
566 # ifndef ALLOC_MB_T
567 #  ifdef MGETHDR
568 #   define      ALLOC_MB_T(m,l) do { \
569                                         MGETHDR((m), M_NOWAIT, MT_HEADER); \
570                                         if ((m) != NULL) { \
571                                                 (m)->m_len = (l); \
572                                                 (m)->m_pkthdr.len = (l); \
573                                         } \
574                                 } while (0)
575 #  else
576 #   define      ALLOC_MB_T(m,l) do { \
577                                         MGET((m), M_NOWAIT, MT_HEADER); \
578                                         if ((m) != NULL) { \
579                                                 (m)->m_len = (l); \
580                                                 (m)->m_pkthdr.len = (l); \
581                                         } \
582                                 } while (0)
583 #  endif
584 # endif
585 # ifndef PREP_MB_T
586 #  define       PREP_MB_T(f, m) do { \
587                                                 mb_t *_o = *(f)->fin_mp; \
588                                                 (m)->m_next = _o; \
589                                                 *(fin)->fin_mp = (m); \
590                                                 if (_o->m_flags & M_PKTHDR) { \
591                                                         (m)->m_pkthdr.len += \
592                                                             _o->m_pkthdr.len; \
593                                                         (m)->m_pkthdr.rcvif = \
594                                                           _o->m_pkthdr.rcvif; \
595                                                 } \
596                                         } while (0)
597 # endif
598 # ifndef M_DUP
599 #  ifdef M_COPYALL
600 #   define      M_DUP(m)        m_dup(m, 0, M_COPYALL, 0)
601 #  else
602 #   define      M_DUP(m)        m_dup(m)
603 #  endif
604 # endif
605
606 # ifndef MTOD
607 #  define       MTOD(m,t)       mtod(m,t)
608 # endif
609
610 # ifndef COPYIN
611 #  define       COPYIN(a,b,c)   (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
612 #  define       COPYOUT(a,b,c)  (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
613 # endif
614
615 # ifndef KMALLOC
616 #  define       KMALLOC(a,b)    (a) = (b)new_kmem_alloc(sizeof(*(a)), \
617                                                         KMEM_NOSLEEP)
618 #  define       KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
619 # endif
620
621 # ifndef        GET_MINOR
622 #  define       GET_MINOR(x)    dev2unit(x)
623 # endif
624 # define        PANIC(x,y)      if (x) panic y
625 #endif /* _KERNEL */
626
627 #if !defined(IFNAME) && !defined(_KERNEL)
628 # define        IFNAME(x)       get_ifname((struct ifnet *)x)
629 #endif
630 #ifndef COPYIFNAME
631 # define        NEED_FRGETIFNAME
632 extern  char    *ipf_getifname __P((struct ifnet *, char *));
633 # define        COPYIFNAME(v, x, b) \
634                                 ipf_getifname((struct ifnet *)x, b)
635 #endif
636
637 #ifndef ASSERT
638 # ifdef _KERNEL
639 #  define       ASSERT(x)
640 # else
641 #  define       ASSERT(x)       do { if (!(x)) abort(); } while (0)
642 # endif
643 #endif
644
645 #ifndef BCOPYIN
646 #  define       BCOPYIN(a,b,c)  (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
647 #  define       BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
648 #endif
649
650 /*
651  * Because the ctype(3) posix definition, if used "safely" in code everywhere,
652  * would mean all normal code that walks through strings needed casts.  Yuck.
653  */
654 #define ISALNUM(x)      isalnum((u_char)(x))
655 #define ISALPHA(x)      isalpha((u_char)(x))
656 #define ISDIGIT(x)      isdigit((u_char)(x))
657 #define ISSPACE(x)      isspace((u_char)(x))
658 #define ISUPPER(x)      isupper((u_char)(x))
659 #define ISXDIGIT(x)     isxdigit((u_char)(x))
660 #define ISLOWER(x)      islower((u_char)(x))
661 #define TOUPPER(x)      toupper((u_char)(x))
662 #define TOLOWER(x)      tolower((u_char)(x))
663
664 /*
665  * If mutexes aren't being used, turn all the mutex functions into null-ops.
666  */
667 #if !defined(USE_MUTEXES)
668 # define        USE_SPL                 1
669 # undef         RW_DESTROY
670 # undef         MUTEX_INIT
671 # undef         MUTEX_NUKE
672 # undef         MUTEX_DESTROY
673 # define        MUTEX_ENTER(x)          ;
674 # define        READ_ENTER(x)           ;
675 # define        WRITE_ENTER(x)          ;
676 # define        MUTEX_DOWNGRADE(x)      ;
677 # define        MUTEX_TRY_UPGRADE(x)    ;
678 # define        RWLOCK_INIT(x, y)       ;
679 # define        RWLOCK_EXIT(x)          ;
680 # define        RW_DESTROY(x)           ;
681 # define        MUTEX_EXIT(x)           ;
682 # define        MUTEX_INIT(x,y)         ;
683 # define        MUTEX_DESTROY(x)        ;
684 # define        MUTEX_NUKE(x)           ;
685 #endif /* !USE_MUTEXES */
686 #ifndef ATOMIC_INC
687 # define        ATOMIC_INC(x)           (x)++
688 # define        ATOMIC_DEC(x)           (x)--
689 #endif
690
691 #if defined(USE_SPL) && defined(_KERNEL)
692 # define        SPL_INT(x)      int x
693 #else
694 # define        SPL_INT(x)
695 #endif
696
697 /*
698  * If there are no atomic operations for bit sizes defined, define them to all
699  * use a generic one that works for all sizes.
700  */
701 #ifndef ATOMIC_INCL
702 # define        ATOMIC_INCL             ATOMIC_INC
703 # define        ATOMIC_INC64            ATOMIC_INC
704 # define        ATOMIC_INC32            ATOMIC_INC
705 # define        ATOMIC_DECL             ATOMIC_DEC
706 # define        ATOMIC_DEC64            ATOMIC_DEC
707 # define        ATOMIC_DEC32            ATOMIC_DEC
708 #endif
709
710 #ifndef HDR_T_PRIVATE
711 typedef struct  tcphdr  tcphdr_t;
712 typedef struct  udphdr  udphdr_t;
713 #endif
714 typedef struct  icmp    icmphdr_t;
715 typedef struct  ip      ip_t;
716 typedef struct  ether_header    ether_header_t;
717 typedef struct  tcpiphdr        tcpiphdr_t;
718
719 #ifndef FR_GROUPLEN
720 # define        FR_GROUPLEN     16
721 #endif
722
723 #ifndef offsetof
724 # define offsetof(t,m) (size_t)((&((t *)0L)->m))
725 #endif
726 #ifndef stsizeof
727 # define stsizeof(t,m)  sizeof(((t *)0L)->m)
728 #endif
729
730 /*
731  * This set of macros has been brought about because on Tru64 it is not
732  * possible to easily assign or examine values in a structure that are
733  * bit fields.
734  */
735 #ifndef IP_V
736 # define        IP_V(x)         (x)->ip_v
737 #endif
738 #ifndef IP_V_A
739 # define        IP_V_A(x,y)     (x)->ip_v = (y)
740 #endif
741 #ifndef IP_HL
742 # define        IP_HL(x)        (x)->ip_hl
743 #endif
744 #ifndef IP_HL_A
745 # define        IP_HL_A(x,y)    (x)->ip_hl = ((y) & 0xf)
746 #endif
747 #ifndef TCP_X2
748 # define        TCP_X2(x)       (x)->th_x2
749 #endif
750 #ifndef TCP_X2_A
751 # define        TCP_X2_A(x,y)   (x)->th_x2 = (y)
752 #endif
753 #ifndef TCP_OFF
754 # define        TCP_OFF(x)      (x)->th_off
755 #endif
756 #ifndef TCP_OFF_A
757 # define        TCP_OFF_A(x,y)  (x)->th_off = (y)
758 #endif
759 #define IPMINLEN(i, h)  ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
760
761
762 /*
763  * XXX - This is one of those *awful* hacks which nobody likes
764  */
765 #ifdef  ultrix
766 #define A_A
767 #else
768 #define A_A     &
769 #endif
770
771 #define TCPF_ALL        (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
772                          TH_ECN|TH_CWR)
773
774 #if BSD_GE_YEAR(199306) && !defined(m_act)
775 # define        m_act   m_nextpkt
776 #endif
777
778 /*
779  * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
780  *
781  * Basic Option
782  *
783  * 00000001   -   (Reserved 4)
784  * 00111101   -   Top Secret
785  * 01011010   -   Secret
786  * 10010110   -   Confidential
787  * 01100110   -   (Reserved 3)
788  * 11001100   -   (Reserved 2)
789  * 10101011   -   Unclassified
790  * 11110001   -   (Reserved 1)
791  */
792 #define IPSO_CLASS_RES4         0x01
793 #define IPSO_CLASS_TOPS         0x3d
794 #define IPSO_CLASS_SECR         0x5a
795 #define IPSO_CLASS_CONF         0x96
796 #define IPSO_CLASS_RES3         0x66
797 #define IPSO_CLASS_RES2         0xcc
798 #define IPSO_CLASS_UNCL         0xab
799 #define IPSO_CLASS_RES1         0xf1
800
801 #define IPSO_AUTH_GENSER        0x80
802 #define IPSO_AUTH_ESI           0x40
803 #define IPSO_AUTH_SCI           0x20
804 #define IPSO_AUTH_NSA           0x10
805 #define IPSO_AUTH_DOE           0x08
806 #define IPSO_AUTH_UN            0x06
807 #define IPSO_AUTH_FTE           0x01
808
809 /*
810  * IP option #defines
811  */
812 #undef  IPOPT_RR
813 #define IPOPT_RR        7
814 #undef  IPOPT_ZSU
815 #define IPOPT_ZSU       10      /* ZSU */
816 #undef  IPOPT_MTUP
817 #define IPOPT_MTUP      11      /* MTUP */
818 #undef  IPOPT_MTUR
819 #define IPOPT_MTUR      12      /* MTUR */
820 #undef  IPOPT_ENCODE
821 #define IPOPT_ENCODE    15      /* ENCODE */
822 #undef  IPOPT_TS
823 #define IPOPT_TS        68
824 #undef  IPOPT_TR
825 #define IPOPT_TR        82      /* TR */
826 #undef  IPOPT_SECURITY
827 #define IPOPT_SECURITY  130
828 #undef  IPOPT_LSRR
829 #define IPOPT_LSRR      131
830 #undef  IPOPT_E_SEC
831 #define IPOPT_E_SEC     133     /* E-SEC */
832 #undef  IPOPT_CIPSO
833 #define IPOPT_CIPSO     134     /* CIPSO */
834 #undef  IPOPT_SATID
835 #define IPOPT_SATID     136
836 #ifndef IPOPT_SID
837 # define        IPOPT_SID       IPOPT_SATID
838 #endif
839 #undef  IPOPT_SSRR
840 #define IPOPT_SSRR      137
841 #undef  IPOPT_ADDEXT
842 #define IPOPT_ADDEXT    147     /* ADDEXT */
843 #undef  IPOPT_VISA
844 #define IPOPT_VISA      142     /* VISA */
845 #undef  IPOPT_IMITD
846 #define IPOPT_IMITD     144     /* IMITD */
847 #undef  IPOPT_EIP
848 #define IPOPT_EIP       145     /* EIP */
849 #undef  IPOPT_RTRALRT
850 #define IPOPT_RTRALRT   148     /* RTRALRT */
851 #undef  IPOPT_SDB
852 #define IPOPT_SDB       149
853 #undef  IPOPT_NSAPA
854 #define IPOPT_NSAPA     150
855 #undef  IPOPT_DPS
856 #define IPOPT_DPS       151
857 #undef  IPOPT_UMP
858 #define IPOPT_UMP       152
859 #undef  IPOPT_FINN
860 #define IPOPT_FINN      205     /* FINN */
861 #undef  IPOPT_AH
862 #define IPOPT_AH        256+IPPROTO_AH
863
864 #ifndef TCPOPT_EOL
865 # define TCPOPT_EOL             0
866 #endif
867 #ifndef TCPOPT_NOP
868 # define TCPOPT_NOP             1
869 #endif
870 #ifndef TCPOPT_MAXSEG
871 # define TCPOPT_MAXSEG          2
872 #endif
873 #ifndef TCPOLEN_MAXSEG
874 # define TCPOLEN_MAXSEG         4
875 #endif
876 #ifndef TCPOPT_WINDOW
877 # define TCPOPT_WINDOW          3
878 #endif
879 #ifndef TCPOLEN_WINDOW
880 # define TCPOLEN_WINDOW         3
881 #endif
882 #ifndef TCPOPT_SACK_PERMITTED
883 # define TCPOPT_SACK_PERMITTED  4
884 #endif
885 #ifndef TCPOLEN_SACK_PERMITTED
886 # define TCPOLEN_SACK_PERMITTED 2
887 #endif
888 #ifndef TCPOPT_SACK
889 # define TCPOPT_SACK            5
890 #endif
891 #ifndef TCPOPT_TIMESTAMP
892 # define TCPOPT_TIMESTAMP       8
893 #endif
894
895 #ifndef ICMP_MINLEN
896 # define        ICMP_MINLEN     8
897 #endif
898 #ifndef ICMP_ECHOREPLY
899 # define        ICMP_ECHOREPLY  0
900 #endif
901 #ifndef ICMP_UNREACH
902 # define        ICMP_UNREACH    3
903 #endif
904 #ifndef ICMP_UNREACH_NET
905 # define        ICMP_UNREACH_NET        0
906 #endif
907 #ifndef ICMP_UNREACH_HOST
908 # define        ICMP_UNREACH_HOST       1
909 #endif
910 #ifndef ICMP_UNREACH_PROTOCOL
911 # define        ICMP_UNREACH_PROTOCOL   2
912 #endif
913 #ifndef ICMP_UNREACH_PORT
914 # define        ICMP_UNREACH_PORT       3
915 #endif
916 #ifndef ICMP_UNREACH_NEEDFRAG
917 # define        ICMP_UNREACH_NEEDFRAG   4
918 #endif
919 #ifndef ICMP_UNREACH_SRCFAIL
920 # define        ICMP_UNREACH_SRCFAIL    5
921 #endif
922 #ifndef ICMP_UNREACH_NET_UNKNOWN
923 # define        ICMP_UNREACH_NET_UNKNOWN        6
924 #endif
925 #ifndef ICMP_UNREACH_HOST_UNKNOWN
926 # define        ICMP_UNREACH_HOST_UNKNOWN       7
927 #endif
928 #ifndef ICMP_UNREACH_ISOLATED
929 # define        ICMP_UNREACH_ISOLATED   8
930 #endif
931 #ifndef ICMP_UNREACH_NET_PROHIB
932 # define        ICMP_UNREACH_NET_PROHIB 9
933 #endif
934 #ifndef ICMP_UNREACH_HOST_PROHIB
935 # define        ICMP_UNREACH_HOST_PROHIB        10
936 #endif
937 #ifndef ICMP_UNREACH_TOSNET
938 # define        ICMP_UNREACH_TOSNET     11
939 #endif
940 #ifndef ICMP_UNREACH_TOSHOST
941 # define        ICMP_UNREACH_TOSHOST    12
942 #endif
943 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
944 # define        ICMP_UNREACH_ADMIN_PROHIBIT     13
945 #endif
946 #ifndef ICMP_UNREACH_FILTER
947 # define        ICMP_UNREACH_FILTER     13
948 #endif
949 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
950 # define        ICMP_UNREACH_HOST_PRECEDENCE    14
951 #endif
952 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
953 # define        ICMP_UNREACH_PRECEDENCE_CUTOFF  15
954 #endif
955 #ifndef ICMP_SOURCEQUENCH
956 # define        ICMP_SOURCEQUENCH       4
957 #endif
958 #ifndef ICMP_REDIRECT_NET
959 # define        ICMP_REDIRECT_NET       0
960 #endif
961 #ifndef ICMP_REDIRECT_HOST
962 # define        ICMP_REDIRECT_HOST      1
963 #endif
964 #ifndef ICMP_REDIRECT_TOSNET
965 # define        ICMP_REDIRECT_TOSNET    2
966 #endif
967 #ifndef ICMP_REDIRECT_TOSHOST
968 # define        ICMP_REDIRECT_TOSHOST   3
969 #endif
970 #ifndef ICMP_ALTHOSTADDR
971 # define        ICMP_ALTHOSTADDR        6
972 #endif
973 #ifndef ICMP_TIMXCEED
974 # define        ICMP_TIMXCEED   11
975 #endif
976 #ifndef ICMP_TIMXCEED_INTRANS
977 # define        ICMP_TIMXCEED_INTRANS   0
978 #endif
979 #ifndef ICMP_TIMXCEED_REASS
980 # define                ICMP_TIMXCEED_REASS     1
981 #endif
982 #ifndef ICMP_PARAMPROB
983 # define        ICMP_PARAMPROB  12
984 #endif
985 #ifndef ICMP_PARAMPROB_ERRATPTR
986 # define        ICMP_PARAMPROB_ERRATPTR 0
987 #endif
988 #ifndef ICMP_PARAMPROB_OPTABSENT
989 # define        ICMP_PARAMPROB_OPTABSENT        1
990 #endif
991 #ifndef ICMP_PARAMPROB_LENGTH
992 # define        ICMP_PARAMPROB_LENGTH   2
993 #endif
994 #ifndef ICMP_TSTAMP
995 # define        ICMP_TSTAMP     13
996 #endif
997 #ifndef ICMP_TSTAMPREPLY
998 # define        ICMP_TSTAMPREPLY        14
999 #endif
1000 #ifndef ICMP_IREQ
1001 # define        ICMP_IREQ       15
1002 #endif
1003 #ifndef ICMP_IREQREPLY
1004 # define        ICMP_IREQREPLY  16
1005 #endif
1006 #ifndef ICMP_MASKREQ
1007 # define        ICMP_MASKREQ    17
1008 #endif
1009 #ifndef ICMP_MASKREPLY
1010 # define        ICMP_MASKREPLY  18
1011 #endif
1012 #ifndef ICMP_TRACEROUTE
1013 # define        ICMP_TRACEROUTE 30
1014 #endif
1015 #ifndef ICMP_DATACONVERR
1016 # define        ICMP_DATACONVERR        31
1017 #endif
1018 #ifndef ICMP_MOBILE_REDIRECT
1019 # define        ICMP_MOBILE_REDIRECT    32
1020 #endif
1021 #ifndef ICMP_IPV6_WHEREAREYOU
1022 # define        ICMP_IPV6_WHEREAREYOU   33
1023 #endif
1024 #ifndef ICMP_IPV6_IAMHERE
1025 # define        ICMP_IPV6_IAMHERE       34
1026 #endif
1027 #ifndef ICMP_MOBILE_REGREQUEST
1028 # define        ICMP_MOBILE_REGREQUEST  35
1029 #endif
1030 #ifndef ICMP_MOBILE_REGREPLY
1031 # define        ICMP_MOBILE_REGREPLY    36
1032 #endif
1033 #ifndef ICMP_SKIP
1034 # define        ICMP_SKIP       39
1035 #endif
1036 #ifndef ICMP_PHOTURIS
1037 # define        ICMP_PHOTURIS   40
1038 #endif
1039 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
1040 # define        ICMP_PHOTURIS_UNKNOWN_INDEX     1
1041 #endif
1042 #ifndef ICMP_PHOTURIS_AUTH_FAILED
1043 # define        ICMP_PHOTURIS_AUTH_FAILED       2
1044 #endif
1045 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
1046 # define        ICMP_PHOTURIS_DECRYPT_FAILED    3
1047 #endif
1048 #ifndef IPVERSION
1049 # define        IPVERSION       4
1050 #endif
1051 #ifndef IPOPT_MINOFF
1052 # define        IPOPT_MINOFF    4
1053 #endif
1054 #ifndef IPOPT_COPIED
1055 # define        IPOPT_COPIED(x) ((x)&0x80)
1056 #endif
1057 #ifndef IPOPT_EOL
1058 # define        IPOPT_EOL       0
1059 #endif
1060 #ifndef IPOPT_NOP
1061 # define        IPOPT_NOP       1
1062 #endif
1063 #ifndef IP_MF
1064 # define        IP_MF   ((u_short)0x2000)
1065 #endif
1066 #ifndef ETHERTYPE_IP
1067 # define        ETHERTYPE_IP    ((u_short)0x0800)
1068 #endif
1069 #ifndef TH_FIN
1070 # define        TH_FIN  0x01
1071 #endif
1072 #ifndef TH_SYN
1073 # define        TH_SYN  0x02
1074 #endif
1075 #ifndef TH_RST
1076 # define        TH_RST  0x04
1077 #endif
1078 #ifndef TH_PUSH
1079 # define        TH_PUSH 0x08
1080 #endif
1081 #ifndef TH_ACK
1082 # define        TH_ACK  0x10
1083 #endif
1084 #ifndef TH_URG
1085 # define        TH_URG  0x20
1086 #endif
1087 #undef  TH_ACKMASK
1088 #define TH_ACKMASK      (TH_FIN|TH_SYN|TH_RST|TH_ACK)
1089
1090 #ifndef IPOPT_EOL
1091 # define        IPOPT_EOL       0
1092 #endif
1093 #ifndef IPOPT_NOP
1094 # define        IPOPT_NOP       1
1095 #endif
1096 #ifndef IPOPT_RR
1097 # define        IPOPT_RR        7
1098 #endif
1099 #ifndef IPOPT_TS
1100 # define        IPOPT_TS        68
1101 #endif
1102 #ifndef IPOPT_SECURITY
1103 # define        IPOPT_SECURITY  130
1104 #endif
1105 #ifndef IPOPT_LSRR
1106 # define        IPOPT_LSRR      131
1107 #endif
1108 #ifndef IPOPT_SATID
1109 # define        IPOPT_SATID     136
1110 #endif
1111 #ifndef IPOPT_SSRR
1112 # define        IPOPT_SSRR      137
1113 #endif
1114 #ifndef IPOPT_SECUR_UNCLASS
1115 # define        IPOPT_SECUR_UNCLASS     ((u_short)0x0000)
1116 #endif
1117 #ifndef IPOPT_SECUR_CONFID
1118 # define        IPOPT_SECUR_CONFID      ((u_short)0xf135)
1119 #endif
1120 #ifndef IPOPT_SECUR_EFTO
1121 # define        IPOPT_SECUR_EFTO        ((u_short)0x789a)
1122 #endif
1123 #ifndef IPOPT_SECUR_MMMM
1124 # define        IPOPT_SECUR_MMMM        ((u_short)0xbc4d)
1125 #endif
1126 #ifndef IPOPT_SECUR_RESTR
1127 # define        IPOPT_SECUR_RESTR       ((u_short)0xaf13)
1128 #endif
1129 #ifndef IPOPT_SECUR_SECRET
1130 # define        IPOPT_SECUR_SECRET      ((u_short)0xd788)
1131 #endif
1132 #ifndef IPOPT_SECUR_TOPSECRET
1133 # define        IPOPT_SECUR_TOPSECRET   ((u_short)0x6bc5)
1134 #endif
1135 #ifndef IPOPT_OLEN
1136 # define        IPOPT_OLEN      1
1137 #endif
1138 #ifndef IPPROTO_HOPOPTS
1139 # define        IPPROTO_HOPOPTS 0
1140 #endif
1141 #ifndef IPPROTO_IPIP
1142 # define        IPPROTO_IPIP    4
1143 #endif
1144 #ifndef IPPROTO_ENCAP
1145 # define        IPPROTO_ENCAP   98
1146 #endif
1147 #ifndef IPPROTO_IPV6
1148 # define        IPPROTO_IPV6    41
1149 #endif
1150 #ifndef IPPROTO_ROUTING
1151 # define        IPPROTO_ROUTING 43
1152 #endif
1153 #ifndef IPPROTO_FRAGMENT
1154 # define        IPPROTO_FRAGMENT        44
1155 #endif
1156 #ifndef IPPROTO_GRE
1157 # define        IPPROTO_GRE     47      /* GRE encaps RFC 1701 */
1158 #endif
1159 #ifndef IPPROTO_ESP
1160 # define        IPPROTO_ESP     50
1161 #endif
1162 #ifndef IPPROTO_AH
1163 # define        IPPROTO_AH      51
1164 #endif
1165 #ifndef IPPROTO_ICMPV6
1166 # define        IPPROTO_ICMPV6  58
1167 #endif
1168 #ifndef IPPROTO_NONE
1169 # define        IPPROTO_NONE    59
1170 #endif
1171 #ifndef IPPROTO_DSTOPTS
1172 # define        IPPROTO_DSTOPTS 60
1173 #endif
1174 #ifndef IPPROTO_MOBILITY
1175 # define        IPPROTO_MOBILITY        135
1176 #endif
1177
1178 #ifndef ICMP_ROUTERADVERT
1179 # define        ICMP_ROUTERADVERT       9
1180 #endif
1181 #ifndef ICMP_ROUTERSOLICIT
1182 # define        ICMP_ROUTERSOLICIT      10
1183 #endif
1184 #ifndef ICMP6_DST_UNREACH
1185 # define        ICMP6_DST_UNREACH       1
1186 #endif
1187 #ifndef ICMP6_PACKET_TOO_BIG
1188 # define        ICMP6_PACKET_TOO_BIG    2
1189 #endif
1190 #ifndef ICMP6_TIME_EXCEEDED
1191 # define        ICMP6_TIME_EXCEEDED     3
1192 #endif
1193 #ifndef ICMP6_PARAM_PROB
1194 # define        ICMP6_PARAM_PROB        4
1195 #endif
1196
1197 #ifndef ICMP6_ECHO_REQUEST
1198 # define        ICMP6_ECHO_REQUEST      128
1199 #endif
1200 #ifndef ICMP6_ECHO_REPLY
1201 # define        ICMP6_ECHO_REPLY        129
1202 #endif
1203 #ifndef ICMP6_MEMBERSHIP_QUERY
1204 # define        ICMP6_MEMBERSHIP_QUERY  130
1205 #endif
1206 #ifndef MLD6_LISTENER_QUERY
1207 # define        MLD6_LISTENER_QUERY     130
1208 #endif
1209 #ifndef ICMP6_MEMBERSHIP_REPORT
1210 # define        ICMP6_MEMBERSHIP_REPORT 131
1211 #endif
1212 #ifndef MLD6_LISTENER_REPORT
1213 # define        MLD6_LISTENER_REPORT    131
1214 #endif
1215 #ifndef ICMP6_MEMBERSHIP_REDUCTION
1216 # define        ICMP6_MEMBERSHIP_REDUCTION      132
1217 #endif
1218 #ifndef MLD6_LISTENER_DONE
1219 # define        MLD6_LISTENER_DONE      132
1220 #endif
1221 #ifndef ND_ROUTER_SOLICIT
1222 # define        ND_ROUTER_SOLICIT       133
1223 #endif
1224 #ifndef ND_ROUTER_ADVERT
1225 # define        ND_ROUTER_ADVERT        134
1226 #endif
1227 #ifndef ND_NEIGHBOR_SOLICIT
1228 # define        ND_NEIGHBOR_SOLICIT     135
1229 #endif
1230 #ifndef ND_NEIGHBOR_ADVERT
1231 # define        ND_NEIGHBOR_ADVERT      136
1232 #endif
1233 #ifndef ND_REDIRECT
1234 # define        ND_REDIRECT     137
1235 #endif
1236 #ifndef ICMP6_ROUTER_RENUMBERING
1237 # define        ICMP6_ROUTER_RENUMBERING        138
1238 #endif
1239 #ifndef ICMP6_WRUREQUEST
1240 # define        ICMP6_WRUREQUEST        139
1241 #endif
1242 #ifndef ICMP6_WRUREPLY
1243 # define        ICMP6_WRUREPLY          140
1244 #endif
1245 #ifndef ICMP6_FQDN_QUERY
1246 # define        ICMP6_FQDN_QUERY        139
1247 #endif
1248 #ifndef ICMP6_FQDN_REPLY
1249 # define        ICMP6_FQDN_REPLY        140
1250 #endif
1251 #ifndef ICMP6_NI_QUERY
1252 # define        ICMP6_NI_QUERY          139
1253 #endif
1254 #ifndef ICMP6_NI_REPLY
1255 # define        ICMP6_NI_REPLY          140
1256 #endif
1257 #ifndef MLD6_MTRACE_RESP
1258 # define        MLD6_MTRACE_RESP        200
1259 #endif
1260 #ifndef MLD6_MTRACE
1261 # define        MLD6_MTRACE             201
1262 #endif
1263 #ifndef ICMP6_HADISCOV_REQUEST
1264 # define        ICMP6_HADISCOV_REQUEST  202
1265 #endif
1266 #ifndef ICMP6_HADISCOV_REPLY
1267 # define        ICMP6_HADISCOV_REPLY    203
1268 #endif
1269 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
1270 # define        ICMP6_MOBILEPREFIX_SOLICIT      204
1271 #endif
1272 #ifndef ICMP6_MOBILEPREFIX_ADVERT
1273 # define        ICMP6_MOBILEPREFIX_ADVERT       205
1274 #endif
1275 #ifndef ICMP6_MAXTYPE
1276 # define        ICMP6_MAXTYPE           205
1277 #endif
1278
1279 #ifndef ICMP6_DST_UNREACH_NOROUTE
1280 # define        ICMP6_DST_UNREACH_NOROUTE       0
1281 #endif
1282 #ifndef ICMP6_DST_UNREACH_ADMIN
1283 # define        ICMP6_DST_UNREACH_ADMIN         1
1284 #endif
1285 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
1286 # define        ICMP6_DST_UNREACH_NOTNEIGHBOR   2
1287 #endif
1288 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
1289 # define        ICMP6_DST_UNREACH_BEYONDSCOPE   2
1290 #endif
1291 #ifndef ICMP6_DST_UNREACH_ADDR
1292 # define        ICMP6_DST_UNREACH_ADDR          3
1293 #endif
1294 #ifndef ICMP6_DST_UNREACH_NOPORT
1295 # define        ICMP6_DST_UNREACH_NOPORT        4
1296 #endif
1297 #ifndef ICMP6_TIME_EXCEED_TRANSIT
1298 # define        ICMP6_TIME_EXCEED_TRANSIT       0
1299 #endif
1300 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
1301 # define        ICMP6_TIME_EXCEED_REASSEMBLY    1
1302 #endif
1303
1304 #ifndef ICMP6_NI_SUCCESS
1305 # define        ICMP6_NI_SUCCESS        0
1306 #endif
1307 #ifndef ICMP6_NI_REFUSED
1308 # define        ICMP6_NI_REFUSED        1
1309 #endif
1310 #ifndef ICMP6_NI_UNKNOWN
1311 # define        ICMP6_NI_UNKNOWN        2
1312 #endif
1313
1314 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
1315 # define        ICMP6_ROUTER_RENUMBERING_COMMAND        0
1316 #endif
1317 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
1318 # define        ICMP6_ROUTER_RENUMBERING_RESULT 1
1319 #endif
1320 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1321 # define        ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255
1322 #endif
1323
1324 #ifndef ICMP6_PARAMPROB_HEADER
1325 # define        ICMP6_PARAMPROB_HEADER  0
1326 #endif
1327 #ifndef ICMP6_PARAMPROB_NEXTHEADER
1328 # define        ICMP6_PARAMPROB_NEXTHEADER      1
1329 #endif
1330 #ifndef ICMP6_PARAMPROB_OPTION
1331 # define        ICMP6_PARAMPROB_OPTION  2
1332 #endif
1333
1334 #ifndef ICMP6_NI_SUBJ_IPV6
1335 # define        ICMP6_NI_SUBJ_IPV6      0
1336 #endif
1337 #ifndef ICMP6_NI_SUBJ_FQDN
1338 # define        ICMP6_NI_SUBJ_FQDN      1
1339 #endif
1340 #ifndef ICMP6_NI_SUBJ_IPV4
1341 # define        ICMP6_NI_SUBJ_IPV4      2
1342 #endif
1343
1344 #ifndef MLD_MTRACE_RESP
1345 # define        MLD_MTRACE_RESP         200
1346 #endif
1347 #ifndef MLD_MTRACE
1348 # define        MLD_MTRACE              201
1349 #endif
1350 #ifndef MLD6_MTRACE_RESP
1351 # define        MLD6_MTRACE_RESP        MLD_MTRACE_RESP
1352 #endif
1353 #ifndef MLD6_MTRACE
1354 # define        MLD6_MTRACE             MLD_MTRACE
1355 #endif
1356
1357 #if !defined(IPV6_FLOWINFO_MASK)
1358 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1359 #  define IPV6_FLOWINFO_MASK    0x0fffffff      /* flow info (28 bits) */
1360 # else
1361 #  if(BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1362 #   define IPV6_FLOWINFO_MASK   0xffffff0f      /* flow info (28 bits) */
1363 #  endif /* LITTLE_ENDIAN */
1364 # endif
1365 #endif
1366 #if !defined(IPV6_FLOWLABEL_MASK)
1367 # if (BYTE_ORDER == BIG_ENDIAN) || defined(_BIG_ENDIAN)
1368 #  define IPV6_FLOWLABEL_MASK   0x000fffff      /* flow label (20 bits) */
1369 # else
1370 #  if (BYTE_ORDER == LITTLE_ENDIAN) || !defined(_BIG_ENDIAN)
1371 #   define IPV6_FLOWLABEL_MASK  0xffff0f00      /* flow label (20 bits) */
1372 #  endif /* LITTLE_ENDIAN */
1373 # endif
1374 #endif
1375
1376 /*
1377  * ECN is a new addition to TCP - RFC 2481
1378  */
1379 #ifndef TH_ECN
1380 # define        TH_ECN  0x40
1381 #endif
1382 #ifndef TH_CWR
1383 # define        TH_CWR  0x80
1384 #endif
1385 #define TH_ECNALL       (TH_ECN|TH_CWR)
1386
1387 /*
1388  * TCP States
1389  */
1390 #define IPF_TCPS_LISTEN         0       /* listening for connection */
1391 #define IPF_TCPS_SYN_SENT       1       /* active, have sent syn */
1392 #define IPF_TCPS_SYN_RECEIVED   2       /* have send and received syn */
1393 #define IPF_TCPS_HALF_ESTAB     3       /* for connections not fully "up" */
1394 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
1395 #define IPF_TCPS_ESTABLISHED    4       /* established */
1396 #define IPF_TCPS_CLOSE_WAIT     5       /* rcvd fin, waiting for close */
1397 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
1398 #define IPF_TCPS_FIN_WAIT_1     6       /* have closed, sent fin */
1399 #define IPF_TCPS_CLOSING        7       /* closed xchd FIN; await FIN ACK */
1400 #define IPF_TCPS_LAST_ACK       8       /* had fin and close; await FIN ACK */
1401 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
1402 #define IPF_TCPS_FIN_WAIT_2     9       /* have closed, fin is acked */
1403 #define IPF_TCPS_TIME_WAIT      10      /* in 2*msl quiet wait after close */
1404 #define IPF_TCPS_CLOSED         11      /* closed */
1405 #define IPF_TCP_NSTATES         12
1406
1407 #define TCP_MSL                 120
1408
1409 #undef  ICMP_MAX_UNREACH
1410 #define ICMP_MAX_UNREACH        14
1411 #undef  ICMP_MAXTYPE
1412 #define ICMP_MAXTYPE            18
1413
1414 #ifndef IFNAMSIZ
1415 #define IFNAMSIZ                16
1416 #endif
1417
1418 #ifndef LOG_FTP
1419 # define        LOG_FTP         (11<<3)
1420 #endif
1421 #ifndef LOG_AUTHPRIV
1422 # define        LOG_AUTHPRIV    (10<<3)
1423 #endif
1424 #ifndef LOG_AUDIT
1425 # define        LOG_AUDIT       (13<<3)
1426 #endif
1427 #ifndef LOG_NTP
1428 # define        LOG_NTP         (12<<3)
1429 #endif
1430 #ifndef LOG_SECURITY
1431 # define        LOG_SECURITY    (13<<3)
1432 #endif
1433 #ifndef LOG_LFMT
1434 # define        LOG_LFMT        (14<<3)
1435 #endif
1436 #ifndef LOG_CONSOLE
1437 # define        LOG_CONSOLE     (14<<3)
1438 #endif
1439
1440 /*
1441  * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1442  * another IP header and then 64 bits of data, totalling 56.  Of course,
1443  * the last 64 bits is dependent on that being available.
1444  */
1445 #define ICMPERR_ICMPHLEN        8
1446 #define ICMPERR_IPICMPHLEN      (20 + 8)
1447 #define ICMPERR_MINPKTLEN       (20 + 8 + 20)
1448 #define ICMPERR_MAXPKTLEN       (20 + 8 + 20 + 8)
1449 #define ICMP6ERR_MINPKTLEN      (40 + 8)
1450 #define ICMP6ERR_IPICMPHLEN     (40 + 8 + 40)
1451
1452 #ifndef MIN
1453 # define        MIN(a,b)        (((a)<(b))?(a):(b))
1454 #endif
1455
1456 #ifdef RESCUE
1457 # undef IPFILTER_BPF
1458 #endif
1459
1460 #ifdef IPF_DEBUG
1461 # define        DPRINT(x)       printf x
1462 #else
1463 # define        DPRINT(x)
1464 #endif
1465
1466 #ifdef DTRACE_PROBE
1467 # ifdef _KERNEL
1468 #  define       DT(_n)                  DTRACE_PROBE(_n)
1469 #  define       DT1(_n,_a,_b)           DTRACE_PROBE1(_n,_a,_b)
1470 #  define       DT2(_n,_a,_b,_c,_d)     DTRACE_PROBE2(_n,_a,_b,_c,_d)
1471 #  define       DT3(_n,_a,_b,_c,_d,_e,_f)       \
1472                                         DTRACE_PROBE3(_n,_a,_b,_c,_d,_e,_f)
1473 #  define       DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h) \
1474                                 DTRACE_PROBE4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1475 # else
1476 #  define       DT(_n)
1477 #  define       DT1(_n,_a,_b)
1478 #  define       DT2(_n,_a,_b,_c,_d)
1479 #  define       DT3(_n,_a,_b,_c,_d,_e,_f)
1480 #  define       DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1481 # endif
1482 #else
1483 # define        DT(_n)
1484 # define        DT1(_n,_a,_b)
1485 # define        DT2(_n,_a,_b,_c,_d)
1486 # define        DT3(_n,_a,_b,_c,_d,_e,_f)
1487 # define        DT4(_n,_a,_b,_c,_d,_e,_f,_g,_h)
1488 #endif
1489
1490 struct ip6_routing {
1491         u_char  ip6r_nxt;       /* next header */
1492         u_char  ip6r_len;       /* length in units of 8 octets */
1493         u_char  ip6r_type;      /* always zero */
1494         u_char  ip6r_segleft;   /* segments left */
1495         u_32_t  ip6r_reserved;  /* reserved field */
1496 };
1497
1498 #endif  /* __IP_COMPAT_H__ */