From nobody Tue Feb 10 06:43:01 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.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1490108714962442.16190180159265; Tue, 21 Mar 2017 08:05:14 -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 2BCC1C05490C; Tue, 21 Mar 2017 15:05:14 +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 EC0D7B9292; Tue, 21 Mar 2017 15:05:13 +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 8D7EF18521C8; Tue, 21 Mar 2017 15:05:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2LF49eM011459 for ; Tue, 21 Mar 2017 11:04:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B5921837C; Tue, 21 Mar 2017 15:04:09 +0000 (UTC) Received: from vhost2.laine.org (ovpn-116-242.phx2.redhat.com [10.3.116.242]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDA135DD6E for ; Tue, 21 Mar 2017 15:04:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2BCC1C05490C Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=laine.org Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2BCC1C05490C From: Laine Stump To: libvir-list@redhat.com Date: Tue, 21 Mar 2017 11:03:59 -0400 Message-Id: <20170321150400.13422-3-laine@laine.org> In-Reply-To: <20170321150400.13422-1-laine@laine.org> References: <20170321150400.13422-1-laine@laine.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] util: new function virNetDevTapAttachBridge() 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: , MIME-Version: 1.0 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.32]); Tue, 21 Mar 2017 15:05:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch splits out the part of virNetDevTapCreateInBridgePort() that would need to be re-done if an existing tap device had to be re-attached to a bridge, and puts it into a separate function. This can be used both when an existing domain interface config is updated to change its connection, and also to re-attach to the "same" bridge when a network has been stopped and restarted. So far it is used for nothing. --- src/libvirt_private.syms | 1 + src/util/virnetdevtap.c | 111 +++++++++++++++++++++++++++++++------------= ---- src/util/virnetdevtap.h | 12 +++++ 3 files changed, 87 insertions(+), 37 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 1d783b6..905d55a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2106,6 +2106,7 @@ virNetDevOpenvswitchSetTimeout; =20 =20 # util/virnetdevtap.h +virNetDevTapAttachBridge; virNetDevTapCreate; virNetDevTapCreateInBridgePort; virNetDevTapDelete; diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index 41e68f4..02ef7fd 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -505,6 +505,77 @@ int virNetDevTapDelete(const char *ifname ATTRIBUTE_UN= USED, =20 =20 /** + * virNetDevTapAttachBridge: + * @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) + * + * This attaches an existing tap device (@tapname) to a bridge + * (@brname). + * + * Returns 0 in case of success or -1 on failure + */ +int +virNetDevTapAttachBridge(const char *tapname, + const char *brname, + const virMacAddr *macaddr, + const unsigned char *vmuuid, + virNetDevVPortProfilePtr virtPortProfile, + virNetDevVlanPtr virtVlan, + unsigned int mtu, + unsigned int *actualMTU) +{ + /* If an MTU is specified for the new device, set it before + * attaching the device to the bridge, as it may affect the MTU of + * the bridge (in particular if it is the first device attached to + * the bridge, or if it is smaller than the current MTU of the + * bridge). If MTU isn't specified for the new device (i.e. 0), + * we need to set the interface MTU to the current MTU of the + * bridge (to avoid inadvertantly changing the bridge's MTU). + */ + if (mtu > 0) { + if (virNetDevSetMTU(tapname, mtu) < 0) + goto error; + } else { + if (virNetDevSetMTUFromDevice(tapname, brname) < 0) + goto error; + } + if (actualMTU) { + int retMTU =3D virNetDevGetMTU(tapname); + + if (retMTU < 0) + goto error; + + *actualMTU =3D retMTU; + } + + + if (virtPortProfile) { + if (virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFILE_= MIDONET) { + if (virNetDevMidonetBindPort(tapname, virtPortProfile) < 0) + goto error; + } else if (virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT_P= ROFILE_OPENVSWITCH) { + if (virNetDevOpenvswitchAddPort(brname, tapname, macaddr, vmuu= id, + virtPortProfile, virtVlan) < 0) + goto error; + } + } else { + if (virNetDevBridgeAddPort(brname, tapname) < 0) + goto error; + } + + return 0; + + error: + return -1; +} + + +/** * virNetDevTapCreateInBridgePort: * @brname: the bridge name * @ifname: the interface name (or name template) @@ -582,43 +653,9 @@ int virNetDevTapCreateInBridgePort(const char *brname, if (virNetDevSetMAC(*ifname, &tapmac) < 0) goto error; =20 - /* If an MTU is specified for the new device, set it before - * attaching the device to the bridge, as it may affect the MTU of - * the bridge (in particular if it is the first device attached to - * the bridge, or if it is smaller than the current MTU of the - * bridge). If MTU isn't specified for the new device (i.e. 0), - * we need to set the interface MTU to the current MTU of the - * bridge (to avoid inadvertantly changing the bridge's MTU). - */ - if (mtu > 0) { - if (virNetDevSetMTU(*ifname, mtu) < 0) - goto error; - } else { - if (virNetDevSetMTUFromDevice(*ifname, brname) < 0) - goto error; - } - if (actualMTU) { - int retMTU =3D virNetDevGetMTU(*ifname); - - if (retMTU < 0) - goto error; - - *actualMTU =3D retMTU; - } - - - if (virtPortProfile) { - if (virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFILE_= MIDONET) { - if (virNetDevMidonetBindPort(*ifname, virtPortProfile) < 0) - goto error; - } else if (virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT_P= ROFILE_OPENVSWITCH) { - if (virNetDevOpenvswitchAddPort(brname, *ifname, macaddr, vmuu= id, - virtPortProfile, virtVlan) < 0) - goto error; - } - } else { - if (virNetDevBridgeAddPort(brname, *ifname) < 0) - goto error; + if (virNetDevTapAttachBridge(*ifname, brname, macaddr, vmuuid, + virtPortProfile, virtVlan, mtu, actualMTU= ) < 0) { + goto error; } =20 if (virNetDevSetOnline(*ifname, !!(flags & VIR_NETDEV_TAP_CREATE_IFUP)= ) < 0) diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h index 6441df4..6bb3b88 100644 --- a/src/util/virnetdevtap.h +++ b/src/util/virnetdevtap.h @@ -62,6 +62,18 @@ typedef enum { VIR_NETDEV_TAP_CREATE_PERSIST =3D 1 << 3, } virNetDevTapCreateFlags; =20 +int +virNetDevTapAttachBridge(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.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list