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