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