ip_compat.h revision 64580
153642Sguido/* 260857Sdarrenr * Copyright (C) 1993-2000 by Darren Reed. 353642Sguido * 453642Sguido * Redistribution and use in source and binary forms are permitted 553642Sguido * provided that this notice is preserved and due credit is given 653642Sguido * to the original author and the contributors. 753642Sguido * 853642Sguido * @(#)ip_compat.h 1.8 1/14/96 955929Sguido * $Id: ip_compat.h,v 2.1.2.3 1999/11/18 13:55:26 darrenr Exp $ 1057126Sguido * $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_compat.h 64580 2000-08-13 04:31:06Z darrenr $ 1153642Sguido */ 1253642Sguido 1353642Sguido#ifndef __IP_COMPAT_H__ 1453642Sguido#define __IP_COMPAT_H__ 1553642Sguido 1653642Sguido#ifndef __P 1753642Sguido# ifdef __STDC__ 1853642Sguido# define __P(x) x 1953642Sguido# else 2053642Sguido# define __P(x) () 2153642Sguido# endif 2253642Sguido#endif 2353642Sguido#ifndef __STDC__ 2453642Sguido# undef const 2553642Sguido# define const 2653642Sguido#endif 2753642Sguido 2853642Sguido#ifndef SOLARIS 2953642Sguido#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 3053642Sguido#endif 3160857Sdarrenr#if SOLARIS2 >= 8 3260857Sdarrenr# ifndef USE_INET6 3360857Sdarrenr# define USE_INET6 3460857Sdarrenr# endif 3560857Sdarrenr#endif 3653642Sguido 3753642Sguido#if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__) 3853642Sguido# undef KERNEL 3953642Sguido# undef _KERNEL 4053642Sguido# undef __KERNEL__ 4153642Sguido# define KERNEL 4253642Sguido# define _KERNEL 4353642Sguido# define __KERNEL__ 4453642Sguido#endif 4553642Sguido 4653642Sguido#if defined(__SVR4) || defined(__svr4__) || defined(__sgi) 4753642Sguido#define index strchr 4853642Sguido# if !defined(KERNEL) 4953642Sguido# define bzero(a,b) memset(a,0,b) 5053642Sguido# define bcmp memcmp 5153642Sguido# define bcopy(a,b,c) memmove(b,a,c) 5253642Sguido# endif 5353642Sguido#endif 5453642Sguido 5553642Sguido#ifndef offsetof 5653642Sguido#define offsetof(t,m) (int)((&((t *)0L)->m)) 5753642Sguido#endif 5853642Sguido 5953642Sguido#if defined(__sgi) || defined(bsdi) 6053642Sguidostruct ether_addr { 6153642Sguido u_char ether_addr_octet[6]; 6253642Sguido}; 6353642Sguido#endif 6453642Sguido 6553642Sguido#if defined(__sgi) && !defined(IPFILTER_LKM) 6653642Sguido# ifdef __STDC__ 6753642Sguido# define IPL_EXTERN(ep) ipfilter##ep 6853642Sguido# else 6953642Sguido# define IPL_EXTERN(ep) ipfilter/**/ep 7053642Sguido# endif 7153642Sguido#else 7253642Sguido# ifdef __STDC__ 7353642Sguido# define IPL_EXTERN(ep) ipl##ep 7453642Sguido# else 7553642Sguido# define IPL_EXTERN(ep) ipl/**/ep 7653642Sguido# endif 7753642Sguido#endif 7853642Sguido 7953642Sguido#ifdef linux 8053642Sguido# include <sys/sysmacros.h> 8153642Sguido#endif 8253642Sguido#if SOLARIS 8353642Sguido# define MTYPE(m) ((m)->b_datap->db_type) 8453642Sguido# include <sys/isa_defs.h> 8553642Sguido# include <sys/ioccom.h> 8653642Sguido# include <sys/sysmacros.h> 8753642Sguido# include <sys/kmem.h> 8853642Sguido/* 8953642Sguido * because Solaris 2 defines these in two places :-/ 9053642Sguido */ 9153642Sguido# undef IPOPT_EOL 9253642Sguido# undef IPOPT_NOP 9353642Sguido# undef IPOPT_LSRR 9453642Sguido# undef IPOPT_RR 9553642Sguido# undef IPOPT_SSRR 9653642Sguido# ifndef KERNEL 9753642Sguido# define _KERNEL 9853642Sguido# undef RES_INIT 9960857Sdarrenr# if SOLARIS2 >= 8 10060857Sdarrenr# include <netinet/ip6.h> 10160857Sdarrenr# endif 10253642Sguido# include <inet/common.h> 10353642Sguido# include <inet/ip.h> 10453642Sguido# include <inet/ip_ire.h> 10553642Sguido# undef _KERNEL 10653642Sguido# else /* _KERNEL */ 10760857Sdarrenr# if SOLARIS2 >= 8 10860857Sdarrenr# include <netinet/ip6.h> 10960857Sdarrenr# endif 11053642Sguido# include <inet/common.h> 11153642Sguido# include <inet/ip.h> 11253642Sguido# include <inet/ip_ire.h> 11353642Sguido# endif /* _KERNEL */ 11455929Sguido# if SOLARIS2 >= 8 11560857Sdarrenr# include <inet/ip_if.h> 11655929Sguido# include <netinet/ip6.h> 11755929Sguido# define ipif_local_addr ipif_lcl_addr 11860857Sdarrenr/* Only defined in private include file */ 11960857Sdarrenr# ifndef V4_PART_OF_V6 12060857Sdarrenr# define V4_PART_OF_V6(v6) v6.s6_addr32[3] 12160857Sdarrenr# endif 12255929Sguido# endif 12353642Sguido#else 12453642Sguido# if !defined(__sgi) 12553642Sguidotypedef int minor_t; 12653642Sguido#endif 12753642Sguido#endif /* SOLARIS */ 12853642Sguido#define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h))) 12953642Sguido 13064580Sdarrenr#if defined(__FreeBSD__) && (__FreeBSD__ >= 5) && defined(_KERNEL) 13164580Sdarrenr# include <machine/in_cksum.h> 13264580Sdarrenr#endif 13364580Sdarrenr 13453642Sguido#ifndef IP_OFFMASK 13553642Sguido#define IP_OFFMASK 0x1fff 13653642Sguido#endif 13753642Sguido 13853642Sguido#if BSD > 199306 13953642Sguido# define USE_QUAD_T 14053642Sguido# define U_QUAD_T u_quad_t 14153642Sguido# define QUAD_T quad_t 14253642Sguido#else /* BSD > 199306 */ 14353642Sguido# define U_QUAD_T u_long 14453642Sguido# define QUAD_T long 14553642Sguido#endif /* BSD > 199306 */ 14653642Sguido 14760857Sdarrenr 14853642Sguido/* 14953642Sguido * These operating systems already take care of the problem for us. 15053642Sguido */ 15153642Sguido#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \ 15253642Sguido defined(__sgi) 15353642Sguidotypedef u_int32_t u_32_t; 15460857Sdarrenr# if defined(_KERNEL) && !defined(IPFILTER_LKM) 15560857Sdarrenr# if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000) 15660857Sdarrenr# include "opt_inet.h" 15760857Sdarrenr# endif 15860857Sdarrenr# if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \ 15960857Sdarrenr !defined(KLD_MODULE) 16060857Sdarrenr# include "opt_inet6.h" 16160857Sdarrenr# endif 16260857Sdarrenr# ifdef INET6 16360857Sdarrenr# define USE_INET6 16460857Sdarrenr# endif 16560857Sdarrenr# endif 16653642Sguido#else 16753642Sguido/* 16853642Sguido * Really, any arch where sizeof(long) != sizeof(int). 16953642Sguido */ 17053642Sguido# if defined(__alpha__) || defined(__alpha) || defined(_LP64) 17153642Sguidotypedef unsigned int u_32_t; 17253642Sguido# else 17360857Sdarrenr# if SOLARIS2 >= 6 17460857Sdarrenrtypedef uint32_t u_32_t; 17560857Sdarrenr# else 17660857Sdarrenrtypedef unsigned int u_32_t; 17760857Sdarrenr# endif 17853642Sguido# endif 17953642Sguido#endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */ 18053642Sguido 18160857Sdarrenr#ifdef USE_INET6 18260857Sdarrenr# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 18360857Sdarrenr# include <netinet/ip6.h> 18460857Sdarrenr# ifdef _KERNEL 18560857Sdarrenr# include <netinet6/ip6_var.h> 18660857Sdarrenr# endif 18760857Sdarrenrtypedef struct ip6_hdr ip6_t; 18860857Sdarrenr# endif 18960857Sdarrenrunion i6addr { 19060857Sdarrenr u_32_t i6[4]; 19160857Sdarrenr struct in_addr in4; 19260857Sdarrenr struct in6_addr in6; 19360857Sdarrenr}; 19460857Sdarrenr#else 19560857Sdarrenrunion i6addr { 19660857Sdarrenr u_32_t i6[4]; 19760857Sdarrenr struct in_addr in4; 19860857Sdarrenr}; 19960857Sdarrenr#endif 20060857Sdarrenr 20160857Sdarrenr#define IP6CMP(a,b) bcmp((char *)&(a), (char *)&(b), sizeof(a)) 20260857Sdarrenr#define IP6EQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) == 0) 20360857Sdarrenr#define IP6NEQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) != 0) 20460857Sdarrenr 20553642Sguido#ifndef MAX 20653642Sguido#define MAX(a,b) (((a) > (b)) ? (a) : (b)) 20753642Sguido#endif 20853642Sguido 20953642Sguido/* 21053642Sguido * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108. 21153642Sguido * 21253642Sguido * Basic Option 21353642Sguido * 21453642Sguido * 00000001 - (Reserved 4) 21553642Sguido * 00111101 - Top Secret 21653642Sguido * 01011010 - Secret 21753642Sguido * 10010110 - Confidential 21853642Sguido * 01100110 - (Reserved 3) 21953642Sguido * 11001100 - (Reserved 2) 22053642Sguido * 10101011 - Unclassified 22153642Sguido * 11110001 - (Reserved 1) 22253642Sguido */ 22353642Sguido#define IPSO_CLASS_RES4 0x01 22453642Sguido#define IPSO_CLASS_TOPS 0x3d 22553642Sguido#define IPSO_CLASS_SECR 0x5a 22653642Sguido#define IPSO_CLASS_CONF 0x96 22753642Sguido#define IPSO_CLASS_RES3 0x66 22853642Sguido#define IPSO_CLASS_RES2 0xcc 22953642Sguido#define IPSO_CLASS_UNCL 0xab 23053642Sguido#define IPSO_CLASS_RES1 0xf1 23153642Sguido 23253642Sguido#define IPSO_AUTH_GENSER 0x80 23353642Sguido#define IPSO_AUTH_ESI 0x40 23453642Sguido#define IPSO_AUTH_SCI 0x20 23553642Sguido#define IPSO_AUTH_NSA 0x10 23653642Sguido#define IPSO_AUTH_DOE 0x08 23753642Sguido#define IPSO_AUTH_UN 0x06 23853642Sguido#define IPSO_AUTH_FTE 0x01 23953642Sguido 24053642Sguido/* 24153642Sguido * IP option #defines 24253642Sguido */ 24353642Sguido/*#define IPOPT_RR 7 */ 24453642Sguido#define IPOPT_ZSU 10 /* ZSU */ 24553642Sguido#define IPOPT_MTUP 11 /* MTUP */ 24653642Sguido#define IPOPT_MTUR 12 /* MTUR */ 24753642Sguido#define IPOPT_ENCODE 15 /* ENCODE */ 24853642Sguido/*#define IPOPT_TS 68 */ 24953642Sguido#define IPOPT_TR 82 /* TR */ 25053642Sguido/*#define IPOPT_SECURITY 130 */ 25153642Sguido/*#define IPOPT_LSRR 131 */ 25253642Sguido#define IPOPT_E_SEC 133 /* E-SEC */ 25353642Sguido#define IPOPT_CIPSO 134 /* CIPSO */ 25453642Sguido/*#define IPOPT_SATID 136 */ 25553642Sguido#ifndef IPOPT_SID 25653642Sguido# define IPOPT_SID IPOPT_SATID 25753642Sguido#endif 25853642Sguido/*#define IPOPT_SSRR 137 */ 25953642Sguido#define IPOPT_ADDEXT 147 /* ADDEXT */ 26053642Sguido#define IPOPT_VISA 142 /* VISA */ 26153642Sguido#define IPOPT_IMITD 144 /* IMITD */ 26253642Sguido#define IPOPT_EIP 145 /* EIP */ 26353642Sguido#define IPOPT_FINN 205 /* FINN */ 26453642Sguido 26553642Sguido 26660857Sdarrenr#if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL)) 26753642Sguido# if __FreeBSD__ < 3 26853642Sguido# include <machine/spl.h> 26960857Sdarrenr# else 27060857Sdarrenr# if __FreeBSD__ == 3 27160857Sdarrenr# if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL) 27260857Sdarrenr# define ACTUALLY_LKM_NOT_KERNEL 27360857Sdarrenr# endif 27460857Sdarrenr# endif 27553642Sguido# endif 27653642Sguido#endif /* __FreeBSD__ && KERNEL */ 27753642Sguido 27853642Sguido/* 27953642Sguido * Build some macros and #defines to enable the same code to compile anywhere 28053642Sguido * Well, that's the idea, anyway :-) 28153642Sguido */ 28260857Sdarrenr#if !SOLARIS || (SOLARIS2 < 6) || !defined(KERNEL) 28360857Sdarrenr# define ATOMIC_INCL ATOMIC_INC 28460857Sdarrenr# define ATOMIC_INC64 ATOMIC_INC 28560857Sdarrenr# define ATOMIC_INC32 ATOMIC_INC 28660857Sdarrenr# define ATOMIC_INC16 ATOMIC_INC 28760857Sdarrenr# define ATOMIC_DECL ATOMIC_DEC 28860857Sdarrenr# define ATOMIC_DEC64 ATOMIC_DEC 28960857Sdarrenr# define ATOMIC_DEC32 ATOMIC_DEC 29060857Sdarrenr# define ATOMIC_DEC16 ATOMIC_DEC 29160857Sdarrenr#endif 29253642Sguido#ifdef KERNEL 29353642Sguido# if SOLARIS 29460857Sdarrenr# if SOLARIS2 >= 6 29560857Sdarrenr# include <sys/atomic.h> 29660857Sdarrenr# if SOLARIS2 == 6 29760857Sdarrenr# define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1) 29860857Sdarrenr# define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1) 29960857Sdarrenr# else 30060857Sdarrenr# define ATOMIC_INCL(x) atomic_add_long(&(x), 1) 30160857Sdarrenr# define ATOMIC_DECL(x) atomic_add_long(&(x), -1) 30260857Sdarrenr# endif 30360857Sdarrenr# define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1) 30460857Sdarrenr# define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1) 30560857Sdarrenr# define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1) 30660857Sdarrenr# define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1) 30760857Sdarrenr# define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1) 30860857Sdarrenr# define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1) 30960857Sdarrenr# else 31060857Sdarrenr# define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \ 31153642Sguido mutex_exit(&ipf_rw); } 31260857Sdarrenr# define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \ 31353642Sguido mutex_exit(&ipf_rw); } 31460857Sdarrenr# endif 31553642Sguido# define MUTEX_ENTER(x) mutex_enter(x) 31653642Sguido# if 1 31753642Sguido# define KRWLOCK_T krwlock_t 31853642Sguido# define READ_ENTER(x) rw_enter(x, RW_READER) 31953642Sguido# define WRITE_ENTER(x) rw_enter(x, RW_WRITER) 32053642Sguido# define RW_UPGRADE(x) { if (rw_tryupgrade(x) == 0) { \ 32153642Sguido rw_exit(x); \ 32253642Sguido rw_enter(x, RW_WRITER); } \ 32353642Sguido } 32453642Sguido# define MUTEX_DOWNGRADE(x) rw_downgrade(x) 32553642Sguido# define RWLOCK_INIT(x, y, z) rw_init((x), (y), RW_DRIVER, (z)) 32653642Sguido# define RWLOCK_EXIT(x) rw_exit(x) 32753642Sguido# define RW_DESTROY(x) rw_destroy(x) 32853642Sguido# else 32953642Sguido# define KRWLOCK_T kmutex_t 33053642Sguido# define READ_ENTER(x) mutex_enter(x) 33153642Sguido# define WRITE_ENTER(x) mutex_enter(x) 33253642Sguido# define MUTEX_DOWNGRADE(x) ; 33353642Sguido# define RWLOCK_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z)) 33453642Sguido# define RWLOCK_EXIT(x) mutex_exit(x) 33553642Sguido# define RW_DESTROY(x) mutex_destroy(x) 33653642Sguido# endif 33760857Sdarrenr# define MUTEX_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z)) 33860857Sdarrenr# define MUTEX_DESTROY(x) mutex_destroy(x) 33953642Sguido# define MUTEX_EXIT(x) mutex_exit(x) 34053642Sguido# define MTOD(m,t) (t)((m)->b_rptr) 34153642Sguido# define IRCOPY(a,b,c) copyin((a), (b), (c)) 34253642Sguido# define IWCOPY(a,b,c) copyout((a), (b), (c)) 34360857Sdarrenr# define IRCOPYPTR ircopyptr 34460857Sdarrenr# define IWCOPYPTR iwcopyptr 34553642Sguido# define FREE_MB_T(m) freemsg(m) 34653642Sguido# define SPL_NET(x) ; 34753642Sguido# define SPL_IMP(x) ; 34853642Sguido# undef SPL_X 34953642Sguido# define SPL_X(x) ; 35053642Sguido# ifdef sparc 35153642Sguido# define ntohs(x) (x) 35253642Sguido# define ntohl(x) (x) 35353642Sguido# define htons(x) (x) 35453642Sguido# define htonl(x) (x) 35553642Sguido# endif /* sparc */ 35653642Sguido# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 35753642Sguido# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 35853642Sguido# define GET_MINOR(x) getminor(x) 35953642Sguidotypedef struct qif { 36053642Sguido struct qif *qf_next; 36153642Sguido ill_t *qf_ill; 36253642Sguido kmutex_t qf_lock; 36353642Sguido void *qf_iptr; 36453642Sguido void *qf_optr; 36553642Sguido queue_t *qf_in; 36653642Sguido queue_t *qf_out; 36753642Sguido struct qinit *qf_wqinfo; 36853642Sguido struct qinit *qf_rqinfo; 36953642Sguido struct qinit qf_wqinit; 37053642Sguido struct qinit qf_rqinit; 37153642Sguido mblk_t *qf_m; /* These three fields are for passing data up from */ 37253642Sguido queue_t *qf_q; /* fr_qin and fr_qout to the packet processing. */ 37353642Sguido size_t qf_off; 37453642Sguido size_t qf_len; /* this field is used for in ipfr_fastroute */ 37553642Sguido char qf_name[8]; 37653642Sguido /* 37753642Sguido * in case the ILL has disappeared... 37853642Sguido */ 37953642Sguido size_t qf_hl; /* header length */ 38060857Sdarrenr int qf_sap; 38153642Sguido} qif_t; 38260857Sdarrenrextern ill_t *get_unit __P((char *, int)); 38360857Sdarrenr# define GETUNIT(n, v) get_unit(n, v) 38460857Sdarrenr# define IFNAME(x) ((ill_t *)x)->ill_name 38553642Sguido# else /* SOLARIS */ 38653642Sguido# if defined(__sgi) 38753642Sguido# define hz HZ 38853642Sguido# include <sys/ksynch.h> 38953642Sguido# define IPF_LOCK_PL plhi 39053642Sguido# include <sys/sema.h> 39153642Sguido#undef kmutex_t 39253642Sguidotypedef struct { 39353642Sguido lock_t *l; 39453642Sguido int pl; 39553642Sguido} kmutex_t; 39653642Sguido# define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ 39753642Sguido (x)++; MUTEX_EXIT(&ipf_rw); } 39853642Sguido# define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ 39953642Sguido (x)--; MUTEX_EXIT(&ipf_rw); } 40053642Sguido# define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL); 40153642Sguido# define KRWLOCK_T kmutex_t 40253642Sguido# define READ_ENTER(x) MUTEX_ENTER(x) 40353642Sguido# define WRITE_ENTER(x) MUTEX_ENTER(x) 40453642Sguido# define RW_UPGRADE(x) ; 40553642Sguido# define MUTEX_DOWNGRADE(x) ; 40660857Sdarrenr# define RWLOCK_EXIT(x) MUTEX_EXIT(x) 40760857Sdarrenr# define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl); 40860857Sdarrenr# define MUTEX_INIT(x,y,z) (x).l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP) 40960857Sdarrenr# define MUTEX_DESTROY(x) LOCK_DEALLOC((x).l) 41053642Sguido# else /* __sgi */ 41153642Sguido# define ATOMIC_INC(x) (x)++ 41253642Sguido# define ATOMIC_DEC(x) (x)-- 41353642Sguido# define MUTEX_ENTER(x) ; 41460857Sdarrenr# define READ_ENTER(x) ; 41560857Sdarrenr# define WRITE_ENTER(x) ; 41660857Sdarrenr# define RW_UPGRADE(x) ; 41753642Sguido# define MUTEX_DOWNGRADE(x) ; 41860857Sdarrenr# define RWLOCK_EXIT(x) ; 41960857Sdarrenr# define MUTEX_EXIT(x) ; 42060857Sdarrenr# define MUTEX_INIT(x,y,z) ; 42160857Sdarrenr# define MUTEX_DESTROY(x) ; 42253642Sguido# endif /* __sgi */ 42353642Sguido# ifndef linux 42453642Sguido# define FREE_MB_T(m) m_freem(m) 42553642Sguido# define MTOD(m,t) mtod(m,t) 42660857Sdarrenr# define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 42760857Sdarrenr# define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 42860857Sdarrenr# define IRCOPYPTR ircopyptr 42960857Sdarrenr# define IWCOPYPTR iwcopyptr 43053642Sguido# endif /* !linux */ 43153642Sguido# endif /* SOLARIS */ 43253642Sguido 43353642Sguido# ifdef sun 43453642Sguido# if !SOLARIS 43553642Sguido# include <sys/kmem_alloc.h> 43660857Sdarrenr# define GETUNIT(n, v) ifunit(n, IFNAMSIZ) 43760857Sdarrenr# define IFNAME(x) ((struct ifnet *)x)->if_name 43853642Sguido# endif 43953642Sguido# else 44053642Sguido# ifndef linux 44160857Sdarrenr# define GETUNIT(n, v) ifunit(n) 44260857Sdarrenr# if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ 44360857Sdarrenr (defined(OpenBSD) && (OpenBSD >= 199603)) 44460857Sdarrenr# define IFNAME(x) ((struct ifnet *)x)->if_xname 44560857Sdarrenr# else 44660857Sdarrenr# define IFNAME(x) ((struct ifnet *)x)->if_name 44760857Sdarrenr# endif 44853642Sguido# endif 44953642Sguido# endif /* sun */ 45053642Sguido 45153642Sguido# if defined(sun) && !defined(linux) || defined(__sgi) 45253642Sguido# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 45353642Sguido# define SLEEP(id, n) sleep((id), PZERO+1) 45453642Sguido# define WAKEUP(id) wakeup(id) 45553642Sguido# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 45653642Sguido# define KFREES(x,s) kmem_free((char *)(x), (s)) 45753642Sguido# if !SOLARIS 45853642Sguidoextern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 45953642Sguidoextern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 46053642Sguido# endif 46153642Sguido# ifdef __sgi 46253642Sguido# include <sys/kmem.h> 46353642Sguido# include <sys/ddi.h> 46453642Sguido# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 46553642Sguido# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 46653642Sguido# define GET_MINOR(x) getminor(x) 46753642Sguido# else 46853642Sguido# if !SOLARIS 46953642Sguido# define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \ 47053642Sguido KMEM_NOSLEEP) 47153642Sguido# define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP) 47253642Sguido# endif /* SOLARIS */ 47353642Sguido# endif /* __sgi */ 47453642Sguido# endif /* sun && !linux */ 47553642Sguido# ifndef GET_MINOR 47653642Sguido# define GET_MINOR(x) minor(x) 47753642Sguido# endif 47853642Sguido# if (BSD >= 199306) || defined(__FreeBSD__) 47953642Sguido# include <vm/vm.h> 48053642Sguido# if !defined(__FreeBSD__) || (defined (__FreeBSD__) && __FreeBSD__>=3) 48153642Sguido# include <vm/vm_extern.h> 48253642Sguido# include <sys/proc.h> 48353642Sguidoextern vm_map_t kmem_map; 48453642Sguido# else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */ 48553642Sguido# include <vm/vm_kern.h> 48653642Sguido# endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */ 48753642Sguido# ifdef M_PFIL 48853642Sguido# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT) 48953642Sguido# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT) 49053642Sguido# define KFREE(x) FREE((x), M_PFIL) 49153642Sguido# define KFREES(x,s) FREE((x), M_PFIL) 49253642Sguido# else 49353642Sguido# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT) 49453642Sguido# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT) 49553642Sguido# define KFREE(x) FREE((x), M_TEMP) 49653642Sguido# define KFREES(x,s) FREE((x), M_TEMP) 49753642Sguido# endif /* M_PFIL */ 49853642Sguido# define UIOMOVE(a,b,c,d) uiomove(a,b,d) 49953642Sguido# define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0) 50053642Sguido# define WAKEUP(id) wakeup(id) 50153642Sguido# endif /* BSD */ 50253642Sguido# if defined(NetBSD) && NetBSD <= 1991011 && NetBSD >= 199407 50353642Sguido# define SPL_NET(x) x = splsoftnet() 50453642Sguido# define SPL_X(x) (void) splx(x) 50553642Sguido# else 50653642Sguido# if !SOLARIS && !defined(linux) 50753642Sguido# define SPL_IMP(x) x = splimp() 50853642Sguido# define SPL_NET(x) x = splnet() 50953642Sguido# define SPL_X(x) (void) splx(x) 51053642Sguido# endif 51153642Sguido# endif /* NetBSD && NetBSD <= 1991011 && NetBSD >= 199407 */ 51253642Sguido# define PANIC(x,y) if (x) panic y 51353642Sguido#else /* KERNEL */ 51453642Sguido# define SLEEP(x,y) ; 51553642Sguido# define WAKEUP(x) ; 51653642Sguido# define PANIC(x,y) ; 51753642Sguido# define ATOMIC_INC(x) (x)++ 51853642Sguido# define ATOMIC_DEC(x) (x)-- 51953642Sguido# define MUTEX_ENTER(x) ; 52053642Sguido# define READ_ENTER(x) ; 52160857Sdarrenr# define MUTEX_INIT(x,y,z) ; 52260857Sdarrenr# define MUTEX_DESTROY(x) ; 52353642Sguido# define WRITE_ENTER(x) ; 52453642Sguido# define RW_UPGRADE(x) ; 52553642Sguido# define MUTEX_DOWNGRADE(x) ; 52653642Sguido# define RWLOCK_EXIT(x) ; 52753642Sguido# define MUTEX_EXIT(x) ; 52853642Sguido# define SPL_NET(x) ; 52953642Sguido# define SPL_IMP(x) ; 53053642Sguido# undef SPL_X 53153642Sguido# define SPL_X(x) ; 53253642Sguido# define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a)) 53353642Sguido# define KMALLOCS(a,b,c) (a) = (b)malloc(c) 53453642Sguido# define KFREE(x) free(x) 53553642Sguido# define KFREES(x,s) free(x) 53660857Sdarrenr# define GETUNIT(x, v) get_unit(x,v) 53760857Sdarrenr# define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 53860857Sdarrenr# define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 53960857Sdarrenr# define IRCOPYPTR ircopyptr 54060857Sdarrenr# define IWCOPYPTR iwcopyptr 54153642Sguido#endif /* KERNEL */ 54253642Sguido 54353642Sguido#if SOLARIS 54453642Sguidotypedef mblk_t mb_t; 54553642Sguido# if SOLARIS2 >= 7 54653642Sguido# ifdef lint 54753642Sguido# define ALIGN32(ptr) (ptr ? 0L : 0L) 54853642Sguido# define ALIGN16(ptr) (ptr ? 0L : 0L) 54953642Sguido# else 55053642Sguido# define ALIGN32(ptr) (ptr) 55153642Sguido# define ALIGN16(ptr) (ptr) 55253642Sguido# endif 55353642Sguido# endif 55453642Sguido#else 55553642Sguido# ifdef linux 55653642Sguido# ifndef kernel 55753642Sguidotypedef struct mb { 55853642Sguido struct mb *next; 55953642Sguido u_int len; 56053642Sguido u_char *data; 56153642Sguido} mb_t; 56253642Sguido# else 56353642Sguidotypedef struct sk_buff mb_t; 56453642Sguido# endif 56553642Sguido# else 56653642Sguidotypedef struct mbuf mb_t; 56753642Sguido# endif 56853642Sguido#endif /* SOLARIS */ 56953642Sguido 57053642Sguido#if defined(linux) || defined(__sgi) 57153642Sguido/* 57253642Sguido * These #ifdef's are here mainly for linux, but who knows, they may 57353642Sguido * not be in other places or maybe one day linux will grow up and some 57453642Sguido * of these will turn up there too. 57553642Sguido */ 57653642Sguido#ifndef ICMP_MINLEN 57753642Sguido# define ICMP_MINLEN 8 57853642Sguido#endif 57953642Sguido#ifndef ICMP_UNREACH 58053642Sguido# define ICMP_UNREACH ICMP_DEST_UNREACH 58153642Sguido#endif 58253642Sguido#ifndef ICMP_SOURCEQUENCH 58353642Sguido# define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH 58453642Sguido#endif 58553642Sguido#ifndef ICMP_TIMXCEED 58653642Sguido# define ICMP_TIMXCEED ICMP_TIME_EXCEEDED 58753642Sguido#endif 58853642Sguido#ifndef ICMP_PARAMPROB 58953642Sguido# define ICMP_PARAMPROB ICMP_PARAMETERPROB 59053642Sguido#endif 59153642Sguido#ifndef ICMP_TSTAMP 59253642Sguido# define ICMP_TSTAMP ICMP_TIMESTAMP 59353642Sguido#endif 59453642Sguido#ifndef ICMP_TSTAMPREPLY 59553642Sguido# define ICMP_TSTAMPREPLY ICMP_TIMESTAMPREPLY 59653642Sguido#endif 59753642Sguido#ifndef ICMP_IREQ 59853642Sguido# define ICMP_IREQ ICMP_INFO_REQUEST 59953642Sguido#endif 60053642Sguido#ifndef ICMP_IREQREPLY 60153642Sguido# define ICMP_IREQREPLY ICMP_INFO_REPLY 60253642Sguido#endif 60353642Sguido#ifndef ICMP_MASKREQ 60453642Sguido# define ICMP_MASKREQ ICMP_ADDRESS 60553642Sguido#endif 60653642Sguido#ifndef ICMP_MASKREPLY 60753642Sguido# define ICMP_MASKREPLY ICMP_ADDRESSREPLY 60853642Sguido#endif 60953642Sguido#ifndef IPVERSION 61053642Sguido# define IPVERSION 4 61153642Sguido#endif 61253642Sguido#ifndef IPOPT_MINOFF 61353642Sguido# define IPOPT_MINOFF 4 61453642Sguido#endif 61553642Sguido#ifndef IPOPT_COPIED 61653642Sguido# define IPOPT_COPIED(x) ((x)&0x80) 61753642Sguido#endif 61853642Sguido#ifndef IPOPT_EOL 61953642Sguido# define IPOPT_EOL 0 62053642Sguido#endif 62153642Sguido#ifndef IPOPT_NOP 62253642Sguido# define IPOPT_NOP 1 62353642Sguido#endif 62453642Sguido#ifndef IP_MF 62553642Sguido# define IP_MF ((u_short)0x2000) 62653642Sguido#endif 62753642Sguido#ifndef ETHERTYPE_IP 62853642Sguido# define ETHERTYPE_IP ((u_short)0x0800) 62953642Sguido#endif 63053642Sguido#ifndef TH_FIN 63153642Sguido# define TH_FIN 0x01 63253642Sguido#endif 63353642Sguido#ifndef TH_SYN 63453642Sguido# define TH_SYN 0x02 63553642Sguido#endif 63653642Sguido#ifndef TH_RST 63753642Sguido# define TH_RST 0x04 63853642Sguido#endif 63953642Sguido#ifndef TH_PUSH 64053642Sguido# define TH_PUSH 0x08 64153642Sguido#endif 64253642Sguido#ifndef TH_ACK 64353642Sguido# define TH_ACK 0x10 64453642Sguido#endif 64553642Sguido#ifndef TH_URG 64653642Sguido# define TH_URG 0x20 64753642Sguido#endif 64853642Sguido#ifndef IPOPT_EOL 64953642Sguido# define IPOPT_EOL 0 65053642Sguido#endif 65153642Sguido#ifndef IPOPT_NOP 65253642Sguido# define IPOPT_NOP 1 65353642Sguido#endif 65453642Sguido#ifndef IPOPT_RR 65553642Sguido# define IPOPT_RR 7 65653642Sguido#endif 65753642Sguido#ifndef IPOPT_TS 65853642Sguido# define IPOPT_TS 68 65953642Sguido#endif 66053642Sguido#ifndef IPOPT_SECURITY 66153642Sguido# define IPOPT_SECURITY 130 66253642Sguido#endif 66353642Sguido#ifndef IPOPT_LSRR 66453642Sguido# define IPOPT_LSRR 131 66553642Sguido#endif 66653642Sguido#ifndef IPOPT_SATID 66753642Sguido# define IPOPT_SATID 136 66853642Sguido#endif 66953642Sguido#ifndef IPOPT_SSRR 67053642Sguido# define IPOPT_SSRR 137 67153642Sguido#endif 67253642Sguido#ifndef IPOPT_SECUR_UNCLASS 67353642Sguido# define IPOPT_SECUR_UNCLASS ((u_short)0x0000) 67453642Sguido#endif 67553642Sguido#ifndef IPOPT_SECUR_CONFID 67653642Sguido# define IPOPT_SECUR_CONFID ((u_short)0xf135) 67753642Sguido#endif 67853642Sguido#ifndef IPOPT_SECUR_EFTO 67953642Sguido# define IPOPT_SECUR_EFTO ((u_short)0x789a) 68053642Sguido#endif 68153642Sguido#ifndef IPOPT_SECUR_MMMM 68253642Sguido# define IPOPT_SECUR_MMMM ((u_short)0xbc4d) 68353642Sguido#endif 68453642Sguido#ifndef IPOPT_SECUR_RESTR 68553642Sguido# define IPOPT_SECUR_RESTR ((u_short)0xaf13) 68653642Sguido#endif 68753642Sguido#ifndef IPOPT_SECUR_SECRET 68853642Sguido# define IPOPT_SECUR_SECRET ((u_short)0xd788) 68953642Sguido#endif 69053642Sguido#ifndef IPOPT_SECUR_TOPSECRET 69153642Sguido# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) 69253642Sguido#endif 69353642Sguido#ifndef IPOPT_OLEN 69453642Sguido# define IPOPT_OLEN 1 69553642Sguido#endif 69653642Sguido#endif /* linux || __sgi */ 69753642Sguido 69853642Sguido#ifdef linux 69953642Sguido#include <linux/in_systm.h> 70053642Sguido/* 70153642Sguido * TCP States 70253642Sguido */ 70353642Sguido#define TCPS_CLOSED 0 /* closed */ 70453642Sguido#define TCPS_LISTEN 1 /* listening for connection */ 70553642Sguido#define TCPS_SYN_SENT 2 /* active, have sent syn */ 70653642Sguido#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ 70753642Sguido/* states < TCPS_ESTABLISHED are those where connections not established */ 70853642Sguido#define TCPS_ESTABLISHED 4 /* established */ 70953642Sguido#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 71053642Sguido/* states > TCPS_CLOSE_WAIT are those where user has closed */ 71153642Sguido#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 71253642Sguido#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 71353642Sguido#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 71453642Sguido/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 71553642Sguido#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 71653642Sguido#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 71753642Sguido 71853642Sguido/* 71953642Sguido * file flags. 72053642Sguido */ 72153642Sguido#ifdef WRITE 72253642Sguido#define FWRITE WRITE 72353642Sguido#define FREAD READ 72453642Sguido#else 72553642Sguido#define FWRITE _IOC_WRITE 72653642Sguido#define FREAD _IOC_READ 72753642Sguido#endif 72853642Sguido/* 72953642Sguido * mbuf related problems. 73053642Sguido */ 73153642Sguido#define mtod(m,t) (t)((m)->data) 73253642Sguido#define m_len len 73353642Sguido#define m_next next 73453642Sguido 73553642Sguido#ifdef IP_DF 73653642Sguido#undef IP_DF 73753642Sguido#endif 73853642Sguido#define IP_DF 0x4000 73953642Sguido 74053642Sguidotypedef struct { 74153642Sguido __u16 th_sport; 74253642Sguido __u16 th_dport; 74353642Sguido __u32 th_seq; 74453642Sguido __u32 th_ack; 74553642Sguido# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 74653642Sguido defined(vax) 74753642Sguido __u8 th_res:4; 74853642Sguido __u8 th_off:4; 74953642Sguido#else 75053642Sguido __u8 th_off:4; 75153642Sguido __u8 th_res:4; 75253642Sguido#endif 75353642Sguido __u8 th_flags; 75453642Sguido __u16 th_win; 75553642Sguido __u16 th_sum; 75653642Sguido __u16 th_urp; 75753642Sguido} tcphdr_t; 75853642Sguido 75953642Sguidotypedef struct { 76053642Sguido __u16 uh_sport; 76153642Sguido __u16 uh_dport; 76253642Sguido __u16 uh_ulen; 76353642Sguido __u16 uh_sum; 76453642Sguido} udphdr_t; 76553642Sguido 76653642Sguidotypedef struct { 76753642Sguido# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 76853642Sguido defined(vax) 76953642Sguido __u8 ip_hl:4; 77053642Sguido __u8 ip_v:4; 77153642Sguido# else 77255929Sguido __u8 ip_v:4; 77353642Sguido __u8 ip_hl:4; 77453642Sguido# endif 77553642Sguido __u8 ip_tos; 77653642Sguido __u16 ip_len; 77753642Sguido __u16 ip_id; 77853642Sguido __u16 ip_off; 77953642Sguido __u8 ip_ttl; 78053642Sguido __u8 ip_p; 78153642Sguido __u16 ip_sum; 78253642Sguido struct in_addr ip_src; 78353642Sguido struct in_addr ip_dst; 78453642Sguido} ip_t; 78553642Sguido 78653642Sguido/* 78753642Sguido * Structure of an icmp header. 78853642Sguido */ 78953642Sguidotypedef struct icmp { 79053642Sguido __u8 icmp_type; /* type of message, see below */ 79153642Sguido __u8 icmp_code; /* type sub code */ 79253642Sguido __u16 icmp_cksum; /* ones complement cksum of struct */ 79353642Sguido union { 79453642Sguido __u8 ih_pptr; /* ICMP_PARAMPROB */ 79553642Sguido struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 79653642Sguido struct ih_idseq { 79753642Sguido __u16 icd_id; 79853642Sguido __u16 icd_seq; 79953642Sguido } ih_idseq; 80053642Sguido int ih_void; 80153642Sguido } icmp_hun; 80253642Sguido# define icmp_pptr icmp_hun.ih_pptr 80353642Sguido# define icmp_gwaddr icmp_hun.ih_gwaddr 80453642Sguido# define icmp_id icmp_hun.ih_idseq.icd_id 80553642Sguido# define icmp_seq icmp_hun.ih_idseq.icd_seq 80653642Sguido# define icmp_void icmp_hun.ih_void 80753642Sguido union { 80853642Sguido struct id_ts { 80953642Sguido n_time its_otime; 81053642Sguido n_time its_rtime; 81153642Sguido n_time its_ttime; 81253642Sguido } id_ts; 81353642Sguido struct id_ip { 81453642Sguido ip_t idi_ip; 81553642Sguido /* options and then 64 bits of data */ 81653642Sguido } id_ip; 81753642Sguido u_long id_mask; 81853642Sguido char id_data[1]; 81953642Sguido } icmp_dun; 82053642Sguido# define icmp_otime icmp_dun.id_ts.its_otime 82153642Sguido# define icmp_rtime icmp_dun.id_ts.its_rtime 82253642Sguido# define icmp_ttime icmp_dun.id_ts.its_ttime 82353642Sguido# define icmp_ip icmp_dun.id_ip.idi_ip 82453642Sguido# define icmp_mask icmp_dun.id_mask 82553642Sguido# define icmp_data icmp_dun.id_data 82653642Sguido} icmphdr_t; 82753642Sguido 82853642Sguido# ifndef LINUX_IPOVLY 82953642Sguido# define LINUX_IPOVLY 83053642Sguidostruct ipovly { 83153642Sguido caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 83253642Sguido u_char ih_x1; /* (unused) */ 83353642Sguido u_char ih_pr; /* protocol */ 83453642Sguido short ih_len; /* protocol length */ 83553642Sguido struct in_addr ih_src; /* source internet address */ 83653642Sguido struct in_addr ih_dst; /* destination internet address */ 83753642Sguido}; 83853642Sguido# endif 83953642Sguido 84053642Sguidotypedef struct { 84153642Sguido __u8 ether_dhost[6]; 84253642Sguido __u8 ether_shost[6]; 84353642Sguido __u16 ether_type; 84453642Sguido} ether_header_t; 84553642Sguido 84653642Sguidotypedef struct uio { 84753642Sguido int uio_resid; 84853642Sguido int uio_rw; 84953642Sguido caddr_t uio_buf; 85053642Sguido} uio_t; 85153642Sguido 85253642Sguido# define UIO_READ 0 85353642Sguido# define UIO_WRITE 1 85453642Sguido# define UIOMOVE(a, b, c, d) uiomove(a,b,c,d) 85553642Sguido 85653642Sguido/* 85753642Sguido * For masking struct ifnet onto struct device 85853642Sguido */ 85953642Sguido# define if_name name 86053642Sguido 86153642Sguido# ifdef KERNEL 86260857Sdarrenr# define GETUNIT(x, v) dev_get(x) 86353642Sguido# define FREE_MB_T(m) kfree_skb(m, FREE_WRITE) 86453642Sguido# define uniqtime do_gettimeofday 86553642Sguido# undef INT_MAX 86653642Sguido# undef UINT_MAX 86753642Sguido# undef LONG_MAX 86853642Sguido# undef ULONG_MAX 86953642Sguido# include <linux/netdevice.h> 87053642Sguido# define SPL_X(x) 87153642Sguido# define SPL_NET(x) 87253642Sguido# define SPL_IMP(x) 87353642Sguido 87453642Sguido# define bcmp(a,b,c) memcmp(a,b,c) 87553642Sguido# define bcopy(a,b,c) memcpy(b,a,c) 87653642Sguido# define bzero(a,c) memset(a,0,c) 87753642Sguido 87853642Sguido# define UNITNAME(n) dev_get((n)) 87953642Sguido 88053642Sguido# define KMALLOC(a,b) (a) = (b)kmalloc(sizeof(*(a)), GFP_ATOMIC) 88153642Sguido# define KMALLOCS(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC) 88253642Sguido# define KFREE(x) kfree_s((x), sizeof(*(x))) 88353642Sguido# define KFREES(x,s) kfree_s((x), (s)) 88460857Sdarrenr#define IRCOPY(const void *a, void *b, size_t c) { \ 88560857Sdarrenr int error; \ 88660857Sdarrenr 88760857Sdarrenr error = verify_area(VERIFY_READ, a ,c); \ 88860857Sdarrenr if (!error) \ 88960857Sdarrenr memcpy_fromfs(b, a, c); \ 89060857Sdarrenr return error; \ 89160857Sdarrenr} 89260857Sdarrenrstatic inline int IWCOPY(const void *a, void *b, size_t c) 89360857Sdarrenr{ 89460857Sdarrenr int error; 89560857Sdarrenr 89660857Sdarrenr error = verify_area(VERIFY_WRITE, b, c); 89760857Sdarrenr if (!error) 89860857Sdarrenr memcpy_tofs(b, a, c); 89960857Sdarrenr return error; 90060857Sdarrenr} 90160857Sdarrenrstatic inline int IRCOPYPTR(const void *a, void *b, size_t c) { 90260857Sdarrenr caddr_t ca; 90360857Sdarrenr int error; 90460857Sdarrenr 90560857Sdarrenr error = verify_area(VERIFY_READ, a ,sizeof(ca)); 90660857Sdarrenr if (!error) { 90760857Sdarrenr memcpy_fromfs(ca, a, sizeof(ca)); 90860857Sdarrenr error = verify_area(VERIFY_READ, ca , c); 90960857Sdarrenr if (!error) 91060857Sdarrenr memcpy_fromfs(b, ca, c); 91160857Sdarrenr } 91260857Sdarrenr return error; 91360857Sdarrenr} 91460857Sdarrenrstatic inline int IWCOPYPTR(const void *a, void *b, size_t c) { 91560857Sdarrenr caddr_t ca; 91660857Sdarrenr int error; 91760857Sdarrenr 91860857Sdarrenr 91960857Sdarrenr error = verify_area(VERIFY_READ, b ,sizeof(ca)); 92060857Sdarrenr if (!error) { 92160857Sdarrenr memcpy_fromfs(ca, b, sizeof(ca)); 92260857Sdarrenr error = verify_area(VERIFY_WRITE, ca, c); 92360857Sdarrenr if (!error) 92460857Sdarrenr memcpy_tofs(ca, a, c); 92560857Sdarrenr } 92660857Sdarrenr return error; 92760857Sdarrenr} 92853642Sguido# else 92953642Sguido# define __KERNEL__ 93053642Sguido# undef INT_MAX 93153642Sguido# undef UINT_MAX 93253642Sguido# undef LONG_MAX 93353642Sguido# undef ULONG_MAX 93453642Sguido# define s8 __s8 93553642Sguido# define u8 __u8 93653642Sguido# define s16 __s16 93753642Sguido# define u16 __u16 93853642Sguido# define s32 __s32 93953642Sguido# define u32 __u32 94053642Sguido# include <linux/netdevice.h> 94153642Sguido# undef __KERNEL__ 94253642Sguido# endif 94353642Sguido# define ifnet device 94453642Sguido#else 94553642Sguidotypedef struct tcphdr tcphdr_t; 94653642Sguidotypedef struct udphdr udphdr_t; 94753642Sguidotypedef struct icmp icmphdr_t; 94853642Sguidotypedef struct ip ip_t; 94953642Sguidotypedef struct ether_header ether_header_t; 95053642Sguido#endif /* linux */ 95153642Sguidotypedef struct tcpiphdr tcpiphdr_t; 95253642Sguido 95353642Sguido#if defined(hpux) || defined(linux) 95453642Sguidostruct ether_addr { 95553642Sguido char ether_addr_octet[6]; 95653642Sguido}; 95753642Sguido#endif 95853642Sguido 95953642Sguido/* 96053642Sguido * XXX - This is one of those *awful* hacks which nobody likes 96153642Sguido */ 96253642Sguido#ifdef ultrix 96353642Sguido#define A_A 96453642Sguido#else 96553642Sguido#define A_A & 96653642Sguido#endif 96753642Sguido 96860857Sdarrenr#define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG) 96960857Sdarrenr 97053642Sguido#ifndef ICMP_ROUTERADVERT 97153642Sguido# define ICMP_ROUTERADVERT 9 97253642Sguido#endif 97353642Sguido#ifndef ICMP_ROUTERSOLICIT 97453642Sguido# define ICMP_ROUTERSOLICIT 10 97553642Sguido#endif 97660857Sdarrenr#undef ICMP_MAX_UNREACH 97760857Sdarrenr#define ICMP_MAX_UNREACH 14 97860857Sdarrenr#undef ICMP_MAXTYPE 97960857Sdarrenr#define ICMP_MAXTYPE 18 98053642Sguido/* 98153642Sguido * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data, 98253642Sguido * another IP header and then 64 bits of data, totalling 56. Of course, 98353642Sguido * the last 64 bits is dependant on that being available. 98453642Sguido */ 98553642Sguido#define ICMPERR_ICMPHLEN 8 98653642Sguido#define ICMPERR_IPICMPHLEN (20 + 8) 98753642Sguido#define ICMPERR_MINPKTLEN (20 + 8 + 20) 98853642Sguido#define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8) 98960857Sdarrenr#define ICMP6ERR_MINPKTLEN (20 + 8) 99053642Sguido 99153642Sguido#endif /* __IP_COMPAT_H__ */ 992