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>
40 #include <libubox/list.h>
41 #include <libubox/utils.h>
43 #include "icmp_codes.h"
64 FW3_TARGET_UNSPEC
= 0,
65 FW3_TARGET_ACCEPT
= 6,
66 FW3_TARGET_REJECT
= 7,
68 FW3_TARGET_NOTRACK
= 9,
75 FW3_DEFAULT_UNSPEC
= 0,
76 FW3_DEFAULT_CUSTOM_CHAINS
= 12,
77 FW3_DEFAULT_SYN_FLOOD
= 13,
78 FW3_DEFAULT_MTU_FIX
= 14,
79 FW3_DEFAULT_DROP_INVALID
= 15,
84 FW3_LIMIT_UNIT_SECOND
= 0,
85 FW3_LIMIT_UNIT_MINUTE
= 1,
86 FW3_LIMIT_UNIT_HOUR
= 2,
87 FW3_LIMIT_UNIT_DAY
= 3,
92 FW3_IPSET_METHOD_UNSPEC
= 0,
93 FW3_IPSET_METHOD_BITMAP
= 1,
94 FW3_IPSET_METHOD_HASH
= 2,
95 FW3_IPSET_METHOD_LIST
= 3,
100 FW3_IPSET_TYPE_UNSPEC
= 0,
101 FW3_IPSET_TYPE_IP
= 1,
102 FW3_IPSET_TYPE_PORT
= 2,
103 FW3_IPSET_TYPE_MAC
= 3,
104 FW3_IPSET_TYPE_NET
= 4,
105 FW3_IPSET_TYPE_SET
= 5,
108 struct fw3_ipset_datatype
110 struct list_head list
;
111 enum fw3_ipset_type type
;
117 struct list_head list
;
127 struct list_head list
;
131 enum fw3_family family
;
136 struct ether_addr mac
;
142 struct list_head list
;
146 struct ether_addr mac
;
151 struct list_head list
;
160 struct list_head list
;
170 struct list_head list
;
173 enum fw3_family family
;
187 enum fw3_limit_unit unit
;
192 enum fw3_target policy_input
;
193 enum fw3_target policy_output
;
194 enum fw3_target policy_forward
;
199 struct fw3_limit syn_flood_rate
;
204 bool tcp_window_scaling
;
206 bool accept_redirects
;
207 bool accept_source_route
;
218 struct list_head list
;
222 enum fw3_family family
;
224 enum fw3_target policy_input
;
225 enum fw3_target policy_output
;
226 enum fw3_target policy_forward
;
228 struct list_head networks
;
229 struct list_head devices
;
230 struct list_head subnets
;
232 const char *extra_src
;
233 const char *extra_dest
;
236 struct list_head masq_src
;
237 struct list_head masq_dest
;
243 struct fw3_limit log_limit
;
253 struct list_head list
;
257 enum fw3_family family
;
259 struct fw3_zone
*_src
;
260 struct fw3_zone
*_dest
;
262 struct fw3_device src
;
263 struct fw3_device dest
;
265 struct fw3_ipset
*_ipset
;
266 struct fw3_device ipset
;
268 struct list_head proto
;
270 struct list_head ip_src
;
271 struct list_head mac_src
;
272 struct list_head port_src
;
274 struct list_head ip_dest
;
275 struct list_head port_dest
;
277 struct list_head icmp_type
;
279 enum fw3_target target
;
281 struct fw3_limit limit
;
288 struct list_head list
;
292 enum fw3_family family
;
294 struct fw3_zone
*_src
;
295 struct fw3_zone
*_dest
;
297 struct fw3_device src
;
298 struct fw3_device dest
;
300 struct fw3_ipset
*_ipset
;
301 struct fw3_device ipset
;
303 struct list_head proto
;
305 struct fw3_address ip_src
;
306 struct list_head mac_src
;
307 struct fw3_port port_src
;
309 struct fw3_address ip_dest
;
310 struct fw3_port port_dest
;
312 struct fw3_address ip_redir
;
313 struct fw3_port port_redir
;
315 enum fw3_target target
;
324 struct list_head list
;
328 enum fw3_family family
;
330 struct fw3_zone
*_src
;
331 struct fw3_zone
*_dest
;
333 struct fw3_device src
;
334 struct fw3_device dest
;
339 struct list_head list
;
342 enum fw3_family family
;
344 enum fw3_ipset_method method
;
345 struct list_head datatypes
;
347 struct list_head iprange
;
348 struct fw3_port portrange
;
356 const char *external
;
363 struct uci_context
*uci
;
364 struct fw3_defaults defaults
;
365 struct list_head zones
;
366 struct list_head rules
;
367 struct list_head redirects
;
368 struct list_head forwards
;
369 struct list_head ipsets
;
378 bool (*parse
)(void *, const char *);
383 #define FW3_OPT(name, parse, structure, member) \
384 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
386 #define FW3_LIST(name, parse, structure, member) \
387 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
388 sizeof(struct fw3_##structure) }
391 bool fw3_parse_bool(void *ptr
, const char *val
);
392 bool fw3_parse_int(void *ptr
, const char *val
);
393 bool fw3_parse_string(void *ptr
, const char *val
);
394 bool fw3_parse_target(void *ptr
, const char *val
);
395 bool fw3_parse_limit(void *ptr
, const char *val
);
396 bool fw3_parse_device(void *ptr
, const char *val
);
397 bool fw3_parse_address(void *ptr
, const char *val
);
398 bool fw3_parse_mac(void *ptr
, const char *val
);
399 bool fw3_parse_port(void *ptr
, const char *val
);
400 bool fw3_parse_family(void *ptr
, const char *val
);
401 bool fw3_parse_icmptype(void *ptr
, const char *val
);
402 bool fw3_parse_protocol(void *ptr
, const char *val
);
403 bool fw3_parse_ipset_method(void *ptr
, const char *val
);
404 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
);
406 void fw3_parse_options(void *s
, struct fw3_option
*opts
, int n
,
407 struct uci_section
*section
);
409 void fw3_format_in_out(struct fw3_device
*in
, struct fw3_device
*out
);
410 void fw3_format_src_dest(struct fw3_address
*src
, struct fw3_address
*dest
);
411 void fw3_format_sport_dport(struct fw3_port
*sp
, struct fw3_port
*dp
);
412 void fw3_format_mac(struct fw3_mac
*mac
);
413 void fw3_format_protocol(struct fw3_protocol
*proto
, enum fw3_family family
);
414 void fw3_format_icmptype(struct fw3_icmptype
*icmp
, enum fw3_family family
);
415 void fw3_format_limit(struct fw3_limit
*limit
);
416 void fw3_format_ipset(struct fw3_ipset
*ipset
, bool invert
);
418 void __fw3_format_comment(const char *comment
, ...);
419 #define fw3_format_comment(...) __fw3_format_comment(__VA_ARGS__, NULL)
421 void fw3_format_extra(const char *extra
);