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.57 2007/10/10 09:51:42 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
173 # include "radix_ipf.h"
175 # include "radix_ipf_local.h"
177 # include <inet/ip.h>
179 # include <inet/ip_ire.h>
183 # if defined(SOLARIS2) && SOLARIS2 >= 8
184 # define SNPRINTF snprintf
186 # include <inet/ip_if.h>
187 # define ipif_local_addr ipif_lcl_addr
188 /* Only defined in private include file */
189 # ifndef V4_PART_OF_V6
190 # define V4_PART_OF_V6(v6) v6.s6_addr32[3]
196 # endif /* SOLARIS2 >= 8 */
198 # if defined(SOLARIS2) && SOLARIS2 >= 6
199 # include <sys/atomic.h>
200 typedef uint32_t u_32_t;
202 typedef unsigned int u_32_t;
207 # define NEED_LOCAL_RAND 1
208 # define ipf_random arc4random
209 # define KRWLOCK_T krwlock_t
210 # define KMUTEX_T kmutex_t
212 # if !defined(FW_HOOKS)
216 # include <sys/neti.h>
218 extern net_data_t ipfipv4;
219 extern net_data_t ipfipv6;
221 typedef struct qpktinfo {
230 # define QF_GROUP 0x01
235 # define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1)
236 # define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1)
238 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
239 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
240 # endif /* SOLARIS2 == 6 */
241 # define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1)
242 # define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1)
243 # define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1)
244 # define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1)
245 # define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1)
246 # define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1)
248 # define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \
249 mutex_exit(&ipf_rw); }
250 # define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \
251 mutex_exit(&ipf_rw); }
252 # endif /* SOLARIS2 >= 6 */
254 # define MUTEX_ENTER(x) mutex_enter(&(x)->ipf_lk)
255 # define READ_ENTER(x) rw_enter(&(x)->ipf_lk, RW_READER)
256 # define WRITE_ENTER(x) rw_enter(&(x)->ipf_lk, RW_WRITER)
257 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
258 # define RWLOCK_INIT(x, y) rw_init(&(x)->ipf_lk, (y), \
260 # define RWLOCK_EXIT(x) rw_exit(&(x)->ipf_lk)
261 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
262 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, (y), \
264 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk)
265 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
266 # define MUTEX_EXIT(x) mutex_exit(&(x)->ipf_lk)
267 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
268 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
269 # define BCOPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
270 # define BCOPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
271 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
272 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
273 # define KFREES(x,s) kmem_free((char *)(x), (s))
274 # define SPL_SCHED(x) ;
275 # define SPL_NET(x) ;
276 # define SPL_IMP(x) ;
280 # define ntohs(x) (x)
281 # define ntohl(x) (x)
282 # define htons(x) (x)
283 # define htonl(x) (x)
285 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
286 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
287 # define GET_MINOR(x) getminor(x)
288 extern void *get_unit __P((char *, int));
289 # define GETIFP(n, v) get_unit(n, v)
290 # if defined(_INET_IP_STACK_H)
291 # define COPYIFNAME(v, x, b) \
294 (void) net_getifname(ipfipv4,\
298 (void) net_getifname(ipfipv6,\
304 # define COPYIFNAME(v, x, b) \
305 (void) strncpy(b, ((qif_t *)x)->qf_name, \
308 # define GETKTIME(x) uniqtime((struct timeval *)x)
309 # define MSGDSIZE(x) msgdsize(x)
310 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr)
311 # define M_DUPLICATE(x) dupmsg((x))
312 # define MTOD(m,t) ((t)((m)->b_rptr))
313 # define MTYPE(m) ((m)->b_datap->db_type)
314 # define FREE_MB_T(m) freemsg(m)
315 # define m_next b_cont
316 # if !defined(_INET_IP_STACK_H)
317 # define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
319 # define CACHE_HASH(x) ((uintptr_t)(x)->fin_ifp & 7)
321 # define IPF_PANIC(x,y) if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
323 # endif /* _KERNEL */
325 # if defined(SOLARIS2) && (SOLARIS2 >= 7)
327 # define ALIGN32(ptr) (ptr ? 0L : 0L)
328 # define ALIGN16(ptr) (ptr ? 0L : 0L)
330 # define ALIGN32(ptr) (ptr)
331 # define ALIGN16(ptr) (ptr)
335 # if defined(SOLARIS2) && SOLARIS2 < 6
336 typedef struct uio uio_t;
338 typedef int ioctlcmd_t;
339 typedef uint8_t u_int8_t;
341 # define OS_RECOGNISED 1
345 /* ----------------------------------------------------------------------- */
347 /* ----------------------------------------------------------------------- */
350 # include <sys/sysmacros.h>
351 # include <sys/spinlock.h>
352 # include <sys/lock.h>
353 # include <sys/stream.h>
355 # include <netinet/if_ether.h>
356 # include <netinet/ip6.h>
357 # include <netinet/icmp6.h>
358 typedef struct ip6_hdr ip6_t;
362 # define SNPRINTF sprintf
363 # if (HPUXREV >= 1111)
366 # include <machine/sys/user.h>
367 # include <sys/kthread_iface.h>
368 # define READ_COLLISION 0x01
370 typedef struct iplog_select_s {
371 kthread_t *read_waiter;
377 # define GETKTIME(x) uniqtime((struct timeval *)x)
380 # include "kern_svcs.h"
382 # include <sys/kern_svcs.h>
387 # include <sys/reg.h>
388 # include "../netinet/ip_info.h"
390 * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
391 * are available. Attempting to use them actually results in unresolved
392 * symbols when it comes time to load the module.
393 * This has been fixed! Yipee!
397 # define ATOMIC_INCL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
398 # define ATOMIC_DECL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
400 # define ATOMIC_INCL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
401 # define ATOMIC_DECL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
403 # define ATOMIC_INC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
404 # define ATOMIC_INC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
405 # define ATOMIC_INC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
406 # define ATOMIC_DEC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
407 # define ATOMIC_DEC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
408 # define ATOMIC_DEC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
410 # define ATOMIC_INC64(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
411 MUTEX_EXIT(&ipf_rw); }
412 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
413 MUTEX_EXIT(&ipf_rw); }
414 # define ATOMIC_INC32(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
415 MUTEX_EXIT(&ipf_rw); }
416 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
417 MUTEX_EXIT(&ipf_rw); }
418 # define ATOMIC_INCL(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
419 MUTEX_EXIT(&ipf_rw); }
420 # define ATOMIC_DECL(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
421 MUTEX_EXIT(&ipf_rw); }
422 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
423 MUTEX_EXIT(&ipf_rw); }
424 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
425 MUTEX_EXIT(&ipf_rw); }
427 # define ip_cksum ip_csuma
428 # define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c)
430 # define MUTEX_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, (y))
431 # define MUTEX_ENTER(x) spinlock(&(x)->ipf_lk)
432 # define MUTEX_EXIT(x) spinunlock(&(x)->ipf_lk);
433 # define MUTEX_DESTROY(x)
434 # define MUTEX_NUKE(x) bzero((char *)(x), sizeof(*(x)))
435 # define KMUTEX_T lock_t
436 # define kmutex_t lock_t /* for pfil.h */
437 # define krwlock_t lock_t /* for pfil.h */
439 * The read-write lock implementation in HP-UX 11.0 is crippled - it can
440 * only be used by threads working in a user context!
441 * This has been fixed! Yipee! (Or at least it does in 11.00, not 11.11..)
444 # define MUTEX_DOWNGRADE(x) lock_write_to_read(x)
445 # define KRWLOCK_T struct rw_lock
446 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
447 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
449 # define RWLOCK_INIT(x, y) rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
451 # define RWLOCK_INIT(x, y) lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
453 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
455 # define KRWLOCK_T lock_t
456 # define KMUTEX_T lock_t
457 # define READ_ENTER(x) MUTEX_ENTER(x)
458 # define WRITE_ENTER(x) MUTEX_ENTER(x)
459 # define MUTEX_DOWNGRADE(x)
460 # define RWLOCK_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, y)
461 # define RWLOCK_EXIT(x) MUTEX_EXIT(x)
463 # define RW_DESTROY(x)
464 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
465 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
466 # define SPL_SCHED(x) ;
467 # define SPL_NET(x) ;
468 # define SPL_IMP(x) ;
471 extern void *get_unit __P((char *, int));
472 # define GETIFP(n, v) get_unit(n, v)
473 # define COPYIFNAME(v, x, b) \
474 (void) strncpy(b, ((qif_t *)x)->qf_name, \
476 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
477 # define SLEEP(id, n) { lock_t *_l = get_sleep_lock((caddr_t)id); \
478 sleep(id, PZERO+1); \
481 # define WAKEUP(id,x) { lock_t *_l = get_sleep_lock((caddr_t)id); \
485 # define POLLWAKEUP(x) ;
486 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
487 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
488 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
489 # define KFREES(x,s) kmem_free((char *)(x), (s))
490 # define MSGDSIZE(x) msgdsize(x)
491 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr)
492 # define M_DUPLICATE(x) dupmsg((x))
493 # define MTOD(m,t) ((t)((m)->b_rptr))
494 # define MTYPE(m) ((m)->b_datap->db_type)
495 # define FREE_MB_T(m) freemsg(m)
496 # define m_next b_cont
497 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
500 # define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
507 typedef unsigned char uchar_t;
509 # ifndef _SYS_STREAM_INCLUDED
510 typedef char * mblk_t;
511 typedef void * queue_t;
512 typedef u_long ulong;
514 # include <netinet/ip_info.h>
516 # endif /* _KERNEL */
519 # define ALIGN32(ptr) (ptr ? 0L : 0L)
520 # define ALIGN16(ptr) (ptr ? 0L : 0L)
522 # define ALIGN32(ptr) (ptr)
523 # define ALIGN16(ptr) (ptr)
526 typedef struct uio uio_t;
527 typedef int ioctlcmd_t;
529 typedef unsigned int u_32_t;
532 # define OS_RECOGNISED 1
536 /* ----------------------------------------------------------------------- */
538 /* ----------------------------------------------------------------------- */
542 typedef struct uio uio_t;
544 typedef int ioctlcmd_t;
545 typedef u_int32_t u_32_t;
553 # include <sys/ksynch.h>
554 # define IPF_LOCK_PL plhi
555 # include <sys/sema.h>
563 # define KMUTEX_T mutex_t
565 # define KMUTEX_T kmutex_t
566 # define KRWLOCK_T kmutex_t
570 # define NEED_LOCAL_RAND 1
571 # define ipf_random arc4random
572 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \
573 (x)++; MUTEX_EXIT(&ipf_rw); }
574 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \
575 (x)--; MUTEX_EXIT(&ipf_rw); }
578 # include <sys/atomic_ops.h>
579 # define ATOMIC_INCL(x) atomicAddUlong(&(x), 1)
580 # define ATOMIC_INC64(x) atomicAddUint64(&(x), 1)
581 # define ATOMIC_INC32(x) atomicAddUint(&(x), 1)
582 # define ATOMIC_INC16 ATOMIC_INC
583 # define ATOMIC_DECL(x) atomicAddUlong(&(x), -1)
584 # define ATOMIC_DEC64(x) atomicAddUint64(&(x), -1)
585 # define ATOMIC_DEC32(x) atomicAddUint(&(x), -1)
586 # define ATOMIC_DEC16 ATOMIC_DEC
588 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, \
591 # define MUTEX_ENTER(x) mutex_lock(&(x)->ipf_lk, 0)
593 # define MUTEX_EXIT(x) mutex_unlock(&(x)->ipf_lk)
594 # undef MUTEX_DESTROY
595 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk)
596 # define MUTEX_DOWNGRADE(x) mrdemote(&(x)->ipf_lk)
597 # define KRWLOCK_T mrlock_t
598 # define RWLOCK_INIT(x, y) mrinit(&(x)->ipf_lk, y)
600 # define RW_DESTROY(x) mrfree(&(x)->ipf_lk)
601 # define READ_ENTER(x) RW_RDLOCK(&(x)->ipf_lk)
602 # define WRITE_ENTER(x) RW_WRLOCK(&(x)->ipf_lk)
603 # define RWLOCK_EXIT(x) RW_UNLOCK(&(x)->ipf_lk)
605 # define READ_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
606 # define WRITE_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
607 # define MUTEX_DOWNGRADE(x) ;
608 # define RWLOCK_EXIT(x) MUTEX_EXIT(&(x)->ipf_lk)
609 # define MUTEX_EXIT(x) UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
610 # define MUTEX_INIT(x,y) (x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
611 # define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->ipf_lk.l)
612 # define MUTEX_ENTER(x) (x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
615 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
616 # define FREE_MB_T(m) m_freem(m)
617 # define MTOD(m,t) mtod(m,t)
618 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
619 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
620 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
621 # define SLEEP(id, n) sleep((id), PZERO+1)
622 # define WAKEUP(id,x) wakeup(id+x)
623 # define POLLWAKEUP(x) ;
624 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
625 # define KFREES(x,s) kmem_free((char *)(x), (s))
626 # define GETIFP(n,v) ifunit(n)
627 # include <sys/kmem.h>
628 # include <sys/ddi.h>
629 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
630 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
631 # define GET_MINOR(x) getminor(x)
633 # define SPL_IMP(x) (x) = splimp()
634 # define SPL_NET(x) (x) = splnet()
635 # define SPL_SCHED(x) (x) = splsched()
636 # define SPL_X(x) (void) splx(x)
637 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
638 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
639 # define MSGDSIZE(x) mbufchainlen(x)
640 # define M_LEN(x) (x)->m_len
641 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
642 # define GETKTIME(x) microtime((struct timeval *)x)
643 # define IFNAME(x) ((struct ifnet *)x)->if_name
644 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
645 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
646 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
647 typedef struct mbuf mb_t;
651 # undef MUTEX_DESTROY
652 # endif /* _KERNEL */
654 # define OS_RECOGNISED 1
658 /* ----------------------------------------------------------------------- */
660 /* ----------------------------------------------------------------------- */
664 # include <kern/lock.h>
665 # include <sys/sysmacros.h>
668 # define NEED_LOCAL_RAND 1
669 # define ipf_random arc4random
670 # define KMUTEX_T simple_lock_data_t
671 # define KRWLOCK_T lock_data_t
672 # include <net/net_globals.h>
674 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
675 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
676 # define MUTEX_DOWNGRADE(x) lock_write_to_read(&(x)->ipf_lk)
677 # define RWLOCK_INIT(x, y) lock_init(&(x)->ipf_lk, TRUE)
678 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
679 # define RW_DESTROY(x) lock_terminate(&(x)->ipf_lk)
680 # define MUTEX_ENTER(x) simple_lock(&(x)->ipf_lk)
681 # define MUTEX_INIT(x, y) simple_lock_init(&(x)->ipf_lk)
682 # define MUTEX_DESTROY(x) simple_lock_terminate(&(x)->ipf_lk)
683 # define MUTEX_EXIT(x) simple_unlock(&(x)->ipf_lk)
684 # define MUTEX_NUKE(x) bzero(x, sizeof(*(x)))
685 # define ATOMIC_INC64(x) atomic_incq((uint64_t*)&(x))
686 # define ATOMIC_DEC64(x) atomic_decq((uint64_t*)&(x))
687 # define ATOMIC_INC32(x) atomic_incl((uint32_t*)&(x))
688 # define ATOMIC_DEC32(x) atomic_decl((uint32_t*)&(x))
689 # define ATOMIC_INC16(x) { simple_lock(&ipf_rw); (x)++; \
690 simple_unlock(&ipf_rw); }
691 # define ATOMIC_DEC16(x) { simple_lock(&ipf_rw); (x)--; \
692 simple_unlock(&ipf_rw); }
693 # define ATOMIC_INCL(x) atomic_incl((uint32_t*)&(x))
694 # define ATOMIC_DECL(x) atomic_decl((uint32_t*)&(x))
695 # define ATOMIC_INC(x) { simple_lock(&ipf_rw); (x)++; \
696 simple_unlock(&ipf_rw); }
697 # define ATOMIC_DEC(x) { simple_lock(&ipf_rw); (x)--; \
698 simple_unlock(&ipf_rw); }
699 # define SPL_SCHED(x) ;
700 # define SPL_NET(x) ;
701 # define SPL_IMP(x) ;
704 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a, b, d)
705 # define FREE_MB_T(m) m_freem(m)
706 # define MTOD(m,t) mtod(m,t)
707 # define GETIFP(n, v) ifunit(n)
708 # define GET_MINOR getminor
709 # define WAKEUP(id,x) wakeup(id + x)
710 # define POLLWAKEUP(x) ;
711 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
712 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
713 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
714 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFILT, \
715 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
716 # define KFREE(x) FREE((x), M_PFILT)
717 # define KFREES(x,s) FREE((x), M_PFILT)
718 # define MSGDSIZE(x) mbufchainlen(x)
719 # define M_LEN(x) (x)->m_len
720 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
721 # define GETKTIME(x) microtime((struct timeval *)x)
722 # define IFNAME(x) ((struct ifnet *)x)->if_name
723 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
724 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
725 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
726 typedef struct mbuf mb_t;
727 # endif /* _KERNEL */
729 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
730 # define IP_V(x) ((x)->ip_vhl >> 4)
731 # define IP_HL(x) ((x)->ip_vhl & 0xf)
732 # define IP_V_A(x,y) (x)->ip_vhl |= (((y) << 4) & 0xf0)
733 # define IP_HL_A(x,y) (x)->ip_vhl |= ((y) & 0xf)
734 # define TCP_X2(x) ((x)->th_xoff & 0xf)
735 # define TCP_X2_A(x,y) (x)->th_xoff |= ((y) & 0xf)
736 # define TCP_OFF(x) ((x)->th_xoff >> 4)
737 # define TCP_OFF_A(x,y) (x)->th_xoff |= (((y) << 4) & 0xf0)
741 * These are from's Solaris' #defines for little endian.
743 #define IP6F_MORE_FRAG 0x0100
744 #define IP6F_RESERVED_MASK 0x0600
745 #define IP6F_OFF_MASK 0xf8ff
752 typedef int ioctlcmd_t;
754 * Really, any arch where sizeof(long) != sizeof(int).
756 typedef unsigned int u_32_t;
759 # define OS_RECOGNISED 1
762 /* ----------------------------------------------------------------------- */
764 /* ----------------------------------------------------------------------- */
766 # if (NetBSD >= 199905) && !defined(IPFILTER_LKM) && defined(_KERNEL)
767 # include "opt_ipfilter.h"
769 # if defined(_KERNEL)
770 # include <sys/systm.h>
774 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
775 # include "bpfilter.h"
776 # if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
777 # include "opt_inet.h"
782 # if (__NetBSD_Version__ >= 105000000)
783 # define HAVE_M_PULLDOWN 1
787 # if (__NetBSD_Version__ >= 499000000)
788 typedef char * caddr_t;
791 # define ipf_random arc4random
794 # if (__NetBSD_Version__ >= 399001400)
795 # define KMALLOCS(a, b, c) (a) = (b)malloc((c), _M_IPF, M_NOWAIT)
797 # define MSGDSIZE(x) mbufchainlen(x)
798 # define M_LEN(x) (x)->m_len
799 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
800 # define GETKTIME(x) microtime((struct timeval *)x)
801 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
802 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
803 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
804 typedef struct mbuf mb_t;
805 # endif /* _KERNEL */
806 # if (NetBSD <= 1991011) && (NetBSD >= 199606)
807 # define IFNAME(x) ((struct ifnet *)x)->if_xname
808 # define COPYIFNAME(v, x, b) \
810 ((struct ifnet *)x)->if_xname, \
812 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
814 # define IFNAME(x) ((struct ifnet *)x)->if_name
815 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
816 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
818 typedef struct uio uio_t;
819 typedef u_long ioctlcmd_t;
821 typedef u_int32_t u_32_t;
824 # define OS_RECOGNISED 1
825 #endif /* __NetBSD__ */
828 /* ----------------------------------------------------------------------- */
830 /* ----------------------------------------------------------------------- */
832 # if (__FreeBSD_version < 400000)
833 # define NEED_LOCAL_RAND 1
835 # define ipf_random arc4random
837 # if defined(_KERNEL)
838 # if (__FreeBSD_version >= 500000)
839 # include "opt_bpf.h"
843 # if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)
844 # include "opt_inet6.h"
846 # if defined(INET6) && !defined(USE_INET6)
851 # if defined(_KERNEL)
852 # if (__FreeBSD_version >= 400000)
854 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
855 * There may be other, safe, kernels but this is not extensively tested yet.
857 # define HAVE_M_PULLDOWN
859 # if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
860 # include "opt_ipfilter.h"
862 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
863 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
865 # if (__FreeBSD_version >= 500043)
868 # endif /* _KERNEL */
870 # if (__FreeBSD_version >= 500043)
871 # include <sys/mutex.h>
872 # if (__FreeBSD_version > 700014)
873 # include <sys/rwlock.h>
874 # define KRWLOCK_T struct rwlock
876 # define READ_ENTER(x) rw_rlock(&(x)->ipf_lk)
877 # define WRITE_ENTER(x) rw_wlock(&(x)->ipf_lk)
878 # define MUTEX_DOWNGRADE(x) rw_downgrade(&(x)->ipf_lk)
879 # define RWLOCK_INIT(x, y) rw_init(&(x)->ipf_lk, (y))
880 # define RW_DESTROY(x) rw_destroy(&(x)->ipf_lk)
881 # define RWLOCK_EXIT(x) do { \
882 if (rw_wowned(&(x)->ipf_lk)) \
883 rw_wunlock(&(x)->ipf_lk); \
885 rw_runlock(&(x)->ipf_lk); \
891 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
892 * for what we want to use them for, despite testing showing they work -
893 * with a WITNESS kernel, it generates LOR messages.
896 # if (__FreeBSD_version < 700000)
897 # define KRWLOCK_T struct mtx
898 # define READ_ENTER(x) mtx_lock(&(x)->ipf_lk)
899 # define WRITE_ENTER(x) mtx_lock(&(x)->ipf_lk)
900 # define RWLOCK_EXIT(x) mtx_unlock(&(x)->ipf_lk)
901 # define MUTEX_DOWNGRADE(x) ;
902 # define RWLOCK_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
904 # define RW_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
906 # define KRWLOCK_T struct sx
907 # define READ_ENTER(x) sx_slock(&(x)->ipf_lk)
908 # define WRITE_ENTER(x) sx_xlock(&(x)->ipf_lk)
909 # define MUTEX_DOWNGRADE(x) sx_downgrade(&(x)->ipf_lk)
910 # define RWLOCK_INIT(x, y) sx_init(&(x)->ipf_lk, (y))
911 # define RW_DESTROY(x) sx_destroy(&(x)->ipf_lk)
913 # define RWLOCK_EXIT(x) sx_unlock(&(x)->ipf_lk)
915 # define RWLOCK_EXIT(x) do { \
916 if ((x)->ipf_lk.sx_cnt < 0) \
917 sx_xunlock(&(x)->ipf_lk); \
919 sx_sunlock(&(x)->ipf_lk); \
925 # define KMUTEX_T struct mtx
928 # if (__FreeBSD_version >= 501113)
929 # include <net/if_var.h>
930 # define IFNAME(x) ((struct ifnet *)x)->if_xname
931 # define COPYIFNAME(v, x, b) \
933 ((struct ifnet *)x)->if_xname, \
936 # if (__FreeBSD_version >= 500043)
937 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index) & 7)
939 # define IFNAME(x) ((struct ifnet *)x)->if_name
940 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
941 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
945 # define GETKTIME(x) microtime((struct timeval *)x)
947 # if (__FreeBSD_version >= 500002)
948 # include <netinet/in_systm.h>
949 # include <netinet/ip.h>
950 # include <machine/in_cksum.h>
953 # if (__FreeBSD_version >= 500043)
955 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk)
956 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk)
957 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
959 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
960 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
961 # include <machine/atomic.h>
962 # define ATOMIC_INC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)++; \
963 mtx_unlock(&ipf_rw.ipf_lk); }
964 # define ATOMIC_DEC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)--; \
965 mtx_unlock(&ipf_rw.ipf_lk); }
966 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
967 # define ATOMIC_INC64(x) ATOMIC_INC(x)
968 # define ATOMIC_INC32(x) atomic_add_32((u_int *)&(x), 1)
969 # define ATOMIC_INC16(x) atomic_add_16(&(x), 1)
970 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
971 # define ATOMIC_DEC64(x) ATOMIC_DEC(x)
972 # define ATOMIC_DEC32(x) atomic_add_32((u_int *)&(x), -1)
973 # define ATOMIC_DEC16(x) atomic_add_16(&(x), -1)
975 # define SPL_NET(x) ;
976 # define SPL_IMP(x) ;
977 # define SPL_SCHED(x) ;
978 extern int in_cksum __P((struct mbuf *, int));
980 # define SPL_SCHED(x) x = splhigh()
981 # endif /* __FreeBSD_version >= 500043 */
982 # define MSGDSIZE(x) mbufchainlen(x)
983 # define M_LEN(x) (x)->m_len
984 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
985 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
986 typedef struct mbuf mb_t;
987 # endif /* _KERNEL */
990 # include <machine/spl.h>
992 # if __FreeBSD__ == 3
993 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
994 # define ACTUALLY_LKM_NOT_KERNEL
999 # if (__FreeBSD_version >= 300000)
1000 typedef u_long ioctlcmd_t;
1002 typedef int ioctlcmd_t;
1004 typedef struct uio uio_t;
1005 typedef int minor_t;
1006 typedef u_int32_t u_32_t;
1009 # define OS_RECOGNISED 1
1010 #endif /* __FreeBSD__ */
1013 /* ----------------------------------------------------------------------- */
1015 /* ----------------------------------------------------------------------- */
1022 # if !defined(IPFILTER_LKM)
1023 # include "bpfilter.h"
1025 # if (OpenBSD >= 200311)
1026 # define SNPRINTF snprintf
1027 # if defined(USE_INET6)
1028 # include "netinet6/in6_var.h"
1029 # include "netinet6/nd6.h"
1032 # if (OpenBSD >= 200012)
1033 # define HAVE_M_PULLDOWN 1
1035 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
1036 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
1037 # define GETKTIME(x) microtime((struct timeval *)x)
1038 # define MSGDSIZE(x) mbufchainlen(x)
1039 # define M_LEN(x) (x)->m_len
1040 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1041 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1042 typedef struct mbuf mb_t;
1043 # endif /* _KERNEL */
1044 # if (OpenBSD >= 199603)
1045 # define IFNAME(x, b) ((struct ifnet *)x)->if_xname
1046 # define COPYIFNAME(v, x, b) \
1048 ((struct ifnet *)x)->if_xname, \
1050 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
1052 # define IFNAME(x, b) ((struct ifnet *)x)->if_name
1053 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1054 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1057 typedef struct uio uio_t;
1058 typedef u_long ioctlcmd_t;
1059 typedef int minor_t;
1060 typedef u_int32_t u_32_t;
1063 # define OS_RECOGNISED 1
1064 #endif /* __OpenBSD__ */
1067 /* ----------------------------------------------------------------------- */
1069 /* ----------------------------------------------------------------------- */
1070 #ifdef _BSDI_VERSION
1076 # define GETKTIME(x) microtime((struct timeval *)x)
1077 # define MSGDSIZE(x) mbufchainlen(x)
1078 # define M_LEN(x) (x)->m_len
1079 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1080 # define IFNAME(x, b) ((struct ifnet *)x)->if_name
1081 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1082 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1083 typedef struct mbuf mb_t;
1084 # endif /* _KERNEL */
1086 # if (_BSDI_VERSION >= 199701)
1087 typedef u_long ioctlcmd_t;
1089 typedef int ioctlcmd_t;
1091 typedef u_int32_t u_32_t;
1094 #endif /* _BSDI_VERSION */
1097 /* ----------------------------------------------------------------------- */
1099 /* ----------------------------------------------------------------------- */
1100 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1102 # include <sys/kmem_alloc.h>
1103 # define GETKTIME(x) uniqtime((struct timeval *)x)
1104 # define MSGDSIZE(x) mbufchainlen(x)
1105 # define M_LEN(x) (x)->m_len
1106 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1107 # define IFNAME(x, b) ((struct ifnet *)x)->if_name
1108 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1109 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1110 # define GETIFP(n, v) ifunit(n, IFNAMSIZ)
1111 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
1112 # define KFREES(x,s) kmem_free((char *)(x), (s))
1113 # define SLEEP(id, n) sleep((id), PZERO+1)
1114 # define WAKEUP(id,x) wakeup(id + x)
1115 # define POLLWAKEUP(x) ;
1116 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1117 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1119 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
1120 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
1122 typedef struct mbuf mb_t;
1125 typedef struct uio uio_t;
1126 typedef int ioctlcmd_t;
1127 typedef int minor_t;
1128 typedef unsigned int u_32_t;
1131 # define OS_RECOGNISED 1
1133 #endif /* SunOS 4 */
1135 /* ----------------------------------------------------------------------- */
1137 /* ----------------------------------------------------------------------- */
1138 #if defined(linux) && !defined(OS_RECOGNISED)
1139 #include <linux/config.h>
1140 #include <linux/version.h>
1141 # if (LINUX >= 20600) && defined(_KERNEL)
1142 # define HDR_T_PRIVATE 1
1153 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1154 # define COPYIN(a,b,c) copy_from_user((caddr_t)(b), (caddr_t)(a), (c))
1155 # define COPYOUT(a,b,c) copy_to_user((caddr_t)(b), (caddr_t)(a), (c))
1156 # define FREE_MB_T(m) kfree_skb(m)
1157 # define GETKTIME(x) do_gettimeofday((struct timeval *)x)
1158 # define POLLWAKEUP(x) ;
1159 # ifdef wait_event_interruptible
1160 # define SLEEP(x,s) wait_event_interruptible((*(x##_linux)), 0)
1162 # define SLEEP(x,s) 0, interruptible_sleep_on(x##_linux)
1164 # define WAKEUP(x,y) wake_up(x##_linux + y)
1165 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1166 # define USE_MUTEXES
1167 # define KRWLOCK_T rwlock_t
1168 # define KMUTEX_T spinlock_t
1169 # define MUTEX_INIT(x,y) spin_lock_init(&(x)->ipf_lk)
1170 # define MUTEX_ENTER(x) spin_lock(&(x)->ipf_lk)
1171 # define MUTEX_EXIT(x) spin_unlock(&(x)->ipf_lk)
1172 # define MUTEX_DESTROY(x) do { } while (0)
1173 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1174 # define READ_ENTER(x) ipf_read_enter(x)
1175 # define WRITE_ENTER(x) ipf_write_enter(x)
1176 # define RWLOCK_INIT(x,y) ipf_rw_init(x, y)
1177 # define RW_DESTROY(x) do { } while (0)
1178 # define RWLOCK_EXIT(x) ipf_rw_exit(x)
1179 # define MUTEX_DOWNGRADE(x) ipf_rw_downgrade(x)
1180 # define ATOMIC_INCL(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1182 # define ATOMIC_DECL(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1184 # define ATOMIC_INC64(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1186 # define ATOMIC_INC32(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1188 # define ATOMIC_INC16(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1190 # define ATOMIC_DEC64(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1192 # define ATOMIC_DEC32(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1194 # define ATOMIC_DEC16(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1196 # define SPL_SCHED(x) do { } while (0)
1197 # define SPL_IMP(x) do { } while (0)
1198 # define SPL_NET(x) do { } while (0)
1199 # define SPL_X(x) do { } while (0)
1200 # define IFNAME(x) ((struct net_device*)x)->name
1201 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1202 ((struct net_device *)fin->fin_ifp)->ifindex) & 7)
1203 typedef struct sk_buff mb_t;
1204 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1205 extern void m_copyback __P((mb_t *, int, int, caddr_t));
1206 extern void m_adj __P((mb_t *, int));
1207 extern mb_t *m_pullup __P((mb_t *, int));
1208 # define mbuf sk_buff
1210 # define mtod(m, t) ((t)(m)->data)
1211 # define m_data data
1213 # define m_next next
1214 # define M_DUPLICATE(m) skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1216 # define MSGDSIZE(m) (m)->len
1217 # define M_LEN(m) (m)->len
1219 # define splnet(x) ;
1220 # define printf printk
1221 # define bcopy(s,d,z) memmove(d, s, z)
1222 # define bzero(s,z) memset(s, 0, z)
1223 # define bcmp(a,b,z) memcmp(a, b, z)
1225 # define ifnet net_device
1226 # define if_xname name
1227 # define if_unit ifindex
1229 # define KMALLOC(x,t) (x) = (t)kmalloc(sizeof(*(x)), \
1230 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1231 # define KFREE(x) kfree(x)
1232 # define KMALLOCS(x,t,s) (x) = (t)kmalloc((s), \
1233 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1234 # define KFREES(x,s) kfree(x)
1236 # define GETIFP(n,v) dev_get_by_name(n)
1239 # include <net/ethernet.h>
1244 # ifndef _NET_ROUTE_H
1250 char if_xname[IFNAMSIZ];
1252 int (* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1253 struct ifaddr *if_addrlist;
1255 # define IFNAME(x) ((struct ifnet *)x)->if_xname
1257 # endif /* _KERNEL */
1259 # define COPYIFNAME(v, x, b) \
1261 ((struct ifnet *)x)->if_xname, \
1264 # include <linux/fs.h>
1265 # define FWRITE FMODE_WRITE
1266 # define FREAD FMODE_READ
1268 # define __USE_MISC 1
1269 # define __FAVOR_BSD 1
1271 typedef struct uio {
1272 struct iovec *uio_iov;
1281 extern int uiomove __P((caddr_t, size_t, int, struct uio *));
1284 # define UIO_WRITE 2
1286 typedef u_long ioctlcmd_t;
1287 typedef int minor_t;
1288 typedef u_int32_t u_32_t;
1291 # define OS_RECOGNISED 1
1296 /* ----------------------------------------------------------------------- */
1298 /* ----------------------------------------------------------------------- */
1302 # include <sys/lock.h>
1303 # include <sys/sysmacros.h>
1306 # define rw_read_locked(x) 0
1307 # include <net/net_globals.h>
1308 # include <net/net_malloc.h>
1309 # define KMUTEX_T simple_lock_t
1310 # define KRWLOCK_T complex_lock_t
1311 # define USE_MUTEXES 1
1313 # define READ_ENTER(x) lock_read((x)->ipf_lk)
1314 # define WRITE_ENTER(x) lock_write((x)->ipf_lk)
1315 # define MUTEX_DOWNGRADE(x) lock_write_to_read((x)->ipf_lk)
1316 # define RWLOCK_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1319 lock_init((x)->ipf_lk, TRUE)
1320 # define RWLOCK_EXIT(x) lock_done((x)->ipf_lk)
1321 # define RW_DESTROY(x) lock_free(&(x)->ipf_lk)
1322 # define MUTEX_ENTER(x) simple_lock((x)->ipf_lk)
1323 # define MUTEX_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1326 simple_lock_init((x)->ipf_lk)
1327 # define MUTEX_DESTROY(x) lock_free(&(x)->ipf_lk)
1328 # define MUTEX_EXIT(x) simple_unlock((x)->ipf_lk)
1329 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1330 # define ATOMIC_INC64(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1331 MUTEX_EXIT(&ipf_rw); }
1332 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1333 MUTEX_EXIT(&ipf_rw); }
1334 # define ATOMIC_INC32(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1335 MUTEX_EXIT(&ipf_rw); }
1336 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1337 MUTEX_EXIT(&ipf_rw); }
1338 # define ATOMIC_INCL(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1339 MUTEX_EXIT(&ipf_rw); }
1340 # define ATOMIC_DECL(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1341 MUTEX_EXIT(&ipf_rw); }
1342 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1343 MUTEX_EXIT(&ipf_rw); }
1344 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1345 MUTEX_EXIT(&ipf_rw); }
1346 # define SPL_SCHED(x) x = splsched()
1347 # define SPL_NET(x) x = splnet()
1348 # define SPL_IMP(x) x = splimp()
1350 # define SPL_X(x) splx(x)
1351 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1352 extern void* getifp __P((char *, int));
1353 # define GETIFP(n, v) getifp(n, v)
1354 # define GET_MINOR minor
1355 # define SLEEP(id, n) sleepx((id), PZERO+1, 0)
1356 # define WAKEUP(id,x) wakeup(id)
1357 # define POLLWAKEUP(x) ;
1358 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
1359 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
1360 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1361 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, \
1362 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1363 # define KFREE(x) FREE((x), M_TEMP)
1364 # define KFREES(x,s) FREE((x), M_TEMP)
1365 # define MSGDSIZE(x) mbufchainlen(x)
1366 # define M_LEN(x) (x)->m_len
1367 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1368 # define GETKTIME(x)
1369 # define IFNAME(x, b) ((struct ifnet *)x)->if_name
1370 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1371 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1372 # define IPF_PANIC(x,y)
1373 typedef struct mbuf mb_t;
1374 # endif /* _KERNEL */
1377 * These are from's Solaris' #defines for little endian.
1379 #if !defined(IP6F_MORE_FRAG)
1380 # define IP6F_MORE_FRAG 0x0100
1382 #if !defined(IP6F_RESERVED_MASK)
1383 # define IP6F_RESERVED_MASK 0x0600
1385 #if !defined(IP6F_OFF_MASK)
1386 # define IP6F_OFF_MASK 0xf8ff
1394 typedef int ioctlcmd_t;
1395 typedef int minor_t;
1397 * Really, any arch where sizeof(long) != sizeof(int).
1399 typedef unsigned int u_32_t;
1402 # define OS_RECOGNISED 1
1406 #ifndef OS_RECOGNISED
1407 #error ip_compat.h does not recognise this platform/OS.
1411 /* ----------------------------------------------------------------------- */
1413 /* ----------------------------------------------------------------------- */
1414 #ifndef OS_RECOGNISED
1418 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1421 #if !defined(IPFILTER_BPF)
1422 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
1423 (defined(NBPFILTER) && (NBPFILTER > 0))
1424 # define IPFILTER_BPF
1429 * Userland locking primitives
1437 #if defined(__hpux) || defined(__linux)
1477 #define ipf_lk ipf_lkun_s.ipf_slk
1478 #define ipf_lname ipf_lkun_s.ipf_lname
1479 #define ipf_isr ipf_lkun_s.ipf_sr
1480 #define ipf_isw ipf_lkun_s.ipf_sw
1481 #define ipf_magic ipf_lkun_s.ipf_magic
1483 #if !defined(__GNUC__) || \
1484 (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1489 # define INLINE __inline__
1492 #if defined(linux) && defined(_KERNEL)
1493 extern void ipf_read_enter __P((ipfrwlock_t *));
1494 extern void ipf_write_enter __P((ipfrwlock_t *));
1495 extern void ipf_rw_exit __P((ipfrwlock_t *));
1496 extern void ipf_rw_init __P((ipfrwlock_t *, char *));
1497 extern void ipf_rw_downgrade __P((ipfrwlock_t *));
1501 * In a non-kernel environment, there are a lot of macros that need to be
1502 * filled in to be null-ops or to point to some compatibility function,
1503 * somewhere in userland.
1506 typedef struct mb_s {
1507 struct mb_s *mb_next;
1509 u_long mb_buf[2048];
1512 # define m_next mb_next
1513 # define MSGDSIZE(x) (x)->mb_len /* XXX - from ipt.c */
1514 # define M_LEN(x) (x)->mb_len
1515 # define M_DUPLICATE(x) (x)
1516 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL)
1518 # define MTOD(m, t) ((t)(m)->mb_buf)
1519 # define FREE_MB_T(x)
1520 # define SLEEP(x,y) 1;
1521 # define WAKEUP(x,y) ;
1522 # define POLLWAKEUP(y) ;
1523 # define IPF_PANIC(x,y) ;
1524 # define PANIC(x,y) ;
1525 # define SPL_SCHED(x) ;
1526 # define SPL_NET(x) ;
1527 # define SPL_IMP(x) ;
1529 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
1530 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
1531 # define KFREE(x) free(x)
1532 # define KFREES(x,s) free(x)
1533 # define GETIFP(x, v) get_unit(x,v)
1534 # define COPYIN(a,b,c) bcopywrap((a), (b), (c))
1535 # define COPYOUT(a,b,c) bcopywrap((a), (b), (c))
1536 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \
1538 # define COPYBACK(m, o, l, b) bcopy((b), \
1539 MTOD((mb_t *)m, char *) + (o), \
1541 # define UIOMOVE(a,b,c,d) ipfuiomove((caddr_t)a,b,c,d)
1542 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1543 extern int ipfuiomove __P((caddr_t, int, int, struct uio *));
1544 extern int bcopywrap __P((void *, void *, size_t));
1546 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1547 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1550 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu)
1551 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \
1553 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu)
1554 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y)
1555 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
1557 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \
1559 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \
1561 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y)
1562 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu)
1563 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu)
1564 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \
1568 # define USE_MUTEXES 1
1570 extern void eMmutex_destroy __P((eMmutex_t *));
1571 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1572 extern void eMmutex_exit __P((eMmutex_t *));
1573 extern void eMmutex_init __P((eMmutex_t *, char *));
1574 extern void eMrwlock_destroy __P((eMrwlock_t *));
1575 extern void eMrwlock_exit __P((eMrwlock_t *));
1576 extern void eMrwlock_init __P((eMrwlock_t *, char *));
1577 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1578 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1579 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1583 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1586 # define IP_OFFMASK 0x1fff
1591 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1596 # define U_QUAD_T unsigned long long
1597 # define QUAD_T long long
1598 #else /* BSD > 199306 */
1599 # define U_QUAD_T u_long
1600 # define QUAD_T long
1601 #endif /* BSD > 199306 */
1605 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1606 defined(__osf__) || defined(linux)
1607 # include <netinet/ip6.h>
1608 # include <netinet/icmp6.h>
1609 # if !defined(linux)
1610 # if defined(_KERNEL) && !defined(__osf__)
1611 # include <netinet6/ip6_var.h>
1614 typedef struct ip6_hdr ip6_t;
1619 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
1622 #if defined(_KERNEL)
1624 # define COPYDATA mb_copydata
1625 # define COPYBACK mb_copyback
1627 # define COPYDATA m_copydata
1628 # define COPYBACK m_copyback
1630 # if (BSD >= 199306) || defined(__FreeBSD__)
1631 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1632 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1633 defined(_BSDI_VERSION)
1636 # if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
1637 (__FreeBSD_version >= 300000))
1638 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
1639 (defined(OpenBSD) && (OpenBSD >= 200111))
1640 # include <uvm/uvm_extern.h>
1642 # include <vm/vm_extern.h>
1643 extern vm_map_t kmem_map;
1645 # include <sys/proc.h>
1646 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1647 # include <vm/vm_kern.h>
1648 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1650 # ifdef IPFILTER_M_IPFILTER
1651 # include <sys/malloc.h>
1652 MALLOC_DECLARE(M_IPFILTER);
1653 # define _M_IPF M_IPFILTER
1654 # else /* IPFILTER_M_IPFILTER */
1656 # define _M_IPF M_PFIL
1659 # define _M_IPF M_IPFILTER
1661 # define _M_IPF M_TEMP
1662 # endif /* M_IPFILTER */
1663 # endif /* M_PFIL */
1664 # endif /* IPFILTER_M_IPFILTER */
1665 # if defined(__FreeBSD__) && __FreeBSD_version >= 800051
1666 # define KMALLOC(a, b) do { \
1667 a = (b)malloc(sizeof(*(a)), _M_IPF, M_NOWAIT); \
1669 # define KMALLOCS(a, b, c) do { \
1670 a = (b)malloc((c), _M_IPF, ((c) > 4096) ? M_WAITOK : M_NOWAIT); \
1672 # define KFREE(x) free((x), _M_IPF)
1673 # define KFREES(x,s) free((x), _M_IPF)
1675 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1676 # if !defined(KMALLOCS)
1677 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1679 # define KFREE(x) FREE((x), _M_IPF)
1680 # define KFREES(x,s) FREE((x), _M_IPF)
1682 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,d)
1683 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
1684 # define WAKEUP(id,x) wakeup(id+x)
1685 # define POLLWAKEUP(x) selwakeup(ipfselwait+x)
1686 # define GETIFP(n, v) ifunit(n)
1687 # endif /* (Free)BSD */
1689 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
1690 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1691 (defined(OpenBSD) && (OpenBSD >= 200006))
1692 # define SPL_NET(x) x = splsoftnet()
1694 # define SPL_IMP(x) x = splimp()
1695 # define SPL_NET(x) x = splnet()
1696 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1697 # if !defined(SPL_SCHED)
1698 # define SPL_SCHED(x) x = splsched()
1700 # define SPL_X(x) (void) splx(x)
1701 # endif /* !USE_MUTEXES */
1704 # define FREE_MB_T(m) m_freem(m)
1708 # define MTOD(m,t) mtod(m,t)
1712 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1713 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1717 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
1719 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1723 # define GET_MINOR(x) dev2unit(x)
1725 # define PANIC(x,y) if (x) panic y
1726 #endif /* _KERNEL */
1728 #if !defined(IFNAME) && !defined(_KERNEL)
1729 # define IFNAME(x) ((struct ifnet *)x)->if_name
1732 # define NEED_FRGETIFNAME
1733 extern char *fr_getifname __P((struct ifnet *, char *));
1734 # define COPYIFNAME(v, x, b) \
1735 fr_getifname((struct ifnet *)x, b)
1742 # define ASSERT(x) do { if (!(x)) abort(); } while (0)
1747 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1748 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1752 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1753 * would mean all normal code that walks through strings needed casts. Yuck.
1755 #define ISALNUM(x) isalnum((u_char)(x))
1756 #define ISALPHA(x) isalpha((u_char)(x))
1757 #define ISASCII(x) isascii((u_char)(x))
1758 #define ISDIGIT(x) isdigit((u_char)(x))
1759 #define ISPRINT(x) isprint((u_char)(x))
1760 #define ISSPACE(x) isspace((u_char)(x))
1761 #define ISUPPER(x) isupper((u_char)(x))
1762 #define ISXDIGIT(x) isxdigit((u_char)(x))
1763 #define ISLOWER(x) islower((u_char)(x))
1764 #define TOUPPER(x) toupper((u_char)(x))
1765 #define TOLOWER(x) tolower((u_char)(x))
1768 * If mutexes aren't being used, turn all the mutex functions into null-ops.
1770 #if !defined(USE_MUTEXES)
1775 # undef MUTEX_DESTROY
1776 # define MUTEX_ENTER(x) ;
1777 # define READ_ENTER(x) ;
1778 # define WRITE_ENTER(x) ;
1779 # define MUTEX_DOWNGRADE(x) ;
1780 # define RWLOCK_INIT(x, y) ;
1781 # define RWLOCK_EXIT(x) ;
1782 # define RW_DESTROY(x) ;
1783 # define MUTEX_EXIT(x) ;
1784 # define MUTEX_INIT(x,y) ;
1785 # define MUTEX_DESTROY(x) ;
1786 # define MUTEX_NUKE(x) ;
1787 #endif /* !USE_MUTEXES */
1789 # define ATOMIC_INC(x) (x)++
1790 # define ATOMIC_DEC(x) (x)--
1793 #if defined(USE_SPL) && defined(_KERNEL)
1794 # define SPL_INT(x) int x
1800 * If there are no atomic operations for bit sizes defined, define them to all
1801 * use a generic one that works for all sizes.
1804 # define ATOMIC_INCL ATOMIC_INC
1805 # define ATOMIC_INC64 ATOMIC_INC
1806 # define ATOMIC_INC32 ATOMIC_INC
1807 # define ATOMIC_INC16 ATOMIC_INC
1808 # define ATOMIC_DECL ATOMIC_DEC
1809 # define ATOMIC_DEC64 ATOMIC_DEC
1810 # define ATOMIC_DEC32 ATOMIC_DEC
1811 # define ATOMIC_DEC16 ATOMIC_DEC
1814 #ifndef HDR_T_PRIVATE
1815 typedef struct tcphdr tcphdr_t;
1816 typedef struct udphdr udphdr_t;
1818 typedef struct icmp icmphdr_t;
1819 typedef struct ip ip_t;
1820 typedef struct ether_header ether_header_t;
1821 typedef struct tcpiphdr tcpiphdr_t;
1824 # define FR_GROUPLEN 16
1828 # define offsetof(t,m) (int)((&((t *)0L)->m))
1832 * This set of macros has been brought about because on Tru64 it is not
1833 * possible to easily assign or examine values in a structure that are
1837 # define IP_V(x) (x)->ip_v
1840 # define IP_V_A(x,y) (x)->ip_v = (y)
1843 # define IP_HL(x) (x)->ip_hl
1846 # define IP_HL_A(x,y) (x)->ip_hl = ((y) & 0xf)
1849 # define TCP_X2(x) (x)->th_x2
1852 # define TCP_X2_A(x,y) (x)->th_x2 = (y)
1855 # define TCP_OFF(x) (x)->th_off
1858 # define TCP_OFF_A(x,y) (x)->th_off = (y)
1860 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
1864 * XXX - This is one of those *awful* hacks which nobody likes
1872 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
1875 #if (BSD >= 199306) && !defined(m_act)
1876 # define m_act m_nextpkt
1880 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
1884 * 00000001 - (Reserved 4)
1885 * 00111101 - Top Secret
1887 * 10010110 - Confidential
1888 * 01100110 - (Reserved 3)
1889 * 11001100 - (Reserved 2)
1890 * 10101011 - Unclassified
1891 * 11110001 - (Reserved 1)
1893 #define IPSO_CLASS_RES4 0x01
1894 #define IPSO_CLASS_TOPS 0x3d
1895 #define IPSO_CLASS_SECR 0x5a
1896 #define IPSO_CLASS_CONF 0x96
1897 #define IPSO_CLASS_RES3 0x66
1898 #define IPSO_CLASS_RES2 0xcc
1899 #define IPSO_CLASS_UNCL 0xab
1900 #define IPSO_CLASS_RES1 0xf1
1902 #define IPSO_AUTH_GENSER 0x80
1903 #define IPSO_AUTH_ESI 0x40
1904 #define IPSO_AUTH_SCI 0x20
1905 #define IPSO_AUTH_NSA 0x10
1906 #define IPSO_AUTH_DOE 0x08
1907 #define IPSO_AUTH_UN 0x06
1908 #define IPSO_AUTH_FTE 0x01
1911 * IP option #defines
1916 #define IPOPT_ZSU 10 /* ZSU */
1918 #define IPOPT_MTUP 11 /* MTUP */
1920 #define IPOPT_MTUR 12 /* MTUR */
1922 #define IPOPT_ENCODE 15 /* ENCODE */
1926 #define IPOPT_TR 82 /* TR */
1927 #undef IPOPT_SECURITY
1928 #define IPOPT_SECURITY 130
1930 #define IPOPT_LSRR 131
1932 #define IPOPT_E_SEC 133 /* E-SEC */
1934 #define IPOPT_CIPSO 134 /* CIPSO */
1936 #define IPOPT_SATID 136
1938 # define IPOPT_SID IPOPT_SATID
1941 #define IPOPT_SSRR 137
1943 #define IPOPT_ADDEXT 147 /* ADDEXT */
1945 #define IPOPT_VISA 142 /* VISA */
1947 #define IPOPT_IMITD 144 /* IMITD */
1949 #define IPOPT_EIP 145 /* EIP */
1950 #undef IPOPT_RTRALRT
1951 #define IPOPT_RTRALRT 148 /* RTRALRT */
1953 #define IPOPT_SDB 149
1955 #define IPOPT_NSAPA 150
1957 #define IPOPT_DPS 151
1959 #define IPOPT_UMP 152
1961 #define IPOPT_FINN 205 /* FINN */
1964 # define TCPOPT_EOL 0
1967 # define TCPOPT_NOP 1
1969 #ifndef TCPOPT_MAXSEG
1970 # define TCPOPT_MAXSEG 2
1972 #ifndef TCPOLEN_MAXSEG
1973 # define TCPOLEN_MAXSEG 4
1975 #ifndef TCPOPT_WINDOW
1976 # define TCPOPT_WINDOW 3
1978 #ifndef TCPOLEN_WINDOW
1979 # define TCPOLEN_WINDOW 3
1981 #ifndef TCPOPT_SACK_PERMITTED
1982 # define TCPOPT_SACK_PERMITTED 4
1984 #ifndef TCPOLEN_SACK_PERMITTED
1985 # define TCPOLEN_SACK_PERMITTED 2
1988 # define TCPOPT_SACK 5
1990 #ifndef TCPOPT_TIMESTAMP
1991 # define TCPOPT_TIMESTAMP 8
1995 # define ICMP_MINLEN 8
1997 #ifndef ICMP_ECHOREPLY
1998 # define ICMP_ECHOREPLY 0
2000 #ifndef ICMP_UNREACH
2001 # define ICMP_UNREACH 3
2003 #ifndef ICMP_UNREACH_NET
2004 # define ICMP_UNREACH_NET 0
2006 #ifndef ICMP_UNREACH_HOST
2007 # define ICMP_UNREACH_HOST 1
2009 #ifndef ICMP_UNREACH_PROTOCOL
2010 # define ICMP_UNREACH_PROTOCOL 2
2012 #ifndef ICMP_UNREACH_PORT
2013 # define ICMP_UNREACH_PORT 3
2015 #ifndef ICMP_UNREACH_NEEDFRAG
2016 # define ICMP_UNREACH_NEEDFRAG 4
2018 #ifndef ICMP_UNREACH_SRCFAIL
2019 # define ICMP_UNREACH_SRCFAIL 5
2021 #ifndef ICMP_UNREACH_NET_UNKNOWN
2022 # define ICMP_UNREACH_NET_UNKNOWN 6
2024 #ifndef ICMP_UNREACH_HOST_UNKNOWN
2025 # define ICMP_UNREACH_HOST_UNKNOWN 7
2027 #ifndef ICMP_UNREACH_ISOLATED
2028 # define ICMP_UNREACH_ISOLATED 8
2030 #ifndef ICMP_UNREACH_NET_PROHIB
2031 # define ICMP_UNREACH_NET_PROHIB 9
2033 #ifndef ICMP_UNREACH_HOST_PROHIB
2034 # define ICMP_UNREACH_HOST_PROHIB 10
2036 #ifndef ICMP_UNREACH_TOSNET
2037 # define ICMP_UNREACH_TOSNET 11
2039 #ifndef ICMP_UNREACH_TOSHOST
2040 # define ICMP_UNREACH_TOSHOST 12
2042 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
2043 # define ICMP_UNREACH_ADMIN_PROHIBIT 13
2045 #ifndef ICMP_UNREACH_FILTER
2046 # define ICMP_UNREACH_FILTER 13
2048 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
2049 # define ICMP_UNREACH_HOST_PRECEDENCE 14
2051 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
2052 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
2054 #ifndef ICMP_SOURCEQUENCH
2055 # define ICMP_SOURCEQUENCH 4
2057 #ifndef ICMP_REDIRECT_NET
2058 # define ICMP_REDIRECT_NET 0
2060 #ifndef ICMP_REDIRECT_HOST
2061 # define ICMP_REDIRECT_HOST 1
2063 #ifndef ICMP_REDIRECT_TOSNET
2064 # define ICMP_REDIRECT_TOSNET 2
2066 #ifndef ICMP_REDIRECT_TOSHOST
2067 # define ICMP_REDIRECT_TOSHOST 3
2069 #ifndef ICMP_ALTHOSTADDR
2070 # define ICMP_ALTHOSTADDR 6
2072 #ifndef ICMP_TIMXCEED
2073 # define ICMP_TIMXCEED 11
2075 #ifndef ICMP_TIMXCEED_INTRANS
2076 # define ICMP_TIMXCEED_INTRANS 0
2078 #ifndef ICMP_TIMXCEED_REASS
2079 # define ICMP_TIMXCEED_REASS 1
2081 #ifndef ICMP_PARAMPROB
2082 # define ICMP_PARAMPROB 12
2084 #ifndef ICMP_PARAMPROB_ERRATPTR
2085 # define ICMP_PARAMPROB_ERRATPTR 0
2087 #ifndef ICMP_PARAMPROB_OPTABSENT
2088 # define ICMP_PARAMPROB_OPTABSENT 1
2090 #ifndef ICMP_PARAMPROB_LENGTH
2091 # define ICMP_PARAMPROB_LENGTH 2
2094 # define ICMP_TSTAMP 13
2096 #ifndef ICMP_TSTAMPREPLY
2097 # define ICMP_TSTAMPREPLY 14
2100 # define ICMP_IREQ 15
2102 #ifndef ICMP_IREQREPLY
2103 # define ICMP_IREQREPLY 16
2105 #ifndef ICMP_MASKREQ
2106 # define ICMP_MASKREQ 17
2108 #ifndef ICMP_MASKREPLY
2109 # define ICMP_MASKREPLY 18
2111 #ifndef ICMP_TRACEROUTE
2112 # define ICMP_TRACEROUTE 30
2114 #ifndef ICMP_DATACONVERR
2115 # define ICMP_DATACONVERR 31
2117 #ifndef ICMP_MOBILE_REDIRECT
2118 # define ICMP_MOBILE_REDIRECT 32
2120 #ifndef ICMP_IPV6_WHEREAREYOU
2121 # define ICMP_IPV6_WHEREAREYOU 33
2123 #ifndef ICMP_IPV6_IAMHERE
2124 # define ICMP_IPV6_IAMHERE 34
2126 #ifndef ICMP_MOBILE_REGREQUEST
2127 # define ICMP_MOBILE_REGREQUEST 35
2129 #ifndef ICMP_MOBILE_REGREPLY
2130 # define ICMP_MOBILE_REGREPLY 36
2133 # define ICMP_SKIP 39
2135 #ifndef ICMP_PHOTURIS
2136 # define ICMP_PHOTURIS 40
2138 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
2139 # define ICMP_PHOTURIS_UNKNOWN_INDEX 1
2141 #ifndef ICMP_PHOTURIS_AUTH_FAILED
2142 # define ICMP_PHOTURIS_AUTH_FAILED 2
2144 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
2145 # define ICMP_PHOTURIS_DECRYPT_FAILED 3
2148 # define IPVERSION 4
2150 #ifndef IPOPT_MINOFF
2151 # define IPOPT_MINOFF 4
2153 #ifndef IPOPT_COPIED
2154 # define IPOPT_COPIED(x) ((x)&0x80)
2157 # define IPOPT_EOL 0
2160 # define IPOPT_NOP 1
2163 # define IP_MF ((u_short)0x2000)
2165 #ifndef ETHERTYPE_IP
2166 # define ETHERTYPE_IP ((u_short)0x0800)
2169 # define TH_FIN 0x01
2172 # define TH_SYN 0x02
2175 # define TH_RST 0x04
2178 # define TH_PUSH 0x08
2181 # define TH_ACK 0x10
2184 # define TH_URG 0x20
2187 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK)
2190 # define IPOPT_EOL 0
2193 # define IPOPT_NOP 1
2199 # define IPOPT_TS 68
2201 #ifndef IPOPT_SECURITY
2202 # define IPOPT_SECURITY 130
2205 # define IPOPT_LSRR 131
2208 # define IPOPT_SATID 136
2211 # define IPOPT_SSRR 137
2213 #ifndef IPOPT_SECUR_UNCLASS
2214 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
2216 #ifndef IPOPT_SECUR_CONFID
2217 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
2219 #ifndef IPOPT_SECUR_EFTO
2220 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
2222 #ifndef IPOPT_SECUR_MMMM
2223 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
2225 #ifndef IPOPT_SECUR_RESTR
2226 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
2228 #ifndef IPOPT_SECUR_SECRET
2229 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
2231 #ifndef IPOPT_SECUR_TOPSECRET
2232 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
2235 # define IPOPT_OLEN 1
2237 #ifndef IPPROTO_HOPOPTS
2238 # define IPPROTO_HOPOPTS 0
2240 #ifndef IPPROTO_ENCAP
2241 # define IPPROTO_ENCAP 4
2243 #ifndef IPPROTO_IPV6
2244 # define IPPROTO_IPV6 41
2246 #ifndef IPPROTO_ROUTING
2247 # define IPPROTO_ROUTING 43
2249 #ifndef IPPROTO_FRAGMENT
2250 # define IPPROTO_FRAGMENT 44
2253 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
2256 # define IPPROTO_ESP 50
2259 # define IPPROTO_AH 51
2261 #ifndef IPPROTO_ICMPV6
2262 # define IPPROTO_ICMPV6 58
2264 #ifndef IPPROTO_NONE
2265 # define IPPROTO_NONE 59
2267 #ifndef IPPROTO_DSTOPTS
2268 # define IPPROTO_DSTOPTS 60
2270 #ifndef IPPROTO_MOBILITY
2271 # define IPPROTO_MOBILITY 135
2274 #ifndef ICMP_ROUTERADVERT
2275 # define ICMP_ROUTERADVERT 9
2277 #ifndef ICMP_ROUTERSOLICIT
2278 # define ICMP_ROUTERSOLICIT 10
2280 #ifndef ICMP6_DST_UNREACH
2281 # define ICMP6_DST_UNREACH 1
2283 #ifndef ICMP6_PACKET_TOO_BIG
2284 # define ICMP6_PACKET_TOO_BIG 2
2286 #ifndef ICMP6_TIME_EXCEEDED
2287 # define ICMP6_TIME_EXCEEDED 3
2289 #ifndef ICMP6_PARAM_PROB
2290 # define ICMP6_PARAM_PROB 4
2293 #ifndef ICMP6_ECHO_REQUEST
2294 # define ICMP6_ECHO_REQUEST 128
2296 #ifndef ICMP6_ECHO_REPLY
2297 # define ICMP6_ECHO_REPLY 129
2299 #ifndef ICMP6_MEMBERSHIP_QUERY
2300 # define ICMP6_MEMBERSHIP_QUERY 130
2302 #ifndef MLD6_LISTENER_QUERY
2303 # define MLD6_LISTENER_QUERY 130
2305 #ifndef ICMP6_MEMBERSHIP_REPORT
2306 # define ICMP6_MEMBERSHIP_REPORT 131
2308 #ifndef MLD6_LISTENER_REPORT
2309 # define MLD6_LISTENER_REPORT 131
2311 #ifndef ICMP6_MEMBERSHIP_REDUCTION
2312 # define ICMP6_MEMBERSHIP_REDUCTION 132
2314 #ifndef MLD6_LISTENER_DONE
2315 # define MLD6_LISTENER_DONE 132
2317 #ifndef ND_ROUTER_SOLICIT
2318 # define ND_ROUTER_SOLICIT 133
2320 #ifndef ND_ROUTER_ADVERT
2321 # define ND_ROUTER_ADVERT 134
2323 #ifndef ND_NEIGHBOR_SOLICIT
2324 # define ND_NEIGHBOR_SOLICIT 135
2326 #ifndef ND_NEIGHBOR_ADVERT
2327 # define ND_NEIGHBOR_ADVERT 136
2330 # define ND_REDIRECT 137
2332 #ifndef ICMP6_ROUTER_RENUMBERING
2333 # define ICMP6_ROUTER_RENUMBERING 138
2335 #ifndef ICMP6_WRUREQUEST
2336 # define ICMP6_WRUREQUEST 139
2338 #ifndef ICMP6_WRUREPLY
2339 # define ICMP6_WRUREPLY 140
2341 #ifndef ICMP6_FQDN_QUERY
2342 # define ICMP6_FQDN_QUERY 139
2344 #ifndef ICMP6_FQDN_REPLY
2345 # define ICMP6_FQDN_REPLY 140
2347 #ifndef ICMP6_NI_QUERY
2348 # define ICMP6_NI_QUERY 139
2350 #ifndef ICMP6_NI_REPLY
2351 # define ICMP6_NI_REPLY 140
2353 #ifndef MLD6_MTRACE_RESP
2354 # define MLD6_MTRACE_RESP 200
2357 # define MLD6_MTRACE 201
2359 #ifndef ICMP6_HADISCOV_REQUEST
2360 # define ICMP6_HADISCOV_REQUEST 202
2362 #ifndef ICMP6_HADISCOV_REPLY
2363 # define ICMP6_HADISCOV_REPLY 203
2365 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
2366 # define ICMP6_MOBILEPREFIX_SOLICIT 204
2368 #ifndef ICMP6_MOBILEPREFIX_ADVERT
2369 # define ICMP6_MOBILEPREFIX_ADVERT 205
2371 #ifndef ICMP6_MAXTYPE
2372 # define ICMP6_MAXTYPE 205
2375 #ifndef ICMP6_DST_UNREACH_NOROUTE
2376 # define ICMP6_DST_UNREACH_NOROUTE 0
2378 #ifndef ICMP6_DST_UNREACH_ADMIN
2379 # define ICMP6_DST_UNREACH_ADMIN 1
2381 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
2382 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
2384 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
2385 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
2387 #ifndef ICMP6_DST_UNREACH_ADDR
2388 # define ICMP6_DST_UNREACH_ADDR 3
2390 #ifndef ICMP6_DST_UNREACH_NOPORT
2391 # define ICMP6_DST_UNREACH_NOPORT 4
2393 #ifndef ICMP6_TIME_EXCEED_TRANSIT
2394 # define ICMP6_TIME_EXCEED_TRANSIT 0
2396 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
2397 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
2400 #ifndef ICMP6_NI_SUCCESS
2401 # define ICMP6_NI_SUCCESS 0
2403 #ifndef ICMP6_NI_REFUSED
2404 # define ICMP6_NI_REFUSED 1
2406 #ifndef ICMP6_NI_UNKNOWN
2407 # define ICMP6_NI_UNKNOWN 2
2410 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
2411 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
2413 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
2414 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
2416 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2417 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
2420 #ifndef ICMP6_PARAMPROB_HEADER
2421 # define ICMP6_PARAMPROB_HEADER 0
2423 #ifndef ICMP6_PARAMPROB_NEXTHEADER
2424 # define ICMP6_PARAMPROB_NEXTHEADER 1
2426 #ifndef ICMP6_PARAMPROB_OPTION
2427 # define ICMP6_PARAMPROB_OPTION 2
2430 #ifndef ICMP6_NI_SUBJ_IPV6
2431 # define ICMP6_NI_SUBJ_IPV6 0
2433 #ifndef ICMP6_NI_SUBJ_FQDN
2434 # define ICMP6_NI_SUBJ_FQDN 1
2436 #ifndef ICMP6_NI_SUBJ_IPV4
2437 # define ICMP6_NI_SUBJ_IPV4 2
2441 * ECN is a new addition to TCP - RFC 2481
2444 # define TH_ECN 0x40
2447 # define TH_CWR 0x80
2449 #define TH_ECNALL (TH_ECN|TH_CWR)
2454 #define IPF_TCPS_LISTEN 0 /* listening for connection */
2455 #define IPF_TCPS_SYN_SENT 1 /* active, have sent syn */
2456 #define IPF_TCPS_SYN_RECEIVED 2 /* have send and received syn */
2457 #define IPF_TCPS_HALF_ESTAB 3 /* for connections not fully "up" */
2458 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2459 #define IPF_TCPS_ESTABLISHED 4 /* established */
2460 #define IPF_TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
2461 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2462 #define IPF_TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
2463 #define IPF_TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
2464 #define IPF_TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
2465 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2466 #define IPF_TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
2467 #define IPF_TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
2468 #define IPF_TCPS_CLOSED 11 /* closed */
2469 #define IPF_TCP_NSTATES 12
2473 #undef ICMP_MAX_UNREACH
2474 #define ICMP_MAX_UNREACH 14
2476 #define ICMP_MAXTYPE 18
2483 # define LOG_FTP (11<<3)
2485 #ifndef LOG_AUTHPRIV
2486 # define LOG_AUTHPRIV (10<<3)
2489 # define LOG_AUDIT (13<<3)
2492 # define LOG_NTP (12<<3)
2494 #ifndef LOG_SECURITY
2495 # define LOG_SECURITY (13<<3)
2498 # define LOG_LFMT (14<<3)
2501 # define LOG_CONSOLE (14<<3)
2505 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2506 * another IP header and then 64 bits of data, totalling 56. Of course,
2507 * the last 64 bits is dependent on that being available.
2509 #define ICMPERR_ICMPHLEN 8
2510 #define ICMPERR_IPICMPHLEN (20 + 8)
2511 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
2512 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
2513 #define ICMP6ERR_MINPKTLEN (40 + 8)
2514 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
2517 # define MIN(a,b) (((a)<(b))?(a):(b))
2521 # define DPRINT(x) printf x
2527 # undef IPFILTER_BPF
2530 #endif /* __IP_COMPAT_H__ */