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