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,
93 FW3_REJECT_CODE_TCP_RESET
= 0,
94 FW3_REJECT_CODE_PORT_UNREACH
= 1,
95 FW3_REJECT_CODE_ADM_PROHIBITED
= 2,
100 extern const char *fw3_flag_names
[__FW3_FLAG_MAX
];
105 FW3_LIMIT_UNIT_SECOND
= 0,
106 FW3_LIMIT_UNIT_MINUTE
= 1,
107 FW3_LIMIT_UNIT_HOUR
= 2,
108 FW3_LIMIT_UNIT_DAY
= 3,
113 extern const char *fw3_limit_units
[__FW3_LIMIT_UNIT_MAX
];
116 enum fw3_ipset_method
118 FW3_IPSET_METHOD_UNSPEC
= 0,
119 FW3_IPSET_METHOD_BITMAP
= 1,
120 FW3_IPSET_METHOD_HASH
= 2,
121 FW3_IPSET_METHOD_LIST
= 3,
123 __FW3_IPSET_METHOD_MAX
128 FW3_IPSET_TYPE_UNSPEC
= 0,
129 FW3_IPSET_TYPE_IP
= 1,
130 FW3_IPSET_TYPE_PORT
= 2,
131 FW3_IPSET_TYPE_MAC
= 3,
132 FW3_IPSET_TYPE_NET
= 4,
133 FW3_IPSET_TYPE_SET
= 5,
138 extern const char *fw3_ipset_method_names
[__FW3_IPSET_METHOD_MAX
];
139 extern const char *fw3_ipset_type_names
[__FW3_IPSET_TYPE_MAX
];
142 enum fw3_include_type
144 FW3_INC_TYPE_SCRIPT
= 0,
145 FW3_INC_TYPE_RESTORE
= 1,
148 enum fw3_reflection_source
150 FW3_REFLECTION_INTERNAL
= 0,
151 FW3_REFLECTION_EXTERNAL
= 1,
154 struct fw3_ipset_datatype
156 struct list_head list
;
157 enum fw3_ipset_type type
;
167 struct fw3_ipset
*ptr
;
172 struct list_head list
;
183 struct list_head list
;
189 enum fw3_family family
;
193 struct ether_addr mac
;
198 struct ether_addr mac
;
204 struct list_head list
;
208 struct ether_addr mac
;
213 struct list_head list
;
222 struct list_head list
;
232 struct list_head list
;
235 enum fw3_family family
;
249 enum fw3_limit_unit unit
;
259 uint32_t monthdays
; /* bit 0 is invert + 1 .. 31 */
260 uint8_t weekdays
; /* bit 0 is invert + 1 .. 7 */
271 struct fw3_cthelpermatch
273 struct list_head list
;
278 struct fw3_cthelper
*ptr
;
283 enum fw3_flag policy_input
;
284 enum fw3_flag policy_output
;
285 enum fw3_flag policy_forward
;
288 enum fw3_reject_code tcp_reject_code
;
289 enum fw3_reject_code any_reject_code
;
292 struct fw3_limit syn_flood_rate
;
296 bool tcp_window_scaling
;
298 bool accept_redirects
;
299 bool accept_source_route
;
303 bool flow_offloading
;
304 bool flow_offloading_hw
;
313 struct list_head list
;
318 enum fw3_family family
;
320 enum fw3_flag policy_input
;
321 enum fw3_flag policy_output
;
322 enum fw3_flag policy_forward
;
324 struct list_head networks
;
325 struct list_head devices
;
326 struct list_head subnets
;
328 const char *extra_src
;
329 const char *extra_dest
;
332 bool masq_allow_invalid
;
333 struct list_head masq_src
;
334 struct list_head masq_dest
;
338 struct list_head cthelpers
;
341 struct fw3_limit log_limit
;
348 struct list_head old_addrs
;
353 struct list_head list
;
358 enum fw3_family family
;
360 struct fw3_zone
*_src
;
361 struct fw3_zone
*_dest
;
366 struct fw3_device src
;
367 struct fw3_device dest
;
368 struct fw3_setmatch ipset
;
369 struct fw3_cthelpermatch helper
;
371 struct list_head proto
;
373 struct list_head ip_src
;
374 struct list_head mac_src
;
375 struct list_head port_src
;
377 struct list_head ip_dest
;
378 struct list_head port_dest
;
380 struct list_head icmp_type
;
382 struct fw3_limit limit
;
383 struct fw3_time time
;
384 struct fw3_mark mark
;
386 enum fw3_flag target
;
387 struct fw3_mark set_mark
;
388 struct fw3_mark set_xmark
;
389 struct fw3_cthelpermatch set_helper
;
396 struct list_head list
;
401 enum fw3_family family
;
403 struct fw3_zone
*_src
;
404 struct fw3_zone
*_dest
;
406 struct fw3_device src
;
407 struct fw3_device dest
;
408 struct fw3_setmatch ipset
;
409 struct fw3_cthelpermatch helper
;
411 struct list_head proto
;
413 struct fw3_address ip_src
;
414 struct list_head mac_src
;
415 struct fw3_port port_src
;
417 struct fw3_address ip_dest
;
418 struct fw3_port port_dest
;
420 struct fw3_address ip_redir
;
421 struct fw3_port port_redir
;
423 struct fw3_limit limit
;
424 struct fw3_time time
;
425 struct fw3_mark mark
;
427 enum fw3_flag target
;
433 enum fw3_reflection_source reflection_src
;
438 struct list_head list
;
443 enum fw3_family family
;
445 struct fw3_zone
*_src
;
447 struct fw3_device src
;
448 struct fw3_setmatch ipset
;
449 struct fw3_cthelpermatch helper
;
452 struct list_head proto
;
454 struct fw3_address ip_src
;
455 struct fw3_port port_src
;
457 struct fw3_address ip_dest
;
458 struct fw3_port port_dest
;
460 struct fw3_address ip_snat
;
461 struct fw3_port port_snat
;
463 struct fw3_limit limit
;
464 struct fw3_time time
;
465 struct fw3_mark mark
;
466 bool connlimit_ports
;
468 enum fw3_flag target
;
475 struct list_head list
;
480 enum fw3_family family
;
482 struct fw3_zone
*_src
;
483 struct fw3_zone
*_dest
;
485 struct fw3_device src
;
486 struct fw3_device dest
;
491 struct list_head list
;
495 enum fw3_family family
;
497 enum fw3_ipset_method method
;
498 struct list_head datatypes
;
500 struct fw3_address iprange
;
501 struct fw3_port portrange
;
509 const char *external
;
511 struct list_head entries
;
512 const char *loadfile
;
519 struct list_head list
;
523 enum fw3_family family
;
526 enum fw3_include_type type
;
533 struct list_head list
;
538 const char *description
;
539 enum fw3_family family
;
540 struct list_head proto
;
541 struct fw3_port port
;
546 struct list_head list
;
552 struct uci_context
*uci
;
553 struct fw3_defaults defaults
;
554 struct list_head zones
;
555 struct list_head rules
;
556 struct list_head redirects
;
557 struct list_head snats
;
558 struct list_head forwards
;
559 struct list_head ipsets
;
560 struct list_head includes
;
561 struct list_head cthelpers
;
567 struct fw3_chain_spec
{
578 bool (*parse
)(void *, const char *, bool);
583 #define FW3_OPT(name, parse, structure, member) \
584 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
586 #define FW3_LIST(name, parse, structure, member) \
587 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
588 sizeof(struct fw3_##structure) }
590 bool fw3_parse_bool(void *ptr
, const char *val
, bool is_list
);
591 bool fw3_parse_int(void *ptr
, const char *val
, bool is_list
);
592 bool fw3_parse_string(void *ptr
, const char *val
, bool is_list
);
593 bool fw3_parse_target(void *ptr
, const char *val
, bool is_list
);
594 bool fw3_parse_reject_code(void *ptr
, const char *val
, bool is_list
);
595 bool fw3_parse_limit(void *ptr
, const char *val
, bool is_list
);
596 bool fw3_parse_device(void *ptr
, const char *val
, bool is_list
);
597 bool fw3_parse_address(void *ptr
, const char *val
, bool is_list
);
598 bool fw3_parse_network(void *ptr
, const char *val
, bool is_list
);
599 bool fw3_parse_mac(void *ptr
, const char *val
, bool is_list
);
600 bool fw3_parse_port(void *ptr
, const char *val
, bool is_list
);
601 bool fw3_parse_family(void *ptr
, const char *val
, bool is_list
);
602 bool fw3_parse_icmptype(void *ptr
, const char *val
, bool is_list
);
603 bool fw3_parse_protocol(void *ptr
, const char *val
, bool is_list
);
605 bool fw3_parse_ipset_method(void *ptr
, const char *val
, bool is_list
);
606 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
, bool is_list
);
608 bool fw3_parse_include_type(void *ptr
, const char *val
, bool is_list
);
609 bool fw3_parse_reflection_source(void *ptr
, const char *val
, bool is_list
);
611 bool fw3_parse_date(void *ptr
, const char *val
, bool is_list
);
612 bool fw3_parse_time(void *ptr
, const char *val
, bool is_list
);
613 bool fw3_parse_weekdays(void *ptr
, const char *val
, bool is_list
);
614 bool fw3_parse_monthdays(void *ptr
, const char *val
, bool is_list
);
615 bool fw3_parse_mark(void *ptr
, const char *val
, bool is_list
);
616 bool fw3_parse_setmatch(void *ptr
, const char *val
, bool is_list
);
617 bool fw3_parse_direction(void *ptr
, const char *val
, bool is_list
);
618 bool fw3_parse_cthelper(void *ptr
, const char *val
, bool is_list
);
619 bool fw3_parse_setentry(void *ptr
, const char *val
, bool is_list
);
621 bool fw3_parse_options(void *s
, const struct fw3_option
*opts
,
622 struct uci_section
*section
);
623 bool fw3_parse_blob_options(void *s
, const struct fw3_option
*opts
,
624 struct blob_attr
*a
, const char *name
);
626 const char * fw3_address_to_string(struct fw3_address
*address
,
627 bool allow_invert
, bool as_cidr
);