[PATCH] rpc: 'getaddrinfo' function support both IPv4 and IPv6

Ján Tomko jtomko at redhat.com
Mon Mar 2 16:54:42 UTC 2020


The commit summary is too generic.
How about:
rpc: getaddrinfo: also accept IPv4-mapped IPv6 addresses

On a Monday in 2020, Zhimin Feng wrote:
>If only IPv6 is configured and nscd is started, getaddrinfo

Is ncsd required to reproduce this?

Looking at glibc source:
libvirt passes AI_ADDRCONFIG and if getifaddrs returs only one family,
it is placed into req->ai_family and the code below is hit.

>function reture value is -9. So hints.ai_flags should include
>the AI_V4MAPPED flag.
>
>The following is the partial implementation of getaddrinfo(glibc):
>
>    if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
>        at->family = AF_INET;
>    else if (req->ai_family == AF_INET6 && (req->ai_flags & AI_V4MAPPED))
>    {
>        at->addr[3] = at->addr[0];
>	at->addr[2] = htonl (0xffff);
>	at->addr[1] = 0;
>	at->addr[0] = 0;
>	at->family = AF_INET6;
>    }
>    else
>    {
>         result = -EAI_ADDRFAMILY;
>         goto free_and_return;
>    }

However small, I'd rather not include GPL code in our commit messages.
Proposed commit message:

If only IPv6 is configured on the host, getaddrinfo with AI_ADDRCONFIG
in hints would return EAI_ADDRFAMILY for nodenames that resolve to IPv4.

Also pass AI_V4MAPPED to accept IPv4-mapped addresses on IPv6-only
systems.

>
>Signed-off-by: Zhimin Feng <fengzhimin1 at huawei.com>
>---
> src/rpc/virnetsocket.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
>index a217404fa6..c547acefc0 100644
>--- a/src/rpc/virnetsocket.c
>+++ b/src/rpc/virnetsocket.c
>@@ -575,7 +575,7 @@ int virNetSocketNewConnectTCP(const char *nodename,
>
>     memset(&hints, 0, sizeof(hints));
>     hints.ai_family = family;
>-    hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG;
>+    hints.ai_flags = AI_PASSIVE | AI_ADDRCONFIG | AI_V4MAPPED;
>     hints.ai_socktype = SOCK_STREAM;
>
>     int e = getaddrinfo(nodename, service, &hints, &ai);

Reviewed-by: Ján Tomko <jtomko at redhat.com>

Jano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20200302/a8196cfa/attachment-0001.sig>


More information about the libvir-list mailing list