zone: avoid duplicates in devices list
authorTony Ambardar <itugrok@yahoo.com>
Mon, 22 Mar 2021 01:06:18 +0000 (18:06 -0700)
committerJo-Philipp Wich <jo@mein.io>
Tue, 23 Mar 2021 08:59:37 +0000 (09:59 +0100)
While resolving zones to devices it's possible to introduce duplicates due
to the presence of aliased interfaces.

Fix this by consolidating the fw3_zone->devices list during creation.

Signed-off-by: Tony Ambardar <itugrok@yahoo.com>
zones.c

diff --git a/zones.c b/zones.c
index d45077af615abde04781928f35e4e377e7505b13..51a8fdf6af58bb51a7ab39d7f04c50145cb9a725 100644 (file)
--- a/zones.c
+++ b/zones.c
@@ -137,7 +137,7 @@ check_masq_addrs(struct list_head *head)
 static void
 resolve_networks(struct uci_element *e, struct fw3_zone *zone)
 {
-       struct fw3_device *net, *tmp;
+       struct fw3_device *net, *dev, *tmp;
 
        list_for_each_entry(net, &zone->networks, list)
        {
@@ -149,8 +149,15 @@ resolve_networks(struct uci_element *e, struct fw3_zone *zone)
                        continue;
                }
 
+               list_for_each_entry(dev, &zone->devices, list)
+                       if (!strcmp(dev->name, tmp->name))
+                               goto alias;
+
                snprintf(tmp->network, sizeof(tmp->network), "%s", net->name);
                list_add_tail(&tmp->list, &zone->devices);
+               continue;
+alias:
+               free(tmp);
        }
 }