From 359adcfc54c0b1f5c8597658bc219dae57b9f082 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 7 Jun 2017 16:18:30 +0200 Subject: [PATCH] options: emit an empty address item when resolving networks fails 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 --- options.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/options.c b/options.c index f686cf0..6d2a283 100644 --- 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); -- 2.30.2