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"
73 FW3_FLAG_SRC_ACCEPT = 12,
74 FW3_FLAG_SRC_REJECT = 13,
75 FW3_FLAG_SRC_DROP = 14,
76 FW3_FLAG_CUSTOM_CHAINS = 15,
77 FW3_FLAG_SYN_FLOOD = 16,
78 FW3_FLAG_MTU_FIX = 17,
79 FW3_FLAG_DROP_INVALID = 18,
80 FW3_FLAG_HOTPLUG = 19,
81 FW3_FLAG_DELETED = 20,
86 extern const char *fw3_flag_names[__FW3_FLAG_MAX];
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 enum fw3_reflection_source
123 FW3_REFLECTION_INTERNAL = 0,
124 FW3_REFLECTION_EXTERNAL = 1,
127 struct fw3_ipset_datatype
129 struct list_head list;
130 enum fw3_ipset_type type;
136 struct list_head list;
142 struct fw3_device *network;
147 struct list_head list;
152 enum fw3_family family;
157 struct ether_addr mac;
162 struct ether_addr mac;
168 struct list_head list;
172 struct ether_addr mac;
177 struct list_head list;
186 struct list_head list;
196 struct list_head list;
199 enum fw3_family family;
213 enum fw3_limit_unit unit;
223 uint32_t monthdays; /* bit 0 is invert + 1 .. 31 */
224 uint8_t weekdays; /* bit 0 is invert + 1 .. 7 */
229 enum fw3_flag policy_input;
230 enum fw3_flag policy_output;
231 enum fw3_flag policy_forward;
236 struct fw3_limit syn_flood_rate;
240 bool tcp_window_scaling;
242 bool accept_redirects;
243 bool accept_source_route;
254 struct list_head list;
255 struct list_head running_list;
260 enum fw3_family family;
262 enum fw3_flag policy_input;
263 enum fw3_flag policy_output;
264 enum fw3_flag policy_forward;
266 struct list_head networks;
267 struct list_head devices;
268 struct list_head subnets;
270 struct list_head running_networks;
271 struct list_head running_devices;
273 const char *extra_src;
274 const char *extra_dest;
277 struct list_head masq_src;
278 struct list_head masq_dest;
284 struct fw3_limit log_limit;
293 struct list_head list;
298 enum fw3_family family;
300 struct fw3_zone *_src;
301 struct fw3_zone *_dest;
303 struct fw3_device src;
304 struct fw3_device dest;
306 struct fw3_ipset *_ipset;
307 struct fw3_device ipset;
309 struct list_head proto;
311 struct list_head ip_src;
312 struct list_head mac_src;
313 struct list_head port_src;
315 struct list_head ip_dest;
316 struct list_head port_dest;
318 struct list_head icmp_type;
320 struct fw3_limit limit;
321 struct fw3_time time;
323 enum fw3_flag target;
330 struct list_head list;
335 enum fw3_family family;
337 struct fw3_zone *_src;
338 struct fw3_zone *_dest;
340 struct fw3_device src;
341 struct fw3_device dest;
343 struct fw3_ipset *_ipset;
344 struct fw3_device ipset;
346 struct list_head proto;
348 struct fw3_address ip_src;
349 struct list_head mac_src;
350 struct fw3_port port_src;
352 struct fw3_address ip_dest;
353 struct fw3_port port_dest;
355 struct fw3_address ip_redir;
356 struct fw3_port port_redir;
358 struct fw3_time time;
360 enum fw3_flag target;
365 enum fw3_reflection_source reflection_src;
370 struct list_head list;
375 enum fw3_family family;
377 struct fw3_zone *_src;
378 struct fw3_zone *_dest;
380 struct fw3_device src;
381 struct fw3_device dest;
386 struct list_head list;
387 struct list_head running_list;
391 enum fw3_family family;
393 enum fw3_ipset_method method;
394 struct list_head datatypes;
396 struct fw3_address iprange;
397 struct fw3_port portrange;
405 const char *external;
412 struct list_head list;
413 struct list_head running_list;
417 enum fw3_family family;
420 enum fw3_include_type type;
427 struct uci_context *uci;
428 struct fw3_defaults defaults;
429 struct list_head zones;
430 struct list_head rules;
431 struct list_head redirects;
432 struct list_head forwards;
433 struct list_head ipsets;
434 struct list_head includes;
436 struct list_head running_zones;
437 struct list_head running_ipsets;
447 bool (*parse)(void *, const char *, bool);
452 #define FW3_OPT(name, parse, structure, member) \
453 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
455 #define FW3_LIST(name, parse, structure, member) \
456 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
457 sizeof(struct fw3_##structure) }
459 bool fw3_parse_bool(void *ptr, const char *val, bool is_list);
460 bool fw3_parse_int(void *ptr, const char *val, bool is_list);
461 bool fw3_parse_string(void *ptr, const char *val, bool is_list);
462 bool fw3_parse_target(void *ptr, const char *val, bool is_list);
463 bool fw3_parse_limit(void *ptr, const char *val, bool is_list);
464 bool fw3_parse_device(void *ptr, const char *val, bool is_list);
465 bool fw3_parse_address(void *ptr, const char *val, bool is_list);
466 bool fw3_parse_network(void *ptr, const char *val, bool is_list);
467 bool fw3_parse_mac(void *ptr, const char *val, bool is_list);
468 bool fw3_parse_port(void *ptr, const char *val, bool is_list);
469 bool fw3_parse_family(void *ptr, const char *val, bool is_list);
470 bool fw3_parse_icmptype(void *ptr, const char *val, bool is_list);
471 bool fw3_parse_protocol(void *ptr, const char *val, bool is_list);
473 bool fw3_parse_ipset_method(void *ptr, const char *val, bool is_list);
474 bool fw3_parse_ipset_datatype(void *ptr, const char *val, bool is_list);
476 bool fw3_parse_include_type(void *ptr, const char *val, bool is_list);
477 bool fw3_parse_reflection_source(void *ptr, const char *val, bool is_list);
479 bool fw3_parse_date(void *ptr, const char *val, bool is_list);
480 bool fw3_parse_time(void *ptr, const char *val, bool is_list);
481 bool fw3_parse_weekdays(void *ptr, const char *val, bool is_list);
482 bool fw3_parse_monthdays(void *ptr, const char *val, bool is_list);
484 void fw3_parse_options(void *s, const struct fw3_option *opts,
485 struct uci_section *section);
487 void fw3_format_in_out(struct fw3_device *in, struct fw3_device *out);
488 void fw3_format_src_dest(struct fw3_address *src, struct fw3_address *dest);
489 void fw3_format_sport_dport(struct fw3_port *sp, struct fw3_port *dp);
490 void fw3_format_mac(struct fw3_mac *mac);
491 void fw3_format_protocol(struct fw3_protocol *proto, enum fw3_family family);
492 void fw3_format_icmptype(struct fw3_icmptype *icmp, enum fw3_family family);
493 void fw3_format_limit(struct fw3_limit *limit);
494 void fw3_format_ipset(struct fw3_ipset *ipset, bool invert);
495 void fw3_format_time(struct fw3_time *time);
497 void __fw3_format_comment(const char *comment, ...);
498 #define fw3_format_comment(...) __fw3_format_comment(__VA_ARGS__, NULL)
500 void fw3_format_extra(const char *extra);