xref: /freebsd/lib/libpfctl/libpfctl.h (revision b1bebaaba9b9c0ddfe503c43ca8e9e3917ee2c57)
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 	TAILQ_ENTRY(pfctl_state)	entry;
373 
374 	uint64_t		 id;
375 	uint32_t		 creatorid;
376 	uint8_t		 	 direction;
377 
378 	struct pfctl_state_peer	 src;
379 	struct pfctl_state_peer	 dst;
380 
381 	uint32_t		 rule;
382 	uint32_t		 anchor;
383 	uint32_t		 nat_rule;
384 	struct pf_addr		 rt_addr;
385 	struct pfctl_state_key	 key[2];	/* addresses stack and wire  */
386 	char			 ifname[IFNAMSIZ];
387 	char			 orig_ifname[IFNAMSIZ];
388 	uint64_t		 packets[2];
389 	uint64_t		 bytes[2];
390 	uint32_t		 creation;
391 	uint32_t		 expire;
392 	uint32_t		 pfsync_time;
393 	uint16_t		 state_flags;
394 	uint32_t		 sync_flags;
395 	uint16_t		 qid;
396 	uint16_t		 pqid;
397 	uint16_t		 dnpipe;
398 	uint16_t		 dnrpipe;
399 	uint8_t			 log;
400 	int32_t			 rtableid;
401 	uint8_t			 min_ttl;
402 	uint8_t			 set_tos;
403 	uint16_t		 max_mss;
404 	uint8_t			 set_prio[2];
405 	uint8_t			 rt;
406 	char			 rt_ifname[IFNAMSIZ];
407 	sa_family_t		 rt_af;
408 	uint8_t			 src_node_flags;
409 };
410 
411 TAILQ_HEAD(pfctl_statelist, pfctl_state);
412 struct pfctl_states {
413 	struct pfctl_statelist	states;
414 };
415 
416 enum pfctl_syncookies_mode {
417 	PFCTL_SYNCOOKIES_NEVER,
418 	PFCTL_SYNCOOKIES_ALWAYS,
419 	PFCTL_SYNCOOKIES_ADAPTIVE
420 };
421 extern const char* PFCTL_SYNCOOKIES_MODE_NAMES[];
422 
423 struct pfctl_syncookies {
424 	enum pfctl_syncookies_mode	mode;
425 	uint8_t				highwater;	/* Percent */
426 	uint8_t				lowwater;	/* Percent */
427 	uint32_t			halfopen_states;
428 };
429 
430 struct pfctl_src_node {
431 	struct pf_addr		addr;
432 	struct pf_addr		raddr;
433 	int			rule;
434 	uint64_t		bytes[2];
435 	uint64_t		packets[2];
436 	uint32_t		states;
437 	uint32_t		conn;
438 	sa_family_t		af;
439 	sa_family_t		raf;
440 	uint8_t			ruletype;
441 	uint64_t		creation;
442 	uint64_t		expire;
443 	struct pfctl_threshold	conn_rate;
444 	pf_sn_types_t		type;
445 };
446 
447 #define	PF_DEVICE	"/dev/pf"
448 
449 struct pfctl_handle;
450 struct pfctl_handle	*pfctl_open(const char *pf_device);
451 void	pfctl_close(struct pfctl_handle *);
452 int	pfctl_fd(struct pfctl_handle *);
453 
454 int	pfctl_startstop(struct pfctl_handle *h, int start);
455 struct pfctl_status* pfctl_get_status_h(struct pfctl_handle *h);
456 struct pfctl_status* pfctl_get_status(int dev);
457 int	pfctl_clear_status(struct pfctl_handle *h);
458 uint64_t pfctl_status_counter(struct pfctl_status *status, int id);
459 uint64_t pfctl_status_lcounter(struct pfctl_status *status, int id);
460 uint64_t pfctl_status_fcounter(struct pfctl_status *status, int id);
461 uint64_t pfctl_status_scounter(struct pfctl_status *status, int id);
462 void	pfctl_free_status(struct pfctl_status *status);
463 
464 int	pfctl_get_eth_rulesets_info(int dev,
465 	    struct pfctl_eth_rulesets_info *ri, const char *path);
466 int	pfctl_get_eth_ruleset(int dev, const char *path, int nr,
467 	    struct pfctl_eth_ruleset_info *ri);
468 int	pfctl_get_eth_rules_info(int dev, struct pfctl_eth_rules_info *rules,
469 	    const char *path);
470 int	pfctl_get_eth_rule(int dev, uint32_t nr, uint32_t ticket,
471 	    const char *path, struct pfctl_eth_rule *rule, bool clear,
472 	    char *anchor_call);
473 int	pfctl_add_eth_rule(int dev, const struct pfctl_eth_rule *r,
474 	    const char *anchor, const char *anchor_call, uint32_t ticket);
475 int	pfctl_get_rules_info_h(struct pfctl_handle *h,
476 	    struct pfctl_rules_info *rules, uint32_t ruleset,
477 	    const char *path);
478 int	pfctl_get_rules_info(int dev, struct pfctl_rules_info *rules,
479 	    uint32_t ruleset, const char *path);
480 int	pfctl_get_rule(int dev, uint32_t nr, uint32_t ticket,
481 	    const char *anchor, uint32_t ruleset, struct pfctl_rule *rule,
482 	    char *anchor_call);
483 int	pfctl_get_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);
486 int	pfctl_get_clear_rule(int dev, uint32_t nr, uint32_t ticket,
487 	    const char *anchor, uint32_t ruleset, struct pfctl_rule *rule,
488 	    char *anchor_call, bool clear);
489 int	pfctl_get_clear_rule_h(struct pfctl_handle *h, uint32_t nr, uint32_t ticket,
490 	    const char *anchor, uint32_t ruleset, struct pfctl_rule *rule,
491 	    char *anchor_call, bool clear);
492 int	pfctl_add_rule(int dev, const struct pfctl_rule *r,
493 	    const char *anchor, const char *anchor_call, uint32_t ticket,
494 	    uint32_t pool_ticket);
495 int	pfctl_add_rule_h(struct pfctl_handle *h, const struct pfctl_rule *r,
496 	    const char *anchor, const char *anchor_call, uint32_t ticket,
497 	    uint32_t pool_ticket);
498 int	pfctl_set_keepcounters(int dev, bool keep);
499 int	pfctl_get_creatorids(struct pfctl_handle *h, uint32_t *creators, size_t *len);
500 
501 struct pfctl_state_filter {
502 	char			ifname[IFNAMSIZ];
503 	uint16_t		proto;
504 	sa_family_t		af;
505 	struct pf_addr		addr;
506 	struct pf_addr		mask;
507 };
508 typedef int (*pfctl_get_state_fn)(struct pfctl_state *, void *);
509 int pfctl_get_states_iter(pfctl_get_state_fn f, void *arg);
510 int pfctl_get_states_h(struct pfctl_handle *h, struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg);
511 int pfctl_get_filtered_states_iter(struct pfctl_state_filter *filter, pfctl_get_state_fn f, void *arg);
512 int	pfctl_get_states(int dev, struct pfctl_states *states);
513 void	pfctl_free_states(struct pfctl_states *states);
514 int	pfctl_clear_states(int dev, const struct pfctl_kill *kill,
515 	    unsigned int *killed);
516 int	pfctl_kill_states(int dev, const struct pfctl_kill *kill,
517 	    unsigned int *killed);
518 int	pfctl_clear_states_h(struct pfctl_handle *h, const struct pfctl_kill *kill,
519 	    unsigned int *killed);
520 int	pfctl_kill_states_h(struct pfctl_handle *h, const struct pfctl_kill *kill,
521 	    unsigned int *killed);
522 int	pfctl_clear_rules(int dev, const char *anchorname);
523 int	pfctl_clear_nat(int dev, const char *anchorname);
524 int	pfctl_clear_eth_rules(int dev, const char *anchorname);
525 int	pfctl_set_syncookies(int dev, const struct pfctl_syncookies *s);
526 int	pfctl_get_syncookies(int dev, struct pfctl_syncookies *s);
527 int	pfctl_table_add_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr
528 	    *addr, int size, int *nadd, int flags);
529 int	pfctl_table_add_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
530 	    *addr, int size, int *nadd, int flags);
531 int	pfctl_table_del_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
532 	    struct pfr_addr *addr, int size, int *ndel, int flags);
533 int	pfctl_table_del_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
534 	    *addr, int size, int *ndel, int flags);
535 int	pfctl_table_set_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl,
536 	    struct pfr_addr *addr, int size, int *nadd, int *ndel,
537 	    int *nchange, int flags);
538 int	pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
539 	    *addr, int size, int *size2, int *nadd, int *ndel, int *nchange,
540 	    int flags);
541 int	pfctl_table_get_addrs_h(struct pfctl_handle *h, struct pfr_table *tbl, struct pfr_addr *addr,
542 	    int *size, int flags);
543 int	pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr
544 	    *addr, int *size, int flags);
545 int	pfctl_set_statusif(struct pfctl_handle *h, const char *ifname);
546 
547 struct pfctl_natlook_key {
548 	sa_family_t af;
549 	uint8_t direction;
550 	uint8_t proto;
551 	struct pf_addr saddr;
552 	struct pf_addr daddr;
553 	uint16_t sport;
554 	uint16_t dport;
555 };
556 struct pfctl_natlook {
557 	struct pf_addr saddr;
558 	struct pf_addr daddr;
559 	uint16_t sport;
560 	uint16_t dport;
561 };
562 int	pfctl_natlook(struct pfctl_handle *h,
563 	    const struct pfctl_natlook_key *k, struct pfctl_natlook *r);
564 int	pfctl_set_debug(struct pfctl_handle *h, uint32_t level);
565 int	pfctl_set_timeout(struct pfctl_handle *h, uint32_t timeout, uint32_t seconds);
566 int	pfctl_get_timeout(struct pfctl_handle *h, uint32_t timeout, uint32_t *seconds);
567 int	pfctl_set_limit(struct pfctl_handle *h, const int index, const uint limit);
568 int	pfctl_get_limit(struct pfctl_handle *h, const int index, uint *limit);
569 int	pfctl_begin_addrs(struct pfctl_handle *h, uint32_t *ticket);
570 int	pfctl_add_addr(struct pfctl_handle *h, const struct pfioc_pooladdr *pa, int which);
571 int	pfctl_get_addrs(struct pfctl_handle *h, uint32_t ticket, uint32_t r_num,
572 	    uint8_t r_action, const char *anchor, uint32_t *nr, int which);
573 int	pfctl_get_addr(struct pfctl_handle *h, uint32_t ticket, uint32_t r_num,
574 	    uint8_t r_action, const char *anchor, uint32_t nr, struct pfioc_pooladdr *pa,
575 	    int which);
576 int	pfctl_get_rulesets(struct pfctl_handle *h, const char *path, uint32_t *nr);
577 int	pfctl_get_ruleset(struct pfctl_handle *h, const char *path, uint32_t nr, struct pfioc_ruleset *rs);
578 typedef int (*pfctl_get_srcnode_fn)(struct pfctl_src_node*, void *);
579 int	pfctl_get_srcnodes(struct pfctl_handle *h, pfctl_get_srcnode_fn fn, void *arg);
580 
581 int	pfctl_clear_tables(struct pfctl_handle *h, struct pfr_table *filter,
582 	    int *ndel, int flags);
583 int	pfctl_add_table(struct pfctl_handle *h, struct pfr_table *table,
584 	    int *nadd, int flags);
585 int	pfctl_del_table(struct pfctl_handle *h, struct pfr_table *table,
586 	    int *ndel, int flags);
587 
588 typedef int (*pfctl_get_tstats_fn)(const struct pfr_tstats *t, void *arg);
589 int	pfctl_get_tstats(struct pfctl_handle *h, const struct pfr_table *filter,
590 	    pfctl_get_tstats_fn fn, void *arg);
591 int	pfctl_clear_tstats(struct pfctl_handle *h, const struct pfr_table *filter,
592 	    int *nzero, int flags);
593 int	pfctl_clear_addrs(struct pfctl_handle *h, const struct pfr_table *filter,
594 	    int *ndel, int flags);
595 
596 int	pfctl_get_astats(struct pfctl_handle *h, const struct pfr_table *tbl,
597 	    struct pfr_astats *addr, int *size, int flags);
598 int	pfctl_clr_astats(struct pfctl_handle *h, const struct pfr_table *tbl,
599 	    struct pfr_addr *addr, int size, int *nzero, int flags);
600 
601 struct pfctl_limit_rate {
602 	unsigned int	 limit;
603 	unsigned int	 seconds;
604 };
605 
606 struct pfctl_state_lim {
607 	uint32_t		 ticket;
608 	char			 name[PF_STATELIM_NAME_LEN];
609 	uint32_t		 id;
610 	unsigned int		 limit;
611 
612 	struct pfctl_limit_rate	 rate;
613 
614 	char			 description[PF_STATELIM_DESCR_LEN];
615 
616 	unsigned int		 inuse;
617 	uint64_t		 admitted;
618 	uint64_t		 hardlimited;
619 	uint64_t		 ratelimited;
620 };
621 
622 int	pfctl_state_limiter_nget(struct pfctl_handle *h, struct pfctl_state_lim *lim);
623 int	pfctl_state_limiter_add(struct pfctl_handle *h, struct pfctl_state_lim *lim);
624 
625 struct pfctl_source_lim {
626 	uint32_t	 ticket;
627 
628 	char		 name[PF_SOURCELIM_NAME_LEN];
629 	uint32_t	 id;
630 
631 	/* limit on the total number of address entries */
632 	unsigned int	 entries;
633 
634 	/* limit on the number of states per address entry */
635 	unsigned int	 limit;
636 
637 	/* rate limit on the creation of states by an address entry */
638 	struct pfctl_limit_rate	 rate;
639 
640 	/*
641 	 * when the number of states on an entry exceeds hwm, add
642 	 * the address to the specified table. when the number of
643 	 * states goes below lwm, remove it from the table.
644 	 */
645 	char		 overload_tblname[PF_TABLE_NAME_SIZE];
646 	unsigned int	 overload_hwm;
647 	unsigned int	 overload_lwm;
648 
649 	/*
650 	 * mask addresses before they're used for entries. /64s
651 	 * everywhere for inet6 makes it easy to use too much memory.
652 	 */
653 	unsigned int	 inet_prefix;
654 	unsigned int	 inet6_prefix;
655 
656 	char	 description[PF_SOURCELIM_DESCR_LEN];
657 
658 	unsigned int	 nentries;
659 	unsigned int	 inuse;
660 
661 	uint64_t	 addrallocs;
662 	uint64_t	 addrnomem;
663 	uint64_t	 admitted;
664 	uint64_t	 addrlimited;
665 	uint64_t	 hardlimited;
666 	uint64_t	 ratelimited;
667 };
668 
669 int	pfctl_source_limiter_get(struct pfctl_handle *h, struct pfctl_source_lim *lim);
670 int	pfctl_source_limiter_nget(struct pfctl_handle *h, struct pfctl_source_lim *lim);
671 int	pfctl_source_limiter_add(struct pfctl_handle *h, struct pfctl_source_lim *lim);
672 
673 struct pfctl_source {
674 	sa_family_t	 af;
675 	unsigned int	 rdomain;
676 	struct pf_addr	 addr;
677 
678 	unsigned int	 inet_prefix;
679 	unsigned int	 inet6_prefix;
680 
681 	unsigned int	 limit;
682 	unsigned int	 inuse;
683 	uint64_t	 admitted;
684 	uint64_t	 hardlimited;
685 	uint64_t	 ratelimited;
686 };
687 typedef int (*pfctl_get_source_fn)(struct pfctl_source *, void *);
688 int	pfctl_source_get(struct pfctl_handle *h, int id,
689 	    pfctl_get_source_fn fn, void *arg);
690 
691 struct pfctl_source_clear {
692 	char		 name[PF_SOURCELIM_NAME_LEN];
693 	uint32_t	 id;
694 	sa_family_t	 af;
695 	unsigned int	 rdomain;
696 	struct pf_addr	 addr;
697 };
698 int	pfctl_source_clear(struct pfctl_handle *h, struct pfctl_source_clear *);
699 
700 #endif
701