#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <ctype.h>
#include "netifd.h"
#include "system.h"
static void vlan_dev_cb(struct device_user *dep, enum device_event ev)
{
- char name[IFNAMSIZ + 1];
+ char name[IFNAMSIZ];
struct vlan_device *vldev;
vldev = container_of(dep, struct vlan_device, dep);
};
struct vlan_device *vldev;
struct device_user *dep;
- char name[IFNAMSIZ + 1];
+ char name[IFNAMSIZ];
char *err = NULL;
int id, *alias_id;
{
s = strchr(s, '.');
if (!s)
- goto out;
+ return NULL;
*s = 0;
s++;
-out:
return s;
}
-struct device *get_vlan_device_chain(const char *ifname, bool create)
+struct device *get_vlan_device_chain(const char *ifname, int create)
{
- struct device *dev = NULL;
+ struct device *dev = NULL, *vldev;
char *buf, *s, *next;
buf = strdup(ifname);
return NULL;
s = split_vlan(buf);
- dev = device_get(buf, create);
- if (!dev)
- goto error;
+ dev = __device_get(buf, create, false);
+ if (!dev || !s)
+ goto out;
- do {
+ /* for the first split, we need to check if we're using an alias or
+ * if the . separator isn't being used as a vlan separator (e.g. for
+ * AP WDS VLANs */
+ if (!isdigit(s[0])) {
+ next = split_vlan(s);
+ vldev = get_vlan_device(dev, s, create);
+ if (!vldev) {
+ s[-1] = '.';
+ dev = __device_get(buf, create, false);
+ if (!dev)
+ goto out;
+
+ if (next)
+ next[-1] = '.';
+ } else {
+ dev = vldev;
+ s = next;
+ }
+ }
+
+
+ while (s) {
next = split_vlan(s);
dev = get_vlan_device(dev, s, create);
if (!dev)
- goto error;
+ break;
s = next;
- if (!s)
- goto out;
- } while (1);
+ }
-error:
- dev = NULL;
out:
free(buf);
return dev;