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