xref: /freebsd/lib/libpfctl/libpfctl.h (revision a5b1b2d2c5e585364809fdf8f165d6dc742faadb)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2021 Rubicon Communications, LLC (Netgate)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  *    - Redistributions of source code must retain the above copyright
12  *      notice, this list of conditions and the following disclaimer.
13  *    - Redistributions in binary form must reproduce the above
14  *      copyright notice, this list of conditions and the following
15  *      disclaimer in the documentation and/or other materials provided
16  *      with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _PFCTL_IOCTL_H_
33 #define _PFCTL_IOCTL_H_
34 
35 #include <netpfil/pf/pf.h>
36 
37 struct pfctl_anchor;
38 struct pfctl_eth_anchor;
39 
40 struct pfctl_status_counter {
41 	uint64_t	 id;
42 	uint64_t	 counter;
43 	char		*name;
44 
45 	TAILQ_ENTRY(pfctl_status_counter) entry;
46 };
47 TAILQ_HEAD(pfctl_status_counters, pfctl_status_counter);
48 
49 struct pfctl_status {
50 	bool		running;
51 	uint32_t	since;
52 	uint32_t	debug;
53 	uint32_t	hostid;
54 	uint64_t	states;
55 	uint64_t	src_nodes;
56 	char		ifname[IFNAMSIZ];
57 	uint8_t		pf_chksum[PF_MD5_DIGEST_LENGTH];
58 	bool		syncookies_active;
59 	uint32_t	reass;
60 
61 	struct pfctl_status_counters	 counters;
62 	struct pfctl_status_counters	 lcounters;
63 	struct pfctl_status_counters	 fcounters;
64 	struct pfctl_status_counters	 scounters;
65 	struct pfctl_status_counters	 ncounters;
66 	uint64_t	fragments;
67 	uint64_t	pcounters[2][2][2];
68 	uint64_t	bcounters[2][2];
69 };
70 
71 struct pfctl_eth_rulesets_info {
72 	uint32_t	nr;
73 };
74 
75 struct pfctl_eth_rules_info {
76 	uint32_t	nr;
77 	uint32_t	ticket;
78 };
79 
80 struct pfctl_eth_addr {
81 	uint8_t	addr[ETHER_ADDR_LEN];
82 	uint8_t	mask[ETHER_ADDR_LEN];
83 	bool	neg;
84 	bool	isset;
85 };
86 
87 struct pfctl_eth_rule {
88 	uint32_t		 nr;
89 
90 	char			label[PF_RULE_MAX_LABEL_COUNT][PF_RULE_LABEL_SIZE];
91 	uint32_t		ridentifier;
92 
93 	bool			 quick;
94 
95 	/* Filter */
96 	char			 ifname[IFNAMSIZ];
97 	uint8_t			 ifnot;
98 	uint8_t			 direction;
99 	uint16_t		 proto;
100 	struct pfctl_eth_addr	 src, dst;
101 	struct pf_rule_addr	 ipsrc, ipdst;
102 	char			 match_tagname[PF_TAG_NAME_SIZE];
103 	uint16_t		 match_tag;
104 	bool			 match_tag_not;
105 
106 	/* Stats */
107 	uint64_t		 evaluations;
108 	uint64_t		 packets[2];
109 	uint64_t		 bytes[2];
110 	time_t			 last_active_timestamp;
111 
112 	/* Action */
113 	char			 qname[PF_QNAME_SIZE];
114 	char			 tagname[PF_TAG_NAME_SIZE];
115 	uint16_t		 dnpipe;
116 	uint32_t		 dnflags;
117 	char			 bridge_to[IFNAMSIZ];
118 	uint8_t			 action;
119 
120 	struct pfctl_eth_anchor	*anchor;
121 	uint8_t			 anchor_relative;
122 	uint8_t			 anchor_wildcard;
123 
124 	TAILQ_ENTRY(pfctl_eth_rule)	 entries;
125 };
126 TAILQ_HEAD(pfctl_eth_rules, pfctl_eth_rule);
127 
128 struct pfctl_eth_ruleset_info {
129 	uint32_t	nr;
130 	char		name[PF_ANCHOR_NAME_SIZE];
131 	char		path[MAXPATHLEN];
132 };
133 
134 struct pfctl_eth_ruleset {
135 	struct pfctl_eth_rules	 rules;
136 	struct pfctl_eth_anchor	*anchor;
137 };
138 
139 struct pfctl_eth_anchor {
140 	struct pfctl_eth_anchor		*parent;
141 	char				 name[PF_ANCHOR_NAME_SIZE];
142 	char				 path[MAXPATHLEN];
143 	struct pfctl_eth_ruleset	 ruleset;
144 	int				 refcnt;	/* anchor rules */
145 	int				 match;	/* XXX: used for pfctl black magic */
146 };
147 
148 struct pfctl_pooladdr {
149 	struct pf_addr_wrap		 addr;
150 	TAILQ_ENTRY(pfctl_pooladdr)	 entries;
151 	char				 ifname[IFNAMSIZ];
152 	sa_family_t		 	 af;
153 };
154 
155 TAILQ_HEAD(pfctl_palist, pfctl_pooladdr);
156 
157 struct pfctl_pool {
158 	struct pfctl_palist	 list;
159 	struct pfctl_pooladdr	*cur;
160 	struct pf_poolhashkey	 key;
161 	struct pf_addr		 counter;
162 	struct pf_mape_portset	 mape;
163 	int			 tblidx;
164 	uint16_t		 proxy_port[2];
165 	uint8_t			 opts;
166 };
167 
168 struct pfctl_rules_info {
169 	uint32_t	nr;
170 	uint32_t	ticket;
171 };
172 
173 struct pfctl_threshold {
174 	uint32_t		limit;
175 	uint32_t		seconds;
176 	uint32_t		count;
177 	uint32_t		last;
178 };
179 
180 struct pfctl_rule {
181 	struct pf_rule_addr	 src;
182 	struct pf_rule_addr	 dst;
183 	union pf_rule_ptr	 skip[PF_SKIP_COUNT];
184 	char			 label[PF_RULE_MAX_LABEL_COUNT][PF_RULE_LABEL_SIZE];
185 	uint32_t		 ridentifier;
186 	char			 ifname[IFNAMSIZ];
187 	char			 qname[PF_QNAME_SIZE];
188 	char			 pqname[PF_QNAME_SIZE];
189 	char			 tagname[PF_TAG_NAME_SIZE];
190 	char			 match_tagname[PF_TAG_NAME_SIZE];
191 
192 	char			 overload_tblname[PF_TABLE_NAME_SIZE];
193 
194 	TAILQ_ENTRY(pfctl_rule)	 entries;
195 	struct pfctl_pool	 nat;
196 	union {
197 		/* Alias old and new names. */
198 		struct pfctl_pool	 rpool;
199 		struct pfctl_pool	 rdr;
200 	};
201 	struct pfctl_pool	 route;
202 	struct pfctl_threshold	 pktrate;
203 
204 	uint64_t		 evaluations;
205 	uint64_t		 packets[2];
206 	uint64_t		 bytes[2];
207 	time_t			 last_active_timestamp;
208 
209 	struct pfi_kif		*kif;
210 	struct pfctl_anchor	*anchor;
211 	struct pfr_ktable	*overload_tbl;
212 
213 	pf_osfp_t		 os_fingerprint;
214 
215 	int			 rtableid;
216 	uint32_t		 timeout[PFTM_MAX];
217 	uint32_t		 max_states;
218 	uint32_t		 max_src_nodes;
219 	uint32_t		 max_src_states;
220 	uint32_t		 max_src_conn;
221 	struct {
222 		uint32_t		limit;
223 		uint32_t		seconds;
224 	}			 max_src_conn_rate;
225 	uint16_t		 max_pkt_size;
226 	uint32_t		 qid;
227 	uint32_t		 pqid;
228 	uint16_t		 dnpipe;
229 	uint16_t		 dnrpipe;
230 	uint32_t		 free_flags;
231 	uint32_t		 nr;
232 	uint32_t		 prob;
233 	uid_t			 cuid;
234 	pid_t			 cpid;
235 
236 	uint64_t		 states_cur;
237 	uint64_t		 states_tot;
238 	uint64_t		 src_nodes;
239 	uint64_t		 src_nodes_type[PF_SN_MAX];
240 
241 	uint16_t		 return_icmp;
242 	uint16_t		 return_icmp6;
243 	uint16_t		 max_mss;
244 	uint16_t		 tag;
245 	uint16_t		 match_tag;
246 	uint16_t		 scrub_flags;
247 
248 	struct pf_rule_uid	 uid;
249 	struct pf_rule_gid	 gid;
250 	char			 rcv_ifname[IFNAMSIZ];
251 	bool			 rcvifnot;
252 	struct {
253 		uint8_t		 id;
254 		int		 limiter_action;
255 	}			 statelim;
256 	struct {
257 		uint8_t		 id;
258 		int		 limiter_action;
259 	}			 sourcelim;
260 
261 	uint32_t		 rule_flag;
262 	uint8_t			 action;
263 	uint8_t			 direction;
264 	uint8_t			 log;
265 	uint8_t			 logif;
266 	uint8_t			 quick;
267 	uint8_t			 ifnot;
268 	uint8_t			 match_tag_not;
269 	uint8_t			 natpass;
270 
271 	uint8_t			 keep_state;
272 	sa_family_t		 af;
273 	uint8_t			 proto;
274 	uint16_t		 type;
275 	uint16_t		 code;
276 	uint8_t			 flags;
277 	uint8_t			 flagset;
278 	uint8_t			 min_ttl;
279 	uint8_t			 allow_opts;
280 	uint8_t			 rt;
281 	uint8_t			 return_ttl;
282 	uint8_t			 tos;
283 	uint8_t			 set_tos;
284 	uint8_t			 anchor_relative;
285 	uint8_t			 anchor_wildcard;
286 
287 	uint8_t			 flush;
288 	uint8_t			 prio;
289 	uint8_t			 set_prio[2];
290 	sa_family_t		 naf;
291 
292 	struct {
293 		struct pf_addr		addr;
294 		uint16_t		port;
295 	}			divert;
296 
297 	time_t			exptime;
298 };
299 
300 TAILQ_HEAD(pfctl_rulequeue, pfctl_rule);
301 
302 struct pfctl_ruleset {
303 	struct {
304 		struct pfctl_rulequeue	 queues[2];
305 		struct {
306 			struct pfctl_rulequeue	*ptr;
307 			struct pfctl_rule	**ptr_array;
308 			uint32_t		 rcount;
309 			uint32_t		 ticket;
310 			int			 open;
311 		}			 active, inactive;
312 	}			 rules[PF_RULESET_MAX];
313 	struct pfctl_anchor	*anchor;
314 	uint32_t		 tticket;
315 	int			 tables;
316 	int			 topen;
317 };
318 
319 RB_HEAD(pfctl_anchor_global, pfctl_anchor);
320 RB_HEAD(pfctl_anchor_node, pfctl_anchor);
321 struct pfctl_anchor {
322 	RB_ENTRY(pfctl_anchor)	 entry_global;
323 	RB_ENTRY(pfctl_anchor)	 entry_node;
324 	struct pfctl_anchor	*parent;
325 	struct pfctl_anchor_node children;
326 	char			 name[PF_ANCHOR_NAME_SIZE];
327 	char			 path[MAXPATHLEN];
328 	struct pfctl_ruleset	 ruleset;
329 	int			 refcnt;	/* anchor rules */
330 	int			 match;	/* XXX: used for pfctl black magic */
331 };
332 RB_PROTOTYPE(pfctl_anchor_global, pfctl_anchor, entry_global,
333     pf_anchor_compare);
334 RB_PROTOTYPE(pfctl_anchor_node, pfctl_anchor, entry_node,
335     pf_anchor_compare);
336 
337 struct pfctl_state_cmp {
338 	uint64_t	id;
339 	uint32_t	creatorid;
340 	uint8_t		direction;
341 };
342 
343 struct pfctl_kill {
344 	struct pfctl_state_cmp	cmp;
345 	sa_family_t		af;
346 	int			proto;
347 	struct pf_rule_addr	src;
348 	struct pf_rule_addr	dst;
349 	struct pf_rule_addr	rt_addr;
350 	char			ifname[IFNAMSIZ];
351 	char			label[PF_RULE_LABEL_SIZE];
352 	bool			kill_match;
353 	bool			nat;
354 };
355 
356 struct pfctl_state_peer {
357 	uint32_t			 seqlo;
358 	uint32_t			 seqhi;
359 	uint32_t			 seqdiff;
360 	uint8_t				 state;
361 	uint8_t				 wscale;
362 };
363 
364 struct pfctl_state_key {
365 	struct pf_addr	 addr[2];
366 	uint16_t	 port[2];
367 	sa_family_t	 af;
368 	uint8_t	 	 proto;
369 };
370 
371 struct pfctl_state {
372 	uint64_t		 id;
373 	uint32_t		 creatorid;
374 	uint8_t		 	 direction;
375 
376 	struct pfctl_state_peer	 src;
377 	struct pfctl_state_peer	 dst;
378 
379 	uint32_t		 rule;
380 	uint32_t		 anchor;
381 	uint32_t		 nat_rule;
382 	struct pf_addr		 rt_addr;
383 	struct pfctl_state_key	 key[2];	/* addresses stack and wire  */
384 	char			 ifname[IFNAMSIZ];
385 	char			 orig_ifname[IFNAMSIZ];
386 	uint64_t		 packets[2];
387 	uint64_t		 bytes[2];
388 	uint32_t		 creation;
389 	uint32_t		 expire;
390 	uint32_t		 pfsync_time;
391 	uint16_t		 state_flags;
392 	uint32_t		 sync_flags;
393 	uint16_t		 qid;
394 	uint16_t		 pqid;
395 	uint16_t		 dnpipe;
396 	uint16_t		 dnrpipe;
397 	uint8_t			 log;
398 	int32_t			 rtableid;
399 	uint8_t			 min_ttl;
400 	uint8_t			 set_tos;
401 	uint16_t		 max_mss;
402 	uint8_t			 set_prio[2];
403 	uint8_t			 rt;
404 	char			 rt_ifname[IFNAMSIZ];
405 	sa_family_t		 rt_af;
406 	uint8_t			 src_node_flags;
407 	struct pfctl_rule	 created_by_rule;
408 };
409 
410 enum pfctl_syncookies_mode {
411 	PFCTL_SYNCOOKIES_NEVER,
412 	PFCTL_SYNCOOKIES_ALWAYS,
413 	PFCTL_SYNCOOKIES_ADAPTIVE
414 };
415 extern const char* PFCTL_SYNCOOKIES_MODE_NAMES[];
416 
417 struct pfctl_syncookies {
418 	enum pfctl_syncookies_mode	mode;
419 	uint8_t				highwater;	/* Percent */
420 	uint8_t				lowwater;	/* Percent */
421 	uint32_t			halfopen_states;
422 };
423 
424 struct pfctl_src_node {
425 	struct pf_addr		addr;
426 	struct pf_addr		raddr;
427 	int			rule;
428 	uint64_t		bytes[2];
429 	uint64_t		packets[2];
430 	uint32_t		states;
431 	uint32_t		conn;
432 	sa_family_t		af;
433 	sa_family_t		raf;
434 	uint8_t			ruletype;
435 	uint64_t		creation;
436 	uint64_t		expire;
437 	struct pfctl_threshold	conn_rate;
438 	pf_sn_types_t		type;
439 };
440 
441 #define	PF_DEVICE	"/dev/pf"
442 
443 struct pfctl_handle;
444 struct pfctl_handle	*pfctl_open(const char *pf_device);
445 void	pfctl_close(struct pfctl_handle *);
446 int	pfctl_fd(struct pfctl_handle *);
447 
448 int	pfctl_startstop(struct pfctl_handle *h, int start);
449 struct pfctl_status* pfctl_get_status_h(struct pfctl_handle *h);
450 struct pfctl_status* pfctl_get_status(int dev);
451 int	pfctl_clear_status(struct pfctl_handle *h);
452 uint64_t pfctl_status_counter(struct pfctl_status *status, int id);
453 uint64_t pfctl_status_lcounter(struct pfctl_status *status, int id);
454 uint64_t pfctl_status_fcounter(struct pfctl_status *status, int id);
455 uint64_t pfctl_status_scounter(struct pfctl_status *status, int id);
456 void	pfctl_free_status(struct pfctl_status *status);
457 
458 int	pfctl_get_eth_rulesets_info(int dev,
459 	    struct pfctl_eth_rulesets_info *ri, const char *path);
460 int	pfctl_get_eth_ruleset(int dev, const char *path, int nr,
461 	    struct pfctl_eth_ruleset_info *ri);
462 int	pfctl_get_eth_rules_info(int dev, struct pfctl_eth_rules_info *rules,
463 	    const char *path);
464 int	pfctl_get_eth_rule(int dev, uint32_t nr, uint32_t ticket,
465 	    const char *path, struct pfctl_eth_rule *rule, bool clear,
466 	    char *anchor_call);
467 int	pfctl_add_eth_rule(int dev, const struct pfctl_eth_rule *r,
468 	    const char *anchor, const char *anchor_call, uint32_t ticket);
469 int	pfctl_get_rules_info_h(struct pfctl_handle *h,
470 	    struct pfctl_rules_info *rules, uint32_t ruleset,
471 	    const char *path);
472 int	pfctl_get_rules_info(int dev, struct pfctl_rules_info *rules,
473 	    uint32_t ruleset, const char *path);
474 int	pfctl_get_rule(int dev, uint32_t nr, uint32_t ticket,
475 	    const char *anchor, uint32_t ruleset, struct pfctl_rule *rule,
476 	    char *anchor_call);
477 int	pfctl_get_rule_h(struct pfctl_handle *h, uint32_t nr, uint32_t ticket,
478 	    const char *anchor, uint32_t ruleset, struct pfctl_rule *rule,
479 	    char *anchor_call);
480 int	pfctl_get_clear_rule(int dev, uint32_t nr, uint32_t ticket,
481 	    const char *anchor, uint32_t ruleset, struct pfctl_rule *rule,
482 	    char *anchor_call, bool clear);
483 int	pfctl_get_clear_rule_h(struct pfctl_handle *h, uint32_t nr, uint32_t ticket,
484 	    const char *anchor, uint32_t ruleset, struct pfctl_rule *rule,
485 	    char *anchor_call, bool clear);
486 int	pfctl_add_rule(int dev, const struct pfctl_rule *r,
487 	    const char *anchor, const char *anchor_call, uint32_t ticket,
488 	    uint32_t pool_ticket);
489 int	pfctl_add_rule_h(struct pfctl_handle *h, const struct pfctl_rule *r,
490 	    const char *anchor, const char *anchor_call, uint32_t ticket,
491 	    uint32_t pool_ticket);
492 int	pfctl_set_keepcounters(int dev, bool keep);
493 int	pfctl_get_creatorids(struct pfctl_handle *h, uint32_t *creators, size_t *len);
494 
495 struct pfctl_state_filter {
496 	char			ifname[IFNAMSIZ];
497 	uint16_t		proto;
498 	sa_family_t		af;
499 	struct pf_addr		addr;
500 	struct pf_addr		mask;
501 	bool			include_rule;
502 };
503 typedef int (*pfctl_get_state_fn)(struct pfctl_state *, void *);
504 int pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg);
505 int	pfctl_clear_states(int dev, const struct pfctl_kill *kill,
506 	    unsigned int *killed);
507 int	pfctl_kill_states(int dev, const struct pfctl_kill *kill,
508 	    unsigned int *killed);
509 int	pfctl_clear_states_h(struct pfctl_handle *h, const struct pfctl_kill *kill,
510 	    unsigned int *killed);
511 int	pfctl_kill_states_h(struct pfctl_handle *h, const struct pfctl_kill *kill,
512 	    unsigned int *killed);
513 int	pfctl_clear_rules(int dev, const char *anchorname);
514 int	pfctl_clear_nat(int dev, const char *anchorname);
515 int	pfctl_clear_eth_rules(int dev, const char *anchorname);
516 int	pfctl_set_syncookies(int dev, const struct pfctl_syncookies *s);
517 int	pfctl_get_syncookies(int dev, struct pfctl_syncookies *s);
518 int	pfctl_table_add_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr
519 	    *addr, int size, int *nadd, int flags);
520 int	pfctl_table_add_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
521 	    *addr, int size, int *nadd, int flags);
522 int	pfctl_table_del_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
523 	    struct pfr_addr *addr, int size, int *ndel, int flags);
524 int	pfctl_table_del_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
525 	    *addr, int size, int *ndel, int flags);
526 int	pfctl_table_set_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
527 	    struct pfr_addr *addr, int size, int *nadd, int *ndel,
528 	    int *nchange, int flags);
529 int	pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
530 	    *addr, int size, int *size2, int *nadd, int *ndel, int *nchange,
531 	    int flags);
532 int	pfctl_table_get_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr *addr,
533 	    int *size, int flags);
534 int	pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
535 	    *addr, int *size, int flags);
536 int	pfctl_set_statusif(struct pfctl_handle *h, const char *ifname);
537 
538 struct pfctl_natlook_key {
539 	sa_family_t af;
540 	uint8_t direction;
541 	uint8_t proto;
542 	struct pf_addr saddr;
543 	struct pf_addr daddr;
544 	uint16_t sport;
545 	uint16_t dport;
546 };
547 struct pfctl_natlook {
548 	struct pf_addr saddr;
549 	struct pf_addr daddr;
550 	uint16_t sport;
551 	uint16_t dport;
552 };
553 int	pfctl_natlook(struct pfctl_handle *h,
554 	    const struct pfctl_natlook_key *k, struct pfctl_natlook *r);
555 int	pfctl_set_debug(struct pfctl_handle *h, uint32_t level);
556 int	pfctl_set_timeout(struct pfctl_handle *h, uint32_t timeout, uint32_t seconds);
557 int	pfctl_get_timeout(struct pfctl_handle *h, uint32_t timeout, uint32_t *seconds);
558 int	pfctl_set_limit(struct pfctl_handle *h, const int index, const uint limit);
559 int	pfctl_get_limit(struct pfctl_handle *h, const int index, uint *limit);
560 int	pfctl_begin_addrs(struct pfctl_handle *h, uint32_t *ticket);
561 int	pfctl_add_addr(struct pfctl_handle *h, const struct pfioc_pooladdr *pa, int which);
562 int	pfctl_get_addrs(struct pfctl_handle *h, uint32_t ticket, uint32_t r_num,
563 	    uint8_t r_action, const char *anchor, uint32_t *nr, int which);
564 int	pfctl_get_addr(struct pfctl_handle *h, uint32_t ticket, uint32_t r_num,
565 	    uint8_t r_action, const char *anchor, uint32_t nr, struct pfioc_pooladdr *pa,
566 	    int which);
567 int	pfctl_get_rulesets(struct pfctl_handle *h, const char *path, uint32_t *nr);
568 int	pfctl_get_ruleset(struct pfctl_handle *h, const char *path, uint32_t nr, struct pfioc_ruleset *rs);
569 typedef int (*pfctl_get_srcnode_fn)(struct pfctl_src_node*, void *);
570 int	pfctl_get_srcnodes(struct pfctl_handle *h, pfctl_get_srcnode_fn fn, void *arg);
571 
572 int	pfctl_clear_tables(struct pfctl_handle *h, struct pfr_table *filter,
573 	    int *ndel, int flags);
574 int	pfctl_add_table(struct pfctl_handle *h, struct pfr_table *table,
575 	    int *nadd, int flags);
576 int	pfctl_del_table(struct pfctl_handle *h, struct pfr_table *table,
577 	    int *ndel, int flags);
578 
579 typedef int (*pfctl_get_tstats_fn)(const struct pfr_tstats *t, void *arg);
580 int	pfctl_get_tstats(struct pfctl_handle *h, const struct pfr_table *filter,
581 	    pfctl_get_tstats_fn fn, void *arg);
582 int	pfctl_clear_tstats(struct pfctl_handle *h, const struct pfr_table *filter,
583 	    int *nzero, int flags);
584 int	pfctl_clear_addrs(struct pfctl_handle *h, const struct pfr_table *filter,
585 	    int *ndel, int flags);
586 
587 int	pfctl_get_astats(struct pfctl_handle *h, const struct pfr_table *tbl,
588 	    struct pfr_astats *addr, int *size, int flags);
589 int	pfctl_clr_astats(struct pfctl_handle *h, const struct pfr_table *tbl,
590 	    struct pfr_addr *addr, int size, int *nzero, int flags);
591 int	pfctl_test_addrs(struct pfctl_handle *h, const struct pfr_table *tbl,
592 	    struct pfr_addr *addr, int size, int *nmatch, int flags);
593 int	pfctl_ina_define(struct pfctl_handle *h, struct pfr_table *tbl,
594 	    struct pfr_addr *addr, int size, int *nadd, int *naddr,
595 	    int ticket, int flags);
596 
597 struct pfctl_limit_rate {
598 	unsigned int	 limit;
599 	unsigned int	 seconds;
600 };
601 
602 struct pfctl_state_lim {
603 	uint32_t		 ticket;
604 	char			 name[PF_STATELIM_NAME_LEN];
605 	uint32_t		 id;
606 	unsigned int		 limit;
607 
608 	struct pfctl_limit_rate	 rate;
609 
610 	char			 description[PF_STATELIM_DESCR_LEN];
611 
612 	unsigned int		 inuse;
613 	uint64_t		 admitted;
614 	uint64_t		 hardlimited;
615 	uint64_t		 ratelimited;
616 };
617 
618 int	pfctl_state_limiter_nget(struct pfctl_handle *h, struct pfctl_state_lim *lim);
619 int	pfctl_state_limiter_add(struct pfctl_handle *h, struct pfctl_state_lim *lim);
620 
621 struct pfctl_source_lim {
622 	uint32_t	 ticket;
623 
624 	char		 name[PF_SOURCELIM_NAME_LEN];
625 	uint32_t	 id;
626 
627 	/* limit on the total number of address entries */
628 	unsigned int	 entries;
629 
630 	/* limit on the number of states per address entry */
631 	unsigned int	 limit;
632 
633 	/* rate limit on the creation of states by an address entry */
634 	struct pfctl_limit_rate	 rate;
635 
636 	/*
637 	 * when the number of states on an entry exceeds hwm, add
638 	 * the address to the specified table. when the number of
639 	 * states goes below lwm, remove it from the table.
640 	 */
641 	char		 overload_tblname[PF_TABLE_NAME_SIZE];
642 	unsigned int	 overload_hwm;
643 	unsigned int	 overload_lwm;
644 
645 	/*
646 	 * mask addresses before they're used for entries. /64s
647 	 * everywhere for inet6 makes it easy to use too much memory.
648 	 */
649 	unsigned int	 inet_prefix;
650 	unsigned int	 inet6_prefix;
651 
652 	char	 description[PF_SOURCELIM_DESCR_LEN];
653 
654 	unsigned int	 nentries;
655 	unsigned int	 inuse;
656 
657 	uint64_t	 addrallocs;
658 	uint64_t	 addrnomem;
659 	uint64_t	 admitted;
660 	uint64_t	 addrlimited;
661 	uint64_t	 hardlimited;
662 	uint64_t	 ratelimited;
663 };
664 
665 int	pfctl_source_limiter_get(struct pfctl_handle *h, struct pfctl_source_lim *lim);
666 int	pfctl_source_limiter_nget(struct pfctl_handle *h, struct pfctl_source_lim *lim);
667 int	pfctl_source_limiter_add(struct pfctl_handle *h, struct pfctl_source_lim *lim);
668 
669 struct pfctl_source {
670 	sa_family_t	 af;
671 	unsigned int	 rdomain;
672 	struct pf_addr	 addr;
673 
674 	unsigned int	 inet_prefix;
675 	unsigned int	 inet6_prefix;
676 
677 	unsigned int	 limit;
678 	unsigned int	 inuse;
679 	uint64_t	 admitted;
680 	uint64_t	 hardlimited;
681 	uint64_t	 ratelimited;
682 };
683 typedef int (*pfctl_get_source_fn)(struct pfctl_source *, void *);
684 int	pfctl_source_get(struct pfctl_handle *h, int id,
685 	    pfctl_get_source_fn fn, void *arg);
686 
687 struct pfctl_source_clear {
688 	char		 name[PF_SOURCELIM_NAME_LEN];
689 	uint32_t	 id;
690 	sa_family_t	 af;
691 	unsigned int	 rdomain;
692 	struct pf_addr	 addr;
693 };
694 int	pfctl_source_clear(struct pfctl_handle *h, struct pfctl_source_clear *);
695 
696 int	pfctl_flush_fingerprints(struct pfctl_handle *h);
697 int	pfctl_get_fingerprint(struct pfctl_handle *h, int idx, struct pf_osfp_ioctl *fp);
698 int	pfctl_add_fingerprint(struct pfctl_handle *h, struct pf_osfp_ioctl *fp);
699 
700 #endif
701