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