Home | History | Annotate | Line # | Download | only in netinet
ip_fil.h revision 1.3
      1 /*	$NetBSD: ip_fil.h,v 1.3 2012/07/22 14:27:51 darrenr Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 2012 by Darren Reed.
      5  *
      6  * See the IPFILTER.LICENCE file for details on licencing.
      7  *
      8  * @(#)ip_fil.h	1.35 6/5/96
      9  * Id: ip_fil.h,v 1.1.1.2 2012/07/22 13:45:13 darrenr Exp
     10  */
     11 
     12 #ifndef _NETINET_IP_FIL_H_
     13 #define _NETINET_IP_FIL_H_
     14 
     15 #include "netinet/ip_compat.h"
     16 #include "netinet/ipf_rb.h"
     17 #if NETBSD_GE_REV(104040000)
     18 # include <sys/callout.h>
     19 #endif
     20 #if defined(BSD) && defined(_KERNEL)
     21 # if NETBSD_LT_REV(399000000) || defined(__osf__) || FREEBSD_LT_REV(500043)
     22 #  include <sys/select.h>
     23 # else
     24 #  include <sys/selinfo.h>
     25 # endif
     26 #endif
     27 
     28 #if !defined(linux) || !defined(_KERNEL)
     29 # include <netinet/in.h>
     30 #endif
     31 
     32 #ifndef	SOLARIS
     33 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
     34 #endif
     35 
     36 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
     37 # define	SIOCADAFR	_IOW('r', 60, struct ipfobj)
     38 # define	SIOCRMAFR	_IOW('r', 61, struct ipfobj)
     39 # define	SIOCSETFF	_IOW('r', 62, u_int)
     40 # define	SIOCGETFF	_IOR('r', 63, u_int)
     41 # define	SIOCGETFS	_IOWR('r', 64, struct ipfobj)
     42 # define	SIOCIPFFL	_IOWR('r', 65, int)
     43 # define	SIOCIPFFB	_IOR('r', 66, int)
     44 # define	SIOCADIFR	_IOW('r', 67, struct ipfobj)
     45 # define	SIOCRMIFR	_IOW('r', 68, struct ipfobj)
     46 # define	SIOCSWAPA	_IOR('r', 69, u_int)
     47 # define	SIOCINAFR	_IOW('r', 70, struct ipfobj)
     48 # define	SIOCINIFR	_IOW('r', 71, struct ipfobj)
     49 # define	SIOCFRENB	_IOW('r', 72, u_int)
     50 # define	SIOCFRSYN	_IOW('r', 73, u_int)
     51 # define	SIOCFRZST	_IOWR('r', 74, struct ipfobj)
     52 # define	SIOCZRLST	_IOWR('r', 75, struct ipfobj)
     53 # define	SIOCAUTHW	_IOWR('r', 76, struct ipfobj)
     54 # define	SIOCAUTHR	_IOWR('r', 77, struct ipfobj)
     55 # define	SIOCSTAT1	_IOWR('r', 78, struct ipfobj)
     56 # define	SIOCSTLCK	_IOWR('r', 79, u_int)
     57 # define	SIOCSTPUT	_IOWR('r', 80, struct ipfobj)
     58 # define	SIOCSTGET	_IOWR('r', 81, struct ipfobj)
     59 # define	SIOCSTGSZ	_IOWR('r', 82, struct ipfobj)
     60 # define	SIOCSTAT2	_IOWR('r', 83, struct ipfobj)
     61 # define	SIOCSETLG	_IOWR('r', 84, int)
     62 # define	SIOCGETLG	_IOWR('r', 85, int)
     63 # define	SIOCFUNCL	_IOWR('r', 86, struct ipfunc_resolve)
     64 # define	SIOCIPFGETNEXT	_IOWR('r', 87, struct ipfobj)
     65 # define	SIOCIPFGET	_IOWR('r', 88, struct ipfobj)
     66 # define	SIOCIPFSET	_IOWR('r', 89, struct ipfobj)
     67 # define	SIOCIPFL6	_IOWR('r', 90, int)
     68 # define	SIOCIPFITER	_IOWR('r', 91, struct ipfobj)
     69 # define	SIOCGENITER	_IOWR('r', 92, struct ipfobj)
     70 # define	SIOCGTABL	_IOWR('r', 93, struct ipfobj)
     71 # define	SIOCIPFDELTOK	_IOWR('r', 94, int)
     72 # define	SIOCLOOKUPITER	_IOWR('r', 95, struct ipfobj)
     73 # define	SIOCGTQTAB	_IOWR('r', 96, struct ipfobj)
     74 # define	SIOCMATCHFLUSH	_IOWR('r', 97, struct ipfobj)
     75 # define	SIOCIPFINTERROR	_IOR('r', 98, int)
     76 #else
     77 # define	SIOCADAFR	_IOW(r, 60, struct ipfobj)
     78 # define	SIOCRMAFR	_IOW(r, 61, struct ipfobj)
     79 # define	SIOCSETFF	_IOW(r, 62, u_int)
     80 # define	SIOCGETFF	_IOR(r, 63, u_int)
     81 # define	SIOCGETFS	_IOWR(r, 64, struct ipfobj)
     82 # define	SIOCIPFFL	_IOWR(r, 65, int)
     83 # define	SIOCIPFFB	_IOR(r, 66, int)
     84 # define	SIOCADIFR	_IOW(r, 67, struct ipfobj)
     85 # define	SIOCRMIFR	_IOW(r, 68, struct ipfobj)
     86 # define	SIOCSWAPA	_IOR(r, 69, u_int)
     87 # define	SIOCINAFR	_IOW(r, 70, struct ipfobj)
     88 # define	SIOCINIFR	_IOW(r, 71, struct ipfobj)
     89 # define	SIOCFRENB	_IOW(r, 72, u_int)
     90 # define	SIOCFRSYN	_IOW(r, 73, u_int)
     91 # define	SIOCFRZST	_IOWR(r, 74, struct ipfobj)
     92 # define	SIOCZRLST	_IOWR(r, 75, struct ipfobj)
     93 # define	SIOCAUTHW	_IOWR(r, 76, struct ipfobj)
     94 # define	SIOCAUTHR	_IOWR(r, 77, struct ipfobj)
     95 # define	SIOCSTAT1	_IOWR(r, 78, struct ipfobj)
     96 # define	SIOCSTLCK	_IOWR(r, 79, u_int)
     97 # define	SIOCSTPUT	_IOWR(r, 80, struct ipfobj)
     98 # define	SIOCSTGET	_IOWR(r, 81, struct ipfobj)
     99 # define	SIOCSTGSZ	_IOWR(r, 82, struct ipfobj)
    100 # define	SIOCSTAT2	_IOWR(r, 83, struct ipfobj)
    101 # define	SIOCSETLG	_IOWR(r, 84, int)
    102 # define	SIOCGETLG	_IOWR(r, 85, int)
    103 # define	SIOCFUNCL	_IOWR(r, 86, struct ipfunc_resolve)
    104 # define	SIOCIPFGETNEXT	_IOWR(r, 87, struct ipfobj)
    105 # define	SIOCIPFGET	_IOWR(r, 88, struct ipfobj)
    106 # define	SIOCIPFSET	_IOWR(r, 89, struct ipfobj)
    107 # define	SIOCIPFL6	_IOWR(r, 90, int)
    108 # define	SIOCIPFITER	_IOWR(r, 91, struct ipfobj)
    109 # define	SIOCGENITER	_IOWR(r, 92, struct ipfobj)
    110 # define	SIOCGTABL	_IOWR(r, 93, struct ipfobj)
    111 # define	SIOCIPFDELTOK	_IOWR(r, 94, int)
    112 # define	SIOCLOOKUPITER	_IOWR(r, 95, struct ipfobj)
    113 # define	SIOCGTQTAB	_IOWR(r, 96, struct ipfobj)
    114 # define	SIOCMATCHFLUSH	_IOWR(r, 97, struct ipfobj)
    115 # define	SIOCIPFINTERROR	_IOR(r, 98, int)
    116 #endif
    117 #define	SIOCADDFR	SIOCADAFR
    118 #define	SIOCDELFR	SIOCRMAFR
    119 #define	SIOCINSFR	SIOCINAFR
    120 #define	SIOCATHST	SIOCSTAT1
    121 #define	SIOCGFRST	SIOCSTAT2
    122 
    123 
    124 struct ipscan;
    125 struct ifnet;
    126 struct ipf_main_softc_s;
    127 
    128 typedef	int	(* lookupfunc_t)(struct ipf_main_softc_s *, void *,
    129     int, void *, u_int);
    130 
    131 /*
    132  * i6addr is used as a container for both IPv4 and IPv6 addresses, as well
    133  * as other types of objects, depending on its qualifier.
    134  */
    135 #ifdef	USE_INET6
    136 typedef	union	i6addr	{
    137 	u_32_t	i6[4];
    138 	struct	in_addr	in4;
    139 	struct	in6_addr in6;
    140 	void	*vptr[2];
    141 	lookupfunc_t	lptr[2];
    142 	struct {
    143 		u_short	type;
    144 		u_short	subtype;
    145 		int	name;
    146 	} i6un;
    147 } i6addr_t;
    148 #else
    149 typedef	union	i6addr	{
    150 	u_32_t	i6[4];
    151 	struct	in_addr	in4;
    152 	void	*vptr[2];
    153 	lookupfunc_t	lptr[2];
    154 	struct {
    155 		u_short	type;
    156 		u_short	subtype;
    157 		int	name;
    158 	} i6un;
    159 } i6addr_t;
    160 #endif
    161 
    162 #define in4_addr	in4.s_addr
    163 #define	iplookupnum	i6[1]
    164 #define	iplookupname	i6un.name
    165 #define	iplookuptype	i6un.type
    166 #define	iplookupsubtype	i6un.subtype
    167 /*
    168  * NOTE: These DO overlap the above on 64bit systems and this IS recognised.
    169  */
    170 #define	iplookupptr	vptr[0]
    171 #define	iplookupfunc	lptr[1]
    172 
    173 /* Avoid casting to a type presuming 64-bit alignment. */
    174 #define	I60(x)	(((u_32_t *)(x))[0])
    175 #define	I61(x)	(((u_32_t *)(x))[1])
    176 #define	I62(x)	(((u_32_t *)(x))[2])
    177 #define	I63(x)	(((u_32_t *)(x))[3])
    178 #define	HI60(x)	ntohl(((u_32_t *)(x))[0])
    179 #define	HI61(x)	ntohl(((u_32_t *)(x))[1])
    180 #define	HI62(x)	ntohl(((u_32_t *)(x))[2])
    181 #define	HI63(x)	ntohl(((u_32_t *)(x))[3])
    182 
    183 #define	IP6_EQ(a,b)	((I63(a) == I63(b)) && (I62(a) == I62(b)) && \
    184 			 (I61(a) == I61(b)) && (I60(a) == I60(b)))
    185 #define	IP6_NEQ(a,b)	((I63(a) != I63(b)) || (I62(a) != I62(b)) || \
    186 			 (I61(a) != I61(b)) || (I60(a) != I60(b)))
    187 #define IP6_ISZERO(a)   ((I60(a) | I61(a) | I62(a) | I63(a)) == 0)
    188 #define IP6_NOTZERO(a)  ((I60(a) | I61(a) | I62(a) | I63(a)) != 0)
    189 #define	IP6_ISONES(a)	((I63(a) == 0xffffffff) && (I62(a) == 0xffffffff) && \
    190 			 (I61(a) == 0xffffffff) && (I60(a) == 0xffffffff))
    191 #define	IP6_GT(a,b)	(ntohl(HI60(a)) > ntohl(HI60(b)) || \
    192 			 (HI60(a) == HI60(b) && \
    193 			  (ntohl(HI61(a)) > ntohl(HI61(b)) || \
    194 			   (HI61(a) == HI61(b) && \
    195 			    (ntohl(HI62(a)) > ntohl(HI62(b)) || \
    196 			     (HI62(a) == HI62(b) && \
    197 			      ntohl(HI63(a)) > ntohl(HI63(b))))))))
    198 #define	IP6_LT(a,b)	(ntohl(HI60(a)) < ntohl(HI60(b)) || \
    199 			 (HI60(a) == HI60(b) && \
    200 			  (ntohl(HI61(a)) < ntohl(HI61(b)) || \
    201 			   (HI61(a) == HI61(b) && \
    202 			    (ntohl(HI62(a)) < ntohl(HI62(b)) || \
    203 			     (HI62(a) == HI62(b) && \
    204 			      ntohl(HI63(a)) < ntohl(HI63(b))))))))
    205 #define	NLADD(n,x)	htonl(ntohl(n) + (x))
    206 #define	IP6_INC(a)	\
    207 		do { u_32_t *_i6 = (u_32_t *)(a); \
    208 		  _i6[3] = NLADD(_i6[3], 1); \
    209 		  if (_i6[3] == 0) { \
    210 			_i6[2] = NLADD(_i6[2], 1); \
    211 			if (_i6[2] == 0) { \
    212 				_i6[1] = NLADD(_i6[1], 1); \
    213 				if (_i6[1] == 0) { \
    214 					_i6[0] = NLADD(_i6[0], 1); \
    215 				} \
    216 			} \
    217 		  } \
    218 		} while (0)
    219 #define	IP6_ADD(a,x,d)	\
    220 		do { i6addr_t *_s = (i6addr_t *)(a); \
    221 		  i6addr_t *_d = (i6addr_t *)(d); \
    222 		  _d->i6[0] = NLADD(_s->i6[0], x); \
    223 		  if (ntohl(_d->i6[0]) < ntohl(_s->i6[0])) { \
    224 			_d->i6[1] = NLADD(_d->i6[1], 1); \
    225 			if (ntohl(_d->i6[1]) < ntohl(_s->i6[1])) { \
    226 				_d->i6[2] = NLADD(_d->i6[2], 1); \
    227 				if (ntohl(_d->i6[2]) < ntohl(_s->i6[2])) { \
    228 					_d->i6[3] = NLADD(_d->i6[3], 1); \
    229 				} \
    230 			} \
    231 		  } \
    232 		} while (0)
    233 #define	IP6_AND(a,b,d)	do { i6addr_t *_s1 = (i6addr_t *)(a); \
    234 			  i6addr_t *_s2 = (i6addr_t *)(b); \
    235 			  i6addr_t *_d = (i6addr_t *)(d); \
    236 			  _d->i6[0] = _s1->i6[0] & _s2->i6[0]; \
    237 			  _d->i6[1] = _s1->i6[1] & _s2->i6[1]; \
    238 			  _d->i6[2] = _s1->i6[2] & _s2->i6[2]; \
    239 			  _d->i6[3] = _s1->i6[3] & _s2->i6[3]; \
    240 			} while (0)
    241 #define	IP6_ANDASSIGN(a,m) \
    242 			do { i6addr_t *_d = (i6addr_t *)(a); \
    243 			  i6addr_t *_m = (i6addr_t *)(m); \
    244 			  _d->i6[0] &= _m->i6[0]; \
    245 			  _d->i6[1] &= _m->i6[1]; \
    246 			  _d->i6[2] &= _m->i6[2]; \
    247 			  _d->i6[3] &= _m->i6[3]; \
    248 			} while (0)
    249 #define	IP6_MASKEQ(a,m,b) \
    250 			(((I60(a) & I60(m)) == I60(b)) && \
    251 			 ((I61(a) & I61(m)) == I61(b)) && \
    252 			 ((I62(a) & I62(m)) == I62(b)) && \
    253 			 ((I63(a) & I63(m)) == I63(b)))
    254 #define	IP6_MASKNEQ(a,m,b) \
    255 			(((I60(a) & I60(m)) != I60(b)) || \
    256 			 ((I61(a) & I61(m)) != I61(b)) || \
    257 			 ((I62(a) & I62(m)) != I62(b)) || \
    258 			 ((I63(a) & I63(m)) != I63(b)))
    259 #define	IP6_MERGE(a,b,c) \
    260 			do { i6addr_t *_d, *_s1, *_s2; \
    261 			  _d = (i6addr_t *)(a); \
    262 			  _s1 = (i6addr_t *)(b); \
    263 			  _s2 = (i6addr_t *)(c); \
    264 			  _d->i6[0] |= _s1->i6[0] & ~_s2->i6[0]; \
    265 			  _d->i6[1] |= _s1->i6[1] & ~_s2->i6[1]; \
    266 			  _d->i6[2] |= _s1->i6[2] & ~_s2->i6[2]; \
    267 			  _d->i6[3] |= _s1->i6[3] & ~_s2->i6[3]; \
    268 			} while (0)
    269 #define	IP6_MASK(a,b,c) \
    270 			do { i6addr_t *_d, *_s1, *_s2; \
    271 			  _d = (i6addr_t *)(a); \
    272 			  _s1 = (i6addr_t *)(b); \
    273 			  _s2 = (i6addr_t *)(c); \
    274 			  _d->i6[0] = _s1->i6[0] & ~_s2->i6[0]; \
    275 			  _d->i6[1] = _s1->i6[1] & ~_s2->i6[1]; \
    276 			  _d->i6[2] = _s1->i6[2] & ~_s2->i6[2]; \
    277 			  _d->i6[3] = _s1->i6[3] & ~_s2->i6[3]; \
    278 			} while (0)
    279 #define	IP6_SETONES(a)	\
    280 			do { i6addr_t *_d = (i6addr_t *)(a); \
    281 			  _d->i6[0] = 0xffffffff; \
    282 			  _d->i6[1] = 0xffffffff; \
    283 			  _d->i6[2] = 0xffffffff; \
    284 			  _d->i6[3] = 0xffffffff; \
    285 			} while (0)
    286 
    287 typedef	union ipso_u	{
    288 	u_short	ipso_ripso[2];
    289 	u_32_t	ipso_doi;
    290 } ipso_t;
    291 
    292 typedef	struct	fr_ip	{
    293 	u_32_t	fi_v:4;		/* IP version */
    294 	u_32_t	fi_xx:4;	/* spare */
    295 	u_32_t	fi_tos:8;	/* IP packet TOS */
    296 	u_32_t	fi_ttl:8;	/* IP packet TTL */
    297 	u_32_t	fi_p:8;		/* IP packet protocol */
    298 	u_32_t	fi_optmsk;	/* bitmask composed from IP options */
    299 	i6addr_t fi_src;	/* source address from packet */
    300 	i6addr_t fi_dst;	/* destination address from packet */
    301 	ipso_t	fi_ipso;	/* IP security options */
    302 	u_32_t	fi_flx;		/* packet flags */
    303 	u_32_t	fi_tcpmsk;	/* TCP options set/reset */
    304 	u_32_t	fi_ports[2];	/* TCP ports */
    305 	u_char	fi_tcpf;	/* TCP flags */
    306 	u_char	fi_sensitivity;
    307 	u_char	fi_xxx[2];	/* pad */
    308 } fr_ip_t;
    309 
    310 /*
    311  * For use in fi_flx
    312  */
    313 #define	FI_TCPUDP	0x0001	/* TCP/UCP implied comparison*/
    314 #define	FI_OPTIONS	0x0002
    315 #define	FI_FRAG		0x0004
    316 #define	FI_SHORT	0x0008
    317 #define	FI_NATED	0x0010
    318 #define	FI_MULTICAST	0x0020
    319 #define	FI_BROADCAST	0x0040
    320 #define	FI_MBCAST	0x0080
    321 #define	FI_STATE	0x0100
    322 #define	FI_BADNAT	0x0200
    323 #define	FI_BAD		0x0400
    324 #define	FI_OOW		0x0800	/* Out of state window, else match */
    325 #define	FI_ICMPERR	0x1000
    326 #define	FI_FRAGBODY	0x2000
    327 #define	FI_BADSRC	0x4000
    328 #define	FI_LOWTTL	0x8000
    329 #define	FI_CMP		0x5cfe3	/* Not FI_FRAG,FI_NATED,FI_FRAGTAIL */
    330 #define	FI_ICMPCMP	0x0003	/* Flags we can check for ICMP error packets */
    331 #define	FI_WITH		0x5effe	/* Not FI_TCPUDP */
    332 #define	FI_V6EXTHDR	0x10000
    333 #define	FI_COALESCE	0x20000
    334 #define	FI_NEWNAT	0x40000
    335 #define	FI_ICMPQUERY	0x80000
    336 #define	FI_ENCAP	0x100000	/* encap/decap with NAT */
    337 #define	FI_AH		0x200000	/* AH header present */
    338 #define	FI_DOCKSUM	0x10000000	/* Proxy wants L4 recalculation */
    339 #define	FI_NOCKSUM	0x20000000	/* don't do a L4 checksum validation */
    340 #define	FI_NOWILD	0x40000000	/* Do not do wildcard searches */
    341 #define	FI_IGNORE	0x80000000
    342 
    343 #define	fi_secmsk	fi_ipso.ipso_ripso[0]
    344 #define	fi_auth		fi_ipso.ipso_ripso[1]
    345 #define	fi_doi		fi_ipso.ipso_doi
    346 #define	fi_saddr	fi_src.in4.s_addr
    347 #define	fi_daddr	fi_dst.in4.s_addr
    348 #define	fi_srcnum	fi_src.iplookupnum
    349 #define	fi_dstnum	fi_dst.iplookupnum
    350 #define	fi_srcname	fi_src.iplookupname
    351 #define	fi_dstname	fi_dst.iplookupname
    352 #define	fi_srctype	fi_src.iplookuptype
    353 #define	fi_dsttype	fi_dst.iplookuptype
    354 #define	fi_srcsubtype	fi_src.iplookupsubtype
    355 #define	fi_dstsubtype	fi_dst.iplookupsubtype
    356 #define	fi_srcptr	fi_src.iplookupptr
    357 #define	fi_dstptr	fi_dst.iplookupptr
    358 #define	fi_srcfunc	fi_src.iplookupfunc
    359 #define	fi_dstfunc	fi_dst.iplookupfunc
    360 
    361 
    362 /*
    363  * These are both used by the state and NAT code to indicate that one port or
    364  * the other should be treated as a wildcard.
    365  * NOTE: When updating, check bit masks in ip_state.h and update there too.
    366  */
    367 #define	SI_W_SPORT	0x00000100
    368 #define	SI_W_DPORT	0x00000200
    369 #define	SI_WILDP	(SI_W_SPORT|SI_W_DPORT)
    370 #define	SI_W_SADDR	0x00000400
    371 #define	SI_W_DADDR	0x00000800
    372 #define	SI_WILDA	(SI_W_SADDR|SI_W_DADDR)
    373 #define	SI_NEWFR	0x00001000
    374 #define	SI_CLONE	0x00002000
    375 #define	SI_CLONED	0x00004000
    376 #define	SI_NEWCLONE	0x00008000
    377 
    378 typedef	struct {
    379 	u_short	fda_ports[2];
    380 	u_char	fda_tcpf;		/* TCP header flags (SYN, ACK, etc) */
    381 } frdat_t;
    382 
    383 typedef enum fr_breasons_e {
    384 	FRB_BLOCKED = 0,
    385 	FRB_LOGFAIL = 1,
    386 	FRB_PPSRATE = 2,
    387 	FRB_JUMBO = 3,
    388 	FRB_MAKEFRIP = 4,
    389 	FRB_STATEADD = 5,
    390 	FRB_UPDATEIPID = 6,
    391 	FRB_LOGFAIL2 = 7,
    392 	FRB_DECAPFRIP = 8,
    393 	FRB_AUTHNEW = 9,
    394 	FRB_AUTHCAPTURE = 10,
    395 	FRB_COALESCE = 11,
    396 	FRB_PULLUP = 12,
    397 	FRB_AUTHFEEDBACK = 13,
    398 	FRB_BADFRAG = 14,
    399 	FRB_NATV4 = 15,
    400 	FRB_NATV6 = 16,
    401 } fr_breason_t;
    402 
    403 #define	FRB_MAX_VALUE	16
    404 
    405 typedef enum ipf_cksum_e {
    406 	FI_CK_BAD = -1,
    407 	FI_CK_NEEDED = 0,
    408 	FI_CK_SUMOK = 1,
    409 	FI_CK_L4PART = 2,
    410 	FI_CK_L4FULL = 4
    411 } ipf_cksum_t;
    412 
    413 typedef	struct	fr_info	{
    414 	void	*fin_main_soft;
    415 	void	*fin_ifp;		/* interface packet is `on' */
    416 	struct	frentry *fin_fr;	/* last matching rule */
    417 	int	fin_out;		/* in or out ? 1 == out, 0 == in */
    418 	fr_ip_t	fin_fi;			/* IP Packet summary */
    419 	frdat_t	fin_dat;		/* TCP/UDP ports, ICMP code/type */
    420 	int	fin_dlen;		/* length of data portion of packet */
    421 	int	fin_plen;
    422 	u_32_t	fin_rule;		/* rule # last matched */
    423 	u_short	fin_hlen;		/* length of IP header in bytes */
    424 	char	fin_group[FR_GROUPLEN];	/* group number, -1 for none */
    425 	void	*fin_dp;		/* start of data past IP header */
    426 	/*
    427 	 * Fields after fin_dp aren't used for compression of log records.
    428 	 * fin_fi contains the IP version (fin_family)
    429 	 * fin_rule isn't included because adding a new rule can change it but
    430 	 * not change fin_fr. fin_rule is the rule number reported.
    431 	 * It isn't necessary to include fin_crc because that is checked
    432 	 * for explicitly, before calling bcmp.
    433 	 */
    434 	u_32_t	fin_crc;		/* Simple calculation for logging */
    435 	int	fin_family;		/* AF_INET, etc. */
    436 	int	fin_icode;		/* ICMP error to return */
    437 	int	fin_mtu;		/* MTU input for ICMP need-frag */
    438 	int	fin_rev;		/* state only: 1 = reverse */
    439 	int	fin_ipoff;		/* # bytes from buffer start to hdr */
    440 	u_32_t	fin_id;			/* IP packet id field */
    441 	u_short	fin_l4hlen;		/* length of L4 header, if known */
    442 	u_short	fin_off;
    443 	int	fin_depth;		/* Group nesting depth */
    444 	int	fin_error;		/* Error code to return */
    445 	ipf_cksum_t	fin_cksum;	/* -1 = bad, 1 = good, 0 = not done */
    446 	fr_breason_t	fin_reason;	/* why auto blocked */
    447 	u_int	fin_pktnum;
    448 	void	*fin_nattag;
    449 	struct frdest	*fin_dif;
    450 	struct frdest	*fin_tif;
    451 	union {
    452 		ip_t	*fip_ip;
    453 #ifdef USE_INET6
    454 		ip6_t	*fip_ip6;
    455 #endif
    456 	} fin_ipu;
    457 	mb_t	**fin_mp;		/* pointer to pointer to mbuf */
    458 	mb_t	*fin_m;			/* pointer to mbuf */
    459 #ifdef	MENTAT
    460 	mb_t	*fin_qfm;		/* pointer to mblk where pkt starts */
    461 	void	*fin_qpi;
    462 	char	fin_ifname[LIFNAMSIZ];
    463 #endif
    464 #ifdef	__sgi
    465 	void	*fin_hbuf;
    466 #endif
    467 	void	*fin_fraghdr;		/* pointer to start of ipv6 frag hdr */
    468 } fr_info_t;
    469 
    470 #define	fin_ip		fin_ipu.fip_ip
    471 #define	fin_ip6		fin_ipu.fip_ip6
    472 #define	fin_v		fin_fi.fi_v
    473 #define	fin_p		fin_fi.fi_p
    474 #define	fin_flx		fin_fi.fi_flx
    475 #define	fin_optmsk	fin_fi.fi_optmsk
    476 #define	fin_secmsk	fin_fi.fi_secmsk
    477 #define	fin_doi		fin_fi.fi_doi
    478 #define	fin_auth	fin_fi.fi_auth
    479 #define	fin_src		fin_fi.fi_src.in4
    480 #define	fin_saddr	fin_fi.fi_saddr
    481 #define	fin_dst		fin_fi.fi_dst.in4
    482 #define	fin_daddr	fin_fi.fi_daddr
    483 #define	fin_data	fin_fi.fi_ports
    484 #define	fin_sport	fin_fi.fi_ports[0]
    485 #define	fin_dport	fin_fi.fi_ports[1]
    486 #define	fin_tcpf	fin_fi.fi_tcpf
    487 #define	fin_src6	fin_fi.fi_src
    488 #define	fin_dst6	fin_fi.fi_dst
    489 #define	fin_srcip6	fin_fi.fi_src.in6
    490 #define	fin_dstip6	fin_fi.fi_dst.in6
    491 
    492 #define	IPF_IN		0
    493 #define	IPF_OUT		1
    494 
    495 typedef	struct frentry	*(*ipfunc_t)(fr_info_t *, u_32_t *);
    496 typedef	int		(*ipfuncinit_t)(struct ipf_main_softc_s *,
    497     struct frentry *);
    498 
    499 typedef	struct	ipfunc_resolve	{
    500 	char		ipfu_name[32];
    501 	ipfunc_t	ipfu_addr;
    502 	ipfuncinit_t	ipfu_init;
    503 	ipfuncinit_t	ipfu_fini;
    504 } ipfunc_resolve_t;
    505 
    506 /*
    507  * Size for compares on fr_info structures
    508  */
    509 #define	FI_CSIZE	offsetof(fr_info_t, fin_icode)
    510 #define	FI_LCSIZE	offsetof(fr_info_t, fin_dp)
    511 
    512 /*
    513  * Size for copying cache fr_info structure
    514  */
    515 #define	FI_COPYSIZE	offsetof(fr_info_t, fin_dp)
    516 
    517 /*
    518  * Structure for holding IPFilter's tag information
    519  */
    520 #define	IPFTAG_LEN	16
    521 typedef	struct	{
    522 	union	{
    523 		u_32_t	iptu_num[4];
    524 		char	iptu_tag[IPFTAG_LEN];
    525 	} ipt_un;
    526 	int	ipt_not;
    527 } ipftag_t;
    528 
    529 #define	ipt_tag	ipt_un.iptu_tag
    530 #define	ipt_num	ipt_un.iptu_num
    531 
    532 /*
    533  * Structure to define address for pool lookups.
    534  */
    535 typedef	struct	{
    536 	u_char		adf_len;
    537 	sa_family_t	adf_family;
    538 	u_char		adf_xxx[2];
    539 	i6addr_t	adf_addr;
    540 } addrfamily_t;
    541 
    542 
    543 RBI_LINK(ipf_rb, host_node_s);
    544 
    545 typedef	struct	host_node_s {
    546 	RBI_FIELD(ipf_rb)	hn_entry;
    547 	addrfamily_t		hn_addr;
    548 	int			hn_active;
    549 } host_node_t;
    550 
    551 typedef RBI_HEAD(ipf_rb, host_node_s) ipf_rb_head_t;
    552 
    553 typedef	struct	host_track_s {
    554 	ipf_rb_head_t	ht_root;
    555 	int		ht_max_nodes;
    556 	int		ht_max_per_node;
    557 	int		ht_netmask;
    558 	int		ht_cur_nodes;
    559 } host_track_t;
    560 
    561 
    562 typedef enum fr_dtypes_e {
    563 	FRD_NORMAL = 0,
    564 	FRD_DSTLIST
    565 } fr_dtypes_t;
    566 /*
    567  * This structure is used to hold information about the next hop for where
    568  * to forward a packet.
    569  */
    570 typedef	struct	frdest	{
    571 	void		*fd_ptr;
    572 	addrfamily_t	fd_addr;
    573 	fr_dtypes_t	fd_type;
    574 	int		fd_name;
    575 	int		fd_local;
    576 } frdest_t;
    577 
    578 #define	fd_ip6	fd_addr.adf_addr
    579 #define	fd_ip	fd_ip6.in4
    580 
    581 
    582 typedef enum fr_ctypes_e {
    583 	FR_NONE = 0,
    584 	FR_EQUAL,
    585 	FR_NEQUAL,
    586 	FR_LESST,
    587 	FR_GREATERT,
    588 	FR_LESSTE,
    589 	FR_GREATERTE,
    590 	FR_OUTRANGE,
    591 	FR_INRANGE,
    592 	FR_INCRANGE
    593 } fr_ctypes_t;
    594 
    595 /*
    596  * This structure holds information about a port comparison.
    597  */
    598 typedef	struct	frpcmp	{
    599 	fr_ctypes_t	frp_cmp;	/* data for port comparisons */
    600 	u_32_t		frp_port;	/* top port for <> and >< */
    601 	u_32_t		frp_top;	/* top port for <> and >< */
    602 } frpcmp_t;
    603 
    604 
    605 /*
    606  * Structure containing all the relevant TCP things that can be checked in
    607  * a filter rule.
    608  */
    609 typedef	struct	frtuc	{
    610 	u_char		ftu_tcpfm;	/* tcp flags mask */
    611 	u_char		ftu_tcpf;	/* tcp flags */
    612 	frpcmp_t	ftu_src;
    613 	frpcmp_t	ftu_dst;
    614 } frtuc_t;
    615 
    616 #define	ftu_scmp	ftu_src.frp_cmp
    617 #define	ftu_dcmp	ftu_dst.frp_cmp
    618 #define	ftu_sport	ftu_src.frp_port
    619 #define	ftu_dport	ftu_dst.frp_port
    620 #define	ftu_stop	ftu_src.frp_top
    621 #define	ftu_dtop	ftu_dst.frp_top
    622 
    623 #define	FR_TCPFMAX	0x3f
    624 
    625 typedef enum fr_atypes_e {
    626 	FRI_NONE = -1,	/* For LHS of NAT */
    627 	FRI_NORMAL = 0,	/* Normal address */
    628 	FRI_DYNAMIC,	/* dynamic address */
    629 	FRI_LOOKUP,	/* address is a pool # */
    630 	FRI_RANGE,	/* address/mask is a range */
    631 	FRI_NETWORK,	/* network address from if */
    632 	FRI_BROADCAST,	/* broadcast address from if */
    633 	FRI_PEERADDR,	/* Peer address for P-to-P */
    634 	FRI_NETMASKED,	/* network address with netmask from if */
    635 	FRI_SPLIT,	/* For NAT compatibility */
    636 	FRI_INTERFACE	/* address is based on interface name */
    637 } fr_atypes_t;
    638 
    639 /*
    640  * This structure makes up what is considered to be the IPFilter specific
    641  * matching components of a filter rule, as opposed to the data structures
    642  * used to define the result which are in frentry_t and not here.
    643  */
    644 typedef	struct	fripf	{
    645 	fr_ip_t		fri_ip;
    646 	fr_ip_t		fri_mip;	/* mask structure */
    647 
    648 	u_short		fri_icmpm;	/* data for ICMP packets (mask) */
    649 	u_short		fri_icmp;
    650 
    651 	frtuc_t		fri_tuc;
    652 	fr_atypes_t	fri_satype;	/* addres type */
    653 	fr_atypes_t	fri_datype;	/* addres type */
    654 	int		fri_sifpidx;	/* doing dynamic addressing */
    655 	int		fri_difpidx;	/* index into fr_ifps[] to use when */
    656 } fripf_t;
    657 
    658 #define	fri_dlookup	fri_mip.fi_dst
    659 #define	fri_slookup	fri_mip.fi_src
    660 #define	fri_dstnum	fri_mip.fi_dstnum
    661 #define	fri_srcnum	fri_mip.fi_srcnum
    662 #define	fri_dstname	fri_mip.fi_dstname
    663 #define	fri_srcname	fri_mip.fi_srcname
    664 #define	fri_dstptr	fri_mip.fi_dstptr
    665 #define	fri_srcptr	fri_mip.fi_srcptr
    666 
    667 
    668 typedef enum fr_rtypes_e {
    669 	FR_T_NONE = 0,
    670 	FR_T_IPF,		/* IPF structures */
    671 	FR_T_BPFOPC,		/* BPF opcode */
    672 	FR_T_CALLFUNC,		/* callout to function in fr_func only */
    673 	FR_T_COMPIPF,			/* compiled C code */
    674 	FR_T_IPFEXPR,			/* IPF expression */
    675 	FR_T_BUILTIN = 0x40000000,	/* rule is in kernel space */
    676 	FR_T_IPF_BUILTIN,
    677 	FR_T_BPFOPC_BUILTIN,
    678 	FR_T_CALLFUNC_BUILTIN,
    679 	FR_T_COMPIPF_BUILTIN,
    680 	FR_T_IPFEXPR_BUILTIN
    681 } fr_rtypes_t;
    682 
    683 typedef	struct	frentry	* (* frentfunc_t)(fr_info_t *);
    684 
    685 typedef	struct	frentry {
    686 	ipfmutex_t	fr_lock;
    687 	struct	frentry	*fr_next;
    688 	struct	frentry	**fr_pnext;
    689 	struct	frgroup	*fr_grp;
    690 	struct	frgroup	*fr_grphead;
    691 	struct	frgroup	*fr_icmpgrp;
    692 	struct	ipscan	*fr_isc;
    693 	struct	frentry	*fr_dnext;	/* 2 fr_die linked list pointers */
    694 	struct	frentry	**fr_pdnext;
    695 	void	*fr_ifas[4];
    696 	void	*fr_ptr;	/* for use with fr_arg */
    697 	int	fr_comment;	/* text comment for rule */
    698 	int	fr_size;	/* size of this structure */
    699 	int	fr_ref;		/* reference count */
    700 	int	fr_statecnt;	/* state count - for limit rules */
    701 	u_32_t	fr_die;		/* only used on loading the rule */
    702 	u_int	fr_cksum;	/* checksum on filter rules for performance */
    703 	/*
    704 	 * The line number from a file is here because we need to be able to
    705 	 * match the rule generated with ``grep rule ipf.conf | ipf -rf -''
    706 	 * with the rule loaded using ``ipf -f ipf.conf'' - thus it can't be
    707 	 * on the other side of fr_func.
    708 	 */
    709 	int	fr_flineno;	/* line number from conf file */
    710 	/*
    711 	 * These are only incremented when a packet  matches this rule and
    712 	 * it is the last match
    713 	 */
    714 	U_QUAD_T	fr_hits;
    715 	U_QUAD_T	fr_bytes;
    716 
    717 	/*
    718 	 * For PPS rate limiting
    719 	 * fr_lpu is used to always have the same size for this field,
    720 	 * allocating 64bits for seconds and 32bits for milliseconds.
    721 	 */
    722 	union {
    723 		struct timeval	frp_lastpkt;
    724 		char	frp_bytes[12];
    725 	} fr_lpu;
    726 	int		fr_curpps;
    727 
    728 	union	{
    729 		void		*fru_data;
    730 		char		*fru_caddr;
    731 		fripf_t		*fru_ipf;
    732 		frentfunc_t	fru_func;
    733 	} fr_dun;
    734 
    735 	/*
    736 	 * Fields after this may not change whilst in the kernel.
    737 	 */
    738 	ipfunc_t fr_func; 	/* call this function */
    739 	int	fr_dsize;
    740 	int	fr_pps;
    741 	fr_rtypes_t	fr_type;
    742 	u_32_t	fr_flags;	/* per-rule flags && options (see below) */
    743 	u_32_t	fr_logtag;	/* user defined log tag # */
    744 	u_32_t	fr_collect;	/* collection number */
    745 	u_int	fr_arg;		/* misc. numeric arg for rule */
    746 	u_int	fr_loglevel;	/* syslog log facility + priority */
    747 	u_char	fr_family;
    748 	u_char	fr_icode;	/* return ICMP code */
    749 	int	fr_group;	/* group to which this rule belongs */
    750 	int	fr_grhead;	/* group # which this rule starts */
    751 	int	fr_ifnames[4];
    752 	int	fr_isctag;
    753 	int	fr_rpc;		/* XID Filtering */
    754 	ipftag_t fr_nattag;
    755 	frdest_t fr_tifs[2];	/* "to"/"reply-to" interface */
    756 	frdest_t fr_dif;	/* duplicate packet interface */
    757 	/*
    758 	 * These are all options related to stateful filtering
    759 	 */
    760 	host_track_t	fr_srctrack;
    761 	int	fr_nostatelog;
    762 	int	fr_statemax;	/* max reference count */
    763 	int	fr_icmphead;	/* ICMP group  for state options */
    764 	u_int	fr_age[2];	/* non-TCP state timeouts */
    765 	/*
    766 	 * How big is the name buffer at the end?
    767 	 */
    768 	int	fr_namelen;
    769 	char	fr_names[1];
    770 } frentry_t;
    771 
    772 #define	fr_lastpkt	fr_lpu.frp_lastpkt
    773 #define	fr_caddr	fr_dun.fru_caddr
    774 #define	fr_data		fr_dun.fru_data
    775 #define	fr_dfunc	fr_dun.fru_func
    776 #define	fr_ipf		fr_dun.fru_ipf
    777 #define	fr_ip		fr_ipf->fri_ip
    778 #define	fr_mip		fr_ipf->fri_mip
    779 #define	fr_icmpm	fr_ipf->fri_icmpm
    780 #define	fr_icmp		fr_ipf->fri_icmp
    781 #define	fr_tuc		fr_ipf->fri_tuc
    782 #define	fr_satype	fr_ipf->fri_satype
    783 #define	fr_datype	fr_ipf->fri_datype
    784 #define	fr_sifpidx	fr_ipf->fri_sifpidx
    785 #define	fr_difpidx	fr_ipf->fri_difpidx
    786 #define	fr_proto	fr_ip.fi_p
    787 #define	fr_mproto	fr_mip.fi_p
    788 #define	fr_ttl		fr_ip.fi_ttl
    789 #define	fr_mttl		fr_mip.fi_ttl
    790 #define	fr_tos		fr_ip.fi_tos
    791 #define	fr_mtos		fr_mip.fi_tos
    792 #define	fr_tcpfm	fr_tuc.ftu_tcpfm
    793 #define	fr_tcpf		fr_tuc.ftu_tcpf
    794 #define	fr_scmp		fr_tuc.ftu_scmp
    795 #define	fr_dcmp		fr_tuc.ftu_dcmp
    796 #define	fr_dport	fr_tuc.ftu_dport
    797 #define	fr_sport	fr_tuc.ftu_sport
    798 #define	fr_stop		fr_tuc.ftu_stop
    799 #define	fr_dtop		fr_tuc.ftu_dtop
    800 #define	fr_dst		fr_ip.fi_dst.in4
    801 #define	fr_dst6		fr_ip.fi_dst
    802 #define	fr_daddr	fr_ip.fi_dst.in4.s_addr
    803 #define	fr_src		fr_ip.fi_src.in4
    804 #define	fr_src6		fr_ip.fi_src
    805 #define	fr_saddr	fr_ip.fi_src.in4.s_addr
    806 #define	fr_dmsk		fr_mip.fi_dst.in4
    807 #define	fr_dmsk6	fr_mip.fi_dst
    808 #define	fr_dmask	fr_mip.fi_dst.in4.s_addr
    809 #define	fr_smsk		fr_mip.fi_src.in4
    810 #define	fr_smsk6	fr_mip.fi_src
    811 #define	fr_smask	fr_mip.fi_src.in4.s_addr
    812 #define	fr_dstnum	fr_ip.fi_dstnum
    813 #define	fr_srcnum	fr_ip.fi_srcnum
    814 #define	fr_dlookup	fr_ip.fi_dst
    815 #define	fr_slookup	fr_ip.fi_src
    816 #define	fr_dstname	fr_ip.fi_dstname
    817 #define	fr_srcname	fr_ip.fi_srcname
    818 #define	fr_dsttype	fr_ip.fi_dsttype
    819 #define	fr_srctype	fr_ip.fi_srctype
    820 #define	fr_dstsubtype	fr_ip.fi_dstsubtype
    821 #define	fr_srcsubtype	fr_ip.fi_srcsubtype
    822 #define	fr_dstptr	fr_mip.fi_dstptr
    823 #define	fr_srcptr	fr_mip.fi_srcptr
    824 #define	fr_dstfunc	fr_mip.fi_dstfunc
    825 #define	fr_srcfunc	fr_mip.fi_srcfunc
    826 #define	fr_optbits	fr_ip.fi_optmsk
    827 #define	fr_optmask	fr_mip.fi_optmsk
    828 #define	fr_secbits	fr_ip.fi_secmsk
    829 #define	fr_secmask	fr_mip.fi_secmsk
    830 #define	fr_authbits	fr_ip.fi_auth
    831 #define	fr_authmask	fr_mip.fi_auth
    832 #define	fr_doi		fr_ip.fi_doi
    833 #define	fr_doimask	fr_mip.fi_doi
    834 #define	fr_flx		fr_ip.fi_flx
    835 #define	fr_mflx		fr_mip.fi_flx
    836 #define	fr_ifa		fr_ifas[0]
    837 #define	fr_oifa		fr_ifas[2]
    838 #define	fr_tif		fr_tifs[0]
    839 #define	fr_rif		fr_tifs[1]
    840 
    841 #define	FR_NOLOGTAG	0
    842 
    843 #define	FR_CMPSIZ	(sizeof(struct frentry) - \
    844 			 offsetof(struct frentry, fr_func))
    845 #define	FR_NAME(_f, _n)	(_f)->fr_names + (_f)->_n
    846 
    847 
    848 /*
    849  * fr_flags
    850  */
    851 #define	FR_BLOCK	0x00001	/* do not allow packet to pass */
    852 #define	FR_PASS		0x00002	/* allow packet to pass */
    853 #define	FR_AUTH		0x00003	/* use authentication */
    854 #define	FR_PREAUTH	0x00004	/* require preauthentication */
    855 #define	FR_ACCOUNT	0x00005	/* Accounting rule */
    856 #define	FR_SKIP		0x00006	/* skip rule */
    857 #define	FR_DECAPSULATE	0x00008	/* decapsulate rule */
    858 #define	FR_CALL		0x00009	/* call rule */
    859 #define	FR_CMDMASK	0x0000f
    860 #define	FR_LOG		0x00010	/* Log */
    861 #define	FR_LOGB		0x00011	/* Log-fail */
    862 #define	FR_LOGP		0x00012	/* Log-pass */
    863 #define	FR_LOGMASK	(FR_LOG|FR_CMDMASK)
    864 #define	FR_CALLNOW	0x00020	/* call another function (fr_func) if matches */
    865 #define	FR_NOTSRCIP	0x00040
    866 #define	FR_NOTDSTIP	0x00080
    867 #define	FR_QUICK	0x00100	/* match & stop processing list */
    868 #define	FR_KEEPFRAG	0x00200	/* keep fragment information */
    869 #define	FR_KEEPSTATE	0x00400	/* keep `connection' state information */
    870 #define	FR_FASTROUTE	0x00800	/* bypass normal routing */
    871 #define	FR_RETRST	0x01000	/* Return TCP RST packet - reset connection */
    872 #define	FR_RETICMP	0x02000	/* Return ICMP unreachable packet */
    873 #define	FR_FAKEICMP	0x03000	/* Return ICMP unreachable with fake source */
    874 #define	FR_OUTQUE	0x04000	/* outgoing packets */
    875 #define	FR_INQUE	0x08000	/* ingoing packets */
    876 #define	FR_LOGBODY	0x10000	/* Log the body */
    877 #define	FR_LOGFIRST	0x20000	/* Log the first byte if state held */
    878 #define	FR_LOGORBLOCK	0x40000	/* block the packet if it can't be logged */
    879 #define	FR_STLOOSE	0x80000	/* loose state checking */
    880 #define	FR_FRSTRICT	0x100000	/* strict frag. cache */
    881 #define	FR_STSTRICT	0x200000	/* strict keep state */
    882 #define	FR_NEWISN	0x400000	/* new ISN for outgoing TCP */
    883 #define	FR_NOICMPERR	0x800000	/* do not match ICMP errors in state */
    884 #define	FR_STATESYNC	0x1000000	/* synchronize state to slave */
    885 #define	FR_COPIED	0x2000000	/* copied from user space */
    886 #define	FR_INACTIVE	0x4000000	/* only used when flush'ing rules */
    887 #define	FR_NOMATCH	0x8000000	/* no match occured */
    888 		/*	0x10000000 	FF_LOGPASS */
    889 		/*	0x20000000 	FF_LOGBLOCK */
    890 		/*	0x40000000 	FF_LOGNOMATCH */
    891 		/*	0x80000000 	FF_BLOCKNONIP */
    892 
    893 #define	FR_RETMASK	(FR_RETICMP|FR_RETRST|FR_FAKEICMP)
    894 #define	FR_ISBLOCK(x)	(((x) & FR_CMDMASK) == FR_BLOCK)
    895 #define	FR_ISPASS(x)	(((x) & FR_CMDMASK) == FR_PASS)
    896 #define	FR_ISAUTH(x)	(((x) & FR_CMDMASK) == FR_AUTH)
    897 #define	FR_ISPREAUTH(x)	(((x) & FR_CMDMASK) == FR_PREAUTH)
    898 #define	FR_ISACCOUNT(x)	(((x) & FR_CMDMASK) == FR_ACCOUNT)
    899 #define	FR_ISSKIP(x)	(((x) & FR_CMDMASK) == FR_SKIP)
    900 #define	FR_ISDECAPS(x)	(((x) & FR_CMDMASK) == FR_DECAPSULATE)
    901 #define	FR_ISNOMATCH(x)	((x) & FR_NOMATCH)
    902 #define	FR_INOUT	(FR_INQUE|FR_OUTQUE)
    903 
    904 /*
    905  * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags
    906  */
    907 #define	FF_LOGPASS	0x10000000
    908 #define	FF_LOGBLOCK	0x20000000
    909 #define	FF_LOGNOMATCH	0x40000000
    910 #define	FF_LOGGING	(FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH)
    911 #define	FF_BLOCKNONIP	0x80000000	/* Solaris2 Only */
    912 
    913 
    914 /*
    915  * Structure that passes information on what/how to flush to the kernel.
    916  */
    917 typedef	struct	ipfflush	{
    918 	int		ipflu_how;
    919 	int		ipflu_arg;
    920 } ipfflush_t;
    921 
    922 
    923 /*
    924  *
    925  */
    926 typedef	struct	ipfgetctl	{
    927 	u_int		ipfg_min;	/* min value */
    928 	u_int		ipfg_current;	/* current value */
    929 	u_int		ipfg_max;	/* max value */
    930 	u_int		ipfg_default;	/* default value */
    931 	u_int		ipfg_steps;	/* value increments */
    932 	char		ipfg_name[40];	/* tag name for this control */
    933 } ipfgetctl_t;
    934 
    935 typedef	struct	ipfsetctl	{
    936 	int	ipfs_which;	/* 0 = min 1 = current 2 = max 3 = default */
    937 	u_int	ipfs_value;	/* min value */
    938 	char	ipfs_name[40];	/* tag name for this control */
    939 } ipfsetctl_t;
    940 
    941 
    942 /*
    943  * Some of the statistics below are in their own counters, but most are kept
    944  * in this single structure so that they can all easily be collected and
    945  * copied back as required.
    946  */
    947 typedef	struct	ipf_statistics {
    948 	u_long	fr_icmp_coalesce;
    949 	u_long	fr_tcp_frag;
    950 	u_long	fr_tcp_pullup;
    951 	u_long	fr_tcp_short;
    952 	u_long	fr_tcp_small;
    953 	u_long	fr_tcp_bad_flags;
    954 	u_long	fr_udp_pullup;
    955 	u_long	fr_ip_freed;
    956 	u_long	fr_v6_ah_bad;
    957 	u_long	fr_v6_bad;
    958 	u_long	fr_v6_badfrag;
    959 	u_long	fr_v6_dst_bad;
    960 	u_long	fr_v6_esp_pullup;
    961 	u_long	fr_v6_ext_short;
    962 	u_long	fr_v6_ext_pullup;
    963 	u_long	fr_v6_ext_hlen;
    964 	u_long	fr_v6_frag_bad;
    965 	u_long	fr_v6_frag_pullup;
    966 	u_long	fr_v6_frag_size;
    967 	u_long	fr_v6_gre_pullup;
    968 	u_long	fr_v6_icmp6_pullup;
    969 	u_long	fr_v6_rh_bad;
    970 	u_long	fr_v6_badttl;	/* TTL in packet doesn't reach minimum */
    971 	u_long	fr_v4_ah_bad;
    972 	u_long	fr_v4_ah_pullup;
    973 	u_long	fr_v4_esp_pullup;
    974 	u_long	fr_v4_cipso_bad;
    975 	u_long	fr_v4_cipso_tlen;
    976 	u_long	fr_v4_gre_frag;
    977 	u_long	fr_v4_gre_pullup;
    978 	u_long	fr_v4_icmp_frag;
    979 	u_long	fr_v4_icmp_pullup;
    980 	u_long	fr_v4_badttl;	/* TTL in packet doesn't reach minimum */
    981 	u_long	fr_v4_badsrc;	/* source received doesn't match route */
    982 	u_long	fr_l4_badcksum;	/* layer 4 header checksum failure */
    983 	u_long	fr_badcoalesces;
    984 	u_long	fr_pass;	/* packets allowed */
    985 	u_long	fr_block;	/* packets denied */
    986 	u_long	fr_nom;		/* packets which don't match any rule */
    987 	u_long	fr_short;	/* packets which are short */
    988 	u_long	fr_ppkl;	/* packets allowed and logged */
    989 	u_long	fr_bpkl;	/* packets denied and logged */
    990 	u_long	fr_npkl;	/* packets unmatched and logged */
    991 	u_long	fr_ret;		/* packets for which a return is sent */
    992 	u_long	fr_acct;	/* packets for which counting was performed */
    993 	u_long	fr_bnfr;	/* bad attempts to allocate fragment state */
    994 	u_long	fr_nfr;		/* new fragment state kept */
    995 	u_long	fr_cfr;		/* add new fragment state but complete pkt */
    996 	u_long	fr_bads;	/* bad attempts to allocate packet state */
    997 	u_long	fr_ads;		/* new packet state kept */
    998 	u_long	fr_chit;	/* cached hit */
    999 	u_long	fr_cmiss;	/* cached miss */
   1000 	u_long	fr_tcpbad;	/* TCP checksum check failures */
   1001 	u_long	fr_pull[2];	/* good and bad pullup attempts */
   1002 	u_long	fr_bad;		/* bad IP packets to the filter */
   1003 	u_long	fr_ipv6;	/* IPv6 packets in/out */
   1004 	u_long	fr_ppshit;	/* dropped because of pps ceiling */
   1005 	u_long	fr_ipud;	/* IP id update failures */
   1006 	u_long	fr_blocked[FRB_MAX_VALUE + 1];
   1007 } ipf_statistics_t;
   1008 
   1009 /*
   1010  * Log structure.  Each packet header logged is prepended by one of these.
   1011  * Following this in the log records read from the device will be an ipflog
   1012  * structure which is then followed by any packet data.
   1013  */
   1014 typedef	struct	iplog	{
   1015 	u_32_t		ipl_magic;
   1016 	u_int		ipl_count;
   1017 	u_32_t		ipl_seqnum;
   1018 	struct	timeval	ipl_time;
   1019 	size_t		ipl_dsize;
   1020 	struct	iplog	*ipl_next;
   1021 } iplog_t;
   1022 
   1023 #define	ipl_sec		ipl_time.tv_sec
   1024 #define	ipl_usec	ipl_time.tv_usec
   1025 
   1026 #define IPL_MAGIC	0x49504c4d	/* 'IPLM' */
   1027 #define IPL_MAGIC_NAT	0x49504c4e	/* 'IPLN' */
   1028 #define IPL_MAGIC_STATE	0x49504c53	/* 'IPLS' */
   1029 #define	IPLOG_SIZE	sizeof(iplog_t)
   1030 
   1031 typedef	struct	ipflog	{
   1032 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
   1033         (defined(OpenBSD) && (OpenBSD >= 199603))
   1034 #else
   1035 	u_int	fl_unit;
   1036 #endif
   1037 	u_32_t		fl_rule;
   1038 	u_32_t		fl_flags;
   1039 	u_32_t		fl_lflags;
   1040 	u_32_t		fl_logtag;
   1041 	ipftag_t	fl_nattag;
   1042 	u_short		fl_plen;	/* extra data after hlen */
   1043 	u_short		fl_loglevel;	/* syslog log level */
   1044 	char		fl_group[FR_GROUPLEN];
   1045 	u_char		fl_hlen;	/* length of IP headers saved */
   1046 	u_char		fl_dir;
   1047 	u_char		fl_breason;	/* from fin_reason */
   1048 	u_char		fl_family;	/* address family of packet logged */
   1049 	char		fl_ifname[LIFNAMSIZ];
   1050 } ipflog_t;
   1051 
   1052 #ifndef	IPF_LOGGING
   1053 # define	IPF_LOGGING	0
   1054 #endif
   1055 #ifndef	IPF_DEFAULT_PASS
   1056 # define	IPF_DEFAULT_PASS	FR_PASS
   1057 #endif
   1058 
   1059 #define	DEFAULT_IPFLOGSIZE	32768
   1060 #ifndef	IPFILTER_LOGSIZE
   1061 # define	IPFILTER_LOGSIZE	DEFAULT_IPFLOGSIZE
   1062 #else
   1063 # if IPFILTER_LOGSIZE < 8192
   1064 #  error IPFILTER_LOGSIZE too small.  Must be >= 8192
   1065 # endif
   1066 #endif
   1067 
   1068 #define	IPF_OPTCOPY	0x07ff00	/* bit mask of copied options */
   1069 
   1070 /*
   1071  * Device filenames for reading log information.  Use ipf on Solaris2 because
   1072  * ipl is already a name used by something else.
   1073  */
   1074 #ifndef	IPL_NAME
   1075 # if	SOLARIS
   1076 #  define	IPL_NAME	"/dev/ipf"
   1077 # else
   1078 #  define	IPL_NAME	"/dev/ipl"
   1079 # endif
   1080 #endif
   1081 /*
   1082  * Pathnames for various IP Filter control devices.  Used by LKM
   1083  * and userland, so defined here.
   1084  */
   1085 #define	IPNAT_NAME	"/dev/ipnat"
   1086 #define	IPSTATE_NAME	"/dev/ipstate"
   1087 #define	IPAUTH_NAME	"/dev/ipauth"
   1088 #define	IPSYNC_NAME	"/dev/ipsync"
   1089 #define	IPSCAN_NAME	"/dev/ipscan"
   1090 #define	IPLOOKUP_NAME	"/dev/iplookup"
   1091 
   1092 #define	IPL_LOGIPF	0	/* Minor device #'s for accessing logs */
   1093 #define	IPL_LOGNAT	1
   1094 #define	IPL_LOGSTATE	2
   1095 #define	IPL_LOGAUTH	3
   1096 #define	IPL_LOGSYNC	4
   1097 #define	IPL_LOGSCAN	5
   1098 #define	IPL_LOGLOOKUP	6
   1099 #define	IPL_LOGCOUNT	7
   1100 #define	IPL_LOGMAX	7
   1101 #define	IPL_LOGSIZE	IPL_LOGMAX + 1
   1102 #define	IPL_LOGALL	-1
   1103 #define	IPL_LOGNONE	-2
   1104 
   1105 /*
   1106  * For SIOCGETFS
   1107  */
   1108 typedef	struct	friostat	{
   1109 	ipf_statistics_t f_st[2];
   1110 	frentry_t	*f_ipf[2][2];
   1111 	frentry_t	*f_acct[2][2];
   1112 	frentry_t	*f_auth;
   1113 	struct frgroup	*f_groups[IPL_LOGSIZE][2];
   1114 	u_long		f_froute[2];
   1115 	u_long		f_log_ok;
   1116 	u_long		f_log_fail;
   1117 	u_long		f_rb_no_mem;
   1118 	u_long		f_rb_node_max;
   1119 	u_32_t		f_ticks;
   1120 	int		f_locks[IPL_LOGSIZE];
   1121 	int		f_defpass;	/* default pass - from fr_pass */
   1122 	int		f_active;	/* 1 or 0 - active rule set */
   1123 	int		f_running;	/* 1 if running, else 0 */
   1124 	int		f_logging;	/* 1 if enabled, else 0 */
   1125 	int		f_features;
   1126 	char		f_version[32];	/* version string */
   1127 } friostat_t;
   1128 
   1129 #define	f_fin		f_ipf[0]
   1130 #define	f_fout		f_ipf[1]
   1131 #define	f_acctin	f_acct[0]
   1132 #define	f_acctout	f_acct[1]
   1133 
   1134 #define	IPF_FEAT_LKM		0x001
   1135 #define	IPF_FEAT_LOG		0x002
   1136 #define	IPF_FEAT_LOOKUP		0x004
   1137 #define	IPF_FEAT_BPF		0x008
   1138 #define	IPF_FEAT_COMPILED	0x010
   1139 #define	IPF_FEAT_CKSUM		0x020
   1140 #define	IPF_FEAT_SYNC		0x040
   1141 #define	IPF_FEAT_SCAN		0x080
   1142 #define	IPF_FEAT_IPV6		0x100
   1143 
   1144 typedef struct	optlist {
   1145 	u_short ol_val;
   1146 	int	ol_bit;
   1147 } optlist_t;
   1148 
   1149 
   1150 /*
   1151  * Group list structure.
   1152  */
   1153 typedef	struct frgroup {
   1154 	struct frgroup	*fg_next;
   1155 	struct frentry	*fg_head;
   1156 	struct frentry	*fg_start;
   1157 	struct frgroup	**fg_set;
   1158 	u_32_t		fg_flags;
   1159 	int		fg_ref;
   1160 	char		fg_name[FR_GROUPLEN];
   1161 } frgroup_t;
   1162 
   1163 #define	FG_NAME(g)	(*(g)->fg_name == '\0' ? "" : (g)->fg_name)
   1164 
   1165 
   1166 /*
   1167  * Used by state and NAT tables
   1168  */
   1169 typedef struct icmpinfo {
   1170 	u_short		ici_id;
   1171 	u_short		ici_seq;
   1172 	u_char		ici_type;
   1173 } icmpinfo_t;
   1174 
   1175 typedef struct udpinfo {
   1176 	u_short		us_sport;
   1177 	u_short		us_dport;
   1178 } udpinfo_t;
   1179 
   1180 
   1181 typedef	struct	tcpdata	{
   1182 	u_32_t		td_end;
   1183 	u_32_t		td_maxend;
   1184 	u_32_t		td_maxwin;
   1185 	u_32_t		td_winscale;
   1186 	u_32_t		td_maxseg;
   1187 	int		td_winflags;
   1188 } tcpdata_t;
   1189 
   1190 #define	TCP_WSCALE_MAX		14
   1191 
   1192 #define	TCP_WSCALE_SEEN		0x00000001
   1193 #define	TCP_WSCALE_FIRST	0x00000002
   1194 #define	TCP_SACK_PERMIT		0x00000004
   1195 
   1196 
   1197 typedef	struct tcpinfo {
   1198 	u_32_t		ts_sport;
   1199 	u_32_t		ts_dport;
   1200 	tcpdata_t	ts_data[2];
   1201 } tcpinfo_t;
   1202 
   1203 
   1204 /*
   1205  * Structures to define a GRE header as seen in a packet.
   1206  */
   1207 struct	grebits	{
   1208 #if defined(sparc)
   1209 	u_32_t		grb_ver:3;
   1210 	u_32_t		grb_flags:3;
   1211 	u_32_t		grb_A:1;
   1212 	u_32_t		grb_recur:1;
   1213 	u_32_t		grb_s:1;
   1214 	u_32_t		grb_S:1;
   1215 	u_32_t		grb_K:1;
   1216 	u_32_t		grb_R:1;
   1217 	u_32_t		grb_C:1;
   1218 #else
   1219 	u_32_t		grb_C:1;
   1220 	u_32_t		grb_R:1;
   1221 	u_32_t		grb_K:1;
   1222 	u_32_t		grb_S:1;
   1223 	u_32_t		grb_s:1;
   1224 	u_32_t		grb_recur:1;
   1225 	u_32_t		grb_A:1;
   1226 	u_32_t		grb_flags:3;
   1227 	u_32_t		grb_ver:3;
   1228 #endif
   1229 	u_short		grb_ptype;
   1230 };
   1231 
   1232 typedef	struct	grehdr	{
   1233 	union	{
   1234 		struct	grebits	gru_bits;
   1235 		u_short	gru_flags;
   1236 	} gr_un;
   1237 	u_short		gr_len;
   1238 	u_short		gr_call;
   1239 } grehdr_t;
   1240 
   1241 #define	gr_flags	gr_un.gru_flags
   1242 #define	gr_bits		gr_un.gru_bits
   1243 #define	gr_ptype	gr_bits.grb_ptype
   1244 #define	gr_C		gr_bits.grb_C
   1245 #define	gr_R		gr_bits.grb_R
   1246 #define	gr_K		gr_bits.grb_K
   1247 #define	gr_S		gr_bits.grb_S
   1248 #define	gr_s		gr_bits.grb_s
   1249 #define	gr_recur	gr_bits.grb_recur
   1250 #define	gr_A		gr_bits.grb_A
   1251 #define	gr_ver		gr_bits.grb_ver
   1252 
   1253 /*
   1254  * GRE information tracked by "keep state"
   1255  */
   1256 typedef	struct	greinfo	{
   1257 	u_short		gs_call[2];
   1258 	u_short		gs_flags;
   1259 	u_short		gs_ptype;
   1260 } greinfo_t;
   1261 
   1262 #define	GRE_REV(x)	((ntohs(x) >> 13) & 7)
   1263 
   1264 
   1265 /*
   1266  * Format of an Authentication header
   1267  */
   1268 typedef	struct	authhdr	{
   1269 	u_char		ah_next;
   1270 	u_char		ah_plen;
   1271 	u_short		ah_reserved;
   1272 	u_32_t		ah_spi;
   1273 	u_32_t		ah_seq;
   1274 	/* Following the sequence number field is 0 or more bytes of */
   1275 	/* authentication data, as specified by ah_plen - RFC 2402.  */
   1276 } authhdr_t;
   1277 
   1278 
   1279 /*
   1280  * Timeout tail queue list member
   1281  */
   1282 typedef	struct	ipftqent	{
   1283 	struct ipftqent **tqe_pnext;
   1284 	struct ipftqent *tqe_next;
   1285 	struct	ipftq	*tqe_ifq;
   1286 	void		*tqe_parent;	/* pointer back to NAT/state struct */
   1287 	u_32_t		tqe_die;	/* when this entriy is to die */
   1288 	u_32_t		tqe_touched;
   1289 	int		tqe_flags;
   1290 	int		tqe_state[2];	/* current state of this entry */
   1291 } ipftqent_t;
   1292 
   1293 #define	TQE_RULEBASED	0x00000001
   1294 #define	TQE_DELETE	0x00000002
   1295 
   1296 
   1297 /*
   1298  * Timeout tail queue head for IPFilter
   1299  */
   1300 typedef struct  ipftq   {
   1301 	ipfmutex_t	ifq_lock;
   1302 	u_int		ifq_ttl;
   1303 	ipftqent_t	*ifq_head;
   1304 	ipftqent_t	**ifq_tail;
   1305 	struct ipftq	*ifq_next;
   1306 	struct ipftq	**ifq_pnext;
   1307 	int		ifq_ref;
   1308 	u_int		ifq_flags;
   1309 } ipftq_t;
   1310 
   1311 #define	IFQF_USER	0x01		/* User defined aging */
   1312 #define	IFQF_DELETE	0x02		/* Marked for deletion */
   1313 #define	IFQF_PROXY	0x04		/* Timeout queue in use by a proxy */
   1314 
   1315 #define	IPFTQ_INIT(x,y,z)	do {			\
   1316 					(x)->ifq_ttl = (y);	\
   1317 					(x)->ifq_head = NULL;	\
   1318 					(x)->ifq_ref = 1;	\
   1319 					(x)->ifq_tail = &(x)->ifq_head; \
   1320 					MUTEX_INIT(&(x)->ifq_lock, (z)); \
   1321 				} while (0)
   1322 
   1323 #define	IPF_HZ_MULT	1
   1324 #define	IPF_HZ_DIVIDE	2		/* How many times a second ipfilter */
   1325 					/* checks its timeout queues.       */
   1326 #define	IPF_TTLVAL(x)	(((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE)
   1327 
   1328 typedef	int	(*ipftq_delete_fn_t)(struct ipf_main_softc_s *, void *);
   1329 
   1330 
   1331 /*
   1332  * Object structure description.  For passing through in ioctls.
   1333  */
   1334 typedef	struct	ipfobj	{
   1335 	u_32_t		ipfo_rev;	/* IPFilter version number */
   1336 	u_32_t		ipfo_size;	/* size of object at ipfo_ptr */
   1337 	void		*ipfo_ptr;	/* pointer to object */
   1338 	int		ipfo_type;	/* type of object being pointed to */
   1339 	int		ipfo_offset;	/* bytes from ipfo_ptr where to start */
   1340 	int		ipfo_retval;	/* return value */
   1341 	u_char		ipfo_xxxpad[28];	/* reserved for future use */
   1342 } ipfobj_t;
   1343 
   1344 #define	IPFOBJ_FRENTRY		0	/* struct frentry */
   1345 #define	IPFOBJ_IPFSTAT		1	/* struct friostat */
   1346 #define	IPFOBJ_IPFINFO		2	/* struct fr_info */
   1347 #define	IPFOBJ_AUTHSTAT		3	/* struct fr_authstat */
   1348 #define	IPFOBJ_FRAGSTAT		4	/* struct ipfrstat */
   1349 #define	IPFOBJ_IPNAT		5	/* struct ipnat */
   1350 #define	IPFOBJ_NATSTAT		6	/* struct natstat */
   1351 #define	IPFOBJ_STATESAVE	7	/* struct ipstate_save */
   1352 #define	IPFOBJ_NATSAVE		8	/* struct nat_save */
   1353 #define	IPFOBJ_NATLOOKUP	9	/* struct natlookup */
   1354 #define	IPFOBJ_IPSTATE		10	/* struct ipstate */
   1355 #define	IPFOBJ_STATESTAT	11	/* struct ips_stat */
   1356 #define	IPFOBJ_FRAUTH		12	/* struct frauth */
   1357 #define	IPFOBJ_TUNEABLE		13	/* struct ipftune */
   1358 #define	IPFOBJ_NAT		14	/* struct nat */
   1359 #define	IPFOBJ_IPFITER		15	/* struct ipfruleiter */
   1360 #define	IPFOBJ_GENITER		16	/* struct ipfgeniter */
   1361 #define	IPFOBJ_GTABLE		17	/* struct ipftable */
   1362 #define	IPFOBJ_LOOKUPITER	18	/* struct ipflookupiter */
   1363 #define	IPFOBJ_STATETQTAB	19	/* struct ipftq * NSTATES */
   1364 #define	IPFOBJ_IPFEXPR		20
   1365 #define	IPFOBJ_PROXYCTL		21	/* strct ap_ctl */
   1366 #define	IPFOBJ_FRIPF		22	/* structfripf */
   1367 #define	IPFOBJ_COUNT		23	/* How many #defines are above this? */
   1368 
   1369 
   1370 typedef	union	ipftunevalptr	{
   1371 	void		*ipftp_void;
   1372 	u_long		*ipftp_long;
   1373 	u_int		*ipftp_int;
   1374 	u_short		*ipftp_short;
   1375 	u_char		*ipftp_char;
   1376 	u_long		ipftp_offset;
   1377 } ipftunevalptr_t;
   1378 
   1379 typedef	union	ipftuneval	{
   1380 	u_long		ipftu_long;
   1381 	u_int		ipftu_int;
   1382 	u_short		ipftu_short;
   1383 	u_char		ipftu_char;
   1384 } ipftuneval_t;
   1385 
   1386 struct ipftuneable;
   1387 typedef	int (* ipftunefunc_t)(struct ipf_main_softc_s *, struct ipftuneable *,
   1388     ipftuneval_t *);
   1389 
   1390 typedef	struct	ipftuneable	{
   1391 	ipftunevalptr_t	ipft_una;
   1392 	const char	*ipft_name;
   1393 	u_long		ipft_min;
   1394 	u_long		ipft_max;
   1395 	int		ipft_sz;
   1396 	int		ipft_flags;
   1397 	struct ipftuneable *ipft_next;
   1398 	ipftunefunc_t	ipft_func;
   1399 } ipftuneable_t;
   1400 
   1401 #define	ipft_addr	ipft_una.ipftp_void
   1402 #define	ipft_plong	ipft_una.ipftp_long
   1403 #define	ipft_pint	ipft_una.ipftp_int
   1404 #define	ipft_pshort	ipft_una.ipftp_short
   1405 #define	ipft_pchar	ipft_una.ipftp_char
   1406 
   1407 #define	IPFT_RDONLY	1	/* read-only */
   1408 #define	IPFT_WRDISABLED	2	/* write when disabled only */
   1409 
   1410 typedef	struct	ipftune	{
   1411 	void    	*ipft_cookie;
   1412 	ipftuneval_t	ipft_un;
   1413 	u_long  	ipft_min;
   1414 	u_long  	ipft_max;
   1415 	int		ipft_sz;
   1416 	int		ipft_flags;
   1417 	char		ipft_name[80];
   1418 } ipftune_t;
   1419 
   1420 #define	ipft_vlong	ipft_un.ipftu_long
   1421 #define	ipft_vint	ipft_un.ipftu_int
   1422 #define	ipft_vshort	ipft_un.ipftu_short
   1423 #define	ipft_vchar	ipft_un.ipftu_char
   1424 
   1425 /*
   1426  * Hash table header
   1427  */
   1428 #define	IPFHASH(x,y)	typedef struct { 			\
   1429 				ipfrwlock_t	ipfh_lock;	\
   1430 				struct	x	*ipfh_head;	\
   1431 				} y
   1432 
   1433 /*
   1434 ** HPUX Port
   1435 */
   1436 #ifdef __hpux
   1437 /* HP-UX locking sequence deadlock detection module lock MAJOR ID */
   1438 # define	IPF_SMAJ	0	/* temp assignment XXX, not critical */
   1439 #endif
   1440 
   1441 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \
   1442     (__FreeBSD_version >= 220000)
   1443 # define	CDEV_MAJOR	79
   1444 #endif
   1445 
   1446 /*
   1447  * Post NetBSD 1.2 has the PFIL interface for packet filters.  This turns
   1448  * on those hooks.  We don't need any special mods in non-IP Filter code
   1449  * with this!
   1450  */
   1451 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \
   1452     (defined(NetBSD1_2) && NetBSD1_2 > 1) || \
   1453     (defined(__FreeBSD__) && (__FreeBSD_version >= 500043))
   1454 # if (NetBSD >= 199905)
   1455 #  define PFIL_HOOKS
   1456 # endif
   1457 # ifdef PFIL_HOOKS
   1458 #  define NETBSD_PF
   1459 # endif
   1460 #endif
   1461 
   1462 #ifdef _KERNEL
   1463 # define	FR_VERBOSE(verb_pr)
   1464 # define	FR_DEBUG(verb_pr)
   1465 #else
   1466 extern	void	ipfkdebug(char *, ...);
   1467 extern	void	ipfkverbose(char *, ...);
   1468 # define	FR_VERBOSE(verb_pr)	ipfkverbose verb_pr
   1469 # define	FR_DEBUG(verb_pr)	ipfkdebug verb_pr
   1470 #endif
   1471 
   1472 /*
   1473  *
   1474  */
   1475 typedef	struct	ipfruleiter {
   1476 	int		iri_inout;
   1477 	char		iri_group[FR_GROUPLEN];
   1478 	int		iri_active;
   1479 	int		iri_nrules;
   1480 	int		iri_v;		/* No longer used (compatibility) */
   1481 	frentry_t	*iri_rule;
   1482 } ipfruleiter_t;
   1483 
   1484 /*
   1485  * Values for iri_inout
   1486  */
   1487 #define	F_IN	0
   1488 #define	F_OUT	1
   1489 #define	F_ACIN	2
   1490 #define	F_ACOUT	3
   1491 
   1492 
   1493 typedef	struct	ipfgeniter {
   1494 	int	igi_type;
   1495 	int	igi_nitems;
   1496 	void	*igi_data;
   1497 } ipfgeniter_t;
   1498 
   1499 #define	IPFGENITER_IPF		0
   1500 #define	IPFGENITER_NAT		1
   1501 #define	IPFGENITER_IPNAT	2
   1502 #define	IPFGENITER_FRAG		3
   1503 #define	IPFGENITER_AUTH		4
   1504 #define	IPFGENITER_STATE	5
   1505 #define	IPFGENITER_NATFRAG	6
   1506 #define	IPFGENITER_HOSTMAP	7
   1507 #define	IPFGENITER_LOOKUP	8
   1508 
   1509 typedef	struct	ipftable {
   1510 	int	ita_type;
   1511 	void	*ita_table;
   1512 } ipftable_t;
   1513 
   1514 #define	IPFTABLE_BUCKETS	1
   1515 #define	IPFTABLE_BUCKETS_NATIN	2
   1516 #define	IPFTABLE_BUCKETS_NATOUT	3
   1517 
   1518 
   1519 typedef struct ipf_v4_masktab_s {
   1520 	u_32_t	imt4_active[33];
   1521 	int	imt4_masks[33];
   1522 	int	imt4_max;
   1523 } ipf_v4_masktab_t;
   1524 
   1525 typedef struct ipf_v6_masktab_s {
   1526 	i6addr_t	imt6_active[129];
   1527 	int		imt6_masks[129];
   1528 	int		imt6_max;
   1529 } ipf_v6_masktab_t;
   1530 
   1531 
   1532 /*
   1533  *
   1534  */
   1535 typedef struct ipftoken {
   1536 	struct ipftoken	*ipt_next;
   1537 	struct ipftoken	**ipt_pnext;
   1538 	void		*ipt_ctx;
   1539 	void		*ipt_data;
   1540 	u_long		ipt_die;
   1541 	int		ipt_type;
   1542 	int		ipt_uid;
   1543 	int		ipt_subtype;
   1544 	int		ipt_ref;
   1545 	int		ipt_complete;
   1546 } ipftoken_t;
   1547 
   1548 
   1549 /*
   1550  *
   1551  */
   1552 typedef struct ipfexp {
   1553 	int		ipfe_cmd;
   1554 	int		ipfe_not;
   1555 	int		ipfe_narg;
   1556 	int		ipfe_size;
   1557 	int		ipfe_arg0[1];
   1558 } ipfexp_t;
   1559 
   1560 /*
   1561  * Currently support commands (ipfe_cmd)
   1562  * 32bits is split up follows:
   1563  * aabbcccc
   1564  * aa = 0 = packet matching, 1 = meta data matching
   1565  * bb = IP protocol number
   1566  * cccc = command
   1567  */
   1568 #define	IPF_EXP_IP_PR		0x00000001
   1569 #define	IPF_EXP_IP_ADDR		0x00000002
   1570 #define	IPF_EXP_IP_SRCADDR	0x00000003
   1571 #define	IPF_EXP_IP_DSTADDR	0x00000004
   1572 #define	IPF_EXP_IP6_ADDR	0x00000005
   1573 #define	IPF_EXP_IP6_SRCADDR	0x00000006
   1574 #define	IPF_EXP_IP6_DSTADDR	0x00000007
   1575 #define	IPF_EXP_TCP_FLAGS	0x00060001
   1576 #define	IPF_EXP_TCP_PORT	0x00060002
   1577 #define	IPF_EXP_TCP_SPORT	0x00060003
   1578 #define	IPF_EXP_TCP_DPORT	0x00060004
   1579 #define	IPF_EXP_UDP_PORT	0x00110002
   1580 #define	IPF_EXP_UDP_SPORT	0x00110003
   1581 #define	IPF_EXP_UDP_DPORT	0x00110004
   1582 #define	IPF_EXP_IDLE_GT		0x01000001
   1583 #define	IPF_EXP_TCP_STATE	0x01060002
   1584 #define	IPF_EXP_END		0xffffffff
   1585 
   1586 #define	ONE_DAY			IPF_TTLVAL(1 * 86400)   /* 1 day */
   1587 #define	FIVE_DAYS		(5 * ONE_DAY)
   1588 
   1589 typedef struct ipf_main_softc_s {
   1590 	struct ipf_main_softc_s *ipf_next;
   1591 	ipfmutex_t	ipf_rw;
   1592 	ipfmutex_t      ipf_timeoutlock;
   1593 	ipfrwlock_t     ipf_mutex;
   1594 	ipfrwlock_t	ipf_frag;
   1595 	ipfrwlock_t	ipf_global;
   1596 	ipfrwlock_t	ipf_tokens;
   1597 	ipfrwlock_t	ipf_state;
   1598 	ipfrwlock_t	ipf_nat;
   1599 	ipfrwlock_t	ipf_natfrag;
   1600 	ipfrwlock_t	ipf_poolrw;
   1601 	int		ipf_dynamic_softc;
   1602 	int		ipf_refcnt;
   1603 	int		ipf_running;
   1604 	int		ipf_flags;
   1605 	int		ipf_active;
   1606 	int		ipf_control_forwarding;
   1607 	int		ipf_update_ipid;
   1608 	int		ipf_chksrc;	/* causes a system crash if enabled */
   1609 	int		ipf_pass;
   1610 	int		ipf_minttl;
   1611 	int		ipf_icmpminfragmtu;
   1612 	int		ipf_interror;	/* Should be in a struct that is per  */
   1613 					/* thread or process. Does not belong */
   1614 					/* here but there's a lot more work   */
   1615 					/* in doing that properly. For now,   */
   1616 					/* it is squatting. */
   1617 	u_int		ipf_tcpidletimeout;
   1618 	u_int		ipf_tcpclosewait;
   1619 	u_int		ipf_tcplastack;
   1620 	u_int		ipf_tcptimewait;
   1621 	u_int		ipf_tcptimeout;
   1622 	u_int		ipf_tcpsynsent;
   1623 	u_int		ipf_tcpsynrecv;
   1624 	u_int		ipf_tcpclosed;
   1625 	u_int		ipf_tcphalfclosed;
   1626 	u_int		ipf_udptimeout;
   1627 	u_int		ipf_udpacktimeout;
   1628 	u_int		ipf_icmptimeout;
   1629 	u_int		ipf_icmpacktimeout;
   1630 	u_int		ipf_iptimeout;
   1631 	u_long		ipf_ticks;
   1632 	u_long		ipf_userifqs;
   1633 	u_long		ipf_rb_no_mem;
   1634 	u_long		ipf_rb_node_max;
   1635 	u_long		ipf_frouteok[2];
   1636 	ipftuneable_t	*ipf_tuners;
   1637 	void		*ipf_frag_soft;
   1638 	void		*ipf_nat_soft;
   1639 	void		*ipf_state_soft;
   1640 	void		*ipf_auth_soft;
   1641 	void		*ipf_proxy_soft;
   1642 	void		*ipf_sync_soft;
   1643 	void		*ipf_lookup_soft;
   1644 	void		*ipf_log_soft;
   1645 	struct frgroup	*ipf_groups[IPL_LOGSIZE][2];
   1646 	frentry_t	*ipf_rules[2][2];
   1647 	frentry_t	*ipf_acct[2][2];
   1648 	frentry_t	*ipf_rule_explist[2];
   1649 	ipftoken_t	*ipf_token_head;
   1650 	ipftoken_t	**ipf_token_tail;
   1651 #if defined(__FreeBSD_version) && (__FreeBSD_version >= 300000) && \
   1652     defined(_KERNEL)
   1653 	struct callout_handle ipf_slow_ch;
   1654 #endif
   1655 #if defined(linux) && defined(_KERNEL)
   1656 	struct timer_list	ipf_timer;
   1657 #endif
   1658 #if NETBSD_GE_REV(104040000)
   1659 	struct callout	ipf_slow_ch;
   1660 #endif
   1661 #if SOLARIS
   1662 # if SOLARIS2 >= 7
   1663 	timeout_id_t	ipf_slow_ch;
   1664 # else
   1665 	int		ipf_slow_ch;
   1666 # endif
   1667 #endif
   1668 #if defined(_KERNEL)
   1669 # if SOLARIS
   1670 	struct pollhead	ipf_poll_head[IPL_LOGSIZE];
   1671 	void		*ipf_dip;
   1672 #  if defined(INSTANCES)
   1673 	int		ipf_get_loopback;
   1674 	u_long		ipf_idnum;
   1675 	net_handle_t	ipf_nd_v4;
   1676 	net_handle_t	ipf_nd_v6;
   1677 	hook_t		*ipf_hk_v4_in;
   1678 	hook_t		*ipf_hk_v4_out;
   1679 	hook_t		*ipf_hk_v4_nic;
   1680 	hook_t		*ipf_hk_v6_in;
   1681 	hook_t		*ipf_hk_v6_out;
   1682 	hook_t		*ipf_hk_v6_nic;
   1683 	hook_t		*ipf_hk_loop_v4_in;
   1684 	hook_t		*ipf_hk_loop_v4_out;
   1685 	hook_t		*ipf_hk_loop_v6_in;
   1686 	hook_t		*ipf_hk_loop_v6_out;
   1687 #  endif
   1688 # else
   1689 #  if defined(linux) && defined(_KERNEL)
   1690 	struct poll_table_struct	ipf_selwait[IPL_LOGSIZE];
   1691 	wait_queue_head_t		iplh_linux[IPL_LOGSIZE];
   1692 #  else
   1693 	struct selinfo	ipf_selwait[IPL_LOGSIZE];
   1694 #  endif
   1695 # endif
   1696 #endif
   1697 	void		*ipf_slow;
   1698 	ipf_statistics_t ipf_stats[2];
   1699 	u_char		ipf_iss_secret[32];
   1700 	u_short		ipf_ip_id;
   1701 } ipf_main_softc_t;
   1702 
   1703 #define	IPFERROR(_e)	do { softc->ipf_interror = (_e); \
   1704 			     DT1(user_error, int, _e); \
   1705 			} while (0)
   1706 
   1707 #ifndef	_KERNEL
   1708 extern	int	ipf_check(void *, struct ip *, int, void *, int, mb_t **);
   1709 extern	int	(*ipf_checkp)(ip_t *, int, void *, int, mb_t **);
   1710 extern	struct	ifnet *get_unit(char *, int);
   1711 extern	char	*get_ifname(struct ifnet *);
   1712 extern	int	ipfioctl(ipf_main_softc_t *, int, ioctlcmd_t,
   1713 			      void *, int);
   1714 extern	void	m_freem(mb_t *);
   1715 extern	size_t	msgdsize(mb_t *);
   1716 extern	int	bcopywrap(void *, void *, size_t);
   1717 #else /* #ifndef _KERNEL */
   1718 # if defined(__NetBSD__) && defined(PFIL_HOOKS)
   1719 extern	void	ipfilterattach(int);
   1720 # endif
   1721 extern	int	ipl_enable(void);
   1722 extern	int	ipl_disable(void);
   1723 # ifdef MENTAT
   1724 extern	int	ipf_check(void *, struct ip *, int, void *, int, void *,
   1725 			       mblk_t **);
   1726 #  if SOLARIS
   1727 extern	void	ipf_prependmbt(fr_info_t *, mblk_t *);
   1728 #   if SOLARIS2 >= 7
   1729 extern	int	ipfioctl(dev_t, int, intptr_t, int, cred_t *, int *);
   1730 #   else
   1731 extern	int	ipfioctl(dev_t, int, int *, int, cred_t *, int *);
   1732 #   endif
   1733 #  endif
   1734 #  ifdef __hpux
   1735 extern	int	ipfioctl(dev_t, int, caddr_t, int);
   1736 extern	int	ipf_select(dev_t, int);
   1737 #  endif
   1738 extern	int	ipf_qout(queue_t *, mblk_t *);
   1739 # else /* MENTAT */
   1740 extern	int	ipf_check(void *, struct ip *, int, void *, int, mb_t **);
   1741 extern	int	(*fr_checkp)(ip_t *, int, void *, int, mb_t **);
   1742 extern	size_t	mbufchainlen(mb_t *);
   1743 #  ifdef	__sgi
   1744 #   include <sys/cred.h>
   1745 extern	int	ipfioctl(dev_t, int, caddr_t, int, cred_t *, int *);
   1746 extern	int	ipfilter_sgi_attach(void);
   1747 extern	void	ipfilter_sgi_detach(void);
   1748 extern	void	ipfilter_sgi_intfsync(void);
   1749 #  else
   1750 #   ifdef	IPFILTER_LKM
   1751 extern	int	ipf_identify(char *);
   1752 #   endif
   1753 #   if BSDOS_GE_REV(199510) || FREEBSD_GE_REV(220000) || \
   1754       (defined(NetBSD) && (NetBSD >= 199511)) || defined(__OpenBSD__)
   1755 #    if defined(__NetBSD__) || BSDOS_GE_REV(199701) || \
   1756        defined(__OpenBSD__) || FREEBSD_GE_REV(300000)
   1757 #     if (__FreeBSD_version >= 500024)
   1758 #      if (__FreeBSD_version >= 502116)
   1759 extern	int	ipfioctl(struct cdev*, u_long, caddr_t, int, struct thread *);
   1760 #      else
   1761 extern	int	ipfioctl(dev_t, u_long, caddr_t, int, struct thread *);
   1762 #      endif /* __FreeBSD_version >= 502116 */
   1763 #     else
   1764 #      if  NETBSD_GE_REV(499001000)
   1765 extern	int	ipfioctl(dev_t, u_long, void *, int, struct lwp *);
   1766 #       else
   1767 #       if  NETBSD_GE_REV(399001400)
   1768 extern	int	ipfioctl(dev_t, u_long, caddr_t, int, struct lwp *);
   1769 #       else
   1770 extern	int	ipfioctl(dev_t, u_long, caddr_t, int, struct proc *);
   1771 #       endif
   1772 #      endif
   1773 #     endif /* __FreeBSD_version >= 500024 */
   1774 #    else
   1775 extern	int	ipfioctl(dev_t, int, caddr_t, int, struct proc *);
   1776 #    endif
   1777 #   else
   1778 #    ifdef linux
   1779 extern	int	ipfioctl(struct inode *, struct file *, u_int, u_long);
   1780 #    else
   1781 extern	int	ipfioctl(dev_t, int, caddr_t, int);
   1782 #    endif
   1783 #   endif /* (_BSDI_VERSION >= 199510) */
   1784 #  endif /* __ sgi */
   1785 # endif /* MENTAT */
   1786 
   1787 # if defined(__FreeBSD_version)
   1788 extern	int	ipf_pfil_hook(void);
   1789 extern	int	ipf_pfil_unhook(void);
   1790 extern	void	ipf_event_reg(void);
   1791 extern	void	ipf_event_dereg(void);
   1792 # endif
   1793 
   1794 # if defined(INSTANCES)
   1795 extern	ipf_main_softc_t	*ipf_find_softc(u_long);
   1796 extern	int	ipf_set_loopback(ipf_main_softc_t *, ipftuneable_t *,
   1797 				      ipftuneval_t *);
   1798 # endif
   1799 
   1800 #endif /* #ifndef _KERNEL */
   1801 
   1802 extern	char	*memstr(const char *, char *, size_t, size_t);
   1803 extern	int	count4bits(u_32_t);
   1804 #ifdef USE_INET6
   1805 extern	int	count6bits(u_32_t *);
   1806 #endif
   1807 extern	int	frrequest(ipf_main_softc_t *, int, ioctlcmd_t, void *,
   1808 			       int, int);
   1809 extern	char	*getifname(struct ifnet *);
   1810 extern	int	ipfattach(ipf_main_softc_t *);
   1811 extern	int	ipfdetach(ipf_main_softc_t *);
   1812 extern	u_short	ipf_cksum(u_short *, int);
   1813 extern	int	copyinptr(ipf_main_softc_t *, void *, void *, size_t);
   1814 extern	int	copyoutptr(ipf_main_softc_t *, void *, void *, size_t);
   1815 extern	int	ipf_fastroute(mb_t *, mb_t **, fr_info_t *, frdest_t *);
   1816 extern	int	ipf_inject(fr_info_t *, mb_t *);
   1817 extern	int	ipf_inobj(ipf_main_softc_t *, void *, ipfobj_t *,
   1818 			       void *, int);
   1819 extern	int	ipf_inobjsz(ipf_main_softc_t *, void *, void *,
   1820 				 int , int);
   1821 extern	int	ipf_ioctlswitch(ipf_main_softc_t *, int, void *,
   1822 				     ioctlcmd_t, int, int, void *);
   1823 extern	int	ipf_ipf_ioctl(ipf_main_softc_t *, void *, ioctlcmd_t,
   1824 				   int, int, void *);
   1825 extern	int	ipf_ipftune(ipf_main_softc_t *, ioctlcmd_t, void *);
   1826 extern	int	ipf_matcharray_load(ipf_main_softc_t *, void *,
   1827 					 ipfobj_t *, int **);
   1828 extern	int	ipf_matcharray_verify(int *, int);
   1829 extern	int	ipf_outobj(ipf_main_softc_t *, void *, void *, int);
   1830 extern	int	ipf_outobjk(ipf_main_softc_t *, ipfobj_t *, void *);
   1831 extern	int	ipf_outobjsz(ipf_main_softc_t *, void *, void *,
   1832 				  int, int);
   1833 extern	void	*ipf_pullup(mb_t *, fr_info_t *, int);
   1834 extern	int	ipf_resolvedest(ipf_main_softc_t *, char *,
   1835 				     struct frdest *, int);
   1836 extern	int	ipf_resolvefunc(ipf_main_softc_t *, void *);
   1837 extern	void	*ipf_resolvenic(ipf_main_softc_t *, char *, int);
   1838 extern	int	ipf_send_icmp_err(int, fr_info_t *, int);
   1839 extern	int	ipf_send_reset(fr_info_t *);
   1840 #if  (defined(__FreeBSD_version) && (__FreeBSD_version < 501000)) || \
   1841      !defined(_KERNEL) || defined(linux)
   1842 extern	int	ppsratecheck(struct timeval *, int *, int);
   1843 #endif
   1844 extern	void	ipf_apply_timeout(ipftq_t *, u_int);
   1845 extern	ipftq_t	*ipf_addtimeoutqueue(ipf_main_softc_t *, ipftq_t **,
   1846 					  u_int);
   1847 extern	void	ipf_deletequeueentry(ipftqent_t *);
   1848 extern	int	ipf_deletetimeoutqueue(ipftq_t *);
   1849 extern	void	ipf_freetimeoutqueue(ipf_main_softc_t *, ipftq_t *);
   1850 extern	void	ipf_movequeue(u_long, ipftqent_t *, ipftq_t *,
   1851 				   ipftq_t *);
   1852 extern	void	ipf_queueappend(u_long, ipftqent_t *, ipftq_t *, void *);
   1853 extern	void	ipf_queueback(u_long, ipftqent_t *);
   1854 extern	int	ipf_queueflush(ipf_main_softc_t *, ipftq_delete_fn_t,
   1855 				    ipftq_t *, ipftq_t *, u_int *, int, int);
   1856 extern	void	ipf_queuefront(ipftqent_t *);
   1857 extern	int	ipf_settimeout_tcp(ipftuneable_t *, ipftuneval_t *,
   1858 					ipftq_t *);
   1859 extern	int	ipf_checkv4sum(fr_info_t *);
   1860 extern	int	ipf_checkl4sum(fr_info_t *);
   1861 extern	int	ipf_ifpfillv4addr(int, struct sockaddr_in *,
   1862 				      struct sockaddr_in *, struct in_addr *,
   1863 				      struct in_addr *);
   1864 extern	int	ipf_coalesce(fr_info_t *);
   1865 #ifdef	USE_INET6
   1866 extern	int	ipf_checkv6sum(fr_info_t *);
   1867 extern	int	ipf_ifpfillv6addr(int, struct sockaddr_in6 *,
   1868 				      struct sockaddr_in6 *, i6addr_t *,
   1869 				      i6addr_t *);
   1870 #endif
   1871 
   1872 extern	int	ipf_tune_add(ipf_main_softc_t *, ipftuneable_t *);
   1873 extern	int	ipf_tune_add_array(ipf_main_softc_t *, ipftuneable_t *);
   1874 extern	int	ipf_tune_del(ipf_main_softc_t *, ipftuneable_t *);
   1875 extern	int	ipf_tune_del_array(ipf_main_softc_t *, ipftuneable_t *);
   1876 extern	int	ipf_tune_array_link(ipf_main_softc_t *, ipftuneable_t *);
   1877 extern	int	ipf_tune_array_unlink(ipf_main_softc_t *,
   1878 					   ipftuneable_t *);
   1879 extern	ipftuneable_t *ipf_tune_array_copy(void *, size_t,
   1880 						ipftuneable_t *);
   1881 
   1882 extern int	ipf_pr_pullup(fr_info_t *, int);
   1883 
   1884 extern	int	ipf_flush(ipf_main_softc_t *, minor_t, int);
   1885 extern	frgroup_t *ipf_group_add(ipf_main_softc_t *, char *, void *,
   1886 				      u_32_t, minor_t, int);
   1887 extern	void	ipf_group_del(ipf_main_softc_t *, frgroup_t *, frentry_t *);
   1888 extern	int	ipf_derefrule(ipf_main_softc_t *, frentry_t **);
   1889 extern	frgroup_t *ipf_findgroup(ipf_main_softc_t *, char *, minor_t,
   1890 				      int, frgroup_t ***);
   1891 
   1892 extern	int	ipf_log_init(void);
   1893 extern	int	ipf_log_bytesused(ipf_main_softc_t *, int);
   1894 extern	int	ipf_log_canread(ipf_main_softc_t *, int);
   1895 extern	int	ipf_log_clear(ipf_main_softc_t *, minor_t);
   1896 extern	u_long  ipf_log_failures(ipf_main_softc_t *, int);
   1897 extern	int	ipf_log_read(ipf_main_softc_t *, minor_t, uio_t *);
   1898 extern	int	ipf_log_items(ipf_main_softc_t *, int, fr_info_t *,
   1899 				   void **, size_t *, int *, int);
   1900 extern	u_long  ipf_log_logok(ipf_main_softc_t *, int);
   1901 extern	void	ipf_log_unload(ipf_main_softc_t *);
   1902 extern	int 	ipf_log_pkt(fr_info_t *, u_int);
   1903 extern	int 	ipf_log_pkt(fr_info_t *, u_int);
   1904 
   1905 extern	frentry_t	*ipf_acctpkt(fr_info_t *, u_32_t *);
   1906 extern	u_short		fr_cksum(fr_info_t *, ip_t *, int, void *);
   1907 extern	void		ipf_deinitialise(ipf_main_softc_t *);
   1908 extern	int		ipf_deliverlocal(ipf_main_softc_t *, int, void *,
   1909 					      i6addr_t *);
   1910 extern	frentry_t 	*ipf_dstgrpmap(fr_info_t *, u_32_t *);
   1911 extern	void		ipf_fixskip(frentry_t **, frentry_t *, int);
   1912 extern	void		ipf_forgetifp(ipf_main_softc_t *, void *);
   1913 extern	frentry_t 	*ipf_getrulen(ipf_main_softc_t *, int, char *,
   1914 					   u_32_t);
   1915 extern	int		ipf_ifpaddr(ipf_main_softc_t *, int, int, void *,
   1916 					i6addr_t *, i6addr_t *);
   1917 extern	int		ipf_initialise(void);
   1918 extern	int		ipf_lock(void *, int *);
   1919 extern  int		ipf_makefrip(int, ip_t *, fr_info_t *);
   1920 extern	void		ipf_inet_mask_add(int, ipf_v4_masktab_t *);
   1921 extern	void		ipf_inet_mask_del(int, ipf_v4_masktab_t *);
   1922 #ifdef	USE_INET6
   1923 extern	void		ipf_inet6_mask_add(int, i6addr_t *, ipf_v6_masktab_t *);
   1924 extern	void		ipf_inet6_mask_del(int, i6addr_t *, ipf_v6_masktab_t *);
   1925 #endif
   1926 extern	int		ipf_matchtag(ipftag_t *, ipftag_t *);
   1927 extern	int		ipf_matchicmpqueryreply(int, icmpinfo_t *,
   1928 						     struct icmp *, int);
   1929 extern	u_32_t		ipf_newisn(fr_info_t *);
   1930 extern	u_short		ipf_nextipid(fr_info_t *);
   1931 extern	u_int		ipf_pcksum(fr_info_t *, int, u_int);
   1932 extern	void		ipf_rule_expire(ipf_main_softc_t *);
   1933 extern	int		ipf_scanlist(fr_info_t *, u_32_t);
   1934 extern	frentry_t 	*ipf_srcgrpmap(fr_info_t *, u_32_t *);
   1935 extern	int		ipf_tcpudpchk(fr_ip_t *, frtuc_t *);
   1936 extern	int		ipf_verifysrc(fr_info_t *fin);
   1937 extern	int		ipf_zerostats(ipf_main_softc_t *, void *);
   1938 extern	int		ipf_getnextrule(ipf_main_softc_t *, ipftoken_t *,
   1939 					     void *);
   1940 extern	int		ipf_sync(ipf_main_softc_t *, void *);
   1941 extern	int		ipf_token_deref(ipf_main_softc_t *, ipftoken_t *);
   1942 extern	void		ipf_token_expire(ipf_main_softc_t *);
   1943 extern	ipftoken_t	*ipf_token_find(ipf_main_softc_t *, int, int,
   1944 					    void *);
   1945 extern	void		ipf_token_free(ipf_main_softc_t *, ipftoken_t *);
   1946 extern	int		ipf_token_del(ipf_main_softc_t *, int, int,
   1947 					  void *);
   1948 extern	void		ipf_token_mark_complete(ipftoken_t *);
   1949 extern	int		ipf_genericiter(ipf_main_softc_t *, void *,
   1950 					     int, void *);
   1951 #ifdef	IPFILTER_LOOKUP
   1952 extern	void		*ipf_resolvelookup(int, u_int, u_int,
   1953 						lookupfunc_t *);
   1954 #endif
   1955 extern	u_32_t		ipf_random(void);
   1956 
   1957 extern	int		ipf_main_load(void);
   1958 extern	void		*ipf_main_soft_create(void *);
   1959 extern	void		ipf_main_soft_destroy(ipf_main_softc_t *);
   1960 extern	int		ipf_main_soft_init(ipf_main_softc_t *);
   1961 extern	int		ipf_main_soft_fini(ipf_main_softc_t *);
   1962 extern	int		ipf_main_unload(void);
   1963 extern	int		ipf_load_all(void);
   1964 extern	int		ipf_unload_all(void);
   1965 extern	void		ipf_destroy_all(ipf_main_softc_t *);
   1966 extern	ipf_main_softc_t *ipf_create_all(void *);
   1967 extern	int		ipf_init_all(ipf_main_softc_t *);
   1968 extern	int		ipf_fini_all(ipf_main_softc_t *);
   1969 extern	void		ipf_log_soft_destroy(ipf_main_softc_t *, void *);
   1970 extern	void		*ipf_log_soft_create(ipf_main_softc_t *);
   1971 extern	int		ipf_log_soft_init(ipf_main_softc_t *, void *);
   1972 extern	int		ipf_log_soft_fini(ipf_main_softc_t *, void *);
   1973 extern	int		ipf_log_main_load(void);
   1974 extern	int		ipf_log_main_unload(void);
   1975 
   1976 
   1977 extern	char	ipfilter_version[];
   1978 #ifdef	USE_INET6
   1979 extern	int	icmptoicmp6types[ICMP_MAXTYPE+1];
   1980 extern	int	icmptoicmp6unreach[ICMP_MAX_UNREACH];
   1981 extern	int	icmpreplytype6[ICMP6_MAXTYPE + 1];
   1982 #endif
   1983 #ifdef	IPFILTER_COMPAT
   1984 extern	int	ipf_in_compat(ipf_main_softc_t *, ipfobj_t *, void *,int);
   1985 extern	int	ipf_out_compat(ipf_main_softc_t *, ipfobj_t *, void *);
   1986 #endif
   1987 extern	int	icmpreplytype4[ICMP_MAXTYPE + 1];
   1988 
   1989 extern	int	ipf_ht_node_add(ipf_main_softc_t *, host_track_t *,
   1990 				     int, i6addr_t *);
   1991 extern	int	ipf_ht_node_del(host_track_t *, int, i6addr_t *);
   1992 extern	void	ipf_rb_ht_flush(host_track_t *);
   1993 extern	void	ipf_rb_ht_freenode(host_node_t *, void *);
   1994 extern	void	ipf_rb_ht_init(host_track_t *);
   1995 
   1996 #endif /* _NETINET_IP_FIL_H_ */
   1997