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,
86 extern const char *fw3_flag_names
[__FW3_FLAG_MAX
];
91 FW3_LIMIT_UNIT_SECOND
= 0,
92 FW3_LIMIT_UNIT_MINUTE
= 1,
93 FW3_LIMIT_UNIT_HOUR
= 2,
94 FW3_LIMIT_UNIT_DAY
= 3,
99 extern const char *fw3_limit_units
[__FW3_LIMIT_UNIT_MAX
];
102 enum fw3_ipset_method
104 FW3_IPSET_METHOD_UNSPEC
= 0,
105 FW3_IPSET_METHOD_BITMAP
= 1,
106 FW3_IPSET_METHOD_HASH
= 2,
107 FW3_IPSET_METHOD_LIST
= 3,
109 __FW3_IPSET_METHOD_MAX
114 FW3_IPSET_TYPE_UNSPEC
= 0,
115 FW3_IPSET_TYPE_IP
= 1,
116 FW3_IPSET_TYPE_PORT
= 2,
117 FW3_IPSET_TYPE_MAC
= 3,
118 FW3_IPSET_TYPE_NET
= 4,
119 FW3_IPSET_TYPE_SET
= 5,
124 extern const char *fw3_ipset_method_names
[__FW3_IPSET_METHOD_MAX
];
125 extern const char *fw3_ipset_type_names
[__FW3_IPSET_TYPE_MAX
];
128 enum fw3_include_type
130 FW3_INC_TYPE_SCRIPT
= 0,
131 FW3_INC_TYPE_RESTORE
= 1,
134 enum fw3_reflection_source
136 FW3_REFLECTION_INTERNAL
= 0,
137 FW3_REFLECTION_EXTERNAL
= 1,
140 struct fw3_ipset_datatype
142 struct list_head list
;
143 enum fw3_ipset_type type
;
149 struct list_head list
;
160 struct list_head list
;
166 enum fw3_family family
;
171 struct ether_addr mac
;
176 struct ether_addr mac
;
182 struct list_head list
;
186 struct ether_addr mac
;
191 struct list_head list
;
200 struct list_head list
;
210 struct list_head list
;
213 enum fw3_family family
;
227 enum fw3_limit_unit unit
;
237 uint32_t monthdays
; /* bit 0 is invert + 1 .. 31 */
238 uint8_t weekdays
; /* bit 0 is invert + 1 .. 7 */
251 enum fw3_flag policy_input
;
252 enum fw3_flag policy_output
;
253 enum fw3_flag policy_forward
;
258 struct fw3_limit syn_flood_rate
;
262 bool tcp_window_scaling
;
264 bool accept_redirects
;
265 bool accept_source_route
;
276 struct list_head list
;
281 enum fw3_family family
;
283 enum fw3_flag policy_input
;
284 enum fw3_flag policy_output
;
285 enum fw3_flag policy_forward
;
287 struct list_head networks
;
288 struct list_head devices
;
289 struct list_head subnets
;
291 const char *extra_src
;
292 const char *extra_dest
;
295 struct list_head masq_src
;
296 struct list_head masq_dest
;
302 struct fw3_limit log_limit
;
311 struct list_head list
;
316 enum fw3_family family
;
318 struct fw3_zone
*_src
;
319 struct fw3_zone
*_dest
;
321 struct fw3_device src
;
322 struct fw3_device dest
;
324 struct fw3_ipset
*_ipset
;
325 struct fw3_device ipset
;
327 struct list_head proto
;
329 struct list_head ip_src
;
330 struct list_head mac_src
;
331 struct list_head port_src
;
333 struct list_head ip_dest
;
334 struct list_head port_dest
;
336 struct list_head icmp_type
;
338 struct fw3_limit limit
;
339 struct fw3_time time
;
340 struct fw3_mark mark
;
342 enum fw3_flag target
;
343 struct fw3_mark set_mark
;
344 struct fw3_mark set_xmark
;
351 struct list_head list
;
356 enum fw3_family family
;
358 struct fw3_zone
*_src
;
359 struct fw3_zone
*_dest
;
361 struct fw3_device src
;
362 struct fw3_device dest
;
364 struct fw3_ipset
*_ipset
;
365 struct fw3_device ipset
;
367 struct list_head proto
;
369 struct fw3_address ip_src
;
370 struct list_head mac_src
;
371 struct fw3_port port_src
;
373 struct fw3_address ip_dest
;
374 struct fw3_port port_dest
;
376 struct fw3_address ip_redir
;
377 struct fw3_port port_redir
;
379 struct fw3_time time
;
380 struct fw3_mark mark
;
382 enum fw3_flag target
;
387 enum fw3_reflection_source reflection_src
;
392 struct list_head list
;
397 enum fw3_family family
;
399 struct fw3_zone
*_src
;
400 struct fw3_zone
*_dest
;
402 struct fw3_device src
;
403 struct fw3_device dest
;
408 struct list_head list
;
412 enum fw3_family family
;
414 enum fw3_ipset_method method
;
415 struct list_head datatypes
;
417 struct fw3_address iprange
;
418 struct fw3_port portrange
;
426 const char *external
;
433 struct list_head list
;
437 enum fw3_family family
;
440 enum fw3_include_type type
;
447 struct uci_context
*uci
;
448 struct fw3_defaults defaults
;
449 struct list_head zones
;
450 struct list_head rules
;
451 struct list_head redirects
;
452 struct list_head forwards
;
453 struct list_head ipsets
;
454 struct list_head includes
;
460 struct fw3_chain_spec
{
471 bool (*parse
)(void *, const char *, bool);
476 #define FW3_OPT(name, parse, structure, member) \
477 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
479 #define FW3_LIST(name, parse, structure, member) \
480 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
481 sizeof(struct fw3_##structure) }
483 bool fw3_parse_bool(void *ptr
, const char *val
, bool is_list
);
484 bool fw3_parse_int(void *ptr
, const char *val
, bool is_list
);
485 bool fw3_parse_string(void *ptr
, const char *val
, bool is_list
);
486 bool fw3_parse_target(void *ptr
, const char *val
, bool is_list
);
487 bool fw3_parse_limit(void *ptr
, const char *val
, bool is_list
);
488 bool fw3_parse_device(void *ptr
, const char *val
, bool is_list
);
489 bool fw3_parse_address(void *ptr
, const char *val
, bool is_list
);
490 bool fw3_parse_network(void *ptr
, const char *val
, bool is_list
);
491 bool fw3_parse_mac(void *ptr
, const char *val
, bool is_list
);
492 bool fw3_parse_port(void *ptr
, const char *val
, bool is_list
);
493 bool fw3_parse_family(void *ptr
, const char *val
, bool is_list
);
494 bool fw3_parse_icmptype(void *ptr
, const char *val
, bool is_list
);
495 bool fw3_parse_protocol(void *ptr
, const char *val
, bool is_list
);
497 bool fw3_parse_ipset_method(void *ptr
, const char *val
, bool is_list
);
498 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
, bool is_list
);
500 bool fw3_parse_include_type(void *ptr
, const char *val
, bool is_list
);
501 bool fw3_parse_reflection_source(void *ptr
, const char *val
, bool is_list
);
503 bool fw3_parse_date(void *ptr
, const char *val
, bool is_list
);
504 bool fw3_parse_time(void *ptr
, const char *val
, bool is_list
);
505 bool fw3_parse_weekdays(void *ptr
, const char *val
, bool is_list
);
506 bool fw3_parse_monthdays(void *ptr
, const char *val
, bool is_list
);
507 bool fw3_parse_mark(void *ptr
, const char *val
, bool is_list
);
509 void fw3_parse_options(void *s
, const struct fw3_option
*opts
,
510 struct uci_section
*section
);
512 const char * fw3_address_to_string(struct fw3_address
*address
,