char name[];
};
+struct bridge_vlan_hotplug_port {
+ struct list_head list;
+ struct bridge_vlan_port port;
+};
+
static void
bridge_reset_primary(struct bridge_state *bst)
{
static struct bridge_vlan_port *
bridge_find_vlan_member_port(struct bridge_member *bm, struct bridge_vlan *vlan)
{
+ struct bridge_vlan_hotplug_port *port;
const char *ifname = bm->dev.dev->ifname;
int i;
return &vlan->ports[i];
}
+ list_for_each_entry(port, &vlan->hotplug_ports, list) {
+ if (strcmp(port->port.ifname, ifname) != 0)
+ continue;
+
+ return &port->port;
+ }
+
return NULL;
}
static void
bridge_free_member(struct bridge_member *bm)
{
+ struct bridge_state *bst = bm->bst;
struct device *dev = bm->dev.dev;
+ const char *ifname = dev->ifname;
+ struct bridge_vlan *vlan;
bridge_remove_member(bm);
+
+ vlist_for_each_element(&bst->dev.vlans, vlan, node) {
+ struct bridge_vlan_hotplug_port *port, *tmp;
+
+ list_for_each_entry_safe(port, tmp, &vlan->hotplug_ports, list) {
+ if (strcmp(port->port.ifname, ifname) != 0)
+ continue;
+
+ list_del(&port->list);
+ free(port);
+ }
+ }
+
device_remove_user(&bm->dev);
/*
bridge_create_member(bst, name, dev, false);
}
+static void
+bridge_hotplug_create_member_vlans(struct bridge_state *bst, struct blob_attr *vlans, const char *ifname)
+{
+ struct bridge_vlan *vlan;
+ struct blob_attr *cur;
+ int rem;
+
+ if (!vlans)
+ return;
+
+ blobmsg_for_each_attr(cur, vlans, rem) {
+ struct bridge_vlan_hotplug_port *port;
+ uint16_t flags = BRVLAN_F_UNTAGGED;
+ char *name_buf;
+ unsigned int vid;
+ char *end;
+
+ if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
+ continue;
+
+ vid = strtoul(blobmsg_get_string(cur), &end, 0);
+ if (!vid || vid > 4095)
+ continue;
+
+ vlan = vlist_find(&bst->dev.vlans, &vid, vlan, node);
+ if (!vlan)
+ continue;
+
+ if (end && *end) {
+ if (*end != ':')
+ continue;
+
+ for (end++; *end; end++) {
+ switch (*end) {
+ case 't':
+ flags &= ~BRVLAN_F_UNTAGGED;
+ break;
+ case '*':
+ flags |= BRVLAN_F_PVID;
+ break;
+ }
+ }
+ }
+
+ port = calloc_a(sizeof(*port), &name_buf, strlen(ifname) + 1);
+ if (!port)
+ continue;
+
+ port->port.flags = flags;
+ port->port.ifname = strcpy(name_buf, ifname);
+ list_add_tail(&port->list, &vlan->hotplug_ports);
+ }
+}
+
static int
-bridge_hotplug_add(struct device *dev, struct device *member)
+bridge_hotplug_add(struct device *dev, struct device *member, struct blob_attr *vlan)
{
struct bridge_state *bst = container_of(dev, struct bridge_state, dev);
+ bridge_hotplug_create_member_vlans(bst, vlan, member->ifname);
bridge_create_member(bst, member->ifname, member, true);
return 0;
return true;
}
+static void
+bridge_vlan_free(struct bridge_vlan *vlan)
+{
+ struct bridge_vlan_hotplug_port *port, *tmp;
+
+ if (!vlan)
+ return;
+
+ list_for_each_entry_safe(port, tmp, &vlan->hotplug_ports, list)
+ free(port);
+
+ free(vlan);
+}
+
static void
bridge_vlan_update(struct vlist_tree *tree, struct vlist_node *node_new,
struct vlist_node *node_old)
if (node_old)
bridge_set_vlan_state(bst, vlan_old, false);
+ if (node_old && node_new)
+ list_splice_init(&vlan_old->hotplug_ports, &vlan_new->hotplug_ports);
+
if (node_new)
bridge_set_vlan_state(bst, vlan_new, true);
bst->dev.config_pending = true;
out:
- free(vlan_old);
+ bridge_vlan_free(vlan_old);
}
static struct device *
}
static int
-interface_add_link(struct interface *iface, struct device *dev, bool link_ext)
+interface_add_link(struct interface *iface, struct device *dev,
+ struct blob_attr *vlan, bool link_ext)
{
struct device *mdev = iface->main_dev.dev;
if (mdev) {
if (mdev->hotplug_ops)
- return mdev->hotplug_ops->add(mdev, dev);
+ return mdev->hotplug_ops->add(mdev, dev, vlan);
else
return UBUS_STATUS_NOT_SUPPORTED;
}
}
int
-interface_handle_link(struct interface *iface, const char *name, bool add, bool link_ext)
+interface_handle_link(struct interface *iface, const char *name,
+ struct blob_attr *vlan, bool add, bool link_ext)
{
struct device *dev;
int ret;
interface_set_device_config(iface, dev);
device_set_present(dev, true);
- ret = interface_add_link(iface, dev, link_ext);
+ ret = interface_add_link(iface, dev, vlan, link_ext);
} else {
ret = interface_remove_link(iface, dev);
}
enum {
DEV_LINK_NAME,
DEV_LINK_EXT,
+ DEV_LINK_VLAN,
__DEV_LINK_MAX,
};
static const struct blobmsg_policy dev_link_policy[__DEV_LINK_MAX] = {
[DEV_LINK_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
[DEV_LINK_EXT] = { .name = "link-ext", .type = BLOBMSG_TYPE_BOOL },
+ [DEV_LINK_VLAN] = { .name = "vlan", .type = BLOBMSG_TYPE_ARRAY },
};
static int
if (cur)
link_ext = blobmsg_get_bool(cur);
- return interface_handle_link(iface, blobmsg_data(tb[DEV_LINK_NAME]), add, link_ext);
+ return interface_handle_link(iface, blobmsg_data(tb[DEV_LINK_NAME]),
+ tb[DEV_LINK_VLAN], add, link_ext);
}