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"
79 FW3_FLAG_MASQUERADE
= 15,
80 FW3_FLAG_SRC_ACCEPT
= 16,
81 FW3_FLAG_SRC_REJECT
= 17,
82 FW3_FLAG_SRC_DROP
= 18,
83 FW3_FLAG_CUSTOM_CHAINS
= 19,
84 FW3_FLAG_SYN_FLOOD
= 20,
85 FW3_FLAG_MTU_FIX
= 21,
86 FW3_FLAG_DROP_INVALID
= 22,
87 FW3_FLAG_HOTPLUG
= 23,
94 FW3_REJECT_CODE_TCP_RESET
= 0,
95 FW3_REJECT_CODE_PORT_UNREACH
= 1,
96 FW3_REJECT_CODE_ADM_PROHIBITED
= 2,
101 extern const char *fw3_flag_names
[__FW3_FLAG_MAX
];
106 FW3_LIMIT_UNIT_SECOND
= 0,
107 FW3_LIMIT_UNIT_MINUTE
= 1,
108 FW3_LIMIT_UNIT_HOUR
= 2,
109 FW3_LIMIT_UNIT_DAY
= 3,
114 extern const char *fw3_limit_units
[__FW3_LIMIT_UNIT_MAX
];
117 enum fw3_ipset_method
119 FW3_IPSET_METHOD_UNSPEC
= 0,
120 FW3_IPSET_METHOD_BITMAP
= 1,
121 FW3_IPSET_METHOD_HASH
= 2,
122 FW3_IPSET_METHOD_LIST
= 3,
124 __FW3_IPSET_METHOD_MAX
129 FW3_IPSET_TYPE_UNSPEC
= 0,
130 FW3_IPSET_TYPE_IP
= 1,
131 FW3_IPSET_TYPE_PORT
= 2,
132 FW3_IPSET_TYPE_MAC
= 3,
133 FW3_IPSET_TYPE_NET
= 4,
134 FW3_IPSET_TYPE_SET
= 5,
139 extern const char *fw3_ipset_method_names
[__FW3_IPSET_METHOD_MAX
];
140 extern const char *fw3_ipset_type_names
[__FW3_IPSET_TYPE_MAX
];
143 enum fw3_include_type
145 FW3_INC_TYPE_SCRIPT
= 0,
146 FW3_INC_TYPE_RESTORE
= 1,
149 enum fw3_reflection_source
151 FW3_REFLECTION_INTERNAL
= 0,
152 FW3_REFLECTION_EXTERNAL
= 1,
155 struct fw3_ipset_datatype
157 struct list_head list
;
158 enum fw3_ipset_type type
;
168 struct fw3_ipset
*ptr
;
173 struct list_head list
;
184 struct list_head list
;
190 enum fw3_family family
;
194 struct ether_addr mac
;
199 struct ether_addr mac
;
205 struct list_head list
;
209 struct ether_addr mac
;
214 struct list_head list
;
223 struct list_head list
;
233 struct list_head list
;
236 enum fw3_family family
;
250 enum fw3_limit_unit unit
;
260 uint32_t monthdays
; /* bit 0 is invert + 1 .. 31 */
261 uint8_t weekdays
; /* bit 0 is invert + 1 .. 7 */
279 struct fw3_cthelpermatch
281 struct list_head list
;
286 struct fw3_cthelper
*ptr
;
291 enum fw3_flag policy_input
;
292 enum fw3_flag policy_output
;
293 enum fw3_flag policy_forward
;
296 enum fw3_reject_code tcp_reject_code
;
297 enum fw3_reject_code any_reject_code
;
300 struct fw3_limit syn_flood_rate
;
304 bool tcp_window_scaling
;
306 bool accept_redirects
;
307 bool accept_source_route
;
311 bool flow_offloading
;
312 bool flow_offloading_hw
;
321 struct list_head list
;
326 enum fw3_family family
;
328 enum fw3_flag policy_input
;
329 enum fw3_flag policy_output
;
330 enum fw3_flag policy_forward
;
332 struct list_head networks
;
333 struct list_head devices
;
334 struct list_head subnets
;
336 const char *extra_src
;
337 const char *extra_dest
;
340 bool masq_allow_invalid
;
341 struct list_head masq_src
;
342 struct list_head masq_dest
;
346 struct list_head cthelpers
;
349 struct fw3_limit log_limit
;
356 struct list_head old_addrs
;
361 struct list_head list
;
366 enum fw3_family family
;
368 struct fw3_zone
*_src
;
369 struct fw3_zone
*_dest
;
374 struct fw3_device src
;
375 struct fw3_device dest
;
376 struct fw3_setmatch ipset
;
377 struct fw3_cthelpermatch helper
;
379 struct list_head proto
;
381 struct list_head ip_src
;
382 struct list_head mac_src
;
383 struct list_head port_src
;
385 struct list_head ip_dest
;
386 struct list_head port_dest
;
388 struct list_head icmp_type
;
390 struct fw3_limit limit
;
391 struct fw3_time time
;
392 struct fw3_mark mark
;
393 struct fw3_dscp dscp
;
395 enum fw3_flag target
;
396 struct fw3_mark set_mark
;
397 struct fw3_mark set_xmark
;
398 struct fw3_dscp set_dscp
;
399 struct fw3_cthelpermatch set_helper
;
406 struct list_head list
;
411 enum fw3_family family
;
413 struct fw3_zone
*_src
;
414 struct fw3_zone
*_dest
;
416 struct fw3_device src
;
417 struct fw3_device dest
;
418 struct fw3_setmatch ipset
;
419 struct fw3_cthelpermatch helper
;
421 struct list_head proto
;
423 struct fw3_address ip_src
;
424 struct list_head mac_src
;
425 struct fw3_port port_src
;
427 struct fw3_address ip_dest
;
428 struct fw3_port port_dest
;
430 struct fw3_address ip_redir
;
431 struct fw3_port port_redir
;
433 struct fw3_limit limit
;
434 struct fw3_time time
;
435 struct fw3_mark mark
;
437 enum fw3_flag target
;
443 enum fw3_reflection_source reflection_src
;
448 struct list_head list
;
453 enum fw3_family family
;
455 struct fw3_zone
*_src
;
457 struct fw3_device src
;
458 struct fw3_setmatch ipset
;
459 struct fw3_cthelpermatch helper
;
462 struct list_head proto
;
464 struct fw3_address ip_src
;
465 struct fw3_port port_src
;
467 struct fw3_address ip_dest
;
468 struct fw3_port port_dest
;
470 struct fw3_address ip_snat
;
471 struct fw3_port port_snat
;
473 struct fw3_limit limit
;
474 struct fw3_time time
;
475 struct fw3_mark mark
;
476 bool connlimit_ports
;
478 enum fw3_flag target
;
485 struct list_head list
;
490 enum fw3_family family
;
492 struct fw3_zone
*_src
;
493 struct fw3_zone
*_dest
;
495 struct fw3_device src
;
496 struct fw3_device dest
;
501 struct list_head list
;
505 enum fw3_family family
;
507 enum fw3_ipset_method method
;
508 struct list_head datatypes
;
510 struct fw3_address iprange
;
511 struct fw3_port portrange
;
519 const char *external
;
521 struct list_head entries
;
522 const char *loadfile
;
529 struct list_head list
;
533 enum fw3_family family
;
536 enum fw3_include_type type
;
543 struct list_head list
;
548 const char *description
;
549 enum fw3_family family
;
550 struct list_head proto
;
551 struct fw3_port port
;
556 struct list_head list
;
562 struct uci_context
*uci
;
563 struct fw3_defaults defaults
;
564 struct list_head zones
;
565 struct list_head rules
;
566 struct list_head redirects
;
567 struct list_head snats
;
568 struct list_head forwards
;
569 struct list_head ipsets
;
570 struct list_head includes
;
571 struct list_head cthelpers
;
577 struct fw3_chain_spec
{
588 bool (*parse
)(void *, const char *, bool);
593 #define FW3_OPT(name, parse, structure, member) \
594 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
596 #define FW3_LIST(name, parse, structure, member) \
597 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
598 sizeof(struct fw3_##structure) }
600 bool fw3_parse_bool(void *ptr
, const char *val
, bool is_list
);
601 bool fw3_parse_int(void *ptr
, const char *val
, bool is_list
);
602 bool fw3_parse_string(void *ptr
, const char *val
, bool is_list
);
603 bool fw3_parse_target(void *ptr
, const char *val
, bool is_list
);
604 bool fw3_parse_reject_code(void *ptr
, const char *val
, bool is_list
);
605 bool fw3_parse_limit(void *ptr
, const char *val
, bool is_list
);
606 bool fw3_parse_device(void *ptr
, const char *val
, bool is_list
);
607 bool fw3_parse_address(void *ptr
, const char *val
, bool is_list
);
608 bool fw3_parse_network(void *ptr
, const char *val
, bool is_list
);
609 bool fw3_parse_mac(void *ptr
, const char *val
, bool is_list
);
610 bool fw3_parse_port(void *ptr
, const char *val
, bool is_list
);
611 bool fw3_parse_family(void *ptr
, const char *val
, bool is_list
);
612 bool fw3_parse_icmptype(void *ptr
, const char *val
, bool is_list
);
613 bool fw3_parse_protocol(void *ptr
, const char *val
, bool is_list
);
615 bool fw3_parse_ipset_method(void *ptr
, const char *val
, bool is_list
);
616 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
, bool is_list
);
618 bool fw3_parse_include_type(void *ptr
, const char *val
, bool is_list
);
619 bool fw3_parse_reflection_source(void *ptr
, const char *val
, bool is_list
);
621 bool fw3_parse_date(void *ptr
, const char *val
, bool is_list
);
622 bool fw3_parse_time(void *ptr
, const char *val
, bool is_list
);
623 bool fw3_parse_weekdays(void *ptr
, const char *val
, bool is_list
);
624 bool fw3_parse_monthdays(void *ptr
, const char *val
, bool is_list
);
625 bool fw3_parse_mark(void *ptr
, const char *val
, bool is_list
);
626 bool fw3_parse_dscp(void *ptr
, const char *val
, bool is_list
);
627 bool fw3_parse_setmatch(void *ptr
, const char *val
, bool is_list
);
628 bool fw3_parse_direction(void *ptr
, const char *val
, bool is_list
);
629 bool fw3_parse_cthelper(void *ptr
, const char *val
, bool is_list
);
630 bool fw3_parse_setentry(void *ptr
, const char *val
, bool is_list
);
632 bool fw3_parse_options(void *s
, const struct fw3_option
*opts
,
633 struct uci_section
*section
);
634 bool fw3_parse_blob_options(void *s
, const struct fw3_option
*opts
,
635 struct blob_attr
*a
, const char *name
);
637 const char * fw3_address_to_string(struct fw3_address
*address
,
638 bool allow_invert
, bool as_cidr
);