Always call res_init() before getaddrinfo().
authorGuus Sliepen <guus@tinc-vpn.org>
Mon, 9 Feb 2015 14:06:12 +0000 (15:06 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 9 Feb 2015 14:06:12 +0000 (15:06 +0100)
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.

src/have.h
src/net.c
src/net_setup.c
src/netutl.c

index bcd46127a5c49b00dbfc5ef4601db0fe48d4fc8f..e83f98f48ebe1694e491cdc4e5a50f8f34b3c86b 100644 (file)
 #include <netinet/if_ether.h>
 #endif
 
+#ifdef HAVE_ARPA_NAMESER_H
+#include <arpa/nameser.h>
+#ifdef STATUS
+#undef STATUS
+#endif
+#endif
+
+#ifdef HAVE_RESOLV_H
+#include <resolv.h>
+#endif
+
 #endif /* __TINC_SYSTEM_H__ */
index 8d0a0cf481ce9ca34197526ec68752785e487972..08f0a87484c308412d10b8947c952ef320c8ebe5 100644 (file)
--- a/src/net.c
+++ b/src/net.c
 #include "subnet.h"
 #include "xalloc.h"
 
-#ifdef HAVE_ARPA_NAMESER_H
-#include <arpa/nameser.h>
-#endif
-
-#ifdef HAVE_RESOLV_H
-#include <resolv.h>
-#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)
index 765a9ebf37a1ea0bd11b01c49b84247b6e76d87c..121b989279bff7a810d316cc9737396bb33ff43e 100644 (file)
@@ -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);
 
index c57b24ff1e2dd86a554b24e63187b3885ca0a164..fc3cdc9166cbeedb572b55e3f96907c8d7dd910e 100644 (file)
@@ -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) {