Implement support for "network" datatype and use it for masq_src / masq_dest
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 18 Mar 2013 15:38:33 +0000 (16:38 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 19 Mar 2013 12:28:50 +0000 (13:28 +0100)
options.c
options.h
zones.c

index 5c529b30f2b512d1de903836a13f670779bec420..98ef9de195bac6882f21ba1a43979ddc88f6a928 100644 (file)
--- 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)
 {
index 33224b8383e9d790322486256994fb9178141c77..b00bdb55c0166486c09ffefb10331cff267b4308 100644 (file)
--- 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 a2ace471c3e6088d027e8e82fc3bfd2b8fd3f64a..9f4df5864c875e3939eef0574ec1a404150db442 100644 (file)
--- 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;