nterface-ip: remove superfluous iface check in interface_ip_set_enabled()
[project/netifd.git] / tunnel.c
index 3ef5086..3fa3e21 100644 (file)
--- a/tunnel.c
+++ b/tunnel.c
@@ -35,22 +35,47 @@ tunnel_set_state(struct device *dev, bool up)
 
        ret = tun->set_state(dev, up);
        if (ret || !up)
-               system_del_ip_tunnel(dev->ifname);
+               system_del_ip_tunnel(dev->ifname, dev->config);
 
        return ret;
 }
 
+static enum dev_change_type
+tunnel_reload(struct device *dev, struct blob_attr *attr)
+{
+       struct blob_attr *tb_dev[__DEV_ATTR_MAX];
+       const struct uci_blob_param_list *cfg = dev->type->config_params;
+
+       if (uci_blob_check_equal(dev->config, attr, cfg))
+               return DEV_CONFIG_NO_CHANGE;
+
+       memset(tb_dev, 0, sizeof(tb_dev));
+
+       if (attr)
+               blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, tb_dev,
+                       blob_data(attr), blob_len(attr));
+
+       device_init_settings(dev, tb_dev);
+
+       return DEV_CONFIG_RESTART;
+}
+
 static struct device *
-tunnel_create(const char *name, struct blob_attr *attr)
+tunnel_create(const char *name, struct device_type *devtype,
+       struct blob_attr *attr)
 {
        struct tunnel *tun;
        struct device *dev;
 
        tun = calloc(1, sizeof(*tun));
+       if (!tun)
+               return NULL;
+
        dev = &tun->dev;
-       device_init(dev, &tunnel_device_type, name);
+       device_init(dev, devtype, name);
        tun->set_state = dev->set_state;
        dev->set_state = tunnel_set_state;
+       device_apply_config(dev, devtype, attr);
        device_set_present(dev, true);
 
        return dev;
@@ -64,12 +89,15 @@ tunnel_free(struct device *dev)
        free(tun);
 }
 
-const struct device_type tunnel_device_type = {
-       .name = "IP tunnel",
+struct device_type tunnel_device_type = {
+       .name = "tunnel",
        .config_params = &tunnel_attr_list,
-
+       .reload = tunnel_reload,
        .create = tunnel_create,
        .free = tunnel_free,
 };
 
-
+static void __init tunnel_device_type_init(void)
+{
+       device_type_add(&tunnel_device_type);
+}