From nobody Sun Feb 8 22:22:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1594813746; cv=none; d=zohomail.com; s=zohoarc; b=HdrKj9XaGAsncLJyAW4xD+T940o3YsuBrTy7sW2CJUnRos7trQkk3Vth996MfRMbGBT21EZlp/E7YCEx4MqxcnvHgP0ez92xHroyQ8Jrj3zr+14E5kUQ2c7o7prFZXEdW6rTASz2goGEou9BpTv8UCpkhW8KaFJIOT/H7Nf15Mg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594813746; h=Content-Type:Content-Transfer-Encoding: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=w7eR88FNdsHiDKfJQLsi9qpOpvPDO/b0ZG/t0Cpopxw=; b=VvjH02CK9hRhf0/XzvrxzVvTodPlLU0Rx8OYR4m/orUGqHzDdN53BPWvTY+uca697ETvqmlf61taFVfm7WZ8h643mnrZNnQjqQZzWmq+LpjoPstGHrnf5KxQEQlu5v0ZNTW4wIwW2UJz0ZgE2Kafk1p4a0VCJoYOACxRUYfMbG0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1594813746190798.662611556048; Wed, 15 Jul 2020 04:49:06 -0700 (PDT) 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-16-EdQInl7OPLOlWWL_DpabfQ-1; Wed, 15 Jul 2020 07:49:02 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7367A800597; Wed, 15 Jul 2020 11:48:57 +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 4FF2860C84; Wed, 15 Jul 2020 11:48:57 +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 1E2EF1809561; Wed, 15 Jul 2020 11:48:57 +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 06FBmrZ3023052 for ; Wed, 15 Jul 2020 07:48:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6CD475D9C5; Wed, 15 Jul 2020 11:48:53 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF710757DF for ; Wed, 15 Jul 2020 11:48:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594813745; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=w7eR88FNdsHiDKfJQLsi9qpOpvPDO/b0ZG/t0Cpopxw=; b=WYJ0rtU/YeQzvLOnGBta7zmTZPUu14xHMa4FVrmTHKbP01v4yKy4+08rxpIwKOyjiqh+ZF Ur2/dtaxKvT6tUbLHuKLUtxWw16WxMHc5cwGdvQuPFBpCcOo73H/3VWISJCZyeM0ygm9pC 641NM908DXC+4Sm8pTthDAXTPAoA3MI= X-MC-Unique: EdQInl7OPLOlWWL_DpabfQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] virNetSocketCheckProtocols: Separate out checking family via getaddrinfo() Date: Wed, 15 Jul 2020 13:48:44 +0200 Message-Id: <58cf5bf47817a597bc871a6aca8f7df6614162ad.1594813562.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@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.12 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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The virNetSocketCheckProtocols() function is supposed to tell caller whether IPv4 and/or IPv6 is supported on the system. In the initial round, it uses getifaddrs() to see if an interface has IPv4/IPv6 address assigned and then to double check IPv6 it uses getaddrinfo() to lookup IPv6 loopback address. Separate out this latter code because it is going to be reused. Since the original code lived under an #ifdef and the new function doesn't it is marked as unused - because on some systems it may be so. Signed-off-by: Michal Privoznik --- src/rpc/virnetsocket.c | 63 ++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index d1f4c531aa..b6bc3edc3b 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -141,16 +141,48 @@ static int virNetSocketForkDaemon(const char *binary) } #endif =20 + +static int G_GNUC_UNUSED +virNetSocketCheckProtocolByLookup(const char *address, + int family, + bool *hasFamily) +{ + struct addrinfo hints; + struct addrinfo *ai =3D NULL; + int gaierr; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family =3D family; + hints.ai_flags =3D AI_PASSIVE | AI_ADDRCONFIG; + hints.ai_socktype =3D SOCK_STREAM; + + if ((gaierr =3D getaddrinfo(address, NULL, &hints, &ai)) !=3D 0) { + *hasFamily =3D false; + + if (gaierr =3D=3D EAI_FAMILY || +#ifdef EAI_ADDRFAMILY + gaierr =3D=3D EAI_ADDRFAMILY || +#endif + gaierr =3D=3D EAI_NONAME) { + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Cannot resolve ::1 address: %s"), + gai_strerror(gaierr)); + return -1; + } + } else { + *hasFamily =3D true; + } + + freeaddrinfo(ai); + return 0; +} + int virNetSocketCheckProtocols(bool *hasIPv4, bool *hasIPv6) { #ifdef HAVE_IFADDRS_H struct ifaddrs *ifaddr =3D NULL, *ifa; - struct addrinfo hints; - struct addrinfo *ai =3D NULL; - int gaierr; - - memset(&hints, 0, sizeof(hints)); =20 *hasIPv4 =3D *hasIPv6 =3D false; =20 @@ -172,26 +204,9 @@ int virNetSocketCheckProtocols(bool *hasIPv4, =20 freeifaddrs(ifaddr); =20 - hints.ai_flags =3D AI_PASSIVE | AI_ADDRCONFIG; - hints.ai_family =3D AF_INET6; - hints.ai_socktype =3D SOCK_STREAM; =20 - if ((gaierr =3D getaddrinfo("::1", NULL, &hints, &ai)) !=3D 0) { - if (gaierr =3D=3D EAI_FAMILY || -# ifdef EAI_ADDRFAMILY - gaierr =3D=3D EAI_ADDRFAMILY || -# endif - gaierr =3D=3D EAI_NONAME) { - *hasIPv6 =3D false; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Cannot resolve ::1 address: %s"), - gai_strerror(gaierr)); - return -1; - } - } - - freeaddrinfo(ai); + if (virNetSocketCheckProtocolByLookup("::1", AF_INET6, hasIPv6) < 0) + return -1; =20 VIR_DEBUG("Protocols: v4 %d v6 %d", *hasIPv4, *hasIPv6); =20 --=20 2.26.2