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
;
300 struct list_head list
;
305 enum fw3_family family
;
307 enum fw3_flag policy_input
;
308 enum fw3_flag policy_output
;
309 enum fw3_flag policy_forward
;
311 struct list_head networks
;
312 struct list_head devices
;
313 struct list_head subnets
;
315 const char *extra_src
;
316 const char *extra_dest
;
319 bool masq_allow_invalid
;
320 struct list_head masq_src
;
321 struct list_head masq_dest
;
325 struct list_head cthelpers
;
328 struct fw3_limit log_limit
;
335 struct list_head old_addrs
;
340 struct list_head list
;
345 enum fw3_family family
;
347 struct fw3_zone
*_src
;
348 struct fw3_zone
*_dest
;
353 struct fw3_device src
;
354 struct fw3_device dest
;
355 struct fw3_setmatch ipset
;
356 struct fw3_cthelpermatch helper
;
358 struct list_head proto
;
360 struct list_head ip_src
;
361 struct list_head mac_src
;
362 struct list_head port_src
;
364 struct list_head ip_dest
;
365 struct list_head port_dest
;
367 struct list_head icmp_type
;
369 struct fw3_limit limit
;
370 struct fw3_time time
;
371 struct fw3_mark mark
;
373 enum fw3_flag target
;
374 struct fw3_mark set_mark
;
375 struct fw3_mark set_xmark
;
376 struct fw3_cthelpermatch set_helper
;
383 struct list_head list
;
388 enum fw3_family family
;
390 struct fw3_zone
*_src
;
391 struct fw3_zone
*_dest
;
393 struct fw3_device src
;
394 struct fw3_device dest
;
395 struct fw3_setmatch ipset
;
396 struct fw3_cthelpermatch helper
;
398 struct list_head proto
;
400 struct fw3_address ip_src
;
401 struct list_head mac_src
;
402 struct fw3_port port_src
;
404 struct fw3_address ip_dest
;
405 struct fw3_port port_dest
;
407 struct fw3_address ip_redir
;
408 struct fw3_port port_redir
;
410 struct fw3_limit limit
;
411 struct fw3_time time
;
412 struct fw3_mark mark
;
414 enum fw3_flag target
;
420 enum fw3_reflection_source reflection_src
;
425 struct list_head list
;
430 enum fw3_family family
;
432 struct fw3_zone
*_src
;
434 struct fw3_device src
;
435 struct fw3_setmatch ipset
;
436 struct fw3_cthelpermatch helper
;
439 struct list_head proto
;
441 struct fw3_address ip_src
;
442 struct fw3_port port_src
;
444 struct fw3_address ip_dest
;
445 struct fw3_port port_dest
;
447 struct fw3_address ip_snat
;
448 struct fw3_port port_snat
;
450 struct fw3_limit limit
;
451 struct fw3_time time
;
452 struct fw3_mark mark
;
453 bool connlimit_ports
;
455 enum fw3_flag target
;
462 struct list_head list
;
467 enum fw3_family family
;
469 struct fw3_zone
*_src
;
470 struct fw3_zone
*_dest
;
472 struct fw3_device src
;
473 struct fw3_device dest
;
478 struct list_head list
;
482 enum fw3_family family
;
484 enum fw3_ipset_method method
;
485 struct list_head datatypes
;
487 struct fw3_address iprange
;
488 struct fw3_port portrange
;
496 const char *external
;
503 struct list_head list
;
507 enum fw3_family family
;
510 enum fw3_include_type type
;
517 struct list_head list
;
522 const char *description
;
523 enum fw3_family family
;
524 struct fw3_protocol proto
;
525 struct fw3_port port
;
530 struct uci_context
*uci
;
531 struct fw3_defaults defaults
;
532 struct list_head zones
;
533 struct list_head rules
;
534 struct list_head redirects
;
535 struct list_head snats
;
536 struct list_head forwards
;
537 struct list_head ipsets
;
538 struct list_head includes
;
539 struct list_head cthelpers
;
545 struct fw3_chain_spec
{
556 bool (*parse
)(void *, const char *, bool);
561 #define FW3_OPT(name, parse, structure, member) \
562 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
564 #define FW3_LIST(name, parse, structure, member) \
565 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
566 sizeof(struct fw3_##structure) }
568 bool fw3_parse_bool(void *ptr
, const char *val
, bool is_list
);
569 bool fw3_parse_int(void *ptr
, const char *val
, bool is_list
);
570 bool fw3_parse_string(void *ptr
, const char *val
, bool is_list
);
571 bool fw3_parse_target(void *ptr
, const char *val
, bool is_list
);
572 bool fw3_parse_limit(void *ptr
, const char *val
, bool is_list
);
573 bool fw3_parse_device(void *ptr
, const char *val
, bool is_list
);
574 bool fw3_parse_address(void *ptr
, const char *val
, bool is_list
);
575 bool fw3_parse_network(void *ptr
, const char *val
, bool is_list
);
576 bool fw3_parse_mac(void *ptr
, const char *val
, bool is_list
);
577 bool fw3_parse_port(void *ptr
, const char *val
, bool is_list
);
578 bool fw3_parse_family(void *ptr
, const char *val
, bool is_list
);
579 bool fw3_parse_icmptype(void *ptr
, const char *val
, bool is_list
);
580 bool fw3_parse_protocol(void *ptr
, const char *val
, bool is_list
);
582 bool fw3_parse_ipset_method(void *ptr
, const char *val
, bool is_list
);
583 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
, bool is_list
);
585 bool fw3_parse_include_type(void *ptr
, const char *val
, bool is_list
);
586 bool fw3_parse_reflection_source(void *ptr
, const char *val
, bool is_list
);
588 bool fw3_parse_date(void *ptr
, const char *val
, bool is_list
);
589 bool fw3_parse_time(void *ptr
, const char *val
, bool is_list
);
590 bool fw3_parse_weekdays(void *ptr
, const char *val
, bool is_list
);
591 bool fw3_parse_monthdays(void *ptr
, const char *val
, bool is_list
);
592 bool fw3_parse_mark(void *ptr
, const char *val
, bool is_list
);
593 bool fw3_parse_setmatch(void *ptr
, const char *val
, bool is_list
);
594 bool fw3_parse_direction(void *ptr
, const char *val
, bool is_list
);
595 bool fw3_parse_cthelper(void *ptr
, const char *val
, bool is_list
);
597 bool fw3_parse_options(void *s
, const struct fw3_option
*opts
,
598 struct uci_section
*section
);
599 bool fw3_parse_blob_options(void *s
, const struct fw3_option
*opts
,
600 struct blob_attr
*a
, const char *name
);
602 const char * fw3_address_to_string(struct fw3_address
*address
,
603 bool allow_invert
, bool as_cidr
);