From nobody Tue Jan 21 07:28:04 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 1736364985324908.6731611086863; Wed, 8 Jan 2025 11:36:25 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 5409C1389; Wed, 8 Jan 2025 14:36:24 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 187E61402; Wed, 8 Jan 2025 14:34:13 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id E1A44E89; Wed, 8 Jan 2025 14:34:02 -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 90CA71173 for ; Wed, 8 Jan 2025 14:34:01 -0500 (EST) Received: from plato.solinno.co.uk (e.d.1.4.d.2.c.e.4.d.9.9.7.9.7.e.a.c.f.8.6.f.d.1.0.b.8.0.1.0.0.2.ip6.arpa [IPv6:2001:8b0:1df6:8fca:e797:99d4:ec2d:41de]) by doppler.solinno.uk (Postfix) with ESMTPSA id BA23562056; Wed, 8 Jan 2025 19:34:00 +0000 (GMT) Received: by plato.solinno.co.uk (Postfix, from userid 1000) id 636EB45; Wed, 08 Jan 2025 19:34:16 +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=1736364840; bh=w8qXNMvUblMsk/7+PRNXnAFOMzUIZVvm+2vMkdDEZ+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RxlnLir5MD2mL4fOyPGpbLfHWgYPMXI13oG0jCsW/0efbXLJwyNHXSMwWu0ohsUno P0qaNlYdUm2AnFNiDIDlRIJCsaUrpBNzB9A3RScZ6I74v9jaIgseriQP0kB3gJgvGe 5a7NwSK8cgSnwnmkN/Ku0O8SgGee6HCMLAv9AEis= From: Leigh Brown To: devel@lists.libvirt.org, Laine Stump Subject: [PATCH v5 2/4] util: Add vlan support to virNetDevBridgeAddPort Date: Wed, 8 Jan 2025 19:34:13 +0000 Message-ID: <20250108193415.200555-3-leigh@solinno.co.uk> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250108193415.200555-1-leigh@solinno.co.uk> References: <20250108193415.200555-1-leigh@solinno.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FXLHIPQG6L6EW4LON32X4NYUEUD236HH X-Message-ID-Hash: FXLHIPQG6L6EW4LON32X4NYUEUD236HH 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: 1736364986444116600 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 | 77 ++++++++++++++++++++++++++++++++++++-- src/util/virnetdevbridge.h | 4 +- src/util/virnetdevtap.c | 2 +- 4 files changed, 78 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..d080c70dbf 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -313,6 +313,67 @@ 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) { + if (error !=3D 0) + virReportSystemError(-error, + _("error removing vlan filter from interf= ace %1$s"), + ifname); + return -1; + } + + // 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 error; + } + } + + 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 error; + } + } + } 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 error; + } + } + + return 0; + + error: + if (error !=3D 0) + virReportSystemError(-error, + _("error adding vlan filter to interface %1$s= "), + ifname); + return -1; +} + =20 #else int @@ -593,7 +654,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 +675,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 +706,8 @@ int virNetDevBridgeAddPort(const char *brname, } #else int virNetDevBridgeAddPort(const char *brname, - const char *ifname) + const char *ifname, + const virNetDevVlan *virtVlan G_GNUC_UNUSED) { 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