2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * @(#)ip_compat.h 1.8 1/14/96
7 * $Id: ip_compat.h,v 2.26.2.46 2002/06/27 14:39:40 darrenr Exp $
8 * $FreeBSD: src/sys/contrib/ipfilter/netinet/ip_compat.h,v 1.13.2.5 2003/03/01 03:55:54 darrenr Exp $
9 * $DragonFly: src/sys/contrib/ipfilter/netinet/ip_compat.h,v 1.2 2003/06/17 04:28:20 dillon Exp $
12 #ifndef __IP_COMPAT_H__
13 #define __IP_COMPAT_H__
28 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
31 # if !defined(SOLARIS2)
32 # define SOLARIS2 3 /* Pick an old version */
42 #if defined(sun) && !(defined(__svr4__) || defined(__SVR4))
46 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
55 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
58 # define bzero(a,b) memset(a,0,b)
60 # define bcopy(a,b,c) memmove(b,a,c)
65 #define offsetof(t,m) (int)((&((t *)0L)->m))
68 #if defined(__sgi) || defined(bsdi)
70 u_char ether_addr_octet[6];
76 # define LIFNAMSIZ IF_NAMESIZE
79 # define LIFNAMSIZ IFNAMSIZ
86 #if defined(__sgi) && !defined(IPFILTER_LKM)
88 # define IPL_EXTERN(ep) ipfilter##ep
90 # define IPL_EXTERN(ep) ipfilter/**/ep
94 # define IPL_EXTERN(ep) ipl##ep
96 # define IPL_EXTERN(ep) ipl/**/ep
101 # include <sys/debug.h>
105 # include <sys/sysmacros.h>
109 * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
126 # define MTYPE(m) ((m)->b_datap->db_type)
128 # include <sys/isa_defs.h>
130 # include <sys/ioccom.h>
131 # include <sys/sysmacros.h>
132 # include <sys/kmem.h>
134 * because Solaris 2 defines these in two places :-/
145 # include <netinet/ip6.h>
147 # include <inet/common.h>
148 # include <inet/ip.h>
149 # include <inet/ip_ire.h>
153 # include <netinet/ip6.h>
155 # include <inet/common.h>
156 # include <inet/ip.h>
157 # include <inet/ip_ire.h>
158 # endif /* _KERNEL */
160 # include <inet/ip_if.h>
161 # include <netinet/ip6.h>
162 # define ipif_local_addr ipif_lcl_addr
163 /* Only defined in private include file */
164 # ifndef V4_PART_OF_V6
165 # define V4_PART_OF_V6(v6) v6.s6_addr32[3]
177 struct qinit *qf_wqinfo;
178 struct qinit *qf_rqinfo;
179 struct qinit qf_wqinit;
180 struct qinit qf_rqinit;
181 mblk_t *qf_m; /* These three fields are for passing data up from */
182 queue_t *qf_q; /* fr_qin and fr_qout to the packet processing. */
184 size_t qf_len; /* this field is used for in ipfr_fastroute */
185 char qf_name[LIFNAMSIZ];
187 * in case the ILL has disappeared...
189 size_t qf_hl; /* header length */
192 int qf_tunoff; /* tunnel offset */
202 #define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
205 #define IP_OFFMASK 0x1fff
210 # define U_QUAD_T u_quad_t
211 # define QUAD_T quad_t
212 #else /* BSD > 199306 */
213 # define U_QUAD_T u_long
215 #endif /* BSD > 199306 */
218 #if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL))
219 # include <sys/param.h>
220 # ifndef __FreeBSD_version
222 # include <osreldate.h>
224 # include <sys/osreldate.h>
228 # define ACTUALLY_LKM_NOT_KERNEL
230 # if defined(__FreeBSD_version) && (__FreeBSD_version < 300000)
231 # include <machine/spl.h>
233 # if (__FreeBSD_version >= 300000) && (__FreeBSD_version < 400000)
234 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
235 # define ACTUALLY_LKM_NOT_KERNEL
239 #endif /* __FreeBSD__ && KERNEL */
241 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 500000) && \
243 # include <machine/in_cksum.h>
247 * These operating systems already take care of the problem for us.
249 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
251 typedef u_int32_t u_32_t;
252 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
253 # if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
254 # include "opt_inet.h"
256 # if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
258 # include "opt_inet6.h"
264 # if !defined(_KERNEL) && !defined(IPFILTER_LKM) && !defined(USE_INET6)
265 # if (defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)) || \
266 (defined(OpenBSD) && (OpenBSD >= 200111)) || \
267 (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000))
273 * Really, any arch where sizeof(long) != sizeof(int).
275 # if defined(__alpha__) || defined(__alpha) || defined(_LP64)
276 typedef unsigned int u_32_t;
279 typedef uint32_t u_32_t;
281 typedef unsigned int u_32_t;
284 #endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
287 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
288 # include <netinet/ip6.h>
290 # include <netinet6/ip6_var.h>
292 typedef struct ip6_hdr ip6_t;
294 # include <netinet/icmp6.h>
307 #define IP6CMP(a,b) bcmp((char *)&(a), (char *)&(b), sizeof(a))
308 #define IP6EQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) == 0)
309 #define IP6NEQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) != 0)
310 #define IP6_ISZERO(a) ((((union i6addr *)(a))->i6[0] | \
311 ((union i6addr *)(a))->i6[1] | \
312 ((union i6addr *)(a))->i6[2] | \
313 ((union i6addr *)(a))->i6[3]) == 0)
314 #define IP6_NOTZERO(a) ((((union i6addr *)(a))->i6[0] | \
315 ((union i6addr *)(a))->i6[1] | \
316 ((union i6addr *)(a))->i6[2] | \
317 ((union i6addr *)(a))->i6[3]) != 0)
320 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
324 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
328 * 00000001 - (Reserved 4)
329 * 00111101 - Top Secret
331 * 10010110 - Confidential
332 * 01100110 - (Reserved 3)
333 * 11001100 - (Reserved 2)
334 * 10101011 - Unclassified
335 * 11110001 - (Reserved 1)
337 #define IPSO_CLASS_RES4 0x01
338 #define IPSO_CLASS_TOPS 0x3d
339 #define IPSO_CLASS_SECR 0x5a
340 #define IPSO_CLASS_CONF 0x96
341 #define IPSO_CLASS_RES3 0x66
342 #define IPSO_CLASS_RES2 0xcc
343 #define IPSO_CLASS_UNCL 0xab
344 #define IPSO_CLASS_RES1 0xf1
346 #define IPSO_AUTH_GENSER 0x80
347 #define IPSO_AUTH_ESI 0x40
348 #define IPSO_AUTH_SCI 0x20
349 #define IPSO_AUTH_NSA 0x10
350 #define IPSO_AUTH_DOE 0x08
351 #define IPSO_AUTH_UN 0x06
352 #define IPSO_AUTH_FTE 0x01
357 /*#define IPOPT_RR 7 */
358 #define IPOPT_ZSU 10 /* ZSU */
359 #define IPOPT_MTUP 11 /* MTUP */
360 #define IPOPT_MTUR 12 /* MTUR */
361 #define IPOPT_ENCODE 15 /* ENCODE */
362 /*#define IPOPT_TS 68 */
363 #define IPOPT_TR 82 /* TR */
364 /*#define IPOPT_SECURITY 130 */
365 /*#define IPOPT_LSRR 131 */
366 #define IPOPT_E_SEC 133 /* E-SEC */
367 #define IPOPT_CIPSO 134 /* CIPSO */
368 /*#define IPOPT_SATID 136 */
370 # define IPOPT_SID IPOPT_SATID
372 /*#define IPOPT_SSRR 137 */
373 #define IPOPT_ADDEXT 147 /* ADDEXT */
374 #define IPOPT_VISA 142 /* VISA */
375 #define IPOPT_IMITD 144 /* IMITD */
376 #define IPOPT_EIP 145 /* EIP */
377 #define IPOPT_FINN 205 /* FINN */
379 #ifndef TCPOPT_WSCALE
380 # define TCPOPT_WSCALE 3
384 * Build some macros and #defines to enable the same code to compile anywhere
385 * Well, that's the idea, anyway :-)
391 # define ALIGN32(ptr) (ptr ? 0L : 0L)
392 # define ALIGN16(ptr) (ptr ? 0L : 0L)
394 # define ALIGN32(ptr) (ptr)
395 # define ALIGN16(ptr) (ptr)
399 typedef struct mbuf mb_t;
402 #if !SOLARIS || (SOLARIS2 < 6) || !defined(KERNEL)
403 # define ATOMIC_INCL ATOMIC_INC
404 # define ATOMIC_INC64 ATOMIC_INC
405 # define ATOMIC_INC32 ATOMIC_INC
406 # define ATOMIC_INC16 ATOMIC_INC
407 # define ATOMIC_DECL ATOMIC_DEC
408 # define ATOMIC_DEC64 ATOMIC_DEC
409 # define ATOMIC_DEC32 ATOMIC_DEC
410 # define ATOMIC_DEC16 ATOMIC_DEC
414 # include <sys/ksynch.h>
415 # define IPF_LOCK_PL plhi
416 # include <sys/sema.h>
423 # undef MUTEX_DESTROY
428 # include <sys/atomic.h>
430 # define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1)
431 # define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1)
433 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
434 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
436 # define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1)
437 # define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1)
438 # define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1)
439 # define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1)
440 # define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1)
441 # define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1)
443 # define IRE_CACHE IRE_ROUTE
444 # define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \
445 mutex_exit(&ipf_rw); }
446 # define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \
447 mutex_exit(&ipf_rw); }
449 # define MUTEX_ENTER(x) mutex_enter(x)
451 # define KRWLOCK_T krwlock_t
452 # define READ_ENTER(x) rw_enter(x, RW_READER)
453 # define WRITE_ENTER(x) rw_enter(x, RW_WRITER)
454 # define RW_UPGRADE(x) { if (rw_tryupgrade(x) == 0) { \
456 rw_enter(x, RW_WRITER); } \
458 # define MUTEX_DOWNGRADE(x) rw_downgrade(x)
459 # define RWLOCK_INIT(x, y, z) rw_init((x), (y), RW_DRIVER, (z))
460 # define RWLOCK_EXIT(x) rw_exit(x)
461 # define RW_DESTROY(x) rw_destroy(x)
463 # define KRWLOCK_T kmutex_t
464 # define READ_ENTER(x) mutex_enter(x)
465 # define WRITE_ENTER(x) mutex_enter(x)
466 # define MUTEX_DOWNGRADE(x) ;
467 # define RWLOCK_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z))
468 # define RWLOCK_EXIT(x) mutex_exit(x)
469 # define RW_DESTROY(x) mutex_destroy(x)
471 # define MUTEX_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z))
472 # define MUTEX_DESTROY(x) mutex_destroy(x)
473 # define MUTEX_EXIT(x) mutex_exit(x)
474 # define MTOD(m,t) (t)((m)->b_rptr)
475 # define IRCOPY(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
476 # define IWCOPY(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
477 # define IRCOPYPTR ircopyptr
478 # define IWCOPYPTR iwcopyptr
479 # define FREE_MB_T(m) freemsg(m)
480 # define SPL_NET(x) ;
481 # define SPL_IMP(x) ;
485 # define ntohs(x) (x)
486 # define ntohl(x) (x)
487 # define htons(x) (x)
488 # define htonl(x) (x)
490 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
491 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
492 # define GET_MINOR(x) getminor(x)
493 extern ill_t *get_unit __P((char *, int));
494 # define GETUNIT(n, v) get_unit(n, v)
495 # define IFNAME(x) ((ill_t *)x)->ill_name
498 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \
499 (x)++; MUTEX_EXIT(&ipf_rw); }
500 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \
501 (x)--; MUTEX_EXIT(&ipf_rw); }
502 # define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL);
503 # define KRWLOCK_T kmutex_t
504 # define READ_ENTER(x) MUTEX_ENTER(x)
505 # define WRITE_ENTER(x) MUTEX_ENTER(x)
506 # define RW_UPGRADE(x) ;
507 # define MUTEX_DOWNGRADE(x) ;
508 # define RWLOCK_EXIT(x) MUTEX_EXIT(x)
509 # define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl);
510 # define MUTEX_INIT(x,y,z) (x)->l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
511 # define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->l)
513 # define ATOMIC_INC(x) (x)++
514 # define ATOMIC_DEC(x) (x)--
515 # define MUTEX_ENTER(x) ;
516 # define READ_ENTER(x) ;
517 # define WRITE_ENTER(x) ;
518 # define RW_UPGRADE(x) ;
519 # define MUTEX_DOWNGRADE(x) ;
520 # define RWLOCK_EXIT(x) ;
521 # define MUTEX_EXIT(x) ;
522 # define MUTEX_INIT(x,y,z) ;
523 # define MUTEX_DESTROY(x) ;
526 # define FREE_MB_T(m) m_freem(m)
527 # define MTOD(m,t) mtod(m,t)
528 # define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
529 # define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
530 # define IRCOPYPTR ircopyptr
531 # define IWCOPYPTR iwcopyptr
533 # endif /* SOLARIS */
537 # include <sys/time.h>
538 # include <sys/kmem_alloc.h>
539 # define GETUNIT(n, v) ifunit(n, IFNAMSIZ)
540 # define IFNAME(x) ((struct ifnet *)x)->if_name
544 # define GETUNIT(n, v) ifunit(n)
545 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \
546 (defined(OpenBSD) && (OpenBSD >= 199603))
547 # define IFNAME(x) ((struct ifnet *)x)->if_xname
549 # define USE_GETIFNAME 1
550 # define IFNAME(x) get_ifname((struct ifnet *)x)
551 extern char *get_ifname __P((struct ifnet *));
556 # if defined(sun) && !defined(linux) || defined(__sgi)
557 # define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d)
558 # define SLEEP(id, n) sleep((id), PZERO+1)
559 # define WAKEUP(id) wakeup(id)
560 # define KFREE(x) kmem_free((char *)(x), sizeof(*(x)))
561 # define KFREES(x,s) kmem_free((char *)(x), (s))
563 extern void m_copydata __P((struct mbuf *, int, int, caddr_t));
564 extern void m_copyback __P((struct mbuf *, int, int, caddr_t));
567 # include <sys/kmem.h>
568 # include <sys/ddi.h>
569 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
570 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
571 # define GET_MINOR(x) getminor(x)
574 # define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \
576 # define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
577 # endif /* SOLARIS */
579 # endif /* sun && !linux */
581 # define GET_MINOR(x) minor(x)
583 # if (BSD >= 199306) || defined(__FreeBSD__)
584 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
585 defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
586 defined(_BSDI_VERSION)
589 # if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
590 (__FreeBSD_version >= 300000))
591 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
592 (defined(OpenBSD) && (OpenBSD >= 200111))
593 # include <uvm/uvm_extern.h>
595 # include <vm/vm_extern.h>
596 extern vm_map_t kmem_map;
598 # include <sys/proc.h>
599 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
600 # include <vm/vm_kern.h>
601 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
603 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT)
604 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT)
605 # define KFREE(x) FREE((x), M_PFIL)
606 # define KFREES(x,s) FREE((x), M_PFIL)
608 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
609 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT)
610 # define KFREE(x) FREE((x), M_TEMP)
611 # define KFREES(x,s) FREE((x), M_TEMP)
613 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
614 # define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0)
615 # define WAKEUP(id) wakeup(id)
617 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
618 (defined(OpenBSD) && (OpenBSD >= 200006))
619 # define SPL_NET(x) x = splsoftnet()
620 # define SPL_X(x) (void) splx(x)
622 # if !SOLARIS && !defined(linux)
623 # define SPL_IMP(x) x = splimp()
624 # define SPL_NET(x) x = splnet()
625 # define SPL_X(x) (void) splx(x)
627 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
628 # define PANIC(x,y) if (x) panic y
630 # define SLEEP(x,y) 1
632 # define PANIC(x,y) ;
633 # define ATOMIC_INC(x) (x)++
634 # define ATOMIC_DEC(x) (x)--
635 # define MUTEX_ENTER(x) ;
636 # define READ_ENTER(x) ;
637 # define MUTEX_INIT(x,y,z) ;
638 # define MUTEX_DESTROY(x) ;
639 # define WRITE_ENTER(x) ;
640 # define RW_UPGRADE(x) ;
641 # define MUTEX_DOWNGRADE(x) ;
642 # define RWLOCK_EXIT(x) ;
643 # define MUTEX_EXIT(x) ;
644 # define SPL_NET(x) ;
645 # define SPL_IMP(x) ;
648 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
649 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
650 # define KFREE(x) free(x)
651 # define KFREES(x,s) free(x)
652 # define FREE_MB_T(x) ;
653 # define GETUNIT(x, v) get_unit(x,v)
654 # define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
655 # define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
656 # define IRCOPYPTR ircopyptr
657 # define IWCOPYPTR iwcopyptr
658 # define IFNAME(x) get_ifname((struct ifnet *)x)
659 # define UIOMOVE(a,b,c,d) ipfuiomove(a,b,c,d)
660 # include <sys/time.h>
661 extern void m_copydata __P((mb_t *, int, int, caddr_t));
662 extern int ipfuiomove __P((caddr_t, int, int, struct uio *));
666 * These #ifdef's are here mainly for linux, but who knows, they may
667 * not be in other places or maybe one day linux will grow up and some
668 * of these will turn up there too.
671 # define ICMP_MINLEN 8
673 #ifndef ICMP_ECHOREPLY
674 # define ICMP_ECHOREPLY 0
677 # define ICMP_UNREACH 3
679 #ifndef ICMP_UNREACH_NET
680 # define ICMP_UNREACH_NET 0
682 #ifndef ICMP_UNREACH_HOST
683 # define ICMP_UNREACH_HOST 1
685 #ifndef ICMP_UNREACH_PROTOCOL
686 # define ICMP_UNREACH_PROTOCOL 2
688 #ifndef ICMP_UNREACH_PORT
689 # define ICMP_UNREACH_PORT 3
691 #ifndef ICMP_UNREACH_NEEDFRAG
692 # define ICMP_UNREACH_NEEDFRAG 4
694 #ifndef ICMP_UNREACH_SRCFAIL
695 # define ICMP_UNREACH_SRCFAIL 5
697 #ifndef ICMP_UNREACH_NET_UNKNOWN
698 # define ICMP_UNREACH_NET_UNKNOWN 6
700 #ifndef ICMP_UNREACH_HOST_UNKNOWN
701 # define ICMP_UNREACH_HOST_UNKNOWN 7
703 #ifndef ICMP_UNREACH_ISOLATED
704 # define ICMP_UNREACH_ISOLATED 8
706 #ifndef ICMP_UNREACH_NET_PROHIB
707 # define ICMP_UNREACH_NET_PROHIB 9
709 #ifndef ICMP_UNREACH_HOST_PROHIB
710 # define ICMP_UNREACH_HOST_PROHIB 10
712 #ifndef ICMP_UNREACH_TOSNET
713 # define ICMP_UNREACH_TOSNET 11
715 #ifndef ICMP_UNREACH_TOSHOST
716 # define ICMP_UNREACH_TOSHOST 12
718 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
719 # define ICMP_UNREACH_ADMIN_PROHIBIT 13
721 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
722 # define ICMP_UNREACH_HOST_PRECEDENCE 14
724 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
725 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
727 #ifndef ICMP_SOURCEQUENCH
728 # define ICMP_SOURCEQUENCH 4
730 #ifndef ICMP_REDIRECT_NET
731 # define ICMP_REDIRECT_NET 0
733 #ifndef ICMP_REDIRECT_HOST
734 # define ICMP_REDIRECT_HOST 1
736 #ifndef ICMP_REDIRECT_TOSNET
737 # define ICMP_REDIRECT_TOSNET 2
739 #ifndef ICMP_REDIRECT_TOSHOST
740 # define ICMP_REDIRECT_TOSHOST 3
742 #ifndef ICMP_ALTHOSTADDR
743 # define ICMP_ALTHOSTADDR 6
745 #ifndef ICMP_TIMXCEED
746 # define ICMP_TIMXCEED 11
748 #ifndef ICMP_TIMXCEED_INTRANS
749 # define ICMP_TIMXCEED_INTRANS 0
751 #ifndef ICMP_TIMXCEED_REASS
752 # define ICMP_TIMXCEED_REASS 1
754 #ifndef ICMP_PARAMPROB
755 # define ICMP_PARAMPROB 12
757 #ifndef ICMP_PARAMPROB_ERRATPTR
758 # define ICMP_PARAMPROB_ERRATPTR 0
760 #ifndef ICMP_PARAMPROB_OPTABSENT
761 # define ICMP_PARAMPROB_OPTABSENT 1
763 #ifndef ICMP_PARAMPROB_LENGTH
764 # define ICMP_PARAMPROB_LENGTH 2
767 # define ICMP_TSTAMP 13
769 #ifndef ICMP_TSTAMPREPLY
770 # define ICMP_TSTAMPREPLY 14
773 # define ICMP_IREQ 15
775 #ifndef ICMP_IREQREPLY
776 # define ICMP_IREQREPLY 16
779 # define ICMP_MASKREQ 17
781 #ifndef ICMP_MASKREPLY
782 # define ICMP_MASKREPLY 18
784 #ifndef ICMP_TRACEROUTE
785 # define ICMP_TRACEROUTE 30
787 #ifndef ICMP_DATACONVERR
788 # define ICMP_DATACONVERR 31
790 #ifndef ICMP_MOBILE_REDIRECT
791 # define ICMP_MOBILE_REDIRECT 32
793 #ifndef ICMP_IPV6_WHEREAREYOU
794 # define ICMP_IPV6_WHEREAREYOU 33
796 #ifndef ICMP_IPV6_IAMHERE
797 # define ICMP_IPV6_IAMHERE 34
799 #ifndef ICMP_MOBILE_REGREQUEST
800 # define ICMP_MOBILE_REGREQUEST 35
802 #ifndef ICMP_MOBILE_REGREPLY
803 # define ICMP_MOBILE_REGREPLY 36
806 # define ICMP_SKIP 39
808 #ifndef ICMP_PHOTURIS
809 # define ICMP_PHOTURIS 40
811 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
812 # define ICMP_PHOTURIS_UNKNOWN_INDEX 1
814 #ifndef ICMP_PHOTURIS_AUTH_FAILED
815 # define ICMP_PHOTURIS_AUTH_FAILED 2
817 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
818 # define ICMP_PHOTURIS_DECRYPT_FAILED 3
824 # define IPOPT_MINOFF 4
827 # define IPOPT_COPIED(x) ((x)&0x80)
836 # define IP_MF ((u_short)0x2000)
839 # define ETHERTYPE_IP ((u_short)0x0800)
851 # define TH_PUSH 0x08
871 #ifndef IPOPT_SECURITY
872 # define IPOPT_SECURITY 130
875 # define IPOPT_LSRR 131
878 # define IPOPT_SATID 136
881 # define IPOPT_SSRR 137
883 #ifndef IPOPT_SECUR_UNCLASS
884 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
886 #ifndef IPOPT_SECUR_CONFID
887 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
889 #ifndef IPOPT_SECUR_EFTO
890 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
892 #ifndef IPOPT_SECUR_MMMM
893 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
895 #ifndef IPOPT_SECUR_RESTR
896 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
898 #ifndef IPOPT_SECUR_SECRET
899 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
901 #ifndef IPOPT_SECUR_TOPSECRET
902 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
905 # define IPOPT_OLEN 1
908 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
911 # define IPPROTO_ESP 50
913 #ifndef IPPROTO_ICMPV6
914 # define IPPROTO_ICMPV6 58
918 #include <linux/in_systm.h>
922 #define TCPS_CLOSED 0 /* closed */
923 #define TCPS_LISTEN 1 /* listening for connection */
924 #define TCPS_SYN_SENT 2 /* active, have sent syn */
925 #define TCPS_SYN_RECEIVED 3 /* have send and received syn */
926 /* states < TCPS_ESTABLISHED are those where connections not established */
927 #define TCPS_ESTABLISHED 4 /* established */
928 #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
929 /* states > TCPS_CLOSE_WAIT are those where user has closed */
930 #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
931 #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
932 #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
933 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
934 #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
935 #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
944 #define FWRITE _IOC_WRITE
945 #define FREAD _IOC_READ
948 * mbuf related problems.
950 #define mtod(m,t) (t)((m)->data)
964 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
986 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
1001 struct in_addr ip_src;
1002 struct in_addr ip_dst;
1006 * Structure of an icmp header.
1008 typedef struct icmp {
1009 __u8 icmp_type; /* type of message, see below */
1010 __u8 icmp_code; /* type sub code */
1011 __u16 icmp_cksum; /* ones complement cksum of struct */
1013 __u8 ih_pptr; /* ICMP_PARAMPROB */
1014 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
1021 # define icmp_pptr icmp_hun.ih_pptr
1022 # define icmp_gwaddr icmp_hun.ih_gwaddr
1023 # define icmp_id icmp_hun.ih_idseq.icd_id
1024 # define icmp_seq icmp_hun.ih_idseq.icd_seq
1025 # define icmp_void icmp_hun.ih_void
1034 /* options and then 64 bits of data */
1039 # define icmp_otime icmp_dun.id_ts.its_otime
1040 # define icmp_rtime icmp_dun.id_ts.its_rtime
1041 # define icmp_ttime icmp_dun.id_ts.its_ttime
1042 # define icmp_ip icmp_dun.id_ip.idi_ip
1043 # define icmp_mask icmp_dun.id_mask
1044 # define icmp_data icmp_dun.id_data
1047 # ifndef LINUX_IPOVLY
1048 # define LINUX_IPOVLY
1050 caddr_t ih_next, ih_prev; /* for protocol sequence q's */
1051 u_char ih_x1; /* (unused) */
1052 u_char ih_pr; /* protocol */
1053 short ih_len; /* protocol length */
1054 struct in_addr ih_src; /* source internet address */
1055 struct in_addr ih_dst; /* destination internet address */
1060 __u8 ether_dhost[6];
1061 __u8 ether_shost[6];
1065 typedef struct uio {
1072 # define UIO_WRITE 1
1073 # define UIOMOVE(a, b, c, d) uiomove(a,b,c,d)
1076 * For masking struct ifnet onto struct device
1078 # define if_name name
1081 # define GETUNIT(x, v) dev_get(x)
1082 # define FREE_MB_T(m) kfree_skb(m, FREE_WRITE)
1083 # define uniqtime do_gettimeofday
1088 # include <linux/netdevice.h>
1093 # define bcmp(a,b,c) memcmp(a,b,c)
1094 # define bcopy(a,b,c) memcpy(b,a,c)
1095 # define bzero(a,c) memset(a,0,c)
1097 # define UNITNAME(n) dev_get((n))
1099 # define KMALLOC(a,b) (a) = (b)kmalloc(sizeof(*(a)), GFP_ATOMIC)
1100 # define KMALLOCS(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC)
1101 # define KFREE(x) kfree_s((x), sizeof(*(x)))
1102 # define KFREES(x,s) kfree_s((x), (s))
1103 #define IRCOPY(const void *a, void *b, size_t c) { \
1106 error = verify_area(VERIFY_READ, a ,c); \
1108 memcpy_fromfs(b, a, c); \
1111 static inline int IWCOPY(const void *a, void *b, size_t c)
1115 error = verify_area(VERIFY_WRITE, b, c);
1117 memcpy_tofs(b, a, c);
1120 static inline int IRCOPYPTR(const void *a, void *b, size_t c) {
1124 error = verify_area(VERIFY_READ, a ,sizeof(ca));
1126 memcpy_fromfs(ca, a, sizeof(ca));
1127 error = verify_area(VERIFY_READ, ca , c);
1129 memcpy_fromfs(b, ca, c);
1133 static inline int IWCOPYPTR(const void *a, void *b, size_t c) {
1138 error = verify_area(VERIFY_READ, b ,sizeof(ca));
1140 memcpy_fromfs(ca, b, sizeof(ca));
1141 error = verify_area(VERIFY_WRITE, ca, c);
1143 memcpy_tofs(ca, a, c);
1159 # include <linux/netdevice.h>
1162 # define ifnet device
1164 typedef struct tcphdr tcphdr_t;
1165 typedef struct udphdr udphdr_t;
1166 typedef struct icmp icmphdr_t;
1167 typedef struct ip ip_t;
1168 typedef struct ether_header ether_header_t;
1170 typedef struct tcpiphdr tcpiphdr_t;
1172 #if defined(hpux) || defined(linux)
1174 char ether_addr_octet[6];
1179 * XXX - This is one of those *awful* hacks which nobody likes
1187 #if (BSD >= 199306) && !defined(m_act)
1188 # define m_act m_nextpkt
1191 #ifndef ICMP_ROUTERADVERT
1192 # define ICMP_ROUTERADVERT 9
1194 #ifndef ICMP_ROUTERSOLICIT
1195 # define ICMP_ROUTERSOLICIT 10
1197 #undef ICMP_MAX_UNREACH
1198 #define ICMP_MAX_UNREACH 14
1200 #define ICMP_MAXTYPE 18
1202 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1203 * another IP header and then 64 bits of data, totalling 56. Of course,
1204 * the last 64 bits is dependant on that being available.
1206 #define ICMPERR_ICMPHLEN 8
1207 #define ICMPERR_IPICMPHLEN (20 + 8)
1208 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
1209 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
1210 #define ICMP6_MINLEN 8
1211 #define ICMP6ERR_MINPKTLEN (40 + 8)
1212 #define ICMP6ERR_IPICMPHLEN (40 + 8 + 40)
1214 #ifndef ICMP6_DST_UNREACH
1215 # define ICMP6_DST_UNREACH 1
1217 #ifndef ICMP6_PACKET_TOO_BIG
1218 # define ICMP6_PACKET_TOO_BIG 2
1220 #ifndef ICMP6_TIME_EXCEEDED
1221 # define ICMP6_TIME_EXCEEDED 3
1223 #ifndef ICMP6_PARAM_PROB
1224 # define ICMP6_PARAM_PROB 4
1227 #ifndef ICMP6_ECHO_REQUEST
1228 # define ICMP6_ECHO_REQUEST 128
1230 #ifndef ICMP6_ECHO_REPLY
1231 # define ICMP6_ECHO_REPLY 129
1233 #ifndef ICMP6_MEMBERSHIP_QUERY
1234 # define ICMP6_MEMBERSHIP_QUERY 130
1236 #ifndef MLD6_LISTENER_QUERY
1237 # define MLD6_LISTENER_QUERY 130
1239 #ifndef ICMP6_MEMBERSHIP_REPORT
1240 # define ICMP6_MEMBERSHIP_REPORT 131
1242 #ifndef MLD6_LISTENER_REPORT
1243 # define MLD6_LISTENER_REPORT 131
1245 #ifndef ICMP6_MEMBERSHIP_REDUCTION
1246 # define ICMP6_MEMBERSHIP_REDUCTION 132
1248 #ifndef MLD6_LISTENER_DONE
1249 # define MLD6_LISTENER_DONE 132
1251 #ifndef ND_ROUTER_SOLICIT
1252 # define ND_ROUTER_SOLICIT 133
1254 #ifndef ND_ROUTER_ADVERT
1255 # define ND_ROUTER_ADVERT 134
1257 #ifndef ND_NEIGHBOR_SOLICIT
1258 # define ND_NEIGHBOR_SOLICIT 135
1260 #ifndef ND_NEIGHBOR_ADVERT
1261 # define ND_NEIGHBOR_ADVERT 136
1264 # define ND_REDIRECT 137
1266 #ifndef ICMP6_ROUTER_RENUMBERING
1267 # define ICMP6_ROUTER_RENUMBERING 138
1269 #ifndef ICMP6_WRUREQUEST
1270 # define ICMP6_WRUREQUEST 139
1272 #ifndef ICMP6_WRUREPLY
1273 # define ICMP6_WRUREPLY 140
1275 #ifndef ICMP6_FQDN_QUERY
1276 # define ICMP6_FQDN_QUERY 139
1278 #ifndef ICMP6_FQDN_REPLY
1279 # define ICMP6_FQDN_REPLY 140
1281 #ifndef ICMP6_NI_QUERY
1282 # define ICMP6_NI_QUERY 139
1284 #ifndef ICMP6_NI_REPLY
1285 # define ICMP6_NI_REPLY 140
1287 #ifndef MLD6_MTRACE_RESP
1288 # define MLD6_MTRACE_RESP 200
1291 # define MLD6_MTRACE 201
1293 #ifndef ICMP6_HADISCOV_REQUEST
1294 # define ICMP6_HADISCOV_REQUEST 202
1296 #ifndef ICMP6_HADISCOV_REPLY
1297 # define ICMP6_HADISCOV_REPLY 203
1299 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
1300 # define ICMP6_MOBILEPREFIX_SOLICIT 204
1302 #ifndef ICMP6_MOBILEPREFIX_ADVERT
1303 # define ICMP6_MOBILEPREFIX_ADVERT 205
1305 #ifndef ICMP6_MAXTYPE
1306 # define ICMP6_MAXTYPE 205
1309 #ifndef ICMP6_DST_UNREACH_NOROUTE
1310 # define ICMP6_DST_UNREACH_NOROUTE 0
1312 #ifndef ICMP6_DST_UNREACH_ADMIN
1313 # define ICMP6_DST_UNREACH_ADMIN 1
1315 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
1316 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
1318 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
1319 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
1321 #ifndef ICMP6_DST_UNREACH_ADDR
1322 # define ICMP6_DST_UNREACH_ADDR 3
1324 #ifndef ICMP6_DST_UNREACH_NOPORT
1325 # define ICMP6_DST_UNREACH_NOPORT 4
1327 #ifndef ICMP6_TIME_EXCEED_TRANSIT
1328 # define ICMP6_TIME_EXCEED_TRANSIT 0
1330 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
1331 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
1334 #ifndef ICMP6_NI_SUCCESS
1335 # define ICMP6_NI_SUCCESS 0
1337 #ifndef ICMP6_NI_REFUSED
1338 # define ICMP6_NI_REFUSED 1
1340 #ifndef ICMP6_NI_UNKNOWN
1341 # define ICMP6_NI_UNKNOWN 2
1344 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
1345 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
1347 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
1348 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
1350 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1351 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
1354 #ifndef ICMP6_PARAMPROB_HEADER
1355 # define ICMP6_PARAMPROB_HEADER 0
1357 #ifndef ICMP6_PARAMPROB_NEXTHEADER
1358 # define ICMP6_PARAMPROB_NEXTHEADER 1
1360 #ifndef ICMP6_PARAMPROB_OPTION
1361 # define ICMP6_PARAMPROB_OPTION 2
1364 #ifndef ICMP6_NI_SUBJ_IPV6
1365 # define ICMP6_NI_SUBJ_IPV6 0
1367 #ifndef ICMP6_NI_SUBJ_FQDN
1368 # define ICMP6_NI_SUBJ_FQDN 1
1370 #ifndef ICMP6_NI_SUBJ_IPV4
1371 # define ICMP6_NI_SUBJ_IPV4 2
1375 * ECN is a new addition to TCP - RFC 2481
1378 # define TH_ECN 0x40
1381 # define TH_CWR 0x80
1383 #define TH_ECNALL (TH_ECN|TH_CWR)
1385 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECN|TH_CWR)
1387 #endif /* __IP_COMPAT_H__ */