Print this page
2976 remove useless offsetof() macros
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/inet/ipf/netinet/ip_fil.h
+++ new/usr/src/uts/common/inet/ipf/netinet/ip_fil.h
1 1 /*
2 2 * Copyright (C) 1993-2001, 2003 by Darren Reed.
3 3 *
4 4 * See the IPFILTER.LICENCE file for details on licencing.
5 5 *
6 6 * @(#)ip_fil.h 1.35 6/5/96
7 7 * $Id: ip_fil.h,v 2.170.2.22 2005/07/16 05:55:35 darrenr Exp $
8 8 *
9 9 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
10 10 *
11 11 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
12 12 */
13 13
14 14 #ifndef __IP_FIL_H__
15 15 #define __IP_FIL_H__
16 16
17 17 #include "netinet/ip_compat.h"
18 18 #include <sys/zone.h>
19 19
20 20 #ifndef SOLARIS
21 21 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
22 22 #endif
23 23
24 24 #ifndef __P
25 25 # ifdef __STDC__
26 26 # define __P(x) x
27 27 # else
28 28 # define __P(x) ()
29 29 # endif
30 30 #endif
31 31
32 32 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
33 33 # define SIOCADAFR _IOW('r', 60, struct ipfobj)
34 34 # define SIOCRMAFR _IOW('r', 61, struct ipfobj)
35 35 # define SIOCSETFF _IOW('r', 62, u_int)
36 36 # define SIOCGETFF _IOR('r', 63, u_int)
37 37 # define SIOCGETFS _IOWR('r', 64, struct ipfobj)
38 38 # define SIOCIPFFL _IOWR('r', 65, int)
39 39 # define SIOCIPFFB _IOR('r', 66, int)
40 40 # define SIOCADIFR _IOW('r', 67, struct ipfobj)
41 41 # define SIOCRMIFR _IOW('r', 68, struct ipfobj)
42 42 # define SIOCSWAPA _IOR('r', 69, u_int)
43 43 # define SIOCINAFR _IOW('r', 70, struct ipfobj)
44 44 # define SIOCINIFR _IOW('r', 71, struct ipfobj)
45 45 # define SIOCFRENB _IOW('r', 72, u_int)
46 46 # define SIOCFRSYN _IOW('r', 73, u_int)
47 47 # define SIOCFRZST _IOWR('r', 74, struct ipfobj)
48 48 # define SIOCZRLST _IOWR('r', 75, struct ipfobj)
49 49 # define SIOCAUTHW _IOWR('r', 76, struct ipfobj)
50 50 # define SIOCAUTHR _IOWR('r', 77, struct ipfobj)
51 51 # define SIOCATHST _IOWR('r', 78, struct ipfobj)
52 52 # define SIOCSTLCK _IOWR('r', 79, u_int)
53 53 # define SIOCSTPUT _IOWR('r', 80, struct ipfobj)
54 54 # define SIOCSTGET _IOWR('r', 81, struct ipfobj)
55 55 # define SIOCSTGSZ _IOWR('r', 82, struct ipfobj)
56 56 # define SIOCGFRST _IOWR('r', 83, struct ipfobj)
57 57 # define SIOCSETLG _IOWR('r', 84, int)
58 58 # define SIOCGETLG _IOWR('r', 85, int)
59 59 # define SIOCFUNCL _IOWR('r', 86, struct ipfunc_resolve)
60 60 # define SIOCIPFGETNEXT _IOWR('r', 87, struct ipfobj)
61 61 # define SIOCIPFGET _IOWR('r', 88, struct ipfobj)
62 62 # define SIOCIPFSET _IOWR('r', 89, struct ipfobj)
63 63 # define SIOCIPFL6 _IOWR('r', 90, int)
64 64 # define SIOCIPFLP _IOWR('r', 91, int)
65 65 # define SIOCIPFITER _IOWR('r', 92, struct ipfobj)
66 66 # define SIOCGENITER _IOWR('r', 93, struct ipfobj)
67 67 # define SIOCGTABL _IOWR('r', 94, struct ipfobj)
68 68 # define SIOCIPFDELTOK _IOWR('r', 95, int)
69 69 # define SIOCLOOKUPITER _IOWR('r', 96, struct ipfobj)
70 70 #else
71 71 # define SIOCADAFR _IOW(r, 60, struct ipfobj)
72 72 # define SIOCRMAFR _IOW(r, 61, struct ipfobj)
73 73 # define SIOCSETFF _IOW(r, 62, u_int)
74 74 # define SIOCGETFF _IOR(r, 63, u_int)
75 75 # define SIOCGETFS _IOWR(r, 64, struct ipfobj)
76 76 # define SIOCIPFFL _IOWR(r, 65, int)
77 77 # define SIOCIPFFB _IOR(r, 66, int)
78 78 # define SIOCADIFR _IOW(r, 67, struct ipfobj)
79 79 # define SIOCRMIFR _IOW(r, 68, struct ipfobj)
80 80 # define SIOCSWAPA _IOR(r, 69, u_int)
81 81 # define SIOCINAFR _IOW(r, 70, struct ipfobj)
82 82 # define SIOCINIFR _IOW(r, 71, struct ipfobj)
83 83 # define SIOCFRENB _IOW(r, 72, u_int)
84 84 # define SIOCFRSYN _IOW(r, 73, u_int)
85 85 # define SIOCFRZST _IOWR(r, 74, struct ipfobj)
86 86 # define SIOCZRLST _IOWR(r, 75, struct ipfobj)
87 87 # define SIOCAUTHW _IOWR(r, 76, struct ipfobj)
88 88 # define SIOCAUTHR _IOWR(r, 77, struct ipfobj)
89 89 # define SIOCATHST _IOWR(r, 78, struct ipfobj)
90 90 # define SIOCSTLCK _IOWR(r, 79, u_int)
91 91 # define SIOCSTPUT _IOWR(r, 80, struct ipfobj)
92 92 # define SIOCSTGET _IOWR(r, 81, struct ipfobj)
93 93 # define SIOCSTGSZ _IOWR(r, 82, struct ipfobj)
94 94 # define SIOCGFRST _IOWR(r, 83, struct ipfobj)
95 95 # define SIOCSETLG _IOWR(r, 84, int)
96 96 # define SIOCGETLG _IOWR(r, 85, int)
97 97 # define SIOCFUNCL _IOWR(r, 86, struct ipfunc_resolve)
98 98 # define SIOCIPFGETNEXT _IOWR(r, 87, struct ipfobj)
99 99 # define SIOCIPFGET _IOWR(r, 88, struct ipfobj)
100 100 # define SIOCIPFSET _IOWR(r, 89, struct ipfobj)
101 101 # define SIOCIPFL6 _IOWR(r, 90, int)
102 102 # define SIOCIPFLP _IOWR(r, 91, int)
103 103 # define SIOCIPFITER _IOWR(r, 92, struct ipfobj)
104 104 # define SIOCGENITER _IOWR(r, 93, struct ipfobj)
105 105 # define SIOCGTABL _IOWR(r, 94, struct ipfobj)
106 106 # define SIOCIPFDELTOK _IOWR(r, 95, int)
107 107 # define SIOCLOOKUPITER _IOWR(r, 96, struct ipfobj)
108 108 #endif
109 109 #define SIOCADDFR SIOCADAFR
110 110 #define SIOCDELFR SIOCRMAFR
111 111 #define SIOCINSFR SIOCINAFR
112 112 # define SIOCIPFZONESET _IOWR('r', 97, struct ipfzoneobj)
113 113
114 114 /*
115 115 * What type of table is getting flushed?
116 116 */
117 117
118 118 #define NAT_FLUSH 1
119 119 #define STATE_FLUSH 2
120 120
121 121 /*
122 122 * What table flush options are available?
123 123 */
124 124
125 125 #define FLUSH_LIST 0
126 126 #define FLUSH_TABLE_ALL 1 /* Flush entire table */
127 127 #define FLUSH_TABLE_CLOSING 2 /* Flush "closing" entries" */
128 128 #define FLUSH_TABLE_EXTRA 3 /* Targetted flush: almost closed, long idle */
129 129
130 130 #define VALID_TABLE_FLUSH_OPT(x) ((x) >= 1 && (x) <= 3)
131 131
132 132 /*
133 133 * Define the default hi and lo watermarks used when flushing the
134 134 * tables. The values represent percent full of respective tables.
135 135 */
136 136
137 137 #define NAT_FLUSH_HI 95
138 138 #define NAT_FLUSH_LO 75
139 139
140 140 #define ST_FLUSH_HI 95
141 141 #define ST_FLUSH_LO 75
142 142
143 143 /*
144 144 * How full are the tables?
145 145 */
146 146
147 147 #define NAT_TAB_WATER_LEVEL(x) ((x)->ifs_nat_stats.ns_inuse * 100 \
148 148 / (x)->ifs_ipf_nattable_max)
149 149
150 150 #define ST_TAB_WATER_LEVEL(x) ((x)->ifs_ips_num * 100 \
151 151 / (x)->ifs_fr_statemax)
152 152
153 153 struct ipscan;
154 154 struct ifnet;
155 155
156 156 typedef struct ipf_stack ipf_stack_t;
157 157 typedef struct fr_info fr_info_t;
158 158
159 159 typedef int (* lookupfunc_t) __P((void *, int, void *, fr_info_t *, ipf_stack_t *));
160 160
161 161 /*
162 162 * i6addr is used as a container for both IPv4 and IPv6 addresses, as well
163 163 * as other types of objects, depending on its qualifier.
164 164 */
165 165 #ifdef USE_INET6
166 166 typedef union i6addr {
167 167 u_32_t i6[4];
168 168 struct in_addr in4;
169 169 struct in6_addr in6;
170 170 void *vptr[2];
171 171 lookupfunc_t lptr[2];
172 172 } i6addr_t;
173 173 #define in6_addr8 in6.s6_addr
174 174 #else
175 175 typedef union i6addr {
176 176 u_32_t i6[4];
177 177 struct in_addr in4;
178 178 void *vptr[2];
179 179 lookupfunc_t lptr[2];
180 180 } i6addr_t;
181 181 #endif
182 182
183 183 #define in4_addr in4.s_addr
184 184 #define iplookupnum i6[0]
185 185 #define iplookuptype i6[1]
186 186 /*
187 187 * NOTE: These DO overlap the above on 64bit systems and this IS recognised.
188 188 */
189 189 #define iplookupptr vptr[0]
190 190 #define iplookupfunc lptr[1]
191 191
192 192 #define I60(x) (((i6addr_t *)(x))->i6[0])
193 193 #define I61(x) (((i6addr_t *)(x))->i6[1])
194 194 #define I62(x) (((i6addr_t *)(x))->i6[2])
195 195 #define I63(x) (((i6addr_t *)(x))->i6[3])
196 196 #define HI60(x) ntohl(((i6addr_t *)(x))->i6[0])
197 197 #define HI61(x) ntohl(((i6addr_t *)(x))->i6[1])
198 198 #define HI62(x) ntohl(((i6addr_t *)(x))->i6[2])
199 199 #define HI63(x) ntohl(((i6addr_t *)(x))->i6[3])
200 200
201 201 #define IP6_EQ(a,b) ((I63(a) == I63(b)) && (I62(a) == I62(b)) && \
202 202 (I61(a) == I61(b)) && (I60(a) == I60(b)))
203 203 #define IP6_NEQ(a,b) ((I63(a) != I63(b)) || (I62(a) != I62(b)) || \
204 204 (I61(a) != I61(b)) || (I60(a) != I60(b)))
205 205 #define IP6_ISZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) == 0)
206 206 #define IP6_NOTZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) != 0)
207 207 #define IP6_ISONES(a) ((I63(a) == 0xffffffff) && (I62(a) == 0xffffffff) && \
208 208 (I61(a) == 0xffffffff) && (I60(a) == 0xffffffff))
209 209 #define IP6_GT(a,b) (ntohl(HI60(a)) > ntohl(HI60(b)) || \
210 210 (HI60(a) == HI60(b) && \
211 211 (ntohl(HI61(a)) > ntohl(HI61(b)) || \
212 212 (HI61(a) == HI61(b) && \
213 213 (ntohl(HI62(a)) > ntohl(HI62(b)) || \
214 214 (HI62(a) == HI62(b) && \
215 215 ntohl(HI63(a)) > ntohl(HI63(b))))))))
216 216 #define IP6_LT(a,b) (ntohl(HI60(a)) < ntohl(HI60(b)) || \
217 217 (HI60(a) == HI60(b) && \
218 218 (ntohl(HI61(a)) < ntohl(HI61(b)) || \
219 219 (HI61(a) == HI61(b) && \
220 220 (ntohl(HI62(a)) < ntohl(HI62(b)) || \
221 221 (HI62(a) == HI62(b) && \
222 222 ntohl(HI63(a)) < ntohl(HI63(b))))))))
223 223 #define NLADD(n,x) htonl(ntohl(n) + (x))
224 224 #define IP6_INC(a) \
225 225 { i6addr_t *_i6 = (i6addr_t *)(a); \
226 226 _i6->i6[3] = NLADD(_i6->i6[3], 1); \
227 227 if (_i6->i6[3] == 0) { \
228 228 _i6->i6[2] = NLADD(_i6->i6[2], 1); \
229 229 if (_i6->i6[2] == 0) { \
230 230 _i6->i6[1] = NLADD(_i6->i6[1], 1); \
231 231 if (_i6->i6[1] == 0) { \
232 232 _i6->i6[0] = NLADD(_i6->i6[0], 1); \
233 233 } \
234 234 } \
235 235 } \
236 236 }
237 237 #define IP6_ADD(a,x,d) \
238 238 { i6addr_t *_s = (i6addr_t *)(a); \
239 239 i6addr_t *_d = (i6addr_t *)(d); \
240 240 _d->i6[3] = NLADD(_s->i6[3], x); \
241 241 if (ntohl(_d->i6[3]) < ntohl(_s->i6[3])) { \
242 242 _d->i6[2] = NLADD(_d->i6[2], 1); \
243 243 if (ntohl(_d->i6[2]) < ntohl(_s->i6[2])) { \
244 244 _d->i6[1] = NLADD(_d->i6[1], 1); \
245 245 if (ntohl(_d->i6[1]) < ntohl(_s->i6[1])) { \
246 246 _d->i6[0] = NLADD(_d->i6[0], 1); \
247 247 } \
248 248 } \
249 249 } \
250 250 }
251 251 #define IP6_AND(a,b,d) { i6addr_t *_s1 = (i6addr_t *)(a); \
252 252 i6addr_t *_s2 = (i6addr_t *)(b); \
253 253 i6addr_t *_d = (i6addr_t *)(d); \
254 254 _d->i6[0] = _s1->i6[0] & _s2->i6[0]; \
255 255 _d->i6[1] = _s1->i6[1] & _s2->i6[1]; \
256 256 _d->i6[2] = _s1->i6[2] & _s2->i6[2]; \
257 257 _d->i6[3] = _s1->i6[3] & _s2->i6[3]; \
258 258 }
259 259 #define IP6_MASKEQ(a,m,b) \
260 260 (((I60(a) & I60(m)) == I60(b)) && \
261 261 ((I61(a) & I61(m)) == I61(b)) && \
262 262 ((I62(a) & I62(m)) == I62(b)) && \
263 263 ((I63(a) & I63(m)) == I63(b)))
264 264 #define IP6_MASKNEQ(a,m,b) \
265 265 (((I60(a) & I60(m)) != I60(b)) || \
266 266 ((I61(a) & I61(m)) != I61(b)) || \
267 267 ((I62(a) & I62(m)) != I62(b)) || \
268 268 ((I63(a) & I63(m)) != I63(b)))
269 269 #define IP6_MERGE(a,b,c) \
270 270 { i6addr_t *_d, *_s1, *_s2; \
271 271 _d = (i6addr_t *)(a); \
272 272 _s1 = (i6addr_t *)(b); \
273 273 _s2 = (i6addr_t *)(c); \
274 274 _d->i6[0] |= _s1->i6[0] & ~_s2->i6[0]; \
275 275 _d->i6[1] |= _s1->i6[1] & ~_s2->i6[1]; \
276 276 _d->i6[2] |= _s1->i6[2] & ~_s2->i6[2]; \
277 277 _d->i6[3] |= _s1->i6[3] & ~_s2->i6[3]; \
278 278 }
279 279
280 280
281 281 typedef struct fr_ip {
282 282 u_32_t fi_v:4; /* IP version */
283 283 u_32_t fi_xx:4; /* spare */
284 284 u_32_t fi_tos:8; /* IP packet TOS */
285 285 u_32_t fi_ttl:8; /* IP packet TTL */
286 286 u_32_t fi_p:8; /* IP packet protocol */
287 287 u_32_t fi_optmsk; /* bitmask composed from IP options */
288 288 i6addr_t fi_src; /* source address from packet */
289 289 i6addr_t fi_dst; /* destination address from packet */
290 290 u_short fi_secmsk; /* bitmask composed from IP security options */
291 291 u_short fi_auth; /* authentication code from IP sec. options */
292 292 u_32_t fi_flx; /* packet flags */
293 293 u_32_t fi_tcpmsk; /* TCP options set/reset */
294 294 u_32_t fi_res1; /* RESERVED */
295 295 } fr_ip_t;
296 296
297 297 /*
298 298 * For use in fi_flx
299 299 */
300 300 #define FI_TCPUDP 0x0001 /* TCP/UCP implied comparison*/
301 301 #define FI_OPTIONS 0x0002
302 302 #define FI_FRAG 0x0004
303 303 #define FI_SHORT 0x0008
304 304 #define FI_NATED 0x0010
305 305 #define FI_MULTICAST 0x0020
306 306 #define FI_BROADCAST 0x0040
307 307 #define FI_MBCAST 0x0080
308 308 #define FI_STATE 0x0100
309 309 #define FI_BADNAT 0x0200
310 310 #define FI_BAD 0x0400
311 311 #define FI_OOW 0x0800 /* Out of state window, else match */
312 312 #define FI_ICMPERR 0x1000
313 313 #define FI_FRAGBODY 0x2000
314 314 #define FI_BADSRC 0x4000
315 315 #define FI_LOWTTL 0x8000
316 316 #define FI_CMP 0xcf03 /* Not FI_FRAG,FI_NATED,FI_FRAGTAIL,broadcast */
317 317 #define FI_ICMPCMP 0x0003 /* Flags we can check for ICMP error packets */
318 318 #define FI_WITH 0xeffe /* Not FI_TCPUDP */
319 319 #define FI_V6EXTHDR 0x10000
320 320 #define FI_COALESCE 0x20000
321 321 #define FI_ICMPQUERY 0x40000
322 322 #define FI_NEWNAT 0x80000
323 323 #define FI_MOREFRAG 0x100000
324 324 #define FI_NEG_OOW 0x10000000 /* packet underflows TCP window */
325 325 #define FI_NOCKSUM 0x20000000 /* don't do a L4 checksum validation */
326 326 #define FI_DONTCACHE 0x40000000 /* don't cache the result */
327 327 #define FI_IGNORE 0x80000000
328 328
329 329 #define fi_saddr fi_src.in4.s_addr
330 330 #define fi_daddr fi_dst.in4.s_addr
331 331 #define fi_srcnum fi_src.iplookupnum
332 332 #define fi_dstnum fi_dst.iplookupnum
333 333 #define fi_srctype fi_src.iplookuptype
334 334 #define fi_dsttype fi_dst.iplookuptype
335 335 #define fi_srcptr fi_src.iplookupptr
336 336 #define fi_dstptr fi_dst.iplookupptr
337 337 #define fi_srcfunc fi_src.iplookupfunc
338 338 #define fi_dstfunc fi_dst.iplookupfunc
339 339
340 340
341 341 /*
342 342 * These are both used by the state and NAT code to indicate that one port or
343 343 * the other should be treated as a wildcard.
344 344 * NOTE: When updating, check bit masks in ip_state.h and update there too.
345 345 */
346 346 #define SI_W_SPORT 0x00000100
347 347 #define SI_W_DPORT 0x00000200
348 348 #define SI_WILDP (SI_W_SPORT|SI_W_DPORT)
349 349 #define SI_W_SADDR 0x00000400
350 350 #define SI_W_DADDR 0x00000800
351 351 #define SI_WILDA (SI_W_SADDR|SI_W_DADDR)
352 352 #define SI_NEWFR 0x00001000
353 353 #define SI_CLONE 0x00002000
354 354 #define SI_CLONED 0x00004000
355 355
356 356
357 357
358 358
359 359 struct fr_info {
360 360 void *fin_ifp; /* interface packet is `on' */
361 361 fr_ip_t fin_fi; /* IP Packet summary */
362 362 union {
363 363 u_short fid_16[2]; /* TCP/UDP ports, ICMP code/type */
364 364 u_32_t fid_32;
365 365 } fin_dat;
366 366 int fin_out; /* in or out ? 1 == out, 0 == in */
367 367 int fin_rev; /* state only: 1 = reverse */
368 368 u_short fin_hlen; /* length of IP header in bytes */
369 369 u_char fin_tcpf; /* TCP header flags (SYN, ACK, etc) */
370 370 u_char fin_icode; /* ICMP error to return */
371 371 u_32_t fin_rule; /* rule # last matched */
372 372 char fin_group[FR_GROUPLEN]; /* group number, -1 for none */
373 373 struct frentry *fin_fr; /* last matching rule */
374 374 void *fin_dp; /* start of data past IP header */
375 375 int fin_dlen; /* length of data portion of packet */
376 376 int fin_plen;
377 377 int fin_ipoff; /* # bytes from buffer start to hdr */
378 378 u_32_t fin_id; /* IP packet id field */
379 379 u_short fin_off;
380 380 int fin_depth; /* Group nesting depth */
381 381 int fin_error; /* Error code to return */
382 382 u_int fin_pktnum;
383 383 void *fin_nattag;
384 384 union {
385 385 ip_t *fip_ip;
386 386 #ifdef USE_INET6
387 387 ip6_t *fip_ip6;
388 388 #endif
389 389 } fin_ipu;
390 390 mb_t **fin_mp; /* pointer to pointer to mbuf */
391 391 mb_t *fin_m; /* pointer to mbuf */
392 392 #ifdef MENTAT
393 393 mb_t *fin_qfm; /* pointer to mblk where pkt starts */
394 394 void *fin_qpi;
395 395 ipf_stack_t *fin_ifs;
396 396 #endif
397 397 #ifdef __sgi
398 398 void *fin_hbuf;
399 399 #endif
400 400 };
401 401
402 402 #define fin_ip fin_ipu.fip_ip
403 403 #define fin_ip6 fin_ipu.fip_ip6
404 404 #define fin_v fin_fi.fi_v
405 405 #define fin_p fin_fi.fi_p
406 406 #define fin_flx fin_fi.fi_flx
407 407 #define fin_optmsk fin_fi.fi_optmsk
408 408 #define fin_secmsk fin_fi.fi_secmsk
409 409 #define fin_auth fin_fi.fi_auth
410 410 #define fin_src fin_fi.fi_src.in4
411 411 #define fin_saddr fin_fi.fi_saddr
412 412 #define fin_dst fin_fi.fi_dst.in4
413 413 #define fin_daddr fin_fi.fi_daddr
414 414 #define fin_data fin_dat.fid_16
415 415 #define fin_sport fin_dat.fid_16[0]
416 416 #define fin_dport fin_dat.fid_16[1]
417 417 #define fin_ports fin_dat.fid_32
418 418
419 419 #ifdef USE_INET6
420 420 # define fin_src6 fin_fi.fi_src
421 421 # define fin_dst6 fin_fi.fi_dst
422 422 # define fin_dstip6 fin_fi.fi_dst.in6
423 423 # define fin_srcip6 fin_fi.fi_src.in6
424 424 #endif
425 425
426 426 #define IPF_IN 0
427 427 #define IPF_OUT 1
428 428
429 429 typedef struct frentry *(*ipfunc_t) __P((fr_info_t *, u_32_t *));
430 430 typedef int (*ipfuncinit_t) __P((struct frentry *,
431 431 ipf_stack_t *));
432 432
433 433 typedef struct ipfunc_resolve {
434 434 char ipfu_name[32];
435 435 ipfunc_t ipfu_addr;
436 436 ipfuncinit_t ipfu_init;
437 437 } ipfunc_resolve_t;
438 438
439 439 /*
440 440 * Size for compares on fr_info structures
441 441 */
442 442 #define FI_CSIZE offsetof(fr_info_t, fin_icode)
443 443 #define FI_LCSIZE offsetof(fr_info_t, fin_dp)
444 444
445 445 /*
446 446 * Size for copying cache fr_info structure
447 447 */
448 448 #define FI_COPYSIZE offsetof(fr_info_t, fin_dp)
449 449
450 450 /*
451 451 * Structure for holding IPFilter's tag information
452 452 */
453 453 #define IPFTAG_LEN 16
454 454 typedef struct {
455 455 union {
456 456 u_32_t iptu_num[4];
457 457 char iptu_tag[IPFTAG_LEN];
458 458 } ipt_un;
459 459 int ipt_not;
460 460 } ipftag_t;
461 461
462 462 #define ipt_tag ipt_un.iptu_tag
463 463 #define ipt_num ipt_un.iptu_num
464 464
465 465
466 466 /*
467 467 * This structure is used to hold information about the next hop for where
468 468 * to forward a packet.
469 469 */
470 470 typedef struct frdest {
471 471 void *fd_ifp;
472 472 i6addr_t fd_ip6;
473 473 char fd_ifname[LIFNAMSIZ];
474 474 } frdest_t;
475 475
476 476 #define fd_ip fd_ip6.in4
477 477
478 478
479 479 /*
480 480 * This structure holds information about a port comparison.
481 481 */
482 482 typedef struct frpcmp {
483 483 int frp_cmp; /* data for port comparisons */
484 484 u_short frp_port; /* top port for <> and >< */
485 485 u_short frp_top; /* top port for <> and >< */
486 486 } frpcmp_t;
487 487
488 488 #define FR_NONE 0
489 489 #define FR_EQUAL 1
490 490 #define FR_NEQUAL 2
491 491 #define FR_LESST 3
492 492 #define FR_GREATERT 4
493 493 #define FR_LESSTE 5
494 494 #define FR_GREATERTE 6
495 495 #define FR_OUTRANGE 7
496 496 #define FR_INRANGE 8
497 497 #define FR_INCRANGE 9
498 498
499 499 /*
500 500 * Structure containing all the relevant TCP things that can be checked in
501 501 * a filter rule.
502 502 */
503 503 typedef struct frtuc {
504 504 u_char ftu_tcpfm; /* tcp flags mask */
505 505 u_char ftu_tcpf; /* tcp flags */
506 506 frpcmp_t ftu_src;
507 507 frpcmp_t ftu_dst;
508 508 } frtuc_t;
509 509
510 510 #define ftu_scmp ftu_src.frp_cmp
511 511 #define ftu_dcmp ftu_dst.frp_cmp
512 512 #define ftu_sport ftu_src.frp_port
513 513 #define ftu_dport ftu_dst.frp_port
514 514 #define ftu_stop ftu_src.frp_top
515 515 #define ftu_dtop ftu_dst.frp_top
516 516
517 517 #define FR_TCPFMAX 0x3f
518 518
519 519 /*
520 520 * This structure makes up what is considered to be the IPFilter specific
521 521 * matching components of a filter rule, as opposed to the data structures
522 522 * used to define the result which are in frentry_t and not here.
523 523 */
524 524 typedef struct fripf {
525 525 fr_ip_t fri_ip;
526 526 fr_ip_t fri_mip; /* mask structure */
527 527
528 528 u_short fri_icmpm; /* data for ICMP packets (mask) */
529 529 u_short fri_icmp;
530 530
531 531 frtuc_t fri_tuc;
532 532 int fri_satype; /* addres type */
533 533 int fri_datype; /* addres type */
534 534 int fri_sifpidx; /* doing dynamic addressing */
535 535 int fri_difpidx; /* index into fr_ifps[] to use when */
536 536 } fripf_t;
537 537
538 538 #define fri_dstnum fri_ip.fi_dstnum
539 539 #define fri_srcnum fri_mip.fi_srcnum
540 540 #define fri_dstptr fri_ip.fi_dstptr
541 541 #define fri_srcptr fri_mip.fi_srcptr
542 542
543 543 #define FRI_NORMAL 0 /* Normal address */
544 544 #define FRI_DYNAMIC 1 /* dynamic address */
545 545 #define FRI_LOOKUP 2 /* address is a pool # */
546 546 #define FRI_RANGE 3 /* address/mask is a range */
547 547 #define FRI_NETWORK 4 /* network address from if */
548 548 #define FRI_BROADCAST 5 /* broadcast address from if */
549 549 #define FRI_PEERADDR 6 /* Peer address for P-to-P */
550 550 #define FRI_NETMASKED 7 /* network address with netmask from if */
551 551
552 552
553 553 typedef struct frentry * (* frentfunc_t) __P((fr_info_t *));
554 554
555 555 typedef struct frentry {
556 556 ipfmutex_t fr_lock;
557 557 struct frentry *fr_next;
558 558 struct frentry **fr_grp;
559 559 struct ipscan *fr_isc;
560 560 void *fr_ifas[4];
561 561 void *fr_ptr; /* for use with fr_arg */
562 562 char *fr_comment; /* text comment for rule */
563 563 int fr_ref; /* reference count - for grouping */
564 564 int fr_statecnt; /* state count - for limit rules */
565 565 /*
566 566 * These are only incremented when a packet matches this rule and
567 567 * it is the last match
568 568 */
569 569 U_QUAD_T fr_hits;
570 570 U_QUAD_T fr_bytes;
571 571
572 572 /*
573 573 * For PPS rate limiting
574 574 */
575 575 struct timeval fr_lastpkt;
576 576 int fr_curpps;
577 577
578 578 union {
579 579 void *fru_data;
580 580 caddr_t fru_caddr;
581 581 fripf_t *fru_ipf;
582 582 frentfunc_t fru_func;
583 583 } fr_dun;
584 584
585 585 /*
586 586 * Fields after this may not change whilst in the kernel.
587 587 */
588 588 ipfunc_t fr_func; /* call this function */
589 589 int fr_dsize;
590 590 int fr_pps;
591 591 int fr_statemax; /* max reference count */
592 592 int fr_flineno; /* line number from conf file */
593 593 u_32_t fr_type;
594 594 u_32_t fr_flags; /* per-rule flags && options (see below) */
595 595 u_32_t fr_logtag; /* user defined log tag # */
596 596 u_32_t fr_collect; /* collection number */
597 597 u_int fr_arg; /* misc. numeric arg for rule */
598 598 u_int fr_loglevel; /* syslog log facility + priority */
599 599 u_int fr_age[2]; /* non-TCP timeouts */
600 600 u_char fr_v;
601 601 u_char fr_icode; /* return ICMP code */
602 602 char fr_group[FR_GROUPLEN]; /* group to which this rule belongs */
603 603 char fr_grhead[FR_GROUPLEN]; /* group # which this rule starts */
604 604 ipftag_t fr_nattag;
605 605 char fr_ifnames[4][LIFNAMSIZ];
606 606 char fr_isctag[16];
607 607 frdest_t fr_tifs[2]; /* "to"/"reply-to" interface */
608 608 frdest_t fr_dif; /* duplicate packet interface */
609 609 /*
610 610 * This must be last and will change after loaded into the kernel.
611 611 */
612 612 u_int fr_cksum; /* checksum on filter rules for performance */
613 613 } frentry_t;
614 614
615 615 #define fr_caddr fr_dun.fru_caddr
616 616 #define fr_data fr_dun.fru_data
617 617 #define fr_dfunc fr_dun.fru_func
618 618 #define fr_ipf fr_dun.fru_ipf
619 619 #define fr_ip fr_ipf->fri_ip
620 620 #define fr_mip fr_ipf->fri_mip
621 621 #define fr_icmpm fr_ipf->fri_icmpm
622 622 #define fr_icmp fr_ipf->fri_icmp
623 623 #define fr_tuc fr_ipf->fri_tuc
624 624 #define fr_satype fr_ipf->fri_satype
625 625 #define fr_datype fr_ipf->fri_datype
626 626 #define fr_sifpidx fr_ipf->fri_sifpidx
627 627 #define fr_difpidx fr_ipf->fri_difpidx
628 628 #define fr_proto fr_ip.fi_p
629 629 #define fr_mproto fr_mip.fi_p
630 630 #define fr_ttl fr_ip.fi_ttl
631 631 #define fr_mttl fr_mip.fi_ttl
632 632 #define fr_tos fr_ip.fi_tos
633 633 #define fr_mtos fr_mip.fi_tos
634 634 #define fr_tcpfm fr_tuc.ftu_tcpfm
635 635 #define fr_tcpf fr_tuc.ftu_tcpf
636 636 #define fr_scmp fr_tuc.ftu_scmp
637 637 #define fr_dcmp fr_tuc.ftu_dcmp
638 638 #define fr_dport fr_tuc.ftu_dport
639 639 #define fr_sport fr_tuc.ftu_sport
640 640 #define fr_stop fr_tuc.ftu_stop
641 641 #define fr_dtop fr_tuc.ftu_dtop
642 642 #define fr_dst fr_ip.fi_dst.in4
643 643 #define fr_daddr fr_ip.fi_dst.in4.s_addr
644 644 #define fr_src fr_ip.fi_src.in4
645 645 #define fr_saddr fr_ip.fi_src.in4.s_addr
646 646 #define fr_dmsk fr_mip.fi_dst.in4
647 647 #define fr_dmask fr_mip.fi_dst.in4.s_addr
648 648 #define fr_smsk fr_mip.fi_src.in4
649 649 #define fr_smask fr_mip.fi_src.in4.s_addr
650 650 #define fr_dstnum fr_ip.fi_dstnum
651 651 #define fr_srcnum fr_ip.fi_srcnum
652 652 #define fr_dsttype fr_ip.fi_dsttype
653 653 #define fr_srctype fr_ip.fi_srctype
654 654 #define fr_dstptr fr_mip.fi_dstptr
655 655 #define fr_srcptr fr_mip.fi_srcptr
656 656 #define fr_dstfunc fr_mip.fi_dstfunc
657 657 #define fr_srcfunc fr_mip.fi_srcfunc
658 658 #define fr_optbits fr_ip.fi_optmsk
659 659 #define fr_optmask fr_mip.fi_optmsk
660 660 #define fr_secbits fr_ip.fi_secmsk
661 661 #define fr_secmask fr_mip.fi_secmsk
662 662 #define fr_authbits fr_ip.fi_auth
663 663 #define fr_authmask fr_mip.fi_auth
664 664 #define fr_flx fr_ip.fi_flx
↓ open down ↓ |
664 lines elided |
↑ open up ↑ |
665 665 #define fr_mflx fr_mip.fi_flx
666 666 #define fr_ifname fr_ifnames[0]
667 667 #define fr_oifname fr_ifnames[2]
668 668 #define fr_ifa fr_ifas[0]
669 669 #define fr_oifa fr_ifas[2]
670 670 #define fr_tif fr_tifs[0]
671 671 #define fr_rif fr_tifs[1]
672 672
673 673 #define FR_NOLOGTAG 0
674 674
675 -#ifndef offsetof
676 -#define offsetof(t,m) (size_t)((&((t *)0)->m))
677 -#endif
678 675 #define FR_CMPSIZ (sizeof(struct frentry) - \
679 676 offsetof(struct frentry, fr_func))
680 677
681 678 /*
682 679 * fr_type
683 680 */
684 681 #define FR_T_NONE 0
685 682 #define FR_T_IPF 1 /* IPF structures */
686 683 #define FR_T_BPFOPC 2 /* BPF opcode */
687 684 #define FR_T_CALLFUNC 3 /* callout to function in fr_func only */
688 685 #define FR_T_COMPIPF 4 /* compiled C code */
689 686 #define FR_T_BUILTIN 0x80000000 /* rule is in kernel space */
690 687
691 688 /*
692 689 * fr_flags
693 690 */
694 691 #define FR_CALL 0x00000 /* call rule */
695 692 #define FR_BLOCK 0x00001 /* do not allow packet to pass */
696 693 #define FR_PASS 0x00002 /* allow packet to pass */
697 694 #define FR_AUTH 0x00003 /* use authentication */
698 695 #define FR_PREAUTH 0x00004 /* require preauthentication */
699 696 #define FR_ACCOUNT 0x00005 /* Accounting rule */
700 697 #define FR_SKIP 0x00006 /* skip rule */
701 698 #define FR_DIVERT 0x00007 /* divert rule */
702 699 #define FR_CMDMASK 0x0000f
703 700 #define FR_LOG 0x00010 /* Log */
704 701 #define FR_LOGB 0x00011 /* Log-fail */
705 702 #define FR_LOGP 0x00012 /* Log-pass */
706 703 #define FR_LOGMASK (FR_LOG|FR_CMDMASK)
707 704 #define FR_CALLNOW 0x00020 /* call another function (fr_func) if matches */
708 705 #define FR_NOTSRCIP 0x00040
709 706 #define FR_NOTDSTIP 0x00080
710 707 #define FR_QUICK 0x00100 /* match & stop processing list */
711 708 #define FR_KEEPFRAG 0x00200 /* keep fragment information */
712 709 #define FR_KEEPSTATE 0x00400 /* keep `connection' state information */
713 710 #define FR_FASTROUTE 0x00800 /* bypass normal routing */
714 711 #define FR_RETRST 0x01000 /* Return TCP RST packet - reset connection */
715 712 #define FR_RETICMP 0x02000 /* Return ICMP unreachable packet */
716 713 #define FR_FAKEICMP 0x03000 /* Return ICMP unreachable with fake source */
717 714 #define FR_OUTQUE 0x04000 /* outgoing packets */
718 715 #define FR_INQUE 0x08000 /* ingoing packets */
719 716 #define FR_LOGBODY 0x10000 /* Log the body */
720 717 #define FR_LOGFIRST 0x20000 /* Log the first byte if state held */
721 718 #define FR_LOGORBLOCK 0x40000 /* block the packet if it can't be logged */
722 719 #define FR_DUP 0x80000 /* duplicate packet */
723 720 #define FR_FRSTRICT 0x100000 /* strict frag. cache */
724 721 #define FR_STSTRICT 0x200000 /* strict keep state */
725 722 #define FR_NEWISN 0x400000 /* new ISN for outgoing TCP */
726 723 #define FR_NOICMPERR 0x800000 /* do not match ICMP errors in state */
727 724 #define FR_STATESYNC 0x1000000 /* synchronize state to slave */
728 725 #define FR_NOMATCH 0x8000000 /* no match occured */
729 726 /* 0x10000000 FF_LOGPASS */
730 727 /* 0x20000000 FF_LOGBLOCK */
731 728 /* 0x40000000 FF_LOGNOMATCH */
732 729 /* 0x80000000 FF_BLOCKNONIP */
733 730 #define FR_COPIED 0x40000000 /* copied from user space */
734 731 #define FR_INACTIVE 0x80000000 /* only used when flush'ing rules */
735 732
736 733 #define FR_RETMASK (FR_RETICMP|FR_RETRST|FR_FAKEICMP)
737 734 #define FR_ISBLOCK(x) (((x) & FR_CMDMASK) == FR_BLOCK)
738 735 #define FR_ISPASS(x) (((x) & FR_CMDMASK) == FR_PASS)
739 736 #define FR_ISAUTH(x) (((x) & FR_CMDMASK) == FR_AUTH)
740 737 #define FR_ISPREAUTH(x) (((x) & FR_CMDMASK) == FR_PREAUTH)
741 738 #define FR_ISACCOUNT(x) (((x) & FR_CMDMASK) == FR_ACCOUNT)
742 739 #define FR_ISSKIP(x) (((x) & FR_CMDMASK) == FR_SKIP)
743 740 #define FR_ISNOMATCH(x) ((x) & FR_NOMATCH)
744 741 #define FR_INOUT (FR_INQUE|FR_OUTQUE)
745 742
746 743 /*
747 744 * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags
748 745 */
749 746 #define FF_LOGPASS 0x10000000
750 747 #define FF_LOGBLOCK 0x20000000
751 748 #define FF_LOGNOMATCH 0x40000000
752 749 #define FF_LOGGING (FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH)
753 750 #define FF_BLOCKNONIP 0x80000000 /* Solaris2 Only */
754 751
755 752
756 753 /*
757 754 * Structure that passes information on what/how to flush to the kernel.
758 755 */
759 756 typedef struct ipfflush {
760 757 int ipflu_how;
761 758 int ipflu_arg;
762 759 } ipfflush_t;
763 760
764 761
765 762 /*
766 763 *
767 764 */
768 765 typedef struct ipfgetctl {
769 766 u_int ipfg_min; /* min value */
770 767 u_int ipfg_current; /* current value */
771 768 u_int ipfg_max; /* max value */
772 769 u_int ipfg_default; /* default value */
773 770 u_int ipfg_steps; /* value increments */
774 771 char ipfg_name[40]; /* tag name for this control */
775 772 } ipfgetctl_t;
776 773
777 774 typedef struct ipfsetctl {
778 775 int ipfs_which; /* 0 = min 1 = current 2 = max 3 = default */
779 776 u_int ipfs_value; /* min value */
780 777 char ipfs_name[40]; /* tag name for this control */
781 778 } ipfsetctl_t;
782 779
783 780
784 781 /*
785 782 * Some of the statistics below are in their own counters, but most are kept
786 783 * in this single structure so that they can all easily be collected and
787 784 * copied back as required.
788 785 *
789 786 * NOTE: when changing, keep in sync with kstats (below).
790 787 */
791 788 typedef struct filterstats {
792 789 u_long fr_pass; /* packets allowed */
793 790 u_long fr_block; /* packets denied */
794 791 u_long fr_nom; /* packets which don't match any rule */
795 792 u_long fr_short; /* packets which are short */
796 793 u_long fr_ppkl; /* packets allowed and logged */
797 794 u_long fr_bpkl; /* packets denied and logged */
798 795 u_long fr_npkl; /* packets unmatched and logged */
799 796 u_long fr_pkl; /* packets logged */
800 797 u_long fr_skip; /* packets to be logged but buffer full */
801 798 u_long fr_ret; /* packets for which a return is sent */
802 799 u_long fr_acct; /* packets for which counting was performed */
803 800 u_long fr_bnfr; /* bad attempts to allocate fragment state */
804 801 u_long fr_nfr; /* new fragment state kept */
805 802 u_long fr_cfr; /* add new fragment state but complete pkt */
806 803 u_long fr_bads; /* bad attempts to allocate packet state */
807 804 u_long fr_ads; /* new packet state kept */
808 805 u_long fr_chit; /* cached hit */
809 806 u_long fr_tcpbad; /* TCP checksum check failures */
810 807 u_long fr_pull[2]; /* good and bad pullup attempts */
811 808 u_long fr_badsrc; /* source received doesn't match route */
812 809 u_long fr_badttl; /* TTL in packet doesn't reach minimum */
813 810 u_long fr_bad; /* bad IP packets to the filter */
814 811 u_long fr_ipv6; /* IPv6 packets in/out */
815 812 u_long fr_ppshit; /* dropped because of pps ceiling */
816 813 u_long fr_ipud; /* IP id update failures */
817 814 } filterstats_t;
818 815
819 816 /*
820 817 * kstat "copy" of the above - keep in sync!
821 818 * also keep in sync with initialisation code in solaris.c, ipf_kstat_init().
822 819 */
823 820 typedef struct filter_kstats {
824 821 kstat_named_t fks_pass; /* see above for comments */
825 822 kstat_named_t fks_block;
826 823 kstat_named_t fks_nom;
827 824 kstat_named_t fks_short;
828 825 kstat_named_t fks_ppkl;
829 826 kstat_named_t fks_bpkl;
830 827 kstat_named_t fks_npkl;
831 828 kstat_named_t fks_pkl;
832 829 kstat_named_t fks_skip;
833 830 kstat_named_t fks_ret;
834 831 kstat_named_t fks_acct;
835 832 kstat_named_t fks_bnfr;
836 833 kstat_named_t fks_nfr;
837 834 kstat_named_t fks_cfr;
838 835 kstat_named_t fks_bads;
839 836 kstat_named_t fks_ads;
840 837 kstat_named_t fks_chit;
841 838 kstat_named_t fks_tcpbad;
842 839 kstat_named_t fks_pull[2];
843 840 kstat_named_t fks_badsrc;
844 841 kstat_named_t fks_badttl;
845 842 kstat_named_t fks_bad;
846 843 kstat_named_t fks_ipv6;
847 844 kstat_named_t fks_ppshit;
848 845 kstat_named_t fks_ipud;
849 846 } filter_kstats_t;
850 847
851 848 /*
852 849 * Log structure. Each packet header logged is prepended by one of these.
853 850 * Following this in the log records read from the device will be an ipflog
854 851 * structure which is then followed by any packet data.
855 852 */
856 853 typedef struct iplog {
857 854 u_32_t ipl_magic;
858 855 u_int ipl_count;
859 856 struct timeval ipl_time;
860 857 size_t ipl_dsize;
861 858 struct iplog *ipl_next;
862 859 } iplog_t;
863 860
864 861 #define ipl_sec ipl_time.tv_sec
865 862 #define ipl_usec ipl_time.tv_usec
866 863
867 864 #define IPL_MAGIC 0x49504c4d /* 'IPLM' */
868 865 #define IPL_MAGIC_NAT 0x49504c4e /* 'IPLN' */
869 866 #define IPL_MAGIC_STATE 0x49504c53 /* 'IPLS' */
870 867 #define IPLOG_SIZE sizeof(iplog_t)
871 868
872 869 typedef struct ipflog {
873 870 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
874 871 (defined(OpenBSD) && (OpenBSD >= 199603))
875 872 #else
876 873 u_int fl_unit;
877 874 #endif
878 875 u_32_t fl_rule;
879 876 u_32_t fl_flags;
880 877 u_32_t fl_lflags;
881 878 u_32_t fl_logtag;
882 879 ipftag_t fl_nattag;
883 880 u_short fl_plen; /* extra data after hlen */
884 881 u_short fl_loglevel; /* syslog log level */
885 882 char fl_group[FR_GROUPLEN];
886 883 u_char fl_hlen; /* length of IP headers saved */
887 884 u_char fl_dir;
888 885 u_char fl_xxx[2]; /* pad */
889 886 char fl_ifname[LIFNAMSIZ];
890 887 } ipflog_t;
891 888
892 889 #ifndef IPF_LOGGING
893 890 # define IPF_LOGGING 0
894 891 #endif
895 892 #ifndef IPF_DEFAULT_PASS
896 893 # define IPF_DEFAULT_PASS FR_PASS
897 894 #endif
898 895
899 896 #define DEFAULT_IPFLOGSIZE 8192
900 897 #ifndef IPFILTER_LOGSIZE
901 898 # define IPFILTER_LOGSIZE DEFAULT_IPFLOGSIZE
902 899 #else
903 900 # if IPFILTER_LOGSIZE < DEFAULT_IPFLOGSIZE
904 901 # error IPFILTER_LOGSIZE too small. Must be >= DEFAULT_IPFLOGSIZE
905 902 # endif
906 903 #endif
907 904
908 905 #define IPF_OPTCOPY 0x07ff00 /* bit mask of copied options */
909 906
910 907 /*
911 908 * Device filenames for reading log information. Use ipf on Solaris2 because
912 909 * ipl is already a name used by something else.
913 910 */
914 911 #ifndef IPL_NAME
915 912 # if SOLARIS
916 913 # define IPL_NAME "/dev/ipf"
917 914 # else
918 915 # define IPL_NAME "/dev/ipl"
919 916 # endif
920 917 #endif
921 918 /*
922 919 * Pathnames for various IP Filter control devices. Used by LKM
923 920 * and userland, so defined here.
924 921 */
925 922 #define IPNAT_NAME "/dev/ipnat"
926 923 #define IPSTATE_NAME "/dev/ipstate"
927 924 #define IPAUTH_NAME "/dev/ipauth"
928 925 #define IPSYNC_NAME "/dev/ipsync"
929 926 #define IPSCAN_NAME "/dev/ipscan"
930 927 #define IPLOOKUP_NAME "/dev/iplookup"
931 928
932 929 #define IPL_LOGIPF 0 /* Minor device #'s for accessing logs */
933 930 #define IPL_LOGNAT 1
934 931 #define IPL_LOGSTATE 2
935 932 #define IPL_LOGAUTH 3
936 933 #define IPL_LOGSYNC 4
937 934 #define IPL_LOGSCAN 5
938 935 #define IPL_LOGLOOKUP 6
939 936 #define IPL_LOGCOUNT 7
940 937 #define IPL_LOGMAX 7
941 938 #define IPL_LOGSIZE (IPL_LOGMAX + 1)
942 939 #define IPL_LOGALL -1
943 940 #define IPL_LOGNONE -2
944 941
945 942 /*
946 943 * For SIOCGETFS
947 944 */
948 945 typedef struct friostat {
949 946 struct filterstats f_st[2];
950 947 struct frentry *f_ipf[2][2];
951 948 struct frentry *f_acct[2][2];
952 949 struct frentry *f_ipf6[2][2];
953 950 struct frentry *f_acct6[2][2];
954 951 struct frentry *f_auth;
955 952 struct frgroup *f_groups[IPL_LOGSIZE][2];
956 953 u_long f_froute[2];
957 954 u_long f_ticks;
958 955 int f_locks[IPL_LOGMAX];
959 956 size_t f_kmutex_sz;
960 957 size_t f_krwlock_sz;
961 958 int f_defpass; /* default pass - from fr_pass */
962 959 int f_active; /* 1 or 0 - active rule set */
963 960 int f_running; /* 1 if running, else 0 */
964 961 int f_logging; /* 1 if enabled, else 0 */
965 962 int f_features;
966 963 char f_version[32]; /* version string */
967 964 } friostat_t;
968 965
969 966 #define f_fin f_ipf[0]
970 967 #define f_fin6 f_ipf6[0]
971 968 #define f_fout f_ipf[1]
972 969 #define f_fout6 f_ipf6[1]
973 970 #define f_acctin f_acct[0]
974 971 #define f_acctin6 f_acct6[0]
975 972 #define f_acctout f_acct[1]
976 973 #define f_acctout6 f_acct6[1]
977 974
978 975 #define IPF_FEAT_LKM 0x001
979 976 #define IPF_FEAT_LOG 0x002
980 977 #define IPF_FEAT_LOOKUP 0x004
981 978 #define IPF_FEAT_BPF 0x008
982 979 #define IPF_FEAT_COMPILED 0x010
983 980 #define IPF_FEAT_CKSUM 0x020
984 981 #define IPF_FEAT_SYNC 0x040
985 982 #define IPF_FEAT_SCAN 0x080
986 983 #define IPF_FEAT_IPV6 0x100
987 984
988 985 typedef struct optlist {
989 986 u_short ol_val;
990 987 int ol_bit;
991 988 } optlist_t;
992 989
993 990
994 991 /*
995 992 * Group list structure.
996 993 */
997 994 typedef struct frgroup {
998 995 struct frgroup *fg_next;
999 996 struct frentry *fg_head;
1000 997 struct frentry *fg_start;
1001 998 u_32_t fg_flags;
1002 999 int fg_ref;
1003 1000 char fg_name[FR_GROUPLEN];
1004 1001 } frgroup_t;
1005 1002
1006 1003 #define FG_NAME(g) (*(g)->fg_name == '\0' ? "" : (g)->fg_name)
1007 1004
1008 1005
1009 1006 /*
1010 1007 * Used by state and NAT tables
1011 1008 */
1012 1009 typedef struct icmpinfo {
1013 1010 u_short ici_id;
1014 1011 u_short ici_seq;
1015 1012 u_char ici_type;
1016 1013 } icmpinfo_t;
1017 1014
1018 1015 typedef struct udpinfo {
1019 1016 u_short us_sport;
1020 1017 u_short us_dport;
1021 1018 } udpinfo_t;
1022 1019
1023 1020
1024 1021 typedef struct tcpdata {
1025 1022 u_32_t td_end;
1026 1023 u_32_t td_maxend;
1027 1024 u_32_t td_maxwin;
1028 1025 u_32_t td_winscale;
1029 1026 u_32_t td_maxseg;
1030 1027 int td_winflags;
1031 1028 } tcpdata_t;
1032 1029
1033 1030 #define TCP_WSCALE_MAX 14
1034 1031
1035 1032 #define TCP_WSCALE_SEEN 0x00000001
1036 1033 #define TCP_WSCALE_FIRST 0x00000002
1037 1034 #define TCP_SACK_PERMIT 0x00000004
1038 1035
1039 1036
1040 1037 typedef struct tcpinfo {
1041 1038 u_short ts_sport;
1042 1039 u_short ts_dport;
1043 1040 tcpdata_t ts_data[2];
1044 1041 } tcpinfo_t;
1045 1042
1046 1043
1047 1044 /*
1048 1045 * Structures to define a GRE header as seen in a packet.
1049 1046 */
1050 1047 struct grebits {
1051 1048 u_32_t grb_C:1;
1052 1049 u_32_t grb_R:1;
1053 1050 u_32_t grb_K:1;
1054 1051 u_32_t grb_S:1;
1055 1052 u_32_t grb_s:1;
1056 1053 u_32_t grb_recur:1;
1057 1054 u_32_t grb_A:1;
1058 1055 u_32_t grb_flags:3;
1059 1056 u_32_t grb_ver:3;
1060 1057 u_short grb_ptype;
1061 1058 };
1062 1059
1063 1060 typedef struct grehdr {
1064 1061 union {
1065 1062 struct grebits gru_bits;
1066 1063 u_short gru_flags;
1067 1064 } gr_un;
1068 1065 u_short gr_len;
1069 1066 u_short gr_call;
1070 1067 } grehdr_t;
1071 1068
1072 1069 #define gr_flags gr_un.gru_flags
1073 1070 #define gr_bits gr_un.gru_bits
1074 1071 #define gr_ptype gr_bits.grb_ptype
1075 1072 #define gr_C gr_bits.grb_C
1076 1073 #define gr_R gr_bits.grb_R
1077 1074 #define gr_K gr_bits.grb_K
1078 1075 #define gr_S gr_bits.grb_S
1079 1076 #define gr_s gr_bits.grb_s
1080 1077 #define gr_recur gr_bits.grb_recur
1081 1078 #define gr_A gr_bits.grb_A
1082 1079 #define gr_ver gr_bits.grb_ver
1083 1080
1084 1081 /*
1085 1082 * GRE information tracked by "keep state"
1086 1083 */
1087 1084 typedef struct greinfo {
1088 1085 u_short gs_call[2];
1089 1086 u_short gs_flags;
1090 1087 u_short gs_ptype;
1091 1088 } greinfo_t;
1092 1089
1093 1090 #define GRE_REV(x) ((ntohs(x) >> 13) & 7)
1094 1091
1095 1092
1096 1093 /*
1097 1094 * Format of an Authentication header
1098 1095 */
1099 1096 typedef struct authhdr {
1100 1097 u_char ah_next;
1101 1098 u_char ah_plen;
1102 1099 u_short ah_reserved;
1103 1100 u_32_t ah_spi;
1104 1101 u_32_t ah_seq;
1105 1102 /* Following the sequence number field is 0 or more bytes of */
1106 1103 /* authentication data, as specified by ah_plen - RFC 2402. */
1107 1104 } authhdr_t;
1108 1105
1109 1106
1110 1107 /*
1111 1108 * Timeout tail queue list member
1112 1109 */
1113 1110 typedef struct ipftqent {
1114 1111 struct ipftqent **tqe_pnext;
1115 1112 struct ipftqent *tqe_next;
1116 1113 struct ipftq *tqe_ifq;
1117 1114 void *tqe_parent; /* pointer back to NAT/state struct */
1118 1115 u_long tqe_die; /* when this entriy is to die */
1119 1116 u_long tqe_touched;
1120 1117 int tqe_flags;
1121 1118 int tqe_state[2]; /* current state of this entry */
1122 1119 } ipftqent_t;
1123 1120
1124 1121 #define TQE_RULEBASED 0x00000001
1125 1122
1126 1123
1127 1124 /*
1128 1125 * Timeout tail queue head for IPFilter
1129 1126 */
1130 1127 typedef struct ipftq {
1131 1128 ipfmutex_t ifq_lock;
1132 1129 u_int ifq_ttl;
1133 1130 ipftqent_t *ifq_head;
1134 1131 ipftqent_t **ifq_tail;
1135 1132 struct ipftq *ifq_next;
1136 1133 struct ipftq **ifq_pnext;
1137 1134 int ifq_ref;
1138 1135 u_int ifq_flags;
1139 1136 } ipftq_t;
1140 1137
1141 1138 #define IFQF_USER 0x01 /* User defined aging */
1142 1139 #define IFQF_DELETE 0x02 /* Marked for deletion */
1143 1140 #define IFQF_PROXY 0x04 /* Timeout queue in use by a proxy */
1144 1141
1145 1142 #define IPF_HZ_MULT 1
1146 1143 #define IPF_HZ_DIVIDE 2 /* How many times a second ipfilter */
1147 1144 /* checks its timeout queues. */
1148 1145 #define IPF_TTLVAL(x) (((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE)
1149 1146
1150 1147 /*
1151 1148 * Structure to define address for pool lookups.
1152 1149 */
1153 1150 typedef struct {
1154 1151 u_char adf_len;
1155 1152 sa_family_t adf_family;
1156 1153 i6addr_t adf_addr;
1157 1154 } addrfamily_t;
1158 1155
1159 1156
1160 1157 /*
1161 1158 * Object structure description. For passing through in ioctls.
1162 1159 */
1163 1160 typedef struct ipfobj {
1164 1161 u_32_t ipfo_rev; /* IPFilter version number */
1165 1162 u_32_t ipfo_size; /* size of object at ipfo_ptr */
1166 1163 void *ipfo_ptr; /* pointer to object */
1167 1164 int ipfo_type; /* type of object being pointed to */
1168 1165 int ipfo_offset; /* bytes from ipfo_ptr where to start */
1169 1166 u_char ipfo_xxxpad[32]; /* reserved for future use */
1170 1167 } ipfobj_t;
1171 1168
1172 1169 /*
1173 1170 * ioctl struct for setting what zone further ioctls will act on. ipfz_gz is a
1174 1171 * boolean: set it to 1 to operate on the GZ-controlled stack.
1175 1172 */
1176 1173 typedef struct ipfzoneobj {
1177 1174 u_32_t ipfz_gz; /* GZ stack boolean */
1178 1175 char ipfz_zonename[ZONENAME_MAX]; /* zone to act on */
1179 1176 } ipfzoneobj_t;
1180 1177
1181 1178 #if defined(_KERNEL)
1182 1179 /* Set ipfs_zoneid to this if no zone has been set: */
1183 1180 #define IPFS_ZONE_UNSET -2
1184 1181
1185 1182 typedef struct ipf_devstate {
1186 1183 zoneid_t ipfs_zoneid;
1187 1184 minor_t ipfs_minor;
1188 1185 boolean_t ipfs_gz;
1189 1186 } ipf_devstate_t;
1190 1187 #endif
1191 1188
1192 1189 #define IPFOBJ_FRENTRY 0 /* struct frentry */
1193 1190 #define IPFOBJ_IPFSTAT 1 /* struct friostat */
1194 1191 #define IPFOBJ_IPFINFO 2 /* struct fr_info */
1195 1192 #define IPFOBJ_AUTHSTAT 3 /* struct fr_authstat */
1196 1193 #define IPFOBJ_FRAGSTAT 4 /* struct ipfrstat */
1197 1194 #define IPFOBJ_IPNAT 5 /* struct ipnat */
1198 1195 #define IPFOBJ_NATSTAT 6 /* struct natstat */
1199 1196 #define IPFOBJ_STATESAVE 7 /* struct ipstate_save */
1200 1197 #define IPFOBJ_NATSAVE 8 /* struct nat_save */
1201 1198 #define IPFOBJ_NATLOOKUP 9 /* struct natlookup */
1202 1199 #define IPFOBJ_IPSTATE 10 /* struct ipstate */
1203 1200 #define IPFOBJ_STATESTAT 11 /* struct ips_stat */
1204 1201 #define IPFOBJ_FRAUTH 12 /* struct frauth */
1205 1202 #define IPFOBJ_TUNEABLE 13 /* struct ipftune */
1206 1203 #define IPFOBJ_NAT 14 /* struct nat */
1207 1204 #define IPFOBJ_IPFITER 15 /* struct ipfruleiter */
1208 1205 #define IPFOBJ_GENITER 16 /* struct ipfgeniter */
1209 1206 #define IPFOBJ_GTABLE 17 /* struct ipftable */
1210 1207 #define IPFOBJ_LOOKUPITER 18 /* struct ipflookupiter */
1211 1208 #define IPFOBJ_COUNT 19 /* How many #defines are above this? */
1212 1209
1213 1210
1214 1211 typedef union ipftunevalptr {
1215 1212 void *ipftp_void;
1216 1213 u_long *ipftp_long;
1217 1214 u_int *ipftp_int;
1218 1215 u_short *ipftp_short;
1219 1216 u_char *ipftp_char;
1220 1217 } ipftunevalptr_t;
1221 1218
1222 1219 typedef struct ipftuneable {
1223 1220 ipftunevalptr_t ipft_una;
1224 1221 char *ipft_name;
1225 1222 u_long ipft_min;
1226 1223 u_long ipft_max;
1227 1224 int ipft_sz;
1228 1225 int ipft_flags;
1229 1226 struct ipftuneable *ipft_next;
1230 1227 } ipftuneable_t;
1231 1228
1232 1229 #define ipft_addr ipft_una.ipftp_void
1233 1230 #define ipft_plong ipft_una.ipftp_long
1234 1231 #define ipft_pint ipft_una.ipftp_int
1235 1232 #define ipft_pshort ipft_una.ipftp_short
1236 1233 #define ipft_pchar ipft_una.ipftp_char
1237 1234
1238 1235 #define IPFT_RDONLY 1 /* read-only */
1239 1236 #define IPFT_WRDISABLED 2 /* write when disabled only */
1240 1237
1241 1238 typedef union ipftuneval {
1242 1239 u_long ipftu_long;
1243 1240 u_int ipftu_int;
1244 1241 u_short ipftu_short;
1245 1242 u_char ipftu_char;
1246 1243 } ipftuneval_t;
1247 1244
1248 1245 typedef struct ipftune {
1249 1246 void *ipft_cookie;
1250 1247 ipftuneval_t ipft_un;
1251 1248 u_long ipft_min;
1252 1249 u_long ipft_max;
1253 1250 int ipft_sz;
1254 1251 int ipft_flags;
1255 1252 char ipft_name[80];
1256 1253 } ipftune_t;
1257 1254
1258 1255 #define ipft_vlong ipft_un.ipftu_long
1259 1256 #define ipft_vint ipft_un.ipftu_int
1260 1257 #define ipft_vshort ipft_un.ipftu_short
1261 1258 #define ipft_vchar ipft_un.ipftu_char
1262 1259
1263 1260 /*
1264 1261 * ipfruleiter is iterator structure used for filter rules.
1265 1262 */
1266 1263 typedef struct ipfruleiter {
1267 1264 int iri_ver;
1268 1265 int iri_inout;
1269 1266 char iri_group[FR_GROUPLEN];
1270 1267 int iri_active;
1271 1268 int iri_nrules;
1272 1269 frentry_t *iri_rule;
1273 1270 } ipfruleiter_t;
1274 1271
1275 1272 /* Values for iri_inout */
1276 1273 #define F_IN 0
1277 1274 #define F_OUT 1
1278 1275 #define F_ACIN 2
1279 1276 #define F_ACOUT 3
1280 1277
1281 1278 /*
1282 1279 * ipfgeniter is generic iterator structure used for nat rules,
1283 1280 * hostmap entries and nat table entries.
1284 1281 */
1285 1282 typedef struct ipfgeniter {
1286 1283 int igi_type; /* type of data we're looking at */
1287 1284 int igi_nitems;
1288 1285 void *igi_data;
1289 1286 } ipfgeniter_t;
1290 1287
1291 1288 #define IPFGENITER_IPF 0
1292 1289 #define IPFGENITER_NAT 1
1293 1290 #define IPFGENITER_IPNAT 2
1294 1291 #define IPFGENITER_FRAG 3
1295 1292 #define IPFGENITER_AUTH 4
1296 1293 #define IPFGENITER_STATE 5
1297 1294 #define IPFGENITER_NATFRAG 6
1298 1295 #define IPFGENITER_HOSTMAP 7
1299 1296 #define IPFGENITER_LOOKUP 8
1300 1297
1301 1298 typedef struct ipftable {
1302 1299 int ita_type;
1303 1300 void *ita_table;
1304 1301 } ipftable_t;
1305 1302
1306 1303 typedef struct ipftoken {
1307 1304 struct ipftoken *ipt_next;
1308 1305 struct ipftoken **ipt_pnext;
1309 1306 void *ipt_ctx;
1310 1307 void *ipt_data;
1311 1308 u_long ipt_die;
1312 1309 int ipt_type;
1313 1310 int ipt_uid;
1314 1311 int ipt_subtype;
1315 1312 int ipt_alive;
1316 1313 } ipftoken_t;
1317 1314
1318 1315
1319 1316 /*
1320 1317 * sync commands
1321 1318 */
1322 1319 #define IPFSYNC_RESYNC 0
1323 1320 #define IPFSYNC_NEWIFP 1
1324 1321 #define IPFSYNC_OLDIFP 2
1325 1322
1326 1323
1327 1324 /*
1328 1325 ** HPUX Port
1329 1326 */
1330 1327 #ifdef __hpux
1331 1328 /* HP-UX locking sequence deadlock detection module lock MAJOR ID */
1332 1329 # define IPF_SMAJ 0 /* temp assignment XXX, not critical */
1333 1330 #endif
1334 1331
1335 1332 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \
1336 1333 (__FreeBSD_version >= 220000)
1337 1334 # define CDEV_MAJOR 79
1338 1335 #endif
1339 1336
1340 1337 /*
1341 1338 * Post NetBSD 1.2 has the PFIL interface for packet filters. This turns
1342 1339 * on those hooks. We don't need any special mods in non-IP Filter code
1343 1340 * with this!
1344 1341 */
1345 1342 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \
1346 1343 (defined(NetBSD1_2) && NetBSD1_2 > 1) || \
1347 1344 (defined(__FreeBSD__) && (__FreeBSD_version >= 500043))
1348 1345 # if (NetBSD >= 199905)
1349 1346 # define PFIL_HOOKS
1350 1347 # endif
1351 1348 # ifdef PFIL_HOOKS
1352 1349 # define NETBSD_PF
1353 1350 # endif
1354 1351 #endif
1355 1352
1356 1353 #ifndef _KERNEL
1357 1354 extern int fr_check __P((struct ip *, int, void *, int, mb_t **, ipf_stack_t *));
1358 1355 extern int (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **, ipf_stack_t *));
1359 1356 extern int ipf_log __P((void));
1360 1357 extern struct ifnet *get_unit __P((char *, int, ipf_stack_t *));
1361 1358 extern char *get_ifname __P((struct ifnet *));
1362 1359 # if defined(__NetBSD__) || defined(__OpenBSD__) || \
1363 1360 (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000)
1364 1361 extern int frrequest __P((int, u_long, caddr_t, int, int, ipf_stack_t *));
1365 1362 # else
1366 1363 extern int iplioctl __P((int, ioctlcmd_t, caddr_t, int));
1367 1364 # endif
1368 1365 extern int iplopen __P((dev_t, int));
1369 1366 extern int iplclose __P((dev_t, int));
1370 1367 extern void m_freem __P((mb_t *));
1371 1368 #else /* #ifndef _KERNEL */
1372 1369 extern phy_if_t get_unit __P((char *, int, ipf_stack_t *));
1373 1370 # if defined(__NetBSD__) && defined(PFIL_HOOKS)
1374 1371 extern void ipfilterattach __P((int));
1375 1372 # endif
1376 1373 extern int ipl_enable __P((void));
1377 1374 extern int ipl_disable __P((void));
1378 1375 # ifdef MENTAT
1379 1376 extern int fr_check __P((struct ip *, int, void *, int, void *,
1380 1377 mblk_t **, ipf_stack_t *));
1381 1378 # if SOLARIS
1382 1379 # if SOLARIS2 >= 7
1383 1380 extern int iplioctl __P((dev_t, int, intptr_t, int, cred_t *, int *));
1384 1381 # else
1385 1382 extern int iplioctl __P((dev_t, int, int *, int, cred_t *, int *));
1386 1383 # endif
1387 1384 # if SOLARIS2 >= 10 && defined(_KERNEL)
1388 1385 extern int fr_make_rst __P((fr_info_t *));
1389 1386 extern int fr_make_icmp __P((fr_info_t *));
1390 1387 extern void fr_calc_chksum __P((fr_info_t *, mb_t *));
1391 1388 extern ipf_stack_t *ipf_find_stack(const zoneid_t, ipf_devstate_t *);
1392 1389 # endif
1393 1390 extern int iplopen __P((dev_t *, int, int, cred_t *));
1394 1391 extern int iplclose __P((dev_t, int, int, cred_t *));
1395 1392 extern int iplread __P((dev_t, uio_t *, cred_t *));
1396 1393 extern int iplwrite __P((dev_t, uio_t *, cred_t *));
1397 1394 # endif
1398 1395 # ifdef __hpux
1399 1396 extern int iplopen __P((dev_t, int, intptr_t, int));
1400 1397 extern int iplclose __P((dev_t, int, int));
1401 1398 extern int iplioctl __P((dev_t, int, caddr_t, int));
1402 1399 extern int iplread __P((dev_t, uio_t *));
1403 1400 extern int iplwrite __P((dev_t, uio_t *));
1404 1401 extern int iplselect __P((dev_t, int));
1405 1402 # endif
1406 1403 extern int ipfsync __P((ipf_stack_t *));
1407 1404 extern int fr_qout __P((queue_t *, mblk_t *));
1408 1405 # else /* MENTAT */
1409 1406 extern int fr_check __P((struct ip *, int, void *, int, mb_t **, ipf_stack_t *));
1410 1407 extern int (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **, ipf_stack_t *));
1411 1408 extern size_t mbufchainlen __P((mb_t *));
1412 1409 # ifdef __sgi
1413 1410 # include <sys/cred.h>
1414 1411 extern int iplioctl __P((dev_t, int, caddr_t, int, cred_t *, int *));
1415 1412 extern int iplopen __P((dev_t *, int, int, cred_t *));
1416 1413 extern int iplclose __P((dev_t, int, int, cred_t *));
1417 1414 extern int iplread __P((dev_t, uio_t *, cred_t *));
1418 1415 extern int iplwrite __P((dev_t, uio_t *, cred_t *));
1419 1416 extern int ipfsync __P((ipf_stack_t *));
1420 1417 extern int ipfilter_sgi_attach __P((void));
1421 1418 extern void ipfilter_sgi_detach __P((void));
1422 1419 extern void ipfilter_sgi_intfsync __P((void));
1423 1420 # else
1424 1421 # ifdef IPFILTER_LKM
1425 1422 extern int iplidentify __P((char *));
1426 1423 # endif
1427 1424 # if (_BSDI_VERSION >= 199510) || (__FreeBSD_version >= 220000) || \
1428 1425 (NetBSD >= 199511) || defined(__OpenBSD__)
1429 1426 # if defined(__NetBSD__) || (_BSDI_VERSION >= 199701) || \
1430 1427 defined(__OpenBSD__) || (__FreeBSD_version >= 300000)
1431 1428 # if (__FreeBSD_version >= 500024)
1432 1429 # if (__FreeBSD_version >= 502116)
1433 1430 extern int iplioctl __P((struct cdev*, u_long, caddr_t, int, struct thread *));
1434 1431 # else
1435 1432 extern int iplioctl __P((dev_t, u_long, caddr_t, int, struct thread *));
1436 1433 # endif /* __FreeBSD_version >= 502116 */
1437 1434 # else
1438 1435 extern int iplioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
1439 1436 # endif /* __FreeBSD_version >= 500024 */
1440 1437 # else
1441 1438 extern int iplioctl __P((dev_t, int, caddr_t, int, struct proc *));
1442 1439 # endif
1443 1440 # if (__FreeBSD_version >= 500024)
1444 1441 # if (__FreeBSD_version >= 502116)
1445 1442 extern int iplopen __P((struct cdev*, int, int, struct thread *));
1446 1443 extern int iplclose __P((struct cdev*, int, int, struct thread *));
1447 1444 # else
1448 1445 extern int iplopen __P((dev_t, int, int, struct thread *));
1449 1446 extern int iplclose __P((dev_t, int, int, struct thread *));
1450 1447 # endif /* __FreeBSD_version >= 502116 */
1451 1448 # else
1452 1449 extern int iplopen __P((dev_t, int, int, struct proc *));
1453 1450 extern int iplclose __P((dev_t, int, int, struct proc *));
1454 1451 # endif /* __FreeBSD_version >= 500024 */
1455 1452 # else
1456 1453 # ifdef linux
1457 1454 extern int iplioctl __P((struct inode *, struct file *, u_int, u_long));
1458 1455 # else
1459 1456 extern int iplopen __P((dev_t, int));
1460 1457 extern int iplclose __P((dev_t, int));
1461 1458 extern int iplioctl __P((dev_t, int, caddr_t, int));
1462 1459 # endif
1463 1460 # endif /* (_BSDI_VERSION >= 199510) */
1464 1461 # if BSD >= 199306
1465 1462 # if (__FreeBSD_version >= 502116)
1466 1463 extern int iplread __P((struct cdev*, struct uio *, int));
1467 1464 extern int iplwrite __P((struct cdev*, struct uio *, int));
1468 1465 # else
1469 1466 extern int iplread __P((dev_t, struct uio *, int));
1470 1467 extern int iplwrite __P((dev_t, struct uio *, int));
1471 1468 # endif /* __FreeBSD_version >= 502116 */
1472 1469 # else
1473 1470 # ifndef linux
1474 1471 extern int iplread __P((dev_t, struct uio *));
1475 1472 extern int iplwrite __P((dev_t, struct uio *));
1476 1473 # endif
1477 1474 # endif /* BSD >= 199306 */
1478 1475 # endif /* __ sgi */
1479 1476 # endif /* MENTAT */
1480 1477
1481 1478 #endif /* #ifndef _KERNEL */
1482 1479
1483 1480 extern char *memstr __P((char *, char *, int, int));
1484 1481 extern int count4bits __P((u_32_t));
1485 1482 extern int count6bits __P((u_32_t *));
1486 1483 extern int frrequest __P((int, ioctlcmd_t, caddr_t, int, int, ipf_stack_t *));
1487 1484 extern char *getifname __P((struct ifnet *));
1488 1485 extern int iplattach __P((ipf_stack_t *));
1489 1486 extern int ipldetach __P((ipf_stack_t *));
1490 1487 extern u_short ipf_cksum __P((u_short *, int));
1491 1488 extern int copyinptr __P((void *, void *, size_t));
1492 1489 extern int copyoutptr __P((void *, void *, size_t));
1493 1490 extern int fr_fastroute __P((mb_t *, mb_t **, fr_info_t *, frdest_t *));
1494 1491 extern int fr_inobj __P((void *, void *, int));
1495 1492 extern int fr_inobjsz __P((void *, void *, int, int));
1496 1493 extern int fr_ioctlswitch __P((int, void *, ioctlcmd_t, int, int, void *,
1497 1494 ipf_stack_t *));
1498 1495 extern int fr_ipftune __P((ioctlcmd_t, void *, ipf_stack_t *));
1499 1496 extern int fr_outobj __P((void *, void *, int));
1500 1497 extern int fr_outobjsz __P((void *, void *, int, int));
1501 1498 extern void *fr_pullup __P((mb_t *, fr_info_t *, int));
1502 1499 extern void fr_resolvedest __P((struct frdest *, int, ipf_stack_t *));
1503 1500 extern int fr_resolvefunc __P((void *));
1504 1501 extern void *fr_resolvenic __P((char *, int, ipf_stack_t *));
1505 1502 extern int fr_send_icmp_err __P((int, fr_info_t *, int));
1506 1503 extern int fr_send_reset __P((fr_info_t *));
1507 1504 #if (__FreeBSD_version < 490000) || !defined(_KERNEL)
1508 1505 extern int ppsratecheck __P((struct timeval *, int *, int));
1509 1506 #endif
1510 1507 extern ipftq_t *fr_addtimeoutqueue __P((ipftq_t **, u_int, ipf_stack_t *));
1511 1508 extern void fr_deletequeueentry __P((ipftqent_t *));
1512 1509 extern int fr_deletetimeoutqueue __P((ipftq_t *));
1513 1510 extern void fr_freetimeoutqueue __P((ipftq_t *, ipf_stack_t *));
1514 1511 extern void fr_movequeue __P((ipftqent_t *, ipftq_t *, ipftq_t *,
1515 1512 ipf_stack_t *));
1516 1513 extern void fr_queueappend __P((ipftqent_t *, ipftq_t *, void *,
1517 1514 ipf_stack_t *));
1518 1515 extern void fr_queueback __P((ipftqent_t *, ipf_stack_t *));
1519 1516 extern void fr_queuefront __P((ipftqent_t *));
1520 1517 extern void fr_checkv4sum __P((fr_info_t *));
1521 1518 extern int fr_checkl4sum __P((fr_info_t *));
1522 1519 extern int fr_ifpfillv4addr __P((int, struct sockaddr_in *,
1523 1520 struct sockaddr_in *, struct in_addr *,
1524 1521 struct in_addr *));
1525 1522 extern int fr_coalesce __P((fr_info_t *));
1526 1523 #ifdef USE_INET6
1527 1524 extern void fr_checkv6sum __P((fr_info_t *));
1528 1525 extern int fr_ifpfillv6addr __P((int, struct sockaddr_in6 *,
1529 1526 struct sockaddr_in6 *, struct in_addr *,
1530 1527 struct in_addr *));
1531 1528 #endif
1532 1529
1533 1530 #define IPFILTER_COMPAT
1534 1531 extern int fr_incomptrans __P((ipfobj_t *, void *));
1535 1532 extern int fr_outcomptrans __P((ipfobj_t *, void *));
1536 1533
1537 1534 extern int fr_addipftune __P((ipftuneable_t *, ipf_stack_t *));
1538 1535 extern int fr_delipftune __P((ipftuneable_t *, ipf_stack_t *));
1539 1536
1540 1537 extern int frflush __P((minor_t, int, int, ipf_stack_t *));
1541 1538 extern void frsync __P((int, int, void *, char *, ipf_stack_t *));
1542 1539 #if SOLARIS2 >= 10
1543 1540 extern void fr_ifindexsync __P((void *, void *, ipf_stack_t *));
1544 1541 #endif
1545 1542 extern frgroup_t *fr_addgroup __P((char *, void *, u_32_t, minor_t, int,
1546 1543 ipf_stack_t *));
1547 1544 extern int fr_derefrule __P((frentry_t **, ipf_stack_t *));
1548 1545 extern void fr_delgroup __P((char *, minor_t, int, ipf_stack_t *));
1549 1546 extern frgroup_t *fr_findgroup __P((char *, minor_t, int, frgroup_t ***,
1550 1547 ipf_stack_t *));
1551 1548
1552 1549 extern int fr_loginit __P((ipf_stack_t *));
1553 1550 extern int ipflog_clear __P((minor_t, ipf_stack_t *));
1554 1551 extern int ipflog_read __P((minor_t, struct uio *, ipf_stack_t *));
1555 1552 extern int ipflog __P((fr_info_t *, u_int));
1556 1553 extern int ipllog __P((int, fr_info_t *, void **, size_t *, int *, int,
1557 1554 ipf_stack_t *));
1558 1555 extern void fr_logunload __P((ipf_stack_t *));
1559 1556
1560 1557 extern frentry_t *fr_acctpkt __P((fr_info_t *, u_32_t *));
1561 1558 extern int fr_copytolog __P((int, char *, int));
1562 1559 extern u_short fr_cksum __P((mb_t *, ip_t *, int, void *));
1563 1560 extern void fr_deinitialise __P((ipf_stack_t *));
1564 1561 extern frentry_t *fr_dolog __P((fr_info_t *, u_32_t *));
1565 1562 extern frentry_t *fr_dstgrpmap __P((fr_info_t *, u_32_t *));
1566 1563 extern void fr_fixskip __P((frentry_t **, frentry_t *, int));
1567 1564 extern void fr_forgetifp __P((void *, ipf_stack_t *));
1568 1565 extern frentry_t *fr_getrulen __P((int, char *, u_32_t,
1569 1566 ipf_stack_t *));
1570 1567 extern void fr_getstat __P((struct friostat *, ipf_stack_t *));
1571 1568 extern int fr_ifpaddr __P((int, int, void *,
1572 1569 struct in_addr *, struct in_addr *,
1573 1570 ipf_stack_t *));
1574 1571 extern int fr_initialise __P((ipf_stack_t *));
1575 1572 extern int fr_lock __P((caddr_t, int *));
1576 1573 extern int fr_makefrip __P((int, ip_t *, fr_info_t *));
1577 1574 extern int fr_matchtag __P((ipftag_t *, ipftag_t *));
1578 1575 extern int fr_matchicmpqueryreply __P((int, icmpinfo_t *,
1579 1576 struct icmp *, int));
1580 1577 extern u_32_t fr_newisn __P((fr_info_t *));
1581 1578 extern u_short fr_nextipid __P((fr_info_t *));
1582 1579 extern int fr_rulen __P((int, frentry_t *, ipf_stack_t *));
1583 1580 extern int fr_scanlist __P((fr_info_t *, u_32_t));
1584 1581 extern frentry_t *fr_srcgrpmap __P((fr_info_t *, u_32_t *));
1585 1582 extern int fr_tcpudpchk __P((fr_info_t *, frtuc_t *));
1586 1583 extern int fr_verifysrc __P((fr_info_t *fin));
1587 1584 extern int fr_zerostats __P((char *, ipf_stack_t *));
1588 1585 extern ipftoken_t *ipf_findtoken __P((int, int, void *, ipf_stack_t *));
1589 1586 extern int ipf_getnextrule __P((ipftoken_t *, void *,
1590 1587 ipf_stack_t *));
1591 1588 extern void ipf_expiretokens __P((ipf_stack_t *));
1592 1589 extern void ipf_freetoken __P((ipftoken_t *, ipf_stack_t *));
1593 1590 extern int ipf_deltoken __P((int, int, void *, ipf_stack_t *));
1594 1591 extern int ipf_genericiter __P((void *, int, void *, ipf_stack_t *));
1595 1592 extern int ipf_extraflush __P((int, ipftq_t *, ipftq_t *, ipf_stack_t *));
1596 1593 extern int ipf_flushclosing __P((int, int, ipftq_t *, ipftq_t *, ipf_stack_t *));
1597 1594 extern int ipf_earlydrop __P((int, ipftq_t *, int, ipf_stack_t *));
1598 1595
1599 1596 #ifndef ipf_random
1600 1597 extern u_32_t ipf_random __P((void));
1601 1598 #endif
1602 1599
1603 1600 #if defined(_KERNEL)
1604 1601 extern int fr_setzoneid __P((ipf_devstate_t *, void *));
1605 1602 #endif
1606 1603
1607 1604 extern char ipfilter_version[];
1608 1605 #ifdef USE_INET6
1609 1606 extern int icmptoicmp6types[ICMP_MAXTYPE+1];
1610 1607 extern int icmptoicmp6unreach[ICMP_MAX_UNREACH];
1611 1608 extern int icmpreplytype6[ICMP6_MAXTYPE + 1];
1612 1609 #endif
1613 1610 extern int icmpreplytype4[ICMP_MAXTYPE + 1];
1614 1611 extern frentry_t *ipfrule_match __P((fr_info_t *));
1615 1612
1616 1613 extern void ipftuneable_alloc(ipf_stack_t *);
1617 1614 extern void ipftuneable_free(ipf_stack_t *);
1618 1615
1619 1616 #endif /* __IP_FIL_H__ */
↓ open down ↓ |
932 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX