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
= 1,
66 FW3_TARGET_REJECT
= 2,
68 FW3_TARGET_NOTRACK
= 4,
75 FW3_LIMIT_UNIT_SECOND
= 0,
76 FW3_LIMIT_UNIT_MINUTE
= 1,
77 FW3_LIMIT_UNIT_HOUR
= 2,
78 FW3_LIMIT_UNIT_DAY
= 3,
83 FW3_IPSET_METHOD_UNSPEC
= 0,
84 FW3_IPSET_METHOD_BITMAP
= 1,
85 FW3_IPSET_METHOD_HASH
= 2,
86 FW3_IPSET_METHOD_LIST
= 3,
91 FW3_IPSET_TYPE_UNSPEC
= 0,
92 FW3_IPSET_TYPE_IP
= 1,
93 FW3_IPSET_TYPE_PORT
= 2,
94 FW3_IPSET_TYPE_MAC
= 3,
95 FW3_IPSET_TYPE_NET
= 4,
96 FW3_IPSET_TYPE_SET
= 5,
99 struct fw3_ipset_datatype
101 struct list_head list
;
102 enum fw3_ipset_type type
;
108 struct list_head list
;
118 struct list_head list
;
122 enum fw3_family family
;
127 struct ether_addr mac
;
133 struct list_head list
;
137 struct ether_addr mac
;
142 struct list_head list
;
151 struct list_head list
;
161 struct list_head list
;
164 enum fw3_family family
;
178 enum fw3_limit_unit unit
;
183 enum fw3_target policy_input
;
184 enum fw3_target policy_output
;
185 enum fw3_target policy_forward
;
190 struct fw3_limit syn_flood_rate
;
195 bool tcp_window_scaling
;
197 bool accept_redirects
;
198 bool accept_source_route
;
207 struct list_head list
;
211 enum fw3_family family
;
213 enum fw3_target policy_input
;
214 enum fw3_target policy_output
;
215 enum fw3_target policy_forward
;
217 struct list_head networks
;
218 struct list_head devices
;
219 struct list_head subnets
;
221 const char *extra_src
;
222 const char *extra_dest
;
225 struct list_head masq_src
;
226 struct list_head masq_dest
;
232 struct fw3_limit log_limit
;
236 bool has_src_target
[FW3_TARGET_SNAT
+ 1];
237 bool has_dest_target
[FW3_TARGET_SNAT
+ 1];
242 struct list_head list
;
246 enum fw3_family family
;
248 struct fw3_zone
*_src
;
249 struct fw3_zone
*_dest
;
251 struct fw3_device src
;
252 struct fw3_device dest
;
254 struct fw3_ipset
*_ipset
;
255 struct fw3_device ipset
;
257 struct list_head proto
;
259 struct list_head ip_src
;
260 struct list_head mac_src
;
261 struct list_head port_src
;
263 struct list_head ip_dest
;
264 struct list_head port_dest
;
266 struct list_head icmp_type
;
268 enum fw3_target target
;
270 struct fw3_limit limit
;
277 struct list_head list
;
281 enum fw3_family family
;
283 struct fw3_zone
*_src
;
284 struct fw3_zone
*_dest
;
286 struct fw3_device src
;
287 struct fw3_device dest
;
289 struct fw3_ipset
*_ipset
;
290 struct fw3_device ipset
;
292 struct list_head proto
;
294 struct fw3_address ip_src
;
295 struct list_head mac_src
;
296 struct fw3_port port_src
;
298 struct fw3_address ip_dest
;
299 struct fw3_port port_dest
;
301 struct fw3_address ip_redir
;
302 struct fw3_port port_redir
;
304 enum fw3_target target
;
313 struct list_head list
;
317 enum fw3_family family
;
319 struct fw3_zone
*_src
;
320 struct fw3_zone
*_dest
;
322 struct fw3_device src
;
323 struct fw3_device dest
;
328 struct list_head list
;
331 enum fw3_family family
;
333 enum fw3_ipset_method method
;
334 struct list_head datatypes
;
336 struct list_head iprange
;
337 struct fw3_port portrange
;
345 const char *external
;
350 struct uci_context
*uci
;
351 struct fw3_defaults defaults
;
352 struct list_head zones
;
353 struct list_head rules
;
354 struct list_head redirects
;
355 struct list_head forwards
;
356 struct list_head ipsets
;
365 bool (*parse
)(void *, const char *);
370 #define FW3_OPT(name, parse, structure, member) \
371 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member) }
373 #define FW3_LIST(name, parse, structure, member) \
374 { name, fw3_parse_##parse, offsetof(struct fw3_##structure, member), \
375 sizeof(struct fw3_##structure) }
378 bool fw3_parse_bool(void *ptr
, const char *val
);
379 bool fw3_parse_int(void *ptr
, const char *val
);
380 bool fw3_parse_string(void *ptr
, const char *val
);
381 bool fw3_parse_target(void *ptr
, const char *val
);
382 bool fw3_parse_limit(void *ptr
, const char *val
);
383 bool fw3_parse_device(void *ptr
, const char *val
);
384 bool fw3_parse_address(void *ptr
, const char *val
);
385 bool fw3_parse_mac(void *ptr
, const char *val
);
386 bool fw3_parse_port(void *ptr
, const char *val
);
387 bool fw3_parse_family(void *ptr
, const char *val
);
388 bool fw3_parse_icmptype(void *ptr
, const char *val
);
389 bool fw3_parse_protocol(void *ptr
, const char *val
);
390 bool fw3_parse_ipset_method(void *ptr
, const char *val
);
391 bool fw3_parse_ipset_datatype(void *ptr
, const char *val
);
393 void fw3_parse_options(void *s
, struct fw3_option
*opts
, int n
,
394 struct uci_section
*section
);
396 void fw3_format_in_out(struct fw3_device
*in
, struct fw3_device
*out
);
397 void fw3_format_src_dest(struct fw3_address
*src
, struct fw3_address
*dest
);
398 void fw3_format_sport_dport(struct fw3_port
*sp
, struct fw3_port
*dp
);
399 void fw3_format_mac(struct fw3_mac
*mac
);
400 void fw3_format_protocol(struct fw3_protocol
*proto
, enum fw3_family family
);
401 void fw3_format_icmptype(struct fw3_icmptype
*icmp
, enum fw3_family family
);
402 void fw3_format_limit(struct fw3_limit
*limit
);
403 void fw3_format_ipset(struct fw3_ipset
*ipset
, bool invert
);
405 void __fw3_format_comment(const char *comment
, ...);
406 #define fw3_format_comment(...) __fw3_format_comment(__VA_ARGS__, NULL)
408 void fw3_format_extra(const char *extra
);