config: restore interface defaults when cleaning interface
[project/odhcpd.git] / src / config.c
index daf583b..5174f2c 100644 (file)
@@ -162,6 +162,15 @@ static int mkdir_p(char *dir, mode_t mask)
        return ret;
 }
 
        return ret;
 }
 
+static void free_lease(struct lease *l)
+{
+       if (l->head.next)
+               list_del(&l->head);
+
+       free(l->duid);
+       free(l);
+}
+
 static struct interface* get_interface(const char *name)
 {
        struct interface *c;
 static struct interface* get_interface(const char *name)
 {
        struct interface *c;
@@ -171,6 +180,12 @@ static struct interface* get_interface(const char *name)
        return NULL;
 }
 
        return NULL;
 }
 
+static void set_interface_defaults(struct interface *iface)
+{
+       iface->managed = 1;
+       iface->learn_routes = 1;
+}
+
 static void clean_interface(struct interface *iface)
 {
        free(iface->dns);
 static void clean_interface(struct interface *iface)
 {
        free(iface->dns);
@@ -181,6 +196,7 @@ static void clean_interface(struct interface *iface)
        free(iface->dhcpv6_raw);
        free(iface->filter_class);
        memset(&iface->ra, 0, sizeof(*iface) - offsetof(struct interface, ra));
        free(iface->dhcpv6_raw);
        free(iface->filter_class);
        memset(&iface->ra, 0, sizeof(*iface) - offsetof(struct interface, ra));
+       set_interface_defaults(iface);
 }
 
 static void close_interface(struct interface *iface)
 }
 
 static void close_interface(struct interface *iface)
@@ -323,10 +339,9 @@ static int set_lease(struct uci_section *s)
        return 0;
 
 err:
        return 0;
 
 err:
-       if (lease) {
-               free(lease->duid);
-               free(lease);
-       }
+       if (lease)
+               free_lease(lease);
+
        return -1;
 }
 
        return -1;
 }
 
@@ -349,9 +364,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
 
                strncpy(iface->name, name, sizeof(iface->name) - 1);
 
 
                strncpy(iface->name, name, sizeof(iface->name) - 1);
 
-               /* Default settings */
-               iface->managed = 1;
-               iface->learn_routes = true;
+               set_interface_defaults(iface);
 
                list_add(&iface->head, &interfaces);
                overwrite = true;
 
                list_add(&iface->head, &interfaces);
                overwrite = true;
@@ -607,12 +620,8 @@ void odhcpd_reload(void)
 {
        struct uci_context *uci = uci_alloc_context();
 
 {
        struct uci_context *uci = uci_alloc_context();
 
-       while (!list_empty(&leases)) {
-               struct lease *l = list_first_entry(&leases, struct lease, head);
-               list_del(&l->head);
-               free(l->duid);
-               free(l);
-       }
+       while (!list_empty(&leases))
+               free_lease(list_first_entry(&leases, struct lease, head));
 
        struct interface *master = NULL, *i, *n;
 
 
        struct interface *master = NULL, *i, *n;
 
@@ -717,10 +726,10 @@ void odhcpd_reload(void)
                                i->ndp = (master && master->ndp == RELAYD_RELAY) ?
                                                RELAYD_RELAY : RELAYD_DISABLED;
 
                                i->ndp = (master && master->ndp == RELAYD_RELAY) ?
                                                RELAYD_RELAY : RELAYD_DISABLED;
 
-                       setup_router_interface(i, true);
-                       setup_dhcpv6_interface(i, true);
-                       setup_ndp_interface(i, true);
-                       setup_dhcpv4_interface(i, true);
+                       setup_router_interface(i, !i->ignore || i->ra != RELAYD_DISABLED);
+                       setup_dhcpv6_interface(i, !i->ignore || i->dhcpv6 != RELAYD_DISABLED);
+                       setup_ndp_interface(i, !i->ignore || i->ndp != RELAYD_DISABLED);
+                       setup_dhcpv4_interface(i, !i->ignore || i->dhcpv4 != RELAYD_DISABLED);
                } else {
                        close_interface(i);
                }
                } else {
                        close_interface(i);
                }