diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-07-05 14:18:04 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-07-05 15:10:43 +0200 |
commit | 6094417533d97662f693d134ab04595a292de30c (patch) | |
tree | fffff9ec567c011095f9d5239481baff78b985a3 | |
parent | 0be9a1d0c1db1164a296a70157c01d1e5165d6cc (diff) |
fix ifname for alias+vlan chains
-rw-r--r-- | device.c | 9 | ||||
-rw-r--r-- | device.h | 4 | ||||
-rw-r--r-- | ubus.c | 3 | ||||
-rw-r--r-- | vlan.c | 12 |
4 files changed, 25 insertions, 3 deletions
@@ -163,6 +163,7 @@ alias_device_create(const char *name, struct blob_attr *attr) alias = calloc(1, sizeof(*alias) + strlen(name) + 1); strcpy(alias->name, name); alias->dev.set_state = alias_device_set_state; + alias->dev.hidden = true; device_init_virtual(&alias->dev, &alias_device_type, NULL); alias->avl.key = alias->name; avl_insert(&aliases, &alias->avl); @@ -269,13 +270,19 @@ alias_notify_device(const char *name, struct device *dev) device_remove_user(&alias->dep); strcpy(alias->dev.ifname, dev->ifname); device_add_user(&alias->dep, dev); + alias->dev.hidden = false; + device_broadcast_event(&alias->dev, DEV_EVENT_UPDATE_IFNAME); } } device_set_present(&alias->dev, !!dev); - if (!dev && alias->dep.dev && !alias->dep.dev->active) + if (!dev && alias->dep.dev && !alias->dep.dev->active) { device_remove_user(&alias->dep); + alias->dev.hidden = true; + alias->dev.ifname[0] = 0; + device_broadcast_event(&alias->dev, DEV_EVENT_UPDATE_IFNAME); + } device_unlock(); } @@ -66,6 +66,8 @@ enum device_event { DEV_EVENT_ADD, DEV_EVENT_REMOVE, + DEV_EVENT_UPDATE_IFNAME, + DEV_EVENT_SETUP, DEV_EVENT_TEARDOWN, DEV_EVENT_UP, @@ -113,9 +115,11 @@ struct device { bool sys_present; bool present; int active; + bool external; bool disabled; bool deferred; + bool hidden; bool current_config; bool default_config; @@ -496,7 +496,8 @@ netifd_handle_status(struct ubus_context *ctx, struct ubus_object *obj, blobmsg_add_string(&b, "proto", iface->proto_handler->name); dev = iface->main_dev.dev; - if (dev && !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) + if (dev && !dev->hidden && + !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) blobmsg_add_string(&b, "device", dev->ifname); if (iface->state == IFS_UP) { @@ -61,6 +61,12 @@ static int vlan_set_device_state(struct device *dev, bool up) return ret; } +static void vlan_dev_set_name(struct vlan_device *vldev, struct device *dev) +{ + vldev->dev.hidden = dev->hidden; + snprintf(vldev->dev.ifname, IFNAMSIZ, "%s.%d", dev->ifname, vldev->id); +} + static void vlan_dev_cb(struct device_user *dep, enum device_event ev) { struct vlan_device *vldev; @@ -73,6 +79,10 @@ static void vlan_dev_cb(struct device_user *dep, enum device_event ev) case DEV_EVENT_REMOVE: device_set_present(&vldev->dev, false); break; + case DEV_EVENT_UPDATE_IFNAME: + vlan_dev_set_name(vldev, dep->dev); + device_broadcast_event(&vldev->dev, ev); + break; default: break; } @@ -104,7 +114,6 @@ static struct device *get_vlan_device(struct device *dev, int id, bool create) return NULL; vldev = calloc(1, sizeof(*vldev)); - snprintf(vldev->dev.ifname, IFNAMSIZ, "%s.%d", dev->ifname, id); device_init_virtual(&vldev->dev, &vlan_type, NULL); vldev->dev.default_config = true; @@ -113,6 +122,7 @@ static struct device *get_vlan_device(struct device *dev, int id, bool create) vldev->dev.set_state = vlan_set_device_state; vldev->id = id; + vlan_dev_set_name(vldev, dev); vldev->dep.cb = vlan_dev_cb; device_add_user(&vldev->dep, dev); |