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