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