redirects: respect src_dip option for reflection rules
authorJo-Philipp Wich <jow@openwrt.org>
Thu, 8 Jan 2015 13:17:16 +0000 (14:17 +0100)
committerJo-Philipp Wich <jow@openwrt.org>
Thu, 8 Jan 2015 13:17:16 +0000 (14:17 +0100)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
redirects.c
zones.c
zones.h

index 89b3ad939de4193ceaec7229bd9b3730fec19b01..a30c5406b9fd47f24a2e965c01ce63d2824804a1 100644 (file)
@@ -136,7 +136,7 @@ resolve_dest(struct uci_element *e, struct fw3_redirect *redir,
 
        list_for_each_entry(zone, &state->zones, list)
        {
-               addrs = fw3_resolve_zone_addresses(zone);
+               addrs = fw3_resolve_zone_addresses(zone, NULL);
 
                if (!addrs)
                        continue;
@@ -593,8 +593,8 @@ expand_redirect(struct fw3_ipt_handle *handle, struct fw3_state *state,
        if (!redir->_dest || !redir->_src->masq)
                return;
 
-       ext_addrs = fw3_resolve_zone_addresses(redir->_src);
-       int_addrs = fw3_resolve_zone_addresses(redir->_dest);
+       ext_addrs = fw3_resolve_zone_addresses(redir->_src, &redir->ip_dest);
+       int_addrs = fw3_resolve_zone_addresses(redir->_dest, NULL);
 
        if (!ext_addrs || !int_addrs)
                goto out;
diff --git a/zones.c b/zones.c
index 0e17d680ef8d3dcaa3ee33f1c95fe02b6b641a4d..2ddd7b44443f3b2714e19ffb2f8b8b29320700d2 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -678,10 +678,10 @@ fw3_lookup_zone(struct fw3_state *state, const char *name)
 }
 
 struct list_head *
-fw3_resolve_zone_addresses(struct fw3_zone *zone)
+fw3_resolve_zone_addresses(struct fw3_zone *zone, struct fw3_address *addr)
 {
        struct fw3_device *net;
-       struct fw3_address *addr, *tmp;
+       struct fw3_address *cur, *tmp;
        struct list_head *all;
 
        all = calloc(1, sizeof(*all));
@@ -690,18 +690,31 @@ fw3_resolve_zone_addresses(struct fw3_zone *zone)
 
        INIT_LIST_HEAD(all);
 
-       list_for_each_entry(net, &zone->networks, list)
-               fw3_ubus_address(all, net->name);
-
-       list_for_each_entry(addr, &zone->subnets, list)
+       if (addr && addr->set)
        {
                tmp = malloc(sizeof(*tmp));
 
-               if (!tmp)
-                       continue;
+               if (tmp)
+               {
+                       *tmp = *addr;
+                       list_add_tail(&tmp->list, all);
+               }
+       }
+       else
+       {
+               list_for_each_entry(net, &zone->networks, list)
+                       fw3_ubus_address(all, net->name);
+
+               list_for_each_entry(cur, &zone->subnets, list)
+               {
+                       tmp = malloc(sizeof(*tmp));
 
-               memcpy(tmp, addr, sizeof(*tmp));
-               list_add_tail(&tmp->list, all);
+                       if (!tmp)
+                               continue;
+
+                       *tmp = *cur;
+                       list_add_tail(&tmp->list, all);
+               }
        }
 
        return all;
diff --git a/zones.h b/zones.h
index cf5ce3c7ee1da2fd81ee4bc4aec1e07c27c3bd5e..4205196268f75061280ac13da656ab4362245a06 100644 (file)
--- a/zones.h
+++ b/zones.h
@@ -44,7 +44,8 @@ void fw3_hotplug_zones(struct fw3_state *state, bool add);
 
 struct fw3_zone * fw3_lookup_zone(struct fw3_state *state, const char *name);
 
-struct list_head * fw3_resolve_zone_addresses(struct fw3_zone *zone);
+struct list_head * fw3_resolve_zone_addresses(struct fw3_zone *zone,
+                                              struct fw3_address *addr);
 
 #define fw3_free_zone(zone) \
        fw3_free_object(zone, fw3_zone_opts)