Add fw3_resolve_zone_addresses() helper to obtain a list of all subnets covered by...
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 26 May 2013 14:02:24 +0000 (16:02 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 26 May 2013 14:09:06 +0000 (16:09 +0200)
zones.c
zones.h

diff --git a/zones.c b/zones.c
index 4c17c6800cc3d8738038800b8fbd8f8d8f2421a5..dbf682f482b763b6e2dbaacf6e5bb5ba2c3fc590 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -643,6 +643,51 @@ fw3_lookup_zone(struct fw3_state *state, const char *name)
        return NULL;
 }
 
+struct list_head *
+fw3_resolve_zone_addresses(struct fw3_zone *zone)
+{
+       struct fw3_device *net;
+       struct fw3_address *addr, *tmp;
+       struct list_head *addrs, *all;
+
+       all = malloc(sizeof(*all));
+
+       if (!all)
+               return NULL;
+
+       memset(all, 0, sizeof(*all));
+       INIT_LIST_HEAD(all);
+
+       list_for_each_entry(net, &zone->networks, list)
+       {
+               addrs = fw3_ubus_address(net->name);
+
+               if (!addrs)
+                       continue;
+
+               list_for_each_entry_safe(addr, tmp, addrs, list)
+               {
+                       list_del(&addr->list);
+                       list_add_tail(&addr->list, all);
+               }
+
+               free(addrs);
+       }
+
+       list_for_each_entry(addr, &zone->subnets, list)
+       {
+               tmp = malloc(sizeof(*tmp));
+
+               if (!tmp)
+                       continue;
+
+               memcpy(tmp, addr, sizeof(*tmp));
+               list_add_tail(&tmp->list, all);
+       }
+
+       return all;
+}
+
 void
 fw3_free_zone(struct fw3_zone *zone)
 {
diff --git a/zones.h b/zones.h
index dfae81c9d013efe9e306dc7c7dc6e67a076bb128..b438870fc0cbc38b8e7cd0814a7d1578bb79dd6c 100644 (file)
--- a/zones.h
+++ b/zones.h
@@ -44,6 +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);
+
 void fw3_free_zone(struct fw3_zone *zone);
 
 #define fw3_to_src_target(t) \