17c478bdstevel@tonic-gate/*
2ab25eebyz * Copyright (C) 1993-2001, 2003 by Darren Reed.
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing.
57c478bdstevel@tonic-gate *
6ab25eebyz * @(#)ip_compat.h	1.8 1/14/96
7ab25eebyz * $Id: ip_compat.h,v 2.142.2.30 2005/08/11 15:13:49 darrenr Exp $
8ab25eebyz *
972680cfDarren Reed * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
107c478bdstevel@tonic-gate * Use is subject to license terms.
117c478bdstevel@tonic-gate */
127c478bdstevel@tonic-gate
137c478bdstevel@tonic-gate#ifndef	__IP_COMPAT_H__
147c478bdstevel@tonic-gate#define	__IP_COMPAT_H__
157c478bdstevel@tonic-gate
167c478bdstevel@tonic-gate#ifndef	__P
177c478bdstevel@tonic-gate# ifdef	__STDC__
187c478bdstevel@tonic-gate#  define	__P(x)  x
197c478bdstevel@tonic-gate# else
207c478bdstevel@tonic-gate#  define	__P(x)  ()
217c478bdstevel@tonic-gate# endif
227c478bdstevel@tonic-gate#endif
237c478bdstevel@tonic-gate#ifndef	__STDC__
247c478bdstevel@tonic-gate# undef		const
257c478bdstevel@tonic-gate# define	const
267c478bdstevel@tonic-gate#endif
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate#if defined(_KERNEL) || defined(KERNEL) || defined(__KERNEL__)
297c478bdstevel@tonic-gate# undef	KERNEL
307c478bdstevel@tonic-gate# undef	_KERNEL
31ae7a42bToomas Soome# undef		__KERNEL__
327c478bdstevel@tonic-gate# define	KERNEL
337c478bdstevel@tonic-gate# define	_KERNEL
34ae7a42bToomas Soome# define	__KERNEL__
357c478bdstevel@tonic-gate#endif
367c478bdstevel@tonic-gate
37ae7a42bToomas Soome#ifdef	SOLARIS
38ae7a42bToomas Soome#undef	SOLARIS
39ae7a42bToomas Soome#endif
40ae7a42bToomas Soome#if (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
41ae7a42bToomas Soome#define	SOLARIS	(1)
42ae7a42bToomas Soome#else
43ae7a42bToomas Soome#define	SOLARIS	(0)
447c478bdstevel@tonic-gate#endif
45ab25eebyz#if SOLARIS2 >= 8
467c478bdstevel@tonic-gate# ifndef	USE_INET6
477c478bdstevel@tonic-gate#  define	USE_INET6
487c478bdstevel@tonic-gate# endif
497c478bdstevel@tonic-gate#endif
507c478bdstevel@tonic-gate#if defined(__FreeBSD_version) && (__FreeBSD_version >= 400000) && \
51ab25eebyz    !defined(_KERNEL) && !defined(USE_INET6) && !defined(NOINET6)
527c478bdstevel@tonic-gate# define	USE_INET6
537c478bdstevel@tonic-gate#endif
547c478bdstevel@tonic-gate#if defined(__NetBSD_Version__) && (__NetBSD_Version__ >= 105000000) && \
55ab25eebyz    !defined(_KERNEL) && !defined(USE_INET6)
567c478bdstevel@tonic-gate# define	USE_INET6
57ab25eebyz# define	IPFILTER_M_IPFILTER
587c478bdstevel@tonic-gate#endif
59ab25eebyz#if defined(OpenBSD) && (OpenBSD >= 200206) && \
60ab25eebyz    !defined(_KERNEL) && !defined(USE_INET6)
617c478bdstevel@tonic-gate# define	USE_INET6
627c478bdstevel@tonic-gate#endif
637c478bdstevel@tonic-gate#if defined(__osf__)
647c478bdstevel@tonic-gate# define	USE_INET6
657c478bdstevel@tonic-gate#endif
66ab25eebyz#if defined(linux) && (!defined(_KERNEL) || defined(CONFIG_IPV6))
67ab25eebyz# define	USE_INET6
68ab25eebyz#endif
69ab25eebyz#if defined(HPUXREV) && (HPUXREV >= 1111)
70ab25eebyz# define	USE_INET6
71ab25eebyz#endif
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gate#if defined(BSD) && (BSD < 199103) && defined(__osf__)
747c478bdstevel@tonic-gate# undef BSD
757c478bdstevel@tonic-gate# define BSD 199103
767c478bdstevel@tonic-gate#endif
777c478bdstevel@tonic-gate
787c478bdstevel@tonic-gate#if defined(__SVR4) || defined(__svr4__) || defined(__sgi)
797c478bdstevel@tonic-gate# define index   strchr
807c478bdstevel@tonic-gate# if !defined(_KERNEL)
817c478bdstevel@tonic-gate#  define	bzero(a,b)	memset(a,0,b)
827c478bdstevel@tonic-gate#  define	bcmp		memcmp
837c478bdstevel@tonic-gate#  define	bcopy(a,b,c)	memmove(b,a,c)
847c478bdstevel@tonic-gate# endif
857c478bdstevel@tonic-gate#endif
867c478bdstevel@tonic-gate
877c478bdstevel@tonic-gate#ifndef LIFNAMSIZ
887c478bdstevel@tonic-gate# ifdef IF_NAMESIZE
897c478bdstevel@tonic-gate#  define	LIFNAMSIZ	IF_NAMESIZE
907c478bdstevel@tonic-gate# else
917c478bdstevel@tonic-gate#  ifdef	IFNAMSIZ
927c478bdstevel@tonic-gate#   define	LIFNAMSIZ	IFNAMSIZ
937c478bdstevel@tonic-gate#  else
947c478bdstevel@tonic-gate#   define	LIFNAMSIZ	16
957c478bdstevel@tonic-gate#  endif
967c478bdstevel@tonic-gate# endif
977c478bdstevel@tonic-gate#endif
987c478bdstevel@tonic-gate
997c478bdstevel@tonic-gate#if defined(__sgi) || defined(bsdi) || defined(__hpux) || defined(hpux)
1007c478bdstevel@tonic-gatestruct  ether_addr {
1017c478bdstevel@tonic-gate        u_char  ether_addr_octet[6];
1027c478bdstevel@tonic-gate};
1037c478bdstevel@tonic-gate#endif
1047c478bdstevel@tonic-gate
1057c478bdstevel@tonic-gate#if defined(__sgi) && !defined(IPFILTER_LKM)
1067c478bdstevel@tonic-gate# ifdef __STDC__
1077c478bdstevel@tonic-gate#  define IPL_EXTERN(ep) ipfilter##ep
1087c478bdstevel@tonic-gate# else
1097c478bdstevel@tonic-gate#  define IPL_EXTERN(ep) ipfilter/**/ep
1107c478bdstevel@tonic-gate# endif
1117c478bdstevel@tonic-gate#else
1127c478bdstevel@tonic-gate# ifdef __STDC__
1137c478bdstevel@tonic-gate#  define IPL_EXTERN(ep) ipl##ep
1147c478bdstevel@tonic-gate# else
1157c478bdstevel@tonic-gate#  define IPL_EXTERN(ep) ipl/**/ep
1167c478bdstevel@tonic-gate# endif
1177c478bdstevel@tonic-gate#endif
1187c478bdstevel@tonic-gate
1197c478bdstevel@tonic-gate/*
1207c478bdstevel@tonic-gate * This is a workaround for <sys/uio.h> troubles on FreeBSD and OpenBSD.
1217c478bdstevel@tonic-gate */
122ab25eebyz#ifndef linux
123ab25eebyz# ifndef _KERNEL
124ab25eebyz#  define ADD_KERNEL
125ab25eebyz#  define _KERNEL
126ab25eebyz#  define KERNEL
127ab25eebyz# endif
128ab25eebyz# ifdef __OpenBSD__
1297c478bdstevel@tonic-gatestruct file;
130ab25eebyz# endif
131ab25eebyz# include <sys/uio.h>
132ab25eebyz# ifdef ADD_KERNEL
133ab25eebyz#  undef _KERNEL
134ab25eebyz#  undef KERNEL
135ab25eebyz# endif
1367c478bdstevel@tonic-gate#endif
1377c478bdstevel@tonic-gate
1387c478bdstevel@tonic-gate
1397c478bdstevel@tonic-gate/* ----------------------------------------------------------------------- */
1407c478bdstevel@tonic-gate/*                                  S O L A R I S                          */
1417c478bdstevel@tonic-gate/* ----------------------------------------------------------------------- */
142af5f29dToomas Soome#ifdef SOLARIS
1437c478bdstevel@tonic-gate# define	MENTAT	1
1447c478bdstevel@tonic-gate# include	<sys/cmn_err.h>
1457c478bdstevel@tonic-gate# include	<sys/isa_defs.h>
1467c478bdstevel@tonic-gate# include	<sys/stream.h>
1477c478bdstevel@tonic-gate# include	<sys/ioccom.h>
1487c478bdstevel@tonic-gate# include	<sys/sysmacros.h>
1497c478bdstevel@tonic-gate# include	<sys/kmem.h>
1507c478bdstevel@tonic-gate# if SOLARIS2 >= 10
1517c478bdstevel@tonic-gate#  include	<sys/procset.h>
1527c478bdstevel@tonic-gate#  include	<sys/proc.h>
1537c478bdstevel@tonic-gate#  include	<sys/devops.h>
1547c478bdstevel@tonic-gate#  include	<sys/ddi_impldefs.h>
155f4b3ec6dh#  include	<sys/neti.h>
1567c478bdstevel@tonic-gate# endif
157c793af9sangeeta
158c793af9sangeeta/*
159c793af9sangeeta * inet/ip.h would end up including radix.h with _KERNEL, which is not
160c793af9sangeeta * what the tools intend, so include radix.h first.
161c793af9sangeeta */
162c793af9sangeeta#if SOLARIS2 > 10
163c793af9sangeeta# include <net/radix.h>
164c793af9sangeeta#endif
1657c478bdstevel@tonic-gate/*
1667c478bdstevel@tonic-gate * because Solaris 2 defines these in two places :-/
1677c478bdstevel@tonic-gate */
1687c478bdstevel@tonic-gate# ifndef	KERNEL
169f4b3ec6dh#  define	ADD_KERNEL
1707c478bdstevel@tonic-gate#  define	_KERNEL
1717c478bdstevel@tonic-gate#  undef	RES_INIT
1727c478bdstevel@tonic-gate# endif /* _KERNEL */
1737c478bdstevel@tonic-gate
1747c478bdstevel@tonic-gate# if SOLARIS2 >= 8
1757c478bdstevel@tonic-gate#  include <netinet/ip6.h>
1767c478bdstevel@tonic-gate#  include <netinet/icmp6.h>
1777c478bdstevel@tonic-gate# endif
1787c478bdstevel@tonic-gate
1797c478bdstevel@tonic-gate# include <inet/common.h>
1807c478bdstevel@tonic-gate/* These 5 are defined in <inet/ip.h> and <netinet/ip.h> */
1817c478bdstevel@tonic-gate# undef	IPOPT_EOL
1827c478bdstevel@tonic-gate# undef	IPOPT_NOP
1837c478bdstevel@tonic-gate# undef	IPOPT_LSRR
1847c478bdstevel@tonic-gate# undef	IPOPT_RR
1857c478bdstevel@tonic-gate# undef	IPOPT_SSRR
186ab25eebyz# ifdef i386
187ab25eebyz#  define _SYS_PROMIF_H
188ab25eebyz# endif
189f4b3ec6dh# ifdef ADD_KERNEL
190f4b3ec6dh#  undef _KERNEL
191f4b3ec6dh# endif
1927c478bdstevel@tonic-gate# include <inet/ip.h>
1937c478bdstevel@tonic-gate# undef COPYOUT
1947c478bdstevel@tonic-gate# include <inet/ip_ire.h>
1957c478bdstevel@tonic-gate# ifndef	KERNEL
1967c478bdstevel@tonic-gate#  undef	_KERNEL
1977c478bdstevel@tonic-gate# endif
1987c478bdstevel@tonic-gate# if SOLARIS2 >= 8
199ab25eebyz#  define SNPRINTF	snprintf
200ab25eebyz
2017c478bdstevel@tonic-gate#  include <inet/ip_if.h>
2027c478bdstevel@tonic-gate#  define	ipif_local_addr	ipif_lcl_addr
2037c478bdstevel@tonic-gate/* Only defined in private include file */
2047c478bdstevel@tonic-gate#  ifndef	V4_PART_OF_V6
2057c478bdstevel@tonic-gate#   define	V4_PART_OF_V6(v6)	v6.s6_addr32[3]
2067c478bdstevel@tonic-gate#  endif
2077c478bdstevel@tonic-gatestruct ip6_ext {
2087c478bdstevel@tonic-gate	u_char	ip6e_nxt;
2097c478bdstevel@tonic-gate	u_char	ip6e_len;
2107c478bdstevel@tonic-gate};
2117c478bdstevel@tonic-gate# endif /* SOLARIS2 >= 8 */
2127c478bdstevel@tonic-gate
213381a2a9dr# ifdef FW_HOOKS
214381a2a9dr
215381a2a9dr#  define	SOLARIS_PFHOOKS	1
216381a2a9dr
217381a2a9drtypedef	struct	qpktinfo	{
218381a2a9dr	/* data that changes per-packet */
219381a2a9dr	void		*qpi_ill;	/* COPIED */
220381a2a9dr	mblk_t		*qpi_m;
221381a2a9dr	void		*qpi_data;	/* where layer 3 header starts */
222381a2a9dr	size_t		qpi_off;
2231b47e08dr	int		qpi_flags;	/* Uses FI_* flags */
224381a2a9dr} qpktinfo_t;
225381a2a9dr
226381a2a9drextern void mb_copydata __P((mblk_t *, size_t , size_t, char *));
227381a2a9drextern void mb_copyback __P((mblk_t *, size_t , size_t, char *));
228381a2a9dr# endif
229381a2a9dr
2307c478bdstevel@tonic-gate# if SOLARIS2 >= 6
2317c478bdstevel@tonic-gate#  include <sys/atomic.h>
2327c478bdstevel@tonic-gatetypedef	uint32_t	u_32_t;
2337c478bdstevel@tonic-gate# else
2347c478bdstevel@tonic-gatetypedef unsigned int	u_32_t;
2357c478bdstevel@tonic-gate# endif
2367c478bdstevel@tonic-gate# define	U_32_T	1
2377c478bdstevel@tonic-gate
2387c478bdstevel@tonic-gate# ifdef _KERNEL
2397c478bdstevel@tonic-gate#  define	KRWLOCK_T		krwlock_t
2407c478bdstevel@tonic-gate#  define	KMUTEX_T		kmutex_t
24140cdc2eAlexandr Nedvedicky#  if SOLARIS2 >= 10
24240cdc2eAlexandr Nedvedicky#   include <sys/sdt.h>
243a117327Alexandr Nedvedicky
244a117327Alexandr Nedvedicky#   define IPF_IS_LOOPBACK(f)	((f) & FI_NOCKSUM)
24540cdc2eAlexandr Nedvedicky#  endif /* SOLARIS2 >= 10 */
2467c478bdstevel@tonic-gate#  if SOLARIS2 >= 6
2477c478bdstevel@tonic-gate#   if SOLARIS2 == 6
2481a5e258Josef 'Jeff' Sipek#    define	ATOMIC_INCL(x)		atomic_inc_ulong((uint32_t *)&(x))
2491a5e258Josef 'Jeff' Sipek#    define	ATOMIC_DECL(x)		atomic_dec_ulong((uint32_t *)&(x))
2507c478bdstevel@tonic-gate#   else
2511a5e258Josef 'Jeff' Sipek#    define	ATOMIC_INCL(x)		atomic_inc_ulong(&(x))
2521a5e258Josef 'Jeff' Sipek#    define	ATOMIC_DECL(x)		atomic_dec_ulong(&(x))
2537c478bdstevel@tonic-gate#   endif /* SOLARIS2 == 6 */
2541a5e258Josef 'Jeff' Sipek#   define	ATOMIC_INC64(x)		atomic_inc_64((uint64_t *)&(x))
2551a5e258Josef 'Jeff' Sipek#   define	ATOMIC_INC32(x)		atomic_inc_32((uint32_t *)&(x))
2561a5e258Josef 'Jeff' Sipek#   define	ATOMIC_INC16(x)		atomic_inc_16((uint16_t *)&(x))
2571a5e258Josef 'Jeff' Sipek#   define	ATOMIC_DEC64(x)		atomic_dec_64((uint64_t *)&(x))
2581a5e258Josef 'Jeff' Sipek#   define	ATOMIC_DEC32(x)		atomic_dec_32((uint32_t *)&(x))
2591a5e258Josef 'Jeff' Sipek#   define	ATOMIC_DEC16(x)		atomic_dec_16((uint16_t *)&(x))
2607c478bdstevel@tonic-gate#  else
2617c478bdstevel@tonic-gate#   define	ATOMIC_INC(x)		{ mutex_enter(&ipf_rw); (x)++; \
2627c478bdstevel@tonic-gate					  mutex_exit(&ipf_rw); }
2637c478bdstevel@tonic-gate#   define	ATOMIC_DEC(x)		{ mutex_enter(&ipf_rw); (x)--; \
2647c478bdstevel@tonic-gate					  mutex_exit(&ipf_rw); }
2657c478bdstevel@tonic-gate#  endif /* SOLARIS2 >= 6 */
2667c478bdstevel@tonic-gate#  define	USE_MUTEXES
2677c478bdstevel@tonic-gate#  define	MUTEX_ENTER(x)		mutex_enter(&(x)->ipf_lk)
2687c478bdstevel@tonic-gate#  define	READ_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_READER)
2697c478bdstevel@tonic-gate#  define	WRITE_ENTER(x)		rw_enter(&(x)->ipf_lk, RW_WRITER)
2707c478bdstevel@tonic-gate#  define	MUTEX_DOWNGRADE(x)	rw_downgrade(&(x)->ipf_lk)
2717c478bdstevel@tonic-gate#  define	RWLOCK_INIT(x, y)	rw_init(&(x)->ipf_lk, (y),  \
2727c478bdstevel@tonic-gate						RW_DRIVER, NULL)
2737c478bdstevel@tonic-gate#  define	RWLOCK_EXIT(x)		rw_exit(&(x)->ipf_lk)
2747c478bdstevel@tonic-gate#  define	RW_DESTROY(x)		rw_destroy(&(x)->ipf_lk)
2757c478bdstevel@tonic-gate#  define	MUTEX_INIT(x, y)	mutex_init(&(x)->ipf_lk, (y), \
2767c478bdstevel@tonic-gate						   MUTEX_DRIVER, NULL)
2777c478bdstevel@tonic-gate#  define	MUTEX_DESTROY(x)	mutex_destroy(&(x)->ipf_lk)
2787c478bdstevel@tonic-gate#  define	MUTEX_NUKE(x)		bzero((x), sizeof(*(x)))
2797c478bdstevel@tonic-gate#  define	MUTEX_EXIT(x)		mutex_exit(&(x)->ipf_lk)
2807c478bdstevel@tonic-gate#  define	COPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
2817c478bdstevel@tonic-gate#  define	COPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
282bb1d9deJohn Ojemann#  define	BCOPYIN(a,b,c)	copyin((caddr_t)(a), (caddr_t)(b), (c))
283bb1d9deJohn Ojemann#  define	BCOPYOUT(a,b,c)	copyout((caddr_t)(a), (caddr_t)(b), (c))
2847c478bdstevel@tonic-gate#  define	UIOMOVE(a,b,c,d)	uiomove((caddr_t)a,b,c,d)
2857c478bdstevel@tonic-gate#  define	KFREE(x)	kmem_free((char *)(x), sizeof(*(x)))
2867c478bdstevel@tonic-gate#  define	KFREES(x,s)	kmem_free((char *)(x), (s))
2877c478bdstevel@tonic-gate#  define	SPL_NET(x)	;
2887c478bdstevel@tonic-gate#  define	SPL_IMP(x)	;
2897c478bdstevel@tonic-gate#  undef	SPL_X
2907c478bdstevel@tonic-gate#  define	SPL_X(x)	;
2917c478bdstevel@tonic-gate#  ifdef sparc
2927c478bdstevel@tonic-gate#   define	ntohs(x)	(x)
2937c478bdstevel@tonic-gate#   define	ntohl(x)	(x)
2947c478bdstevel@tonic-gate#   define	htons(x)	(x)
2957c478bdstevel@tonic-gate#   define	htonl(x)	(x)
2967c478bdstevel@tonic-gate#  endif /* sparc */
2977c478bdstevel@tonic-gate#  define	KMALLOC(a,b)	(a) = (b)kmem_alloc(sizeof(*(a)), KM_NOSLEEP)
2987c478bdstevel@tonic-gate#  define	KMALLOCS(a,b,c)	(a) = (b)kmem_alloc((c), KM_NOSLEEP)
2997c478bdstevel@tonic-gate#  define	GET_MINOR(x)	getminor(x)
300f4b3ec6dh/*extern	phy_if_t	get_unit __P((char *, int, ipf_stack_t *));*/
301f4b3ec6dh#  define	GETIFP(n, v, ifs)	(void *)get_unit(n, v, ifs)
302381a2a9dr#  define	IFNAME(x)	((ill_t *)x)->ill_name
303381a2a9dr#  define	COPYIFNAME(x, b, v)	(void) net_getifname(((v) == 4) ? \
304f4b3ec6dh					ifs->ifs_ipf_ipv4 : ifs->ifs_ipf_ipv6,\
305f4b3ec6dh					(phy_if_t)(x), (b), sizeof(b))
3067c478bdstevel@tonic-gate#  define	GETKTIME(x)	uniqtime((struct timeval *)x)
3077c478bdstevel@tonic-gate#  define	MSGDSIZE(x)	msgdsize(x)
3087c478bdstevel@tonic-gate#  define	M_LEN(x)	((x)->b_wptr - (x)->b_rptr)
309201a9dcAlexandr Nedvedicky#  define	M_DUPLICATE(x)	copymsg((x))
310ab25eebyz#  define	MTOD(m,t)	((t)((m)->b_rptr))
3117c478bdstevel@tonic-gate#  define	MTYPE(m)	((m)->b_datap->db_type)
3127c478bdstevel@tonic-gate#  define	FREE_MB_T(m)	freemsg(m)
313ab25eebyz#  define	m_next		b_cont
314381a2a9dr#  define	CACHE_HASH(x)	(((phy_if_t)(x)->fin_ifp) & 7)
3157c478bdstevel@tonic-gate#  define	IPF_PANIC(x,y)	if (x) { printf y; cmn_err(CE_PANIC, "ipf_panic"); }
3167c478bdstevel@tonic-gatetypedef mblk_t mb_t;
3177c478bdstevel@tonic-gate# endif /* _KERNEL */
3187c478bdstevel@tonic-gate
3197c478bdstevel@tonic-gate# if (SOLARIS2 >= 7)
3207c478bdstevel@tonic-gate#  ifdef lint
3217c478bdstevel@tonic-gate#   define ALIGN32(ptr)    (ptr ? 0L : 0L)
3227c478bdstevel@tonic-gate#   define ALIGN16(ptr)    (ptr ? 0L : 0L)
3237c478bdstevel@tonic-gate#  else
3247c478bdstevel@tonic-gate#   define ALIGN32(ptr)    (ptr)
3257c478bdstevel@tonic-gate#   define ALIGN16(ptr)    (ptr)
3267c478bdstevel@tonic-gate#  endif
3277c478bdstevel@tonic-gate# endif
3287c478bdstevel@tonic-gate
329ab25eebyz# if SOLARIS2 < 6
330ab25eebyztypedef	struct uio	uio_t;
331ab25eebyz# endif
332ab25eebyztypedef	int		ioctlcmd_t;
333ab073b3drtypedef	uint8_t		u_int8_t;
3347c478bdstevel@tonic-gate
3357c478bdstevel@tonic-gate# define OS_RECOGNISED 1
3367c478bdstevel@tonic-gate
3377c478bdstevel@tonic-gate#endif /* SOLARIS */
3387c478bdstevel@tonic-gate
3397c478bdstevel@tonic-gate/* ----------------------------------------------------------------------- */
3407c478bdstevel@tonic-gate/*                                  H P U X                                */
3417c478bdstevel@tonic-gate/* ----------------------------------------------------------------------- */
3427c478bdstevel@tonic-gate#ifdef __hpux
3437c478bdstevel@tonic-gate# define	MENTAT	1
3447c478bdstevel@tonic-gate# include	<sys/sysmacros.h>
3457c478bdstevel@tonic-gate# include	<sys/spinlock.h>
3467c478bdstevel@tonic-gate# include	<sys/lock.h>
3477c478bdstevel@tonic-gate# include	<sys/stream.h>
348ab25eebyz# ifdef USE_INET6
349ab25eebyz#  include	<netinet/if_ether.h>
350ab25eebyz#  include	<netinet/ip6.h>
351ab25eebyz#  include	<netinet/icmp6.h>
352ab25eebyztypedef	struct	ip6_hdr	ip6_t;
353ab25eebyz# endif
3547c478bdstevel@tonic-gate
3557c478bdstevel@tonic-gate# ifdef _KERNEL
356ab25eebyz#  define SNPRINTF	sprintf
357ab25eebyz#  if (HPUXREV >= 1111)
358ab25eebyz#   define	IPL_SELECT
359ab25eebyz#   ifdef	IPL_SELECT
360ab25eebyz#    include	<machine/sys/user.h>
361ab25eebyz#    include	<sys/kthread_iface.h>
362ab25eebyz#    define	READ_COLLISION	0x01
363ab25eebyz
364ab25eebyztypedef	struct	iplog_select_s {
365ab25eebyz	kthread_t	*read_waiter;
366ab25eebyz	int		state;
367ab25eebyz} iplog_select_t;
368ab25eebyz#   endif
369ab25eebyz#  endif
3707c478bdstevel@tonic-gate
3717c478bdstevel@tonic-gate#  define	GETKTIME(x)	uniqtime((struct timeval *)x)
3727c478bdstevel@tonic-gate
3737c478bdstevel@tonic-gate#  if HPUXREV == 1111
3747c478bdstevel@tonic-gate#   include	"kern_svcs.h"
3757c478bdstevel@tonic-gate#  else
3767c478bdstevel@tonic-gate#   include	<sys/kern_svcs.h>
3777c478bdstevel@tonic-gate#  endif
3787c478bdstevel@tonic-gate#  undef	ti_flags
3797c478bdstevel@tonic-gate#  undef	TCP_NODELAY
3807c478bdstevel@tonic-gate#  undef	TCP_MAXSEG
3817c478bdstevel@tonic-gate#  include <sys/reg.h>
3827c478bdstevel@tonic-gate#  include "../netinet/ip_info.h"
3837c478bdstevel@tonic-gate/*
3847c478bdstevel@tonic-gate * According to /usr/include/sys/spinlock.h on HP-UX 11.00, these functions
3857c478bdstevel@tonic-gate * are available.  Attempting to use them actually results in unresolved
3867c478bdstevel@tonic-gate * symbols when it comes time to load the module.
387ab25eebyz * This has been fixed!  Yipee!
3887c478bdstevel@tonic-gate */
389ab25eebyz#  if 1
3907c478bdstevel@tonic-gate#   ifdef __LP64__
391ab25eebyz#    define	ATOMIC_INCL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
392ab25eebyz#    define	ATOMIC_DECL(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
3937c478bdstevel@tonic-gate#   else
394ab25eebyz#    define	ATOMIC_INCL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
395ab25eebyz#    define	ATOMIC_DECL(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
3967c478bdstevel@tonic-gate#   endif
397ab25eebyz#   define	ATOMIC_INC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), 1)
398ab25eebyz#   define	ATOMIC_INC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), 1)
399ab25eebyz#   define	ATOMIC_INC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), 1)
400ab25eebyz#   define	ATOMIC_DEC64(x)		lock_and_incr_int64(&ipf_rw.ipf_lk, &(x), -1)
401ab25eebyz#   define	ATOMIC_DEC32(x)		lock_and_incr_int32(&ipf_rw.ipf_lk, &(x), -1)
402ab25eebyz#   define	ATOMIC_DEC16(x)		lock_and_incr_int16(&ipf_rw.ipf_lk, &(x), -1)
4037c478bdstevel@tonic-gate#  else /* 0 */
404ab25eebyz#   define	ATOMIC_INC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
405ab25eebyz					  MUTEX_EXIT(&ipf_rw); }
406ab25eebyz#   define	ATOMIC_DEC64(x)		{ MUTEX_ENTER(&ipf_rw); (x)--; \
407ab25eebyz					  MUTEX_EXIT(&ipf_rw); }
408ab25eebyz#   define	ATOMIC_INC32(x)		{ MUTEX_ENTER(&ipf_rw); (x)++; \
409