1 /*
2  * Copyright (C) 1993-2001, 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * @(#)ip_fil.h	1.35 6/5/96
7  * $Id: ip_fil.h,v 2.170.2.22 2005/07/16 05:55:35 darrenr Exp $
8  *
9  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
10  * Use is subject to license terms.
11  */
12 
13 #pragma ident	"%Z%%M%	%I%	%E% SMI"
14 
15 #ifndef	__IP_FIL_H__
16 #define	__IP_FIL_H__
17 
18 #include "netinet/ip_compat.h"
19 
20 #ifndef	SOLARIS
21 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
22 #endif
23 
24 #ifndef	__P
25 # ifdef	__STDC__
26 #  define	__P(x)	x
27 # else
28 #  define	__P(x)	()
29 # endif
30 #endif
31 
32 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
33 # define	SIOCADAFR	_IOW('r', 60, struct ipfobj)
34 # define	SIOCRMAFR	_IOW('r', 61, struct ipfobj)
35 # define	SIOCSETFF	_IOW('r', 62, u_int)
36 # define	SIOCGETFF	_IOR('r', 63, u_int)
37 # define	SIOCGETFS	_IOWR('r', 64, struct ipfobj)
38 # define	SIOCIPFFL	_IOWR('r', 65, int)
39 # define	SIOCIPFFB	_IOR('r', 66, int)
40 # define	SIOCADIFR	_IOW('r', 67, struct ipfobj)
41 # define	SIOCRMIFR	_IOW('r', 68, struct ipfobj)
42 # define	SIOCSWAPA	_IOR('r', 69, u_int)
43 # define	SIOCINAFR	_IOW('r', 70, struct ipfobj)
44 # define	SIOCINIFR	_IOW('r', 71, struct ipfobj)
45 # define	SIOCFRENB	_IOW('r', 72, u_int)
46 # define	SIOCFRSYN	_IOW('r', 73, u_int)
47 # define	SIOCFRZST	_IOWR('r', 74, struct ipfobj)
48 # define	SIOCZRLST	_IOWR('r', 75, struct ipfobj)
49 # define	SIOCAUTHW	_IOWR('r', 76, struct ipfobj)
50 # define	SIOCAUTHR	_IOWR('r', 77, struct ipfobj)
51 # define	SIOCATHST	_IOWR('r', 78, struct ipfobj)
52 # define	SIOCSTLCK	_IOWR('r', 79, u_int)
53 # define	SIOCSTPUT	_IOWR('r', 80, struct ipfobj)
54 # define	SIOCSTGET	_IOWR('r', 81, struct ipfobj)
55 # define	SIOCSTGSZ	_IOWR('r', 82, struct ipfobj)
56 # define	SIOCGFRST	_IOWR('r', 83, struct ipfobj)
57 # define	SIOCSETLG	_IOWR('r', 84, int)
58 # define	SIOCGETLG	_IOWR('r', 85, int)
59 # define	SIOCFUNCL	_IOWR('r', 86, struct ipfunc_resolve)
60 # define	SIOCIPFGETNEXT	_IOWR('r', 87, struct ipfobj)
61 # define	SIOCIPFGET	_IOWR('r', 88, struct ipfobj)
62 # define	SIOCIPFSET	_IOWR('r', 89, struct ipfobj)
63 # define	SIOCIPFL6	_IOWR('r', 90, int)
64 # define	SIOCIPFLP	_IOWR('r', 91, int)
65 # define	SIOCIPFITER	_IOWR('r', 92, struct ipfobj)
66 # define	SIOCGENITER	_IOWR('r', 93, struct ipfobj)
67 # define	SIOCGTABL	_IOWR('r', 94, struct ipfobj)
68 # define	SIOCIPFDELTOK	_IOWR('r', 95, int)
69 # define	SIOCLOOKUPITER	_IOWR('r', 96, struct ipfobj)
70 #else
71 # define	SIOCADAFR	_IOW(r, 60, struct ipfobj)
72 # define	SIOCRMAFR	_IOW(r, 61, struct ipfobj)
73 # define	SIOCSETFF	_IOW(r, 62, u_int)
74 # define	SIOCGETFF	_IOR(r, 63, u_int)
75 # define	SIOCGETFS	_IOWR(r, 64, struct ipfobj)
76 # define	SIOCIPFFL	_IOWR(r, 65, int)
77 # define	SIOCIPFFB	_IOR(r, 66, int)
78 # define	SIOCADIFR	_IOW(r, 67, struct ipfobj)
79 # define	SIOCRMIFR	_IOW(r, 68, struct ipfobj)
80 # define	SIOCSWAPA	_IOR(r, 69, u_int)
81 # define	SIOCINAFR	_IOW(r, 70, struct ipfobj)
82 # define	SIOCINIFR	_IOW(r, 71, struct ipfobj)
83 # define	SIOCFRENB	_IOW(r, 72, u_int)
84 # define	SIOCFRSYN	_IOW(r, 73, u_int)
85 # define	SIOCFRZST	_IOWR(r, 74, struct ipfobj)
86 # define	SIOCZRLST	_IOWR(r, 75, struct ipfobj)
87 # define	SIOCAUTHW	_IOWR(r, 76, struct ipfobj)
88 # define	SIOCAUTHR	_IOWR(r, 77, struct ipfobj)
89 # define	SIOCATHST	_IOWR(r, 78, struct ipfobj)
90 # define	SIOCSTLCK	_IOWR(r, 79, u_int)
91 # define	SIOCSTPUT	_IOWR(r, 80, struct ipfobj)
92 # define	SIOCSTGET	_IOWR(r, 81, struct ipfobj)
93 # define	SIOCSTGSZ	_IOWR(r, 82, struct ipfobj)
94 # define	SIOCGFRST	_IOWR(r, 83, struct ipfobj)
95 # define	SIOCSETLG	_IOWR(r, 84, int)
96 # define	SIOCGETLG	_IOWR(r, 85, int)
97 # define	SIOCFUNCL	_IOWR(r, 86, struct ipfunc_resolve)
98 # define	SIOCIPFGETNEXT	_IOWR(r, 87, struct ipfobj)
99 # define	SIOCIPFGET	_IOWR(r, 88, struct ipfobj)
100 # define	SIOCIPFSET	_IOWR(r, 89, struct ipfobj)
101 # define	SIOCIPFL6	_IOWR(r, 90, int)
102 # define	SIOCIPFLP	_IOWR(r, 91, int)
103 # define	SIOCIPFITER	_IOWR(r, 92, struct ipfobj)
104 # define	SIOCGENITER	_IOWR(r, 93, struct ipfobj)
105 # define	SIOCGTABL	_IOWR(r, 94, struct ipfobj)
106 # define	SIOCIPFDELTOK	_IOWR(r, 95, int)
107 # define	SIOCLOOKUPITER	_IOWR(r, 96, struct ipfobj)
108 #endif
109 #define	SIOCADDFR	SIOCADAFR
110 #define	SIOCDELFR	SIOCRMAFR
111 #define	SIOCINSFR	SIOCINAFR
112 
113 
114 struct ipscan;
115 struct ifnet;
116 
117 typedef struct ipf_stack ipf_stack_t;
118 
119 typedef	int	(* lookupfunc_t) __P((void *, int, void *, ipf_stack_t *));
120 
121 
122 /*
123  * i6addr is used as a container for both IPv4 and IPv6 addresses, as well
124  * as other types of objects, depending on its qualifier.
125  */
126 #ifdef	USE_INET6
127 typedef	union	i6addr	{
128 	u_32_t	i6[4];
129 	struct	in_addr	in4;
130 	struct	in6_addr in6;
131 	void	*vptr[2];
132 	lookupfunc_t	lptr[2];
133 } i6addr_t;
134 #define	in6_addr8	in6.s6_addr
135 #else
136 typedef	union	i6addr	{
137 	u_32_t	i6[4];
138 	struct	in_addr	in4;
139 	void	*vptr[2];
140 	lookupfunc_t	lptr[2];
141 } i6addr_t;
142 #endif
143 
144 #define	in4_addr	in4.s_addr
145 #define	iplookupnum	i6[0]
146 #define	iplookuptype	i6[1]
147 /*
148  * NOTE: These DO overlap the above on 64bit systems and this IS recognised.
149  */
150 #define	iplookupptr	vptr[0]
151 #define	iplookupfunc	lptr[1]
152 
153 #define	I60(x)	(((i6addr_t *)(x))->i6[0])
154 #define	I61(x)	(((i6addr_t *)(x))->i6[1])
155 #define	I62(x)	(((i6addr_t *)(x))->i6[2])
156 #define	I63(x)	(((i6addr_t *)(x))->i6[3])
157 #define	HI60(x)	ntohl(((i6addr_t *)(x))->i6[0])
158 #define	HI61(x)	ntohl(((i6addr_t *)(x))->i6[1])
159 #define	HI62(x)	ntohl(((i6addr_t *)(x))->i6[2])
160 #define	HI63(x)	ntohl(((i6addr_t *)(x))->i6[3])
161 
162 #define	IP6_EQ(a,b)	((I63(a) == I63(b)) && (I62(a) == I62(b)) && \
163 			 (I61(a) == I61(b)) && (I60(a) == I60(b)))
164 #define	IP6_NEQ(a,b)	((I63(a) != I63(b)) || (I62(a) != I62(b)) || \
165 			 (I61(a) != I61(b)) || (I60(a) != I60(b)))
166 #define	IP6_ISZERO(a)   ((I60(a) | I61(a) | I62(a) | I63(a)) == 0)
167 #define IP6_NOTZERO(a)  ((I60(a) | I61(a) | I62(a) | I63(a)) != 0)
168 #define	IP6_ISONES(a)	((I63(a) == 0xffffffff) && (I62(a) == 0xffffffff) && \
169 			 (I61(a) == 0xffffffff) && (I60(a) == 0xffffffff))
170 #define	IP6_GT(a,b)	(ntohl(HI60(a)) > ntohl(HI60(b)) || \
171 			 (HI60(a) == HI60(b) && \
172 			  (ntohl(HI61(a)) > ntohl(HI61(b)) || \
173 			   (HI61(a) == HI61(b) && \
174 			    (ntohl(HI62(a)) > ntohl(HI62(b)) || \
175 			     (HI62(a) == HI62(b) && \
176 			      ntohl(HI63(a)) > ntohl(HI63(b))))))))
177 #define	IP6_LT(a,b)	(ntohl(HI60(a)) < ntohl(HI60(b)) || \
178 			 (HI60(a) == HI60(b) && \
179 			  (ntohl(HI61(a)) < ntohl(HI61(b)) || \
180 			   (HI61(a) == HI61(b) && \
181 			    (ntohl(HI62(a)) < ntohl(HI62(b)) || \
182 			     (HI62(a) == HI62(b) && \
183 			      ntohl(HI63(a)) < ntohl(HI63(b))))))))
184 #define	NLADD(n,x)	htonl(ntohl(n) + (x))
185 #define	IP6_INC(a)	\
186 		{ i6addr_t *_i6 = (i6addr_t *)(a); \
187 		  _i6->i6[3] = NLADD(_i6->i6[3], 1); \
188 		  if (_i6->i6[3] == 0) { \
189 			_i6->i6[2] = NLADD(_i6->i6[2], 1); \
190 			if (_i6->i6[2] == 0) { \
191 				_i6->i6[1] = NLADD(_i6->i6[1], 1); \
192 				if (_i6->i6[1] == 0) { \
193 					_i6->i6[0] = NLADD(_i6->i6[0], 1); \
194 				} \
195 			} \
196 		  } \
197 		}
198 #define	IP6_ADD(a,x,d)	\
199 		{ i6addr_t *_s = (i6addr_t *)(a); \
200 		  i6addr_t *_d = (i6addr_t *)(d); \
201 		  _d->i6[3] = NLADD(_s->i6[3], x); \
202 		  if (ntohl(_d->i6[3]) < ntohl(_s->i6[3])) { \
203 			_d->i6[2] = NLADD(_d->i6[2], 1); \
204 			if (ntohl(_d->i6[2]) < ntohl(_s->i6[2])) { \
205 				_d->i6[1] = NLADD(_d->i6[1], 1); \
206 				if (ntohl(_d->i6[1]) < ntohl(_s->i6[1])) { \
207 					_d->i6[0] = NLADD(_d->i6[0], 1); \
208 				} \
209 			} \
210 		  } \
211 		}
212 #define	IP6_AND(a,b,d)	{ i6addr_t *_s1 = (i6addr_t *)(a); \
213 			  i6addr_t *_s2 = (i6addr_t *)(b); \
214 			  i6addr_t *_d = (i6addr_t *)(d); \
215 			  _d->i6[0] = _s1->i6[0] & _s2->i6[0]; \
216 			  _d->i6[1] = _s1->i6[1] & _s2->i6[1]; \
217 			  _d->i6[2] = _s1->i6[2] & _s2->i6[2]; \
218 			  _d->i6[3] = _s1->i6[3] & _s2->i6[3]; \
219 			}
220 #define	IP6_MASKEQ(a,m,b) \
221 			(((I60(a) & I60(m)) == I60(b)) && \
222 			 ((I61(a) & I61(m)) == I61(b)) && \
223 			 ((I62(a) & I62(m)) == I62(b)) && \
224 			 ((I63(a) & I63(m)) == I63(b)))
225 #define	IP6_MASKNEQ(a,m,b) \
226 			(((I60(a) & I60(m)) != I60(b)) || \
227 			 ((I61(a) & I61(m)) != I61(b)) || \
228 			 ((I62(a) & I62(m)) != I62(b)) || \
229 			 ((I63(a) & I63(m)) != I63(b)))
230 #define	IP6_MERGE(a,b,c) \
231 			{ i6addr_t *_d, *_s1, *_s2; \
232 			  _d = (i6addr_t *)(a); \
233 			  _s1 = (i6addr_t *)(b); \
234 			  _s2 = (i6addr_t *)(c); \
235 			  _d->i6[0] |= _s1->i6[0] & ~_s2->i6[0]; \
236 			  _d->i6[1] |= _s1->i6[1] & ~_s2->i6[1]; \
237 			  _d->i6[2] |= _s1->i6[2] & ~_s2->i6[2]; \
238 			  _d->i6[3] |= _s1->i6[3] & ~_s2->i6[3]; \
239 			}
240 
241 
242 typedef	struct	fr_ip	{
243 	u_32_t	fi_v:4;		/* IP version */
244 	u_32_t	fi_xx:4;	/* spare */
245 	u_32_t	fi_tos:8;	/* IP packet TOS */
246 	u_32_t	fi_ttl:8;	/* IP packet TTL */
247 	u_32_t	fi_p:8;		/* IP packet protocol */
248 	u_32_t	fi_optmsk;	/* bitmask composed from IP options */
249 	i6addr_t fi_src;	/* source address from packet */
250 	i6addr_t fi_dst;	/* destination address from packet */
251 	u_short	fi_secmsk;	/* bitmask composed from IP security options */
252 	u_short	fi_auth;	/* authentication code from IP sec. options */
253 	u_32_t	fi_flx;		/* packet flags */
254 	u_32_t	fi_tcpmsk;	/* TCP options set/reset */
255 	u_32_t	fi_res1;	/* RESERVED */
256 } fr_ip_t;
257 
258 /*
259  * For use in fi_flx
260  */
261 #define	FI_MULTICAST	0x0001
262 #define	FI_BROADCAST	0x0002
263 #define	FI_FRAG		0x0004
264 #define	FI_SHORT	0x0008
265 #define	FI_NATED	0x0010
266 #define	FI_TCPUDP	0x0020	/* TCP/UCP implied comparison*/
267 #define	FI_OPTIONS	0x0040
268 #define	FI_MBCAST	0x0080
269 #define	FI_STATE	0x0100
270 #define	FI_BADNAT	0x0200
271 #define	FI_BAD		0x0400
272 #define	FI_OOW		0x0800	/* Out of state window, else match */
273 #define	FI_ICMPERR	0x1000
274 #define	FI_FRAGBODY	0x2000
275 #define	FI_BADSRC	0x4000
276 #define	FI_LOWTTL	0x8000
277 #define	FI_CMP		0xcfe3	/* Not FI_FRAG,FI_NATED,FI_FRAGTAIL */
278 #define	FI_ICMPCMP	0x0003	/* Flags we can check for ICMP error packets */
279 #define	FI_WITH		0xeffe	/* Not FI_TCPUDP */
280 #define	FI_V6EXTHDR	0x10000
281 #define	FI_COALESCE	0x20000
282 #define	FI_ICMPQUERY	0x40000
283 #define	FI_NOCKSUM	0x20000000	/* don't do a L4 checksum validation */
284 #define	FI_DONTCACHE	0x40000000	/* don't cache the result */
285 #define	FI_IGNORE	0x80000000
286 
287 #define	fi_saddr	fi_src.in4.s_addr
288 #define	fi_daddr	fi_dst.in4.s_addr
289 #define	fi_srcnum	fi_src.iplookupnum
290 #define	fi_dstnum	fi_dst.iplookupnum
291 #define	fi_srctype	fi_src.iplookuptype
292 #define	fi_dsttype	fi_dst.iplookuptype
293 #define	fi_srcptr	fi_src.iplookupptr
294 #define	fi_dstptr	fi_dst.iplookupptr
295 #define	fi_srcfunc	fi_src.iplookupfunc
296 #define	fi_dstfunc	fi_dst.iplookupfunc
297 
298 
299 /*
300  * These are both used by the state and NAT code to indicate that one port or
301  * the other should be treated as a wildcard.
302  * NOTE: When updating, check bit masks in ip_state.h and update there too.
303  */
304 #define	SI_W_SPORT	0x00000100
305 #define	SI_W_DPORT	0x00000200
306 #define	SI_WILDP	(SI_W_SPORT|SI_W_DPORT)
307 #define	SI_W_SADDR	0x00000400
308 #define	SI_W_DADDR	0x00000800
309 #define	SI_WILDA	(SI_W_SADDR|SI_W_DADDR)
310 #define	SI_NEWFR	0x00001000
311 #define	SI_CLONE	0x00002000
312 #define	SI_CLONED	0x00004000
313 
314 
315 
316 
317 typedef	struct	fr_info	{
318 	void	*fin_ifp;		/* interface packet is `on' */
319 	fr_ip_t	fin_fi;		/* IP Packet summary */
320 	union	{
321 		u_short	fid_16[2];	/* TCP/UDP ports, ICMP code/type */
322 		u_32_t	fid_32;
323 	} fin_dat;
324 	int	fin_out;		/* in or out ? 1 == out, 0 == in */
325 	int	fin_rev;		/* state only: 1 = reverse */
326 	u_short	fin_hlen;		/* length of IP header in bytes */
327 	u_char	fin_tcpf;		/* TCP header flags (SYN, ACK, etc) */
328 	u_char	fin_icode;		/* ICMP error to return */
329 	u_32_t	fin_rule;		/* rule # last matched */
330 	char	fin_group[FR_GROUPLEN];	/* group number, -1 for none */
331 	struct	frentry *fin_fr;	/* last matching rule */
332 	void	*fin_dp;		/* start of data past IP header */
333 	int	fin_dlen;		/* length of data portion of packet */
334 	int	fin_plen;
335 	int	fin_flen;		/* length of layer 4 hdr and
336 					   ipv6 ext hdr after fragment hdr */
337 	int	fin_ipoff;		/* # bytes from buffer start to hdr */
338 	u_32_t	fin_id;			/* IP packet id field */
339 	u_short	fin_off;
340 	int	fin_depth;		/* Group nesting depth */
341 	int	fin_error;		/* Error code to return */
342 	void	*fin_nat;
343 	void	*fin_state;
344 	void	*fin_nattag;
345 	union {
346 		ip_t	*fip_ip;
347 #ifdef	USE_INET6
348 		ip6_t	*fip_ip6;
349 #endif
350 	} fin_ipu;
351 	mb_t	**fin_mp;		/* pointer to pointer to mbuf */
352 	mb_t	*fin_m;			/* pointer to mbuf */
353 #ifdef	MENTAT
354 	mb_t	*fin_qfm;		/* pointer to mblk where pkt starts */
355 	void	*fin_qpi;
356 	ipf_stack_t *fin_ifs;
357 #endif
358 #ifdef	__sgi
359 	void	*fin_hbuf;
360 #endif
361 } fr_info_t;
362 
363 #define	fin_ip		fin_ipu.fip_ip
364 #define	fin_ip6		fin_ipu.fip_ip6
365 #define	fin_v		fin_fi.fi_v
366 #define	fin_p		fin_fi.fi_p
367 #define	fin_flx		fin_fi.fi_flx
368 #define	fin_optmsk	fin_fi.fi_optmsk
369 #define	fin_secmsk	fin_fi.fi_secmsk
370 #define	fin_auth	fin_fi.fi_auth
371 #define	fin_src		fin_fi.fi_src.in4
372 #define	fin_saddr	fin_fi.fi_saddr
373 #define	fin_dst		fin_fi.fi_dst.in4
374 #define	fin_daddr	fin_fi.fi_daddr
375 #define	fin_data	fin_dat.fid_16
376 #define	fin_sport	fin_dat.fid_16[0]
377 #define	fin_dport	fin_dat.fid_16[1]
378 #define	fin_ports	fin_dat.fid_32
379 
380 #ifdef	USE_INET6
381 # define	fin_src6	fin_fi.fi_src
382 # define	fin_dst6	fin_fi.fi_dst
383 # define	fin_dstip6	fin_fi.fi_dst.in6
384 # define	fin_srcip6	fin_fi.fi_src.in6
385 #endif
386 
387 #define	IPF_IN	0
388 #define	IPF_OUT	1
389 
390 typedef	struct frentry	*(*ipfunc_t) __P((fr_info_t *, u_32_t *));
391 typedef	int		(*ipfuncinit_t) __P((struct frentry *,
392 					     ipf_stack_t *));
393 
394 typedef	struct	ipfunc_resolve	{
395 	char		ipfu_name[32];
396 	ipfunc_t	ipfu_addr;
397 	ipfuncinit_t	ipfu_init;
398 } ipfunc_resolve_t;
399 
400 /*
401  * Size for compares on fr_info structures
402  */
403 #define	FI_CSIZE	offsetof(fr_info_t, fin_icode)
404 #define	FI_LCSIZE	offsetof(fr_info_t, fin_dp)
405 
406 /*
407  * Size for copying cache fr_info structure
408  */
409 #define	FI_COPYSIZE	offsetof(fr_info_t, fin_dp)
410 
411 /*
412  * Structure for holding IPFilter's tag information
413  */
414 #define	IPFTAG_LEN	16
415 typedef	struct	{
416 	union	{
417 		u_32_t	iptu_num[4];
418 		char	iptu_tag[IPFTAG_LEN];
419 	} ipt_un;
420 	int	ipt_not;
421 } ipftag_t;
422 
423 #define	ipt_tag	ipt_un.iptu_tag
424 #define	ipt_num	ipt_un.iptu_num
425 
426 
427 /*
428  * This structure is used to hold information about the next hop for where
429  * to forward a packet.
430  */
431 typedef	struct	frdest	{
432 	void	*fd_ifp;
433 	i6addr_t	fd_ip6;
434 	char	fd_ifname[LIFNAMSIZ];
435 } frdest_t;
436 
437 #define	fd_ip	fd_ip6.in4
438 
439 
440 /*
441  * This structure holds information about a port comparison.
442  */
443 typedef	struct	frpcmp	{
444 	int	frp_cmp;	/* data for port comparisons */
445 	u_short	frp_port;	/* top port for <> and >< */
446 	u_short	frp_top;	/* top port for <> and >< */
447 } frpcmp_t;
448 
449 #define FR_NONE 0
450 #define FR_EQUAL 1
451 #define FR_NEQUAL 2
452 #define FR_LESST 3
453 #define FR_GREATERT 4
454 #define FR_LESSTE 5
455 #define FR_GREATERTE 6
456 #define FR_OUTRANGE 7
457 #define FR_INRANGE 8
458 #define FR_INCRANGE 9
459 
460 /*
461  * Structure containing all the relevant TCP things that can be checked in
462  * a filter rule.
463  */
464 typedef	struct	frtuc	{
465 	u_char		ftu_tcpfm;	/* tcp flags mask */
466 	u_char		ftu_tcpf;	/* tcp flags */
467 	frpcmp_t	ftu_src;
468 	frpcmp_t	ftu_dst;
469 } frtuc_t;
470 
471 #define	ftu_scmp	ftu_src.frp_cmp
472 #define	ftu_dcmp	ftu_dst.frp_cmp
473 #define	ftu_sport	ftu_src.frp_port
474 #define	ftu_dport	ftu_dst.frp_port
475 #define	ftu_stop	ftu_src.frp_top
476 #define	ftu_dtop	ftu_dst.frp_top
477 
478 #define	FR_TCPFMAX	0x3f
479 
480 /*
481  * This structure makes up what is considered to be the IPFilter specific
482  * matching components of a filter rule, as opposed to the data structures
483  * used to define the result which are in frentry_t and not here.
484  */
485 typedef	struct	fripf	{
486 	fr_ip_t	fri_ip;
487 	fr_ip_t	fri_mip;	/* mask structure */
488 
489 	u_short	fri_icmpm;		/* data for ICMP packets (mask) */
490 	u_short	fri_icmp;
491 
492 	frtuc_t	fri_tuc;
493 	int	fri_satype;		/* addres type */
494 	int	fri_datype;		/* addres type */
495 	int	fri_sifpidx;		/* doing dynamic addressing */
496 	int	fri_difpidx;		/* index into fr_ifps[] to use when */
497 } fripf_t;
498 
499 #define	fri_dstnum	fri_ip.fi_dstnum
500 #define	fri_srcnum	fri_mip.fi_srcnum
501 #define	fri_dstptr	fri_ip.fi_dstptr
502 #define	fri_srcptr	fri_mip.fi_srcptr
503 
504 #define	FRI_NORMAL	0	/* Normal address */
505 #define	FRI_DYNAMIC	1	/* dynamic address */
506 #define	FRI_LOOKUP	2	/* address is a pool # */
507 #define	FRI_RANGE	3	/* address/mask is a range */
508 #define	FRI_NETWORK	4	/* network address from if */
509 #define	FRI_BROADCAST	5	/* broadcast address from if */
510 #define	FRI_PEERADDR	6	/* Peer address for P-to-P */
511 #define	FRI_NETMASKED	7	/* network address with netmask from if */
512 
513 
514 typedef	struct	frentry	* (* frentfunc_t) __P((fr_info_t *));
515 
516 typedef	struct	frentry {
517 	ipfmutex_t	fr_lock;
518 	struct	frentry	*fr_next;
519 	struct	frentry	**fr_grp;
520 	struct	ipscan	*fr_isc;
521 	void	*fr_ifas[4];
522 	void	*fr_ptr;	/* for use with fr_arg */
523 	char	*fr_comment;	/* text comment for rule */
524 	int	fr_ref;		/* reference count - for grouping */
525 	int	fr_statecnt;	/* state count - for limit rules */
526 	/*
527 	 * These are only incremented when a packet  matches this rule and
528 	 * it is the last match
529 	 */
530 	U_QUAD_T	fr_hits;
531 	U_QUAD_T	fr_bytes;
532 
533 	/*
534 	 * For PPS rate limiting
535 	 */
536 	struct timeval	fr_lastpkt;
537 	int		fr_curpps;
538 
539 	union	{
540 		void		*fru_data;
541 		caddr_t		fru_caddr;
542 		fripf_t		*fru_ipf;
543 		frentfunc_t	fru_func;
544 	} fr_dun;
545 
546 	/*
547 	 * Fields after this may not change whilst in the kernel.
548 	 */
549 	ipfunc_t fr_func; 	/* call this function */
550 	int	fr_dsize;
551 	int	fr_pps;
552 	int	fr_statemax;	/* max reference count */
553 	int	fr_flineno;	/* line number from conf file */
554 	u_32_t	fr_type;
555 	u_32_t	fr_flags;	/* per-rule flags && options (see below) */
556 	u_32_t	fr_logtag;	/* user defined log tag # */
557 	u_32_t	fr_collect;	/* collection number */
558 	u_int	fr_arg;		/* misc. numeric arg for rule */
559 	u_int	fr_loglevel;	/* syslog log facility + priority */
560 	u_int	fr_age[2];	/* non-TCP timeouts */
561 	u_char	fr_v;
562 	u_char	fr_icode;	/* return ICMP code */
563 	char	fr_group[FR_GROUPLEN];	/* group to which this rule belongs */
564 	char	fr_grhead[FR_GROUPLEN];	/* group # which this rule starts */
565 	ipftag_t fr_nattag;
566 	char	fr_ifnames[4][LIFNAMSIZ];
567 	char	fr_isctag[16];
568 	frdest_t fr_tifs[2];	/* "to"/"reply-to" interface */
569 	frdest_t fr_dif;	/* duplicate packet interface */
570 	/*
571 	 * This must be last and will change after loaded into the kernel.
572 	 */
573 	u_int	fr_cksum;	/* checksum on filter rules for performance */
574 } frentry_t;
575 
576 #define	fr_caddr	fr_dun.fru_caddr
577 #define	fr_data		fr_dun.fru_data
578 #define	fr_dfunc	fr_dun.fru_func
579 #define	fr_ipf		fr_dun.fru_ipf
580 #define	fr_ip		fr_ipf->fri_ip
581 #define	fr_mip		fr_ipf->fri_mip
582 #define	fr_icmpm	fr_ipf->fri_icmpm
583 #define	fr_icmp		fr_ipf->fri_icmp
584 #define	fr_tuc		fr_ipf->fri_tuc
585 #define	fr_satype	fr_ipf->fri_satype
586 #define	fr_datype	fr_ipf->fri_datype
587 #define	fr_sifpidx	fr_ipf->fri_sifpidx
588 #define	fr_difpidx	fr_ipf->fri_difpidx
589 #define	fr_proto	fr_ip.fi_p
590 #define	fr_mproto	fr_mip.fi_p
591 #define	fr_ttl		fr_ip.fi_ttl
592 #define	fr_mttl		fr_mip.fi_ttl
593 #define	fr_tos		fr_ip.fi_tos
594 #define	fr_mtos		fr_mip.fi_tos
595 #define	fr_tcpfm	fr_tuc.ftu_tcpfm
596 #define	fr_tcpf		fr_tuc.ftu_tcpf
597 #define	fr_scmp		fr_tuc.ftu_scmp
598 #define	fr_dcmp		fr_tuc.ftu_dcmp
599 #define	fr_dport	fr_tuc.ftu_dport
600 #define	fr_sport	fr_tuc.ftu_sport
601 #define	fr_stop		fr_tuc.ftu_stop
602 #define	fr_dtop		fr_tuc.ftu_dtop
603 #define	fr_dst		fr_ip.fi_dst.in4
604 #define	fr_daddr	fr_ip.fi_dst.in4.s_addr
605 #define	fr_src		fr_ip.fi_src.in4
606 #define	fr_saddr	fr_ip.fi_src.in4.s_addr
607 #define	fr_dmsk		fr_mip.fi_dst.in4
608 #define	fr_dmask	fr_mip.fi_dst.in4.s_addr
609 #define	fr_smsk		fr_mip.fi_src.in4
610 #define	fr_smask	fr_mip.fi_src.in4.s_addr
611 #define	fr_dstnum	fr_ip.fi_dstnum
612 #define	fr_srcnum	fr_ip.fi_srcnum
613 #define	fr_dsttype	fr_ip.fi_dsttype
614 #define	fr_srctype	fr_ip.fi_srctype
615 #define	fr_dstptr	fr_mip.fi_dstptr
616 #define	fr_srcptr	fr_mip.fi_srcptr
617 #define	fr_dstfunc	fr_mip.fi_dstfunc
618 #define	fr_srcfunc	fr_mip.fi_srcfunc
619 #define	fr_optbits	fr_ip.fi_optmsk
620 #define	fr_optmask	fr_mip.fi_optmsk
621 #define	fr_secbits	fr_ip.fi_secmsk
622 #define	fr_secmask	fr_mip.fi_secmsk
623 #define	fr_authbits	fr_ip.fi_auth
624 #define	fr_authmask	fr_mip.fi_auth
625 #define	fr_flx		fr_ip.fi_flx
626 #define	fr_mflx		fr_mip.fi_flx
627 #define	fr_ifname	fr_ifnames[0]
628 #define	fr_oifname	fr_ifnames[2]
629 #define	fr_ifa		fr_ifas[0]
630 #define	fr_oifa		fr_ifas[2]
631 #define	fr_tif		fr_tifs[0]
632 #define	fr_rif		fr_tifs[1]
633 
634 #define	FR_NOLOGTAG	0
635 
636 #ifndef	offsetof
637 #define	offsetof(t,m)	(int)((&((t *)0L)->m))
638 #endif
639 #define	FR_CMPSIZ	(sizeof(struct frentry) - \
640 			 offsetof(struct frentry, fr_func))
641 
642 /*
643  * fr_type
644  */
645 #define	FR_T_NONE	0
646 #define	FR_T_IPF	1	/* IPF structures */
647 #define	FR_T_BPFOPC	2	/* BPF opcode */
648 #define	FR_T_CALLFUNC	3	/* callout to function in fr_func only */
649 #define	FR_T_COMPIPF	4	/* compiled C code */
650 #define	FR_T_BUILTIN	0x80000000	/* rule is in kernel space */
651 
652 /*
653  * fr_flags
654  */
655 #define	FR_CALL		0x00000	/* call rule */
656 #define	FR_BLOCK	0x00001	/* do not allow packet to pass */
657 #define	FR_PASS		0x00002	/* allow packet to pass */
658 #define	FR_AUTH		0x00003	/* use authentication */
659 #define	FR_PREAUTH	0x00004	/* require preauthentication */
660 #define	FR_ACCOUNT	0x00005	/* Accounting rule */
661 #define	FR_SKIP		0x00006	/* skip rule */
662 #define	FR_DIVERT	0x00007	/* divert rule */
663 #define	FR_CMDMASK	0x0000f
664 #define	FR_LOG		0x00010	/* Log */
665 #define	FR_LOGB		0x00011	/* Log-fail */
666 #define	FR_LOGP		0x00012	/* Log-pass */
667 #define	FR_LOGMASK	(FR_LOG|FR_CMDMASK)
668 #define	FR_CALLNOW	0x00020	/* call another function (fr_func) if matches */
669 #define	FR_NOTSRCIP	0x00040
670 #define	FR_NOTDSTIP	0x00080
671 #define	FR_QUICK	0x00100	/* match & stop processing list */
672 #define	FR_KEEPFRAG	0x00200	/* keep fragment information */
673 #define	FR_KEEPSTATE	0x00400	/* keep `connection' state information */
674 #define	FR_FASTROUTE	0x00800	/* bypass normal routing */
675 #define	FR_RETRST	0x01000	/* Return TCP RST packet - reset connection */
676 #define	FR_RETICMP	0x02000	/* Return ICMP unreachable packet */
677 #define	FR_FAKEICMP	0x03000	/* Return ICMP unreachable with fake source */
678 #define	FR_OUTQUE	0x04000	/* outgoing packets */
679 #define	FR_INQUE	0x08000	/* ingoing packets */
680 #define	FR_LOGBODY	0x10000	/* Log the body */
681 #define	FR_LOGFIRST	0x20000	/* Log the first byte if state held */
682 #define	FR_LOGORBLOCK	0x40000	/* block the packet if it can't be logged */
683 #define	FR_DUP		0x80000	/* duplicate packet */
684 #define	FR_FRSTRICT	0x100000	/* strict frag. cache */
685 #define	FR_STSTRICT	0x200000	/* strict keep state */
686 #define	FR_NEWISN	0x400000	/* new ISN for outgoing TCP */
687 #define	FR_NOICMPERR	0x800000	/* do not match ICMP errors in state */
688 #define	FR_STATESYNC	0x1000000	/* synchronize state to slave */
689 #define	FR_NOMATCH	0x8000000	/* no match occured */
690 		/*	0x10000000 	FF_LOGPASS */
691 		/*	0x20000000 	FF_LOGBLOCK */
692 		/*	0x40000000 	FF_LOGNOMATCH */
693 		/*	0x80000000 	FF_BLOCKNONIP */
694 #define	FR_COPIED	0x40000000	/* copied from user space */
695 #define	FR_INACTIVE	0x80000000	/* only used when flush'ing rules */
696 
697 #define	FR_RETMASK	(FR_RETICMP|FR_RETRST|FR_FAKEICMP)
698 #define	FR_ISBLOCK(x)	(((x) & FR_CMDMASK) == FR_BLOCK)
699 #define	FR_ISPASS(x)	(((x) & FR_CMDMASK) == FR_PASS)
700 #define	FR_ISAUTH(x)	(((x) & FR_CMDMASK) == FR_AUTH)
701 #define	FR_ISPREAUTH(x)	(((x) & FR_CMDMASK) == FR_PREAUTH)
702 #define	FR_ISACCOUNT(x)	(((x) & FR_CMDMASK) == FR_ACCOUNT)
703 #define	FR_ISSKIP(x)	(((x) & FR_CMDMASK) == FR_SKIP)
704 #define	FR_ISNOMATCH(x)	((x) & FR_NOMATCH)
705 #define	FR_INOUT	(FR_INQUE|FR_OUTQUE)
706 
707 /*
708  * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags
709  */
710 #define	FF_LOGPASS	0x10000000
711 #define	FF_LOGBLOCK	0x20000000
712 #define	FF_LOGNOMATCH	0x40000000
713 #define	FF_LOGGING	(FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH)
714 #define	FF_BLOCKNONIP	0x80000000	/* Solaris2 Only */
715 
716 
717 /*
718  * Structure that passes information on what/how to flush to the kernel.
719  */
720 typedef	struct	ipfflush	{
721 	int	ipflu_how;
722 	int	ipflu_arg;
723 } ipfflush_t;
724 
725 
726 /*
727  *
728  */
729 typedef	struct	ipfgetctl	{
730 	u_int	ipfg_min;	/* min value */
731 	u_int	ipfg_current;	/* current value */
732 	u_int	ipfg_max;	/* max value */
733 	u_int	ipfg_default;	/* default value */
734 	u_int	ipfg_steps;	/* value increments */
735 	char	ipfg_name[40];	/* tag name for this control */
736 } ipfgetctl_t;
737 
738 typedef	struct	ipfsetctl	{
739 	int	ipfs_which;	/* 0 = min 1 = current 2 = max 3 = default */
740 	u_int	ipfs_value;	/* min value */
741 	char	ipfs_name[40];	/* tag name for this control */
742 } ipfsetctl_t;
743 
744 
745 /*
746  * Some of the statistics below are in their own counters, but most are kept
747  * in this single structure so that they can all easily be collected and
748  * copied back as required.
749  *
750  * NOTE: when changing, keep in sync with kstats (below).
751  */
752 typedef	struct	filterstats {
753 	u_long	fr_pass;	/* packets allowed */
754 	u_long	fr_block;	/* packets denied */
755 	u_long	fr_nom;		/* packets which don't match any rule */
756 	u_long	fr_short;	/* packets which are short */
757 	u_long	fr_ppkl;	/* packets allowed and logged */
758 	u_long	fr_bpkl;	/* packets denied and logged */
759 	u_long	fr_npkl;	/* packets unmatched and logged */
760 	u_long	fr_pkl;		/* packets logged */
761 	u_long	fr_skip;	/* packets to be logged but buffer full */
762 	u_long	fr_ret;		/* packets for which a return is sent */
763 	u_long	fr_acct;	/* packets for which counting was performed */
764 	u_long	fr_bnfr;	/* bad attempts to allocate fragment state */
765 	u_long	fr_nfr;		/* new fragment state kept */
766 	u_long	fr_cfr;		/* add new fragment state but complete pkt */
767 	u_long	fr_bads;	/* bad attempts to allocate packet state */
768 	u_long	fr_ads;		/* new packet state kept */
769 	u_long	fr_chit;	/* cached hit */
770 	u_long	fr_tcpbad;	/* TCP checksum check failures */
771 	u_long	fr_pull[2];	/* good and bad pullup attempts */
772 	u_long	fr_badsrc;	/* source received doesn't match route */
773 	u_long	fr_badttl;	/* TTL in packet doesn't reach minimum */
774 	u_long	fr_bad;		/* bad IP packets to the filter */
775 	u_long	fr_ipv6;	/* IPv6 packets in/out */
776 	u_long	fr_ppshit;	/* dropped because of pps ceiling */
777 	u_long	fr_ipud;	/* IP id update failures */
778 } filterstats_t;
779 
780 /*
781  * kstat "copy" of the above - keep in sync!
782  * also keep in sync with initialisation code in solaris.c, ipf_kstat_init().
783  */
784 typedef struct  filter_kstats {
785 	kstat_named_t   fks_pass;	/* see above for comments */
786 	kstat_named_t   fks_block;
787 	kstat_named_t   fks_nom;
788 	kstat_named_t   fks_short;
789 	kstat_named_t   fks_ppkl;
790 	kstat_named_t   fks_bpkl;
791 	kstat_named_t   fks_npkl;
792 	kstat_named_t   fks_pkl;
793 	kstat_named_t   fks_skip;
794 	kstat_named_t   fks_ret;
795 	kstat_named_t   fks_acct;
796 	kstat_named_t   fks_bnfr;
797 	kstat_named_t   fks_nfr;
798 	kstat_named_t   fks_cfr;
799 	kstat_named_t   fks_bads;
800 	kstat_named_t   fks_ads;
801 	kstat_named_t   fks_chit;
802 	kstat_named_t   fks_tcpbad;
803 	kstat_named_t   fks_pull[2];
804 	kstat_named_t   fks_badsrc;
805 	kstat_named_t   fks_badttl;
806 	kstat_named_t   fks_bad;
807 	kstat_named_t   fks_ipv6;
808 	kstat_named_t   fks_ppshit;
809 	kstat_named_t   fks_ipud;
810 } filter_kstats_t;
811 
812 /*
813  * Log structure.  Each packet header logged is prepended by one of these.
814  * Following this in the log records read from the device will be an ipflog
815  * structure which is then followed by any packet data.
816  */
817 typedef	struct	iplog	{
818 	u_32_t		ipl_magic;
819 	u_int		ipl_count;
820 	struct	timeval	ipl_time;
821 	size_t		ipl_dsize;
822 	struct	iplog	*ipl_next;
823 } iplog_t;
824 
825 #define	ipl_sec		ipl_time.tv_sec
826 #define	ipl_usec	ipl_time.tv_usec
827 
828 #define IPL_MAGIC	0x49504c4d	/* 'IPLM' */
829 #define IPL_MAGIC_NAT	0x49504c4e	/* 'IPLN' */
830 #define IPL_MAGIC_STATE	0x49504c53	/* 'IPLS' */
831 #define	IPLOG_SIZE	sizeof(iplog_t)
832 
833 typedef	struct	ipflog	{
834 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
835         (defined(OpenBSD) && (OpenBSD >= 199603))
836 #else
837 	u_int	fl_unit;
838 #endif
839 	u_32_t	fl_rule;
840 	u_32_t	fl_flags;
841 	u_32_t	fl_lflags;
842 	u_32_t	fl_logtag;
843 	ipftag_t	fl_nattag;
844 	u_short	fl_plen;	/* extra data after hlen */
845 	u_short	fl_loglevel;	/* syslog log level */
846 	char	fl_group[FR_GROUPLEN];
847 	u_char	fl_hlen;	/* length of IP headers saved */
848 	u_char	fl_dir;
849 	u_char	fl_xxx[2];	/* pad */
850 	char	fl_ifname[LIFNAMSIZ];
851 } ipflog_t;
852 
853 #ifndef	IPF_LOGGING
854 # define	IPF_LOGGING	0
855 #endif
856 #ifndef	IPF_DEFAULT_PASS
857 # define	IPF_DEFAULT_PASS	FR_PASS
858 #endif
859 
860 #define	DEFAULT_IPFLOGSIZE	8192
861 #ifndef	IPFILTER_LOGSIZE
862 # define	IPFILTER_LOGSIZE	DEFAULT_IPFLOGSIZE
863 #else
864 # if IPFILTER_LOGSIZE < DEFAULT_IPFLOGSIZE
865 #  error IPFILTER_LOGSIZE too small.  Must be >= DEFAULT_IPFLOGSIZE
866 # endif
867 #endif
868 
869 #define	IPF_OPTCOPY	0x07ff00	/* bit mask of copied options */
870 
871 /*
872  * Device filenames for reading log information.  Use ipf on Solaris2 because
873  * ipl is already a name used by something else.
874  */
875 #ifndef	IPL_NAME
876 # if	SOLARIS
877 #  define	IPL_NAME	"/dev/ipf"
878 # else
879 #  define	IPL_NAME	"/dev/ipl"
880 # endif
881 #endif
882 /*
883  * Pathnames for various IP Filter control devices.  Used by LKM
884  * and userland, so defined here.
885  */
886 #define	IPNAT_NAME	"/dev/ipnat"
887 #define	IPSTATE_NAME	"/dev/ipstate"
888 #define	IPAUTH_NAME	"/dev/ipauth"
889 #define	IPSYNC_NAME	"/dev/ipsync"
890 #define	IPSCAN_NAME	"/dev/ipscan"
891 #define	IPLOOKUP_NAME	"/dev/iplookup"
892 
893 #define	IPL_LOGIPF	0	/* Minor device #'s for accessing logs */
894 #define	IPL_LOGNAT	1
895 #define	IPL_LOGSTATE	2
896 #define	IPL_LOGAUTH	3
897 #define	IPL_LOGSYNC	4
898 #define	IPL_LOGSCAN	5
899 #define	IPL_LOGLOOKUP	6
900 #define	IPL_LOGCOUNT	7
901 #define	IPL_LOGMAX	7
902 #define	IPL_LOGSIZE	(IPL_LOGMAX + 1)
903 #define	IPL_LOGALL	-1
904 #define	IPL_LOGNONE	-2
905 
906 /*
907  * For SIOCGETFS
908  */
909 typedef	struct	friostat	{
910 	struct	filterstats	f_st[2];
911 	struct	frentry		*f_ipf[2][2];
912 	struct	frentry		*f_acct[2][2];
913 	struct	frentry		*f_ipf6[2][2];
914 	struct	frentry		*f_acct6[2][2];
915 	struct	frentry		*f_auth;
916 	struct	frgroup		*f_groups[IPL_LOGSIZE][2];
917 	u_long	f_froute[2];
918 	u_long	f_ticks;
919 	int	f_locks[IPL_LOGMAX];
920 	size_t	f_kmutex_sz;
921 	size_t	f_krwlock_sz;
922 	int	f_defpass;	/* default pass - from fr_pass */
923 	int	f_active;	/* 1 or 0 - active rule set */
924 	int	f_running;	/* 1 if running, else 0 */
925 	int	f_logging;	/* 1 if enabled, else 0 */
926 	int	f_features;
927 	char	f_version[32];	/* version string */
928 } friostat_t;
929 
930 #define	f_fin		f_ipf[0]
931 #define	f_fin6		f_ipf6[0]
932 #define	f_fout		f_ipf[1]
933 #define	f_fout6		f_ipf6[1]
934 #define	f_acctin	f_acct[0]
935 #define	f_acctin6	f_acct6[0]
936 #define	f_acctout	f_acct[1]
937 #define	f_acctout6	f_acct6[1]
938 
939 #define	IPF_FEAT_LKM		0x001
940 #define	IPF_FEAT_LOG		0x002
941 #define	IPF_FEAT_LOOKUP		0x004
942 #define	IPF_FEAT_BPF		0x008
943 #define	IPF_FEAT_COMPILED	0x010
944 #define	IPF_FEAT_CKSUM		0x020
945 #define	IPF_FEAT_SYNC		0x040
946 #define	IPF_FEAT_SCAN		0x080
947 #define	IPF_FEAT_IPV6		0x100
948 
949 typedef struct	optlist {
950 	u_short ol_val;
951 	int	ol_bit;
952 } optlist_t;
953 
954 
955 /*
956  * Group list structure.
957  */
958 typedef	struct frgroup {
959 	struct	frgroup	*fg_next;
960 	struct	frentry	*fg_head;
961 	struct	frentry	*fg_start;
962 	u_32_t	fg_flags;
963 	int	fg_ref;
964 	char	fg_name[FR_GROUPLEN];
965 } frgroup_t;
966 
967 #define	FG_NAME(g)	(*(g)->fg_name == '\0' ? "" : (g)->fg_name)
968 
969 
970 /*
971  * Used by state and NAT tables
972  */
973 typedef struct icmpinfo {
974 	u_short	ici_id;
975 	u_short	ici_seq;
976 	u_char	ici_type;
977 } icmpinfo_t;
978 
979 typedef struct udpinfo {
980 	u_short	us_sport;
981 	u_short	us_dport;
982 } udpinfo_t;
983 
984 
985 typedef	struct	tcpdata	{
986 	u_32_t	td_end;
987 	u_32_t	td_maxend;
988 	u_32_t	td_maxwin;
989 	u_32_t	td_winscale;
990 	u_32_t	td_maxseg;
991 	int	td_winflags;
992 } tcpdata_t;
993 
994 #define	TCP_WSCALE_MAX		14
995 
996 #define	TCP_WSCALE_SEEN		0x00000001
997 #define	TCP_WSCALE_FIRST	0x00000002
998 #define TCP_SACK_PERMIT		0x00000004
999 
1000 
1001 typedef	struct tcpinfo {
1002 	u_short	ts_sport;
1003 	u_short	ts_dport;
1004 	tcpdata_t ts_data[2];
1005 } tcpinfo_t;
1006 
1007 
1008 /*
1009  * Structures to define a GRE header as seen in a packet.
1010  */
1011 struct	grebits	{
1012 	u_32_t	grb_C:1;
1013 	u_32_t	grb_R:1;
1014 	u_32_t	grb_K:1;
1015 	u_32_t	grb_S:1;
1016 	u_32_t	grb_s:1;
1017 	u_32_t	grb_recur:1;
1018 	u_32_t	grb_A:1;
1019 	u_32_t	grb_flags:3;
1020 	u_32_t	grb_ver:3;
1021 	u_short	grb_ptype;
1022 };
1023 
1024 typedef	struct	grehdr	{
1025 	union	{
1026 		struct	grebits	gru_bits;
1027 		u_short	gru_flags;
1028 	} gr_un;
1029 	u_short	gr_len;
1030 	u_short	gr_call;
1031 } grehdr_t;
1032 
1033 #define	gr_flags	gr_un.gru_flags
1034 #define	gr_bits		gr_un.gru_bits
1035 #define	gr_ptype	gr_bits.grb_ptype
1036 #define	gr_C		gr_bits.grb_C
1037 #define	gr_R		gr_bits.grb_R
1038 #define	gr_K		gr_bits.grb_K
1039 #define	gr_S		gr_bits.grb_S
1040 #define	gr_s		gr_bits.grb_s
1041 #define	gr_recur	gr_bits.grb_recur
1042 #define	gr_A		gr_bits.grb_A
1043 #define	gr_ver		gr_bits.grb_ver
1044 
1045 /*
1046  * GRE information tracked by "keep state"
1047  */
1048 typedef	struct	greinfo	{
1049 	u_short	gs_call[2];
1050 	u_short	gs_flags;
1051 	u_short	gs_ptype;
1052 } greinfo_t;
1053 
1054 #define	GRE_REV(x)	((ntohs(x) >> 13) & 7)
1055 
1056 
1057 /*
1058  * Format of an Authentication header
1059  */
1060 typedef	struct	authhdr	{
1061 	u_char	ah_next;
1062 	u_char	ah_plen;
1063 	u_short	ah_reserved;
1064 	u_32_t	ah_spi;
1065 	u_32_t	ah_seq;
1066 	/* Following the sequence number field is 0 or more bytes of */
1067 	/* authentication data, as specified by ah_plen - RFC 2402.  */
1068 } authhdr_t;
1069 
1070 
1071 /*
1072  * Timeout tail queue list member
1073  */
1074 typedef	struct	ipftqent	{
1075 	struct ipftqent **tqe_pnext;
1076 	struct ipftqent *tqe_next;
1077 	struct	ipftq	*tqe_ifq;
1078 	void	*tqe_parent;		/* pointer back to NAT/state struct */
1079 	u_long	tqe_die;		/* when this entriy is to die */
1080 	u_long	tqe_touched;
1081 	int	tqe_flags;
1082 	int	tqe_state[2];		/* current state of this entry */
1083 } ipftqent_t;
1084 
1085 #define	TQE_RULEBASED	0x00000001
1086 
1087 
1088 /*
1089  * Timeout tail queue head for IPFilter
1090  */
1091 typedef struct  ipftq   {
1092 	ipfmutex_t	ifq_lock;
1093 	u_int	ifq_ttl;
1094 	ipftqent_t	*ifq_head;
1095 	ipftqent_t	**ifq_tail;
1096 	struct	ipftq	*ifq_next;
1097 	struct	ipftq	**ifq_pnext;
1098 	int	ifq_ref;
1099 	u_int	ifq_flags;
1100 } ipftq_t;
1101 
1102 #define	IFQF_USER	0x01		/* User defined aging */
1103 #define	IFQF_DELETE	0x02		/* Marked for deletion */
1104 #define	IFQF_PROXY	0x04		/* Timeout queue in use by a proxy */
1105 
1106 #define	IPF_HZ_MULT	1
1107 #define	IPF_HZ_DIVIDE	2		/* How many times a second ipfilter */
1108 					/* checks its timeout queues.       */
1109 #define	IPF_TTLVAL(x)	(((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE)
1110 
1111 /*
1112  * Structure to define address for pool lookups.
1113  */
1114 typedef	struct	{
1115 	u_char		adf_len;
1116 	sa_family_t	adf_family;
1117 	i6addr_t	adf_addr;
1118 } addrfamily_t;
1119 
1120 
1121 /*
1122  * Object structure description.  For passing through in ioctls.
1123  */
1124 typedef	struct	ipfobj	{
1125 	u_32_t	ipfo_rev;		/* IPFilter version number */
1126 	u_32_t	ipfo_size;		/* size of object at ipfo_ptr */
1127 	void	*ipfo_ptr;		/* pointer to object */
1128 	int	ipfo_type;		/* type of object being pointed to */
1129 	int	ipfo_offset;		/* bytes from ipfo_ptr where to start */
1130 	u_char	ipfo_xxxpad[32];	/* reserved for future use */
1131 } ipfobj_t;
1132 
1133 #define	IPFOBJ_FRENTRY		0	/* struct frentry */
1134 #define	IPFOBJ_IPFSTAT		1	/* struct friostat */
1135 #define	IPFOBJ_IPFINFO		2	/* struct fr_info */
1136 #define	IPFOBJ_AUTHSTAT		3	/* struct fr_authstat */
1137 #define	IPFOBJ_FRAGSTAT		4	/* struct ipfrstat */
1138 #define	IPFOBJ_IPNAT		5	/* struct ipnat */
1139 #define	IPFOBJ_NATSTAT		6	/* struct natstat */
1140 #define	IPFOBJ_STATESAVE	7	/* struct ipstate_save */
1141 #define	IPFOBJ_NATSAVE		8	/* struct nat_save */
1142 #define	IPFOBJ_NATLOOKUP	9	/* struct natlookup */
1143 #define	IPFOBJ_IPSTATE		10	/* struct ipstate */
1144 #define	IPFOBJ_STATESTAT	11	/* struct ips_stat */
1145 #define	IPFOBJ_FRAUTH		12	/* struct frauth */
1146 #define	IPFOBJ_TUNEABLE		13	/* struct ipftune */
1147 #define	IPFOBJ_NAT		14	/* struct nat */
1148 #define	IPFOBJ_IPFITER		15	/* struct ipfruleiter */
1149 #define	IPFOBJ_GENITER		16	/* struct ipfgeniter */
1150 #define	IPFOBJ_GTABLE		17	/* struct ipftable */
1151 #define	IPFOBJ_LOOKUPITER	18	/* struct ipflookupiter */
1152 #define	IPFOBJ_COUNT		19	/* How many #defines are above this? */
1153 
1154 
1155 typedef	union	ipftunevalptr	{
1156 	void	*ipftp_void;
1157 	u_long	*ipftp_long;
1158 	u_int	*ipftp_int;
1159 	u_short	*ipftp_short;
1160 	u_char	*ipftp_char;
1161 } ipftunevalptr_t;
1162 
1163 typedef	struct	ipftuneable	{
1164 	ipftunevalptr_t	ipft_una;
1165 	char		*ipft_name;
1166 	u_long		ipft_min;
1167 	u_long		ipft_max;
1168 	int		ipft_sz;
1169 	int		ipft_flags;
1170 	struct ipftuneable *ipft_next;
1171 } ipftuneable_t;
1172 
1173 #define	ipft_addr	ipft_una.ipftp_void
1174 #define	ipft_plong	ipft_una.ipftp_long
1175 #define	ipft_pint	ipft_una.ipftp_int
1176 #define	ipft_pshort	ipft_una.ipftp_short
1177 #define	ipft_pchar	ipft_una.ipftp_char
1178 
1179 #define	IPFT_RDONLY	1	/* read-only */
1180 #define	IPFT_WRDISABLED	2	/* write when disabled only */
1181 
1182 typedef	union	ipftuneval	{
1183 	u_long	ipftu_long;
1184 	u_int	ipftu_int;
1185 	u_short	ipftu_short;
1186 	u_char	ipftu_char;
1187 } ipftuneval_t;
1188 
1189 typedef	struct	ipftune	{
1190 	void    	*ipft_cookie;
1191 	ipftuneval_t	ipft_un;
1192 	u_long  	ipft_min;
1193 	u_long  	ipft_max;
1194 	int		ipft_sz;
1195 	int		ipft_flags;
1196 	char		ipft_name[80];
1197 } ipftune_t;
1198 
1199 #define	ipft_vlong	ipft_un.ipftu_long
1200 #define	ipft_vint	ipft_un.ipftu_int
1201 #define	ipft_vshort	ipft_un.ipftu_short
1202 #define	ipft_vchar	ipft_un.ipftu_char
1203 
1204 /*
1205  * ipfruleiter is iterator structure used for filter rules.
1206  */
1207 typedef	struct	ipfruleiter {
1208 	int		iri_ver;
1209 	int		iri_inout;
1210 	char		iri_group[FR_GROUPLEN];
1211 	int		iri_active;
1212 	int		iri_nrules;
1213 	frentry_t	*iri_rule;
1214 } ipfruleiter_t;
1215 
1216 /* Values for iri_inout  */
1217 #define	F_IN	0
1218 #define	F_OUT	1
1219 #define	F_ACIN	2
1220 #define	F_ACOUT	3
1221 
1222 /*
1223  * ipfgeniter is generic iterator structure used for nat rules,
1224  * hostmap entries and nat table entries.
1225  */
1226 typedef	struct	ipfgeniter {
1227 	int	igi_type;	/* type of data we're looking at */
1228 	int	igi_nitems;
1229 	void	*igi_data;
1230 } ipfgeniter_t;
1231 
1232 #define	IPFGENITER_IPF		0
1233 #define	IPFGENITER_NAT		1
1234 #define	IPFGENITER_IPNAT	2
1235 #define	IPFGENITER_FRAG		3
1236 #define	IPFGENITER_AUTH		4
1237 #define	IPFGENITER_STATE	5
1238 #define	IPFGENITER_NATFRAG	6
1239 #define	IPFGENITER_HOSTMAP	7
1240 #define	IPFGENITER_LOOKUP	8
1241 
1242 typedef struct  ipftable {
1243         int     ita_type;
1244         void    *ita_table;
1245 } ipftable_t;
1246 
1247 typedef struct ipftoken {
1248         struct ipftoken *ipt_next;
1249         struct ipftoken **ipt_pnext;
1250         void            *ipt_ctx;
1251         void            *ipt_data;
1252         u_long          ipt_die;
1253         int             ipt_type;
1254         int             ipt_uid;
1255         int             ipt_subtype;
1256         int             ipt_alive;
1257 } ipftoken_t;
1258 
1259 
1260 /*
1261  * sync commands
1262  */
1263 #define	IPFSYNC_RESYNC	0
1264 #define	IPFSYNC_NEWIFP	1
1265 #define	IPFSYNC_OLDIFP	2
1266 
1267 
1268 /*
1269 ** HPUX Port
1270 */
1271 #ifdef __hpux
1272 /* HP-UX locking sequence deadlock detection module lock MAJOR ID */
1273 # define	IPF_SMAJ	0	/* temp assignment XXX, not critical */
1274 #endif
1275 
1276 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \
1277     (__FreeBSD_version >= 220000)
1278 # define	CDEV_MAJOR	79
1279 #endif
1280 
1281 /*
1282  * Post NetBSD 1.2 has the PFIL interface for packet filters.  This turns
1283  * on those hooks.  We don't need any special mods in non-IP Filter code
1284  * with this!
1285  */
1286 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \
1287     (defined(NetBSD1_2) && NetBSD1_2 > 1) || \
1288     (defined(__FreeBSD__) && (__FreeBSD_version >= 500043))
1289 # if (NetBSD >= 199905)
1290 #  define PFIL_HOOKS
1291 # endif
1292 # ifdef PFIL_HOOKS
1293 #  define NETBSD_PF
1294 # endif
1295 #endif
1296 
1297 #ifndef	_KERNEL
1298 extern	int	fr_check __P((struct ip *, int, void *, int, mb_t **, ipf_stack_t *));
1299 extern	int	(*fr_checkp) __P((ip_t *, int, void *, int, mb_t **, ipf_stack_t *));
1300 extern	int	ipf_log __P((void));
1301 extern	struct	ifnet *get_unit __P((char *, int, ipf_stack_t *));
1302 extern	char	*get_ifname __P((struct ifnet *));
1303 # if defined(__NetBSD__) || defined(__OpenBSD__) || \
1304 	  (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000)
1305 extern	int	frrequest __P((int, u_long, caddr_t, int, int, ipf_stack_t *));
1306 # else
1307 extern	int	iplioctl __P((int, ioctlcmd_t, caddr_t, int));
1308 # endif
1309 extern	int	iplopen __P((dev_t, int));
1310 extern	int	iplclose __P((dev_t, int));
1311 extern	void	m_freem __P((mb_t *));
1312 #else /* #ifndef _KERNEL */
1313 extern	phy_if_t	get_unit __P((char *, int, ipf_stack_t *));
1314 # if defined(__NetBSD__) && defined(PFIL_HOOKS)
1315 extern	void	ipfilterattach __P((int));
1316 # endif
1317 extern	int	ipl_enable __P((void));
1318 extern	int	ipl_disable __P((void));
1319 # ifdef MENTAT
1320 extern	int	fr_check __P((struct ip *, int, void *, int, void *,
1321 			      mblk_t **, ipf_stack_t *));
1322 #  if SOLARIS
1323 #   if SOLARIS2 >= 7
1324 extern	int	iplioctl __P((dev_t, int, intptr_t, int, cred_t *, int *));
1325 #   else
1326 extern	int	iplioctl __P((dev_t, int, int *, int, cred_t *, int *));
1327 #   endif
1328 extern	int	iplopen __P((dev_t *, int, int, cred_t *));
1329 extern	int	iplclose __P((dev_t, int, int, cred_t *));
1330 extern	int	iplread __P((dev_t, uio_t *, cred_t *));
1331 extern	int	iplwrite __P((dev_t, uio_t *, cred_t *));
1332 #  endif
1333 #  ifdef __hpux
1334 extern	int	iplopen __P((dev_t, int, intptr_t, int));
1335 extern	int	iplclose __P((dev_t, int, int));
1336 extern	int	iplioctl __P((dev_t, int, caddr_t, int));
1337 extern	int	iplread __P((dev_t, uio_t *));
1338 extern	int	iplwrite __P((dev_t, uio_t *));
1339 extern	int	iplselect __P((dev_t, int));
1340 #  endif
1341 extern	int	ipfsync __P((ipf_stack_t *));
1342 extern	int	fr_qout __P((queue_t *, mblk_t *));
1343 # else /* MENTAT */
1344 extern	int	fr_check __P((struct ip *, int, void *, int, mb_t **, ipf_stack_t *));
1345 extern	int	(*fr_checkp) __P((ip_t *, int, void *, int, mb_t **, ipf_stack_t *));
1346 extern	size_t	mbufchainlen __P((mb_t *));
1347 #  ifdef	__sgi
1348 #   include <sys/cred.h>
1349 extern	int	iplioctl __P((dev_t, int, caddr_t, int, cred_t *, int *));
1350 extern	int	iplopen __P((dev_t *, int, int, cred_t *));
1351 extern	int	iplclose __P((dev_t, int, int, cred_t *));
1352 extern	int	iplread __P((dev_t, uio_t *, cred_t *));
1353 extern	int	iplwrite __P((dev_t, uio_t *, cred_t *));
1354 extern	int	ipfsync __P((ipf_stack_t *));
1355 extern	int	ipfilter_sgi_attach __P((void));
1356 extern	void	ipfilter_sgi_detach __P((void));
1357 extern	void	ipfilter_sgi_intfsync __P((void));
1358 #  else
1359 #   ifdef	IPFILTER_LKM
1360 extern	int	iplidentify __P((char *));
1361 #   endif
1362 #   if (_BSDI_VERSION >= 199510) || (__FreeBSD_version >= 220000) || \
1363       (NetBSD >= 199511) || defined(__OpenBSD__)
1364 #    if defined(__NetBSD__) || (_BSDI_VERSION >= 199701) || \
1365        defined(__OpenBSD__) || (__FreeBSD_version >= 300000)
1366 #     if (__FreeBSD_version >= 500024)
1367 #      if (__FreeBSD_version >= 502116)
1368 extern	int	iplioctl __P((struct cdev*, u_long, caddr_t, int, struct thread *));
1369 #      else
1370 extern	int	iplioctl __P((dev_t, u_long, caddr_t, int, struct thread *));
1371 #      endif /* __FreeBSD_version >= 502116 */
1372 #     else
1373 extern	int	iplioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
1374 #     endif /* __FreeBSD_version >= 500024 */
1375 #    else
1376 extern	int	iplioctl __P((dev_t, int, caddr_t, int, struct proc *));
1377 #    endif
1378 #    if (__FreeBSD_version >= 500024)
1379 #      if (__FreeBSD_version >= 502116)
1380 extern	int	iplopen __P((struct cdev*, int, int, struct thread *));
1381 extern	int	iplclose __P((struct cdev*, int, int, struct thread *));
1382 #      else
1383 extern	int	iplopen __P((dev_t, int, int, struct thread *));
1384 extern	int	iplclose __P((dev_t, int, int, struct thread *));
1385 #      endif /* __FreeBSD_version >= 502116 */
1386 #    else
1387 extern	int	iplopen __P((dev_t, int, int, struct proc *));
1388 extern	int	iplclose __P((dev_t, int, int, struct proc *));
1389 #    endif /* __FreeBSD_version >= 500024 */
1390 #   else
1391 #    ifdef linux
1392 extern	int	iplioctl __P((struct inode *, struct file *, u_int, u_long));
1393 #    else
1394 extern	int	iplopen __P((dev_t, int));
1395 extern	int	iplclose __P((dev_t, int));
1396 extern	int	iplioctl __P((dev_t, int, caddr_t, int));
1397 #    endif
1398 #   endif /* (_BSDI_VERSION >= 199510) */
1399 #   if	BSD >= 199306
1400 #      if (__FreeBSD_version >= 502116)
1401 extern	int	iplread __P((struct cdev*, struct uio *, int));
1402 extern	int	iplwrite __P((struct cdev*, struct uio *, int));
1403 #      else
1404 extern	int	iplread __P((dev_t, struct uio *, int));
1405 extern	int	iplwrite __P((dev_t, struct uio *, int));
1406 #      endif /* __FreeBSD_version >= 502116 */
1407 #   else
1408 #    ifndef linux
1409 extern	int	iplread __P((dev_t, struct uio *));
1410 extern	int	iplwrite __P((dev_t, struct uio *));
1411 #    endif
1412 #   endif /* BSD >= 199306 */
1413 #  endif /* __ sgi */
1414 # endif /* MENTAT */
1415 
1416 #endif /* #ifndef _KERNEL */
1417 
1418 extern	char	*memstr __P((char *, char *, int, int));
1419 extern	int	count4bits __P((u_32_t));
1420 extern	int	count6bits __P((u_32_t *));
1421 extern	int	frrequest __P((int, ioctlcmd_t, caddr_t, int, int, ipf_stack_t *));
1422 extern	char	*getifname __P((struct ifnet *));
1423 extern	int	iplattach __P((ipf_stack_t *, netstack_t *));
1424 extern	int	ipldetach __P((ipf_stack_t *));
1425 extern	u_short	ipf_cksum __P((u_short *, int));
1426 extern	int	copyinptr __P((void *, void *, size_t));
1427 extern	int	copyoutptr __P((void *, void *, size_t));
1428 extern	int	fr_fastroute __P((mb_t *, mb_t **, fr_info_t *, frdest_t *));
1429 extern	int	fr_inobj __P((void *, void *, int));
1430 extern	int	fr_inobjsz __P((void *, void *, int, int));
1431 extern	int	fr_ioctlswitch __P((int, void *, ioctlcmd_t, int, int, void *,
1432 				    ipf_stack_t *));
1433 extern	int	fr_ipftune __P((ioctlcmd_t, void *, ipf_stack_t *));
1434 extern	int	fr_outobj __P((void *, void *, int));
1435 extern	int	fr_outobjsz __P((void *, void *, int, int));
1436 extern	void	*fr_pullup __P((mb_t *, fr_info_t *, int));
1437 extern	void	fr_resolvedest __P((struct frdest *, int, ipf_stack_t *));
1438 extern	int	fr_resolvefunc __P((void *));
1439 extern	void	*fr_resolvenic __P((char *, int, ipf_stack_t *));
1440 extern	int	fr_send_icmp_err __P((int, fr_info_t *, int));
1441 extern	int	fr_send_reset __P((fr_info_t *));
1442 #if  (__FreeBSD_version < 490000) || !defined(_KERNEL)
1443 extern	int	ppsratecheck __P((struct timeval *, int *, int));
1444 #endif
1445 extern	ipftq_t	*fr_addtimeoutqueue __P((ipftq_t **, u_int, ipf_stack_t *));
1446 extern	void	fr_deletequeueentry __P((ipftqent_t *));
1447 extern	int	fr_deletetimeoutqueue __P((ipftq_t *));
1448 extern	void	fr_freetimeoutqueue __P((ipftq_t *, ipf_stack_t *));
1449 extern	void	fr_movequeue __P((ipftqent_t *, ipftq_t *, ipftq_t *,
1450 				  ipf_stack_t *));
1451 extern	void	fr_queueappend __P((ipftqent_t *, ipftq_t *, void *,
1452 				    ipf_stack_t *));
1453 extern	void	fr_queueback __P((ipftqent_t *, ipf_stack_t *));
1454 extern	void	fr_queuefront __P((ipftqent_t *));
1455 extern	void	fr_checkv4sum __P((fr_info_t *));
1456 extern	int	fr_checkl4sum __P((fr_info_t *));
1457 extern	int	fr_ifpfillv4addr __P((int, struct sockaddr_in *,
1458 				      struct sockaddr_in *, struct in_addr *,
1459 				      struct in_addr *));
1460 extern	int	fr_coalesce __P((fr_info_t *));
1461 #ifdef	USE_INET6
1462 extern	void	fr_checkv6sum __P((fr_info_t *));
1463 extern	int	fr_ifpfillv6addr __P((int, struct sockaddr_in6 *,
1464 				      struct sockaddr_in6 *, struct in_addr *,
1465 				      struct in_addr *));
1466 #endif
1467 
1468 #define	IPFILTER_COMPAT
1469 extern	int	fr_incomptrans __P((ipfobj_t *, void *));
1470 extern	int	fr_outcomptrans __P((ipfobj_t *, void *));
1471 
1472 extern	int		fr_addipftune __P((ipftuneable_t *, ipf_stack_t *));
1473 extern	int		fr_delipftune __P((ipftuneable_t *, ipf_stack_t *));
1474 
1475 extern	int	frflush __P((minor_t, int, int, ipf_stack_t *));
1476 extern	void	frsync __P((int, int, void *, char *, ipf_stack_t *));
1477 extern	frgroup_t *fr_addgroup __P((char *, void *, u_32_t, minor_t, int,
1478 				    ipf_stack_t *));
1479 extern	int	fr_derefrule __P((frentry_t **, ipf_stack_t *));
1480 extern	void	fr_delgroup __P((char *, minor_t, int, ipf_stack_t *));
1481 extern	frgroup_t *fr_findgroup __P((char *, minor_t, int, frgroup_t ***,
1482 				     ipf_stack_t *));
1483 
1484 extern	int	fr_loginit __P((ipf_stack_t *));
1485 extern	int	ipflog_clear __P((minor_t, ipf_stack_t *));
1486 extern	int	ipflog_read __P((minor_t, struct uio *, ipf_stack_t *));
1487 extern	int	ipflog __P((fr_info_t *, u_int));
1488 extern	int	ipllog __P((int, fr_info_t *, void **, size_t *, int *, int,
1489 			    ipf_stack_t *));
1490 extern	void	fr_logunload __P((ipf_stack_t *));
1491 
1492 extern	frentry_t	*fr_acctpkt __P((fr_info_t *, u_32_t *));
1493 extern	int		fr_copytolog __P((int, char *, int));
1494 extern	u_short		fr_cksum __P((mb_t *, ip_t *, int, void *));
1495 extern	void		fr_deinitialise __P((ipf_stack_t *));
1496 extern	frentry_t 	*fr_dolog __P((fr_info_t *, u_32_t *));
1497 extern	frentry_t 	*fr_dstgrpmap __P((fr_info_t *, u_32_t *));
1498 extern	void		fr_fixskip __P((frentry_t **, frentry_t *, int));
1499 extern	void		fr_forgetifp __P((void *, ipf_stack_t *));
1500 extern	frentry_t 	*fr_getrulen __P((int, char *, u_32_t,
1501 					  ipf_stack_t *));
1502 extern	void		fr_getstat __P((struct friostat *, ipf_stack_t *));
1503 extern	int		fr_ifpaddr __P((int, int, void *,
1504 					struct in_addr *, struct in_addr *,
1505 					ipf_stack_t *));
1506 extern	int		fr_initialise __P((ipf_stack_t *));
1507 extern	void		fr_lock __P((caddr_t, int *));
1508 extern  int		fr_makefrip __P((int, ip_t *, fr_info_t *));
1509 extern	int		fr_matchtag __P((ipftag_t *, ipftag_t *));
1510 extern	int		fr_matchicmpqueryreply __P((int, icmpinfo_t *,
1511 						    struct icmp *, int));
1512 extern	u_32_t		fr_newisn __P((fr_info_t *));
1513 extern	u_short		fr_nextipid __P((fr_info_t *));
1514 extern	int		fr_rulen __P((int, frentry_t *, ipf_stack_t *));
1515 extern	int		fr_scanlist __P((fr_info_t *, u_32_t));
1516 extern	frentry_t 	*fr_srcgrpmap __P((fr_info_t *, u_32_t *));
1517 extern	int		fr_tcpudpchk __P((fr_info_t *, frtuc_t *));
1518 extern	int		fr_verifysrc __P((fr_info_t *fin));
1519 extern	int		fr_zerostats __P((char *, ipf_stack_t *));
1520 extern	ipftoken_t	*ipf_findtoken __P((int, int, void *, ipf_stack_t *));
1521 extern	int		ipf_getnextrule __P((ipftoken_t *, void *,
1522 					     ipf_stack_t *));
1523 extern  void            ipf_expiretokens __P((ipf_stack_t *));
1524 extern	void		ipf_freetoken __P((ipftoken_t *, ipf_stack_t *));
1525 extern	int		ipf_deltoken __P((int,int, void *, ipf_stack_t *));
1526 extern	int		ipf_genericiter __P((void *, int, void *,
1527 					     ipf_stack_t *));
1528 
1529 extern	char	ipfilter_version[];
1530 #ifdef	USE_INET6
1531 extern	int	icmptoicmp6types[ICMP_MAXTYPE+1];
1532 extern	int	icmptoicmp6unreach[ICMP_MAX_UNREACH];
1533 extern	int	icmpreplytype6[ICMP6_MAXTYPE + 1];
1534 #endif
1535 extern	int	icmpreplytype4[ICMP_MAXTYPE + 1];
1536 extern	frentry_t *ipfrule_match __P((fr_info_t *));
1537 
1538 extern void	ipftuneable_alloc(ipf_stack_t *);
1539 extern void	ipftuneable_free(ipf_stack_t *);
1540 
1541 #endif	/* __IP_FIL_H__ */
1542