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