From nobody Tue May 14 21:05:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608098540; cv=none; d=zohomail.com; s=zohoarc; b=jxAXL1gt5WgVOywQIu01Y3QgqzG61k9rAmDM50ywJUI6sgbEmgIBuC5gUNTx6XoZ4yEicfX0P86ZZC3nsLG/WEMXygbOu8Ymj3bNxFKpEFlG+llWUGh9/FhBjPBS9YhXrTWvmfM6VRGRIf4o6xVNpZDey+yW4dY7wwRr/fixQdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608098540; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Byh5a9g6XAy5I/7W+0BbL6wmY7fZ8oRKyXljEMf85YI=; b=czpTTZJepk9H9LHOG5vsA4U+iPm5Qp3J/tqT4J0Kk77B4Lk1Al4dcmr6hje95gTg4/mHy4krakqOtWfXL/GWi2UZ3OgH7mvAw0AMkjCyO2ezjw/f0VNVRRhLYFE84DxqOls7KWYckKNID2nfBQeibOdgsGmL/CDtetmpf7umSSg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1608098540673440.36114928576274; Tue, 15 Dec 2020 22:02:20 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-hg-SWT5qMjm4oZD2VGAw2w-1; Wed, 16 Dec 2020 01:02:16 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A0A811005513; Wed, 16 Dec 2020 06:02:10 +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 7EB3F74AC8; Wed, 16 Dec 2020 06:02:10 +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 4A33A4E58E; Wed, 16 Dec 2020 06:02:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BG61pWC018902 for ; Wed, 16 Dec 2020 01:01:51 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4357A11422DE; Wed, 16 Dec 2020 06:01:51 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FB1411422DA for ; Wed, 16 Dec 2020 06:01:48 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C697E858295 for ; Wed, 16 Dec 2020 06:01:48 +0000 (UTC) Received: from m97136.mail.qiye.163.com (m97136.mail.qiye.163.com [220.181.97.136]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-108-uXPmQtmFOB-GG-I9qHkctg-1; Wed, 16 Dec 2020 01:01:43 -0500 Received: from localhost.localdomain (unknown [113.128.197.238]) by smtp2 (Coremail) with SMTP id iOCowACXdvCzotlfMxHeCg--.15612S3; Wed, 16 Dec 2020 14:01:28 +0800 (CST) X-MC-Unique: hg-SWT5qMjm4oZD2VGAw2w-1 X-MC-Unique: uXPmQtmFOB-GG-I9qHkctg-1 From: Shi Lei To: libvir-list@redhat.com Subject: [PATCHv3 1/3] util:netlink: Enable virNetlinkNewLink to support veth Date: Wed, 16 Dec 2020 14:01:04 +0800 Message-Id: <20201216060106.44120-2-shi_lei@massclouds.com> In-Reply-To: <20201216060106.44120-1-shi_lei@massclouds.com> References: <20201216060106.44120-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: iOCowACXdvCzotlfMxHeCg--.15612S3 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjfUptfHDUUUU X-Originating-IP: [113.128.197.238] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiDBj8T1f11yw3cQABs5 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: Shi Lei , laine@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Shi Lei Reviewed-by: Laine Stump --- src/util/virnetlink.c | 14 ++++++++++++++ src/util/virnetlink.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c index fdd3a6a4..8625b896 100644 --- a/src/util/virnetlink.c +++ b/src/util/virnetlink.c @@ -24,6 +24,7 @@ #include =20 #include +#include =20 #include "virnetlink.h" #include "virnetdev.h" @@ -535,6 +536,19 @@ virNetlinkNewLink(const char *ifname, NETLINK_MSG_NEST_END(nl_msg, infodata); } =20 + if (STREQ(type, "veth") && extra_args && extra_args->veth_peer) { + struct nlattr *infoveth =3D NULL; + + NETLINK_MSG_NEST_START(nl_msg, infodata, IFLA_INFO_DATA); + NETLINK_MSG_NEST_START(nl_msg, infoveth, VETH_INFO_PEER); + nlmsg_reserve(nl_msg, sizeof(struct ifinfomsg), 0); + NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, + (strlen(extra_args->veth_peer) + 1), + extra_args->veth_peer); + NETLINK_MSG_NEST_END(nl_msg, infoveth); + NETLINK_MSG_NEST_END(nl_msg, infodata); + } + NETLINK_MSG_NEST_END(nl_msg, linkinfo); =20 if (extra_args) { diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h index 7121eac4..7c4ed202 100644 --- a/src/util/virnetlink.h +++ b/src/util/virnetlink.h @@ -84,6 +84,7 @@ struct _virNetlinkNewLinkData { const int *ifindex; /* The index for the 'link' device */ const virMacAddr *mac; /* The MAC address of the device */ const uint32_t *macvlan_mode; /* The mode of macvlan */ + const char *veth_peer; /* The peer name for veth */ }; =20 int virNetlinkNewLink(const char *ifname, --=20 2.25.1 From nobody Tue May 14 21:05:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608098522; cv=none; d=zohomail.com; s=zohoarc; b=nD9YcMEP4j0sU2ZQsN940D5H8Bq7k00PHQoomoaZjzHjLeeu53W9F8/rmwOub5RI7vPcBELq/t2sLjx+DRMSw85ODNaNZ1ikUtpBspSfeP9Bt0/nY6ADh0i4GTCF2oTU0P4ZWeYKwGMf5Z+b2P3rwqgMYM23RPHrh/VLCYgbUX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608098522; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0MbzVDvOS/9lKEOnnrk5bl+JnV5XzddAY689GzaqKEM=; b=IHY3+PafG+RsTalBkFDPI3OTaCx9uJiza10ZcGNYR+O4xQq3FxlMNkQHOQwKT3S0m5iuWZE5wa3N5kVO9kcrAppqOs7cW5ywxrC9g3jfZG7FUQL0Q27KIBvI17N9sfXDPVOCaNEX2qMw6B7mXUOyMMbzx7LMjGMpi7esM/afuBQ= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1608098521944255.1799764464613; Tue, 15 Dec 2020 22:02:01 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-436-_7_GNE0iMJ-mI7ABoSPo5Q-1; Wed, 16 Dec 2020 01:01:57 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE25B801817; Wed, 16 Dec 2020 06:01:48 +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 96B2D722C1; Wed, 16 Dec 2020 06:01:48 +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 2C54A1809CA0; Wed, 16 Dec 2020 06:01:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BG61fCI018864 for ; Wed, 16 Dec 2020 01:01:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 08DE42026D76; Wed, 16 Dec 2020 06:01:41 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 038042026D49 for ; Wed, 16 Dec 2020 06:01:38 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F380811E76 for ; Wed, 16 Dec 2020 06:01:38 +0000 (UTC) Received: from m97136.mail.qiye.163.com (m97136.mail.qiye.163.com [220.181.97.136]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-591-qWG_TT2nP8ma0tURA16p2g-1; Wed, 16 Dec 2020 01:01:33 -0500 Received: from localhost.localdomain (unknown [113.128.197.238]) by smtp2 (Coremail) with SMTP id iOCowACXdvCzotlfMxHeCg--.15612S4; Wed, 16 Dec 2020 14:01:28 +0800 (CST) X-MC-Unique: _7_GNE0iMJ-mI7ABoSPo5Q-1 X-MC-Unique: qWG_TT2nP8ma0tURA16p2g-1 From: Shi Lei To: libvir-list@redhat.com Subject: [PATCHv3 2/3] util:veth: Create veth device pair by netlink Date: Wed, 16 Dec 2020 14:01:05 +0800 Message-Id: <20201216060106.44120-3-shi_lei@massclouds.com> In-Reply-To: <20201216060106.44120-1-shi_lei@massclouds.com> References: <20201216060106.44120-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: iOCowACXdvCzotlfMxHeCg--.15612S4 X-Coremail-Antispam: 1Uf129KBjvJXoWxur45KF4rKFWkXr13Zw43KFg_yoWrKF4xpw 4fCF9Ykr18trZrAayUZFyrWFn8Ar4ktry5K39rZwnrZ3y5J3y5XryIkFy8W3yxtrWfCr1F gF4avF98uayUGFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JbRqXLUUUUU= X-Originating-IP: [113.128.197.238] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiRRj8T1bdHWxQlwAAsT X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Shi Lei , laine@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When netlink is supported, use netlink to create veth device pair rather than 'ip link' command. Signed-off-by: Shi Lei Reviewed-by: Laine Stump --- src/util/virnetdevveth.c | 126 ++++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 54 deletions(-) diff --git a/src/util/virnetdevveth.c b/src/util/virnetdevveth.c index 194f595a..7133af44 100644 --- a/src/util/virnetdevveth.c +++ b/src/util/virnetdevveth.c @@ -27,21 +27,69 @@ #include "virfile.h" #include "virstring.h" #include "virnetdev.h" +#include "virnetlink.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 VIR_LOG_INIT("util.netdevveth"); =20 =20 +#if defined(WITH_LIBNL) +static int +virNetDevVethCreateInternal(const char *veth1, const char *veth2) +{ + int status; /* Just ignore it */ + virNetlinkNewLinkData data =3D { .veth_peer =3D veth2 }; + + return virNetlinkNewLink(veth1, "veth", &data, &status); +} + +static int +virNetDevVethDeleteInternal(const char *veth) +{ + return virNetlinkDelLink(veth, NULL); +} +#else +static int +virNetDevVethCreateInternal(const char *veth1, const char *veth2) +{ + g_autoptr(virCommand) cmd =3D virCommandNew("ip"); + virCommandAddArgList(cmd, "link", "add", veth1, "type", "veth", + "peer", "name", veth2, NULL); + + return virCommandRun(cmd, NULL); +} + +static int +virNetDevVethDeleteInternal(const char *veth) +{ + int status; + g_autoptr(virCommand) cmd =3D virCommandNewArgList("ip", "link", + "del", veth, NULL); + + if (virCommandRun(cmd, &status) < 0) + return -1; + + if (status !=3D 0) { + if (!virNetDevExists(veth)) { + VIR_DEBUG("Device %s already deleted (by kernel namespace clea= nup)", veth); + return 0; + } + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to delete veth device %s"), veth); + return -1; + } + + return 0; +} +#endif /* WITH_LIBNL */ + /** * virNetDevVethCreate: - * @veth1: pointer to name for parent end of veth pair - * @veth2: pointer to return name for container end of veth pair + * @veth1: pointer to name for one end of veth pair + * @veth2: pointer to name for another end of veth pair * - * Creates a veth device pair using the ip command: - * ip link add veth1 type veth peer name veth2 - * If veth1 points to NULL on entry, it will be a valid interface on - * return. veth2 should point to NULL on entry. + * Creates a veth device pair. * * NOTE: If veth1 and veth2 names are not specified, ip will auto assign * names. There seems to be two problems here - @@ -58,44 +106,31 @@ VIR_LOG_INIT("util.netdevveth"); * * Returns 0 on success or -1 in case of error */ -int virNetDevVethCreate(char** veth1, char** veth2) +int virNetDevVethCreate(char **veth1, char **veth2) { - int status; - g_autofree char *veth1auto =3D NULL; - g_autofree char *veth2auto =3D NULL; - g_autoptr(virCommand) cmd =3D NULL; + const char *orig1 =3D *veth1; + const char *orig2 =3D *veth2; =20 - if (virNetDevGenerateName(&veth1auto, VIR_NET_DEV_GEN_NAME_VNET) < 0) - return -1; + if (virNetDevGenerateName(veth1, VIR_NET_DEV_GEN_NAME_VNET) < 0) + goto cleanup; =20 - if (virNetDevGenerateName(&veth2auto, VIR_NET_DEV_GEN_NAME_VNET) < 0) - return -1; + if (virNetDevGenerateName(veth2, VIR_NET_DEV_GEN_NAME_VNET) < 0) + goto cleanup; =20 - cmd =3D virCommandNew("ip"); - virCommandAddArgList(cmd, "link", "add", - *veth1 ? *veth1 : veth1auto, - "type", "veth", "peer", "name", - *veth2 ? *veth2 : veth2auto, - NULL); + if (virNetDevVethCreateInternal(*veth1, *veth2) < 0) + goto cleanup; =20 - if (virCommandRun(cmd, &status) < 0 || status) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Failed to allocate free veth pair")); - return -1; - } + VIR_DEBUG("Create Host: %s guest: %s", *veth1, *veth2); + return 0; =20 - VIR_DEBUG("create veth host: %s guest: %s: %d", - *veth1 ? *veth1 : veth1auto, - *veth2 ? *veth2 : veth2auto, - status); + cleanup: + if (orig1 =3D=3D NULL) + VIR_FREE(*veth1); =20 - if (veth1auto) - *veth1 =3D g_steal_pointer(&veth1auto); - if (veth2auto) - *veth2 =3D g_steal_pointer(&veth2auto); + if (orig2 =3D=3D NULL) + VIR_FREE(*veth2); =20 - VIR_DEBUG("Create Host: %s guest: %s", *veth1, *veth2); - return 0; + return -1; } =20 /** @@ -111,22 +146,5 @@ int virNetDevVethCreate(char** veth1, char** veth2) */ int virNetDevVethDelete(const char *veth) { - int status; - g_autoptr(virCommand) cmd =3D virCommandNewArgList("ip", "link", - "del", veth, NULL); - - if (virCommandRun(cmd, &status) < 0) - return -1; - - if (status !=3D 0) { - if (!virNetDevExists(veth)) { - VIR_DEBUG("Device %s already deleted (by kernel namespace clea= nup)", veth); - return 0; - } - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to delete veth device %s"), veth); - return -1; - } - - return 0; + return virNetDevVethDeleteInternal(veth); } --=20 2.25.1 From nobody Tue May 14 21:05:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608098519; cv=none; d=zohomail.com; s=zohoarc; b=T+BVM7122fSDXVB9239zY8P8/suV2HVWVAeFGjdMsjO8q/enfXs8vHVQJg1T8YatdyWUXaWkH7zEM9lyU+l0dyLR3LRHheSpX1hkeAdU/UiMRKK5MTJhywenPetQVhCzK40UMfOz3mg5NZh+BTcy4LJ4X2n9NzyR4MHR6yRwVa4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608098519; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wNJYqhNwVaYLSNWbYLDIItNyOURu5w5Vgw7lIVBTMp8=; b=kEAaXPXxx/Ga80ZNIiu+WzK9qHo+ogR+ON9Pq4jAIDMZCGWpnylNMlIhJzR4RYKJetxheJ0HqVk4Riz67dAqCF8mKft7wxr3Edxu8q8HO7jIqlJr8B2S9zCG1bo4sDPnfVj/qSWV9So0VknivEux/dx/w9VEAoXcNkvvjam8fj8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1608098519085639.7231594632807; Tue, 15 Dec 2020 22:01:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-66-ZTxUFeFHP_upb84bm4OJzw-1; Wed, 16 Dec 2020 01:01:54 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 860AD8015DB; Wed, 16 Dec 2020 06:01:49 +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 983F35D9F1; Wed, 16 Dec 2020 06:01:48 +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 2C2F44BB40; Wed, 16 Dec 2020 06:01:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BG61fcR018863 for ; Wed, 16 Dec 2020 01:01:41 -0500 Received: by smtp.corp.redhat.com (Postfix) id 08D972026D5D; Wed, 16 Dec 2020 06:01:41 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 034582026D48 for ; Wed, 16 Dec 2020 06:01:40 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 532F2101A53F for ; Wed, 16 Dec 2020 06:01:40 +0000 (UTC) Received: from m97136.mail.qiye.163.com (m97136.mail.qiye.163.com [220.181.97.136]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-494-8KJhXnorMWKfcWM1VS0yKQ-1; Wed, 16 Dec 2020 01:01:33 -0500 Received: from localhost.localdomain (unknown [113.128.197.238]) by smtp2 (Coremail) with SMTP id iOCowACXdvCzotlfMxHeCg--.15612S5; Wed, 16 Dec 2020 14:01:28 +0800 (CST) X-MC-Unique: ZTxUFeFHP_upb84bm4OJzw-1 X-MC-Unique: 8KJhXnorMWKfcWM1VS0yKQ-1 From: Shi Lei To: libvir-list@redhat.com Subject: [PATCHv3 3/3] lxc: fix a memory leak Date: Wed, 16 Dec 2020 14:01:06 +0800 Message-Id: <20201216060106.44120-4-shi_lei@massclouds.com> In-Reply-To: <20201216060106.44120-1-shi_lei@massclouds.com> References: <20201216060106.44120-1-shi_lei@massclouds.com> MIME-Version: 1.0 X-CM-TRANSID: iOCowACXdvCzotlfMxHeCg--.15612S5 X-Coremail-Antispam: 1Uf129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7v73 VFW2AGmfu7bjvjm3AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjfUpEfODUUUU X-Originating-IP: [113.128.197.238] X-CM-SenderInfo: pvklsz1hl6ztxvvfz0xxgvhudrp/1tbiAwz8T1ilmJnQJQAAs1 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Shi Lei , laine@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In virLXCProcessSetupInterfaceTap, containerVeth needs to be freed on failure. Signed-off-by: Shi Lei Reviewed-by: Laine Stump --- src/lxc/lxc_process.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 85d0287a..0f7c9295 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -303,7 +303,7 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm, const char *brname) { char *parentVeth; - char *containerVeth =3D NULL; + g_autofree char *containerVeth =3D NULL; const virNetDevVPortProfile *vport =3D virDomainNetGetActualVirtPortPr= ofile(net); =20 VIR_DEBUG("calling vethCreate()"); @@ -357,7 +357,7 @@ virLXCProcessSetupInterfaceTap(virDomainDefPtr vm, virDomainConfNWFilterInstantiate(vm->name, vm->uuid, net, false) <= 0) return NULL; =20 - return containerVeth; + return g_steal_pointer(&containerVeth); } =20 =20 --=20 2.25.1