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"
66 FW3_TARGET_UNSPEC
= 0,
67 FW3_TARGET_ACCEPT
= 6,
68 FW3_TARGET_REJECT
= 7,
70 FW3_TARGET_NOTRACK
= 9,
77 FW3_DEFAULT_UNSPEC
= 0,
78 FW3_DEFAULT_CUSTOM_CHAINS
= 12,
79 FW3_DEFAULT_SYN_FLOOD
= 13,
80 FW3_DEFAULT_MTU_FIX
= 14,
81 FW3_DEFAULT_DROP_INVALID
= 15,
84 extern const char *fw3_flag_names
[FW3_DEFAULT_DROP_INVALID
+ 1];
89 FW3_LIMIT_UNIT_SECOND
= 0,
90 FW3_LIMIT_UNIT_MINUTE
= 1,
91 FW3_LIMIT_UNIT_HOUR
= 2,
92 FW3_LIMIT_UNIT_DAY
= 3,
97 FW3_IPSET_METHOD_UNSPEC
= 0,
98 FW3_IPSET_METHOD_BITMAP
= 1,
99 FW3_IPSET_METHOD_HASH
= 2,
100 FW3_IPSET_METHOD_LIST
= 3,
105 FW3_IPSET_TYPE_UNSPEC
= 0,
106 FW3_IPSET_TYPE_IP
= 1,
107 FW3_IPSET_TYPE_PORT
= 2,
108 FW3_IPSET_TYPE_MAC
= 3,
109 FW3_IPSET_TYPE_NET
= 4,
110 FW3_IPSET_TYPE_SET
= 5,
113 enum fw3_include_type
115 FW3_INC_TYPE_SCRIPT
= 0,
116 FW3_INC_TYPE_RESTORE
= 1,
119 struct fw3_ipset_datatype
121 struct list_head list
;
122 enum fw3_ipset_type type
;
128 struct list_head list
;
138 struct list_head list
;
143 enum fw3_family family
;
148 struct ether_addr mac
;
153 struct ether_addr mac
;
159 struct list_head list
;
163 struct ether_addr mac
;
168 struct list_head list
;
177 struct list_head list
;
187 struct list_head list
;
190 enum fw3_family family
;
204 enum fw3_limit_unit unit
;
214 uint32_t monthdays
; /* bit 0 is invert + 1 .. 31 */
215 uint8_t weekdays
; /* bit 0 is invert + 1 .. 7 */
220 enum fw3_target policy_input
;
221 enum fw3_target policy_output
;
222 enum fw3_target policy_forward
;
227 struct fw3_limit syn_flood_rate
;
231 bool tcp_window_scaling
;
233 bool accept_redirects
;
234 bool accept_source_route
;
245 struct list_head list
;
246 struct list_head running_list
;
250 enum fw3_family family
;
252 enum fw3_target policy_input
;
253 enum fw3_target policy_output
;
254 enum fw3_target policy_forward
;
256 struct list_head networks
;
257 struct list_head devices
;
258 struct list_head subnets
;
260 const char *extra_src
;
261 const char *extra_dest
;
264 struct list_head masq_src
;
265 struct list_head masq_dest
;
271 struct fw3_limit log_limit
;
281 struct list_head list
;
285 enum fw3_family family
;
287 struct fw3_zone
*_src
;
288 struct fw3_zone
*_dest
;
290 struct fw3_device src
;
291 struct fw3_device dest
;
293 struct fw3_ipset
*_ipset
;
294 struct fw3_device ipset
;
296 struct list_head proto
;
298 struct list_head ip_src
;
299 struct list_head mac_src
;
300 struct list_head port_src
;
302 struct list_head ip_dest
;
303 struct list_head port_dest
;
305 struct list_head icmp_type
;
307 struct fw3_limit limit
;
308 struct fw3_time time
;
310 enum fw3_target target
;
317 struct list_head list
;
321 enum fw3_family family
;
323 struct fw3_zone
*_src
;
324 struct fw3_zone
*_dest
;
326 struct fw3_device src
;
327 struct fw3_device dest
;
329 struct fw3_ipset
*_ipset
;
330 struct fw3_device ipset
;
332 struct list_head proto
;
334 struct fw3_address ip_src
;
335 struct list_head mac_src
;
336 struct fw3_port port_src
;
338 struct fw3_address ip_dest
;
339 struct fw3_port port_dest
;
341 struct fw3_address ip_redir
;
342 struct fw3_port port_redir
;
344 struct fw3_time time
;
346 enum fw3_target target
;
355 struct list_head list
;
359 enum fw3_family family
;
361 struct fw3_zone
*_src
;
362 struct fw3_zone
*_dest
;
364 struct fw3_device src
;
365 struct fw3_device dest
;
370 struct list_head list
;
371 struct list_head running_list
;
374 enum fw3_family family
;
376 enum fw3_ipset_method method
;
377 struct list_head datatypes
;
379 struct fw3_address iprange
;
380 struct fw3_port portrange
;
388 const char *external
;
395 struct list_head list
;
396 struct list_head running_list
;
399 enum fw3_family family
;
402 enum fw3_include_type type
;
407 struct uci_context
*uci
;
408 struct fw3_defaults defaults
;
409 struct list_head zones
;
410 struct list_head rules
;
411 struct list_head redirects
;
412 struct list_head forwards
;
413 struct list_head ipsets
;
414 struct list_head includes
;
416 struct fw3_defaults running_defaults
;
417 struct list_head running_zones
;
418 struct list_head running_ipsets
;
428 bool (*parse
)(void *, const char *);
433 #define FW3_OPT(name, parse, structure, member) \
434 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
436 #define FW3_LIST(name, parse, structure, member) \
437 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
438 sizeof(struct fw3_##structure) }
441 bool fw3_parse_bool(void *ptr
, const char *val
);
442 bool fw3_parse_int(void *ptr
, const char *val
);
443 bool fw3_parse_string(void *ptr
, const char *val
);
444 bool fw3_parse_target(void *ptr
, const char *val
);
445 bool fw3_parse_limit(void *ptr
, const char *val
);
446 bool fw3_parse_device(void *ptr
, const char *val
);
447 bool fw3_parse_address(void *ptr
, const char *val
);
448 bool fw3_parse_mac(void *ptr
, const char *val
);
449 bool fw3_parse_port(void *ptr
, const char *val
);
450 bool fw3_parse_family(void *ptr
, const char *val
);
451 bool fw3_parse_icmptype(void *ptr
, const char *val
);
452 bool fw3_parse_protocol(void *ptr
, const char *val
);
454 bool fw3_parse_ipset_method(void *ptr
, const char *val
);
455 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
);
457 bool fw3_parse_include_type(void *ptr
, const char *val
);
459 bool fw3_parse_date(void *ptr
, const char *val
);
460 bool fw3_parse_time(void *ptr
, const char *val
);
461 bool fw3_parse_weekdays(void *ptr
, const char *val
);
462 bool fw3_parse_monthdays(void *ptr
, const char *val
);
464 void fw3_parse_options(void *s
, const struct fw3_option
*opts
,
465 struct uci_section
*section
);
467 void fw3_format_in_out(struct fw3_device
*in
, struct fw3_device
*out
);
468 void fw3_format_src_dest(struct fw3_address
*src
, struct fw3_address
*dest
);
469 void fw3_format_sport_dport(struct fw3_port
*sp
, struct fw3_port
*dp
);
470 void fw3_format_mac(struct fw3_mac
*mac
);
471 void fw3_format_protocol(struct fw3_protocol
*proto
, enum fw3_family family
);
472 void fw3_format_icmptype(struct fw3_icmptype
*icmp
, enum fw3_family family
);
473 void fw3_format_limit(struct fw3_limit
*limit
);
474 void fw3_format_ipset(struct fw3_ipset
*ipset
, bool invert
);
475 void fw3_format_time(struct fw3_time
*time
);
477 void __fw3_format_comment(const char *comment
, ...);
478 #define fw3_format_comment(...) __fw3_format_comment(__VA_ARGS__, NULL)
480 void fw3_format_extra(const char *extra
);