ip_compat.h revision 53642
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 53642 1999-11-23 21:44:59Z 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# else 210# if defined(IPFILTER_LKM) && !defined(KLD_MODULE) 211# define KLD_MODULE 212# endif 213# endif 214# endif 215#endif /* __FreeBSD__ && KERNEL */ 216 217/* 218 * Build some macros and #defines to enable the same code to compile anywhere 219 * Well, that's the idea, anyway :-) 220 */ 221#ifdef KERNEL 222# if SOLARIS 223# define ATOMIC_INC(x) { mutex_enter(&ipf_rw); (x)++; \ 224 mutex_exit(&ipf_rw); } 225# define ATOMIC_DEC(x) { mutex_enter(&ipf_rw); (x)--; \ 226 mutex_exit(&ipf_rw); } 227# define MUTEX_ENTER(x) mutex_enter(x) 228# if 1 229# define KRWLOCK_T krwlock_t 230# define READ_ENTER(x) rw_enter(x, RW_READER) 231# define WRITE_ENTER(x) rw_enter(x, RW_WRITER) 232# define RW_UPGRADE(x) { if (rw_tryupgrade(x) == 0) { \ 233 rw_exit(x); \ 234 rw_enter(x, RW_WRITER); } \ 235 } 236# define MUTEX_DOWNGRADE(x) rw_downgrade(x) 237# define RWLOCK_INIT(x, y, z) rw_init((x), (y), RW_DRIVER, (z)) 238# define RWLOCK_EXIT(x) rw_exit(x) 239# define RW_DESTROY(x) rw_destroy(x) 240# else 241# define KRWLOCK_T kmutex_t 242# define READ_ENTER(x) mutex_enter(x) 243# define WRITE_ENTER(x) mutex_enter(x) 244# define MUTEX_DOWNGRADE(x) ; 245# define RWLOCK_INIT(x, y, z) mutex_init((x), (y), MUTEX_DRIVER, (z)) 246# define RWLOCK_EXIT(x) mutex_exit(x) 247# define RW_DESTROY(x) mutex_destroy(x) 248# endif 249# define MUTEX_EXIT(x) mutex_exit(x) 250# define MTOD(m,t) (t)((m)->b_rptr) 251# define IRCOPY(a,b,c) copyin((a), (b), (c)) 252# define IWCOPY(a,b,c) copyout((a), (b), (c)) 253# define FREE_MB_T(m) freemsg(m) 254# define SPL_NET(x) ; 255# define SPL_IMP(x) ; 256# undef SPL_X 257# define SPL_X(x) ; 258# ifdef sparc 259# define ntohs(x) (x) 260# define ntohl(x) (x) 261# define htons(x) (x) 262# define htonl(x) (x) 263# endif /* sparc */ 264# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 265# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 266# define GET_MINOR(x) getminor(x) 267typedef struct qif { 268 struct qif *qf_next; 269 ill_t *qf_ill; 270 kmutex_t qf_lock; 271 void *qf_iptr; 272 void *qf_optr; 273 queue_t *qf_in; 274 queue_t *qf_out; 275 struct qinit *qf_wqinfo; 276 struct qinit *qf_rqinfo; 277 struct qinit qf_wqinit; 278 struct qinit qf_rqinit; 279 mblk_t *qf_m; /* These three fields are for passing data up from */ 280 queue_t *qf_q; /* fr_qin and fr_qout to the packet processing. */ 281 size_t qf_off; 282 size_t qf_len; /* this field is used for in ipfr_fastroute */ 283 char qf_name[8]; 284 /* 285 * in case the ILL has disappeared... 286 */ 287 size_t qf_hl; /* header length */ 288} qif_t; 289extern ill_t *get_unit __P((char *)); 290# define GETUNIT(n) get_unit((n)) 291# else /* SOLARIS */ 292# if defined(__sgi) 293# define hz HZ 294# include <sys/ksynch.h> 295# define IPF_LOCK_PL plhi 296# include <sys/sema.h> 297#undef kmutex_t 298typedef struct { 299 lock_t *l; 300 int pl; 301} kmutex_t; 302# define ATOMIC_INC(x) { MUTEX_ENTER(&ipf_rw); \ 303 (x)++; MUTEX_EXIT(&ipf_rw); } 304# define ATOMIC_DEC(x) { MUTEX_ENTER(&ipf_rw); \ 305 (x)--; MUTEX_EXIT(&ipf_rw); } 306# define MUTEX_ENTER(x) (x)->pl = LOCK((x)->l, IPF_LOCK_PL); 307# define KRWLOCK_T kmutex_t 308# define READ_ENTER(x) MUTEX_ENTER(x) 309# define WRITE_ENTER(x) MUTEX_ENTER(x) 310# define RW_UPGRADE(x) ; 311# define MUTEX_DOWNGRADE(x) ; 312# define RWLOCK_EXIT(x) MUTEX_EXIT(x) 313# define MUTEX_EXIT(x) UNLOCK((x)->l, (x)->pl); 314# else /* __sgi */ 315# define ATOMIC_INC(x) (x)++ 316# define ATOMIC_DEC(x) (x)-- 317# define MUTEX_ENTER(x) ; 318# define READ_ENTER(x) ; 319# define WRITE_ENTER(x) ; 320# define RW_UPGRADE(x) ; 321# define MUTEX_DOWNGRADE(x) ; 322# define RWLOCK_EXIT(x) ; 323# define MUTEX_EXIT(x) ; 324# endif /* __sgi */ 325# ifndef linux 326# define FREE_MB_T(m) m_freem(m) 327# define MTOD(m,t) mtod(m,t) 328# define IRCOPY(a,b,c) bcopy((a), (b), (c)) 329# define IWCOPY(a,b,c) bcopy((a), (b), (c)) 330# endif /* !linux */ 331# endif /* SOLARIS */ 332 333# ifdef sun 334# if !SOLARIS 335# include <sys/kmem_alloc.h> 336# define GETUNIT(n) ifunit((n), IFNAMSIZ) 337# endif 338# else 339# ifndef linux 340# define GETUNIT(n) ifunit((n)) 341# endif 342# endif /* sun */ 343 344# if defined(sun) && !defined(linux) || defined(__sgi) 345# define UIOMOVE(a,b,c,d) uiomove((caddr_t)a,b,c,d) 346# define SLEEP(id, n) sleep((id), PZERO+1) 347# define WAKEUP(id) wakeup(id) 348# define KFREE(x) kmem_free((char *)(x), sizeof(*(x))) 349# define KFREES(x,s) kmem_free((char *)(x), (s)) 350# if !SOLARIS 351extern void m_copydata __P((struct mbuf *, int, int, caddr_t)); 352extern void m_copyback __P((struct mbuf *, int, int, caddr_t)); 353# endif 354# ifdef __sgi 355# include <sys/kmem.h> 356# include <sys/ddi.h> 357# define KMALLOC(a,b) (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP) 358# define KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP) 359# define GET_MINOR(x) getminor(x) 360# else 361# if !SOLARIS 362# define KMALLOC(a,b) (a) = (b)new_kmem_alloc(sizeof(*(a)), \ 363 KMEM_NOSLEEP) 364# define KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP) 365# endif /* SOLARIS */ 366# endif /* __sgi */ 367# endif /* sun && !linux */ 368# ifndef GET_MINOR 369# define GET_MINOR(x) minor(x) 370# endif 371# if (BSD >= 199306) || defined(__FreeBSD__) 372# include <vm/vm.h> 373# if !defined(__FreeBSD__) || (defined (__FreeBSD__) && __FreeBSD__>=3) 374# include <vm/vm_extern.h> 375# include <sys/proc.h> 376extern vm_map_t kmem_map; 377# else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */ 378# include <vm/vm_kern.h> 379# endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD__>=3) */ 380# ifdef M_PFIL 381# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT) 382# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_PFIL, M_NOWAIT) 383# define KFREE(x) FREE((x), M_PFIL) 384# define KFREES(x,s) FREE((x), M_PFIL) 385# else 386# define KMALLOC(a, b) MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT) 387# define KMALLOCS(a, b, c) MALLOC((a), b, (c), M_TEMP, M_NOWAIT) 388# define KFREE(x) FREE((x), M_TEMP) 389# define KFREES(x,s) FREE((x), M_TEMP) 390# endif /* M_PFIL */ 391# define UIOMOVE(a,b,c,d) uiomove(a,b,d) 392# define SLEEP(id, n) tsleep((id), PPAUSE|PCATCH, n, 0) 393# define WAKEUP(id) wakeup(id) 394# endif /* BSD */ 395# if defined(NetBSD) && NetBSD <= 1991011 && NetBSD >= 199407 396# define SPL_NET(x) x = splsoftnet() 397# define SPL_X(x) (void) splx(x) 398# else 399# if !SOLARIS && !defined(linux) 400# define SPL_IMP(x) x = splimp() 401# define SPL_NET(x) x = splnet() 402# define SPL_X(x) (void) splx(x) 403# endif 404# endif /* NetBSD && NetBSD <= 1991011 && NetBSD >= 199407 */ 405# define PANIC(x,y) if (x) panic y 406#else /* KERNEL */ 407# define SLEEP(x,y) ; 408# define WAKEUP(x) ; 409# define PANIC(x,y) ; 410# define ATOMIC_INC(x) (x)++ 411# define ATOMIC_DEC(x) (x)-- 412# define MUTEX_ENTER(x) ; 413# define READ_ENTER(x) ; 414# define WRITE_ENTER(x) ; 415# define RW_UPGRADE(x) ; 416# define MUTEX_DOWNGRADE(x) ; 417# define RWLOCK_EXIT(x) ; 418# define MUTEX_EXIT(x) ; 419# define SPL_NET(x) ; 420# define SPL_IMP(x) ; 421# undef SPL_X 422# define SPL_X(x) ; 423# define KMALLOC(a,b) (a) = (b)malloc(sizeof(*a)) 424# define KMALLOCS(a,b,c) (a) = (b)malloc(c) 425# define KFREE(x) free(x) 426# define KFREES(x,s) free(x) 427# define GETUNIT(x) get_unit(x) 428# define IRCOPY(a,b,c) bcopy((a), (b), (c)) 429# define IWCOPY(a,b,c) bcopy((a), (b), (c)) 430#endif /* KERNEL */ 431 432#if SOLARIS 433typedef mblk_t mb_t; 434# if SOLARIS2 >= 7 435# ifdef lint 436# define ALIGN32(ptr) (ptr ? 0L : 0L) 437# define ALIGN16(ptr) (ptr ? 0L : 0L) 438# else 439# define ALIGN32(ptr) (ptr) 440# define ALIGN16(ptr) (ptr) 441# endif 442# endif 443#else 444# ifdef linux 445# ifndef kernel 446typedef struct mb { 447 struct mb *next; 448 u_int len; 449 u_char *data; 450} mb_t; 451# else 452typedef struct sk_buff mb_t; 453# endif 454# else 455typedef struct mbuf mb_t; 456# endif 457#endif /* SOLARIS */ 458 459#if defined(linux) || defined(__sgi) 460/* 461 * These #ifdef's are here mainly for linux, but who knows, they may 462 * not be in other places or maybe one day linux will grow up and some 463 * of these will turn up there too. 464 */ 465#ifndef ICMP_MINLEN 466# define ICMP_MINLEN 8 467#endif 468#ifndef ICMP_UNREACH 469# define ICMP_UNREACH ICMP_DEST_UNREACH 470#endif 471#ifndef ICMP_SOURCEQUENCH 472# define ICMP_SOURCEQUENCH ICMP_SOURCE_QUENCH 473#endif 474#ifndef ICMP_TIMXCEED 475# define ICMP_TIMXCEED ICMP_TIME_EXCEEDED 476#endif 477#ifndef ICMP_PARAMPROB 478# define ICMP_PARAMPROB ICMP_PARAMETERPROB 479#endif 480#ifndef ICMP_TSTAMP 481# define ICMP_TSTAMP ICMP_TIMESTAMP 482#endif 483#ifndef ICMP_TSTAMPREPLY 484# define ICMP_TSTAMPREPLY ICMP_TIMESTAMPREPLY 485#endif 486#ifndef ICMP_IREQ 487# define ICMP_IREQ ICMP_INFO_REQUEST 488#endif 489#ifndef ICMP_IREQREPLY 490# define ICMP_IREQREPLY ICMP_INFO_REPLY 491#endif 492#ifndef ICMP_MASKREQ 493# define ICMP_MASKREQ ICMP_ADDRESS 494#endif 495#ifndef ICMP_MASKREPLY 496# define ICMP_MASKREPLY ICMP_ADDRESSREPLY 497#endif 498#ifndef IPVERSION 499# define IPVERSION 4 500#endif 501#ifndef IPOPT_MINOFF 502# define IPOPT_MINOFF 4 503#endif 504#ifndef IPOPT_COPIED 505# define IPOPT_COPIED(x) ((x)&0x80) 506#endif 507#ifndef IPOPT_EOL 508# define IPOPT_EOL 0 509#endif 510#ifndef IPOPT_NOP 511# define IPOPT_NOP 1 512#endif 513#ifndef IP_MF 514# define IP_MF ((u_short)0x2000) 515#endif 516#ifndef ETHERTYPE_IP 517# define ETHERTYPE_IP ((u_short)0x0800) 518#endif 519#ifndef TH_FIN 520# define TH_FIN 0x01 521#endif 522#ifndef TH_SYN 523# define TH_SYN 0x02 524#endif 525#ifndef TH_RST 526# define TH_RST 0x04 527#endif 528#ifndef TH_PUSH 529# define TH_PUSH 0x08 530#endif 531#ifndef TH_ACK 532# define TH_ACK 0x10 533#endif 534#ifndef TH_URG 535# define TH_URG 0x20 536#endif 537#ifndef IPOPT_EOL 538# define IPOPT_EOL 0 539#endif 540#ifndef IPOPT_NOP 541# define IPOPT_NOP 1 542#endif 543#ifndef IPOPT_RR 544# define IPOPT_RR 7 545#endif 546#ifndef IPOPT_TS 547# define IPOPT_TS 68 548#endif 549#ifndef IPOPT_SECURITY 550# define IPOPT_SECURITY 130 551#endif 552#ifndef IPOPT_LSRR 553# define IPOPT_LSRR 131 554#endif 555#ifndef IPOPT_SATID 556# define IPOPT_SATID 136 557#endif 558#ifndef IPOPT_SSRR 559# define IPOPT_SSRR 137 560#endif 561#ifndef IPOPT_SECUR_UNCLASS 562# define IPOPT_SECUR_UNCLASS ((u_short)0x0000) 563#endif 564#ifndef IPOPT_SECUR_CONFID 565# define IPOPT_SECUR_CONFID ((u_short)0xf135) 566#endif 567#ifndef IPOPT_SECUR_EFTO 568# define IPOPT_SECUR_EFTO ((u_short)0x789a) 569#endif 570#ifndef IPOPT_SECUR_MMMM 571# define IPOPT_SECUR_MMMM ((u_short)0xbc4d) 572#endif 573#ifndef IPOPT_SECUR_RESTR 574# define IPOPT_SECUR_RESTR ((u_short)0xaf13) 575#endif 576#ifndef IPOPT_SECUR_SECRET 577# define IPOPT_SECUR_SECRET ((u_short)0xd788) 578#endif 579#ifndef IPOPT_SECUR_TOPSECRET 580# define IPOPT_SECUR_TOPSECRET ((u_short)0x6bc5) 581#endif 582#ifndef IPOPT_OLEN 583# define IPOPT_OLEN 1 584#endif 585#endif /* linux || __sgi */ 586 587#ifdef linux 588#include <linux/in_systm.h> 589/* 590 * TCP States 591 */ 592#define TCPS_CLOSED 0 /* closed */ 593#define TCPS_LISTEN 1 /* listening for connection */ 594#define TCPS_SYN_SENT 2 /* active, have sent syn */ 595#define TCPS_SYN_RECEIVED 3 /* have send and received syn */ 596/* states < TCPS_ESTABLISHED are those where connections not established */ 597#define TCPS_ESTABLISHED 4 /* established */ 598#define TCPS_CLOSE_WAIT 5 /* rcvd fin, waiting for close */ 599/* states > TCPS_CLOSE_WAIT are those where user has closed */ 600#define TCPS_FIN_WAIT_1 6 /* have closed, sent fin */ 601#define TCPS_CLOSING 7 /* closed xchd FIN; await FIN ACK */ 602#define TCPS_LAST_ACK 8 /* had fin and close; await FIN ACK */ 603/* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */ 604#define TCPS_FIN_WAIT_2 9 /* have closed, fin is acked */ 605#define TCPS_TIME_WAIT 10 /* in 2*msl quiet wait after close */ 606 607/* 608 * file flags. 609 */ 610#ifdef WRITE 611#define FWRITE WRITE 612#define FREAD READ 613#else 614#define FWRITE _IOC_WRITE 615#define FREAD _IOC_READ 616#endif 617/* 618 * mbuf related problems. 619 */ 620#define mtod(m,t) (t)((m)->data) 621#define m_len len 622#define m_next next 623 624#ifdef IP_DF 625#undef IP_DF 626#endif 627#define IP_DF 0x4000 628 629typedef struct { 630 __u16 th_sport; 631 __u16 th_dport; 632 __u32 th_seq; 633 __u32 th_ack; 634# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 635 defined(vax) 636 __u8 th_res:4; 637 __u8 th_off:4; 638#else 639 __u8 th_off:4; 640 __u8 th_res:4; 641#endif 642 __u8 th_flags; 643 __u16 th_win; 644 __u16 th_sum; 645 __u16 th_urp; 646} tcphdr_t; 647 648typedef struct { 649 __u16 uh_sport; 650 __u16 uh_dport; 651 __u16 uh_ulen; 652 __u16 uh_sum; 653} udphdr_t; 654 655typedef struct { 656# if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\ 657 defined(vax) 658 __u8 ip_hl:4; 659 __u8 ip_v:4; 660# else 661 __u8 ip_hl:4; 662 __u8 ip_v:4; 663# endif 664 __u8 ip_tos; 665 __u16 ip_len; 666 __u16 ip_id; 667 __u16 ip_off; 668 __u8 ip_ttl; 669 __u8 ip_p; 670 __u16 ip_sum; 671 struct in_addr ip_src; 672 struct in_addr ip_dst; 673} ip_t; 674 675/* 676 * Structure of an icmp header. 677 */ 678typedef struct icmp { 679 __u8 icmp_type; /* type of message, see below */ 680 __u8 icmp_code; /* type sub code */ 681 __u16 icmp_cksum; /* ones complement cksum of struct */ 682 union { 683 __u8 ih_pptr; /* ICMP_PARAMPROB */ 684 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 685 struct ih_idseq { 686 __u16 icd_id; 687 __u16 icd_seq; 688 } ih_idseq; 689 int ih_void; 690 } icmp_hun; 691# define icmp_pptr icmp_hun.ih_pptr 692# define icmp_gwaddr icmp_hun.ih_gwaddr 693# define icmp_id icmp_hun.ih_idseq.icd_id 694# define icmp_seq icmp_hun.ih_idseq.icd_seq 695# define icmp_void icmp_hun.ih_void 696 union { 697 struct id_ts { 698 n_time its_otime; 699 n_time its_rtime; 700 n_time its_ttime; 701 } id_ts; 702 struct id_ip { 703 ip_t idi_ip; 704 /* options and then 64 bits of data */ 705 } id_ip; 706 u_long id_mask; 707 char id_data[1]; 708 } icmp_dun; 709# define icmp_otime icmp_dun.id_ts.its_otime 710# define icmp_rtime icmp_dun.id_ts.its_rtime 711# define icmp_ttime icmp_dun.id_ts.its_ttime 712# define icmp_ip icmp_dun.id_ip.idi_ip 713# define icmp_mask icmp_dun.id_mask 714# define icmp_data icmp_dun.id_data 715} icmphdr_t; 716 717# ifndef LINUX_IPOVLY 718# define LINUX_IPOVLY 719struct ipovly { 720 caddr_t ih_next, ih_prev; /* for protocol sequence q's */ 721 u_char ih_x1; /* (unused) */ 722 u_char ih_pr; /* protocol */ 723 short ih_len; /* protocol length */ 724 struct in_addr ih_src; /* source internet address */ 725 struct in_addr ih_dst; /* destination internet address */ 726}; 727# endif 728 729typedef struct { 730 __u8 ether_dhost[6]; 731 __u8 ether_shost[6]; 732 __u16 ether_type; 733} ether_header_t; 734 735typedef struct uio { 736 int uio_resid; 737 int uio_rw; 738 caddr_t uio_buf; 739} uio_t; 740 741# define UIO_READ 0 742# define UIO_WRITE 1 743# define UIOMOVE(a, b, c, d) uiomove(a,b,c,d) 744 745/* 746 * For masking struct ifnet onto struct device 747 */ 748# define if_name name 749 750# ifdef KERNEL 751# define GETUNIT(x) dev_get(x) 752# define FREE_MB_T(m) kfree_skb(m, FREE_WRITE) 753# define uniqtime do_gettimeofday 754# undef INT_MAX 755# undef UINT_MAX 756# undef LONG_MAX 757# undef ULONG_MAX 758# include <linux/netdevice.h> 759# define SPL_X(x) 760# define SPL_NET(x) 761# define SPL_IMP(x) 762 763# define bcmp(a,b,c) memcmp(a,b,c) 764# define bcopy(a,b,c) memcpy(b,a,c) 765# define bzero(a,c) memset(a,0,c) 766 767# define UNITNAME(n) dev_get((n)) 768 769# define KMALLOC(a,b) (a) = (b)kmalloc(sizeof(*(a)), GFP_ATOMIC) 770# define KMALLOCS(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC) 771# define KFREE(x) kfree_s((x), sizeof(*(x))) 772# define KFREES(x,s) kfree_s((x), (s)) 773# define IRCOPY(a,b,c) { \ 774 error = verify_area(VERIFY_READ, (a) ,(c)); \ 775 if (!error) \ 776 memcpy_fromfs((b), (a), (c)); \ 777 } 778# define IWCOPY(a,b,c) { \ 779 error = verify_area(VERIFY_WRITE, (b), (c)); \ 780 if (!error) \ 781 memcpy_tofs((b), (a), (c)); \ 782 } 783# else 784# define __KERNEL__ 785# undef INT_MAX 786# undef UINT_MAX 787# undef LONG_MAX 788# undef ULONG_MAX 789# define s8 __s8 790# define u8 __u8 791# define s16 __s16 792# define u16 __u16 793# define s32 __s32 794# define u32 __u32 795# include <linux/netdevice.h> 796# undef __KERNEL__ 797# endif 798# define ifnet device 799#else 800typedef struct tcphdr tcphdr_t; 801typedef struct udphdr udphdr_t; 802typedef struct icmp icmphdr_t; 803typedef struct ip ip_t; 804typedef struct ether_header ether_header_t; 805#endif /* linux */ 806typedef struct tcpiphdr tcpiphdr_t; 807 808#if defined(hpux) || defined(linux) 809struct ether_addr { 810 char ether_addr_octet[6]; 811}; 812#endif 813 814/* 815 * XXX - This is one of those *awful* hacks which nobody likes 816 */ 817#ifdef ultrix 818#define A_A 819#else 820#define A_A & 821#endif 822 823#ifndef ICMP_ROUTERADVERT 824# define ICMP_ROUTERADVERT 9 825#endif 826#ifndef ICMP_ROUTERSOLICIT 827# define ICMP_ROUTERSOLICIT 10 828#endif 829/* 830 * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data, 831 * another IP header and then 64 bits of data, totalling 56. Of course, 832 * the last 64 bits is dependant on that being available. 833 */ 834#define ICMPERR_ICMPHLEN 8 835#define ICMPERR_IPICMPHLEN (20 + 8) 836#define ICMPERR_MINPKTLEN (20 + 8 + 20) 837#define ICMPERR_MAXPKTLEN (20 + 8 + 20 + 8) 838 839#endif /* __IP_COMPAT_H__ */ 840