interface: Fix triggering of interface update event
[project/netifd.git] / vlandev.c
index 7b2038e..7e46251 100644 (file)
--- a/vlandev.c
+++ b/vlandev.c
 #include "system.h"
 
 enum {
-       VLANDEV_ATTR_TYPE,
        VLANDEV_ATTR_IFNAME,
        VLANDEV_ATTR_VID,
        __VLANDEV_ATTR_MAX
 };
 
 static const struct blobmsg_policy vlandev_attrs[__VLANDEV_ATTR_MAX] = {
-       [VLANDEV_ATTR_TYPE] = { "type", BLOBMSG_TYPE_STRING },
        [VLANDEV_ATTR_IFNAME] = { "ifname", BLOBMSG_TYPE_STRING },
        [VLANDEV_ATTR_VID] = { "vid", BLOBMSG_TYPE_INT32 },
 };
@@ -40,6 +38,8 @@ static const struct uci_blob_param_list vlandev_attr_list = {
        .next = { &device_attr_list },
 };
 
+static struct device_type vlan8021q_device_type;
+
 struct vlandev_device {
        struct device dev;
        struct device_user parent;
@@ -63,12 +63,6 @@ vlandev_base_cb(struct device_user *dev, enum device_event ev)
        case DEV_EVENT_REMOVE:
                device_set_present(&mvdev->dev, false);
                break;
-       case DEV_EVENT_LINK_UP:
-               device_set_link(&mvdev->dev, true);
-               break;
-       case DEV_EVENT_LINK_DOWN:
-               device_set_link(&mvdev->dev, false);
-               break;
        default:
                return;
        }
@@ -131,6 +125,7 @@ vlandev_free(struct device *dev)
 
        mvdev = container_of(dev, struct vlandev_device, dev);
        device_remove_user(&mvdev->parent);
+       free(mvdev->config_data);
        free(mvdev);
 }
 
@@ -163,15 +158,10 @@ vlandev_apply_settings(struct vlandev_device *mvdev, struct blob_attr **tb)
        struct vlandev_config *cfg = &mvdev->config;
        struct blob_attr *cur;
 
-       cfg->proto = VLAN_PROTO_8021Q;
+       cfg->proto = (mvdev->dev.type == &vlan8021q_device_type) ?
+               VLAN_PROTO_8021Q : VLAN_PROTO_8021AD;
        cfg->vid = 1;
 
-       if ((cur = tb[VLANDEV_ATTR_TYPE]))
-       {
-               if(!strcmp(blobmsg_data(cur), "8021ad"))
-                       cfg->proto = VLAN_PROTO_8021AD;
-       }
-
        if ((cur = tb[VLANDEV_ATTR_VID]))
                cfg->vid = (uint16_t) blobmsg_get_u32(cur);
 }
@@ -185,6 +175,7 @@ vlandev_reload(struct device *dev, struct blob_attr *attr)
        struct vlandev_device *mvdev;
 
        mvdev = container_of(dev, struct vlandev_device, dev);
+       attr = blob_memdup(attr);
 
        blobmsg_parse(device_attr_list.params, __DEV_ATTR_MAX, tb_dev,
                blob_data(attr), blob_len(attr));
@@ -214,12 +205,14 @@ vlandev_reload(struct device *dev, struct blob_attr *attr)
                vlandev_config_init(dev);
        }
 
+       free(mvdev->config_data);
        mvdev->config_data = attr;
        return ret;
 }
 
 static struct device *
-vlandev_create(const char *name, struct blob_attr *attr)
+vlandev_create(const char *name, struct device_type *devtype,
+              struct blob_attr *attr)
 {
        struct vlandev_device *mvdev;
        struct device *dev = NULL;
@@ -229,7 +222,7 @@ vlandev_create(const char *name, struct blob_attr *attr)
                return NULL;
 
        dev = &mvdev->dev;
-       device_init(dev, &vlandev_device_type, name);
+       device_init(dev, devtype, name);
        dev->config_pending = true;
 
        mvdev->set_state = dev->set_state;
@@ -243,14 +236,28 @@ vlandev_create(const char *name, struct blob_attr *attr)
        return dev;
 }
 
-const struct device_type vlandev_device_type = {
-       .name = "VLANDEV",
+static struct device_type vlan8021ad_device_type = {
+       .name = "8021ad",
        .config_params = &vlandev_attr_list,
-       .keep_link_status = true,
+       .create = vlandev_create,
+       .config_init = vlandev_config_init,
+       .reload = vlandev_reload,
+       .free = vlandev_free,
+       .dump_info = vlandev_dump_info,
+};
 
+static struct device_type vlan8021q_device_type = {
+       .name = "8021q",
+       .config_params = &vlandev_attr_list,
        .create = vlandev_create,
        .config_init = vlandev_config_init,
        .reload = vlandev_reload,
        .free = vlandev_free,
        .dump_info = vlandev_dump_info,
 };
+
+static void __init vlandev_device_type_init(void)
+{
+       device_type_add(&vlan8021ad_device_type);
+       device_type_add(&vlan8021q_device_type);
+}