From patchwork Thu May 24 04:47:34 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: 919563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rxhl5Crhz9s0q for ; Thu, 24 May 2018 14:48:07 +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="D3qZRHhn"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="AMX2bTP8"; 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 40rxhl334JzF1Hf for ; Thu, 24 May 2018 14:48:07 +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="D3qZRHhn"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="AMX2bTP8"; 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="D3qZRHhn"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="AMX2bTP8"; 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 40rxhW41qDzF1H5 for ; Thu, 24 May 2018 14:47:55 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 074AA21C3F; Thu, 24 May 2018 00:47:53 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:47:53 -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=jOQxPzPskikzo5Idpx1bktjEnh13T5j8/arO4EYmcng=; b=D3qZRHhn B0+7P6C0WYZ5iD1HqrLOkufZ4V2wlTdhxYzc1v/IwQZJEb1QbAmTXxYxakYIp3e8 okbR2EWnPc5vEjAYK9nPub8SkHgUybQ6Bqh+W+uApGkQnaTtDZobQVyj8W2x+rJt xZ0CEEDtth/BeifNVNF5Du0hfKxPNw4Y+9/117skogpbMbnqHSM2zoJL9FK/+t9t nNC8kD2exWdO1TFvv/S2SmDvql8Svcaxxxcmoh6xWhr3UNEp8lEZgqm7E30bKKTs 4WyytpjjU8EYZ7e4MmZWITaNsGonTqbtuLk1T+Oa6VBIxBZYJMOFITuOox7UgTDT nEo6VIBXEGWr9A== 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=jOQxPzPskikzo5Idpx1bktjEnh13T5j8/arO4EYmcng=; b=AMX2bTP8 RH/qcow2cp85UYY63UtM6U1tu4Jfx3keov3xYNYyedpPTFD0me0MmqunGbE8WRC7 aKvbR5pfb7iM1p+GOXprOVe3v+repnM1B+CtwLHIQvNI+8meayvTahuJdTi1jkLc HZ7OvmrKDoH2+cxDYaqa9KIvlIRNf/B73i7CpqDK8JeomomD7NZLbbcX0qNxs0KS 5DfdJu7qMzQDpE027oyum7iCD8LXCrNn3QMqL1x7rzyNIJtFnxsmQV6IZ7b50bNW TtEgC2mF0bTGS4VznezIqYRP5ZSY0e/6rB1rR+S8sTSCv+1FbDUlI8xfUgDg2Jvg AAWrUWr0YQVBdQ== 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 A9913102BA; Thu, 24 May 2018 00:47:51 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 1/9] lib: Add support and helpers for IPv6 host addresses Date: Thu, 24 May 2018 14:47:34 +1000 Message-Id: <20180524044742.25889-2-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" Recognise IPv6 addresses and URLs, and allow an interface_info struct to have both an IPv4 and IPv6 address. The addr_scheme() helper returns the address family of a given address. Signed-off-by: Samuel Mendoza-Jonas --- lib/pb-protocol/pb-protocol.c | 6 +++- lib/types/types.h | 1 + lib/url/url.c | 45 ++++++++++++++++++++++++++---- lib/url/url.h | 2 ++ test/urls/Makefile.am | 3 ++ test/urls/data/ipv6-full.test | 7 +++++ test/urls/data/ipv6-multidirs.test | 7 +++++ test/urls/data/ipv6-noport.test | 7 +++++ 8 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 test/urls/data/ipv6-full.test create mode 100644 test/urls/data/ipv6-multidirs.test create mode 100644 test/urls/data/ipv6-noport.test diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index dbbda40..87505fc 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -253,7 +253,8 @@ int pb_protocol_system_info_len(const struct system_info *sysinfo) len += 4 + if_info->hwaddr_size + 4 + optional_strlen(if_info->name) + sizeof(if_info->link) + - 4 + optional_strlen(if_info->address); + 4 + optional_strlen(if_info->address) + + 4 + optional_strlen(if_info->address_v6); } for (i = 0; i < sysinfo->n_blockdevs; i++) { @@ -494,6 +495,7 @@ int pb_protocol_serialise_system_info(const struct system_info *sysinfo, pos += sizeof(bool); pos += pb_protocol_serialise_string(pos, if_info->address); + pos += pb_protocol_serialise_string(pos, if_info->address_v6); } *(uint32_t *)pos = __cpu_to_be32(sysinfo->n_blockdevs); @@ -1011,6 +1013,8 @@ int pb_protocol_deserialise_system_info(struct system_info *sysinfo, if (read_string(if_info, &pos, &len, &if_info->address)) goto out; + if (read_string(if_info, &pos, &len, &if_info->address_v6)) + goto out; sysinfo->interfaces[i] = if_info; } diff --git a/lib/types/types.h b/lib/types/types.h index 9ab2a43..5f99b58 100644 --- a/lib/types/types.h +++ b/lib/types/types.h @@ -110,6 +110,7 @@ struct interface_info { char *name; bool link; char *address; + char *address_v6; }; struct blockdev_info { diff --git a/lib/url/url.c b/lib/url/url.c index 6eeced3..f0e8b0e 100644 --- a/lib/url/url.c +++ b/lib/url/url.c @@ -197,19 +197,35 @@ struct pb_url *pb_url_parse(void *ctx, const char *url_str) goto fail; } - col = strchr(p, ':'); + col = strrchr(p, ':'); + if (col <= p) + col = NULL; + if (col && strchr(col , ']')) { + /* + * This is likely an IPv6 address with no port. + * See https://www.ietf.org/rfc/rfc2732.txt + */ + col = NULL; + } if (col) { len = path - col - 1; url->port = len ? talloc_strndup(url, col + 1, len) : NULL; len = col - p; - url->host = len ? talloc_strndup(url, p, len) : NULL; } else { url->port = NULL; - url->host = talloc_strndup(url, p, path - p); + len = path - p; } + if (p[0] == '[' && p[len - 1] == ']') + /* IPv6 */ + url->host = talloc_strndup(url, p + 1, len - 2); + else + /* IPv4 */ + url->host = talloc_strndup(url, p, len); + + /* remove multiple leading slashes */ for (; *path && *(path+1) == '/'; path++) ; @@ -231,13 +247,32 @@ bool is_url(const char *str) return strstr(str, "://") != NULL; } +int addr_scheme(const char *address) +{ + uint8_t buf[sizeof(struct in6_addr)]; + int rc; + + rc = inet_pton(AF_INET, address , buf); + if (rc == 1) + return AF_INET; + rc = inet_pton(AF_INET6, address , buf); + if (rc == 1) + return AF_INET6; + + return 0; +} + char *pb_url_to_string(struct pb_url *url) { const struct pb_scheme_info *scheme = pb_url_scheme_info(url->scheme); assert(scheme); - return talloc_asprintf(url, "%s://%s%s", scheme->str, - scheme->has_host ? url->host : "", url->path); + if (scheme->has_host && addr_scheme(url->host) == AF_INET6) + return talloc_asprintf(url, "%s://[%s]%s", scheme->str, + url->host, url->path); + else + return talloc_asprintf(url, "%s://%s%s", scheme->str, + scheme->has_host ? url->host : "", url->path); } static void pb_url_update_full(struct pb_url *url) diff --git a/lib/url/url.h b/lib/url/url.h index 9043615..49dff4a 100644 --- a/lib/url/url.h +++ b/lib/url/url.h @@ -19,6 +19,7 @@ #if !defined(_PB_URL_PARSER_H) #define _PB_URL_PARSER_H +#include #include /** @@ -61,6 +62,7 @@ struct pb_url { }; bool is_url(const char *str); +int addr_scheme(const char *address); struct pb_url *pb_url_parse(void *ctx, const char *url_str); struct pb_url *pb_url_copy(void *ctx, const struct pb_url *url); struct pb_url *pb_url_join(void *ctx, const struct pb_url *url, const char *s); diff --git a/test/urls/Makefile.am b/test/urls/Makefile.am index ad670b8..aab0f2b 100644 --- a/test/urls/Makefile.am +++ b/test/urls/Makefile.am @@ -20,6 +20,9 @@ test_urls_parse_url_LDADD = $(core_lib) url_TESTS = \ test/urls/data/double-slash.test \ test/urls/data/http-simple.test \ + test/urls/data/ipv6-full.test \ + test/urls/data/ipv6-multidirs.test \ + test/urls/data/ipv6-noport.test \ test/urls/data/join-full.test \ test/urls/data/join-absolute.test \ test/urls/data/join-relative.test \ diff --git a/test/urls/data/ipv6-full.test b/test/urls/data/ipv6-full.test new file mode 100644 index 0000000..b4943eb --- /dev/null +++ b/test/urls/data/ipv6-full.test @@ -0,0 +1,7 @@ +http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html +scheme http +host FEDC:BA98:7654:3210:FEDC:BA98:7654:3210 +port 80 +path /index.html +dir / +file index.html diff --git a/test/urls/data/ipv6-multidirs.test b/test/urls/data/ipv6-multidirs.test new file mode 100644 index 0000000..68b852a --- /dev/null +++ b/test/urls/data/ipv6-multidirs.test @@ -0,0 +1,7 @@ +tftp://[fd69:d65f:b8b5:61::1]/installers/ubuntu-18.04/vmlinux +scheme tftp +host fd69:d65f:b8b5:61::1 +port (null) +path /installers/ubuntu-18.04/vmlinux +dir /installers/ubuntu-18.04/ +file vmlinux diff --git a/test/urls/data/ipv6-noport.test b/test/urls/data/ipv6-noport.test new file mode 100644 index 0000000..bd3b008 --- /dev/null +++ b/test/urls/data/ipv6-noport.test @@ -0,0 +1,7 @@ +http://[1080:0:0:0:8:800:200C:417A]/index.html +scheme http +host 1080:0:0:0:8:800:200C:417A +port (null) +path /index.html +dir / +file index.html From patchwork Thu May 24 04:47:35 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: 919565 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 40rxj75n0qz9s0q for ; Thu, 24 May 2018 14:48:27 +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="MxJojqCV"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="UsKJCHnO"; 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 40rxj742M4zF1Hg for ; Thu, 24 May 2018 14:48:27 +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="MxJojqCV"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="UsKJCHnO"; 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="MxJojqCV"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="UsKJCHnO"; 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 40rxhY0kzqzF1H5 for ; Thu, 24 May 2018 14:47:56 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 854F221C2C; Thu, 24 May 2018 00:47:54 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:47:54 -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=+nXOscsw+1sVHOJi2OoSwVZ4T1AEGdtdkig96VqsDq8=; b=MxJojqCV T8wi2FHucUZad4ZvqAVunAs+5hWwn8MWV2mZeHTNMm7572PhtnS/hsY3qG5PVQoA b9dscFp0uuuwROUM3j7x7bYwVa6S5QDrtXQtscYrpBbjwAYnXPR4YQZcBu+sqGw7 JZLkArZVRMuHo13TlOaHzpnBQkFcKaulvu0h+ldaZV+qnhE4aztiv8ADMhEjmY2e oKOOcn11iSikHtOpHSjLYd0NYVB0DzSA+pZdtq7xBcGgPr98npSjwG2nroC3ypaN ZRqKjcXw52HeJIRB214090oyaq4elm/G/uwdB1M8BHGP4nQT5G50Zoa6Pih18jCM eAJo0NvxF+q1Sg== 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=+nXOscsw+1sVHOJi2OoSwVZ4T1AEGdtdkig96VqsDq8=; b=UsKJCHnO erxFfQOa2NDHxrPJC+O4lfd98DNjWc4b2achVK9FKU/dKWUXIy63zetMT/0oymAK TzzNcn/0dFYWqhg47bcB9wneG+JQlF11hd2poVtNlqmKXw97oD+5Nc96ZJZb4Clf HXa/7JNL55aSbhYH6NMg8DLBSaw1vSxpmx+abTGm8gfFapRgrR27O4IknorWdZo5 YfdxrUiuYnkwqHyUuSv1oPn3okj80mPvkc+U7V3jKSoYW6DPOjC7R2T2kJU88B1x mkSgS01w2ulN5SG1kOyqYuRC4j9SeguqGAwiWP/U5ghgpzBr/ZGkBCs88eNJVb2g t9HTkK8LBJIfAQ== 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 414B91025E; Thu, 24 May 2018 00:47:53 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 2/9] discover/sysinfo: Set IPv6 addresses Date: Thu, 24 May 2018 14:47:35 +1000 Message-Id: <20180524044742.25889-3-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" Signed-off-by: Samuel Mendoza-Jonas --- discover/sysinfo.c | 23 +++++++++++++++++++---- ui/ncurses/nc-sysinfo.c | 3 +++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/discover/sysinfo.c b/discover/sysinfo.c index 74d1eae..b7286f1 100644 --- a/discover/sysinfo.c +++ b/discover/sysinfo.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "discover-server.h" #include "platform.h" @@ -32,7 +33,7 @@ void system_info_set_interface_address(unsigned int hwaddr_size, { struct interface_info *if_info; unsigned int i; - char mac[20]; + char mac[20], **if_addr, *new_addr, *subnet; for (i = 0; i < sysinfo->n_interfaces; i++) { if_info = sysinfo->interfaces[i]; @@ -43,12 +44,26 @@ void system_info_set_interface_address(unsigned int hwaddr_size, if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size)) continue; + /* + * Don't include the subnet from a static config, and check if + * we're updating the IPv4 or IPv6 address. + * */ + if ((subnet = strchr(address, '/'))) + new_addr = talloc_strndup(if_info, address, subnet - address); + else + new_addr = talloc_strdup(if_info, address); + if (addr_scheme(new_addr) == AF_INET) + if_addr = &if_info->address; + else + if_addr = &if_info->address_v6; + /* Found an existing interface. Notify clients if a new address * is set */ - if (!if_info->address || strcmp(if_info->address, address)) { - talloc_free(if_info->address); - if_info->address = talloc_strdup(if_info, address); + if (!*if_addr || strcmp(*if_addr, address)) { + talloc_free(*if_addr); + *if_addr = new_addr; discover_server_notify_system_info(server, sysinfo); + pb_log("ADDR: %s on %s\n", *if_addr, if_info->name); return; } } diff --git a/ui/ncurses/nc-sysinfo.c b/ui/ncurses/nc-sysinfo.c index 8252b45..756f15d 100644 --- a/ui/ncurses/nc-sysinfo.c +++ b/ui/ncurses/nc-sysinfo.c @@ -131,6 +131,9 @@ static void sysinfo_screen_populate(struct sysinfo_screen *screen, line("%s:", info->name); line(_(" MAC: %s"), macbuf); line(_(" IP Address: %s"), info->address ?: _("none")); + if (info->address_v6) + line(_(" IPv6 Address: %s"), + info->address_v6 ?: _("none")); /* TRANSLATORS: these "up" / "down" strings refer to the * link status for a network connection. */ line(_(" link: %s"), info->link ? _("up") : _("down")); From patchwork Thu May 24 04:47:36 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: 919566 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rxjK1xHTz9s0q for ; Thu, 24 May 2018 14:48:37 +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="Ts8Dk3Ah"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="iwDf39RX"; 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 40rxjJ6XZnzF1H5 for ; Thu, 24 May 2018 14:48:36 +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="Ts8Dk3Ah"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="iwDf39RX"; 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="Ts8Dk3Ah"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="iwDf39RX"; 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 40rxhZ4NtDzF15L for ; Thu, 24 May 2018 14:47:58 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 16D0021CDA; Thu, 24 May 2018 00:47:56 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:47:56 -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=3plZI5gB2GoXSlpu81S75iozG23cLqJK4QY8JmprZd0=; b=Ts8Dk3Ah XNM/KGUV6iZZHl101sr7F3TIGaOWXIo37E1aBIAqXH9czNlzaEY6ZxlmMRyCKlz6 8d3j1PFxRIMCbr8F0zkrmIUQ//JreBS7PDuaDt3z2cdN8rjqE1dMt0RoGrBFAiiB X+sPL5fW668aoSvbRxS6YNzU+Saisc7xmbx1lkGQAt8R5+rvXjS2uKVWGcG8GIDP tt9OezlSSsI2mUecost4cWvHPbR33yOkPDBMy9FBHsM8vwAs23ofhR91PAlB6knR HYHyTIRGsq+eX6QszIWQrU3k7hwDnUlSv8ZVj1lKvEkUuiYHoY1O577Jwq6igEnd 5Mpu91sFefDapQ== 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=3plZI5gB2GoXSlpu81S75iozG23cLqJK4QY8JmprZd0=; b=iwDf39RX IXYBoCe4eI0vjCU/qpJK20536jn93wo1bspKGRZRV6zz1dLN8wG3kKENkr0sFntZ 80DXQQ7WFebutH2onaaQUYg0GF/FwzLHR7patmbs/lAgepDDDJYpHKP6zlnMnK37 VVpYKlMSjUt+mLh6vWvy973YXg6KdwDGsSoF51Cw5PdZTUfiDGWSsBzTeIX7dXcv 5xzTonOo3HMnYI11m/JW5S1we8MKGXLWG36kkssg93VT++ebKUG4WNGOEc4aWW1/ KzfiFpVQGWXxDQNH9kV3tGbEj9501CaTpVbuHz7ynb2R4TB/C6nKPcyyufYdpS8Y jwLv+1Keo53l7A== 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 CB6511025E; Thu, 24 May 2018 00:47:54 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 3/9] lib/system: Add udhcpc6 Date: Thu, 24 May 2018 14:47:36 +1000 Message-Id: <20180524044742.25889-4-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" Signed-off-by: Samuel Mendoza-Jonas --- configure.ac | 1 + lib/system/system.c | 1 + lib/system/system.h | 1 + 3 files changed, 3 insertions(+) diff --git a/configure.ac b/configure.ac index 564cb5d..a44fd6f 100644 --- a/configure.ac +++ b/configure.ac @@ -341,6 +341,7 @@ DEFINE_HOST_PROG(UMOUNT, umount, [/bin/umount]) DEFINE_HOST_PROG(WGET, wget, [/usr/bin/wget]) DEFINE_HOST_PROG(IP, ip, [/sbin/ip]) DEFINE_HOST_PROG(UDHCPC, udhcpc, [/sbin/udhcpc]) +DEFINE_HOST_PROG(UDHCPC6, udhcpc6, [/usr/bin/udhcpc6]) DEFINE_HOST_PROG(VGSCAN, vgscan, [/usr/sbin/vgscan]) DEFINE_HOST_PROG(VGCHANGE, vgchange, [/usr/sbin/vgchange]) DEFINE_HOST_PROG(PB_PLUGIN, pb-plugin, [/usr/sbin/pb-plugin]) diff --git a/lib/system/system.c b/lib/system/system.c index b1121a1..d0884a3 100644 --- a/lib/system/system.c +++ b/lib/system/system.c @@ -28,6 +28,7 @@ const struct pb_system_apps pb_system_apps = { .wget = HOST_PROG_WGET, .ip = HOST_PROG_IP, .udhcpc = HOST_PROG_UDHCPC, + .udhcpc6 = HOST_PROG_UDHCPC6, .vgscan = HOST_PROG_VGSCAN, .vgchange = HOST_PROG_VGCHANGE, .pb_plugin = HOST_PROG_PB_PLUGIN, diff --git a/lib/system/system.h b/lib/system/system.h index d27c2cd..7219209 100644 --- a/lib/system/system.h +++ b/lib/system/system.h @@ -13,6 +13,7 @@ struct pb_system_apps { const char *wget; const char *ip; const char *udhcpc; + const char *udhcpc6; const char *vgscan; const char *vgchange; const char *pb_plugin; From patchwork Thu May 24 04:47:37 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: 919567 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 40rxjT5Hz3z9s0x for ; Thu, 24 May 2018 14:48:45 +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="lnUyQtUO"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TmQSm3qQ"; 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 40rxjT3cx3zF1H5 for ; Thu, 24 May 2018 14:48:45 +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="lnUyQtUO"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TmQSm3qQ"; 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="lnUyQtUO"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TmQSm3qQ"; 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 40rxhb74PBzF15L for ; Thu, 24 May 2018 14:47:59 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id A3A0621C56; Thu, 24 May 2018 00:47:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:47:57 -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=INaBFYMuoWBzS85UfcjYW+NTYUCvY7I1O4dURl41LsQ=; b=lnUyQtUO gCi2R1pyqf2TMPSYVNSzlWDTpCSRaSUFr/tY3r0aRJ7V4BUbLyN/yXZTVwogKq8C mZfQyBVyhBuomWP8zzjGEz8tbe79om1+TFt5oob/66MaBdVkPvJbYolMmj+gtxtp yHlxrIbNrdfNdRjzvrp+HxWJEevSqV4F0ukoSk3SpRfVxJvnKscE1la7YIiDGLE5 35ivDeOw6mLfQycha3cIydzzDDZ9g0mhUMb9aPVAyskETs0n9qnKcc/DLvjdVVQB 0Yl8wOWLjNEVtqh1OSh5gKO6XK32Jw43rZiOt1j9zMfR4yFVC0E37cW+6vCjvcoV v++1d4Cs7E7wMg== 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=INaBFYMuoWBzS85UfcjYW+NTYUCvY7I1O4dURl41LsQ=; b=TmQSm3qQ j/KoArj3QMsGylYN7+GI35APSb8fJAHWeoTSwNVSBIPT2ifJZSsknuJwQHojW6Oa EkMfxQweoYT0dMXuEV6ZJXyDqua5MNCsyc4zh8yf/broKbWDiOJPGfn3zd0G6m1b BlO+gVWxEd3Fn6iAu01SaLcTBPp56xbRGQ5nyUk8FZpv0AC/bMYV4rqG2HztCQcE 56qm27yZ/iQtvbWcHUQK1kaaRAuYQktjRZMZZJsIFkbZZJ/6DXCbaGtvs6kYA8Jo /l1gIsYS5tJiJir8Z+7HKDzX8NwN+U/2jRKKlFzuObV0KtlROuvaw1e70YHPsOfY VmqEdyCp7S5cbA== 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 6224F1025E; Thu, 24 May 2018 00:47:56 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 4/9] utils/pb-udhcpc: Recognise DHCPv6 parameters Date: Thu, 24 May 2018 14:47:37 +1000 Message-Id: <20180524044742.25889-5-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" Signed-off-by: Samuel Mendoza-Jonas --- utils/pb-udhcpc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utils/pb-udhcpc b/utils/pb-udhcpc index 4495266..0507ea4 100644 --- a/utils/pb-udhcpc +++ b/utils/pb-udhcpc @@ -19,7 +19,8 @@ pb_add () { # Collect relevant DHCP response parameters into $paramstr for name in pxeconffile pxepathprefix bootfile mac ip siaddr \ - serverid tftp + serverid tftp \ + ipv6 bootfile_url bootfile_param do value=$(eval "echo \${$name}") [ -n "$value" ] || continue; From patchwork Thu May 24 04:47:38 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: 919568 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 40rxjf1jHFz9s0q for ; Thu, 24 May 2018 14:48:54 +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="F1MoefyJ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="XBIn+Sde"; 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 40rxjd70SszF1Gj for ; Thu, 24 May 2018 14:48:53 +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="F1MoefyJ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="XBIn+Sde"; 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="F1MoefyJ"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="XBIn+Sde"; 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 40rxhd5cXGzF15L for ; Thu, 24 May 2018 14:48:01 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 5155821C3F; Thu, 24 May 2018 00:47:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:47:59 -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=MFP74++G9+xrQUPxk9yc83eNN6DZBQvBiHjXjzYk+Nc=; b=F1MoefyJ zqNBhh76olm5WaVzwvoOoWMBDSy+GsiH47IUVrIF6V/3vOUbcKo1HBe7X7e5skWQ LLdb7ld5ysrBYhsEPh30YZ62vzVI3qAp4N5HEnddze7QhSxd8V7BWH6klPRnRXk8 t2KXWuBivynRldvkFqA+iI+vf9itV8H2lRwVv4Nf/CLxGF8FRjNrEcUpXZSBYfUn hmxbdoxSFsMbjFhv2cNXzI07yTOuNU0wR02m7gC+Zl3/mTHRwLDd2dX9Ryecul0G 1YuPVAvY6Mw1IOmc3+dDit1z4kcgsH31KF6HH3CUK/4CUL5fCdhlr2Tqg+FPK+qy OSA/P9ez0Pwnmg== 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=MFP74++G9+xrQUPxk9yc83eNN6DZBQvBiHjXjzYk+Nc=; b=XBIn+Sde 4unNrA3p4EaWTm2+Macy6FFrZIF4nbyRG8dGPTqMlNERbrz4R2vjQodh1ZjH/fY6 xkiJA1PSmBDH/Rb1NRaWzEu74ADEx9CQnGG0bUFRlPmq6GLEhRrSXI0BxCvje2w7 /xsrFCFVAoJC70InRASuyVRapb8Dd+pKJwekfbo7eRQYHRWQ8k4MlSZehnLsu44H 5li4GZoItgEVSaw4y5t3TMQ5K+wo84DXo8zHZ+DN/AE5L4lsT/aoj7bIvgQkHFoV GOZIS04eIhy5nigtOmDuRCa/t+mVIMubhQgGC8NYLzno3tGMgPhodeRrq20c9X+N dgAz0d/M/D4tOg== 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 011651025E; Thu, 24 May 2018 00:47:57 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 5/9] discover: Support IPv6 addresses Date: Thu, 24 May 2018 14:47:38 +1000 Message-Id: <20180524044742.25889-6-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" Support handling IPv6 addresses from user events and call the udhcpc6 client in addition to the udhcpc client. Signed-off-by: Samuel Mendoza-Jonas --- discover/device-handler.c | 51 +++++++++++++++-------- discover/network.c | 86 ++++++++++++++++++++++++++++++--------- discover/user-event.c | 8 +++- 3 files changed, 106 insertions(+), 39 deletions(-) diff --git a/discover/device-handler.c b/discover/device-handler.c index 569e652..4164409 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -1167,10 +1167,15 @@ int device_handler_dhcp(struct device_handler *handler, struct discover_device *dev, struct event *event) { struct discover_context *ctx; + const char *ip; + + if (event_get_param(event, "ipv6")) + ip = event_get_param(event, "ipv6"); + else + ip = event_get_param(event, "ip"); device_handler_status_dev_info(handler, dev, - _("Processing DHCP lease response (ip: %s)"), - event_get_param(event, "ip")); + _("Processing DHCP lease response (ip: %s)"), ip); pending_network_jobs_start(); @@ -1265,32 +1270,44 @@ void device_handler_update_config(struct device_handler *handler, static char *device_from_addr(void *ctx, struct pb_url *url) { char *ipaddr, *buf, *tok, *dev = NULL; + bool ipv6_route; const char *delim = " "; - struct sockaddr_in *ip; - struct sockaddr_in si; + struct sockaddr_in *ipv4; + struct sockaddr_in6 *ipv6; struct addrinfo *res; struct process *p; int rc; - /* Note: IPv4 only */ - rc = inet_pton(AF_INET, url->host, &(si.sin_addr)); - if (rc > 0) { - ipaddr = url->host; - } else { - /* need to turn hostname into a valid IP */ - rc = getaddrinfo(url->host, NULL, NULL, &res); - if (rc) { - pb_debug("%s: Invalid URL\n",__func__); - return NULL; - } + /* Confirm url->host is either a valid hostname, or a + * valid IPv4 or IPv6 address */ + rc = getaddrinfo(url->host, NULL, NULL, &res); + if (rc) { + pb_debug("%s: Invalid URL\n",__func__); + return NULL; + } + + switch (res->ai_family) { + case AF_INET: /* ipv4 */ ipaddr = talloc_array(ctx,char,INET_ADDRSTRLEN); - ip = (struct sockaddr_in *) res->ai_addr; - inet_ntop(AF_INET, &(ip->sin_addr), ipaddr, INET_ADDRSTRLEN); + ipv4 = (struct sockaddr_in *) res->ai_addr; + inet_ntop(AF_INET, &(ipv4->sin_addr), ipaddr, INET_ADDRSTRLEN); + ipv6_route = false; + break; + case AF_INET6: /* ipv6 */ + ipaddr = talloc_array(ctx,char,INET6_ADDRSTRLEN); + ipv6 = (struct sockaddr_in6 *) res->ai_addr; + inet_ntop(AF_INET6, &(ipv6->sin6_addr), ipaddr, INET6_ADDRSTRLEN); + ipv6_route = true; + break; + default: /* error */ freeaddrinfo(res); + return NULL; } + freeaddrinfo(res); const char *argv[] = { pb_system_apps.ip, + ipv6_route ? "-6" : "-4", "route", "show", "to", "match", ipaddr, NULL diff --git a/discover/network.c b/discover/network.c index e2cae91..7a9ae21 100644 --- a/discover/network.c +++ b/discover/network.c @@ -53,6 +53,7 @@ struct interface { struct list_item list; struct process *udhcpc_process; + struct process *udhcpc6_process; struct discover_device *dev; bool ready; }; @@ -279,6 +280,13 @@ static int interface_change(struct interface *interface, bool up) process_stop_async(interface->udhcpc_process); process_release(interface->udhcpc_process); } + if (!up && interface->udhcpc6_process) { + /* we don't care about the callback from here */ + interface->udhcpc6_process->exit_cb = NULL; + interface->udhcpc6_process->data = NULL; + process_stop_async(interface->udhcpc6_process); + process_release(interface->udhcpc6_process); + } if (!up) { rc = process_run_simple(interface, pb_system_apps.ip, @@ -312,9 +320,17 @@ static int interface_down(struct interface *interface) static void udhcpc_process_exit(struct process *process) { struct interface *interface = process->data; - pb_debug("udhcp client [pid %d] for interface %s exited, rc %d\n", - process->pid, interface->name, process->exit_status); - interface->udhcpc_process = NULL; + + if (process == interface->udhcpc_process) { + pb_debug("udhcpc client [pid %d] for interface %s exited, rc %d\n", + process->pid, interface->name, process->exit_status); + interface->udhcpc_process = NULL; + } else { + pb_debug("udhcpc6 client [pid %d] for interface %s exited, rc %d\n", + process->pid, interface->name, process->exit_status); + interface->udhcpc6_process = NULL; + } + process_release(process); } @@ -322,10 +338,10 @@ static void configure_interface_dhcp(struct network *network, struct interface *interface) { const struct platform *platform; - char pidfile[256], id[10]; - struct process *process; + char pidfile[256], idv4[10], idv6[10]; + struct process *p_v4, *p_v6; int rc; - const char *argv[] = { + const char *argv_ipv4[] = { pb_system_apps.udhcpc, "-R", "-f", @@ -333,7 +349,21 @@ static void configure_interface_dhcp(struct network *network, "-O", "pxepathprefix", "-p", pidfile, "-i", interface->name, - "-x", id, /* [11,12] - dhcp client identifier */ + "-x", idv4, /* [11,12] - dhcp client identifier */ + NULL, + }; + + const char *argv_ipv6[] = { + pb_system_apps.udhcpc6, + "-R", + "-f", + "-O", "bootfile_url", + "-O", "bootfile_param", + "-O", "pxeconffile", + "-O", "pxepathprefix", + "-p", pidfile, + "-i", interface->name, + "-x", idv6, /* [15,16] - dhcp client identifier */ NULL, }; @@ -344,24 +374,40 @@ static void configure_interface_dhcp(struct network *network, PIDFILE_BASE, interface->name); platform = platform_get(); - if (platform && platform->dhcp_arch_id != 0xffff) - snprintf(id, sizeof(id), "0x5d:%04x", platform->dhcp_arch_id); + if (platform && platform->dhcp_arch_id != 0xffff) { + snprintf(idv6, sizeof(idv6), "0x3d:%04x", + platform->dhcp_arch_id); + snprintf(idv4, sizeof(idv4), "0x5d:%04x", + platform->dhcp_arch_id); + } else { + argv_ipv4[11] = argv_ipv6[15] = NULL; + } + + p_v4 = process_create(interface); + p_v4->path = pb_system_apps.udhcpc; + p_v4->argv = argv_ipv4; + p_v4->exit_cb = udhcpc_process_exit; + p_v4->data = interface; + + pb_log("Running DHCPv4 client\n"); + rc = process_run_async(p_v4); + if (rc) + process_release(p_v4); else - argv[11] = NULL; - - process = process_create(interface); - - process->path = pb_system_apps.udhcpc; - process->argv = argv; - process->exit_cb = udhcpc_process_exit; - process->data = interface; + interface->udhcpc_process = p_v4; - rc = process_run_async(process); + pb_log("Running DHCPv6 client\n"); + p_v6 = process_create(interface); + p_v6->path = pb_system_apps.udhcpc6; + p_v6->argv = argv_ipv6; + p_v6->exit_cb = udhcpc_process_exit; + p_v6->data = interface; + rc = process_run_async(p_v6); if (rc) - process_release(process); + process_release(p_v6); else - interface->udhcpc_process = process; + interface->udhcpc6_process = p_v6; return; } diff --git a/discover/user-event.c b/discover/user-event.c index 77d28c1..59e0717 100644 --- a/discover/user-event.c +++ b/discover/user-event.c @@ -395,8 +395,12 @@ static int user_event_dhcp(struct user_event *uev, struct event *event) hwaddr, hwaddr + 1, hwaddr + 2, hwaddr + 3, hwaddr + 4, hwaddr + 5); - system_info_set_interface_address(sizeof(hwaddr), hwaddr, - event_get_param(event, "ip")); + if (event_get_param(event, "ipv6")) + system_info_set_interface_address(sizeof(hwaddr), hwaddr, + event_get_param(event, "ipv6")); + else + system_info_set_interface_address(sizeof(hwaddr), hwaddr, + event_get_param(event, "ip")); dev = discover_device_create(handler, event_get_param(event, "mac"), event->device); From patchwork Thu May 24 04:47:39 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: 919569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rxjp0ydJz9s0q for ; Thu, 24 May 2018 14:49:02 +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="qdjBop6J"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="BI0mJQcU"; 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 40rxjn61WfzF15L for ; Thu, 24 May 2018 14:49:01 +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="qdjBop6J"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="BI0mJQcU"; 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="qdjBop6J"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="BI0mJQcU"; 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 40rxhg0fnDzF1HF for ; Thu, 24 May 2018 14:48:03 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id CA8EC21C56; Thu, 24 May 2018 00:48:00 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:48:00 -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=zTpaCR5g5bmpBgq0fwNIMYUaf+ceC1XNbokTbn1ZTS8=; b=qdjBop6J wEAnF8qNsxAY8GcaeSeMGc0ijfikH5WViDg/oYF5oJJ5/lbLGp4He5ShOGx9xyVp GV+gyeMxzr6+6qrukNP0wTJbWivD4aVv3Nt/RF35L6XEPq/ZPpnM6DGFxTI2VE2v XemRmyUszcWmMfu4DwVQWjseBpxPE6U3vBFHK9guZPGFcEVs2uCaDv7DRi7jjx79 nbqkgh8nCrdr5+1mEwojLMBmBnTUajYqV16m2eljZyidPELbF9a0Lwdn1kxu91/I zZ2gP2hmDOnsJqO8Vu6ZybDG6f0OR1gssDZKK+o7FzAJryqlBiCTXGpc9GdeEzxY 9Y5601L2vVD2xA== 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=zTpaCR5g5bmpBgq0fwNIMYUaf+ceC1XNbokTbn1ZTS8=; b=BI0mJQcU KBroaDf8C3H+GvnXphqMoNXET9o/Bakk0daUHsXbjRreosAkcmV8IT2GyyMG+aKa zHL9C4uv1mUTbTgaYsoKYQ4/oOQIh1XS6k2xVWMfXxxlRf+94B2mJaHhwukq208P phmAQ/SBaQgEFtAPR/i7Boan/k3uX4ufzx/O0uZkt0NAkcJtgYCzsOxZVVqGPnBF nlEvdMp+W1k1yNZIDZ6nxrpZMgOln7VZgBLtne+AADoN3TgunblS8lQPr5QGx7r9 NLN+2eu1lkyoMKh74DSfpHhfcJ8gVSavoLEJaPhrjYuutxAKcoiIguxKW2d9etBC TwJX2ZlY3m+dIg== 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 887871025E; Thu, 24 May 2018 00:47:59 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 6/9] discover/user-event: Use bootfile_url if available Date: Thu, 24 May 2018 14:47:39 +1000 Message-Id: <20180524044742.25889-7-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" Signed-off-by: Samuel Mendoza-Jonas --- discover/user-event.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/discover/user-event.c b/discover/user-event.c index 59e0717..2212bfe 100644 --- a/discover/user-event.c +++ b/discover/user-event.c @@ -251,13 +251,14 @@ static char *parse_ip_addr(struct discover_context *ctx, const char *ip) struct pb_url *user_event_parse_conf_url(struct discover_context *ctx, struct event *event, bool *is_complete) { - const char *conffile, *pathprefix, *host, *bootfile; + const char *conffile, *pathprefix, *host, *bootfile, *bootfile_url; char *p, *basedir, *url_str; struct pb_url *url; conffile = event_get_param(event, "pxeconffile"); pathprefix = event_get_param(event, "pxepathprefix"); bootfile = event_get_param(event, "bootfile"); + bootfile_url = event_get_param(event, "bootfile_url"); /* If we're given a conf file, we're able to generate a complete URL to * the configuration file, and the parser doesn't need to do any @@ -288,6 +289,12 @@ struct pb_url *user_event_parse_conf_url(struct discover_context *ctx, host = parse_host_addr(event); if (!host) { pb_log("%s: host address not found\n", __func__); + + /* No full URLs and no host address? Check for DHCPv6 options */ + if (bootfile_url && is_url(bootfile_url)) { + *is_complete = true; + return pb_url_parse(ctx, bootfile_url); + } return NULL; } From patchwork Thu May 24 04:47:40 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: 919570 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 40rxjy5mjjz9s0q for ; Thu, 24 May 2018 14:49:10 +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="Pd1/RnOm"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="XFXzN2po"; 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 40rxjy3Mf7zDrBx for ; Thu, 24 May 2018 14:49:10 +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="Pd1/RnOm"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="XFXzN2po"; 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="Pd1/RnOm"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="XFXzN2po"; 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 40rxhh5Mx6zF1Hp for ; Thu, 24 May 2018 14:48:04 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 7C37921C60; Thu, 24 May 2018 00:48:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:48:02 -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=60AJp+U+aUDrJFK7y/Fvz94yuLels9lVcxYI5pix5nI=; b=Pd1/RnOm 5mUc8HFmYQmwQRVIk0PD61irz39RFYoc9KiNzh97TaLpALNVT9P6QqOUcc6Q6/xg Twoy6lGpEwYpU4Lh+HAG727fHxBBFf9pwr8lKdj693dAV+uav2xkpV3NxU4VPxIY UQmwlMwNkDHrT6UB0y5cDvyp2XcOMMZsbVLj99QVofmrLq34HVQKnEMFXXoCATK7 tsS9MGJ8eT43G9EcACMROHLdVSgTbckVK9kbj3CqlqwXTVXCxEJEYbocVaYLEvBe b+rD5ElZbsCxI0QLZnr4X49N4Tf+WZ/KxvyAD1A4pm8xP5fzKkn0R8F/i3FfeJCA t45fqo1hOzqEzA== 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=60AJp+U+aUDrJFK7y/Fvz94yuLels9lVcxYI5pix5nI=; b=XFXzN2po oUBdbaB4ejQTnMeCZXmB7+Zj3aMGl5vkG4xVqcMTJ9FXsVH7DvM+/WTW/VyBU0B7 D0ereavG7DMhiKBL/GVYz9smGefBoP5eRfMgGsPRgzhdDqfTAnwf5e83/icjPlUA 5HmExj+YWcv6LhcwKPhnPUCWQb3ZZUjeb/K3RQnziSrDlvg3WynTgDA7nMOAM+zs Wkf+7qt7B79RWOEsJW2Y649JPUESErHUR02QUax2e5Q22cHdRp1sYWmXAWM3SbvN MzvJ8UjMfxdIiquVldaq66GCoqGtvI+HrndpXDajHBoi5IuA33NKQZgAI49tLfNz 0rovKpr6KPr5sw== 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 1D0021025E; Thu, 24 May 2018 00:48:00 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 7/9] discover/pxe-parser: Parse simple iPXE scripts Date: Thu, 24 May 2018 14:47:40 +1000 Message-Id: <20180524044742.25889-8-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" Signed-off-by: Samuel Mendoza-Jonas --- discover/pxe-parser.c | 96 ++++++++++++++++++++++++++++- test/parser/Makefile.am | 3 + test/parser/test-pxe-ipxe-default.c | 40 ++++++++++++ test/parser/test-pxe-ipxe-named.c | 39 ++++++++++++ test/parser/test-pxe-ipxe.c | 40 ++++++++++++ 5 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 test/parser/test-pxe-ipxe-default.c create mode 100644 test/parser/test-pxe-ipxe-named.c create mode 100644 test/parser/test-pxe-ipxe.c diff --git a/discover/pxe-parser.c b/discover/pxe-parser.c index fd8b8e8..da9a49f 100644 --- a/discover/pxe-parser.c +++ b/discover/pxe-parser.c @@ -258,6 +258,97 @@ static void pxe_load_next_filename(struct conf_context *conf) return; } +/* + * Parse a limited set of iPXE commands. This is handled separately from + * conf_parse_buf() since not all commands will have a value. + */ +static bool ipxe_simple_parser(struct conf_context *ctx, char *buf, int len) +{ + struct discover_boot_option *opt; + char *p, *name, *value; + struct pb_url *url; + + p = strstr(buf, "#!ipxe"); + + /* Only try to parse this if the ipxe header is right at the start */ + if (!p || p != buf) + return false; + p = strchr(buf, '\n') + 1; + + opt = discover_boot_option_create(ctx->dc, ctx->dc->device); + + opt->option->id = talloc_asprintf(opt, "%s@%p", + ctx->dc->device->device->id, opt); + opt->option->type = DISCOVER_BOOT_OPTION; + + while (p && p <= buf + len) { + + p = conf_get_pair(ctx, p, &name, &value, ' ', '\n'); + + /* The 'boot' command appears by itself without options */ + if (!name && value && streq(value, "boot")) { + opt->option->is_default = true; + continue; + } + + /* All other parameters require a value */ + if (!value) { + pb_debug("%s: '%s' missing value\n", __func__, name); + continue; + } + + if (streq(name, "kernel")) { + char *args, *name = NULL, *saveptr = NULL, *tmp; + + /* + * value is of the form: + * boot_image [--name option_name ] [option args ...] + */ + tmp = strtok_r(value, " ", &saveptr); + if (!tmp) { + pb_log("%s: malformed kernel statement\n", __func__); + break; + } + + url = pxe_url_join(ctx->dc, ctx->dc->conf_url, tmp); + opt->boot_image = create_url_resource(opt, url); + + tmp = strtok_r(NULL, " ", &saveptr); + if (!tmp) + continue; + if (streq(tmp, "--name")) { + tmp = strtok_r(NULL, " ", &saveptr); + name = talloc_asprintf(opt, "%s", + tmp ?: "malformed ipxe option"); + args = strtok_r(NULL, " ", &saveptr); + } else + args = tmp; + + while (args) { + pxe_append_string(opt, args); + args = strtok_r(NULL, " ", &saveptr); + } + + opt->option->name = name ?: talloc_asprintf(opt, + "ipxe option (%s)", url->full); + continue; + } + + if (streq(name, "initrd")) { + url = pxe_url_join(ctx->dc, ctx->dc->conf_url, value); + opt->initrd = create_url_resource(opt, url); + continue; + } + } + + if (opt->boot_image) + discover_context_add_boot_option(ctx->dc, opt); + else + pb_debug("ipxe file did not contain a valid option\n"); + + return true; +} + /* * Callback for asynchronous loads from pxe_parse() * @param result Result of load_url_async() @@ -308,9 +399,10 @@ static void pxe_conf_parse_cb(struct load_url_result *result, void *data) * Parse the first successfully downloaded file. We only want to parse * the first because otherwise we could parse options from both a * machine-specific config and a 'fallback' default config + * We also check if the file is in the limited ipxe format. */ - - conf_parse_buf(conf, buf, len); + if (!ipxe_simple_parser(conf, buf, len)) + conf_parse_buf(conf, buf, len); /* We may be called well after the original caller of iterate_parsers(), * commit any new boot options ourselves */ diff --git a/test/parser/Makefile.am b/test/parser/Makefile.am index 6ff3972..1732158 100644 --- a/test/parser/Makefile.am +++ b/test/parser/Makefile.am @@ -64,6 +64,9 @@ parser_TESTS = \ test/parser/test-pxe-initrd-in-append \ test/parser/test-pxe-mac-without-conf \ test/parser/test-pxe-ip-without-conf \ + test/parser/test-pxe-ipxe \ + test/parser/test-pxe-ipxe-named \ + test/parser/test-pxe-ipxe-default \ test/parser/test-pxe-non-url-conf \ test/parser/test-pxe-local \ test/parser/test-pxe-ipappend \ diff --git a/test/parser/test-pxe-ipxe-default.c b/test/parser/test-pxe-ipxe-default.c new file mode 100644 index 0000000..d80cc41 --- /dev/null +++ b/test/parser/test-pxe-ipxe-default.c @@ -0,0 +1,40 @@ +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +#!ipxe +kernel vmlinux --name test-option +initrd initrd +boot +#endif + +/** + * Test that we recognise an ipxe-formatted script obtained from bootfile_url + * (DHCPv6 option 59) that some vendors use, and that we set it as default. + */ + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded_url(test, "tftp://host/dir1/conf"); + + test_set_event_source(test); + test_set_event_param(test->ctx->event, "bootfile_url", "tftp://host/dir1/conf"); + + test_run_parser(test, "pxe"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + + check_name(opt, "test-option"); + + check_resolved_url_resource(opt->boot_image, + "tftp://host/dir1/vmlinux"); + check_resolved_url_resource(opt->initrd, + "tftp://host/dir1/initrd"); + check_args(opt, NULL); + check_is_default(opt); +} diff --git a/test/parser/test-pxe-ipxe-named.c b/test/parser/test-pxe-ipxe-named.c new file mode 100644 index 0000000..dae2fc6 --- /dev/null +++ b/test/parser/test-pxe-ipxe-named.c @@ -0,0 +1,39 @@ +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +#!ipxe +kernel vmlinux --name test-option append kernel args +initrd initrd +#endif + +/** + * Test that we recognise an ipxe-formatted script obtained from bootfile_url + * (DHCPv6 option 59) that some vendors use, and that we correctly parse the + * --name parameter from the kernel arguments. + */ + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded_url(test, "tftp://host/dir1/conf"); + + test_set_event_source(test); + test_set_event_param(test->ctx->event, "bootfile_url", "tftp://host/dir1/conf"); + + test_run_parser(test, "pxe"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + + check_name(opt, "test-option"); + + check_resolved_url_resource(opt->boot_image, + "tftp://host/dir1/vmlinux"); + check_resolved_url_resource(opt->initrd, + "tftp://host/dir1/initrd"); + check_args(opt, "append kernel args"); +} diff --git a/test/parser/test-pxe-ipxe.c b/test/parser/test-pxe-ipxe.c new file mode 100644 index 0000000..e3bc202 --- /dev/null +++ b/test/parser/test-pxe-ipxe.c @@ -0,0 +1,40 @@ + + +#include "parser-test.h" + +#if 0 /* PARSER_EMBEDDED_CONFIG */ +#!ipxe +kernel vmlinux append kernel args +initrd initrd +#endif + +/** + * Test that we recognise an ipxe-formatted script obtained from bootfile_url + * (DHCPv6 option 59) that some vendors use. + */ + +void run_test(struct parser_test *test) +{ + struct discover_boot_option *opt; + struct discover_context *ctx; + + test_read_conf_embedded_url(test, "tftp://host/dir1/conf"); + + test_set_event_source(test); + test_set_event_param(test->ctx->event, "bootfile_url", "tftp://host/dir1/conf"); + + test_run_parser(test, "pxe"); + + ctx = test->ctx; + + check_boot_option_count(ctx, 1); + opt = get_boot_option(ctx, 0); + + check_name(opt, "ipxe option (tftp://host/dir1/vmlinux)"); + + check_resolved_url_resource(opt->boot_image, + "tftp://host/dir1/vmlinux"); + check_resolved_url_resource(opt->initrd, + "tftp://host/dir1/initrd"); + check_args(opt, "append kernel args"); +} 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, From patchwork Thu May 24 04:47:42 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: 919572 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40rxkH2t0Lz9s0q for ; Thu, 24 May 2018 14:49:27 +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="npPYJglY"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="G3ObZIRn"; 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 40rxkH0rVJzF1Hr for ; Thu, 24 May 2018 14:49:27 +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="npPYJglY"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="G3ObZIRn"; 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="npPYJglY"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="G3ObZIRn"; 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 40rxhm25cRzF1LK for ; Thu, 24 May 2018 14:48:08 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 9E9A021C2C; Thu, 24 May 2018 00:48:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Thu, 24 May 2018 00:48:05 -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=wrvCvfjgs6HPZ5AhVGAALUsijxOOV2xutCtUB2FKzVk=; b=npPYJglY nTpvjcatCb12JjNfsf0TT4vrUkGR6eBP2TRBFMNa7kjFtzC/OPbmXOROMIr+RVGw 8x1zc3SpI6Yci4+yEkfmOaGkcQcWgOmiTDVSwIaMB57wRalbUsMqIa0PLc5/1eB9 vZkVUIZbnKHP6KS18cOJXbsZKFJ0cxlI8bIeSZci5E+cj13DjvnTkJiKOoOgTAVV Eyr5SwtdJVxqjV3coKzQFDqhZ75zAmF1hyTn/pt9prnEIYljtu83SbEXt63CWXNc /3w8UpsIjNg7I6NMVu6AYBFYI0j/rWF3a2/PQ9l1adxphstKMHkTwyxngLmEwpJj ecNa9YC6ZeDH0A== 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=wrvCvfjgs6HPZ5AhVGAALUsijxOOV2xutCtUB2FKzVk=; b=G3ObZIRn Zu0AH9tahocwsGkar2olB0iOsQM0g3McDUtl4EcoltF7W0F7ThXyJSDpY9Au9onH 3rZ//miqO/HWMdIdjN1bEbm0vljWRBYMwiuIdWRcxUYQ+CSVMZ7syEW5GATcECu8 2hy7sPRcui4taKsZCuO0iV8jTacbrRKXn3M11WLEGAn8WaoV1ORKL6hd/sKyvduo b5MQ4nqbvXJRAvMY0m4INb4ICHI74FKNeDQsvZhqKmnf54szV7raxuX+iWh6N7ys 7g6MPSjX0iUZKPBXkBkj0YsHdVb8wFYeMP3pMKtfbqHFCfN+1idAwMRlqexbNu6F fvL5iFmG7ZEviA== 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 58A651025E; Thu, 24 May 2018 00:48:04 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH v2 9/9] ui/ncurses: Allow IPv6 addresses in address fields Date: Thu, 24 May 2018 14:47:42 +1000 Message-Id: <20180524044742.25889-10-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" Signed-off-by: Samuel Mendoza-Jonas --- ui/ncurses/nc-config.c | 8 +-- ui/ncurses/nc-widgets.c | 115 +++++++++++++++++++++++++++------------- ui/ncurses/nc-widgets.h | 4 +- 3 files changed, 84 insertions(+), 43 deletions(-) diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c index 5c0f23b..5186176 100644 --- a/ui/ncurses/nc-config.c +++ b/ui/ncurses/nc-config.c @@ -1029,8 +1029,8 @@ static void config_screen_setup_widgets(struct config_screen *screen, widget_textbox_set_fixed_size(screen->widgets.ip_addr_f); widget_textbox_set_fixed_size(screen->widgets.ip_mask_f); - widget_textbox_set_validator_ipv4(screen->widgets.ip_addr_f); - widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 31); + widget_textbox_set_validator_ip(screen->widgets.ip_addr_f); + widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, 1, 127); screen->widgets.gateway_l = widget_new_label(set, 0, 0, _("Gateway:")); screen->widgets.gateway_f = widget_new_textbox(set, 0, 0, 16, gw); @@ -1038,7 +1038,7 @@ static void config_screen_setup_widgets(struct config_screen *screen, widget_new_label(set, 0, 0, _("(eg. 192.168.0.1)")); widget_textbox_set_fixed_size(screen->widgets.gateway_f); - widget_textbox_set_validator_ipv4(screen->widgets.gateway_f); + widget_textbox_set_validator_ip(screen->widgets.gateway_f); screen->widgets.url_l = widget_new_label(set, 0, 0, _("URL:")); screen->widgets.url_f = widget_new_textbox(set, 0, 0, 32, url); @@ -1059,7 +1059,7 @@ static void config_screen_setup_widgets(struct config_screen *screen, screen->widgets.dns_help_l = widget_new_label(set, 0, 0, _("(eg. 192.168.0.2)")); - widget_textbox_set_validator_ipv4_multi(screen->widgets.dns_f); + widget_textbox_set_validator_ip_multi(screen->widgets.dns_f); screen->widgets.dns_dhcp_help_l = widget_new_label(set, 0, 0, _("(if not provided by DHCP server)")); diff --git a/ui/ncurses/nc-widgets.c b/ui/ncurses/nc-widgets.c index 93c882b..30915a9 100644 --- a/ui/ncurses/nc-widgets.c +++ b/ui/ncurses/nc-widgets.c @@ -44,8 +44,10 @@ # error "Curses form.h not found." #endif -#include +#include #include +#include +#include #include #include @@ -83,7 +85,8 @@ struct nc_widgetset { FIELD *cur_field; /* custom validators */ - FIELDTYPE *ipv4_multi_type; + FIELDTYPE *ip_multi_type; + FIELDTYPE *ip_type; FIELDTYPE *url_type; }; @@ -415,54 +418,88 @@ void widget_textbox_set_validator_url(struct nc_widget_textbox *textbox) set_field_type(textbox->widget.field, textbox->set->url_type); } -void widget_textbox_set_validator_ipv4(struct nc_widget_textbox *textbox) +static bool check_ip_field(FIELD *field, + const void *arg __attribute__((unused))) +{ + char *str; + int rc; + + str = strip_string(field_buffer(field, 0)); + + rc = addr_scheme(str); + + return (rc == AF_INET || rc == AF_INET6); +} + + +static bool check_ipv6_multi_char(int c) { - set_field_type(textbox->widget.field, TYPE_IPV4); + return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || + c == ':' || c == ' '; } -static bool check_ipv4_multi_char(int c, - const void *arg __attribute__((unused))) +static bool check_ipv4_multi_char(int c) { return isdigit(c) || c == '.' || c == ' '; } -static bool check_ipv4_multi_field(FIELD *field, +static bool check_ip_multi_field(FIELD *field, const void *arg __attribute__((unused))) { - char *buf = field_buffer(field, 0); - unsigned int ip[4]; - int n, len; - - while (*buf != '\0') { - n = sscanf(buf, "%u.%u.%u.%u%n", - &ip[0], &ip[1], &ip[2], &ip[3], &len); - if (n != 4) - return false; - - if (ip[0] > 255 || ip[1] > 255 || ip[2] > 255 || ip[3] > 255) - return false; - - for (buf += len; *buf != '\0'; buf++) { - if (isspace(*buf)) - continue; - else if (isdigit(*buf)) - break; - else - return false; - } + char *buf, *tok, *saveptr; + bool result; + int type; + + /* Use strdup directly since we can't easily reach a talloc parent */ + buf = strdup(strip_string(field_buffer(field, 0))); + if (!buf) + /* We tried */ + return true; + + result = false; + tok = strtok_r(buf, " ", &saveptr); + if (!tok || *tok == '\0') + goto err; + + while (tok) { + type = addr_scheme(tok); + if (!(type == AF_INET || type == AF_INET6)) + goto err; + + tok = strtok_r(NULL, " ", &saveptr); } + result = true; - return true; +err: + free(buf); + return result; +} + +static bool check_ip_multi_char(int c, const void *arg __attribute__((unused))) +{ + return (check_ipv4_multi_char(c) || check_ipv6_multi_char(c)); } -void widget_textbox_set_validator_ipv4_multi(struct nc_widget_textbox *textbox) +void widget_textbox_set_validator_ip(struct nc_widget_textbox *textbox) +{ + if (!textbox->set->ip_type) { + textbox->set->ip_type = new_fieldtype(check_ip_field, NULL); + } + set_field_type(textbox->widget.field, textbox->set->ip_type); +} + +/* + * In a perfect world we would use link_fieldtype() but segfaults do not + * enhance the user experience. + */ +void widget_textbox_set_validator_ip_multi(struct nc_widget_textbox *textbox) { - if (!textbox->set->ipv4_multi_type) { - textbox->set->ipv4_multi_type = new_fieldtype( - check_ipv4_multi_field, - check_ipv4_multi_char); + if (!textbox->set->ip_multi_type) { + textbox->set->ip_multi_type = new_fieldtype( + check_ip_multi_field, + check_ip_multi_char); } - set_field_type(textbox->widget.field, textbox->set->ipv4_multi_type); + set_field_type(textbox->widget.field, textbox->set->ip_multi_type); } static void subset_update_order(struct nc_widget_subset *subset) @@ -1201,8 +1238,12 @@ static int widgetset_destructor(void *ptr) { struct nc_widgetset *set = ptr; free_form(set->form); - if (set->ipv4_multi_type) - free_fieldtype(set->ipv4_multi_type); + if (set->ip_type) + free_fieldtype(set->ip_type); + if (set->ip_multi_type) + free_fieldtype(set->ip_multi_type); + if (set->url_type) + free_fieldtype(set->url_type); return 0; } diff --git a/ui/ncurses/nc-widgets.h b/ui/ncurses/nc-widgets.h index aa9263f..a946c4f 100644 --- a/ui/ncurses/nc-widgets.h +++ b/ui/ncurses/nc-widgets.h @@ -40,8 +40,8 @@ struct nc_widget_button *widget_new_button(struct nc_widgetset *set, void widget_textbox_set_fixed_size(struct nc_widget_textbox *textbox); void widget_textbox_set_validator_integer(struct nc_widget_textbox *textbox, long min, long max); -void widget_textbox_set_validator_ipv4(struct nc_widget_textbox *textbox); -void widget_textbox_set_validator_ipv4_multi(struct nc_widget_textbox *textbox); +void widget_textbox_set_validator_ip(struct nc_widget_textbox *textbox); +void widget_textbox_set_validator_ip_multi(struct nc_widget_textbox *textbox); void widget_textbox_set_validator_url(struct nc_widget_textbox *textbox); void widget_subset_add_option(struct nc_widget_subset *subset, const char *text);