key to data elements point at wrong memory area
[project/netifd.git] / interface.c
index 81de337..0620617 100644 (file)
@@ -151,7 +151,7 @@ interface_add_data(struct interface *iface, const struct blob_attr *data)
 
        n = calloc(1, sizeof(*n) + blob_pad_len(data));
        memcpy(n->data, data, blob_pad_len(data));
-       n->node.key = blobmsg_name(data);
+       n->node.key = blobmsg_name(n->data);
 
        o = avl_find_element(&iface->data, n->node.key, o, node);
        if (o)
@@ -220,6 +220,9 @@ __interface_set_down(struct interface *iface, bool force)
        interface_proto_event(iface->proto, PROTO_CMD_TEARDOWN, force);
        if (force)
                interface_flush_state(iface);
+
+       if (iface->dynamic)
+               vlist_delete(&interfaces, &iface->node);
 }
 
 static void
@@ -375,6 +378,7 @@ interface_alias_cb(struct interface_user *dep, struct interface *iface, enum int
                interface_remove_user(dep);
                break;
        case IFEV_RELOAD:
+       case IFEV_UPDATE:
                break;
        }
 }
@@ -480,8 +484,10 @@ interface_proto_cb(struct interface_proto_state *state, enum interface_proto_eve
 
        switch (ev) {
        case IFPEV_UP:
-               if (iface->state != IFS_SETUP)
+               if (iface->state != IFS_SETUP) {
+                       interface_event(iface, IFEV_UPDATE);
                        return;
+               }
 
                interface_ip_set_enabled(&iface->config_ip, true);
                system_flush_routes();
@@ -530,7 +536,7 @@ void interface_set_proto_state(struct interface *iface, struct interface_proto_s
 
 void
 interface_init(struct interface *iface, const char *name,
-              struct blob_attr *config)
+              struct blob_attr *config, bool dynamic)
 {
        struct blob_attr *tb[IFACE_ATTR_MAX];
        struct blob_attr *cur;
@@ -600,6 +606,10 @@ interface_init(struct interface *iface, const char *name,
        }
 
        iface->config_autostart = iface->autostart;
+       iface->dynamic = dynamic;
+
+       if (iface->dynamic)
+               iface->node.version = -1; // Don't delete on reload
 }
 
 static bool __interface_add(struct interface *iface, struct blob_attr *config, bool alias)
@@ -675,6 +685,9 @@ interface_set_main_dev(struct interface *iface, struct device *dev)
                interface_set_l3_dev(iface, dev);
 
        device_add_user(&iface->main_dev, dev);
+       if (!dev)
+               return;
+
        if (claimed)
                device_claim(&iface->l3_dev);