1 /* $OpenBSD: pfctl_parser.h,v 1.74 2004/02/10 22:26:56 dhartmei Exp $ */
2 /* $DragonFly: src/usr.sbin/pfctl/pfctl_parser.h,v 1.3 2008/04/11 18:21:49 dillon Exp $ */
5 * Copyright (c) 2001 Daniel Hartmeier
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
34 #ifndef _PFCTL_PARSER_H_
35 #define _PFCTL_PARSER_H_
37 #define PF_OSFP_FILE "/etc/pf.os"
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
51 #define PF_TH_ALL 0xFF
53 #define PF_NAT_PROXY_PORT_LOW 50001
54 #define PF_NAT_PROXY_PORT_HIGH 65535
56 #define FCNT_NAMES { \
67 u_int32_t tticket
; /* table ticket */
68 int tdirty
; /* kernel dirty */
70 struct pfioc_pooladdr paddr
;
71 struct pfioc_altq
*paltq
;
72 struct pfioc_queue
*pqueue
;
73 struct pfr_buffer
*trans
;
79 char ifname
[IFNAMSIZ
];
87 struct pf_addr_wrap addr
;
92 u_int32_t ifindex
; /* link-local IPv6 addrs */
95 struct node_host
*next
;
96 struct node_host
*tail
;
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
105 pf_osfp_t fingerprint
;
106 struct node_os
*next
;
107 struct node_os
*tail
;
110 struct node_queue_bw
{
111 u_int32_t bw_absolute
;
112 u_int16_t bw_percent
;
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 */
122 struct node_hfsc_opts
{
123 struct node_hfsc_sc realtime
;
124 struct node_hfsc_sc linkshare
;
125 struct node_hfsc_sc upperlimit
;
129 struct node_fairq_sc
{
130 struct node_queue_bw m1
; /* slope of 1st segment; bps */
131 u_int d
; /* x-projection of m1; msec */
132 struct node_queue_bw m2
; /* slope of 2nd segment; bps */
136 struct node_fairq_opts
{
137 struct node_fairq_sc linkshare
;
138 struct node_queue_bw hogs_bw
;
143 struct node_queue_opt
{
146 struct cbq_opts cbq_opts
;
147 struct priq_opts priq_opts
;
148 struct node_hfsc_opts hfsc_opts
;
149 struct node_fairq_opts fairq_opts
;
153 /* XXX should be in machine/limits.h */
155 #define UID_MAX UINT_MAX
156 #define GID_MAX UINT_MAX
160 * Absolutely this is not correct location to define this.
161 * Should we use an another sperate header file?
162 * NOTE: This is also defined in sys/bus/usb/usb_port.h
163 * perhaps place in sys/queue.h?
165 #define SIMPLEQ_HEAD STAILQ_HEAD
166 #define SIMPLEQ_HEAD_INITIALIZER STAILQ_HEAD_INITIALIZER
167 #define SIMPLEQ_ENTRY STAILQ_ENTRY
168 #define SIMPLEQ_FIRST STAILQ_FIRST
169 #define SIMPLEQ_END(head) NULL
170 #define SIMPLEQ_EMPTY STAILQ_EMPTY
171 #define SIMPLEQ_NEXT STAILQ_NEXT
172 /*#define SIMPLEQ_FOREACH STAILQ_FOREACH*/
173 #define SIMPLEQ_FOREACH(var, head, field) \
174 for((var) = SIMPLEQ_FIRST(head); \
175 (var) != SIMPLEQ_END(head); \
176 (var) = SIMPLEQ_NEXT(var, field))
177 #define SIMPLEQ_INIT STAILQ_INIT
178 #define SIMPLEQ_INSERT_HEAD STAILQ_INSERT_HEAD
179 #define SIMPLEQ_INSERT_TAIL STAILQ_INSERT_TAIL
180 #define SIMPLEQ_INSERT_AFTER STAILQ_INSERT_AFTER
181 #define SIMPLEQ_REMOVE_HEAD STAILQ_REMOVE_HEAD
183 SIMPLEQ_HEAD(node_tinithead
, node_tinit
);
184 struct node_tinit
{ /* table initializer */
185 SIMPLEQ_ENTRY(node_tinit
) entries
;
186 struct node_host
*host
;
190 struct pfr_buffer
; /* forward definition */
192 int pfctl_rules(int, char *, int, char *, char *, struct pfr_buffer
*);
194 int pfctl_add_rule(struct pfctl
*, struct pf_rule
*);
195 int pfctl_add_altq(struct pfctl
*, struct pf_altq
*);
196 int pfctl_add_pool(struct pfctl
*, struct pf_pool
*, sa_family_t
);
197 void pfctl_clear_pool(struct pf_pool
*);
199 int pfctl_set_timeout(struct pfctl
*, const char *, int, int);
200 int pfctl_set_optimization(struct pfctl
*, const char *);
201 int pfctl_set_limit(struct pfctl
*, const char *, unsigned int);
202 int pfctl_set_logif(struct pfctl
*, char *);
203 int pfctl_set_hostid(struct pfctl
*, u_int32_t
);
204 int pfctl_set_debug(struct pfctl
*, char *);
206 int parse_rules(FILE *, struct pfctl
*);
207 int parse_flags(const char *);
208 int pfctl_load_anchors(int, int, struct pfr_buffer
*);
210 void print_pool(struct pf_pool
*, u_int16_t
, u_int16_t
, sa_family_t
, int);
211 void print_src_node(struct pf_src_node
*, int);
212 void print_rule(struct pf_rule
*, int);
213 void print_tabledef(const char *, int, int, struct node_tinithead
*);
214 void print_status(struct pf_status
*, int);
216 int eval_pfaltq(struct pfctl
*, struct pf_altq
*, struct node_queue_bw
*,
217 struct node_queue_opt
*);
218 int eval_pfqueue(struct pfctl
*, struct pf_altq
*, struct node_queue_bw
*,
219 struct node_queue_opt
*);
221 void print_altq(const struct pf_altq
*, unsigned, struct node_queue_bw
*,
222 struct node_queue_opt
*);
223 void print_queue(const struct pf_altq
*, unsigned, struct node_queue_bw
*,
224 int, struct node_queue_opt
*);
226 int pfctl_define_table(char *, int, int, const char *, const char *,
227 struct pfr_buffer
*, u_int32_t
);
229 void pfctl_clear_fingerprints(int, int);
230 int pfctl_file_fingerprints(int, int, const char *);
231 pf_osfp_t
pfctl_get_fingerprint(const char *);
232 int pfctl_load_fingerprints(int, int);
233 char *pfctl_lookup_fingerprint(pf_osfp_t
, char *, size_t);
234 void pfctl_show_fingerprints(int);
248 const struct icmptypeent
*geticmptypebynumber(u_int8_t
, u_int8_t
);
249 const struct icmptypeent
*geticmptypebyname(char *, u_int8_t
);
250 const struct icmpcodeent
*geticmpcodebynumber(u_int8_t
, u_int8_t
, u_int8_t
);
251 const struct icmpcodeent
*geticmpcodebyname(u_long
, char *, u_int8_t
);
258 #define PFCTL_FLAG_FILTER 0x02
259 #define PFCTL_FLAG_NAT 0x04
260 #define PFCTL_FLAG_OPTION 0x08
261 #define PFCTL_FLAG_ALTQ 0x10
262 #define PFCTL_FLAG_TABLE 0x20
264 extern const struct pf_timeout pf_timeouts
[];
266 void set_ipmask(struct node_host
*, u_int8_t
);
267 int check_netmask(struct node_host
*, sa_family_t
);
269 struct node_host
*ifa_exists(const char *, int);
270 struct node_host
*ifa_lookup(const char *, int);
271 struct node_host
*host(const char *);
273 int append_addr(struct pfr_buffer
*, char *, int);
274 int append_addr_host(struct pfr_buffer
*,
275 struct node_host
*, int, int);
277 #endif /* _PFCTL_PARSER_H_ */