[PATCH 3/3] wireless: allow adding bridge vlans

John Crispin john at phrozen.org
Sun Jul 12 12:50:20 EDT 2020


An AP/Vlan will only have a virtual 802.1q tag. Add code to make the bridge
add the define vid and take care of possibly tagging when the packet leaves
the bridge.

Signed-off-by: John Crispin <john at phrozen.org>
---
 wireless.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 wireless.h |  4 ++++
 2 files changed, 53 insertions(+)

diff --git a/wireless.c b/wireless.c
index efb7992..0596b59 100644
--- a/wireless.c
+++ b/wireless.c
@@ -16,6 +16,7 @@
 #include "wireless.h"
 #include "handler.h"
 #include "ubus.h"
+#include "system.h"
 
 #define WIRELESS_SETUP_RETRY	3
 
@@ -49,6 +50,8 @@ enum {
 	VIF_ATTR_NETWORK,
 	VIF_ATTR_ISOLATE,
 	VIF_ATTR_MODE,
+	VIF_ATTR_VID,
+	VIF_ATTR_UNTAG,
 	__VIF_ATTR_MAX,
 };
 
@@ -57,6 +60,8 @@ static const struct blobmsg_policy vif_policy[__VIF_ATTR_MAX] = {
 	[VIF_ATTR_NETWORK] = { .name = "network", .type = BLOBMSG_TYPE_ARRAY },
 	[VIF_ATTR_ISOLATE] = { .name = "isolate", .type = BLOBMSG_TYPE_BOOL },
 	[VIF_ATTR_MODE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
+	[VIF_ATTR_VID] = { .name = "vid", .type = BLOBMSG_TYPE_INT32 },
+	[VIF_ATTR_UNTAG] = { .name = "vlan_untag", .type = BLOBMSG_TYPE_BOOL },
 };
 
 static const struct uci_blob_param_list vif_param = {
@@ -68,6 +73,8 @@ enum {
 	VLAN_ATTR_DISABLED,
 	VLAN_ATTR_NETWORK,
 	VLAN_ATTR_ISOLATE,
+	VLAN_ATTR_VID,
+	VLAN_ATTR_UNTAG,
 	__VLAN_ATTR_MAX,
 };
 
@@ -75,6 +82,8 @@ static const struct blobmsg_policy vlan_policy[__VLAN_ATTR_MAX] = {
 	[VLAN_ATTR_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
 	[VLAN_ATTR_NETWORK] = { .name = "network", .type = BLOBMSG_TYPE_ARRAY },
 	[VLAN_ATTR_ISOLATE] = { .name = "isolate", .type = BLOBMSG_TYPE_BOOL },
+	[VLAN_ATTR_VID] = { .name = "vid", .type = BLOBMSG_TYPE_INT32 },
+	[VLAN_ATTR_UNTAG] = { .name = "vlan_untag", .type = BLOBMSG_TYPE_BOOL },
 };
 
 static const struct uci_blob_param_list vlan_param = {
@@ -313,6 +322,8 @@ static void wireless_interface_handle_link(struct wireless_interface *vif, bool
 	}
 
 	blobmsg_for_each_attr(cur, vif->network, rem) {
+		struct device *bridge;
+
 		network = blobmsg_data(cur);
 
 		iface = vlist_find(&interfaces, network, iface, node);
@@ -320,6 +331,16 @@ static void wireless_interface_handle_link(struct wireless_interface *vif, bool
 			continue;
 
 		interface_handle_link(iface, vif->ifname, up, true);
+
+		if (!vif->vid)
+			continue;
+
+		bridge = device_get(iface->ifname, 0);
+		if (!bridge || !bridge->type->bridge_capability)
+			continue;
+
+		system_bridge_vlan(vif->ifname, 1, vif->vid, 0, 0, 1);
+		system_bridge_vlan(iface->ifname, 0, vif->vid, !vif->untag, 1, 1);
 	}
 }
 
@@ -343,6 +364,8 @@ static void wireless_vlan_handle_link(struct wireless_vlan *vlan, bool up)
 	}
 
 	blobmsg_for_each_attr(cur, vlan->network, rem) {
+		struct device *bridge;
+
 		network = blobmsg_data(cur);
 
 		iface = vlist_find(&interfaces, network, iface, node);
@@ -350,6 +373,16 @@ static void wireless_vlan_handle_link(struct wireless_vlan *vlan, bool up)
 			continue;
 
 		interface_handle_link(iface, vlan->ifname, up, true);
+
+		if (!vlan->vid)
+			continue;
+
+		bridge = device_get(iface->ifname, 0);
+		if (!bridge || !bridge->type->bridge_capability)
+			continue;
+
+		system_bridge_vlan(vlan->ifname, 1, vlan->vid, 0, 0, 1);
+		system_bridge_vlan(iface->ifname, 0, vlan->vid, !vlan->untag, 1, 1);
 	}
 }
 
@@ -767,6 +800,14 @@ wireless_interface_init_config(struct wireless_interface *vif)
 	cur = tb[VIF_ATTR_MODE];
 	if (cur)
 		vif->ap_mode = !strcmp(blobmsg_get_string(cur), "ap");
+
+	cur = tb[VIF_ATTR_UNTAG];
+	if (cur)
+		vif->untag = blobmsg_get_bool(cur);
+
+	cur = tb[VIF_ATTR_VID];
+	if (cur)
+		vif->vid = blobmsg_get_u32(cur);
 }
 
 static void
@@ -829,6 +870,14 @@ wireless_vlan_init_config(struct wireless_vlan *vlan)
 	cur = tb[VLAN_ATTR_ISOLATE];
 	if (cur)
 		vlan->isolate = blobmsg_get_bool(cur);
+
+	cur = tb[VLAN_ATTR_UNTAG];
+	if (cur)
+		vlan->untag = blobmsg_get_bool(cur);
+
+	cur = tb[VLAN_ATTR_VID];
+	if (cur)
+		vlan->vid = blobmsg_get_u32(cur);
 }
 
 static void
diff --git a/wireless.h b/wireless.h
index 5fedd20..2160451 100644
--- a/wireless.h
+++ b/wireless.h
@@ -90,6 +90,8 @@ struct wireless_interface {
 	struct blob_attr *network;
 	bool isolate;
 	bool ap_mode;
+	bool untag;
+	int vid;
 };
 
 struct wireless_vlan {
@@ -106,6 +108,8 @@ struct wireless_vlan {
 	const char *ifname;
 	struct blob_attr *network;
 	bool isolate;
+	bool untag;
+	int vid;
 };
 
 struct wireless_station {
-- 
2.25.1




More information about the openwrt-devel mailing list