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