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