2 * firewall3 - 3rd OpenWrt UCI firewall implementation
4 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
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>
45 #include "icmp_codes.h"
74 FW3_FLAG_SRC_ACCEPT
= 13,
75 FW3_FLAG_SRC_REJECT
= 14,
76 FW3_FLAG_SRC_DROP
= 15,
77 FW3_FLAG_CUSTOM_CHAINS
= 16,
78 FW3_FLAG_SYN_FLOOD
= 17,
79 FW3_FLAG_MTU_FIX
= 18,
80 FW3_FLAG_DROP_INVALID
= 19,
81 FW3_FLAG_HOTPLUG
= 20,
82 FW3_FLAG_DELETED
= 21,
87 extern const char *fw3_flag_names
[__FW3_FLAG_MAX
];
92 FW3_LIMIT_UNIT_SECOND
= 0,
93 FW3_LIMIT_UNIT_MINUTE
= 1,
94 FW3_LIMIT_UNIT_HOUR
= 2,
95 FW3_LIMIT_UNIT_DAY
= 3,
100 FW3_IPSET_METHOD_UNSPEC
= 0,
101 FW3_IPSET_METHOD_BITMAP
= 1,
102 FW3_IPSET_METHOD_HASH
= 2,
103 FW3_IPSET_METHOD_LIST
= 3,
108 FW3_IPSET_TYPE_UNSPEC
= 0,
109 FW3_IPSET_TYPE_IP
= 1,
110 FW3_IPSET_TYPE_PORT
= 2,
111 FW3_IPSET_TYPE_MAC
= 3,
112 FW3_IPSET_TYPE_NET
= 4,
113 FW3_IPSET_TYPE_SET
= 5,
116 enum fw3_include_type
118 FW3_INC_TYPE_SCRIPT
= 0,
119 FW3_INC_TYPE_RESTORE
= 1,
122 enum fw3_reflection_source
124 FW3_REFLECTION_INTERNAL
= 0,
125 FW3_REFLECTION_EXTERNAL
= 1,
128 struct fw3_ipset_datatype
130 struct list_head list
;
131 enum fw3_ipset_type type
;
137 struct list_head list
;
143 struct fw3_device
*network
;
148 struct list_head list
;
153 enum fw3_family family
;
158 struct ether_addr mac
;
163 struct ether_addr mac
;
169 struct list_head list
;
173 struct ether_addr mac
;
178 struct list_head list
;
187 struct list_head list
;
197 struct list_head list
;
200 enum fw3_family family
;
214 enum fw3_limit_unit unit
;
224 uint32_t monthdays
; /* bit 0 is invert + 1 .. 31 */
225 uint8_t weekdays
; /* bit 0 is invert + 1 .. 7 */
238 enum fw3_flag policy_input
;
239 enum fw3_flag policy_output
;
240 enum fw3_flag policy_forward
;
245 struct fw3_limit syn_flood_rate
;
249 bool tcp_window_scaling
;
251 bool accept_redirects
;
252 bool accept_source_route
;
263 struct list_head list
;
264 struct list_head running_list
;
269 enum fw3_family family
;
271 enum fw3_flag policy_input
;
272 enum fw3_flag policy_output
;
273 enum fw3_flag policy_forward
;
275 struct list_head networks
;
276 struct list_head devices
;
277 struct list_head subnets
;
279 struct list_head running_networks
;
280 struct list_head running_devices
;
282 const char *extra_src
;
283 const char *extra_dest
;
286 struct list_head masq_src
;
287 struct list_head masq_dest
;
293 struct fw3_limit log_limit
;
302 struct list_head list
;
307 enum fw3_family family
;
309 struct fw3_zone
*_src
;
310 struct fw3_zone
*_dest
;
312 struct fw3_device src
;
313 struct fw3_device dest
;
315 struct fw3_ipset
*_ipset
;
316 struct fw3_device ipset
;
318 struct list_head proto
;
320 struct list_head ip_src
;
321 struct list_head mac_src
;
322 struct list_head port_src
;
324 struct list_head ip_dest
;
325 struct list_head port_dest
;
327 struct list_head icmp_type
;
329 struct fw3_limit limit
;
330 struct fw3_time time
;
331 struct fw3_mark mark
;
333 enum fw3_flag target
;
334 struct fw3_mark set_mark
;
335 struct fw3_mark set_xmark
;
342 struct list_head list
;
347 enum fw3_family family
;
349 struct fw3_zone
*_src
;
350 struct fw3_zone
*_dest
;
352 struct fw3_device src
;
353 struct fw3_device dest
;
355 struct fw3_ipset
*_ipset
;
356 struct fw3_device ipset
;
358 struct list_head proto
;
360 struct fw3_address ip_src
;
361 struct list_head mac_src
;
362 struct fw3_port port_src
;
364 struct fw3_address ip_dest
;
365 struct fw3_port port_dest
;
367 struct fw3_address ip_redir
;
368 struct fw3_port port_redir
;
370 struct fw3_time time
;
371 struct fw3_mark mark
;
373 enum fw3_flag target
;
378 enum fw3_reflection_source reflection_src
;
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
;
399 struct list_head list
;
400 struct list_head running_list
;
404 enum fw3_family family
;
406 enum fw3_ipset_method method
;
407 struct list_head datatypes
;
409 struct fw3_address iprange
;
410 struct fw3_port portrange
;
418 const char *external
;
425 struct list_head list
;
426 struct list_head running_list
;
430 enum fw3_family family
;
433 enum fw3_include_type type
;
440 struct uci_context
*uci
;
441 struct fw3_defaults defaults
;
442 struct list_head zones
;
443 struct list_head rules
;
444 struct list_head redirects
;
445 struct list_head forwards
;
446 struct list_head ipsets
;
447 struct list_head includes
;
449 struct list_head running_zones
;
450 struct list_head running_ipsets
;
460 bool (*parse
)(void *, const char *, bool);
465 #define FW3_OPT(name, parse, structure, member) \
466 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
468 #define FW3_LIST(name, parse, structure, member) \
469 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
470 sizeof(struct fw3_##structure) }
472 bool fw3_parse_bool(void *ptr
, const char *val
, bool is_list
);
473 bool fw3_parse_int(void *ptr
, const char *val
, bool is_list
);
474 bool fw3_parse_string(void *ptr
, const char *val
, bool is_list
);
475 bool fw3_parse_target(void *ptr
, const char *val
, bool is_list
);
476 bool fw3_parse_limit(void *ptr
, const char *val
, bool is_list
);
477 bool fw3_parse_device(void *ptr
, const char *val
, bool is_list
);
478 bool fw3_parse_address(void *ptr
, const char *val
, bool is_list
);
479 bool fw3_parse_network(void *ptr
, const char *val
, bool is_list
);
480 bool fw3_parse_mac(void *ptr
, const char *val
, bool is_list
);
481 bool fw3_parse_port(void *ptr
, const char *val
, bool is_list
);
482 bool fw3_parse_family(void *ptr
, const char *val
, bool is_list
);
483 bool fw3_parse_icmptype(void *ptr
, const char *val
, bool is_list
);
484 bool fw3_parse_protocol(void *ptr
, const char *val
, bool is_list
);
486 bool fw3_parse_ipset_method(void *ptr
, const char *val
, bool is_list
);
487 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
, bool is_list
);
489 bool fw3_parse_include_type(void *ptr
, const char *val
, bool is_list
);
490 bool fw3_parse_reflection_source(void *ptr
, const char *val
, bool is_list
);
492 bool fw3_parse_date(void *ptr
, const char *val
, bool is_list
);
493 bool fw3_parse_time(void *ptr
, const char *val
, bool is_list
);
494 bool fw3_parse_weekdays(void *ptr
, const char *val
, bool is_list
);
495 bool fw3_parse_monthdays(void *ptr
, const char *val
, bool is_list
);
496 bool fw3_parse_mark(void *ptr
, const char *val
, bool is_list
);
498 void fw3_parse_options(void *s
, const struct fw3_option
*opts
,
499 struct uci_section
*section
);
501 void fw3_format_in_out(struct fw3_device
*in
, struct fw3_device
*out
);
502 void fw3_format_src_dest(struct fw3_address
*src
, struct fw3_address
*dest
);
503 void fw3_format_sport_dport(struct fw3_port
*sp
, struct fw3_port
*dp
);
504 void fw3_format_mac(struct fw3_mac
*mac
);
505 void fw3_format_protocol(struct fw3_protocol
*proto
, enum fw3_family family
);
506 void fw3_format_icmptype(struct fw3_icmptype
*icmp
, enum fw3_family family
);
507 void fw3_format_limit(struct fw3_limit
*limit
);
508 void fw3_format_ipset(struct fw3_ipset
*ipset
, bool invert
);
509 void fw3_format_time(struct fw3_time
*time
);
510 void fw3_format_mark(struct fw3_mark
*mark
);
512 void __fw3_format_comment(const char *comment
, ...);
513 #define fw3_format_comment(...) __fw3_format_comment(__VA_ARGS__, NULL)
515 void fw3_format_extra(const char *extra
);