summaryrefslogtreecommitdiff
path: root/vlan.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2020-11-20 18:58:10 +0100
committerFelix Fietkau <nbd@nbd.name>2020-11-20 19:01:17 +0100
commit4544f026bb0996adb6d95224031f0ba35cb8c046 (patch)
tree0ed33ee832d2ef7037b0bf15ea884c688b2db3c7 /vlan.c
parent5e18d5b9ccb189efb914733e7b74073f5c75e0df (diff)
downloadnetifd-4544f026bb0996adb6d95224031f0ba35cb8c046.tar.gz
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 <nbd@nbd.name>
Diffstat (limited to 'vlan.c')
-rw-r--r--vlan.c22
1 files changed, 14 insertions, 8 deletions
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;