improve matching api
authorSteven Barth <steven@midlink.org>
Tue, 15 Oct 2013 18:56:26 +0000 (20:56 +0200)
committerSteven Barth <steven@midlink.org>
Tue, 15 Oct 2013 18:56:26 +0000 (20:56 +0200)
src/ubus.c

index 9116dd849f1e3df9125241a76384e37d1420bb69..bf1d072d5d5bc3fae37ec1e3512ccfbd10541ecb 100644 (file)
@@ -238,18 +238,25 @@ void ubus_apply_network(void)
                const char *ifname = (tb[IFACE_ATTR_IFNAME]) ?
                                blobmsg_get_string(tb[IFACE_ATTR_IFNAME]) : "";
 
+               bool matched = false;
                struct interface *c;
                list_for_each_entry(c, &interfaces, head) {
                        char *f = memmem(c->upstream, c->upstream_len,
                                        interface, strlen(interface) + 1);
-                       if (strcmp(interface, c->name) && strcmp(ifname, c->ifname) &&
-                                       (!f || (f != c->upstream && f[-1] != 0)))
+                       bool cmatched = !strcmp(interface, c->name) || !strcmp(ifname, c->ifname);
+                       matched |= cmatched;
+
+                       if (!cmatched && (!f || (f != c->upstream && f[-1] != 0)))
                                continue;
 
-                       if (!c || !c->ignore)
+                       if (!c->ignore)
                                config_parse_interface(blobmsg_data(tb[IFACE_ATTR_DATA]),
-                                               blobmsg_data_len(tb[IFACE_ATTR_DATA]), interface, false);
+                                               blobmsg_data_len(tb[IFACE_ATTR_DATA]), c->name, false);
                }
+
+               if (!matched)
+                       config_parse_interface(blobmsg_data(tb[IFACE_ATTR_DATA]),
+                                       blobmsg_data_len(tb[IFACE_ATTR_DATA]), interface, false);
        }
 }