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