From patchwork Wed May 9 05:36:59 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: 910660 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 40glqy6qY9z9s1w for ; Wed, 9 May 2018 15:52:30 +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="YlPPR4A4"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="nZdHcI+X"; 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 40glqy5M5wzF2Mb for ; Wed, 9 May 2018 15:52:30 +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="YlPPR4A4"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="nZdHcI+X"; 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.27; helo=out3-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="YlPPR4A4"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="nZdHcI+X"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40glVS2FYszF25j for ; Wed, 9 May 2018 15:37:20 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id DE06F22A84; Wed, 9 May 2018 01:37:17 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 09 May 2018 01:37:17 -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= fm2; bh=zSQJDQCjSSO1SklQoG6Je9ph2Im/oc80JvUTufKdZvA=; b=YlPPR4A4 LfP/EnWrsmQziMhHwklgAF7Ka6pt4i2qYrA/0YLfd5AHbiJEo7tCNWKQ6MBsEXRM zBDs5zGIQMdTpuAmK2qasTjcDq4YAHi80JRivQK2IChuxB9A6cyMKsX2sn9Ismlu LSWzJQZAgIm1qmkd6c9zRzldF+fr5kNvfKZBO5CXeelfkp8y5/CoxBy2ginjT2ds RVNKJHT56JjiYkM5Y0b8RNmN+VxculyOsJXqJKQUsWTpEvULhTpE843Tr9FK/MdZ nsn7NUFCxSrxJixlfjcpWszkjxrHJ1qgGCPDNX79sk8ArrDYdSipmkXO5vnqlocJ kuST3acC4eSAmw== 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=zSQJDQCjSSO1SklQoG6Je9ph2Im/oc80JvUTufKdZvA=; b=nZdHcI+X msYTrunYYDZOzNHGiZ/we/0g9F0y/xqDUkM3kbz2ISMTtcJSCgdNWsAWYS1nNf2z bjm+loRMaJuSuKdcJ9e8/kYA+uCNjn/3KA5zJ5CAdzWF8Wv8L0GVfQ2Gm8oST9rT 8tOdB5Ca7fOQdqudmLNMP6OWJb6s/Hg1K2W1IKkg7nBnxW1muk4Ps2NN6CbqSD8t bLi5RqvZgVONVrIP1M5n8H2YWC9uGHyhOWql/IROD6TqW1+17jHifVwaG8l7HN6F II5YfgOEkEe4ufA1sU/+QS87KnbThuL2Vt2BQIREvKfF8Qc/gSSTcpQ2elhGnfiZ zLG8HCPLtWGbYA== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 9EAEA10253; Wed, 9 May 2018 01:37:16 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 1/7] lib/url: Parse IPv6 URLs Date: Wed, 9 May 2018 15:36:59 +1000 Message-Id: <20180509053705.3143-2-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509053705.3143-1-sam@mendozajonas.com> References: <20180509053705.3143-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 --- lib/url/url.c | 32 +++++++++++++++++++++++++----- 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 +++++++ 5 files changed, 51 insertions(+), 5 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/url/url.c b/lib/url/url.c index 6eeced3..830151e 100644 --- a/lib/url/url.c +++ b/lib/url/url.c @@ -20,6 +20,7 @@ #include "config.h" #endif +#include #include #include @@ -197,19 +198,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++) ; @@ -234,10 +251,15 @@ bool is_url(const char *str) char *pb_url_to_string(struct pb_url *url) { const struct pb_scheme_info *scheme = pb_url_scheme_info(url->scheme); + uint8_t addr[INET6_ADDRSTRLEN]; assert(scheme); - return talloc_asprintf(url, "%s://%s%s", scheme->str, - scheme->has_host ? url->host : "", url->path); + if (scheme->has_host && inet_pton(AF_INET6, url->host, addr) == 1) + 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/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 Wed May 9 05:37:00 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: 910661 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 40glr61QWvz9s3q for ; Wed, 9 May 2018 15:52:38 +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="PLxssxBY"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="EZFI2/fI"; 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 40glr56rlBzF2Mb for ; Wed, 9 May 2018 15:52:37 +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="PLxssxBY"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="EZFI2/fI"; 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.27; helo=out3-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="PLxssxBY"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="EZFI2/fI"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40glVT4k2MzF279 for ; Wed, 9 May 2018 15:37:21 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 6C7F322EB8; Wed, 9 May 2018 01:37:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 09 May 2018 01:37:19 -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= fm2; bh=Y515msqHVlJ8Op9FG2WpSR8lY2xNj6t0M1SBFLrQ8X4=; b=PLxssxBY DV7Vm8z3KsI7emFmdKAfrHyv86wbVjfuwWqLYazhQVcbYzAaaevFx5ideRw7e9sY cmNlorLqqy4+J83CIG2hbbA7Hfs4AWWnoFsve/hCC5ySgznt9TCwtatyC6o7DI84 3urViABH2JykOtZ5od+ro6OcXx/5d0cFG6T4/e4bN0RYZEfePkrX8ENk21UuoK9q ZlRUY+aAgzCvYBSums8k/MtVse02mGaaDfmG0j8ywkbhCNqYZ6mh8R26bg4lMPzI pGhivYeR+Vk9H/OLFKQqPc9gfHppBOkdWcFMsQnyCN7P/Hfi4HYkPrh6Cj0pBG0N fRstxzNxCeGOrg== 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=Y515msqHVlJ8Op9FG2WpSR8lY2xNj6t0M1SBFLrQ8X4=; b=EZFI2/fI NhuqlfL92tCLUFBQ5xEoioH+Gvth9vpwnUrKECsV43hmK+x022hGSc2WO3K3qASk dQOE4NJmISbaY/2DKpJrQ7EAQIfdbk9/lokP6TDwbCY0mMP3LB6HrZ1foGtMbUHK 4Fydc82uzFKtrYyTKcdAXmjYbkmaleMQfcs+nyO75Hs6VmEoLQ4SLnu+1amKvol8 ZA/jnaWGMEvrC3o3DFDK/kfhglWiW74NWs2GJHlmSWy2TRpLXT4SU0FEZdoSn2DY 3mGJ4Ca1eC5Wb7THwsd8ggykiAhzMuEnKq7AZF0NO2oAYnrpmBt3dh/Bnv6RNjfQ dLHBVnjRQIQcXw== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 3220610253; Wed, 9 May 2018 01:37:17 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 2/7] lib/system: Add udhcpc6 Date: Wed, 9 May 2018 15:37:00 +1000 Message-Id: <20180509053705.3143-3-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509053705.3143-1-sam@mendozajonas.com> References: <20180509053705.3143-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 1fa0ea4..62a0b3f 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 Wed May 9 05:37:01 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: 910662 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 40glrG0znKz9s1w for ; Wed, 9 May 2018 15:52:46 +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="kHZEDpfC"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="SSZyEol1"; 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 40glrF6jTvzF1n5 for ; Wed, 9 May 2018 15:52: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="kHZEDpfC"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="SSZyEol1"; 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.27; helo=out3-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="kHZEDpfC"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="SSZyEol1"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40glVW2GnyzF27k for ; Wed, 9 May 2018 15:37:23 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 122C821C5B; Wed, 9 May 2018 01:37:21 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 09 May 2018 01:37:21 -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= fm2; bh=INaBFYMuoWBzS85UfcjYW+NTYUCvY7I1O4dURl41LsQ=; b=kHZEDpfC 8LFw5tfnCEawCHGmVghPTMTkZ26OqWmXuE2ULSuE39CdlP892MMwjd35ltcdqsHz bvTY05ZlpQlvkvsic9EuBPdTrDsAQ3Lh3Vi0L/FjwRNjNiZzeFHKf/eSYelKfE6J RsTOJZAOZ3l0PEPNDIbJ3Bsqh932iD9XiXdqmIwA3zQQeDVsPU/JgdrIhbxI1sLS YC3hDCKfn1KjxNnHCPcVWTB7GW4fKhf8VXysrOvf7Z5D/6MvsTNZsGiNippM48nD YzY3uC0fKdcBdnUHUgMYs7M9d9CTTAvDX/3BFqy0mWP5TGAoU9sugiioZZryFHLh m3Nz6BNVwIEPoQ== 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=SSZyEol1 8u1tUP8hlNoYewVHeYp1M+umfg6imIzkRgKCYTp2Thb9KEcjCkTR1fDm0bwo4keu oZmHP57yIJnpvSuvHpAn9Yf/D55v7RdVyoBOJmL4MCOnMBo+8WGbFYmXEbRdoDjr KRar/1Ut735ghPIcGxOEX1uooOFyTUd0d0Q//mHGSJkIkjwZubi+YxP14z6nKGM6 RCkaNLuZjOI0E1Usv2u21xI9jDuABjzDTz8iGOK8hM2nSRfUQ1RToj2ZDksmmDK/ 67WbQA070tDTB3YXMm69UKEkH0VhxrDGaHKIXoHpcwM4zh9eN1W+yXx9CXFrj8c5 gCbRxqn3ouwskw== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id B789710253; Wed, 9 May 2018 01:37:19 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 3/7] utils/pb-udhcpc: Recognise DHCPv6 parameters Date: Wed, 9 May 2018 15:37:01 +1000 Message-Id: <20180509053705.3143-4-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509053705.3143-1-sam@mendozajonas.com> References: <20180509053705.3143-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 Wed May 9 05:37:02 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: 910663 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 40glrP1Rk0z9s1w for ; Wed, 9 May 2018 15:52:53 +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="UqhR+70z"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="evKquckr"; 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 40glrN71V2zF26C for ; Wed, 9 May 2018 15:52:52 +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="UqhR+70z"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="evKquckr"; 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.27; helo=out3-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="UqhR+70z"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="evKquckr"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40glVX69vdzF26C for ; Wed, 9 May 2018 15:37:24 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 97A4322B9C; Wed, 9 May 2018 01:37:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 09 May 2018 01:37:22 -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= fm2; bh=0cSwR67+e8tGeoAHwoWXmxxKjCy1LTr+RXCjRKRALEA=; b=UqhR+70z SOO/ZoHDgAyPfOBhmnALhBIM6wXJe76KpyWpBrLlM4RXrU8Z+9ZgW3EFNyfiYQ+x SOMs4yNdpSoF603e1RIb03IlkdmUjiVtwPuLbAsxk20MxybkS/U6E9kEBuGlvL6B MODw536XxH6TQQBySsSGFPL70HubhuqWzkBmH3KfITivr4YCbXlzx2A8oNptWah6 xkNRygPl5Aa7DL1K/LaRRZae3eYiBJVrCknJejcPOv1gU74sGAUZiik9wkMM1M9D oCAyOSFuwuvHuF48DTlMDlGD5YXEVWBkjUJHQENbyhmvshyz87ajRgqO/tKTVeYm cPghkZafbn3MSA== 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=0cSwR67+e8tGeoAHwoWXmxxKjCy1LTr+RXCjRKRALEA=; b=evKquckr lq3YVoNBt5dtqmWuV9JMGeVsR+Hl9W7ffE3ED3X/wGHv1etGfGzhObG7LtVXfHpq Lg/20O36wjtxdQcmbHY0o+zjwTQ9XljdBtpCmPgYPDALjGyfHkhzcvdqiVzBB1lW qgDiZKD0uAofqISL2Z+7Eyd2G4OfkqPuHURP0vnrQrYlE++aa+7rgf1vhjNzoMoj A3DU7B2G4zh5Yhy8Lqi88O3dF/Zn4y1/0ECsLgEtgr5MJ8e/u2jfWnHmxCOnfMM5 VG9uQBFSQfajRvoBkeLkY8LVnTFgZQBvTcm3wyxYa22JpLpNUOtBYtxVdGerM5R7 o5CXUAK3EZAp1A== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 5800B10253; Wed, 9 May 2018 01:37:21 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 4/7] lib/types: Add DHCP scheme to network config Date: Wed, 9 May 2018 15:37:02 +1000 Message-Id: <20180509053705.3143-5-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509053705.3143-1-sam@mendozajonas.com> References: <20180509053705.3143-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 --- lib/pb-protocol/pb-protocol.c | 9 +++++++++ lib/types/types.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/lib/pb-protocol/pb-protocol.c b/lib/pb-protocol/pb-protocol.c index dbbda40..74a89de 100644 --- a/lib/pb-protocol/pb-protocol.c +++ b/lib/pb-protocol/pb-protocol.c @@ -309,6 +309,8 @@ int pb_protocol_config_len(const struct config *config) for (i = 0; i < config->network.n_dns_servers; i++) len += 4 + optional_strlen(config->network.dns_servers[i]); + len += 4 /* config->network.addr_type */; + len += 4 + optional_strlen(config->http_proxy); len += 4 + optional_strlen(config->https_proxy); @@ -581,6 +583,9 @@ int pb_protocol_serialise_config(const struct config *config, config->network.dns_servers[i]); } + *(uint32_t *)pos = __cpu_to_be32(config->network.addr_type); + pos += 4; + pos += pb_protocol_serialise_string(pos, config->http_proxy); pos += pb_protocol_serialise_string(pos, config->https_proxy); @@ -1141,6 +1146,10 @@ int pb_protocol_deserialise_config(struct config *config, config->network.dns_servers[i] = str; } + if (read_u32(&pos, &len, &tmp)) + goto out; + config->network.addr_type = tmp; + if (read_string(config, &pos, &len, &str)) goto out; config->http_proxy = str; diff --git a/lib/types/types.h b/lib/types/types.h index 9ab2a43..1bf518e 100644 --- a/lib/types/types.h +++ b/lib/types/types.h @@ -162,6 +162,10 @@ struct network_config { unsigned int n_interfaces; const char **dns_servers; unsigned int n_dns_servers; + enum { + ADDR_IPV4, + ADDR_IPV6, + } addr_type; }; struct autoboot_option { From patchwork Wed May 9 05:37:03 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: 910664 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 40glrZ3nBPz9s3q for ; Wed, 9 May 2018 15:53: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="SqNK9aXW"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OPIfWx3+"; 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 40glrZ1QBbzF27Q for ; Wed, 9 May 2018 15:53:02 +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="SqNK9aXW"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OPIfWx3+"; 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.27; helo=out3-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="SqNK9aXW"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="OPIfWx3+"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40glVZ2qCdzF27L for ; Wed, 9 May 2018 15:37:26 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 25A052299C; Wed, 9 May 2018 01:37:24 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 09 May 2018 01:37:24 -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= fm2; bh=O1LkIe9LR6C89ICsOVpmFB9/gpC4qeOl8MgMdMEdv9k=; b=SqNK9aXW TeFEVQHQfLFnzio1THKuwf56HQAiNIrX6t/rf4AIQfmwyAl0EH/0ZoTamA7JKGHm Gi7/I5CaiwAUvybi+0bRqsT1W6cC8VjjSrEYYcO7UqVzbIHP6EbtPgH1mPHlQkbZ etQbHFRYtGsc2E2XGv/5/GrjHFXyws5VxEX189x2UeNMbpBUt8P+EzhZdvpy1u63 WU56pwln5xu/HEJ6Zs5Gwxz830unIzxrzvZYaRqehCml9jaKCa23ahmlosFwdqEu 5X+EeDf3Jugrfju3c7zBn58uRXXYEcHft9PmTkqwNPNtkXjfeFvfdDueTQFTbEFx kSrLapcUKj+nGw== 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=O1LkIe9LR6C89ICsOVpmFB9/gpC4qeOl8MgMdMEdv9k=; b=OPIfWx3+ 6+1HdxQ/X3J5lOi+/xcGWrrtX1i3OhSjkgfXdLhuMjnCuCeDXVFpbHeIzI2hCgBo DyIvmLYG4cb90XSYpMAe/hcRg1PNqfdoswONEybqDB4Um6pF6SVq2U4xaWYk1Zn1 hu+j2hcLMZ+KuajcleY4S86YY4WvPx6rTF3UYjvVSxpIEWcrNfXgKQFEQEni55uz SdV+YSg9ZPjf/8hlu9r6koNBpIJUeuYyqW9e+o0OqcRZzcPxlHjkRitrxsOjnkwy XI8FcbhSuYjXDTfRMSNVmIc4k3ZBqmhsqv5bXFId0VIxFWnWZsPEWcM0/kVMFKV+ Vqzs3FCPKiTa1w== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id E177510253; Wed, 9 May 2018 01:37:22 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 5/7] discover/platform-powerpc: Add NVRAM parameter for IPv6 Date: Wed, 9 May 2018 15:37:03 +1000 Message-Id: <20180509053705.3143-6-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509053705.3143-1-sam@mendozajonas.com> References: <20180509053705.3143-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" Add a new NVRAM parameter to signal which address scheme should be used. This is kept separate from petitboot,network to maintain some backwards compatibility for IPv4 configurations. Signed-off-by: Samuel Mendoza-Jonas --- discover/platform-powerpc.c | 15 +++++++++++++++ discover/platform.c | 1 + 2 files changed, 16 insertions(+) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index df8c7d6..ba7c470 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -53,6 +53,7 @@ struct platform_powerpc { static const char *known_params[] = { "auto-boot?", "petitboot,network", + "petitboot,network_type", "petitboot,timeout", "petitboot,bootdevs", "petitboot,language", @@ -387,6 +388,16 @@ static void populate_network_config(struct platform_powerpc *platform, const char *cval; int i; + cval = get_param(platform, "petitboot,network_type"); + if (!cval || !strlen(cval) || strncmp(cval, "ipv4", strlen("ipv4")) == 0) + config->network.addr_type = ADDR_IPV4; + else if (strncmp(cval, "ipv6", strlen("ipv6")) == 0) + config->network.addr_type = ADDR_IPV6; + else { + pb_debug("malformed petitboot,network_type param"); + config->network.addr_type = ADDR_IPV4; + } + cval = get_param(platform, "petitboot,network"); if (!cval || !strlen(cval)) return; @@ -630,6 +641,10 @@ static void update_network_config(struct platform_powerpc *platform, config->network.interfaces[0]->override) return; + update_string_config(platform, "petitboot,network_type", + config->network.addr_type == ADDR_IPV6 ? + "ipv6" : "ipv4"); + val = talloc_strdup(platform, ""); for (i = 0; i < config->network.n_interfaces; i++) { diff --git a/discover/platform.c b/discover/platform.c index cc6306f..30a6ffd 100644 --- a/discover/platform.c +++ b/discover/platform.c @@ -126,6 +126,7 @@ void config_set_defaults(struct config *config) config->network.n_interfaces = 0; config->network.dns_servers = NULL; config->network.n_dns_servers = 0; + config->network.addr_type = ADDR_IPV4; config->http_proxy = NULL; config->https_proxy = NULL; config->safe_mode = false; From patchwork Wed May 9 05:37:04 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: 910665 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 40glrj4Cj4z9s1w for ; Wed, 9 May 2018 15:53:09 +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="MOk+tDd0"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="lZbDE1B8"; 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 40glrj2dH0zF2Lp for ; Wed, 9 May 2018 15:53:09 +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="MOk+tDd0"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="lZbDE1B8"; 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.27; helo=out3-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="MOk+tDd0"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="lZbDE1B8"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40glVb6rqqzF25f for ; Wed, 9 May 2018 15:37:27 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id B777F22B9C; Wed, 9 May 2018 01:37:25 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 09 May 2018 01:37:25 -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= fm2; bh=aSo+043w5dEBnWaxgZpMwyIHrc42cQy04C+fREHe7Eo=; b=MOk+tDd0 k/nfa67XExdiMZwD3oTxIDR90yswLsmx84mmuNS4Ei+NErjN2xE4Wt2g+l5hIE/W C4WONlcOceF9/0o67EueyxRfOLJnSJS/S8JsuLR1E3jvBK4ImHh/xjT+0ITdwaUI ZQTxurb5tzJZlwHON7kOUXM56n1uUIGA9p9pNPIBFFcc2wbrF/AZBt/RP6+T7bRt km8BwjBH4dzQtzyMwzcGE7SxKy1BVflkY7+Zs7EsK3MuGdMiOzLDne9AZtKu2jd0 CZYgWZ5XtT/o3CZUq+pwrYIN6O71f8j8oH5+YpzkUh0TQ05UC8VwzMuT6OU5epiQ CxI0Oj0Dqz4kXA== 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=aSo+043w5dEBnWaxgZpMwyIHrc42cQy04C+fREHe7Eo=; b=lZbDE1B8 r/xgaXjVBgQyhnvPavozXeHdI1jB0I5p7jX4W1BSD/QfMHq1Spw6859it/hjh3eB NTQq8mgEAfbi6rIu//Bb9+1PYYVFGUisrR6931AmXm+KK4OU8UA7NhvEj7N1s7Zo NxBUm/NNFHAmtgaMvVlk0pDZDY0bo25lNffyFbb1CkGZt9yBZyE0Pkq0kDBe4vMd WO6BVPMEgBUSHq/0zhl9aDxae1GoscFru9HVqoFnxj5MPENqdXPXsocUfpriy+06 cVvIz1zRXt2Z5dHFz0/2VNItGae0HLS5+ezdVVM9ED7bPJFgmetisH3mZ8N7Qj1E ReJFEShlYc281g== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 78E5610253; Wed, 9 May 2018 01:37:24 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 6/7] discover: Support IPv6 addresses Date: Wed, 9 May 2018 15:37:04 +1000 Message-Id: <20180509053705.3143-7-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509053705.3143-1-sam@mendozajonas.com> References: <20180509053705.3143-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 if configured to use IPv6 addresses. Signed-off-by: Samuel Mendoza-Jonas --- discover/device-handler.c | 51 ++++++++++++++++++++++++++------------- discover/network.c | 40 ++++++++++++++++++++++++------ discover/user-event.c | 8 ++++-- 3 files changed, 73 insertions(+), 26 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..c81c5e6 100644 --- a/discover/network.c +++ b/discover/network.c @@ -322,10 +322,11 @@ static void configure_interface_dhcp(struct network *network, struct interface *interface) { const struct platform *platform; + const struct config *config = config_get(); char pidfile[256], id[10]; struct process *process; int rc; - const char *argv[] = { + const char *argv_ipv4[] = { pb_system_apps.udhcpc, "-R", "-f", @@ -337,6 +338,20 @@ static void configure_interface_dhcp(struct network *network, 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", id, /* [15,16] - dhcp client identifier */ + NULL, + }; + device_handler_status_dev_info(network->handler, interface->dev, _("Configuring with DHCP")); @@ -344,15 +359,26 @@ 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); - else - argv[11] = NULL; + if (platform && platform->dhcp_arch_id != 0xffff) { + if (config->network.addr_type == ADDR_IPV6) + snprintf(id, sizeof(id), "0x3d:%04x", + platform->dhcp_arch_id); + else + snprintf(id, sizeof(id), "0x5d:%04x", + platform->dhcp_arch_id); + } else { + argv_ipv4[11] = argv_ipv6[15] = NULL; + } process = process_create(interface); - process->path = pb_system_apps.udhcpc; - process->argv = argv; + if (config->network.addr_type == ADDR_IPV6) { + process->path = pb_system_apps.udhcpc6; + process->argv = argv_ipv6; + } else { + process->path = pb_system_apps.udhcpc; + process->argv = argv_ipv4; + } process->exit_cb = udhcpc_process_exit; process->data = interface; 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 Wed May 9 05:37:05 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: 910666 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 40glrs0qChz9s1w for ; Wed, 9 May 2018 15:53:17 +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="QgT7WBlU"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="CDJihZ2b"; 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 40glrr6NNgzF2Mv for ; Wed, 9 May 2018 15:53:16 +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="QgT7WBlU"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="CDJihZ2b"; 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.27; helo=out3-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="QgT7WBlU"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="CDJihZ2b"; dkim-atps=neutral Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40glVd5ym8zF26C for ; Wed, 9 May 2018 15:37:29 +1000 (AEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 82A222262B; Wed, 9 May 2018 01:37:27 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 09 May 2018 01:37:27 -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= fm2; bh=HeSP5CpZjJlbhtriT/cr4XBowrpQjs9cV2QEE7DGY7Y=; b=QgT7WBlU hQHt3pUs1PzgUd9rxB+x+WSvWWJrYp9+hFvcWhYPFw02TDg+Knd7NKY9Cp6dkwoP 9PbnjNveZES87neQj9jhryYf0AYcZvrTKiDB910lmz8NKjOC3xfKVAxW+rqOWACF tV0MgmvssPsO/Xfu03LuKtslnSgtSOgq9Eb2WiDBm9qsuSfpwjG3F3WKRjCG/EC/ GrPs9cGeTPZvJle+47OT0AgxjlY+PkPV798VT3qwzr3mB7XmsWBw50QdouineEKx 5Qm8Llrjh5UXtR30xsutuJzAj+hVgOGmDOIHHH4MB1cGCcFaKGIKe7uMPF/mJnyK z7YufN/rP5l8xQ== 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=HeSP5CpZjJlbhtriT/cr4XBowrpQjs9cV2QEE7DGY7Y=; b=CDJihZ2b jzEB9m+jXaY1Oo5eJDZMJjCBMwb25lGZ3TcC64FCqpexoLc5hZMMRXpxKx4Gh4T0 7MWUu4IEFYgC3Ki14w9KLRFcIc8kQB5x7BM7a36AhHzw7vvJrPa525LGAMIthPEE YeEHTQZxhEIko1VsIAGUZtt1tNAxgPLzLTd4lAQiM0Cz2YyZdgiQ/M7AqdR8l4uh xBgs0oOzCPYYBrpBTLpMBPDbC+NxWwXVsPA0BSOGo54AyNsXKOeDsz7G5F1AAd9X RMqwBw5pOfN0Imzd1WQgzd7IpPfSn436hxmyfZgXTXYWewe49UjCAl9RBYioFIV3 WSUwhyR05A2Kpg== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 07FBC1025E; Wed, 9 May 2018 01:37:25 -0400 (EDT) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 7/7] ui/ncurses: Allow user to configure IPv6 addresses Date: Wed, 9 May 2018 15:37:05 +1000 Message-Id: <20180509053705.3143-8-sam@mendozajonas.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509053705.3143-1-sam@mendozajonas.com> References: <20180509053705.3143-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" Add an option to switch between IPv4 and IPv6 address schemes. For now only support IPv4 /or/ IPv6, not a combination. Signed-off-by: Samuel Mendoza-Jonas --- ui/ncurses/nc-config.c | 114 +++++++++++++++++++++++++++++++++++----- ui/ncurses/nc-widgets.c | 67 ++++++++++++++++++++++- ui/ncurses/nc-widgets.h | 4 ++ 3 files changed, 171 insertions(+), 14 deletions(-) diff --git a/ui/ncurses/nc-config.c b/ui/ncurses/nc-config.c index 5c0f23b..e2c9887 100644 --- a/ui/ncurses/nc-config.c +++ b/ui/ncurses/nc-config.c @@ -33,7 +33,7 @@ #include "nc-config.h" #include "nc-widgets.h" -#define N_FIELDS 48 +#define N_FIELDS 50 extern struct help_text config_help_text; @@ -89,6 +89,9 @@ struct config_screen { struct nc_widget_label *network_l; struct nc_widget_select *network_f; + struct nc_widget_label *net_addr_type_l; + struct nc_widget_select *net_addr_type_f; + struct nc_widget_label *iface_l; struct nc_widget_select *iface_f; struct nc_widget_label *ip_addr_l; @@ -258,6 +261,11 @@ static int screen_process_form(struct config_screen *screen) net_conf_type = widget_select_get_value(screen->widgets.network_f); + if (widget_select_get_value(screen->widgets.net_addr_type_f) == ADDR_IPV6) + config->network.addr_type = ADDR_IPV6; + else + config->network.addr_type = ADDR_IPV4; + /* if we don't have any network interfaces, prevent per-interface * configuration */ if (sysinfo->n_interfaces == 0) @@ -527,6 +535,11 @@ static void config_screen_layout_widgets(struct config_screen *screen) y += 1; + y += layout_pair(screen, y, screen->widgets.net_addr_type_l, + widget_select_base(screen->widgets.net_addr_type_f)); + + y += 1; + /* conditionally show iface select */ wl = widget_label_base(screen->widgets.iface_l); wf = widget_select_base(screen->widgets.iface_f); @@ -674,6 +687,46 @@ static void config_screen_layout_widgets(struct config_screen *screen) y, screen->field_x + 28); } +static void config_screen_net_addr_change(void *arg, int value) +{ + struct config_screen *screen = arg; + + widgetset_unpost(screen->widgetset); + + if (value == ADDR_IPV4) { + widget_textbox_set_validator_ipv4(screen->widgets.ip_addr_f); + widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, + 1, 31); + widget_update_label(screen->widgets.ip_addr_mask_help_l, + _("(eg. 192.168.0.10 / 24)")); + + widget_textbox_set_validator_ipv4(screen->widgets.gateway_f); + widget_update_label(screen->widgets.gateway_help_l, + _("(eg. 192.168.0.1)")); + + widget_textbox_set_validator_ipv4_multi(screen->widgets.dns_f); + widget_update_label(screen->widgets.dns_help_l, + _("(eg. 192.168.0.2)")); + } else { + widget_textbox_set_validator_ipv6(screen->widgets.ip_addr_f); + widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, + 1, 127); + widget_update_label(screen->widgets.ip_addr_mask_help_l, + _("(eg. fd69:d75f::27 / 64)")); + + widget_textbox_set_validator_ipv6(screen->widgets.gateway_f); + widget_update_label(screen->widgets.gateway_help_l, + _("(eg. fd69:d75f::1)")); + + widget_textbox_set_validator_ipv6_multi(screen->widgets.dns_f); + widget_update_label(screen->widgets.dns_help_l, + _("(eg. fd69:d75f::2)")); + } + + config_screen_layout_widgets(screen); + widgetset_post(screen->widgetset); +} + static void config_screen_network_change(void *arg, int value) { struct config_screen *screen = arg; @@ -979,6 +1032,21 @@ static void config_screen_setup_widgets(struct config_screen *screen, widget_select_on_change(screen->widgets.network_f, config_screen_network_change, screen); + screen->widgets.net_addr_type_l = widget_new_label(set, 0, 0, + _("IP Scheme:")); + screen->widgets.net_addr_type_f = widget_new_select(set, 0, 0, + COLS - screen->field_x - 1); + + widget_select_add_option(screen->widgets.net_addr_type_f, + ADDR_IPV4, _("IPv4"), + config->network.addr_type == ADDR_IPV4); + widget_select_add_option(screen->widgets.net_addr_type_f, + ADDR_IPV6, _("IPv6"), + config->network.addr_type == ADDR_IPV6); + + widget_select_on_change(screen->widgets.net_addr_type_f, + config_screen_net_addr_change, screen); + screen->widgets.iface_l = widget_new_label(set, 0, 0, _("Device:")); screen->widgets.iface_f = widget_new_select(set, 0, 0, 50); @@ -1024,21 +1092,36 @@ static void config_screen_setup_widgets(struct config_screen *screen, screen->widgets.ip_addr_f = widget_new_textbox(set, 0, 0, 16, ip); screen->widgets.ip_mask_l = widget_new_label(set, 0, 0, "/"); screen->widgets.ip_mask_f = widget_new_textbox(set, 0, 0, 3, mask); - screen->widgets.ip_addr_mask_help_l = - widget_new_label(set, 0, 0, _("(eg. 192.168.0.10 / 24)")); 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); + if (config->network.addr_type == ADDR_IPV4) { + screen->widgets.ip_addr_mask_help_l = + widget_new_label(set, 0, 0, _("(eg. 192.168.0.10 / 24)")); + widget_textbox_set_validator_ipv4(screen->widgets.ip_addr_f); + widget_textbox_set_validator_integer(screen->widgets.ip_mask_f, + 1, 31); + } else { + screen->widgets.ip_addr_mask_help_l = + widget_new_label(set, 0, 0, _("(eg. fd69:d75f::27 / 64)")); + widget_textbox_set_validator_ipv6(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); - screen->widgets.gateway_help_l = - 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); + if (config->network.addr_type == ADDR_IPV4) { + widget_textbox_set_validator_ipv4(screen->widgets.gateway_f); + screen->widgets.gateway_help_l = + widget_new_label(set, 0, 0, _("(eg. 192.168.0.1)")); + } else { + widget_textbox_set_validator_ipv6(screen->widgets.gateway_f); + screen->widgets.gateway_help_l = + widget_new_label(set, 0, 0, _("(eg. fd69:d75f::1)")); + } + screen->widgets.url_l = widget_new_label(set, 0, 0, _("URL:")); screen->widgets.url_f = widget_new_textbox(set, 0, 0, 32, url); @@ -1056,10 +1139,15 @@ static void config_screen_setup_widgets(struct config_screen *screen, screen->widgets.dns_l = widget_new_label(set, 0, 0, _("DNS Server(s):")); screen->widgets.dns_f = widget_new_textbox(set, 0, 0, 32, str); - 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); + if (config->network.addr_type == ADDR_IPV4) { + 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); + } else { + screen->widgets.dns_help_l = + widget_new_label(set, 0, 0, _("(eg. fd69:d75f::2)")); + widget_textbox_set_validator_ipv6_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..d17d79d 100644 --- a/ui/ncurses/nc-widgets.c +++ b/ui/ncurses/nc-widgets.c @@ -44,8 +44,9 @@ # error "Curses form.h not found." #endif -#include +#include #include +#include #include #include @@ -84,6 +85,8 @@ struct nc_widgetset { /* custom validators */ FIELDTYPE *ipv4_multi_type; + FIELDTYPE *ipv6_multi_type; + FIELDTYPE *ipv6_type; FIELDTYPE *url_type; }; @@ -196,6 +199,10 @@ static int label_destructor(void *ptr) return 0; } +void widget_update_label(struct nc_widget_label *label, char *str) +{ + set_field_buffer(label->widget.field, 0, str); +} struct nc_widget_label *widget_new_label(struct nc_widgetset *set, int y, int x, char *str) @@ -415,11 +422,59 @@ void widget_textbox_set_validator_url(struct nc_widget_textbox *textbox) set_field_type(textbox->widget.field, textbox->set->url_type); } +static bool check_ipv6_field(FIELD *field, + const void *arg __attribute__((unused))) +{ + uint8_t addr[sizeof(struct in6_addr)]; + int rc; + + rc = inet_pton(AF_INET6, strip_string(field_buffer(field, 0)), addr); + + return rc == 1; +} + +void widget_textbox_set_validator_ipv6(struct nc_widget_textbox *textbox) +{ + if (!textbox->set->ipv6_type) { + textbox->set->ipv6_type = new_fieldtype(check_ipv6_field, NULL); + } + set_field_type(textbox->widget.field, textbox->set->ipv6_type); +} + void widget_textbox_set_validator_ipv4(struct nc_widget_textbox *textbox) { set_field_type(textbox->widget.field, TYPE_IPV4); } +static bool check_ipv6_multi_char(int c, + const void *arg __attribute__((unused))) +{ + return isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || + c == ':' || c == ' '; +} + +static bool check_ipv6_multi_field(FIELD *field, + const void *arg __attribute__((unused))) +{ + char *tok, *saveptr, *str; + uint8_t addr[INET6_ADDRSTRLEN]; + int rc; + + str = field_buffer(field, 0); + tok = strtok_r(str, " ", &saveptr); + if (!tok || *tok == '\0') + return false; + + while (tok) { + rc = inet_pton(AF_INET6, tok, addr); + if (rc != 1) + return false; + tok = strtok_r(NULL, " ", &saveptr); + } + + return true; +} + static bool check_ipv4_multi_char(int c, const void *arg __attribute__((unused))) { @@ -455,6 +510,16 @@ static bool check_ipv4_multi_field(FIELD *field, return true; } +void widget_textbox_set_validator_ipv6_multi(struct nc_widget_textbox *textbox) +{ + if (!textbox->set->ipv6_multi_type) { + textbox->set->ipv6_multi_type = new_fieldtype( + check_ipv6_multi_field, + check_ipv6_multi_char); + } + set_field_type(textbox->widget.field, textbox->set->ipv6_multi_type); +} + void widget_textbox_set_validator_ipv4_multi(struct nc_widget_textbox *textbox) { if (!textbox->set->ipv4_multi_type) { diff --git a/ui/ncurses/nc-widgets.h b/ui/ncurses/nc-widgets.h index aa9263f..217215a 100644 --- a/ui/ncurses/nc-widgets.h +++ b/ui/ncurses/nc-widgets.h @@ -37,11 +37,15 @@ struct nc_widget_button *widget_new_button(struct nc_widgetset *set, int y, int x, int size, const char *str, void (*click)(void *), void *arg); +void widget_update_label(struct nc_widget_label *label, char *str); + 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_ipv6(struct nc_widget_textbox *textbox); +void widget_textbox_set_validator_ipv6_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);