From nobody Sun Dec 22 08:11:00 2024 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 1733318478169903.7172446610532; Wed, 4 Dec 2024 05:21:18 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id C5B1D13DF; Wed, 4 Dec 2024 08:21:16 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 74504136C; Wed, 4 Dec 2024 08:20:48 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0B806136A; Wed, 4 Dec 2024 08:20:45 -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 05E9E136B for ; Wed, 4 Dec 2024 08:20:43 -0500 (EST) Received: from folly.solinno.co.uk (folly.dyn.solinno.co.uk [192.168.2.135]) by doppler.solinno.uk (Postfix) with ESMTPSA id BB42620AB5; Wed, 4 Dec 2024 13:20:42 +0000 (GMT) Received: by folly.solinno.co.uk (Postfix, from userid 1000) id 9A3AE200CC; Wed, 4 Dec 2024 13:20:42 +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.8 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=1733318442; bh=nUCymzAxCd9q0IB10LI5WW+mfI7hEQmphWxh4ZbZM3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JU/kYh5ljKonzQ3jwlLJmp8tKFX67f3egpqnvm+RiVZ67FsM0rjI9a226mTanUP7O LHN0QdFkoI8p5/rLzHLL5l9qcylFWV71ZlFpLJ9jN6I6nlIjbvXP0NkAcRwWTglFlP 5yAyNEtQOwZEx5HKtlODeRPQjYHiYwY6oYQ08pc8= From: Leigh Brown To: devel@lists.libvirt.org Subject: [RFC PATCH 1/3] util: bridge: add virNetDevBridgeSetupVlans() Date: Wed, 4 Dec 2024 13:20:35 +0000 Message-Id: <20241204132037.10809-2-leigh@solinno.co.uk> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241204132037.10809-1-leigh@solinno.co.uk> References: <20241204132037.10809-1-leigh@solinno.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: SN2TL4ESQPQQ4KGQTGFNHY7CNVIQHCMB X-Message-ID-Hash: SN2TL4ESQPQQ4KGQTGFNHY7CNVIQHCMB 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: 1733318480612116600 Content-Type: text/plain; charset="utf-8" In preparation for adding vlan support using iproute2 bridge vlan functionality, add the virNetDevBridgeSetupVlans function that configures a bridge interface using the passed virNetDevVlan struct. Signed-off-by: Leigh Brown --- meson.build | 1 + src/util/virnetdevbridge.c | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/meson.build b/meson.build index ca1b915737..39c01ebeef 100644 --- a/meson.build +++ b/meson.build @@ -857,6 +857,7 @@ optional_programs =3D [ 'ovs-vsctl', 'rmmod', 'tc', + 'bridge', ] + optional_test_programs =20 missing_optional_programs =3D [] diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c index 5fd88f3195..0862342cee 100644 --- a/src/util/virnetdevbridge.c +++ b/src/util/virnetdevbridge.c @@ -24,6 +24,7 @@ #include "virfile.h" #include "virlog.h" #include "virstring.h" +#include "vircommand.h" =20 #ifdef WITH_NET_IF_H # include @@ -379,8 +380,61 @@ virNetDevBridgePortSetIsolated(const char *brname G_GN= UC_UNUSED, _("Unable to set bridge port isolated on this pla= tform")); return -1; } + #endif =20 +static int +virNetDevBridgeSetupVlans(const char *ifname, const virNetDevVlan *virtVla= n) +{ + g_autoptr(virCommand) cmd =3D NULL; + + if (!virtVlan || !virtVlan->nTags) + return 0; + + // The interface will have been automatically added to vlan 1, so remo= ve it + cmd =3D virCommandNewArgList(BRIDGE, "vlan", "delete", + "dev", ifname, "vid", "1", NULL); + if (virCommandRun(cmd, NULL) < 0) + return -1; + + // If trunk mode, add the native VLAN then add any others + if (virtVlan->trunk) { + size_t i; + + virCommandFree(cmd); + cmd =3D virCommandNewArgList(BRIDGE, "vlan", "add", + "dev", ifname, "vid", NULL); + virCommandAddArgFormat(cmd, "%d", virtVlan->nativeTag); + virCommandAddArg(cmd, "pvid"); + if (virtVlan->nativeMode =3D=3D VIR_NATIVE_VLAN_MODE_UNTAGGED) + virCommandAddArg(cmd, "untagged"); + if (virCommandRun(cmd, NULL) < 0) + return -1; + + for (i =3D 0; i < virtVlan->nTags; i++) { + if (virtVlan->tag[i] !=3D virtVlan->nativeTag) { + virCommandFree(cmd); + cmd =3D virCommandNewArgList(BRIDGE, "vlan", "add", + "dev", ifname, "vid", NULL); + virCommandAddArgFormat(cmd, "%d", virtVlan->tag[i]); + if (virCommandRun(cmd, NULL) < 0) + return -1; + } + } + } else { + // In native mode, add the single VLAN as pvid untagged + virCommandFree(cmd); + cmd =3D virCommandNewArgList(BRIDGE, "vlan", "add", + "dev", ifname, "vid", NULL); + virCommandAddArgFormat(cmd, "%d", virtVlan->tag[0]); + virCommandAddArgList(cmd, "pvid", "untagged", NULL); + if (virCommandRun(cmd, NULL) < 0) + return -1; + } + + return 0; +} + =20 /** * virNetDevBridgeCreate: --=20 2.39.5