pfctl_parser.h revision 1.1.1.1 1 /* $OpenBSD: pfctl_parser.h,v 1.74 2004/02/10 22:26:56 dhartmei 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_PARSER_H_
34 #define _PFCTL_PARSER_H_
35
36 #define PF_OSFP_FILE "/etc/pf.os"
37
38 #define PF_OPT_DISABLE 0x0001
39 #define PF_OPT_ENABLE 0x0002
40 #define PF_OPT_VERBOSE 0x0004
41 #define PF_OPT_NOACTION 0x0008
42 #define PF_OPT_QUIET 0x0010
43 #define PF_OPT_CLRRULECTRS 0x0020
44 #define PF_OPT_USEDNS 0x0040
45 #define PF_OPT_VERBOSE2 0x0080
46 #define PF_OPT_DUMMYACTION 0x0100
47 #define PF_OPT_DEBUG 0x0200
48 #define PF_OPT_SHOWALL 0x0400
49
50 #define PF_TH_ALL 0xFF
51
52 #define PF_NAT_PROXY_PORT_LOW 50001
53 #define PF_NAT_PROXY_PORT_HIGH 65535
54
55 #define FCNT_NAMES { \
56 "searches", \
57 "inserts", \
58 "removals", \
59 NULL \
60 }
61
62 struct pfctl {
63 int dev;
64 int opts;
65 int loadopt;
66 u_int32_t tticket; /* table ticket */
67 int tdirty; /* kernel dirty */
68 u_int32_t rule_nr;
69 struct pfioc_pooladdr paddr;
70 struct pfioc_altq *paltq;
71 struct pfioc_queue *pqueue;
72 struct pfr_buffer *trans;
73 const char *anchor;
74 const char *ruleset;
75 };
76
77 struct node_if {
78 char ifname[IFNAMSIZ];
79 u_int8_t not;
80 u_int ifa_flags;
81 struct node_if *next;
82 struct node_if *tail;
83 };
84
85 struct node_host {
86 struct pf_addr_wrap addr;
87 struct pf_addr bcast;
88 struct pf_addr peer;
89 sa_family_t af;
90 u_int8_t not;
91 u_int32_t ifindex; /* link-local IPv6 addrs */
92 char *ifname;
93 u_int ifa_flags;
94 struct node_host *next;
95 struct node_host *tail;
96 };
97 /* special flags used by ifa_exists */
98 #define PF_IFA_FLAG_GROUP 0x10000
99 #define PF_IFA_FLAG_DYNAMIC 0x20000
100 #define PF_IFA_FLAG_CLONABLE 0x40000
101
102 struct node_os {
103 char *os;
104 pf_osfp_t fingerprint;
105 struct node_os *next;
106 struct node_os *tail;
107 };
108
109 struct node_queue_bw {
110 u_int32_t bw_absolute;
111 u_int16_t bw_percent;
112 };
113
114 struct node_hfsc_sc {
115 struct node_queue_bw m1; /* slope of 1st segment; bps */
116 u_int d; /* x-projection of m1; msec */
117 struct node_queue_bw m2; /* slope of 2nd segment; bps */
118 u_int8_t used;
119 };
120
121 struct node_hfsc_opts {
122 struct node_hfsc_sc realtime;
123 struct node_hfsc_sc linkshare;
124 struct node_hfsc_sc upperlimit;
125 int flags;
126 };
127
128 struct node_queue_opt {
129 int qtype;
130 union {
131 struct cbq_opts cbq_opts;
132 struct priq_opts priq_opts;
133 struct node_hfsc_opts hfsc_opts;
134 } data;
135 };
136
137 SIMPLEQ_HEAD(node_tinithead, node_tinit);
138 struct node_tinit { /* table initializer */
139 SIMPLEQ_ENTRY(node_tinit) entries;
140 struct node_host *host;
141 char *file;
142 };
143
144 struct pfr_buffer; /* forward definition */
145
146 int pfctl_rules(int, char *, int, char *, char *, struct pfr_buffer *);
147
148 int pfctl_add_rule(struct pfctl *, struct pf_rule *);
149 int pfctl_add_altq(struct pfctl *, struct pf_altq *);
150 int pfctl_add_pool(struct pfctl *, struct pf_pool *, sa_family_t);
151 void pfctl_clear_pool(struct pf_pool *);
152
153 int pfctl_set_timeout(struct pfctl *, const char *, int, int);
154 int pfctl_set_optimization(struct pfctl *, const char *);
155 int pfctl_set_limit(struct pfctl *, const char *, unsigned int);
156 int pfctl_set_logif(struct pfctl *, char *);
157 int pfctl_set_hostid(struct pfctl *, u_int32_t);
158 int pfctl_set_debug(struct pfctl *, char *);
159
160 int parse_rules(FILE *, struct pfctl *);
161 int parse_flags(char *);
162 int pfctl_load_anchors(int, int, struct pfr_buffer *);
163
164 void print_pool(struct pf_pool *, u_int16_t, u_int16_t, sa_family_t, int);
165 void print_src_node(struct pf_src_node *, int);
166 void print_rule(struct pf_rule *, int);
167 void print_tabledef(const char *, int, int, struct node_tinithead *);
168 void print_status(struct pf_status *, int);
169
170 int eval_pfaltq(struct pfctl *, struct pf_altq *, struct node_queue_bw *,
171 struct node_queue_opt *);
172 int eval_pfqueue(struct pfctl *, struct pf_altq *, struct node_queue_bw *,
173 struct node_queue_opt *);
174
175 void print_altq(const struct pf_altq *, unsigned, struct node_queue_bw *,
176 struct node_queue_opt *);
177 void print_queue(const struct pf_altq *, unsigned, struct node_queue_bw *,
178 int, struct node_queue_opt *);
179
180 int pfctl_define_table(char *, int, int, const char *, const char *,
181 struct pfr_buffer *, u_int32_t);
182
183 void pfctl_clear_fingerprints(int, int);
184 int pfctl_file_fingerprints(int, int, const char *);
185 pf_osfp_t pfctl_get_fingerprint(const char *);
186 int pfctl_load_fingerprints(int, int);
187 char *pfctl_lookup_fingerprint(pf_osfp_t, char *, size_t);
188 void pfctl_show_fingerprints(int);
189
190
191 struct icmptypeent {
192 const char *name;
193 u_int8_t type;
194 };
195
196 struct icmpcodeent {
197 const char *name;
198 u_int8_t type;
199 u_int8_t code;
200 };
201
202 const struct icmptypeent *geticmptypebynumber(u_int8_t, u_int8_t);
203 const struct icmptypeent *geticmptypebyname(char *, u_int8_t);
204 const struct icmpcodeent *geticmpcodebynumber(u_int8_t, u_int8_t, u_int8_t);
205 const struct icmpcodeent *geticmpcodebyname(u_long, char *, u_int8_t);
206
207 struct pf_timeout {
208 const char *name;
209 int timeout;
210 };
211
212 #define PFCTL_FLAG_FILTER 0x02
213 #define PFCTL_FLAG_NAT 0x04
214 #define PFCTL_FLAG_OPTION 0x08
215 #define PFCTL_FLAG_ALTQ 0x10
216 #define PFCTL_FLAG_TABLE 0x20
217
218 extern const struct pf_timeout pf_timeouts[];
219
220 void set_ipmask(struct node_host *, u_int8_t);
221 int check_netmask(struct node_host *, sa_family_t);
222 void ifa_load(void);
223 struct node_host *ifa_exists(const char *, int);
224 struct node_host *ifa_lookup(const char *, int);
225 struct node_host *host(const char *);
226
227 int append_addr(struct pfr_buffer *, char *, int);
228 int append_addr_host(struct pfr_buffer *,
229 struct node_host *, int, int);
230
231 #endif /* _PFCTL_PARSER_H_ */
232