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>
42 #include <libubox/list.h>
43 #include <libubox/utils.h>
45 #include "icmp_codes.h"
66 FW3_TARGET_UNSPEC = 0,
67 FW3_TARGET_ACCEPT = 6,
68 FW3_TARGET_REJECT = 7,
70 FW3_TARGET_NOTRACK = 9,
73 FW3_TARGET_CUSTOM_CNS_V4 = 12,
74 FW3_TARGET_CUSTOM_CNS_V6 = 13,
79 FW3_DEFAULT_UNSPEC = 0,
80 FW3_DEFAULT_CUSTOM_CHAINS = 14,
81 FW3_DEFAULT_SYN_FLOOD = 15,
82 FW3_DEFAULT_MTU_FIX = 16,
83 FW3_DEFAULT_DROP_INVALID = 17,
86 extern const char *fw3_flag_names[FW3_DEFAULT_DROP_INVALID + 1];
91 FW3_LIMIT_UNIT_SECOND = 0,
92 FW3_LIMIT_UNIT_MINUTE = 1,
93 FW3_LIMIT_UNIT_HOUR = 2,
94 FW3_LIMIT_UNIT_DAY = 3,
99 FW3_IPSET_METHOD_UNSPEC = 0,
100 FW3_IPSET_METHOD_BITMAP = 1,
101 FW3_IPSET_METHOD_HASH = 2,
102 FW3_IPSET_METHOD_LIST = 3,
107 FW3_IPSET_TYPE_UNSPEC = 0,
108 FW3_IPSET_TYPE_IP = 1,
109 FW3_IPSET_TYPE_PORT = 2,
110 FW3_IPSET_TYPE_MAC = 3,
111 FW3_IPSET_TYPE_NET = 4,
112 FW3_IPSET_TYPE_SET = 5,
115 enum fw3_include_type
117 FW3_INC_TYPE_SCRIPT = 0,
118 FW3_INC_TYPE_RESTORE = 1,
121 struct fw3_ipset_datatype
123 struct list_head list;
124 enum fw3_ipset_type type;
130 struct list_head list;
140 struct list_head list;
145 enum fw3_family family;
150 struct ether_addr mac;
155 struct ether_addr mac;
161 struct list_head list;
165 struct ether_addr mac;
170 struct list_head list;
179 struct list_head list;
189 struct list_head list;
192 enum fw3_family family;
206 enum fw3_limit_unit unit;
216 uint32_t monthdays; /* bit 0 is invert + 1 .. 31 */
217 uint8_t weekdays; /* bit 0 is invert + 1 .. 7 */
222 enum fw3_target policy_input;
223 enum fw3_target policy_output;
224 enum fw3_target policy_forward;
229 struct fw3_limit syn_flood_rate;
233 bool tcp_window_scaling;
235 bool accept_redirects;
236 bool accept_source_route;
243 uint32_t running_flags;
248 struct list_head list;
249 struct list_head running_list;
254 enum fw3_family family;
256 enum fw3_target policy_input;
257 enum fw3_target policy_output;
258 enum fw3_target policy_forward;
260 struct list_head networks;
261 struct list_head devices;
262 struct list_head subnets;
264 const char *extra_src;
265 const char *extra_dest;
268 struct list_head masq_src;
269 struct list_head masq_dest;
275 struct fw3_limit log_limit;
282 uint32_t running_src_flags;
283 uint32_t running_dst_flags;
288 struct list_head list;
293 enum fw3_family family;
295 struct fw3_zone *_src;
296 struct fw3_zone *_dest;
298 struct fw3_device src;
299 struct fw3_device dest;
301 struct fw3_ipset *_ipset;
302 struct fw3_device ipset;
304 struct list_head proto;
306 struct list_head ip_src;
307 struct list_head mac_src;
308 struct list_head port_src;
310 struct list_head ip_dest;
311 struct list_head port_dest;
313 struct list_head icmp_type;
315 struct fw3_limit limit;
316 struct fw3_time time;
318 enum fw3_target target;
325 struct list_head list;
330 enum fw3_family family;
332 struct fw3_zone *_src;
333 struct fw3_zone *_dest;
335 struct fw3_device src;
336 struct fw3_device dest;
338 struct fw3_ipset *_ipset;
339 struct fw3_device ipset;
341 struct list_head proto;
343 struct fw3_address ip_src;
344 struct list_head mac_src;
345 struct fw3_port port_src;
347 struct fw3_address ip_dest;
348 struct fw3_port port_dest;
350 struct fw3_address ip_redir;
351 struct fw3_port port_redir;
353 struct fw3_time time;
355 enum fw3_target target;
364 struct list_head list;
369 enum fw3_family family;
371 struct fw3_zone *_src;
372 struct fw3_zone *_dest;
374 struct fw3_device src;
375 struct fw3_device dest;
380 struct list_head list;
381 struct list_head running_list;
385 enum fw3_family family;
387 enum fw3_ipset_method method;
388 struct list_head datatypes;
390 struct fw3_address iprange;
391 struct fw3_port portrange;
399 const char *external;
406 struct list_head list;
407 struct list_head running_list;
411 enum fw3_family family;
414 enum fw3_include_type type;
419 struct uci_context *uci;
420 struct fw3_defaults defaults;
421 struct list_head zones;
422 struct list_head rules;
423 struct list_head redirects;
424 struct list_head forwards;
425 struct list_head ipsets;
426 struct list_head includes;
428 struct list_head running_zones;
429 struct list_head running_ipsets;
439 bool (*parse)(void *, const char *);
444 #define FW3_OPT(name, parse, structure, member) \
445 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
447 #define FW3_LIST(name, parse, structure, member) \
448 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
449 sizeof(struct fw3_##structure) }
452 bool fw3_parse_bool(void *ptr, const char *val);
453 bool fw3_parse_int(void *ptr, const char *val);
454 bool fw3_parse_string(void *ptr, const char *val);
455 bool fw3_parse_target(void *ptr, const char *val);
456 bool fw3_parse_limit(void *ptr, const char *val);
457 bool fw3_parse_device(void *ptr, const char *val);
458 bool fw3_parse_address(void *ptr, const char *val);
459 bool fw3_parse_mac(void *ptr, const char *val);
460 bool fw3_parse_port(void *ptr, const char *val);
461 bool fw3_parse_family(void *ptr, const char *val);
462 bool fw3_parse_icmptype(void *ptr, const char *val);
463 bool fw3_parse_protocol(void *ptr, const char *val);
465 bool fw3_parse_ipset_method(void *ptr, const char *val);
466 bool fw3_parse_ipset_datatype(void *ptr, const char *val);
468 bool fw3_parse_include_type(void *ptr, const char *val);
470 bool fw3_parse_date(void *ptr, const char *val);
471 bool fw3_parse_time(void *ptr, const char *val);
472 bool fw3_parse_weekdays(void *ptr, const char *val);
473 bool fw3_parse_monthdays(void *ptr, const char *val);
475 void fw3_parse_options(void *s, const struct fw3_option *opts,
476 struct uci_section *section);
478 void fw3_format_in_out(struct fw3_device *in, struct fw3_device *out);
479 void fw3_format_src_dest(struct fw3_address *src, struct fw3_address *dest);
480 void fw3_format_sport_dport(struct fw3_port *sp, struct fw3_port *dp);
481 void fw3_format_mac(struct fw3_mac *mac);
482 void fw3_format_protocol(struct fw3_protocol *proto, enum fw3_family family);
483 void fw3_format_icmptype(struct fw3_icmptype *icmp, enum fw3_family family);
484 void fw3_format_limit(struct fw3_limit *limit);
485 void fw3_format_ipset(struct fw3_ipset *ipset, bool invert);
486 void fw3_format_time(struct fw3_time *time);
488 void __fw3_format_comment(const char *comment, ...);
489 #define fw3_format_comment(...) __fw3_format_comment(__VA_ARGS__, NULL)
491 void fw3_format_extra(const char *extra);