From patchwork Thu May 24 04:47:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Mendoza-Jonas X-Patchwork-Id: 919571 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rxk72bLDz9s0q for ; Thu, 24 May 2018 14:49:19 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="XowvO20o"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="CDG/chz+"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40rxk70XvszF1Kr for ; Thu, 24 May 2018 14:49:19 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="XowvO20o"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="CDG/chz+"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=mendozajonas.com (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=sam@mendozajonas.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=mendozajonas.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=mendozajonas.com header.i=@mendozajonas.com header.b="XowvO20o"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="CDG/chz+"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40rxhk5d5gzF1Hp for ; Thu, 24 May 2018 14:48:06 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 1270421C6B; Thu, 24 May 2018 00:48:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:48:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= mendozajonas.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=F4NGiRlwGYg4cqywvXqWbA6WpZR6DEZkwFKkmvFbszI=; b=XowvO20o svOucrWJA64ZWnlxrh956qq1/6thrpRPlgVIV+vomzgKzyBkozdO0uWlRCFryeZj h55kb+NlhIH+2d+aNqOeXtSTb26mVwBltO+G+uWzsKbBTCQ8z0vb6qNsjKpxoNVh sS4sEa6NmoHO/g0D3G6F7po/Q4e0VCLcM75AWujeoDALBFGIFCaTwXQ7pQ/rVH94 zefs77/Eg/4ygfjKzm01prQu2UyEe+2Cz+7TvZKD/NAsAu/cowz5M3zCmCJEJ5en HNGHOgm7dwM4EDkDbgGk8FXabnsoXhFeMWnlgKgIXLPGdiHv6KdvpV3MgMZNGyqo 5QOOCwUMFKuQnw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=F4NGiRlwGYg4cqywvXqWbA6WpZR6DEZkwFKkmvFbszI=; b=CDG/chz+ dNxOVeYSBzpoVJiixpwNECKlyG92I5yWxpiRfGzr5zzUCIp/NX3+Ji9CObRXO5iZ HExW3k71GsGPJzHa8kbfRau/IA4DE5mms4o0ZpQvPcnj5EQcFgC7x7y2ozvsjQfg FXi1YA5iNMh1gs2+h3Qw8UDj2FZuWAW4qpxv8fD3Jg1q9aLnas59QhgbCifWPQo1 a2pTkqnEOn1oGa7skZfK6ggDWvnKIZ7rJpRf8JxMXYhiuOmL97TLN3K+bH93WQJS b1W3qhoFXZ3BEfOtjodOhWSnrxmYccGNmXvSOunTUardspN6dsCA3qkm/6nICiWV fTGoHU/qZylP6g== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id C061F10377; Thu, 24 May 2018 00:48:02 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 8/9] discover: Determine connectivity with getaddrinfo() Date: Thu, 24 May 2018 14:47:41 +1000 Message-Id: <20180524044742.25889-9-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524044742.25889-1-sam@mendozajonas.com> References: <20180524044742.25889-1-sam@mendozajonas.com> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Samuel Mendoza-Jonas MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" 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 --- discover/paths.c | 8 ++++++-- discover/sysinfo.c | 10 ---------- discover/sysinfo.h | 1 - 3 files changed, 6 insertions(+), 13 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 +#include #include #include #include -#include +#include #include +#include #include #include @@ -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; diff --git a/discover/sysinfo.c b/discover/sysinfo.c index b7286f1..7037437 100644 --- a/discover/sysinfo.c +++ b/discover/sysinfo.c @@ -18,16 +18,6 @@ const struct system_info *system_info_get(void) return sysinfo; } -bool system_info_network_available(void) -{ - unsigned int i; - - for (i = 0; i < sysinfo->n_interfaces; i++) - if (sysinfo->interfaces[i]->address) - return true; - return false; -} - void system_info_set_interface_address(unsigned int hwaddr_size, uint8_t *hwaddr, const char *address) { diff --git a/discover/sysinfo.h b/discover/sysinfo.h index 835dfbe..c570951 100644 --- a/discover/sysinfo.h +++ b/discover/sysinfo.h @@ -7,7 +7,6 @@ struct discover_server; const struct system_info *system_info_get(void); -bool system_info_network_available(void); void system_info_set_interface_address(unsigned int hwaddr_size, uint8_t *hwaddr, const char *address); void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr,