From nobody Tue Sep 9 19:11:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=solinno.co.uk Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1735810259219130.24653844339957; Thu, 2 Jan 2025 01:30:59 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8F262C62; Thu, 2 Jan 2025 04:30:58 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3C3E9A62; Thu, 2 Jan 2025 04:29:48 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6B14CA4F; Thu, 2 Jan 2025 04:29:42 -0500 (EST) Received: from doppler.solinno.uk (doppler.solinno.uk [81.2.106.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 868F7A4F for ; Thu, 2 Jan 2025 04:29:40 -0500 (EST) Received: from plato.solinno.co.uk (plato.dyn.solinno.co.uk [192.168.2.64]) by doppler.solinno.uk (Postfix) with ESMTPSA id AFD6420B76; Thu, 2 Jan 2025 09:29:38 +0000 (GMT) Received: by plato.solinno.co.uk (Postfix, from userid 1000) id 1A18840; Thu, 02 Jan 2025 09:29:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=solinno.co.uk; s=mail; t=1735810178; bh=uHcgAWsDm6o3vrFCIvVq0WVBdx96WtmwgEQ3T8KTfSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JHfldxtF+mUQUne1PXo1pTpZTo53Odmt0isekecuUYYSUeUOoZObhPUZlgY05Zeko AB9awVBEszOf0waXEPv1Gd389pr3dbiJgLF46NGQaoNrSXD5BVPBAZFxxMDqMsNKKD HL5tTN0jBG2bz3U/kxXdJs+Wp6MaBmZf9ZQbs/rs= From: Leigh Brown To: devel@lists.libvirt.org, Laine Stump Subject: [RFC v3 PATCH 1/4] util: add netlink bridge vlan filtering Date: Thu, 2 Jan 2025 09:29:33 +0000 Message-ID: <20250102092936.3046-2-leigh@solinno.co.uk> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250102092936.3046-1-leigh@solinno.co.uk> References: <20250102092936.3046-1-leigh@solinno.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: SAKILSNRIDVFZ2PVVTXNDEKZ35SAJB63 X-Message-ID-Hash: SAKILSNRIDVFZ2PVVTXNDEKZ35SAJB63 X-MailFrom: leigh@solinno.co.uk X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Leigh Brown X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZM-MESSAGEID: 1735810260641019100 Content-Type: text/plain; charset="utf-8" Enable capability to add and remove vlan filters for a standard linux bridge using netlink. New function virNetlinkBridgeVlanFilterSet can be used to add or remove a vlan filter to a given bridge interface. Signed-off-by: Leigh Brown Reviewed-by: Laine Stump --- src/util/virnetlink.c | 66 +++++++++++++++++++++++++++++++++++++++++++ src/util/virnetlink.h | 7 +++++ 2 files changed, 73 insertions(+) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index 24cd69a385..206646d9d7 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -701,6 +701,72 @@ virNetlinkDelLink(const char *ifname, virNetlinkTalkFa= llback fallback) return 0; } =20 +/** + * virNetlinkBridgeVlanFilterSet: + * + * @ifname: name of the link + * @cmd: netlink command, either RTM_SETLINK or RTM_DELLINK + * @flags: flags to use when adding the vlan filter + * @vid: vlan id to add or remove + * @error: netlink error code + * + * Add or remove a vlan filter from an interface associated with a + * bridge. + * + * Returns 0 on success, -1 on error. Additionally, if the @error is + * non-zero, then a netlink failure occurred, but no error message + * is generated leaving it up to the caller to handle the condition. + */ +int +virNetlinkBridgeVlanFilterSet(const char *ifname, + int cmd, + const unsigned short flags, + const short vid, + int *error) +{ + struct ifinfomsg ifm =3D { .ifi_family =3D PF_BRIDGE }; + struct bridge_vlan_info vinfo =3D { .flags =3D flags, .vid =3D vid }; + struct nlattr *afspec =3D NULL; + g_autoptr(virNetlinkMsg) nl_msg =3D NULL; + g_autofree struct nlmsghdr *resp =3D NULL; + unsigned int resp_len =3D 0; + + *error =3D 0; + + if (vid < 1 || vid > 4095) { + virReportError(ERANGE, _("vlanid out of range: %1$d"), vid); + return -1; + } + + if (!(cmd =3D=3D RTM_SETLINK || cmd =3D=3D RTM_DELLINK)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid vlan filter command %1$d"), cmd); + return -1; + } + + if (virNetDevGetIndex(ifname, &ifm.ifi_index) < 0) + return -1; + + nl_msg =3D virNetlinkMsgNew(cmd, NLM_F_REQUEST); + + NETLINK_MSG_APPEND(nl_msg, sizeof(ifm), &ifm); + + NETLINK_MSG_NEST_START(nl_msg, afspec, IFLA_AF_SPEC); + NETLINK_MSG_PUT(nl_msg, IFLA_BRIDGE_VLAN_INFO, sizeof(vinfo), &vinfo); + NETLINK_MSG_NEST_END(nl_msg, afspec); + + if (virNetlinkTalk(ifname, nl_msg, 0, 0, &resp, &resp_len, error, NULL= ) < 0) + return -1; + + if (resp->nlmsg_type !=3D NLMSG_ERROR && resp->nlmsg_type !=3D NLMSG_D= ONE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed netlink response message")); + return -1; + } + + return 0; +} + /** * virNetlinkGetNeighbor: * diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 75192f645f..327fb426a1 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -25,6 +25,7 @@ #if defined(WITH_LIBNL) =20 # include +# include =20 typedef struct nl_msg virNetlinkMsg; G_DEFINE_AUTOPTR_CLEANUP_FUNC(virNetlinkMsg, nlmsg_free); @@ -76,6 +77,12 @@ typedef int (*virNetlinkTalkFallback)(const char *ifname= ); =20 int virNetlinkDelLink(const char *ifname, virNetlinkTalkFallback fallback); =20 +int virNetlinkBridgeVlanFilterSet(const char *ifname, + int cmd, + const unsigned short flags, + const short vid, + int *error); + int virNetlinkGetErrorCode(struct nlmsghdr *resp, unsigned int recvbuflen); =20 int virNetlinkDumpLink(const char *ifname, int ifindex, --=20 2.39.5 From nobody Tue Sep 9 19:11:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=solinno.co.uk Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1735810296382857.0986268435253; Thu, 2 Jan 2025 01:31:36 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5B14FB80; Thu, 2 Jan 2025 04:31:35 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id CBE31A95; Thu, 2 Jan 2025 04:29:50 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6DE97A50; Thu, 2 Jan 2025 04:29:42 -0500 (EST) Received: from doppler.solinno.uk (doppler.solinno.uk [81.2.106.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 87E07A56 for ; Thu, 2 Jan 2025 04:29:40 -0500 (EST) Received: from plato.solinno.co.uk (plato.dyn.solinno.co.uk [192.168.2.64]) by doppler.solinno.uk (Postfix) with ESMTPSA id B1DF620BC6; Thu, 2 Jan 2025 09:29:38 +0000 (GMT) Received: by plato.solinno.co.uk (Postfix, from userid 1000) id 1D4E145; Thu, 02 Jan 2025 09:29:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=solinno.co.uk; s=mail; t=1735810178; bh=1YMnwKoixNbw8o83U+GtpN+nyrRCabfSu3aW+2bn2Ts=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EAZRaWbimtqKlEhydFp1mOg9q+Lx8ArNu3qyprRpi2fRYylsfn4mjTF17wlrFzK8g 42uJvQ9Hfqr0R9B5wnL+v6USGyhro/PFzH0QxnW5ujptJ2KR3UzBqRrUDn79JTGVfW yeYnNoB9LX3u1SLBtQVlKSlPcg96Bd7TkOmm7MLs= From: Leigh Brown To: devel@lists.libvirt.org, Laine Stump Subject: [RFC v3 PATCH 2/4] util: Add vlan support to virNetDevBridgeAddPort Date: Thu, 2 Jan 2025 09:29:34 +0000 Message-ID: <20250102092936.3046-3-leigh@solinno.co.uk> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250102092936.3046-1-leigh@solinno.co.uk> References: <20250102092936.3046-1-leigh@solinno.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AZERVYRBMENVGN4MEMSOMNUBO3I3T3PO X-Message-ID-Hash: AZERVYRBMENVGN4MEMSOMNUBO3I3T3PO X-MailFrom: leigh@solinno.co.uk X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Leigh Brown X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZM-MESSAGEID: 1735810300924019100 Content-Type: text/plain; charset="utf-8" Add virNetDevBridgeSetupVlans function to configures a bridge interface using the passed virNetDevVlan struct. Add virVlan parameter to the Linux version of virNetDevBridgeAddPort and call virNetDevBridgeSetupVlans to set up the required vlan configuration. Update callers of virNetDevBridgeAddPort to pass NULL for now. Signed-off-by: Leigh Brown Reviewed-by: Laine Stump --- src/lxc/lxc_process.c | 2 +- src/util/virnetdevbridge.c | 75 ++++++++++++++++++++++++++++++++++++-- src/util/virnetdevbridge.h | 4 +- src/util/virnetdevtap.c | 2 +- 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index c2982244f0..7c760cec40 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -289,7 +289,7 @@ virLXCProcessSetupInterfaceTap(virDomainDef *vm, vport, virDomainNetGetActualVl= an(net)) < 0) return NULL; } else { - if (virNetDevBridgeAddPort(brname, parentVeth) < 0) + if (virNetDevBridgeAddPort(brname, parentVeth, NULL) < 0) return NULL; =20 if (virDomainNetGetActualPortOptionsIsolated(net) =3D=3D VIR_T= RISTATE_BOOL_YES && diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 5fd88f3195..80f028e9b7 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -313,6 +313,65 @@ virNetDevBridgePortSetIsolated(const char *brname, return virNetDevBridgePortSet(brname, ifname, "isolated", enable ? 1 := 0); } =20 +static int +virNetDevBridgeSetupVlans(const char *ifname, const virNetDevVlan *virtVla= n) +{ + int error =3D 0; + unsigned short flags; + + if (!virtVlan || !virtVlan->nTags) + return 0; + + // The interface will have been automatically added to vlan 1, so remo= ve it + if (virNetlinkBridgeVlanFilterSet(ifname, RTM_DELLINK, 0, 1, &error) <= 0) + goto err_delete; + + // If trunk mode, add the native VLAN then add the others, if any + if (virtVlan->trunk) { + size_t i; + + if (virtVlan->nativeTag) { + flags =3D BRIDGE_VLAN_INFO_PVID; + if (virtVlan->nativeMode =3D=3D VIR_NATIVE_VLAN_MODE_UNTAGGED = || + virtVlan->nativeMode =3D=3D VIR_NATIVE_VLAN_MODE_DEFAULT) + flags |=3D BRIDGE_VLAN_INFO_UNTAGGED; + + if (virNetlinkBridgeVlanFilterSet(ifname, RTM_SETLINK, flags, + virtVlan->nativeTag, &error)= < 0) + goto err_add; + } + + for (i =3D 0; i < virtVlan->nTags; i++) { + if (virtVlan->tag[i] !=3D virtVlan->nativeTag) + if (virNetlinkBridgeVlanFilterSet(ifname, RTM_SETLINK, 0, + virtVlan->tag[i], &error= ) < 0) + goto err_add; + } + } else { + // In native mode, add the single VLAN as pvid untagged + flags =3D BRIDGE_VLAN_INFO_PVID | BRIDGE_VLAN_INFO_UNTAGGED; + if (virNetlinkBridgeVlanFilterSet(ifname, RTM_SETLINK, flags, + virtVlan->tag[0], &error) < 0) + goto err_add; + } + + return 0; + + err_add: + if (error !=3D 0) + virReportSystemError(-error, + _("error adding vlan filter to interface %1$s= "), + ifname); + return -1; + + err_delete: + if (error !=3D 0) + virReportSystemError(-error, + _("error removing vlan filter from interface = %1$s"), + ifname); + return -1; +} + =20 #else int @@ -593,7 +652,8 @@ int virNetDevBridgeDelete(const char *brname G_GNUC_UNU= SED) */ #if defined(WITH_STRUCT_IFREQ) && defined(SIOCBRADDIF) int virNetDevBridgeAddPort(const char *brname, - const char *ifname) + const char *ifname, + const virNetDevVlan *virtVlan) { struct ifreq ifr; VIR_AUTOCLOSE fd =3D -1; @@ -613,14 +673,20 @@ int virNetDevBridgeAddPort(const char *brname, return -1; } =20 - return 0; + return virNetDevBridgeSetupVlans(ifname, virtVlan); } #elif defined(WITH_BSD_BRIDGE_MGMT) int virNetDevBridgeAddPort(const char *brname, - const char *ifname) + const char *ifname, + const virNetDevVlan *virtVlan) { struct ifbreq req =3D { 0 }; =20 + if (virtVlan) { + virReportSystemError(ENOSYS, "%s", _("Not supported on this platfo= rm")); + return -1; + } + if (virStrcpyStatic(req.ifbr_ifsname, ifname) < 0) { virReportSystemError(ERANGE, _("Network interface name '%1$s' is too long"= ), @@ -638,7 +704,8 @@ int virNetDevBridgeAddPort(const char *brname, } #else int virNetDevBridgeAddPort(const char *brname, - const char *ifname) + const char *ifname, + const virNetDevVlan *virtVlan) { virReportSystemError(ENOSYS, _("Unable to add bridge %1$s port %2$s"), brname,= ifname); diff --git a/src/util/virnetdevbridge.h b/src/util/virnetdevbridge.h index db4099bf0b..5f51656abe 100644 --- a/src/util/virnetdevbridge.h +++ b/src/util/virnetdevbridge.h @@ -20,6 +20,7 @@ =20 #include "internal.h" #include "virmacaddr.h" +#include "virnetdevvlan.h" =20 int virNetDevBridgeCreate(const char *brname, const virMacAddr *mac) @@ -28,7 +29,8 @@ int virNetDevBridgeDelete(const char *brname) ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT; =20 int virNetDevBridgeAddPort(const char *brname, - const char *ifname) + const char *ifname, + const virNetDevVlan *virtVlan) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; =20 int virNetDevBridgeRemovePort(const char *brname, diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 2701ba6dfc..a9573eb8e1 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -483,7 +483,7 @@ virNetDevTapAttachBridge(const char *tapname, return -1; } } else { - if (virNetDevBridgeAddPort(brname, tapname) < 0) + if (virNetDevBridgeAddPort(brname, tapname, NULL) < 0) return -1; =20 if (isolatedPort =3D=3D VIR_TRISTATE_BOOL_YES && --=20 2.39.5 From nobody Tue Sep 9 19:11:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=solinno.co.uk Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1735810235896576.8407177608818; Thu, 2 Jan 2025 01:30:35 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 8E20CC63; Thu, 2 Jan 2025 04:30:34 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A9234AD3; Thu, 2 Jan 2025 04:29:45 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id DCB51A50; Thu, 2 Jan 2025 04:29:41 -0500 (EST) Received: from doppler.solinno.uk (doppler.solinno.uk [81.2.106.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 83DE2A50 for ; Thu, 2 Jan 2025 04:29:40 -0500 (EST) Received: from plato.solinno.co.uk (4.8.1.b.4.f.e.4.8.3.4.5.b.6.a.a.a.c.f.8.6.f.d.1.0.b.8.0.1.0.0.2.ip6.arpa [IPv6:2001:8b0:1df6:8fca:aa6b:5438:4ef4:b184]) by doppler.solinno.uk (Postfix) with ESMTPSA id D1FEE20C04; Thu, 2 Jan 2025 09:29:38 +0000 (GMT) Received: by plato.solinno.co.uk (Postfix, from userid 1000) id 20A4B46; Thu, 02 Jan 2025 09:29:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=solinno.co.uk; s=mail; t=1735810178; bh=yzNWw/c0FtgzD7WWxIZDk7XkF1OguvtQr/fPuPqmJsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HwCPd12A7QCjQCKnUO8hq2roy4YPYmZs/cz61IRaffe855YzFwdVHYzBcidv3xCrD PXsKvGCgA7U02Rxhjo33fXyhPJ4uCR8QLGhu8qWPTeAGP8NJ7LEaXZMbh/3Km8pn3c ROolihAPK6wrwK7As0WdLef7j/4DCSXmAu9DI7ZY= From: Leigh Brown To: devel@lists.libvirt.org, Laine Stump Subject: [RFC v3 PATCH 3/4] Enable vlan support for standard linux bridges Date: Thu, 2 Jan 2025 09:29:35 +0000 Message-ID: <20250102092936.3046-4-leigh@solinno.co.uk> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250102092936.3046-1-leigh@solinno.co.uk> References: <20250102092936.3046-1-leigh@solinno.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: R4UFZXPPVXCODTUJR665JGKLXRT4F7LL X-Message-ID-Hash: R4UFZXPPVXCODTUJR665JGKLXRT4F7LL X-MailFrom: leigh@solinno.co.uk X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Leigh Brown X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZM-MESSAGEID: 1735810237339019100 Content-Type: text/plain; charset="utf-8" Adjust domain and network validation to permit standard linux bridges to allow vlan configuration. Update calls to virNetDevBridgeAddPort to pass the vlan configuration. Signed-off-by: Leigh Brown --- src/conf/domain_validate.c | 3 ++- src/lxc/lxc_process.c | 3 ++- src/network/bridge_driver.c | 13 ++++++++----- src/util/virnetdevtap.c | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 1034bb57f5..c7a79a0277 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2077,7 +2077,8 @@ virDomainActualNetDefValidate(const virDomainNetDef *= net) (actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT && virDomainNetGetActualDirectMode(net) =3D=3D VIR_NETDEV_MACV= LAN_MODE_PASSTHRU) || (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - vport && vport->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFI= LE_OPENVSWITCH))) { + vport && vport->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFI= LE_OPENVSWITCH) || + (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && !vport))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("interface %1$s - vlan tag not supported for = this connection type"), macstr); diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 7c760cec40..c427b38605 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -289,7 +289,8 @@ virLXCProcessSetupInterfaceTap(virDomainDef *vm, vport, virDomainNetGetActualVl= an(net)) < 0) return NULL; } else { - if (virNetDevBridgeAddPort(brname, parentVeth, NULL) < 0) + if (virNetDevBridgeAddPort(brname, parentVeth, + virDomainNetGetActualVlan(net)) < 0) return NULL; =20 if (virDomainNetGetActualPortOptionsIsolated(net) =3D=3D VIR_T= RISTATE_BOOL_YES && diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ce793c12ef..8f47ef2574 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -2999,7 +2999,8 @@ networkValidate(virNetworkDriverState *driver, =20 /* The only type of networks that currently support transparent * vlan configuration are those using hostdev sr-iov devices from - * a pool, and those using an Open vSwitch bridge. + * a pool, those using an Open vSwitch bridge, and standard linux + * bridges. */ =20 vlanAllowed =3D (def->forward.type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV = || @@ -3007,15 +3008,17 @@ networkValidate(virNetworkDriverState *driver, (def->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE && def->virtPortProfile && def->virtPortProfile->virtPortType - =3D=3D VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)); + =3D=3D VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) || + (def->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE && + !def->virtPortProfile)); =20 vlanUsed =3D def->vlan.nTags > 0; for (i =3D 0; i < def->nPortGroups; i++) { if (vlanUsed || def->portGroups[i].vlan.nTags > 0) { /* anyone using this portgroup will get a vlan tag. Verify - * that they will also be using an openvswitch connection, - * as that is the only type of network that currently - * supports a vlan tag. + * that they will also be using an openvswitch connection + * or a standard linux bridge as they are the only types of + * network that currently support a vlan tag. */ if (def->portGroups[i].virtPortProfile) { if (def->forward.type !=3D VIR_NETWORK_FORWARD_BRIDGE || diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index a9573eb8e1..1dc77f0f5c 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -483,7 +483,7 @@ virNetDevTapAttachBridge(const char *tapname, return -1; } } else { - if (virNetDevBridgeAddPort(brname, tapname, NULL) < 0) + if (virNetDevBridgeAddPort(brname, tapname, virtVlan) < 0) return -1; =20 if (isolatedPort =3D=3D VIR_TRISTATE_BOOL_YES && --=20 2.39.5 From nobody Tue Sep 9 19:11:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=solinno.co.uk Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1735810325655816.287812554055; Thu, 2 Jan 2025 01:32:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id ECEE9A59; Thu, 2 Jan 2025 04:32:04 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 96B92C05; Thu, 2 Jan 2025 04:29:52 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 86784A4F; Thu, 2 Jan 2025 04:29:42 -0500 (EST) Received: from doppler.solinno.uk (doppler.solinno.uk [81.2.106.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 85395A52 for ; Thu, 2 Jan 2025 04:29:40 -0500 (EST) Received: from plato.solinno.co.uk (plato.dyn.solinno.co.uk [192.168.2.64]) by doppler.solinno.uk (Postfix) with ESMTPSA id B40B320C03; Thu, 2 Jan 2025 09:29:38 +0000 (GMT) Received: by plato.solinno.co.uk (Postfix, from userid 1000) id 2414147; Thu, 02 Jan 2025 09:29:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=solinno.co.uk; s=mail; t=1735810178; bh=gEDuFbyQ4dBFE1hB6LgsW5Wu8aRjIzAATGm6nGg4yxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jLZivMcJxUqPMUGjc18Xq3tyj1rZJmSmLFtYmvbvammfbLLv6HIukWn3E18zKkjtd sCLUxTXO6MmwCiUN8HXJEKEw9Bbu2biKfj4c50kchnveHnCDT3sm69UlnPvwk25vM9 9PjFUIT0AaXgXw/Rl9XxB3CysdGkKWglVO/TKA5I= From: Leigh Brown To: devel@lists.libvirt.org, Laine Stump Subject: [RFC v3 PATCH 4/4] docs: standard linux bridges now support vlans Date: Thu, 2 Jan 2025 09:29:36 +0000 Message-ID: <20250102092936.3046-5-leigh@solinno.co.uk> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250102092936.3046-1-leigh@solinno.co.uk> References: <20250102092936.3046-1-leigh@solinno.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RHHV5EDCYQG2STUVJN5DBLDNBQD42UU7 X-Message-ID-Hash: RHHV5EDCYQG2STUVJN5DBLDNBQD42UU7 X-MailFrom: leigh@solinno.co.uk X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Leigh Brown X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) X-ZM-MESSAGEID: 1735810327086019100 Content-Type: text/plain; charset="utf-8" Update domain XML and network XML documentation to describe how standard linux bridges support the VLAN configuration. Signed-off-by: Leigh Brown Reviewed-by: Laine Stump --- docs/formatdomain.rst | 37 +++++++++++++++++----------------- docs/formatnetwork.rst | 45 +++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 40 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 8d787ef59a..90b025508a 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -6039,28 +6039,29 @@ VLAN tags to apply to the guest's network traffic := since:`Since 0.10.0`. =20 Network connections that support guest-transparent VLAN tagging include ``type=3D'bridge'`` interfaces connected to an Open vSwitch bridge, SRIOV -Virtual Functions (VF) used via ``type=3D'hostdev'`` (direct device assign= ment) -and, :since:`since 1.3.5`, SRIOV VFs used via ``type=3D'direct'`` with -``mode=3D'passthrough'`` (macvtap "passthru" mode). All other -connection types, including standard linux bridges and libvirt's own virtu= al +Virtual Functions (VF) used via ``type=3D'hostdev'`` (direct device assign= ment), +:since:`since 1.3.5`, SRIOV VFs used via ``type=3D'direct'`` with +``mode=3D'passthrough'`` (macvtap "passthru" mode) and, :since:`since 11.0= .0` +standard linux bridges. Other connection types, including libvirt's own vi= rtual networks, **do not** support it. 802.1Qbh (vn-link) and 802.1Qbg (VEPA) sw= itches provide their own way (outside of libvirt) to tag guest traffic onto a spe= cific VLAN. Each tag is given in a separate ```` subelement of ```` (= for example: ````). For VLAN trunking of multiple tags (which = is -supported only on Open vSwitch connections), multiple ```` subelement= s can -be specified, which implies that the user wants to do VLAN trunking on the -interface for all the specified tags. In the case that VLAN trunking of a = single -tag is desired, the optional attribute ``trunk=3D'yes'`` can be added to t= he -toplevel ```` element to differentiate trunking of a single tag from -normal tagging. - -For network connections using Open vSwitch it is also possible to configure -'native-tagged' and 'native-untagged' VLAN modes :since:`Since 1.1.0`. Thi= s is -done with the optional ``nativeMode`` attribute on the ```` subelemen= t: -``nativeMode`` may be set to 'tagged' or 'untagged'. The ``id`` attribute = of the -```` subelement containing ``nativeMode`` sets which VLAN is consider= ed to -be the "native" VLAN for this interface, and the ``nativeMode`` attribute -determines whether or not traffic for that VLAN will be tagged. +supported on Open vSwitch connections and standard linux bridges), multiple +```` subelements can be specified, which implies that the user wants = to do +VLAN trunking on the interface for all the specified tags. In the case tha= t VLAN +trunking of a single tag is desired, the optional attribute ``trunk=3D'yes= '`` can +be added to the toplevel ```` element to differentiate trunking of a +single tag from normal tagging. + +For network connections using Open vSwitch and standard linux bridges it i= s also +possible to configure 'native-tagged' and 'native-untagged' VLAN modes +:since:`Since 1.1.0`. This is done with the optional ``nativeMode`` attrib= ute on +the ```` subelement: ``nativeMode`` may be set to 'tagged' or 'untagg= ed'. +The ``id`` attribute of the ```` subelement containing ``nativeMode``= sets +which VLAN is considered to be the "native" VLAN for this interface, and t= he +``nativeMode`` attribute determines whether or not traffic for that VLAN w= ill be +tagged. =20 =20 Isolating guests' network traffic from each other diff --git a/docs/formatnetwork.rst b/docs/formatnetwork.rst index 9b4ecbf31d..053fe6ad56 100644 --- a/docs/formatnetwork.rst +++ b/docs/formatnetwork.rst @@ -520,28 +520,29 @@ VLAN tags to apply to the guest's network traffic :si= nce:`Since 0.10.0`. =20 Network connections that support guest-transparent VLAN tagging include ``type=3D'bridge'`` interfaces connected to an Open vSwitch bridge, SRIOV -Virtual Functions (VF) used via ``type=3D'hostdev'`` (direct device assign= ment) -and, :since:`since 1.3.5`, SRIOV VFs used via ``type=3D'direct'`` with -``mode=3D'passthrough'`` (macvtap "passthru" mode). All other -connection types, including standard linux bridges and libvirt's own virtu= al -networks, **do not** support it. 802.1Qbh (vn-link) and 802.1Qbg (VEPA) sw= itches -provide their own way (outside of libvirt) to tag guest traffic onto a spe= cific -VLAN. Each tag is given in a separate ```` subelement of ```` (= for -example: ````). For VLAN trunking of multiple tags (which = is -supported only on Open vSwitch connections), multiple ```` subelement= s can -be specified, which implies that the user wants to do VLAN trunking on the -interface for all the specified tags. In the case that VLAN trunking of a = single -tag is desired, the optional attribute ``trunk=3D'yes'`` can be added to t= he -toplevel ```` element to differentiate trunking of a single tag from -normal tagging. - -For network connections using Open vSwitch it is also possible to configure -'native-tagged' and 'native-untagged' VLAN modes :since:`Since 1.1.0`. Thi= s is -done with the optional ``nativeMode`` attribute on the ```` subelemen= t: -``nativeMode`` may be set to 'tagged' or 'untagged'. The ``id`` attribute = of the -```` subelement containing ``nativeMode`` sets which VLAN is consider= ed to -be the "native" VLAN for this interface, and the ``nativeMode`` attribute -determines whether or not traffic for that VLAN will be tagged. +Virtual Functions (VF) used via ``type=3D'hostdev'`` (direct device assign= ment), +:since:`since 1.3.5`, SRIOV VFs used via ``type=3D'direct'`` with +``mode=3D'passthrough'`` (macvtap "passthru" mode) and, :since:`since 11.0= .0`, +standard linux bridges. All other connection types, including libvirt's own +virtual networks, **do not** support it. 802.1Qbh (vn-link) and 802.1Qbg (= VEPA) +switches provide their own way (outside of libvirt) to tag guest traffic o= nto a +specific VLAN. Each tag is given in a separate ```` subelement of +```` (for example: ````). For VLAN trunking of multi= ple +tags (which is supported on Open vSwitch connections and standard linux +bridges), multiple ```` subelements can be specified, which implies t= hat +the user wants to do VLAN trunking on the interface for all the specified = tags. +In the case that VLAN trunking of a single tag is desired, the optional +attribute ``trunk=3D'yes'`` can be added to the toplevel ```` elemen= t to +differentiate trunking of a single tag from normal tagging. + +For network connections using Open vSwitch :since:`since 1.1.10` and stand= ard +linux bridges :since:`since 11.0.0` it is also possible to configure +'native-tagged' and 'native-untagged' VLAN modes. This is done with the op= tional +``nativeMode`` attribute on the ```` subelement: ``nativeMode`` may b= e set +to 'tagged' or 'untagged'. The ``id`` attribute of the ```` subelement +containing ``nativeMode`` sets which VLAN is considered to be the "native"= VLAN +for this interface, and the ``nativeMode`` attribute determines whether or= not +traffic for that VLAN will be tagged. =20 ```` elements can also be specified in a ```` element, as= well as directly in a domain's ```` element. In the case that a vlan= tag --=20 2.39.5