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