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