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 28e561b..067f624 100644 (file)
--- a/vlan.c
+++ b/vlan.c
@@ -50,7 +50,7 @@ static int vlan_set_device_state(struct device *dev, bool up)
        }
 
        ret = device_claim(&vldev->dep);
-       if (ret)
+       if (ret < 0)
                return ret;
 
        system_vlan_add(vldev->dep.dev, vldev->id);
@@ -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)
@@ -79,14 +82,8 @@ static void vlan_dev_cb(struct device_user *dep, enum device_event ev)
        case DEV_EVENT_REMOVE:
                device_set_present(&vldev->dev, new_state);
                break;
-       case DEV_EVENT_LINK_UP:
-               new_state = true;
-       case DEV_EVENT_LINK_DOWN:
-               device_set_link(&vldev->dev, new_state);
-               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 */
@@ -99,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,
@@ -125,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_virtual(&vldev->dev, &vlan_type, NULL);
+       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;