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.6 2004/07/04 09:24:38 darrenr Exp $
9 * $DragonFly: src/sys/contrib/ipfilter/netinet/ip_compat.h,v 1.12 2005/06/04 14:24:33 corecode Exp $
12 #ifndef __IP_COMPAT_H__
13 #define __IP_COMPAT_H__
21 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
24 # if !defined(SOLARIS2)
25 # define SOLARIS2 3 /* Pick an old version */
35 #if defined(sun) && !(defined(__svr4__) || defined(__SVR4))
39 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
48 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
51 # define bzero(a,b) memset(a,0,b)
53 # define bcopy(a,b,c) memmove(b,a,c)
58 #define offsetof(t,m) (int)((&((t *)0L)->m))
61 #if defined(__sgi) || defined(bsdi)
63 u_char ether_addr_octet[6];
69 # define LIFNAMSIZ IF_NAMESIZE
72 # define LIFNAMSIZ IFNAMSIZ
79 #if defined(__sgi) && !defined(IPFILTER_LKM)
81 # define IPL_EXTERN(ep) ipfilter##ep
83 # define IPL_EXTERN(ep) ipfilter/**/ep
87 # define IPL_EXTERN(ep) ipl##ep
89 # define IPL_EXTERN(ep) ipl/**/ep
94 # include <sys/debug.h>
98 # include <sys/sysmacros.h>
102 * This is a workaround for <sys/uio.h> troubles on FreeBSD
106 # define _KERNEL_STRUCTURES
113 # undef _KERNEL_STRUCTURES
117 # define MTYPE(m) ((m)->b_datap->db_type)
119 # include <sys/isa_defs.h>
121 # include <sys/ioccom.h>
122 # include <sys/sysmacros.h>
123 # include <sys/kmem.h>
125 * because Solaris 2 defines these in two places :-/
136 # include <netinet/ip6.h>
138 # include <inet/common.h>
139 # include <inet/ip.h>
140 # include <inet/ip_ire.h>
144 # include <netinet/ip6.h>
146 # include <inet/common.h>
147 # include <inet/ip.h>
148 # include <inet/ip_ire.h>
149 # endif /* _KERNEL */
151 # include <inet/ip_if.h>
152 # include <netinet/ip6.h>
153 # define ipif_local_addr ipif_lcl_addr
154 /* Only defined in private include file */
155 # ifndef V4_PART_OF_V6
156 # define V4_PART_OF_V6(v6) v6.s6_addr32[3]
159 # define M_BLEN(m) ((m)->b_wptr - (m)->b_rptr)
169 void *qf_data; /* layer 3 header pointer */
170 struct qinit *qf_wqinfo;
171 struct qinit *qf_rqinfo;
172 struct qinit qf_wqinit;
173 struct qinit qf_rqinit;
174 mblk_t *qf_m; /* These three fields are for passing data up from */
175 queue_t *qf_q; /* fr_qin and fr_qout to the packet processing. */
177 size_t qf_len; /* this field is used for in ipfr_fastroute */
178 char qf_name[LIFNAMSIZ];
180 * in case the ILL has disappeared...
182 size_t qf_hl; /* header length */
185 int qf_tunoff; /* tunnel offset */
195 #define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
198 #define IP_OFFMASK 0x1fff
203 # define U_QUAD_T u_quad_t
204 # define QUAD_T quad_t
205 #else /* BSD > 199306 */
206 # define U_QUAD_T u_long
208 #endif /* BSD > 199306 */
210 #if defined(__DragonFly__)
211 # include <sys/param.h>
213 # define ACTUALLY_LKM_NOT_KERNEL
217 #if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL))
218 # include <sys/param.h>
219 # ifndef __FreeBSD_version
221 # include <osreldate.h>
223 # include <sys/osreldate.h>
227 # define ACTUALLY_LKM_NOT_KERNEL
229 # if defined(__FreeBSD_version) && (__FreeBSD_version < 300000)
230 # include <machine/spl.h>
232 # if (__FreeBSD_version >= 300000) && (__FreeBSD_version < 400000)
233 # if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
234 # define ACTUALLY_LKM_NOT_KERNEL
238 #endif /* __FreeBSD__ && KERNEL */
240 #if defined(__DragonFly__) && defined(_KERNEL)
241 #include <sys/in_cksum.h>
245 * These operating systems already take care of the problem for us.
247 #if defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
249 typedef u_int32_t u_32_t;
250 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
251 # if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
252 # include "opt_inet.h"
254 # if (defined(__DragonFly__) || defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)) && \
256 # include "opt_inet6.h"
262 # if !defined(_KERNEL) && !defined(IPFILTER_LKM) && !defined(USE_INET6)
263 # if defined(__DragonFly__) || (defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)) || \
264 (defined(OpenBSD) && (OpenBSD >= 200111)) || \
265 (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000))
271 * Really, any arch where sizeof(long) != sizeof(int).
273 # if defined(__alpha__) || defined(__alpha) || defined(_LP64)
274 typedef unsigned int u_32_t;
277 typedef uint32_t u_32_t;
279 typedef unsigned int u_32_t;
282 #endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
285 # if defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
286 # include <netinet/ip6.h>
288 # include <netinet6/ip6_var.h>
290 typedef struct ip6_hdr ip6_t;
292 # include <netinet/icmp6.h>
305 #define IP6CMP(a,b) bcmp((char *)&(a), (char *)&(b), sizeof(a))
306 #define IP6EQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) == 0)
307 #define IP6NEQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) != 0)
308 #define IP6_ISZERO(a) ((((union i6addr *)(a))->i6[0] | \
309 ((union i6addr *)(a))->i6[1] | \
310 ((union i6addr *)(a))->i6[2] | \
311 ((union i6addr *)(a))->i6[3]) == 0)
312 #define IP6_NOTZERO(a) ((((union i6addr *)(a))->i6[0] | \
313 ((union i6addr *)(a))->i6[1] | \
314 ((union i6addr *)(a))->i6[2] | \
315 ((union i6addr *)(a))->i6[3]) != 0)
318 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
322 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
326 * 00000001 - (Reserved 4)
327 * 00111101 - Top Secret
329 * 10010110 - Confidential
330 * 01100110 - (Reserved 3)
331 * 11001100 - (Reserved 2)
332 * 10101011 - Unclassified
333 * 11110001 - (Reserved 1)
335 #define IPSO_CLASS_RES4 0x01
336 #define IPSO_CLASS_TOPS 0x3d
337 #define IPSO_CLASS_SECR 0x5a
338 #define IPSO_CLASS_CONF 0x96
339 #define IPSO_CLASS_RES3 0x66
340 #define IPSO_CLASS_RES2 0xcc
341 #define IPSO_CLASS_UNCL 0xab
342 #define IPSO_CLASS_RES1 0xf1
344 #define IPSO_AUTH_GENSER 0x80
345 #define IPSO_AUTH_ESI 0x40
346 #define IPSO_AUTH_SCI 0x20
347 #define IPSO_AUTH_NSA 0x10
348 #define IPSO_AUTH_DOE 0x08
349 #define IPSO_AUTH_UN 0x06
350 #define IPSO_AUTH_FTE 0x01
355 /*#define IPOPT_RR 7 */
356 #define IPOPT_ZSU 10 /* ZSU */
357 #define IPOPT_MTUP 11 /* MTUP */
358 #define IPOPT_MTUR 12 /* MTUR */
359 #define IPOPT_ENCODE 15 /* ENCODE */
360 /*#define IPOPT_TS 68 */
361 #define IPOPT_TR 82 /* TR */
362 /*#define IPOPT_SECURITY 130 */
363 /*#define IPOPT_LSRR 131 */
364 #define IPOPT_E_SEC 133 /* E-SEC */
365 #define IPOPT_CIPSO 134 /* CIPSO */
366 /*#define IPOPT_SATID 136 */
368 # define IPOPT_SID IPOPT_SATID
370 /*#define IPOPT_SSRR 137 */
371 #define IPOPT_ADDEXT 147 /* ADDEXT */
372 #define IPOPT_VISA 142 /* VISA */
373 #define IPOPT_IMITD 144 /* IMITD */
374 #define IPOPT_EIP 145 /* EIP */
375 #define IPOPT_FINN 205 /* FINN */
377 #ifndef TCPOPT_WSCALE
378 # define TCPOPT_WSCALE 3
382 * Build some macros and #defines to enable the same code to compile anywhere
383 * Well, that's the idea, anyway :-)
389 # define ALIGN32(ptr) (ptr ? 0L : 0L)
390 # define ALIGN16(ptr) (ptr ? 0L : 0L)
392 # define ALIGN32(ptr) (ptr)
393 # define ALIGN16(ptr) (ptr)
397 typedef struct mbuf mb_t;
400 #if !SOLARIS || (SOLARIS2 < 6) || !defined(KERNEL)
401 # define ATOMIC_INCL ATOMIC_INC
402 # define ATOMIC_INC64 ATOMIC_INC
403 # define ATOMIC_INC32 ATOMIC_INC
404 # define ATOMIC_INC16 ATOMIC_INC
405 # define ATOMIC_DECL ATOMIC_DEC
406 # define ATOMIC_DEC64 ATOMIC_DEC
407 # define ATOMIC_DEC32 ATOMIC_DEC
408 # define ATOMIC_DEC16 ATOMIC_DEC
412 # include <sys/ksynch.h>
413 # define IPF_LOCK_PL plhi
414 # include <sys/sema.h>
421 # undef MUTEX_DESTROY
426 # include <sys/atomic.h>
428 # define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1)
429 # define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1)
431 # define ATOMIC_INCL(x) atomic_add_long(&(x), 1)
432 # define ATOMIC_DECL(x) atomic_add_long(&(x), -1)
434 # define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1)
435 # define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1)
436 # define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1)
437 # define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1)
438 # define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1)
439 # define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1)
441 # define IRE_CACHE IRE_ROUTE
442 # define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \
443 mutex_exit(&ipf_rw); }
444 # define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \
445 mutex_exit(&ipf_rw); }
447 # define MUTEX_ENTER(x) mutex_enter(x)
449 # define KRWLOCK_T krwlock_t
450 # define READ_ENTER(x) rw_enter(x, RW_READER)
451 # define WRITE_ENTER(x) rw_enter(x, RW_WRITER)
452 # define RW_UPGRADE(x) { if (rw_tryupgrade(x) == 0) { \
454 rw_enter(x, RW_WRITER); } \
456 # define MUTEX_DOWNGRADE(x) rw_downgrade(x)
457 # define RWLOCK_INIT(x, y, z) rw_init((x), (y), RW_DRIVER, (z))
458 # define RWLOCK_EXIT(x) rw_exit(x)
459 # define RW_DESTROY(x) rw_destroy(x)
461 # define KRWLOCK_T kmutex_t
462 # define READ_ENTER(x) mutex_enter(x)
463 # define WRITE_ENTER(x) mutex_enter(x)
464 # define MUTEX_DOWNGRADE(x) ;
465 # define RWLOCK_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z))
466 # define RWLOCK_EXIT(x) mutex_exit(x)
467 # define RW_DESTROY(x) mutex_destroy(x)
469 # define MUTEX_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z))
470 # define MUTEX_DESTROY(x) mutex_destroy(x)
471 # define MUTEX_EXIT(x) mutex_exit(x)
472 # define MTOD(m,t) (t)((m)->b_rptr)
473 # define IRCOPY(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c))
474 # define IWCOPY(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c))
475 # define IRCOPYPTR ircopyptr
476 # define IWCOPYPTR iwcopyptr
477 # define FREE_MB_T(m) freemsg(m)
478 # define SPL_NET(x) ;
479 # define SPL_IMP(x) ;
483 # define ntohs(x) (x)
484 # define ntohl(x) (x)
485 # define htons(x) (x)
486 # define htonl(x) (x)
488 # define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
489 # define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
490 # define GET_MINOR(x) getminor(x)
491 extern ill_t *get_unit (char *, int);
492 # define GETUNIT(n, v) get_unit(n, v)
493 # define IFNAME(x) ((ill_t *)x)->ill_name
496 # define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \
497 (x)++; MUTEX_EXIT(&ipf_rw); }
498 # define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \
499 (x)--; MUTEX_EXIT(&ipf_rw); }
500 # define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL);
501 # define KRWLOCK_T kmutex_t
502 # define READ_ENTER(x) MUTEX_ENTER(x)
503 # define WRITE_ENTER(x) MUTEX_ENTER(x)
504 # define RW_UPGRADE(x) ;
505 # define MUTEX_DOWNGRADE(x) ;
506 # define RWLOCK_EXIT(x) MUTEX_EXIT(x)
507 # define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl);
508 # define MUTEX_INIT(x,y,z) (x)->l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
509 # define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->l)
511 # define ATOMIC_INC(x) (x)++
512 # define ATOMIC_DEC(x) (x)--
513 # define MUTEX_ENTER(x) ;
514 # define READ_ENTER(x) ;
515 # define WRITE_ENTER(x) ;
516 # define RW_UPGRADE(x) ;
517 # define MUTEX_DOWNGRADE(x) ;
518 # define RWLOCK_EXIT(x) ;
519 # define MUTEX_EXIT(x) ;
520 # define MUTEX_INIT(x,y,z) ;
521 # define MUTEX_DESTROY(x) ;
524 # define FREE_MB_T(m) m_freem(m)
525 # define MTOD(m,t) mtod(m,t)
526 # define M_BLEN(m) (m)->m_len
527 # define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
528 # define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
529 # define IRCOPYPTR ircopyptr
530 # define IWCOPYPTR iwcopyptr
532 # endif /* SOLARIS */
536 # include <sys/time.h>
537 # include <sys/kmem_alloc.h>
538 # define GETUNIT(n, v) ifunit(n, IFNAMSIZ)
539 # define IFNAME(x) ((struct ifnet *)x)->if_name
543 # define GETUNIT(n, v) ifunit(n)
544 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \
545 (defined(OpenBSD) && (OpenBSD >= 199603)) || \
546 (defined(__DragonFly__))
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 (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), 0)
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 (struct mbuf *, int, int, caddr_t);
564 extern void m_copyback (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(__DragonFly__) || defined(__FreeBSD__)
584 # if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
585 defined(__DragonFly__) || defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
586 defined(_BSDI_VERSION)
589 # if !defined(__FreeBSD__) || (defined(__DragonFly__) || (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>
597 # include <sys/proc.h>
598 # else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
599 # include <vm/vm_kern.h>
600 # endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
602 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT)
603 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT)
604 # define KFREE(x) FREE((x), M_PFIL)
605 # define KFREES(x,s) FREE((x), M_PFIL)
607 # define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
608 # define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT)
609 # define KFREE(x) FREE((x), M_TEMP)
610 # define KFREES(x,s) FREE((x), M_TEMP)
612 # define UIOMOVE(a,b,c,d) uiomove(a,b,d)
613 # define SLEEP(id, n) tsleep((id), PCATCH, n, 0)
614 # define WAKEUP(id) wakeup(id)
616 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
617 (defined(OpenBSD) && (OpenBSD >= 200006))
618 # define SPL_NET(x) x = splsoftnet()
619 # define SPL_X(x) (void) splx(x)
621 # if defined(__DragonFly__)
622 # define SPL_NET(x) crit_enter();
623 # define SPL_X(x) crit_exit();
624 # else /* __DragonFly__ */
625 # if !SOLARIS && !defined(linux)
626 # define SPL_IMP(x) x = splimp()
627 # define SPL_NET(x) x = splnet()
628 # define SPL_X(x) (void) splx(x)
630 # endif /* __DragonFly__ */
631 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
632 # define PANIC(x,y) if (x) panic y
634 # define SLEEP(x,y) 1
636 # define PANIC(x,y) ;
637 # define ATOMIC_INC(x) (x)++
638 # define ATOMIC_DEC(x) (x)--
639 # define MUTEX_ENTER(x) ;
640 # define READ_ENTER(x) ;
641 # define MUTEX_INIT(x,y,z) ;
642 # define MUTEX_DESTROY(x) ;
643 # define WRITE_ENTER(x) ;
644 # define RW_UPGRADE(x) ;
645 # define MUTEX_DOWNGRADE(x) ;
646 # define RWLOCK_EXIT(x) ;
647 # define MUTEX_EXIT(x) ;
648 # define SPL_NET(x) ;
649 # define SPL_IMP(x) ;
652 # define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a))
653 # define KMALLOCS(a,b,c) (a) = (b)malloc(c)
654 # define KFREE(x) free(x)
655 # define KFREES(x,s) free(x)
656 # define FREE_MB_T(x) ;
657 # define GETUNIT(x, v) get_unit(x,v)
658 # define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
659 # define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0)
660 # define IRCOPYPTR ircopyptr
661 # define IWCOPYPTR iwcopyptr
662 # define IFNAME(x) get_ifname((struct ifnet *)x)
663 # define UIOMOVE(a,b,c,d) ipfuiomove(a,b,c,d)
664 # include <sys/time.h>
665 extern void m_copydata (mb_t *, int, int, caddr_t);
666 extern int ipfuiomove (caddr_t, int, int, struct uio *);
670 * These #ifdef's are here mainly for linux, but who knows, they may
671 * not be in other places or maybe one day linux will grow up and some
672 * of these will turn up there too.
675 # define ICMP_MINLEN 8
677 #ifndef ICMP_ECHOREPLY
678 # define ICMP_ECHOREPLY 0
681 # define ICMP_UNREACH 3
683 #ifndef ICMP_UNREACH_NET
684 # define ICMP_UNREACH_NET 0
686 #ifndef ICMP_UNREACH_HOST
687 # define ICMP_UNREACH_HOST 1
689 #ifndef ICMP_UNREACH_PROTOCOL
690 # define ICMP_UNREACH_PROTOCOL 2
692 #ifndef ICMP_UNREACH_PORT
693 # define ICMP_UNREACH_PORT 3
695 #ifndef ICMP_UNREACH_NEEDFRAG
696 # define ICMP_UNREACH_NEEDFRAG 4
698 #ifndef ICMP_UNREACH_SRCFAIL
699 # define ICMP_UNREACH_SRCFAIL 5
701 #ifndef ICMP_UNREACH_NET_UNKNOWN
702 # define ICMP_UNREACH_NET_UNKNOWN 6
704 #ifndef ICMP_UNREACH_HOST_UNKNOWN
705 # define ICMP_UNREACH_HOST_UNKNOWN 7
707 #ifndef ICMP_UNREACH_ISOLATED
708 # define ICMP_UNREACH_ISOLATED 8
710 #ifndef ICMP_UNREACH_NET_PROHIB
711 # define ICMP_UNREACH_NET_PROHIB 9
713 #ifndef ICMP_UNREACH_HOST_PROHIB
714 # define ICMP_UNREACH_HOST_PROHIB 10
716 #ifndef ICMP_UNREACH_TOSNET
717 # define ICMP_UNREACH_TOSNET 11
719 #ifndef ICMP_UNREACH_TOSHOST
720 # define ICMP_UNREACH_TOSHOST 12
722 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
723 # define ICMP_UNREACH_ADMIN_PROHIBIT 13
725 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
726 # define ICMP_UNREACH_HOST_PRECEDENCE 14
728 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
729 # define ICMP_UNREACH_PRECEDENCE_CUTOFF 15
731 #ifndef ICMP_SOURCEQUENCH
732 # define ICMP_SOURCEQUENCH 4
734 #ifndef ICMP_REDIRECT_NET
735 # define ICMP_REDIRECT_NET 0
737 #ifndef ICMP_REDIRECT_HOST
738 # define ICMP_REDIRECT_HOST 1
740 #ifndef ICMP_REDIRECT_TOSNET
741 # define ICMP_REDIRECT_TOSNET 2
743 #ifndef ICMP_REDIRECT_TOSHOST
744 # define ICMP_REDIRECT_TOSHOST 3
746 #ifndef ICMP_ALTHOSTADDR
747 # define ICMP_ALTHOSTADDR 6
749 #ifndef ICMP_TIMXCEED
750 # define ICMP_TIMXCEED 11
752 #ifndef ICMP_TIMXCEED_INTRANS
753 # define ICMP_TIMXCEED_INTRANS 0
755 #ifndef ICMP_TIMXCEED_REASS
756 # define ICMP_TIMXCEED_REASS 1
758 #ifndef ICMP_PARAMPROB
759 # define ICMP_PARAMPROB 12
761 #ifndef ICMP_PARAMPROB_ERRATPTR
762 # define ICMP_PARAMPROB_ERRATPTR 0
764 #ifndef ICMP_PARAMPROB_OPTABSENT
765 # define ICMP_PARAMPROB_OPTABSENT 1
767 #ifndef ICMP_PARAMPROB_LENGTH
768 # define ICMP_PARAMPROB_LENGTH 2
771 # define ICMP_TSTAMP 13
773 #ifndef ICMP_TSTAMPREPLY
774 # define ICMP_TSTAMPREPLY 14
777 # define ICMP_IREQ 15
779 #ifndef ICMP_IREQREPLY
780 # define ICMP_IREQREPLY 16
783 # define ICMP_MASKREQ 17
785 #ifndef ICMP_MASKREPLY
786 # define ICMP_MASKREPLY 18
788 #ifndef ICMP_TRACEROUTE
789 # define ICMP_TRACEROUTE 30
791 #ifndef ICMP_DATACONVERR
792 # define ICMP_DATACONVERR 31
794 #ifndef ICMP_MOBILE_REDIRECT
795 # define ICMP_MOBILE_REDIRECT 32
797 #ifndef ICMP_IPV6_WHEREAREYOU
798 # define ICMP_IPV6_WHEREAREYOU 33
800 #ifndef ICMP_IPV6_IAMHERE
801 # define ICMP_IPV6_IAMHERE 34
803 #ifndef ICMP_MOBILE_REGREQUEST
804 # define ICMP_MOBILE_REGREQUEST 35
806 #ifndef ICMP_MOBILE_REGREPLY
807 # define ICMP_MOBILE_REGREPLY 36
810 # define ICMP_SKIP 39
812 #ifndef ICMP_PHOTURIS
813 # define ICMP_PHOTURIS 40
815 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
816 # define ICMP_PHOTURIS_UNKNOWN_INDEX 1
818 #ifndef ICMP_PHOTURIS_AUTH_FAILED
819 # define ICMP_PHOTURIS_AUTH_FAILED 2
821 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
822 # define ICMP_PHOTURIS_DECRYPT_FAILED 3
828 # define IPOPT_MINOFF 4
831 # define IPOPT_COPIED(x) ((x)&0x80)
840 # define IP_MF ((u_short)0x2000)
843 # define ETHERTYPE_IP ((u_short)0x0800)
855 # define TH_PUSH 0x08
875 #ifndef IPOPT_SECURITY
876 # define IPOPT_SECURITY 130
879 # define IPOPT_LSRR 131
882 # define IPOPT_SATID 136
885 # define IPOPT_SSRR 137
887 #ifndef IPOPT_SECUR_UNCLASS
888 # define IPOPT_SECUR_UNCLASS ((u_short)0x0000)
890 #ifndef IPOPT_SECUR_CONFID
891 # define IPOPT_SECUR_CONFID ((u_short)0xf135)
893 #ifndef IPOPT_SECUR_EFTO
894 # define IPOPT_SECUR_EFTO ((u_short)0x789a)
896 #ifndef IPOPT_SECUR_MMMM
897 # define IPOPT_SECUR_MMMM ((u_short)0xbc4d)
899 #ifndef IPOPT_SECUR_RESTR
900 # define IPOPT_SECUR_RESTR ((u_short)0xaf13)
902 #ifndef IPOPT_SECUR_SECRET
903 # define IPOPT_SECUR_SECRET ((u_short)0xd788)
905 #ifndef IPOPT_SECUR_TOPSECRET
906 # define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5)
909 # define IPOPT_OLEN 1
912 # define IPPROTO_GRE 47 /* GRE encaps RFC 1701 */
915 # define IPPROTO_ESP 50
917 #ifndef IPPROTO_ICMPV6
918 # define IPPROTO_ICMPV6 58
922 #include <linux/in_systm.h>
926 #define TCPS_CLOSED 0 /* closed */
927 #define TCPS_LISTEN 1 /* listening for connection */
928 #define TCPS_SYN_SENT 2 /* active, have sent syn */
929 #define TCPS_SYN_RECEIVED 3 /* have send and received syn */
930 /* states < TCPS_ESTABLISHED are those where connections not established */
931 #define TCPS_ESTABLISHED 4 /* established */
932 #define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */
933 /* states > TCPS_CLOSE_WAIT are those where user has closed */
934 #define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */
935 #define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */
936 #define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */
937 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
938 #define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */
939 #define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */
948 #define FWRITE _IOC_WRITE
949 #define FREAD _IOC_READ
952 * mbuf related problems.
954 #define mtod(m,t) (t)((m)->data)
968 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
990 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
1005 struct in_addr ip_src;
1006 struct in_addr ip_dst;
1010 * Structure of an icmp header.
1012 typedef struct icmp {
1013 __u8 icmp_type; /* type of message, see below */
1014 __u8 icmp_code; /* type sub code */
1015 __u16 icmp_cksum; /* ones complement cksum of struct */
1017 __u8 ih_pptr; /* ICMP_PARAMPROB */
1018 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
1025 # define icmp_pptr icmp_hun.ih_pptr
1026 # define icmp_gwaddr icmp_hun.ih_gwaddr
1027 # define icmp_id icmp_hun.ih_idseq.icd_id
1028 # define icmp_seq icmp_hun.ih_idseq.icd_seq
1029 # define icmp_void icmp_hun.ih_void
1038 /* options and then 64 bits of data */
1043 # define icmp_otime icmp_dun.id_ts.its_otime
1044 # define icmp_rtime icmp_dun.id_ts.its_rtime
1045 # define icmp_ttime icmp_dun.id_ts.its_ttime
1046 # define icmp_ip icmp_dun.id_ip.idi_ip
1047 # define icmp_mask icmp_dun.id_mask
1048 # define icmp_data icmp_dun.id_data
1051 # ifndef LINUX_IPOVLY
1052 # define LINUX_IPOVLY
1054 caddr_t ih_next, ih_prev; /* for protocol sequence q's */
1055 u_char ih_x1; /* (unused) */
1056 u_char ih_pr; /* protocol */
1057 short ih_len; /* protocol length */
1058 struct in_addr ih_src; /* source internet address */
1059 struct in_addr ih_dst; /* destination internet address */
1064 __u8 ether_dhost[6];
1065 __u8 ether_shost[6];
1069 typedef struct uio {
1076 # define UIO_WRITE 1
1077 # define UIOMOVE(a, b, c, d) uiomove(a,b,c,d)
1080 * For masking struct ifnet onto struct device
1082 # define if_name name
1085 # define GETUNIT(x, v) dev_get(x)
1086 # define FREE_MB_T(m) kfree_skb(m, FREE_WRITE)
1087 # define uniqtime do_gettimeofday
1092 # include <linux/netdevice.h>
1097 # define bcmp(a,b,c) memcmp(a,b,c)
1098 # define bcopy(a,b,c) memcpy(b,a,c)
1099 # define bzero(a,c) memset(a,0,c)
1101 # define UNITNAME(n) dev_get((n))
1103 # define KMALLOC(a,b) (a) = (b)kmalloc(sizeof(*(a)), GFP_ATOMIC)
1104 # define KMALLOCS(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC)
1105 # define KFREE(x) kfree_s((x), sizeof(*(x)))
1106 # define KFREES(x,s) kfree_s((x), (s))
1107 #define IRCOPY(const void *a, void *b, size_t c) { \
1110 error = verify_area(VERIFY_READ, a ,c); \
1112 memcpy_fromfs(b, a, c); \
1115 static inline int IWCOPY(const void *a, void *b, size_t c)
1119 error = verify_area(VERIFY_WRITE, b, c);
1121 memcpy_tofs(b, a, c);
1124 static inline int IRCOPYPTR(const void *a, void *b, size_t c) {
1128 error = verify_area(VERIFY_READ, a ,sizeof(ca));
1130 memcpy_fromfs(ca, a, sizeof(ca));
1131 error = verify_area(VERIFY_READ, ca , c);
1133 memcpy_fromfs(b, ca, c);
1137 static inline int IWCOPYPTR(const void *a, void *b, size_t c) {
1142 error = verify_area(VERIFY_READ, b ,sizeof(ca));
1144 memcpy_fromfs(ca, b, sizeof(ca));
1145 error = verify_area(VERIFY_WRITE, ca, c);
1147 memcpy_tofs(ca, a, c);
1163 # include <linux/netdevice.h>
1166 # define ifnet device
1168 typedef struct tcphdr tcphdr_t;
1169 typedef struct udphdr udphdr_t;
1170 typedef struct icmp icmphdr_t;
1171 typedef struct ip ip_t;
1172 typedef struct ether_header ether_header_t;
1174 typedef struct tcpiphdr tcpiphdr_t;
1176 #if defined(hpux) || defined(linux)
1178 char ether_addr_octet[6];
1183 * XXX - This is one of those *awful* hacks which nobody likes
1191 #if (BSD >= 199306) && !defined(m_act)
1192 # define m_act m_nextpkt
1195 #ifndef ICMP_ROUTERADVERT
1196 # define ICMP_ROUTERADVERT 9
1198 #ifndef ICMP_ROUTERSOLICIT
1199 # define ICMP_ROUTERSOLICIT 10
1201 #undef ICMP_MAX_UNREACH
1202 #define ICMP_MAX_UNREACH 14
1204 #define ICMP_MAXTYPE 18
1206 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1207 * another IP header and then 64 bits of data, totalling 56. Of course,
1208 * the last 64 bits is dependant on that being available.
1210 #define ICMPERR_ICMPHLEN 8
1211 #define ICMPERR_IPICMPHLEN (20 + 8)
1212 #define ICMPERR_MINPKTLEN (20 + 8 + 20)
1213 #define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8)
1214 #define ICMP6_MINLEN 8
1215 #define ICMP6ERR_IPICMPHLEN (40 + 8)
1216 #define ICMP6ERR_MINPKTLEN (40 + 8 + 40)
1218 #ifndef ICMP6_DST_UNREACH
1219 # define ICMP6_DST_UNREACH 1
1221 #ifndef ICMP6_PACKET_TOO_BIG
1222 # define ICMP6_PACKET_TOO_BIG 2
1224 #ifndef ICMP6_TIME_EXCEEDED
1225 # define ICMP6_TIME_EXCEEDED 3
1227 #ifndef ICMP6_PARAM_PROB
1228 # define ICMP6_PARAM_PROB 4
1231 #ifndef ICMP6_ECHO_REQUEST
1232 # define ICMP6_ECHO_REQUEST 128
1234 #ifndef ICMP6_ECHO_REPLY
1235 # define ICMP6_ECHO_REPLY 129
1237 #ifndef ICMP6_MEMBERSHIP_QUERY
1238 # define ICMP6_MEMBERSHIP_QUERY 130
1240 #ifndef MLD6_LISTENER_QUERY
1241 # define MLD6_LISTENER_QUERY 130
1243 #ifndef ICMP6_MEMBERSHIP_REPORT
1244 # define ICMP6_MEMBERSHIP_REPORT 131
1246 #ifndef MLD6_LISTENER_REPORT
1247 # define MLD6_LISTENER_REPORT 131
1249 #ifndef ICMP6_MEMBERSHIP_REDUCTION
1250 # define ICMP6_MEMBERSHIP_REDUCTION 132
1252 #ifndef MLD6_LISTENER_DONE
1253 # define MLD6_LISTENER_DONE 132
1255 #ifndef ND_ROUTER_SOLICIT
1256 # define ND_ROUTER_SOLICIT 133
1258 #ifndef ND_ROUTER_ADVERT
1259 # define ND_ROUTER_ADVERT 134
1261 #ifndef ND_NEIGHBOR_SOLICIT
1262 # define ND_NEIGHBOR_SOLICIT 135
1264 #ifndef ND_NEIGHBOR_ADVERT
1265 # define ND_NEIGHBOR_ADVERT 136
1268 # define ND_REDIRECT 137
1270 #ifndef ICMP6_ROUTER_RENUMBERING
1271 # define ICMP6_ROUTER_RENUMBERING 138
1273 #ifndef ICMP6_WRUREQUEST
1274 # define ICMP6_WRUREQUEST 139
1276 #ifndef ICMP6_WRUREPLY
1277 # define ICMP6_WRUREPLY 140
1279 #ifndef ICMP6_FQDN_QUERY
1280 # define ICMP6_FQDN_QUERY 139
1282 #ifndef ICMP6_FQDN_REPLY
1283 # define ICMP6_FQDN_REPLY 140
1285 #ifndef ICMP6_NI_QUERY
1286 # define ICMP6_NI_QUERY 139
1288 #ifndef ICMP6_NI_REPLY
1289 # define ICMP6_NI_REPLY 140
1291 #ifndef MLD6_MTRACE_RESP
1292 # define MLD6_MTRACE_RESP 200
1295 # define MLD6_MTRACE 201
1297 #ifndef ICMP6_HADISCOV_REQUEST
1298 # define ICMP6_HADISCOV_REQUEST 202
1300 #ifndef ICMP6_HADISCOV_REPLY
1301 # define ICMP6_HADISCOV_REPLY 203
1303 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
1304 # define ICMP6_MOBILEPREFIX_SOLICIT 204
1306 #ifndef ICMP6_MOBILEPREFIX_ADVERT
1307 # define ICMP6_MOBILEPREFIX_ADVERT 205
1309 #ifndef ICMP6_MAXTYPE
1310 # define ICMP6_MAXTYPE 205
1313 #ifndef ICMP6_DST_UNREACH_NOROUTE
1314 # define ICMP6_DST_UNREACH_NOROUTE 0
1316 #ifndef ICMP6_DST_UNREACH_ADMIN
1317 # define ICMP6_DST_UNREACH_ADMIN 1
1319 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
1320 # define ICMP6_DST_UNREACH_NOTNEIGHBOR 2
1322 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
1323 # define ICMP6_DST_UNREACH_BEYONDSCOPE 2
1325 #ifndef ICMP6_DST_UNREACH_ADDR
1326 # define ICMP6_DST_UNREACH_ADDR 3
1328 #ifndef ICMP6_DST_UNREACH_NOPORT
1329 # define ICMP6_DST_UNREACH_NOPORT 4
1331 #ifndef ICMP6_TIME_EXCEED_TRANSIT
1332 # define ICMP6_TIME_EXCEED_TRANSIT 0
1334 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
1335 # define ICMP6_TIME_EXCEED_REASSEMBLY 1
1338 #ifndef ICMP6_NI_SUCCESS
1339 # define ICMP6_NI_SUCCESS 0
1341 #ifndef ICMP6_NI_REFUSED
1342 # define ICMP6_NI_REFUSED 1
1344 #ifndef ICMP6_NI_UNKNOWN
1345 # define ICMP6_NI_UNKNOWN 2
1348 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
1349 # define ICMP6_ROUTER_RENUMBERING_COMMAND 0
1351 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
1352 # define ICMP6_ROUTER_RENUMBERING_RESULT 1
1354 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1355 # define ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET 255
1358 #ifndef ICMP6_PARAMPROB_HEADER
1359 # define ICMP6_PARAMPROB_HEADER 0
1361 #ifndef ICMP6_PARAMPROB_NEXTHEADER
1362 # define ICMP6_PARAMPROB_NEXTHEADER 1
1364 #ifndef ICMP6_PARAMPROB_OPTION
1365 # define ICMP6_PARAMPROB_OPTION 2
1368 #ifndef ICMP6_NI_SUBJ_IPV6
1369 # define ICMP6_NI_SUBJ_IPV6 0
1371 #ifndef ICMP6_NI_SUBJ_FQDN
1372 # define ICMP6_NI_SUBJ_FQDN 1
1374 #ifndef ICMP6_NI_SUBJ_IPV4
1375 # define ICMP6_NI_SUBJ_IPV4 2
1379 * ECN is a new addition to TCP - RFC 2481
1382 # define TH_ECN 0x40
1385 # define TH_CWR 0x80
1387 #define TH_ECNALL (TH_ECN|TH_CWR)
1389 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECN|TH_CWR)
1391 #endif /* __IP_COMPAT_H__ */