From nobody Thu May 2 02:08:13 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1563015552; cv=none; d=zoho.com; s=zohoarc; b=SHNICTBBIS46bC554gHKnt6khGt9abd5F6Iecxuz01lNNStRPpUYWrkRpXLqXBfW+n8EsLQa1dH4i/5IV/9aDip++06Sy2y872iasW3QBKK3LuYhFY/wqtiHEdW28CMtjKa1IZwnLIQl6sML7I0FHqlGBWjZnfHRJTMjfzYUpXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563015552; 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:ARC-Authentication-Results; bh=XH3lzg5ROjE0b8ZEhabernGmCqZAyQGfAuxiMoUN+kA=; b=ZxicwXjdz7/4kG+9rEBsd0gr7Bpc+FRdmLw0B6+L7DgXSIIqoDfDrzZee9na9GAxDNO3WgZrYLwii9GyBgwhM3LT1qPHFHH+DmqeL7hp3QfVtTg4MNlSRxjtL2n/LjES8T8xnkv12mRrc2MlmSzomh2yDcpF+XXrpRpmiJfO6qw= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563015552819931.8898152275634; Sat, 13 Jul 2019 03:59:12 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 17EE9C04959E; Sat, 13 Jul 2019 10:59:11 +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 E858E60143; Sat, 13 Jul 2019 10:59: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 AC8F418184A4; Sat, 13 Jul 2019 10:59:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6DAwkLQ010207 for ; Sat, 13 Jul 2019 06:58:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC89F196A0; Sat, 13 Jul 2019 10:58:46 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-18.brq.redhat.com [10.40.204.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99D0919699; Sat, 13 Jul 2019 10:58:45 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Sat, 13 Jul 2019 12:58:34 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: abologna@redhat.com Subject: [libvirt] [PATCH 1/5] libvirt_nss: Use VIR_STEAL_PTR() in findLease() 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 13 Jul 2019 10:59:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- tools/nss/libvirt_nss.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index 3ff1bada31..4de960d6f1 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -332,9 +332,8 @@ findLease(const char *name, =20 #endif /* defined(LIBVIRT_NSS_GUEST) */ =20 - *address =3D tmpAddress; + VIR_STEAL_PTR(*address, tmpAddress); *naddress =3D ntmpAddress; - tmpAddress =3D NULL; ntmpAddress =3D 0; =20 ret =3D 0; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 02:08:13 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1563015534; cv=none; d=zoho.com; s=zohoarc; b=LPE431X+hBquV47lVUeTRLbdJ+XnnH6t0iC7GlazWX1e03o+OYPapNWKcQKBiVPYhn0LaphNKFjxsDTJMuRMoDT7I8JJ1ZA4L++iGcEyeYb1VmCj9dcze79tPH1O9lEka6wyoB/XkP98NNXT0OZK4QkYw8VjycBDnGLr8CPHzDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563015534; 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:ARC-Authentication-Results; bh=2ZI9NTgJ8PMEdQeKow8kgTqasol//fde/F7oR7rUNlY=; b=JIkYcWs2fpUqv9NZUc7z4Y40YXaZepJmb1xqa2sE7bQDrXso+GXfetzB+G/22CawL1LxaP8e9C+JCtH1Vj0JD9NZifx7z0o1AARz6gEUn2TjvcOsq2aGS5bIG8mBlShYQW/wlTFCZkQweFh9x3BzdqF9VPA8sAvXB0qBLqXys7Y= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563015534872563.4929579297897; Sat, 13 Jul 2019 03:58:54 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id F3C0281F13; Sat, 13 Jul 2019 10:58:52 +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 B93935C207; Sat, 13 Jul 2019 10:58:52 +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 AF70D41F53; Sat, 13 Jul 2019 10:58:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6DAwmv3010217 for ; Sat, 13 Jul 2019 06:58:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id AEE77196A0; Sat, 13 Jul 2019 10:58:48 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-18.brq.redhat.com [10.40.204.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7645919699; Sat, 13 Jul 2019 10:58:47 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Sat, 13 Jul 2019 12:58:35 +0200 Message-Id: <11f20684a99d7a3bb97c685045638726c32d7f2f.1563015448.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: abologna@redhat.com Subject: [libvirt] [PATCH 2/5] libvirt_nss: Use VIR_AUTOPTR and VIR_AUTOFREE 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-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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 13 Jul 2019 10:58:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- tools/nss/libvirt_nss.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index 4de960d6f1..e55bf144bc 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -244,11 +244,11 @@ findLease(const char *name, int ret =3D -1; const char *leaseDir =3D LEASEDIR; struct dirent *entry; - virJSONValuePtr leases_array =3D NULL; + VIR_AUTOPTR(virJSONValue) leases_array =3D NULL; ssize_t nleases; - leaseAddress *tmpAddress =3D NULL; + VIR_AUTOFREE(leaseAddress *) tmpAddress =3D NULL; size_t ntmpAddress =3D 0; - virMacMapPtr *macmaps =3D NULL; + VIR_AUTOFREE(virMacMapPtr *) macmaps =3D NULL; size_t nMacmaps =3D 0; =20 *address =3D NULL; @@ -340,12 +340,9 @@ findLease(const char *name, =20 cleanup: *errnop =3D errno; - VIR_FREE(tmpAddress); - virJSONValueFree(leases_array); VIR_DIR_CLOSE(dir); while (nMacmaps) virObjectUnref(macmaps[--nMacmaps]); - VIR_FREE(macmaps); return ret; } =20 @@ -389,7 +386,7 @@ NSS_NAME(gethostbyname3)(const char *name, int af, stru= ct hostent *result, { enum nss_status ret =3D NSS_STATUS_UNAVAIL; char *r_name, **r_aliases, *r_addr, *r_addr_next, **r_addr_list; - leaseAddress *addr =3D NULL; + VIR_AUTOFREE(leaseAddress *) addr =3D NULL; size_t naddr, i; bool found =3D false; size_t nameLen, need, idx =3D 0; @@ -495,7 +492,6 @@ NSS_NAME(gethostbyname3)(const char *name, int af, stru= ct hostent *result, =20 ret =3D NSS_STATUS_SUCCESS; cleanup: - VIR_FREE(addr); return ret; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 02:08:13 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1563015557; cv=none; d=zoho.com; s=zohoarc; b=fEeZgFqliqivKMYaXXATSaL8N/pn6OUrtT2CjDD9Zl9b4QUS3jz8QRZ7yE322raW2sTYp30HVNrs8SDjM5Whtlql3G4JvfVBobcaDJcMCJdRWvuqt3h3EbKgLa1fTUQoW9uC/JQbTgvWr+/21ySmwptxkTYvhMe2VW0ERl5VvPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563015557; 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:ARC-Authentication-Results; bh=EN3rCNfzTzepjCEsN8xHhBthm8BKk4y1rfhrbjpzVE0=; b=fqx4urPkocZX+Z6t3/ERRq5SrBK0xTgGzxLyJECzkxKMbvORdbaZRnDpwa9KyaPc88KL4An3V6aIhDySGPurE8ZSyubjWUou6qMx1n0hrOzHQoSHsndOnXEAU1g7jGV9cJcpU0agkG4zUWVU+XiIH21eOMe1BdhzgamuovMey8E= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563015557184906.1403067253087; Sat, 13 Jul 2019 03:59:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 689B32F8BDC; Sat, 13 Jul 2019 10:59:15 +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 4837F1001B13; Sat, 13 Jul 2019 10:59:15 +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 0FEF68E1F; Sat, 13 Jul 2019 10:59:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6DAwonM010229 for ; Sat, 13 Jul 2019 06:58:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E211196E5; Sat, 13 Jul 2019 10:58:50 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-18.brq.redhat.com [10.40.204.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81FB919699; Sat, 13 Jul 2019 10:58:49 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Sat, 13 Jul 2019 12:58:36 +0200 Message-Id: <072d53d3dfe31861ca2533a5abf043686e9c8b59.1563015448.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: abologna@redhat.com Subject: [libvirt] [PATCH 3/5] libvirt_nss: Drop some needless cleanup labels 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-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 13 Jul 2019 10:59:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- tools/nss/libvirt_nss.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index e55bf144bc..3b2583669b 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -85,7 +85,6 @@ appendAddr(leaseAddress **tmpAddress, virJSONValuePtr lease, int af) { - int ret =3D -1; const char *ipAddr; virSocketAddr sa; int family; @@ -93,21 +92,20 @@ appendAddr(leaseAddress **tmpAddress, =20 if (!(ipAddr =3D virJSONValueObjectGetString(lease, "ip-address"))) { ERROR("ip-address field missing for %s", name); - goto cleanup; + return -1; } =20 DEBUG("IP address: %s", ipAddr); =20 if (virSocketAddrParse(&sa, ipAddr, AF_UNSPEC) < 0) { ERROR("Unable to parse %s", ipAddr); - goto cleanup; + return -1; } =20 family =3D VIR_SOCKET_ADDR_FAMILY(&sa); if (af !=3D AF_UNSPEC && af !=3D family) { DEBUG("Skipping address which family is %d, %d requested", family,= af); - ret =3D 0; - goto cleanup; + return 0; } =20 for (i =3D 0; i < *ntmpAddress; i++) { @@ -117,14 +115,13 @@ appendAddr(leaseAddress **tmpAddress, (void *) &sa.data.inet6.sin6_addr.s6_addr), FAMILY_ADDRESS_SIZE(family)) =3D=3D 0) { DEBUG("IP address already in the list"); - ret =3D 0; - goto cleanup; + return 0; } } =20 if (VIR_REALLOC_N_QUIET(*tmpAddress, *ntmpAddress + 1) < 0) { ERROR("Out of memory"); - goto cleanup; + return -1; } =20 (*tmpAddress)[*ntmpAddress].af =3D family; @@ -134,9 +131,7 @@ appendAddr(leaseAddress **tmpAddress, (void *) &sa.data.inet6.sin6_addr.s6_addr), FAMILY_ADDRESS_SIZE(family)); (*ntmpAddress)++; - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 @@ -153,11 +148,10 @@ findLeaseInJSON(leaseAddress **tmpAddress, size_t i; long long expirytime; time_t currtime; - int ret =3D -1; =20 if ((currtime =3D time(NULL)) =3D=3D (time_t) - 1) { ERROR("Failed to get current system time"); - goto cleanup; + return -1; } =20 for (i =3D 0; i < nleases; i++) { @@ -166,7 +160,7 @@ findLeaseInJSON(leaseAddress **tmpAddress, if (!lease) { /* This should never happen (TM) */ ERROR("Unable to get element %zu of %zu", i, nleases); - goto cleanup; + return -1; } =20 if (macs) { @@ -190,7 +184,7 @@ findLeaseInJSON(leaseAddress **tmpAddress, if (virJSONValueObjectGetNumberLong(lease, "expiry-time", &expiryt= ime) < 0) { /* A lease cannot be present without expiry-time */ ERROR("expiry-time field missing for %s", name); - goto cleanup; + return -1; } =20 /* Do not report expired lease */ @@ -203,12 +197,10 @@ findLeaseInJSON(leaseAddress **tmpAddress, *found =3D true; =20 if (appendAddr(tmpAddress, ntmpAddress, lease, af) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 02:08:13 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1563015536; cv=none; d=zoho.com; s=zohoarc; b=jWL7xNyukfJeMCFfhteaRDmbE3NBjOPoWBO0fwRs5Gwp6z9bec+HsdIjEp6baJcCYpMwgr0aRkLoQuIbKhPXHTBRY7jBI8nT+pfnMQykG9OhJv5wzNNiT9Cjlsips93ooK+nSsxQo76uG4z29jwi2MMDqDlGQiHo7ePV52mcqn0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563015536; 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:ARC-Authentication-Results; bh=Xm+u7nkY+GngV7yqxySRpoksPaVHEwS7/dUEniCYn1E=; b=dcWDisPr+uAzz1kAA4sHvMBdlC+XreBCCjlKU+mqpyi8xBNnkUyeFcg8SpPnv7R13QbrLic5HVj7NUWBZFRspmhctsfkgwpUMk8ruCq5ZBq43XKQVJ1g3fQk/kGj6nIEr0ISfUezNDKJEt79P88jMxatUe8X3t1jinm7olvSd1Y= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563015536079632.4412385546415; Sat, 13 Jul 2019 03:58:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46D1DC057F30; Sat, 13 Jul 2019 10:58:54 +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 228B860920; Sat, 13 Jul 2019 10:58:54 +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 DE5F318184AD; Sat, 13 Jul 2019 10:58:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6DAwqDj010236 for ; Sat, 13 Jul 2019 06:58:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9489F19699; Sat, 13 Jul 2019 10:58:52 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-18.brq.redhat.com [10.40.204.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 442BB196E5; Sat, 13 Jul 2019 10:58:50 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Sat, 13 Jul 2019 12:58:37 +0200 Message-Id: <40d0108d7b671c5299cbbf26cb20c42d910c3783.1563015448.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: abologna@redhat.com Subject: [libvirt] [PATCH 4/5] libvirt_nss: Pass @name to appendAddr() 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-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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 13 Jul 2019 10:58:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" In the nss plugin we have ERROR() macro which by default does nothing. However, at compile time it can be made to report errors (this is useful for debugging because by nature of NSS debugging is hard). Anyway, the appendAddr() function uses @name (which contains name the caller wants us to resolve) for error reporting. But the caller findLeaseInJSON() is not passing it. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- tools/nss/libvirt_nss.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index 3b2583669b..b0e118bf37 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -80,7 +80,8 @@ typedef struct { =20 =20 static int -appendAddr(leaseAddress **tmpAddress, +appendAddr(const char *name ATTRIBUTE_UNUSED, + leaseAddress **tmpAddress, size_t *ntmpAddress, virJSONValuePtr lease, int af) @@ -196,7 +197,7 @@ findLeaseInJSON(leaseAddress **tmpAddress, DEBUG("Found record for %s", name); *found =3D true; =20 - if (appendAddr(tmpAddress, ntmpAddress, lease, af) < 0) + if (appendAddr(name, tmpAddress, ntmpAddress, lease, af) < 0) return -1; } =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu May 2 02:08:13 2024 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 ARC-Seal: i=1; a=rsa-sha256; t=1563015553; cv=none; d=zoho.com; s=zohoarc; b=ImNrw7hKxKgsZZiNYUa4/WldMigzNVl5nprgdvQf12cvzLj5aL/CGW6WU7BvZg9WUWsVmWuSjofhvK2M12gMNysgAd1nCiddnmT3InmODAD5YTVydb+dGw25oheuCWUNkxgpErQTDAmcP9aeKi4OwM2rdHTVNDIyT/XS93hbSlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563015553; 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:ARC-Authentication-Results; bh=PQXXiRNEHhQGiLxKU5JgyT31YVlArP3e0VT53M/GUqw=; b=dvPMBkS3+fQremxJ7/3h4gmNnnjFUqb3fxuhkm1pEfjKcopjqwMzNGZ5q/J4G9g7cvHAF1pBWGnvpTsgGN3siMzHrSKQM49TBEDQKY7bmLV6p5KNcV6IRpwddzhwLC2tFW5951cdpfPN5+b4aEQbj030gNf4WcU+MX/+W2rkoxQ= ARC-Authentication-Results: i=1; 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; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563015553466533.2960870375634; Sat, 13 Jul 2019 03:59:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E113530BC595; Sat, 13 Jul 2019 10:59:11 +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 BC88E196A0; Sat, 13 Jul 2019 10:59:11 +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 7F2BA18184A4; Sat, 13 Jul 2019 10:59:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x6DAwsTl010248 for ; Sat, 13 Jul 2019 06:58:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 55CB7196A0; Sat, 13 Jul 2019 10:58:54 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-18.brq.redhat.com [10.40.204.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 281CE19699; Sat, 13 Jul 2019 10:58:52 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Sat, 13 Jul 2019 12:58:38 +0200 Message-Id: <34130559f6c7ff29bb0a57f53f76372559cfcb8c.1563015448.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: abologna@redhat.com Subject: [libvirt] [PATCH 5/5] libvirt_nss: Report newer addresses first 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-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 13 Jul 2019 10:59:12 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Ideally, a software that's translating domain names would iterate over all addresses the NSS returned, but some software does not bother (e.g. ping). What happens is that for instance when installing a guest, it's assigned one IP address but once it's installed and rebooted it gets a different IP address (because client ID used for the first DHCP traffic when installing the guest was generated dynamically and never saved so after reboot the guest generated new ID which resulted in different IP address to be assigned). This results in 'ping $domain' not working properly as it still pings the old IP address. Well, it might - NSS plugin does not guarantee any order of addresses. To resolve this problem, we can sort the array just before returning it to the caller (ping) so that the newer IP addresses come before older ones. Reported-by: Andrea Bolognani Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- tests/nssdata/virbr0.status | 6 +++--- tests/nsstest.c | 21 ++++++++------------- tools/nss/libvirt_nss.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/tests/nssdata/virbr0.status b/tests/nssdata/virbr0.status index d040774269..783efb1dfb 100644 --- a/tests/nssdata/virbr0.status +++ b/tests/nssdata/virbr0.status @@ -3,19 +3,19 @@ "ip-address": "192.168.122.197", "mac-address": "52:54:00:a4:6f:91", "hostname": "fedora", - "expiry-time": 1900000000 + "expiry-time": 1900000003 }, { "ip-address": "192.168.122.198", "mac-address": "52:54:00:a4:6f:92", "hostname": "fedora", - "expiry-time": 1900000000 + "expiry-time": 1900000002 }, { "ip-address": "192.168.122.254", "mac-address": "52:54:00:3a:b5:0c", "hostname": "gentoo", - "expiry-time": 2000000000 + "expiry-time": 2000000001 }, { "ip-address": "192.168.122.2", diff --git a/tests/nsstest.c b/tests/nsstest.c index d43c59c4a2..4118c31cef 100644 --- a/tests/nsstest.c +++ b/tests/nsstest.c @@ -46,7 +46,7 @@ testGetHostByName(const void *opaque) char buf[BUF_SIZE] =3D { 0 }; char **addrList; int rv, tmp_errno =3D 0, tmp_herrno =3D 0; - size_t i =3D 0, j =3D 0; + size_t i =3D 0; =20 memset(&resolved, 0, sizeof(resolved)); =20 @@ -117,6 +117,7 @@ testGetHostByName(const void *opaque) } =20 addrList =3D resolved.h_addr_list; + i =3D 0; while (*addrList) { virSocketAddr sa; char *ipAddr; @@ -135,14 +136,10 @@ testGetHostByName(const void *opaque) goto cleanup; } =20 - for (j =3D 0; data->ipAddr[j]; j++) { - if (STREQ(data->ipAddr[j], ipAddr)) - break; - } - - if (!data->ipAddr[j]) { + if (STRNEQ_NULLABLE(data->ipAddr[i], ipAddr)) { virReportError(VIR_ERR_INTERNAL_ERROR, - "Unexpected address %s", ipAddr); + "Unexpected address %s, expecting %s", + ipAddr, NULLSTR(data->ipAddr[i])); VIR_FREE(ipAddr); goto cleanup; } @@ -152,12 +149,10 @@ testGetHostByName(const void *opaque) i++; } =20 - for (j =3D 0; data->ipAddr[j]; j++) - ; - - if (i !=3D j) { + if (data->ipAddr[i]) { virReportError(VIR_ERR_INTERNAL_ERROR, - "Expected %zu addresses, got %zu", j, i); + "Expected %s address, got NULL", + data->ipAddr[i]); goto cleanup; } =20 diff --git a/tools/nss/libvirt_nss.c b/tools/nss/libvirt_nss.c index b0e118bf37..519046a4e0 100644 --- a/tools/nss/libvirt_nss.c +++ b/tools/nss/libvirt_nss.c @@ -76,9 +76,29 @@ do { \ typedef struct { unsigned char addr[16]; int af; + long long expirytime; } leaseAddress; =20 =20 +static int +leaseAddressSorter(const void *a, + const void *b) +{ + const leaseAddress *la =3D a; + const leaseAddress *lb =3D b; + + return lb->expirytime - la->expirytime; +} + + +static void +sortAddr(leaseAddress *tmpAddress, + size_t ntmpAddress) +{ + qsort(tmpAddress, ntmpAddress, sizeof(*tmpAddress), leaseAddressSorter= ); +} + + static int appendAddr(const char *name ATTRIBUTE_UNUSED, leaseAddress **tmpAddress, @@ -89,6 +109,7 @@ appendAddr(const char *name ATTRIBUTE_UNUSED, const char *ipAddr; virSocketAddr sa; int family; + long long expirytime; size_t i; =20 if (!(ipAddr =3D virJSONValueObjectGetString(lease, "ip-address"))) { @@ -109,6 +130,12 @@ appendAddr(const char *name ATTRIBUTE_UNUSED, return 0; } =20 + if (virJSONValueObjectGetNumberLong(lease, "expiry-time", &expirytime)= < 0) { + /* A lease cannot be present without expiry-time */ + ERROR("expiry-time field missing for %s", name); + return -1; + } + for (i =3D 0; i < *ntmpAddress; i++) { if (memcmp((*tmpAddress)[i].addr, (family =3D=3D AF_INET ? @@ -125,6 +152,7 @@ appendAddr(const char *name ATTRIBUTE_UNUSED, return -1; } =20 + (*tmpAddress)[*ntmpAddress].expirytime =3D expirytime; (*tmpAddress)[*ntmpAddress].af =3D family; memcpy((*tmpAddress)[*ntmpAddress].addr, (family =3D=3D AF_INET ? @@ -325,6 +353,8 @@ findLease(const char *name, =20 #endif /* defined(LIBVIRT_NSS_GUEST) */ =20 + sortAddr(tmpAddress, ntmpAddress); + VIR_STEAL_PTR(*address, tmpAddress); *naddress =3D ntmpAddress; ntmpAddress =3D 0; --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list