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