xref: /dragonfly/usr.sbin/pfctl/pfctl.h (revision 0db87cb7)
1 /*	$OpenBSD: pfctl.h,v 1.43 2008/05/29 01:00:53 mcbride Exp $ */
2 
3 /*
4  * Copyright (c) 2001 Daniel Hartmeier
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 
33 #ifndef _PFCTL_H_
34 #define _PFCTL_H_
35 
36 enum pfctl_show { PFCTL_SHOW_RULES, PFCTL_SHOW_LABELS, PFCTL_SHOW_NOTHING };
37 
38 enum {	PFRB_TABLES = 1, PFRB_TSTATS, PFRB_ADDRS, PFRB_ASTATS,
39 	PFRB_IFACES, PFRB_TRANS, PFRB_MAX };
40 struct pfr_buffer {
41 	int	 pfrb_type;	/* type of content, see enum above */
42 	int	 pfrb_size;	/* number of objects in buffer */
43 	int	 pfrb_msize;	/* maximum number of objects in buffer */
44 	void	*pfrb_caddr;	/* malloc'ated memory area */
45 };
46 #define PFRB_FOREACH(var, buf)				\
47 	for ((var) = pfr_buf_next((buf), NULL);		\
48 	    (var) != NULL;				\
49 	    (var) = pfr_buf_next((buf), (var)))
50 
51 int	 pfr_get_fd(void);
52 int	 pfr_clr_tables(struct pfr_table *, int *, int);
53 int	 pfr_add_tables(struct pfr_table *, int, int *, int);
54 int	 pfr_del_tables(struct pfr_table *, int, int *, int);
55 int	 pfr_get_tables(struct pfr_table *, struct pfr_table *, int *, int);
56 int	 pfr_get_tstats(struct pfr_table *, struct pfr_tstats *, int *, int);
57 int	 pfr_clr_tstats(struct pfr_table *, int, int *, int);
58 int	 pfr_clr_addrs(struct pfr_table *, int *, int);
59 int	 pfr_add_addrs(struct pfr_table *, struct pfr_addr *, int, int *, int);
60 int	 pfr_del_addrs(struct pfr_table *, struct pfr_addr *, int, int *, int);
61 int	 pfr_set_addrs(struct pfr_table *, struct pfr_addr *, int, int *,
62 	    int *, int *, int *, int);
63 int	 pfr_get_addrs(struct pfr_table *, struct pfr_addr *, int *, int);
64 int	 pfr_get_astats(struct pfr_table *, struct pfr_astats *, int *, int);
65 int	 pfr_tst_addrs(struct pfr_table *, struct pfr_addr *, int, int *, int);
66 int	 pfr_ina_define(struct pfr_table *, struct pfr_addr *, int, int *,
67 	    int *, int, int);
68 void	 pfr_buf_clear(struct pfr_buffer *);
69 int	 pfr_buf_add(struct pfr_buffer *, const void *);
70 const void	*pfr_buf_next(struct pfr_buffer *, const void *);
71 int	 pfr_buf_grow(struct pfr_buffer *, int);
72 int	 pfr_buf_load(struct pfr_buffer *, char *, int,
73 	    int (*)(struct pfr_buffer *, char *, int));
74 const char	*pfr_strerror(int);
75 int	 pfi_get_ifaces(const char *, struct pfi_kif *, int *);
76 int	 pfi_clr_istats(const char *, int *, int);
77 
78 void	 pfctl_print_title(const char *);
79 int	 pfctl_clear_tables(const char *, int);
80 int	 pfctl_show_tables(const char *, int);
81 int	 pfctl_command_tables(int, char *[], char *, const char *, char *,
82 	    const char *, int);
83 int	 pfctl_show_altq(int, const char *, int, int);
84 void	 warn_namespace_collision(const char *);
85 int	 pfctl_show_ifaces(const char *, int);
86 FILE	*pfctl_fopen(const char *, const char *);
87 
88 #ifndef DEFAULT_PRIORITY
89 #define DEFAULT_PRIORITY	1
90 #endif
91 
92 #ifndef DEFAULT_QLIMIT
93 #define DEFAULT_QLIMIT		50
94 #endif
95 
96 /*
97  * generalized service curve used for admission control
98  */
99 struct segment {
100 	LIST_ENTRY(segment)	_next;
101 	double			x, y, d, m;
102 };
103 
104 extern	int loadopt;
105 
106 int		 check_commit_altq(int, int);
107 void		 pfaltq_store(struct pf_altq *);
108 struct pf_altq	*pfaltq_lookup(const char *);
109 char		*rate2str(double);
110 
111 void	 print_addr(struct pf_addr_wrap *, sa_family_t, int);
112 void	 print_host(struct pf_addr *, u_int16_t p, sa_family_t, int);
113 void	 print_seq(struct pfsync_state_peer *);
114 void	 print_state(struct pfsync_state *, int);
115 int	 unmask(struct pf_addr *, sa_family_t);
116 
117 int	 pfctl_cmdline_symset(char *);
118 int	 pfctl_add_trans(struct pfr_buffer *, int, const char *);
119 u_int32_t
120 	 pfctl_get_ticket(struct pfr_buffer *, int, const char *);
121 int	 pfctl_trans(int, struct pfr_buffer *, u_long, int);
122 
123 #endif /* _PFCTL_H_ */
124