From nobody Sun Feb 8 23:23:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552999641662849.9845000581212; Tue, 19 Mar 2019 05:47:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B5393316891A; Tue, 19 Mar 2019 12:47:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 827E85D777; Tue, 19 Mar 2019 12:47:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3C10F181A263; Tue, 19 Mar 2019 12:47:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2JClHgT028773 for ; Tue, 19 Mar 2019 08:47:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id BA57B5D776; Tue, 19 Mar 2019 12:47:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-54.ams2.redhat.com [10.36.112.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id BBE5B5D763; Tue, 19 Mar 2019 12:47:15 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 19 Mar 2019 12:46:30 +0000 Message-Id: <20190319124700.16722-7-berrange@redhat.com> In-Reply-To: <20190319124700.16722-1-berrange@redhat.com> References: <20190319124700.16722-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 06/36] util: add helper method for re-attaching a tap device to a bridge X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 19 Mar 2019 12:47:20 +0000 (UTC) Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Cole Robinson --- src/libvirt_private.syms | 1 + src/util/virnetdevtap.c | 69 ++++++++++++++++++++++++++++++++++++++++ src/util/virnetdevtap.h | 12 +++++++ 3 files changed, 82 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d9494a04bb..6f5a734fdb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2461,6 +2461,7 @@ virNetDevTapDelete; virNetDevTapGetName; virNetDevTapGetRealDeviceName; virNetDevTapInterfaceStats; +virNetDevTapReattachBridge; =20 =20 # util/virnetdevveth.h diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 972f3405aa..0484c7c5a4 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -553,6 +553,75 @@ virNetDevTapAttachBridge(const char *tapname, } =20 =20 +/** + * virNetDevTapReattachBridge: + * @tapname: the tap interface name (or name template) + * @brname: the bridge name + * @macaddr: desired MAC address + * @virtPortProfile: bridge/port specific configuration + * @virtVlan: vlan tag info + * @mtu: requested MTU for port (or 0 for "default") + * @actualMTU: MTU actually set for port (after accounting for bridge's MT= U) + * + * Ensures that the tap device (@tapname) is connected to the bridge + * (@brname), potentially removing it from any existing bridge that + * does not match. + * + * Returns 0 in case of success or -1 on failure + */ +int +virNetDevTapReattachBridge(const char *tapname, + const char *brname, + const virMacAddr *macaddr, + const unsigned char *vmuuid, + virNetDevVPortProfilePtr virtPortProfile, + virNetDevVlanPtr virtVlan, + unsigned int mtu, + unsigned int *actualMTU) +{ + bool useOVS =3D false; + char *master =3D NULL; + + if (virNetDevGetMaster(tapname, &master) < 0) + return -1; + + /* IFLA_MASTER for a tap on an OVS switch is always "ovs-system" */ + if (STREQ_NULLABLE(master, "ovs-system")) { + useOVS =3D true; + VIR_FREE(master); + if (virNetDevOpenvswitchInterfaceGetMaster(tapname, &master) < 0) + return -1; + } + + /* Nothing more todo if we're on the right bridge already */ + if (STREQ_NULLABLE(brname, master)) + return 0; + + /* disconnect from current (incorrect) bridge, if any */ + if (master) { + int ret; + VIR_INFO("Removing %s from %s", tapname, master); + if (useOVS) + ret =3D virNetDevOpenvswitchRemovePort(master, tapname); + else + ret =3D virNetDevBridgeRemovePort(master, tapname); + VIR_FREE(master); + if (ret < 0) + return -1; + } + + VIR_INFO("Attaching %s to %s", tapname, brname); + if (virNetDevTapAttachBridge(tapname, brname, + macaddr, vmuuid, + virtPortProfile, + virtVlan, + mtu, actualMTU) < 0) + return -1; + + return 0; +} + + /** * virNetDevTapCreateInBridgePort: * @brname: the bridge name diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h index 226122aa2c..2b3893cd37 100644 --- a/src/util/virnetdevtap.h +++ b/src/util/virnetdevtap.h @@ -71,6 +71,18 @@ virNetDevTapAttachBridge(const char *tapname, ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_RETURN_CHECK; =20 +int +virNetDevTapReattachBridge(const char *tapname, + const char *brname, + const virMacAddr *macaddr, + const unsigned char *vmuuid, + virNetDevVPortProfilePtr virtPortProfile, + virNetDevVlanPtr virtVlan, + unsigned int mtu, + unsigned int *actualMTU) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) + ATTRIBUTE_RETURN_CHECK; + int virNetDevTapCreateInBridgePort(const char *brname, char **ifname, const virMacAddr *macaddr, --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list