From: Guus Sliepen Date: Mon, 9 Feb 2015 14:06:12 +0000 (+0100) Subject: Always call res_init() before getaddrinfo(). X-Git-Tag: release-1.0.26~12 X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=commitdiff_plain;h=09d60499af3acef2ba9bd7be15e8d1c44249f8d5 Always call res_init() before getaddrinfo(). Unfortunately, glibc assumes that /etc/resolv.conf is a static file that never changes. Even on servers, /etc/resolv.conf might be a dynamically generated file, and we never know when it changes. So just call res_init() every time, so glibc uses up-to-date nameserver information. --- diff --git a/src/have.h b/src/have.h index bcd4612..e83f98f 100644 --- a/src/have.h +++ b/src/have.h @@ -196,4 +196,15 @@ #include #endif +#ifdef HAVE_ARPA_NAMESER_H +#include +#ifdef STATUS +#undef STATUS +#endif +#endif + +#ifdef HAVE_RESOLV_H +#include +#endif + #endif /* __TINC_SYSTEM_H__ */ diff --git a/src/net.c b/src/net.c index 8d0a0cf..08f0a87 100644 --- a/src/net.c +++ b/src/net.c @@ -41,14 +41,6 @@ #include "subnet.h" #include "xalloc.h" -#ifdef HAVE_ARPA_NAMESER_H -#include -#endif - -#ifdef HAVE_RESOLV_H -#include -#endif - bool do_purge = false; volatile bool running = false; #ifdef HAVE_PSELECT @@ -508,9 +500,6 @@ int main_loop(void) { avl_node_t *node; logger(LOG_INFO, "Flushing event queue"); expire_events(); -#if HAVE_DECL_RES_INIT - res_init(); -#endif for(node = connection_tree->head; node; node = node->next) { connection_t *c = node->data; if(c->status.active) diff --git a/src/net_setup.c b/src/net_setup.c index 765a9eb..121b989 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -813,6 +813,10 @@ static bool setup_myself(void) { hint.ai_protocol = IPPROTO_TCP; hint.ai_flags = AI_PASSIVE; +#ifdef HAVE_DECL_RES_INIT + // ensure glibc reloads /etc/resolv.conf. + res_init(); +#endif err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai); free(address); diff --git a/src/netutl.c b/src/netutl.c index c57b24f..fc3cdc9 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -39,6 +39,10 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock hint.ai_family = addressfamily; hint.ai_socktype = socktype; +#ifdef HAVE_DECL_RES_INIT + // ensure glibc reloads /etc/resolv.conf. + res_init(); +#endif err = getaddrinfo(address, service, &hint, &ai); if(err) {