proto-shell: allow running protocols without proto_task.
[project/netifd.git] / interface.c
index f72d967..a9ecf28 100644 (file)
@@ -68,15 +68,9 @@ static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = {
        [IFACE_ATTR_FORCE_LINK] = { .name = "force_link", .type = BLOBMSG_TYPE_BOOL },
 };
 
-static const struct uci_blob_param_info iface_attr_info[IFACE_ATTR_MAX] = {
-       [IFACE_ATTR_DNS] = { .type = BLOBMSG_TYPE_STRING },
-       [IFACE_ATTR_IP6CLASS] = { .type = BLOBMSG_TYPE_STRING },
-};
-
 const struct uci_blob_param_list interface_attr_list = {
        .n_params = IFACE_ATTR_MAX,
        .params = iface_attrs,
-       .info = iface_attr_info,
 };
 
 static void
@@ -145,7 +139,7 @@ void interface_add_error(struct interface *iface, const char *subsystem,
                memcpy(dest, data[i], datalen[i]);
                dest += datalen[i];
        }
-       error->data[n_data++] = NULL;
+       error->data[n_data] = NULL;
 
        if (subsystem)
                error->subsystem = strcpy(d_subsys, subsystem);
@@ -520,6 +514,21 @@ interface_alias_cb(struct interface_user *dep, struct interface *iface, enum int
 }
 
 static void
+interface_set_device_config(struct interface *iface, struct device *dev)
+{
+       if (!dev || !dev->default_config)
+               return;
+
+       if (!iface->device_config &&
+           (!dev->iface_config || dev->config_iface != iface))
+               return;
+
+       dev->config_iface = iface;
+       dev->iface_config = iface->device_config;
+       device_apply_config(dev, dev->type, iface->config);
+}
+
+static void
 interface_claim_device(struct interface *iface)
 {
        struct interface *parent;
@@ -535,8 +544,7 @@ interface_claim_device(struct interface *iface)
        } else if (iface->ifname &&
                !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) {
                dev = device_get(iface->ifname, true);
-               if (dev && dev->default_config && iface->device_config)
-                       device_apply_config(dev, dev->type, iface->config);
+               interface_set_device_config(iface, dev);
        } else {
                dev = iface->ext_dev.dev;
        }
@@ -943,9 +951,7 @@ interface_handle_link(struct interface *iface, const char *name, bool add, bool
        }
 
        if (add) {
-               if (iface->device_config && dev->default_config)
-                       device_apply_config(dev, dev->type, iface->config);
-
+               interface_set_device_config(iface, dev);
                device_set_present(dev, true);
 
                ret = interface_add_link(iface, dev, link_ext);
@@ -1047,7 +1053,7 @@ interface_device_config_changed(struct interface *if_old, struct interface *if_n
        struct blob_attr *ntb[__DEV_ATTR_MAX];
        struct blob_attr *otb[__DEV_ATTR_MAX];
        struct device *dev = if_old->main_dev.dev;
-       unsigned long diff;
+       unsigned long diff = 0;
 
        BUILD_BUG_ON(sizeof(diff) < __DEV_ATTR_MAX / 8);