From patchwork Mon Feb 26 05:27:27 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: 877684 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 3zqVjG2Gldz9s2B for ; Mon, 26 Feb 2018 16:28:18 +1100 (AEDT) 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="QQgHMXiR"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="gibOMiyk"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3zqVjF6vsPzF1Tc for ; Mon, 26 Feb 2018 16:28:17 +1100 (AEDT) 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="QQgHMXiR"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="gibOMiyk"; 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.25; helo=out1-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="QQgHMXiR"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="gibOMiyk"; dkim-atps=neutral Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3zqVhm6q2SzF1Sp for ; Mon, 26 Feb 2018 16:27:51 +1100 (AEDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 5975F20A4B; Mon, 26 Feb 2018 00:27:46 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute2.internal (MEProxy); Mon, 26 Feb 2018 00:27:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= mendozajonas.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=zMNhq3wjrDX9oNJbV XCZ00wD9kQ/2HpKURco9ikH2xM=; b=QQgHMXiRu5w1hwu3CLLkw20bkURlwv5nC yhkRrWD4IyGiN5VmGU/LclxmzQ+xpAJD853isKwSBv/Audr2Q8bHAX7+r1O47rm8 Yz5gmPqhCPTmPKLJ5UqN5bhIpz6kwgE2KQFr2oBtK+nNcWsKebC6ubdn+EdQrZ/f 7oxv7KjjFrY/55qNp3HeJnZcNkdak14r8UOG5wqtTzgMOdP8ll94zvYrhCUngghO 0leDMvzkM8FVIIZ9yF9Sx7+imAcUcn1f1DYMk0dxzlLsudvA4R96F9qtqPXq2dOu v5KRLb3mcNUP8/ubse8FQo4sXwcM4ujsMYFF5Lzcz+3mxdJ6dB7uQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:message-id:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=zMNhq3wjrDX9oNJbV XCZ00wD9kQ/2HpKURco9ikH2xM=; b=gibOMiykUAh5TdR5Jn/PQs1G+HRial33f zX6jyQ955E7OhxAAgn38KsQJ9+gg+k3faC2CEDAt2XGlhH5bg/sN1/Ofl5snhBgz EEncYi6A37uCXhc7zGKEDLzoXsPjx1QPUwmQbcOEiUXPV4uKLLikXvrbYBO7koS7 HHxu3oW4HptnBXBpIgxtXb3+4NjjUP9TgRMZSbPgTzNXBRxjutjl2Gmpka4YTZ67 XJ+Y7r4x2neSrETZeFKcy3iXJwiabgWXov5MinxSA1xlBUKCCkvCeLrev2Q3gsK1 i6SmMIz5jPO6gpoOXg3WJAh7podsfurl3mEFN7DpKbOj/2V62OedA== X-ME-Sender: Received: from v4.ozlabs.ibm.com (unknown [122.99.82.10]) by mail.messagingengine.com (Postfix) with ESMTPA id 341157E1F4; Mon, 26 Feb 2018 00:27:44 -0500 (EST) From: Samuel Mendoza-Jonas To: petitboot@lists.ozlabs.org Subject: [PATCH 1/2] discover/platform-powerpc: Avoid confusing gateway and URL Date: Mon, 26 Feb 2018 16:27:27 +1100 Message-Id: <20180226052728.12631-1-sam@mendozajonas.com> X-Mailer: git-send-email 2.16.2 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" If we have a static network config with a URL set but not a gateway we can confuse the URL as the gateway due to how we write the network string in NVRAM. To avoid changing the parameter format if we only have one of the two tokens check whether or not it's actually a URL; the gateway and the URL will have distinct formats. Signed-off-by: Samuel Mendoza-Jonas --- discover/platform-powerpc.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/discover/platform-powerpc.c b/discover/platform-powerpc.c index ed5733e..dc4abb8 100644 --- a/discover/platform-powerpc.c +++ b/discover/platform-powerpc.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "hostboot.h" #include "platform.h" @@ -287,7 +288,7 @@ static int parse_one_interface_config(struct config *config, char *confstr) { struct interface_config *ifconf; - char *tok, *saveptr; + char *tok, *tok_gw, *tok_url, *saveptr; ifconf = talloc_zero(config, struct interface_config); @@ -320,18 +321,26 @@ static int parse_one_interface_config(struct config *config, ifconf->static_config.address = talloc_strdup(ifconf, tok); - tok = strtok_r(NULL, ",", &saveptr); - if (tok) { - ifconf->static_config.gateway = - talloc_strdup(ifconf, tok); + /* + * If a url is set but not a gateway, we can accidentally + * interpret the url as the gateway. To avoid changing the + * parameter format check if the "gateway" is actually a + * pb-url if it's the last token. + */ + tok_gw = strtok_r(NULL, ",", &saveptr); + tok_url = strtok_r(NULL, ",", &saveptr); + + if (tok_gw) { + if (tok_url || !is_url(tok_gw)) + ifconf->static_config.gateway = + talloc_strdup(ifconf, tok_gw); + else + tok_url = tok_gw; } - tok = strtok_r(NULL, ",", &saveptr); - if (tok) { + if (tok_url) ifconf->static_config.url = - talloc_strdup(ifconf, tok); - } - + talloc_strdup(ifconf, tok_url); } else { pb_log("Unknown network configuration method %s\n", tok); goto out_err;