]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/ipfilter/netinet/ip_compat.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / ipfilter / netinet / ip_compat.h
1 /*
2  * Copyright (C) 1993-2001, 2003 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 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
37 #endif
38 #if (defined(SOLARIS2) && (SOLARIS2 >= 8))
39 # ifndef        USE_INET6
40 #  define       USE_INET6
41 # endif
42 #endif
43 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
44     !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
45 # define        USE_INET6
46 #endif
47 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \
48     !defined(_KERNEL) && !defined(USE_INET6)
49 # define        USE_INET6
50 # define        IPFILTER_M_IPFILTER
51 #endif
52 #if defined(OpenBSD) && (OpenBSD >= 200206) && \
53     !defined(_KERNEL) && !defined(USE_INET6)
54 # define        USE_INET6
55 #endif
56 #if defined(__osf__)
57 # define        USE_INET6
58 #endif
59 #if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6))
60 # define        USE_INET6
61 #endif
62 #if defined(HPUXREV) && (HPUXREV >= 1111)
63 # define        USE_INET6
64 #endif
65
66 #if defined(BSD) && (BSD < 199103) && defined(__osf__)
67 # undef BSD
68 # define BSD 199103
69 #endif
70
71 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
72 # define index   strchr
73 # if !defined(_KERNEL)
74 #  define       bzero(a,b)      memset(a,0,b)
75 #  define       bcmp            memcmp
76 #  define       bcopy(a,b,c)    memmove(b,a,c)
77 # endif
78 #endif
79
80 #ifndef LIFNAMSIZ
81 # ifdef IF_NAMESIZE
82 #  define       LIFNAMSIZ       IF_NAMESIZE
83 # else
84 #  ifdef        IFNAMSIZ
85 #   define      LIFNAMSIZ       IFNAMSIZ
86 #  else
87 #   define      LIFNAMSIZ       16
88 #  endif
89 # endif
90 #endif
91
92 #if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
93 struct  ether_addr {
94         u_char  ether_addr_octet[6];
95 };
96 #endif
97
98 #if defined(__sgi) && !defined(IPFILTER_LKM)
99 # ifdef __STDC__
100 #  define IPL_EXTERN(ep) ipfilter##ep
101 # else
102 #  define IPL_EXTERN(ep) ipfilter/**/ep
103 # endif
104 #else
105 # ifdef __STDC__
106 #  define IPL_EXTERN(ep) ipl##ep
107 # else
108 #  define IPL_EXTERN(ep) ipl/**/ep
109 # endif
110 #endif
111
112 /*
113  * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
114  */
115 #ifndef linux
116 # ifndef _KERNEL
117 #  define ADD_KERNEL
118 #  define _KERNEL
119 #  define KERNEL
120 # endif
121 # ifdef __OpenBSD__
122 struct file;
123 # endif
124 # include <sys/uio.h>
125 # ifdef ADD_KERNEL
126 #  undef _KERNEL
127 #  undef KERNEL
128 # endif
129 #endif
130
131
132 /* ----------------------------------------------------------------------- */
133 /*                                  S O L A R I S                          */
134 /* ----------------------------------------------------------------------- */
135 #if SOLARIS
136 # define        MENTAT  1
137 # include       <sys/cmn_err.h>
138 # include       <sys/isa_defs.h>
139 # include       <sys/stream.h>
140 # include       <sys/ioccom.h>
141 # include       <sys/sysmacros.h>
142 # include       <sys/kmem.h>
143 # if defined(SOLARIS2) && SOLARIS2 >= 10
144 #  include      <sys/procset.h>
145 #  include      <sys/proc.h>
146 #  include      <sys/devops.h>
147 #  include      <sys/ddi_impldefs.h>
148 # endif
149 /*
150  * because Solaris 2 defines these in two places :-/
151  */
152 # ifndef        KERNEL
153 #  define       _KERNEL
154 #  undef        RES_INIT
155 # endif /* _KERNEL */
156
157 # if defined(SOLARIS2) && SOLARIS2 >= 8
158 #  include <netinet/ip6.h>
159 #  include <netinet/icmp6.h>
160 # endif
161
162 # include <inet/common.h>
163 /* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */
164 # undef IPOPT_EOL
165 # undef IPOPT_NOP
166 # undef IPOPT_LSRR
167 # undef IPOPT_RR
168 # undef IPOPT_SSRR
169 # ifdef i386
170 #  define _SYS_PROMIF_H
171 # endif
172 # ifndef _KERNEL
173 #  include "radix_ipf.h"
174 # else
175 #  include "radix_ipf_local.h"
176 # endif
177 # include <inet/ip.h>
178 # undef COPYOUT
179 # include <inet/ip_ire.h>
180 # ifndef        KERNEL
181 #  undef        _KERNEL
182 # endif
183 # if defined(SOLARIS2) && SOLARIS2 >= 8
184 #  define SNPRINTF      snprintf
185
186 #  include <inet/ip_if.h>
187 #  define       ipif_local_addr ipif_lcl_addr
188 /* Only defined in private include file */
189 #  ifndef       V4_PART_OF_V6
190 #   define      V4_PART_OF_V6(v6)       v6.s6_addr32[3]
191 #  endif
192 struct ip6_ext {
193         u_char  ip6e_nxt;
194         u_char  ip6e_len;
195 };
196 # endif /* SOLARIS2 >= 8 */
197
198 # if defined(SOLARIS2) && SOLARIS2 >= 6
199 #  include <sys/atomic.h>
200 typedef uint32_t        u_32_t;
201 # else
202 typedef unsigned int    u_32_t;
203 # endif
204 # define        U_32_T  1
205
206 # ifdef _KERNEL
207 #  define       NEED_LOCAL_RAND 1
208 #  define       ipf_random              arc4random
209 #  define       KRWLOCK_T               krwlock_t
210 #  define       KMUTEX_T                kmutex_t
211
212 #  if !defined(FW_HOOKS)
213 #   include "qif.h"
214 #   include "pfil.h"
215 #  else
216 #   include <sys/neti.h>
217
218 extern net_data_t ipfipv4;
219 extern net_data_t ipfipv6;
220
221 typedef struct qpktinfo {
222         void            *qpi_data;
223         mblk_t          **qpi_mp;
224         mblk_t          *qpi_m;
225         uintptr_t       qpi_real;
226         int             qpi_flags;
227         int             qpi_num;
228         int             qpi_off;
229 } qpktinfo_t;
230 #   define      QF_GROUP                0x01
231 #  endif
232
233 #  if SOLARIS2 >= 6
234 #   if SOLARIS2 == 6
235 #    define     ATOMIC_INCL(x)          atomic_add_long((uint32_t*)&(x), 1)
236 #    define     ATOMIC_DECL(x)          atomic_add_long((uint32_t*)&(x), -1)
237 #   else
238 #    define     ATOMIC_INCL(x)          atomic_add_long(&(x), 1)
239 #    define     ATOMIC_DECL(x)          atomic_add_long(&(x), -1)
240 #   endif /* SOLARIS2 == 6 */
241 #   define      ATOMIC_INC64(x)         atomic_add_64((uint64_t*)&(x), 1)
242 #   define      ATOMIC_INC32(x)         atomic_add_32((uint32_t*)&(x), 1)
243 #   define      ATOMIC_INC16(x)         atomic_add_16((uint16_t*)&(x), 1)
244 #   define      ATOMIC_DEC64(x)         atomic_add_64((uint64_t*)&(x), -1)
245 #   define      ATOMIC_DEC32(x)         atomic_add_32((uint32_t*)&(x), -1)
246 #   define      ATOMIC_DEC16(x)         atomic_add_16((uint16_t*)&(x), -1)
247 #  else
248 #   define      ATOMIC_INC(x)           { mutex_enter(&ipf_rw); (x)++; \
249                                           mutex_exit(&ipf_rw); }
250 #   define      ATOMIC_DEC(x)           { mutex_enter(&ipf_rw); (x)--; \
251                                           mutex_exit(&ipf_rw); }
252 #  endif /* SOLARIS2 >= 6 */
253 #  define       USE_MUTEXES
254 #  define       MUTEX_ENTER(x)          mutex_enter(&(x)->ipf_lk)
255 #  define       READ_ENTER(x)           rw_enter(&(x)->ipf_lk, RW_READER)
256 #  define       WRITE_ENTER(x)          rw_enter(&(x)->ipf_lk, RW_WRITER)
257 #  define       MUTEX_DOWNGRADE(x)      rw_downgrade(&(x)->ipf_lk)
258 #  define       RWLOCK_INIT(x, y)       rw_init(&(x)->ipf_lk, (y),  \
259                                                 RW_DRIVER, NULL)
260 #  define       RWLOCK_EXIT(x)          rw_exit(&(x)->ipf_lk)
261 #  define       RW_DESTROY(x)           rw_destroy(&(x)->ipf_lk)
262 #  define       MUTEX_INIT(x, y)        mutex_init(&(x)->ipf_lk, (y), \
263                                                    MUTEX_DRIVER, NULL)
264 #  define       MUTEX_DESTROY(x)        mutex_destroy(&(x)->ipf_lk)
265 #  define       MUTEX_NUKE(x)           bzero((x), sizeof(*(x)))
266 #  define       MUTEX_EXIT(x)           mutex_exit(&(x)->ipf_lk)
267 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
268 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
269 #  define       BCOPYIN(a,b,c)  copyin((caddr_t)(a), (caddr_t)(b), (c))
270 #  define       BCOPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
271 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,c,d)
272 #  define       KFREE(x)        kmem_free((char *)(x), sizeof(*(x)))
273 #  define       KFREES(x,s)     kmem_free((char *)(x), (s))
274 #  define       SPL_SCHED(x)    ;
275 #  define       SPL_NET(x)      ;
276 #  define       SPL_IMP(x)      ;
277 #  undef        SPL_X
278 #  define       SPL_X(x)        ;
279 #  ifdef sparc
280 #   define      ntohs(x)        (x)
281 #   define      ntohl(x)        (x)
282 #   define      htons(x)        (x)
283 #   define      htonl(x)        (x)
284 #  endif /* sparc */
285 #  define       KMALLOC(a,b)    (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
286 #  define       KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
287 #  define       GET_MINOR(x)    getminor(x)
288 extern  void    *get_unit __P((char *, int));
289 #  define       GETIFP(n, v)    get_unit(n, v)
290 #  if defined(_INET_IP_STACK_H)
291 #   define       COPYIFNAME(v, x, b) \
292                                 do { \
293                                         if ((v) == 4) { \
294                                                 (void) net_getifname(ipfipv4,\
295                                                         (uintptr_t)x, b, \
296                                                         LIFNAMSIZ); \
297                                         } else { \
298                                                 (void) net_getifname(ipfipv6,\
299                                                         (uintptr_t)x, b, \
300                                                         LIFNAMSIZ); \
301                                         } \
302                                 } while (0)
303 #  else
304 #   define       COPYIFNAME(v, x, b) \
305                                 (void) strncpy(b, ((qif_t *)x)->qf_name, \
306                                                LIFNAMSIZ)
307 #  endif
308 #  define       GETKTIME(x)     uniqtime((struct timeval *)x)
309 #  define       MSGDSIZE(x)     msgdsize(x)
310 #  define       M_LEN(x)        ((x)->b_wptr - (x)->b_rptr)
311 #  define       M_DUPLICATE(x)  dupmsg((x))
312 #  define       MTOD(m,t)       ((t)((m)->b_rptr))
313 #  define       MTYPE(m)        ((m)->b_datap->db_type)
314 #  define       FREE_MB_T(m)    freemsg(m)
315 #  define       m_next          b_cont
316 #  if !defined(_INET_IP_STACK_H)
317 #   define      CACHE_HASH(x)   (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
318 #  else
319 #   define      CACHE_HASH(x)   ((uintptr_t)(x)->fin_ifp & 7)
320 #  endif
321 #  define       IPF_PANIC(x,y)  if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
322 typedef mblk_t mb_t;
323 # endif /* _KERNEL */
324
325 # if defined(SOLARIS2) && (SOLARIS2 >= 7)
326 #  ifdef lint
327 #   define ALIGN32(ptr)    (ptr ? 0L : 0L)
328 #   define ALIGN16(ptr)    (ptr ? 0L : 0L)
329 #  else
330 #   define ALIGN32(ptr)    (ptr)
331 #   define ALIGN16(ptr)    (ptr)
332 #  endif
333 # endif
334
335 # if defined(SOLARIS2) && SOLARIS2 < 6
336 typedef struct uio      uio_t;
337 # endif
338 typedef int             ioctlcmd_t;
339 typedef uint8_t         u_int8_t;
340
341 # define OS_RECOGNISED 1
342
343 #endif /* SOLARIS */
344
345 /* ----------------------------------------------------------------------- */
346 /*                                  H P U X                                */
347 /* ----------------------------------------------------------------------- */
348 #ifdef __hpux
349 # define        MENTAT  1
350 # include       <sys/sysmacros.h>
351 # include       <sys/spinlock.h>
352 # include       <sys/lock.h>
353 # include       <sys/stream.h>
354 # ifdef USE_INET6
355 #  include      <netinet/if_ether.h>
356 #  include      <netinet/ip6.h>
357 #  include      <netinet/icmp6.h>
358 typedef struct  ip6_hdr ip6_t;
359 # endif
360
361 # ifdef _KERNEL
362 #  define SNPRINTF      sprintf
363 #  if (HPUXREV >= 1111)
364 #   define      IPL_SELECT
365 #   ifdef       IPL_SELECT
366 #    include    <machine/sys/user.h>
367 #    include    <sys/kthread_iface.h>
368 #    define     READ_COLLISION  0x01
369
370 typedef struct  iplog_select_s {
371         kthread_t       *read_waiter;
372         int             state;
373 } iplog_select_t;
374 #   endif
375 #  endif
376
377 #  define       GETKTIME(x)     uniqtime((struct timeval *)x)
378
379 #  if HPUXREV == 1111
380 #   include     "kern_svcs.h"
381 #  else
382 #   include     <sys/kern_svcs.h>
383 #  endif
384 #  undef        ti_flags
385 #  undef        TCP_NODELAY
386 #  undef        TCP_MAXSEG
387 #  include <sys/reg.h>
388 #  include "../netinet/ip_info.h"
389 /*
390  * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
391  * are available.  Attempting to use them actually results in unresolved
392  * symbols when it comes time to load the module.
393  * This has been fixed!  Yipee!
394  */
395 #  if 1
396 #   ifdef __LP64__
397 #    define     ATOMIC_INCL(x)          lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
398 #    define     ATOMIC_DECL(x)          lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
399 #   else
400 #    define     ATOMIC_INCL(x)          lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
401 #    define     ATOMIC_DECL(x)          lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
402 #   endif
403 #   define      ATOMIC_INC64(x)         lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
404 #   define      ATOMIC_INC32(x)         lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
405 #   define      ATOMIC_INC16(x)         lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
406 #   define      ATOMIC_DEC64(x)         lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
407 #   define      ATOMIC_DEC32(x)         lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
408 #   define      ATOMIC_DEC16(x)         lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
409 #  else /* 0 */
410 #   define      ATOMIC_INC64(x)         { MUTEX_ENTER(&ipf_rw); (x)++; \
411                                           MUTEX_EXIT(&ipf_rw); }
412 #   define      ATOMIC_DEC64(x)         { MUTEX_ENTER(&ipf_rw); (x)--; \
413                                           MUTEX_EXIT(&ipf_rw); }
414 #   define      ATOMIC_INC32(x)         { MUTEX_ENTER(&ipf_rw); (x)++; \
415                                           MUTEX_EXIT(&ipf_rw); }
416 #   define      ATOMIC_DEC32(x)         { MUTEX_ENTER(&ipf_rw); (x)--; \
417                                           MUTEX_EXIT(&ipf_rw); }
418 #   define      ATOMIC_INCL(x)          { MUTEX_ENTER(&ipf_rw); (x)++; \
419                                           MUTEX_EXIT(&ipf_rw); }
420 #   define      ATOMIC_DECL(x)          { MUTEX_ENTER(&ipf_rw); (x)--; \
421                                           MUTEX_EXIT(&ipf_rw); }
422 #   define      ATOMIC_INC(x)           { MUTEX_ENTER(&ipf_rw); (x)++; \
423                                           MUTEX_EXIT(&ipf_rw); }
424 #   define      ATOMIC_DEC(x)           { MUTEX_ENTER(&ipf_rw); (x)--; \
425                                           MUTEX_EXIT(&ipf_rw); }
426 #  endif
427 #  define       ip_cksum                ip_csuma
428 #  define       memcpy(a,b,c)           bcopy((caddr_t)b, (caddr_t)a, c)
429 #  define       USE_MUTEXES
430 #  define       MUTEX_INIT(x, y)        initlock(&(x)->ipf_lk, 0, 0, (y))
431 #  define       MUTEX_ENTER(x)          spinlock(&(x)->ipf_lk)
432 #  define       MUTEX_EXIT(x)           spinunlock(&(x)->ipf_lk);
433 #  define       MUTEX_DESTROY(x)
434 #  define       MUTEX_NUKE(x)           bzero((char *)(x), sizeof(*(x)))
435 #  define       KMUTEX_T                lock_t
436 #  define       kmutex_t                lock_t          /* for pfil.h */
437 #  define       krwlock_t               lock_t          /* for pfil.h */
438 /*
439  * The read-write lock implementation in HP-UX 11.0 is crippled - it can
440  * only be used by threads working in a user context!
441  * This has been fixed!  Yipee! (Or at least it does in 11.00, not 11.11..)
442  */
443 #  if HPUXREV < 1111
444 #   define      MUTEX_DOWNGRADE(x)      lock_write_to_read(x)
445 #   define      KRWLOCK_T               struct rw_lock
446 #   define      READ_ENTER(x)           lock_read(&(x)->ipf_lk)
447 #   define      WRITE_ENTER(x)          lock_write(&(x)->ipf_lk)
448 #   if HPUXREV >= 1111
449 #    define     RWLOCK_INIT(x, y)       rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
450 #   else
451 #    define     RWLOCK_INIT(x, y)       lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
452 #   endif
453 #   define      RWLOCK_EXIT(x)          lock_done(&(x)->ipf_lk)
454 #  else
455 #   define      KRWLOCK_T               lock_t
456 #   define      KMUTEX_T                lock_t
457 #   define      READ_ENTER(x)           MUTEX_ENTER(x)
458 #   define      WRITE_ENTER(x)          MUTEX_ENTER(x)
459 #   define      MUTEX_DOWNGRADE(x)
460 #   define      RWLOCK_INIT(x, y)       initlock(&(x)->ipf_lk, 0, 0, y)
461 #   define      RWLOCK_EXIT(x)          MUTEX_EXIT(x)
462 #  endif
463 #  define       RW_DESTROY(x)
464 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
465 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
466 #  define       SPL_SCHED(x)    ;
467 #  define       SPL_NET(x)      ;
468 #  define       SPL_IMP(x)      ;
469 #  undef        SPL_X
470 #  define       SPL_X(x)        ;
471 extern  void    *get_unit __P((char *, int));
472 #  define       GETIFP(n, v)    get_unit(n, v)
473 #  define       COPYIFNAME(v, x, b) \
474                                 (void) strncpy(b, ((qif_t *)x)->qf_name, \
475                                                LIFNAMSIZ)
476 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,c,d)
477 #  define       SLEEP(id, n)    { lock_t *_l = get_sleep_lock((caddr_t)id); \
478                                   sleep(id, PZERO+1); \
479                                   spinunlock(_l); \
480                                 }
481 #  define       WAKEUP(id,x)    { lock_t *_l = get_sleep_lock((caddr_t)id); \
482                                   wakeup(id + x); \
483                                   spinunlock(_l); \
484                                 }
485 #  define       POLLWAKEUP(x)   ;
486 #  define       KMALLOC(a, b)   MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
487 #  define       KMALLOCS(a, b, c)       MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
488 #  define       KFREE(x)        kmem_free((char *)(x), sizeof(*(x)))
489 #  define       KFREES(x,s)     kmem_free((char *)(x), (s))
490 #  define       MSGDSIZE(x)     msgdsize(x)
491 #  define       M_LEN(x)        ((x)->b_wptr - (x)->b_rptr)
492 #  define       M_DUPLICATE(x)  dupmsg((x))
493 #  define       MTOD(m,t)       ((t)((m)->b_rptr))
494 #  define       MTYPE(m)        ((m)->b_datap->db_type)
495 #  define       FREE_MB_T(m)    freemsg(m)
496 #  define       m_next          b_cont
497 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
498 typedef mblk_t mb_t;
499
500 #  define       CACHE_HASH(x)   (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
501
502 #  include "qif.h"
503 #  include "pfil.h"
504
505 # else /* _KERNEL */
506
507 typedef unsigned char uchar_t;
508
509 #  ifndef       _SYS_STREAM_INCLUDED
510 typedef char * mblk_t;
511 typedef void * queue_t;
512 typedef u_long ulong;
513 #  endif
514 #  include <netinet/ip_info.h>
515
516 # endif /* _KERNEL */
517
518 # ifdef lint
519 #  define ALIGN32(ptr)    (ptr ? 0L : 0L)
520 #  define ALIGN16(ptr)    (ptr ? 0L : 0L)
521 # else
522 #  define ALIGN32(ptr)    (ptr)
523 #  define ALIGN16(ptr)    (ptr)
524 # endif
525
526 typedef struct uio      uio_t;
527 typedef int             ioctlcmd_t;
528 typedef int             minor_t;
529 typedef unsigned int    u_32_t;
530 # define        U_32_T  1
531
532 # define OS_RECOGNISED 1
533
534 #endif /* __hpux */
535
536 /* ----------------------------------------------------------------------- */
537 /*                                  I R I X                                */
538 /* ----------------------------------------------------------------------- */
539 #ifdef __sgi
540 # undef         MENTAT
541 # if IRIX < 60500
542 typedef struct uio      uio_t;
543 # endif
544 typedef int             ioctlcmd_t;
545 typedef u_int32_t       u_32_t;
546 # define        U_32_T  1
547
548 # ifdef INET6
549 #  define USE_INET6
550 # endif
551
552 # define  hz HZ
553 # include <sys/ksynch.h>
554 # define        IPF_LOCK_PL     plhi
555 # include <sys/sema.h>
556 # undef kmutex_t
557 typedef struct {
558         lock_t *l;
559         int pl;
560 } kmutex_t;
561
562 # ifdef MUTEX_INIT
563 #  define       KMUTEX_T                mutex_t
564 # else
565 #  define       KMUTEX_T                kmutex_t
566 #  define       KRWLOCK_T               kmutex_t
567 # endif
568
569 # ifdef _KERNEL
570 #  define       NEED_LOCAL_RAND 1
571 #  define       ipf_random              arc4random
572 #  define       ATOMIC_INC(x)           { MUTEX_ENTER(&ipf_rw); \
573                                           (x)++; MUTEX_EXIT(&ipf_rw); }
574 #  define       ATOMIC_DEC(x)           { MUTEX_ENTER(&ipf_rw); \
575                                           (x)--; MUTEX_EXIT(&ipf_rw); }
576 #  define       USE_MUTEXES
577 #  ifdef MUTEX_INIT
578 #   include <sys/atomic_ops.h>
579 #   define      ATOMIC_INCL(x)          atomicAddUlong(&(x), 1)
580 #   define      ATOMIC_INC64(x)         atomicAddUint64(&(x), 1)
581 #   define      ATOMIC_INC32(x)         atomicAddUint(&(x), 1)
582 #   define      ATOMIC_INC16            ATOMIC_INC
583 #   define      ATOMIC_DECL(x)          atomicAddUlong(&(x), -1)
584 #   define      ATOMIC_DEC64(x)         atomicAddUint64(&(x), -1)
585 #   define      ATOMIC_DEC32(x)         atomicAddUint(&(x), -1)
586 #   define      ATOMIC_DEC16            ATOMIC_DEC
587 #   undef       MUTEX_INIT
588 #   define      MUTEX_INIT(x, y)        mutex_init(&(x)->ipf_lk,  \
589                                                    MUTEX_DEFAULT, y)
590 #   undef       MUTEX_ENTER
591 #   define      MUTEX_ENTER(x)          mutex_lock(&(x)->ipf_lk, 0)
592 #   undef       MUTEX_EXIT
593 #   define      MUTEX_EXIT(x)           mutex_unlock(&(x)->ipf_lk)
594 #   undef       MUTEX_DESTROY
595 #   define      MUTEX_DESTROY(x)        mutex_destroy(&(x)->ipf_lk)
596 #   define      MUTEX_DOWNGRADE(x)      mrdemote(&(x)->ipf_lk)
597 #   define      KRWLOCK_T               mrlock_t
598 #   define      RWLOCK_INIT(x, y)       mrinit(&(x)->ipf_lk, y)
599 #   undef       RW_DESTROY
600 #   define      RW_DESTROY(x)           mrfree(&(x)->ipf_lk)
601 #   define      READ_ENTER(x)           RW_RDLOCK(&(x)->ipf_lk)
602 #   define      WRITE_ENTER(x)          RW_WRLOCK(&(x)->ipf_lk)
603 #   define      RWLOCK_EXIT(x)          RW_UNLOCK(&(x)->ipf_lk)
604 #  else
605 #   define      READ_ENTER(x)           MUTEX_ENTER(&(x)->ipf_lk)
606 #   define      WRITE_ENTER(x)          MUTEX_ENTER(&(x)->ipf_lk)
607 #   define      MUTEX_DOWNGRADE(x)      ;
608 #   define      RWLOCK_EXIT(x)          MUTEX_EXIT(&(x)->ipf_lk)
609 #   define      MUTEX_EXIT(x)           UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
610 #   define      MUTEX_INIT(x,y)         (x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
611 #   define      MUTEX_DESTROY(x)        LOCK_DEALLOC((x)->ipf_lk.l)
612 #   define      MUTEX_ENTER(x)          (x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
613                                                               IPF_LOCK_PL);
614 #  endif
615 #  define       MUTEX_NUKE(x)           bzero((x), sizeof(*(x)))
616 #  define       FREE_MB_T(m)    m_freem(m)
617 #  define       MTOD(m,t)       mtod(m,t)
618 #  define       COPYIN(a,b,c)   (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
619 #  define       COPYOUT(a,b,c)  (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
620 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,c,d)
621 #  define       SLEEP(id, n)    sleep((id), PZERO+1)
622 #  define       WAKEUP(id,x)    wakeup(id+x)
623 #  define       POLLWAKEUP(x)   ;
624 #  define       KFREE(x)        kmem_free((char *)(x), sizeof(*(x)))
625 #  define       KFREES(x,s)     kmem_free((char *)(x), (s))
626 #  define       GETIFP(n,v)     ifunit(n)
627 #  include <sys/kmem.h>
628 #  include <sys/ddi.h>
629 #  define       KMALLOC(a,b)    (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
630 #  define       KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
631 #  define       GET_MINOR(x)    getminor(x)
632 #  define       USE_SPL         1
633 #  define       SPL_IMP(x)      (x) = splimp()
634 #  define       SPL_NET(x)      (x) = splnet()
635 #  define       SPL_SCHED(x)    (x) = splsched()
636 #  define       SPL_X(x)        (void) splx(x)
637 extern  void    m_copydata __P((struct mbuf *, int, int, caddr_t));
638 extern  void    m_copyback __P((struct mbuf *, int, int, caddr_t));
639 #  define       MSGDSIZE(x)     mbufchainlen(x)
640 #  define       M_LEN(x)        (x)->m_len
641 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
642 #  define       GETKTIME(x)     microtime((struct timeval *)x)
643 #  define       IFNAME(x)       ((struct ifnet *)x)->if_name
644 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
645                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
646 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
647 typedef struct mbuf mb_t;
648 # else
649 #  undef RW_DESTROY
650 #  undef MUTEX_INIT
651 #  undef MUTEX_DESTROY
652 # endif /* _KERNEL */
653
654 # define OS_RECOGNISED 1
655
656 #endif /* __sgi */
657
658 /* ----------------------------------------------------------------------- */
659 /*                                  T R U 6 4                              */
660 /* ----------------------------------------------------------------------- */
661 #ifdef __osf__
662 # undef         MENTAT
663
664 # include <kern/lock.h>
665 # include <sys/sysmacros.h>
666
667 # ifdef _KERNEL
668 #  define       NEED_LOCAL_RAND         1
669 #  define       ipf_random              arc4random
670 #  define       KMUTEX_T                simple_lock_data_t
671 #  define       KRWLOCK_T               lock_data_t
672 #  include <net/net_globals.h>
673 #  define       USE_MUTEXES
674 #  define       READ_ENTER(x)           lock_read(&(x)->ipf_lk)
675 #  define       WRITE_ENTER(x)          lock_write(&(x)->ipf_lk)
676 #  define       MUTEX_DOWNGRADE(x)      lock_write_to_read(&(x)->ipf_lk)
677 #  define       RWLOCK_INIT(x, y)       lock_init(&(x)->ipf_lk, TRUE)
678 #  define       RWLOCK_EXIT(x)          lock_done(&(x)->ipf_lk)
679 #  define       RW_DESTROY(x)           lock_terminate(&(x)->ipf_lk)
680 #  define       MUTEX_ENTER(x)          simple_lock(&(x)->ipf_lk)
681 #  define       MUTEX_INIT(x, y)        simple_lock_init(&(x)->ipf_lk)
682 #  define       MUTEX_DESTROY(x)        simple_lock_terminate(&(x)->ipf_lk)
683 #  define       MUTEX_EXIT(x)           simple_unlock(&(x)->ipf_lk)
684 #  define       MUTEX_NUKE(x)           bzero(x, sizeof(*(x)))
685 #  define       ATOMIC_INC64(x)         atomic_incq((uint64_t*)&(x))
686 #  define       ATOMIC_DEC64(x)         atomic_decq((uint64_t*)&(x))
687 #  define       ATOMIC_INC32(x)         atomic_incl((uint32_t*)&(x))
688 #  define       ATOMIC_DEC32(x)         atomic_decl((uint32_t*)&(x))
689 #  define       ATOMIC_INC16(x)         { simple_lock(&ipf_rw); (x)++; \
690                                           simple_unlock(&ipf_rw); }
691 #  define       ATOMIC_DEC16(x)         { simple_lock(&ipf_rw); (x)--; \
692                                           simple_unlock(&ipf_rw); }
693 #  define       ATOMIC_INCL(x)          atomic_incl((uint32_t*)&(x))
694 #  define       ATOMIC_DECL(x)          atomic_decl((uint32_t*)&(x))
695 #  define       ATOMIC_INC(x)           { simple_lock(&ipf_rw); (x)++; \
696                                           simple_unlock(&ipf_rw); }
697 #  define       ATOMIC_DEC(x)           { simple_lock(&ipf_rw); (x)--; \
698                                           simple_unlock(&ipf_rw); }
699 #  define       SPL_SCHED(x)            ;
700 #  define       SPL_NET(x)              ;
701 #  define       SPL_IMP(x)              ;
702 #  undef        SPL_X
703 #  define       SPL_X(x)                ;
704 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a, b, d)
705 #  define       FREE_MB_T(m)            m_freem(m)
706 #  define       MTOD(m,t)               mtod(m,t)
707 #  define       GETIFP(n, v)            ifunit(n)
708 #  define       GET_MINOR               getminor
709 #  define       WAKEUP(id,x)            wakeup(id + x)
710 #  define       POLLWAKEUP(x)           ;
711 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
712 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
713 #  define       KMALLOC(a, b)   MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
714 #  define       KMALLOCS(a, b, c)       MALLOC((a), b, (c), M_PFILT, \
715                                             ((c) > 4096) ? M_WAITOK : M_NOWAIT)
716 #  define       KFREE(x)        FREE((x), M_PFILT)
717 #  define       KFREES(x,s)     FREE((x), M_PFILT)
718 #  define       MSGDSIZE(x)     mbufchainlen(x)
719 #  define       M_LEN(x)        (x)->m_len
720 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
721 #  define       GETKTIME(x)     microtime((struct timeval *)x)
722 #  define       IFNAME(x)       ((struct ifnet *)x)->if_name
723 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
724                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
725 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
726 typedef struct mbuf mb_t;
727 # endif /* _KERNEL */
728
729 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
730 #  define       IP_V(x)         ((x)->ip_vhl >> 4)
731 #  define       IP_HL(x)        ((x)->ip_vhl & 0xf)
732 #  define       IP_V_A(x,y)     (x)->ip_vhl |= (((y) << 4) & 0xf0)
733 #  define       IP_HL_A(x,y)    (x)->ip_vhl |= ((y) & 0xf)
734 #  define       TCP_X2(x)       ((x)->th_xoff & 0xf)
735 #  define       TCP_X2_A(x,y)   (x)->th_xoff |= ((y) & 0xf)
736 #  define       TCP_OFF(x)      ((x)->th_xoff >> 4)
737 #  define       TCP_OFF_A(x,y)  (x)->th_xoff |= (((y) << 4) & 0xf0)
738 # endif
739
740 /*
741  * These are from's Solaris' #defines for little endian.
742  */
743 #define IP6F_MORE_FRAG          0x0100
744 #define IP6F_RESERVED_MASK      0x0600
745 #define IP6F_OFF_MASK           0xf8ff
746
747 struct ip6_ext {
748         u_char  ip6e_nxt;
749         u_char  ip6e_len;
750 };
751
752 typedef int             ioctlcmd_t;  
753 /*
754  * Really, any arch where sizeof(long) != sizeof(int).
755  */
756 typedef unsigned int    u_32_t;
757 # define        U_32_T  1
758
759 # define OS_RECOGNISED 1
760 #endif /* __osf__ */
761
762 /* ----------------------------------------------------------------------- */
763 /*                                  N E T B S D                            */
764 /* ----------------------------------------------------------------------- */
765 #ifdef __NetBSD__
766 # if (NetBSD >= 199905) && !defined(IPFILTER_LKM) && defined(_KERNEL)
767 #  include "opt_ipfilter.h"
768 # endif
769 # if defined(_KERNEL)
770 #  include <sys/systm.h>
771 # else
772 #  include <stddef.h>
773 # endif
774 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
775 #  include "bpfilter.h"
776 #  if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
777 #   include "opt_inet.h"
778 #  endif
779 #  ifdef INET6
780 #   define USE_INET6
781 #  endif
782 #  if (__NetBSD_Version__ >= 105000000)
783 #   define HAVE_M_PULLDOWN 1
784 #  endif
785 # endif
786
787 # if (__NetBSD_Version__ >= 499000000)
788 typedef char *  caddr_t;
789 # endif
790
791 # define        ipf_random      arc4random
792
793 # ifdef _KERNEL
794 #  if (__NetBSD_Version__ >= 399001400)
795 #   define      KMALLOCS(a, b, c)       (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
796 #  endif
797 #  define       MSGDSIZE(x)     mbufchainlen(x)
798 #  define       M_LEN(x)        (x)->m_len
799 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
800 #  define       GETKTIME(x)     microtime((struct timeval *)x)
801 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
802 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
803 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
804 typedef struct mbuf mb_t;
805 # endif /* _KERNEL */
806 # if (NetBSD <= 1991011) && (NetBSD >= 199606)
807 #  define       IFNAME(x)       ((struct ifnet *)x)->if_xname
808 #  define       COPYIFNAME(v, x, b) \
809                                 (void) strncpy(b, \
810                                                ((struct ifnet *)x)->if_xname, \
811                                                LIFNAMSIZ)
812 #  define       CACHE_HASH(x)   ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
813 # else
814 #  define       IFNAME(x)       ((struct ifnet *)x)->if_name
815 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
816                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
817 # endif
818 typedef struct uio      uio_t;
819 typedef u_long          ioctlcmd_t;  
820 typedef int             minor_t;
821 typedef u_int32_t       u_32_t;
822 # define        U_32_T  1
823
824 # define OS_RECOGNISED 1
825 #endif /* __NetBSD__ */
826
827
828 /* ----------------------------------------------------------------------- */
829 /*                                F R E E B S D                            */
830 /* ----------------------------------------------------------------------- */
831 #ifdef __FreeBSD__
832 # if  (__FreeBSD_version < 400000)
833 #  define       NEED_LOCAL_RAND 1
834 # else
835 #  define       ipf_random      arc4random
836 # endif
837 # if defined(_KERNEL)
838 #  if (__FreeBSD_version >= 500000)                          
839 #   include "opt_bpf.h"
840 #  else
841 #   include "bpf.h"    
842 #  endif
843 #  if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)
844 #   include "opt_inet6.h"
845 #  endif
846 #  if defined(INET6) && !defined(USE_INET6)
847 #   define USE_INET6
848 #  endif
849 # endif
850
851 # if defined(_KERNEL)
852 #  if (__FreeBSD_version >= 400000)
853 /*
854  * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
855  * There may be other, safe, kernels but this is not extensively tested yet.
856  */
857 #   define HAVE_M_PULLDOWN
858 #  endif
859 #  if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
860 #   include "opt_ipfilter.h"
861 #  endif
862 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
863 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
864
865 #  if (__FreeBSD_version >= 500043)
866 #   define NETBSD_PF
867 #  endif
868 # endif /* _KERNEL */
869
870 # if (__FreeBSD_version >= 500043)
871 #  include <sys/mutex.h>
872 #  if (__FreeBSD_version > 700014)
873 #   include <sys/rwlock.h>
874 #    define     KRWLOCK_T               struct rwlock
875 #    ifdef _KERNEL
876 #     define    READ_ENTER(x)           rw_rlock(&(x)->ipf_lk)
877 #     define    WRITE_ENTER(x)          rw_wlock(&(x)->ipf_lk)
878 #     define    MUTEX_DOWNGRADE(x)      rw_downgrade(&(x)->ipf_lk)
879 #     define    RWLOCK_INIT(x, y)       rw_init(&(x)->ipf_lk, (y))
880 #     define    RW_DESTROY(x)           rw_destroy(&(x)->ipf_lk)
881 #     define    RWLOCK_EXIT(x)          do { \
882                                             if (rw_wowned(&(x)->ipf_lk)) \
883                                                 rw_wunlock(&(x)->ipf_lk); \
884                                             else \
885                                                 rw_runlock(&(x)->ipf_lk); \
886                                         } while (0)
887 #   endif
888 #  else
889 #   include <sys/sx.h>
890 /*
891  * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
892  * for what we want to use them for, despite testing showing they work -
893  * with a WITNESS kernel, it generates LOR messages.
894  */
895 #   ifdef _KERNEL
896 #    if (__FreeBSD_version < 700000)
897 #     define    KRWLOCK_T               struct mtx
898 #     define    READ_ENTER(x)           mtx_lock(&(x)->ipf_lk)
899 #     define    WRITE_ENTER(x)          mtx_lock(&(x)->ipf_lk)
900 #     define    RWLOCK_EXIT(x)          mtx_unlock(&(x)->ipf_lk)
901 #     define    MUTEX_DOWNGRADE(x)      ;
902 #     define    RWLOCK_INIT(x,y)        mtx_init(&(x)->ipf_lk, (y), NULL,\
903                                                  MTX_DEF)
904 #     define    RW_DESTROY(x)           mtx_destroy(&(x)->ipf_lk)
905 #    else
906 #     define    KRWLOCK_T               struct sx
907 #     define    READ_ENTER(x)           sx_slock(&(x)->ipf_lk)
908 #     define    WRITE_ENTER(x)          sx_xlock(&(x)->ipf_lk)
909 #     define    MUTEX_DOWNGRADE(x)      sx_downgrade(&(x)->ipf_lk)
910 #     define    RWLOCK_INIT(x, y)       sx_init(&(x)->ipf_lk, (y))
911 #     define    RW_DESTROY(x)           sx_destroy(&(x)->ipf_lk)
912 #     ifdef sx_unlock
913 #      define   RWLOCK_EXIT(x)          sx_unlock(&(x)->ipf_lk)
914 #     else
915 #      define   RWLOCK_EXIT(x)          do { \
916                                             if ((x)->ipf_lk.sx_cnt < 0) \
917                                                 sx_xunlock(&(x)->ipf_lk); \
918                                             else \
919                                                 sx_sunlock(&(x)->ipf_lk); \
920                                         } while (0)
921 #     endif
922 #    endif
923 #   endif
924 #  endif
925 #  define       KMUTEX_T                struct mtx
926 # endif
927
928 # if (__FreeBSD_version >= 501113)
929 #  include <net/if_var.h>
930 #  define       IFNAME(x)       ((struct ifnet *)x)->if_xname
931 #  define       COPYIFNAME(v, x, b) \
932                                 (void) strncpy(b, \
933                                                ((struct ifnet *)x)->if_xname, \
934                                                LIFNAMSIZ)
935 # endif
936 # if (__FreeBSD_version >= 500043)
937 #  define       CACHE_HASH(x)   ((((struct ifnet *)fin->fin_ifp)->if_index) & 7)
938 # else
939 #  define       IFNAME(x)       ((struct ifnet *)x)->if_name
940 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
941                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
942 # endif
943
944 # ifdef _KERNEL
945 #  define       GETKTIME(x)     microtime((struct timeval *)x)
946
947 #  if (__FreeBSD_version >= 500002)
948 #   include <netinet/in_systm.h>
949 #   include <netinet/ip.h>
950 #   include <machine/in_cksum.h>
951 #  endif
952
953 #  if (__FreeBSD_version >= 500043)
954 #   define      USE_MUTEXES
955 #   define      MUTEX_ENTER(x)          mtx_lock(&(x)->ipf_lk)
956 #   define      MUTEX_EXIT(x)           mtx_unlock(&(x)->ipf_lk)
957 #   define      MUTEX_INIT(x,y)         mtx_init(&(x)->ipf_lk, (y), NULL,\
958                                                  MTX_DEF)
959 #   define      MUTEX_DESTROY(x)        mtx_destroy(&(x)->ipf_lk)
960 #   define      MUTEX_NUKE(x)           bzero((x), sizeof(*(x)))
961 #   include <machine/atomic.h>
962 #   define      ATOMIC_INC(x)           { mtx_lock(&ipf_rw.ipf_lk); (x)++; \
963                                           mtx_unlock(&ipf_rw.ipf_lk); }
964 #   define      ATOMIC_DEC(x)           { mtx_lock(&ipf_rw.ipf_lk); (x)--; \
965                                           mtx_unlock(&ipf_rw.ipf_lk); }
966 #   define      ATOMIC_INCL(x)          atomic_add_long(&(x), 1)
967 #   define      ATOMIC_INC64(x)         ATOMIC_INC(x)
968 #   define      ATOMIC_INC32(x)         atomic_add_32((u_int *)&(x), 1)
969 #   define      ATOMIC_INC16(x)         atomic_add_16(&(x), 1)
970 #   define      ATOMIC_DECL(x)          atomic_add_long(&(x), -1)
971 #   define      ATOMIC_DEC64(x)         ATOMIC_DEC(x)
972 #   define      ATOMIC_DEC32(x)         atomic_add_32((u_int *)&(x), -1)
973 #   define      ATOMIC_DEC16(x)         atomic_add_16(&(x), -1)
974 #   define      SPL_X(x)        ;
975 #   define      SPL_NET(x)      ;
976 #   define      SPL_IMP(x)      ;
977 #   define      SPL_SCHED(x)    ;
978 #  else
979 #   define      SPL_SCHED(x)    x = splhigh()
980 #  endif /* __FreeBSD_version >= 500043 */
981 #  define       MSGDSIZE(x)     mbufchainlen(x)
982 #  define       M_LEN(x)        (x)->m_len
983 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
984 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
985 typedef struct mbuf mb_t;
986 # endif /* _KERNEL */
987
988 # if __FreeBSD__ < 3
989 #  include <machine/spl.h>
990 # else
991 #  if __FreeBSD__ == 3
992 #   if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
993 #    define     ACTUALLY_LKM_NOT_KERNEL
994 #   endif
995 #  endif
996 # endif
997
998 # if (__FreeBSD_version >= 300000)
999 typedef u_long          ioctlcmd_t;
1000 # else
1001 typedef int             ioctlcmd_t;
1002 # endif
1003 typedef struct uio      uio_t;
1004 typedef int             minor_t;
1005 typedef u_int32_t       u_32_t;
1006 # define        U_32_T  1
1007
1008 # define OS_RECOGNISED 1
1009 #endif /* __FreeBSD__ */
1010
1011
1012 /* ----------------------------------------------------------------------- */
1013 /*                                O P E N B S D                            */
1014 /* ----------------------------------------------------------------------- */
1015 #ifdef __OpenBSD__
1016 # ifdef INET6
1017 #  define USE_INET6
1018 # endif
1019
1020 # ifdef _KERNEL
1021 #  if !defined(IPFILTER_LKM)
1022 #   include "bpfilter.h"
1023 #  endif
1024 #  if (OpenBSD >= 200311)
1025 #   define SNPRINTF     snprintf
1026 #   if defined(USE_INET6)
1027 #    include "netinet6/in6_var.h"
1028 #    include "netinet6/nd6.h"
1029 #   endif
1030 #  endif
1031 #  if (OpenBSD >= 200012)
1032 #   define HAVE_M_PULLDOWN 1
1033 #  endif
1034 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
1035 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
1036 #  define       GETKTIME(x)     microtime((struct timeval *)x)
1037 #  define       MSGDSIZE(x)     mbufchainlen(x)
1038 #  define       M_LEN(x)        (x)->m_len
1039 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
1040 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
1041 typedef struct mbuf mb_t;
1042 # endif /* _KERNEL */
1043 # if (OpenBSD >= 199603)
1044 #  define       IFNAME(x, b)    ((struct ifnet *)x)->if_xname
1045 #  define       COPYIFNAME(v, x, b) \
1046                                 (void) strncpy(b, \
1047                                                ((struct ifnet *)x)->if_xname, \
1048                                                LIFNAMSIZ)
1049 #  define       CACHE_HASH(x)   ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
1050 # else
1051 #  define       IFNAME(x, b)    ((struct ifnet *)x)->if_name
1052 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
1053                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1054 # endif
1055
1056 typedef struct uio      uio_t;
1057 typedef u_long          ioctlcmd_t;  
1058 typedef int             minor_t;
1059 typedef u_int32_t       u_32_t;
1060 # define        U_32_T  1
1061
1062 # define OS_RECOGNISED 1
1063 #endif /* __OpenBSD__ */
1064
1065
1066 /* ----------------------------------------------------------------------- */
1067 /*                                B S D O S                                */
1068 /* ----------------------------------------------------------------------- */
1069 #ifdef _BSDI_VERSION
1070 # ifdef INET6
1071 #  define USE_INET6
1072 # endif
1073
1074 # ifdef _KERNEL
1075 #  define       GETKTIME(x)     microtime((struct timeval *)x)
1076 #  define       MSGDSIZE(x)     mbufchainlen(x)
1077 #  define       M_LEN(x)        (x)->m_len
1078 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
1079 #  define       IFNAME(x, b)    ((struct ifnet *)x)->if_name
1080 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
1081                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1082 typedef struct mbuf mb_t;
1083 # endif /* _KERNEL */
1084
1085 # if (_BSDI_VERSION >= 199701)
1086 typedef u_long          ioctlcmd_t;
1087 # else
1088 typedef int             ioctlcmd_t;
1089 # endif
1090 typedef u_int32_t       u_32_t;
1091 # define        U_32_T  1
1092
1093 #endif /* _BSDI_VERSION */
1094
1095
1096 /* ----------------------------------------------------------------------- */
1097 /*                                  S U N O S 4                            */
1098 /* ----------------------------------------------------------------------- */
1099 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1100 # ifdef _KERNEL
1101 #  include      <sys/kmem_alloc.h>
1102 #  define       GETKTIME(x)     uniqtime((struct timeval *)x)
1103 #  define       MSGDSIZE(x)     mbufchainlen(x)
1104 #  define       M_LEN(x)        (x)->m_len
1105 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
1106 #  define       IFNAME(x, b)    ((struct ifnet *)x)->if_name
1107 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
1108                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1109 #  define       GETIFP(n, v)    ifunit(n, IFNAMSIZ)
1110 #  define       KFREE(x)        kmem_free((char *)(x), sizeof(*(x)))
1111 #  define       KFREES(x,s)     kmem_free((char *)(x), (s))
1112 #  define       SLEEP(id, n)    sleep((id), PZERO+1)
1113 #  define       WAKEUP(id,x)    wakeup(id + x)
1114 #  define       POLLWAKEUP(x)   ;
1115 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,c,d)
1116 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
1117
1118 extern  void    m_copydata __P((struct mbuf *, int, int, caddr_t));
1119 extern  void    m_copyback __P((struct mbuf *, int, int, caddr_t));
1120
1121 typedef struct mbuf mb_t;
1122 # endif
1123
1124 typedef struct uio      uio_t;
1125 typedef int             ioctlcmd_t;  
1126 typedef int             minor_t;
1127 typedef unsigned int    u_32_t;
1128 # define        U_32_T  1
1129
1130 # define OS_RECOGNISED 1
1131
1132 #endif /* SunOS 4 */
1133
1134 /* ----------------------------------------------------------------------- */
1135 /*                            L I N U X                                    */
1136 /* ----------------------------------------------------------------------- */
1137 #if defined(linux) && !defined(OS_RECOGNISED)
1138 #include <linux/config.h>
1139 #include <linux/version.h>
1140 # if (LINUX >= 20600) && defined(_KERNEL)
1141 #  define        HDR_T_PRIVATE  1
1142 # endif
1143 # undef USE_INET6
1144 # ifdef USE_INET6
1145 struct ip6_ext {
1146         u_char  ip6e_nxt;
1147         u_char  ip6e_len;
1148 };
1149 # endif
1150
1151 # ifdef _KERNEL
1152 #  define       IPF_PANIC(x,y)  if (x) { printf y; panic("ipf_panic"); }
1153 #  define       COPYIN(a,b,c)   copy_from_user((caddr_t)(b), (caddr_t)(a), (c))
1154 #  define       COPYOUT(a,b,c)  copy_to_user((caddr_t)(b), (caddr_t)(a), (c))
1155 #  define       FREE_MB_T(m)    kfree_skb(m)
1156 #  define       GETKTIME(x)     do_gettimeofday((struct timeval *)x)
1157 #  define       POLLWAKEUP(x)   ;
1158 #  ifdef wait_event_interruptible
1159 #   define      SLEEP(x,s)      wait_event_interruptible((*(x##_linux)), 0)
1160 #  else
1161 #   define      SLEEP(x,s)      0, interruptible_sleep_on(x##_linux)
1162 #  endif
1163 #   define      WAKEUP(x,y)     wake_up(x##_linux + y)
1164 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,c,d)
1165 #  define       USE_MUTEXES
1166 #  define       KRWLOCK_T               rwlock_t
1167 #  define       KMUTEX_T                spinlock_t
1168 #  define       MUTEX_INIT(x,y)         spin_lock_init(&(x)->ipf_lk)
1169 #  define       MUTEX_ENTER(x)          spin_lock(&(x)->ipf_lk)
1170 #  define       MUTEX_EXIT(x)           spin_unlock(&(x)->ipf_lk)
1171 #  define       MUTEX_DESTROY(x)        do { } while (0)
1172 #  define       MUTEX_NUKE(x)           bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1173 #  define       READ_ENTER(x)           ipf_read_enter(x)
1174 #  define       WRITE_ENTER(x)          ipf_write_enter(x)
1175 #  define       RWLOCK_INIT(x,y)        ipf_rw_init(x, y)
1176 #  define       RW_DESTROY(x)           do { } while (0)
1177 #  define       RWLOCK_EXIT(x)          ipf_rw_exit(x)
1178 #  define       MUTEX_DOWNGRADE(x)      ipf_rw_downgrade(x)
1179 #  define       ATOMIC_INCL(x)          MUTEX_ENTER(&ipf_rw); (x)++; \
1180                                         MUTEX_EXIT(&ipf_rw)
1181 #  define       ATOMIC_DECL(x)          MUTEX_ENTER(&ipf_rw); (x)--; \
1182                                         MUTEX_EXIT(&ipf_rw)
1183 #  define       ATOMIC_INC64(x)         MUTEX_ENTER(&ipf_rw); (x)++; \
1184                                         MUTEX_EXIT(&ipf_rw)
1185 #  define       ATOMIC_INC32(x)         MUTEX_ENTER(&ipf_rw); (x)++; \
1186                                         MUTEX_EXIT(&ipf_rw)
1187 #  define       ATOMIC_INC16(x)         MUTEX_ENTER(&ipf_rw); (x)++; \
1188                                         MUTEX_EXIT(&ipf_rw)
1189 #  define       ATOMIC_DEC64(x)         MUTEX_ENTER(&ipf_rw); (x)--; \
1190                                         MUTEX_EXIT(&ipf_rw)
1191 #  define       ATOMIC_DEC32(x)         MUTEX_ENTER(&ipf_rw); (x)--; \
1192                                         MUTEX_EXIT(&ipf_rw)
1193 #  define       ATOMIC_DEC16(x)         MUTEX_ENTER(&ipf_rw); (x)--; \
1194                                         MUTEX_EXIT(&ipf_rw)
1195 #  define       SPL_SCHED(x)            do { } while (0)
1196 #  define       SPL_IMP(x)              do { } while (0)
1197 #  define       SPL_NET(x)              do { } while (0)
1198 #  define       SPL_X(x)                do { } while (0)
1199 #  define       IFNAME(x)               ((struct net_device*)x)->name
1200 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
1201                           ((struct net_device *)fin->fin_ifp)->ifindex) & 7)
1202 typedef struct  sk_buff mb_t;
1203 extern  void    m_copydata __P((mb_t *, int, int, caddr_t));
1204 extern  void    m_copyback __P((mb_t *, int, int, caddr_t));
1205 extern  void    m_adj __P((mb_t *, int));
1206 extern  mb_t    *m_pullup __P((mb_t *, int));
1207 #  define       mbuf    sk_buff
1208
1209 #  define       mtod(m, t)      ((t)(m)->data)
1210 #  define       m_data          data
1211 #  define       m_len           len
1212 #  define       m_next          next
1213 #  define       M_DUPLICATE(m)  skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1214                                                                 GFP_KERNEL)
1215 #  define       MSGDSIZE(m)     (m)->len
1216 #  define       M_LEN(m)        (m)->len
1217
1218 #  define       splnet(x)       ;
1219 #  define       printf          printk
1220 #  define       bcopy(s,d,z)    memmove(d, s, z)
1221 #  define       bzero(s,z)      memset(s, 0, z)
1222 #  define       bcmp(a,b,z)     memcmp(a, b, z)
1223
1224 #  define       ifnet           net_device
1225 #  define       if_xname        name
1226 #  define       if_unit         ifindex 
1227
1228 #  define       KMALLOC(x,t)    (x) = (t)kmalloc(sizeof(*(x)), \
1229                                     in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1230 #  define       KFREE(x)        kfree(x)
1231 #  define       KMALLOCS(x,t,s) (x) = (t)kmalloc((s), \
1232                                     in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1233 #  define       KFREES(x,s)     kfree(x)
1234
1235 #  define GETIFP(n,v)   dev_get_by_name(n)
1236
1237 # else
1238 #  include <net/ethernet.h>
1239
1240 struct mbuf {
1241 };
1242
1243 #  ifndef _NET_ROUTE_H
1244 struct rtentry {
1245 };
1246 #  endif
1247
1248 struct ifnet {
1249         char    if_xname[IFNAMSIZ];
1250         int     if_unit;
1251         int     (* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1252         struct  ifaddr  *if_addrlist;
1253 };
1254 # define        IFNAME(x)       ((struct ifnet *)x)->if_xname
1255
1256 # endif /* _KERNEL */
1257
1258 # define        COPYIFNAME(v, x, b) \
1259                                 (void) strncpy(b, \
1260                                                ((struct ifnet *)x)->if_xname, \
1261                                                LIFNAMSIZ)
1262
1263 # include <linux/fs.h>
1264 # define        FWRITE  FMODE_WRITE
1265 # define        FREAD   FMODE_READ
1266
1267 # define        __USE_MISC      1
1268 # define        __FAVOR_BSD     1
1269
1270 typedef struct uio {
1271         struct iovec    *uio_iov;
1272         void    *uio_file;
1273         char    *uio_buf;
1274         int     uio_iovcnt;
1275         int     uio_offset;
1276         size_t  uio_resid;
1277         int     uio_rw;
1278 } uio_t;
1279
1280 extern  int     uiomove __P((caddr_t, size_t, int, struct uio *));
1281
1282 # define        UIO_READ        1
1283 # define        UIO_WRITE       2
1284
1285 typedef u_long          ioctlcmd_t;
1286 typedef int             minor_t;
1287 typedef u_int32_t       u_32_t;
1288 # define        U_32_T  1
1289
1290 # define OS_RECOGNISED 1
1291
1292 #endif
1293
1294
1295 /* ----------------------------------------------------------------------- */
1296 /*                                    A I X                                */
1297 /* ----------------------------------------------------------------------- */
1298 #if defined(_AIX51)
1299 # undef         MENTAT
1300
1301 # include <sys/lock.h>
1302 # include <sys/sysmacros.h>
1303
1304 # ifdef _KERNEL
1305 #  define rw_read_locked(x)             0
1306 #  include <net/net_globals.h>
1307 #  include <net/net_malloc.h>
1308 #  define       KMUTEX_T                simple_lock_t
1309 #  define       KRWLOCK_T               complex_lock_t
1310 #  define       USE_MUTEXES             1
1311 #  define       USE_SPL                 1
1312 #  define       READ_ENTER(x)           lock_read((x)->ipf_lk)
1313 #  define       WRITE_ENTER(x)          lock_write((x)->ipf_lk)
1314 #  define       MUTEX_DOWNGRADE(x)      lock_write_to_read((x)->ipf_lk)
1315 #  define       RWLOCK_INIT(x, y)       lock_alloc(&(x)->ipf_lk, \
1316                                                    LOCK_ALLOC_PIN, \
1317                                                    (u_short)y, 0); \
1318                                         lock_init((x)->ipf_lk, TRUE)
1319 #  define       RWLOCK_EXIT(x)          lock_done((x)->ipf_lk)
1320 #  define       RW_DESTROY(x)           lock_free(&(x)->ipf_lk)
1321 #  define       MUTEX_ENTER(x)          simple_lock((x)->ipf_lk)
1322 #  define       MUTEX_INIT(x, y)        lock_alloc(&(x)->ipf_lk, \
1323                                                    LOCK_ALLOC_PIN, \
1324                                                    (u_short)y, 0); \
1325                                         simple_lock_init((x)->ipf_lk)
1326 #  define       MUTEX_DESTROY(x)        lock_free(&(x)->ipf_lk)
1327 #  define       MUTEX_EXIT(x)           simple_unlock((x)->ipf_lk)
1328 #  define       MUTEX_NUKE(x)           bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1329 #   define      ATOMIC_INC64(x)         { MUTEX_ENTER(&ipf_rw); (x)++; \
1330                                           MUTEX_EXIT(&ipf_rw); }
1331 #   define      ATOMIC_DEC64(x)         { MUTEX_ENTER(&ipf_rw); (x)--; \
1332                                           MUTEX_EXIT(&ipf_rw); }
1333 #   define      ATOMIC_INC32(x)         { MUTEX_ENTER(&ipf_rw); (x)++; \
1334                                           MUTEX_EXIT(&ipf_rw); }
1335 #   define      ATOMIC_DEC32(x)         { MUTEX_ENTER(&ipf_rw); (x)--; \
1336                                           MUTEX_EXIT(&ipf_rw); }
1337 #   define      ATOMIC_INCL(x)          { MUTEX_ENTER(&ipf_rw); (x)++; \
1338                                           MUTEX_EXIT(&ipf_rw); }
1339 #   define      ATOMIC_DECL(x)          { MUTEX_ENTER(&ipf_rw); (x)--; \
1340                                           MUTEX_EXIT(&ipf_rw); }
1341 #   define      ATOMIC_INC(x)           { MUTEX_ENTER(&ipf_rw); (x)++; \
1342                                           MUTEX_EXIT(&ipf_rw); }
1343 #   define      ATOMIC_DEC(x)           { MUTEX_ENTER(&ipf_rw); (x)--; \
1344                                           MUTEX_EXIT(&ipf_rw); }
1345 #  define       SPL_SCHED(x)            x = splsched()
1346 #  define       SPL_NET(x)              x = splnet()
1347 #  define       SPL_IMP(x)              x = splimp()
1348 #  undef        SPL_X
1349 #  define       SPL_X(x)                splx(x)
1350 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,c,d)
1351 extern void* getifp __P((char *, int));
1352 #  define       GETIFP(n, v)            getifp(n, v)
1353 #  define       GET_MINOR               minor
1354 #  define       SLEEP(id, n)    sleepx((id), PZERO+1, 0)
1355 #  define       WAKEUP(id,x)    wakeup(id)
1356 #  define       POLLWAKEUP(x)   ;
1357 #  define       COPYIN(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
1358 #  define       COPYOUT(a,b,c)  copyout((caddr_t)(a), (caddr_t)(b), (c))
1359 #  define       KMALLOC(a, b)   MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1360 #  define       KMALLOCS(a, b, c)       MALLOC((a), b, (c), M_TEMP, \
1361                                             ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1362 #  define       KFREE(x)        FREE((x), M_TEMP)
1363 #  define       KFREES(x,s)     FREE((x), M_TEMP)
1364 #  define       MSGDSIZE(x)     mbufchainlen(x)
1365 #  define       M_LEN(x)        (x)->m_len
1366 #  define       M_DUPLICATE(x)  m_copy((x), 0, M_COPYALL)
1367 #  define       GETKTIME(x)
1368 #  define       IFNAME(x, b)    ((struct ifnet *)x)->if_name
1369 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
1370                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1371 #  define       IPF_PANIC(x,y)
1372 typedef struct mbuf mb_t;
1373 # endif /* _KERNEL */
1374
1375 /*
1376  * These are from's Solaris' #defines for little endian.
1377  */
1378 #if !defined(IP6F_MORE_FRAG)
1379 # define        IP6F_MORE_FRAG          0x0100
1380 #endif
1381 #if !defined(IP6F_RESERVED_MASK)
1382 # define        IP6F_RESERVED_MASK      0x0600
1383 #endif
1384 #if !defined(IP6F_OFF_MASK)
1385 # define        IP6F_OFF_MASK           0xf8ff
1386 #endif
1387
1388 struct ip6_ext {
1389         u_char  ip6e_nxt;
1390         u_char  ip6e_len;
1391 };
1392
1393 typedef int             ioctlcmd_t;  
1394 typedef int             minor_t;
1395 /*
1396  * Really, any arch where sizeof(long) != sizeof(int).
1397  */
1398 typedef unsigned int    u_32_t;
1399 # define        U_32_T  1
1400
1401 # define OS_RECOGNISED 1
1402 #endif  /* _AIX51 */
1403
1404
1405 #ifndef OS_RECOGNISED
1406 #error  ip_compat.h does not recognise this platform/OS.
1407 #endif
1408
1409
1410 /* ----------------------------------------------------------------------- */
1411 /*                           G E N E R I C                                 */
1412 /* ----------------------------------------------------------------------- */
1413 #ifndef OS_RECOGNISED
1414 #endif
1415
1416 /*
1417  * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1418  * filter rules.
1419  */
1420 #if !defined(IPFILTER_BPF)
1421 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
1422      (defined(NBPFILTER) && (NBPFILTER > 0))
1423 #  define       IPFILTER_BPF
1424 # endif
1425 #endif
1426
1427 /*
1428  * Userland locking primitives
1429  */
1430 typedef struct  {
1431         char    *eMm_owner;
1432         char    *eMm_heldin;
1433         u_int   eMm_magic;
1434         int     eMm_held;
1435         int     eMm_heldat;
1436 #if defined(__hpux) || defined(__linux)
1437         char    eMm_fill[8];
1438 #endif
1439 } eMmutex_t;
1440
1441 typedef struct  {
1442         char    *eMrw_owner;
1443         char    *eMrw_heldin;
1444         u_int   eMrw_magic;
1445         short   eMrw_read;
1446         short   eMrw_write;
1447         int     eMrw_heldat;
1448 #ifdef __hpux
1449         char    eMm_fill[24];
1450 #endif
1451 } eMrwlock_t;
1452
1453 typedef union {
1454 #ifdef KMUTEX_T
1455         struct  {
1456                 KMUTEX_T        ipf_slk;
1457                 char            *ipf_lname;
1458         } ipf_lkun_s;
1459 #endif
1460         eMmutex_t       ipf_emu;
1461 } ipfmutex_t;
1462
1463 typedef union {
1464 #ifdef KRWLOCK_T
1465         struct  {
1466                 KRWLOCK_T       ipf_slk;
1467                 char            *ipf_lname;
1468                 int             ipf_sr;
1469                 int             ipf_sw;
1470                 u_int           ipf_magic;
1471         } ipf_lkun_s;
1472 #endif
1473         eMrwlock_t      ipf_emu;
1474 } ipfrwlock_t;
1475
1476 #define ipf_lk          ipf_lkun_s.ipf_slk
1477 #define ipf_lname       ipf_lkun_s.ipf_lname
1478 #define ipf_isr         ipf_lkun_s.ipf_sr
1479 #define ipf_isw         ipf_lkun_s.ipf_sw
1480 #define ipf_magic       ipf_lkun_s.ipf_magic
1481
1482 #if !defined(__GNUC__) || \
1483     (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1484 # ifndef        INLINE
1485 #  define       INLINE
1486 # endif
1487 #else
1488 # define        INLINE  __inline__
1489 #endif
1490
1491 #if defined(linux) && defined(_KERNEL)
1492 extern  void    ipf_read_enter __P((ipfrwlock_t *));
1493 extern  void    ipf_write_enter __P((ipfrwlock_t *));
1494 extern  void    ipf_rw_exit __P((ipfrwlock_t *));
1495 extern  void    ipf_rw_init __P((ipfrwlock_t *, char *));
1496 extern  void    ipf_rw_downgrade __P((ipfrwlock_t *));
1497 #endif
1498
1499 /*
1500  * In a non-kernel environment, there are a lot of macros that need to be
1501  * filled in to be null-ops or to point to some compatibility function,
1502  * somewhere in userland.
1503  */
1504 #ifndef _KERNEL
1505 typedef struct  mb_s    {
1506         struct  mb_s    *mb_next;
1507         int             mb_len;
1508         u_long          mb_buf[2048];
1509 } mb_t;
1510 # undef         m_next
1511 # define        m_next          mb_next
1512 # define        MSGDSIZE(x)     (x)->mb_len     /* XXX - from ipt.c */
1513 # define        M_LEN(x)        (x)->mb_len
1514 # define        M_DUPLICATE(x)  (x)
1515 # define        GETKTIME(x)     gettimeofday((struct timeval *)(x), NULL)
1516 # undef         MTOD
1517 # define        MTOD(m, t)      ((t)(m)->mb_buf)
1518 # define        FREE_MB_T(x)
1519 # define        SLEEP(x,y)      1;
1520 # define        WAKEUP(x,y)     ;
1521 # define        POLLWAKEUP(y)   ;
1522 # define        IPF_PANIC(x,y)  ;
1523 # define        PANIC(x,y)      ;
1524 # define        SPL_SCHED(x)    ;
1525 # define        SPL_NET(x)      ;
1526 # define        SPL_IMP(x)      ;
1527 # define        SPL_X(x)        ;
1528 # define        KMALLOC(a,b)    (a) = (b)malloc(sizeof(*a))
1529 # define        KMALLOCS(a,b,c) (a) = (b)malloc(c)
1530 # define        KFREE(x)        free(x)
1531 # define        KFREES(x,s)     free(x)
1532 # define        GETIFP(x, v)    get_unit(x,v)
1533 # define        COPYIN(a,b,c)   bcopywrap((a), (b), (c))
1534 # define        COPYOUT(a,b,c)  bcopywrap((a), (b), (c))
1535 # define        COPYDATA(m, o, l, b)    bcopy(MTOD((mb_t *)m, char *) + (o), \
1536                                               (b), (l))
1537 # define        COPYBACK(m, o, l, b)    bcopy((b), \
1538                                               MTOD((mb_t *)m, char *) + (o), \
1539                                               (l))
1540 # define        UIOMOVE(a,b,c,d)        ipfuiomove((caddr_t)a,b,c,d)
1541 extern  void    m_copydata __P((mb_t *, int, int, caddr_t));
1542 extern  int     ipfuiomove __P((caddr_t, int, int, struct uio *));
1543 extern  int     bcopywrap __P((void *, void *, size_t));
1544 # ifndef CACHE_HASH
1545 #  define       CACHE_HASH(x)   ((IFNAME(fin->fin_ifp)[0] + \
1546                                   ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1547 # endif
1548
1549 # define        MUTEX_DESTROY(x)        eMmutex_destroy(&(x)->ipf_emu)
1550 # define        MUTEX_ENTER(x)          eMmutex_enter(&(x)->ipf_emu, \
1551                                                       __FILE__, __LINE__)
1552 # define        MUTEX_EXIT(x)           eMmutex_exit(&(x)->ipf_emu)
1553 # define        MUTEX_INIT(x,y)         eMmutex_init(&(x)->ipf_emu, y)
1554 # define        MUTEX_NUKE(x)           bzero((x), sizeof(*(x)))
1555
1556 # define        MUTEX_DOWNGRADE(x)      eMrwlock_downgrade(&(x)->ipf_emu, \
1557                                                            __FILE__, __LINE__)
1558 # define        READ_ENTER(x)           eMrwlock_read_enter(&(x)->ipf_emu, \
1559                                                             __FILE__, __LINE__)
1560 # define        RWLOCK_INIT(x, y)       eMrwlock_init(&(x)->ipf_emu, y)
1561 # define        RWLOCK_EXIT(x)          eMrwlock_exit(&(x)->ipf_emu)
1562 # define        RW_DESTROY(x)           eMrwlock_destroy(&(x)->ipf_emu)
1563 # define        WRITE_ENTER(x)          eMrwlock_write_enter(&(x)->ipf_emu, \
1564                                                              __FILE__, \
1565                                                              __LINE__)
1566
1567 # define        USE_MUTEXES             1
1568
1569 extern void eMmutex_destroy __P((eMmutex_t *));
1570 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1571 extern void eMmutex_exit __P((eMmutex_t *));
1572 extern void eMmutex_init __P((eMmutex_t *, char *));
1573 extern void eMrwlock_destroy __P((eMrwlock_t *));
1574 extern void eMrwlock_exit __P((eMrwlock_t *));
1575 extern void eMrwlock_init __P((eMrwlock_t *, char *));
1576 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1577 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1578 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1579
1580 #endif
1581
1582 #define MAX_IPV4HDR     ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1583
1584 #ifndef IP_OFFMASK
1585 # define        IP_OFFMASK      0x1fff
1586 #endif
1587
1588
1589 /*
1590  * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1591  * object.
1592  */
1593 #if (BSD > 199306)
1594 # define        USE_QUAD_T
1595 # define        U_QUAD_T        unsigned long long
1596 # define        QUAD_T          long long
1597 #else /* BSD > 199306 */
1598 # define        U_QUAD_T        u_long
1599 # define        QUAD_T          long
1600 #endif /* BSD > 199306 */
1601
1602
1603 #ifdef  USE_INET6
1604 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1605      defined(__osf__) || defined(linux)
1606 #  include <netinet/ip6.h>
1607 #  include <netinet/icmp6.h>
1608 #  if !defined(linux)
1609 #   if defined(_KERNEL) && !defined(__osf__)
1610 #    include <netinet6/ip6_var.h>
1611 #   endif
1612 #  endif
1613 typedef struct ip6_hdr  ip6_t;
1614 # endif
1615 #endif
1616
1617 #ifndef MAX
1618 # define        MAX(a,b)        (((a) > (b)) ? (a) : (b))
1619 #endif
1620
1621 #if defined(_KERNEL)
1622 # ifdef MENTAT
1623 #  define       COPYDATA        mb_copydata
1624 #  define       COPYBACK        mb_copyback
1625 # else
1626 #  define       COPYDATA        m_copydata
1627 #  define       COPYBACK        m_copyback
1628 # endif
1629 # if (BSD >= 199306) || defined(__FreeBSD__)
1630 #  if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1631        defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1632        defined(_BSDI_VERSION)
1633 #   include <vm/vm.h>
1634 #  endif
1635 #  if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
1636       (__FreeBSD_version >= 300000))
1637 #   if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
1638        (defined(OpenBSD) && (OpenBSD >= 200111))
1639 #    include <uvm/uvm_extern.h>
1640 #   else
1641 #    include <vm/vm_extern.h>
1642 extern  vm_map_t        kmem_map;
1643 #   endif
1644 #   include <sys/proc.h>
1645 #  else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1646 #   include <vm/vm_kern.h>
1647 #  endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1648
1649 #  ifdef IPFILTER_M_IPFILTER
1650 #    include <sys/malloc.h>
1651 MALLOC_DECLARE(M_IPFILTER);
1652 #    define     _M_IPF          M_IPFILTER
1653 #  else /* IPFILTER_M_IPFILTER */
1654 #   ifdef M_PFIL
1655 #    define     _M_IPF          M_PFIL
1656 #   else
1657 #    ifdef M_IPFILTER
1658 #     define    _M_IPF          M_IPFILTER
1659 #    else
1660 #     define    _M_IPF          M_TEMP
1661 #    endif /* M_IPFILTER */
1662 #   endif /* M_PFIL */
1663 #  endif /* IPFILTER_M_IPFILTER */
1664 #  if defined(__FreeBSD__) && __FreeBSD_version >= 800051
1665 #   define      KMALLOC(a, b)   do {                    \
1666         a = (b)malloc(sizeof(*(a)), _M_IPF, M_NOWAIT); \
1667     } while (0)
1668 #   define      KMALLOCS(a, b, c)       do { \
1669         a = (b)malloc((c), _M_IPF, ((c) > 4096) ? M_WAITOK : M_NOWAIT); \
1670     } while (0)
1671 #   define      KFREE(x)        free((x), _M_IPF)
1672 #   define      KFREES(x,s)     free((x), _M_IPF)
1673 #  else
1674 #   define      KMALLOC(a, b)   MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1675 #   if !defined(KMALLOCS)
1676 #    define     KMALLOCS(a, b, c)       MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1677 #   endif
1678 #   define      KFREE(x)        FREE((x), _M_IPF)
1679 #   define      KFREES(x,s)     FREE((x), _M_IPF)
1680 #  endif
1681 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,d)
1682 #  define       SLEEP(id, n)    tsleep((id), PPAUSE|PCATCH, n, 0)
1683 #  define       WAKEUP(id,x)    wakeup(id+x)
1684 #  define       POLLWAKEUP(x)   selwakeup(ipfselwait+x)
1685 #  define       GETIFP(n, v)    ifunit(n)
1686 # endif /* (Free)BSD */
1687
1688 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
1689 #  if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1690       (defined(OpenBSD) && (OpenBSD >= 200006))
1691 #   define      SPL_NET(x)      x = splsoftnet()
1692 #  else
1693 #   define      SPL_IMP(x)      x = splimp()
1694 #   define      SPL_NET(x)      x = splnet()
1695 #  endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1696 #  if !defined(SPL_SCHED)
1697 #   define      SPL_SCHED(x)    x = splsched()
1698 #  endif
1699 #  define       SPL_X(x)        (void) splx(x)
1700 # endif /* !USE_MUTEXES */
1701
1702 # ifndef FREE_MB_T
1703 #  define       FREE_MB_T(m)    m_freem(m)
1704 # endif
1705
1706 # ifndef MTOD
1707 #  define       MTOD(m,t)       mtod(m,t)
1708 # endif
1709
1710 # ifndef COPYIN
1711 #  define       COPYIN(a,b,c)   (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1712 #  define       COPYOUT(a,b,c)  (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1713 # endif
1714
1715 # ifndef KMALLOC
1716 #  define       KMALLOC(a,b)    (a) = (b)new_kmem_alloc(sizeof(*(a)), \
1717                                                         KMEM_NOSLEEP)
1718 #  define       KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1719 # endif
1720
1721 # ifndef        GET_MINOR
1722 #  define       GET_MINOR(x)    dev2unit(x)
1723 # endif
1724 # define        PANIC(x,y)      if (x) panic y
1725 #endif /* _KERNEL */
1726
1727 #if !defined(IFNAME) && !defined(_KERNEL)
1728 # define        IFNAME(x)       ((struct ifnet *)x)->if_name
1729 #endif
1730 #ifndef COPYIFNAME
1731 # define        NEED_FRGETIFNAME
1732 extern  char    *fr_getifname __P((struct ifnet *, char *));
1733 # define        COPYIFNAME(v, x, b) \
1734                                 fr_getifname((struct ifnet *)x, b)
1735 #endif
1736
1737 #ifndef ASSERT
1738 # ifdef _KERNEL
1739 #  define       ASSERT(x)
1740 # else
1741 #  define       ASSERT(x)       do { if (!(x)) abort(); } while (0)
1742 # endif
1743 #endif
1744
1745 #ifndef BCOPYIN
1746 #  define       BCOPYIN(a,b,c)  (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1747 #  define       BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1748 #endif
1749
1750 /*
1751  * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1752  * would mean all normal code that walks through strings needed casts.  Yuck.
1753  */
1754 #define ISALNUM(x)      isalnum((u_char)(x))
1755 #define ISALPHA(x)      isalpha((u_char)(x))
1756 #define ISASCII(x)      isascii((u_char)(x))
1757 #define ISDIGIT(x)      isdigit((u_char)(x))
1758 #define ISPRINT(x)      isprint((u_char)(x))
1759 #define ISSPACE(x)      isspace((u_char)(x))
1760 #define ISUPPER(x)      isupper((u_char)(x))
1761 #define ISXDIGIT(x)     isxdigit((u_char)(x))
1762 #define ISLOWER(x)      islower((u_char)(x))
1763 #define TOUPPER(x)      toupper((u_char)(x))
1764 #define TOLOWER(x)      tolower((u_char)(x))
1765
1766 /*
1767  * If mutexes aren't being used, turn all the mutex functions into null-ops.
1768  */
1769 #if !defined(USE_MUTEXES)
1770 # define        USE_SPL                 1
1771 # undef         RW_DESTROY
1772 # undef         MUTEX_INIT
1773 # undef         MUTEX_NUKE
1774 # undef         MUTEX_DESTROY
1775 # define        MUTEX_ENTER(x)          ;
1776 # define        READ_ENTER(x)           ;
1777 # define        WRITE_ENTER(x)          ;
1778 # define        MUTEX_DOWNGRADE(x)      ;
1779 # define        RWLOCK_INIT(x, y)       ;
1780 # define        RWLOCK_EXIT(x)          ;
1781 # define        RW_DESTROY(x)           ;
1782 # define        MUTEX_EXIT(x)           ;
1783 # define        MUTEX_INIT(x,y)         ;
1784 # define        MUTEX_DESTROY(x)        ;
1785 # define        MUTEX_NUKE(x)           ;
1786 #endif /* !USE_MUTEXES */
1787 #ifndef ATOMIC_INC
1788 # define        ATOMIC_INC(x)           (x)++
1789 # define        ATOMIC_DEC(x)           (x)--
1790 #endif
1791
1792 #if defined(USE_SPL) && defined(_KERNEL)
1793 # define        SPL_INT(x)      int x
1794 #else
1795 # define        SPL_INT(x)
1796 #endif
1797
1798 /*
1799  * If there are no atomic operations for bit sizes defined, define them to all
1800  * use a generic one that works for all sizes.
1801  */
1802 #ifndef ATOMIC_INCL
1803 # define        ATOMIC_INCL             ATOMIC_INC
1804 # define        ATOMIC_INC64            ATOMIC_INC
1805 # define        ATOMIC_INC32            ATOMIC_INC
1806 # define        ATOMIC_INC16            ATOMIC_INC
1807 # define        ATOMIC_DECL             ATOMIC_DEC
1808 # define        ATOMIC_DEC64            ATOMIC_DEC
1809 # define        ATOMIC_DEC32            ATOMIC_DEC
1810 # define        ATOMIC_DEC16            ATOMIC_DEC
1811 #endif
1812
1813 #ifndef HDR_T_PRIVATE
1814 typedef struct  tcphdr  tcphdr_t;
1815 typedef struct  udphdr  udphdr_t;
1816 #endif
1817 typedef struct  icmp    icmphdr_t;
1818 typedef struct  ip      ip_t;
1819 typedef struct  ether_header    ether_header_t;
1820 typedef struct  tcpiphdr        tcpiphdr_t;
1821
1822 #ifndef FR_GROUPLEN
1823 # define        FR_GROUPLEN     16
1824 #endif
1825
1826 #ifndef offsetof
1827 # define offsetof(t,m) (int)((&((t *)0L)->m))
1828 #endif
1829
1830 /*
1831  * This set of macros has been brought about because on Tru64 it is not
1832  * possible to easily assign or examine values in a structure that are
1833  * bit fields.
1834  */
1835 #ifndef IP_V
1836 # define        IP_V(x)         (x)->ip_v
1837 #endif
1838 #ifndef IP_V_A
1839 # define        IP_V_A(x,y)     (x)->ip_v = (y)
1840 #endif
1841 #ifndef IP_HL
1842 # define        IP_HL(x)        (x)->ip_hl
1843 #endif
1844 #ifndef IP_HL_A
1845 # define        IP_HL_A(x,y)    (x)->ip_hl = ((y) & 0xf)
1846 #endif
1847 #ifndef TCP_X2
1848 # define        TCP_X2(x)       (x)->th_x2
1849 #endif
1850 #ifndef TCP_X2_A
1851 # define        TCP_X2_A(x,y)   (x)->th_x2 = (y)
1852 #endif
1853 #ifndef TCP_OFF
1854 # define        TCP_OFF(x)      (x)->th_off
1855 #endif
1856 #ifndef TCP_OFF_A
1857 # define        TCP_OFF_A(x,y)  (x)->th_off = (y)
1858 #endif
1859 #define IPMINLEN(i, h)  ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
1860
1861
1862 /*
1863  * XXX - This is one of those *awful* hacks which nobody likes
1864  */
1865 #ifdef  ultrix
1866 #define A_A
1867 #else
1868 #define A_A     &
1869 #endif
1870
1871 #define TCPF_ALL        (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
1872                          TH_ECN|TH_CWR)
1873
1874 #if (BSD >= 199306) && !defined(m_act)
1875 # define        m_act   m_nextpkt
1876 #endif  
1877
1878 /*
1879  * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
1880  *
1881  * Basic Option
1882  *
1883  * 00000001   -   (Reserved 4)
1884  * 00111101   -   Top Secret
1885  * 01011010   -   Secret
1886  * 10010110   -   Confidential
1887  * 01100110   -   (Reserved 3)
1888  * 11001100   -   (Reserved 2)
1889  * 10101011   -   Unclassified
1890  * 11110001   -   (Reserved 1)
1891  */
1892 #define IPSO_CLASS_RES4         0x01
1893 #define IPSO_CLASS_TOPS         0x3d
1894 #define IPSO_CLASS_SECR         0x5a
1895 #define IPSO_CLASS_CONF         0x96
1896 #define IPSO_CLASS_RES3         0x66
1897 #define IPSO_CLASS_RES2         0xcc
1898 #define IPSO_CLASS_UNCL         0xab
1899 #define IPSO_CLASS_RES1         0xf1
1900
1901 #define IPSO_AUTH_GENSER        0x80
1902 #define IPSO_AUTH_ESI           0x40
1903 #define IPSO_AUTH_SCI           0x20
1904 #define IPSO_AUTH_NSA           0x10
1905 #define IPSO_AUTH_DOE           0x08
1906 #define IPSO_AUTH_UN            0x06
1907 #define IPSO_AUTH_FTE           0x01
1908
1909 /*
1910  * IP option #defines
1911  */
1912 #undef  IPOPT_RR
1913 #define IPOPT_RR        7 
1914 #undef  IPOPT_ZSU
1915 #define IPOPT_ZSU       10      /* ZSU */
1916 #undef  IPOPT_MTUP
1917 #define IPOPT_MTUP      11      /* MTUP */
1918 #undef  IPOPT_MTUR
1919 #define IPOPT_MTUR      12      /* MTUR */
1920 #undef  IPOPT_ENCODE
1921 #define IPOPT_ENCODE    15      /* ENCODE */
1922 #undef  IPOPT_TS
1923 #define IPOPT_TS        68
1924 #undef  IPOPT_TR
1925 #define IPOPT_TR        82      /* TR */
1926 #undef  IPOPT_SECURITY
1927 #define IPOPT_SECURITY  130
1928 #undef  IPOPT_LSRR
1929 #define IPOPT_LSRR      131
1930 #undef  IPOPT_E_SEC
1931 #define IPOPT_E_SEC     133     /* E-SEC */
1932 #undef  IPOPT_CIPSO
1933 #define IPOPT_CIPSO     134     /* CIPSO */
1934 #undef  IPOPT_SATID
1935 #define IPOPT_SATID     136
1936 #ifndef IPOPT_SID
1937 # define        IPOPT_SID       IPOPT_SATID
1938 #endif
1939 #undef  IPOPT_SSRR
1940 #define IPOPT_SSRR      137
1941 #undef  IPOPT_ADDEXT
1942 #define IPOPT_ADDEXT    147     /* ADDEXT */
1943 #undef  IPOPT_VISA
1944 #define IPOPT_VISA      142     /* VISA */
1945 #undef  IPOPT_IMITD
1946 #define IPOPT_IMITD     144     /* IMITD */
1947 #undef  IPOPT_EIP
1948 #define IPOPT_EIP       145     /* EIP */
1949 #undef  IPOPT_RTRALRT
1950 #define IPOPT_RTRALRT   148     /* RTRALRT */
1951 #undef  IPOPT_SDB
1952 #define IPOPT_SDB       149
1953 #undef  IPOPT_NSAPA
1954 #define IPOPT_NSAPA     150
1955 #undef  IPOPT_DPS
1956 #define IPOPT_DPS       151
1957 #undef  IPOPT_UMP
1958 #define IPOPT_UMP       152
1959 #undef  IPOPT_FINN
1960 #define IPOPT_FINN      205     /* FINN */
1961
1962 #ifndef TCPOPT_EOL
1963 # define TCPOPT_EOL             0
1964 #endif
1965 #ifndef TCPOPT_NOP
1966 # define TCPOPT_NOP             1
1967 #endif
1968 #ifndef TCPOPT_MAXSEG
1969 # define TCPOPT_MAXSEG          2
1970 #endif
1971 #ifndef TCPOLEN_MAXSEG
1972 # define TCPOLEN_MAXSEG         4
1973 #endif
1974 #ifndef TCPOPT_WINDOW
1975 # define TCPOPT_WINDOW          3
1976 #endif
1977 #ifndef TCPOLEN_WINDOW
1978 # define TCPOLEN_WINDOW         3
1979 #endif
1980 #ifndef TCPOPT_SACK_PERMITTED
1981 # define TCPOPT_SACK_PERMITTED  4
1982 #endif
1983 #ifndef TCPOLEN_SACK_PERMITTED
1984 # define TCPOLEN_SACK_PERMITTED 2
1985 #endif
1986 #ifndef TCPOPT_SACK
1987 # define TCPOPT_SACK            5
1988 #endif
1989 #ifndef TCPOPT_TIMESTAMP
1990 # define TCPOPT_TIMESTAMP       8
1991 #endif
1992
1993 #ifndef ICMP_MINLEN
1994 # define        ICMP_MINLEN     8
1995 #endif
1996 #ifndef ICMP_ECHOREPLY
1997 # define        ICMP_ECHOREPLY  0
1998 #endif
1999 #ifndef ICMP_UNREACH
2000 # define        ICMP_UNREACH    3
2001 #endif
2002 #ifndef ICMP_UNREACH_NET
2003 # define        ICMP_UNREACH_NET        0
2004 #endif
2005 #ifndef ICMP_UNREACH_HOST
2006 # define        ICMP_UNREACH_HOST       1
2007 #endif
2008 #ifndef ICMP_UNREACH_PROTOCOL
2009 # define        ICMP_UNREACH_PROTOCOL   2
2010 #endif
2011 #ifndef ICMP_UNREACH_PORT
2012 # define        ICMP_UNREACH_PORT       3
2013 #endif
2014 #ifndef ICMP_UNREACH_NEEDFRAG
2015 # define        ICMP_UNREACH_NEEDFRAG   4
2016 #endif
2017 #ifndef ICMP_UNREACH_SRCFAIL
2018 # define        ICMP_UNREACH_SRCFAIL    5
2019 #endif
2020 #ifndef ICMP_UNREACH_NET_UNKNOWN
2021 # define        ICMP_UNREACH_NET_UNKNOWN        6
2022 #endif
2023 #ifndef ICMP_UNREACH_HOST_UNKNOWN
2024 # define        ICMP_UNREACH_HOST_UNKNOWN       7
2025 #endif
2026 #ifndef ICMP_UNREACH_ISOLATED
2027 # define        ICMP_UNREACH_ISOLATED   8
2028 #endif
2029 #ifndef ICMP_UNREACH_NET_PROHIB
2030 # define        ICMP_UNREACH_NET_PROHIB 9
2031 #endif
2032 #ifndef ICMP_UNREACH_HOST_PROHIB
2033 # define        ICMP_UNREACH_HOST_PROHIB        10
2034 #endif
2035 #ifndef ICMP_UNREACH_TOSNET
2036 # define        ICMP_UNREACH_TOSNET     11
2037 #endif
2038 #ifndef ICMP_UNREACH_TOSHOST
2039 # define        ICMP_UNREACH_TOSHOST    12
2040 #endif
2041 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
2042 # define        ICMP_UNREACH_ADMIN_PROHIBIT     13
2043 #endif
2044 #ifndef ICMP_UNREACH_FILTER
2045 # define        ICMP_UNREACH_FILTER     13
2046 #endif
2047 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
2048 # define        ICMP_UNREACH_HOST_PRECEDENCE    14
2049 #endif
2050 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
2051 # define        ICMP_UNREACH_PRECEDENCE_CUTOFF  15
2052 #endif
2053 #ifndef ICMP_SOURCEQUENCH
2054 # define        ICMP_SOURCEQUENCH       4
2055 #endif
2056 #ifndef ICMP_REDIRECT_NET
2057 # define        ICMP_REDIRECT_NET       0
2058 #endif
2059 #ifndef ICMP_REDIRECT_HOST
2060 # define        ICMP_REDIRECT_HOST      1
2061 #endif
2062 #ifndef ICMP_REDIRECT_TOSNET
2063 # define        ICMP_REDIRECT_TOSNET    2
2064 #endif
2065 #ifndef ICMP_REDIRECT_TOSHOST
2066 # define        ICMP_REDIRECT_TOSHOST   3
2067 #endif
2068 #ifndef ICMP_ALTHOSTADDR
2069 # define        ICMP_ALTHOSTADDR        6
2070 #endif
2071 #ifndef ICMP_TIMXCEED
2072 # define        ICMP_TIMXCEED   11
2073 #endif
2074 #ifndef ICMP_TIMXCEED_INTRANS
2075 # define        ICMP_TIMXCEED_INTRANS   0
2076 #endif
2077 #ifndef ICMP_TIMXCEED_REASS
2078 # define                ICMP_TIMXCEED_REASS     1
2079 #endif
2080 #ifndef ICMP_PARAMPROB
2081 # define        ICMP_PARAMPROB  12
2082 #endif
2083 #ifndef ICMP_PARAMPROB_ERRATPTR
2084 # define        ICMP_PARAMPROB_ERRATPTR 0
2085 #endif
2086 #ifndef ICMP_PARAMPROB_OPTABSENT
2087 # define        ICMP_PARAMPROB_OPTABSENT        1
2088 #endif
2089 #ifndef ICMP_PARAMPROB_LENGTH
2090 # define        ICMP_PARAMPROB_LENGTH   2
2091 #endif
2092 #ifndef ICMP_TSTAMP
2093 # define        ICMP_TSTAMP     13
2094 #endif
2095 #ifndef ICMP_TSTAMPREPLY
2096 # define        ICMP_TSTAMPREPLY        14
2097 #endif
2098 #ifndef ICMP_IREQ
2099 # define        ICMP_IREQ       15
2100 #endif
2101 #ifndef ICMP_IREQREPLY
2102 # define        ICMP_IREQREPLY  16
2103 #endif
2104 #ifndef ICMP_MASKREQ
2105 # define        ICMP_MASKREQ    17
2106 #endif
2107 #ifndef ICMP_MASKREPLY
2108 # define        ICMP_MASKREPLY  18
2109 #endif
2110 #ifndef ICMP_TRACEROUTE
2111 # define        ICMP_TRACEROUTE 30
2112 #endif
2113 #ifndef ICMP_DATACONVERR
2114 # define        ICMP_DATACONVERR        31
2115 #endif
2116 #ifndef ICMP_MOBILE_REDIRECT
2117 # define        ICMP_MOBILE_REDIRECT    32
2118 #endif
2119 #ifndef ICMP_IPV6_WHEREAREYOU
2120 # define        ICMP_IPV6_WHEREAREYOU   33
2121 #endif
2122 #ifndef ICMP_IPV6_IAMHERE
2123 # define        ICMP_IPV6_IAMHERE       34
2124 #endif
2125 #ifndef ICMP_MOBILE_REGREQUEST
2126 # define        ICMP_MOBILE_REGREQUEST  35
2127 #endif
2128 #ifndef ICMP_MOBILE_REGREPLY
2129 # define        ICMP_MOBILE_REGREPLY    36
2130 #endif
2131 #ifndef ICMP_SKIP
2132 # define        ICMP_SKIP       39
2133 #endif
2134 #ifndef ICMP_PHOTURIS
2135 # define        ICMP_PHOTURIS   40
2136 #endif
2137 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
2138 # define        ICMP_PHOTURIS_UNKNOWN_INDEX     1
2139 #endif
2140 #ifndef ICMP_PHOTURIS_AUTH_FAILED
2141 # define        ICMP_PHOTURIS_AUTH_FAILED       2
2142 #endif
2143 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
2144 # define        ICMP_PHOTURIS_DECRYPT_FAILED    3
2145 #endif
2146 #ifndef IPVERSION
2147 # define        IPVERSION       4
2148 #endif
2149 #ifndef IPOPT_MINOFF
2150 # define        IPOPT_MINOFF    4
2151 #endif
2152 #ifndef IPOPT_COPIED
2153 # define        IPOPT_COPIED(x) ((x)&0x80)
2154 #endif
2155 #ifndef IPOPT_EOL
2156 # define        IPOPT_EOL       0
2157 #endif
2158 #ifndef IPOPT_NOP
2159 # define        IPOPT_NOP       1
2160 #endif
2161 #ifndef IP_MF
2162 # define        IP_MF   ((u_short)0x2000)
2163 #endif
2164 #ifndef ETHERTYPE_IP
2165 # define        ETHERTYPE_IP    ((u_short)0x0800)
2166 #endif
2167 #ifndef TH_FIN
2168 # define        TH_FIN  0x01
2169 #endif
2170 #ifndef TH_SYN
2171 # define        TH_SYN  0x02
2172 #endif
2173 #ifndef TH_RST
2174 # define        TH_RST  0x04
2175 #endif
2176 #ifndef TH_PUSH
2177 # define        TH_PUSH 0x08
2178 #endif
2179 #ifndef TH_ACK
2180 # define        TH_ACK  0x10
2181 #endif
2182 #ifndef TH_URG
2183 # define        TH_URG  0x20
2184 #endif
2185 #undef  TH_ACKMASK
2186 #define TH_ACKMASK      (TH_FIN|TH_SYN|TH_RST|TH_ACK)
2187
2188 #ifndef IPOPT_EOL
2189 # define        IPOPT_EOL       0
2190 #endif
2191 #ifndef IPOPT_NOP
2192 # define        IPOPT_NOP       1
2193 #endif
2194 #ifndef IPOPT_RR
2195 # define        IPOPT_RR        7
2196 #endif
2197 #ifndef IPOPT_TS
2198 # define        IPOPT_TS        68
2199 #endif
2200 #ifndef IPOPT_SECURITY
2201 # define        IPOPT_SECURITY  130
2202 #endif
2203 #ifndef IPOPT_LSRR
2204 # define        IPOPT_LSRR      131
2205 #endif
2206 #ifndef IPOPT_SATID
2207 # define        IPOPT_SATID     136
2208 #endif
2209 #ifndef IPOPT_SSRR
2210 # define        IPOPT_SSRR      137
2211 #endif
2212 #ifndef IPOPT_SECUR_UNCLASS
2213 # define        IPOPT_SECUR_UNCLASS     ((u_short)0x0000)
2214 #endif
2215 #ifndef IPOPT_SECUR_CONFID
2216 # define        IPOPT_SECUR_CONFID      ((u_short)0xf135)
2217 #endif
2218 #ifndef IPOPT_SECUR_EFTO
2219 # define        IPOPT_SECUR_EFTO        ((u_short)0x789a)
2220 #endif
2221 #ifndef IPOPT_SECUR_MMMM
2222 # define        IPOPT_SECUR_MMMM        ((u_short)0xbc4d)
2223 #endif
2224 #ifndef IPOPT_SECUR_RESTR
2225 # define        IPOPT_SECUR_RESTR       ((u_short)0xaf13)
2226 #endif
2227 #ifndef IPOPT_SECUR_SECRET
2228 # define        IPOPT_SECUR_SECRET      ((u_short)0xd788)
2229 #endif
2230 #ifndef IPOPT_SECUR_TOPSECRET
2231 # define        IPOPT_SECUR_TOPSECRET   ((u_short)0x6bc5)
2232 #endif
2233 #ifndef IPOPT_OLEN
2234 # define        IPOPT_OLEN      1
2235 #endif
2236 #ifndef IPPROTO_HOPOPTS
2237 # define        IPPROTO_HOPOPTS 0
2238 #endif
2239 #ifndef IPPROTO_ENCAP
2240 # define        IPPROTO_ENCAP   4
2241 #endif
2242 #ifndef IPPROTO_IPV6
2243 # define        IPPROTO_IPV6    41
2244 #endif
2245 #ifndef IPPROTO_ROUTING
2246 # define        IPPROTO_ROUTING 43
2247 #endif
2248 #ifndef IPPROTO_FRAGMENT
2249 # define        IPPROTO_FRAGMENT        44
2250 #endif
2251 #ifndef IPPROTO_GRE
2252 # define        IPPROTO_GRE     47      /* GRE encaps RFC 1701 */
2253 #endif
2254 #ifndef IPPROTO_ESP
2255 # define        IPPROTO_ESP     50
2256 #endif
2257 #ifndef IPPROTO_AH
2258 # define        IPPROTO_AH      51
2259 #endif
2260 #ifndef IPPROTO_ICMPV6
2261 # define        IPPROTO_ICMPV6  58
2262 #endif
2263 #ifndef IPPROTO_NONE
2264 # define        IPPROTO_NONE    59
2265 #endif
2266 #ifndef IPPROTO_DSTOPTS
2267 # define        IPPROTO_DSTOPTS 60
2268 #endif
2269 #ifndef IPPROTO_MOBILITY
2270 # define        IPPROTO_MOBILITY        135
2271 #endif
2272
2273 #ifndef ICMP_ROUTERADVERT
2274 # define        ICMP_ROUTERADVERT       9
2275 #endif
2276 #ifndef ICMP_ROUTERSOLICIT
2277 # define        ICMP_ROUTERSOLICIT      10
2278 #endif
2279 #ifndef ICMP6_DST_UNREACH
2280 # define        ICMP6_DST_UNREACH       1
2281 #endif
2282 #ifndef ICMP6_PACKET_TOO_BIG
2283 # define        ICMP6_PACKET_TOO_BIG    2
2284 #endif
2285 #ifndef ICMP6_TIME_EXCEEDED
2286 # define        ICMP6_TIME_EXCEEDED     3
2287 #endif
2288 #ifndef ICMP6_PARAM_PROB
2289 # define        ICMP6_PARAM_PROB        4
2290 #endif
2291
2292 #ifndef ICMP6_ECHO_REQUEST
2293 # define        ICMP6_ECHO_REQUEST      128
2294 #endif
2295 #ifndef ICMP6_ECHO_REPLY
2296 # define        ICMP6_ECHO_REPLY        129
2297 #endif
2298 #ifndef ICMP6_MEMBERSHIP_QUERY
2299 # define        ICMP6_MEMBERSHIP_QUERY  130
2300 #endif
2301 #ifndef MLD6_LISTENER_QUERY
2302 # define        MLD6_LISTENER_QUERY     130
2303 #endif
2304 #ifndef ICMP6_MEMBERSHIP_REPORT
2305 # define        ICMP6_MEMBERSHIP_REPORT 131
2306 #endif
2307 #ifndef MLD6_LISTENER_REPORT
2308 # define        MLD6_LISTENER_REPORT    131
2309 #endif
2310 #ifndef ICMP6_MEMBERSHIP_REDUCTION
2311 # define        ICMP6_MEMBERSHIP_REDUCTION      132
2312 #endif
2313 #ifndef MLD6_LISTENER_DONE
2314 # define        MLD6_LISTENER_DONE      132
2315 #endif
2316 #ifndef ND_ROUTER_SOLICIT
2317 # define        ND_ROUTER_SOLICIT       133
2318 #endif
2319 #ifndef ND_ROUTER_ADVERT
2320 # define        ND_ROUTER_ADVERT        134
2321 #endif
2322 #ifndef ND_NEIGHBOR_SOLICIT
2323 # define        ND_NEIGHBOR_SOLICIT     135
2324 #endif
2325 #ifndef ND_NEIGHBOR_ADVERT
2326 # define        ND_NEIGHBOR_ADVERT      136
2327 #endif
2328 #ifndef ND_REDIRECT
2329 # define        ND_REDIRECT     137
2330 #endif
2331 #ifndef ICMP6_ROUTER_RENUMBERING
2332 # define        ICMP6_ROUTER_RENUMBERING        138
2333 #endif
2334 #ifndef ICMP6_WRUREQUEST
2335 # define        ICMP6_WRUREQUEST        139
2336 #endif
2337 #ifndef ICMP6_WRUREPLY
2338 # define        ICMP6_WRUREPLY          140
2339 #endif
2340 #ifndef ICMP6_FQDN_QUERY
2341 # define        ICMP6_FQDN_QUERY        139
2342 #endif
2343 #ifndef ICMP6_FQDN_REPLY
2344 # define        ICMP6_FQDN_REPLY        140
2345 #endif
2346 #ifndef ICMP6_NI_QUERY
2347 # define        ICMP6_NI_QUERY          139
2348 #endif
2349 #ifndef ICMP6_NI_REPLY
2350 # define        ICMP6_NI_REPLY          140
2351 #endif
2352 #ifndef MLD6_MTRACE_RESP
2353 # define        MLD6_MTRACE_RESP        200
2354 #endif
2355 #ifndef MLD6_MTRACE
2356 # define        MLD6_MTRACE             201
2357 #endif
2358 #ifndef ICMP6_HADISCOV_REQUEST
2359 # define        ICMP6_HADISCOV_REQUEST  202
2360 #endif
2361 #ifndef ICMP6_HADISCOV_REPLY
2362 # define        ICMP6_HADISCOV_REPLY    203
2363 #endif
2364 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
2365 # define        ICMP6_MOBILEPREFIX_SOLICIT      204
2366 #endif
2367 #ifndef ICMP6_MOBILEPREFIX_ADVERT
2368 # define        ICMP6_MOBILEPREFIX_ADVERT       205
2369 #endif
2370 #ifndef ICMP6_MAXTYPE
2371 # define        ICMP6_MAXTYPE           205
2372 #endif
2373
2374 #ifndef ICMP6_DST_UNREACH_NOROUTE
2375 # define        ICMP6_DST_UNREACH_NOROUTE       0
2376 #endif
2377 #ifndef ICMP6_DST_UNREACH_ADMIN
2378 # define        ICMP6_DST_UNREACH_ADMIN         1
2379 #endif
2380 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
2381 # define        ICMP6_DST_UNREACH_NOTNEIGHBOR   2
2382 #endif
2383 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
2384 # define        ICMP6_DST_UNREACH_BEYONDSCOPE   2
2385 #endif
2386 #ifndef ICMP6_DST_UNREACH_ADDR
2387 # define        ICMP6_DST_UNREACH_ADDR          3
2388 #endif
2389 #ifndef ICMP6_DST_UNREACH_NOPORT
2390 # define        ICMP6_DST_UNREACH_NOPORT        4
2391 #endif
2392 #ifndef ICMP6_TIME_EXCEED_TRANSIT
2393 # define        ICMP6_TIME_EXCEED_TRANSIT       0
2394 #endif
2395 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
2396 # define        ICMP6_TIME_EXCEED_REASSEMBLY    1
2397 #endif
2398
2399 #ifndef ICMP6_NI_SUCCESS
2400 # define        ICMP6_NI_SUCCESS        0
2401 #endif
2402 #ifndef ICMP6_NI_REFUSED
2403 # define        ICMP6_NI_REFUSED        1
2404 #endif
2405 #ifndef ICMP6_NI_UNKNOWN
2406 # define        ICMP6_NI_UNKNOWN        2
2407 #endif
2408
2409 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
2410 # define        ICMP6_ROUTER_RENUMBERING_COMMAND        0
2411 #endif
2412 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
2413 # define        ICMP6_ROUTER_RENUMBERING_RESULT 1
2414 #endif
2415 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2416 # define        ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255
2417 #endif
2418
2419 #ifndef ICMP6_PARAMPROB_HEADER
2420 # define        ICMP6_PARAMPROB_HEADER  0
2421 #endif
2422 #ifndef ICMP6_PARAMPROB_NEXTHEADER
2423 # define        ICMP6_PARAMPROB_NEXTHEADER      1
2424 #endif
2425 #ifndef ICMP6_PARAMPROB_OPTION
2426 # define        ICMP6_PARAMPROB_OPTION  2
2427 #endif
2428
2429 #ifndef ICMP6_NI_SUBJ_IPV6
2430 # define        ICMP6_NI_SUBJ_IPV6      0
2431 #endif
2432 #ifndef ICMP6_NI_SUBJ_FQDN
2433 # define        ICMP6_NI_SUBJ_FQDN      1
2434 #endif
2435 #ifndef ICMP6_NI_SUBJ_IPV4
2436 # define        ICMP6_NI_SUBJ_IPV4      2
2437 #endif
2438
2439 /*
2440  * ECN is a new addition to TCP - RFC 2481
2441  */
2442 #ifndef TH_ECN
2443 # define        TH_ECN  0x40
2444 #endif
2445 #ifndef TH_CWR
2446 # define        TH_CWR  0x80
2447 #endif
2448 #define TH_ECNALL       (TH_ECN|TH_CWR)
2449
2450 /*
2451  * TCP States
2452  */
2453 #define IPF_TCPS_LISTEN         0       /* listening for connection */
2454 #define IPF_TCPS_SYN_SENT       1       /* active, have sent syn */
2455 #define IPF_TCPS_SYN_RECEIVED   2       /* have send and received syn */
2456 #define IPF_TCPS_HALF_ESTAB     3       /* for connections not fully "up" */
2457 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2458 #define IPF_TCPS_ESTABLISHED    4       /* established */
2459 #define IPF_TCPS_CLOSE_WAIT     5       /* rcvd fin, waiting for close */
2460 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2461 #define IPF_TCPS_FIN_WAIT_1     6       /* have closed, sent fin */
2462 #define IPF_TCPS_CLOSING        7       /* closed xchd FIN; await FIN ACK */
2463 #define IPF_TCPS_LAST_ACK       8       /* had fin and close; await FIN ACK */
2464 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2465 #define IPF_TCPS_FIN_WAIT_2     9       /* have closed, fin is acked */
2466 #define IPF_TCPS_TIME_WAIT      10      /* in 2*msl quiet wait after close */
2467 #define IPF_TCPS_CLOSED         11      /* closed */
2468 #define IPF_TCP_NSTATES         12
2469
2470 #define TCP_MSL                 120
2471
2472 #undef  ICMP_MAX_UNREACH
2473 #define ICMP_MAX_UNREACH        14
2474 #undef  ICMP_MAXTYPE
2475 #define ICMP_MAXTYPE            18
2476
2477 #ifndef IFNAMSIZ
2478 #define IFNAMSIZ                16
2479 #endif
2480
2481 #ifndef LOG_FTP
2482 # define        LOG_FTP         (11<<3)
2483 #endif
2484 #ifndef LOG_AUTHPRIV
2485 # define        LOG_AUTHPRIV    (10<<3)
2486 #endif
2487 #ifndef LOG_AUDIT
2488 # define        LOG_AUDIT       (13<<3)
2489 #endif
2490 #ifndef LOG_NTP
2491 # define        LOG_NTP         (12<<3)
2492 #endif
2493 #ifndef LOG_SECURITY
2494 # define        LOG_SECURITY    (13<<3)
2495 #endif
2496 #ifndef LOG_LFMT
2497 # define        LOG_LFMT        (14<<3)
2498 #endif
2499 #ifndef LOG_CONSOLE
2500 # define        LOG_CONSOLE     (14<<3)
2501 #endif
2502
2503 /*
2504  * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2505  * another IP header and then 64 bits of data, totalling 56.  Of course,
2506  * the last 64 bits is dependent on that being available.
2507  */
2508 #define ICMPERR_ICMPHLEN        8
2509 #define ICMPERR_IPICMPHLEN      (20 + 8)
2510 #define ICMPERR_MINPKTLEN       (20 + 8 + 20)
2511 #define ICMPERR_MAXPKTLEN       (20 + 8 + 20 + 8)
2512 #define ICMP6ERR_MINPKTLEN      (40 + 8)
2513 #define ICMP6ERR_IPICMPHLEN     (40 + 8 + 40)
2514
2515 #ifndef MIN
2516 # define        MIN(a,b)        (((a)<(b))?(a):(b))
2517 #endif
2518
2519 #ifdef IPF_DEBUG
2520 # define        DPRINT(x)       printf x
2521 #else
2522 # define        DPRINT(x)
2523 #endif
2524
2525 #ifdef RESCUE
2526 # undef IPFILTER_BPF
2527 #endif
2528
2529 #endif  /* __IP_COMPAT_H__ */