Skip to content

Commit

Permalink
qemu: fix IPv6 resolution
Browse files Browse the repository at this point in the history
Fixes #2353
  • Loading branch information
osy committed Sep 26, 2021
1 parent 8443531 commit f87c78c
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions patches/qemu-6.1.0-utm.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1490,3 +1490,65 @@ index 0bb210a2c2..a6afc87be8 100644
--
2.28.0

From e89f21e5999cefe031817c1190af2e4565513346 Mon Sep 17 00:00:00 2001
From: osy <50960678+osy@users.noreply.github.com>
Date: Sun, 26 Sep 2021 15:36:00 -0700
Subject: [PATCH] resolv: fix IPv6 resolution on Darwin

res_sockaddr_union() has a field for IPv4 and a field for IPv6. When we
used `&servers[i].sin.sin_addr`, it does not return the right address
for IPv6.
---
src/slirp.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/subprojects/libslirp/src/slirp.c b/subprojects/libslirp/src/slirp.c
index a669b45..5fd1a94 100644
--- a/subprojects/libslirp/src/slirp.c
+++ b/subprojects/libslirp/src/slirp.c
@@ -143,6 +143,10 @@ static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr,
union res_sockaddr_union servers[NI_MAXSERV];
int count;
int found;
+ void *addr;
+
+ // we only support IPv4 and IPv4, we assume it's one or the other
+ assert(af == AF_INET || af == AF_INET6);

if (res_ninit(&state) != 0) {
return -1;
@@ -154,12 +158,17 @@ static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr,
for (int i = 0; i < count; i++) {
if (af == servers[i].sin.sin_family) {
found++;
+ if (af == AF_INET) {
+ addr = &servers[i].sin.sin_addr;
+ } else { // af == AF_INET6
+ addr = &servers[i].sin6.sin6_addr;
+ }
}

// we use the first found entry
if (found == 1) {
- memcpy(pdns_addr, &servers[i].sin.sin_addr, addrlen);
- memcpy(cached_addr, &servers[i].sin.sin_addr, addrlen);
+ memcpy(pdns_addr, addr, addrlen);
+ memcpy(cached_addr, addr, addrlen);
if (scope_id) {
*scope_id = 0;
}
@@ -171,10 +180,7 @@ static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr,
break;
} else if (slirp_debug & DBG_MISC) {
char s[INET6_ADDRSTRLEN];
- const char *res = inet_ntop(servers[i].sin.sin_family,
- &servers[i].sin.sin_addr,
- s,
- sizeof(s));
+ const char *res = inet_ntop(af, addr, s, sizeof(s));
if (!res) {
res = " (string conversion error)";
}
--
2.28.0

0 comments on commit f87c78c

Please sign in to comment.