Fix prefix class logic
[project/odhcpd.git] / src / config.c
index d33309f..6c09541 100644 (file)
@@ -273,8 +273,6 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                iface = calloc(1, sizeof(*iface));
                strncpy(iface->name, name, sizeof(iface->name) - 1);
                list_add(&iface->head, &interfaces);
                iface = calloc(1, sizeof(*iface));
                strncpy(iface->name, name, sizeof(iface->name) - 1);
                list_add(&iface->head, &interfaces);
-       } else if (overwrite) {
-               clean_interface(iface);
        }
 
        const char *ifname = NULL;
        }
 
        const char *ifname = NULL;
@@ -282,10 +280,13 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        if (overwrite || !iface->ifname[0])
                ifname = ubus_get_ifname(name);
 #endif
        if (overwrite || !iface->ifname[0])
                ifname = ubus_get_ifname(name);
 #endif
-       if ((c = tb[IFACE_ATTR_IFNAME]))
-               ifname = blobmsg_get_string(c);
-       else if ((c = tb[IFACE_ATTR_NETWORKID]))
-               ifname = blobmsg_get_string(c);
+
+       if (overwrite) {
+               if ((c = tb[IFACE_ATTR_IFNAME]))
+                       ifname = blobmsg_get_string(c);
+               else if ((c = tb[IFACE_ATTR_NETWORKID]))
+                       ifname = blobmsg_get_string(c);
+       }
 
        if (!iface->ifname[0] && !ifname)
                return -1;
 
        if (!iface->ifname[0] && !ifname)
                return -1;
@@ -295,13 +296,10 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
 
        iface->inuse = true;
 
 
        iface->inuse = true;
 
-       if (overwrite)
-               clean_interface(iface);
-
        if ((c = tb[IFACE_ATTR_DYNAMICDHCP]))
                iface->no_dynamic_dhcp = !blobmsg_get_bool(c);
 
        if ((c = tb[IFACE_ATTR_DYNAMICDHCP]))
                iface->no_dynamic_dhcp = !blobmsg_get_bool(c);
 
-       if ((c = tb[IFACE_ATTR_IGNORE]))
+       if (overwrite && (c = tb[IFACE_ATTR_IGNORE]))
                iface->ignore = blobmsg_get_bool(c);
 
        if ((c = tb[IFACE_ATTR_LEASETIME])) {
                iface->ignore = blobmsg_get_bool(c);
 
        if ((c = tb[IFACE_ATTR_LEASETIME])) {
@@ -340,7 +338,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
        if ((c = tb[IFACE_ATTR_MASTER]))
                iface->master = blobmsg_get_bool(c);
 
        if ((c = tb[IFACE_ATTR_MASTER]))
                iface->master = blobmsg_get_bool(c);
 
-       if ((c = tb[IFACE_ATTR_UPSTREAM])) {
+       if (overwrite && (c = tb[IFACE_ATTR_UPSTREAM])) {
                struct blob_attr *cur;
                unsigned rem;
 
                struct blob_attr *cur;
                unsigned rem;
 
@@ -500,6 +498,10 @@ void odhcpd_reload(void)
                free(l);
        }
 
                free(l);
        }
 
+       struct interface *master = NULL, *i, *n;
+       list_for_each_entry(i, &interfaces, head)
+               clean_interface(i);
+
        struct uci_package *dhcp = NULL;
        if (!uci_load(uci, "dhcp", &dhcp)) {
                struct uci_element *e;
        struct uci_package *dhcp = NULL;
        if (!uci_load(uci, "dhcp", &dhcp)) {
                struct uci_element *e;
@@ -518,12 +520,12 @@ void odhcpd_reload(void)
                }
        }
 
                }
        }
 
+
 #ifdef WITH_UBUS
        ubus_apply_network();
 #endif
 
        // Evaluate hybrid mode for master
 #ifdef WITH_UBUS
        ubus_apply_network();
 #endif
 
        // Evaluate hybrid mode for master
-       struct interface *master = NULL, *i, *n;
        list_for_each_entry(i, &interfaces, head) {
                if (!i->master)
                        continue;
        list_for_each_entry(i, &interfaces, head) {
                if (!i->master)
                        continue;
@@ -567,7 +569,6 @@ void odhcpd_reload(void)
                        setup_dhcpv6_interface(i, true);
                        setup_ndp_interface(i, true);
                        setup_dhcpv4_interface(i, true);
                        setup_dhcpv6_interface(i, true);
                        setup_ndp_interface(i, true);
                        setup_dhcpv4_interface(i, true);
-                       i->inuse = false;
                } else {
                        close_interface(i);
                }
                } else {
                        close_interface(i);
                }
@@ -609,7 +610,8 @@ void odhcpd_run(void)
        signal(SIGHUP, handle_signal);
 
 #ifdef WITH_UBUS
        signal(SIGHUP, handle_signal);
 
 #ifdef WITH_UBUS
-       init_ubus();
+       while (init_ubus())
+               sleep(1);
 #endif
 
        odhcpd_reload();
 #endif
 
        odhcpd_reload();