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