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