pfctl_parser.h revision 1.1 1 1.1 itojun /* $OpenBSD: pfctl_parser.h,v 1.74 2004/02/10 22:26:56 dhartmei Exp $ */
2 1.1 itojun
3 1.1 itojun /*
4 1.1 itojun * Copyright (c) 2001 Daniel Hartmeier
5 1.1 itojun * All rights reserved.
6 1.1 itojun *
7 1.1 itojun * Redistribution and use in source and binary forms, with or without
8 1.1 itojun * modification, are permitted provided that the following conditions
9 1.1 itojun * are met:
10 1.1 itojun *
11 1.1 itojun * - Redistributions of source code must retain the above copyright
12 1.1 itojun * notice, this list of conditions and the following disclaimer.
13 1.1 itojun * - Redistributions in binary form must reproduce the above
14 1.1 itojun * copyright notice, this list of conditions and the following
15 1.1 itojun * disclaimer in the documentation and/or other materials provided
16 1.1 itojun * with the distribution.
17 1.1 itojun *
18 1.1 itojun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 1.1 itojun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 1.1 itojun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 1.1 itojun * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 1.1 itojun * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.1 itojun * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 1.1 itojun * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 1.1 itojun * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 1.1 itojun * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 1.1 itojun * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 itojun * POSSIBILITY OF SUCH DAMAGE.
30 1.1 itojun *
31 1.1 itojun */
32 1.1 itojun
33 1.1 itojun #ifndef _PFCTL_PARSER_H_
34 1.1 itojun #define _PFCTL_PARSER_H_
35 1.1 itojun
36 1.1 itojun #define PF_OSFP_FILE "/etc/pf.os"
37 1.1 itojun
38 1.1 itojun #define PF_OPT_DISABLE 0x0001
39 1.1 itojun #define PF_OPT_ENABLE 0x0002
40 1.1 itojun #define PF_OPT_VERBOSE 0x0004
41 1.1 itojun #define PF_OPT_NOACTION 0x0008
42 1.1 itojun #define PF_OPT_QUIET 0x0010
43 1.1 itojun #define PF_OPT_CLRRULECTRS 0x0020
44 1.1 itojun #define PF_OPT_USEDNS 0x0040
45 1.1 itojun #define PF_OPT_VERBOSE2 0x0080
46 1.1 itojun #define PF_OPT_DUMMYACTION 0x0100
47 1.1 itojun #define PF_OPT_DEBUG 0x0200
48 1.1 itojun #define PF_OPT_SHOWALL 0x0400
49 1.1 itojun
50 1.1 itojun #define PF_TH_ALL 0xFF
51 1.1 itojun
52 1.1 itojun #define PF_NAT_PROXY_PORT_LOW 50001
53 1.1 itojun #define PF_NAT_PROXY_PORT_HIGH 65535
54 1.1 itojun
55 1.1 itojun #define FCNT_NAMES { \
56 1.1 itojun "searches", \
57 1.1 itojun "inserts", \
58 1.1 itojun "removals", \
59 1.1 itojun NULL \
60 1.1 itojun }
61 1.1 itojun
62 1.1 itojun struct pfctl {
63 1.1 itojun int dev;
64 1.1 itojun int opts;
65 1.1 itojun int loadopt;
66 1.1 itojun u_int32_t tticket; /* table ticket */
67 1.1 itojun int tdirty; /* kernel dirty */
68 1.1 itojun u_int32_t rule_nr;
69 1.1 itojun struct pfioc_pooladdr paddr;
70 1.1 itojun struct pfioc_altq *paltq;
71 1.1 itojun struct pfioc_queue *pqueue;
72 1.1 itojun struct pfr_buffer *trans;
73 1.1 itojun const char *anchor;
74 1.1 itojun const char *ruleset;
75 1.1 itojun };
76 1.1 itojun
77 1.1 itojun struct node_if {
78 1.1 itojun char ifname[IFNAMSIZ];
79 1.1 itojun u_int8_t not;
80 1.1 itojun u_int ifa_flags;
81 1.1 itojun struct node_if *next;
82 1.1 itojun struct node_if *tail;
83 1.1 itojun };
84 1.1 itojun
85 1.1 itojun struct node_host {
86 1.1 itojun struct pf_addr_wrap addr;
87 1.1 itojun struct pf_addr bcast;
88 1.1 itojun struct pf_addr peer;
89 1.1 itojun sa_family_t af;
90 1.1 itojun u_int8_t not;
91 1.1 itojun u_int32_t ifindex; /* link-local IPv6 addrs */
92 1.1 itojun char *ifname;
93 1.1 itojun u_int ifa_flags;
94 1.1 itojun struct node_host *next;
95 1.1 itojun struct node_host *tail;
96 1.1 itojun };
97 1.1 itojun /* special flags used by ifa_exists */
98 1.1 itojun #define PF_IFA_FLAG_GROUP 0x10000
99 1.1 itojun #define PF_IFA_FLAG_DYNAMIC 0x20000
100 1.1 itojun #define PF_IFA_FLAG_CLONABLE 0x40000
101 1.1 itojun
102 1.1 itojun struct node_os {
103 1.1 itojun char *os;
104 1.1 itojun pf_osfp_t fingerprint;
105 1.1 itojun struct node_os *next;
106 1.1 itojun struct node_os *tail;
107 1.1 itojun };
108 1.1 itojun
109 1.1 itojun struct node_queue_bw {
110 1.1 itojun u_int32_t bw_absolute;
111 1.1 itojun u_int16_t bw_percent;
112 1.1 itojun };
113 1.1 itojun
114 1.1 itojun struct node_hfsc_sc {
115 1.1 itojun struct node_queue_bw m1; /* slope of 1st segment; bps */
116 1.1 itojun u_int d; /* x-projection of m1; msec */
117 1.1 itojun struct node_queue_bw m2; /* slope of 2nd segment; bps */
118 1.1 itojun u_int8_t used;
119 1.1 itojun };
120 1.1 itojun
121 1.1 itojun struct node_hfsc_opts {
122 1.1 itojun struct node_hfsc_sc realtime;
123 1.1 itojun struct node_hfsc_sc linkshare;
124 1.1 itojun struct node_hfsc_sc upperlimit;
125 1.1 itojun int flags;
126 1.1 itojun };
127 1.1 itojun
128 1.1 itojun struct node_queue_opt {
129 1.1 itojun int qtype;
130 1.1 itojun union {
131 1.1 itojun struct cbq_opts cbq_opts;
132 1.1 itojun struct priq_opts priq_opts;
133 1.1 itojun struct node_hfsc_opts hfsc_opts;
134 1.1 itojun } data;
135 1.1 itojun };
136 1.1 itojun
137 1.1 itojun SIMPLEQ_HEAD(node_tinithead, node_tinit);
138 1.1 itojun struct node_tinit { /* table initializer */
139 1.1 itojun SIMPLEQ_ENTRY(node_tinit) entries;
140 1.1 itojun struct node_host *host;
141 1.1 itojun char *file;
142 1.1 itojun };
143 1.1 itojun
144 1.1 itojun struct pfr_buffer; /* forward definition */
145 1.1 itojun
146 1.1 itojun int pfctl_rules(int, char *, int, char *, char *, struct pfr_buffer *);
147 1.1 itojun
148 1.1 itojun int pfctl_add_rule(struct pfctl *, struct pf_rule *);
149 1.1 itojun int pfctl_add_altq(struct pfctl *, struct pf_altq *);
150 1.1 itojun int pfctl_add_pool(struct pfctl *, struct pf_pool *, sa_family_t);
151 1.1 itojun void pfctl_clear_pool(struct pf_pool *);
152 1.1 itojun
153 1.1 itojun int pfctl_set_timeout(struct pfctl *, const char *, int, int);
154 1.1 itojun int pfctl_set_optimization(struct pfctl *, const char *);
155 1.1 itojun int pfctl_set_limit(struct pfctl *, const char *, unsigned int);
156 1.1 itojun int pfctl_set_logif(struct pfctl *, char *);
157 1.1 itojun int pfctl_set_hostid(struct pfctl *, u_int32_t);
158 1.1 itojun int pfctl_set_debug(struct pfctl *, char *);
159 1.1 itojun
160 1.1 itojun int parse_rules(FILE *, struct pfctl *);
161 1.1 itojun int parse_flags(char *);
162 1.1 itojun int pfctl_load_anchors(int, int, struct pfr_buffer *);
163 1.1 itojun
164 1.1 itojun void print_pool(struct pf_pool *, u_int16_t, u_int16_t, sa_family_t, int);
165 1.1 itojun void print_src_node(struct pf_src_node *, int);
166 1.1 itojun void print_rule(struct pf_rule *, int);
167 1.1 itojun void print_tabledef(const char *, int, int, struct node_tinithead *);
168 1.1 itojun void print_status(struct pf_status *, int);
169 1.1 itojun
170 1.1 itojun int eval_pfaltq(struct pfctl *, struct pf_altq *, struct node_queue_bw *,
171 1.1 itojun struct node_queue_opt *);
172 1.1 itojun int eval_pfqueue(struct pfctl *, struct pf_altq *, struct node_queue_bw *,
173 1.1 itojun struct node_queue_opt *);
174 1.1 itojun
175 1.1 itojun void print_altq(const struct pf_altq *, unsigned, struct node_queue_bw *,
176 1.1 itojun struct node_queue_opt *);
177 1.1 itojun void print_queue(const struct pf_altq *, unsigned, struct node_queue_bw *,
178 1.1 itojun int, struct node_queue_opt *);
179 1.1 itojun
180 1.1 itojun int pfctl_define_table(char *, int, int, const char *, const char *,
181 1.1 itojun struct pfr_buffer *, u_int32_t);
182 1.1 itojun
183 1.1 itojun void pfctl_clear_fingerprints(int, int);
184 1.1 itojun int pfctl_file_fingerprints(int, int, const char *);
185 1.1 itojun pf_osfp_t pfctl_get_fingerprint(const char *);
186 1.1 itojun int pfctl_load_fingerprints(int, int);
187 1.1 itojun char *pfctl_lookup_fingerprint(pf_osfp_t, char *, size_t);
188 1.1 itojun void pfctl_show_fingerprints(int);
189 1.1 itojun
190 1.1 itojun
191 1.1 itojun struct icmptypeent {
192 1.1 itojun const char *name;
193 1.1 itojun u_int8_t type;
194 1.1 itojun };
195 1.1 itojun
196 1.1 itojun struct icmpcodeent {
197 1.1 itojun const char *name;
198 1.1 itojun u_int8_t type;
199 1.1 itojun u_int8_t code;
200 1.1 itojun };
201 1.1 itojun
202 1.1 itojun const struct icmptypeent *geticmptypebynumber(u_int8_t, u_int8_t);
203 1.1 itojun const struct icmptypeent *geticmptypebyname(char *, u_int8_t);
204 1.1 itojun const struct icmpcodeent *geticmpcodebynumber(u_int8_t, u_int8_t, u_int8_t);
205 1.1 itojun const struct icmpcodeent *geticmpcodebyname(u_long, char *, u_int8_t);
206 1.1 itojun
207 1.1 itojun struct pf_timeout {
208 1.1 itojun const char *name;
209 1.1 itojun int timeout;
210 1.1 itojun };
211 1.1 itojun
212 1.1 itojun #define PFCTL_FLAG_FILTER 0x02
213 1.1 itojun #define PFCTL_FLAG_NAT 0x04
214 1.1 itojun #define PFCTL_FLAG_OPTION 0x08
215 1.1 itojun #define PFCTL_FLAG_ALTQ 0x10
216 1.1 itojun #define PFCTL_FLAG_TABLE 0x20
217 1.1 itojun
218 1.1 itojun extern const struct pf_timeout pf_timeouts[];
219 1.1 itojun
220 1.1 itojun void set_ipmask(struct node_host *, u_int8_t);
221 1.1 itojun int check_netmask(struct node_host *, sa_family_t);
222 1.1 itojun void ifa_load(void);
223 1.1 itojun struct node_host *ifa_exists(const char *, int);
224 1.1 itojun struct node_host *ifa_lookup(const char *, int);
225 1.1 itojun struct node_host *host(const char *);
226 1.1 itojun
227 1.1 itojun int append_addr(struct pfr_buffer *, char *, int);
228 1.1 itojun int append_addr_host(struct pfr_buffer *,
229 1.1 itojun struct node_host *, int, int);
230 1.1 itojun
231 1.1 itojun #endif /* _PFCTL_PARSER_H_ */
232