From patchwork Sun Jul 12 16:50:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Crispin X-Patchwork-Id: 1327566 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=phrozen.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=JqJPXf32; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B4Xqp3X52z9sR4 for ; Mon, 13 Jul 2020 02:51:50 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pG5MZOWBvPB8sMYS8P+Utme3VK8kjZAHWWKJSxxxbPo=; b=JqJPXf32Mb/Qc1f5GUSp+/GuS Vt94fKZsnc6sAp4cX90iPX7vIaxv3DCRmJRb289Gy4zEkSycS1VtlC1+OSfcL+ncgtHew0yfspV7F IJPeCJBy/vo/M36xFq5igU8z3nTDqeZB56J2RwRsRvAA3Y6/uP3WjaYjM63xo8EK8diIjTX5IKlHU dyjOOJbzRo3zgkKyfntWqXKHDk7rf5MG23d9fQ+x4WM7KqndKBrjFU5alWcFknWivqtWMLov1qXce 3FNCvyvF5L6KF5Ug0ZuTYl1y2gKlJ31reOOtG71wnmcy3EzS4YuocJb9j7qJFEAVOhEihKSF40++T cS5xnCcpA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jufBV-0002A9-Ra; Sun, 12 Jul 2020 16:50:37 +0000 Received: from nbd.name ([2a01:4f8:221:3d45::2]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jufBN-000282-Uy for openwrt-devel@lists.openwrt.org; Sun, 12 Jul 2020 16:50:32 +0000 Received: from [84.242.30.208] (helo=bertha9.lan) by ds12 with esmtpa (Exim 4.89) (envelope-from ) id 1jufBK-0007By-IJ; Sun, 12 Jul 2020 18:50:26 +0200 From: John Crispin To: openwrt-devel@lists.openwrt.org Subject: [PATCH 3/3] wireless: allow adding bridge vlans Date: Sun, 12 Jul 2020 18:50:20 +0200 Message-Id: <20200712165020.249741-4-john@phrozen.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200712165020.249741-1-john@phrozen.org> References: <20200712165020.249741-1-john@phrozen.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200712_125030_248813_092AC831 X-CRM114-Status: GOOD ( 13.22 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Crispin Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 --- 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 {