From a0b4c3356f90dbd5be4f6ddff5bd74319a6655b9 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 18 Mar 2013 16:38:33 +0100 Subject: [PATCH] Implement support for "network" datatype and use it for masq_src / masq_dest --- options.c | 33 +++++++++++++++++++++++++++++++++ options.h | 1 + zones.c | 12 ++++++++---- 3 files changed, 42 insertions(+), 4 deletions(-) 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; -- 2.25.1