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 2006 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  * NOTE: when changing, keep in sync with kstats (below).
691  */
692 typedef	struct	filterstats {
693 	u_long	fr_pass;	/* packets allowed */
694 	u_long	fr_block;	/* packets denied */
695 	u_long	fr_nom;		/* packets which don't match any rule */
696 	u_long	fr_short;	/* packets which are short */
697 	u_long	fr_ppkl;	/* packets allowed and logged */
698 	u_long	fr_bpkl;	/* packets denied and logged */
699 	u_long	fr_npkl;	/* packets unmatched and logged */
700 	u_long	fr_pkl;		/* packets logged */
701 	u_long	fr_skip;	/* packets to be logged but buffer full */
702 	u_long	fr_ret;		/* packets for which a return is sent */
703 	u_long	fr_acct;	/* packets for which counting was performed */
704 	u_long	fr_bnfr;	/* bad attempts to allocate fragment state */
705 	u_long	fr_nfr;		/* new fragment state kept */
706 	u_long	fr_cfr;		/* add new fragment state but complete pkt */
707 	u_long	fr_bads;	/* bad attempts to allocate packet state */
708 	u_long	fr_ads;		/* new packet state kept */
709 	u_long	fr_chit;	/* cached hit */
710 	u_long	fr_tcpbad;	/* TCP checksum check failures */
711 	u_long	fr_pull[2];	/* good and bad pullup attempts */
712 	u_long	fr_badsrc;	/* source received doesn't match route */
713 	u_long	fr_badttl;	/* TTL in packet doesn't reach minimum */
714 	u_long	fr_bad;		/* bad IP packets to the filter */
715 	u_long	fr_ipv6;	/* IPv6 packets in/out */
716 	u_long	fr_ppshit;	/* dropped because of pps ceiling */
717 	u_long	fr_ipud;	/* IP id update failures */
718 } filterstats_t;
719 
720 /*
721  * kstat "copy" of the above - keep in sync!
722  * also keep in sync with initialisation code in solaris.c, ipf_kstat_init().
723  */
724 typedef struct  filter_kstats {
725 	kstat_named_t   fks_pass;	/* see above for comments */
726 	kstat_named_t   fks_block;
727 	kstat_named_t   fks_nom;
728 	kstat_named_t   fks_short;
729 	kstat_named_t   fks_ppkl;
730 	kstat_named_t   fks_bpkl;
731 	kstat_named_t   fks_npkl;
732 	kstat_named_t   fks_pkl;
733 	kstat_named_t   fks_skip;
734 	kstat_named_t   fks_ret;
735 	kstat_named_t   fks_acct;
736 	kstat_named_t   fks_bnfr;
737 	kstat_named_t   fks_nfr;
738 	kstat_named_t   fks_cfr;
739 	kstat_named_t   fks_bads;
740 	kstat_named_t   fks_ads;
741 	kstat_named_t   fks_chit;
742 	kstat_named_t   fks_tcpbad;
743 	kstat_named_t   fks_pull[2];
744 	kstat_named_t   fks_badsrc;
745 	kstat_named_t   fks_badttl;
746 	kstat_named_t   fks_bad;
747 	kstat_named_t   fks_ipv6;
748 	kstat_named_t   fks_ppshit;
749 	kstat_named_t   fks_ipud;
750 } filter_kstats_t;
751 
752 /*
753  * Log structure.  Each packet header logged is prepended by one of these.
754  * Following this in the log records read from the device will be an ipflog
755  * structure which is then followed by any packet data.
756  */
757 typedef	struct	iplog	{
758 	u_32_t		ipl_magic;
759 	u_int		ipl_count;
760 	struct	timeval	ipl_tv;
761 	size_t		ipl_dsize;
762 	struct	iplog	*ipl_next;
763 } iplog_t;
764 
765 #define	ipl_sec		ipl_tv.tv_sec
766 #define	ipl_usec	ipl_tv.tv_usec
767 
768 #define IPL_MAGIC	0x49504c4d	/* 'IPLM' */
769 #define	IPLOG_SIZE	sizeof(iplog_t)
770 
771 typedef	struct	ipflog	{
772 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
773         (defined(OpenBSD) && (OpenBSD >= 199603))
774 #else
775 	u_int	fl_unit;
776 #endif
777 	u_32_t	fl_rule;
778 	u_32_t	fl_flags;
779 	u_32_t	fl_lflags;
780 	u_32_t	fl_tag;
781 	u_short	fl_plen;	/* extra data after hlen */
782 	u_short	fl_loglevel;	/* syslog log level */
783 	char	fl_group[FR_GROUPLEN];
784 	u_char	fl_hlen;	/* length of IP headers saved */
785 	u_char	fl_dir;
786 	u_char	fl_xxx[6];	/* pad */
787 	char	fl_ifname[LIFNAMSIZ];
788 } ipflog_t;
789 
790 #ifndef	IPF_LOGGING
791 # define	IPF_LOGGING	0
792 #endif
793 #ifndef	IPF_DEFAULT_PASS
794 # define	IPF_DEFAULT_PASS	FR_PASS
795 #endif
796 
797 #define	DEFAULT_IPFLOGSIZE	8192
798 #ifndef	IPFILTER_LOGSIZE
799 # define	IPFILTER_LOGSIZE	DEFAULT_IPFLOGSIZE
800 #else
801 # if IPF_LOGSIZE < DEFAULT_IPFLOGSIZE
802 #  error IPFILTER_LOGSISZE too small.  Must be >= DEFAULT_IPFLOGSIZE
803 # endif
804 #endif
805 
806 #define	IPF_OPTCOPY	0x07ff00	/* bit mask of copied options */
807 
808 /*
809  * Device filenames for reading log information.  Use ipf on Solaris2 because
810  * ipl is already a name used by something else.
811  */
812 #ifndef	IPL_NAME
813 # if	SOLARIS
814 #  define	IPL_NAME	"/dev/ipf"
815 # else
816 #  define	IPL_NAME	"/dev/ipl"
817 # endif
818 #endif
819 /*
820  * Pathnames for various IP Filter control devices.  Used by LKM
821  * and userland, so defined here.
822  */
823 #define	IPNAT_NAME	"/dev/ipnat"
824 #define	IPSTATE_NAME	"/dev/ipstate"
825 #define	IPAUTH_NAME	"/dev/ipauth"
826 #define	IPSYNC_NAME	"/dev/ipsync"
827 #define	IPSCAN_NAME	"/dev/ipscan"
828 #define	IPLOOKUP_NAME	"/dev/iplookup"
829 
830 #define	IPL_LOGIPF	0	/* Minor device #'s for accessing logs */
831 #define	IPL_LOGNAT	1
832 #define	IPL_LOGSTATE	2
833 #define	IPL_LOGAUTH	3
834 #define	IPL_LOGSYNC	4
835 #define	IPL_LOGSCAN	5
836 #define	IPL_LOGLOOKUP	6
837 #define	IPL_LOGCOUNT	7
838 #define	IPL_LOGMAX	7
839 #define	IPL_LOGSIZE	IPL_LOGMAX + 1
840 #define	IPL_LOGALL	-1
841 #define	IPL_LOGNONE	-2
842 
843 /*
844  * For SIOCGETFS
845  */
846 typedef	struct	friostat	{
847 	struct	filterstats	f_st[2];
848 	struct	frentry		*f_ipf[2][2];
849 	struct	frentry		*f_acct[2][2];
850 	struct	frentry		*f_ipf6[2][2];
851 	struct	frentry		*f_acct6[2][2];
852 	struct	frentry		*f_auth;
853 	struct	frgroup		*f_groups[IPL_LOGSIZE][2];
854 	u_long	f_froute[2];
855 	u_long	f_ticks;
856 	int	f_locks[IPL_LOGMAX];
857 	size_t	f_kmutex_sz;
858 	size_t	f_krwlock_sz;
859 	int	f_defpass;	/* default pass - from fr_pass */
860 	char	f_active;	/* 1 or 0 - active rule set */
861 	char	f_running;	/* 1 if running, else 0 */
862 	char	f_logging;	/* 1 if enabled, else 0 */
863 	char	f_version[32];	/* version string */
864 } friostat_t;
865 
866 #define	f_fin		f_ipf[0]
867 #define	f_fin6		f_ipf6[0]
868 #define	f_fout		f_ipf[1]
869 #define	f_fout6		f_ipf6[1]
870 #define	f_acctin	f_acct[0]
871 #define	f_acctin6	f_acct6[0]
872 #define	f_acctout	f_acct[1]
873 #define	f_acctout6	f_acct6[1]
874 
875 
876 typedef struct	optlist {
877 	u_short ol_val;
878 	int	ol_bit;
879 } optlist_t;
880 
881 
882 /*
883  * Group list structure.
884  */
885 typedef	struct frgroup {
886 	struct	frgroup	*fg_next;
887 	struct	frentry	*fg_head;
888 	struct	frentry	*fg_start;
889 	u_32_t	fg_flags;
890 	int	fg_ref;
891 	char	fg_name[FR_GROUPLEN];
892 } frgroup_t;
893 
894 #define	FG_NAME(g)	(*(g)->fg_name == '\0' ? "" : (g)->fg_name)
895 
896 
897 /*
898  * Used by state and NAT tables
899  */
900 typedef struct icmpinfo {
901 	u_short	ici_id;
902 	u_short	ici_seq;
903 	u_char	ici_type;
904 } icmpinfo_t;
905 
906 typedef struct udpinfo {
907 	u_short	us_sport;
908 	u_short	us_dport;
909 } udpinfo_t;
910 
911 
912 typedef	struct	tcpdata	{
913 	u_32_t	td_end;
914 	u_32_t	td_maxend;
915 	u_32_t	td_maxwin;
916 	u_32_t	td_winscale;
917 	u_32_t	td_maxseg;
918 	int	td_winflags;
919 } tcpdata_t;
920 
921 #define	TCP_WSCALE_MAX		14
922 
923 #define	TCP_WSCALE_SEEN		0x00000001
924 #define	TCP_WSCALE_FIRST	0x00000002
925 
926 
927 typedef	struct tcpinfo {
928 	u_short	ts_sport;
929 	u_short	ts_dport;
930 	tcpdata_t ts_data[2];
931 } tcpinfo_t;
932 
933 typedef	struct	greinfo	{
934 	u_short	gs_flags;
935 	u_short	gs_ptype;
936 	u_short	gs_call;
937 } greinfo_t;
938 
939 typedef	struct	grehdr	{
940 	union	{
941 		struct	grebits	{
942 			u_32_t	grub_C:1;
943 			u_32_t	grub_R:1;
944 			u_32_t	grub_K:1;
945 			u_32_t	grub_S:1;
946 			u_32_t	grub_s:1;
947 			u_32_t	grub_recur:1;
948 			u_32_t	grub_A:1;
949 			u_32_t	grub_flags:3;
950 			u_32_t	grub_ver:3;
951 			u_short	grub_ptype;
952 		} gru_bits;
953 		u_short	gru_flags;
954 	} gr_un;
955 	u_short	gr_len;
956 	u_short	gr_call;
957 } grehdr_t;
958 
959 #define	gr_bits		gr_un.gru_bits
960 #define	gr_ptype	gr_un.gru_bits.grub_ptype
961 #define	gr_C		gr_bits.grub_C
962 #define	gr_R		gr_bits.grub_R
963 #define	gr_K		gr_bits.grub_K
964 #define	gr_S		gr_bits.grub_S
965 #define	gr_s		gr_bits.grub_s
966 #define	gr_recur	gr_bits.grub_recur
967 #define	gr_A		gr_bits.grub_A
968 #define	gr_flags	gr_bits.grub_flags
969 #define	gr_ver		gr_bits.grub_ver
970 
971 
972 /*
973  * Timeout tail queue list member
974  */
975 typedef	struct	ipftqent	{
976 	struct ipftqent **tqe_pnext;
977 	struct ipftqent *tqe_next;
978 	struct	ipftq	*tqe_ifq;
979 	void	*tqe_parent;		/* pointer back to NAT/state struct */
980 	u_long	tqe_die;		/* when this entriy is to die */
981 	u_long	tqe_touched;
982 	int	tqe_flags;
983 	int	tqe_state[2];		/* current state of this entry */
984 } ipftqent_t;
985 
986 #define	TQE_RULEBASED	0x00000001
987 
988 
989 /*
990  * Timeout tail queue head for IPFilter
991  */
992 typedef struct  ipftq   {
993 	ipfmutex_t	ifq_lock;
994 	u_int	ifq_ttl;
995 	ipftqent_t	*ifq_head;
996 	ipftqent_t	**ifq_tail;
997 	struct	ipftq	*ifq_next;
998 	struct	ipftq	**ifq_pnext;
999 	int	ifq_ref;
1000 	u_int	ifq_flags;
1001 } ipftq_t;
1002 
1003 #define	IFQF_USER	0x01		/* User defined aging */
1004 
1005 #define	IPF_HZ_MULT	1
1006 #define	IPF_HZ_DIVIDE	2		/* How many times a second ipfilter */
1007 					/* checks its timeout queues.       */
1008 #define	IPF_TTLVAL(x)	(((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE)
1009 
1010 /*
1011  * Structure to define address for pool lookups.
1012  */
1013 typedef	struct	{
1014 	u_char		adf_len;
1015 	sa_family_t	adf_family;
1016 	i6addr_t	adf_addr;
1017 } addrfamily_t;
1018 
1019 
1020 /*
1021  * Object structure description.  For passing through in ioctls.
1022  */
1023 typedef	struct	ipfobj	{
1024 	u_32_t	ipfo_rev;		/* IPFilter version number */
1025 	u_32_t	ipfo_size;		/* size of object at ipfo_ptr */
1026 	void	*ipfo_ptr;		/* pointer to object */
1027 	int	ipfo_type;		/* type of object being pointed to */
1028 	int	ipfo_offset;		/* bytes from ipfo_ptr where to start */
1029 	u_char	ipfo_xxxpad[32];	/* reserved for future use */
1030 } ipfobj_t;
1031 
1032 #define	IPFOBJ_FRENTRY		0	/* struct frentry */
1033 #define	IPFOBJ_IPFSTAT		1	/* struct friostat */
1034 #define	IPFOBJ_IPFINFO		2	/* struct fr_info */
1035 #define	IPFOBJ_AUTHSTAT		3	/* struct fr_authstat */
1036 #define	IPFOBJ_FRAGSTAT		4	/* struct ipfrstat */
1037 #define	IPFOBJ_IPNAT		5	/* struct ipnat */
1038 #define	IPFOBJ_NATSTAT		6	/* struct natstat */
1039 #define	IPFOBJ_STATESAVE	7	/* struct ipstate_save */
1040 #define	IPFOBJ_NATSAVE		8	/* struct nat_save */
1041 #define	IPFOBJ_NATLOOKUP	9	/* struct natlookup */
1042 #define	IPFOBJ_IPSTATE		10	/* struct ipstate */
1043 #define	IPFOBJ_STATESTAT	11	/* struct ips_stat */
1044 #define	IPFOBJ_FRAUTH		12	/* struct frauth */
1045 #define	IPFOBJ_TUNEABLE		13	/* struct ipftune */
1046 
1047 
1048 typedef	union	ipftunevalptr	{
1049 	void	*ipftp_void;
1050 	u_long	*ipftp_long;
1051 	u_int	*ipftp_int;
1052 	u_short	*ipftp_short;
1053 	u_char	*ipftp_char;
1054 } ipftunevalptr_t;
1055 
1056 typedef	struct	ipftuneable	{
1057 	ipftunevalptr_t	ipft_una;
1058 	char		*ipft_name;
1059 	u_long		ipft_min;
1060 	u_long		ipft_max;
1061 	int		ipft_sz;
1062 	int		ipft_flags;
1063 } ipftuneable_t;
1064 
1065 #define	ipft_addr	ipft_una.ipftp_void
1066 #define	ipft_plong	ipft_una.ipftp_long
1067 #define	ipft_pint	ipft_una.ipftp_int
1068 #define	ipft_pshort	ipft_una.ipftp_short
1069 #define	ipft_pchar	ipft_una.ipftp_char
1070 
1071 #define	IPFT_RDONLY	1	/* read-only */
1072 #define	IPFT_WRDISABLED	2	/* write when disabled only */
1073 
1074 typedef	union	ipftuneval	{
1075 	u_long	ipftu_long;
1076 	u_int	ipftu_int;
1077 	u_short	ipftu_short;
1078 	u_char	ipftu_char;
1079 } ipftuneval_t;
1080 
1081 typedef	struct	ipftune	{
1082 	void    	*ipft_cookie;
1083 	ipftuneval_t	ipft_un;
1084 	u_long  	ipft_min;
1085 	u_long  	ipft_max;
1086 	int		ipft_sz;
1087 	int		ipft_flags;
1088 	char		ipft_name[80];
1089 } ipftune_t;
1090 
1091 #define	ipft_vlong	ipft_un.ipftu_long
1092 #define	ipft_vint	ipft_un.ipftu_int
1093 #define	ipft_vshort	ipft_un.ipftu_short
1094 #define	ipft_vchar	ipft_un.ipftu_char
1095 
1096 
1097 /*
1098 ** HPUX Port
1099 */
1100 #ifdef __hpux
1101 /* HP-UX locking sequence deadlock detection module lock MAJOR ID */
1102 # define	IPF_SMAJ	0	/* temp assignment XXX, not critical */
1103 #endif
1104 
1105 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \
1106     (__FreeBSD_version >= 220000)
1107 # define	CDEV_MAJOR	79
1108 #endif
1109 
1110 /*
1111  * Post NetBSD 1.2 has the PFIL interface for packet filters.  This turns
1112  * on those hooks.  We don't need any special mods in non-IP Filter code
1113  * with this!
1114  */
1115 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \
1116     (defined(NetBSD1_2) && NetBSD1_2 > 1) || \
1117     (defined(__FreeBSD__) && (__FreeBSD_version >= 500043))
1118 # if (NetBSD >= 199905)
1119 #  define PFIL_HOOKS
1120 # endif
1121 # ifdef PFIL_HOOKS
1122 #  define NETBSD_PF
1123 # endif
1124 #endif
1125 
1126 #ifndef	_KERNEL
1127 extern	int	fr_check __P((struct ip *, int, void *, int, mb_t **));
1128 extern	int	(*fr_checkp) __P((ip_t *, int, void *, int, mb_t **));
1129 extern	int	ipf_log __P((void));
1130 extern	struct	ifnet *get_unit __P((char *, int));
1131 extern	char	*get_ifname __P((struct ifnet *));
1132 # if defined(__NetBSD__) || defined(__OpenBSD__) || \
1133 	  (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000)
1134 extern	int	frrequest __P((int, u_long, caddr_t, int, int));
1135 extern	int	iplioctl __P((int, u_long, caddr_t, int));
1136 extern	int	fr_ipftune __P((u_long, char *));
1137 # else
1138 extern	int	frrequest __P((int, int, caddr_t, int, int));
1139 extern	int	iplioctl __P((int, int, caddr_t, int));
1140 extern	int	fr_ipftune __P((int, char *));
1141 # endif
1142 extern	int	iplopen __P((dev_t, int));
1143 extern	int	iplclose __P((dev_t, int));
1144 extern	void	m_freem __P((mb_t *));
1145 #else /* #ifndef _KERNEL */
1146 extern	void	*fr_pullup __P((mb_t *, fr_info_t *, int));
1147 # if defined(__NetBSD__) && defined(PFIL_HOOKS)
1148 extern	void	ipfilterattach __P((int));
1149 # endif
1150 extern	int	ipl_enable __P((void));
1151 extern	int	ipl_disable __P((void));
1152 # ifdef MENTAT
1153 extern	int	frrequest __P((int, int, caddr_t, int, int));
1154 extern	int	fr_check __P((struct ip *, int, void *, int, struct qif *,
1155 			      mblk_t **));
1156 #  if SOLARIS
1157 #   if SOLARIS2 >= 7
1158 extern	int	iplioctl __P((dev_t, int, intptr_t, int, cred_t *, int *));
1159 extern	int	fr_ipftune __P((int, char *));
1160 #   else
1161 extern	int	iplioctl __P((dev_t, int, int *, int, cred_t *, int *));
1162 extern	int	fr_ipftune __P((int, char *));
1163 #   endif
1164 extern	int	iplopen __P((dev_t *, int, int, cred_t *));
1165 extern	int	iplclose __P((dev_t, int, int, cred_t *));
1166 extern	int	iplread __P((dev_t, struct uio *, cred_t *));
1167 #  endif
1168 #  ifdef __hpux
1169 extern	int	iplopen __P((dev_t, int, intptr_t, int));
1170 extern	int	iplclose __P((dev_t, int, int));
1171 extern	int	iplioctl __P((dev_t, int, caddr_t, int));
1172 extern	int	fr_ipftune __P((int, char *));
1173 extern	int	iplread __P((dev_t, struct uio *));
1174 extern	int	iplselect __P((dev_t, int));
1175 #  endif
1176 extern	int	ipfsync __P((void));
1177 extern	int	fr_qout __P((queue_t *, mblk_t *));
1178 extern	void	copyin_mblk __P((mblk_t *, size_t, size_t, char *));
1179 # else /* MENTAT */
1180 extern	int	fr_check __P((struct ip *, int, void *, int, mb_t **));
1181 extern	int	(*fr_checkp) __P((ip_t *, int, void *, int, mb_t **));
1182 extern	size_t	mbufchainlen __P((mb_t *));
1183 #  ifdef	__sgi
1184 #   include <sys/cred.h>
1185 extern	int	frrequest __P((int, int, caddr_t, int, int));
1186 extern	int	iplioctl __P((dev_t, int, caddr_t, int, cred_t *, int *));
1187 extern	int	fr_ipftune __P((int, char *));
1188 extern	int	iplopen __P((dev_t *, int, int, cred_t *));
1189 extern	int	iplclose __P((dev_t, int, int, cred_t *));
1190 extern	int	iplread __P((dev_t, struct uio *, cred_t *));
1191 extern	int	ipfsync __P((void));
1192 extern	int	ipfilter_sgi_attach __P((void));
1193 extern	void	ipfilter_sgi_detach __P((void));
1194 extern	void	ipfilter_sgi_intfsync __P((void));
1195 #  else
1196 #   ifdef	IPFILTER_LKM
1197 extern	int	iplidentify __P((char *));
1198 #   endif
1199 #   if (_BSDI_VERSION >= 199510) || (__FreeBSD_version >= 220000) || \
1200       (NetBSD >= 199511) || defined(__OpenBSD__)
1201 #    if defined(__NetBSD__) || (_BSDI_VERSION >= 199701) || \
1202        defined(__OpenBSD__) || (__FreeBSD_version >= 300000)
1203 extern	int	frrequest __P((int, u_long, caddr_t, int, int));
1204 #     if (__FreeBSD_version >= 500024)
1205 extern	int	iplioctl __P((dev_t, u_long, caddr_t, int, struct thread *));
1206 extern	int	fr_ipftune __P((u_long, char *));
1207 #     else
1208 extern	int	iplioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
1209 extern	int	fr_ipftune __P((u_long, char *));
1210 #     endif /* __FreeBSD_version >= 500024 */
1211 #    else
1212 extern	int	frrequest __P((int, int, caddr_t, int, int));
1213 extern	int	iplioctl __P((dev_t, int, caddr_t, int, struct proc *));
1214 extern	int	fr_ipftune __P((int, char *));
1215 #    endif
1216 #    if (__FreeBSD_version >= 500024)
1217 extern	int	iplopen __P((dev_t, int, int, struct thread *));
1218 extern	int	iplclose __P((dev_t, int, int, struct thread *));
1219 #    else
1220 extern	int	iplopen __P((dev_t, int, int, struct proc *));
1221 extern	int	iplclose __P((dev_t, int, int, struct proc *));
1222 #    endif /* __FreeBSD_version >= 500024 */
1223 #   else
1224 extern	int	iplopen __P((dev_t, int));
1225 extern	int	iplclose __P((dev_t, int));
1226 extern	int	frrequest __P((int, int, caddr_t, int, int));
1227 extern	int	iplioctl __P((dev_t, int, caddr_t, int));
1228 extern	int	fr_ipftune __P((int, char *));
1229 #   endif /* (_BSDI_VERSION >= 199510) */
1230 #   if	BSD >= 199306
1231 extern	int	iplread __P((dev_t, struct uio *, int));
1232 #   else
1233 extern	int	iplread __P((dev_t, struct uio *));
1234 #   endif /* BSD >= 199306 */
1235 #  endif /* __ sgi */
1236 # endif /* MENTAT */
1237 
1238 #endif /* #ifndef _KERNEL */
1239 
1240 extern	ipfmutex_t	ipl_mutex, ipf_authmx, ipf_rw, ipf_hostmap;
1241 extern	ipfmutex_t	ipf_timeoutlock;
1242 extern	ipfrwlock_t	ipf_mutex, ipf_global, ip_poolrw;
1243 extern	ipfrwlock_t	ipf_frag, ipf_state, ipf_nat, ipf_natfrag, ipf_auth;
1244 
1245 extern	char	*memstr __P((char *, char *, int, int));
1246 extern	int	count4bits __P((u_32_t));
1247 #ifdef USE_INET6
1248 extern	int	count6bits __P((u_32_t *));
1249 #endif
1250 extern	char	*getifname __P((struct ifnet *));
1251 extern	int	iplattach __P((void));
1252 extern	int	ipldetach __P((void));
1253 # if defined(__NetBSD__) || defined(__OpenBSD__)
1254 extern  INLINE  int     fr_ioctlswitch __P((int, void *, u_long, int));
1255 #else
1256 extern  INLINE  int     fr_ioctlswitch __P((int, void *, int, int));
1257 #endif
1258 extern	u_short	ipf_cksum __P((u_short *, int));
1259 extern	int	copyinptr __P((void *, void *, size_t));
1260 extern	int	copyoutptr __P((void *, void *, size_t));
1261 extern	int	fr_inobj __P((void *, void *, int));
1262 extern	int	fr_outobj __P((void *, void *, int));
1263 extern	int	fr_send_reset __P((fr_info_t *));
1264 extern	int	fr_send_icmp_err __P((int, fr_info_t *, int));
1265 extern	void	fr_resolvdest __P((struct frdest *, int));
1266 extern	int	fr_resolvefunc __P((void *));
1267 extern	int	fr_fastroute __P((mb_t *, mb_t **, fr_info_t *, frdest_t *));
1268 extern	int	ppsratecheck __P((struct timeval *, int *, int));
1269 extern	ipftq_t	*fr_addtimeoutqueue __P((ipftq_t **, u_int));
1270 extern	void	fr_deletetimeoutqueue __P((ipftq_t *));
1271 extern	void	fr_movequeue __P((ipftqent_t *, ipftq_t *, ipftq_t *));
1272 extern	void	fr_queuefront __P((ipftqent_t *));
1273 extern	void	fr_queueback __P((ipftqent_t *));
1274 extern	void	fr_checkv4sum __P((fr_info_t *));
1275 extern	int	fr_checkl4sum __P((fr_info_t *));
1276 extern	int	fr_ifpfillv4addr __P((int, struct sockaddr_in *,
1277 				      struct sockaddr_in *, struct in_addr *,
1278 				      struct in_addr *));
1279 extern	int	fr_coalesce __P((fr_info_t *));
1280 #ifdef	USE_INET6
1281 extern	void	fr_checkv6sum __P((fr_info_t *));
1282 extern	int	fr_ifpfillv6addr __P((int, struct sockaddr_in6 *,
1283 				      struct sockaddr_in6 *, struct in_addr *,
1284 				      struct in_addr *));
1285 #endif
1286 
1287 extern	int	frflush __P((minor_t, int, int));
1288 extern	void	frsync __P((void));
1289 extern	frgroup_t *fr_addgroup __P((char *, void *, u_32_t, minor_t, int));
1290 extern	int	fr_derefrule __P((frentry_t **));
1291 extern	void	fr_delgroup __P((char *, minor_t, int));
1292 extern	frgroup_t *fr_findgroup __P((char *, minor_t, int, frgroup_t ***));
1293 
1294 extern	int	fr_loginit __P((void));
1295 extern	int	ipflog_clear __P((minor_t));
1296 extern	int	ipflog_read __P((minor_t, struct uio *));
1297 extern	int	ipflog __P((fr_info_t *, u_int));
1298 extern	int	ipllog __P((int, fr_info_t *, void **, size_t *, int *, int));
1299 extern	void	fr_logunload __P((void));
1300 
1301 extern	frentry_t	*fr_acctpkt __P((fr_info_t *, u_32_t *));
1302 extern	int		fr_copytolog __P((int, char *, int));
1303 extern	u_short		fr_cksum __P((mb_t *, ip_t *, int, void *));
1304 extern	frentry_t 	*fr_dolog __P((fr_info_t *, u_32_t *));
1305 extern	frentry_t 	*fr_dstgrpmap __P((fr_info_t *, u_32_t *));
1306 extern	void		fr_fixskip __P((frentry_t **, frentry_t *, int));
1307 extern	void		fr_forgetifp __P((void *));
1308 extern	frentry_t 	*fr_getrulen __P((int, char *, u_32_t));
1309 extern	void		fr_getstat __P((struct friostat *));
1310 extern	int		fr_ifpaddr __P((int, int, void *,
1311 				struct in_addr *, struct in_addr *));
1312 extern	int		fr_lock __P((caddr_t, int *));
1313 extern  int		fr_makefrip __P((int, ip_t *, fr_info_t *));
1314 extern	int		fr_matchtag __P((ipftag_t *, ipftag_t *));
1315 extern	int		fr_matchicmpqueryreply __P((int, icmpinfo_t *,
1316 					    struct icmp *, int));
1317 extern	u_32_t		fr_newisn __P((fr_info_t *));
1318 extern	INLINE	u_short	fr_nextipid __P((fr_info_t *));
1319 extern	int		fr_rulen __P((int, frentry_t *));
1320 extern	int		fr_scanlist __P((fr_info_t *, u_32_t));
1321 extern	frentry_t 	*fr_srcgrpmap __P((fr_info_t *, u_32_t *));
1322 extern	int		fr_tcpudpchk __P((fr_info_t *, frtuc_t *));
1323 extern	int		fr_verifysrc __P((fr_info_t *fin));
1324 
1325 extern	int	fr_unreach;
1326 extern	int	fr_running;
1327 extern	u_long	fr_frouteok[2];
1328 extern	int	fr_pass;
1329 extern	int	fr_flags;
1330 extern	int	fr_active;
1331 extern	int	fr_chksrc;
1332 extern	int	fr_minttl;
1333 extern	int	fr_refcnt;
1334 extern	int	fr_control_forwarding;
1335 extern	int	fr_update_ipid;
1336 extern	int	nat_logging;
1337 extern	int	ipstate_logging;
1338 extern	int	ipl_suppress;
1339 extern	int	ipl_buffer_sz;
1340 extern	int	ipl_logmax;
1341 extern	int	ipl_logall;
1342 extern	u_long	fr_ticks;
1343 extern	fr_info_t	frcache[2][8];
1344 extern	char	ipfilter_version[];
1345 extern	iplog_t	**iplh[IPL_LOGMAX+1], *iplt[IPL_LOGMAX+1];
1346 extern	int	iplused[IPL_LOGMAX + 1];
1347 extern	struct frentry *ipfilter[2][2], *ipacct[2][2];
1348 #ifdef	USE_INET6
1349 extern	struct frentry *ipfilter6[2][2], *ipacct6[2][2];
1350 extern	int	icmptoicmp6types[ICMP_MAXTYPE+1];
1351 extern	int	icmptoicmp6unreach[ICMP_MAX_UNREACH];
1352 extern	int	icmpreplytype6[ICMP6_MAXTYPE + 1];
1353 #endif
1354 extern	int	icmpreplytype4[ICMP_MAXTYPE + 1];
1355 extern	struct frgroup *ipfgroups[IPL_LOGSIZE][2];
1356 extern	struct filterstats frstats[];
1357 extern	int	icmpreplytype4[ICMP_MAXTYPE + 1];
1358 extern	struct frgroup *ipfgroups[IPL_LOGSIZE][2];
1359 extern	struct filterstats frstats[];
1360 extern	frentry_t *ipfrule_match __P((fr_info_t *));
1361 extern	u_char	ipf_iss_secret[32];
1362 
1363 
1364 #endif	/* __IP_FIL_H__ */
1365