2 * firewall3 - 3rd OpenWrt UCI firewall implementation
4 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #ifndef __FW3_OPTIONS_H
20 #define __FW3_OPTIONS_H
33 #include <arpa/inet.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #include <netinet/ether.h>
40 #include <libubox/list.h>
41 #include <libubox/utils.h>
43 #include "icmp_codes.h"
64 FW3_TARGET_UNSPEC
= 0,
65 FW3_TARGET_ACCEPT
= 6,
66 FW3_TARGET_REJECT
= 7,
68 FW3_TARGET_NOTRACK
= 9,
75 FW3_DEFAULT_UNSPEC
= 0,
76 FW3_DEFAULT_CUSTOM_CHAINS
= 12,
77 FW3_DEFAULT_SYN_FLOOD
= 13,
78 FW3_DEFAULT_MTU_FIX
= 14,
79 FW3_DEFAULT_DROP_INVALID
= 15,
82 extern const char *fw3_flag_names
[FW3_DEFAULT_DROP_INVALID
+ 1];
87 FW3_LIMIT_UNIT_SECOND
= 0,
88 FW3_LIMIT_UNIT_MINUTE
= 1,
89 FW3_LIMIT_UNIT_HOUR
= 2,
90 FW3_LIMIT_UNIT_DAY
= 3,
95 FW3_IPSET_METHOD_UNSPEC
= 0,
96 FW3_IPSET_METHOD_BITMAP
= 1,
97 FW3_IPSET_METHOD_HASH
= 2,
98 FW3_IPSET_METHOD_LIST
= 3,
103 FW3_IPSET_TYPE_UNSPEC
= 0,
104 FW3_IPSET_TYPE_IP
= 1,
105 FW3_IPSET_TYPE_PORT
= 2,
106 FW3_IPSET_TYPE_MAC
= 3,
107 FW3_IPSET_TYPE_NET
= 4,
108 FW3_IPSET_TYPE_SET
= 5,
111 struct fw3_ipset_datatype
113 struct list_head list
;
114 enum fw3_ipset_type type
;
120 struct list_head list
;
130 struct list_head list
;
134 enum fw3_family family
;
139 struct ether_addr mac
;
145 struct list_head list
;
149 struct ether_addr mac
;
154 struct list_head list
;
163 struct list_head list
;
173 struct list_head list
;
176 enum fw3_family family
;
190 enum fw3_limit_unit unit
;
195 enum fw3_target policy_input
;
196 enum fw3_target policy_output
;
197 enum fw3_target policy_forward
;
202 struct fw3_limit syn_flood_rate
;
207 bool tcp_window_scaling
;
209 bool accept_redirects
;
210 bool accept_source_route
;
221 struct list_head list
;
225 enum fw3_family family
;
227 enum fw3_target policy_input
;
228 enum fw3_target policy_output
;
229 enum fw3_target policy_forward
;
231 struct list_head networks
;
232 struct list_head devices
;
233 struct list_head subnets
;
235 const char *extra_src
;
236 const char *extra_dest
;
239 struct list_head masq_src
;
240 struct list_head masq_dest
;
246 struct fw3_limit log_limit
;
256 struct list_head list
;
260 enum fw3_family family
;
262 struct fw3_zone
*_src
;
263 struct fw3_zone
*_dest
;
265 struct fw3_device src
;
266 struct fw3_device dest
;
268 struct fw3_ipset
*_ipset
;
269 struct fw3_device ipset
;
271 struct list_head proto
;
273 struct list_head ip_src
;
274 struct list_head mac_src
;
275 struct list_head port_src
;
277 struct list_head ip_dest
;
278 struct list_head port_dest
;
280 struct list_head icmp_type
;
282 enum fw3_target target
;
284 struct fw3_limit limit
;
291 struct list_head list
;
295 enum fw3_family family
;
297 struct fw3_zone
*_src
;
298 struct fw3_zone
*_dest
;
300 struct fw3_device src
;
301 struct fw3_device dest
;
303 struct fw3_ipset
*_ipset
;
304 struct fw3_device ipset
;
306 struct list_head proto
;
308 struct fw3_address ip_src
;
309 struct list_head mac_src
;
310 struct fw3_port port_src
;
312 struct fw3_address ip_dest
;
313 struct fw3_port port_dest
;
315 struct fw3_address ip_redir
;
316 struct fw3_port port_redir
;
318 enum fw3_target target
;
327 struct list_head list
;
331 enum fw3_family family
;
333 struct fw3_zone
*_src
;
334 struct fw3_zone
*_dest
;
336 struct fw3_device src
;
337 struct fw3_device dest
;
342 struct list_head list
;
345 enum fw3_family family
;
347 enum fw3_ipset_method method
;
348 struct list_head datatypes
;
350 struct list_head iprange
;
351 struct fw3_port portrange
;
359 const char *external
;
366 struct uci_context
*uci
;
367 struct fw3_defaults defaults
;
368 struct list_head zones
;
369 struct list_head rules
;
370 struct list_head redirects
;
371 struct list_head forwards
;
372 struct list_head ipsets
;
381 bool (*parse
)(void *, const char *);
386 #define FW3_OPT(name, parse, structure, member) \
387 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
389 #define FW3_LIST(name, parse, structure, member) \
390 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
391 sizeof(struct fw3_##structure) }
394 bool fw3_parse_bool(void *ptr
, const char *val
);
395 bool fw3_parse_int(void *ptr
, const char *val
);
396 bool fw3_parse_string(void *ptr
, const char *val
);
397 bool fw3_parse_target(void *ptr
, const char *val
);
398 bool fw3_parse_limit(void *ptr
, const char *val
);
399 bool fw3_parse_device(void *ptr
, const char *val
);
400 bool fw3_parse_address(void *ptr
, const char *val
);
401 bool fw3_parse_mac(void *ptr
, const char *val
);
402 bool fw3_parse_port(void *ptr
, const char *val
);
403 bool fw3_parse_family(void *ptr
, const char *val
);
404 bool fw3_parse_icmptype(void *ptr
, const char *val
);
405 bool fw3_parse_protocol(void *ptr
, const char *val
);
406 bool fw3_parse_ipset_method(void *ptr
, const char *val
);
407 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
);
409 void fw3_parse_options(void *s
, struct fw3_option
*opts
, int n
,
410 struct uci_section
*section
);
412 void fw3_format_in_out(struct fw3_device
*in
, struct fw3_device
*out
);
413 void fw3_format_src_dest(struct fw3_address
*src
, struct fw3_address
*dest
);
414 void fw3_format_sport_dport(struct fw3_port
*sp
, struct fw3_port
*dp
);
415 void fw3_format_mac(struct fw3_mac
*mac
);
416 void fw3_format_protocol(struct fw3_protocol
*proto
, enum fw3_family family
);
417 void fw3_format_icmptype(struct fw3_icmptype
*icmp
, enum fw3_family family
);
418 void fw3_format_limit(struct fw3_limit
*limit
);
419 void fw3_format_ipset(struct fw3_ipset
*ipset
, bool invert
);
421 void __fw3_format_comment(const char *comment
, ...);
422 #define fw3_format_comment(...) __fw3_format_comment(__VA_ARGS__, NULL)
424 void fw3_format_extra(const char *extra
);