From nobody Tue Dec 16 08:40:59 2025 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 1519396073344675.4013209996036; Fri, 23 Feb 2018 06:27:53 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6ECA612A2; Fri, 23 Feb 2018 14:27:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C4BE5DA2A; Fri, 23 Feb 2018 14:27:51 +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 EA9404A46F; Fri, 23 Feb 2018 14:27:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1NERnH1032714 for ; Fri, 23 Feb 2018 09:27:49 -0500 Received: by smtp.corp.redhat.com (Postfix) id 87D419C049; Fri, 23 Feb 2018 14:27:49 +0000 (UTC) Received: from dnr.brq.redhat.com (unknown [10.43.2.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CF9E9C04C for ; Fri, 23 Feb 2018 14:27:49 +0000 (UTC) From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Date: Fri, 23 Feb 2018 15:27:32 +0100 Message-Id: <6c8836479538f5de15bed1a131fb0a90ebe44df2.1519395939.git.jtomko@redhat.com> In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/16] vboxDumpNetwork: re-introduce this function 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 23 Feb 2018 14:27:52 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Split out per-adapter code from vboxDumpNetworks. Signed-off-by: J=C3=A1n Tomko --- src/vbox/vbox_common.c | 186 +++++++++++++++++++++++++--------------------= ---- 1 file changed, 96 insertions(+), 90 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 03266557a..295f48376 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3695,6 +3695,101 @@ vboxDumpSharedFolders(virDomainDefPtr def, vboxDriv= erPtr data, IMachine *machine } =20 static void +vboxDumpNetwork(virDomainNetDefPtr net, vboxDriverPtr data, INetworkAdapte= r *adapter) +{ + PRUint32 attachmentType =3D NetworkAttachmentType_Null; + PRUint32 adapterType =3D NetworkAdapterType_Null; + PRUnichar *MACAddressUtf16 =3D NULL; + char *MACAddress =3D NULL; + char macaddr[VIR_MAC_STRING_BUFLEN] =3D {0}; + + gVBoxAPI.UINetworkAdapter.GetAttachmentType(adapter, &attachmentType); + if (attachmentType =3D=3D NetworkAttachmentType_NAT) { + + net->type =3D VIR_DOMAIN_NET_TYPE_USER; + + } else if (attachmentType =3D=3D NetworkAttachmentType_Bridged) { + PRUnichar *hostIntUtf16 =3D NULL; + char *hostInt =3D NULL; + + net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + + gVBoxAPI.UINetworkAdapter.GetBridgedInterface(adapter, &hostIntUtf= 16); + + VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt); + ignore_value(VIR_STRDUP(net->data.bridge.brname, hostInt)); + + VBOX_UTF8_FREE(hostInt); + VBOX_UTF16_FREE(hostIntUtf16); + + } else if (attachmentType =3D=3D NetworkAttachmentType_Internal) { + PRUnichar *intNetUtf16 =3D NULL; + char *intNet =3D NULL; + + net->type =3D VIR_DOMAIN_NET_TYPE_INTERNAL; + + gVBoxAPI.UINetworkAdapter.GetInternalNetwork(adapter, &intNetUtf16= ); + + VBOX_UTF16_TO_UTF8(intNetUtf16, &intNet); + ignore_value(VIR_STRDUP(net->data.internal.name, intNet)); + + VBOX_UTF8_FREE(intNet); + VBOX_UTF16_FREE(intNetUtf16); + + } else if (attachmentType =3D=3D NetworkAttachmentType_HostOnly) { + PRUnichar *hostIntUtf16 =3D NULL; + char *hostInt =3D NULL; + + net->type =3D VIR_DOMAIN_NET_TYPE_NETWORK; + + gVBoxAPI.UINetworkAdapter.GetHostOnlyInterface(adapter, &hostIntUt= f16); + + VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt); + ignore_value(VIR_STRDUP(net->data.network.name, hostInt)); + + VBOX_UTF8_FREE(hostInt); + VBOX_UTF16_FREE(hostIntUtf16); + + } else { + /* default to user type i.e. NAT in VirtualBox if this + * dump is ever used to create a machine. + */ + net->type =3D VIR_DOMAIN_NET_TYPE_USER; + } + + gVBoxAPI.UINetworkAdapter.GetAdapterType(adapter, &adapterType); + if (adapterType =3D=3D NetworkAdapterType_Am79C970A) { + ignore_value(VIR_STRDUP(net->model, "Am79C970A")); + } else if (adapterType =3D=3D NetworkAdapterType_Am79C973) { + ignore_value(VIR_STRDUP(net->model, "Am79C973")); + } else if (adapterType =3D=3D NetworkAdapterType_I82540EM) { + ignore_value(VIR_STRDUP(net->model, "82540EM")); + } else if (adapterType =3D=3D NetworkAdapterType_I82545EM) { + ignore_value(VIR_STRDUP(net->model, "82545EM")); + } else if (adapterType =3D=3D NetworkAdapterType_I82543GC) { + ignore_value(VIR_STRDUP(net->model, "82543GC")); + } else if (gVBoxAPI.APIVersion >=3D 3000051 && + adapterType =3D=3D NetworkAdapterType_Virtio) { + /* Only vbox 3.1 and later support NetworkAdapterType_Virto */ + ignore_value(VIR_STRDUP(net->model, "virtio")); + } + + gVBoxAPI.UINetworkAdapter.GetMACAddress(adapter, &MACAddressUtf16); + VBOX_UTF16_TO_UTF8(MACAddressUtf16, &MACAddress); + snprintf(macaddr, VIR_MAC_STRING_BUFLEN, + "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", + MACAddress[0], MACAddress[1], MACAddress[2], MACAddress[3], + MACAddress[4], MACAddress[5], MACAddress[6], MACAddress[7], + MACAddress[8], MACAddress[9], MACAddress[10], MACAddress[11]); + + /* XXX some real error handling here some day ... */ + ignore_value(virMacAddrParse(macaddr, &net->mac)); + + VBOX_UTF16_FREE(MACAddressUtf16); + VBOX_UTF8_FREE(MACAddress); +} + +static void vboxDumpNetworks(virDomainDefPtr def, vboxDriverPtr data, IMachine *machin= e, PRUint32 networkAdapterCount) { PRUint32 netAdpIncCnt =3D 0; @@ -3734,98 +3829,9 @@ vboxDumpNetworks(virDomainDefPtr def, vboxDriverPtr = data, IMachine *machine, PRU =20 gVBoxAPI.UINetworkAdapter.GetEnabled(adapter, &enabled); if (enabled) { - PRUint32 attachmentType =3D NetworkAttachmentType_Null; - PRUint32 adapterType =3D NetworkAdapterType_Null; - PRUnichar *MACAddressUtf16 =3D NULL; - char *MACAddress =3D NULL; - char macaddr[VIR_MAC_STRING_BUFLEN] =3D {0}; - - gVBoxAPI.UINetworkAdapter.GetAttachmentType(adapter, &atta= chmentType); - if (attachmentType =3D=3D NetworkAttachmentType_NAT) { - - net->type =3D VIR_DOMAIN_NET_TYPE_USER; - - } else if (attachmentType =3D=3D NetworkAttachmentType_Bri= dged) { - PRUnichar *hostIntUtf16 =3D NULL; - char *hostInt =3D NULL; - - net->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - - gVBoxAPI.UINetworkAdapter.GetBridgedInterface(adapter,= &hostIntUtf16); - - VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt); - ignore_value(VIR_STRDUP(net->data.bridge.brname, hostI= nt)); - - VBOX_UTF8_FREE(hostInt); - VBOX_UTF16_FREE(hostIntUtf16); - - } else if (attachmentType =3D=3D NetworkAttachmentType_Int= ernal) { - PRUnichar *intNetUtf16 =3D NULL; - char *intNet =3D NULL; - - net->type =3D VIR_DOMAIN_NET_TYPE_INTERNAL; - - gVBoxAPI.UINetworkAdapter.GetInternalNetwork(adapter, = &intNetUtf16); - - VBOX_UTF16_TO_UTF8(intNetUtf16, &intNet); - ignore_value(VIR_STRDUP(net->data.internal.name, intNe= t)); - - VBOX_UTF8_FREE(intNet); - VBOX_UTF16_FREE(intNetUtf16); - - } else if (attachmentType =3D=3D NetworkAttachmentType_Hos= tOnly) { - PRUnichar *hostIntUtf16 =3D NULL; - char *hostInt =3D NULL; - - net->type =3D VIR_DOMAIN_NET_TYPE_NETWORK; - - gVBoxAPI.UINetworkAdapter.GetHostOnlyInterface(adapter= , &hostIntUtf16); - - VBOX_UTF16_TO_UTF8(hostIntUtf16, &hostInt); - ignore_value(VIR_STRDUP(net->data.network.name, hostIn= t)); - - VBOX_UTF8_FREE(hostInt); - VBOX_UTF16_FREE(hostIntUtf16); - - } else { - /* default to user type i.e. NAT in VirtualBox if this - * dump is ever used to create a machine. - */ - net->type =3D VIR_DOMAIN_NET_TYPE_USER; - } - - gVBoxAPI.UINetworkAdapter.GetAdapterType(adapter, &adapter= Type); - if (adapterType =3D=3D NetworkAdapterType_Am79C970A) { - ignore_value(VIR_STRDUP(net->model, "Am79C970A")); - } else if (adapterType =3D=3D NetworkAdapterType_Am79C973)= { - ignore_value(VIR_STRDUP(net->model, "Am79C973")); - } else if (adapterType =3D=3D NetworkAdapterType_I82540EM)= { - ignore_value(VIR_STRDUP(net->model, "82540EM")); - } else if (adapterType =3D=3D NetworkAdapterType_I82545EM)= { - ignore_value(VIR_STRDUP(net->model, "82545EM")); - } else if (adapterType =3D=3D NetworkAdapterType_I82543GC)= { - ignore_value(VIR_STRDUP(net->model, "82543GC")); - } else if (gVBoxAPI.APIVersion >=3D 3000051 && - adapterType =3D=3D NetworkAdapterType_Virtio) { - /* Only vbox 3.1 and later support NetworkAdapterType_= Virto */ - ignore_value(VIR_STRDUP(net->model, "virtio")); - } - - gVBoxAPI.UINetworkAdapter.GetMACAddress(adapter, &MACAddre= ssUtf16); - VBOX_UTF16_TO_UTF8(MACAddressUtf16, &MACAddress); - snprintf(macaddr, VIR_MAC_STRING_BUFLEN, - "%c%c:%c%c:%c%c:%c%c:%c%c:%c%c", - MACAddress[0], MACAddress[1], MACAddress[2], MACA= ddress[3], - MACAddress[4], MACAddress[5], MACAddress[6], MACA= ddress[7], - MACAddress[8], MACAddress[9], MACAddress[10], MAC= Address[11]); - - /* XXX some real error handling here some day ... */ - ignore_value(virMacAddrParse(macaddr, &net->mac)); + vboxDumpNetwork(net, data, adapter); =20 netAdpIncCnt++; - - VBOX_UTF16_FREE(MACAddressUtf16); - VBOX_UTF8_FREE(MACAddress); } =20 VBOX_RELEASE(adapter); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list