From nobody Sun Dec 22 08:07:04 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 1734690881251600.704171259563; Fri, 20 Dec 2024 02:34:41 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3293D12AF; Fri, 20 Dec 2024 05:34:40 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E057F15FE; Fri, 20 Dec 2024 05:33:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7AF8212A3; Fri, 20 Dec 2024 05:33:04 -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 7A2D11573 for ; Fri, 20 Dec 2024 05:33:02 -0500 (EST) Received: from plato.solinno.co.uk (plato.dyn.solinno.co.uk [192.168.2.203]) by doppler.solinno.uk (Postfix) with ESMTPSA id 9A9F020273; Fri, 20 Dec 2024 10:33:00 +0000 (GMT) Received: by plato.solinno.co.uk (Postfix, from userid 1000) id BA84344; Fri, 20 Dec 2024 10:33:05 +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=1734690780; bh=H5ndDmZmBufZTjCG1jSh2d3qlH9rPu60XxJ/Qnm1Uf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=enNNHFI3VQyZz3VTgfG4S7bw4gUdzqjBOCECuCliWSu2SGTb2ME3jrCuDTQUocKW3 Pk01hfhsIE/ZnuQMx6vwr5t5P1PAXbnKciJySq+ClZGn9qbQZJF49puyES5ZPxs0gt GkaKBvUyLB+OW7BmBYFEPcjhiVzo6d8Ih7X/xMYk= From: Leigh Brown To: devel@lists.libvirt.org Subject: [RFC v2 PATCH 1/4] util: Add virNetDevBridgeSetupVlans function Date: Fri, 20 Dec 2024 10:33:01 +0000 Message-ID: <20241220103304.29496-2-leigh@solinno.co.uk> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241220103304.29496-1-leigh@solinno.co.uk> References: <20241220103304.29496-1-leigh@solinno.co.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: P3SBLWOVNUQPFEXOLO5DLAANF5GDV6D4 X-Message-ID-Hash: P3SBLWOVNUQPFEXOLO5DLAANF5GDV6D4 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: 1734690882174116600 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 | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 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..353f95b040 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,64 @@ 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; + + if (virtVlan->nativeTag) { + 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 = || + virtVlan->nativeMode =3D=3D VIR_NATIVE_VLAN_MODE_DEFAULT) + 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