[libvirt] virNetSocketNewListenTCP tries just one address

Olaf Hering olaf at aepfle.de
Wed Apr 11 20:37:08 UTC 2018


On Wed, Mar 28, Olaf Hering wrote:

> > How can libvirt tell whether this is a misconfiguration of DNS or host's
> > interfaces?
> By simply cycling through the 'runp' list to see if any bind() succeeds?

This change fixes /etc/sysconfig/network/ifcfg-br0:BOOTPROTO='dhcp4' for me.
Just keep going in virNetSocketNewListenTCP:

Apr 11 22:18:02 macintyre-old libvirtd[8017]: 2018-04-11 20:18:02.553+0000: 8021: error : virNetSocketNewListenTCP:323 : virNetSocketNewListenTCP: macintyre-old.arch.suse.de 49152 0: Success
Apr 11 22:18:02 macintyre-old libvirtd[8017]: 2018-04-11 20:18:02.555+0000: 8021: error : virNetSocketNewListenTCP:394 : virNetSocketNewListenTCP: bind to '10.161.8.197': Ok: Success
Apr 11 22:18:02 macintyre-old libvirtd[8017]: 2018-04-11 20:18:02.555+0000: 8021: error : virNetSocketNewListenTCP:394 : virNetSocketNewListenTCP: bind to '2620:113:80c0:8000:10:161:8:197': Ok: Cannot assign requested address

You get the idea.

Olaf

---
 src/rpc/virnetsocket.c | 34 ++++++++++++++++++++--------------
 1 file changed, 20 insertions(+), 14 deletions(-)

--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -320,6 +320,7 @@ int virNetSocketNewListenTCP(const char *nodename,
     *retsocks = NULL;
     *nretsocks = 0;
 
+    virReportSystemError(errno, "%s: %s %s %d", __func__, nodename, service, family);
     memset(&hints, 0, sizeof(hints));
     hints.ai_family = family;
     hints.ai_flags = AI_PASSIVE;
@@ -383,12 +384,17 @@ int virNetSocketNewListenTCP(const char *nodename,
             }
         }
 #endif
-
-        if (bind(fd, runp->ai_addr, runp->ai_addrlen) < 0) {
-            if (errno != EADDRINUSE) {
-                virReportSystemError(errno, "%s", _("Unable to bind to port"));
-                goto error;
-            }
+        e = bind(fd, runp->ai_addr, runp->ai_addrlen);
+	{
+        char hostname[123];
+        int r, oe = errno;
+        memset(hostname, 0, sizeof(hostname));
+        r = getnameinfo(runp->ai_addr,runp->ai_addrlen,hostname, sizeof(hostname), NULL, 0, NI_NUMERICHOST);
+        errno = oe;
+        virReportSystemError(errno, "%s: bind to '%s': %s", __func__, hostname, r ? gai_strerror(r) : "Ok");
+	}
+        if (e < 0) {
+            if (errno == EADDRINUSE)
             addrInUse = true;
             VIR_FORCE_CLOSE(fd);
             runp = runp->ai_next;
@@ -412,14 +418,14 @@ int virNetSocketNewListenTCP(const char *nodename,
         fd = -1;
     }
 
-    if (nsocks == 0 && familyNotSupported) {
-        virReportSystemError(EAFNOSUPPORT, "%s", _("Unable to bind to port"));
-        goto error;
-    }
-
-    if (nsocks == 0 &&
-        addrInUse) {
-        virReportSystemError(EADDRINUSE, "%s", _("Unable to bind to port"));
+    if (nsocks == 0) {
+      if (familyNotSupported)
+        errno = EAFNOSUPPORT;
+      else if(addrInUse)
+        errno = EADDRINUSE;
+      else 
+        errno = EDESTADDRREQ;
+        virReportSystemError(errno, "%s", _("Unable to bind to port"));
         goto error;
     }
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180411/5450ea91/attachment-0001.sig>


More information about the libvir-list mailing list