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