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