xref: /freebsd/sbin/pfctl/pfctl.h (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1 /*	$OpenBSD: pfctl.h,v 1.42 2007/12/05 12:01:47 chl Exp $ */
2 
3 /*-
4  * SPDX-License-Identifier: BSD-2-Clause
5  *
6  * Copyright (c) 2001 Daniel Hartmeier
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  *    - Redistributions of source code must retain the above copyright
14  *      notice, this list of conditions and the following disclaimer.
15  *    - Redistributions in binary form must reproduce the above
16  *      copyright notice, this list of conditions and the following
17  *      disclaimer in the documentation and/or other materials provided
18  *      with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  * $FreeBSD$
34  */
35 
36 #ifndef _PFCTL_H_
37 #define _PFCTL_H_
38 
39 #include <libpfctl.h>
40 
41 struct pfctl;
42 
43 enum pfctl_show { PFCTL_SHOW_RULES, PFCTL_SHOW_LABELS, PFCTL_SHOW_NOTHING };
44 
45 enum {	PFRB_TABLES = 1, PFRB_TSTATS, PFRB_ADDRS, PFRB_ASTATS,
46 	PFRB_IFACES, PFRB_TRANS, PFRB_MAX };
47 struct pfr_buffer {
48 	int	 pfrb_type;	/* type of content, see enum above */
49 	int	 pfrb_size;	/* number of objects in buffer */
50 	int	 pfrb_msize;	/* maximum number of objects in buffer */
51 	void	*pfrb_caddr;	/* malloc'ated memory area */
52 };
53 #define PFRB_FOREACH(var, buf)				\
54 	for ((var) = pfr_buf_next((buf), NULL);		\
55 	    (var) != NULL;				\
56 	    (var) = pfr_buf_next((buf), (var)))
57 
58 int	 pfr_get_fd(void);
59 int	 pfr_clr_tables(struct pfr_table *, int *, int);
60 int	 pfr_add_tables(struct pfr_table *, int, int *, int);
61 int	 pfr_del_tables(struct pfr_table *, int, int *, int);
62 int	 pfr_get_tables(struct pfr_table *, struct pfr_table *, int *, int);
63 int	 pfr_get_tstats(struct pfr_table *, struct pfr_tstats *, int *, int);
64 int	 pfr_clr_tstats(struct pfr_table *, int, int *, int);
65 int	 pfr_clr_addrs(struct pfr_table *, int *, int);
66 int	 pfr_add_addrs(struct pfr_table *, struct pfr_addr *, int, int *, int);
67 int	 pfr_del_addrs(struct pfr_table *, struct pfr_addr *, int, int *, int);
68 int	 pfr_set_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
69 	    int *, int *, int *, int);
70 int	 pfr_get_addrs(struct pfr_table *, struct pfr_addr *, int *, int);
71 int	 pfr_get_astats(struct pfr_table *, struct pfr_astats *, int *, int);
72 int	 pfr_tst_addrs(struct pfr_table *, struct pfr_addr *, int, int *, int);
73 int	 pfr_ina_define(struct pfr_table *, struct pfr_addr *, int, int *,
74 	    int *, int, int);
75 void	 pfr_buf_clear(struct pfr_buffer *);
76 int	 pfr_buf_add(struct pfr_buffer *, const void *);
77 void	*pfr_buf_next(struct pfr_buffer *, const void *);
78 int	 pfr_buf_grow(struct pfr_buffer *, int);
79 int	 pfr_buf_load(struct pfr_buffer *, char *, int,
80 	    int (*)(struct pfr_buffer *, char *, int));
81 char	*pfr_strerror(int);
82 int	 pfi_get_ifaces(const char *, struct pfi_kif *, int *);
83 int	 pfi_clr_istats(const char *, int *, int);
84 
85 void	 pfctl_print_title(char *);
86 int	 pfctl_clear_tables(const char *, int);
87 int	 pfctl_show_tables(const char *, int);
88 int	 pfctl_command_tables(int, char *[], char *, const char *, char *,
89 	    const char *, int);
90 int	 pfctl_show_altq(int, const char *, int, int);
91 void	 warn_namespace_collision(const char *);
92 int	 pfctl_show_ifaces(const char *, int);
93 FILE	*pfctl_fopen(const char *, const char *);
94 
95 #ifdef __FreeBSD__
96 extern int altqsupport;
97 extern int dummynetsupport;
98 #define	HTONL(x)		(x) = htonl((__uint32_t)(x))
99 #endif
100 
101 #ifndef DEFAULT_PRIORITY
102 #define DEFAULT_PRIORITY	1
103 #endif
104 
105 #ifndef DEFAULT_QLIMIT
106 #define DEFAULT_QLIMIT		50
107 #endif
108 
109 /*
110  * generalized service curve used for admission control
111  */
112 struct segment {
113 	LIST_ENTRY(segment)	_next;
114 	double			x, y, d, m;
115 };
116 
117 extern	int loadopt;
118 
119 int		 check_commit_altq(int, int);
120 void		 pfaltq_store(struct pf_altq *);
121 char		*rate2str(double);
122 
123 void	 print_addr(struct pf_addr_wrap *, sa_family_t, int);
124 void	 print_host(struct pf_addr *, u_int16_t p, sa_family_t, int);
125 void	 print_seq(struct pfctl_state_peer *);
126 void	 print_state(struct pfctl_state *, int);
127 int	 unmask(struct pf_addr *, sa_family_t);
128 
129 int	 pfctl_cmdline_symset(char *);
130 int	 pfctl_add_trans(struct pfr_buffer *, int, const char *);
131 u_int32_t
132 	 pfctl_get_ticket(struct pfr_buffer *, int, const char *);
133 int	 pfctl_trans(int, struct pfr_buffer *, u_long, int);
134 
135 int	 pf_get_ruleset_number(u_int8_t);
136 void	 pf_init_ruleset(struct pfctl_ruleset *);
137 int	 pfctl_anchor_setup(struct pfctl_rule *,
138 	    const struct pfctl_ruleset *, const char *);
139 void	 pf_remove_if_empty_ruleset(struct pfctl_ruleset *);
140 struct pfctl_ruleset	*pf_find_ruleset(const char *);
141 struct pfctl_ruleset	*pf_find_or_create_ruleset(const char *);
142 void			 pf_init_eth_ruleset(struct pfctl_eth_ruleset *);
143 int			 pfctl_eth_anchor_setup(struct pfctl *,
144 			    struct pfctl_eth_rule *,
145 			    const struct pfctl_eth_ruleset *, const char *);
146 struct pfctl_eth_ruleset	*pf_find_or_create_eth_ruleset(const char *);
147 void			 pf_remove_if_empty_eth_ruleset(
148 			    struct pfctl_eth_ruleset *);
149 
150 void		 expand_label(char *, size_t, struct pfctl_rule *);
151 
152 const char *pfctl_proto2name(int);
153 
154 #endif /* _PFCTL_H_ */
155