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"
77 FW3_FLAG_MASQUERADE
= 13,
78 FW3_FLAG_SRC_ACCEPT
= 14,
79 FW3_FLAG_SRC_REJECT
= 15,
80 FW3_FLAG_SRC_DROP
= 16,
81 FW3_FLAG_CUSTOM_CHAINS
= 17,
82 FW3_FLAG_SYN_FLOOD
= 18,
83 FW3_FLAG_MTU_FIX
= 19,
84 FW3_FLAG_DROP_INVALID
= 20,
85 FW3_FLAG_HOTPLUG
= 21,
90 extern const char *fw3_flag_names
[__FW3_FLAG_MAX
];
95 FW3_LIMIT_UNIT_SECOND
= 0,
96 FW3_LIMIT_UNIT_MINUTE
= 1,
97 FW3_LIMIT_UNIT_HOUR
= 2,
98 FW3_LIMIT_UNIT_DAY
= 3,
103 extern const char *fw3_limit_units
[__FW3_LIMIT_UNIT_MAX
];
106 enum fw3_ipset_method
108 FW3_IPSET_METHOD_UNSPEC
= 0,
109 FW3_IPSET_METHOD_BITMAP
= 1,
110 FW3_IPSET_METHOD_HASH
= 2,
111 FW3_IPSET_METHOD_LIST
= 3,
113 __FW3_IPSET_METHOD_MAX
118 FW3_IPSET_TYPE_UNSPEC
= 0,
119 FW3_IPSET_TYPE_IP
= 1,
120 FW3_IPSET_TYPE_PORT
= 2,
121 FW3_IPSET_TYPE_MAC
= 3,
122 FW3_IPSET_TYPE_NET
= 4,
123 FW3_IPSET_TYPE_SET
= 5,
128 extern const char *fw3_ipset_method_names
[__FW3_IPSET_METHOD_MAX
];
129 extern const char *fw3_ipset_type_names
[__FW3_IPSET_TYPE_MAX
];
132 enum fw3_include_type
134 FW3_INC_TYPE_SCRIPT
= 0,
135 FW3_INC_TYPE_RESTORE
= 1,
138 enum fw3_reflection_source
140 FW3_REFLECTION_INTERNAL
= 0,
141 FW3_REFLECTION_EXTERNAL
= 1,
144 struct fw3_ipset_datatype
146 struct list_head list
;
147 enum fw3_ipset_type type
;
157 struct fw3_ipset
*ptr
;
162 struct list_head list
;
173 struct list_head list
;
179 enum fw3_family family
;
183 struct ether_addr mac
;
188 struct ether_addr mac
;
194 struct list_head list
;
198 struct ether_addr mac
;
203 struct list_head list
;
212 struct list_head list
;
222 struct list_head list
;
225 enum fw3_family family
;
239 enum fw3_limit_unit unit
;
249 uint32_t monthdays
; /* bit 0 is invert + 1 .. 31 */
250 uint8_t weekdays
; /* bit 0 is invert + 1 .. 7 */
263 enum fw3_flag policy_input
;
264 enum fw3_flag policy_output
;
265 enum fw3_flag policy_forward
;
270 struct fw3_limit syn_flood_rate
;
274 bool tcp_window_scaling
;
276 bool accept_redirects
;
277 bool accept_source_route
;
288 struct list_head list
;
293 enum fw3_family family
;
295 enum fw3_flag policy_input
;
296 enum fw3_flag policy_output
;
297 enum fw3_flag policy_forward
;
299 struct list_head networks
;
300 struct list_head devices
;
301 struct list_head subnets
;
303 const char *extra_src
;
304 const char *extra_dest
;
307 bool masq_allow_invalid
;
308 struct list_head masq_src
;
309 struct list_head masq_dest
;
314 struct fw3_limit log_limit
;
320 struct list_head old_addrs
;
325 struct list_head list
;
330 enum fw3_family family
;
332 struct fw3_zone
*_src
;
333 struct fw3_zone
*_dest
;
338 struct fw3_device src
;
339 struct fw3_device dest
;
340 struct fw3_setmatch ipset
;
342 struct list_head proto
;
344 struct list_head ip_src
;
345 struct list_head mac_src
;
346 struct list_head port_src
;
348 struct list_head ip_dest
;
349 struct list_head port_dest
;
351 struct list_head icmp_type
;
353 struct fw3_limit limit
;
354 struct fw3_time time
;
355 struct fw3_mark mark
;
357 enum fw3_flag target
;
358 struct fw3_mark set_mark
;
359 struct fw3_mark set_xmark
;
366 struct list_head list
;
371 enum fw3_family family
;
373 struct fw3_zone
*_src
;
374 struct fw3_zone
*_dest
;
376 struct fw3_device src
;
377 struct fw3_device dest
;
378 struct fw3_setmatch ipset
;
380 struct list_head proto
;
382 struct fw3_address ip_src
;
383 struct list_head mac_src
;
384 struct fw3_port port_src
;
386 struct fw3_address ip_dest
;
387 struct fw3_port port_dest
;
389 struct fw3_address ip_redir
;
390 struct fw3_port port_redir
;
392 struct fw3_limit limit
;
393 struct fw3_time time
;
394 struct fw3_mark mark
;
396 enum fw3_flag target
;
402 enum fw3_reflection_source reflection_src
;
407 struct list_head list
;
412 enum fw3_family family
;
414 struct fw3_zone
*_src
;
416 struct fw3_device src
;
417 struct fw3_setmatch ipset
;
420 struct list_head proto
;
422 struct fw3_address ip_src
;
423 struct fw3_port port_src
;
425 struct fw3_address ip_dest
;
426 struct fw3_port port_dest
;
428 struct fw3_address ip_snat
;
429 struct fw3_port port_snat
;
431 struct fw3_limit limit
;
432 struct fw3_time time
;
433 struct fw3_mark mark
;
434 bool connlimit_ports
;
436 enum fw3_flag target
;
443 struct list_head list
;
448 enum fw3_family family
;
450 struct fw3_zone
*_src
;
451 struct fw3_zone
*_dest
;
453 struct fw3_device src
;
454 struct fw3_device dest
;
459 struct list_head list
;
463 enum fw3_family family
;
465 enum fw3_ipset_method method
;
466 struct list_head datatypes
;
468 struct fw3_address iprange
;
469 struct fw3_port portrange
;
477 const char *external
;
484 struct list_head list
;
488 enum fw3_family family
;
491 enum fw3_include_type type
;
498 struct uci_context
*uci
;
499 struct fw3_defaults defaults
;
500 struct list_head zones
;
501 struct list_head rules
;
502 struct list_head redirects
;
503 struct list_head snats
;
504 struct list_head forwards
;
505 struct list_head ipsets
;
506 struct list_head includes
;
512 struct fw3_chain_spec
{
523 bool (*parse
)(void *, const char *, bool);
528 #define FW3_OPT(name, parse, structure, member) \
529 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
531 #define FW3_LIST(name, parse, structure, member) \
532 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
533 sizeof(struct fw3_##structure) }
535 bool fw3_parse_bool(void *ptr
, const char *val
, bool is_list
);
536 bool fw3_parse_int(void *ptr
, const char *val
, bool is_list
);
537 bool fw3_parse_string(void *ptr
, const char *val
, bool is_list
);
538 bool fw3_parse_target(void *ptr
, const char *val
, bool is_list
);
539 bool fw3_parse_limit(void *ptr
, const char *val
, bool is_list
);
540 bool fw3_parse_device(void *ptr
, const char *val
, bool is_list
);
541 bool fw3_parse_address(void *ptr
, const char *val
, bool is_list
);
542 bool fw3_parse_network(void *ptr
, const char *val
, bool is_list
);
543 bool fw3_parse_mac(void *ptr
, const char *val
, bool is_list
);
544 bool fw3_parse_port(void *ptr
, const char *val
, bool is_list
);
545 bool fw3_parse_family(void *ptr
, const char *val
, bool is_list
);
546 bool fw3_parse_icmptype(void *ptr
, const char *val
, bool is_list
);
547 bool fw3_parse_protocol(void *ptr
, const char *val
, bool is_list
);
549 bool fw3_parse_ipset_method(void *ptr
, const char *val
, bool is_list
);
550 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
, bool is_list
);
552 bool fw3_parse_include_type(void *ptr
, const char *val
, bool is_list
);
553 bool fw3_parse_reflection_source(void *ptr
, const char *val
, bool is_list
);
555 bool fw3_parse_date(void *ptr
, const char *val
, bool is_list
);
556 bool fw3_parse_time(void *ptr
, const char *val
, bool is_list
);
557 bool fw3_parse_weekdays(void *ptr
, const char *val
, bool is_list
);
558 bool fw3_parse_monthdays(void *ptr
, const char *val
, bool is_list
);
559 bool fw3_parse_mark(void *ptr
, const char *val
, bool is_list
);
560 bool fw3_parse_setmatch(void *ptr
, const char *val
, bool is_list
);
561 bool fw3_parse_direction(void *ptr
, const char *val
, bool is_list
);
563 bool fw3_parse_options(void *s
, const struct fw3_option
*opts
,
564 struct uci_section
*section
);
565 bool fw3_parse_blob_options(void *s
, const struct fw3_option
*opts
,
566 struct blob_attr
*a
, const char *name
);
568 const char * fw3_address_to_string(struct fw3_address
*address
,
569 bool allow_invert
, bool as_cidr
);