diff options
author | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-05-23 14:39:17 +1000 |
---|---|---|
committer | Samuel Mendoza-Jonas <sam@mendozajonas.com> | 2018-07-10 14:42:56 +1000 |
commit | 735a9ed99a56df4e6bc496bdbe30a5aaa80a9685 (patch) | |
tree | 8732d8c53ba2fa2875f1141e30333cbec40a451c /discover/paths.c | |
parent | d30872fe40c87300e62ef2aea484b9cea618c9de (diff) | |
download | talos-petitboot-735a9ed99a56df4e6bc496bdbe30a5aaa80a9685.tar.gz talos-petitboot-735a9ed99a56df4e6bc496bdbe30a5aaa80a9685.zip |
discover: Determine connectivity with getaddrinfo()
Use getaddrinfo() to determine if a remote URL is reachable instead of
only checking if we have an addresses configured. This avoids, for
example, trying to load an IPv4 URL when only an IPv6 address is
available.
Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/paths.c')
-rw-r--r-- | discover/paths.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/discover/paths.c b/discover/paths.c index c5b5778..dd54ba2 100644 --- a/discover/paths.c +++ b/discover/paths.c @@ -3,11 +3,13 @@ #endif #include <assert.h> +#include <netdb.h> #include <string.h> #include <stdio.h> #include <stdlib.h> -#include <sys/types.h> +#include <sys/socket.h> #include <sys/stat.h> +#include <sys/types.h> #include <talloc/talloc.h> #include <system/system.h> @@ -547,6 +549,7 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url, { struct load_url_result *result; struct load_task *task; + struct addrinfo *res; int flags = 0; if (!url) @@ -579,7 +582,8 @@ struct load_url_result *load_url_async(void *ctx, struct pb_url *url, /* If the url is remote but network is not yet available queue up this * load for later */ - if (!system_info_network_available() && url->scheme != pb_url_file) { + if (url->scheme != pb_url_file && + getaddrinfo(url->host, NULL, NULL, &res) != 0) { pb_log("load task for %s queued pending network\n", url->full); pending_network_jobs_add(task, flags); task->result->status = LOAD_ASYNC; |