From: Jo-Philipp Wich Date: Mon, 18 Mar 2013 15:38:33 +0000 (+0100) Subject: Implement support for "network" datatype and use it for masq_src / masq_dest X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a0b4c3356f90dbd5be4f6ddff5bd74319a6655b9;p=oweals%2Ffirewall3.git Implement support for "network" datatype and use it for masq_src / masq_dest --- diff --git a/options.c b/options.c index 5c529b3..98ef9de 100644 --- a/options.c +++ b/options.c @@ -17,6 +17,7 @@ */ #include "options.h" +#include "ubus.h" static bool @@ -288,6 +289,38 @@ fw3_parse_address(void *ptr, const char *val) return true; } +bool +fw3_parse_network(void *ptr, const char *val) +{ + struct fw3_device dev; + struct fw3_address *tmp, *addr = ptr; + struct list_head *list; + + if (!fw3_parse_address(addr, val)) + { + memset(&dev, 0, sizeof(dev)); + + if (!fw3_parse_device(&dev, val)) + return false; + + list = fw3_ubus_address(dev.name); + + if (list) + { + list_for_each_entry(tmp, list, list) + { + *addr = *tmp; + addr->invert = dev.invert; + break; + } + + fw3_ubus_address_free(list); + } + } + + return true; +} + bool fw3_parse_mac(void *ptr, const char *val) { diff --git a/options.h b/options.h index 33224b8..b00bdb5 100644 --- a/options.h +++ b/options.h @@ -463,6 +463,7 @@ bool fw3_parse_target(void *ptr, const char *val); bool fw3_parse_limit(void *ptr, const char *val); bool fw3_parse_device(void *ptr, const char *val); bool fw3_parse_address(void *ptr, const char *val); +bool fw3_parse_network(void *ptr, const char *val); bool fw3_parse_mac(void *ptr, const char *val); bool fw3_parse_port(void *ptr, const char *val); bool fw3_parse_family(void *ptr, const char *val); diff --git a/zones.c b/zones.c index a2ace47..9f4df58 100644 --- a/zones.c +++ b/zones.c @@ -80,8 +80,8 @@ const struct fw3_option fw3_zone_opts[] = { FW3_OPT("output", target, zone, policy_output), FW3_OPT("masq", bool, zone, masq), - FW3_LIST("masq_src", address, zone, masq_src), - FW3_LIST("masq_dest", address, zone, masq_dest), + FW3_LIST("masq_src", network, zone, masq_src), + FW3_LIST("masq_dest", network, zone, masq_dest), FW3_OPT("extra", string, zone, extra_src), FW3_OPT("extra_src", string, zone, extra_src), @@ -462,9 +462,13 @@ print_zone_rule(struct fw3_state *state, enum fw3_family family, fw3_foreach(msrc, &zone->masq_src) fw3_foreach(mdest, &zone->masq_dest) { - fw3_pr("-A zone_%s_postrouting ", zone->name); + if (!fw3_is_family(msrc, family) || + !fw3_is_family(mdest, family)) + continue; + + fw3_pr("-A zone_%s_postrouting", zone->name); fw3_format_src_dest(msrc, mdest); - fw3_pr("-j MASQUERADE\n"); + fw3_pr(" -j MASQUERADE\n"); } } break;