2 * Copyright (C) 1993-2001, 2003 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * @(#)ip_compat.h 1.8 1/14/96
8 * Id: ip_compat.h,v 2.142.2.36 2006/03/26 05:50:29 darrenr Exp $
11 #ifndef __IP_COMPAT_H__
12 #define __IP_COMPAT_H__
26 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
36 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
38 #if defined(SOLARIS2) && SOLARIS2 >= 8
43 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
44 !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
47 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \
48 !defined(_KERNEL) && !defined(USE_INET6)
50 # define IPFILTER_M_IPFILTER
52 #if defined(OpenBSD) && (OpenBSD >= 200206) && \
53 !defined(_KERNEL) && !defined(USE_INET6)
59 #if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6))
62 #if defined(HPUXREV) && (HPUXREV >= 1111)
66 #if defined(BSD) && (BSD < 199103) && defined(__osf__)
71 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
73 # if !defined(_KERNEL)
74 # define bzero(a,b) memset(a,0,b)
76 # define bcopy(a,b,c) memmove(b,a,c)
82 # define LIFNAMSIZ IF_NAMESIZE
85 # define LIFNAMSIZ IFNAMSIZ
92 #if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
94 u_char ether_addr_octet[6];
98 #if defined(__sgi) && !defined(IPFILTER_LKM)
100 # define IPL_EXTERN(ep) ipfilter##ep
102 # define IPL_EXTERN(ep) ipfilter/**/ep
106 # define IPL_EXTERN(ep) ipl##ep
108 # define IPL_EXTERN(ep) ipl/**/ep
113 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
124 # include <sys/uio.h>
132 /* ----------------------------------------------------------------------- */
134 /* ----------------------------------------------------------------------- */
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>
150 * because Solaris 2 defines these in two places :-/
155 # endif /* _KERNEL */
157 # if defined(SOLARIS2) && SOLARIS2 >= 8
158 # include <netinet/ip6.h>
159 # include <netinet/icmp6.h>
162 # include <inet/common.h>
163 /* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */
170 # define _SYS_PROMIF_H
172 # include <inet/ip.h>
174 # include <inet/ip_ire.h>
178 # if defined(SOLARIS2) && SOLARIS2 >= 8
179 # define SNPRINTF snprintf
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]
191 # endif /* SOLARIS2 >= 8 */
193 # if defined(SOLARIS2) && SOLARIS2 >= 6
194 # include <sys/atomic.h>
195 typedef uint32_t u_32_t;
197 typedef unsigned int u_32_t;
202 # define KRWLOCK_T krwlock_t
203 # define KMUTEX_T kmutex_t
206 # if defined(SOLARIS2) && 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)
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)
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 */
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), \
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), \
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) copyin((caddr_t)(a), (caddr_t)(b), (c))
243 # define BCOPYOUT(a,b,c) 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_SCHED(x) ;
248 # define SPL_NET(x) ;
249 # define SPL_IMP(x) ;
253 # define ntohs(x) (x)
254 # define ntohl(x) (x)
255 # define htons(x) (x)
256 # define htonl(x) (x)
258 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
259 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
260 # define GET_MINOR(x) getminor(x)
261 extern void *get_unit __P((char *, int));
262 # define GETIFP(n, v) get_unit(n, v)
263 # define IFNAME(x) ((qif_t *)x)->qf_name
264 # define COPYIFNAME(x, b) \
265 (void) strncpy(b, ((qif_t *)x)->qf_name, \
267 # define GETKTIME(x) uniqtime((struct timeval *)x)
268 # define MSGDSIZE(x) msgdsize(x)
269 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr)
270 # define M_DUPLICATE(x) dupmsg((x))
271 # define MTOD(m,t) ((t)((m)->b_rptr))
272 # define MTYPE(m) ((m)->b_datap->db_type)
273 # define FREE_MB_T(m) freemsg(m)
274 # define m_next b_cont
275 # define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
276 # define IPF_PANIC(x,y) if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
278 # endif /* _KERNEL */
280 # if defined(SOLARIS2) && (SOLARIS2 >= 7)
282 # define ALIGN32(ptr) (ptr ? 0L : 0L)
283 # define ALIGN16(ptr) (ptr ? 0L : 0L)
285 # define ALIGN32(ptr) (ptr)
286 # define ALIGN16(ptr) (ptr)
290 # if defined(SOLARIS2) && SOLARIS2 < 6
291 typedef struct uio uio_t;
293 typedef int ioctlcmd_t;
295 # define OS_RECOGNISED 1
299 /* ----------------------------------------------------------------------- */
301 /* ----------------------------------------------------------------------- */
304 # include <sys/sysmacros.h>
305 # include <sys/spinlock.h>
306 # include <sys/lock.h>
307 # include <sys/stream.h>
309 # include <netinet/if_ether.h>
310 # include <netinet/ip6.h>
311 # include <netinet/icmp6.h>
312 typedef struct ip6_hdr ip6_t;
316 # define SNPRINTF sprintf
317 # if (HPUXREV >= 1111)
320 # include <machine/sys/user.h>
321 # include <sys/kthread_iface.h>
322 # define READ_COLLISION 0x01
324 typedef struct iplog_select_s {
325 kthread_t *read_waiter;
331 # define GETKTIME(x) uniqtime((struct timeval *)x)
334 # include "kern_svcs.h"
336 # include <sys/kern_svcs.h>
341 # include <sys/reg.h>
342 # include "../netinet/ip_info.h"
344 * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
345 * are available. Attempting to use them actually results in unresolved
346 * symbols when it comes time to load the module.
347 * This has been fixed! Yipee!
351 # define ATOMIC_INCL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
352 # define ATOMIC_DECL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
354 # define ATOMIC_INCL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
355 # define ATOMIC_DECL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
357 # define ATOMIC_INC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
358 # define ATOMIC_INC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
359 # define ATOMIC_INC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
360 # define ATOMIC_DEC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
361 # define ATOMIC_DEC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
362 # define ATOMIC_DEC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
364 # define ATOMIC_INC64(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
365 MUTEX_EXIT(&ipf_rw); }
366 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
367 MUTEX_EXIT(&ipf_rw); }
368 # define ATOMIC_INC32(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
369 MUTEX_EXIT(&ipf_rw); }
370 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
371 MUTEX_EXIT(&ipf_rw); }
372 # define ATOMIC_INCL(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
373 MUTEX_EXIT(&ipf_rw); }
374 # define ATOMIC_DECL(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
375 MUTEX_EXIT(&ipf_rw); }
376 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
377 MUTEX_EXIT(&ipf_rw); }
378 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
379 MUTEX_EXIT(&ipf_rw); }
381 # define ip_cksum ip_csuma
382 # define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c)
384 # define MUTEX_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, (y))
385 # define MUTEX_ENTER(x) spinlock(&(x)->ipf_lk)
386 # define MUTEX_EXIT(x) spinunlock(&(x)->ipf_lk);
387 # define MUTEX_DESTROY(x)
388 # define MUTEX_NUKE(x) bzero((char *)(x), sizeof(*(x)))
389 # define KMUTEX_T lock_t
390 # define kmutex_t lock_t /* for pfil.h */
391 # define krwlock_t lock_t /* for pfil.h */
393 * The read-write lock implementation in HP-UX 11.0 is crippled - it can
394 * only be used by threads working in a user context!
395 * This has been fixed! Yipee! (Or at least it does in 11.00, not 11.11..)
398 # define MUTEX_DOWNGRADE(x) lock_write_to_read(x)
399 # define KRWLOCK_T struct rw_lock
400 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
401 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
403 # define RWLOCK_INIT(x, y) rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
405 # define RWLOCK_INIT(x, y) lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
407 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
409 # define KRWLOCK_T lock_t
410 # define KMUTEX_T lock_t
411 # define READ_ENTER(x) MUTEX_ENTER(x)
412 # define WRITE_ENTER(x) MUTEX_ENTER(x)
413 # define MUTEX_DOWNGRADE(x)
414 # define RWLOCK_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, y)
415 # define RWLOCK_EXIT(x) MUTEX_EXIT(x)
417 # define RW_DESTROY(x)
418 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
419 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
420 # define SPL_SCHED(x) ;
421 # define SPL_NET(x) ;
422 # define SPL_IMP(x) ;
425 extern void *get_unit __P((char *, int));
426 # define GETIFP(n, v) get_unit(n, v)
427 # define IFNAME(x, b) ((ill_t *)x)->ill_name
428 # define COPYIFNAME(x, b) \
429 (void) strncpy(b, ((qif_t *)x)->qf_name, \
431 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
432 # define SLEEP(id, n) { lock_t *_l = get_sleep_lock((caddr_t)id); \
433 sleep(id, PZERO+1); \
436 # define WAKEUP(id,x) { lock_t *_l = get_sleep_lock((caddr_t)id); \
440 # define POLLWAKEUP(x) ;
441 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
442 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
443 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
444 # define KFREES(x,s) kmem_free((char *)(x), (s))
445 # define MSGDSIZE(x) msgdsize(x)
446 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr)
447 # define M_DUPLICATE(x) dupmsg((x))
448 # define MTOD(m,t) ((t)((m)->b_rptr))
449 # define MTYPE(m) ((m)->b_datap->db_type)
450 # define FREE_MB_T(m) freemsg(m)
451 # define m_next b_cont
452 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
455 # define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
462 typedef unsigned char uchar_t;
464 # ifndef _SYS_STREAM_INCLUDED
465 typedef char * mblk_t;
466 typedef void * queue_t;
467 typedef u_long ulong;
469 # include <netinet/ip_info.h>
471 # endif /* _KERNEL */
474 # define ALIGN32(ptr) (ptr ? 0L : 0L)
475 # define ALIGN16(ptr) (ptr ? 0L : 0L)
477 # define ALIGN32(ptr) (ptr)
478 # define ALIGN16(ptr) (ptr)
481 typedef struct uio uio_t;
482 typedef int ioctlcmd_t;
484 typedef unsigned int u_32_t;
487 # define OS_RECOGNISED 1
491 /* ----------------------------------------------------------------------- */
493 /* ----------------------------------------------------------------------- */
497 typedef struct uio uio_t;
499 typedef int ioctlcmd_t;
500 typedef u_int32_t u_32_t;
508 # include <sys/ksynch.h>
509 # define IPF_LOCK_PL plhi
510 # include <sys/sema.h>
518 # define KMUTEX_T mutex_t
520 # define KMUTEX_T kmutex_t
521 # define KRWLOCK_T kmutex_t
525 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \
526 (x)++; MUTEX_EXIT(&ipf_rw); }
527 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \
528 (x)--; MUTEX_EXIT(&ipf_rw); }
531 # include <sys/atomic_ops.h>
532 # define ATOMIC_INCL(x) atomicAddUlong(&(x), 1)
533 # define ATOMIC_INC64(x) atomicAddUint64(&(x), 1)
534 # define ATOMIC_INC32(x) atomicAddUint(&(x), 1)
535 # define ATOMIC_INC16 ATOMIC_INC
536 # define ATOMIC_DECL(x) atomicAddUlong(&(x), -1)
537 # define ATOMIC_DEC64(x) atomicAddUint64(&(x), -1)
538 # define ATOMIC_DEC32(x) atomicAddUint(&(x), -1)
539 # define ATOMIC_DEC16 ATOMIC_DEC
541 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, \
544 # define MUTEX_ENTER(x) mutex_lock(&(x)->ipf_lk, 0)
546 # define MUTEX_EXIT(x) mutex_unlock(&(x)->ipf_lk)
547 # undef MUTEX_DESTROY
548 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk)
549 # define MUTEX_DOWNGRADE(x) mrdemote(&(x)->ipf_lk)
550 # define KRWLOCK_T mrlock_t
551 # define RWLOCK_INIT(x, y) mrinit(&(x)->ipf_lk, y)
553 # define RW_DESTROY(x) mrfree(&(x)->ipf_lk)
554 # define READ_ENTER(x) RW_RDLOCK(&(x)->ipf_lk)
555 # define WRITE_ENTER(x) RW_WRLOCK(&(x)->ipf_lk)
556 # define RWLOCK_EXIT(x) RW_UNLOCK(&(x)->ipf_lk)
558 # define READ_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
559 # define WRITE_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
560 # define MUTEX_DOWNGRADE(x) ;
561 # define RWLOCK_EXIT(x) MUTEX_EXIT(&(x)->ipf_lk)
562 # define MUTEX_EXIT(x) UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
563 # define MUTEX_INIT(x,y) (x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
564 # define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->ipf_lk.l)
565 # define MUTEX_ENTER(x) (x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
568 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
569 # define FREE_MB_T(m) m_freem(m)
570 # define MTOD(m,t) mtod(m,t)
571 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
572 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
573 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
574 # define SLEEP(id, n) sleep((id), PZERO+1)
575 # define WAKEUP(id,x) wakeup(id+x)
576 # define POLLWAKEUP(x) ;
577 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
578 # define KFREES(x,s) kmem_free((char *)(x), (s))
579 # define GETIFP(n,v) ifunit(n)
580 # include <sys/kmem.h>
581 # include <sys/ddi.h>
582 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
583 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
584 # define GET_MINOR(x) getminor(x)
586 # define SPL_IMP(x) (x) = splimp()
587 # define SPL_NET(x) (x) = splnet()
588 # define SPL_SCHED(x) (x) = splsched()
589 # define SPL_X(x) (void) splx(x)
590 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
591 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
592 # define MSGDSIZE(x) mbufchainlen(x)
593 # define M_LEN(x) (x)->m_len
594 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
595 # define GETKTIME(x) microtime((struct timeval *)x)
596 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
597 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
598 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
599 typedef struct mbuf mb_t;
603 # undef MUTEX_DESTROY
604 # endif /* _KERNEL */
606 # define OS_RECOGNISED 1
610 /* ----------------------------------------------------------------------- */
612 /* ----------------------------------------------------------------------- */
616 # include <kern/lock.h>
617 # include <sys/sysmacros.h>
620 # define KMUTEX_T simple_lock_data_t
621 # define KRWLOCK_T lock_data_t
622 # include <net/net_globals.h>
624 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
625 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
626 # define MUTEX_DOWNGRADE(x) lock_write_to_read(&(x)->ipf_lk)
627 # define RWLOCK_INIT(x, y) lock_init(&(x)->ipf_lk, TRUE)
628 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
629 # define RW_DESTROY(x) lock_terminate(&(x)->ipf_lk)
630 # define MUTEX_ENTER(x) simple_lock(&(x)->ipf_lk)
631 # define MUTEX_INIT(x, y) simple_lock_init(&(x)->ipf_lk)
632 # define MUTEX_DESTROY(x) simple_lock_terminate(&(x)->ipf_lk)
633 # define MUTEX_EXIT(x) simple_unlock(&(x)->ipf_lk)
634 # define MUTEX_NUKE(x) bzero(x, sizeof(*(x)))
635 # define ATOMIC_INC64(x) atomic_incq((uint64_t*)&(x))
636 # define ATOMIC_DEC64(x) atomic_decq((uint64_t*)&(x))
637 # define ATOMIC_INC32(x) atomic_incl((uint32_t*)&(x))
638 # define ATOMIC_DEC32(x) atomic_decl((uint32_t*)&(x))
639 # define ATOMIC_INC16(x) { simple_lock(&ipf_rw); (x)++; \
640 simple_unlock(&ipf_rw); }
641 # define ATOMIC_DEC16(x) { simple_lock(&ipf_rw); (x)--; \
642 simple_unlock(&ipf_rw); }
643 # define ATOMIC_INCL(x) atomic_incl((uint32_t*)&(x))
644 # define ATOMIC_DECL(x) atomic_decl((uint32_t*)&(x))
645 # define ATOMIC_INC(x) { simple_lock(&ipf_rw); (x)++; \
646 simple_unlock(&ipf_rw); }
647 # define ATOMIC_DEC(x) { simple_lock(&ipf_rw); (x)--; \
648 simple_unlock(&ipf_rw); }
649 # define SPL_SCHED(x) ;
650 # define SPL_NET(x) ;
651 # define SPL_IMP(x) ;
654 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a, b, d)
655 # define FREE_MB_T(m) m_freem(m)
656 # define MTOD(m,t) mtod(m,t)
657 # define GETIFP(n, v) ifunit(n)
658 # define GET_MINOR getminor
659 # define WAKEUP(id,x) wakeup(id + x)
660 # define POLLWAKEUP(x) ;
661 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
662 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
663 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
664 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFILT, \
665 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
666 # define KFREE(x) FREE((x), M_PFILT)
667 # define KFREES(x,s) FREE((x), M_PFILT)
668 # define MSGDSIZE(x) mbufchainlen(x)
669 # define M_LEN(x) (x)->m_len
670 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
671 # define GETKTIME(x) microtime((struct timeval *)x)
672 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
673 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
674 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
675 typedef struct mbuf mb_t;
676 # endif /* _KERNEL */
678 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
679 # define IP_V(x) ((x)->ip_vhl >> 4)
680 # define IP_HL(x) ((x)->ip_vhl & 0xf)
681 # define IP_V_A(x,y) (x)->ip_vhl |= (((y) << 4) & 0xf0)
682 # define IP_HL_A(x,y) (x)->ip_vhl |= ((y) & 0xf)
683 # define TCP_X2(x) ((x)->th_xoff & 0xf)
684 # define TCP_X2_A(x,y) (x)->th_xoff |= ((y) & 0xf)
685 # define TCP_OFF(x) ((x)->th_xoff >> 4)
686 # define TCP_OFF_A(x,y) (x)->th_xoff |= (((y) << 4) & 0xf0)
690 * These are from's Solaris' #defines for little endian.
692 #define IP6F_MORE_FRAG 0x0100
693 #define IP6F_RESERVED_MASK 0x0600
694 #define IP6F_OFF_MASK 0xf8ff
701 typedef int ioctlcmd_t;
703 * Really, any arch where sizeof(long) != sizeof(int).
705 typedef unsigned int u_32_t;
708 # define OS_RECOGNISED 1
711 /* ----------------------------------------------------------------------- */
713 /* ----------------------------------------------------------------------- */
715 # if (NetBSD >= 199905) && !defined(IPFILTER_LKM) && defined(_KERNEL)
716 # include "opt_ipfilter.h"
718 # if defined(_KERNEL)
719 # include <sys/systm.h>
723 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
724 # include "bpfilter.h"
725 # if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
726 # include "opt_inet.h"
731 # if (__NetBSD_Version__ >= 105000000)
732 # define HAVE_M_PULLDOWN 1
736 # if (__NetBSD_Version__ >= 499000000)
737 typedef char * caddr_t;
741 # if (__NetBSD_Version__ >= 399001400)
742 # define KMALLOCS(a, b, c) (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
744 # define MSGDSIZE(x) mbufchainlen(x)
745 # define M_LEN(x) (x)->m_len
746 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
747 # define GETKTIME(x) microtime((struct timeval *)x)
748 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
749 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
750 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
751 typedef struct mbuf mb_t;
752 # endif /* _KERNEL */
753 # if (NetBSD <= 1991011) && (NetBSD >= 199606)
754 # define IFNAME(x) ((struct ifnet *)x)->if_xname
755 # define COPYIFNAME(x, b) \
757 ((struct ifnet *)x)->if_xname, \
759 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
761 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
762 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
764 typedef struct uio uio_t;
765 typedef u_long ioctlcmd_t;
767 typedef u_int32_t u_32_t;
770 # define OS_RECOGNISED 1
771 #endif /* __NetBSD__ */
774 /* ----------------------------------------------------------------------- */
776 /* ----------------------------------------------------------------------- */
778 # if defined(_KERNEL)
779 # if (__FreeBSD_version >= 500000)
780 # include "opt_bpf.h"
784 # if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)
785 # include "opt_inet6.h"
787 # if defined(INET6) && !defined(USE_INET6)
792 # if defined(_KERNEL)
793 # if (__FreeBSD_version >= 400000)
795 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
796 * There may be other, safe, kernels but this is not extensively tested yet.
798 # define HAVE_M_PULLDOWN
800 # if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
801 # include "opt_ipfilter.h"
803 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
804 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
806 # if (__FreeBSD_version >= 500043)
809 # endif /* _KERNEL */
811 # if (__FreeBSD_version >= 500043)
812 # include <sys/mutex.h>
815 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
816 * for what we want to use them for, despite testing showing they work -
817 * with a WITNESS kernel, it generates LOR messages.
819 # define KMUTEX_T struct mtx
820 # if (__FreeBSD_version < 700000)
821 # define KRWLOCK_T struct mtx
823 # define KRWLOCK_T struct sx
827 # if (__FreeBSD_version >= 501113)
828 # include <net/if_var.h>
829 # define IFNAME(x) ((struct ifnet *)x)->if_xname
830 # define COPYIFNAME(x, b) \
832 ((struct ifnet *)x)->if_xname, \
835 # if (__FreeBSD_version >= 500043)
836 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index) & 7)
838 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
839 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
843 # define GETKTIME(x) microtime((struct timeval *)x)
845 # if (__FreeBSD_version >= 500002)
846 # include <netinet/in_systm.h>
847 # include <netinet/ip.h>
848 # include <machine/in_cksum.h>
851 # if (__FreeBSD_version >= 500043)
853 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk)
854 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk)
855 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
857 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
858 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
860 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
861 * for what we want to use them for, despite testing showing they work -
862 * with a WITNESS kernel, it generates LOR messages.
864 # if (__FreeBSD_version < 700000)
865 # define READ_ENTER(x) mtx_lock(&(x)->ipf_lk)
866 # define WRITE_ENTER(x) mtx_lock(&(x)->ipf_lk)
867 # define RWLOCK_EXIT(x) mtx_unlock(&(x)->ipf_lk)
868 # define MUTEX_DOWNGRADE(x) ;
869 # define RWLOCK_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
871 # define RW_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
873 # define READ_ENTER(x) sx_slock(&(x)->ipf_lk)
874 # define WRITE_ENTER(x) sx_xlock(&(x)->ipf_lk)
875 # define MUTEX_DOWNGRADE(x) sx_downgrade(&(x)->ipf_lk)
876 # define RWLOCK_INIT(x, y) sx_init(&(x)->ipf_lk, (y))
877 # define RW_DESTROY(x) sx_destroy(&(x)->ipf_lk)
879 # define RWLOCK_EXIT(x) sx_unlock(&(x)->ipf_lk)
881 # define RWLOCK_EXIT(x) do { \
882 if ((x)->ipf_lk.sx_cnt < 0) \
883 sx_xunlock(&(x)->ipf_lk); \
885 sx_sunlock(&(x)->ipf_lk); \
889 # include <machine/atomic.h>
890 # define ATOMIC_INC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)++; \
891 mtx_unlock(&ipf_rw.ipf_lk); }
892 # define ATOMIC_DEC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)--; \
893 mtx_unlock(&ipf_rw.ipf_lk); }
894 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
895 # define ATOMIC_INC64(x) ATOMIC_INC(x)
896 # define ATOMIC_INC32(x) atomic_add_32((u_int *)&(x), 1)
897 # define ATOMIC_INC16(x) atomic_add_16(&(x), 1)
898 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
899 # define ATOMIC_DEC64(x) ATOMIC_DEC(x)
900 # define ATOMIC_DEC32(x) atomic_add_32((u_int *)&(x), -1)
901 # define ATOMIC_DEC16(x) atomic_add_16(&(x), -1)
903 # define SPL_NET(x) ;
904 # define SPL_IMP(x) ;
905 # define SPL_SCHED(x) ;
906 extern int in_cksum __P((struct mbuf *, int));
907 # endif /* __FreeBSD_version >= 500043 */
908 # define MSGDSIZE(x) mbufchainlen(x)
909 # define M_LEN(x) (x)->m_len
910 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
911 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
912 typedef struct mbuf mb_t;
913 # endif /* _KERNEL */
916 # include <machine/spl.h>
918 # if __FreeBSD__ == 3
919 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
920 # define ACTUALLY_LKM_NOT_KERNEL
925 # if (__FreeBSD_version >= 300000)
926 typedef u_long ioctlcmd_t;
928 typedef int ioctlcmd_t;
930 typedef struct uio uio_t;
932 typedef u_int32_t u_32_t;
935 # define OS_RECOGNISED 1
936 #endif /* __FreeBSD__ */
939 /* ----------------------------------------------------------------------- */
941 /* ----------------------------------------------------------------------- */
948 # if !defined(IPFILTER_LKM)
949 # include "bpfilter.h"
951 # if (OpenBSD >= 200311)
952 # define SNPRINTF snprintf
953 # if defined(USE_INET6)
954 # include "netinet6/in6_var.h"
955 # include "netinet6/nd6.h"
958 # if (OpenBSD >= 200012)
959 # define HAVE_M_PULLDOWN 1
961 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
962 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
963 # define GETKTIME(x) microtime((struct timeval *)x)
964 # define MSGDSIZE(x) mbufchainlen(x)
965 # define M_LEN(x) (x)->m_len
966 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
967 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
968 typedef struct mbuf mb_t;
969 # endif /* _KERNEL */
970 # if (OpenBSD >= 199603)
971 # define IFNAME(x, b) ((struct ifnet *)x)->if_xname
972 # define COPYIFNAME(x, b) \
974 ((struct ifnet *)x)->if_xname, \
976 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
978 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
979 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
982 typedef struct uio uio_t;
983 typedef u_long ioctlcmd_t;
985 typedef u_int32_t u_32_t;
988 # define OS_RECOGNISED 1
989 #endif /* __OpenBSD__ */
992 /* ----------------------------------------------------------------------- */
994 /* ----------------------------------------------------------------------- */
1001 # define GETKTIME(x) microtime((struct timeval *)x)
1002 # define MSGDSIZE(x) mbufchainlen(x)
1003 # define M_LEN(x) (x)->m_len
1004 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1005 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1006 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1007 typedef struct mbuf mb_t;
1008 # endif /* _KERNEL */
1010 # if (_BSDI_VERSION >= 199701)
1011 typedef u_long ioctlcmd_t;
1013 typedef int ioctlcmd_t;
1015 typedef u_int32_t u_32_t;
1018 #endif /* _BSDI_VERSION */
1021 /* ----------------------------------------------------------------------- */
1023 /* ----------------------------------------------------------------------- */
1024 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1026 # include <sys/kmem_alloc.h>
1027 # define GETKTIME(x) uniqtime((struct timeval *)x)
1028 # define MSGDSIZE(x) mbufchainlen(x)
1029 # define M_LEN(x) (x)->m_len
1030 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1031 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1032 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1033 # define GETIFP(n, v) ifunit(n, IFNAMSIZ)
1034 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
1035 # define KFREES(x,s) kmem_free((char *)(x), (s))
1036 # define SLEEP(id, n) sleep((id), PZERO+1)
1037 # define WAKEUP(id,x) wakeup(id + x)
1038 # define POLLWAKEUP(x) ;
1039 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1040 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1042 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
1043 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
1045 typedef struct mbuf mb_t;
1048 typedef struct uio uio_t;
1049 typedef int ioctlcmd_t;
1050 typedef int minor_t;
1051 typedef unsigned int u_32_t;
1054 # define OS_RECOGNISED 1
1056 #endif /* SunOS 4 */
1058 /* ----------------------------------------------------------------------- */
1060 /* ----------------------------------------------------------------------- */
1061 #if defined(linux) && !defined(OS_RECOGNISED)
1062 #include <linux/config.h>
1063 #include <linux/version.h>
1064 # if (LINUX >= 20600) && defined(_KERNEL)
1065 # define HDR_T_PRIVATE 1
1076 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
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 POLLWAKEUP(x) ;
1082 # ifdef wait_event_interruptible
1083 # define SLEEP(x,s) wait_event_interruptible((*(x##_linux)), 0)
1085 # define SLEEP(x,s) 0, interruptible_sleep_on(x##_linux)
1087 # define WAKEUP(x,y) wake_up(x##_linux + y)
1088 # define UIOMOVE(a,b,c,d) uiomove(a,b,c,d)
1089 # define USE_MUTEXES
1090 # define KRWLOCK_T rwlock_t
1091 # define KMUTEX_T spinlock_t
1092 # define MUTEX_INIT(x,y) spin_lock_init(&(x)->ipf_lk)
1093 # define MUTEX_ENTER(x) spin_lock(&(x)->ipf_lk)
1094 # define MUTEX_EXIT(x) spin_unlock(&(x)->ipf_lk)
1095 # define MUTEX_DESTROY(x) do { } while (0)
1096 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1097 # define READ_ENTER(x) ipf_read_enter(x)
1098 # define WRITE_ENTER(x) ipf_write_enter(x)
1099 # define RWLOCK_INIT(x,y) ipf_rw_init(x, y)
1100 # define RW_DESTROY(x) do { } while (0)
1101 # define RWLOCK_EXIT(x) ipf_rw_exit(x)
1102 # define MUTEX_DOWNGRADE(x) ipf_rw_downgrade(x)
1103 # define ATOMIC_INCL(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1105 # define ATOMIC_DECL(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1107 # define ATOMIC_INC64(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1109 # define ATOMIC_INC32(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1111 # define ATOMIC_INC16(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1113 # define ATOMIC_DEC64(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1115 # define ATOMIC_DEC32(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1117 # define ATOMIC_DEC16(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1119 # define SPL_SCHED(x) do { } while (0)
1120 # define SPL_IMP(x) do { } while (0)
1121 # define SPL_NET(x) do { } while (0)
1122 # define SPL_X(x) do { } while (0)
1123 # define IFNAME(x) ((struct net_device*)x)->name
1124 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1125 ((struct net_device *)fin->fin_ifp)->ifindex) & 7)
1126 typedef struct sk_buff mb_t;
1127 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1128 extern void m_copyback __P((mb_t *, int, int, caddr_t));
1129 extern void m_adj __P((mb_t *, int));
1130 extern mb_t *m_pullup __P((mb_t *, int));
1131 # define mbuf sk_buff
1133 # define mtod(m, t) ((t)(m)->data)
1134 # define m_data data
1136 # define m_next next
1137 # define M_DUPLICATE(m) skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1139 # define MSGDSIZE(m) (m)->len
1140 # define M_LEN(m) (m)->len
1142 # define splnet(x) ;
1143 # define printf printk
1144 # define bcopy(s,d,z) memmove(d, s, z)
1145 # define bzero(s,z) memset(s, 0, z)
1146 # define bcmp(a,b,z) memcmp(a, b, z)
1148 # define ifnet net_device
1149 # define if_xname name
1150 # define if_unit ifindex
1152 # define KMALLOC(x,t) (x) = (t)kmalloc(sizeof(*(x)), \
1153 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1154 # define KFREE(x) kfree(x)
1155 # define KMALLOCS(x,t,s) (x) = (t)kmalloc((s), \
1156 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1157 # define KFREES(x,s) kfree(x)
1159 # define GETIFP(n,v) dev_get_by_name(n)
1162 # include <net/ethernet.h>
1167 # ifndef _NET_ROUTE_H
1173 char if_xname[IFNAMSIZ];
1175 int (* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1176 struct ifaddr *if_addrlist;
1178 # define IFNAME(x) ((struct ifnet *)x)->if_xname
1180 # endif /* _KERNEL */
1182 # define COPYIFNAME(x, b) \
1184 ((struct ifnet *)x)->if_xname, \
1187 # include <linux/fs.h>
1188 # define FWRITE FMODE_WRITE
1189 # define FREAD FMODE_READ
1191 # define __USE_MISC 1
1192 # define __FAVOR_BSD 1
1194 typedef struct uio {
1195 struct iovec *uio_iov;
1204 extern int uiomove __P((caddr_t, size_t, int, struct uio *));
1207 # define UIO_WRITE 2
1209 typedef u_long ioctlcmd_t;
1210 typedef int minor_t;
1211 typedef u_int32_t u_32_t;
1214 # define OS_RECOGNISED 1
1219 /* ----------------------------------------------------------------------- */
1221 /* ----------------------------------------------------------------------- */
1225 # include <sys/lock.h>
1226 # include <sys/sysmacros.h>
1229 # define rw_read_locked(x) 0
1230 # include <net/net_globals.h>
1231 # include <net/net_malloc.h>
1232 # define KMUTEX_T simple_lock_t
1233 # define KRWLOCK_T complex_lock_t
1234 # define USE_MUTEXES 1
1236 # define READ_ENTER(x) lock_read((x)->ipf_lk)
1237 # define WRITE_ENTER(x) lock_write((x)->ipf_lk)
1238 # define MUTEX_DOWNGRADE(x) lock_write_to_read((x)->ipf_lk)
1239 # define RWLOCK_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1242 lock_init((x)->ipf_lk, TRUE)
1243 # define RWLOCK_EXIT(x) lock_done((x)->ipf_lk)
1244 # define RW_DESTROY(x) lock_free(&(x)->ipf_lk)
1245 # define MUTEX_ENTER(x) simple_lock((x)->ipf_lk)
1246 # define MUTEX_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1249 simple_lock_init((x)->ipf_lk)
1250 # define MUTEX_DESTROY(x) lock_free(&(x)->ipf_lk)
1251 # define MUTEX_EXIT(x) simple_unlock((x)->ipf_lk)
1252 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1253 # define ATOMIC_INC64(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1254 MUTEX_EXIT(&ipf_rw); }
1255 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1256 MUTEX_EXIT(&ipf_rw); }
1257 # define ATOMIC_INC32(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1258 MUTEX_EXIT(&ipf_rw); }
1259 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1260 MUTEX_EXIT(&ipf_rw); }
1261 # define ATOMIC_INCL(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1262 MUTEX_EXIT(&ipf_rw); }
1263 # define ATOMIC_DECL(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1264 MUTEX_EXIT(&ipf_rw); }
1265 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1266 MUTEX_EXIT(&ipf_rw); }
1267 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1268 MUTEX_EXIT(&ipf_rw); }
1269 # define SPL_SCHED(x) x = splsched()
1270 # define SPL_NET(x) x = splnet()
1271 # define SPL_IMP(x) x = splimp()
1273 # define SPL_X(x) splx(x)
1274 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1275 extern void* getifp __P((char *, int));
1276 # define GETIFP(n, v) getifp(n, v)
1277 # define GET_MINOR minor
1278 # define SLEEP(id, n) sleepx((id), PZERO+1, 0)
1279 # define WAKEUP(id,x) wakeup(id)
1280 # define POLLWAKEUP(x) ;
1281 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
1282 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
1283 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1284 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, \
1285 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1286 # define KFREE(x) FREE((x), M_TEMP)
1287 # define KFREES(x,s) FREE((x), M_TEMP)
1288 # define MSGDSIZE(x) mbufchainlen(x)
1289 # define M_LEN(x) (x)->m_len
1290 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1291 # define GETKTIME(x)
1292 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1293 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1294 # define IPF_PANIC(x,y)
1295 typedef struct mbuf mb_t;
1296 # endif /* _KERNEL */
1299 * These are from's Solaris' #defines for little endian.
1301 #if !defined(IP6F_MORE_FRAG)
1302 # define IP6F_MORE_FRAG 0x0100
1304 #if !defined(IP6F_RESERVED_MASK)
1305 # define IP6F_RESERVED_MASK 0x0600
1307 #if !defined(IP6F_OFF_MASK)
1308 # define IP6F_OFF_MASK 0xf8ff
1316 typedef int ioctlcmd_t;
1317 typedef int minor_t;
1319 * Really, any arch where sizeof(long) != sizeof(int).
1321 typedef unsigned int u_32_t;
1324 # define OS_RECOGNISED 1
1328 #ifndef OS_RECOGNISED
1329 #error ip_compat.h does not recognise this platform/OS.
1333 /* ----------------------------------------------------------------------- */
1335 /* ----------------------------------------------------------------------- */
1336 #ifndef OS_RECOGNISED
1340 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1343 #if !defined(IPFILTER_BPF)
1344 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
1345 (defined(NBPFILTER) && (NBPFILTER > 0))
1346 # define IPFILTER_BPF
1351 * Userland locking primitives
1359 #if defined(__hpux) || defined(__linux)
1399 #define ipf_lk ipf_lkun_s.ipf_slk
1400 #define ipf_lname ipf_lkun_s.ipf_lname
1401 #define ipf_isr ipf_lkun_s.ipf_sr
1402 #define ipf_isw ipf_lkun_s.ipf_sw
1403 #define ipf_magic ipf_lkun_s.ipf_magic
1405 #if !defined(__GNUC__) || \
1406 (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1411 # define INLINE __inline__
1414 #if defined(linux) && defined(_KERNEL)
1415 extern void ipf_read_enter __P((ipfrwlock_t *));
1416 extern void ipf_write_enter __P((ipfrwlock_t *));
1417 extern void ipf_rw_exit __P((ipfrwlock_t *));
1418 extern void ipf_rw_init __P((ipfrwlock_t *, char *));
1419 extern void ipf_rw_downgrade __P((ipfrwlock_t *));
1423 * In a non-kernel environment, there are a lot of macros that need to be
1424 * filled in to be null-ops or to point to some compatibility function,
1425 * somewhere in userland.
1428 typedef struct mb_s {
1429 struct mb_s *mb_next;
1431 u_long mb_buf[2048];
1434 # define m_next mb_next
1435 # define MSGDSIZE(x) (x)->mb_len /* XXX - from ipt.c */
1436 # define M_LEN(x) (x)->mb_len
1437 # define M_DUPLICATE(x) (x)
1438 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL)
1440 # define MTOD(m, t) ((t)(m)->mb_buf)
1441 # define FREE_MB_T(x)
1442 # define SLEEP(x,y) 1;
1443 # define WAKEUP(x,y) ;
1444 # define POLLWAKEUP(y) ;
1445 # define IPF_PANIC(x,y) ;
1446 # define PANIC(x,y) ;
1447 # define SPL_SCHED(x) ;
1448 # define SPL_NET(x) ;
1449 # define SPL_IMP(x) ;
1451 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
1452 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
1453 # define KFREE(x) free(x)
1454 # define KFREES(x,s) free(x)
1455 # define GETIFP(x, v) get_unit(x,v)
1456 # define COPYIN(a,b,c) bcopywrap((a), (b), (c))
1457 # define COPYOUT(a,b,c) bcopywrap((a), (b), (c))
1458 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \
1460 # define COPYBACK(m, o, l, b) bcopy((b), \
1461 MTOD((mb_t *)m, char *) + (o), \
1463 # define UIOMOVE(a,b,c,d) ipfuiomove(a,b,c,d)
1464 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1465 extern int ipfuiomove __P((caddr_t, int, int, struct uio *));
1466 extern int bcopywrap __P((void *, void *, size_t));
1468 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1469 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1472 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu)
1473 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \
1475 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu)
1476 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y)
1477 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
1479 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \
1481 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \
1483 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y)
1484 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu)
1485 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu)
1486 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \
1490 # define USE_MUTEXES 1
1492 extern void eMmutex_destroy __P((eMmutex_t *));
1493 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1494 extern void eMmutex_exit __P((eMmutex_t *));
1495 extern void eMmutex_init __P((eMmutex_t *, char *));
1496 extern void eMrwlock_destroy __P((eMrwlock_t *));
1497 extern void eMrwlock_exit __P((eMrwlock_t *));
1498 extern void eMrwlock_init __P((eMrwlock_t *, char *));
1499 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1500 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1501 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1505 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1508 # define IP_OFFMASK 0x1fff
1513 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1518 # define U_QUAD_T unsigned long long
1519 # define QUAD_T long long
1520 #else /* BSD > 199306 */
1521 # define U_QUAD_T u_long
1522 # define QUAD_T long
1523 #endif /* BSD > 199306 */
1527 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1528 defined(__osf__) || defined(linux)
1529 # include <netinet/ip6.h>
1530 # include <netinet/icmp6.h>
1531 # if !defined(linux)
1532 # if defined(_KERNEL) && !defined(__osf__)
1533 # include <netinet6/ip6_var.h>
1536 typedef struct ip6_hdr ip6_t;
1541 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
1544 #if defined(_KERNEL)
1546 # define COPYDATA mb_copydata
1547 # define COPYBACK mb_copyback
1549 # define COPYDATA m_copydata
1550 # define COPYBACK m_copyback
1552 # if (BSD >= 199306) || defined(__FreeBSD__)
1553 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1554 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1555 defined(_BSDI_VERSION)
1558 # if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
1559 (__FreeBSD_version >= 300000))
1560 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
1561 (defined(OpenBSD) && (OpenBSD >= 200111))
1562 # include <uvm/uvm_extern.h>
1564 # include <vm/vm_extern.h>
1565 extern vm_map_t kmem_map;
1567 # include <sys/proc.h>
1568 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1569 # include <vm/vm_kern.h>
1570 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1572 # ifdef IPFILTER_M_IPFILTER
1573 # include <sys/malloc.h>
1574 MALLOC_DECLARE(M_IPFILTER);
1575 # define _M_IPF M_IPFILTER
1576 # else /* IPFILTER_M_IPFILTER */
1578 # define _M_IPF M_PFIL
1581 # define _M_IPF M_IPFILTER
1583 # define _M_IPF M_TEMP
1584 # endif /* M_IPFILTER */
1585 # endif /* M_PFIL */
1586 # endif /* IPFILTER_M_IPFILTER */
1587 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1588 # if !defined(KMALLOCS)
1589 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1591 # define KFREE(x) FREE((x), _M_IPF)
1592 # define KFREES(x,s) FREE((x), _M_IPF)
1593 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
1594 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
1595 # define WAKEUP(id,x) wakeup(id+x)
1596 # define POLLWAKEUP(x) selwakeup(ipfselwait+x)
1597 # define GETIFP(n, v) ifunit(n)
1598 # endif /* (Free)BSD */
1600 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
1601 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1602 (defined(OpenBSD) && (OpenBSD >= 200006))
1603 # define SPL_NET(x) x = splsoftnet()
1605 # define SPL_IMP(x) x = splimp()
1606 # define SPL_NET(x) x = splnet()
1607 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1608 # define SPL_SCHED(x) x = splsched()
1609 # define SPL_X(x) (void) splx(x)
1610 # endif /* !USE_MUTEXES */
1613 # define FREE_MB_T(m) m_freem(m)
1617 # define MTOD(m,t) mtod(m,t)
1621 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1622 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1626 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
1628 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1632 # define GET_MINOR(x) minor(x)
1634 # define PANIC(x,y) if (x) panic y
1635 #endif /* _KERNEL */
1638 # define IFNAME(x) ((struct ifnet *)x)->if_name
1641 # define NEED_FRGETIFNAME
1642 extern char *fr_getifname __P((struct ifnet *, char *));
1643 # define COPYIFNAME(x, b) \
1644 fr_getifname((struct ifnet *)x, b)
1652 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1653 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1657 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1658 * would mean all normal code that walks through strings needed casts. Yuck.
1660 #define ISALNUM(x) isalnum((u_char)(x))
1661 #define ISALPHA(x) isalpha((u_char)(x))
1662 #define ISASCII(x) isascii((u_char)(x))
1663 #define ISDIGIT(x) isdigit((u_char)(x))
1664 #define ISPRINT(x) isprint((u_char)(x))
1665 #define ISSPACE(x) isspace((u_char)(x))
1666 #define ISUPPER(x) isupper((u_char)(x))
1667 #define ISXDIGIT(x) isxdigit((u_char)(x))
1668 #define ISLOWER(x) islower((u_char)(x))
1669 #define TOUPPER(x) toupper((u_char)(x))
1670 #define TOLOWER(x) tolower((u_char)(x))
1673 * If mutexes aren't being used, turn all the mutex functions into null-ops.
1675 #if !defined(USE_MUTEXES)
1680 # undef MUTEX_DESTROY
1681 # define MUTEX_ENTER(x) ;
1682 # define READ_ENTER(x) ;
1683 # define WRITE_ENTER(x) ;
1684 # define MUTEX_DOWNGRADE(x) ;
1685 # define RWLOCK_INIT(x, y) ;
1686 # define RWLOCK_EXIT(x) ;
1687 # define RW_DESTROY(x) ;
1688 # define MUTEX_EXIT(x) ;
1689 # define MUTEX_INIT(x,y) ;
1690 # define MUTEX_DESTROY(x) ;
1691 # define MUTEX_NUKE(x) ;
1692 #endif /* !USE_MUTEXES */
1694 # define ATOMIC_INC(x) (x)++
1695 # define ATOMIC_DEC(x) (x)--
1698 #if defined(USE_SPL) && defined(_KERNEL)
1699 # define SPL_INT(x) int x
1705 * If there are no atomic operations for bit sizes defined, define them to all
1706 * use a generic one that works for all sizes.
1709 # define ATOMIC_INCL ATOMIC_INC
1710 # define ATOMIC_INC64 ATOMIC_INC
1711 # define ATOMIC_INC32 ATOMIC_INC
1712 # define ATOMIC_INC16 ATOMIC_INC
1713 # define ATOMIC_DECL ATOMIC_DEC
1714 # define ATOMIC_DEC64 ATOMIC_DEC
1715 # define ATOMIC_DEC32 ATOMIC_DEC
1716 # define ATOMIC_DEC16 ATOMIC_DEC
1719 #ifndef HDR_T_PRIVATE
1720 typedef struct tcphdr tcphdr_t;
1721 typedef struct udphdr udphdr_t;
1723 typedef struct icmp icmphdr_t;
1724 typedef struct ip ip_t;
1725 typedef struct ether_header ether_header_t;
1726 typedef struct tcpiphdr tcpiphdr_t;
1729 # define FR_GROUPLEN 16
1733 # define offsetof(t,m) (int)((&((t *)0L)->m))
1737 * This set of macros has been brought about because on Tru64 it is not
1738 * possible to easily assign or examine values in a structure that are
1742 # define IP_V(x) (x)->ip_v
1745 # define IP_V_A(x,y) (x)->ip_v = (y)
1748 # define IP_HL(x) (x)->ip_hl
1751 # define IP_HL_A(x,y) (x)->ip_hl = ((y) & 0xf)
1754 # define TCP_X2(x) (x)->th_x2
1757 # define TCP_X2_A(x,y) (x)->th_x2 = (y)
1760 # define TCP_OFF(x) (x)->th_off
1763 # define TCP_OFF_A(x,y) (x)->th_off = (y)
1765 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
1769 * XXX - This is one of those *awful* hacks which nobody likes
1777 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
1780 #if (BSD >= 199306) && !defined(m_act)
1781 # define m_act m_nextpkt
1785 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
1789 * 00000001 - (Reserved 4)
1790 * 00111101 - Top Secret
1792 * 10010110 - Confidential
1793 * 01100110 - (Reserved 3)
1794 * 11001100 - (Reserved 2)
1795 * 10101011 - Unclassified
1796 * 11110001 - (Reserved 1)
1798 #define IPSO_CLASS_RES4 0x01
1799 #define IPSO_CLASS_TOPS 0x3d
1800 #define IPSO_CLASS_SECR 0x5a
1801 #define IPSO_CLASS_CONF 0x96
1802 #define IPSO_CLASS_RES3 0x66
1803 #define IPSO_CLASS_RES2 0xcc
1804 #define IPSO_CLASS_UNCL 0xab
1805 #define IPSO_CLASS_RES1 0xf1
1807 #define IPSO_AUTH_GENSER 0x80
1808 #define IPSO_AUTH_ESI 0x40
1809 #define IPSO_AUTH_SCI 0x20
1810 #define IPSO_AUTH_NSA 0x10
1811 #define IPSO_AUTH_DOE 0x08
1812 #define IPSO_AUTH_UN 0x06
1813 #define IPSO_AUTH_FTE 0x01
1816 * IP option #defines
1821 #define IPOPT_ZSU 10 /* ZSU */
1823 #define IPOPT_MTUP 11 /* MTUP */
1825 #define IPOPT_MTUR 12 /* MTUR */
1827 #define IPOPT_ENCODE 15 /* ENCODE */
1831 #define IPOPT_TR 82 /* TR */
1832 #undef IPOPT_SECURITY
1833 #define IPOPT_SECURITY 130
1835 #define IPOPT_LSRR 131
1837 #define IPOPT_E_SEC 133 /* E-SEC */
1839 #define IPOPT_CIPSO 134 /* CIPSO */
1841 #define IPOPT_SATID 136
1843 # define IPOPT_SID IPOPT_SATID
1846 #define IPOPT_SSRR 137
1848 #define IPOPT_ADDEXT 147 /* ADDEXT */
1850 #define IPOPT_VISA 142 /* VISA */
1852 #define IPOPT_IMITD 144 /* IMITD */
1854 #define IPOPT_EIP 145 /* EIP */
1855 #undef IPOPT_RTRALRT
1856 #define IPOPT_RTRALRT 148 /* RTRALRT */
1858 #define IPOPT_SDB 149
1860 #define IPOPT_NSAPA 150
1862 #define IPOPT_DPS 151
1864 #define IPOPT_UMP 152
1866 #define IPOPT_FINN 205 /* FINN */
1869 # define TCPOPT_EOL 0
1872 # define TCPOPT_NOP 1
1874 #ifndef TCPOPT_MAXSEG
1875 # define TCPOPT_MAXSEG 2
1877 #ifndef TCPOLEN_MAXSEG
1878 # define TCPOLEN_MAXSEG 4
1880 #ifndef TCPOPT_WINDOW
1881 # define TCPOPT_WINDOW 3
1883 #ifndef TCPOLEN_WINDOW
1884 # define TCPOLEN_WINDOW 3
1886 #ifndef TCPOPT_SACK_PERMITTED
1887 # define TCPOPT_SACK_PERMITTED 4
1889 #ifndef TCPOLEN_SACK_PERMITTED
1890 # define TCPOLEN_SACK_PERMITTED 2
1893 # define TCPOPT_SACK 5
1895 #ifndef TCPOPT_TIMESTAMP
1896 # define TCPOPT_TIMESTAMP 8
1900 # define ICMP_MINLEN 8
1902 #ifndef ICMP_ECHOREPLY
1903 # define ICMP_ECHOREPLY 0
1905 #ifndef ICMP_UNREACH
1906 # define ICMP_UNREACH 3
1908 #ifndef ICMP_UNREACH_NET
1909 # define ICMP_UNREACH_NET 0
1911 #ifndef ICMP_UNREACH_HOST
1912 # define ICMP_UNREACH_HOST 1
1914 #ifndef ICMP_UNREACH_PROTOCOL
1915 # define ICMP_UNREACH_PROTOCOL 2
1917 #ifndef ICMP_UNREACH_PORT
1918 # define ICMP_UNREACH_PORT 3
1920 #ifndef ICMP_UNREACH_NEEDFRAG
1921 # define ICMP_UNREACH_NEEDFRAG 4
1923 #ifndef ICMP_UNREACH_SRCFAIL
1924 # define ICMP_UNREACH_SRCFAIL 5
1926 #ifndef ICMP_UNREACH_NET_UNKNOWN
1927 # define ICMP_UNREACH_NET_UNKNOWN 6
1929 #ifndef ICMP_UNREACH_HOST_UNKNOWN
1930 # define ICMP_UNREACH_HOST_UNKNOWN 7
1932 #ifndef ICMP_UNREACH_ISOLATED
1933 # define ICMP_UNREACH_ISOLATED 8
1935 #ifndef ICMP_UNREACH_NET_PROHIB
1936 # define ICMP_UNREACH_NET_PROHIB 9
1938 #ifndef ICMP_UNREACH_HOST_PROHIB
1939 # define ICMP_UNREACH_HOST_PROHIB 10
1941 #ifndef ICMP_UNREACH_TOSNET
1942 # define ICMP_UNREACH_TOSNET 11
1944 #ifndef ICMP_UNREACH_TOSHOST
1945 # define ICMP_UNREACH_TOSHOST 12
1947 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
1948 # define ICMP_UNREACH_ADMIN_PROHIBIT 13
1950 #ifndef ICMP_UNREACH_FILTER
1951 # define ICMP_UNREACH_FILTER 13
1953 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
1954 # define ICMP_UNREACH_HOST_PRECEDENCE 14
1956 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
1957 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
1959 #ifndef ICMP_SOURCEQUENCH
1960 # define ICMP_SOURCEQUENCH 4
1962 #ifndef ICMP_REDIRECT_NET
1963 # define ICMP_REDIRECT_NET 0
1965 #ifndef ICMP_REDIRECT_HOST
1966 # define ICMP_REDIRECT_HOST 1
1968 #ifndef ICMP_REDIRECT_TOSNET
1969 # define ICMP_REDIRECT_TOSNET 2
1971 #ifndef ICMP_REDIRECT_TOSHOST
1972 # define ICMP_REDIRECT_TOSHOST 3
1974 #ifndef ICMP_ALTHOSTADDR
1975 # define ICMP_ALTHOSTADDR 6
1977 #ifndef ICMP_TIMXCEED
1978 # define ICMP_TIMXCEED 11
1980 #ifndef ICMP_TIMXCEED_INTRANS
1981 # define ICMP_TIMXCEED_INTRANS 0
1983 #ifndef ICMP_TIMXCEED_REASS
1984 # define ICMP_TIMXCEED_REASS 1
1986 #ifndef ICMP_PARAMPROB
1987 # define ICMP_PARAMPROB 12
1989 #ifndef ICMP_PARAMPROB_ERRATPTR
1990 # define ICMP_PARAMPROB_ERRATPTR 0
1992 #ifndef ICMP_PARAMPROB_OPTABSENT
1993 # define ICMP_PARAMPROB_OPTABSENT 1
1995 #ifndef ICMP_PARAMPROB_LENGTH
1996 # define ICMP_PARAMPROB_LENGTH 2
1999 # define ICMP_TSTAMP 13
2001 #ifndef ICMP_TSTAMPREPLY
2002 # define ICMP_TSTAMPREPLY 14
2005 # define ICMP_IREQ 15
2007 #ifndef ICMP_IREQREPLY
2008 # define ICMP_IREQREPLY 16
2010 #ifndef ICMP_MASKREQ
2011 # define ICMP_MASKREQ 17
2013 #ifndef ICMP_MASKREPLY
2014 # define ICMP_MASKREPLY 18
2016 #ifndef ICMP_TRACEROUTE
2017 # define ICMP_TRACEROUTE 30
2019 #ifndef ICMP_DATACONVERR
2020 # define ICMP_DATACONVERR 31
2022 #ifndef ICMP_MOBILE_REDIRECT
2023 # define ICMP_MOBILE_REDIRECT 32
2025 #ifndef ICMP_IPV6_WHEREAREYOU
2026 # define ICMP_IPV6_WHEREAREYOU 33
2028 #ifndef ICMP_IPV6_IAMHERE
2029 # define ICMP_IPV6_IAMHERE 34
2031 #ifndef ICMP_MOBILE_REGREQUEST
2032 # define ICMP_MOBILE_REGREQUEST 35
2034 #ifndef ICMP_MOBILE_REGREPLY
2035 # define ICMP_MOBILE_REGREPLY 36
2038 # define ICMP_SKIP 39
2040 #ifndef ICMP_PHOTURIS
2041 # define ICMP_PHOTURIS 40
2043 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
2044 # define ICMP_PHOTURIS_UNKNOWN_INDEX 1
2046 #ifndef ICMP_PHOTURIS_AUTH_FAILED
2047 # define ICMP_PHOTURIS_AUTH_FAILED 2
2049 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
2050 # define ICMP_PHOTURIS_DECRYPT_FAILED 3
2053 # define IPVERSION 4
2055 #ifndef IPOPT_MINOFF
2056 # define IPOPT_MINOFF 4
2058 #ifndef IPOPT_COPIED
2059 # define IPOPT_COPIED(x) ((x)&0x80)
2062 # define IPOPT_EOL 0
2065 # define IPOPT_NOP 1
2068 # define IP_MF ((u_short)0x2000)
2070 #ifndef ETHERTYPE_IP
2071 # define ETHERTYPE_IP ((u_short)0x0800)
2074 # define TH_FIN 0x01
2077 # define TH_SYN 0x02
2080 # define TH_RST 0x04
2083 # define TH_PUSH 0x08
2086 # define TH_ACK 0x10
2089 # define TH_URG 0x20
2092 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK)
2095 # define IPOPT_EOL 0
2098 # define IPOPT_NOP 1
2104 # define IPOPT_TS 68
2106 #ifndef IPOPT_SECURITY
2107 # define IPOPT_SECURITY 130
2110 # define IPOPT_LSRR 131
2113 # define IPOPT_SATID 136
2116 # define IPOPT_SSRR 137
2118 #ifndef IPOPT_SECUR_UNCLASS
2119 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
2121 #ifndef IPOPT_SECUR_CONFID
2122 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
2124 #ifndef IPOPT_SECUR_EFTO
2125 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
2127 #ifndef IPOPT_SECUR_MMMM
2128 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
2130 #ifndef IPOPT_SECUR_RESTR
2131 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
2133 #ifndef IPOPT_SECUR_SECRET
2134 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
2136 #ifndef IPOPT_SECUR_TOPSECRET
2137 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
2140 # define IPOPT_OLEN 1
2142 #ifndef IPPROTO_HOPOPTS
2143 # define IPPROTO_HOPOPTS 0
2145 #ifndef IPPROTO_ENCAP
2146 # define IPPROTO_ENCAP 4
2148 #ifndef IPPROTO_IPV6
2149 # define IPPROTO_IPV6 41
2151 #ifndef IPPROTO_ROUTING
2152 # define IPPROTO_ROUTING 43
2154 #ifndef IPPROTO_FRAGMENT
2155 # define IPPROTO_FRAGMENT 44
2158 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
2161 # define IPPROTO_ESP 50
2164 # define IPPROTO_AH 51
2166 #ifndef IPPROTO_ICMPV6
2167 # define IPPROTO_ICMPV6 58
2169 #ifndef IPPROTO_NONE
2170 # define IPPROTO_NONE 59
2172 #ifndef IPPROTO_DSTOPTS
2173 # define IPPROTO_DSTOPTS 60
2175 #ifndef IPPROTO_MOBILITY
2176 # define IPPROTO_MOBILITY 135
2179 #ifndef ICMP_ROUTERADVERT
2180 # define ICMP_ROUTERADVERT 9
2182 #ifndef ICMP_ROUTERSOLICIT
2183 # define ICMP_ROUTERSOLICIT 10
2185 #ifndef ICMP6_DST_UNREACH
2186 # define ICMP6_DST_UNREACH 1
2188 #ifndef ICMP6_PACKET_TOO_BIG
2189 # define ICMP6_PACKET_TOO_BIG 2
2191 #ifndef ICMP6_TIME_EXCEEDED
2192 # define ICMP6_TIME_EXCEEDED 3
2194 #ifndef ICMP6_PARAM_PROB
2195 # define ICMP6_PARAM_PROB 4
2198 #ifndef ICMP6_ECHO_REQUEST
2199 # define ICMP6_ECHO_REQUEST 128
2201 #ifndef ICMP6_ECHO_REPLY
2202 # define ICMP6_ECHO_REPLY 129
2204 #ifndef ICMP6_MEMBERSHIP_QUERY
2205 # define ICMP6_MEMBERSHIP_QUERY 130
2207 #ifndef MLD6_LISTENER_QUERY
2208 # define MLD6_LISTENER_QUERY 130
2210 #ifndef ICMP6_MEMBERSHIP_REPORT
2211 # define ICMP6_MEMBERSHIP_REPORT 131
2213 #ifndef MLD6_LISTENER_REPORT
2214 # define MLD6_LISTENER_REPORT 131
2216 #ifndef ICMP6_MEMBERSHIP_REDUCTION
2217 # define ICMP6_MEMBERSHIP_REDUCTION 132
2219 #ifndef MLD6_LISTENER_DONE
2220 # define MLD6_LISTENER_DONE 132
2222 #ifndef ND_ROUTER_SOLICIT
2223 # define ND_ROUTER_SOLICIT 133
2225 #ifndef ND_ROUTER_ADVERT
2226 # define ND_ROUTER_ADVERT 134
2228 #ifndef ND_NEIGHBOR_SOLICIT
2229 # define ND_NEIGHBOR_SOLICIT 135
2231 #ifndef ND_NEIGHBOR_ADVERT
2232 # define ND_NEIGHBOR_ADVERT 136
2235 # define ND_REDIRECT 137
2237 #ifndef ICMP6_ROUTER_RENUMBERING
2238 # define ICMP6_ROUTER_RENUMBERING 138
2240 #ifndef ICMP6_WRUREQUEST
2241 # define ICMP6_WRUREQUEST 139
2243 #ifndef ICMP6_WRUREPLY
2244 # define ICMP6_WRUREPLY 140
2246 #ifndef ICMP6_FQDN_QUERY
2247 # define ICMP6_FQDN_QUERY 139
2249 #ifndef ICMP6_FQDN_REPLY
2250 # define ICMP6_FQDN_REPLY 140
2252 #ifndef ICMP6_NI_QUERY
2253 # define ICMP6_NI_QUERY 139
2255 #ifndef ICMP6_NI_REPLY
2256 # define ICMP6_NI_REPLY 140
2258 #ifndef MLD6_MTRACE_RESP
2259 # define MLD6_MTRACE_RESP 200
2262 # define MLD6_MTRACE 201
2264 #ifndef ICMP6_HADISCOV_REQUEST
2265 # define ICMP6_HADISCOV_REQUEST 202
2267 #ifndef ICMP6_HADISCOV_REPLY
2268 # define ICMP6_HADISCOV_REPLY 203
2270 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
2271 # define ICMP6_MOBILEPREFIX_SOLICIT 204
2273 #ifndef ICMP6_MOBILEPREFIX_ADVERT
2274 # define ICMP6_MOBILEPREFIX_ADVERT 205
2276 #ifndef ICMP6_MAXTYPE
2277 # define ICMP6_MAXTYPE 205
2280 #ifndef ICMP6_DST_UNREACH_NOROUTE
2281 # define ICMP6_DST_UNREACH_NOROUTE 0
2283 #ifndef ICMP6_DST_UNREACH_ADMIN
2284 # define ICMP6_DST_UNREACH_ADMIN 1
2286 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
2287 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
2289 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
2290 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
2292 #ifndef ICMP6_DST_UNREACH_ADDR
2293 # define ICMP6_DST_UNREACH_ADDR 3
2295 #ifndef ICMP6_DST_UNREACH_NOPORT
2296 # define ICMP6_DST_UNREACH_NOPORT 4
2298 #ifndef ICMP6_TIME_EXCEED_TRANSIT
2299 # define ICMP6_TIME_EXCEED_TRANSIT 0
2301 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
2302 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
2305 #ifndef ICMP6_NI_SUCCESS
2306 # define ICMP6_NI_SUCCESS 0
2308 #ifndef ICMP6_NI_REFUSED
2309 # define ICMP6_NI_REFUSED 1
2311 #ifndef ICMP6_NI_UNKNOWN
2312 # define ICMP6_NI_UNKNOWN 2
2315 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
2316 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
2318 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
2319 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
2321 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2322 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
2325 #ifndef ICMP6_PARAMPROB_HEADER
2326 # define ICMP6_PARAMPROB_HEADER 0
2328 #ifndef ICMP6_PARAMPROB_NEXTHEADER
2329 # define ICMP6_PARAMPROB_NEXTHEADER 1
2331 #ifndef ICMP6_PARAMPROB_OPTION
2332 # define ICMP6_PARAMPROB_OPTION 2
2335 #ifndef ICMP6_NI_SUBJ_IPV6
2336 # define ICMP6_NI_SUBJ_IPV6 0
2338 #ifndef ICMP6_NI_SUBJ_FQDN
2339 # define ICMP6_NI_SUBJ_FQDN 1
2341 #ifndef ICMP6_NI_SUBJ_IPV4
2342 # define ICMP6_NI_SUBJ_IPV4 2
2346 * ECN is a new addition to TCP - RFC 2481
2349 # define TH_ECN 0x40
2352 # define TH_CWR 0x80
2354 #define TH_ECNALL (TH_ECN|TH_CWR)
2359 #define IPF_TCPS_LISTEN 0 /* listening for connection */
2360 #define IPF_TCPS_SYN_SENT 1 /* active, have sent syn */
2361 #define IPF_TCPS_SYN_RECEIVED 2 /* have send and received syn */
2362 #define IPF_TCPS_HALF_ESTAB 3 /* for connections not fully "up" */
2363 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2364 #define IPF_TCPS_ESTABLISHED 4 /* established */
2365 #define IPF_TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
2366 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2367 #define IPF_TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
2368 #define IPF_TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
2369 #define IPF_TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
2370 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2371 #define IPF_TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
2372 #define IPF_TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
2373 #define IPF_TCPS_CLOSED 11 /* closed */
2374 #define IPF_TCP_NSTATES 12
2378 #undef ICMP_MAX_UNREACH
2379 #define ICMP_MAX_UNREACH 14
2381 #define ICMP_MAXTYPE 18
2388 # define LOG_FTP (11<<3)
2390 #ifndef LOG_AUTHPRIV
2391 # define LOG_AUTHPRIV (10<<3)
2394 # define LOG_AUDIT (13<<3)
2397 # define LOG_NTP (12<<3)
2399 #ifndef LOG_SECURITY
2400 # define LOG_SECURITY (13<<3)
2403 # define LOG_LFMT (14<<3)
2406 # define LOG_CONSOLE (14<<3)
2410 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2411 * another IP header and then 64 bits of data, totalling 56. Of course,
2412 * the last 64 bits is dependent on that being available.
2414 #define ICMPERR_ICMPHLEN 8
2415 #define ICMPERR_IPICMPHLEN (20 + 8)
2416 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
2417 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
2418 #define ICMP6ERR_MINPKTLEN (40 + 8)
2419 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
2422 # define MIN(a,b) (((a)<(b))?(a):(b))
2426 # define DPRINT(x) printf x
2432 # undef IPFILTER_BPF
2435 #endif /* __IP_COMPAT_H__ */