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