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>
35 #include <netinet/in.h>
36 #include <netinet/ether.h>
42 #include <libubox/list.h>
43 #include <libubox/utils.h>
44 #include <libubox/blobmsg.h>
46 #include "icmp_codes.h"
75 FW3_FLAG_MASQUERADE
= 13,
76 FW3_FLAG_SRC_ACCEPT
= 14,
77 FW3_FLAG_SRC_REJECT
= 15,
78 FW3_FLAG_SRC_DROP
= 16,
79 FW3_FLAG_CUSTOM_CHAINS
= 17,
80 FW3_FLAG_SYN_FLOOD
= 18,
81 FW3_FLAG_MTU_FIX
= 19,
82 FW3_FLAG_DROP_INVALID
= 20,
83 FW3_FLAG_HOTPLUG
= 21,
88 extern const char *fw3_flag_names
[__FW3_FLAG_MAX
];
93 FW3_LIMIT_UNIT_SECOND
= 0,
94 FW3_LIMIT_UNIT_MINUTE
= 1,
95 FW3_LIMIT_UNIT_HOUR
= 2,
96 FW3_LIMIT_UNIT_DAY
= 3,
101 extern const char *fw3_limit_units
[__FW3_LIMIT_UNIT_MAX
];
104 enum fw3_ipset_method
106 FW3_IPSET_METHOD_UNSPEC
= 0,
107 FW3_IPSET_METHOD_BITMAP
= 1,
108 FW3_IPSET_METHOD_HASH
= 2,
109 FW3_IPSET_METHOD_LIST
= 3,
111 __FW3_IPSET_METHOD_MAX
116 FW3_IPSET_TYPE_UNSPEC
= 0,
117 FW3_IPSET_TYPE_IP
= 1,
118 FW3_IPSET_TYPE_PORT
= 2,
119 FW3_IPSET_TYPE_MAC
= 3,
120 FW3_IPSET_TYPE_NET
= 4,
121 FW3_IPSET_TYPE_SET
= 5,
126 extern const char *fw3_ipset_method_names
[__FW3_IPSET_METHOD_MAX
];
127 extern const char *fw3_ipset_type_names
[__FW3_IPSET_TYPE_MAX
];
130 enum fw3_include_type
132 FW3_INC_TYPE_SCRIPT
= 0,
133 FW3_INC_TYPE_RESTORE
= 1,
136 enum fw3_reflection_source
138 FW3_REFLECTION_INTERNAL
= 0,
139 FW3_REFLECTION_EXTERNAL
= 1,
142 struct fw3_ipset_datatype
144 struct list_head list
;
145 enum fw3_ipset_type type
;
155 struct fw3_ipset
*ptr
;
160 struct list_head list
;
171 struct list_head list
;
177 enum fw3_family family
;
181 struct ether_addr mac
;
186 struct ether_addr mac
;
192 struct list_head list
;
196 struct ether_addr mac
;
201 struct list_head list
;
210 struct list_head list
;
220 struct list_head list
;
223 enum fw3_family family
;
237 enum fw3_limit_unit unit
;
247 uint32_t monthdays
; /* bit 0 is invert + 1 .. 31 */
248 uint8_t weekdays
; /* bit 0 is invert + 1 .. 7 */
261 enum fw3_flag policy_input
;
262 enum fw3_flag policy_output
;
263 enum fw3_flag policy_forward
;
268 struct fw3_limit syn_flood_rate
;
272 bool tcp_window_scaling
;
274 bool accept_redirects
;
275 bool accept_source_route
;
286 struct list_head list
;
291 enum fw3_family family
;
293 enum fw3_flag policy_input
;
294 enum fw3_flag policy_output
;
295 enum fw3_flag policy_forward
;
297 struct list_head networks
;
298 struct list_head devices
;
299 struct list_head subnets
;
301 const char *extra_src
;
302 const char *extra_dest
;
305 struct list_head masq_src
;
306 struct list_head masq_dest
;
312 struct fw3_limit log_limit
;
318 struct list_head old_addrs
;
323 struct list_head list
;
328 enum fw3_family family
;
330 struct fw3_zone
*_src
;
331 struct fw3_zone
*_dest
;
336 struct fw3_device src
;
337 struct fw3_device dest
;
338 struct fw3_setmatch ipset
;
340 struct list_head proto
;
342 struct list_head ip_src
;
343 struct list_head mac_src
;
344 struct list_head port_src
;
346 struct list_head ip_dest
;
347 struct list_head port_dest
;
349 struct list_head icmp_type
;
351 struct fw3_limit limit
;
352 struct fw3_time time
;
353 struct fw3_mark mark
;
355 enum fw3_flag target
;
356 struct fw3_mark set_mark
;
357 struct fw3_mark set_xmark
;
364 struct list_head list
;
369 enum fw3_family family
;
371 struct fw3_zone
*_src
;
372 struct fw3_zone
*_dest
;
374 struct fw3_device src
;
375 struct fw3_device dest
;
376 struct fw3_setmatch ipset
;
378 struct list_head proto
;
380 struct fw3_address ip_src
;
381 struct list_head mac_src
;
382 struct fw3_port port_src
;
384 struct fw3_address ip_dest
;
385 struct fw3_port port_dest
;
387 struct fw3_address ip_redir
;
388 struct fw3_port port_redir
;
390 struct fw3_limit limit
;
391 struct fw3_time time
;
392 struct fw3_mark mark
;
394 enum fw3_flag target
;
400 enum fw3_reflection_source reflection_src
;
405 struct list_head list
;
410 enum fw3_family family
;
412 struct fw3_zone
*_src
;
414 struct fw3_device src
;
415 struct fw3_setmatch ipset
;
418 struct list_head proto
;
420 struct fw3_address ip_src
;
421 struct fw3_port port_src
;
423 struct fw3_address ip_dest
;
424 struct fw3_port port_dest
;
426 struct fw3_address ip_snat
;
427 struct fw3_port port_snat
;
429 struct fw3_limit limit
;
430 struct fw3_time time
;
431 struct fw3_mark mark
;
432 bool connlimit_ports
;
434 enum fw3_flag target
;
441 struct list_head list
;
446 enum fw3_family family
;
448 struct fw3_zone
*_src
;
449 struct fw3_zone
*_dest
;
451 struct fw3_device src
;
452 struct fw3_device dest
;
457 struct list_head list
;
461 enum fw3_family family
;
463 enum fw3_ipset_method method
;
464 struct list_head datatypes
;
466 struct fw3_address iprange
;
467 struct fw3_port portrange
;
475 const char *external
;
482 struct list_head list
;
486 enum fw3_family family
;
489 enum fw3_include_type type
;
496 struct uci_context
*uci
;
497 struct fw3_defaults defaults
;
498 struct list_head zones
;
499 struct list_head rules
;
500 struct list_head redirects
;
501 struct list_head snats
;
502 struct list_head forwards
;
503 struct list_head ipsets
;
504 struct list_head includes
;
510 struct fw3_chain_spec
{
521 bool (*parse
)(void *, const char *, bool);
526 #define FW3_OPT(name, parse, structure, member) \
527 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
529 #define FW3_LIST(name, parse, structure, member) \
530 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
531 sizeof(struct fw3_##structure) }
533 bool fw3_parse_bool(void *ptr
, const char *val
, bool is_list
);
534 bool fw3_parse_int(void *ptr
, const char *val
, bool is_list
);
535 bool fw3_parse_string(void *ptr
, const char *val
, bool is_list
);
536 bool fw3_parse_target(void *ptr
, const char *val
, bool is_list
);
537 bool fw3_parse_limit(void *ptr
, const char *val
, bool is_list
);
538 bool fw3_parse_device(void *ptr
, const char *val
, bool is_list
);
539 bool fw3_parse_address(void *ptr
, const char *val
, bool is_list
);
540 bool fw3_parse_network(void *ptr
, const char *val
, bool is_list
);
541 bool fw3_parse_mac(void *ptr
, const char *val
, bool is_list
);
542 bool fw3_parse_port(void *ptr
, const char *val
, bool is_list
);
543 bool fw3_parse_family(void *ptr
, const char *val
, bool is_list
);
544 bool fw3_parse_icmptype(void *ptr
, const char *val
, bool is_list
);
545 bool fw3_parse_protocol(void *ptr
, const char *val
, bool is_list
);
547 bool fw3_parse_ipset_method(void *ptr
, const char *val
, bool is_list
);
548 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
, bool is_list
);
550 bool fw3_parse_include_type(void *ptr
, const char *val
, bool is_list
);
551 bool fw3_parse_reflection_source(void *ptr
, const char *val
, bool is_list
);
553 bool fw3_parse_date(void *ptr
, const char *val
, bool is_list
);
554 bool fw3_parse_time(void *ptr
, const char *val
, bool is_list
);
555 bool fw3_parse_weekdays(void *ptr
, const char *val
, bool is_list
);
556 bool fw3_parse_monthdays(void *ptr
, const char *val
, bool is_list
);
557 bool fw3_parse_mark(void *ptr
, const char *val
, bool is_list
);
558 bool fw3_parse_setmatch(void *ptr
, const char *val
, bool is_list
);
559 bool fw3_parse_direction(void *ptr
, const char *val
, bool is_list
);
561 bool fw3_parse_options(void *s
, const struct fw3_option
*opts
,
562 struct uci_section
*section
);
563 bool fw3_parse_blob_options(void *s
, const struct fw3_option
*opts
,
564 struct blob_attr
*a
, const char *name
);
566 const char * fw3_address_to_string(struct fw3_address
*address
,
567 bool allow_invert
, bool as_cidr
);