1 /*
2  * Copyright (C) 1993-2001, 2003 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.142.2.30 2005/08/11 15:13:49 darrenr Exp $
8  *
9  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
10  * Use is subject to license terms.
11  */
12 
13 #pragma ident	"%Z%%M%	%I%	%E% SMI"
14 
15 #ifndef	__IP_COMPAT_H__
16 #define	__IP_COMPAT_H__
17 
18 #ifndef	__P
19 # ifdef	__STDC__
20 #  define	__P(x)  x
21 # else
22 #  define	__P(x)  ()
23 # endif
24 #endif
25 #ifndef	__STDC__
26 # undef		const
27 # define	const
28 #endif
29 
30 #if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
31 # undef	KERNEL
32 # undef	_KERNEL
33 # undef 	__KERNEL__
34 # define	KERNEL
35 # define	_KERNEL
36 # define 	__KERNEL__
37 #endif
38 
39 #ifndef	SOLARIS
40 #define	SOLARIS	(defined(sun) && (defined(__svr4__) || defined(__SVR4)))
41 #endif
42 #if SOLARIS2 >= 8
43 # ifndef	USE_INET6
44 #  define	USE_INET6
45 # endif
46 #endif
47 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
48     !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
49 # define	USE_INET6
50 #endif
51 #if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \
52     !defined(_KERNEL) && !defined(USE_INET6)
53 # define	USE_INET6
54 # define	IPFILTER_M_IPFILTER
55 #endif
56 #if defined(OpenBSD) && (OpenBSD >= 200206) && \
57     !defined(_KERNEL) && !defined(USE_INET6)
58 # define	USE_INET6
59 #endif
60 #if defined(__osf__)
61 # define	USE_INET6
62 #endif
63 #if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6))
64 # define	USE_INET6
65 #endif
66 #if defined(HPUXREV) && (HPUXREV >= 1111)
67 # define	USE_INET6
68 #endif
69 
70 #if defined(BSD) && (BSD < 199103) && defined(__osf__)
71 # undef BSD
72 # define BSD 199103
73 #endif
74 
75 #if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
76 # define index   strchr
77 # if !defined(_KERNEL)
78 #  define	bzero(a,b)	memset(a,0,b)
79 #  define	bcmp		memcmp
80 #  define	bcopy(a,b,c)	memmove(b,a,c)
81 # endif
82 #endif
83 
84 #ifndef LIFNAMSIZ
85 # ifdef IF_NAMESIZE
86 #  define	LIFNAMSIZ	IF_NAMESIZE
87 # else
88 #  ifdef	IFNAMSIZ
89 #   define	LIFNAMSIZ	IFNAMSIZ
90 #  else
91 #   define	LIFNAMSIZ	16
92 #  endif
93 # endif
94 #endif
95 
96 #if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
97 struct  ether_addr {
98         u_char  ether_addr_octet[6];
99 };
100 #endif
101 
102 #if defined(__sgi) && !defined(IPFILTER_LKM)
103 # ifdef __STDC__
104 #  define IPL_EXTERN(ep) ipfilter##ep
105 # else
106 #  define IPL_EXTERN(ep) ipfilter/**/ep
107 # endif
108 #else
109 # ifdef __STDC__
110 #  define IPL_EXTERN(ep) ipl##ep
111 # else
112 #  define IPL_EXTERN(ep) ipl/**/ep
113 # endif
114 #endif
115 
116 /*
117  * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
118  */
119 #ifndef linux
120 # ifndef _KERNEL
121 #  define ADD_KERNEL
122 #  define _KERNEL
123 #  define KERNEL
124 # endif
125 # ifdef __OpenBSD__
126 struct file;
127 # endif
128 # include <sys/uio.h>
129 # ifdef ADD_KERNEL
130 #  undef _KERNEL
131 #  undef KERNEL
132 # endif
133 #endif
134 
135 
136 /* ----------------------------------------------------------------------- */
137 /*                                  S O L A R I S                          */
138 /* ----------------------------------------------------------------------- */
139 #if SOLARIS
140 # define	MENTAT	1
141 # include	<sys/cmn_err.h>
142 # include	<sys/isa_defs.h>
143 # include	<sys/stream.h>
144 # include	<sys/ioccom.h>
145 # include	<sys/sysmacros.h>
146 # include	<sys/kmem.h>
147 # if SOLARIS2 >= 10
148 #  include	<sys/procset.h>
149 #  include	<sys/proc.h>
150 #  include	<sys/devops.h>
151 #  include	<sys/ddi_impldefs.h>
152 # endif
153 
154 /*
155  * inet/ip.h would end up including radix.h with _KERNEL, which is not
156  * what the tools intend, so include radix.h first.
157  */
158 #if SOLARIS2 > 10
159 # include <net/radix.h>
160 #endif
161 /*
162  * because Solaris 2 defines these in two places :-/
163  */
164 # ifndef	KERNEL
165 #  define	_KERNEL
166 #  undef	RES_INIT
167 # endif /* _KERNEL */
168 
169 # if SOLARIS2 >= 8
170 #  include <netinet/ip6.h>
171 #  include <netinet/icmp6.h>
172 # endif
173 
174 # include <inet/common.h>
175 /* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */
176 # undef	IPOPT_EOL
177 # undef	IPOPT_NOP
178 # undef	IPOPT_LSRR
179 # undef	IPOPT_RR
180 # undef	IPOPT_SSRR
181 # ifdef i386
182 #  define _SYS_PROMIF_H
183 # endif
184 # include <inet/ip.h>
185 # undef COPYOUT
186 # include <inet/ip_ire.h>
187 # ifndef	KERNEL
188 #  undef	_KERNEL
189 # endif
190 # if SOLARIS2 >= 8
191 #  define SNPRINTF	snprintf
192 
193 #  include <inet/ip_if.h>
194 #  define	ipif_local_addr	ipif_lcl_addr
195 /* Only defined in private include file */
196 #  ifndef	V4_PART_OF_V6
197 #   define	V4_PART_OF_V6(v6)	v6.s6_addr32[3]
198 #  endif
199 struct ip6_ext {
200 	u_char	ip6e_nxt;
201 	u_char	ip6e_len;
202 };
203 # endif /* SOLARIS2 >= 8 */
204 
205 # ifdef FW_HOOKS
206 
207 #  define	SOLARIS_PFHOOKS	1
208 
209 typedef	struct	qpktinfo	{
210 	/* data that changes per-packet */
211 	void		*qpi_ill;	/* COPIED */
212 	mblk_t		*qpi_m;
213 	void		*qpi_data;	/* where layer 3 header starts */
214 	size_t		qpi_off;
215 	int		qpi_flags;
216 } qpktinfo_t;
217 
218 #define	QPI_NOCKSUM	0x01
219 
220 extern net_data_t ipf_ipv4;
221 extern net_data_t ipf_ipv6;
222 
223 extern void mb_copydata __P((mblk_t *, size_t , size_t, char *));
224 extern void mb_copyback __P((mblk_t *, size_t , size_t, char *));
225 # endif
226 
227 # if SOLARIS2 >= 6
228 #  include <sys/atomic.h>
229 typedef	uint32_t	u_32_t;
230 # else
231 typedef unsigned int	u_32_t;
232 # endif
233 # define	U_32_T	1
234 
235 # ifdef _KERNEL
236 #  define	KRWLOCK_T		krwlock_t
237 #  define	KMUTEX_T		kmutex_t
238 #  if SOLARIS2 >= 6
239 #   if SOLARIS2 == 6
240 #    define	ATOMIC_INCL(x)		atomic_add_long((uint32_t*)&(x), 1)
241 #    define	ATOMIC_DECL(x)		atomic_add_long((uint32_t*)&(x), -1)
242 #   else
243 #    define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
244 #    define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
245 #   endif /* SOLARIS2 == 6 */
246 #   define	ATOMIC_INC64(x)		atomic_add_64((uint64_t*)&(x), 1)
247 #   define	ATOMIC_INC32(x)		atomic_add_32((uint32_t*)&(x), 1)
248 #   define	ATOMIC_INC16(x)		atomic_add_16((uint16_t*)&(x), 1)
249 #   define	ATOMIC_DEC64(x)		atomic_add_64((uint64_t*)&(x), -1)
250 #   define	ATOMIC_DEC32(x)		atomic_add_32((uint32_t*)&(x), -1)
251 #   define	ATOMIC_DEC16(x)		atomic_add_16((uint16_t*)&(x), -1)
252 #  else
253 #   define	ATOMIC_INC(x)		{ mutex_enter(&ipf_rw); (x)++; \
254 					  mutex_exit(&ipf_rw); }
255 #   define	ATOMIC_DEC(x)		{ mutex_enter(&ipf_rw); (x)--; \
256 					  mutex_exit(&ipf_rw); }
257 #  endif /* SOLARIS2 >= 6 */
258 #  define	USE_MUTEXES
259 #  define	MUTEX_ENTER(x)		mutex_enter(&(x)->ipf_lk)
260 #  define	READ_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_READER)
261 #  define	WRITE_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_WRITER)
262 #  define	MUTEX_DOWNGRADE(x)	rw_downgrade(&(x)->ipf_lk)
263 #  define	RWLOCK_INIT(x, y)	rw_init(&(x)->ipf_lk, (y),  \
264 						RW_DRIVER, NULL)
265 #  define	RWLOCK_EXIT(x)		rw_exit(&(x)->ipf_lk)
266 #  define	RW_DESTROY(x)		rw_destroy(&(x)->ipf_lk)
267 #  define	MUTEX_INIT(x, y)	mutex_init(&(x)->ipf_lk, (y), \
268 						   MUTEX_DRIVER, NULL)
269 #  define	MUTEX_DESTROY(x)	mutex_destroy(&(x)->ipf_lk)
270 #  define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
271 #  define	MUTEX_EXIT(x)		mutex_exit(&(x)->ipf_lk)
272 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
273 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
274 #  define	BCOPYIN(a,b,c)	(void) copyin((caddr_t)(a), (caddr_t)(b), (c))
275 #  define	BCOPYOUT(a,b,c)	(void) copyout((caddr_t)(a), (caddr_t)(b), (c))
276 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
277 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
278 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
279 #  define	SPL_NET(x)	;
280 #  define	SPL_IMP(x)	;
281 #  undef	SPL_X
282 #  define	SPL_X(x)	;
283 #  ifdef sparc
284 #   define	ntohs(x)	(x)
285 #   define	ntohl(x)	(x)
286 #   define	htons(x)	(x)
287 #   define	htonl(x)	(x)
288 #  endif /* sparc */
289 #  define	KMALLOC(a,b)	(a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
290 #  define	KMALLOCS(a,b,c)	(a) = (b)kmem_alloc((c), KM_NOSLEEP)
291 #  define	GET_MINOR(x)	getminor(x)
292 extern	phy_if_t	get_unit __P((char *, int));
293 #  define	GETIFP(n, v)	(void *)get_unit(n, v)
294 #  define	IFNAME(x)	((ill_t *)x)->ill_name
295 #  define	COPYIFNAME(x, b, v)	(void) net_getifname(((v) == 4) ? \
296 					    ipf_ipv4 : ipf_ipv6, \
297 					    (phy_if_t)(x), (b), sizeof(b))
298 #  define	GETKTIME(x)	uniqtime((struct timeval *)x)
299 #  define	MSGDSIZE(x)	msgdsize(x)
300 #  define	M_LEN(x)	((x)->b_wptr - (x)->b_rptr)
301 #  define	M_DUPLICATE(x)	dupmsg((x))
302 #  define	MTOD(m,t)	((t)((m)->b_rptr))
303 #  define	MTYPE(m)	((m)->b_datap->db_type)
304 #  define	FREE_MB_T(m)	freemsg(m)
305 #  define	m_next		b_cont
306 #  define	CACHE_HASH(x)	(((phy_if_t)(x)->fin_ifp) & 7)
307 #  define	IPF_PANIC(x,y)	if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
308 typedef mblk_t mb_t;
309 # endif /* _KERNEL */
310 
311 # if (SOLARIS2 >= 7)
312 #  ifdef lint
313 #   define ALIGN32(ptr)    (ptr ? 0L : 0L)
314 #   define ALIGN16(ptr)    (ptr ? 0L : 0L)
315 #  else
316 #   define ALIGN32(ptr)    (ptr)
317 #   define ALIGN16(ptr)    (ptr)
318 #  endif
319 # endif
320 
321 # if SOLARIS2 < 6
322 typedef	struct uio	uio_t;
323 # endif
324 typedef	int		ioctlcmd_t;
325 
326 # define OS_RECOGNISED 1
327 
328 #endif /* SOLARIS */
329 
330 /* ----------------------------------------------------------------------- */
331 /*                                  H P U X                                */
332 /* ----------------------------------------------------------------------- */
333 #ifdef __hpux
334 # define	MENTAT	1
335 # include	<sys/sysmacros.h>
336 # include	<sys/spinlock.h>
337 # include	<sys/lock.h>
338 # include	<sys/stream.h>
339 # ifdef USE_INET6
340 #  include	<netinet/if_ether.h>
341 #  include	<netinet/ip6.h>
342 #  include	<netinet/icmp6.h>
343 typedef	struct	ip6_hdr	ip6_t;
344 # endif
345 
346 # ifdef _KERNEL
347 #  define SNPRINTF	sprintf
348 #  if (HPUXREV >= 1111)
349 #   define	IPL_SELECT
350 #   ifdef	IPL_SELECT
351 #    include	<machine/sys/user.h>
352 #    include	<sys/kthread_iface.h>
353 #    define	READ_COLLISION	0x01
354 
355 typedef	struct	iplog_select_s {
356 	kthread_t	*read_waiter;
357 	int		state;
358 } iplog_select_t;
359 #   endif
360 #  endif
361 
362 #  define	GETKTIME(x)	uniqtime((struct timeval *)x)
363 
364 #  if HPUXREV == 1111
365 #   include	"kern_svcs.h"
366 #  else
367 #   include	<sys/kern_svcs.h>
368 #  endif
369 #  undef	ti_flags
370 #  undef	TCP_NODELAY
371 #  undef	TCP_MAXSEG
372 #  include <sys/reg.h>
373 #  include "../netinet/ip_info.h"
374 /*
375  * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
376  * are available.  Attempting to use them actually results in unresolved
377  * symbols when it comes time to load the module.
378  * This has been fixed!  Yipee!
379  */
380 #  if 1
381 #   ifdef __LP64__
382 #    define	ATOMIC_INCL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
383 #    define	ATOMIC_DECL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
384 #   else
385 #    define	ATOMIC_INCL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
386 #    define	ATOMIC_DECL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
387 #   endif
388 #   define	ATOMIC_INC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
389 #   define	ATOMIC_INC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
390 #   define	ATOMIC_INC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
391 #   define	ATOMIC_DEC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
392 #   define	ATOMIC_DEC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
393 #   define	ATOMIC_DEC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
394 #  else /* 0 */
395 #   define	ATOMIC_INC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
396 					  MUTEX_EXIT(&ipf_rw); }
397 #   define	ATOMIC_DEC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
398 					  MUTEX_EXIT(&ipf_rw); }
399 #   define	ATOMIC_INC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
400 					  MUTEX_EXIT(&ipf_rw); }
401 #   define	ATOMIC_DEC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
402 					  MUTEX_EXIT(&ipf_rw); }
403 #   define	ATOMIC_INCL(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
404 					  MUTEX_EXIT(&ipf_rw); }
405 #   define	ATOMIC_DECL(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
406 					  MUTEX_EXIT(&ipf_rw); }
407 #   define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
408 					  MUTEX_EXIT(&ipf_rw); }
409 #   define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
410 					  MUTEX_EXIT(&ipf_rw); }
411 #  endif
412 #  define	ip_cksum		ip_csuma
413 #  define	memcpy(a,b,c)		bcopy((caddr_t)b, (caddr_t)a, c)
414 #  define	USE_MUTEXES
415 #  define	MUTEX_INIT(x, y)	initlock(&(x)->ipf_lk, 0, 0, (y))
416 #  define	MUTEX_ENTER(x)		spinlock(&(x)->ipf_lk)
417 #  define	MUTEX_EXIT(x)		spinunlock(&(x)->ipf_lk);
418 #  define	MUTEX_DESTROY(x)
419 #  define	MUTEX_NUKE(x)		bzero((char *)(x), sizeof(*(x)))
420 #  define	KMUTEX_T		lock_t
421 #  define	kmutex_t		lock_t		/* for pfil.h */
422 #  define	krwlock_t		lock_t		/* for pfil.h */
423 /*
424  * The read-write lock implementation in HP-UX 11.0 is crippled - it can
425  * only be used by threads working in a user context!
426  * This has been fixed!  Yipee! (Or at least it does in 11.00, not 11.11..)
427  */
428 #  if HPUXREV < 1111
429 #   define	MUTEX_DOWNGRADE(x)	lock_write_to_read(x)
430 #   define	KRWLOCK_T		struct rw_lock
431 #   define	READ_ENTER(x)		lock_read(&(x)->ipf_lk)
432 #   define	WRITE_ENTER(x)		lock_write(&(x)->ipf_lk)
433 #   if HPUXREV >= 1111
434 #    define	RWLOCK_INIT(x, y)	rwlock_init4(&(x)->ipf_lk, 0, RWLCK_CANSLEEP, 0, y)
435 #   else
436 #    define	RWLOCK_INIT(x, y)	lock_init3(&(x)->ipf_lk, 0, 1, 0, 0, y)
437 #   endif
438 #   define	RWLOCK_EXIT(x)		lock_done(&(x)->ipf_lk)
439 #  else
440 #   define	KRWLOCK_T		lock_t
441 #   define	KMUTEX_T		lock_t
442 #   define	READ_ENTER(x)		MUTEX_ENTER(x)
443 #   define	WRITE_ENTER(x)		MUTEX_ENTER(x)
444 #   define	MUTEX_DOWNGRADE(x)
445 #   define	RWLOCK_INIT(x, y)	initlock(&(x)->ipf_lk, 0, 0, y)
446 #   define	RWLOCK_EXIT(x)		MUTEX_EXIT(x)
447 #  endif
448 #  define	RW_DESTROY(x)
449 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
450 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
451 #  if HPUXREV >= 1111
452 #   define	BCOPYIN(a,b,c)	0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
453 #   define	BCOPYOUT(a,b,c)	0; bcopy((caddr_t)(a), (caddr_t)(b), (c))
454 #  else
455 #   define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
456 #   define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
457 #  endif
458 #  define	SPL_NET(x)	;
459 #  define	SPL_IMP(x)	;
460 #  undef	SPL_X
461 #  define	SPL_X(x)	;
462 extern	void	*get_unit __P((char *, int));
463 #  define	GETIFP(n, v)	get_unit(n, v)
464 #  define	IFNAME(x, b)	((ill_t *)x)->ill_name
465 #  define	COPYIFNAME(x, b, v) \
466 				strncpy(b, ((ifinfo_t *)x)->ifi_name, \
467 					LIFNAMSIZ)
468 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
469 #  define	SLEEP(id, n)	{ lock_t *_l = get_sleep_lock((caddr_t)id); \
470 				  sleep(id, PZERO+1); \
471 				  spinunlock(_l); \
472 				}
473 #  define	WAKEUP(id,x)	{ lock_t *_l = get_sleep_lock((caddr_t)id); \
474 				  wakeup(id + x); \
475 				  spinunlock(_l); \
476 				}
477 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_IOSYS, M_NOWAIT)
478 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_IOSYS, M_NOWAIT)
479 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
480 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
481 #  define	MSGDSIZE(x)	msgdsize(x)
482 #  define	M_LEN(x)	((x)->b_wptr - (x)->b_rptr)
483 #  define	M_DUPLICATE(x)	dupmsg((x))
484 #  define	MTOD(m,t)	((t)((m)->b_rptr))
485 #  define	MTYPE(m)	((m)->b_datap->db_type)
486 #  define	FREE_MB_T(m)	freemsg(m)
487 #  define	m_next		b_cont
488 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
489 typedef mblk_t mb_t;
490 
491 #  define	CACHE_HASH(x)	(((phy_if_t)(x)->fin_ifp) & 7)
492 
493 #  include "qif.h"
494 #  include "pfil.h"
495 
496 # else /* _KERNEL */
497 
498 typedef	unsigned char uchar_t;
499 
500 #  ifndef	_SYS_STREAM_INCLUDED
501 typedef char * mblk_t;
502 typedef void * queue_t;
503 typedef	u_long ulong;
504 #  endif
505 #  include <netinet/ip_info.h>
506 
507 # endif /* _KERNEL */
508 
509 # ifdef lint
510 #  define ALIGN32(ptr)    (ptr ? 0L : 0L)
511 #  define ALIGN16(ptr)    (ptr ? 0L : 0L)
512 # else
513 #  define ALIGN32(ptr)    (ptr)
514 #  define ALIGN16(ptr)    (ptr)
515 # endif
516 
517 typedef	struct uio	uio_t;
518 typedef	int		ioctlcmd_t;
519 typedef	int		minor_t;
520 typedef unsigned int	u_32_t;
521 # define	U_32_T	1
522 
523 # define OS_RECOGNISED 1
524 
525 #endif /* __hpux */
526 
527 /* ----------------------------------------------------------------------- */
528 /*                                  I R I X                                */
529 /* ----------------------------------------------------------------------- */
530 #ifdef __sgi
531 # undef		MENTAT
532 # if IRIX < 60500
533 typedef	struct uio	uio_t;
534 # endif
535 typedef	int		ioctlcmd_t;
536 typedef u_int32_t       u_32_t;
537 # define	U_32_T	1
538 
539 # ifdef INET6
540 #  define USE_INET6
541 # endif
542 
543 # define  hz HZ
544 # include <sys/ksynch.h>
545 # define	IPF_LOCK_PL	plhi
546 # include <sys/sema.h>
547 # undef kmutex_t
548 typedef struct {
549 	lock_t *l;
550 	int pl;
551 } kmutex_t;
552 
553 # ifdef MUTEX_INIT
554 #  define	KMUTEX_T		mutex_t
555 # else
556 #  define	KMUTEX_T		kmutex_t
557 #  define	KRWLOCK_T		kmutex_t
558 # endif
559 
560 # ifdef _KERNEL
561 #  define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); \
562 					  (x)++; MUTEX_EXIT(&ipf_rw); }
563 #  define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); \
564 					  (x)--; MUTEX_EXIT(&ipf_rw); }
565 #  define	USE_MUTEXES
566 #  ifdef MUTEX_INIT
567 #   include <sys/atomic_ops.h>
568 #   define	ATOMIC_INCL(x)		atomicAddUlong(&(x), 1)
569 #   define	ATOMIC_INC64(x)		atomicAddUint64(&(x), 1)
570 #   define	ATOMIC_INC32(x)		atomicAddUint(&(x), 1)
571 #   define	ATOMIC_INC16		ATOMIC_INC
572 #   define	ATOMIC_DECL(x)		atomicAddUlong(&(x), -1)
573 #   define	ATOMIC_DEC64(x)		atomicAddUint64(&(x), -1)
574 #   define	ATOMIC_DEC32(x)		atomicAddUint(&(x), -1)
575 #   define	ATOMIC_DEC16		ATOMIC_DEC
576 #   undef	MUTEX_INIT
577 #   define	MUTEX_INIT(x, y)	mutex_init(&(x)->ipf_lk,  \
578 						   MUTEX_DEFAULT, y)
579 #   undef	MUTEX_ENTER
580 #   define	MUTEX_ENTER(x)		mutex_lock(&(x)->ipf_lk, 0)
581 #   undef	MUTEX_EXIT
582 #   define	MUTEX_EXIT(x)		mutex_unlock(&(x)->ipf_lk)
583 #   undef	MUTEX_DESTROY
584 #   define	MUTEX_DESTROY(x)	mutex_destroy(&(x)->ipf_lk)
585 #   define	MUTEX_DOWNGRADE(x)	mrdemote(&(x)->ipf_lk)
586 #   define	KRWLOCK_T		mrlock_t
587 #   define	RWLOCK_INIT(x, y)	mrinit(&(x)->ipf_lk, y)
588 #   undef	RW_DESTROY
589 #   define	RW_DESTROY(x)		mrfree(&(x)->ipf_lk)
590 #   define	READ_ENTER(x)		RW_RDLOCK(&(x)->ipf_lk)
591 #   define	WRITE_ENTER(x)		RW_WRLOCK(&(x)->ipf_lk)
592 #   define	RWLOCK_EXIT(x)		RW_UNLOCK(&(x)->ipf_lk)
593 #  else
594 #   define	READ_ENTER(x)		MUTEX_ENTER(&(x)->ipf_lk)
595 #   define	WRITE_ENTER(x)		MUTEX_ENTER(&(x)->ipf_lk)
596 #   define	MUTEX_DOWNGRADE(x)	;
597 #   define	RWLOCK_EXIT(x)		MUTEX_EXIT(&(x)->ipf_lk)
598 #   define	MUTEX_EXIT(x)		UNLOCK((x)->ipf_lk.l, (x)->ipf_lk.pl);
599 #   define	MUTEX_INIT(x,y)		(x)->ipf_lk.l = LOCK_ALLOC((uchar_t)-1, IPF_LOCK_PL, (lkinfo_t *)-1, KM_NOSLEEP)
600 #   define	MUTEX_DESTROY(x)	LOCK_DEALLOC((x)->ipf_lk.l)
601 #   define	MUTEX_ENTER(x)		(x)->ipf_lk.pl = LOCK((x)->ipf_lk.l, \
602 							      IPF_LOCK_PL);
603 #  endif
604 #  define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
605 #  define	FREE_MB_T(m)	m_freem(m)
606 #  define	MTOD(m,t)	mtod(m,t)
607 #  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
608 #  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
609 #  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
610 #  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
611 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
612 #  define	SLEEP(id, n)	sleep((id), PZERO+1)
613 #  define	WAKEUP(id,x)	wakeup(id+x)
614 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
615 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
616 #  define	GETIFP(n,v)	ifunit(n)
617 #  include <sys/kmem.h>
618 #  include <sys/ddi.h>
619 #  define	KMALLOC(a,b)	(a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
620 #  define	KMALLOCS(a,b,c)	(a) = (b)kmem_alloc((c), KM_NOSLEEP)
621 #  define	GET_MINOR(x)	getminor(x)
622 #  define	USE_SPL		1
623 #  define	SPL_IMP(x)	(x) = splimp()
624 #  define	SPL_NET(x)	(x) = splnet()
625 #  define	SPL_X(x)	(void) splx(x)
626 extern	void	m_copydata __P((struct mbuf *, int, int, caddr_t));
627 extern	void	m_copyback __P((struct mbuf *, int, int, caddr_t));
628 #  define	MSGDSIZE(x)	mbufchainlen(x)
629 #  define	M_LEN(x)	(x)->m_len
630 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
631 #  define	GETKTIME(x)	microtime((struct timeval *)x)
632 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
633 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
634 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
635 typedef struct mbuf mb_t;
636 # else
637 #  undef RW_DESTROY
638 #  undef MUTEX_INIT
639 #  undef MUTEX_DESTROY
640 # endif /* _KERNEL */
641 
642 # define OS_RECOGNISED 1
643 
644 #endif /* __sgi */
645 
646 /* ----------------------------------------------------------------------- */
647 /*                                  T R U 6 4                              */
648 /* ----------------------------------------------------------------------- */
649 #ifdef __osf__
650 # undef		MENTAT
651 
652 # include <kern/lock.h>
653 # include <sys/sysmacros.h>
654 
655 # ifdef _KERNEL
656 #  define	KMUTEX_T		simple_lock_data_t
657 #  define	KRWLOCK_T		lock_data_t
658 #  include <net/net_globals.h>
659 #  define	USE_MUTEXES
660 #  define	READ_ENTER(x)		lock_read(&(x)->ipf_lk)
661 #  define	WRITE_ENTER(x)		lock_write(&(x)->ipf_lk)
662 #  define	MUTEX_DOWNGRADE(x)	lock_write_to_read(&(x)->ipf_lk)
663 #  define	RWLOCK_INIT(x, y)	lock_init(&(x)->ipf_lk, TRUE)
664 #  define	RWLOCK_EXIT(x)		lock_done(&(x)->ipf_lk)
665 #  define	RW_DESTROY(x)		lock_terminate(&(x)->ipf_lk)
666 #  define	MUTEX_ENTER(x)		simple_lock(&(x)->ipf_lk)
667 #  define	MUTEX_INIT(x, y)	simple_lock_init(&(x)->ipf_lk)
668 #  define	MUTEX_DESTROY(x)	simple_lock_terminate(&(x)->ipf_lk)
669 #  define	MUTEX_EXIT(x)		simple_unlock(&(x)->ipf_lk)
670 #  define	MUTEX_NUKE(x)		bzero(x, sizeof(*(x)))
671 #  define	ATOMIC_INC64(x)		atomic_incq((uint64_t*)&(x))
672 #  define	ATOMIC_DEC64(x)		atomic_decq((uint64_t*)&(x))
673 #  define	ATOMIC_INC32(x)		atomic_incl((uint32_t*)&(x))
674 #  define	ATOMIC_DEC32(x)		atomic_decl((uint32_t*)&(x))
675 #  define	ATOMIC_INC16(x)		{ simple_lock(&ipf_rw); (x)++; \
676 					  simple_unlock(&ipf_rw); }
677 #  define	ATOMIC_DEC16(x)		{ simple_lock(&ipf_rw); (x)--; \
678 					  simple_unlock(&ipf_rw); }
679 #  define	ATOMIC_INCL(x)		atomic_incl((uint32_t*)&(x))
680 #  define	ATOMIC_DECL(x)		atomic_decl((uint32_t*)&(x))
681 #  define	ATOMIC_INC(x)		{ simple_lock(&ipf_rw); (x)++; \
682 					  simple_unlock(&ipf_rw); }
683 #  define	ATOMIC_DEC(x)		{ simple_lock(&ipf_rw); (x)--; \
684 					  simple_unlock(&ipf_rw); }
685 #  define	SPL_NET(x)		;
686 #  define	SPL_IMP(x)		;
687 #  undef	SPL_X
688 #  define	SPL_X(x)		;
689 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a, b, d)
690 #  define	FREE_MB_T(m)		m_freem(m)
691 #  define	MTOD(m,t)		mtod(m,t)
692 #  define	GETIFP(n, v)		ifunit(n)
693 #  define	GET_MINOR		getminor
694 #  define	WAKEUP(id,x)		wakeup(id + x)
695 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
696 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
697 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
698 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
699 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_PFILT, M_NOWAIT)
700 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_PFILT, \
701 					    ((c) > 4096) ? M_WAITOK : M_NOWAIT)
702 #  define	KFREE(x)	FREE((x), M_PFILT)
703 #  define	KFREES(x,s)	FREE((x), M_PFILT)
704 #  define	MSGDSIZE(x)	mbufchainlen(x)
705 #  define	M_LEN(x)	(x)->m_len
706 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
707 #  define	GETKTIME(x)	microtime((struct timeval *)x)
708 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
709 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
710 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
711 typedef struct mbuf mb_t;
712 # endif /* _KERNEL */
713 
714 # if (defined(_KERNEL) || defined(_NO_BITFIELDS) || (__STDC__ == 1))
715 #  define	IP_V(x)		((x)->ip_vhl >> 4)
716 #  define	IP_HL(x)	((x)->ip_vhl & 0xf)
717 #  define	IP_V_A(x,y)	(x)->ip_vhl |= (((y) << 4) & 0xf0)
718 #  define	IP_HL_A(x,y)	(x)->ip_vhl |= ((y) & 0xf)
719 #  define	TCP_X2(x)	((x)->th_xoff & 0xf)
720 #  define	TCP_X2_A(x,y)	(x)->th_xoff |= ((y) & 0xf)
721 #  define	TCP_OFF(x)	((x)->th_xoff >> 4)
722 #  define	TCP_OFF_A(x,y)	(x)->th_xoff |= (((y) << 4) & 0xf0)
723 # endif
724 
725 /*
726  * These are from's Solaris' #defines for little endian.
727  */
728 #define	IP6F_MORE_FRAG		0x0100
729 #define	IP6F_RESERVED_MASK	0x0600
730 #define	IP6F_OFF_MASK		0xf8ff
731 
732 struct ip6_ext {
733 	u_char	ip6e_nxt;
734 	u_char	ip6e_len;
735 };
736 
737 typedef	int		ioctlcmd_t;
738 /*
739  * Really, any arch where sizeof(long) != sizeof(int).
740  */
741 typedef unsigned int    u_32_t;
742 # define	U_32_T	1
743 
744 # define OS_RECOGNISED 1
745 #endif /* __osf__ */
746 
747 /* ----------------------------------------------------------------------- */
748 /*                                  N E T B S D                            */
749 /* ----------------------------------------------------------------------- */
750 #ifdef __NetBSD__
751 # if defined(_KERNEL) && !defined(IPFILTER_LKM)
752 #  include "bpfilter.h"
753 #  if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 104110000)
754 #   include "opt_inet.h"
755 #  endif
756 #  ifdef INET6
757 #   define USE_INET6
758 #  endif
759 #  if (__NetBSD_Version__ >= 105000000)
760 #   define HAVE_M_PULLDOWN 1
761 #  endif
762 # endif
763 
764 # ifdef _KERNEL
765 #  define	MSGDSIZE(x)	mbufchainlen(x)
766 #  define	M_LEN(x)	(x)->m_len
767 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
768 #  define	GETKTIME(x)	microtime((struct timeval *)x)
769 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
770 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
771 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
772 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
773 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
774 typedef struct mbuf mb_t;
775 # endif /* _KERNEL */
776 # if (NetBSD <= 1991011) && (NetBSD >= 199606)
777 #  define	IFNAME(x)	((struct ifnet *)x)->if_xname
778 #  define	COPYIFNAME(x, b, v) \
779 				(void) strncpy(b, \
780 					       ((struct ifnet *)x)->if_xname, \
781 					       LIFNAMSIZ)
782 #  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index)&7)
783 # else
784 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
785 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
786 # endif
787 
788 typedef	struct uio	uio_t;
789 typedef	u_long		ioctlcmd_t;
790 typedef	int		minor_t;
791 typedef	u_int32_t	u_32_t;
792 # define	U_32_T	1
793 
794 # define OS_RECOGNISED 1
795 #endif /* __NetBSD__ */
796 
797 
798 /* ----------------------------------------------------------------------- */
799 /*                                F R E E B S D                            */
800 /* ----------------------------------------------------------------------- */
801 #ifdef __FreeBSD__
802 # if defined(_KERNEL)
803 #  if (__FreeBSD_version >= 500000)
804 #   include "opt_bpf.h"
805 #  else
806 #   include "bpf.h"
807 #  endif
808 #  if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000)
809 #   include "opt_inet6.h"
810 #  endif
811 #  if defined(INET6) && !defined(USE_INET6)
812 #   define USE_INET6
813 #  endif
814 # endif
815 
816 # if defined(_KERNEL)
817 #  if (__FreeBSD_version >= 400000)
818 /*
819  * When #define'd, the 5.2.1 kernel panics when used with the ftp proxy.
820  * There may be other, safe, kernels but this is not extensively tested yet.
821  */
822 #   define HAVE_M_PULLDOWN
823 #  endif
824 #  if !defined(IPFILTER_LKM) && (__FreeBSD_version >= 300000)
825 #   include "opt_ipfilter.h"
826 #  endif
827 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
828 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
829 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
830 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
831 
832 #  if (__FreeBSD_version >= 500043)
833 #   define NETBSD_PF
834 #  endif
835 # endif /* _KERNEL */
836 
837 # if (__FreeBSD_version >= 500043)
838 #  include <sys/mutex.h>
839 #  include <sys/sx.h>
840 /*
841  * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
842  * for what we want to use them for, despite testing showing they work -
843  * with a WITNESS kernel, it generates LOR messages.
844  */
845 #  define	KMUTEX_T		struct mtx
846 #  if 1
847 #   define	KRWLOCK_T		struct mtx
848 #  else
849 #   define	KRWLOCK_T		struct sx
850 #  endif
851 # endif
852 
853 # if (__FreeBSD_version >= 501113)
854 #  include <net/if_var.h>
855 #  define	IFNAME(x)	((struct ifnet *)x)->if_xname
856 #  define	COPYIFNAME(x, b) \
857 				(void) strncpy(b, \
858 					       ((struct ifnet *)x)->if_xname, \
859 					       LIFNAMSIZ)
860 # endif
861 # if (__FreeBSD_version >= 500043)
862 #  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index) & 7)
863 # else
864 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
865 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
866 # endif
867 
868 # ifdef _KERNEL
869 #  define	GETKTIME(x)	microtime((struct timeval *)x)
870 
871 #  if (__FreeBSD_version >= 500002)
872 #   include <netinet/in_systm.h>
873 #   include <netinet/ip.h>
874 #   include <machine/in_cksum.h>
875 #  endif
876 
877 #  if (__FreeBSD_version >= 500043)
878 #   define	USE_MUTEXES
879 #   define	MUTEX_ENTER(x)		mtx_lock(&(x)->ipf_lk)
880 #   define	MUTEX_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
881 #   define	MUTEX_INIT(x,y)		mtx_init(&(x)->ipf_lk, (y), NULL,\
882 						 MTX_DEF)
883 #   define	MUTEX_DESTROY(x)	mtx_destroy(&(x)->ipf_lk)
884 #   define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
885 /*
886  * Whilst the sx(9) locks on FreeBSD have the right semantics and interface
887  * for what we want to use them for, despite testing showing they work -
888  * with a WITNESS kernel, it generates LOR messages.
889  */
890 #   if 1
891 #    define	READ_ENTER(x)		mtx_lock(&(x)->ipf_lk)
892 #    define	WRITE_ENTER(x)		mtx_lock(&(x)->ipf_lk)
893 #    define	RWLOCK_EXIT(x)		mtx_unlock(&(x)->ipf_lk)
894 #    define	MUTEX_DOWNGRADE(x)	;
895 #    define	RWLOCK_INIT(x,y)	mtx_init(&(x)->ipf_lk, (y), NULL,\
896 						 MTX_DEF)
897 #    define	RW_DESTROY(x)		mtx_destroy(&(x)->ipf_lk)
898 #   else
899 #    define	READ_ENTER(x)		sx_slock(&(x)->ipf_lk)
900 #    define	WRITE_ENTER(x)		sx_xlock(&(x)->ipf_lk)
901 #    define	MUTEX_DOWNGRADE(x)	sx_downgrade(&(x)->ipf_lk)
902 #    define	RWLOCK_INIT(x, y)	sx_init(&(x)->ipf_lk, (y))
903 #    define	RW_DESTROY(x)		sx_destroy(&(x)->ipf_lk)
904 #    ifdef sx_unlock
905 #     define	RWLOCK_EXIT(x)		sx_unlock(x)
906 #    else
907 #     define	RWLOCK_EXIT(x)		do { \
908 					    if ((x)->ipf_lk.sx_cnt < 0) \
909 						sx_xunlock(&(x)->ipf_lk); \
910 					    else \
911 						sx_sunlock(&(x)->ipf_lk); \
912 					} while (0)
913 #    endif
914 #   endif
915 #   include <machine/atomic.h>
916 #   define	ATOMIC_INC(x)		{ mtx_lock(&ipf_rw.ipf_lk); (x)++; \
917 					  mtx_unlock(&ipf_rw.ipf_lk); }
918 #   define	ATOMIC_DEC(x)		{ mtx_lock(&ipf_rw.ipf_lk); (x)--; \
919 					  mtx_unlock(&ipf_rw.ipf_lk); }
920 #   define	ATOMIC_INCL(x)		atomic_add_long(&(x), 1)
921 #   define	ATOMIC_INC64(x)		ATOMIC_INC(x)
922 #   define	ATOMIC_INC32(x)		atomic_add_32(&(x), 1)
923 #   define	ATOMIC_INC16(x)		atomic_add_16(&(x), 1)
924 #   define	ATOMIC_DECL(x)		atomic_add_long(&(x), -1)
925 #   define	ATOMIC_DEC64(x)		ATOMIC_DEC(x)
926 #   define	ATOMIC_DEC32(x)		atomic_add_32(&(x), -1)
927 #   define	ATOMIC_DEC16(x)		atomic_add_16(&(x), -1)
928 #   define	SPL_X(x)	;
929 #   define	SPL_NET(x)	;
930 #   define	SPL_IMP(x)	;
931 extern	int	in_cksum __P((struct mbuf *, int));
932 #  endif /* __FreeBSD_version >= 500043 */
933 #  define	MSGDSIZE(x)	mbufchainlen(x)
934 #  define	M_LEN(x)	(x)->m_len
935 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
936 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
937 typedef struct mbuf mb_t;
938 # endif /* _KERNEL */
939 
940 # if __FreeBSD__ < 3
941 #  include <machine/spl.h>
942 # else
943 #  if __FreeBSD__ == 3
944 #   if defined(IPFILTER_LKM) && !defined(ACTUALLY_LKM_NOT_KERNEL)
945 #    define	ACTUALLY_LKM_NOT_KERNEL
946 #   endif
947 #  endif
948 # endif
949 
950 # if (__FreeBSD_version >= 300000)
951 typedef	u_long		ioctlcmd_t;
952 # else
953 typedef	int		ioctlcmd_t;
954 # endif
955 typedef	struct uio	uio_t;
956 typedef	int		minor_t;
957 typedef	u_int32_t	u_32_t;
958 # define	U_32_T	1
959 
960 # define OS_RECOGNISED 1
961 #endif /* __FreeBSD__ */
962 
963 
964 /* ----------------------------------------------------------------------- */
965 /*                                O P E N B S D                            */
966 /* ----------------------------------------------------------------------- */
967 #ifdef __OpenBSD__
968 # ifdef INET6
969 #  define USE_INET6
970 # endif
971 
972 # ifdef _KERNEL
973 #  if !defined(IPFILTER_LKM)
974 #   include "bpfilter.h"
975 #  endif
976 #  if (OpenBSD >= 200311)
977 #   define SNPRINTF	snprintf
978 #   if defined(USE_INET6)
979 #    include "netinet6/in6_var.h"
980 #    include "netinet6/nd6.h"
981 #   endif
982 #  endif
983 #  if (OpenBSD >= 200012)
984 #   define HAVE_M_PULLDOWN 1
985 #  endif
986 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
987 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
988 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
989 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
990 #  define	GETKTIME(x)	microtime((struct timeval *)x)
991 #  define	MSGDSIZE(x)	mbufchainlen(x)
992 #  define	M_LEN(x)	(x)->m_len
993 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
994 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
995 typedef struct mbuf mb_t;
996 # endif /* _KERNEL */
997 # if (OpenBSD >= 199603)
998 #  define	IFNAME(x, b)	((struct ifnet *)x)->if_xname
999 #  define	COPYIFNAME(x, b, v) \
1000 				(void) strncpy(b, \
1001 					       ((struct ifnet *)x)->if_xname, \
1002 					       LIFNAMSIZ)
1003 #  define	CACHE_HASH(x)	((((struct ifnet *)fin->fin_ifp)->if_index)&7)
1004 # else
1005 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1006 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1007 # endif
1008 
1009 typedef	struct uio	uio_t;
1010 typedef	u_long		ioctlcmd_t;
1011 typedef	int		minor_t;
1012 typedef	u_int32_t	u_32_t;
1013 # define	U_32_T	1
1014 
1015 # define OS_RECOGNISED 1
1016 #endif /* __OpenBSD__ */
1017 
1018 
1019 /* ----------------------------------------------------------------------- */
1020 /*                                B S D O S                                */
1021 /* ----------------------------------------------------------------------- */
1022 #ifdef _BSDI_VERSION
1023 # ifdef INET6
1024 #  define USE_INET6
1025 # endif
1026 
1027 # ifdef _KERNEL
1028 #  define	GETKTIME(x)	microtime((struct timeval *)x)
1029 #  define	MSGDSIZE(x)	mbufchainlen(x)
1030 #  define	M_LEN(x)	(x)->m_len
1031 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1032 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1033 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1034 typedef struct mbuf mb_t;
1035 # endif /* _KERNEL */
1036 
1037 # if (_BSDI_VERSION >= 199701)
1038 typedef	u_long		ioctlcmd_t;
1039 # else
1040 typedef	int		ioctlcmd_t;
1041 # endif
1042 typedef	u_int32_t	u_32_t;
1043 # define	U_32_T	1
1044 
1045 #endif /* _BSDI_VERSION */
1046 
1047 
1048 /* ----------------------------------------------------------------------- */
1049 /*                                  S U N O S 4                            */
1050 /* ----------------------------------------------------------------------- */
1051 #if defined(sun) && !defined(OS_RECOGNISED) /* SunOS4 */
1052 # ifdef _KERNEL
1053 #  include	<sys/kmem_alloc.h>
1054 #  define	GETKTIME(x)	uniqtime((struct timeval *)x)
1055 #  define	MSGDSIZE(x)	mbufchainlen(x)
1056 #  define	M_LEN(x)	(x)->m_len
1057 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1058 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1059 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1060 #  define	GETIFP(n, v)	ifunit(n, IFNAMSIZ)
1061 #  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
1062 #  define	KFREES(x,s)	kmem_free((char *)(x), (s))
1063 #  define	SLEEP(id, n)	sleep((id), PZERO+1)
1064 #  define	WAKEUP(id,x)	wakeup(id + x)
1065 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
1066 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
1067 
1068 extern	void	m_copydata __P((struct mbuf *, int, int, caddr_t));
1069 extern	void	m_copyback __P((struct mbuf *, int, int, caddr_t));
1070 
1071 typedef struct mbuf mb_t;
1072 # endif
1073 
1074 typedef	struct uio	uio_t;
1075 typedef	int		ioctlcmd_t;
1076 typedef	int		minor_t;
1077 typedef	unsigned int	u_32_t;
1078 # define	U_32_T	1
1079 
1080 # define OS_RECOGNISED 1
1081 
1082 #endif /* SunOS 4 */
1083 
1084 /* ----------------------------------------------------------------------- */
1085 /*                            L I N U X                                    */
1086 /* ----------------------------------------------------------------------- */
1087 #if defined(linux) && !defined(OS_RECOGNISED)
1088 #include <linux/config.h>
1089 #include <linux/version.h>
1090 # if LINUX >= 20600
1091 #  define	 HDR_T_PRIVATE	1
1092 # endif
1093 # undef USE_INET6
1094 # ifdef USE_INET6
1095 struct ip6_ext {
1096 	u_char	ip6e_nxt;
1097 	u_char	ip6e_len;
1098 };
1099 # endif
1100 
1101 # ifdef _KERNEL
1102 #  define	IPF_PANIC(x,y)	if (x) { printf y; panic("ipf_panic"); }
1103 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1104 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1105 #  define	COPYIN(a,b,c)	copy_from_user((caddr_t)(b), (caddr_t)(a), (c))
1106 #  define	COPYOUT(a,b,c)	copy_to_user((caddr_t)(b), (caddr_t)(a), (c))
1107 #  define	FREE_MB_T(m)	kfree_skb(m)
1108 #  define	GETKTIME(x)	do_gettimeofday((struct timeval *)x)
1109 #  define	SLEEP(x,s)	0, interruptible_sleep_on(x##_linux)
1110 #  define	WAKEUP(x,y)	wake_up(x##_linux + y)
1111 #  define	UIOMOVE(a,b,c,d)	uiomove(a,b,c,d)
1112 #  define	USE_MUTEXES
1113 #  define	KRWLOCK_T		rwlock_t
1114 #  define	KMUTEX_T		spinlock_t
1115 #  define	MUTEX_INIT(x,y)		spin_lock_init(&(x)->ipf_lk)
1116 #  define	MUTEX_ENTER(x)		spin_lock(&(x)->ipf_lk)
1117 #  define	MUTEX_EXIT(x)		spin_unlock(&(x)->ipf_lk)
1118 #  define	MUTEX_DESTROY(x)	do { } while (0)
1119 #  define	MUTEX_NUKE(x)		bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1120 #  define	READ_ENTER(x)		ipf_read_enter(x)
1121 #  define	WRITE_ENTER(x)		ipf_write_enter(x)
1122 #  define	RWLOCK_INIT(x,y)	rwlock_init(&(x)->ipf_lk)
1123 #  define	RW_DESTROY(x)		do { } while (0)
1124 #  define	RWLOCK_EXIT(x)		ipf_rw_exit(x)
1125 #  define	MUTEX_DOWNGRADE(x)	ipf_rw_downgrade(x)
1126 #  define	ATOMIC_INCL(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1127 					MUTEX_EXIT(&ipf_rw)
1128 #  define	ATOMIC_DECL(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1129 					MUTEX_EXIT(&ipf_rw)
1130 #  define	ATOMIC_INC64(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1131 					MUTEX_EXIT(&ipf_rw)
1132 #  define	ATOMIC_INC32(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1133 					MUTEX_EXIT(&ipf_rw)
1134 #  define	ATOMIC_INC16(x)		MUTEX_ENTER(&ipf_rw); (x)++; \
1135 					MUTEX_EXIT(&ipf_rw)
1136 #  define	ATOMIC_DEC64(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1137 					MUTEX_EXIT(&ipf_rw)
1138 #  define	ATOMIC_DEC32(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1139 					MUTEX_EXIT(&ipf_rw)
1140 #  define	ATOMIC_DEC16(x)		MUTEX_ENTER(&ipf_rw); (x)--; \
1141 					MUTEX_EXIT(&ipf_rw)
1142 #  define	SPL_IMP(x)		do { } while (0)
1143 #  define	SPL_NET(x)		do { } while (0)
1144 #  define	SPL_X(x)		do { } while (0)
1145 #  define	IFNAME(x)		((struct net_device*)x)->name
1146 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1147 			  ((struct net_device *)fin->fin_ifp)->ifindex) & 7)
1148 typedef	struct	sk_buff	mb_t;
1149 extern	void	m_copydata __P((mb_t *, int, int, caddr_t));
1150 extern	void	m_copyback __P((mb_t *, int, int, caddr_t));
1151 extern	void	m_adj __P((mb_t *, int));
1152 extern	mb_t	*m_pullup __P((mb_t *, int));
1153 #  define	mbuf	sk_buff
1154 
1155 #  define	mtod(m, t)	((t)(m)->data)
1156 #  define	m_len		len
1157 #  define	m_next		next
1158 #  define	M_DUPLICATE(m)	skb_clone((m), in_interrupt() ? GFP_ATOMIC : \
1159 								GFP_KERNEL)
1160 #  define	MSGDSIZE(m)	(m)->len
1161 #  define	M_LEN(m)	(m)->len
1162 
1163 #  define	splnet(x)	;
1164 #  define	printf		printk
1165 #  define	bcopy(s,d,z)	memmove(d, s, z)
1166 #  define	bzero(s,z)	memset(s, 0, z)
1167 #  define	bcmp(a,b,z)	memcmp(a, b, z)
1168 
1169 #  define	ifnet		net_device
1170 #  define	if_xname	name
1171 #  define	if_unit		ifindex
1172 
1173 #  define	KMALLOC(x,t)	(x) = (t)kmalloc(sizeof(*(x)), \
1174 				    in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1175 #  define	KFREE(x)	kfree(x)
1176 #  define	KMALLOCS(x,t,s)	(x) = (t)kmalloc((s), \
1177 				    in_interrupt() ? GFP_ATOMIC : GFP_KERNEL)
1178 #  define	KFREES(x,s)	kfree(x)
1179 
1180 #  define GETIFP(n,v)	dev_get_by_name(n)
1181 
1182 # else
1183 #  include <net/ethernet.h>
1184 
1185 struct mbuf {
1186 };
1187 
1188 #  ifndef _NET_ROUTE_H
1189 struct rtentry {
1190 };
1191 #  endif
1192 
1193 struct ifnet {
1194 	char	if_xname[IFNAMSIZ];
1195 	int	if_unit;
1196 	int	(* if_output) __P((struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *));
1197 	struct	ifaddr	*if_addrlist;
1198 };
1199 # define	IFNAME(x)	((struct ifnet *)x)->if_xname
1200 
1201 # endif	/* _KERNEL */
1202 
1203 # define	COPYIFNAME(x, b) \
1204 				(void) strncpy(b, \
1205 					       ((struct ifnet *)x)->if_xname, \
1206 					       LIFNAMSIZ)
1207 
1208 # include <linux/fs.h>
1209 # define	FWRITE	FMODE_WRITE
1210 # define	FREAD	FMODE_READ
1211 
1212 # define	__USE_MISC	1
1213 # define	__FAVOR_BSD	1
1214 
1215 typedef	struct uio {
1216 	struct iovec	*uio_iov;
1217 	void	*uio_file;
1218 	char	*uio_buf;
1219 	int	uio_iovcnt;
1220 	int	uio_offset;
1221 	size_t	uio_resid;
1222 	int	uio_rw;
1223 } uio_t;
1224 
1225 extern	int	uiomove __P((caddr_t, size_t, int, struct uio *));
1226 
1227 # define	UIO_READ	1
1228 # define	UIO_WRITE	2
1229 
1230 typedef	u_long		ioctlcmd_t;
1231 typedef	int		minor_t;
1232 typedef u_int32_t 	u_32_t;
1233 # define	U_32_T	1
1234 
1235 # define OS_RECOGNISED 1
1236 
1237 #endif
1238 
1239 
1240 /* ----------------------------------------------------------------------- */
1241 /*                                    A I X                                */
1242 /* ----------------------------------------------------------------------- */
1243 #if defined(_AIX51)
1244 # undef		MENTAT
1245 
1246 # include <sys/lock.h>
1247 # include <sys/sysmacros.h>
1248 
1249 # ifdef _KERNEL
1250 #  define rw_read_locked(x)		0
1251 #  include <net/net_globals.h>
1252 #  include <net/net_malloc.h>
1253 #  define	KMUTEX_T		simple_lock_t
1254 #  define	KRWLOCK_T		complex_lock_t
1255 #  define	USE_MUTEXES		1
1256 #  define	USE_SPL			1
1257 #  define	READ_ENTER(x)		lock_read((x)->ipf_lk)
1258 #  define	WRITE_ENTER(x)		lock_write((x)->ipf_lk)
1259 #  define	MUTEX_DOWNGRADE(x)	lock_write_to_read((x)->ipf_lk)
1260 #  define	RWLOCK_INIT(x, y)	lock_alloc(&(x)->ipf_lk, \
1261 						   LOCK_ALLOC_PIN, \
1262 						   (u_short)y, 0); \
1263 					lock_init((x)->ipf_lk, TRUE)
1264 #  define	RWLOCK_EXIT(x)		lock_done((x)->ipf_lk)
1265 #  define	RW_DESTROY(x)		lock_free(&(x)->ipf_lk)
1266 #  define	MUTEX_ENTER(x)		simple_lock((x)->ipf_lk)
1267 #  define	MUTEX_INIT(x, y)	lock_alloc(&(x)->ipf_lk, \
1268 						   LOCK_ALLOC_PIN, \
1269 						   (u_short)y, 0); \
1270 					simple_lock_init((x)->ipf_lk)
1271 #  define	MUTEX_DESTROY(x)	lock_free(&(x)->ipf_lk)
1272 #  define	MUTEX_EXIT(x)		simple_unlock((x)->ipf_lk)
1273 #  define	MUTEX_NUKE(x)		bzero(&(x)->ipf_lk, sizeof((x)->ipf_lk))
1274 #   define	ATOMIC_INC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1275 					  MUTEX_EXIT(&ipf_rw); }
1276 #   define	ATOMIC_DEC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1277 					  MUTEX_EXIT(&ipf_rw); }
1278 #   define	ATOMIC_INC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1279 					  MUTEX_EXIT(&ipf_rw); }
1280 #   define	ATOMIC_DEC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1281 					  MUTEX_EXIT(&ipf_rw); }
1282 #   define	ATOMIC_INCL(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1283 					  MUTEX_EXIT(&ipf_rw); }
1284 #   define	ATOMIC_DECL(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1285 					  MUTEX_EXIT(&ipf_rw); }
1286 #   define	ATOMIC_INC(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
1287 					  MUTEX_EXIT(&ipf_rw); }
1288 #   define	ATOMIC_DEC(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
1289 					  MUTEX_EXIT(&ipf_rw); }
1290 #  define	SPL_NET(x)		x = splnet()
1291 #  define	SPL_IMP(x)		x = splimp()
1292 #  undef	SPL_X
1293 #  define	SPL_X(x)		splx(x)
1294 #  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
1295 extern void* getifp __P((char *, int));
1296 #  define	GETIFP(n, v)		getifp(n, v)
1297 #  define	GET_MINOR		minor
1298 #  define	SLEEP(id, n)	sleepx((id), PZERO+1, 0)
1299 #  define	WAKEUP(id,x)	wakeup(id)
1300 #  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
1301 #  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
1302 #  define	BCOPYIN(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1303 #  define	BCOPYOUT(a,b,c)	bcopy((caddr_t)(a), (caddr_t)(b), (c))
1304 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), M_TEMP, M_NOWAIT)
1305 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), M_TEMP, \
1306 					    ((c) > 4096) ? M_WAITOK : M_NOWAIT)
1307 #  define	KFREE(x)	FREE((x), M_TEMP)
1308 #  define	KFREES(x,s)	FREE((x), M_TEMP)
1309 #  define	MSGDSIZE(x)	mbufchainlen(x)
1310 #  define	M_LEN(x)	(x)->m_len
1311 #  define	M_DUPLICATE(x)	m_copy((x), 0, M_COPYALL)
1312 #  define	GETKTIME(x)
1313 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1314 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1315 #  define	IPF_PANIC(x,y)
1316 typedef struct mbuf mb_t;
1317 # endif /* _KERNEL */
1318 
1319 /*
1320  * These are from's Solaris' #defines for little endian.
1321  */
1322 #if !defined(IP6F_MORE_FRAG)
1323 # define	IP6F_MORE_FRAG		0x0100
1324 #endif
1325 #if !defined(IP6F_RESERVED_MASK)
1326 # define	IP6F_RESERVED_MASK	0x0600
1327 #endif
1328 #if !defined(IP6F_OFF_MASK)
1329 # define	IP6F_OFF_MASK		0xf8ff
1330 #endif
1331 
1332 struct ip6_ext {
1333 	u_char	ip6e_nxt;
1334 	u_char	ip6e_len;
1335 };
1336 
1337 typedef	int		ioctlcmd_t;
1338 typedef	int		minor_t;
1339 /*
1340  * Really, any arch where sizeof(long) != sizeof(int).
1341  */
1342 typedef unsigned int    u_32_t;
1343 # define	U_32_T	1
1344 
1345 # define OS_RECOGNISED 1
1346 #endif	/* _AIX51 */
1347 
1348 
1349 #ifndef	OS_RECOGNISED
1350 #error	ip_compat.h does not recognise this platform/OS.
1351 #endif
1352 
1353 
1354 /* ----------------------------------------------------------------------- */
1355 /*                           G E N E R I C                                 */
1356 /* ----------------------------------------------------------------------- */
1357 #ifndef OS_RECOGNISED
1358 #endif
1359 
1360 /*
1361  * For BSD kernels, if bpf is in the kernel, enable ipfilter to use bpf in
1362  * filter rules.
1363  */
1364 #if !defined(IPFILTER_BPF) && ((NBPF > 0) || (NBPFILTER > 0) || (DEV_BPF > 0))
1365 # define IPFILTER_BPF
1366 #endif
1367 
1368 /*
1369  * Userland locking primitives
1370  */
1371 typedef	struct	{
1372 	char	*eMm_owner;
1373 	char	*eMm_heldin;
1374 	u_int	eMm_magic;
1375 	int	eMm_held;
1376 	int	eMm_heldat;
1377 #ifdef __hpux
1378 	char	eMm_fill[8];
1379 #endif
1380 } eMmutex_t;
1381 
1382 typedef	struct	{
1383 	char	*eMrw_owner;
1384 	char	*eMrw_heldin;
1385 	u_int	eMrw_magic;
1386 	short	eMrw_read;
1387 	short	eMrw_write;
1388 	int	eMrw_heldat;
1389 #ifdef __hpux
1390 	char	eMm_fill[24];
1391 #endif
1392 } eMrwlock_t;
1393 
1394 typedef union {
1395 #ifdef KMUTEX_T
1396 	struct	{
1397 		KMUTEX_T	ipf_slk;
1398 		char		*ipf_lname;
1399 	} ipf_lkun_s;
1400 #endif
1401 	eMmutex_t	ipf_emu;
1402 } ipfmutex_t;
1403 
1404 typedef union {
1405 #ifdef KRWLOCK_T
1406 	struct	{
1407 		KRWLOCK_T	ipf_slk;
1408 		char		*ipf_lname;
1409 		int		ipf_sr;
1410 		int		ipf_sw;
1411 		u_int		ipf_magic;
1412 	} ipf_lkun_s;
1413 #endif
1414 	eMrwlock_t	ipf_emu;
1415 } ipfrwlock_t;
1416 
1417 #define	ipf_lk		ipf_lkun_s.ipf_slk
1418 #define	ipf_lname	ipf_lkun_s.ipf_lname
1419 #define	ipf_isr		ipf_lkun_s.ipf_sr
1420 #define	ipf_isw		ipf_lkun_s.ipf_sw
1421 #define	ipf_magic	ipf_lkun_s.ipf_magic
1422 
1423 #if !defined(__GNUC__) || \
1424     (defined(__FreeBSD_version) && (__FreeBSD_version >= 503000))
1425 # ifndef	INLINE
1426 #  define	INLINE
1427 # endif
1428 #else
1429 # define	INLINE	__inline__
1430 #endif
1431 
1432 #if defined(linux) && defined(_KERNEL)
1433 extern	INLINE	void	ipf_read_enter __P((ipfrwlock_t *));
1434 extern	INLINE	void	ipf_write_enter __P((ipfrwlock_t *));
1435 extern	INLINE	void	ipf_rw_exit __P((ipfrwlock_t *));
1436 extern	INLINE	void	ipf_rw_downgrade __P((ipfrwlock_t *));
1437 #endif
1438 
1439 /*
1440  * In a non-kernel environment, there are a lot of macros that need to be
1441  * filled in to be null-ops or to point to some compatibility function,
1442  * somewhere in userland.
1443  */
1444 #ifndef _KERNEL
1445 typedef	struct	mb_s	{
1446 	struct	mb_s	*mb_next;
1447 	int		mb_len;
1448 	u_long		mb_buf[2048];
1449 } mb_t;
1450 # undef		m_next
1451 # define	m_next		mb_next
1452 # define	MSGDSIZE(x)	(x)->mb_len	/* XXX - from ipt.c */
1453 # define	M_LEN(x)	(x)->mb_len
1454 # define	M_DUPLICATE(x)	(x)
1455 # define	GETKTIME(x)	gettimeofday((struct timeval *)(x), NULL)
1456 # undef		MTOD
1457 # define	MTOD(m, t)	((t)(m)->mb_buf)
1458 # define	FREE_MB_T(x)
1459 # define	SLEEP(x,y)	1;
1460 # define	WAKEUP(x,y)	;
1461 # define	IPF_PANIC(x,y)	;
1462 # define	PANIC(x,y)	;
1463 # define	SPL_NET(x)	;
1464 # define	SPL_IMP(x)	;
1465 # define	SPL_X(x)	;
1466 # define	KMALLOC(a,b)	(a) = (b)malloc(sizeof(*a))
1467 # define	KMALLOCS(a,b,c)	(a) = (b)malloc(c)
1468 # define	KFREE(x)	free(x)
1469 # define	KFREES(x,s)	free(x)
1470 # define	GETIFP(x, v)	get_unit(x,v)
1471 # define	COPYIN(a,b,c)	(bcopy((a), (b), (c)), 0)
1472 # define	COPYOUT(a,b,c)	(bcopy((a), (b), (c)), 0)
1473 # define	BCOPYIN(a,b,c)	(bcopy((a), (b), (c)), 0)
1474 # define	BCOPYOUT(a,b,c)	(bcopy((a), (b), (c)), 0)
1475 # define	COPYDATA(m, o, l, b)	bcopy(MTOD((mb_t *)m, char *) + (o), \
1476 					      (b), (l))
1477 # define	COPYBACK(m, o, l, b)	bcopy((b), \
1478 					      MTOD((mb_t *)m, char *) + (o), \
1479 					      (l))
1480 # define	UIOMOVE(a,b,c,d)	ipfuiomove(a,b,c,d)
1481 extern	void	m_copydata __P((mb_t *, int, int, caddr_t));
1482 extern	int	ipfuiomove __P((caddr_t, int, int, struct uio *));
1483 # ifndef CACHE_HASH
1484 #  define	CACHE_HASH(x)	((IFNAME(fin->fin_ifp)[0] + \
1485 				  ((struct ifnet *)fin->fin_ifp)->if_unit) & 7)
1486 # endif
1487 
1488 # define	MUTEX_DESTROY(x)	eMmutex_destroy(&(x)->ipf_emu)
1489 # define	MUTEX_ENTER(x)		eMmutex_enter(&(x)->ipf_emu, \
1490 						      __FILE__, __LINE__)
1491 # define	MUTEX_EXIT(x)		eMmutex_exit(&(x)->ipf_emu)
1492 # define	MUTEX_INIT(x,y)		eMmutex_init(&(x)->ipf_emu, y)
1493 # define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
1494 
1495 # define	MUTEX_DOWNGRADE(x)	eMrwlock_downgrade(&(x)->ipf_emu, \
1496 							   __FILE__, __LINE__)
1497 # define	READ_ENTER(x)		eMrwlock_read_enter(&(x)->ipf_emu, \
1498 							    __FILE__, __LINE__)
1499 # define	RWLOCK_INIT(x, y)	eMrwlock_init(&(x)->ipf_emu, y)
1500 # define	RWLOCK_EXIT(x)		eMrwlock_exit(&(x)->ipf_emu)
1501 # define	RW_DESTROY(x)		eMrwlock_destroy(&(x)->ipf_emu)
1502 # define	WRITE_ENTER(x)		eMrwlock_write_enter(&(x)->ipf_emu, \
1503 							     __FILE__, \
1504 							     __LINE__)
1505 
1506 # define	USE_MUTEXES		1
1507 
1508 extern void eMmutex_destroy __P((eMmutex_t *));
1509 extern void eMmutex_enter __P((eMmutex_t *, char *, int));
1510 extern void eMmutex_exit __P((eMmutex_t *));
1511 extern void eMmutex_init __P((eMmutex_t *, char *));
1512 extern void eMrwlock_destroy __P((eMrwlock_t *));
1513 extern void eMrwlock_exit __P((eMrwlock_t *));
1514 extern void eMrwlock_init __P((eMrwlock_t *, char *));
1515 extern void eMrwlock_read_enter __P((eMrwlock_t *, char *, int));
1516 extern void eMrwlock_write_enter __P((eMrwlock_t *, char *, int));
1517 extern void eMrwlock_downgrade __P((eMrwlock_t *, char *, int));
1518 
1519 #undef NET_IS_HCK_L3_FULL
1520 #define	NET_IS_HCK_L3_FULL(n, x) (0)
1521 #undef NET_IS_HCK_L3_PART
1522 #define	NET_IS_HCK_L3_PART(n, x) (0)
1523 #undef NET_IS_HCK_L4_FULL
1524 #define	NET_IS_HCK_L4_FULL(n, x) (0)
1525 #undef NET_IS_HCK_L4_PART
1526 #define	NET_IS_HCK_L4_PART(n, x) (0)
1527 
1528 #endif
1529 
1530 #define	MAX_IPV4HDR	((0xf << 2) + sizeof(struct icmp) + sizeof(ip_t) + 8)
1531 
1532 #ifndef	IP_OFFMASK
1533 # define	IP_OFFMASK	0x1fff
1534 #endif
1535 
1536 
1537 /*
1538  * On BSD's use quad_t as a guarantee for getting at least a 64bit sized
1539  * object.
1540  */
1541 #if	BSD > 199306
1542 # define	USE_QUAD_T
1543 # define	U_QUAD_T	u_quad_t
1544 # define	QUAD_T		quad_t
1545 #else /* BSD > 199306 */
1546 # define	U_QUAD_T	u_long
1547 # define	QUAD_T		long
1548 #endif /* BSD > 199306 */
1549 
1550 
1551 #ifdef	USE_INET6
1552 # if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__) || \
1553      defined(__osf__) || defined(linux)
1554 #  include <netinet/ip6.h>
1555 #  include <netinet/icmp6.h>
1556 #  if !defined(linux)
1557 #   if defined(_KERNEL) && !defined(__osf__)
1558 #    include <netinet6/ip6_var.h>
1559 #   endif
1560 #  endif
1561 typedef	struct ip6_hdr	ip6_t;
1562 # endif
1563 #endif
1564 
1565 #ifndef	MAX
1566 # define	MAX(a,b)	(((a) > (b)) ? (a) : (b))
1567 #endif
1568 
1569 #if defined(_KERNEL)
1570 # ifdef MENTAT
1571 #  define	COPYDATA	mb_copydata
1572 #  define	COPYBACK	mb_copyback
1573 # else
1574 #  define	COPYDATA	m_copydata
1575 #  define	COPYBACK	m_copyback
1576 # endif
1577 # if (BSD >= 199306) || defined(__FreeBSD__)
1578 #  if (defined(__NetBSD_Version__) && (__NetBSD_Version__ < 105180000)) || \
1579        defined(__FreeBSD__) || (defined(OpenBSD) && (OpenBSD < 200206)) || \
1580        defined(_BSDI_VERSION)
1581 #   include <vm/vm.h>
1582 #  endif
1583 #  if !defined(__FreeBSD__) || (defined (__FreeBSD_version) && \
1584       (__FreeBSD_version >= 300000))
1585 #   if (defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105180000)) || \
1586        (defined(OpenBSD) && (OpenBSD >= 200111))
1587 #    include <uvm/uvm_extern.h>
1588 #   else
1589 #    include <vm/vm_extern.h>
1590 extern  vm_map_t        kmem_map;
1591 #   endif
1592 #   include <sys/proc.h>
1593 #  else /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1594 #   include <vm/vm_kern.h>
1595 #  endif /* !__FreeBSD__ || (__FreeBSD__ && __FreeBSD_version >= 300000) */
1596 
1597 #  ifdef IPFILTER_M_IPFILTER
1598 #    include <sys/malloc.h>
1599 MALLOC_DECLARE(M_IPFILTER);
1600 #    define	_M_IPF		M_IPFILTER
1601 #  else /* IPFILTER_M_IPFILTER */
1602 #   ifdef M_PFIL
1603 #    define	_M_IPF		M_PFIL
1604 #   else
1605 #    ifdef M_IPFILTER
1606 #     define	_M_IPF		M_IPFILTER
1607 #    else
1608 #     define	_M_IPF		M_TEMP
1609 #    endif /* M_IPFILTER */
1610 #   endif /* M_PFIL */
1611 #  endif /* IPFILTER_M_IPFILTER */
1612 #  define	KMALLOC(a, b)	MALLOC((a), b, sizeof(*(a)), _M_IPF, M_NOWAIT)
1613 #  define	KMALLOCS(a, b, c)	MALLOC((a), b, (c), _M_IPF, M_NOWAIT)
1614 #  define	KFREE(x)	FREE((x), _M_IPF)
1615 #  define	KFREES(x,s)	FREE((x), _M_IPF)
1616 #  define	UIOMOVE(a,b,c,d)	uiomove(a,b,d)
1617 #  define	SLEEP(id, n)	tsleep((id), PPAUSE|PCATCH, n, 0)
1618 #  define	WAKEUP(id,x)	wakeup(id+x)
1619 #  define	GETIFP(n, v)	ifunit(n)
1620 # endif /* (Free)BSD */
1621 
1622 # if !defined(USE_MUTEXES) && !defined(SPL_NET)
1623 #  if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199407)) || \
1624       (defined(OpenBSD) && (OpenBSD >= 200006))
1625 #   define	SPL_NET(x)	x = splsoftnet()
1626 #  else
1627 #   define	SPL_IMP(x)	x = splimp()
1628 #   define	SPL_NET(x)	x = splnet()
1629 #  endif /* NetBSD && (NetBSD <= 1991011) && (NetBSD >= 199407) */
1630 #  define	SPL_X(x)	(void) splx(x)
1631 # endif /* !USE_MUTEXES */
1632 
1633 # ifndef FREE_MB_T
1634 #  define	FREE_MB_T(m)	m_freem(m)
1635 # endif
1636 
1637 # ifndef MTOD
1638 #  define	MTOD(m,t)	mtod(m,t)
1639 # endif
1640 
1641 # ifndef COPYIN
1642 #  define	COPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1643 #  define	COPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1644 #  define	BCOPYIN(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1645 #  define	BCOPYOUT(a,b,c)	(bcopy((caddr_t)(a), (caddr_t)(b), (c)), 0)
1646 # endif
1647 
1648 # ifndef KMALLOC
1649 #  define	KMALLOC(a,b)	(a) = (b)new_kmem_alloc(sizeof(*(a)), \
1650 							KMEM_NOSLEEP)
1651 #  define	KMALLOCS(a,b,c)	(a) = (b)new_kmem_alloc((c), KMEM_NOSLEEP)
1652 # endif
1653 
1654 # ifndef	GET_MINOR
1655 #  define	GET_MINOR(x)	minor(x)
1656 # endif
1657 # define	PANIC(x,y)	if (x) panic y
1658 #endif /* _KERNEL */
1659 
1660 #ifndef	IFNAME
1661 # define	IFNAME(x)	((struct ifnet *)x)->if_name
1662 #endif
1663 #ifndef	COPYIFNAME
1664 # define	NEED_FRGETIFNAME
1665 extern	char	*fr_getifname __P((struct ifnet *, char *));
1666 # define	COPYIFNAME(x, b, v) \
1667 				fr_getifname((struct ifnet *)x, b)
1668 #endif
1669 
1670 #ifndef ASSERT
1671 # define	ASSERT(x)
1672 #endif
1673 
1674 /*
1675  * Because the ctype(3) posix definition, if used "safely" in code everywhere,
1676  * would mean all normal code that walks through strings needed casts.  Yuck.
1677  */
1678 #define	ISALNUM(x)	isalnum((u_char)(x))
1679 #define	ISALPHA(x)	isalpha((u_char)(x))
1680 #define	ISASCII(x)	isascii((u_char)(x))
1681 #define	ISDIGIT(x)	isdigit((u_char)(x))
1682 #define	ISPRINT(x)	isprint((u_char)(x))
1683 #define	ISSPACE(x)	isspace((u_char)(x))
1684 #define	ISUPPER(x)	isupper((u_char)(x))
1685 #define	ISXDIGIT(x)	isxdigit((u_char)(x))
1686 #define	ISLOWER(x)	islower((u_char)(x))
1687 #define	TOUPPER(x)	toupper((u_char)(x))
1688 #define	TOLOWER(x)	tolower((u_char)(x))
1689 
1690 /*
1691  * If mutexes aren't being used, turn all the mutex functions into null-ops.
1692  */
1693 #if !defined(USE_MUTEXES)
1694 # define	USE_SPL			1
1695 # undef		RW_DESTROY
1696 # undef		MUTEX_INIT
1697 # undef		MUTEX_NUKE
1698 # undef		MUTEX_DESTROY
1699 # define	MUTEX_ENTER(x)		;
1700 # define	READ_ENTER(x)		;
1701 # define	WRITE_ENTER(x)		;
1702 # define	MUTEX_DOWNGRADE(x)	;
1703 # define	RWLOCK_INIT(x, y)	;
1704 # define	RWLOCK_EXIT(x)		;
1705 # define	RW_DESTROY(x)		;
1706 # define	MUTEX_EXIT(x)		;
1707 # define	MUTEX_INIT(x,y)		;
1708 # define	MUTEX_DESTROY(x)	;
1709 # define	MUTEX_NUKE(x)		;
1710 #endif /* !USE_MUTEXES */
1711 #ifndef	ATOMIC_INC
1712 # define	ATOMIC_INC(x)		(x)++
1713 # define	ATOMIC_DEC(x)		(x)--
1714 #endif
1715 
1716 #if defined(USE_SPL) && defined(_KERNEL)
1717 # define	SPL_INT(x)	int x
1718 #else
1719 # define	SPL_INT(x)
1720 #endif
1721 
1722 /*
1723  * If there are no atomic operations for bit sizes defined, define them to all
1724  * use a generic one that works for all sizes.
1725  */
1726 #ifndef	ATOMIC_INCL
1727 # define	ATOMIC_INCL		ATOMIC_INC
1728 # define	ATOMIC_INC64		ATOMIC_INC
1729 # define	ATOMIC_INC32		ATOMIC_INC
1730 # define	ATOMIC_INC16		ATOMIC_INC
1731 # define	ATOMIC_DECL		ATOMIC_DEC
1732 # define	ATOMIC_DEC64		ATOMIC_DEC
1733 # define	ATOMIC_DEC32		ATOMIC_DEC
1734 # define	ATOMIC_DEC16		ATOMIC_DEC
1735 #endif
1736 
1737 #ifndef HDR_T_PRIVATE
1738 typedef	struct	tcphdr	tcphdr_t;
1739 typedef	struct	udphdr	udphdr_t;
1740 #endif
1741 typedef	struct	icmp	icmphdr_t;
1742 typedef	struct	ip	ip_t;
1743 typedef	struct	ether_header	ether_header_t;
1744 typedef	struct	tcpiphdr	tcpiphdr_t;
1745 
1746 #ifndef	FR_GROUPLEN
1747 # define	FR_GROUPLEN	16
1748 #endif
1749 
1750 #ifdef offsetof
1751 # undef	offsetof
1752 #endif
1753 #ifndef offsetof
1754 # define offsetof(t,m) (int)((&((t *)0L)->m))
1755 #endif
1756 
1757 /*
1758  * This set of macros has been brought about because on Tru64 it is not
1759  * possible to easily assign or examine values in a structure that are
1760  * bit fields.
1761  */
1762 #ifndef IP_V
1763 # define	IP_V(x)		(x)->ip_v
1764 #endif
1765 #ifndef	IP_V_A
1766 # define	IP_V_A(x,y)	(x)->ip_v = (y)
1767 #endif
1768 #ifndef	IP_HL
1769 # define	IP_HL(x)	(x)->ip_hl
1770 #endif
1771 #ifndef	IP_HL_A
1772 # define	IP_HL_A(x,y)	(x)->ip_hl = (y)
1773 #endif
1774 #ifndef	TCP_X2
1775 # define	TCP_X2(x)	(x)->th_x2
1776 #endif
1777 #ifndef	TCP_X2_A
1778 # define	TCP_X2_A(x,y)	(x)->th_x2 = (y)
1779 #endif
1780 #ifndef	TCP_OFF
1781 # define	TCP_OFF(x)	(x)->th_off
1782 #endif
1783 #ifndef	TCP_OFF_A
1784 # define	TCP_OFF_A(x,y)	(x)->th_off = (y)
1785 #endif
1786 #define	IPMINLEN(i, h)	((i)->ip_len >= (IP_HL(i) * 4 + sizeof(struct h)))
1787 
1788 
1789 /*
1790  * XXX - This is one of those *awful* hacks which nobody likes
1791  */
1792 #ifdef	ultrix
1793 #define	A_A
1794 #else
1795 #define	A_A	&
1796 #endif
1797 
1798 #define	TCPF_ALL	(TH_FIN|TH_SYN|TH_RST|TH_PUSH|TH_ACK|TH_URG|\
1799 			 TH_ECN|TH_CWR)
1800 
1801 #if (BSD >= 199306) && !defined(m_act)
1802 # define	m_act	m_nextpkt
1803 #endif
1804 
1805 /*
1806  * Security Options for Intenet Protocol (IPSO) as defined in RFC 1108.
1807  *
1808  * Basic Option
1809  *
1810  * 00000001   -   (Reserved 4)
1811  * 00111101   -   Top Secret
1812  * 01011010   -   Secret
1813  * 10010110   -   Confidential
1814  * 01100110   -   (Reserved 3)
1815  * 11001100   -   (Reserved 2)
1816  * 10101011   -   Unclassified
1817  * 11110001   -   (Reserved 1)
1818  */
1819 #define	IPSO_CLASS_RES4		0x01
1820 #define	IPSO_CLASS_TOPS		0x3d
1821 #define	IPSO_CLASS_SECR		0x5a
1822 #define	IPSO_CLASS_CONF		0x96
1823 #define	IPSO_CLASS_RES3		0x66
1824 #define	IPSO_CLASS_RES2		0xcc
1825 #define	IPSO_CLASS_UNCL		0xab
1826 #define	IPSO_CLASS_RES1		0xf1
1827 
1828 #define	IPSO_AUTH_GENSER	0x80
1829 #define	IPSO_AUTH_ESI		0x40
1830 #define	IPSO_AUTH_SCI		0x20
1831 #define	IPSO_AUTH_NSA		0x10
1832 #define	IPSO_AUTH_DOE		0x08
1833 #define	IPSO_AUTH_UN		0x06
1834 #define	IPSO_AUTH_FTE		0x01
1835 
1836 /*
1837  * IP option #defines
1838  */
1839 #undef	IPOPT_RR
1840 #define	IPOPT_RR	7
1841 #undef	IPOPT_ZSU
1842 #define	IPOPT_ZSU	10	/* ZSU */
1843 #undef	IPOPT_MTUP
1844 #define	IPOPT_MTUP	11	/* MTUP */
1845 #undef	IPOPT_MTUR
1846 #define	IPOPT_MTUR	12	/* MTUR */
1847 #undef	IPOPT_ENCODE
1848 #define	IPOPT_ENCODE	15	/* ENCODE */
1849 #undef	IPOPT_TS
1850 #define	IPOPT_TS	68
1851 #undef	IPOPT_TR
1852 #define	IPOPT_TR	82	/* TR */
1853 #undef	IPOPT_SECURITY
1854 #define	IPOPT_SECURITY	130
1855 #undef	IPOPT_LSRR
1856 #define	IPOPT_LSRR	131
1857 #undef	IPOPT_E_SEC
1858 #define	IPOPT_E_SEC	133	/* E-SEC */
1859 #undef	IPOPT_CIPSO
1860 #define	IPOPT_CIPSO	134	/* CIPSO */
1861 #undef	IPOPT_SATID
1862 #define	IPOPT_SATID	136
1863 #ifndef	IPOPT_SID
1864 # define	IPOPT_SID	IPOPT_SATID
1865 #endif
1866 #undef	IPOPT_SSRR
1867 #define	IPOPT_SSRR	137
1868 #undef	IPOPT_ADDEXT
1869 #define	IPOPT_ADDEXT	147	/* ADDEXT */
1870 #undef	IPOPT_VISA
1871 #define	IPOPT_VISA	142	/* VISA */
1872 #undef	IPOPT_IMITD
1873 #define	IPOPT_IMITD	144	/* IMITD */
1874 #undef	IPOPT_EIP
1875 #define	IPOPT_EIP	145	/* EIP */
1876 #undef	IPOPT_RTRALRT
1877 #define	IPOPT_RTRALRT	148	/* RTRALRT */
1878 #undef	IPOPT_SDB
1879 #define	IPOPT_SDB	149
1880 #undef	IPOPT_NSAPA
1881 #define	IPOPT_NSAPA	150
1882 #undef	IPOPT_DPS
1883 #define	IPOPT_DPS	151
1884 #undef	IPOPT_UMP
1885 #define	IPOPT_UMP	152
1886 #undef	IPOPT_FINN
1887 #define	IPOPT_FINN	205	/* FINN */
1888 
1889 #ifndef TCPOPT_EOL
1890 # define TCPOPT_EOL		0
1891 #endif
1892 #ifndef TCPOPT_NOP
1893 # define TCPOPT_NOP		1
1894 #endif
1895 #ifndef TCPOPT_MAXSEG
1896 # define TCPOPT_MAXSEG		2
1897 #endif
1898 #ifndef TCPOLEN_MAXSEG
1899 # define TCPOLEN_MAXSEG		4
1900 #endif
1901 #ifndef TCPOPT_WINDOW
1902 # define TCPOPT_WINDOW		3
1903 #endif
1904 #ifndef TCPOLEN_WINDOW
1905 # define TCPOLEN_WINDOW		3
1906 #endif
1907 #ifndef TCPOPT_SACK_PERMITTED
1908 # define TCPOPT_SACK_PERMITTED	4
1909 #endif
1910 #ifndef TCPOLEN_SACK_PERMITTED
1911 # define TCPOLEN_SACK_PERMITTED	2
1912 #endif
1913 #ifndef TCPOPT_SACK
1914 # define TCPOPT_SACK		5
1915 #endif
1916 #ifndef TCPOPT_TIMESTAMP
1917 # define TCPOPT_TIMESTAMP	8
1918 #endif
1919 
1920 #ifndef	ICMP_MINLEN
1921 # define	ICMP_MINLEN	8
1922 #endif
1923 #ifndef	ICMP_ECHOREPLY
1924 # define	ICMP_ECHOREPLY	0
1925 #endif
1926 #ifndef	ICMP_UNREACH
1927 # define	ICMP_UNREACH	3
1928 #endif
1929 #ifndef	ICMP_UNREACH_NET
1930 # define	ICMP_UNREACH_NET	0
1931 #endif
1932 #ifndef	ICMP_UNREACH_HOST
1933 # define	ICMP_UNREACH_HOST	1
1934 #endif
1935 #ifndef	ICMP_UNREACH_PROTOCOL
1936 # define	ICMP_UNREACH_PROTOCOL	2
1937 #endif
1938 #ifndef	ICMP_UNREACH_PORT
1939 # define	ICMP_UNREACH_PORT	3
1940 #endif
1941 #ifndef	ICMP_UNREACH_NEEDFRAG
1942 # define	ICMP_UNREACH_NEEDFRAG	4
1943 #endif
1944 #ifndef	ICMP_UNREACH_SRCFAIL
1945 # define	ICMP_UNREACH_SRCFAIL	5
1946 #endif
1947 #ifndef	ICMP_UNREACH_NET_UNKNOWN
1948 # define	ICMP_UNREACH_NET_UNKNOWN	6
1949 #endif
1950 #ifndef	ICMP_UNREACH_HOST_UNKNOWN
1951 # define	ICMP_UNREACH_HOST_UNKNOWN	7
1952 #endif
1953 #ifndef	ICMP_UNREACH_ISOLATED
1954 # define	ICMP_UNREACH_ISOLATED	8
1955 #endif
1956 #ifndef	ICMP_UNREACH_NET_PROHIB
1957 # define	ICMP_UNREACH_NET_PROHIB	9
1958 #endif
1959 #ifndef	ICMP_UNREACH_HOST_PROHIB
1960 # define	ICMP_UNREACH_HOST_PROHIB	10
1961 #endif
1962 #ifndef	ICMP_UNREACH_TOSNET
1963 # define	ICMP_UNREACH_TOSNET	11
1964 #endif
1965 #ifndef	ICMP_UNREACH_TOSHOST
1966 # define	ICMP_UNREACH_TOSHOST	12
1967 #endif
1968 #ifndef	ICMP_UNREACH_ADMIN_PROHIBIT
1969 # define	ICMP_UNREACH_ADMIN_PROHIBIT	13
1970 #endif
1971 #ifndef	ICMP_UNREACH_FILTER
1972 # define	ICMP_UNREACH_FILTER	13
1973 #endif
1974 #ifndef	ICMP_UNREACH_HOST_PRECEDENCE
1975 # define	ICMP_UNREACH_HOST_PRECEDENCE	14
1976 #endif
1977 #ifndef	ICMP_UNREACH_PRECEDENCE_CUTOFF
1978 # define	ICMP_UNREACH_PRECEDENCE_CUTOFF	15
1979 #endif
1980 #ifndef	ICMP_SOURCEQUENCH
1981 # define	ICMP_SOURCEQUENCH	4
1982 #endif
1983 #ifndef	ICMP_REDIRECT_NET
1984 # define	ICMP_REDIRECT_NET	0
1985 #endif
1986 #ifndef	ICMP_REDIRECT_HOST
1987 # define	ICMP_REDIRECT_HOST	1
1988 #endif
1989 #ifndef	ICMP_REDIRECT_TOSNET
1990 # define	ICMP_REDIRECT_TOSNET	2
1991 #endif
1992 #ifndef	ICMP_REDIRECT_TOSHOST
1993 # define	ICMP_REDIRECT_TOSHOST	3
1994 #endif
1995 #ifndef	ICMP_ALTHOSTADDR
1996 # define	ICMP_ALTHOSTADDR	6
1997 #endif
1998 #ifndef	ICMP_TIMXCEED
1999 # define	ICMP_TIMXCEED	11
2000 #endif
2001 #ifndef	ICMP_TIMXCEED_INTRANS
2002 # define	ICMP_TIMXCEED_INTRANS	0
2003 #endif
2004 #ifndef	ICMP_TIMXCEED_REASS
2005 # define		ICMP_TIMXCEED_REASS	1
2006 #endif
2007 #ifndef	ICMP_PARAMPROB
2008 # define	ICMP_PARAMPROB	12
2009 #endif
2010 #ifndef	ICMP_PARAMPROB_ERRATPTR
2011 # define	ICMP_PARAMPROB_ERRATPTR	0
2012 #endif
2013 #ifndef	ICMP_PARAMPROB_OPTABSENT
2014 # define	ICMP_PARAMPROB_OPTABSENT	1
2015 #endif
2016 #ifndef	ICMP_PARAMPROB_LENGTH
2017 # define	ICMP_PARAMPROB_LENGTH	2
2018 #endif
2019 #ifndef ICMP_TSTAMP
2020 # define	ICMP_TSTAMP	13
2021 #endif
2022 #ifndef ICMP_TSTAMPREPLY
2023 # define	ICMP_TSTAMPREPLY	14
2024 #endif
2025 #ifndef ICMP_IREQ
2026 # define	ICMP_IREQ	15
2027 #endif
2028 #ifndef ICMP_IREQREPLY
2029 # define	ICMP_IREQREPLY	16
2030 #endif
2031 #ifndef	ICMP_MASKREQ
2032 # define	ICMP_MASKREQ	17
2033 #endif
2034 #ifndef ICMP_MASKREPLY
2035 # define	ICMP_MASKREPLY	18
2036 #endif
2037 #ifndef	ICMP_TRACEROUTE
2038 # define	ICMP_TRACEROUTE	30
2039 #endif
2040 #ifndef	ICMP_DATACONVERR
2041 # define	ICMP_DATACONVERR	31
2042 #endif
2043 #ifndef	ICMP_MOBILE_REDIRECT
2044 # define	ICMP_MOBILE_REDIRECT	32
2045 #endif
2046 #ifndef	ICMP_IPV6_WHEREAREYOU
2047 # define	ICMP_IPV6_WHEREAREYOU	33
2048 #endif
2049 #ifndef	ICMP_IPV6_IAMHERE
2050 # define	ICMP_IPV6_IAMHERE	34
2051 #endif
2052 #ifndef	ICMP_MOBILE_REGREQUEST
2053 # define	ICMP_MOBILE_REGREQUEST	35
2054 #endif
2055 #ifndef	ICMP_MOBILE_REGREPLY
2056 # define	ICMP_MOBILE_REGREPLY	36
2057 #endif
2058 #ifndef	ICMP_SKIP
2059 # define	ICMP_SKIP	39
2060 #endif
2061 #ifndef	ICMP_PHOTURIS
2062 # define	ICMP_PHOTURIS	40
2063 #endif
2064 #ifndef	ICMP_PHOTURIS_UNKNOWN_INDEX
2065 # define	ICMP_PHOTURIS_UNKNOWN_INDEX	1
2066 #endif
2067 #ifndef	ICMP_PHOTURIS_AUTH_FAILED
2068 # define	ICMP_PHOTURIS_AUTH_FAILED	2
2069 #endif
2070 #ifndef	ICMP_PHOTURIS_DECRYPT_FAILED
2071 # define	ICMP_PHOTURIS_DECRYPT_FAILED	3
2072 #endif
2073 #ifndef	IPVERSION
2074 # define	IPVERSION	4
2075 #endif
2076 #ifndef	IPOPT_MINOFF
2077 # define	IPOPT_MINOFF	4
2078 #endif
2079 #ifndef	IPOPT_COPIED
2080 # define	IPOPT_COPIED(x)	((x)&0x80)
2081 #endif
2082 #ifndef	IPOPT_EOL
2083 # define	IPOPT_EOL	0
2084 #endif
2085 #ifndef	IPOPT_NOP
2086 # define	IPOPT_NOP	1
2087 #endif
2088 #ifndef	IP_MF
2089 # define	IP_MF	((u_short)0x2000)
2090 #endif
2091 #ifndef	ETHERTYPE_IP
2092 # define	ETHERTYPE_IP	((u_short)0x0800)
2093 #endif
2094 #ifndef	TH_FIN
2095 # define	TH_FIN	0x01
2096 #endif
2097 #ifndef	TH_SYN
2098 # define	TH_SYN	0x02
2099 #endif
2100 #ifndef	TH_RST
2101 # define	TH_RST	0x04
2102 #endif
2103 #ifndef	TH_PUSH
2104 # define	TH_PUSH	0x08
2105 #endif
2106 #ifndef	TH_ACK
2107 # define	TH_ACK	0x10
2108 #endif
2109 #ifndef	TH_URG
2110 # define	TH_URG	0x20
2111 #endif
2112 #undef	TH_ACKMASK
2113 #define	TH_ACKMASK	(TH_FIN|TH_SYN|TH_RST|TH_ACK)
2114 
2115 #ifndef	IPOPT_EOL
2116 # define	IPOPT_EOL	0
2117 #endif
2118 #ifndef	IPOPT_NOP
2119 # define	IPOPT_NOP	1
2120 #endif
2121 #ifndef	IPOPT_RR
2122 # define	IPOPT_RR	7
2123 #endif
2124 #ifndef	IPOPT_TS
2125 # define	IPOPT_TS	68
2126 #endif
2127 #ifndef	IPOPT_SECURITY
2128 # define	IPOPT_SECURITY	130
2129 #endif
2130 #ifndef	IPOPT_LSRR
2131 # define	IPOPT_LSRR	131
2132 #endif
2133 #ifndef	IPOPT_SATID
2134 # define	IPOPT_SATID	136
2135 #endif
2136 #ifndef	IPOPT_SSRR
2137 # define	IPOPT_SSRR	137
2138 #endif
2139 #ifndef	IPOPT_SECUR_UNCLASS
2140 # define	IPOPT_SECUR_UNCLASS	((u_short)0x0000)
2141 #endif
2142 #ifndef	IPOPT_SECUR_CONFID
2143 # define	IPOPT_SECUR_CONFID	((u_short)0xf135)
2144 #endif
2145 #ifndef	IPOPT_SECUR_EFTO
2146 # define	IPOPT_SECUR_EFTO	((u_short)0x789a)
2147 #endif
2148 #ifndef	IPOPT_SECUR_MMMM
2149 # define	IPOPT_SECUR_MMMM	((u_short)0xbc4d)
2150 #endif
2151 #ifndef	IPOPT_SECUR_RESTR
2152 # define	IPOPT_SECUR_RESTR	((u_short)0xaf13)
2153 #endif
2154 #ifndef	IPOPT_SECUR_SECRET
2155 # define	IPOPT_SECUR_SECRET	((u_short)0xd788)
2156 #endif
2157 #ifndef IPOPT_SECUR_TOPSECRET
2158 # define	IPOPT_SECUR_TOPSECRET	((u_short)0x6bc5)
2159 #endif
2160 #ifndef IPOPT_OLEN
2161 # define	IPOPT_OLEN	1
2162 #endif
2163 #ifndef	IPPROTO_HOPOPTS
2164 # define	IPPROTO_HOPOPTS	0
2165 #endif
2166 #ifndef	IPPROTO_ENCAP
2167 # define	IPPROTO_ENCAP	4
2168 #endif
2169 #ifndef	IPPROTO_IPV6
2170 # define	IPPROTO_IPV6	41
2171 #endif
2172 #ifndef	IPPROTO_ROUTING
2173 # define	IPPROTO_ROUTING	43
2174 #endif
2175 #ifndef	IPPROTO_FRAGMENT
2176 # define	IPPROTO_FRAGMENT	44
2177 #endif
2178 #ifndef	IPPROTO_GRE
2179 # define	IPPROTO_GRE	47	/* GRE encaps RFC 1701 */
2180 #endif
2181 #ifndef	IPPROTO_ESP
2182 # define	IPPROTO_ESP	50
2183 #endif
2184 #ifndef	IPPROTO_AH
2185 # define	IPPROTO_AH	51
2186 #endif
2187 #ifndef	IPPROTO_ICMPV6
2188 # define	IPPROTO_ICMPV6	58
2189 #endif
2190 #ifndef	IPPROTO_NONE
2191 # define	IPPROTO_NONE	59
2192 #endif
2193 #ifndef	IPPROTO_DSTOPTS
2194 # define	IPPROTO_DSTOPTS	60
2195 #endif
2196 #ifndef	IPPROTO_FRAGMENT
2197 # define	IPPROTO_FRAGMENT	44
2198 #endif
2199 #ifndef	ICMP_ROUTERADVERT
2200 # define	ICMP_ROUTERADVERT	9
2201 #endif
2202 #ifndef	ICMP_ROUTERSOLICIT
2203 # define	ICMP_ROUTERSOLICIT	10
2204 #endif
2205 #ifndef	ICMP6_DST_UNREACH
2206 # define	ICMP6_DST_UNREACH	1
2207 #endif
2208 #ifndef	ICMP6_PACKET_TOO_BIG
2209 # define	ICMP6_PACKET_TOO_BIG	2
2210 #endif
2211 #ifndef	ICMP6_TIME_EXCEEDED
2212 # define	ICMP6_TIME_EXCEEDED	3
2213 #endif
2214 #ifndef	ICMP6_PARAM_PROB
2215 # define	ICMP6_PARAM_PROB	4
2216 #endif
2217 
2218 #ifndef	ICMP6_ECHO_REQUEST
2219 # define	ICMP6_ECHO_REQUEST	128
2220 #endif
2221 #ifndef	ICMP6_ECHO_REPLY
2222 # define	ICMP6_ECHO_REPLY	129
2223 #endif
2224 #ifndef	ICMP6_MEMBERSHIP_QUERY
2225 # define	ICMP6_MEMBERSHIP_QUERY	130
2226 #endif
2227 #ifndef	MLD6_LISTENER_QUERY
2228 # define	MLD6_LISTENER_QUERY	130
2229 #endif
2230 #ifndef	ICMP6_MEMBERSHIP_REPORT
2231 # define	ICMP6_MEMBERSHIP_REPORT	131
2232 #endif
2233 #ifndef	MLD6_LISTENER_REPORT
2234 # define	MLD6_LISTENER_REPORT	131
2235 #endif
2236 #ifndef	ICMP6_MEMBERSHIP_REDUCTION
2237 # define	ICMP6_MEMBERSHIP_REDUCTION	132
2238 #endif
2239 #ifndef	MLD6_LISTENER_DONE
2240 # define	MLD6_LISTENER_DONE	132
2241 #endif
2242 #ifndef	ND_ROUTER_SOLICIT
2243 # define	ND_ROUTER_SOLICIT	133
2244 #endif
2245 #ifndef	ND_ROUTER_ADVERT
2246 # define	ND_ROUTER_ADVERT	134
2247 #endif
2248 #ifndef	ND_NEIGHBOR_SOLICIT
2249 # define	ND_NEIGHBOR_SOLICIT	135
2250 #endif
2251 #ifndef	ND_NEIGHBOR_ADVERT
2252 # define	ND_NEIGHBOR_ADVERT	136
2253 #endif
2254 #ifndef	ND_REDIRECT
2255 # define	ND_REDIRECT	137
2256 #endif
2257 #ifndef	ICMP6_ROUTER_RENUMBERING
2258 # define	ICMP6_ROUTER_RENUMBERING	138
2259 #endif
2260 #ifndef	ICMP6_WRUREQUEST
2261 # define	ICMP6_WRUREQUEST	139
2262 #endif
2263 #ifndef	ICMP6_WRUREPLY
2264 # define	ICMP6_WRUREPLY		140
2265 #endif
2266 #ifndef	ICMP6_FQDN_QUERY
2267 # define	ICMP6_FQDN_QUERY	139
2268 #endif
2269 #ifndef	ICMP6_FQDN_REPLY
2270 # define	ICMP6_FQDN_REPLY	140
2271 #endif
2272 #ifndef	ICMP6_NI_QUERY
2273 # define	ICMP6_NI_QUERY		139
2274 #endif
2275 #ifndef	ICMP6_NI_REPLY
2276 # define	ICMP6_NI_REPLY		140
2277 #endif
2278 #ifndef	MLD6_MTRACE_RESP
2279 # define	MLD6_MTRACE_RESP	200
2280 #endif
2281 #ifndef	MLD6_MTRACE
2282 # define	MLD6_MTRACE		201
2283 #endif
2284 #ifndef	ICMP6_HADISCOV_REQUEST
2285 # define	ICMP6_HADISCOV_REQUEST	202
2286 #endif
2287 #ifndef	ICMP6_HADISCOV_REPLY
2288 # define	ICMP6_HADISCOV_REPLY	203
2289 #endif
2290 #ifndef	ICMP6_MOBILEPREFIX_SOLICIT
2291 # define	ICMP6_MOBILEPREFIX_SOLICIT	204
2292 #endif
2293 #ifndef	ICMP6_MOBILEPREFIX_ADVERT
2294 # define	ICMP6_MOBILEPREFIX_ADVERT	205
2295 #endif
2296 #ifndef	ICMP6_MAXTYPE
2297 # define	ICMP6_MAXTYPE		205
2298 #endif
2299 
2300 #ifndef	ICMP6_DST_UNREACH_NOROUTE
2301 # define	ICMP6_DST_UNREACH_NOROUTE	0
2302 #endif
2303 #ifndef	ICMP6_DST_UNREACH_ADMIN
2304 # define	ICMP6_DST_UNREACH_ADMIN		1
2305 #endif
2306 #ifndef	ICMP6_DST_UNREACH_NOTNEIGHBOR
2307 # define	ICMP6_DST_UNREACH_NOTNEIGHBOR	2
2308 #endif
2309 #ifndef	ICMP6_DST_UNREACH_BEYONDSCOPE
2310 # define	ICMP6_DST_UNREACH_BEYONDSCOPE	2
2311 #endif
2312 #ifndef	ICMP6_DST_UNREACH_ADDR
2313 # define	ICMP6_DST_UNREACH_ADDR		3
2314 #endif
2315 #ifndef	ICMP6_DST_UNREACH_NOPORT
2316 # define	ICMP6_DST_UNREACH_NOPORT	4
2317 #endif
2318 #ifndef	ICMP6_TIME_EXCEED_TRANSIT
2319 # define	ICMP6_TIME_EXCEED_TRANSIT	0
2320 #endif
2321 #ifndef	ICMP6_TIME_EXCEED_REASSEMBLY
2322 # define	ICMP6_TIME_EXCEED_REASSEMBLY	1
2323 #endif
2324 
2325 #ifndef	ICMP6_NI_SUCCESS
2326 # define	ICMP6_NI_SUCCESS	0
2327 #endif
2328 #ifndef	ICMP6_NI_REFUSED
2329 # define	ICMP6_NI_REFUSED	1
2330 #endif
2331 #ifndef	ICMP6_NI_UNKNOWN
2332 # define	ICMP6_NI_UNKNOWN	2
2333 #endif
2334 
2335 #ifndef	ICMP6_ROUTER_RENUMBERING_COMMAND
2336 # define	ICMP6_ROUTER_RENUMBERING_COMMAND	0
2337 #endif
2338 #ifndef	ICMP6_ROUTER_RENUMBERING_RESULT
2339 # define	ICMP6_ROUTER_RENUMBERING_RESULT	1
2340 #endif
2341 #ifndef	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET
2342 # define	ICMP6_ROUTER_RENUMBERING_SEQNUM_RESET	255
2343 #endif
2344 
2345 #ifndef	ICMP6_PARAMPROB_HEADER
2346 # define	ICMP6_PARAMPROB_HEADER	0
2347 #endif
2348 #ifndef	ICMP6_PARAMPROB_NEXTHEADER
2349 # define	ICMP6_PARAMPROB_NEXTHEADER	1
2350 #endif
2351 #ifndef	ICMP6_PARAMPROB_OPTION
2352 # define	ICMP6_PARAMPROB_OPTION	2
2353 #endif
2354 
2355 #ifndef	ICMP6_NI_SUBJ_IPV6
2356 # define	ICMP6_NI_SUBJ_IPV6	0
2357 #endif
2358 #ifndef	ICMP6_NI_SUBJ_FQDN
2359 # define	ICMP6_NI_SUBJ_FQDN	1
2360 #endif
2361 #ifndef	ICMP6_NI_SUBJ_IPV4
2362 # define	ICMP6_NI_SUBJ_IPV4	2
2363 #endif
2364 
2365 /*
2366  * ECN is a new addition to TCP - RFC 2481
2367  */
2368 #ifndef TH_ECN
2369 # define	TH_ECN	0x40
2370 #endif
2371 #ifndef TH_CWR
2372 # define	TH_CWR	0x80
2373 #endif
2374 #define	TH_ECNALL	(TH_ECN|TH_CWR)
2375 
2376 /*
2377  * TCP States
2378  */
2379 #define IPF_TCPS_CLOSED		0	/* closed */
2380 #define IPF_TCPS_LISTEN		1	/* listening for connection */
2381 #define IPF_TCPS_SYN_SENT	2	/* active, have sent syn */
2382 #define IPF_TCPS_SYN_RECEIVED	3	/* have send and received syn */
2383 #define IPF_TCPS_HALF_ESTAB	4	/* for connections not fully "up" */
2384 /* states < IPF_TCPS_ESTABLISHED are those where connections not established */
2385 #define IPF_TCPS_ESTABLISHED	5	/* established */
2386 #define IPF_TCPS_CLOSE_WAIT	6	/* rcvd fin, waiting for close */
2387 /* states > IPF_TCPS_CLOSE_WAIT are those where user has closed */
2388 #define IPF_TCPS_FIN_WAIT_1	7	/* have closed, sent fin */
2389 #define IPF_TCPS_CLOSING	8	/* closed xchd FIN; await FIN ACK */
2390 #define IPF_TCPS_LAST_ACK	9	/* had fin and close; await FIN ACK */
2391 /* states > IPF_TCPS_CLOSE_WAIT && < IPF_TCPS_FIN_WAIT_2 await ACK of FIN */
2392 #define IPF_TCPS_FIN_WAIT_2	10	/* have closed, fin is acked */
2393 #define IPF_TCPS_TIME_WAIT	11	/* in 2*msl quiet wait after close */
2394 #define IPF_TCP_NSTATES		12
2395 
2396 #define	TCP_MSL			120
2397 
2398 #undef	ICMP_MAX_UNREACH
2399 #define	ICMP_MAX_UNREACH	14
2400 #undef	ICMP_MAXTYPE
2401 #define	ICMP_MAXTYPE		18
2402 
2403 #ifndef	IFNAMSIZ
2404 #define	IFNAMSIZ		16
2405 #endif
2406 
2407 #ifndef	LOG_FTP
2408 # define	LOG_FTP		(11<<3)
2409 #endif
2410 #ifndef	LOG_AUTHPRIV
2411 # define	LOG_AUTHPRIV	(10<<3)
2412 #endif
2413 #ifndef	LOG_AUDIT
2414 # define	LOG_AUDIT	(13<<3)
2415 #endif
2416 #ifndef	LOG_NTP
2417 # define	LOG_NTP		(12<<3)
2418 #endif
2419 #ifndef	LOG_SECURITY
2420 # define	LOG_SECURITY	(13<<3)
2421 #endif
2422 #ifndef	LOG_LFMT
2423 # define	LOG_LFMT	(14<<3)
2424 #endif
2425 #ifndef	LOG_CONSOLE
2426 # define	LOG_CONSOLE	(14<<3)
2427 #endif
2428 
2429 /*
2430  * ICMP error replies have an IP header (20 bytes), 8 bytes of ICMP data,
2431  * another IP header and then 64 bits of data, totalling 56.  Of course,
2432  * the last 64 bits is dependent on that being available.
2433  */
2434 #define	ICMPERR_ICMPHLEN	8
2435 #define	ICMPERR_IPICMPHLEN	(20 + 8)
2436 #define	ICMPERR_MINPKTLEN	(20 + 8 + 20)
2437 #define	ICMPERR_MAXPKTLEN	(20 + 8 + 20 + 8)
2438 #define ICMP6ERR_MINPKTLEN	(40 + 8)
2439 #define ICMP6ERR_IPICMPHLEN	(40 + 8 + 40)
2440 
2441 #ifndef MIN
2442 # define	MIN(a,b)	(((a)<(b))?(a):(b))
2443 #endif
2444 
2445 #ifdef IPF_DEBUG
2446 # define	DPRINT(x)	printf x
2447 #else
2448 # define	DPRINT(x)
2449 #endif
2450 
2451 #ifdef RESCUE
2452 # undef IPFILTER_BPF
2453 #endif
2454 
2455 #endif	/* __IP_COMPAT_H__ */
2456