Change wording of inferred destination warning for redirects
[project/firewall3.git] / zones.c
diff --git a/zones.c b/zones.c
index 3d3812c..4de6625 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -189,6 +189,14 @@ fw3_load_zones(struct fw3_state *state, struct uci_package *p)
                        continue;
                }
 
+               if (strlen(zone->name) > FW3_ZONE_MAXNAMELEN)
+               {
+                       warn_elem(e, "must not have a name longer than %u characters",
+                                    FW3_ZONE_MAXNAMELEN);
+                       fw3_free_zone(zone);
+                       continue;
+               }
+
                if (list_empty(&zone->networks) && list_empty(&zone->devices) &&
                    list_empty(&zone->subnets) && !zone->extra_src)
                {
@@ -635,22 +643,47 @@ fw3_lookup_zone(struct fw3_state *state, const char *name)
        return NULL;
 }
 
-void
-fw3_free_zone(struct fw3_zone *zone)
+struct list_head *
+fw3_resolve_zone_addresses(struct fw3_zone *zone)
 {
-       struct fw3_device *dev, *tmp;
+       struct fw3_device *net;
+       struct fw3_address *addr, *tmp;
+       struct list_head *addrs, *all;
 
-       list_for_each_entry_safe(dev, tmp, &zone->devices, list)
+       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)
        {
-               list_del(&dev->list);
-               free(dev);
+               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_safe(dev, tmp, &zone->networks, list)
+       list_for_each_entry(addr, &zone->subnets, list)
        {
-               list_del(&dev->list);
-               free(dev);
+               tmp = malloc(sizeof(*tmp));
+
+               if (!tmp)
+                       continue;
+
+               memcpy(tmp, addr, sizeof(*tmp));
+               list_add_tail(&tmp->list, all);
        }
 
-       fw3_free_object(zone, fw3_zone_opts);
+       return all;
 }