options: emit an empty address item when resolving networks fails
authorJo-Philipp Wich <jo@mein.io>
Wed, 7 Jun 2017 14:18:30 +0000 (16:18 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 13 Feb 2018 15:19:22 +0000 (16:19 +0100)
Adjust fw3_parse_network() to emit an empty address item with
.set = false, .resolved = true when we failed to resolve the network
name into any ip address.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
options.c

index f686cf084fa65e59098d5979ef6b0ef3f7224a50..6d2a283fdd8a95f03cdfb3295cb54db8720bed9b 100644 (file)
--- a/options.c
+++ b/options.c
@@ -342,19 +342,31 @@ fw3_parse_network(void *ptr, const char *val, bool is_list)
        struct fw3_device dev = { };
        struct fw3_address *addr, *tmp;
        LIST_HEAD(addr_list);
+       int n_addrs;
 
        if (!fw3_parse_address(ptr, val, is_list))
        {
                if (!fw3_parse_device(&dev, val, false))
                        return false;
 
-               fw3_ubus_address(&addr_list, dev.name);
+               n_addrs = fw3_ubus_address(&addr_list, dev.name);
+
                list_for_each_entry(addr, &addr_list, list)
                {
                        addr->invert = dev.invert;
                        addr->resolved = true;
                }
 
+               /* add an empty address member with .set = false, .resolved = true
+                * to signal resolving failure to callers */
+               if (n_addrs == 0)
+               {
+                       tmp = fw3_alloc(sizeof(*tmp));
+                       tmp->resolved = true;
+
+                       list_add_tail(&tmp->list, &addr_list);
+               }
+
                if (is_list)
                {
                        list_splice_tail(&addr_list, ptr);