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