]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg: retry name resolution on temporary failure
authorJason A. Donenfeld <Jason@zx2c4.com>
Mon, 24 Apr 2017 01:45:40 +0000 (03:45 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 17 May 2017 16:07:42 +0000 (18:07 +0200)
This should solve many problems at init time.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/config.c

index be15870af3a27b429f4224799e5c5ae85b7c54cf..c00e91cf94ce7760ee5f475f6d8f986baf8fad8a 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <errno.h>
@@ -189,7 +190,15 @@ static inline bool parse_endpoint(struct sockaddr *endpoint, const char *value)
                *end = '\0';
                ++end;
        }
-       ret = getaddrinfo(begin, end, &hints, &resolved);
+
+       for (unsigned int timeout = 1000000; timeout < 90000000; timeout = timeout * 3 / 2) {
+               ret = getaddrinfo(begin, end, &hints, &resolved);
+               if (ret != EAI_AGAIN)
+                       break;
+               fprintf(stderr, "%s: `%s`. Trying again in %.2f seconds...\n", gai_strerror(ret), value, timeout / 1000000.0);
+               usleep(timeout);
+       }
+
        if (ret != 0) {
                free(mutable);
                fprintf(stderr, "%s: `%s`\n", gai_strerror(ret), value);