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