Change how DNS resolver handle no default iface
We used to just try any iface we'd been told about as a
fallback, but that will end up mistakenly using a secondary
network's dns when we really don't have a default connection.
It also messed up our detection of whether we were doing the
lookup on the default or not (we'd get back our secondary net
iface as the default, do the compare and think we were on default).
Remove the lies and let dns fail if we don't have an iface for it.
bug:10132565
Conflicts:
libc/netbsd/resolv/res_cache.c
Change-Id: I357a9c34dad83215f44c5e0dd41ce2a7d6fe8f3f
diff --git a/libc/netbsd/resolv/res_cache.c b/libc/netbsd/resolv/res_cache.c
index 8e1bd14..8a6dc83 100644
--- a/libc/netbsd/resolv/res_cache.c
+++ b/libc/netbsd/resolv/res_cache.c
@@ -2531,14 +2531,15 @@
uidiface_info->next = _res_uidiface_list.next;
_res_uidiface_list.next = uidiface_info;
- XLOG("_resolv_set_iface_for_uid_range: [%d,%d], iface %s\n", low, high, ifname);
+ XLOG("_resolv_set_iface_for_uid_range: [%d,%d], iface %s\n", uid_start, uid_end,
+ ifname);
} else {
XLOG("_resolv_set_iface_for_uid_range failing calloc\n");
rv = -1;
errno = EINVAL;
}
} else {
- XLOG("_resolv_set_iface_for_uid_range range [%d,%d] overlaps\n", low, high);
+ XLOG("_resolv_set_iface_for_uid_range range [%d,%d] overlaps\n", uid_start, uid_end);
rv = -1;
errno = EINVAL;
}
@@ -2603,19 +2604,16 @@
char* ifname = _get_default_iface_locked(); // never null, but may be empty
- // if default interface not set. Get first cache with an interface
+ // if default interface not set give up.
if (ifname[0] == '\0') {
- ifname = _find_any_iface_name_locked(); // may be null
+ pthread_mutex_unlock(&_res_cache_list_lock);
+ return 0;
}
- size_t len = 0;
- // if we got the default iface or if (no-default) the find_any call gave an answer
- if (ifname) {
- len = strlen(ifname);
- if (len < buffLen) {
- strncpy(buff, ifname, len);
- buff[len] = '\0';
- }
+ size_t len = strlen(ifname);
+ if (len < buffLen) {
+ strncpy(buff, ifname, len);
+ buff[len] = '\0';
} else {
buff[0] = '\0';
}