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) (void) copyin((caddr_t)(a), (caddr_t)(b), (c))
243 # define BCOPYOUT(a,b,c) (void) copyout((caddr_t)(a), (caddr_t)(b), (c))
244 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
245 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
246 # define KFREES(x,s) kmem_free((char *)(x), (s))
247 # define SPL_NET(x) ;
248 # define SPL_IMP(x) ;
252 # define ntohs(x) (x)
253 # define ntohl(x) (x)
254 # define htons(x) (x)
255 # define htonl(x) (x)
257 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
258 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
259 # define GET_MINOR(x) getminor(x)
260 extern void *get_unit __P((char *, int));
261 # define GETIFP(n, v) get_unit(n, v)
262 # define IFNAME(x) ((qif_t *)x)->qf_name
263 # define COPYIFNAME(x, b) \
264 (void) strncpy(b, ((qif_t *)x)->qf_name, \
266 # define GETKTIME(x) uniqtime((struct timeval *)x)
267 # define MSGDSIZE(x) msgdsize(x)
268 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr)
269 # define M_DUPLICATE(x) dupmsg((x))
270 # define MTOD(m,t) ((t)((m)->b_rptr))
271 # define MTYPE(m) ((m)->b_datap->db_type)
272 # define FREE_MB_T(m) freemsg(m)
273 # define m_next b_cont
274 # define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
275 # define IPF_PANIC(x,y) if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
277 # endif /* _KERNEL */
279 # if defined(SOLARIS2) && (SOLARIS2 >= 7)
281 # define ALIGN32(ptr) (ptr ? 0L : 0L)
282 # define ALIGN16(ptr) (ptr ? 0L : 0L)
284 # define ALIGN32(ptr) (ptr)
285 # define ALIGN16(ptr) (ptr)
289 # if defined(SOLARIS2) && SOLARIS2 < 6
290 typedef struct uio uio_t;
292 typedef int ioctlcmd_t;
294 # define OS_RECOGNISED 1
298 /* ----------------------------------------------------------------------- */
300 /* ----------------------------------------------------------------------- */
303 # include <sys/sysmacros.h>
304 # include <sys/spinlock.h>
305 # include <sys/lock.h>
306 # include <sys/stream.h>
308 # include <netinet/if_ether.h>
309 # include <netinet/ip6.h>
310 # include <netinet/icmp6.h>
311 typedef struct ip6_hdr ip6_t;
315 # define SNPRINTF sprintf
316 # if (HPUXREV >= 1111)
319 # include <machine/sys/user.h>
320 # include <sys/kthread_iface.h>
321 # define READ_COLLISION 0x01
323 typedef struct iplog_select_s {
324 kthread_t *read_waiter;
330 # define GETKTIME(x) uniqtime((struct timeval *)x)
333 # include "kern_svcs.h"
335 # include <sys/kern_svcs.h>
340 # include <sys/reg.h>
341 # include "../netinet/ip_info.h"
343 * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
344 * are available. Attempting to use them actually results in unresolved
345 * symbols when it comes time to load the module.
346 * This has been fixed! Yipee!
350 # define ATOMIC_INCL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
351 # define ATOMIC_DECL(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
353 # define ATOMIC_INCL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
354 # define ATOMIC_DECL(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
356 # define ATOMIC_INC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
357 # define ATOMIC_INC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
358 # define ATOMIC_INC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
359 # define ATOMIC_DEC64(x) lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
360 # define ATOMIC_DEC32(x) lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
361 # define ATOMIC_DEC16(x) lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
363 # define ATOMIC_INC64(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
364 MUTEX_EXIT(&ipf_rw); }
365 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
366 MUTEX_EXIT(&ipf_rw); }
367 # define ATOMIC_INC32(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
368 MUTEX_EXIT(&ipf_rw); }
369 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
370 MUTEX_EXIT(&ipf_rw); }
371 # define ATOMIC_INCL(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
372 MUTEX_EXIT(&ipf_rw); }
373 # define ATOMIC_DECL(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
374 MUTEX_EXIT(&ipf_rw); }
375 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
376 MUTEX_EXIT(&ipf_rw); }
377 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
378 MUTEX_EXIT(&ipf_rw); }
380 # define ip_cksum ip_csuma
381 # define memcpy(a,b,c) bcopy((caddr_t)b, (caddr_t)a, c)
383 # define MUTEX_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, (y))
384 # define MUTEX_ENTER(x) spinlock(&(x)->ipf_lk)
385 # define MUTEX_EXIT(x) spinunlock(&(x)->ipf_lk);
386 # define MUTEX_DESTROY(x)
387 # define MUTEX_NUKE(x) bzero((char *)(x), sizeof(*(x)))
388 # define KMUTEX_T lock_t
389 # define kmutex_t lock_t /* for pfil.h */
390 # define krwlock_t lock_t /* for pfil.h */
392 * The read-write lock implementation in HP-UX 11.0 is crippled - it can
393 * only be used by threads working in a user context!
394 * This has been fixed! Yipee! (Or at least it does in 11.00, not 11.11..)
397 # define MUTEX_DOWNGRADE(x) lock_write_to_read(x)
398 # define KRWLOCK_T struct rw_lock
399 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
400 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
402 # define RWLOCK_INIT(x, y) rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
404 # define RWLOCK_INIT(x, y) lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
406 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
408 # define KRWLOCK_T lock_t
409 # define KMUTEX_T lock_t
410 # define READ_ENTER(x) MUTEX_ENTER(x)
411 # define WRITE_ENTER(x) MUTEX_ENTER(x)
412 # define MUTEX_DOWNGRADE(x)
413 # define RWLOCK_INIT(x, y) initlock(&(x)->ipf_lk, 0, 0, y)
414 # define RWLOCK_EXIT(x) MUTEX_EXIT(x)
416 # define RW_DESTROY(x)
417 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
418 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
420 # define BCOPYIN(a,b,c) 0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
421 # define BCOPYOUT(a,b,c) 0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
423 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
424 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
426 # define SPL_NET(x) ;
427 # define SPL_IMP(x) ;
430 extern void *get_unit __P((char *, int));
431 # define GETIFP(n, v) get_unit(n, v)
432 # define IFNAME(x, b) ((ill_t *)x)->ill_name
433 # define COPYIFNAME(x, b) \
434 (void) strncpy(b, ((qif_t *)x)->qf_name, \
436 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
437 # define SLEEP(id, n) { lock_t *_l = get_sleep_lock((caddr_t)id); \
438 sleep(id, PZERO+1); \
441 # define WAKEUP(id,x) { lock_t *_l = get_sleep_lock((caddr_t)id); \
445 # define POLLWAKEUP(x) ;
446 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
447 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
448 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
449 # define KFREES(x,s) kmem_free((char *)(x), (s))
450 # define MSGDSIZE(x) msgdsize(x)
451 # define M_LEN(x) ((x)->b_wptr - (x)->b_rptr)
452 # define M_DUPLICATE(x) dupmsg((x))
453 # define MTOD(m,t) ((t)((m)->b_rptr))
454 # define MTYPE(m) ((m)->b_datap->db_type)
455 # define FREE_MB_T(m) freemsg(m)
456 # define m_next b_cont
457 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
460 # define CACHE_HASH(x) (((qpktinfo_t *)(x)->fin_qpi)->qpi_num & 7)
467 typedef unsigned char uchar_t;
469 # ifndef _SYS_STREAM_INCLUDED
470 typedef char * mblk_t;
471 typedef void * queue_t;
472 typedef u_long ulong;
474 # include <netinet/ip_info.h>
476 # endif /* _KERNEL */
479 # define ALIGN32(ptr) (ptr ? 0L : 0L)
480 # define ALIGN16(ptr) (ptr ? 0L : 0L)
482 # define ALIGN32(ptr) (ptr)
483 # define ALIGN16(ptr) (ptr)
486 typedef struct uio uio_t;
487 typedef int ioctlcmd_t;
489 typedef unsigned int u_32_t;
492 # define OS_RECOGNISED 1
496 /* ----------------------------------------------------------------------- */
498 /* ----------------------------------------------------------------------- */
502 typedef struct uio uio_t;
504 typedef int ioctlcmd_t;
505 typedef u_int32_t u_32_t;
513 # include <sys/ksynch.h>
514 # define IPF_LOCK_PL plhi
515 # include <sys/sema.h>
523 # define KMUTEX_T mutex_t
525 # define KMUTEX_T kmutex_t
526 # define KRWLOCK_T kmutex_t
530 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \
531 (x)++; MUTEX_EXIT(&ipf_rw); }
532 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \
533 (x)--; MUTEX_EXIT(&ipf_rw); }
536 # include <sys/atomic_ops.h>
537 # define ATOMIC_INCL(x) atomicAddUlong(&(x), 1)
538 # define ATOMIC_INC64(x) atomicAddUint64(&(x), 1)
539 # define ATOMIC_INC32(x) atomicAddUint(&(x), 1)
540 # define ATOMIC_INC16 ATOMIC_INC
541 # define ATOMIC_DECL(x) atomicAddUlong(&(x), -1)
542 # define ATOMIC_DEC64(x) atomicAddUint64(&(x), -1)
543 # define ATOMIC_DEC32(x) atomicAddUint(&(x), -1)
544 # define ATOMIC_DEC16 ATOMIC_DEC
546 # define MUTEX_INIT(x, y) mutex_init(&(x)->ipf_lk, \
549 # define MUTEX_ENTER(x) mutex_lock(&(x)->ipf_lk, 0)
551 # define MUTEX_EXIT(x) mutex_unlock(&(x)->ipf_lk)
552 # undef MUTEX_DESTROY
553 # define MUTEX_DESTROY(x) mutex_destroy(&(x)->ipf_lk)
554 # define MUTEX_DOWNGRADE(x) mrdemote(&(x)->ipf_lk)
555 # define KRWLOCK_T mrlock_t
556 # define RWLOCK_INIT(x, y) mrinit(&(x)->ipf_lk, y)
558 # define RW_DESTROY(x) mrfree(&(x)->ipf_lk)
559 # define READ_ENTER(x) RW_RDLOCK(&(x)->ipf_lk)
560 # define WRITE_ENTER(x) RW_WRLOCK(&(x)->ipf_lk)
561 # define RWLOCK_EXIT(x) RW_UNLOCK(&(x)->ipf_lk)
563 # define READ_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
564 # define WRITE_ENTER(x) MUTEX_ENTER(&(x)->ipf_lk)
565 # define MUTEX_DOWNGRADE(x) ;
566 # define RWLOCK_EXIT(x) MUTEX_EXIT(&(x)->ipf_lk)
567 # define MUTEX_EXIT(x) UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
568 # define MUTEX_INIT(x,y) (x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
569 # define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->ipf_lk.l)
570 # define MUTEX_ENTER(x) (x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
573 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
574 # define FREE_MB_T(m) m_freem(m)
575 # define MTOD(m,t) mtod(m,t)
576 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
577 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
578 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
579 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
580 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
581 # define SLEEP(id, n) sleep((id), PZERO+1)
582 # define WAKEUP(id,x) wakeup(id+x)
583 # define POLLWAKEUP(x) ;
584 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
585 # define KFREES(x,s) kmem_free((char *)(x), (s))
586 # define GETIFP(n,v) ifunit(n)
587 # include <sys/kmem.h>
588 # include <sys/ddi.h>
589 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
590 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
591 # define GET_MINOR(x) getminor(x)
593 # define SPL_IMP(x) (x) = splimp()
594 # define SPL_NET(x) (x) = splnet()
595 # define SPL_X(x) (void) splx(x)
596 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
597 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
598 # define MSGDSIZE(x) mbufchainlen(x)
599 # define M_LEN(x) (x)->m_len
600 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
601 # define GETKTIME(x) microtime((struct timeval *)x)
602 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
603 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
604 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
605 typedef struct mbuf mb_t;
609 # undef MUTEX_DESTROY
610 # endif /* _KERNEL */
612 # define OS_RECOGNISED 1
616 /* ----------------------------------------------------------------------- */
618 /* ----------------------------------------------------------------------- */
622 # include <kern/lock.h>
623 # include <sys/sysmacros.h>
626 # define KMUTEX_T simple_lock_data_t
627 # define KRWLOCK_T lock_data_t
628 # include <net/net_globals.h>
630 # define READ_ENTER(x) lock_read(&(x)->ipf_lk)
631 # define WRITE_ENTER(x) lock_write(&(x)->ipf_lk)
632 # define MUTEX_DOWNGRADE(x) lock_write_to_read(&(x)->ipf_lk)
633 # define RWLOCK_INIT(x, y) lock_init(&(x)->ipf_lk, TRUE)
634 # define RWLOCK_EXIT(x) lock_done(&(x)->ipf_lk)
635 # define RW_DESTROY(x) lock_terminate(&(x)->ipf_lk)
636 # define MUTEX_ENTER(x) simple_lock(&(x)->ipf_lk)
637 # define MUTEX_INIT(x, y) simple_lock_init(&(x)->ipf_lk)
638 # define MUTEX_DESTROY(x) simple_lock_terminate(&(x)->ipf_lk)
639 # define MUTEX_EXIT(x) simple_unlock(&(x)->ipf_lk)
640 # define MUTEX_NUKE(x) bzero(x, sizeof(*(x)))
641 # define ATOMIC_INC64(x) atomic_incq((uint64_t*)&(x))
642 # define ATOMIC_DEC64(x) atomic_decq((uint64_t*)&(x))
643 # define ATOMIC_INC32(x) atomic_incl((uint32_t*)&(x))
644 # define ATOMIC_DEC32(x) atomic_decl((uint32_t*)&(x))
645 # define ATOMIC_INC16(x) { simple_lock(&ipf_rw); (x)++; \
646 simple_unlock(&ipf_rw); }
647 # define ATOMIC_DEC16(x) { simple_lock(&ipf_rw); (x)--; \
648 simple_unlock(&ipf_rw); }
649 # define ATOMIC_INCL(x) atomic_incl((uint32_t*)&(x))
650 # define ATOMIC_DECL(x) atomic_decl((uint32_t*)&(x))
651 # define ATOMIC_INC(x) { simple_lock(&ipf_rw); (x)++; \
652 simple_unlock(&ipf_rw); }
653 # define ATOMIC_DEC(x) { simple_lock(&ipf_rw); (x)--; \
654 simple_unlock(&ipf_rw); }
655 # define SPL_NET(x) ;
656 # define SPL_IMP(x) ;
659 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a, b, d)
660 # define FREE_MB_T(m) m_freem(m)
661 # define MTOD(m,t) mtod(m,t)
662 # define GETIFP(n, v) ifunit(n)
663 # define GET_MINOR getminor
664 # define WAKEUP(id,x) wakeup(id + x)
665 # define POLLWAKEUP(x) ;
666 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
667 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
668 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
669 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
670 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
671 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFILT, \
672 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
673 # define KFREE(x) FREE((x), M_PFILT)
674 # define KFREES(x,s) FREE((x), M_PFILT)
675 # define MSGDSIZE(x) mbufchainlen(x)
676 # define M_LEN(x) (x)->m_len
677 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
678 # define GETKTIME(x) microtime((struct timeval *)x)
679 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
680 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
681 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
682 typedef struct mbuf mb_t;
683 # endif /* _KERNEL */
685 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
686 # define IP_V(x) ((x)->ip_vhl >> 4)
687 # define IP_HL(x) ((x)->ip_vhl & 0xf)
688 # define IP_V_A(x,y) (x)->ip_vhl |= (((y) << 4) & 0xf0)
689 # define IP_HL_A(x,y) (x)->ip_vhl |= ((y) & 0xf)
690 # define TCP_X2(x) ((x)->th_xoff & 0xf)
691 # define TCP_X2_A(x,y) (x)->th_xoff |= ((y) & 0xf)
692 # define TCP_OFF(x) ((x)->th_xoff >> 4)
693 # define TCP_OFF_A(x,y) (x)->th_xoff |= (((y) << 4) & 0xf0)
697 * These are from's Solaris' #defines for little endian.
699 #define IP6F_MORE_FRAG 0x0100
700 #define IP6F_RESERVED_MASK 0x0600
701 #define IP6F_OFF_MASK 0xf8ff
708 typedef int ioctlcmd_t;
710 * Really, any arch where sizeof(long) != sizeof(int).
712 typedef unsigned int u_32_t;
715 # define OS_RECOGNISED 1
718 /* ----------------------------------------------------------------------- */
720 /* ----------------------------------------------------------------------- */
722 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
723 # include "bpfilter.h"
724 # if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
725 # include "opt_inet.h"
730 # if (__NetBSD_Version__ >= 105000000)
731 # define HAVE_M_PULLDOWN 1
736 # define MSGDSIZE(x) mbufchainlen(x)
737 # define M_LEN(x) (x)->m_len
738 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
739 # define GETKTIME(x) microtime((struct timeval *)x)
740 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
741 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
742 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
743 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
744 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
745 typedef struct mbuf mb_t;
746 # endif /* _KERNEL */
747 # if (NetBSD <= 1991011) && (NetBSD >= 199606)
748 # define IFNAME(x) ((struct ifnet *)x)->if_xname
749 # define COPYIFNAME(x, b) \
751 ((struct ifnet *)x)->if_xname, \
753 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
755 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
756 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
759 typedef struct uio uio_t;
760 typedef u_long ioctlcmd_t;
762 typedef u_int32_t u_32_t;
765 # define OS_RECOGNISED 1
766 #endif /* __NetBSD__ */
769 /* ----------------------------------------------------------------------- */
771 /* ----------------------------------------------------------------------- */
773 # if defined(_KERNEL)
774 # if (__FreeBSD_version >= 500000)
775 # include "opt_bpf.h"
779 # if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)
780 # include "opt_inet6.h"
782 # if defined(INET6) && !defined(USE_INET6)
787 # if defined(_KERNEL)
788 # if (__FreeBSD_version >= 400000)
790 * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
791 * There may be other, safe, kernels but this is not extensively tested yet.
793 # define HAVE_M_PULLDOWN
795 # if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
796 # include "opt_ipfilter.h"
798 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
799 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
800 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
801 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
803 # if (__FreeBSD_version >= 500043)
806 # endif /* _KERNEL */
808 # if (__FreeBSD_version >= 500043)
809 # include <sys/mutex.h>
812 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
813 * for what we want to use them for, despite testing showing they work -
814 * with a WITNESS kernel, it generates LOR messages.
816 # define KMUTEX_T struct mtx
818 # define KRWLOCK_T struct mtx
820 # define KRWLOCK_T struct sx
824 # if (__FreeBSD_version >= 501113)
825 # include <net/if_var.h>
826 # define IFNAME(x) ((struct ifnet *)x)->if_xname
827 # define COPYIFNAME(x, b) \
829 ((struct ifnet *)x)->if_xname, \
832 # if (__FreeBSD_version >= 500043)
833 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index) & 7)
835 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
836 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
840 # define GETKTIME(x) microtime((struct timeval *)x)
842 # if (__FreeBSD_version >= 500002)
843 # include <netinet/in_systm.h>
844 # include <netinet/ip.h>
845 # include <machine/in_cksum.h>
848 # if (__FreeBSD_version >= 500043)
850 # define MUTEX_ENTER(x) mtx_lock(&(x)->ipf_lk)
851 # define MUTEX_EXIT(x) mtx_unlock(&(x)->ipf_lk)
852 # define MUTEX_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
854 # define MUTEX_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
855 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
857 * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
858 * for what we want to use them for, despite testing showing they work -
859 * with a WITNESS kernel, it generates LOR messages.
862 # define READ_ENTER(x) mtx_lock(&(x)->ipf_lk)
863 # define WRITE_ENTER(x) mtx_lock(&(x)->ipf_lk)
864 # define RWLOCK_EXIT(x) mtx_unlock(&(x)->ipf_lk)
865 # define MUTEX_DOWNGRADE(x) ;
866 # define RWLOCK_INIT(x,y) mtx_init(&(x)->ipf_lk, (y), NULL,\
868 # define RW_DESTROY(x) mtx_destroy(&(x)->ipf_lk)
870 # define READ_ENTER(x) sx_slock(&(x)->ipf_lk)
871 # define WRITE_ENTER(x) sx_xlock(&(x)->ipf_lk)
872 # define MUTEX_DOWNGRADE(x) sx_downgrade(&(x)->ipf_lk)
873 # define RWLOCK_INIT(x, y) sx_init(&(x)->ipf_lk, (y))
874 # define RW_DESTROY(x) sx_destroy(&(x)->ipf_lk)
876 # define RWLOCK_EXIT(x) sx_unlock(x)
878 # define RWLOCK_EXIT(x) do { \
879 if ((x)->ipf_lk.sx_cnt < 0) \
880 sx_xunlock(&(x)->ipf_lk); \
882 sx_sunlock(&(x)->ipf_lk); \
886 # include <machine/atomic.h>
887 # define ATOMIC_INC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)++; \
888 mtx_unlock(&ipf_rw.ipf_lk); }
889 # define ATOMIC_DEC(x) { mtx_lock(&ipf_rw.ipf_lk); (x)--; \
890 mtx_unlock(&ipf_rw.ipf_lk); }
891 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
892 # define ATOMIC_INC64(x) ATOMIC_INC(x)
893 # define ATOMIC_INC32(x) atomic_add_32(&(x), 1)
894 # define ATOMIC_INC16(x) atomic_add_16(&(x), 1)
895 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
896 # define ATOMIC_DEC64(x) ATOMIC_DEC(x)
897 # define ATOMIC_DEC32(x) atomic_add_32(&(x), -1)
898 # define ATOMIC_DEC16(x) atomic_add_16(&(x), -1)
900 # define SPL_NET(x) ;
901 # define SPL_IMP(x) ;
902 extern int in_cksum __P((struct mbuf *, int));
903 # endif /* __FreeBSD_version >= 500043 */
904 # define MSGDSIZE(x) mbufchainlen(x)
905 # define M_LEN(x) (x)->m_len
906 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
907 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
908 typedef struct mbuf mb_t;
909 # endif /* _KERNEL */
912 # include <machine/spl.h>
914 # if __FreeBSD__ == 3
915 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
916 # define ACTUALLY_LKM_NOT_KERNEL
921 # if (__FreeBSD_version >= 300000)
922 typedef u_long ioctlcmd_t;
924 typedef int ioctlcmd_t;
926 typedef struct uio uio_t;
928 typedef u_int32_t u_32_t;
931 # define OS_RECOGNISED 1
932 #endif /* __FreeBSD__ */
935 /* ----------------------------------------------------------------------- */
937 /* ----------------------------------------------------------------------- */
944 # if !defined(IPFILTER_LKM)
945 # include "bpfilter.h"
947 # if (OpenBSD >= 200311)
948 # define SNPRINTF snprintf
949 # if defined(USE_INET6)
950 # include "netinet6/in6_var.h"
951 # include "netinet6/nd6.h"
954 # if (OpenBSD >= 200012)
955 # define HAVE_M_PULLDOWN 1
957 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
958 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
959 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
960 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
961 # define GETKTIME(x) microtime((struct timeval *)x)
962 # define MSGDSIZE(x) mbufchainlen(x)
963 # define M_LEN(x) (x)->m_len
964 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
965 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
966 typedef struct mbuf mb_t;
967 # endif /* _KERNEL */
968 # if (OpenBSD >= 199603)
969 # define IFNAME(x, b) ((struct ifnet *)x)->if_xname
970 # define COPYIFNAME(x, b) \
972 ((struct ifnet *)x)->if_xname, \
974 # define CACHE_HASH(x) ((((struct ifnet *)fin->fin_ifp)->if_index)&7)
976 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
977 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
980 typedef struct uio uio_t;
981 typedef u_long ioctlcmd_t;
983 typedef u_int32_t u_32_t;
986 # define OS_RECOGNISED 1
987 #endif /* __OpenBSD__ */
990 /* ----------------------------------------------------------------------- */
992 /* ----------------------------------------------------------------------- */
999 # define GETKTIME(x) microtime((struct timeval *)x)
1000 # define MSGDSIZE(x) mbufchainlen(x)
1001 # define M_LEN(x) (x)->m_len
1002 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1003 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1004 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1005 typedef struct mbuf mb_t;
1006 # endif /* _KERNEL */
1008 # if (_BSDI_VERSION >= 199701)
1009 typedef u_long ioctlcmd_t;
1011 typedef int ioctlcmd_t;
1013 typedef u_int32_t u_32_t;
1016 #endif /* _BSDI_VERSION */
1019 /* ----------------------------------------------------------------------- */
1021 /* ----------------------------------------------------------------------- */
1022 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1024 # include <sys/kmem_alloc.h>
1025 # define GETKTIME(x) uniqtime((struct timeval *)x)
1026 # define MSGDSIZE(x) mbufchainlen(x)
1027 # define M_LEN(x) (x)->m_len
1028 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1029 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1030 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1031 # define GETIFP(n, v) ifunit(n, IFNAMSIZ)
1032 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
1033 # define KFREES(x,s) kmem_free((char *)(x), (s))
1034 # define SLEEP(id, n) sleep((id), PZERO+1)
1035 # define WAKEUP(id,x) wakeup(id + x)
1036 # define POLLWAKEUP(x) ;
1037 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1038 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1040 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
1041 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
1043 typedef struct mbuf mb_t;
1046 typedef struct uio uio_t;
1047 typedef int ioctlcmd_t;
1048 typedef int minor_t;
1049 typedef unsigned int u_32_t;
1052 # define OS_RECOGNISED 1
1054 #endif /* SunOS 4 */
1056 /* ----------------------------------------------------------------------- */
1058 /* ----------------------------------------------------------------------- */
1059 #if defined(linux) && !defined(OS_RECOGNISED)
1060 #include <linux/config.h>
1061 #include <linux/version.h>
1063 # define HDR_T_PRIVATE 1
1074 # define IPF_PANIC(x,y) if (x) { printf y; panic("ipf_panic"); }
1075 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
1076 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
1077 # define COPYIN(a,b,c) copy_from_user((caddr_t)(b), (caddr_t)(a), (c))
1078 # define COPYOUT(a,b,c) copy_to_user((caddr_t)(b), (caddr_t)(a), (c))
1079 # define FREE_MB_T(m) kfree_skb(m)
1080 # define GETKTIME(x) do_gettimeofday((struct timeval *)x)
1081 # define SLEEP(x,s) 0, interruptible_sleep_on(x##_linux)
1082 # define POLLWAKEUP(x) ;
1083 # define WAKEUP(x,y) wake_up(x##_linux + y)
1084 # define UIOMOVE(a,b,c,d) uiomove(a,b,c,d)
1085 # define USE_MUTEXES
1086 # define KRWLOCK_T rwlock_t
1087 # define KMUTEX_T spinlock_t
1088 # define MUTEX_INIT(x,y) spin_lock_init(&(x)->ipf_lk)
1089 # define MUTEX_ENTER(x) spin_lock(&(x)->ipf_lk)
1090 # define MUTEX_EXIT(x) spin_unlock(&(x)->ipf_lk)
1091 # define MUTEX_DESTROY(x) do { } while (0)
1092 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1093 # define READ_ENTER(x) ipf_read_enter(x)
1094 # define WRITE_ENTER(x) ipf_write_enter(x)
1095 # define RWLOCK_INIT(x,y) rwlock_init(&(x)->ipf_lk)
1096 # define RW_DESTROY(x) do { } while (0)
1097 # define RWLOCK_EXIT(x) ipf_rw_exit(x)
1098 # define MUTEX_DOWNGRADE(x) ipf_rw_downgrade(x)
1099 # define ATOMIC_INCL(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1101 # define ATOMIC_DECL(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1103 # define ATOMIC_INC64(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1105 # define ATOMIC_INC32(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1107 # define ATOMIC_INC16(x) MUTEX_ENTER(&ipf_rw); (x)++; \
1109 # define ATOMIC_DEC64(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1111 # define ATOMIC_DEC32(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1113 # define ATOMIC_DEC16(x) MUTEX_ENTER(&ipf_rw); (x)--; \
1115 # define SPL_IMP(x) do { } while (0)
1116 # define SPL_NET(x) do { } while (0)
1117 # define SPL_X(x) do { } while (0)
1118 # define IFNAME(x) ((struct net_device*)x)->name
1119 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1120 ((struct net_device *)fin->fin_ifp)->ifindex) & 7)
1121 typedef struct sk_buff mb_t;
1122 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1123 extern void m_copyback __P((mb_t *, int, int, caddr_t));
1124 extern void m_adj __P((mb_t *, int));
1125 extern mb_t *m_pullup __P((mb_t *, int));
1126 # define mbuf sk_buff
1128 # define mtod(m, t) ((t)(m)->data)
1129 # define m_data data
1131 # define m_next next
1132 # define M_DUPLICATE(m) skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1134 # define MSGDSIZE(m) (m)->len
1135 # define M_LEN(m) (m)->len
1137 # define splnet(x) ;
1138 # define printf printk
1139 # define bcopy(s,d,z) memmove(d, s, z)
1140 # define bzero(s,z) memset(s, 0, z)
1141 # define bcmp(a,b,z) memcmp(a, b, z)
1143 # define ifnet net_device
1144 # define if_xname name
1145 # define if_unit ifindex
1147 # define KMALLOC(x,t) (x) = (t)kmalloc(sizeof(*(x)), \
1148 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1149 # define KFREE(x) kfree(x)
1150 # define KMALLOCS(x,t,s) (x) = (t)kmalloc((s), \
1151 in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1152 # define KFREES(x,s) kfree(x)
1154 # define GETIFP(n,v) dev_get_by_name(n)
1157 # include <net/ethernet.h>
1162 # ifndef _NET_ROUTE_H
1168 char if_xname[IFNAMSIZ];
1170 int (* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1171 struct ifaddr *if_addrlist;
1173 # define IFNAME(x) ((struct ifnet *)x)->if_xname
1175 # endif /* _KERNEL */
1177 # define COPYIFNAME(x, b) \
1179 ((struct ifnet *)x)->if_xname, \
1182 # include <linux/fs.h>
1183 # define FWRITE FMODE_WRITE
1184 # define FREAD FMODE_READ
1186 # define __USE_MISC 1
1187 # define __FAVOR_BSD 1
1189 typedef struct uio {
1190 struct iovec *uio_iov;
1199 extern int uiomove __P((caddr_t, size_t, int, struct uio *));
1202 # define UIO_WRITE 2
1204 typedef u_long ioctlcmd_t;
1205 typedef int minor_t;
1206 typedef u_int32_t u_32_t;
1209 # define OS_RECOGNISED 1
1214 /* ----------------------------------------------------------------------- */
1216 /* ----------------------------------------------------------------------- */
1220 # include <sys/lock.h>
1221 # include <sys/sysmacros.h>
1224 # define rw_read_locked(x) 0
1225 # include <net/net_globals.h>
1226 # include <net/net_malloc.h>
1227 # define KMUTEX_T simple_lock_t
1228 # define KRWLOCK_T complex_lock_t
1229 # define USE_MUTEXES 1
1231 # define READ_ENTER(x) lock_read((x)->ipf_lk)
1232 # define WRITE_ENTER(x) lock_write((x)->ipf_lk)
1233 # define MUTEX_DOWNGRADE(x) lock_write_to_read((x)->ipf_lk)
1234 # define RWLOCK_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1237 lock_init((x)->ipf_lk, TRUE)
1238 # define RWLOCK_EXIT(x) lock_done((x)->ipf_lk)
1239 # define RW_DESTROY(x) lock_free(&(x)->ipf_lk)
1240 # define MUTEX_ENTER(x) simple_lock((x)->ipf_lk)
1241 # define MUTEX_INIT(x, y) lock_alloc(&(x)->ipf_lk, \
1244 simple_lock_init((x)->ipf_lk)
1245 # define MUTEX_DESTROY(x) lock_free(&(x)->ipf_lk)
1246 # define MUTEX_EXIT(x) simple_unlock((x)->ipf_lk)
1247 # define MUTEX_NUKE(x) bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1248 # define ATOMIC_INC64(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1249 MUTEX_EXIT(&ipf_rw); }
1250 # define ATOMIC_DEC64(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1251 MUTEX_EXIT(&ipf_rw); }
1252 # define ATOMIC_INC32(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1253 MUTEX_EXIT(&ipf_rw); }
1254 # define ATOMIC_DEC32(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1255 MUTEX_EXIT(&ipf_rw); }
1256 # define ATOMIC_INCL(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1257 MUTEX_EXIT(&ipf_rw); }
1258 # define ATOMIC_DECL(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1259 MUTEX_EXIT(&ipf_rw); }
1260 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); (x)++; \
1261 MUTEX_EXIT(&ipf_rw); }
1262 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); (x)--; \
1263 MUTEX_EXIT(&ipf_rw); }
1264 # define SPL_NET(x) x = splnet()
1265 # define SPL_IMP(x) x = splimp()
1267 # define SPL_X(x) splx(x)
1268 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
1269 extern void* getifp __P((char *, int));
1270 # define GETIFP(n, v) getifp(n, v)
1271 # define GET_MINOR minor
1272 # define SLEEP(id, n) sleepx((id), PZERO+1, 0)
1273 # define WAKEUP(id,x) wakeup(id)
1274 # define POLLWAKEUP(x) ;
1275 # define COPYIN(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
1276 # define COPYOUT(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
1277 # define BCOPYIN(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
1278 # define BCOPYOUT(a,b,c) bcopy((caddr_t)(a), (caddr_t)(b), (c))
1279 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1280 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, \
1281 ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1282 # define KFREE(x) FREE((x), M_TEMP)
1283 # define KFREES(x,s) FREE((x), M_TEMP)
1284 # define MSGDSIZE(x) mbufchainlen(x)
1285 # define M_LEN(x) (x)->m_len
1286 # define M_DUPLICATE(x) m_copy((x), 0, M_COPYALL)
1287 # define GETKTIME(x)
1288 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1289 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1290 # define IPF_PANIC(x,y)
1291 typedef struct mbuf mb_t;
1292 # endif /* _KERNEL */
1295 * These are from's Solaris' #defines for little endian.
1297 #if !defined(IP6F_MORE_FRAG)
1298 # define IP6F_MORE_FRAG 0x0100
1300 #if !defined(IP6F_RESERVED_MASK)
1301 # define IP6F_RESERVED_MASK 0x0600
1303 #if !defined(IP6F_OFF_MASK)
1304 # define IP6F_OFF_MASK 0xf8ff
1312 typedef int ioctlcmd_t;
1313 typedef int minor_t;
1315 * Really, any arch where sizeof(long) != sizeof(int).
1317 typedef unsigned int u_32_t;
1320 # define OS_RECOGNISED 1
1324 #ifndef OS_RECOGNISED
1325 #error ip_compat.h does not recognise this platform/OS.
1329 /* ----------------------------------------------------------------------- */
1331 /* ----------------------------------------------------------------------- */
1332 #ifndef OS_RECOGNISED
1336 * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1339 #if !defined(IPFILTER_BPF)
1340 # if (defined(NBPF) && (NBPF > 0)) || (defined(DEV_BPF) && (DEV_BPF > 0)) || \
1341 (defined(NBPFILTER) && (NBPFILTER > 0))
1342 # define IPFILTER_BPF
1347 * Userland locking primitives
1395 #define ipf_lk ipf_lkun_s.ipf_slk
1396 #define ipf_lname ipf_lkun_s.ipf_lname
1397 #define ipf_isr ipf_lkun_s.ipf_sr
1398 #define ipf_isw ipf_lkun_s.ipf_sw
1399 #define ipf_magic ipf_lkun_s.ipf_magic
1401 #if !defined(__GNUC__) || \
1402 (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1407 # define INLINE __inline__
1410 #if defined(linux) && defined(_KERNEL)
1411 extern void ipf_read_enter __P((ipfrwlock_t *));
1412 extern void ipf_write_enter __P((ipfrwlock_t *));
1413 extern void ipf_rw_exit __P((ipfrwlock_t *));
1414 extern void ipf_rw_downgrade __P((ipfrwlock_t *));
1418 * In a non-kernel environment, there are a lot of macros that need to be
1419 * filled in to be null-ops or to point to some compatibility function,
1420 * somewhere in userland.
1423 typedef struct mb_s {
1424 struct mb_s *mb_next;
1426 u_long mb_buf[2048];
1429 # define m_next mb_next
1430 # define MSGDSIZE(x) (x)->mb_len /* XXX - from ipt.c */
1431 # define M_LEN(x) (x)->mb_len
1432 # define M_DUPLICATE(x) (x)
1433 # define GETKTIME(x) gettimeofday((struct timeval *)(x), NULL)
1435 # define MTOD(m, t) ((t)(m)->mb_buf)
1436 # define FREE_MB_T(x)
1437 # define SLEEP(x,y) 1;
1438 # define WAKEUP(x,y) ;
1439 # define POLLWAKEUP(y) ;
1440 # define IPF_PANIC(x,y) ;
1441 # define PANIC(x,y) ;
1442 # define SPL_NET(x) ;
1443 # define SPL_IMP(x) ;
1445 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
1446 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
1447 # define KFREE(x) free(x)
1448 # define KFREES(x,s) free(x)
1449 # define GETIFP(x, v) get_unit(x,v)
1450 # define COPYIN(a,b,c) bcopywrap((a), (b), (c))
1451 # define COPYOUT(a,b,c) bcopywrap((a), (b), (c))
1452 # define BCOPYIN(a,b,c) (bcopy((a), (b), (c)), 0)
1453 # define BCOPYOUT(a,b,c) (bcopy((a), (b), (c)), 0)
1454 # define COPYDATA(m, o, l, b) bcopy(MTOD((mb_t *)m, char *) + (o), \
1456 # define COPYBACK(m, o, l, b) bcopy((b), \
1457 MTOD((mb_t *)m, char *) + (o), \
1459 # define UIOMOVE(a,b,c,d) ipfuiomove(a,b,c,d)
1460 extern void m_copydata __P((mb_t *, int, int, caddr_t));
1461 extern int ipfuiomove __P((caddr_t, int, int, struct uio *));
1462 extern int bcopywrap __P((void *, void *, size_t));
1464 # define CACHE_HASH(x) ((IFNAME(fin->fin_ifp)[0] + \
1465 ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1468 # define MUTEX_DESTROY(x) eMmutex_destroy(&(x)->ipf_emu)
1469 # define MUTEX_ENTER(x) eMmutex_enter(&(x)->ipf_emu, \
1471 # define MUTEX_EXIT(x) eMmutex_exit(&(x)->ipf_emu)
1472 # define MUTEX_INIT(x,y) eMmutex_init(&(x)->ipf_emu, y)
1473 # define MUTEX_NUKE(x) bzero((x), sizeof(*(x)))
1475 # define MUTEX_DOWNGRADE(x) eMrwlock_downgrade(&(x)->ipf_emu, \
1477 # define READ_ENTER(x) eMrwlock_read_enter(&(x)->ipf_emu, \
1479 # define RWLOCK_INIT(x, y) eMrwlock_init(&(x)->ipf_emu, y)
1480 # define RWLOCK_EXIT(x) eMrwlock_exit(&(x)->ipf_emu)
1481 # define RW_DESTROY(x) eMrwlock_destroy(&(x)->ipf_emu)
1482 # define WRITE_ENTER(x) eMrwlock_write_enter(&(x)->ipf_emu, \
1486 # define USE_MUTEXES 1
1488 extern void eMmutex_destroy __P((eMmutex_t *));
1489 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1490 extern void eMmutex_exit __P((eMmutex_t *));
1491 extern void eMmutex_init __P((eMmutex_t *, char *));
1492 extern void eMrwlock_destroy __P((eMrwlock_t *));
1493 extern void eMrwlock_exit __P((eMrwlock_t *));
1494 extern void eMrwlock_init __P((eMrwlock_t *, char *));
1495 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1496 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1497 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1501 #define MAX_IPV4HDR ((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1504 # define IP_OFFMASK 0x1fff
1509 * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1514 # define U_QUAD_T unsigned long long
1515 # define QUAD_T long long
1516 #else /* BSD > 199306 */
1517 # define U_QUAD_T u_long
1518 # define QUAD_T long
1519 #endif /* BSD > 199306 */
1523 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1524 defined(__osf__) || defined(linux)
1525 # include <netinet/ip6.h>
1526 # include <netinet/icmp6.h>
1527 # if !defined(linux)
1528 # if defined(_KERNEL) && !defined(__osf__)
1529 # include <netinet6/ip6_var.h>
1532 typedef struct ip6_hdr ip6_t;
1537 # define MAX(a,b) (((a) > (b)) ? (a) : (b))
1540 #if defined(_KERNEL)
1542 # define COPYDATA mb_copydata
1543 # define COPYBACK mb_copyback
1545 # define COPYDATA m_copydata
1546 # define COPYBACK m_copyback
1548 # if (BSD >= 199306) || defined(__FreeBSD__)
1549 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1550 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1551 defined(_BSDI_VERSION)
1554 # if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
1555 (__FreeBSD_version >= 300000))
1556 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
1557 (defined(OpenBSD) && (OpenBSD >= 200111))
1558 # include <uvm/uvm_extern.h>
1560 # include <vm/vm_extern.h>
1561 extern vm_map_t kmem_map;
1563 # include <sys/proc.h>
1564 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1565 # include <vm/vm_kern.h>
1566 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1568 # ifdef IPFILTER_M_IPFILTER
1569 # include <sys/malloc.h>
1570 MALLOC_DECLARE(M_IPFILTER);
1571 # define _M_IPF M_IPFILTER
1572 # else /* IPFILTER_M_IPFILTER */
1574 # define _M_IPF M_PFIL
1577 # define _M_IPF M_IPFILTER
1579 # define _M_IPF M_TEMP
1580 # endif /* M_IPFILTER */
1581 # endif /* M_PFIL */
1582 # endif /* IPFILTER_M_IPFILTER */
1583 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1584 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1585 # define KFREE(x) FREE((x), _M_IPF)
1586 # define KFREES(x,s) FREE((x), _M_IPF)
1587 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
1588 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
1589 # define WAKEUP(id,x) wakeup(id+x)
1590 # define POLLWAKEUP(x) selwakeup(ipfselwait+x)
1591 # define GETIFP(n, v) ifunit(n)
1592 # endif /* (Free)BSD */
1594 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
1595 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1596 (defined(OpenBSD) && (OpenBSD >= 200006))
1597 # define SPL_NET(x) x = splsoftnet()
1599 # define SPL_IMP(x) x = splimp()
1600 # define SPL_NET(x) x = splnet()
1601 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1602 # define SPL_X(x) (void) splx(x)
1603 # endif /* !USE_MUTEXES */
1606 # define FREE_MB_T(m) m_freem(m)
1610 # define MTOD(m,t) mtod(m,t)
1614 # define COPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1615 # define COPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1616 # define BCOPYIN(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1617 # define BCOPYOUT(a,b,c) (bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1621 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
1623 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1627 # define GET_MINOR(x) minor(x)
1629 # define PANIC(x,y) if (x) panic y
1630 #endif /* _KERNEL */
1633 # define IFNAME(x) ((struct ifnet *)x)->if_name
1636 # define NEED_FRGETIFNAME
1637 extern char *fr_getifname __P((struct ifnet *, char *));
1638 # define COPYIFNAME(x, b) \
1639 fr_getifname((struct ifnet *)x, b)
1647 * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1648 * would mean all normal code that walks through strings needed casts. Yuck.
1650 #define ISALNUM(x) isalnum((u_char)(x))
1651 #define ISALPHA(x) isalpha((u_char)(x))
1652 #define ISASCII(x) isascii((u_char)(x))
1653 #define ISDIGIT(x) isdigit((u_char)(x))
1654 #define ISPRINT(x) isprint((u_char)(x))
1655 #define ISSPACE(x) isspace((u_char)(x))
1656 #define ISUPPER(x) isupper((u_char)(x))
1657 #define ISXDIGIT(x) isxdigit((u_char)(x))
1658 #define ISLOWER(x) islower((u_char)(x))
1659 #define TOUPPER(x) toupper((u_char)(x))
1660 #define TOLOWER(x) tolower((u_char)(x))
1663 * If mutexes aren't being used, turn all the mutex functions into null-ops.
1665 #if !defined(USE_MUTEXES)
1670 # undef MUTEX_DESTROY
1671 # define MUTEX_ENTER(x) ;
1672 # define READ_ENTER(x) ;
1673 # define WRITE_ENTER(x) ;
1674 # define MUTEX_DOWNGRADE(x) ;
1675 # define RWLOCK_INIT(x, y) ;
1676 # define RWLOCK_EXIT(x) ;
1677 # define RW_DESTROY(x) ;
1678 # define MUTEX_EXIT(x) ;
1679 # define MUTEX_INIT(x,y) ;
1680 # define MUTEX_DESTROY(x) ;
1681 # define MUTEX_NUKE(x) ;
1682 #endif /* !USE_MUTEXES */
1684 # define ATOMIC_INC(x) (x)++
1685 # define ATOMIC_DEC(x) (x)--
1688 #if defined(USE_SPL) && defined(_KERNEL)
1689 # define SPL_INT(x) int x
1695 * If there are no atomic operations for bit sizes defined, define them to all
1696 * use a generic one that works for all sizes.
1699 # define ATOMIC_INCL ATOMIC_INC
1700 # define ATOMIC_INC64 ATOMIC_INC
1701 # define ATOMIC_INC32 ATOMIC_INC
1702 # define ATOMIC_INC16 ATOMIC_INC
1703 # define ATOMIC_DECL ATOMIC_DEC
1704 # define ATOMIC_DEC64 ATOMIC_DEC
1705 # define ATOMIC_DEC32 ATOMIC_DEC
1706 # define ATOMIC_DEC16 ATOMIC_DEC
1709 #ifndef HDR_T_PRIVATE
1710 typedef struct tcphdr tcphdr_t;
1711 typedef struct udphdr udphdr_t;
1713 typedef struct icmp icmphdr_t;
1714 typedef struct ip ip_t;
1715 typedef struct ether_header ether_header_t;
1716 typedef struct tcpiphdr tcpiphdr_t;
1719 # define FR_GROUPLEN 16
1726 # define offsetof(t,m) (int)((&((t *)0L)->m))
1730 * This set of macros has been brought about because on Tru64 it is not
1731 * possible to easily assign or examine values in a structure that are
1735 # define IP_V(x) (x)->ip_v
1738 # define IP_V_A(x,y) (x)->ip_v = (y)
1741 # define IP_HL(x) (x)->ip_hl
1744 # define IP_HL_A(x,y) (x)->ip_hl = (y)
1747 # define TCP_X2(x) (x)->th_x2
1750 # define TCP_X2_A(x,y) (x)->th_x2 = (y)
1753 # define TCP_OFF(x) (x)->th_off
1756 # define TCP_OFF_A(x,y) (x)->th_off = (y)
1758 #define IPMINLEN(i, h) ((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
1762 * XXX - This is one of those *awful* hacks which nobody likes
1770 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
1773 #if (BSD >= 199306) && !defined(m_act)
1774 # define m_act m_nextpkt
1778 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
1782 * 00000001 - (Reserved 4)
1783 * 00111101 - Top Secret
1785 * 10010110 - Confidential
1786 * 01100110 - (Reserved 3)
1787 * 11001100 - (Reserved 2)
1788 * 10101011 - Unclassified
1789 * 11110001 - (Reserved 1)
1791 #define IPSO_CLASS_RES4 0x01
1792 #define IPSO_CLASS_TOPS 0x3d
1793 #define IPSO_CLASS_SECR 0x5a
1794 #define IPSO_CLASS_CONF 0x96
1795 #define IPSO_CLASS_RES3 0x66
1796 #define IPSO_CLASS_RES2 0xcc
1797 #define IPSO_CLASS_UNCL 0xab
1798 #define IPSO_CLASS_RES1 0xf1
1800 #define IPSO_AUTH_GENSER 0x80
1801 #define IPSO_AUTH_ESI 0x40
1802 #define IPSO_AUTH_SCI 0x20
1803 #define IPSO_AUTH_NSA 0x10
1804 #define IPSO_AUTH_DOE 0x08
1805 #define IPSO_AUTH_UN 0x06
1806 #define IPSO_AUTH_FTE 0x01
1809 * IP option #defines
1814 #define IPOPT_ZSU 10 /* ZSU */
1816 #define IPOPT_MTUP 11 /* MTUP */
1818 #define IPOPT_MTUR 12 /* MTUR */
1820 #define IPOPT_ENCODE 15 /* ENCODE */
1824 #define IPOPT_TR 82 /* TR */
1825 #undef IPOPT_SECURITY
1826 #define IPOPT_SECURITY 130
1828 #define IPOPT_LSRR 131
1830 #define IPOPT_E_SEC 133 /* E-SEC */
1832 #define IPOPT_CIPSO 134 /* CIPSO */
1834 #define IPOPT_SATID 136
1836 # define IPOPT_SID IPOPT_SATID
1839 #define IPOPT_SSRR 137
1841 #define IPOPT_ADDEXT 147 /* ADDEXT */
1843 #define IPOPT_VISA 142 /* VISA */
1845 #define IPOPT_IMITD 144 /* IMITD */
1847 #define IPOPT_EIP 145 /* EIP */
1848 #undef IPOPT_RTRALRT
1849 #define IPOPT_RTRALRT 148 /* RTRALRT */
1851 #define IPOPT_SDB 149
1853 #define IPOPT_NSAPA 150
1855 #define IPOPT_DPS 151
1857 #define IPOPT_UMP 152
1859 #define IPOPT_FINN 205 /* FINN */
1862 # define TCPOPT_EOL 0
1865 # define TCPOPT_NOP 1
1867 #ifndef TCPOPT_MAXSEG
1868 # define TCPOPT_MAXSEG 2
1870 #ifndef TCPOLEN_MAXSEG
1871 # define TCPOLEN_MAXSEG 4
1873 #ifndef TCPOPT_WINDOW
1874 # define TCPOPT_WINDOW 3
1876 #ifndef TCPOLEN_WINDOW
1877 # define TCPOLEN_WINDOW 3
1879 #ifndef TCPOPT_SACK_PERMITTED
1880 # define TCPOPT_SACK_PERMITTED 4
1882 #ifndef TCPOLEN_SACK_PERMITTED
1883 # define TCPOLEN_SACK_PERMITTED 2
1886 # define TCPOPT_SACK 5
1888 #ifndef TCPOPT_TIMESTAMP
1889 # define TCPOPT_TIMESTAMP 8
1893 # define ICMP_MINLEN 8
1895 #ifndef ICMP_ECHOREPLY
1896 # define ICMP_ECHOREPLY 0
1898 #ifndef ICMP_UNREACH
1899 # define ICMP_UNREACH 3
1901 #ifndef ICMP_UNREACH_NET
1902 # define ICMP_UNREACH_NET 0
1904 #ifndef ICMP_UNREACH_HOST
1905 # define ICMP_UNREACH_HOST 1
1907 #ifndef ICMP_UNREACH_PROTOCOL
1908 # define ICMP_UNREACH_PROTOCOL 2
1910 #ifndef ICMP_UNREACH_PORT
1911 # define ICMP_UNREACH_PORT 3
1913 #ifndef ICMP_UNREACH_NEEDFRAG
1914 # define ICMP_UNREACH_NEEDFRAG 4
1916 #ifndef ICMP_UNREACH_SRCFAIL
1917 # define ICMP_UNREACH_SRCFAIL 5
1919 #ifndef ICMP_UNREACH_NET_UNKNOWN
1920 # define ICMP_UNREACH_NET_UNKNOWN 6
1922 #ifndef ICMP_UNREACH_HOST_UNKNOWN
1923 # define ICMP_UNREACH_HOST_UNKNOWN 7
1925 #ifndef ICMP_UNREACH_ISOLATED
1926 # define ICMP_UNREACH_ISOLATED 8
1928 #ifndef ICMP_UNREACH_NET_PROHIB
1929 # define ICMP_UNREACH_NET_PROHIB 9
1931 #ifndef ICMP_UNREACH_HOST_PROHIB
1932 # define ICMP_UNREACH_HOST_PROHIB 10
1934 #ifndef ICMP_UNREACH_TOSNET
1935 # define ICMP_UNREACH_TOSNET 11
1937 #ifndef ICMP_UNREACH_TOSHOST
1938 # define ICMP_UNREACH_TOSHOST 12
1940 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
1941 # define ICMP_UNREACH_ADMIN_PROHIBIT 13
1943 #ifndef ICMP_UNREACH_FILTER
1944 # define ICMP_UNREACH_FILTER 13
1946 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
1947 # define ICMP_UNREACH_HOST_PRECEDENCE 14
1949 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
1950 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
1952 #ifndef ICMP_SOURCEQUENCH
1953 # define ICMP_SOURCEQUENCH 4
1955 #ifndef ICMP_REDIRECT_NET
1956 # define ICMP_REDIRECT_NET 0
1958 #ifndef ICMP_REDIRECT_HOST
1959 # define ICMP_REDIRECT_HOST 1
1961 #ifndef ICMP_REDIRECT_TOSNET
1962 # define ICMP_REDIRECT_TOSNET 2
1964 #ifndef ICMP_REDIRECT_TOSHOST
1965 # define ICMP_REDIRECT_TOSHOST 3
1967 #ifndef ICMP_ALTHOSTADDR
1968 # define ICMP_ALTHOSTADDR 6
1970 #ifndef ICMP_TIMXCEED
1971 # define ICMP_TIMXCEED 11
1973 #ifndef ICMP_TIMXCEED_INTRANS
1974 # define ICMP_TIMXCEED_INTRANS 0
1976 #ifndef ICMP_TIMXCEED_REASS
1977 # define ICMP_TIMXCEED_REASS 1
1979 #ifndef ICMP_PARAMPROB
1980 # define ICMP_PARAMPROB 12
1982 #ifndef ICMP_PARAMPROB_ERRATPTR
1983 # define ICMP_PARAMPROB_ERRATPTR 0
1985 #ifndef ICMP_PARAMPROB_OPTABSENT
1986 # define ICMP_PARAMPROB_OPTABSENT 1
1988 #ifndef ICMP_PARAMPROB_LENGTH
1989 # define ICMP_PARAMPROB_LENGTH 2
1992 # define ICMP_TSTAMP 13
1994 #ifndef ICMP_TSTAMPREPLY
1995 # define ICMP_TSTAMPREPLY 14
1998 # define ICMP_IREQ 15
2000 #ifndef ICMP_IREQREPLY
2001 # define ICMP_IREQREPLY 16
2003 #ifndef ICMP_MASKREQ
2004 # define ICMP_MASKREQ 17
2006 #ifndef ICMP_MASKREPLY
2007 # define ICMP_MASKREPLY 18
2009 #ifndef ICMP_TRACEROUTE
2010 # define ICMP_TRACEROUTE 30
2012 #ifndef ICMP_DATACONVERR
2013 # define ICMP_DATACONVERR 31
2015 #ifndef ICMP_MOBILE_REDIRECT
2016 # define ICMP_MOBILE_REDIRECT 32
2018 #ifndef ICMP_IPV6_WHEREAREYOU
2019 # define ICMP_IPV6_WHEREAREYOU 33
2021 #ifndef ICMP_IPV6_IAMHERE
2022 # define ICMP_IPV6_IAMHERE 34
2024 #ifndef ICMP_MOBILE_REGREQUEST
2025 # define ICMP_MOBILE_REGREQUEST 35
2027 #ifndef ICMP_MOBILE_REGREPLY
2028 # define ICMP_MOBILE_REGREPLY 36
2031 # define ICMP_SKIP 39
2033 #ifndef ICMP_PHOTURIS
2034 # define ICMP_PHOTURIS 40
2036 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
2037 # define ICMP_PHOTURIS_UNKNOWN_INDEX 1
2039 #ifndef ICMP_PHOTURIS_AUTH_FAILED
2040 # define ICMP_PHOTURIS_AUTH_FAILED 2
2042 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
2043 # define ICMP_PHOTURIS_DECRYPT_FAILED 3
2046 # define IPVERSION 4
2048 #ifndef IPOPT_MINOFF
2049 # define IPOPT_MINOFF 4
2051 #ifndef IPOPT_COPIED
2052 # define IPOPT_COPIED(x) ((x)&0x80)
2055 # define IPOPT_EOL 0
2058 # define IPOPT_NOP 1
2061 # define IP_MF ((u_short)0x2000)
2063 #ifndef ETHERTYPE_IP
2064 # define ETHERTYPE_IP ((u_short)0x0800)
2067 # define TH_FIN 0x01
2070 # define TH_SYN 0x02
2073 # define TH_RST 0x04
2076 # define TH_PUSH 0x08
2079 # define TH_ACK 0x10
2082 # define TH_URG 0x20
2085 #define TH_ACKMASK (TH_FIN|TH_SYN|TH_RST|TH_ACK)
2088 # define IPOPT_EOL 0
2091 # define IPOPT_NOP 1
2097 # define IPOPT_TS 68
2099 #ifndef IPOPT_SECURITY
2100 # define IPOPT_SECURITY 130
2103 # define IPOPT_LSRR 131
2106 # define IPOPT_SATID 136
2109 # define IPOPT_SSRR 137
2111 #ifndef IPOPT_SECUR_UNCLASS
2112 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
2114 #ifndef IPOPT_SECUR_CONFID
2115 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
2117 #ifndef IPOPT_SECUR_EFTO
2118 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
2120 #ifndef IPOPT_SECUR_MMMM
2121 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
2123 #ifndef IPOPT_SECUR_RESTR
2124 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
2126 #ifndef IPOPT_SECUR_SECRET
2127 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
2129 #ifndef IPOPT_SECUR_TOPSECRET
2130 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
2133 # define IPOPT_OLEN 1
2135 #ifndef IPPROTO_HOPOPTS
2136 # define IPPROTO_HOPOPTS 0
2138 #ifndef IPPROTO_ENCAP
2139 # define IPPROTO_ENCAP 4
2141 #ifndef IPPROTO_IPV6
2142 # define IPPROTO_IPV6 41
2144 #ifndef IPPROTO_ROUTING
2145 # define IPPROTO_ROUTING 43
2147 #ifndef IPPROTO_FRAGMENT
2148 # define IPPROTO_FRAGMENT 44
2151 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
2154 # define IPPROTO_ESP 50
2157 # define IPPROTO_AH 51
2159 #ifndef IPPROTO_ICMPV6
2160 # define IPPROTO_ICMPV6 58
2162 #ifndef IPPROTO_NONE
2163 # define IPPROTO_NONE 59
2165 #ifndef IPPROTO_DSTOPTS
2166 # define IPPROTO_DSTOPTS 60
2168 #ifndef IPPROTO_MOBILITY
2169 # define IPPROTO_MOBILITY 135
2172 #ifndef ICMP_ROUTERADVERT
2173 # define ICMP_ROUTERADVERT 9
2175 #ifndef ICMP_ROUTERSOLICIT
2176 # define ICMP_ROUTERSOLICIT 10
2178 #ifndef ICMP6_DST_UNREACH
2179 # define ICMP6_DST_UNREACH 1
2181 #ifndef ICMP6_PACKET_TOO_BIG
2182 # define ICMP6_PACKET_TOO_BIG 2
2184 #ifndef ICMP6_TIME_EXCEEDED
2185 # define ICMP6_TIME_EXCEEDED 3
2187 #ifndef ICMP6_PARAM_PROB
2188 # define ICMP6_PARAM_PROB 4
2191 #ifndef ICMP6_ECHO_REQUEST
2192 # define ICMP6_ECHO_REQUEST 128
2194 #ifndef ICMP6_ECHO_REPLY
2195 # define ICMP6_ECHO_REPLY 129
2197 #ifndef ICMP6_MEMBERSHIP_QUERY
2198 # define ICMP6_MEMBERSHIP_QUERY 130
2200 #ifndef MLD6_LISTENER_QUERY
2201 # define MLD6_LISTENER_QUERY 130
2203 #ifndef ICMP6_MEMBERSHIP_REPORT
2204 # define ICMP6_MEMBERSHIP_REPORT 131
2206 #ifndef MLD6_LISTENER_REPORT
2207 # define MLD6_LISTENER_REPORT 131
2209 #ifndef ICMP6_MEMBERSHIP_REDUCTION
2210 # define ICMP6_MEMBERSHIP_REDUCTION 132
2212 #ifndef MLD6_LISTENER_DONE
2213 # define MLD6_LISTENER_DONE 132
2215 #ifndef ND_ROUTER_SOLICIT
2216 # define ND_ROUTER_SOLICIT 133
2218 #ifndef ND_ROUTER_ADVERT
2219 # define ND_ROUTER_ADVERT 134
2221 #ifndef ND_NEIGHBOR_SOLICIT
2222 # define ND_NEIGHBOR_SOLICIT 135
2224 #ifndef ND_NEIGHBOR_ADVERT
2225 # define ND_NEIGHBOR_ADVERT 136
2228 # define ND_REDIRECT 137
2230 #ifndef ICMP6_ROUTER_RENUMBERING
2231 # define ICMP6_ROUTER_RENUMBERING 138
2233 #ifndef ICMP6_WRUREQUEST
2234 # define ICMP6_WRUREQUEST 139
2236 #ifndef ICMP6_WRUREPLY
2237 # define ICMP6_WRUREPLY 140
2239 #ifndef ICMP6_FQDN_QUERY
2240 # define ICMP6_FQDN_QUERY 139
2242 #ifndef ICMP6_FQDN_REPLY
2243 # define ICMP6_FQDN_REPLY 140
2245 #ifndef ICMP6_NI_QUERY
2246 # define ICMP6_NI_QUERY 139
2248 #ifndef ICMP6_NI_REPLY
2249 # define ICMP6_NI_REPLY 140
2251 #ifndef MLD6_MTRACE_RESP
2252 # define MLD6_MTRACE_RESP 200
2255 # define MLD6_MTRACE 201
2257 #ifndef ICMP6_HADISCOV_REQUEST
2258 # define ICMP6_HADISCOV_REQUEST 202
2260 #ifndef ICMP6_HADISCOV_REPLY
2261 # define ICMP6_HADISCOV_REPLY 203
2263 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
2264 # define ICMP6_MOBILEPREFIX_SOLICIT 204
2266 #ifndef ICMP6_MOBILEPREFIX_ADVERT
2267 # define ICMP6_MOBILEPREFIX_ADVERT 205
2269 #ifndef ICMP6_MAXTYPE
2270 # define ICMP6_MAXTYPE 205
2273 #ifndef ICMP6_DST_UNREACH_NOROUTE
2274 # define ICMP6_DST_UNREACH_NOROUTE 0
2276 #ifndef ICMP6_DST_UNREACH_ADMIN
2277 # define ICMP6_DST_UNREACH_ADMIN 1
2279 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
2280 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
2282 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
2283 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
2285 #ifndef ICMP6_DST_UNREACH_ADDR
2286 # define ICMP6_DST_UNREACH_ADDR 3
2288 #ifndef ICMP6_DST_UNREACH_NOPORT
2289 # define ICMP6_DST_UNREACH_NOPORT 4
2291 #ifndef ICMP6_TIME_EXCEED_TRANSIT
2292 # define ICMP6_TIME_EXCEED_TRANSIT 0
2294 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
2295 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
2298 #ifndef ICMP6_NI_SUCCESS
2299 # define ICMP6_NI_SUCCESS 0
2301 #ifndef ICMP6_NI_REFUSED
2302 # define ICMP6_NI_REFUSED 1
2304 #ifndef ICMP6_NI_UNKNOWN
2305 # define ICMP6_NI_UNKNOWN 2
2308 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
2309 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
2311 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
2312 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
2314 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2315 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
2318 #ifndef ICMP6_PARAMPROB_HEADER
2319 # define ICMP6_PARAMPROB_HEADER 0
2321 #ifndef ICMP6_PARAMPROB_NEXTHEADER
2322 # define ICMP6_PARAMPROB_NEXTHEADER 1
2324 #ifndef ICMP6_PARAMPROB_OPTION
2325 # define ICMP6_PARAMPROB_OPTION 2
2328 #ifndef ICMP6_NI_SUBJ_IPV6
2329 # define ICMP6_NI_SUBJ_IPV6 0
2331 #ifndef ICMP6_NI_SUBJ_FQDN
2332 # define ICMP6_NI_SUBJ_FQDN 1
2334 #ifndef ICMP6_NI_SUBJ_IPV4
2335 # define ICMP6_NI_SUBJ_IPV4 2
2339 * ECN is a new addition to TCP - RFC 2481
2342 # define TH_ECN 0x40
2345 # define TH_CWR 0x80
2347 #define TH_ECNALL (TH_ECN|TH_CWR)
2352 #define IPF_TCPS_CLOSED 0 /* closed */
2353 #define IPF_TCPS_LISTEN 1 /* listening for connection */
2354 #define IPF_TCPS_SYN_SENT 2 /* active, have sent syn */
2355 #define IPF_TCPS_SYN_RECEIVED 3 /* have send and received syn */
2356 #define IPF_TCPS_HALF_ESTAB 4 /* for connections not fully "up" */
2357 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2358 #define IPF_TCPS_ESTABLISHED 5 /* established */
2359 #define IPF_TCPS_CLOSE_WAIT 6 /* rcvd fin, waiting for close */
2360 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2361 #define IPF_TCPS_FIN_WAIT_1 7 /* have closed, sent fin */
2362 #define IPF_TCPS_CLOSING 8 /* closed xchd FIN; await FIN ACK */
2363 #define IPF_TCPS_LAST_ACK 9 /* had fin and close; await FIN ACK */
2364 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2365 #define IPF_TCPS_FIN_WAIT_2 10 /* have closed, fin is acked */
2366 #define IPF_TCPS_TIME_WAIT 11 /* in 2*msl quiet wait after close */
2367 #define IPF_TCP_NSTATES 12
2371 #undef ICMP_MAX_UNREACH
2372 #define ICMP_MAX_UNREACH 14
2374 #define ICMP_MAXTYPE 18
2381 # define LOG_FTP (11<<3)
2383 #ifndef LOG_AUTHPRIV
2384 # define LOG_AUTHPRIV (10<<3)
2387 # define LOG_AUDIT (13<<3)
2390 # define LOG_NTP (12<<3)
2392 #ifndef LOG_SECURITY
2393 # define LOG_SECURITY (13<<3)
2396 # define LOG_LFMT (14<<3)
2399 # define LOG_CONSOLE (14<<3)
2403 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2404 * another IP header and then 64 bits of data, totalling 56. Of course,
2405 * the last 64 bits is dependent on that being available.
2407 #define ICMPERR_ICMPHLEN 8
2408 #define ICMPERR_IPICMPHLEN (20 + 8)
2409 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
2410 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
2411 #define ICMP6ERR_MINPKTLEN (40 + 8)
2412 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
2415 # define MIN(a,b) (((a)<(b))?(a):(b))
2419 # define DPRINT(x) printf x
2425 # undef IPFILTER_BPF
2428 #endif /* __IP_COMPAT_H__ */