From 4544f026bb0996adb6d95224031f0ba35cb8c046 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 20 Nov 2020 18:58:10 +0100 Subject: bridge-vlan: add support for defining aliases for vlan ids When defining a bridge-vlan like this: config bridge-vlan option device 'switch0' option vlan '1' option ports 'lan1 lan2 lan3 lan4' option alias 'lan' You can use switch0.lan instead of switch0.1 to refer to the VLAN. This ensures that the VLAN ID can be kept in a single place in the config Signed-off-by: Felix Fietkau --- vlan.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'vlan.c') diff --git a/vlan.c b/vlan.c index e238461..82b2d66 100644 --- a/vlan.c +++ b/vlan.c @@ -161,7 +161,7 @@ vlan_config_init(struct device *dev) vlan_hotplug_check(vldev, vldev->dep.dev); } -static struct device *get_vlan_device(struct device *dev, int id, bool create) +static struct device *get_vlan_device(struct device *dev, char *id_str, bool create) { static struct device_type vlan_type = { .name = "VLAN", @@ -172,6 +172,17 @@ static struct device *get_vlan_device(struct device *dev, int id, bool create) struct vlan_device *vldev; struct device_user *dep; char name[IFNAMSIZ + 1]; + char *err = NULL; + int id, *alias_id; + + id = strtoul(id_str, &err, 10); + if (err && *err) { + alias_id = kvlist_get(&dev->vlan_aliases, id_str); + if (!alias_id) + return NULL; + + id = *alias_id; + } /* look for an existing interface before creating a new one */ list_for_each_entry(dep, &dev->users.list, list.list) { @@ -238,8 +249,7 @@ out: struct device *get_vlan_device_chain(const char *ifname, bool create) { struct device *dev = NULL; - char *buf, *s, *next, *err = NULL; - int id; + char *buf, *s, *next; buf = strdup(ifname); if (!buf) @@ -252,11 +262,7 @@ struct device *get_vlan_device_chain(const char *ifname, bool create) do { next = split_vlan(s); - id = strtoul(s, &err, 10); - if (err && *err) - goto error; - - dev = get_vlan_device(dev, id, create); + dev = get_vlan_device(dev, s, create); if (!dev) goto error; -- cgit v1.2.1