interface-ip: DNS name server sorting support in resolv.conf.auto
[project/netifd.git] / vlan.c
diff --git a/vlan.c b/vlan.c
index 8e7141f..067f624 100644 (file)
--- a/vlan.c
+++ b/vlan.c
@@ -63,8 +63,11 @@ static int vlan_set_device_state(struct device *dev, bool up)
 
 static void vlan_dev_set_name(struct vlan_device *vldev, struct device *dev)
 {
+       char name[IFNAMSIZ];
+
        vldev->dev.hidden = dev->hidden;
-       snprintf(vldev->dev.ifname, IFNAMSIZ, "%s.%d", dev->ifname, vldev->id);
+       snprintf(name, IFNAMSIZ, "%s.%d", dev->ifname, vldev->id);
+       device_set_ifname(&vldev->dev, name);
 }
 
 static void vlan_dev_cb(struct device_user *dep, enum device_event ev)
@@ -81,7 +84,6 @@ static void vlan_dev_cb(struct device_user *dep, enum device_event ev)
                break;
        case DEV_EVENT_UPDATE_IFNAME:
                vlan_dev_set_name(vldev, dep->dev);
-               device_broadcast_event(&vldev->dev, ev);
                break;
        case DEV_EVENT_TOPO_CHANGE:
                /* Propagate topo changes */
@@ -94,7 +96,7 @@ static void vlan_dev_cb(struct device_user *dep, enum device_event ev)
 
 static struct device *get_vlan_device(struct device *dev, int id, bool create)
 {
-       static const struct device_type vlan_type = {
+       static struct device_type vlan_type = {
                .name = "VLAN",
                .config_params = &device_attr_list,
                .free = free_vlan_if,
@@ -120,11 +122,14 @@ static struct device *get_vlan_device(struct device *dev, int id, bool create)
        D(DEVICE, "Create vlan device '%s.%d'\n", dev->ifname, id);
 
        vldev = calloc(1, sizeof(*vldev));
+       if (!vldev)
+               return NULL;
 
        vldev->id = id;
-       vlan_dev_set_name(vldev, dev);
 
-       device_init(&vldev->dev, &vlan_type, vldev->dev.ifname);
+       device_init(&vldev->dev, &vlan_type, NULL);
+
+       vlan_dev_set_name(vldev, dev);
        vldev->dev.default_config = true;
 
        vldev->set_state = vldev->dev.set_state;