2 * firewall3 - 3rd OpenWrt UCI firewall implementation
4 * Copyright (C) 2013-2014 Jo-Philipp Wich <jo@mein.io>
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>
37 #include <netinet/in.h>
38 #include <netinet/ether.h>
44 #include <libubox/list.h>
45 #include <libubox/utils.h>
46 #include <libubox/blobmsg.h>
48 #include "icmp_codes.h"
78 FW3_FLAG_MASQUERADE = 14,
79 FW3_FLAG_SRC_ACCEPT = 15,
80 FW3_FLAG_SRC_REJECT = 16,
81 FW3_FLAG_SRC_DROP = 17,
82 FW3_FLAG_CUSTOM_CHAINS = 18,
83 FW3_FLAG_SYN_FLOOD = 19,
84 FW3_FLAG_MTU_FIX = 20,
85 FW3_FLAG_DROP_INVALID = 21,
86 FW3_FLAG_HOTPLUG = 22,
91 extern const char *fw3_flag_names[__FW3_FLAG_MAX];
96 FW3_LIMIT_UNIT_SECOND = 0,
97 FW3_LIMIT_UNIT_MINUTE = 1,
98 FW3_LIMIT_UNIT_HOUR = 2,
99 FW3_LIMIT_UNIT_DAY = 3,
104 extern const char *fw3_limit_units[__FW3_LIMIT_UNIT_MAX];
107 enum fw3_ipset_method
109 FW3_IPSET_METHOD_UNSPEC = 0,
110 FW3_IPSET_METHOD_BITMAP = 1,
111 FW3_IPSET_METHOD_HASH = 2,
112 FW3_IPSET_METHOD_LIST = 3,
114 __FW3_IPSET_METHOD_MAX
119 FW3_IPSET_TYPE_UNSPEC = 0,
120 FW3_IPSET_TYPE_IP = 1,
121 FW3_IPSET_TYPE_PORT = 2,
122 FW3_IPSET_TYPE_MAC = 3,
123 FW3_IPSET_TYPE_NET = 4,
124 FW3_IPSET_TYPE_SET = 5,
129 extern const char *fw3_ipset_method_names[__FW3_IPSET_METHOD_MAX];
130 extern const char *fw3_ipset_type_names[__FW3_IPSET_TYPE_MAX];
133 enum fw3_include_type
135 FW3_INC_TYPE_SCRIPT = 0,
136 FW3_INC_TYPE_RESTORE = 1,
139 enum fw3_reflection_source
141 FW3_REFLECTION_INTERNAL = 0,
142 FW3_REFLECTION_EXTERNAL = 1,
145 struct fw3_ipset_datatype
147 struct list_head list;
148 enum fw3_ipset_type type;
158 struct fw3_ipset *ptr;
163 struct list_head list;
174 struct list_head list;
180 enum fw3_family family;
184 struct ether_addr mac;
189 struct ether_addr mac;
195 struct list_head list;
199 struct ether_addr mac;
204 struct list_head list;
213 struct list_head list;
223 struct list_head list;
226 enum fw3_family family;
240 enum fw3_limit_unit unit;
250 uint32_t monthdays; /* bit 0 is invert + 1 .. 31 */
251 uint8_t weekdays; /* bit 0 is invert + 1 .. 7 */
262 struct fw3_cthelpermatch
264 struct list_head list;
269 struct fw3_cthelper *ptr;
274 enum fw3_flag policy_input;
275 enum fw3_flag policy_output;
276 enum fw3_flag policy_forward;
281 struct fw3_limit syn_flood_rate;
285 bool tcp_window_scaling;
287 bool accept_redirects;
288 bool accept_source_route;
292 bool flow_offloading;
293 bool flow_offloading_hw;
302 struct list_head list;
307 enum fw3_family family;
309 enum fw3_flag policy_input;
310 enum fw3_flag policy_output;
311 enum fw3_flag policy_forward;
313 struct list_head networks;
314 struct list_head devices;
315 struct list_head subnets;
317 const char *extra_src;
318 const char *extra_dest;
321 bool masq_allow_invalid;
322 struct list_head masq_src;
323 struct list_head masq_dest;
327 struct list_head cthelpers;
330 struct fw3_limit log_limit;
337 struct list_head old_addrs;
342 struct list_head list;
347 enum fw3_family family;
349 struct fw3_zone *_src;
350 struct fw3_zone *_dest;
355 struct fw3_device src;
356 struct fw3_device dest;
357 struct fw3_setmatch ipset;
358 struct fw3_cthelpermatch helper;
360 struct list_head proto;
362 struct list_head ip_src;
363 struct list_head mac_src;
364 struct list_head port_src;
366 struct list_head ip_dest;
367 struct list_head port_dest;
369 struct list_head icmp_type;
371 struct fw3_limit limit;
372 struct fw3_time time;
373 struct fw3_mark mark;
375 enum fw3_flag target;
376 struct fw3_mark set_mark;
377 struct fw3_mark set_xmark;
378 struct fw3_cthelpermatch set_helper;
385 struct list_head list;
390 enum fw3_family family;
392 struct fw3_zone *_src;
393 struct fw3_zone *_dest;
395 struct fw3_device src;
396 struct fw3_device dest;
397 struct fw3_setmatch ipset;
398 struct fw3_cthelpermatch helper;
400 struct list_head proto;
402 struct fw3_address ip_src;
403 struct list_head mac_src;
404 struct fw3_port port_src;
406 struct fw3_address ip_dest;
407 struct fw3_port port_dest;
409 struct fw3_address ip_redir;
410 struct fw3_port port_redir;
412 struct fw3_limit limit;
413 struct fw3_time time;
414 struct fw3_mark mark;
416 enum fw3_flag target;
422 enum fw3_reflection_source reflection_src;
427 struct list_head list;
432 enum fw3_family family;
434 struct fw3_zone *_src;
436 struct fw3_device src;
437 struct fw3_setmatch ipset;
438 struct fw3_cthelpermatch helper;
441 struct list_head proto;
443 struct fw3_address ip_src;
444 struct fw3_port port_src;
446 struct fw3_address ip_dest;
447 struct fw3_port port_dest;
449 struct fw3_address ip_snat;
450 struct fw3_port port_snat;
452 struct fw3_limit limit;
453 struct fw3_time time;
454 struct fw3_mark mark;
455 bool connlimit_ports;
457 enum fw3_flag target;
464 struct list_head list;
469 enum fw3_family family;
471 struct fw3_zone *_src;
472 struct fw3_zone *_dest;
474 struct fw3_device src;
475 struct fw3_device dest;
480 struct list_head list;
484 enum fw3_family family;
486 enum fw3_ipset_method method;
487 struct list_head datatypes;
489 struct fw3_address iprange;
490 struct fw3_port portrange;
498 const char *external;
500 struct list_head entries;
501 const char *loadfile;
508 struct list_head list;
512 enum fw3_family family;
515 enum fw3_include_type type;
522 struct list_head list;
527 const char *description;
528 enum fw3_family family;
529 struct fw3_protocol proto;
530 struct fw3_port port;
535 struct list_head list;
541 struct uci_context *uci;
542 struct fw3_defaults defaults;
543 struct list_head zones;
544 struct list_head rules;
545 struct list_head redirects;
546 struct list_head snats;
547 struct list_head forwards;
548 struct list_head ipsets;
549 struct list_head includes;
550 struct list_head cthelpers;
556 struct fw3_chain_spec {
567 bool (*parse)(void *, const char *, bool);
572 #define FW3_OPT(name, parse, structure, member) \
573 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
575 #define FW3_LIST(name, parse, structure, member) \
576 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
577 sizeof(struct fw3_##structure) }
579 bool fw3_parse_bool(void *ptr, const char *val, bool is_list);
580 bool fw3_parse_int(void *ptr, const char *val, bool is_list);
581 bool fw3_parse_string(void *ptr, const char *val, bool is_list);
582 bool fw3_parse_target(void *ptr, const char *val, bool is_list);
583 bool fw3_parse_limit(void *ptr, const char *val, bool is_list);
584 bool fw3_parse_device(void *ptr, const char *val, bool is_list);
585 bool fw3_parse_address(void *ptr, const char *val, bool is_list);
586 bool fw3_parse_network(void *ptr, const char *val, bool is_list);
587 bool fw3_parse_mac(void *ptr, const char *val, bool is_list);
588 bool fw3_parse_port(void *ptr, const char *val, bool is_list);
589 bool fw3_parse_family(void *ptr, const char *val, bool is_list);
590 bool fw3_parse_icmptype(void *ptr, const char *val, bool is_list);
591 bool fw3_parse_protocol(void *ptr, const char *val, bool is_list);
593 bool fw3_parse_ipset_method(void *ptr, const char *val, bool is_list);
594 bool fw3_parse_ipset_datatype(void *ptr, const char *val, bool is_list);
596 bool fw3_parse_include_type(void *ptr, const char *val, bool is_list);
597 bool fw3_parse_reflection_source(void *ptr, const char *val, bool is_list);
599 bool fw3_parse_date(void *ptr, const char *val, bool is_list);
600 bool fw3_parse_time(void *ptr, const char *val, bool is_list);
601 bool fw3_parse_weekdays(void *ptr, const char *val, bool is_list);
602 bool fw3_parse_monthdays(void *ptr, const char *val, bool is_list);
603 bool fw3_parse_mark(void *ptr, const char *val, bool is_list);
604 bool fw3_parse_setmatch(void *ptr, const char *val, bool is_list);
605 bool fw3_parse_direction(void *ptr, const char *val, bool is_list);
606 bool fw3_parse_cthelper(void *ptr, const char *val, bool is_list);
607 bool fw3_parse_setentry(void *ptr, const char *val, bool is_list);
609 bool fw3_parse_options(void *s, const struct fw3_option *opts,
610 struct uci_section *section);
611 bool fw3_parse_blob_options(void *s, const struct fw3_option *opts,
612 struct blob_attr *a, const char *name);
614 const char * fw3_address_to_string(struct fw3_address *address,
615 bool allow_invert, bool as_cidr);