ip_compat.h revision 80482
1/* 2 * Copyright (C) 1993-2001 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 * 6 * @(#)ip_compat.h 1.8 1/14/96 7 * $Id: ip_compat.h,v 2.26.2.9 2001/01/14 14:58:01 darrenr Exp $ 8 * $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_compat.h 80482 2001-07-28 11:58:26Z darrenr $ 9 */ 10 11#ifndef __IP_COMPAT_H__ 12#define __IP_COMPAT_H__ 13 14#ifndef __P 15# ifdef __STDC__ 16# define __P(x) x 17# else 18# define __P(x) () 19# endif 20#endif 21#ifndef __STDC__ 22# undef const 23# define const 24#endif 25 26#ifndef SOLARIS 27#define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 28#endif 29#if SOLARIS && !defined(SOLARIS2) 30# define SOLARIS2 4 /* Pick an old version */ 31#endif 32#if SOLARIS2 >= 8 33# ifndef USE_INET6 34# define USE_INET6 35# endif 36#endif 37 38#if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__) 39# undef KERNEL 40# undef _KERNEL 41# undef __KERNEL__ 42# define KERNEL 43# define _KERNEL 44# define __KERNEL__ 45#endif 46 47#if defined(__SVR4) || defined(__svr4__) || defined(__sgi) 48#define index strchr 49# if !defined(KERNEL) 50# define bzero(a,b) memset(a,0,b) 51# define bcmp memcmp 52# define bcopy(a,b,c) memmove(b,a,c) 53# endif 54#endif 55 56#ifndef offsetof 57#define offsetof(t,m) (int)((&((t *)0L)->m)) 58#endif 59 60#if defined(__sgi) || defined(bsdi) 61struct ether_addr { 62 u_char ether_addr_octet[6]; 63}; 64#endif 65 66#if defined(__sgi) && !defined(IPFILTER_LKM) 67# ifdef __STDC__ 68# define IPL_EXTERN(ep) ipfilter##ep 69# else 70# define IPL_EXTERN(ep) ipfilter/**/ep 71# endif 72#else 73# ifdef __STDC__ 74# define IPL_EXTERN(ep) ipl##ep 75# else 76# define IPL_EXTERN(ep) ipl/**/ep 77# endif 78#endif 79 80#ifdef linux 81# include <sys/sysmacros.h> 82#endif 83#if SOLARIS 84# define MTYPE(m) ((m)->b_datap->db_type) 85# include <sys/isa_defs.h> 86# include <sys/ioccom.h> 87# include <sys/sysmacros.h> 88# include <sys/kmem.h> 89/* 90 * because Solaris 2 defines these in two places :-/ 91 */ 92# undef IPOPT_EOL 93# undef IPOPT_NOP 94# undef IPOPT_LSRR 95# undef IPOPT_RR 96# undef IPOPT_SSRR 97# ifndef KERNEL 98# define _KERNEL 99# undef RES_INIT 100# if SOLARIS2 >= 8 101# include <netinet/ip6.h> 102# endif 103# include <inet/common.h> 104# include <inet/ip.h> 105# include <inet/ip_ire.h> 106# undef _KERNEL 107# else /* _KERNEL */ 108# if SOLARIS2 >= 8 109# include <netinet/ip6.h> 110# endif 111# include <inet/common.h> 112# include <inet/ip.h> 113# include <inet/ip_ire.h> 114# endif /* _KERNEL */ 115# if SOLARIS2 >= 8 116# include <inet/ip_if.h> 117# include <netinet/ip6.h> 118# define ipif_local_addr ipif_lcl_addr 119/* Only defined in private include file */ 120# ifndef V4_PART_OF_V6 121# define V4_PART_OF_V6(v6) v6.s6_addr32[3] 122# endif 123# endif 124 125typedef struct qif { 126 struct qif *qf_next; 127 ill_t *qf_ill; 128 kmutex_t qf_lock; 129 void *qf_iptr; 130 void *qf_optr; 131 queue_t *qf_in; 132 queue_t *qf_out; 133 struct qinit *qf_wqinfo; 134 struct qinit *qf_rqinfo; 135 struct qinit qf_wqinit; 136 struct qinit qf_rqinit; 137 mblk_t *qf_m; /* These three fields are for passing data up from */ 138 queue_t *qf_q; /* fr_qin and fr_qout to the packet processing. */ 139 size_t qf_off; 140 size_t qf_len; /* this field is used for in ipfr_fastroute */ 141 char qf_name[8]; 142 /* 143 * in case the ILL has disappeared... 144 */ 145 size_t qf_hl; /* header length */ 146 int qf_sap; 147} qif_t; 148#else /* SOLARIS */ 149# if !defined(__sgi) 150typedef int minor_t; 151# endif 152#endif /* SOLARIS */ 153#define IPMINLEN(i, h) ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h))) 154 155#if defined(__FreeBSD__) && (__FreeBSD__ >= 5) && defined(_KERNEL) 156# include <machine/in_cksum.h> 157#endif 158 159#ifndef IP_OFFMASK 160#define IP_OFFMASK 0x1fff 161#endif 162 163#if BSD > 199306 164# define USE_QUAD_T 165# define U_QUAD_T u_quad_t 166# define QUAD_T quad_t 167#else /* BSD > 199306 */ 168# define U_QUAD_T u_long 169# define QUAD_T long 170#endif /* BSD > 199306 */ 171 172 173/* 174 * These operating systems already take care of the problem for us. 175 */ 176#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \ 177 defined(__sgi) 178typedef u_int32_t u_32_t; 179# if defined(_KERNEL) && !defined(IPFILTER_LKM) 180# if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000) 181# include "opt_inet.h" 182# endif 183# if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \ 184 !defined(KLD_MODULE) 185# include "opt_inet6.h" 186# endif 187# ifdef INET6 188# define USE_INET6 189# endif 190# endif 191#else 192/* 193 * Really, any arch where sizeof(long) != sizeof(int). 194 */ 195# if defined(__alpha__) || defined(__alpha) || defined(_LP64) 196typedef unsigned int u_32_t; 197# else 198# if SOLARIS2 >= 6 199typedef uint32_t u_32_t; 200# else 201typedef unsigned int u_32_t; 202# endif 203# endif 204#endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */ 205 206#ifdef USE_INET6 207# if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) 208# include <netinet/ip6.h> 209# ifdef _KERNEL 210# include <netinet6/ip6_var.h> 211# endif 212typedef struct ip6_hdr ip6_t; 213# endif 214union i6addr { 215 u_32_t i6[4]; 216 struct in_addr in4; 217 struct in6_addr in6; 218}; 219#else 220union i6addr { 221 u_32_t i6[4]; 222 struct in_addr in4; 223}; 224#endif 225 226#define IP6CMP(a,b) bcmp((char *)&(a), (char *)&(b), sizeof(a)) 227#define IP6EQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) == 0) 228#define IP6NEQ(a,b) (bcmp((char *)&(a), (char *)&(b), sizeof(a)) != 0) 229 230#ifndef MAX 231#define MAX(a,b) (((a) > (b)) ? (a) : (b)) 232#endif 233 234/* 235 * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108. 236 * 237 * Basic Option 238 * 239 * 00000001 - (Reserved 4) 240 * 00111101 - Top Secret 241 * 01011010 - Secret 242 * 10010110 - Confidential 243 * 01100110 - (Reserved 3) 244 * 11001100 - (Reserved 2) 245 * 10101011 - Unclassified 246 * 11110001 - (Reserved 1) 247 */ 248#define IPSO_CLASS_RES4 0x01 249#define IPSO_CLASS_TOPS 0x3d 250#define IPSO_CLASS_SECR 0x5a 251#define IPSO_CLASS_CONF 0x96 252#define IPSO_CLASS_RES3 0x66 253#define IPSO_CLASS_RES2 0xcc 254#define IPSO_CLASS_UNCL 0xab 255#define IPSO_CLASS_RES1 0xf1 256 257#define IPSO_AUTH_GENSER 0x80 258#define IPSO_AUTH_ESI 0x40 259#define IPSO_AUTH_SCI 0x20 260#define IPSO_AUTH_NSA 0x10 261#define IPSO_AUTH_DOE 0x08 262#define IPSO_AUTH_UN 0x06 263#define IPSO_AUTH_FTE 0x01 264 265/* 266 * IP option #defines 267 */ 268/*#define IPOPT_RR 7 */ 269#define IPOPT_ZSU 10 /* ZSU */ 270#define IPOPT_MTUP 11 /* MTUP */ 271#define IPOPT_MTUR 12 /* MTUR */ 272#define IPOPT_ENCODE 15 /* ENCODE */ 273/*#define IPOPT_TS 68 */ 274#define IPOPT_TR 82 /* TR */ 275/*#define IPOPT_SECURITY 130 */ 276/*#define IPOPT_LSRR 131 */ 277#define IPOPT_E_SEC 133 /* E-SEC */ 278#define IPOPT_CIPSO 134 /* CIPSO */ 279/*#define IPOPT_SATID 136 */ 280#ifndef IPOPT_SID 281# define IPOPT_SID IPOPT_SATID 282#endif 283/*#define IPOPT_SSRR 137 */ 284#define IPOPT_ADDEXT 147 /* ADDEXT */ 285#define IPOPT_VISA 142 /* VISA */ 286#define IPOPT_IMITD 144 /* IMITD */ 287#define IPOPT_EIP 145 /* EIP */ 288#define IPOPT_FINN 205 /* FINN */ 289 290 291#if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL)) 292# ifdef IPFILTER_LKM 293# ifndef __FreeBSD_cc_version 294# include <osreldate.h> 295# else 296# if __FreeBSD_cc_version < 430000 297# include <osreldate.h> 298# else 299# include <sys/param.h> 300# endif 301# endif 302# define ACTUALLY_LKM_NOT_KERNEL 303# else 304# ifndef __FreeBSD_cc_version 305# include <sys/osreldate.h> 306# else 307# if __FreeBSD_cc_version < 430000 308# include <sys/osreldate.h> 309# else 310# include <sys/param.h> 311# endif 312# endif 313# endif 314# if __FreeBSD__ < 3 315# include <machine/spl.h> 316# else 317# if __FreeBSD__ == 3 318# if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL) 319# define ACTUALLY_LKM_NOT_KERNEL 320# endif 321# endif 322# endif 323#endif /* __FreeBSD__ && KERNEL */ 324 325/* 326 * Build some macros and #defines to enable the same code to compile anywhere 327 * Well, that's the idea, anyway :-) 328 */ 329#if !SOLARIS || (SOLARIS2 < 6) || !defined(KERNEL) 330# define ATOMIC_INCL ATOMIC_INC 331# define ATOMIC_INC64 ATOMIC_INC 332# define ATOMIC_INC32 ATOMIC_INC 333# define ATOMIC_INC16 ATOMIC_INC 334# define ATOMIC_DECL ATOMIC_DEC 335# define ATOMIC_DEC64 ATOMIC_DEC 336# define ATOMIC_DEC32 ATOMIC_DEC 337# define ATOMIC_DEC16 ATOMIC_DEC 338#endif 339#ifdef __sgi 340# define hz HZ 341# include <sys/ksynch.h> 342# define IPF_LOCK_PL plhi 343# include <sys/sema.h> 344#undef kmutex_t 345typedef struct { 346 lock_t *l; 347 int pl; 348} kmutex_t; 349# undef MUTEX_INIT 350# undef MUTEX_DESTROY 351#endif 352#ifdef KERNEL 353# if SOLARIS 354# if SOLARIS2 >= 6 355# include <sys/atomic.h> 356# if SOLARIS2 == 6 357# define ATOMIC_INCL(x) atomic_add_long((uint32_t*)&(x), 1) 358# define ATOMIC_DECL(x) atomic_add_long((uint32_t*)&(x), -1) 359# else 360# define ATOMIC_INCL(x) atomic_add_long(&(x), 1) 361# define ATOMIC_DECL(x) atomic_add_long(&(x), -1) 362# endif 363# define ATOMIC_INC64(x) atomic_add_64((uint64_t*)&(x), 1) 364# define ATOMIC_INC32(x) atomic_add_32((uint32_t*)&(x), 1) 365# define ATOMIC_INC16(x) atomic_add_16((uint16_t*)&(x), 1) 366# define ATOMIC_DEC64(x) atomic_add_64((uint64_t*)&(x), -1) 367# define ATOMIC_DEC32(x) atomic_add_32((uint32_t*)&(x), -1) 368# define ATOMIC_DEC16(x) atomic_add_16((uint16_t*)&(x), -1) 369# else 370# define IRE_CACHE IRE_ROUTE 371# define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \ 372 mutex_exit(&ipf_rw); } 373# define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \ 374 mutex_exit(&ipf_rw); } 375# endif 376# define MUTEX_ENTER(x) mutex_enter(x) 377# if 1 378# define KRWLOCK_T krwlock_t 379# define READ_ENTER(x) rw_enter(x, RW_READER) 380# define WRITE_ENTER(x) rw_enter(x, RW_WRITER) 381# define RW_UPGRADE(x) { if (rw_tryupgrade(x) == 0) { \ 382 rw_exit(x); \ 383 rw_enter(x, RW_WRITER); } \ 384 } 385# define MUTEX_DOWNGRADE(x) rw_downgrade(x) 386# define RWLOCK_INIT(x, y, z) rw_init((x), (y), RW_DRIVER, (z)) 387# define RWLOCK_EXIT(x) rw_exit(x) 388# define RW_DESTROY(x) rw_destroy(x) 389# else 390# define KRWLOCK_T kmutex_t 391# define READ_ENTER(x) mutex_enter(x) 392# define WRITE_ENTER(x) mutex_enter(x) 393# define MUTEX_DOWNGRADE(x) ; 394# define RWLOCK_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z)) 395# define RWLOCK_EXIT(x) mutex_exit(x) 396# define RW_DESTROY(x) mutex_destroy(x) 397# endif 398# define MUTEX_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z)) 399# define MUTEX_DESTROY(x) mutex_destroy(x) 400# define MUTEX_EXIT(x) mutex_exit(x) 401# define MTOD(m,t) (t)((m)->b_rptr) 402# define IRCOPY(a,b,c) copyin((caddr_t)(a), (caddr_t)(b), (c)) 403# define IWCOPY(a,b,c) copyout((caddr_t)(a), (caddr_t)(b), (c)) 404# define IRCOPYPTR ircopyptr 405# define IWCOPYPTR iwcopyptr 406# define FREE_MB_T(m) freemsg(m) 407# define SPL_NET(x) ; 408# define SPL_IMP(x) ; 409# undef SPL_X 410# define SPL_X(x) ; 411# ifdef sparc 412# define ntohs(x) (x) 413# define ntohl(x) (x) 414# define htons(x) (x) 415# define htonl(x) (x) 416# endif /* sparc */ 417# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 418# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 419# define GET_MINOR(x) getminor(x) 420extern ill_t *get_unit __P((char *, int)); 421# define GETUNIT(n, v) get_unit(n, v) 422# define IFNAME(x) ((ill_t *)x)->ill_name 423# else /* SOLARIS */ 424# if defined(__sgi) 425# define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ 426 (x)++; MUTEX_EXIT(&ipf_rw); } 427# define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ 428 (x)--; MUTEX_EXIT(&ipf_rw); } 429# define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL); 430# define KRWLOCK_T kmutex_t 431# define READ_ENTER(x) MUTEX_ENTER(x) 432# define WRITE_ENTER(x) MUTEX_ENTER(x) 433# define RW_UPGRADE(x) ; 434# define MUTEX_DOWNGRADE(x) ; 435# define RWLOCK_EXIT(x) MUTEX_EXIT(x) 436# define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl); 437# define MUTEX_INIT(x,y,z) (x)->l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP) 438# define MUTEX_DESTROY(x) LOCK_DEALLOC((x)->l) 439# else /* __sgi */ 440# define ATOMIC_INC(x) (x)++ 441# define ATOMIC_DEC(x) (x)-- 442# define MUTEX_ENTER(x) ; 443# define READ_ENTER(x) ; 444# define WRITE_ENTER(x) ; 445# define RW_UPGRADE(x) ; 446# define MUTEX_DOWNGRADE(x) ; 447# define RWLOCK_EXIT(x) ; 448# define MUTEX_EXIT(x) ; 449# define MUTEX_INIT(x,y,z) ; 450# define MUTEX_DESTROY(x) ; 451# endif /* __sgi */ 452# ifndef linux 453# define FREE_MB_T(m) m_freem(m) 454# define MTOD(m,t) mtod(m,t) 455# define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 456# define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 457# define IRCOPYPTR ircopyptr 458# define IWCOPYPTR iwcopyptr 459# endif /* !linux */ 460# endif /* SOLARIS */ 461 462# ifdef sun 463# if !SOLARIS 464# include <sys/kmem_alloc.h> 465# define GETUNIT(n, v) ifunit(n, IFNAMSIZ) 466# define IFNAME(x) ((struct ifnet *)x)->if_name 467# endif 468# else 469# ifndef linux 470# define GETUNIT(n, v) ifunit(n) 471# if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \ 472 (defined(OpenBSD) && (OpenBSD >= 199603)) 473# define IFNAME(x) ((struct ifnet *)x)->if_xname 474# else 475# define USE_GETIFNAME 1 476# define IFNAME(x) get_ifname((struct ifnet *)x) 477extern char *get_ifname __P((struct ifnet *)); 478# endif 479# endif 480# endif /* sun */ 481 482# if defined(sun) && !defined(linux) || defined(__sgi) 483# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 484# define SLEEP(id, n) sleep((id), PZERO+1) 485# define WAKEUP(id) wakeup(id) 486# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 487# define KFREES(x,s) kmem_free((char *)(x), (s)) 488# if !SOLARIS 489extern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 490extern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 491# endif 492# ifdef __sgi 493# include <sys/kmem.h> 494# include <sys/ddi.h> 495# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 496# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 497# define GET_MINOR(x) getminor(x) 498# else 499# if !SOLARIS 500# define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \ 501 KMEM_NOSLEEP) 502# define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP) 503# endif /* SOLARIS */ 504# endif /* __sgi */ 505# endif /* sun && !linux */ 506# ifndef GET_MINOR 507# define GET_MINOR(x) minor(x) 508# endif 509# if (BSD >= 199306) || defined(__FreeBSD__) 510# include <vm/vm.h> 511# if !defined(__FreeBSD__) || (defined (__FreeBSD__) && __FreeBSD__>=3) 512# include <vm/vm_extern.h> 513# include <sys/proc.h> 514extern vm_map_t kmem_map; 515# else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */ 516# include <vm/vm_kern.h> 517# endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */ 518# ifdef M_PFIL 519# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT) 520# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT) 521# define KFREE(x) FREE((x), M_PFIL) 522# define KFREES(x,s) FREE((x), M_PFIL) 523# else 524# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT) 525# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT) 526# define KFREE(x) FREE((x), M_TEMP) 527# define KFREES(x,s) FREE((x), M_TEMP) 528# endif /* M_PFIL */ 529# define UIOMOVE(a,b,c,d) uiomove(a,b,d) 530# define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0) 531# define WAKEUP(id) wakeup(id) 532# endif /* BSD */ 533# if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \ 534 (defined(OpenBSD) && (OpenBSD >= 200006)) 535# define SPL_NET(x) x = splsoftnet() 536# define SPL_X(x) (void) splx(x) 537# else 538# if !SOLARIS && !defined(linux) 539# define SPL_IMP(x) x = splimp() 540# define SPL_NET(x) x = splnet() 541# define SPL_X(x) (void) splx(x) 542# endif 543# endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */ 544# define PANIC(x,y) if (x) panic y 545#else /* KERNEL */ 546# define SLEEP(x,y) ; 547# define WAKEUP(x) ; 548# define PANIC(x,y) ; 549# define ATOMIC_INC(x) (x)++ 550# define ATOMIC_DEC(x) (x)-- 551# define MUTEX_ENTER(x) ; 552# define READ_ENTER(x) ; 553# define MUTEX_INIT(x,y,z) ; 554# define MUTEX_DESTROY(x) ; 555# define WRITE_ENTER(x) ; 556# define RW_UPGRADE(x) ; 557# define MUTEX_DOWNGRADE(x) ; 558# define RWLOCK_EXIT(x) ; 559# define MUTEX_EXIT(x) ; 560# define SPL_NET(x) ; 561# define SPL_IMP(x) ; 562# undef SPL_X 563# define SPL_X(x) ; 564# define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a)) 565# define KMALLOCS(a,b,c) (a) = (b)malloc(c) 566# define KFREE(x) free(x) 567# define KFREES(x,s) free(x) 568# define GETUNIT(x, v) get_unit(x,v) 569# define IRCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 570# define IWCOPY(a,b,c) (bcopy((a), (b), (c)), 0) 571# define IRCOPYPTR ircopyptr 572# define IWCOPYPTR iwcopyptr 573#endif /* KERNEL */ 574 575#if SOLARIS 576typedef mblk_t mb_t; 577# if SOLARIS2 >= 7 578# ifdef lint 579# define ALIGN32(ptr) (ptr ? 0L : 0L) 580# define ALIGN16(ptr) (ptr ? 0L : 0L) 581# else 582# define ALIGN32(ptr) (ptr) 583# define ALIGN16(ptr) (ptr) 584# endif 585# endif 586#else 587# ifdef linux 588# ifndef kernel 589typedef struct mb { 590 struct mb *next; 591 u_int len; 592 u_char *data; 593} mb_t; 594# else 595typedef struct sk_buff mb_t; 596# endif 597# else 598typedef struct mbuf mb_t; 599# endif 600#endif /* SOLARIS */ 601 602/* 603 * These #ifdef's are here mainly for linux, but who knows, they may 604 * not be in other places or maybe one day linux will grow up and some 605 * of these will turn up there too. 606 */ 607#ifndef ICMP_MINLEN 608# define ICMP_MINLEN 8 609#endif 610#ifndef ICMP_UNREACH 611# define ICMP_UNREACH ICMP_DEST_UNREACH 612#endif 613#ifndef ICMP_SOURCEQUENCH 614# define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH 615#endif 616#ifndef ICMP_TIMXCEED 617# define ICMP_TIMXCEED ICMP_TIME_EXCEEDED 618#endif 619#ifndef ICMP_PARAMPROB 620# define ICMP_PARAMPROB ICMP_PARAMETERPROB 621#endif 622#ifndef ICMP_TSTAMP 623# define ICMP_TSTAMP ICMP_TIMESTAMP 624#endif 625#ifndef ICMP_TSTAMPREPLY 626# define ICMP_TSTAMPREPLY ICMP_TIMESTAMPREPLY 627#endif 628#ifndef ICMP_IREQ 629# define ICMP_IREQ ICMP_INFO_REQUEST 630#endif 631#ifndef ICMP_IREQREPLY 632# define ICMP_IREQREPLY ICMP_INFO_REPLY 633#endif 634#ifndef ICMP_MASKREQ 635# define ICMP_MASKREQ ICMP_ADDRESS 636#endif 637#ifndef ICMP_MASKREPLY 638# define ICMP_MASKREPLY ICMP_ADDRESSREPLY 639#endif 640#ifndef ICMP_PARAMPROB_OPTABSENT 641# define ICMP_PARAMPROB_OPTABSENT 1 642#endif 643#ifndef IPVERSION 644# define IPVERSION 4 645#endif 646#ifndef IPOPT_MINOFF 647# define IPOPT_MINOFF 4 648#endif 649#ifndef IPOPT_COPIED 650# define IPOPT_COPIED(x) ((x)&0x80) 651#endif 652#ifndef IPOPT_EOL 653# define IPOPT_EOL 0 654#endif 655#ifndef IPOPT_NOP 656# define IPOPT_NOP 1 657#endif 658#ifndef IP_MF 659# define IP_MF ((u_short)0x2000) 660#endif 661#ifndef ETHERTYPE_IP 662# define ETHERTYPE_IP ((u_short)0x0800) 663#endif 664#ifndef TH_FIN 665# define TH_FIN 0x01 666#endif 667#ifndef TH_SYN 668# define TH_SYN 0x02 669#endif 670#ifndef TH_RST 671# define TH_RST 0x04 672#endif 673#ifndef TH_PUSH 674# define TH_PUSH 0x08 675#endif 676#ifndef TH_ACK 677# define TH_ACK 0x10 678#endif 679#ifndef TH_URG 680# define TH_URG 0x20 681#endif 682#ifndef IPOPT_EOL 683# define IPOPT_EOL 0 684#endif 685#ifndef IPOPT_NOP 686# define IPOPT_NOP 1 687#endif 688#ifndef IPOPT_RR 689# define IPOPT_RR 7 690#endif 691#ifndef IPOPT_TS 692# define IPOPT_TS 68 693#endif 694#ifndef IPOPT_SECURITY 695# define IPOPT_SECURITY 130 696#endif 697#ifndef IPOPT_LSRR 698# define IPOPT_LSRR 131 699#endif 700#ifndef IPOPT_SATID 701# define IPOPT_SATID 136 702#endif 703#ifndef IPOPT_SSRR 704# define IPOPT_SSRR 137 705#endif 706#ifndef IPOPT_SECUR_UNCLASS 707# define IPOPT_SECUR_UNCLASS ((u_short)0x0000) 708#endif 709#ifndef IPOPT_SECUR_CONFID 710# define IPOPT_SECUR_CONFID ((u_short)0xf135) 711#endif 712#ifndef IPOPT_SECUR_EFTO 713# define IPOPT_SECUR_EFTO ((u_short)0x789a) 714#endif 715#ifndef IPOPT_SECUR_MMMM 716# define IPOPT_SECUR_MMMM ((u_short)0xbc4d) 717#endif 718#ifndef IPOPT_SECUR_RESTR 719# define IPOPT_SECUR_RESTR ((u_short)0xaf13) 720#endif 721#ifndef IPOPT_SECUR_SECRET 722# define IPOPT_SECUR_SECRET ((u_short)0xd788) 723#endif 724#ifndef IPOPT_SECUR_TOPSECRET 725# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) 726#endif 727#ifndef IPOPT_OLEN 728# define IPOPT_OLEN 1 729#endif 730 731#ifdef linux 732#include <linux/in_systm.h> 733/* 734 * TCP States 735 */ 736#define TCPS_CLOSED 0 /* closed */ 737#define TCPS_LISTEN 1 /* listening for connection */ 738#define TCPS_SYN_SENT 2 /* active, have sent syn */ 739#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ 740/* states < TCPS_ESTABLISHED are those where connections not established */ 741#define TCPS_ESTABLISHED 4 /* established */ 742#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 743/* states > TCPS_CLOSE_WAIT are those where user has closed */ 744#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 745#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 746#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 747/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 748#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 749#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 750 751/* 752 * file flags. 753 */ 754#ifdef WRITE 755#define FWRITE WRITE 756#define FREAD READ 757#else 758#define FWRITE _IOC_WRITE 759#define FREAD _IOC_READ 760#endif 761/* 762 * mbuf related problems. 763 */ 764#define mtod(m,t) (t)((m)->data) 765#define m_len len 766#define m_next next 767 768#ifdef IP_DF 769#undef IP_DF 770#endif 771#define IP_DF 0x4000 772 773typedef struct { 774 __u16 th_sport; 775 __u16 th_dport; 776 __u32 th_seq; 777 __u32 th_ack; 778# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 779 defined(vax) 780 __u8 th_res:4; 781 __u8 th_off:4; 782#else 783 __u8 th_off:4; 784 __u8 th_res:4; 785#endif 786 __u8 th_flags; 787 __u16 th_win; 788 __u16 th_sum; 789 __u16 th_urp; 790} tcphdr_t; 791 792typedef struct { 793 __u16 uh_sport; 794 __u16 uh_dport; 795 __u16 uh_ulen; 796 __u16 uh_sum; 797} udphdr_t; 798 799typedef struct { 800# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 801 defined(vax) 802 __u8 ip_hl:4; 803 __u8 ip_v:4; 804# else 805 __u8 ip_v:4; 806 __u8 ip_hl:4; 807# endif 808 __u8 ip_tos; 809 __u16 ip_len; 810 __u16 ip_id; 811 __u16 ip_off; 812 __u8 ip_ttl; 813 __u8 ip_p; 814 __u16 ip_sum; 815 struct in_addr ip_src; 816 struct in_addr ip_dst; 817} ip_t; 818 819/* 820 * Structure of an icmp header. 821 */ 822typedef struct icmp { 823 __u8 icmp_type; /* type of message, see below */ 824 __u8 icmp_code; /* type sub code */ 825 __u16 icmp_cksum; /* ones complement cksum of struct */ 826 union { 827 __u8 ih_pptr; /* ICMP_PARAMPROB */ 828 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 829 struct ih_idseq { 830 __u16 icd_id; 831 __u16 icd_seq; 832 } ih_idseq; 833 int ih_void; 834 } icmp_hun; 835# define icmp_pptr icmp_hun.ih_pptr 836# define icmp_gwaddr icmp_hun.ih_gwaddr 837# define icmp_id icmp_hun.ih_idseq.icd_id 838# define icmp_seq icmp_hun.ih_idseq.icd_seq 839# define icmp_void icmp_hun.ih_void 840 union { 841 struct id_ts { 842 n_time its_otime; 843 n_time its_rtime; 844 n_time its_ttime; 845 } id_ts; 846 struct id_ip { 847 ip_t idi_ip; 848 /* options and then 64 bits of data */ 849 } id_ip; 850 u_long id_mask; 851 char id_data[1]; 852 } icmp_dun; 853# define icmp_otime icmp_dun.id_ts.its_otime 854# define icmp_rtime icmp_dun.id_ts.its_rtime 855# define icmp_ttime icmp_dun.id_ts.its_ttime 856# define icmp_ip icmp_dun.id_ip.idi_ip 857# define icmp_mask icmp_dun.id_mask 858# define icmp_data icmp_dun.id_data 859} icmphdr_t; 860 861# ifndef LINUX_IPOVLY 862# define LINUX_IPOVLY 863struct ipovly { 864 caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 865 u_char ih_x1; /* (unused) */ 866 u_char ih_pr; /* protocol */ 867 short ih_len; /* protocol length */ 868 struct in_addr ih_src; /* source internet address */ 869 struct in_addr ih_dst; /* destination internet address */ 870}; 871# endif 872 873typedef struct { 874 __u8 ether_dhost[6]; 875 __u8 ether_shost[6]; 876 __u16 ether_type; 877} ether_header_t; 878 879typedef struct uio { 880 int uio_resid; 881 int uio_rw; 882 caddr_t uio_buf; 883} uio_t; 884 885# define UIO_READ 0 886# define UIO_WRITE 1 887# define UIOMOVE(a, b, c, d) uiomove(a,b,c,d) 888 889/* 890 * For masking struct ifnet onto struct device 891 */ 892# define if_name name 893 894# ifdef KERNEL 895# define GETUNIT(x, v) dev_get(x) 896# define FREE_MB_T(m) kfree_skb(m, FREE_WRITE) 897# define uniqtime do_gettimeofday 898# undef INT_MAX 899# undef UINT_MAX 900# undef LONG_MAX 901# undef ULONG_MAX 902# include <linux/netdevice.h> 903# define SPL_X(x) 904# define SPL_NET(x) 905# define SPL_IMP(x) 906 907# define bcmp(a,b,c) memcmp(a,b,c) 908# define bcopy(a,b,c) memcpy(b,a,c) 909# define bzero(a,c) memset(a,0,c) 910 911# define UNITNAME(n) dev_get((n)) 912 913# define KMALLOC(a,b) (a) = (b)kmalloc(sizeof(*(a)), GFP_ATOMIC) 914# define KMALLOCS(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC) 915# define KFREE(x) kfree_s((x), sizeof(*(x))) 916# define KFREES(x,s) kfree_s((x), (s)) 917#define IRCOPY(const void *a, void *b, size_t c) { \ 918 int error; \ 919 920 error = verify_area(VERIFY_READ, a ,c); \ 921 if (!error) \ 922 memcpy_fromfs(b, a, c); \ 923 return error; \ 924} 925static inline int IWCOPY(const void *a, void *b, size_t c) 926{ 927 int error; 928 929 error = verify_area(VERIFY_WRITE, b, c); 930 if (!error) 931 memcpy_tofs(b, a, c); 932 return error; 933} 934static inline int IRCOPYPTR(const void *a, void *b, size_t c) { 935 caddr_t ca; 936 int error; 937 938 error = verify_area(VERIFY_READ, a ,sizeof(ca)); 939 if (!error) { 940 memcpy_fromfs(ca, a, sizeof(ca)); 941 error = verify_area(VERIFY_READ, ca , c); 942 if (!error) 943 memcpy_fromfs(b, ca, c); 944 } 945 return error; 946} 947static inline int IWCOPYPTR(const void *a, void *b, size_t c) { 948 caddr_t ca; 949 int error; 950 951 952 error = verify_area(VERIFY_READ, b ,sizeof(ca)); 953 if (!error) { 954 memcpy_fromfs(ca, b, sizeof(ca)); 955 error = verify_area(VERIFY_WRITE, ca, c); 956 if (!error) 957 memcpy_tofs(ca, a, c); 958 } 959 return error; 960} 961# else 962# define __KERNEL__ 963# undef INT_MAX 964# undef UINT_MAX 965# undef LONG_MAX 966# undef ULONG_MAX 967# define s8 __s8 968# define u8 __u8 969# define s16 __s16 970# define u16 __u16 971# define s32 __s32 972# define u32 __u32 973# include <linux/netdevice.h> 974# undef __KERNEL__ 975# endif 976# define ifnet device 977#else 978typedef struct tcphdr tcphdr_t; 979typedef struct udphdr udphdr_t; 980typedef struct icmp icmphdr_t; 981typedef struct ip ip_t; 982typedef struct ether_header ether_header_t; 983#endif /* linux */ 984typedef struct tcpiphdr tcpiphdr_t; 985 986#if defined(hpux) || defined(linux) 987struct ether_addr { 988 char ether_addr_octet[6]; 989}; 990#endif 991 992/* 993 * XXX - This is one of those *awful* hacks which nobody likes 994 */ 995#ifdef ultrix 996#define A_A 997#else 998#define A_A & 999#endif 1000 1001#ifndef ICMP_ROUTERADVERT 1002# define ICMP_ROUTERADVERT 9 1003#endif 1004#ifndef ICMP_ROUTERSOLICIT 1005# define ICMP_ROUTERSOLICIT 10 1006#endif 1007#undef ICMP_MAX_UNREACH 1008#define ICMP_MAX_UNREACH 14 1009#undef ICMP_MAXTYPE 1010#define ICMP_MAXTYPE 18 1011/* 1012 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data, 1013 * another IP header and then 64 bits of data, totalling 56. Of course, 1014 * the last 64 bits is dependant on that being available. 1015 */ 1016#define ICMPERR_ICMPHLEN 8 1017#define ICMPERR_IPICMPHLEN (20 + 8) 1018#define ICMPERR_MINPKTLEN (20 + 8 + 20) 1019#define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8) 1020#define ICMP6ERR_MINPKTLEN (40 + 8) 1021#define ICMP6ERR_IPICMPHLEN (40 + 8 + 40) 1022 1023/* 1024 * ECN is a new addition to TCP - RFC 2481 1025 */ 1026#ifndef TH_ECN 1027# define TH_ECN 0x40 1028#endif 1029#ifndef TH_CWR 1030# define TH_CWR 0x80 1031#endif 1032#define TH_ECNALL (TH_ECN|TH_CWR) 1033 1034#define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECN|TH_CWR) 1035 1036#endif /* __IP_COMPAT_H__ */ 1037