]>
Commit | Line | Data |
---|---|---|
b0d623f7 A |
1 | /* |
2 | * Copyright (c) 2008 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | /* $apfw: pfvar.h,v 1.12 2008/08/27 00:01:32 jhw Exp $ */ | |
30 | /* $OpenBSD: pfvar.h,v 1.259 2007/12/02 12:08:04 pascoe Exp $ */ | |
31 | ||
32 | /* | |
33 | * Copyright (c) 2001 Daniel Hartmeier | |
34 | * All rights reserved. | |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * | |
40 | * - Redistributions of source code must retain the above copyright | |
41 | * notice, this list of conditions and the following disclaimer. | |
42 | * - Redistributions in binary form must reproduce the above | |
43 | * copyright notice, this list of conditions and the following | |
44 | * disclaimer in the documentation and/or other materials provided | |
45 | * with the distribution. | |
46 | * | |
47 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
48 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
49 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
50 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
51 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
52 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
53 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
54 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
55 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
56 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
57 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
58 | * POSSIBILITY OF SUCH DAMAGE. | |
59 | * | |
60 | */ | |
61 | ||
62 | #ifndef _NET_PFVAR_H_ | |
63 | #define _NET_PFVAR_H_ | |
64 | ||
65 | #ifdef PRIVATE | |
66 | #if PF || !defined(KERNEL) | |
67 | ||
68 | #ifdef __cplusplus | |
69 | extern "C" { | |
70 | #endif | |
71 | ||
72 | #include <sys/param.h> | |
73 | #include <sys/types.h> | |
74 | #include <sys/queue.h> | |
75 | #include <sys/tree.h> | |
76 | ||
77 | #include <net/radix.h> | |
78 | #include <netinet/in.h> | |
79 | ||
80 | #ifdef KERNEL | |
81 | #include <kern/kern_types.h> | |
82 | #include <kern/zalloc.h> | |
83 | #include <kern/lock.h> | |
84 | ||
85 | #include <machine/endian.h> | |
86 | #include <sys/systm.h> | |
87 | #include <net/pf_mtag.h> | |
88 | ||
89 | #if BYTE_ORDER == BIG_ENDIAN | |
90 | #define htobe64(x) (x) | |
91 | #else /* LITTLE ENDIAN */ | |
92 | #define htobe64(x) __DARWIN_OSSwapInt64(x) | |
93 | #endif /* LITTLE_ENDIAN */ | |
94 | ||
95 | #define be64toh(x) htobe64(x) | |
96 | ||
97 | __private_extern__ lck_rw_t *pf_perim_lock; | |
98 | __private_extern__ lck_mtx_t *pf_lock; | |
99 | ||
100 | struct pool { | |
101 | struct zone *pool_zone; /* pointer to backend zone */ | |
102 | const char *pool_name; /* name of pool */ | |
103 | unsigned int pool_count; /* # of outstanding elements */ | |
104 | unsigned int pool_hiwat; /* high watermark */ | |
105 | unsigned int pool_limit; /* hard limit */ | |
106 | unsigned int pool_fails; /* # of failed allocs due to limit */ | |
107 | }; | |
108 | ||
109 | #define PR_NOWAIT FALSE | |
110 | #define PR_WAITOK TRUE | |
111 | ||
112 | __private_extern__ void pool_init(struct pool *, size_t, unsigned int, | |
113 | unsigned int, int, const char *, void *); | |
114 | __private_extern__ void pool_destroy(struct pool *); | |
115 | __private_extern__ void pool_sethiwat(struct pool *, int); | |
116 | __private_extern__ void pool_sethardlimit(struct pool *, int, | |
117 | const char *, int); | |
118 | __private_extern__ void *pool_get(struct pool *, int); | |
119 | __private_extern__ void pool_put(struct pool *, void *); | |
120 | __private_extern__ u_int64_t pf_time_second(void); | |
121 | #endif /* KERNEL */ | |
122 | ||
123 | union sockaddr_union { | |
124 | struct sockaddr sa; | |
125 | struct sockaddr_in sin; | |
126 | struct sockaddr_in6 sin6; | |
127 | }; | |
128 | ||
129 | struct ip; | |
130 | struct ip6_hdr; | |
131 | struct tcphdr; | |
132 | ||
133 | #define PF_TCPS_PROXY_SRC ((TCP_NSTATES)+0) | |
134 | #define PF_TCPS_PROXY_DST ((TCP_NSTATES)+1) | |
135 | ||
136 | #define PF_MD5_DIGEST_LENGTH 16 | |
137 | #ifdef MD5_DIGEST_LENGTH | |
138 | #if PF_MD5_DIGEST_LENGTH != MD5_DIGEST_LENGTH | |
139 | #error | |
140 | #endif | |
141 | #endif | |
142 | ||
143 | #ifndef NO_APPLE_EXTENSIONS | |
144 | struct pf_grev1_hdr; | |
145 | struct pf_esp_hdr; | |
146 | #endif | |
147 | ||
148 | enum { PF_INOUT, PF_IN, PF_OUT }; | |
149 | enum { PF_PASS, PF_DROP, PF_SCRUB, PF_NOSCRUB, PF_NAT, PF_NONAT, | |
150 | PF_BINAT, PF_NOBINAT, PF_RDR, PF_NORDR, PF_SYNPROXY_DROP }; | |
151 | enum { PF_RULESET_SCRUB, PF_RULESET_FILTER, PF_RULESET_NAT, | |
152 | PF_RULESET_BINAT, PF_RULESET_RDR, PF_RULESET_MAX }; | |
153 | enum { PF_OP_NONE, PF_OP_IRG, PF_OP_EQ, PF_OP_NE, PF_OP_LT, | |
154 | PF_OP_LE, PF_OP_GT, PF_OP_GE, PF_OP_XRG, PF_OP_RRG }; | |
155 | enum { PF_DEBUG_NONE, PF_DEBUG_URGENT, PF_DEBUG_MISC, PF_DEBUG_NOISY }; | |
156 | enum { PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL, | |
157 | PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER, | |
158 | PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET }; | |
159 | enum { PF_GET_NONE, PF_GET_CLR_CNTR }; | |
160 | ||
161 | /* | |
162 | * Note about PFTM_*: real indices into pf_rule.timeout[] come before | |
163 | * PFTM_MAX, special cases afterwards. See pf_state_expires(). | |
164 | */ | |
165 | enum { PFTM_TCP_FIRST_PACKET, PFTM_TCP_OPENING, PFTM_TCP_ESTABLISHED, | |
166 | PFTM_TCP_CLOSING, PFTM_TCP_FIN_WAIT, PFTM_TCP_CLOSED, | |
167 | PFTM_UDP_FIRST_PACKET, PFTM_UDP_SINGLE, PFTM_UDP_MULTIPLE, | |
168 | PFTM_ICMP_FIRST_PACKET, PFTM_ICMP_ERROR_REPLY, | |
169 | #ifndef NO_APPLE_EXTENSIONS | |
170 | PFTM_GREv1_FIRST_PACKET, PFTM_GREv1_INITIATING, PFTM_GREv1_ESTABLISHED, | |
171 | PFTM_ESP_FIRST_PACKET, PFTM_ESP_INITIATING, PFTM_ESP_ESTABLISHED, | |
172 | #endif | |
173 | PFTM_OTHER_FIRST_PACKET, PFTM_OTHER_SINGLE, | |
174 | PFTM_OTHER_MULTIPLE, PFTM_FRAG, PFTM_INTERVAL, | |
175 | PFTM_ADAPTIVE_START, PFTM_ADAPTIVE_END, PFTM_SRC_NODE, | |
176 | PFTM_TS_DIFF, PFTM_MAX, PFTM_PURGE, PFTM_UNLINKED, | |
177 | PFTM_UNTIL_PACKET }; | |
178 | ||
179 | /* PFTM default values */ | |
180 | #define PFTM_TCP_FIRST_PACKET_VAL 120 /* First TCP packet */ | |
181 | #define PFTM_TCP_OPENING_VAL 30 /* No response yet */ | |
182 | #define PFTM_TCP_ESTABLISHED_VAL (24 * 60 * 60) /* Established */ | |
183 | #define PFTM_TCP_CLOSING_VAL (15 * 60) /* Half closed */ | |
184 | #define PFTM_TCP_FIN_WAIT_VAL 45 /* Got both FINs */ | |
185 | #define PFTM_TCP_CLOSED_VAL 90 /* Got a RST */ | |
186 | #define PFTM_UDP_FIRST_PACKET_VAL 60 /* First UDP packet */ | |
187 | #define PFTM_UDP_SINGLE_VAL 30 /* Unidirectional */ | |
188 | #define PFTM_UDP_MULTIPLE_VAL 60 /* Bidirectional */ | |
189 | #define PFTM_ICMP_FIRST_PACKET_VAL 20 /* First ICMP packet */ | |
190 | #define PFTM_ICMP_ERROR_REPLY_VAL 10 /* Got error response */ | |
191 | #ifndef NO_APPLE_EXTENSIONS | |
192 | #define PFTM_GREv1_FIRST_PACKET_VAL 120 | |
193 | #define PFTM_GREv1_INITIATING_VAL 30 | |
194 | #define PFTM_GREv1_ESTABLISHED_VAL 1800 | |
195 | #define PFTM_ESP_FIRST_PACKET_VAL 120 | |
196 | #define PFTM_ESP_INITIATING_VAL 30 | |
197 | #define PFTM_ESP_ESTABLISHED_VAL 900 | |
198 | #endif | |
199 | #define PFTM_OTHER_FIRST_PACKET_VAL 60 /* First packet */ | |
200 | #define PFTM_OTHER_SINGLE_VAL 30 /* Unidirectional */ | |
201 | #define PFTM_OTHER_MULTIPLE_VAL 60 /* Bidirectional */ | |
202 | #define PFTM_FRAG_VAL 30 /* Fragment expire */ | |
203 | #define PFTM_INTERVAL_VAL 10 /* Expire interval */ | |
204 | #define PFTM_SRC_NODE_VAL 0 /* Source tracking */ | |
205 | #define PFTM_TS_DIFF_VAL 30 /* Allowed TS diff */ | |
206 | ||
207 | enum { PF_NOPFROUTE, PF_FASTROUTE, PF_ROUTETO, PF_DUPTO, PF_REPLYTO }; | |
208 | enum { PF_LIMIT_STATES, | |
209 | #ifndef NO_APPLE_EXTENSIONS | |
210 | PF_LIMIT_APP_STATES, | |
211 | #endif | |
212 | PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS, | |
213 | PF_LIMIT_TABLES, PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_MAX }; | |
214 | #define PF_POOL_IDMASK 0x0f | |
215 | enum { PF_POOL_NONE, PF_POOL_BITMASK, PF_POOL_RANDOM, | |
216 | PF_POOL_SRCHASH, PF_POOL_ROUNDROBIN }; | |
217 | enum { PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, PF_ADDR_DYNIFTL, | |
218 | PF_ADDR_TABLE, PF_ADDR_RTLABEL, PF_ADDR_URPFFAILED, | |
219 | PF_ADDR_RANGE }; | |
220 | #define PF_POOL_TYPEMASK 0x0f | |
221 | #define PF_POOL_STICKYADDR 0x20 | |
222 | #define PF_WSCALE_FLAG 0x80 | |
223 | #define PF_WSCALE_MASK 0x0f | |
224 | ||
225 | #define PF_LOG 0x01 | |
226 | #define PF_LOG_ALL 0x02 | |
227 | #define PF_LOG_SOCKET_LOOKUP 0x04 | |
228 | ||
229 | struct pf_addr { | |
230 | union { | |
231 | struct in_addr v4; | |
232 | struct in6_addr v6; | |
233 | u_int8_t addr8[16]; | |
234 | u_int16_t addr16[8]; | |
235 | u_int32_t addr32[4]; | |
236 | } pfa; /* 128-bit address */ | |
237 | #define v4 pfa.v4 | |
238 | #define v6 pfa.v6 | |
239 | #define addr8 pfa.addr8 | |
240 | #define addr16 pfa.addr16 | |
241 | #define addr32 pfa.addr32 | |
242 | }; | |
243 | ||
244 | #define PF_TABLE_NAME_SIZE 32 | |
245 | ||
246 | #define PFI_AFLAG_NETWORK 0x01 | |
247 | #define PFI_AFLAG_BROADCAST 0x02 | |
248 | #define PFI_AFLAG_PEER 0x04 | |
249 | #define PFI_AFLAG_MODEMASK 0x07 | |
250 | #define PFI_AFLAG_NOALIAS 0x08 | |
251 | ||
252 | #ifndef RTLABEL_LEN | |
253 | #define RTLABEL_LEN 32 | |
254 | #endif | |
255 | ||
256 | struct pf_addr_wrap { | |
257 | union { | |
258 | struct { | |
259 | struct pf_addr addr; | |
260 | struct pf_addr mask; | |
261 | } a; | |
262 | char ifname[IFNAMSIZ]; | |
263 | char tblname[PF_TABLE_NAME_SIZE]; | |
264 | char rtlabelname[RTLABEL_LEN]; | |
265 | u_int32_t rtlabel; | |
266 | } v; | |
267 | union { | |
268 | struct pfi_dynaddr *dyn __attribute__((aligned(8))); | |
269 | struct pfr_ktable *tbl __attribute__((aligned(8))); | |
270 | int dyncnt __attribute__((aligned(8))); | |
271 | int tblcnt __attribute__((aligned(8))); | |
272 | } p __attribute__((aligned(8))); | |
273 | u_int8_t type; /* PF_ADDR_* */ | |
274 | u_int8_t iflags; /* PFI_AFLAG_* */ | |
275 | }; | |
276 | ||
277 | #ifndef NO_APPLE_EXTENSIONS | |
278 | struct pf_port_range { | |
279 | u_int16_t port[2]; | |
280 | u_int8_t op; | |
281 | }; | |
282 | ||
283 | union pf_rule_xport { | |
284 | struct pf_port_range range; | |
285 | u_int16_t call_id; | |
286 | u_int32_t spi; | |
287 | }; | |
288 | #endif | |
289 | ||
290 | #ifdef KERNEL | |
291 | struct pfi_dynaddr { | |
292 | TAILQ_ENTRY(pfi_dynaddr) entry; | |
293 | struct pf_addr pfid_addr4; | |
294 | struct pf_addr pfid_mask4; | |
295 | struct pf_addr pfid_addr6; | |
296 | struct pf_addr pfid_mask6; | |
297 | struct pfr_ktable *pfid_kt; | |
298 | struct pfi_kif *pfid_kif; | |
299 | void *pfid_hook_cookie; | |
300 | int pfid_net; /* mask or 128 */ | |
301 | int pfid_acnt4; /* address count IPv4 */ | |
302 | int pfid_acnt6; /* address count IPv6 */ | |
303 | sa_family_t pfid_af; /* rule af */ | |
304 | u_int8_t pfid_iflags; /* PFI_AFLAG_* */ | |
305 | }; | |
306 | ||
307 | /* | |
308 | * Address manipulation macros | |
309 | */ | |
310 | ||
311 | #if INET | |
312 | #if !INET6 | |
313 | #define PF_INET_ONLY | |
314 | #endif /* ! INET6 */ | |
315 | #endif /* INET */ | |
316 | ||
317 | #if INET6 | |
318 | #if !INET | |
319 | #define PF_INET6_ONLY | |
320 | #endif /* ! INET */ | |
321 | #endif /* INET6 */ | |
322 | ||
323 | #if INET | |
324 | #if INET6 | |
325 | #define PF_INET_INET6 | |
326 | #endif /* INET6 */ | |
327 | #endif /* INET */ | |
328 | ||
329 | #else | |
330 | ||
331 | #define PF_INET_INET6 | |
332 | ||
333 | #endif /* KERNEL */ | |
334 | ||
335 | /* Both IPv4 and IPv6 */ | |
336 | #ifdef PF_INET_INET6 | |
337 | ||
338 | #define PF_AEQ(a, b, c) \ | |
339 | ((c == AF_INET && (a)->addr32[0] == (b)->addr32[0]) || \ | |
340 | ((a)->addr32[3] == (b)->addr32[3] && \ | |
341 | (a)->addr32[2] == (b)->addr32[2] && \ | |
342 | (a)->addr32[1] == (b)->addr32[1] && \ | |
343 | (a)->addr32[0] == (b)->addr32[0])) \ | |
344 | ||
345 | #define PF_ANEQ(a, b, c) \ | |
346 | ((c == AF_INET && (a)->addr32[0] != (b)->addr32[0]) || \ | |
347 | ((a)->addr32[3] != (b)->addr32[3] || \ | |
348 | (a)->addr32[2] != (b)->addr32[2] || \ | |
349 | (a)->addr32[1] != (b)->addr32[1] || \ | |
350 | (a)->addr32[0] != (b)->addr32[0])) \ | |
351 | ||
352 | #define PF_AZERO(a, c) \ | |
353 | ((c == AF_INET && !(a)->addr32[0]) || \ | |
354 | (!(a)->addr32[0] && !(a)->addr32[1] && \ | |
355 | !(a)->addr32[2] && !(a)->addr32[3])) \ | |
356 | ||
357 | #define PF_MATCHA(n, a, m, b, f) \ | |
358 | pf_match_addr(n, a, m, b, f) | |
359 | ||
360 | #define PF_ACPY(a, b, f) \ | |
361 | pf_addrcpy(a, b, f) | |
362 | ||
363 | #define PF_AINC(a, f) \ | |
364 | pf_addr_inc(a, f) | |
365 | ||
366 | #define PF_POOLMASK(a, b, c, d, f) \ | |
367 | pf_poolmask(a, b, c, d, f) | |
368 | ||
369 | #else | |
370 | ||
371 | /* Just IPv6 */ | |
372 | ||
373 | #ifdef PF_INET6_ONLY | |
374 | ||
375 | #define PF_AEQ(a, b, c) \ | |
376 | ((a)->addr32[3] == (b)->addr32[3] && \ | |
377 | (a)->addr32[2] == (b)->addr32[2] && \ | |
378 | (a)->addr32[1] == (b)->addr32[1] && \ | |
379 | (a)->addr32[0] == (b)->addr32[0]) \ | |
380 | ||
381 | #define PF_ANEQ(a, b, c) \ | |
382 | ((a)->addr32[3] != (b)->addr32[3] || \ | |
383 | (a)->addr32[2] != (b)->addr32[2] || \ | |
384 | (a)->addr32[1] != (b)->addr32[1] || \ | |
385 | (a)->addr32[0] != (b)->addr32[0]) \ | |
386 | ||
387 | #define PF_AZERO(a, c) \ | |
388 | (!(a)->addr32[0] && \ | |
389 | !(a)->addr32[1] && \ | |
390 | !(a)->addr32[2] && \ | |
391 | !(a)->addr32[3]) \ | |
392 | ||
393 | #define PF_MATCHA(n, a, m, b, f) \ | |
394 | pf_match_addr(n, a, m, b, f) | |
395 | ||
396 | #define PF_ACPY(a, b, f) \ | |
397 | pf_addrcpy(a, b, f) | |
398 | ||
399 | #define PF_AINC(a, f) \ | |
400 | pf_addr_inc(a, f) | |
401 | ||
402 | #define PF_POOLMASK(a, b, c, d, f) \ | |
403 | pf_poolmask(a, b, c, d, f) | |
404 | ||
405 | #else | |
406 | ||
407 | /* Just IPv4 */ | |
408 | #ifdef PF_INET_ONLY | |
409 | ||
410 | #define PF_AEQ(a, b, c) \ | |
411 | ((a)->addr32[0] == (b)->addr32[0]) | |
412 | ||
413 | #define PF_ANEQ(a, b, c) \ | |
414 | ((a)->addr32[0] != (b)->addr32[0]) | |
415 | ||
416 | #define PF_AZERO(a, c) \ | |
417 | (!(a)->addr32[0]) | |
418 | ||
419 | #define PF_MATCHA(n, a, m, b, f) \ | |
420 | pf_match_addr(n, a, m, b, f) | |
421 | ||
422 | #define PF_ACPY(a, b, f) \ | |
423 | (a)->v4.s_addr = (b)->v4.s_addr | |
424 | ||
425 | #define PF_AINC(a, f) \ | |
426 | do { \ | |
427 | (a)->addr32[0] = htonl(ntohl((a)->addr32[0]) + 1); \ | |
428 | } while (0) | |
429 | ||
430 | #define PF_POOLMASK(a, b, c, d, f) \ | |
431 | do { \ | |
432 | (a)->addr32[0] = ((b)->addr32[0] & (c)->addr32[0]) | \ | |
433 | (((c)->addr32[0] ^ 0xffffffff) & (d)->addr32[0]); \ | |
434 | } while (0) | |
435 | ||
436 | #endif /* PF_INET_ONLY */ | |
437 | #endif /* PF_INET6_ONLY */ | |
438 | #endif /* PF_INET_INET6 */ | |
439 | ||
440 | #define PF_MISMATCHAW(aw, x, af, neg, ifp) \ | |
441 | ( \ | |
442 | (((aw)->type == PF_ADDR_NOROUTE && \ | |
443 | pf_routable((x), (af), NULL)) || \ | |
444 | (((aw)->type == PF_ADDR_URPFFAILED && (ifp) != NULL && \ | |
445 | pf_routable((x), (af), (ifp))) || \ | |
446 | ((aw)->type == PF_ADDR_RTLABEL && \ | |
447 | !pf_rtlabel_match((x), (af), (aw))) || \ | |
448 | ((aw)->type == PF_ADDR_TABLE && \ | |
449 | !pfr_match_addr((aw)->p.tbl, (x), (af))) || \ | |
450 | ((aw)->type == PF_ADDR_DYNIFTL && \ | |
451 | !pfi_match_addr((aw)->p.dyn, (x), (af))) || \ | |
452 | ((aw)->type == PF_ADDR_RANGE && \ | |
453 | !pf_match_addr_range(&(aw)->v.a.addr, \ | |
454 | &(aw)->v.a.mask, (x), (af))) || \ | |
455 | ((aw)->type == PF_ADDR_ADDRMASK && \ | |
456 | !PF_AZERO(&(aw)->v.a.mask, (af)) && \ | |
457 | !PF_MATCHA(0, &(aw)->v.a.addr, \ | |
458 | &(aw)->v.a.mask, (x), (af))))) != \ | |
459 | (neg) \ | |
460 | ) | |
461 | ||
462 | ||
463 | struct pf_rule_uid { | |
464 | uid_t uid[2]; | |
465 | u_int8_t op; | |
466 | u_int8_t _pad[3]; | |
467 | }; | |
468 | ||
469 | struct pf_rule_gid { | |
470 | uid_t gid[2]; | |
471 | u_int8_t op; | |
472 | u_int8_t _pad[3]; | |
473 | }; | |
474 | ||
475 | struct pf_rule_addr { | |
476 | struct pf_addr_wrap addr; | |
477 | #ifndef NO_APPLE_EXTENSIONS | |
478 | union pf_rule_xport xport; | |
479 | u_int8_t neg; | |
480 | #else | |
481 | u_int16_t port[2]; | |
482 | u_int8_t neg; | |
483 | u_int8_t port_op; | |
484 | #endif | |
485 | }; | |
486 | ||
487 | struct pf_pooladdr { | |
488 | struct pf_addr_wrap addr; | |
489 | TAILQ_ENTRY(pf_pooladdr) entries; | |
490 | #if !defined(__LP64__) | |
491 | u_int32_t _pad[2]; | |
492 | #endif /* !__LP64__ */ | |
493 | char ifname[IFNAMSIZ]; | |
494 | struct pfi_kif *kif __attribute__((aligned(8))); | |
495 | }; | |
496 | ||
497 | TAILQ_HEAD(pf_palist, pf_pooladdr); | |
498 | ||
499 | struct pf_poolhashkey { | |
500 | union { | |
501 | u_int8_t key8[16]; | |
502 | u_int16_t key16[8]; | |
503 | u_int32_t key32[4]; | |
504 | } pfk; /* 128-bit hash key */ | |
505 | #define key8 pfk.key8 | |
506 | #define key16 pfk.key16 | |
507 | #define key32 pfk.key32 | |
508 | }; | |
509 | ||
510 | struct pf_pool { | |
511 | struct pf_palist list; | |
512 | #if !defined(__LP64__) | |
513 | u_int32_t _pad[2]; | |
514 | #endif /* !__LP64__ */ | |
515 | struct pf_pooladdr *cur __attribute__((aligned(8))); | |
516 | struct pf_poolhashkey key __attribute__((aligned(8))); | |
517 | struct pf_addr counter; | |
518 | int tblidx; | |
519 | u_int16_t proxy_port[2]; | |
520 | u_int8_t port_op; | |
521 | u_int8_t opts; | |
522 | }; | |
523 | ||
524 | ||
525 | /* A packed Operating System description for fingerprinting */ | |
526 | typedef u_int32_t pf_osfp_t; | |
527 | #define PF_OSFP_ANY ((pf_osfp_t)0) | |
528 | #define PF_OSFP_UNKNOWN ((pf_osfp_t)-1) | |
529 | #define PF_OSFP_NOMATCH ((pf_osfp_t)-2) | |
530 | ||
531 | struct pf_osfp_entry { | |
532 | SLIST_ENTRY(pf_osfp_entry) fp_entry; | |
533 | #if !defined(__LP64__) | |
534 | u_int32_t _pad; | |
535 | #endif /* !__LP64__ */ | |
536 | pf_osfp_t fp_os; | |
537 | int fp_enflags; | |
538 | #define PF_OSFP_EXPANDED 0x001 /* expanded entry */ | |
539 | #define PF_OSFP_GENERIC 0x002 /* generic signature */ | |
540 | #define PF_OSFP_NODETAIL 0x004 /* no p0f details */ | |
541 | #define PF_OSFP_LEN 32 | |
542 | char fp_class_nm[PF_OSFP_LEN]; | |
543 | char fp_version_nm[PF_OSFP_LEN]; | |
544 | char fp_subtype_nm[PF_OSFP_LEN]; | |
545 | }; | |
546 | #define PF_OSFP_ENTRY_EQ(a, b) \ | |
547 | ((a)->fp_os == (b)->fp_os && \ | |
548 | memcmp((a)->fp_class_nm, (b)->fp_class_nm, PF_OSFP_LEN) == 0 && \ | |
549 | memcmp((a)->fp_version_nm, (b)->fp_version_nm, PF_OSFP_LEN) == 0 && \ | |
550 | memcmp((a)->fp_subtype_nm, (b)->fp_subtype_nm, PF_OSFP_LEN) == 0) | |
551 | ||
552 | /* handle pf_osfp_t packing */ | |
553 | #define _FP_RESERVED_BIT 1 /* For the special negative #defines */ | |
554 | #define _FP_UNUSED_BITS 1 | |
555 | #define _FP_CLASS_BITS 10 /* OS Class (Windows, Linux) */ | |
556 | #define _FP_VERSION_BITS 10 /* OS version (95, 98, NT, 2.4.54, 3.2) */ | |
557 | #define _FP_SUBTYPE_BITS 10 /* patch level (NT SP4, SP3, ECN patch) */ | |
558 | #define PF_OSFP_UNPACK(osfp, class, version, subtype) do { \ | |
559 | (class) = ((osfp) >> (_FP_VERSION_BITS+_FP_SUBTYPE_BITS)) & \ | |
560 | ((1 << _FP_CLASS_BITS) - 1); \ | |
561 | (version) = ((osfp) >> _FP_SUBTYPE_BITS) & \ | |
562 | ((1 << _FP_VERSION_BITS) - 1);\ | |
563 | (subtype) = (osfp) & ((1 << _FP_SUBTYPE_BITS) - 1); \ | |
564 | } while (0) | |
565 | #define PF_OSFP_PACK(osfp, class, version, subtype) do { \ | |
566 | (osfp) = ((class) & ((1 << _FP_CLASS_BITS) - 1)) << (_FP_VERSION_BITS \ | |
567 | + _FP_SUBTYPE_BITS); \ | |
568 | (osfp) |= ((version) & ((1 << _FP_VERSION_BITS) - 1)) << \ | |
569 | _FP_SUBTYPE_BITS; \ | |
570 | (osfp) |= (subtype) & ((1 << _FP_SUBTYPE_BITS) - 1); \ | |
571 | } while (0) | |
572 | ||
573 | /* the fingerprint of an OSes TCP SYN packet */ | |
574 | typedef u_int64_t pf_tcpopts_t; | |
575 | struct pf_os_fingerprint { | |
576 | SLIST_HEAD(pf_osfp_enlist, pf_osfp_entry) fp_oses; /* list of matches */ | |
577 | pf_tcpopts_t fp_tcpopts; /* packed TCP options */ | |
578 | u_int16_t fp_wsize; /* TCP window size */ | |
579 | u_int16_t fp_psize; /* ip->ip_len */ | |
580 | u_int16_t fp_mss; /* TCP MSS */ | |
581 | u_int16_t fp_flags; | |
582 | #define PF_OSFP_WSIZE_MOD 0x0001 /* Window modulus */ | |
583 | #define PF_OSFP_WSIZE_DC 0x0002 /* Window don't care */ | |
584 | #define PF_OSFP_WSIZE_MSS 0x0004 /* Window multiple of MSS */ | |
585 | #define PF_OSFP_WSIZE_MTU 0x0008 /* Window multiple of MTU */ | |
586 | #define PF_OSFP_PSIZE_MOD 0x0010 /* packet size modulus */ | |
587 | #define PF_OSFP_PSIZE_DC 0x0020 /* packet size don't care */ | |
588 | #define PF_OSFP_WSCALE 0x0040 /* TCP window scaling */ | |
589 | #define PF_OSFP_WSCALE_MOD 0x0080 /* TCP window scale modulus */ | |
590 | #define PF_OSFP_WSCALE_DC 0x0100 /* TCP window scale dont-care */ | |
591 | #define PF_OSFP_MSS 0x0200 /* TCP MSS */ | |
592 | #define PF_OSFP_MSS_MOD 0x0400 /* TCP MSS modulus */ | |
593 | #define PF_OSFP_MSS_DC 0x0800 /* TCP MSS dont-care */ | |
594 | #define PF_OSFP_DF 0x1000 /* IPv4 don't fragment bit */ | |
595 | #define PF_OSFP_TS0 0x2000 /* Zero timestamp */ | |
596 | #define PF_OSFP_INET6 0x4000 /* IPv6 */ | |
597 | u_int8_t fp_optcnt; /* TCP option count */ | |
598 | u_int8_t fp_wscale; /* TCP window scaling */ | |
599 | u_int8_t fp_ttl; /* IPv4 TTL */ | |
600 | #define PF_OSFP_MAXTTL_OFFSET 40 | |
601 | /* TCP options packing */ | |
602 | #define PF_OSFP_TCPOPT_NOP 0x0 /* TCP NOP option */ | |
603 | #define PF_OSFP_TCPOPT_WSCALE 0x1 /* TCP window scaling option */ | |
604 | #define PF_OSFP_TCPOPT_MSS 0x2 /* TCP max segment size opt */ | |
605 | #define PF_OSFP_TCPOPT_SACK 0x3 /* TCP SACK OK option */ | |
606 | #define PF_OSFP_TCPOPT_TS 0x4 /* TCP timestamp option */ | |
607 | #define PF_OSFP_TCPOPT_BITS 3 /* bits used by each option */ | |
608 | #define PF_OSFP_MAX_OPTS \ | |
609 | (sizeof(((struct pf_os_fingerprint *)0)->fp_tcpopts) * 8) \ | |
610 | / PF_OSFP_TCPOPT_BITS | |
611 | ||
612 | SLIST_ENTRY(pf_os_fingerprint) fp_next; | |
613 | }; | |
614 | ||
615 | struct pf_osfp_ioctl { | |
616 | struct pf_osfp_entry fp_os; | |
617 | pf_tcpopts_t fp_tcpopts; /* packed TCP options */ | |
618 | u_int16_t fp_wsize; /* TCP window size */ | |
619 | u_int16_t fp_psize; /* ip->ip_len */ | |
620 | u_int16_t fp_mss; /* TCP MSS */ | |
621 | u_int16_t fp_flags; | |
622 | u_int8_t fp_optcnt; /* TCP option count */ | |
623 | u_int8_t fp_wscale; /* TCP window scaling */ | |
624 | u_int8_t fp_ttl; /* IPv4 TTL */ | |
625 | ||
626 | int fp_getnum; /* DIOCOSFPGET number */ | |
627 | }; | |
628 | ||
629 | ||
630 | union pf_rule_ptr { | |
631 | struct pf_rule *ptr __attribute__((aligned(8))); | |
632 | u_int32_t nr __attribute__((aligned(8))); | |
633 | } __attribute__((aligned(8))); | |
634 | ||
635 | #define PF_ANCHOR_NAME_SIZE 64 | |
636 | ||
637 | struct pf_rule { | |
638 | struct pf_rule_addr src; | |
639 | struct pf_rule_addr dst; | |
640 | #define PF_SKIP_IFP 0 | |
641 | #define PF_SKIP_DIR 1 | |
642 | #define PF_SKIP_AF 2 | |
643 | #define PF_SKIP_PROTO 3 | |
644 | #define PF_SKIP_SRC_ADDR 4 | |
645 | #define PF_SKIP_SRC_PORT 5 | |
646 | #define PF_SKIP_DST_ADDR 6 | |
647 | #define PF_SKIP_DST_PORT 7 | |
648 | #define PF_SKIP_COUNT 8 | |
649 | union pf_rule_ptr skip[PF_SKIP_COUNT]; | |
650 | #define PF_RULE_LABEL_SIZE 64 | |
651 | char label[PF_RULE_LABEL_SIZE]; | |
652 | #define PF_QNAME_SIZE 64 | |
653 | char ifname[IFNAMSIZ]; | |
654 | char qname[PF_QNAME_SIZE]; | |
655 | char pqname[PF_QNAME_SIZE]; | |
656 | #define PF_TAG_NAME_SIZE 64 | |
657 | char tagname[PF_TAG_NAME_SIZE]; | |
658 | char match_tagname[PF_TAG_NAME_SIZE]; | |
659 | ||
660 | char overload_tblname[PF_TABLE_NAME_SIZE]; | |
661 | ||
662 | TAILQ_ENTRY(pf_rule) entries; | |
663 | #if !defined(__LP64__) | |
664 | u_int32_t _pad[2]; | |
665 | #endif /* !__LP64__ */ | |
666 | struct pf_pool rpool; | |
667 | ||
668 | u_int64_t evaluations; | |
669 | u_int64_t packets[2]; | |
670 | u_int64_t bytes[2]; | |
671 | ||
672 | struct pfi_kif *kif __attribute__((aligned(8))); | |
673 | struct pf_anchor *anchor __attribute__((aligned(8))); | |
674 | struct pfr_ktable *overload_tbl __attribute__((aligned(8))); | |
675 | ||
676 | pf_osfp_t os_fingerprint __attribute__((aligned(8))); | |
677 | ||
678 | unsigned int rtableid; | |
679 | u_int32_t timeout[PFTM_MAX]; | |
680 | u_int32_t states; | |
681 | u_int32_t max_states; | |
682 | u_int32_t src_nodes; | |
683 | u_int32_t max_src_nodes; | |
684 | u_int32_t max_src_states; | |
685 | u_int32_t max_src_conn; | |
686 | struct { | |
687 | u_int32_t limit; | |
688 | u_int32_t seconds; | |
689 | } max_src_conn_rate; | |
690 | u_int32_t qid; | |
691 | u_int32_t pqid; | |
692 | u_int32_t rt_listid; | |
693 | u_int32_t nr; | |
694 | u_int32_t prob; | |
695 | uid_t cuid; | |
696 | pid_t cpid; | |
697 | ||
698 | u_int16_t return_icmp; | |
699 | u_int16_t return_icmp6; | |
700 | u_int16_t max_mss; | |
701 | u_int16_t tag; | |
702 | u_int16_t match_tag; | |
703 | ||
704 | struct pf_rule_uid uid; | |
705 | struct pf_rule_gid gid; | |
706 | ||
707 | u_int32_t rule_flag; | |
708 | u_int8_t action; | |
709 | u_int8_t direction; | |
710 | u_int8_t log; | |
711 | u_int8_t logif; | |
712 | u_int8_t quick; | |
713 | u_int8_t ifnot; | |
714 | u_int8_t match_tag_not; | |
715 | u_int8_t natpass; | |
716 | ||
717 | #define PF_STATE_NORMAL 0x1 | |
718 | #define PF_STATE_MODULATE 0x2 | |
719 | #define PF_STATE_SYNPROXY 0x3 | |
720 | u_int8_t keep_state; | |
721 | sa_family_t af; | |
722 | u_int8_t proto; | |
723 | u_int8_t type; | |
724 | u_int8_t code; | |
725 | u_int8_t flags; | |
726 | u_int8_t flagset; | |
727 | u_int8_t min_ttl; | |
728 | u_int8_t allow_opts; | |
729 | u_int8_t rt; | |
730 | u_int8_t return_ttl; | |
731 | u_int8_t tos; | |
732 | u_int8_t anchor_relative; | |
733 | u_int8_t anchor_wildcard; | |
734 | ||
735 | #define PF_FLUSH 0x01 | |
736 | #define PF_FLUSH_GLOBAL 0x02 | |
737 | u_int8_t flush; | |
738 | ||
739 | #ifndef NO_APPLE_EXTENSIONS | |
740 | u_int8_t proto_variant; | |
741 | u_int8_t extfilter; /* Filter mode [PF_EXTFILTER_xxx] */ | |
742 | u_int8_t extmap; /* Mapping mode [PF_EXTMAP_xxx] */ | |
743 | #endif | |
744 | }; | |
745 | ||
746 | /* rule flags */ | |
747 | #define PFRULE_DROP 0x0000 | |
748 | #define PFRULE_RETURNRST 0x0001 | |
749 | #define PFRULE_FRAGMENT 0x0002 | |
750 | #define PFRULE_RETURNICMP 0x0004 | |
751 | #define PFRULE_RETURN 0x0008 | |
752 | #define PFRULE_NOSYNC 0x0010 | |
753 | #define PFRULE_SRCTRACK 0x0020 /* track source states */ | |
754 | #define PFRULE_RULESRCTRACK 0x0040 /* per rule */ | |
755 | ||
756 | /* scrub flags */ | |
757 | #define PFRULE_NODF 0x0100 | |
758 | #define PFRULE_FRAGCROP 0x0200 /* non-buffering frag cache */ | |
759 | #define PFRULE_FRAGDROP 0x0400 /* drop funny fragments */ | |
760 | #define PFRULE_RANDOMID 0x0800 | |
761 | #define PFRULE_REASSEMBLE_TCP 0x1000 | |
762 | ||
763 | /* rule flags again */ | |
764 | #define PFRULE_IFBOUND 0x00010000 /* if-bound */ | |
765 | ||
766 | #define PFSTATE_HIWAT 10000 /* default state table size */ | |
767 | #define PFSTATE_ADAPT_START 6000 /* default adaptive timeout start */ | |
768 | #define PFSTATE_ADAPT_END 12000 /* default adaptive timeout end */ | |
769 | ||
770 | #ifndef NO_APPLE_EXTENSIONS | |
771 | #define PFAPPSTATE_HIWAT 10000 /* default same as state table */ | |
772 | ||
773 | enum pf_extmap { | |
774 | PF_EXTMAP_APD = 1, /* Address-port-dependent mapping */ | |
775 | PF_EXTMAP_AD, /* Address-dependent mapping */ | |
776 | PF_EXTMAP_EI /* Endpoint-independent mapping */ | |
777 | }; | |
778 | ||
779 | enum pf_extfilter { | |
780 | PF_EXTFILTER_APD = 1, /* Address-port-dependent filtering */ | |
781 | PF_EXTFILTER_AD, /* Address-dependent filtering */ | |
782 | PF_EXTFILTER_EI /* Endpoint-independent filtering */ | |
783 | }; | |
784 | #endif | |
785 | ||
786 | struct pf_threshold { | |
787 | u_int32_t limit; | |
788 | #define PF_THRESHOLD_MULT 1000 | |
789 | #define PF_THRESHOLD_MAX 0xffffffff / PF_THRESHOLD_MULT | |
790 | u_int32_t seconds; | |
791 | u_int32_t count; | |
792 | u_int32_t last; | |
793 | }; | |
794 | ||
795 | struct pf_src_node { | |
796 | RB_ENTRY(pf_src_node) entry; | |
797 | struct pf_addr addr; | |
798 | struct pf_addr raddr; | |
799 | union pf_rule_ptr rule; | |
800 | struct pfi_kif *kif; | |
801 | u_int64_t bytes[2]; | |
802 | u_int64_t packets[2]; | |
803 | u_int32_t states; | |
804 | u_int32_t conn; | |
805 | struct pf_threshold conn_rate; | |
806 | u_int64_t creation; | |
807 | u_int64_t expire; | |
808 | sa_family_t af; | |
809 | u_int8_t ruletype; | |
810 | }; | |
811 | ||
812 | #define PFSNODE_HIWAT 10000 /* default source node table size */ | |
813 | ||
814 | struct pf_state_scrub { | |
815 | struct timeval pfss_last; /* time received last packet */ | |
816 | u_int32_t pfss_tsecr; /* last echoed timestamp */ | |
817 | u_int32_t pfss_tsval; /* largest timestamp */ | |
818 | u_int32_t pfss_tsval0; /* original timestamp */ | |
819 | u_int16_t pfss_flags; | |
820 | #define PFSS_TIMESTAMP 0x0001 /* modulate timestamp */ | |
821 | #define PFSS_PAWS 0x0010 /* stricter PAWS checks */ | |
822 | #define PFSS_PAWS_IDLED 0x0020 /* was idle too long. no PAWS */ | |
823 | #define PFSS_DATA_TS 0x0040 /* timestamp on data packets */ | |
824 | #define PFSS_DATA_NOTS 0x0080 /* no timestamp on data packets */ | |
825 | u_int8_t pfss_ttl; /* stashed TTL */ | |
826 | u_int8_t pad; | |
827 | u_int32_t pfss_ts_mod; /* timestamp modulation */ | |
828 | }; | |
829 | ||
830 | #ifndef NO_APPLE_EXTENSIONS | |
831 | union pf_state_xport { | |
832 | u_int16_t port; | |
833 | u_int16_t call_id; | |
834 | u_int32_t spi; | |
835 | }; | |
836 | ||
837 | struct pf_state_host { | |
838 | struct pf_addr addr; | |
839 | union pf_state_xport xport; | |
840 | }; | |
841 | #else | |
842 | struct pf_state_host { | |
843 | struct pf_addr addr; | |
844 | u_int16_t port; | |
845 | u_int16_t pad; | |
846 | }; | |
847 | #endif | |
848 | ||
849 | struct pf_state_peer { | |
850 | u_int32_t seqlo; /* Max sequence number sent */ | |
851 | u_int32_t seqhi; /* Max the other end ACKd + win */ | |
852 | u_int32_t seqdiff; /* Sequence number modulator */ | |
853 | u_int16_t max_win; /* largest window (pre scaling) */ | |
854 | u_int8_t state; /* active state level */ | |
855 | u_int8_t wscale; /* window scaling factor */ | |
856 | u_int16_t mss; /* Maximum segment size option */ | |
857 | u_int8_t tcp_est; /* Did we reach TCPS_ESTABLISHED */ | |
858 | struct pf_state_scrub *scrub; /* state is scrubbed */ | |
859 | u_int8_t pad[3]; | |
860 | }; | |
861 | ||
862 | TAILQ_HEAD(pf_state_queue, pf_state); | |
863 | ||
864 | #ifndef NO_APPLE_EXTENSIONS | |
865 | #ifdef KERNEL | |
866 | struct pf_state; | |
867 | struct pf_pdesc; | |
868 | struct pf_app_state; | |
869 | ||
870 | typedef void (*pf_app_handler)(struct pf_state *, int, int, struct pf_pdesc *, | |
871 | struct pfi_kif *); | |
872 | ||
873 | typedef int (*pf_app_compare)(struct pf_app_state *, struct pf_app_state *); | |
874 | ||
875 | struct pf_pptp_state { | |
876 | struct pf_state *grev1_state; | |
877 | }; | |
878 | ||
879 | struct pf_ike_state { | |
880 | u_int64_t cookie; | |
881 | }; | |
882 | ||
883 | struct pf_app_state { | |
884 | pf_app_handler handler; | |
885 | pf_app_compare compare_lan_ext; | |
886 | pf_app_compare compare_ext_gwy; | |
887 | union { | |
888 | struct pf_pptp_state pptp; | |
889 | struct pf_ike_state ike; | |
890 | } u; | |
891 | }; | |
892 | #endif /* KERNEL */ | |
893 | #define PF_GRE_PPTP_VARIANT 0x01 | |
894 | #endif | |
895 | ||
896 | /* keep synced with struct pf_state, used in RB_FIND */ | |
897 | struct pf_state_key_cmp { | |
898 | struct pf_state_host lan; | |
899 | struct pf_state_host gwy; | |
900 | struct pf_state_host ext; | |
901 | sa_family_t af; | |
902 | u_int8_t proto; | |
903 | u_int8_t direction; | |
904 | #ifndef NO_APPLE_EXTENSIONS | |
905 | u_int8_t proto_variant; | |
906 | struct pf_app_state *app_state; | |
907 | #else | |
908 | u_int8_t pad; | |
909 | #endif | |
910 | }; | |
911 | ||
912 | TAILQ_HEAD(pf_statelist, pf_state); | |
913 | ||
914 | struct pf_state_key { | |
915 | struct pf_state_host lan; | |
916 | struct pf_state_host gwy; | |
917 | struct pf_state_host ext; | |
918 | sa_family_t af; | |
919 | u_int8_t proto; | |
920 | u_int8_t direction; | |
921 | #ifndef NO_APPLE_EXTENSIONS | |
922 | u_int8_t proto_variant; | |
923 | struct pf_app_state *app_state; | |
924 | #else | |
925 | u_int8_t pad; | |
926 | #endif | |
927 | ||
928 | RB_ENTRY(pf_state_key) entry_lan_ext; | |
929 | RB_ENTRY(pf_state_key) entry_ext_gwy; | |
930 | struct pf_statelist states; | |
931 | u_short refcnt; /* same size as if_index */ | |
932 | }; | |
933 | ||
934 | ||
935 | /* keep synced with struct pf_state, used in RB_FIND */ | |
936 | struct pf_state_cmp { | |
937 | u_int64_t id; | |
938 | u_int32_t creatorid; | |
939 | u_int32_t pad; | |
940 | }; | |
941 | ||
942 | struct hook_desc; | |
943 | TAILQ_HEAD(hook_desc_head, hook_desc); | |
944 | ||
945 | struct pf_state { | |
946 | u_int64_t id; | |
947 | u_int32_t creatorid; | |
948 | u_int32_t pad; | |
949 | ||
950 | TAILQ_ENTRY(pf_state) entry_list; | |
951 | TAILQ_ENTRY(pf_state) next; | |
952 | RB_ENTRY(pf_state) entry_id; | |
953 | struct pf_state_peer src; | |
954 | struct pf_state_peer dst; | |
955 | union pf_rule_ptr rule; | |
956 | union pf_rule_ptr anchor; | |
957 | union pf_rule_ptr nat_rule; | |
958 | struct pf_addr rt_addr; | |
959 | #ifndef NO_APPLE_EXTENSIONS | |
960 | struct hook_desc_head unlink_hooks; | |
961 | #endif | |
962 | struct pf_state_key *state_key; | |
963 | struct pfi_kif *kif; | |
964 | struct pfi_kif *rt_kif; | |
965 | struct pf_src_node *src_node; | |
966 | struct pf_src_node *nat_src_node; | |
967 | u_int64_t packets[2]; | |
968 | u_int64_t bytes[2]; | |
969 | u_int64_t creation; | |
970 | u_int64_t expire; | |
971 | u_int64_t pfsync_time; | |
972 | u_int16_t tag; | |
973 | u_int8_t log; | |
974 | u_int8_t allow_opts; | |
975 | u_int8_t timeout; | |
976 | u_int8_t sync_flags; | |
977 | #define PFSTATE_NOSYNC 0x01 | |
978 | #define PFSTATE_FROMSYNC 0x02 | |
979 | #define PFSTATE_STALE 0x04 | |
980 | }; | |
981 | ||
982 | #define __packed __attribute__((__packed__)) | |
983 | ||
984 | /* | |
985 | * Unified state structures for pulling states out of the kernel | |
986 | * used by pfsync(4) and the pf(4) ioctl. | |
987 | */ | |
988 | struct pfsync_state_scrub { | |
989 | u_int16_t pfss_flags; | |
990 | u_int8_t pfss_ttl; /* stashed TTL */ | |
991 | #define PFSYNC_SCRUB_FLAG_VALID 0x01 | |
992 | u_int8_t scrub_flag; | |
993 | u_int32_t pfss_ts_mod; /* timestamp modulation */ | |
994 | } __packed; | |
995 | ||
996 | struct pfsync_state_host { | |
997 | struct pf_addr addr; | |
998 | #ifndef NO_APPLE_EXTENSIONS | |
999 | union pf_state_xport xport; | |
1000 | u_int16_t pad[2]; | |
1001 | #else | |
1002 | u_int16_t port; | |
1003 | u_int16_t pad[3]; | |
1004 | #endif | |
1005 | } __packed; | |
1006 | ||
1007 | struct pfsync_state_peer { | |
1008 | struct pfsync_state_scrub scrub; /* state is scrubbed */ | |
1009 | u_int32_t seqlo; /* Max sequence number sent */ | |
1010 | u_int32_t seqhi; /* Max the other end ACKd + win */ | |
1011 | u_int32_t seqdiff; /* Sequence number modulator */ | |
1012 | u_int16_t max_win; /* largest window (pre scaling) */ | |
1013 | u_int16_t mss; /* Maximum segment size option */ | |
1014 | u_int8_t state; /* active state level */ | |
1015 | u_int8_t wscale; /* window scaling factor */ | |
1016 | u_int8_t pad[6]; | |
1017 | } __packed; | |
1018 | ||
1019 | struct pfsync_state { | |
1020 | u_int32_t id[2]; | |
1021 | char ifname[IFNAMSIZ]; | |
1022 | struct pfsync_state_host lan; | |
1023 | struct pfsync_state_host gwy; | |
1024 | struct pfsync_state_host ext; | |
1025 | struct pfsync_state_peer src; | |
1026 | struct pfsync_state_peer dst; | |
1027 | struct pf_addr rt_addr; | |
1028 | #ifndef NO_APPLE_EXTENSIONS | |
1029 | struct hook_desc_head unlink_hooks; | |
1030 | #if !defined(__LP64__) | |
1031 | u_int32_t _pad[2]; | |
1032 | #endif /* !__LP64__ */ | |
1033 | #endif | |
1034 | u_int32_t rule; | |
1035 | u_int32_t anchor; | |
1036 | u_int32_t nat_rule; | |
1037 | u_int64_t creation; | |
1038 | u_int64_t expire; | |
1039 | u_int32_t packets[2][2]; | |
1040 | u_int32_t bytes[2][2]; | |
1041 | u_int32_t creatorid; | |
1042 | #ifndef NO_APPLE_EXTENSIONS | |
1043 | u_int16_t tag; | |
1044 | #endif | |
1045 | sa_family_t af; | |
1046 | u_int8_t proto; | |
1047 | u_int8_t direction; | |
1048 | u_int8_t log; | |
1049 | u_int8_t allow_opts; | |
1050 | u_int8_t timeout; | |
1051 | u_int8_t sync_flags; | |
1052 | u_int8_t updates; | |
1053 | #ifndef NO_APPLE_EXTENSIONS | |
1054 | u_int8_t proto_variant; | |
1055 | #endif | |
1056 | } __packed; | |
1057 | ||
1058 | #define PFSYNC_FLAG_COMPRESS 0x01 | |
1059 | #define PFSYNC_FLAG_STALE 0x02 | |
1060 | #define PFSYNC_FLAG_SRCNODE 0x04 | |
1061 | #define PFSYNC_FLAG_NATSRCNODE 0x08 | |
1062 | ||
1063 | /* for copies to/from userland via pf_ioctl() */ | |
1064 | #define pf_state_peer_to_pfsync(s, d) do { \ | |
1065 | (d)->seqlo = (s)->seqlo; \ | |
1066 | (d)->seqhi = (s)->seqhi; \ | |
1067 | (d)->seqdiff = (s)->seqdiff; \ | |
1068 | (d)->max_win = (s)->max_win; \ | |
1069 | (d)->mss = (s)->mss; \ | |
1070 | (d)->state = (s)->state; \ | |
1071 | (d)->wscale = (s)->wscale; \ | |
1072 | if ((s)->scrub) { \ | |
1073 | (d)->scrub.pfss_flags = \ | |
1074 | (s)->scrub->pfss_flags & PFSS_TIMESTAMP; \ | |
1075 | (d)->scrub.pfss_ttl = (s)->scrub->pfss_ttl; \ | |
1076 | (d)->scrub.pfss_ts_mod = (s)->scrub->pfss_ts_mod; \ | |
1077 | (d)->scrub.scrub_flag = PFSYNC_SCRUB_FLAG_VALID; \ | |
1078 | } \ | |
1079 | } while (0) | |
1080 | ||
1081 | #define pf_state_peer_from_pfsync(s, d) do { \ | |
1082 | (d)->seqlo = (s)->seqlo; \ | |
1083 | (d)->seqhi = (s)->seqhi; \ | |
1084 | (d)->seqdiff = (s)->seqdiff; \ | |
1085 | (d)->max_win = (s)->max_win; \ | |
1086 | (d)->mss = ntohs((s)->mss); \ | |
1087 | (d)->state = (s)->state; \ | |
1088 | (d)->wscale = (s)->wscale; \ | |
1089 | if ((s)->scrub.scrub_flag == PFSYNC_SCRUB_FLAG_VALID && \ | |
1090 | (d)->scrub != NULL) { \ | |
1091 | (d)->scrub->pfss_flags = \ | |
1092 | ntohs((s)->scrub.pfss_flags) & PFSS_TIMESTAMP; \ | |
1093 | (d)->scrub->pfss_ttl = (s)->scrub.pfss_ttl; \ | |
1094 | (d)->scrub->pfss_ts_mod = (s)->scrub.pfss_ts_mod; \ | |
1095 | } \ | |
1096 | } while (0) | |
1097 | ||
1098 | #define pf_state_counter_to_pfsync(s, d) do { \ | |
1099 | d[0] = (s>>32)&0xffffffff; \ | |
1100 | d[1] = s&0xffffffff; \ | |
1101 | } while (0) | |
1102 | ||
1103 | #define pf_state_counter_from_pfsync(s) \ | |
1104 | (((u_int64_t)(s[0])<<32) | (u_int64_t)(s[1])) | |
1105 | ||
1106 | ||
1107 | ||
1108 | TAILQ_HEAD(pf_rulequeue, pf_rule); | |
1109 | ||
1110 | struct pf_anchor; | |
1111 | ||
1112 | struct pf_ruleset { | |
1113 | struct { | |
1114 | struct pf_rulequeue queues[2]; | |
1115 | struct { | |
1116 | struct pf_rulequeue *ptr; | |
1117 | struct pf_rule **ptr_array; | |
1118 | u_int32_t rcount; | |
1119 | u_int32_t ticket; | |
1120 | int open; | |
1121 | } active, inactive; | |
1122 | } rules[PF_RULESET_MAX]; | |
1123 | struct pf_anchor *anchor; | |
1124 | u_int32_t tticket; | |
1125 | int tables; | |
1126 | int topen; | |
1127 | }; | |
1128 | ||
1129 | RB_HEAD(pf_anchor_global, pf_anchor); | |
1130 | RB_HEAD(pf_anchor_node, pf_anchor); | |
1131 | struct pf_anchor { | |
1132 | RB_ENTRY(pf_anchor) entry_global; | |
1133 | RB_ENTRY(pf_anchor) entry_node; | |
1134 | struct pf_anchor *parent; | |
1135 | struct pf_anchor_node children; | |
1136 | char name[PF_ANCHOR_NAME_SIZE]; | |
1137 | char path[MAXPATHLEN]; | |
1138 | struct pf_ruleset ruleset; | |
1139 | int refcnt; /* anchor rules */ | |
1140 | int match; | |
1141 | }; | |
1142 | #ifdef KERNEL | |
1143 | RB_PROTOTYPE_SC(__private_extern__, pf_anchor_global, pf_anchor, entry_global, | |
1144 | pf_anchor_compare); | |
1145 | RB_PROTOTYPE_SC(__private_extern__, pf_anchor_node, pf_anchor, entry_node, | |
1146 | pf_anchor_compare); | |
1147 | #else /* !KERNEL */ | |
1148 | RB_PROTOTYPE(pf_anchor_global, pf_anchor, entry_global, pf_anchor_compare); | |
1149 | RB_PROTOTYPE(pf_anchor_node, pf_anchor, entry_node, pf_anchor_compare); | |
1150 | #endif /* !KERNEL */ | |
1151 | ||
1152 | #define PF_RESERVED_ANCHOR "_pf" | |
1153 | ||
1154 | #define PFR_TFLAG_PERSIST 0x00000001 | |
1155 | #define PFR_TFLAG_CONST 0x00000002 | |
1156 | #define PFR_TFLAG_ACTIVE 0x00000004 | |
1157 | #define PFR_TFLAG_INACTIVE 0x00000008 | |
1158 | #define PFR_TFLAG_REFERENCED 0x00000010 | |
1159 | #define PFR_TFLAG_REFDANCHOR 0x00000020 | |
1160 | #define PFR_TFLAG_USRMASK 0x00000003 | |
1161 | #define PFR_TFLAG_SETMASK 0x0000003C | |
1162 | #define PFR_TFLAG_ALLMASK 0x0000003F | |
1163 | ||
1164 | struct pfr_table { | |
1165 | char pfrt_anchor[MAXPATHLEN]; | |
1166 | char pfrt_name[PF_TABLE_NAME_SIZE]; | |
1167 | u_int32_t pfrt_flags; | |
1168 | u_int8_t pfrt_fback; | |
1169 | }; | |
1170 | ||
1171 | enum { PFR_FB_NONE, PFR_FB_MATCH, PFR_FB_ADDED, PFR_FB_DELETED, | |
1172 | PFR_FB_CHANGED, PFR_FB_CLEARED, PFR_FB_DUPLICATE, | |
1173 | PFR_FB_NOTMATCH, PFR_FB_CONFLICT, PFR_FB_MAX }; | |
1174 | ||
1175 | struct pfr_addr { | |
1176 | union { | |
1177 | struct in_addr _pfra_ip4addr; | |
1178 | struct in6_addr _pfra_ip6addr; | |
1179 | } pfra_u; | |
1180 | u_int8_t pfra_af; | |
1181 | u_int8_t pfra_net; | |
1182 | u_int8_t pfra_not; | |
1183 | u_int8_t pfra_fback; | |
1184 | }; | |
1185 | #define pfra_ip4addr pfra_u._pfra_ip4addr | |
1186 | #define pfra_ip6addr pfra_u._pfra_ip6addr | |
1187 | ||
1188 | enum { PFR_DIR_IN, PFR_DIR_OUT, PFR_DIR_MAX }; | |
1189 | enum { PFR_OP_BLOCK, PFR_OP_PASS, PFR_OP_ADDR_MAX, PFR_OP_TABLE_MAX }; | |
1190 | #define PFR_OP_XPASS PFR_OP_ADDR_MAX | |
1191 | ||
1192 | struct pfr_astats { | |
1193 | struct pfr_addr pfras_a; | |
1194 | u_int64_t pfras_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; | |
1195 | u_int64_t pfras_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; | |
1196 | u_int64_t pfras_tzero; | |
1197 | }; | |
1198 | ||
1199 | enum { PFR_REFCNT_RULE, PFR_REFCNT_ANCHOR, PFR_REFCNT_MAX }; | |
1200 | ||
1201 | struct pfr_tstats { | |
1202 | struct pfr_table pfrts_t; | |
1203 | u_int64_t pfrts_packets[PFR_DIR_MAX][PFR_OP_TABLE_MAX]; | |
1204 | u_int64_t pfrts_bytes[PFR_DIR_MAX][PFR_OP_TABLE_MAX]; | |
1205 | u_int64_t pfrts_match; | |
1206 | u_int64_t pfrts_nomatch; | |
1207 | u_int64_t pfrts_tzero; | |
1208 | int pfrts_cnt; | |
1209 | int pfrts_refcnt[PFR_REFCNT_MAX]; | |
1210 | }; | |
1211 | #define pfrts_name pfrts_t.pfrt_name | |
1212 | #define pfrts_flags pfrts_t.pfrt_flags | |
1213 | ||
1214 | SLIST_HEAD(pfr_kentryworkq, pfr_kentry); | |
1215 | struct pfr_kentry { | |
1216 | struct radix_node pfrke_node[2]; | |
1217 | union sockaddr_union pfrke_sa; | |
1218 | u_int64_t pfrke_packets[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; | |
1219 | u_int64_t pfrke_bytes[PFR_DIR_MAX][PFR_OP_ADDR_MAX]; | |
1220 | SLIST_ENTRY(pfr_kentry) pfrke_workq; | |
1221 | u_int64_t pfrke_tzero; | |
1222 | u_int8_t pfrke_af; | |
1223 | u_int8_t pfrke_net; | |
1224 | u_int8_t pfrke_not; | |
1225 | u_int8_t pfrke_mark; | |
1226 | u_int8_t pfrke_intrpool; | |
1227 | }; | |
1228 | ||
1229 | SLIST_HEAD(pfr_ktableworkq, pfr_ktable); | |
1230 | RB_HEAD(pfr_ktablehead, pfr_ktable); | |
1231 | struct pfr_ktable { | |
1232 | struct pfr_tstats pfrkt_ts; | |
1233 | RB_ENTRY(pfr_ktable) pfrkt_tree; | |
1234 | SLIST_ENTRY(pfr_ktable) pfrkt_workq; | |
1235 | struct radix_node_head *pfrkt_ip4; | |
1236 | struct radix_node_head *pfrkt_ip6; | |
1237 | struct pfr_ktable *pfrkt_shadow; | |
1238 | struct pfr_ktable *pfrkt_root; | |
1239 | struct pf_ruleset *pfrkt_rs; | |
1240 | u_int64_t pfrkt_larg; | |
1241 | u_int32_t pfrkt_nflags; | |
1242 | }; | |
1243 | #define pfrkt_t pfrkt_ts.pfrts_t | |
1244 | #define pfrkt_name pfrkt_t.pfrt_name | |
1245 | #define pfrkt_anchor pfrkt_t.pfrt_anchor | |
1246 | #define pfrkt_ruleset pfrkt_t.pfrt_ruleset | |
1247 | #define pfrkt_flags pfrkt_t.pfrt_flags | |
1248 | #define pfrkt_cnt pfrkt_ts.pfrts_cnt | |
1249 | #define pfrkt_refcnt pfrkt_ts.pfrts_refcnt | |
1250 | #define pfrkt_packets pfrkt_ts.pfrts_packets | |
1251 | #define pfrkt_bytes pfrkt_ts.pfrts_bytes | |
1252 | #define pfrkt_match pfrkt_ts.pfrts_match | |
1253 | #define pfrkt_nomatch pfrkt_ts.pfrts_nomatch | |
1254 | #define pfrkt_tzero pfrkt_ts.pfrts_tzero | |
1255 | ||
1256 | RB_HEAD(pf_state_tree_lan_ext, pf_state_key); | |
1257 | #ifdef KERNEL | |
1258 | RB_PROTOTYPE_SC(__private_extern__, pf_state_tree_lan_ext, pf_state_key, | |
1259 | entry_lan_ext, pf_state_compare_lan_ext); | |
1260 | #else /* !KERNEL */ | |
1261 | RB_PROTOTYPE(pf_state_tree_lan_ext, pf_state_key, entry_lan_ext, | |
1262 | pf_state_compare_lan_ext); | |
1263 | #endif /* !KERNEL */ | |
1264 | ||
1265 | RB_HEAD(pf_state_tree_ext_gwy, pf_state_key); | |
1266 | #ifdef KERNEL | |
1267 | RB_PROTOTYPE_SC(__private_extern__, pf_state_tree_ext_gwy, pf_state_key, | |
1268 | entry_ext_gwy, pf_state_compare_ext_gwy); | |
1269 | #else /* !KERNEL */ | |
1270 | RB_PROTOTYPE(pf_state_tree_ext_gwy, pf_state_key, entry_ext_gwy, | |
1271 | pf_state_compare_ext_gwy); | |
1272 | #endif /* !KERNEL */ | |
1273 | ||
1274 | RB_HEAD(pfi_ifhead, pfi_kif); | |
1275 | ||
1276 | /* state tables */ | |
1277 | #ifdef KERNEL | |
1278 | __private_extern__ struct pf_state_tree_lan_ext pf_statetbl_lan_ext; | |
1279 | __private_extern__ struct pf_state_tree_ext_gwy pf_statetbl_ext_gwy; | |
1280 | #else /* !KERNEL */ | |
1281 | extern struct pf_state_tree_lan_ext pf_statetbl_lan_ext; | |
1282 | extern struct pf_state_tree_ext_gwy pf_statetbl_ext_gwy; | |
1283 | #endif /* !KERNEL */ | |
1284 | ||
1285 | /* keep synced with pfi_kif, used in RB_FIND */ | |
1286 | struct pfi_kif_cmp { | |
1287 | char pfik_name[IFNAMSIZ]; | |
1288 | }; | |
1289 | ||
1290 | struct pfi_kif { | |
1291 | char pfik_name[IFNAMSIZ]; | |
1292 | RB_ENTRY(pfi_kif) pfik_tree; | |
1293 | u_int64_t pfik_packets[2][2][2]; | |
1294 | u_int64_t pfik_bytes[2][2][2]; | |
1295 | u_int64_t pfik_tzero; | |
1296 | int pfik_flags; | |
1297 | void *pfik_ah_cookie; | |
1298 | struct ifnet *pfik_ifp; | |
1299 | int pfik_states; | |
1300 | int pfik_rules; | |
1301 | TAILQ_HEAD(, pfi_dynaddr) pfik_dynaddrs; | |
1302 | }; | |
1303 | ||
1304 | enum pfi_kif_refs { | |
1305 | PFI_KIF_REF_NONE, | |
1306 | PFI_KIF_REF_STATE, | |
1307 | PFI_KIF_REF_RULE | |
1308 | }; | |
1309 | ||
1310 | #define PFI_IFLAG_SKIP 0x0100 /* skip filtering on interface */ | |
1311 | ||
1312 | #ifdef KERNEL | |
1313 | struct pf_pdesc { | |
1314 | struct { | |
1315 | int done; | |
1316 | uid_t uid; | |
1317 | gid_t gid; | |
1318 | pid_t pid; | |
1319 | } lookup; | |
1320 | u_int64_t tot_len; /* Make Mickey money */ | |
1321 | union { | |
1322 | struct tcphdr *tcp; | |
1323 | struct udphdr *udp; | |
1324 | struct icmp *icmp; | |
1325 | #if INET6 | |
1326 | struct icmp6_hdr *icmp6; | |
1327 | #endif /* INET6 */ | |
1328 | #ifndef NO_APPLE_EXTENSIONS | |
1329 | struct pf_grev1_hdr *grev1; | |
1330 | struct pf_esp_hdr *esp; | |
1331 | #endif | |
1332 | void *any; | |
1333 | } hdr; | |
1334 | struct pf_addr baddr; /* address before translation */ | |
1335 | struct pf_addr naddr; /* address after translation */ | |
1336 | struct pf_rule *nat_rule; /* nat/rdr rule applied to packet */ | |
1337 | struct pf_addr *src; | |
1338 | struct pf_addr *dst; | |
1339 | struct ether_header | |
1340 | *eh; | |
1341 | #ifndef NO_APPLE_EXTENSIONS | |
1342 | struct mbuf *mp; | |
1343 | int lmw; /* lazy writable offset */ | |
1344 | #endif | |
1345 | struct pf_mtag *pf_mtag; | |
1346 | u_int16_t *ip_sum; | |
1347 | u_int32_t p_len; /* total length of payload */ | |
1348 | u_int16_t flags; /* Let SCRUB trigger behavior in */ | |
1349 | /* state code. Easier than tags */ | |
1350 | #define PFDESC_TCP_NORM 0x0001 /* TCP shall be statefully scrubbed */ | |
1351 | #define PFDESC_IP_REAS 0x0002 /* IP frags would've been reassembled */ | |
1352 | sa_family_t af; | |
1353 | u_int8_t proto; | |
1354 | u_int8_t tos; | |
1355 | #ifndef NO_APPLE_EXTENSIONS | |
1356 | u_int8_t proto_variant; | |
1357 | #endif | |
1358 | }; | |
1359 | #endif /* KERNEL */ | |
1360 | ||
1361 | /* flags for RDR options */ | |
1362 | #define PF_DPORT_RANGE 0x01 /* Dest port uses range */ | |
1363 | #define PF_RPORT_RANGE 0x02 /* RDR'ed port uses range */ | |
1364 | ||
1365 | /* Reasons code for passing/dropping a packet */ | |
1366 | #define PFRES_MATCH 0 /* Explicit match of a rule */ | |
1367 | #define PFRES_BADOFF 1 /* Bad offset for pull_hdr */ | |
1368 | #define PFRES_FRAG 2 /* Dropping following fragment */ | |
1369 | #define PFRES_SHORT 3 /* Dropping short packet */ | |
1370 | #define PFRES_NORM 4 /* Dropping by normalizer */ | |
1371 | #define PFRES_MEMORY 5 /* Dropped due to lacking mem */ | |
1372 | #define PFRES_TS 6 /* Bad TCP Timestamp (RFC1323) */ | |
1373 | #define PFRES_CONGEST 7 /* Congestion (of ipintrq) */ | |
1374 | #define PFRES_IPOPTIONS 8 /* IP option */ | |
1375 | #define PFRES_PROTCKSUM 9 /* Protocol checksum invalid */ | |
1376 | #define PFRES_BADSTATE 10 /* State mismatch */ | |
1377 | #define PFRES_STATEINS 11 /* State insertion failure */ | |
1378 | #define PFRES_MAXSTATES 12 /* State limit */ | |
1379 | #define PFRES_SRCLIMIT 13 /* Source node/conn limit */ | |
1380 | #define PFRES_SYNPROXY 14 /* SYN proxy */ | |
1381 | #define PFRES_MAX 15 /* total+1 */ | |
1382 | ||
1383 | #define PFRES_NAMES { \ | |
1384 | "match", \ | |
1385 | "bad-offset", \ | |
1386 | "fragment", \ | |
1387 | "short", \ | |
1388 | "normalize", \ | |
1389 | "memory", \ | |
1390 | "bad-timestamp", \ | |
1391 | "congestion", \ | |
1392 | "ip-option", \ | |
1393 | "proto-cksum", \ | |
1394 | "state-mismatch", \ | |
1395 | "state-insert", \ | |
1396 | "state-limit", \ | |
1397 | "src-limit", \ | |
1398 | "synproxy", \ | |
1399 | NULL \ | |
1400 | } | |
1401 | ||
1402 | /* Counters for other things we want to keep track of */ | |
1403 | #define LCNT_STATES 0 /* states */ | |
1404 | #define LCNT_SRCSTATES 1 /* max-src-states */ | |
1405 | #define LCNT_SRCNODES 2 /* max-src-nodes */ | |
1406 | #define LCNT_SRCCONN 3 /* max-src-conn */ | |
1407 | #define LCNT_SRCCONNRATE 4 /* max-src-conn-rate */ | |
1408 | #define LCNT_OVERLOAD_TABLE 5 /* entry added to overload table */ | |
1409 | #define LCNT_OVERLOAD_FLUSH 6 /* state entries flushed */ | |
1410 | #define LCNT_MAX 7 /* total+1 */ | |
1411 | ||
1412 | #define LCNT_NAMES { \ | |
1413 | "max states per rule", \ | |
1414 | "max-src-states", \ | |
1415 | "max-src-nodes", \ | |
1416 | "max-src-conn", \ | |
1417 | "max-src-conn-rate", \ | |
1418 | "overload table insertion", \ | |
1419 | "overload flush states", \ | |
1420 | NULL \ | |
1421 | } | |
1422 | ||
1423 | /* UDP state enumeration */ | |
1424 | #define PFUDPS_NO_TRAFFIC 0 | |
1425 | #define PFUDPS_SINGLE 1 | |
1426 | #define PFUDPS_MULTIPLE 2 | |
1427 | ||
1428 | #define PFUDPS_NSTATES 3 /* number of state levels */ | |
1429 | ||
1430 | #define PFUDPS_NAMES { \ | |
1431 | "NO_TRAFFIC", \ | |
1432 | "SINGLE", \ | |
1433 | "MULTIPLE", \ | |
1434 | NULL \ | |
1435 | } | |
1436 | ||
1437 | #ifndef NO_APPLE_EXTENSIONS | |
1438 | /* GREv1 protocol state enumeration */ | |
1439 | #define PFGRE1S_NO_TRAFFIC 0 | |
1440 | #define PFGRE1S_INITIATING 1 | |
1441 | #define PFGRE1S_ESTABLISHED 2 | |
1442 | ||
1443 | #define PFGRE1S_NSTATES 3 /* number of state levels */ | |
1444 | ||
1445 | #define PFGRE1S_NAMES { \ | |
1446 | "NO_TRAFFIC", \ | |
1447 | "INITIATING", \ | |
1448 | "ESTABLISHED", \ | |
1449 | NULL \ | |
1450 | } | |
1451 | ||
1452 | #define PFESPS_NO_TRAFFIC 0 | |
1453 | #define PFESPS_INITIATING 1 | |
1454 | #define PFESPS_ESTABLISHED 2 | |
1455 | ||
1456 | #define PFESPS_NSTATES 3 /* number of state levels */ | |
1457 | ||
1458 | #define PFESPS_NAMES { "NO_TRAFFIC", "INITIATING", "ESTABLISHED", NULL } | |
1459 | #endif | |
1460 | ||
1461 | /* Other protocol state enumeration */ | |
1462 | #define PFOTHERS_NO_TRAFFIC 0 | |
1463 | #define PFOTHERS_SINGLE 1 | |
1464 | #define PFOTHERS_MULTIPLE 2 | |
1465 | ||
1466 | #define PFOTHERS_NSTATES 3 /* number of state levels */ | |
1467 | ||
1468 | #define PFOTHERS_NAMES { \ | |
1469 | "NO_TRAFFIC", \ | |
1470 | "SINGLE", \ | |
1471 | "MULTIPLE", \ | |
1472 | NULL \ | |
1473 | } | |
1474 | ||
1475 | #define FCNT_STATE_SEARCH 0 | |
1476 | #define FCNT_STATE_INSERT 1 | |
1477 | #define FCNT_STATE_REMOVALS 2 | |
1478 | #define FCNT_MAX 3 | |
1479 | ||
1480 | #define SCNT_SRC_NODE_SEARCH 0 | |
1481 | #define SCNT_SRC_NODE_INSERT 1 | |
1482 | #define SCNT_SRC_NODE_REMOVALS 2 | |
1483 | #define SCNT_MAX 3 | |
1484 | ||
1485 | #define ACTION_SET(a, x) \ | |
1486 | do { \ | |
1487 | if ((a) != NULL) \ | |
1488 | *(a) = (x); \ | |
1489 | } while (0) | |
1490 | ||
1491 | #define REASON_SET(a, x) \ | |
1492 | do { \ | |
1493 | if ((a) != NULL) \ | |
1494 | *(a) = (x); \ | |
1495 | if (x < PFRES_MAX) \ | |
1496 | pf_status.counters[x]++; \ | |
1497 | } while (0) | |
1498 | ||
1499 | struct pf_status { | |
1500 | u_int64_t counters[PFRES_MAX]; | |
1501 | u_int64_t lcounters[LCNT_MAX]; /* limit counters */ | |
1502 | u_int64_t fcounters[FCNT_MAX]; | |
1503 | u_int64_t scounters[SCNT_MAX]; | |
1504 | u_int64_t pcounters[2][2][3]; | |
1505 | u_int64_t bcounters[2][2]; | |
1506 | u_int64_t stateid; | |
1507 | u_int32_t running; | |
1508 | u_int32_t states; | |
1509 | u_int32_t src_nodes; | |
1510 | u_int64_t since __attribute__((aligned(8))); | |
1511 | u_int32_t debug; | |
1512 | u_int32_t hostid; | |
1513 | char ifname[IFNAMSIZ]; | |
1514 | u_int8_t pf_chksum[PF_MD5_DIGEST_LENGTH]; | |
1515 | }; | |
1516 | ||
1517 | struct cbq_opts { | |
1518 | u_int minburst; | |
1519 | u_int maxburst; | |
1520 | u_int pktsize; | |
1521 | u_int maxpktsize; | |
1522 | u_int ns_per_byte; | |
1523 | u_int maxidle; | |
1524 | int minidle; | |
1525 | u_int offtime; | |
1526 | int flags; | |
1527 | }; | |
1528 | ||
1529 | struct priq_opts { | |
1530 | int flags; | |
1531 | }; | |
1532 | ||
1533 | struct hfsc_opts { | |
1534 | /* real-time service curve */ | |
1535 | u_int rtsc_m1; /* slope of the 1st segment in bps */ | |
1536 | u_int rtsc_d; /* the x-projection of m1 in msec */ | |
1537 | u_int rtsc_m2; /* slope of the 2nd segment in bps */ | |
1538 | /* link-sharing service curve */ | |
1539 | u_int lssc_m1; | |
1540 | u_int lssc_d; | |
1541 | u_int lssc_m2; | |
1542 | /* upper-limit service curve */ | |
1543 | u_int ulsc_m1; | |
1544 | u_int ulsc_d; | |
1545 | u_int ulsc_m2; | |
1546 | int flags; | |
1547 | }; | |
1548 | ||
1549 | struct pf_altq { | |
1550 | char ifname[IFNAMSIZ]; | |
1551 | ||
1552 | void *altq_disc; /* discipline-specific state */ | |
1553 | #if !defined(__LP64__) | |
1554 | u_int32_t _pad; | |
1555 | #endif /* !__LP64__ */ | |
1556 | TAILQ_ENTRY(pf_altq) entries; | |
1557 | #if !defined(__LP64__) | |
1558 | u_int32_t __pad[2]; | |
1559 | #endif /* !__LP64__ */ | |
1560 | ||
1561 | /* scheduler spec */ | |
1562 | u_int8_t scheduler; /* scheduler type */ | |
1563 | u_int16_t tbrsize; /* tokenbucket regulator size */ | |
1564 | u_int32_t ifbandwidth; /* interface bandwidth */ | |
1565 | ||
1566 | /* queue spec */ | |
1567 | char qname[PF_QNAME_SIZE]; /* queue name */ | |
1568 | char parent[PF_QNAME_SIZE]; /* parent name */ | |
1569 | u_int32_t parent_qid; /* parent queue id */ | |
1570 | u_int32_t bandwidth; /* queue bandwidth */ | |
1571 | u_int8_t priority; /* priority */ | |
1572 | u_int16_t qlimit; /* queue size limit */ | |
1573 | u_int16_t flags; /* misc flags */ | |
1574 | union { | |
1575 | struct cbq_opts cbq_opts; | |
1576 | struct priq_opts priq_opts; | |
1577 | struct hfsc_opts hfsc_opts; | |
1578 | } pq_u; | |
1579 | ||
1580 | u_int32_t qid; /* return value */ | |
1581 | }; | |
1582 | ||
1583 | struct pf_tagname { | |
1584 | TAILQ_ENTRY(pf_tagname) entries; | |
1585 | char name[PF_TAG_NAME_SIZE]; | |
1586 | u_int16_t tag; | |
1587 | int ref; | |
1588 | }; | |
1589 | ||
1590 | #define PFFRAG_FRENT_HIWAT 5000 /* Number of fragment entries */ | |
1591 | #define PFFRAG_FRAG_HIWAT 1000 /* Number of fragmented packets */ | |
1592 | #define PFFRAG_FRCENT_HIWAT 50000 /* Number of fragment cache entries */ | |
1593 | #define PFFRAG_FRCACHE_HIWAT 10000 /* Number of fragment descriptors */ | |
1594 | ||
1595 | #define PFR_KTABLE_HIWAT 1000 /* Number of tables */ | |
1596 | #define PFR_KENTRY_HIWAT 200000 /* Number of table entries */ | |
1597 | #define PFR_KENTRY_HIWAT_SMALL 100000 /* Number of table entries (tiny hosts) */ | |
1598 | ||
1599 | /* | |
1600 | * ioctl parameter structures | |
1601 | */ | |
1602 | ||
1603 | struct pfioc_pooladdr { | |
1604 | u_int32_t action; | |
1605 | u_int32_t ticket; | |
1606 | u_int32_t nr; | |
1607 | u_int32_t r_num; | |
1608 | u_int8_t r_action; | |
1609 | u_int8_t r_last; | |
1610 | u_int8_t af; | |
1611 | char anchor[MAXPATHLEN]; | |
1612 | struct pf_pooladdr addr; | |
1613 | }; | |
1614 | ||
1615 | struct pfioc_rule { | |
1616 | u_int32_t action; | |
1617 | u_int32_t ticket; | |
1618 | u_int32_t pool_ticket; | |
1619 | u_int32_t nr; | |
1620 | char anchor[MAXPATHLEN]; | |
1621 | char anchor_call[MAXPATHLEN]; | |
1622 | struct pf_rule rule; | |
1623 | }; | |
1624 | ||
1625 | struct pfioc_natlook { | |
1626 | struct pf_addr saddr; | |
1627 | struct pf_addr daddr; | |
1628 | struct pf_addr rsaddr; | |
1629 | struct pf_addr rdaddr; | |
1630 | #ifndef NO_APPLE_EXTENSIONS | |
1631 | union pf_state_xport sxport; | |
1632 | union pf_state_xport dxport; | |
1633 | union pf_state_xport rsxport; | |
1634 | union pf_state_xport rdxport; | |
1635 | sa_family_t af; | |
1636 | u_int8_t proto; | |
1637 | u_int8_t proto_variant; | |
1638 | u_int8_t direction; | |
1639 | #else | |
1640 | u_int16_t sport; | |
1641 | u_int16_t dport; | |
1642 | u_int16_t rsport; | |
1643 | u_int16_t rdport; | |
1644 | sa_family_t af; | |
1645 | u_int8_t proto; | |
1646 | u_int8_t direction; | |
1647 | #endif | |
1648 | }; | |
1649 | ||
1650 | struct pfioc_state { | |
1651 | struct pfsync_state state; | |
1652 | }; | |
1653 | ||
1654 | struct pfioc_src_node_kill { | |
1655 | /* XXX returns the number of src nodes killed in psnk_af */ | |
1656 | sa_family_t psnk_af; | |
1657 | struct pf_rule_addr psnk_src; | |
1658 | struct pf_rule_addr psnk_dst; | |
1659 | }; | |
1660 | ||
1661 | #ifndef NO_APPLE_EXTENSIONS | |
1662 | struct pfioc_state_addr_kill { | |
1663 | struct pf_addr_wrap addr; | |
1664 | u_int8_t reserved_[3]; | |
1665 | u_int8_t neg; | |
1666 | union pf_rule_xport xport; | |
1667 | }; | |
1668 | #endif | |
1669 | ||
1670 | struct pfioc_state_kill { | |
1671 | /* XXX returns the number of states killed in psk_af */ | |
1672 | sa_family_t psk_af; | |
1673 | #ifndef NO_APPLE_EXTENSIONS | |
1674 | u_int8_t psk_proto; | |
1675 | u_int8_t psk_proto_variant; | |
1676 | u_int8_t _pad; | |
1677 | struct pfioc_state_addr_kill psk_src; | |
1678 | struct pfioc_state_addr_kill psk_dst; | |
1679 | #else | |
1680 | int psk_proto; | |
1681 | struct pf_rule_addr psk_src; | |
1682 | struct pf_rule_addr psk_dst; | |
1683 | #endif | |
1684 | char psk_ifname[IFNAMSIZ]; | |
1685 | }; | |
1686 | ||
1687 | struct pfioc_states { | |
1688 | int ps_len; | |
1689 | union { | |
1690 | caddr_t psu_buf; | |
1691 | struct pfsync_state *psu_states; | |
1692 | } ps_u __attribute__((aligned(8))); | |
1693 | #define ps_buf ps_u.psu_buf | |
1694 | #define ps_states ps_u.psu_states | |
1695 | }; | |
1696 | ||
1697 | struct pfioc_src_nodes { | |
1698 | int psn_len; | |
1699 | union { | |
1700 | caddr_t psu_buf; | |
1701 | struct pf_src_node *psu_src_nodes; | |
1702 | } psn_u __attribute__((aligned(8))); | |
1703 | #define psn_buf psn_u.psu_buf | |
1704 | #define psn_src_nodes psn_u.psu_src_nodes | |
1705 | }; | |
1706 | ||
1707 | struct pfioc_if { | |
1708 | char ifname[IFNAMSIZ]; | |
1709 | }; | |
1710 | ||
1711 | struct pfioc_tm { | |
1712 | int timeout; | |
1713 | int seconds; | |
1714 | }; | |
1715 | ||
1716 | struct pfioc_limit { | |
1717 | int index; | |
1718 | unsigned limit; | |
1719 | }; | |
1720 | ||
1721 | struct pfioc_altq { | |
1722 | u_int32_t action; | |
1723 | u_int32_t ticket; | |
1724 | u_int32_t nr; | |
1725 | struct pf_altq altq __attribute__((aligned(8))); | |
1726 | }; | |
1727 | ||
1728 | struct pfioc_qstats { | |
1729 | u_int32_t ticket; | |
1730 | u_int32_t nr; | |
1731 | void *buf __attribute__((aligned(8))); | |
1732 | int nbytes __attribute__((aligned(8))); | |
1733 | u_int8_t scheduler; | |
1734 | }; | |
1735 | ||
1736 | struct pfioc_ruleset { | |
1737 | u_int32_t nr; | |
1738 | char path[MAXPATHLEN]; | |
1739 | char name[PF_ANCHOR_NAME_SIZE]; | |
1740 | }; | |
1741 | ||
1742 | #define PF_RULESET_ALTQ (PF_RULESET_MAX) | |
1743 | #define PF_RULESET_TABLE (PF_RULESET_MAX+1) | |
1744 | struct pfioc_trans { | |
1745 | int size; /* number of elements */ | |
1746 | int esize; /* size of each element in bytes */ | |
1747 | struct pfioc_trans_e { | |
1748 | int rs_num; | |
1749 | char anchor[MAXPATHLEN]; | |
1750 | u_int32_t ticket; | |
1751 | } *array __attribute__((aligned(8))); | |
1752 | }; | |
1753 | ||
1754 | #define PFR_FLAG_ATOMIC 0x00000001 | |
1755 | #define PFR_FLAG_DUMMY 0x00000002 | |
1756 | #define PFR_FLAG_FEEDBACK 0x00000004 | |
1757 | #define PFR_FLAG_CLSTATS 0x00000008 | |
1758 | #define PFR_FLAG_ADDRSTOO 0x00000010 | |
1759 | #define PFR_FLAG_REPLACE 0x00000020 | |
1760 | #define PFR_FLAG_ALLRSETS 0x00000040 | |
1761 | #define PFR_FLAG_ALLMASK 0x0000007F | |
1762 | #ifdef KERNEL | |
1763 | #define PFR_FLAG_USERIOCTL 0x10000000 | |
1764 | #endif | |
1765 | ||
1766 | struct pfioc_table { | |
1767 | struct pfr_table pfrio_table; | |
1768 | void *pfrio_buffer __attribute__((aligned(8))); | |
1769 | int pfrio_esize __attribute__((aligned(8))); | |
1770 | int pfrio_size; | |
1771 | int pfrio_size2; | |
1772 | int pfrio_nadd; | |
1773 | int pfrio_ndel; | |
1774 | int pfrio_nchange; | |
1775 | int pfrio_flags; | |
1776 | u_int32_t pfrio_ticket; | |
1777 | }; | |
1778 | #define pfrio_exists pfrio_nadd | |
1779 | #define pfrio_nzero pfrio_nadd | |
1780 | #define pfrio_nmatch pfrio_nadd | |
1781 | #define pfrio_naddr pfrio_size2 | |
1782 | #define pfrio_setflag pfrio_size2 | |
1783 | #define pfrio_clrflag pfrio_nadd | |
1784 | ||
1785 | struct pfioc_iface { | |
1786 | char pfiio_name[IFNAMSIZ]; | |
1787 | void *pfiio_buffer __attribute__((aligned(8))); | |
1788 | int pfiio_esize __attribute__((aligned(8))); | |
1789 | int pfiio_size; | |
1790 | int pfiio_nzero; | |
1791 | int pfiio_flags; | |
1792 | }; | |
1793 | ||
1794 | ||
1795 | /* | |
1796 | * ioctl operations | |
1797 | */ | |
1798 | ||
1799 | #define DIOCSTART _IO ('D', 1) | |
1800 | #define DIOCSTOP _IO ('D', 2) | |
1801 | #define DIOCADDRULE _IOWR('D', 4, struct pfioc_rule) | |
1802 | #define DIOCGETRULES _IOWR('D', 6, struct pfioc_rule) | |
1803 | #define DIOCGETRULE _IOWR('D', 7, struct pfioc_rule) | |
1804 | /* XXX cut 8 - 17 */ | |
1805 | #define DIOCCLRSTATES _IOWR('D', 18, struct pfioc_state_kill) | |
1806 | #define DIOCGETSTATE _IOWR('D', 19, struct pfioc_state) | |
1807 | #define DIOCSETSTATUSIF _IOWR('D', 20, struct pfioc_if) | |
1808 | #define DIOCGETSTATUS _IOWR('D', 21, struct pf_status) | |
1809 | #define DIOCCLRSTATUS _IO ('D', 22) | |
1810 | #define DIOCNATLOOK _IOWR('D', 23, struct pfioc_natlook) | |
1811 | #define DIOCSETDEBUG _IOWR('D', 24, u_int32_t) | |
1812 | #define DIOCGETSTATES _IOWR('D', 25, struct pfioc_states) | |
1813 | #define DIOCCHANGERULE _IOWR('D', 26, struct pfioc_rule) | |
1814 | /* XXX cut 26 - 28 */ | |
1815 | #define DIOCSETTIMEOUT _IOWR('D', 29, struct pfioc_tm) | |
1816 | #define DIOCGETTIMEOUT _IOWR('D', 30, struct pfioc_tm) | |
1817 | #define DIOCADDSTATE _IOWR('D', 37, struct pfioc_state) | |
1818 | #define DIOCCLRRULECTRS _IO ('D', 38) | |
1819 | #define DIOCGETLIMIT _IOWR('D', 39, struct pfioc_limit) | |
1820 | #define DIOCSETLIMIT _IOWR('D', 40, struct pfioc_limit) | |
1821 | #define DIOCKILLSTATES _IOWR('D', 41, struct pfioc_state_kill) | |
1822 | #define DIOCSTARTALTQ _IO ('D', 42) | |
1823 | #define DIOCSTOPALTQ _IO ('D', 43) | |
1824 | #define DIOCADDALTQ _IOWR('D', 45, struct pfioc_altq) | |
1825 | #define DIOCGETALTQS _IOWR('D', 47, struct pfioc_altq) | |
1826 | #define DIOCGETALTQ _IOWR('D', 48, struct pfioc_altq) | |
1827 | #define DIOCCHANGEALTQ _IOWR('D', 49, struct pfioc_altq) | |
1828 | #define DIOCGETQSTATS _IOWR('D', 50, struct pfioc_qstats) | |
1829 | #define DIOCBEGINADDRS _IOWR('D', 51, struct pfioc_pooladdr) | |
1830 | #define DIOCADDADDR _IOWR('D', 52, struct pfioc_pooladdr) | |
1831 | #define DIOCGETADDRS _IOWR('D', 53, struct pfioc_pooladdr) | |
1832 | #define DIOCGETADDR _IOWR('D', 54, struct pfioc_pooladdr) | |
1833 | #define DIOCCHANGEADDR _IOWR('D', 55, struct pfioc_pooladdr) | |
1834 | /* XXX cut 55 - 57 */ | |
1835 | #define DIOCGETRULESETS _IOWR('D', 58, struct pfioc_ruleset) | |
1836 | #define DIOCGETRULESET _IOWR('D', 59, struct pfioc_ruleset) | |
1837 | #define DIOCRCLRTABLES _IOWR('D', 60, struct pfioc_table) | |
1838 | #define DIOCRADDTABLES _IOWR('D', 61, struct pfioc_table) | |
1839 | #define DIOCRDELTABLES _IOWR('D', 62, struct pfioc_table) | |
1840 | #define DIOCRGETTABLES _IOWR('D', 63, struct pfioc_table) | |
1841 | #define DIOCRGETTSTATS _IOWR('D', 64, struct pfioc_table) | |
1842 | #define DIOCRCLRTSTATS _IOWR('D', 65, struct pfioc_table) | |
1843 | #define DIOCRCLRADDRS _IOWR('D', 66, struct pfioc_table) | |
1844 | #define DIOCRADDADDRS _IOWR('D', 67, struct pfioc_table) | |
1845 | #define DIOCRDELADDRS _IOWR('D', 68, struct pfioc_table) | |
1846 | #define DIOCRSETADDRS _IOWR('D', 69, struct pfioc_table) | |
1847 | #define DIOCRGETADDRS _IOWR('D', 70, struct pfioc_table) | |
1848 | #define DIOCRGETASTATS _IOWR('D', 71, struct pfioc_table) | |
1849 | #define DIOCRCLRASTATS _IOWR('D', 72, struct pfioc_table) | |
1850 | #define DIOCRTSTADDRS _IOWR('D', 73, struct pfioc_table) | |
1851 | #define DIOCRSETTFLAGS _IOWR('D', 74, struct pfioc_table) | |
1852 | #define DIOCRINADEFINE _IOWR('D', 77, struct pfioc_table) | |
1853 | #define DIOCOSFPFLUSH _IO('D', 78) | |
1854 | #define DIOCOSFPADD _IOWR('D', 79, struct pf_osfp_ioctl) | |
1855 | #define DIOCOSFPGET _IOWR('D', 80, struct pf_osfp_ioctl) | |
1856 | #define DIOCXBEGIN _IOWR('D', 81, struct pfioc_trans) | |
1857 | #define DIOCXCOMMIT _IOWR('D', 82, struct pfioc_trans) | |
1858 | #define DIOCXROLLBACK _IOWR('D', 83, struct pfioc_trans) | |
1859 | #define DIOCGETSRCNODES _IOWR('D', 84, struct pfioc_src_nodes) | |
1860 | #define DIOCCLRSRCNODES _IO('D', 85) | |
1861 | #define DIOCSETHOSTID _IOWR('D', 86, u_int32_t) | |
1862 | #define DIOCIGETIFACES _IOWR('D', 87, struct pfioc_iface) | |
1863 | #define DIOCSETIFFLAG _IOWR('D', 89, struct pfioc_iface) | |
1864 | #define DIOCCLRIFFLAG _IOWR('D', 90, struct pfioc_iface) | |
1865 | #define DIOCKILLSRCNODES _IOWR('D', 91, struct pfioc_src_node_kill) | |
1866 | ||
1867 | #ifdef KERNEL | |
1868 | RB_HEAD(pf_src_tree, pf_src_node); | |
1869 | RB_PROTOTYPE_SC(__private_extern__, pf_src_tree, pf_src_node, entry, | |
1870 | pf_src_compare); | |
1871 | __private_extern__ struct pf_src_tree tree_src_tracking; | |
1872 | ||
1873 | RB_HEAD(pf_state_tree_id, pf_state); | |
1874 | RB_PROTOTYPE_SC(__private_extern__, pf_state_tree_id, pf_state, | |
1875 | entry_id, pf_state_compare_id); | |
1876 | __private_extern__ struct pf_state_tree_id tree_id; | |
1877 | __private_extern__ struct pf_state_queue state_list; | |
1878 | ||
1879 | TAILQ_HEAD(pf_poolqueue, pf_pool); | |
1880 | __private_extern__ struct pf_poolqueue pf_pools[2]; | |
1881 | __private_extern__ struct pf_palist pf_pabuf; | |
1882 | __private_extern__ u_int32_t ticket_pabuf; | |
1883 | #if ALTQ | |
1884 | TAILQ_HEAD(pf_altqqueue, pf_altq); | |
1885 | __private_extern__ struct pf_altqqueue pf_altqs[2]; | |
1886 | __private_extern__ u_int32_t ticket_altqs_active; | |
1887 | __private_extern__ u_int32_t ticket_altqs_inactive; | |
1888 | __private_extern__ int altqs_inactive_open; | |
1889 | __private_extern__ struct pf_altqqueue *pf_altqs_active; | |
1890 | __private_extern__ struct pf_altqqueue *pf_altqs_inactive; | |
1891 | #endif /* ALTQ */ | |
1892 | __private_extern__ struct pf_poolqueue *pf_pools_active; | |
1893 | __private_extern__ struct pf_poolqueue *pf_pools_inactive; | |
1894 | ||
1895 | __private_extern__ int pf_tbladdr_setup(struct pf_ruleset *, | |
1896 | struct pf_addr_wrap *); | |
1897 | __private_extern__ void pf_tbladdr_remove(struct pf_addr_wrap *); | |
1898 | __private_extern__ void pf_tbladdr_copyout(struct pf_addr_wrap *); | |
1899 | __private_extern__ void pf_calc_skip_steps(struct pf_rulequeue *); | |
1900 | ||
1901 | __private_extern__ struct pool pf_src_tree_pl, pf_rule_pl; | |
1902 | __private_extern__ struct pool pf_state_pl, pf_state_key_pl, pf_pooladdr_pl; | |
1903 | __private_extern__ struct pool pf_state_scrub_pl; | |
1904 | #if ALTQ | |
1905 | __private_extern__ struct pool pf_altq_pl; | |
1906 | #endif /* ALTQ */ | |
1907 | #ifndef NO_APPLE_EXTENSIONS | |
1908 | __private_extern__ struct pool pf_app_state_pl; | |
1909 | #endif | |
1910 | ||
1911 | __private_extern__ struct thread *pf_purge_thread; | |
1912 | ||
1913 | __private_extern__ void pfinit(void); | |
1914 | __private_extern__ void pf_purge_thread_fn(void *, wait_result_t); | |
1915 | __private_extern__ void pf_purge_expired_src_nodes(void); | |
1916 | __private_extern__ void pf_purge_expired_states(u_int32_t); | |
1917 | __private_extern__ void pf_unlink_state(struct pf_state *); | |
1918 | __private_extern__ void pf_free_state(struct pf_state *); | |
1919 | __private_extern__ int pf_insert_state(struct pfi_kif *, struct pf_state *); | |
1920 | __private_extern__ int pf_insert_src_node(struct pf_src_node **, | |
1921 | struct pf_rule *, struct pf_addr *, sa_family_t); | |
1922 | __private_extern__ void pf_src_tree_remove_state(struct pf_state *); | |
1923 | __private_extern__ struct pf_state *pf_find_state_byid(struct pf_state_cmp *); | |
1924 | __private_extern__ struct pf_state *pf_find_state_all(struct pf_state_key_cmp *, | |
1925 | u_int, int *); | |
1926 | __private_extern__ void pf_print_state(struct pf_state *); | |
1927 | __private_extern__ void pf_print_flags(u_int8_t); | |
1928 | __private_extern__ u_int16_t pf_cksum_fixup(u_int16_t, u_int16_t, u_int16_t, | |
1929 | u_int8_t); | |
1930 | ||
1931 | __private_extern__ struct ifnet *sync_ifp; | |
1932 | __private_extern__ struct pf_rule pf_default_rule; | |
1933 | __private_extern__ void pf_addrcpy(struct pf_addr *, struct pf_addr *, | |
1934 | u_int8_t); | |
1935 | __private_extern__ void pf_rm_rule(struct pf_rulequeue *, struct pf_rule *); | |
1936 | ||
1937 | #if INET | |
1938 | __private_extern__ int pf_test(int, struct ifnet *, struct mbuf **, | |
1939 | struct ether_header *); | |
1940 | #endif /* INET */ | |
1941 | ||
1942 | #if INET6 | |
1943 | __private_extern__ int pf_test6(int, struct ifnet *, struct mbuf **, | |
1944 | struct ether_header *); | |
1945 | __private_extern__ void pf_poolmask(struct pf_addr *, struct pf_addr *, | |
1946 | struct pf_addr *, struct pf_addr *, u_int8_t); | |
1947 | __private_extern__ void pf_addr_inc(struct pf_addr *, sa_family_t); | |
1948 | #endif /* INET6 */ | |
1949 | ||
1950 | #ifndef NO_APPLE_EXTENSIONS | |
1951 | __private_extern__ struct mbuf *pf_lazy_makewritable(struct pf_pdesc *, | |
1952 | struct mbuf *, int); | |
1953 | #endif | |
1954 | __private_extern__ void *pf_pull_hdr(struct mbuf *, int, void *, int, | |
1955 | u_short *, u_short *, sa_family_t); | |
1956 | __private_extern__ void pf_change_a(void *, u_int16_t *, u_int32_t, u_int8_t); | |
1957 | __private_extern__ int pflog_packet(struct pfi_kif *, struct mbuf *, | |
1958 | sa_family_t, u_int8_t, u_int8_t, struct pf_rule *, struct pf_rule *, | |
1959 | struct pf_ruleset *, struct pf_pdesc *); | |
1960 | __private_extern__ int pf_match_addr(u_int8_t, struct pf_addr *, | |
1961 | struct pf_addr *, struct pf_addr *, sa_family_t); | |
1962 | __private_extern__ int pf_match_addr_range(struct pf_addr *, struct pf_addr *, | |
1963 | struct pf_addr *, sa_family_t); | |
1964 | __private_extern__ int pf_match(u_int8_t, u_int32_t, u_int32_t, u_int32_t); | |
1965 | __private_extern__ int pf_match_port(u_int8_t, u_int16_t, u_int16_t, u_int16_t); | |
1966 | #ifndef NO_APPLE_EXTENSIONS | |
1967 | __private_extern__ int pf_match_xport(u_int8_t, u_int8_t, union pf_rule_xport *, | |
1968 | union pf_state_xport *); | |
1969 | #endif | |
1970 | __private_extern__ int pf_match_uid(u_int8_t, uid_t, uid_t, uid_t); | |
1971 | __private_extern__ int pf_match_gid(u_int8_t, gid_t, gid_t, gid_t); | |
1972 | ||
1973 | __private_extern__ void pf_normalize_init(void); | |
1974 | __private_extern__ int pf_normalize_isempty(void); | |
1975 | __private_extern__ int pf_normalize_ip(struct mbuf **, int, struct pfi_kif *, | |
1976 | u_short *, struct pf_pdesc *); | |
1977 | __private_extern__ int pf_normalize_ip6(struct mbuf **, int, struct pfi_kif *, | |
1978 | u_short *, struct pf_pdesc *); | |
1979 | __private_extern__ int pf_normalize_tcp(int, struct pfi_kif *, struct mbuf *, | |
1980 | int, int, void *, struct pf_pdesc *); | |
1981 | __private_extern__ void pf_normalize_tcp_cleanup(struct pf_state *); | |
1982 | __private_extern__ int pf_normalize_tcp_init(struct mbuf *, int, | |
1983 | struct pf_pdesc *, struct tcphdr *, struct pf_state_peer *, | |
1984 | struct pf_state_peer *); | |
1985 | __private_extern__ int pf_normalize_tcp_stateful(struct mbuf *, int, | |
1986 | struct pf_pdesc *, u_short *, struct tcphdr *, struct pf_state *, | |
1987 | struct pf_state_peer *, struct pf_state_peer *, int *); | |
1988 | __private_extern__ u_int64_t pf_state_expires(const struct pf_state *); | |
1989 | __private_extern__ void pf_purge_expired_fragments(void); | |
1990 | __private_extern__ int pf_routable(struct pf_addr *addr, sa_family_t af, | |
1991 | struct pfi_kif *); | |
1992 | __private_extern__ int pf_rtlabel_match(struct pf_addr *, sa_family_t, | |
1993 | struct pf_addr_wrap *); | |
1994 | __private_extern__ int pf_socket_lookup(int, struct pf_pdesc *); | |
1995 | __private_extern__ struct pf_state_key *pf_alloc_state_key(struct pf_state *); | |
1996 | __private_extern__ void pfr_initialize(void); | |
1997 | __private_extern__ int pfr_match_addr(struct pfr_ktable *, struct pf_addr *, | |
1998 | sa_family_t); | |
1999 | __private_extern__ void pfr_update_stats(struct pfr_ktable *, struct pf_addr *, | |
2000 | sa_family_t, u_int64_t, int, int, int); | |
2001 | __private_extern__ int pfr_pool_get(struct pfr_ktable *, int *, | |
2002 | struct pf_addr *, struct pf_addr **, struct pf_addr **, sa_family_t); | |
2003 | __private_extern__ void pfr_dynaddr_update(struct pfr_ktable *, | |
2004 | struct pfi_dynaddr *); | |
2005 | __private_extern__ struct pfr_ktable *pfr_attach_table(struct pf_ruleset *, | |
2006 | char *); | |
2007 | __private_extern__ void pfr_detach_table(struct pfr_ktable *); | |
2008 | __private_extern__ int pfr_clr_tables(struct pfr_table *, int *, int); | |
2009 | __private_extern__ int pfr_add_tables(struct pfr_table *, int, int *, int); | |
2010 | __private_extern__ int pfr_del_tables(struct pfr_table *, int, int *, int); | |
2011 | __private_extern__ int pfr_get_tables(struct pfr_table *, struct pfr_table *, | |
2012 | int *, int); | |
2013 | __private_extern__ int pfr_get_tstats(struct pfr_table *, struct pfr_tstats *, | |
2014 | int *, int); | |
2015 | __private_extern__ int pfr_clr_tstats(struct pfr_table *, int, int *, int); | |
2016 | __private_extern__ int pfr_set_tflags(struct pfr_table *, int, int, int, int *, | |
2017 | int *, int); | |
2018 | __private_extern__ int pfr_clr_addrs(struct pfr_table *, int *, int); | |
2019 | __private_extern__ int pfr_insert_kentry(struct pfr_ktable *, struct pfr_addr *, | |
2020 | u_int64_t); | |
2021 | __private_extern__ int pfr_add_addrs(struct pfr_table *, struct pfr_addr *, | |
2022 | int, int *, int); | |
2023 | __private_extern__ int pfr_del_addrs(struct pfr_table *, struct pfr_addr *, | |
2024 | int, int *, int); | |
2025 | __private_extern__ int pfr_set_addrs(struct pfr_table *, struct pfr_addr *, | |
2026 | int, int *, int *, int *, int *, int, u_int32_t); | |
2027 | __private_extern__ int pfr_get_addrs(struct pfr_table *, struct pfr_addr *, | |
2028 | int *, int); | |
2029 | __private_extern__ int pfr_get_astats(struct pfr_table *, struct pfr_astats *, | |
2030 | int *, int); | |
2031 | __private_extern__ int pfr_clr_astats(struct pfr_table *, struct pfr_addr *, | |
2032 | int, int *, int); | |
2033 | __private_extern__ int pfr_tst_addrs(struct pfr_table *, struct pfr_addr *, | |
2034 | int, int *, int); | |
2035 | __private_extern__ int pfr_ina_begin(struct pfr_table *, u_int32_t *, int *, | |
2036 | int); | |
2037 | __private_extern__ int pfr_ina_rollback(struct pfr_table *, u_int32_t, int *, | |
2038 | int); | |
2039 | __private_extern__ int pfr_ina_commit(struct pfr_table *, u_int32_t, int *, | |
2040 | int *, int); | |
2041 | __private_extern__ int pfr_ina_define(struct pfr_table *, struct pfr_addr *, | |
2042 | int, int *, int *, u_int32_t, int); | |
2043 | ||
2044 | __private_extern__ struct pfi_kif *pfi_all; | |
2045 | ||
2046 | __private_extern__ void pfi_initialize(void); | |
2047 | __private_extern__ struct pfi_kif *pfi_kif_get(const char *); | |
2048 | __private_extern__ void pfi_kif_ref(struct pfi_kif *, enum pfi_kif_refs); | |
2049 | __private_extern__ void pfi_kif_unref(struct pfi_kif *, enum pfi_kif_refs); | |
2050 | __private_extern__ int pfi_kif_match(struct pfi_kif *, struct pfi_kif *); | |
2051 | __private_extern__ void pfi_attach_ifnet(struct ifnet *); | |
2052 | __private_extern__ void pfi_detach_ifnet(struct ifnet *); | |
2053 | __private_extern__ int pfi_match_addr(struct pfi_dynaddr *, struct pf_addr *, | |
2054 | sa_family_t); | |
2055 | __private_extern__ int pfi_dynaddr_setup(struct pf_addr_wrap *, sa_family_t); | |
2056 | __private_extern__ void pfi_dynaddr_remove(struct pf_addr_wrap *); | |
2057 | __private_extern__ void pfi_dynaddr_copyout(struct pf_addr_wrap *); | |
2058 | __private_extern__ void pfi_update_status(const char *, struct pf_status *); | |
2059 | __private_extern__ int pfi_get_ifaces(const char *, struct pfi_kif *, int *); | |
2060 | __private_extern__ int pfi_set_flags(const char *, int); | |
2061 | __private_extern__ int pfi_clear_flags(const char *, int); | |
2062 | ||
2063 | __private_extern__ u_int16_t pf_tagname2tag(char *); | |
2064 | __private_extern__ void pf_tag2tagname(u_int16_t, char *); | |
2065 | __private_extern__ void pf_tag_ref(u_int16_t); | |
2066 | __private_extern__ void pf_tag_unref(u_int16_t); | |
2067 | __private_extern__ int pf_tag_packet(struct mbuf *, struct pf_mtag *, | |
2068 | int, unsigned int); | |
2069 | __private_extern__ u_int32_t pf_qname2qid(char *); | |
2070 | __private_extern__ void pf_qid2qname(u_int32_t, char *); | |
2071 | __private_extern__ void pf_qid_unref(u_int32_t); | |
2072 | ||
2073 | __private_extern__ struct pf_status pf_status; | |
2074 | __private_extern__ struct pool pf_frent_pl, pf_frag_pl; | |
2075 | ||
2076 | struct pf_pool_limit { | |
2077 | void *pp; | |
2078 | unsigned limit; | |
2079 | }; | |
2080 | __private_extern__ struct pf_pool_limit pf_pool_limits[PF_LIMIT_MAX]; | |
2081 | ||
2082 | __private_extern__ int pf_af_hook(struct ifnet *, struct mbuf **, | |
2083 | struct mbuf **, unsigned int, int); | |
2084 | __private_extern__ int pf_ifaddr_hook(struct ifnet *, unsigned long); | |
2085 | __private_extern__ void pf_ifnet_hook(struct ifnet *, int); | |
2086 | ||
2087 | /* | |
2088 | * The following are defined with "private extern" storage class for | |
2089 | * kernel, and "extern" for user-space. | |
2090 | */ | |
2091 | __private_extern__ struct pf_anchor_global pf_anchors; | |
2092 | __private_extern__ struct pf_anchor pf_main_anchor; | |
2093 | #define pf_main_ruleset pf_main_anchor.ruleset | |
2094 | ||
2095 | /* these ruleset functions can be linked into userland programs (pfctl) */ | |
2096 | __private_extern__ int pf_get_ruleset_number(u_int8_t); | |
2097 | __private_extern__ void pf_init_ruleset(struct pf_ruleset *); | |
2098 | __private_extern__ int pf_anchor_setup(struct pf_rule *, | |
2099 | const struct pf_ruleset *, const char *); | |
2100 | __private_extern__ int pf_anchor_copyout(const struct pf_ruleset *, | |
2101 | const struct pf_rule *, struct pfioc_rule *); | |
2102 | __private_extern__ void pf_anchor_remove(struct pf_rule *); | |
2103 | __private_extern__ void pf_remove_if_empty_ruleset(struct pf_ruleset *); | |
2104 | __private_extern__ struct pf_anchor *pf_find_anchor(const char *); | |
2105 | __private_extern__ struct pf_ruleset *pf_find_ruleset(const char *); | |
2106 | __private_extern__ struct pf_ruleset *pf_find_or_create_ruleset(const char *); | |
2107 | __private_extern__ void pf_rs_initialize(void); | |
2108 | ||
2109 | __private_extern__ int pf_osfp_add(struct pf_osfp_ioctl *); | |
2110 | __private_extern__ struct pf_osfp_enlist *pf_osfp_fingerprint(struct pf_pdesc *, | |
2111 | struct mbuf *, int, const struct tcphdr *); | |
2112 | __private_extern__ struct pf_osfp_enlist *pf_osfp_fingerprint_hdr( | |
2113 | const struct ip *, const struct ip6_hdr *, const struct tcphdr *); | |
2114 | __private_extern__ void pf_osfp_flush(void); | |
2115 | __private_extern__ int pf_osfp_get(struct pf_osfp_ioctl *); | |
2116 | __private_extern__ void pf_osfp_initialize(void); | |
2117 | __private_extern__ int pf_osfp_match(struct pf_osfp_enlist *, pf_osfp_t); | |
2118 | __private_extern__ struct pf_os_fingerprint *pf_osfp_validate(void); | |
2119 | #else /* !KERNEL */ | |
2120 | extern struct pf_anchor_global pf_anchors; | |
2121 | extern struct pf_anchor pf_main_anchor; | |
2122 | #define pf_main_ruleset pf_main_anchor.ruleset | |
2123 | ||
2124 | /* these ruleset functions can be linked into userland programs (pfctl) */ | |
2125 | extern int pf_get_ruleset_number(u_int8_t); | |
2126 | extern void pf_init_ruleset(struct pf_ruleset *); | |
2127 | extern int pf_anchor_setup(struct pf_rule *, const struct pf_ruleset *, | |
2128 | const char *); | |
2129 | extern int pf_anchor_copyout(const struct pf_ruleset *, const struct pf_rule *, | |
2130 | struct pfioc_rule *); | |
2131 | extern void pf_anchor_remove(struct pf_rule *); | |
2132 | extern void pf_remove_if_empty_ruleset(struct pf_ruleset *); | |
2133 | extern struct pf_anchor *pf_find_anchor(const char *); | |
2134 | extern struct pf_ruleset *pf_find_ruleset(const char *); | |
2135 | extern struct pf_ruleset *pf_find_or_create_ruleset(const char *); | |
2136 | extern void pf_rs_initialize(void); | |
2137 | #endif /* !KERNEL */ | |
2138 | ||
2139 | #ifdef __cplusplus | |
2140 | } | |
2141 | #endif | |
2142 | #endif /* PF || !KERNEL */ | |
2143 | #endif /* PRIVATE */ | |
2144 | #endif /* _NET_PFVAR_H_ */ |