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