Use the _KERNEL_STRUCTURES define to allow userland to bring in kernel
[dragonfly.git] / sys / contrib / ipfilter / netinet / ip_compat.h
1 /*
2  * Copyright (C) 1993-2001 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * @(#)ip_compat.h      1.8 1/14/96
7  * $Id: ip_compat.h,v 2.26.2.46 2002/06/27 14:39:40 darrenr Exp $
8  * $FreeBSD: src/sys/contrib/ipfilter/netinet/ip_compat.h,v 1.13.2.5 2003/03/01 03:55:54 darrenr Exp $
9  * $DragonFly: src/sys/contrib/ipfilter/netinet/ip_compat.h,v 1.7 2003/10/09 03:31:33 dillon Exp $
10  */
11
12 #ifndef __IP_COMPAT_H__
13 #define __IP_COMPAT_H__
14
15 #ifndef __STDC__
16 # undef         const
17 # define        const
18 #endif
19
20 #ifndef SOLARIS
21 #define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
22 #endif
23 #if SOLARIS
24 # if !defined(SOLARIS2)
25 #  define       SOLARIS2        3       /* Pick an old version */
26 # endif
27 # if SOLARIS2 >= 8
28 #  ifndef       USE_INET6
29 #   define      USE_INET6
30 #  endif
31 # else
32 #  undef        USE_INET6
33 # endif
34 #endif
35 #if defined(sun) && !(defined(__svr4__) || defined(__SVR4))
36 # undef USE_INET6
37 #endif
38
39 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
40 # undef KERNEL
41 # undef _KERNEL
42 # undef         __KERNEL__
43 # define        KERNEL
44 # define        _KERNEL
45 # define        __KERNEL__
46 #endif
47
48 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
49 #define index   strchr
50 # if !defined(KERNEL)
51 #  define       bzero(a,b)      memset(a,0,b)
52 #  define       bcmp            memcmp
53 #  define       bcopy(a,b,c)    memmove(b,a,c)
54 # endif
55 #endif
56
57 #ifndef offsetof
58 #define offsetof(t,m) (int)((&((t *)0L)->m))
59 #endif
60
61 #if defined(__sgi) || defined(bsdi)
62 struct  ether_addr {
63         u_char  ether_addr_octet[6];
64 };
65 #endif
66
67 #ifndef LIFNAMSIZ
68 # ifdef IF_NAMESIZE
69 #  define       LIFNAMSIZ       IF_NAMESIZE
70 # else
71 #  ifdef        IFNAMSIZ
72 #   define      LIFNAMSIZ       IFNAMSIZ
73 #  else
74 #   define      LIFNAMSIZ       16
75 #  endif
76 # endif
77 #endif
78
79 #if defined(__sgi) && !defined(IPFILTER_LKM)
80 # ifdef __STDC__
81 #  define IPL_EXTERN(ep) ipfilter##ep
82 # else
83 #  define IPL_EXTERN(ep) ipfilter/**/ep
84 # endif
85 #else
86 # ifdef __STDC__
87 #  define IPL_EXTERN(ep) ipl##ep
88 # else
89 #  define IPL_EXTERN(ep) ipl/**/ep
90 # endif
91 #endif
92
93 #ifdef __sgi
94 # include       <sys/debug.h>
95 #endif
96
97 #ifdef  linux
98 # include <sys/sysmacros.h>
99 #endif
100
101 /*
102  * This is a workaround for <sys/uio.h> troubles on FreeBSD
103  */
104 #ifndef _KERNEL
105 # define ADD_KERNEL
106 # define _KERNEL_STRUCTURES
107 #endif
108 #ifdef __OpenBSD__
109 struct file;
110 #endif
111 #include <sys/uio.h>
112 #ifdef ADD_KERNEL
113 # undef _KERNEL_STRUCTURES
114 #endif
115
116 #if     SOLARIS
117 # define        MTYPE(m)        ((m)->b_datap->db_type)
118 # if SOLARIS2 >= 4
119 #  include      <sys/isa_defs.h>
120 # endif
121 # include       <sys/ioccom.h>
122 # include       <sys/sysmacros.h>
123 # include       <sys/kmem.h>
124 /*
125  * because Solaris 2 defines these in two places :-/
126  */
127 # undef IPOPT_EOL
128 # undef IPOPT_NOP
129 # undef IPOPT_LSRR
130 # undef IPOPT_RR
131 # undef IPOPT_SSRR
132 # ifndef        KERNEL
133 #  define       _KERNEL
134 #  undef        RES_INIT
135 #  if SOLARIS2 >= 8
136 #   include <netinet/ip6.h>
137 #  endif
138 #  include <inet/common.h>
139 #  include <inet/ip.h>
140 #  include <inet/ip_ire.h>
141 #  undef        _KERNEL
142 # else /* _KERNEL */
143 #  if SOLARIS2 >= 8
144 #   include <netinet/ip6.h>
145 #  endif
146 #  include <inet/common.h>
147 #  include <inet/ip.h>
148 #  include <inet/ip_ire.h>
149 # endif /* _KERNEL */
150 # if SOLARIS2 >= 8
151 #  include <inet/ip_if.h>
152 #  include <netinet/ip6.h>
153 #  define       ipif_local_addr ipif_lcl_addr
154 /* Only defined in private include file */
155 #  ifndef       V4_PART_OF_V6
156 #   define      V4_PART_OF_V6(v6)       v6.s6_addr32[3]
157 #  endif
158 # endif
159
160 typedef struct  qif     {
161         struct  qif     *qf_next;
162         ill_t   *qf_ill;
163         kmutex_t        qf_lock;
164         void    *qf_iptr;
165         void    *qf_optr;
166         queue_t *qf_in;
167         queue_t *qf_out;
168         struct  qinit   *qf_wqinfo;
169         struct  qinit   *qf_rqinfo;
170         struct  qinit   qf_wqinit;
171         struct  qinit   qf_rqinit;
172         mblk_t  *qf_m;  /* These three fields are for passing data up from */
173         queue_t *qf_q;  /* fr_qin and fr_qout to the packet processing. */
174         size_t  qf_off;
175         size_t  qf_len; /* this field is used for in ipfr_fastroute */
176         char    qf_name[LIFNAMSIZ];
177         /*
178          * in case the ILL has disappeared...
179          */
180         size_t  qf_hl;  /* header length */
181         int     qf_sap;
182 # if SOLARIS2 >= 8
183         int     qf_tunoff;      /* tunnel offset */
184 #endif
185         size_t  qf_incnt;
186         size_t  qf_outcnt;
187 } qif_t;
188 #else /* SOLARIS */
189 # if !defined(__sgi)
190 typedef  int    minor_t;
191 # endif
192 #endif /* SOLARIS */
193 #define IPMINLEN(i, h)  ((i)->ip_len >= ((i)->ip_hl * 4 + sizeof(struct h)))
194
195 #ifndef IP_OFFMASK
196 #define IP_OFFMASK      0x1fff
197 #endif
198
199 #if     BSD > 199306
200 # define        USE_QUAD_T
201 # define        U_QUAD_T        u_quad_t
202 # define        QUAD_T          quad_t
203 #else /* BSD > 199306 */
204 # define        U_QUAD_T        u_long
205 # define        QUAD_T          long
206 #endif /* BSD > 199306 */
207
208
209 #if defined(__FreeBSD__) && (defined(KERNEL) || defined(_KERNEL))
210 # include <sys/param.h>
211 # ifndef __FreeBSD_version
212 #  ifdef IPFILTER_LKM
213 #   include <osreldate.h>
214 #  else
215 #   include <sys/osreldate.h>
216 #  endif
217 # endif
218 # ifdef IPFILTER_LKM
219 #  define       ACTUALLY_LKM_NOT_KERNEL
220 # endif
221 # if defined(__FreeBSD_version) && (__FreeBSD_version < 300000)
222 #  include <machine/spl.h>
223 # else
224 #  if (__FreeBSD_version >= 300000) && (__FreeBSD_version < 400000)
225 #   if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
226 #    define     ACTUALLY_LKM_NOT_KERNEL
227 #   endif
228 #  endif
229 # endif
230 #endif /* __FreeBSD__ && KERNEL */
231
232 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 500000) && \
233     defined(_KERNEL)
234 # include <machine/in_cksum.h>
235 #endif
236
237 /*
238  * These operating systems already take care of the problem for us.
239  */
240 #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
241     defined(__sgi)
242 typedef u_int32_t       u_32_t;
243 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
244 #  if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
245 #   include "opt_inet.h"
246 #  endif
247 #  if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
248       !defined(KLD_MODULE)
249 #   include "opt_inet6.h"
250 #  endif
251 #  ifdef INET6
252 #   define USE_INET6     
253 #  endif   
254 # endif
255 # if !defined(_KERNEL) && !defined(IPFILTER_LKM) && !defined(USE_INET6)
256 #  if (defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)) || \
257       (defined(OpenBSD) && (OpenBSD >= 200111)) || \
258       (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000))
259 #   define USE_INET6
260 #  endif
261 # endif
262 #else
263 /*
264  * Really, any arch where sizeof(long) != sizeof(int).
265  */
266 # if defined(__alpha__) || defined(__alpha) || defined(_LP64)
267 typedef unsigned int    u_32_t;
268 # else
269 #  if SOLARIS2 >= 6
270 typedef uint32_t        u_32_t;
271 #  else
272 typedef unsigned int    u_32_t;
273 #  endif
274 # endif
275 #endif /* __NetBSD__ || __OpenBSD__ || __FreeBSD__ || __sgi */
276
277 #ifdef  USE_INET6
278 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
279 #  include <netinet/ip6.h>
280 #  ifdef        _KERNEL
281 #   include <netinet6/ip6_var.h>
282 #  endif
283 typedef struct ip6_hdr  ip6_t;
284 # endif
285 # include <netinet/icmp6.h>
286 union   i6addr  {
287         u_32_t  i6[4];
288         struct  in_addr in4;
289         struct  in6_addr in6;
290 };
291 #else
292 union   i6addr  {
293         u_32_t  i6[4];
294         struct  in_addr in4;
295 };
296 #endif
297
298 #define IP6CMP(a,b)     bcmp((char *)&(a), (char *)&(b), sizeof(a))
299 #define IP6EQ(a,b)      (bcmp((char *)&(a), (char *)&(b), sizeof(a)) == 0)
300 #define IP6NEQ(a,b)     (bcmp((char *)&(a), (char *)&(b), sizeof(a)) != 0)
301 #define IP6_ISZERO(a)   ((((union i6addr *)(a))->i6[0] | \
302                           ((union i6addr *)(a))->i6[1] | \
303                           ((union i6addr *)(a))->i6[2] | \
304                           ((union i6addr *)(a))->i6[3]) == 0)
305 #define IP6_NOTZERO(a)  ((((union i6addr *)(a))->i6[0] | \
306                           ((union i6addr *)(a))->i6[1] | \
307                           ((union i6addr *)(a))->i6[2] | \
308                           ((union i6addr *)(a))->i6[3]) != 0)
309
310 #ifndef MAX
311 #define MAX(a,b)        (((a) > (b)) ? (a) : (b))
312 #endif
313
314 /*
315  * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
316  *
317  * Basic Option
318  *
319  * 00000001   -   (Reserved 4)
320  * 00111101   -   Top Secret
321  * 01011010   -   Secret
322  * 10010110   -   Confidential
323  * 01100110   -   (Reserved 3)
324  * 11001100   -   (Reserved 2)
325  * 10101011   -   Unclassified
326  * 11110001   -   (Reserved 1)
327  */
328 #define IPSO_CLASS_RES4         0x01
329 #define IPSO_CLASS_TOPS         0x3d
330 #define IPSO_CLASS_SECR         0x5a
331 #define IPSO_CLASS_CONF         0x96
332 #define IPSO_CLASS_RES3         0x66
333 #define IPSO_CLASS_RES2         0xcc
334 #define IPSO_CLASS_UNCL         0xab
335 #define IPSO_CLASS_RES1         0xf1
336
337 #define IPSO_AUTH_GENSER        0x80
338 #define IPSO_AUTH_ESI           0x40
339 #define IPSO_AUTH_SCI           0x20
340 #define IPSO_AUTH_NSA           0x10
341 #define IPSO_AUTH_DOE           0x08
342 #define IPSO_AUTH_UN            0x06
343 #define IPSO_AUTH_FTE           0x01
344
345 /*
346  * IP option #defines
347  */
348 /*#define       IPOPT_RR        7 */
349 #define IPOPT_ZSU       10      /* ZSU */
350 #define IPOPT_MTUP      11      /* MTUP */
351 #define IPOPT_MTUR      12      /* MTUR */
352 #define IPOPT_ENCODE    15      /* ENCODE */
353 /*#define       IPOPT_TS        68 */
354 #define IPOPT_TR        82      /* TR */
355 /*#define       IPOPT_SECURITY  130 */
356 /*#define       IPOPT_LSRR      131 */
357 #define IPOPT_E_SEC     133     /* E-SEC */
358 #define IPOPT_CIPSO     134     /* CIPSO */
359 /*#define       IPOPT_SATID     136 */
360 #ifndef IPOPT_SID
361 # define        IPOPT_SID       IPOPT_SATID
362 #endif
363 /*#define       IPOPT_SSRR      137 */
364 #define IPOPT_ADDEXT    147     /* ADDEXT */
365 #define IPOPT_VISA      142     /* VISA */
366 #define IPOPT_IMITD     144     /* IMITD */
367 #define IPOPT_EIP       145     /* EIP */
368 #define IPOPT_FINN      205     /* FINN */
369
370 #ifndef TCPOPT_WSCALE
371 # define        TCPOPT_WSCALE   3
372 #endif
373
374 /*
375  * Build some macros and #defines to enable the same code to compile anywhere
376  * Well, that's the idea, anyway :-)
377  */
378 #if SOLARIS
379 typedef mblk_t mb_t;
380 # if SOLARIS2 >= 7
381 #  ifdef lint
382 #   define ALIGN32(ptr)    (ptr ? 0L : 0L)
383 #   define ALIGN16(ptr)    (ptr ? 0L : 0L)
384 #  else
385 #   define ALIGN32(ptr)    (ptr)
386 #   define ALIGN16(ptr)    (ptr)
387 #  endif
388 # endif
389 #else
390 typedef struct mbuf mb_t;
391 #endif /* SOLARIS */
392
393 #if !SOLARIS || (SOLARIS2 < 6) || !defined(KERNEL)
394 # define        ATOMIC_INCL             ATOMIC_INC
395 # define        ATOMIC_INC64            ATOMIC_INC
396 # define        ATOMIC_INC32            ATOMIC_INC
397 # define        ATOMIC_INC16            ATOMIC_INC
398 # define        ATOMIC_DECL             ATOMIC_DEC
399 # define        ATOMIC_DEC64            ATOMIC_DEC
400 # define        ATOMIC_DEC32            ATOMIC_DEC
401 # define        ATOMIC_DEC16            ATOMIC_DEC
402 #endif
403 #ifdef __sgi
404 # define  hz HZ
405 # include <sys/ksynch.h>
406 # define        IPF_LOCK_PL     plhi
407 # include <sys/sema.h>
408 #undef kmutex_t
409 typedef struct {
410         lock_t *l;
411         int pl;
412 } kmutex_t;
413 # undef MUTEX_INIT
414 # undef MUTEX_DESTROY
415 #endif
416 #ifdef KERNEL
417 # if SOLARIS
418 #  if SOLARIS2 >= 6
419 #   include <sys/atomic.h>
420 #   if SOLARIS2 == 6
421 #    define     ATOMIC_INCL(x)          atomic_add_long((uint32_t*)&(x), 1)
422 #    define     ATOMIC_DECL(x)          atomic_add_long((uint32_t*)&(x), -1)
423 #   else
424 #    define     ATOMIC_INCL(x)          atomic_add_long(&(x), 1)
425 #    define     ATOMIC_DECL(x)          atomic_add_long(&(x), -1)
426 #   endif
427 #   define      ATOMIC_INC64(x)         atomic_add_64((uint64_t*)&(x), 1)
428 #   define      ATOMIC_INC32(x)         atomic_add_32((uint32_t*)&(x), 1)
429 #   define      ATOMIC_INC16(x)         atomic_add_16((uint16_t*)&(x), 1)
430 #   define      ATOMIC_DEC64(x)         atomic_add_64((uint64_t*)&(x), -1)
431 #   define      ATOMIC_DEC32(x)         atomic_add_32((uint32_t*)&(x), -1)
432 #   define      ATOMIC_DEC16(x)         atomic_add_16((uint16_t*)&(x), -1)
433 #  else
434 #   define      IRE_CACHE               IRE_ROUTE
435 #   define      ATOMIC_INC(x)           { mutex_enter(&ipf_rw); (x)++; \
436                                           mutex_exit(&ipf_rw); }
437 #   define      ATOMIC_DEC(x)           { mutex_enter(&ipf_rw); (x)--; \
438                                           mutex_exit(&ipf_rw); }
439 #  endif
440 #  define       MUTEX_ENTER(x)          mutex_enter(x)
441 #  if 1
442 #   define      KRWLOCK_T               krwlock_t
443 #   define      READ_ENTER(x)           rw_enter(x, RW_READER)
444 #   define      WRITE_ENTER(x)          rw_enter(x, RW_WRITER)
445 #   define      RW_UPGRADE(x)           { if (rw_tryupgrade(x) == 0) { \
446                                               rw_exit(x); \
447                                               rw_enter(x, RW_WRITER); } \
448                                         }
449 #   define      MUTEX_DOWNGRADE(x)      rw_downgrade(x)
450 #   define      RWLOCK_INIT(x, y, z)    rw_init((x), (y), RW_DRIVER, (z))
451 #   define      RWLOCK_EXIT(x)          rw_exit(x)
452 #   define      RW_DESTROY(x)           rw_destroy(x)
453 #  else
454 #   define      KRWLOCK_T               kmutex_t
455 #   define      READ_ENTER(x)           mutex_enter(x)
456 #   define      WRITE_ENTER(x)          mutex_enter(x)
457 #   define      MUTEX_DOWNGRADE(x)      ;
458 #   define      RWLOCK_INIT(x, y, z)    mutex_init((x), (y), MUTEX_DRIVER, (z))
459 #   define      RWLOCK_EXIT(x)          mutex_exit(x)
460 #   define      RW_DESTROY(x)           mutex_destroy(x)
461 #  endif
462 #  define       MUTEX_INIT(x, y, z)     mutex_init((x), (y), MUTEX_DRIVER, (z))
463 #  define       MUTEX_DESTROY(x)        mutex_destroy(x)
464 #  define       MUTEX_EXIT(x)   mutex_exit(x)
465 #  define       MTOD(m,t)       (t)((m)->b_rptr)
466 #  define       IRCOPY(a,b,c)   copyin((caddr_t)(a), (caddr_t)(b), (c))
467 #  define       IWCOPY(a,b,c)   copyout((caddr_t)(a), (caddr_t)(b), (c))
468 #  define       IRCOPYPTR       ircopyptr
469 #  define       IWCOPYPTR       iwcopyptr
470 #  define       FREE_MB_T(m)    freemsg(m)
471 #  define       SPL_NET(x)      ;
472 #  define       SPL_IMP(x)      ;
473 #  undef        SPL_X
474 #  define       SPL_X(x)        ;
475 #  ifdef sparc
476 #   define      ntohs(x)        (x)
477 #   define      ntohl(x)        (x)
478 #   define      htons(x)        (x)
479 #   define      htonl(x)        (x)
480 #  endif /* sparc */
481 #  define       KMALLOC(a,b)    (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
482 #  define       KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
483 #  define       GET_MINOR(x)    getminor(x)
484 extern  ill_t   *get_unit (char *, int);
485 #  define       GETUNIT(n, v)   get_unit(n, v)
486 #  define       IFNAME(x)       ((ill_t *)x)->ill_name
487 # else /* SOLARIS */
488 #  if defined(__sgi)
489 #   define      ATOMIC_INC(x)           { MUTEX_ENTER(&ipf_rw); \
490                                           (x)++; MUTEX_EXIT(&ipf_rw); }
491 #   define      ATOMIC_DEC(x)           { MUTEX_ENTER(&ipf_rw); \
492                                           (x)--; MUTEX_EXIT(&ipf_rw); }
493 #   define      MUTEX_ENTER(x)          (x)->pl = LOCK((x)->l, IPF_LOCK_PL);
494 #   define      KRWLOCK_T               kmutex_t
495 #   define      READ_ENTER(x)           MUTEX_ENTER(x)
496 #   define      WRITE_ENTER(x)          MUTEX_ENTER(x)
497 #   define      RW_UPGRADE(x)           ;
498 #   define      MUTEX_DOWNGRADE(x)      ;
499 #   define      RWLOCK_EXIT(x)          MUTEX_EXIT(x)
500 #   define      MUTEX_EXIT(x)           UNLOCK((x)->l, (x)->pl);
501 #   define      MUTEX_INIT(x,y,z)       (x)->l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
502 #   define      MUTEX_DESTROY(x)        LOCK_DEALLOC((x)->l)
503 #  else /* __sgi */
504 #   define      ATOMIC_INC(x)           (x)++
505 #   define      ATOMIC_DEC(x)           (x)--
506 #   define      MUTEX_ENTER(x)          ;
507 #   define      READ_ENTER(x)           ;
508 #   define      WRITE_ENTER(x)          ;
509 #   define      RW_UPGRADE(x)           ;
510 #   define      MUTEX_DOWNGRADE(x)      ;
511 #   define      RWLOCK_EXIT(x)          ;
512 #   define      MUTEX_EXIT(x)           ;
513 #   define      MUTEX_INIT(x,y,z)       ;
514 #   define      MUTEX_DESTROY(x)        ;
515 #  endif /* __sgi */
516 #  ifndef linux
517 #   define      FREE_MB_T(m)    m_freem(m)
518 #   define      MTOD(m,t)       mtod(m,t)
519 #   define      IRCOPY(a,b,c)   (bcopy((a), (b), (c)), 0)
520 #   define      IWCOPY(a,b,c)   (bcopy((a), (b), (c)), 0)
521 #   define      IRCOPYPTR       ircopyptr
522 #   define      IWCOPYPTR       iwcopyptr
523 #  endif /* !linux */
524 # endif /* SOLARIS */
525
526 # ifdef sun
527 #  if !SOLARIS
528 #   include     <sys/time.h>
529 #   include     <sys/kmem_alloc.h>
530 #   define      GETUNIT(n, v)   ifunit(n, IFNAMSIZ)
531 #   define      IFNAME(x)       ((struct ifnet *)x)->if_name
532 #  endif
533 # else
534 #  ifndef       linux
535 #   define      GETUNIT(n, v)   ifunit(n)
536 #   if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199606)) || \
537         (defined(OpenBSD) && (OpenBSD >= 199603))
538 #    define     IFNAME(x)       ((struct ifnet *)x)->if_xname
539 #   else
540 #    define     USE_GETIFNAME   1
541 #    define     IFNAME(x)       get_ifname((struct ifnet *)x)
542 extern  char    *get_ifname (struct ifnet *);
543 #   endif
544 #  endif
545 # endif /* sun */
546
547 # if defined(sun) && !defined(linux) || defined(__sgi)
548 #  define       UIOMOVE(a,b,c,d)        uiomove((caddr_t)a,b,c,d)
549 #  define       SLEEP(id, n)    sleep((id), 0)
550 #  define       WAKEUP(id)      wakeup(id)
551 #  define       KFREE(x)        kmem_free((char *)(x), sizeof(*(x)))
552 #  define       KFREES(x,s)     kmem_free((char *)(x), (s))
553 #  if !SOLARIS
554 extern  void    m_copydata (struct mbuf *, int, int, caddr_t);
555 extern  void    m_copyback (struct mbuf *, int, int, caddr_t);
556 #  endif
557 #  ifdef __sgi
558 #   include <sys/kmem.h>
559 #   include <sys/ddi.h>
560 #   define      KMALLOC(a,b)    (a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
561 #   define      KMALLOCS(a,b,c) (a) = (b)kmem_alloc((c), KM_NOSLEEP)
562 #   define      GET_MINOR(x)    getminor(x)
563 #  else
564 #   if !SOLARIS
565 #    define     KMALLOC(a,b)    (a) = (b)new_kmem_alloc(sizeof(*(a)), \
566                                                         KMEM_NOSLEEP)
567 #    define     KMALLOCS(a,b,c) (a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
568 #   endif /* SOLARIS */
569 #  endif /* __sgi */
570 # endif /* sun && !linux */
571 # ifndef        GET_MINOR
572 #  define       GET_MINOR(x)    minor(x)
573 # endif
574 # if (BSD >= 199306) || defined(__FreeBSD__)
575 #  if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
576        defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
577        defined(_BSDI_VERSION)
578 #   include <vm/vm.h>
579 #  endif
580 #  if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
581       (__FreeBSD_version >= 300000))
582 #   if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
583        (defined(OpenBSD) && (OpenBSD >= 200111))
584 #    include <uvm/uvm_extern.h>
585 #   else
586 #    include <vm/vm_extern.h>
587 #   endif
588 #   include <sys/proc.h>
589 #  else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
590 #   include <vm/vm_kern.h>
591 #  endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
592 #  ifdef        M_PFIL
593 #   define      KMALLOC(a, b)   MALLOC((a), b, sizeof(*(a)), M_PFIL, M_NOWAIT)
594 #   define      KMALLOCS(a, b, c)       MALLOC((a), b, (c), M_PFIL, M_NOWAIT)
595 #   define      KFREE(x)        FREE((x), M_PFIL)
596 #   define      KFREES(x,s)     FREE((x), M_PFIL)
597 #  else
598 #   define      KMALLOC(a, b)   MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
599 #   define      KMALLOCS(a, b, c)       MALLOC((a), b, (c), M_TEMP, M_NOWAIT)
600 #   define      KFREE(x)        FREE((x), M_TEMP)
601 #   define      KFREES(x,s)     FREE((x), M_TEMP)
602 #  endif /* M_PFIL */
603 #  define       UIOMOVE(a,b,c,d)        uiomove(a,b,d)
604 #  define       SLEEP(id, n)    tsleep((id), PCATCH, n, 0)
605 #  define       WAKEUP(id)      wakeup(id)
606 # endif /* BSD */
607 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
608      (defined(OpenBSD) && (OpenBSD >= 200006))
609 #  define       SPL_NET(x)      x = splsoftnet()
610 #  define       SPL_X(x)        (void) splx(x)
611 # else
612 #  if !SOLARIS && !defined(linux)
613 #   define      SPL_IMP(x)      x = splimp()
614 #   define      SPL_NET(x)      x = splnet()
615 #   define      SPL_X(x)        (void) splx(x)
616 #  endif
617 # endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
618 # define        PANIC(x,y)      if (x) panic y
619 #else /* KERNEL */
620 # define        SLEEP(x,y)      1
621 # define        WAKEUP(x)       ;
622 # define        PANIC(x,y)      ;
623 # define        ATOMIC_INC(x)   (x)++
624 # define        ATOMIC_DEC(x)   (x)--
625 # define        MUTEX_ENTER(x)  ;
626 # define        READ_ENTER(x)   ;
627 # define        MUTEX_INIT(x,y,z)       ;
628 # define        MUTEX_DESTROY(x)        ;
629 # define        WRITE_ENTER(x)  ;
630 # define        RW_UPGRADE(x)   ;
631 # define        MUTEX_DOWNGRADE(x)      ;
632 # define        RWLOCK_EXIT(x)  ;
633 # define        MUTEX_EXIT(x)   ;
634 # define        SPL_NET(x)      ;
635 # define        SPL_IMP(x)      ;
636 # undef         SPL_X
637 # define        SPL_X(x)        ;
638 # define        KMALLOC(a,b)    (a) = (b)malloc(sizeof(*a))
639 # define        KMALLOCS(a,b,c) (a) = (b)malloc(c)
640 # define        KFREE(x)        free(x)
641 # define        KFREES(x,s)     free(x)
642 # define        FREE_MB_T(x)    ;
643 # define        GETUNIT(x, v)   get_unit(x,v)
644 # define        IRCOPY(a,b,c)   (bcopy((a), (b), (c)), 0)
645 # define        IWCOPY(a,b,c)   (bcopy((a), (b), (c)), 0)
646 # define        IRCOPYPTR       ircopyptr
647 # define        IWCOPYPTR       iwcopyptr
648 # define        IFNAME(x)       get_ifname((struct ifnet *)x)
649 # define        UIOMOVE(a,b,c,d)        ipfuiomove(a,b,c,d)
650 # include       <sys/time.h>
651 extern  void    m_copydata (mb_t *, int, int, caddr_t);
652 extern  int     ipfuiomove (caddr_t, int, int, struct uio *);
653 #endif /* KERNEL */
654
655 /*
656  * These #ifdef's are here mainly for linux, but who knows, they may
657  * not be in other places or maybe one day linux will grow up and some
658  * of these will turn up there too.
659  */
660 #ifndef ICMP_MINLEN
661 # define        ICMP_MINLEN     8
662 #endif
663 #ifndef ICMP_ECHOREPLY
664 # define        ICMP_ECHOREPLY  0
665 #endif
666 #ifndef ICMP_UNREACH
667 # define        ICMP_UNREACH    3
668 #endif
669 #ifndef ICMP_UNREACH_NET
670 # define        ICMP_UNREACH_NET        0
671 #endif
672 #ifndef ICMP_UNREACH_HOST
673 # define        ICMP_UNREACH_HOST       1
674 #endif
675 #ifndef ICMP_UNREACH_PROTOCOL
676 # define        ICMP_UNREACH_PROTOCOL   2
677 #endif
678 #ifndef ICMP_UNREACH_PORT
679 # define        ICMP_UNREACH_PORT       3
680 #endif
681 #ifndef ICMP_UNREACH_NEEDFRAG
682 # define        ICMP_UNREACH_NEEDFRAG   4
683 #endif
684 #ifndef ICMP_UNREACH_SRCFAIL
685 # define        ICMP_UNREACH_SRCFAIL    5
686 #endif
687 #ifndef ICMP_UNREACH_NET_UNKNOWN
688 # define        ICMP_UNREACH_NET_UNKNOWN        6
689 #endif
690 #ifndef ICMP_UNREACH_HOST_UNKNOWN
691 # define        ICMP_UNREACH_HOST_UNKNOWN       7
692 #endif
693 #ifndef ICMP_UNREACH_ISOLATED
694 # define        ICMP_UNREACH_ISOLATED   8
695 #endif
696 #ifndef ICMP_UNREACH_NET_PROHIB
697 # define        ICMP_UNREACH_NET_PROHIB 9
698 #endif
699 #ifndef ICMP_UNREACH_HOST_PROHIB
700 # define        ICMP_UNREACH_HOST_PROHIB        10
701 #endif
702 #ifndef ICMP_UNREACH_TOSNET
703 # define        ICMP_UNREACH_TOSNET     11
704 #endif
705 #ifndef ICMP_UNREACH_TOSHOST
706 # define        ICMP_UNREACH_TOSHOST    12
707 #endif
708 #ifndef ICMP_UNREACH_ADMIN_PROHIBIT
709 # define        ICMP_UNREACH_ADMIN_PROHIBIT     13
710 #endif
711 #ifndef ICMP_UNREACH_HOST_PRECEDENCE
712 # define        ICMP_UNREACH_HOST_PRECEDENCE    14
713 #endif
714 #ifndef ICMP_UNREACH_PRECEDENCE_CUTOFF
715 # define        ICMP_UNREACH_PRECEDENCE_CUTOFF  15
716 #endif
717 #ifndef ICMP_SOURCEQUENCH
718 # define        ICMP_SOURCEQUENCH       4
719 #endif
720 #ifndef ICMP_REDIRECT_NET
721 # define        ICMP_REDIRECT_NET       0
722 #endif
723 #ifndef ICMP_REDIRECT_HOST
724 # define        ICMP_REDIRECT_HOST      1
725 #endif
726 #ifndef ICMP_REDIRECT_TOSNET
727 # define        ICMP_REDIRECT_TOSNET    2
728 #endif
729 #ifndef ICMP_REDIRECT_TOSHOST
730 # define        ICMP_REDIRECT_TOSHOST   3
731 #endif
732 #ifndef ICMP_ALTHOSTADDR
733 # define        ICMP_ALTHOSTADDR        6
734 #endif
735 #ifndef ICMP_TIMXCEED
736 # define        ICMP_TIMXCEED   11
737 #endif
738 #ifndef ICMP_TIMXCEED_INTRANS
739 # define        ICMP_TIMXCEED_INTRANS   0
740 #endif
741 #ifndef ICMP_TIMXCEED_REASS
742 # define                ICMP_TIMXCEED_REASS     1
743 #endif
744 #ifndef ICMP_PARAMPROB
745 # define        ICMP_PARAMPROB  12
746 #endif
747 #ifndef ICMP_PARAMPROB_ERRATPTR
748 # define        ICMP_PARAMPROB_ERRATPTR 0
749 #endif
750 #ifndef ICMP_PARAMPROB_OPTABSENT
751 # define        ICMP_PARAMPROB_OPTABSENT        1
752 #endif
753 #ifndef ICMP_PARAMPROB_LENGTH
754 # define        ICMP_PARAMPROB_LENGTH   2
755 #endif
756 #ifndef ICMP_TSTAMP
757 # define        ICMP_TSTAMP     13
758 #endif
759 #ifndef ICMP_TSTAMPREPLY
760 # define        ICMP_TSTAMPREPLY        14
761 #endif
762 #ifndef ICMP_IREQ
763 # define        ICMP_IREQ       15
764 #endif
765 #ifndef ICMP_IREQREPLY
766 # define        ICMP_IREQREPLY  16
767 #endif
768 #ifndef ICMP_MASKREQ
769 # define        ICMP_MASKREQ    17
770 #endif
771 #ifndef ICMP_MASKREPLY
772 # define        ICMP_MASKREPLY  18
773 #endif
774 #ifndef ICMP_TRACEROUTE
775 # define        ICMP_TRACEROUTE 30
776 #endif
777 #ifndef ICMP_DATACONVERR
778 # define        ICMP_DATACONVERR        31
779 #endif
780 #ifndef ICMP_MOBILE_REDIRECT
781 # define        ICMP_MOBILE_REDIRECT    32
782 #endif
783 #ifndef ICMP_IPV6_WHEREAREYOU
784 # define        ICMP_IPV6_WHEREAREYOU   33
785 #endif
786 #ifndef ICMP_IPV6_IAMHERE
787 # define        ICMP_IPV6_IAMHERE       34
788 #endif
789 #ifndef ICMP_MOBILE_REGREQUEST
790 # define        ICMP_MOBILE_REGREQUEST  35
791 #endif
792 #ifndef ICMP_MOBILE_REGREPLY
793 # define        ICMP_MOBILE_REGREPLY    36
794 #endif
795 #ifndef ICMP_SKIP
796 # define        ICMP_SKIP       39
797 #endif
798 #ifndef ICMP_PHOTURIS
799 # define        ICMP_PHOTURIS   40
800 #endif
801 #ifndef ICMP_PHOTURIS_UNKNOWN_INDEX
802 # define        ICMP_PHOTURIS_UNKNOWN_INDEX     1
803 #endif
804 #ifndef ICMP_PHOTURIS_AUTH_FAILED
805 # define        ICMP_PHOTURIS_AUTH_FAILED       2
806 #endif
807 #ifndef ICMP_PHOTURIS_DECRYPT_FAILED
808 # define        ICMP_PHOTURIS_DECRYPT_FAILED    3
809 #endif
810 #ifndef IPVERSION
811 # define        IPVERSION       4
812 #endif
813 #ifndef IPOPT_MINOFF
814 # define        IPOPT_MINOFF    4
815 #endif
816 #ifndef IPOPT_COPIED
817 # define        IPOPT_COPIED(x) ((x)&0x80)
818 #endif
819 #ifndef IPOPT_EOL
820 # define        IPOPT_EOL       0
821 #endif
822 #ifndef IPOPT_NOP
823 # define        IPOPT_NOP       1
824 #endif
825 #ifndef IP_MF
826 # define        IP_MF   ((u_short)0x2000)
827 #endif
828 #ifndef ETHERTYPE_IP
829 # define        ETHERTYPE_IP    ((u_short)0x0800)
830 #endif
831 #ifndef TH_FIN
832 # define        TH_FIN  0x01
833 #endif
834 #ifndef TH_SYN
835 # define        TH_SYN  0x02
836 #endif
837 #ifndef TH_RST
838 # define        TH_RST  0x04
839 #endif
840 #ifndef TH_PUSH
841 # define        TH_PUSH 0x08
842 #endif
843 #ifndef TH_ACK
844 # define        TH_ACK  0x10
845 #endif
846 #ifndef TH_URG
847 # define        TH_URG  0x20
848 #endif
849 #ifndef IPOPT_EOL
850 # define        IPOPT_EOL       0
851 #endif
852 #ifndef IPOPT_NOP
853 # define        IPOPT_NOP       1
854 #endif
855 #ifndef IPOPT_RR
856 # define        IPOPT_RR        7
857 #endif
858 #ifndef IPOPT_TS
859 # define        IPOPT_TS        68
860 #endif
861 #ifndef IPOPT_SECURITY
862 # define        IPOPT_SECURITY  130
863 #endif
864 #ifndef IPOPT_LSRR
865 # define        IPOPT_LSRR      131
866 #endif
867 #ifndef IPOPT_SATID
868 # define        IPOPT_SATID     136
869 #endif
870 #ifndef IPOPT_SSRR
871 # define        IPOPT_SSRR      137
872 #endif
873 #ifndef IPOPT_SECUR_UNCLASS
874 # define        IPOPT_SECUR_UNCLASS     ((u_short)0x0000)
875 #endif
876 #ifndef IPOPT_SECUR_CONFID
877 # define        IPOPT_SECUR_CONFID      ((u_short)0xf135)
878 #endif
879 #ifndef IPOPT_SECUR_EFTO
880 # define        IPOPT_SECUR_EFTO        ((u_short)0x789a)
881 #endif
882 #ifndef IPOPT_SECUR_MMMM
883 # define        IPOPT_SECUR_MMMM        ((u_short)0xbc4d)
884 #endif
885 #ifndef IPOPT_SECUR_RESTR
886 # define        IPOPT_SECUR_RESTR       ((u_short)0xaf13)
887 #endif
888 #ifndef IPOPT_SECUR_SECRET
889 # define        IPOPT_SECUR_SECRET      ((u_short)0xd788)
890 #endif
891 #ifndef IPOPT_SECUR_TOPSECRET
892 # define        IPOPT_SECUR_TOPSECRET   ((u_short)0x6bc5)
893 #endif
894 #ifndef IPOPT_OLEN
895 # define        IPOPT_OLEN      1
896 #endif
897 #ifndef IPPROTO_GRE
898 # define        IPPROTO_GRE     47      /* GRE encaps RFC 1701 */
899 #endif
900 #ifndef IPPROTO_ESP
901 # define        IPPROTO_ESP     50
902 #endif
903 #ifndef IPPROTO_ICMPV6
904 # define        IPPROTO_ICMPV6  58
905 #endif
906
907 #ifdef  linux
908 #include <linux/in_systm.h>
909 /*
910  * TCP States
911  */
912 #define TCPS_CLOSED             0       /* closed */
913 #define TCPS_LISTEN             1       /* listening for connection */
914 #define TCPS_SYN_SENT           2       /* active, have sent syn */
915 #define TCPS_SYN_RECEIVED       3       /* have send and received syn */
916 /* states < TCPS_ESTABLISHED are those where connections not established */
917 #define TCPS_ESTABLISHED        4       /* established */
918 #define TCPS_CLOSE_WAIT         5       /* rcvd fin, waiting for close */
919 /* states > TCPS_CLOSE_WAIT are those where user has closed */
920 #define TCPS_FIN_WAIT_1         6       /* have closed, sent fin */
921 #define TCPS_CLOSING            7       /* closed xchd FIN; await FIN ACK */
922 #define TCPS_LAST_ACK           8       /* had fin and close; await FIN ACK */
923 /* states > TCPS_CLOSE_WAIT && < TCPS_FIN_WAIT_2 await ACK of FIN */
924 #define TCPS_FIN_WAIT_2         9       /* have closed, fin is acked */
925 #define TCPS_TIME_WAIT          10      /* in 2*msl quiet wait after close */
926
927 /*
928  * file flags.
929  */
930 #ifdef WRITE
931 #define FWRITE  WRITE
932 #define FREAD   READ
933 #else
934 #define FWRITE  _IOC_WRITE
935 #define FREAD   _IOC_READ
936 #endif
937 /*
938  * mbuf related problems.
939  */
940 #define mtod(m,t)       (t)((m)->data)
941 #define m_len           len
942 #define m_next          next
943
944 #ifdef  IP_DF
945 #undef  IP_DF
946 #endif
947 #define IP_DF           0x4000
948
949 typedef struct  {
950         __u16   th_sport;
951         __u16   th_dport;
952         __u32   th_seq;
953         __u32   th_ack;
954 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
955     defined(vax)
956         __u8    th_res:4;
957         __u8    th_off:4;
958 #else
959         __u8    th_off:4;
960         __u8    th_res:4;
961 #endif
962         __u8    th_flags;
963         __u16   th_win;
964         __u16   th_sum;
965         __u16   th_urp;
966 } tcphdr_t;
967
968 typedef struct  {
969         __u16   uh_sport;
970         __u16   uh_dport;
971         __u16   uh_ulen;
972         __u16   uh_sum;
973 } udphdr_t;
974
975 typedef struct  {
976 # if defined(__i386__) || defined(__MIPSEL__) || defined(__alpha__) ||\
977     defined(vax)
978         __u8    ip_hl:4;
979         __u8    ip_v:4;
980 # else
981         __u8    ip_v:4;
982         __u8    ip_hl:4;
983 # endif
984         __u8    ip_tos;
985         __u16   ip_len;
986         __u16   ip_id;
987         __u16   ip_off;
988         __u8    ip_ttl;
989         __u8    ip_p;
990         __u16   ip_sum;
991         struct  in_addr ip_src;
992         struct  in_addr ip_dst;
993 } ip_t;
994
995 /*
996  * Structure of an icmp header.
997  */
998 typedef struct icmp {
999         __u8    icmp_type;              /* type of message, see below */
1000         __u8    icmp_code;              /* type sub code */
1001         __u16   icmp_cksum;             /* ones complement cksum of struct */
1002         union {
1003                 __u8    ih_pptr;                /* ICMP_PARAMPROB */
1004                 struct  in_addr ih_gwaddr;      /* ICMP_REDIRECT */
1005                 struct  ih_idseq {
1006                         __u16   icd_id;
1007                         __u16   icd_seq;
1008                 } ih_idseq;
1009                 int ih_void;
1010         } icmp_hun;
1011 # define        icmp_pptr       icmp_hun.ih_pptr
1012 # define        icmp_gwaddr     icmp_hun.ih_gwaddr
1013 # define        icmp_id         icmp_hun.ih_idseq.icd_id
1014 # define        icmp_seq        icmp_hun.ih_idseq.icd_seq
1015 # define        icmp_void       icmp_hun.ih_void
1016         union {
1017                 struct id_ts {
1018                         n_time its_otime;
1019                         n_time its_rtime;
1020                         n_time its_ttime;
1021                 } id_ts;
1022                 struct id_ip  {
1023                         ip_t idi_ip;
1024                         /* options and then 64 bits of data */
1025                 } id_ip;
1026                 u_long  id_mask;
1027                 char    id_data[1];
1028         } icmp_dun;
1029 # define        icmp_otime      icmp_dun.id_ts.its_otime
1030 # define        icmp_rtime      icmp_dun.id_ts.its_rtime
1031 # define        icmp_ttime      icmp_dun.id_ts.its_ttime
1032 # define        icmp_ip         icmp_dun.id_ip.idi_ip
1033 # define        icmp_mask       icmp_dun.id_mask
1034 # define        icmp_data       icmp_dun.id_data
1035 } icmphdr_t;
1036
1037 # ifndef LINUX_IPOVLY
1038 #  define LINUX_IPOVLY
1039 struct ipovly {
1040         caddr_t ih_next, ih_prev;       /* for protocol sequence q's */
1041         u_char  ih_x1;                  /* (unused) */
1042         u_char  ih_pr;                  /* protocol */
1043         short   ih_len;                 /* protocol length */
1044         struct  in_addr ih_src;         /* source internet address */
1045         struct  in_addr ih_dst;         /* destination internet address */
1046 };
1047 # endif
1048
1049 typedef struct  {
1050         __u8    ether_dhost[6];
1051         __u8    ether_shost[6];
1052         __u16   ether_type;
1053 } ether_header_t;
1054
1055 typedef struct  uio     {
1056         int     uio_resid;
1057         int     uio_rw;
1058         caddr_t uio_buf;
1059 } uio_t;
1060
1061 # define        UIO_READ        0
1062 # define        UIO_WRITE       1
1063 # define        UIOMOVE(a, b, c, d)     uiomove(a,b,c,d)
1064
1065 /*
1066  * For masking struct ifnet onto struct device
1067  */
1068 # define        if_name name
1069
1070 # ifdef KERNEL
1071 #  define       GETUNIT(x, v)   dev_get(x)
1072 #  define       FREE_MB_T(m)    kfree_skb(m, FREE_WRITE)
1073 #  define       uniqtime        do_gettimeofday
1074 #  undef INT_MAX
1075 #  undef UINT_MAX
1076 #  undef LONG_MAX
1077 #  undef ULONG_MAX
1078 #  include <linux/netdevice.h>
1079 #  define       SPL_X(x)
1080 #  define       SPL_NET(x)
1081 #  define       SPL_IMP(x)
1082  
1083 #  define       bcmp(a,b,c)     memcmp(a,b,c)
1084 #  define       bcopy(a,b,c)    memcpy(b,a,c)
1085 #  define       bzero(a,c)      memset(a,0,c)
1086
1087 #  define       UNITNAME(n)     dev_get((n))
1088
1089 #  define       KMALLOC(a,b)    (a) = (b)kmalloc(sizeof(*(a)), GFP_ATOMIC)
1090 #  define       KMALLOCS(a,b,c) (a) = (b)kmalloc((c), GFP_ATOMIC)
1091 #  define       KFREE(x)        kfree_s((x), sizeof(*(x)))
1092 #  define       KFREES(x,s)     kfree_s((x), (s))
1093 #define IRCOPY(const void *a, void *b, size_t c)        { \
1094         int error; \
1095
1096         error = verify_area(VERIFY_READ, a ,c); \
1097         if (!error) \
1098                 memcpy_fromfs(b, a, c); \
1099         return error; \
1100 }
1101 static inline int IWCOPY(const void *a, void *b, size_t c)
1102 {
1103         int error;
1104
1105         error = verify_area(VERIFY_WRITE, b, c);
1106         if (!error)
1107                 memcpy_tofs(b, a, c);
1108         return error;
1109 }
1110 static inline int IRCOPYPTR(const void *a, void *b, size_t c) {
1111         caddr_t ca;
1112         int     error;
1113
1114         error = verify_area(VERIFY_READ, a ,sizeof(ca));
1115         if (!error) {
1116                 memcpy_fromfs(ca, a, sizeof(ca));
1117                 error = verify_area(VERIFY_READ, ca , c);
1118                 if (!error)
1119                         memcpy_fromfs(b, ca, c);
1120         }
1121         return error;
1122 }
1123 static inline int IWCOPYPTR(const void *a, void *b, size_t c) {
1124         caddr_t ca;
1125         int     error;
1126
1127
1128         error = verify_area(VERIFY_READ, b ,sizeof(ca));
1129         if (!error) {
1130                 memcpy_fromfs(ca, b, sizeof(ca));
1131                 error = verify_area(VERIFY_WRITE, ca, c);
1132                 if (!error)
1133                         memcpy_tofs(ca, a, c);
1134         }
1135         return error;
1136 }
1137 # else
1138 #  define       __KERNEL__
1139 #  undef INT_MAX
1140 #  undef UINT_MAX
1141 #  undef LONG_MAX
1142 #  undef ULONG_MAX
1143 #  define       s8 __s8
1144 #  define       u8 __u8
1145 #  define       s16 __s16
1146 #  define       u16 __u16
1147 #  define       s32 __s32
1148 #  define       u32 __u32
1149 #  include <linux/netdevice.h>
1150 #  undef        __KERNEL__
1151 # endif
1152 # define        ifnet   device
1153 #else
1154 typedef struct  tcphdr  tcphdr_t;
1155 typedef struct  udphdr  udphdr_t;
1156 typedef struct  icmp    icmphdr_t;
1157 typedef struct  ip      ip_t;
1158 typedef struct  ether_header    ether_header_t;
1159 #endif /* linux */
1160 typedef struct  tcpiphdr        tcpiphdr_t;
1161
1162 #if defined(hpux) || defined(linux)
1163 struct  ether_addr      {
1164         char    ether_addr_octet[6];
1165 };
1166 #endif
1167
1168 /*
1169  * XXX - This is one of those *awful* hacks which nobody likes
1170  */
1171 #ifdef  ultrix
1172 #define A_A
1173 #else
1174 #define A_A     &
1175 #endif
1176
1177 #if (BSD >= 199306) && !defined(m_act)
1178 # define        m_act   m_nextpkt
1179 #endif
1180
1181 #ifndef ICMP_ROUTERADVERT
1182 # define        ICMP_ROUTERADVERT       9
1183 #endif
1184 #ifndef ICMP_ROUTERSOLICIT
1185 # define        ICMP_ROUTERSOLICIT      10
1186 #endif
1187 #undef  ICMP_MAX_UNREACH
1188 #define ICMP_MAX_UNREACH        14
1189 #undef  ICMP_MAXTYPE
1190 #define ICMP_MAXTYPE            18
1191 /*
1192  * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
1193  * another IP header and then 64 bits of data, totalling 56.  Of course,
1194  * the last 64 bits is dependant on that being available.
1195  */
1196 #define ICMPERR_ICMPHLEN        8
1197 #define ICMPERR_IPICMPHLEN      (20 + 8)
1198 #define ICMPERR_MINPKTLEN       (20 + 8 + 20)
1199 #define ICMPERR_MAXPKTLEN       (20 + 8 + 20 + 8)
1200 #define ICMP6_MINLEN            8
1201 #define ICMP6ERR_MINPKTLEN      (40 + 8)
1202 #define ICMP6ERR_IPICMPHLEN     (40 + 8 + 40)
1203
1204 #ifndef ICMP6_DST_UNREACH
1205 # define        ICMP6_DST_UNREACH       1
1206 #endif
1207 #ifndef ICMP6_PACKET_TOO_BIG
1208 # define        ICMP6_PACKET_TOO_BIG    2
1209 #endif
1210 #ifndef ICMP6_TIME_EXCEEDED
1211 # define        ICMP6_TIME_EXCEEDED     3
1212 #endif
1213 #ifndef ICMP6_PARAM_PROB
1214 # define        ICMP6_PARAM_PROB        4
1215 #endif
1216
1217 #ifndef ICMP6_ECHO_REQUEST
1218 # define        ICMP6_ECHO_REQUEST      128
1219 #endif
1220 #ifndef ICMP6_ECHO_REPLY
1221 # define        ICMP6_ECHO_REPLY        129
1222 #endif
1223 #ifndef ICMP6_MEMBERSHIP_QUERY
1224 # define        ICMP6_MEMBERSHIP_QUERY  130
1225 #endif
1226 #ifndef MLD6_LISTENER_QUERY
1227 # define        MLD6_LISTENER_QUERY     130
1228 #endif
1229 #ifndef ICMP6_MEMBERSHIP_REPORT
1230 # define        ICMP6_MEMBERSHIP_REPORT 131
1231 #endif
1232 #ifndef MLD6_LISTENER_REPORT
1233 # define        MLD6_LISTENER_REPORT    131
1234 #endif
1235 #ifndef ICMP6_MEMBERSHIP_REDUCTION
1236 # define        ICMP6_MEMBERSHIP_REDUCTION      132
1237 #endif
1238 #ifndef MLD6_LISTENER_DONE
1239 # define        MLD6_LISTENER_DONE      132
1240 #endif
1241 #ifndef ND_ROUTER_SOLICIT
1242 # define        ND_ROUTER_SOLICIT       133
1243 #endif
1244 #ifndef ND_ROUTER_ADVERT
1245 # define        ND_ROUTER_ADVERT        134
1246 #endif
1247 #ifndef ND_NEIGHBOR_SOLICIT
1248 # define        ND_NEIGHBOR_SOLICIT     135
1249 #endif
1250 #ifndef ND_NEIGHBOR_ADVERT
1251 # define        ND_NEIGHBOR_ADVERT      136
1252 #endif
1253 #ifndef ND_REDIRECT
1254 # define        ND_REDIRECT     137
1255 #endif
1256 #ifndef ICMP6_ROUTER_RENUMBERING
1257 # define        ICMP6_ROUTER_RENUMBERING        138
1258 #endif
1259 #ifndef ICMP6_WRUREQUEST
1260 # define        ICMP6_WRUREQUEST        139
1261 #endif
1262 #ifndef ICMP6_WRUREPLY
1263 # define        ICMP6_WRUREPLY          140
1264 #endif
1265 #ifndef ICMP6_FQDN_QUERY
1266 # define        ICMP6_FQDN_QUERY        139
1267 #endif
1268 #ifndef ICMP6_FQDN_REPLY
1269 # define        ICMP6_FQDN_REPLY        140
1270 #endif
1271 #ifndef ICMP6_NI_QUERY
1272 # define        ICMP6_NI_QUERY          139
1273 #endif
1274 #ifndef ICMP6_NI_REPLY
1275 # define        ICMP6_NI_REPLY          140
1276 #endif
1277 #ifndef MLD6_MTRACE_RESP
1278 # define        MLD6_MTRACE_RESP        200
1279 #endif
1280 #ifndef MLD6_MTRACE
1281 # define        MLD6_MTRACE             201
1282 #endif
1283 #ifndef ICMP6_HADISCOV_REQUEST
1284 # define        ICMP6_HADISCOV_REQUEST  202
1285 #endif
1286 #ifndef ICMP6_HADISCOV_REPLY
1287 # define        ICMP6_HADISCOV_REPLY    203
1288 #endif
1289 #ifndef ICMP6_MOBILEPREFIX_SOLICIT
1290 # define        ICMP6_MOBILEPREFIX_SOLICIT      204
1291 #endif
1292 #ifndef ICMP6_MOBILEPREFIX_ADVERT
1293 # define        ICMP6_MOBILEPREFIX_ADVERT       205
1294 #endif
1295 #ifndef ICMP6_MAXTYPE
1296 # define        ICMP6_MAXTYPE           205
1297 #endif
1298
1299 #ifndef ICMP6_DST_UNREACH_NOROUTE
1300 # define        ICMP6_DST_UNREACH_NOROUTE       0
1301 #endif
1302 #ifndef ICMP6_DST_UNREACH_ADMIN
1303 # define        ICMP6_DST_UNREACH_ADMIN         1
1304 #endif
1305 #ifndef ICMP6_DST_UNREACH_NOTNEIGHBOR
1306 # define        ICMP6_DST_UNREACH_NOTNEIGHBOR   2
1307 #endif
1308 #ifndef ICMP6_DST_UNREACH_BEYONDSCOPE
1309 # define        ICMP6_DST_UNREACH_BEYONDSCOPE   2
1310 #endif
1311 #ifndef ICMP6_DST_UNREACH_ADDR
1312 # define        ICMP6_DST_UNREACH_ADDR          3
1313 #endif
1314 #ifndef ICMP6_DST_UNREACH_NOPORT
1315 # define        ICMP6_DST_UNREACH_NOPORT        4
1316 #endif
1317 #ifndef ICMP6_TIME_EXCEED_TRANSIT
1318 # define        ICMP6_TIME_EXCEED_TRANSIT       0
1319 #endif
1320 #ifndef ICMP6_TIME_EXCEED_REASSEMBLY
1321 # define        ICMP6_TIME_EXCEED_REASSEMBLY    1
1322 #endif
1323
1324 #ifndef ICMP6_NI_SUCCESS
1325 # define        ICMP6_NI_SUCCESS        0
1326 #endif
1327 #ifndef ICMP6_NI_REFUSED
1328 # define        ICMP6_NI_REFUSED        1
1329 #endif
1330 #ifndef ICMP6_NI_UNKNOWN
1331 # define        ICMP6_NI_UNKNOWN        2
1332 #endif
1333
1334 #ifndef ICMP6_ROUTER_RENUMBERING_COMMAND
1335 # define        ICMP6_ROUTER_RENUMBERING_COMMAND        0
1336 #endif
1337 #ifndef ICMP6_ROUTER_RENUMBERING_RESULT
1338 # define        ICMP6_ROUTER_RENUMBERING_RESULT 1
1339 #endif
1340 #ifndef ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
1341 # define        ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET   255
1342 #endif
1343
1344 #ifndef ICMP6_PARAMPROB_HEADER
1345 # define        ICMP6_PARAMPROB_HEADER  0
1346 #endif
1347 #ifndef ICMP6_PARAMPROB_NEXTHEADER
1348 # define        ICMP6_PARAMPROB_NEXTHEADER      1
1349 #endif
1350 #ifndef ICMP6_PARAMPROB_OPTION
1351 # define        ICMP6_PARAMPROB_OPTION  2
1352 #endif
1353
1354 #ifndef ICMP6_NI_SUBJ_IPV6
1355 # define        ICMP6_NI_SUBJ_IPV6      0
1356 #endif
1357 #ifndef ICMP6_NI_SUBJ_FQDN
1358 # define        ICMP6_NI_SUBJ_FQDN      1
1359 #endif
1360 #ifndef ICMP6_NI_SUBJ_IPV4
1361 # define        ICMP6_NI_SUBJ_IPV4      2
1362 #endif
1363
1364 /*
1365  * ECN is a new addition to TCP - RFC 2481
1366  */
1367 #ifndef TH_ECN
1368 # define        TH_ECN  0x40
1369 #endif
1370 #ifndef TH_CWR
1371 # define        TH_CWR  0x80
1372 #endif
1373 #define TH_ECNALL       (TH_ECN|TH_CWR)
1374
1375 #define TCPF_ALL (TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|TH_ECN|TH_CWR)
1376
1377 #endif  /* __IP_COMPAT_H__ */