From patchwork Thu Apr 19 13:11:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 901079 X-Patchwork-Delegate: akodanev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40RfXC0zjfz9s2t for ; Thu, 19 Apr 2018 23:11:53 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1FDD83E74C2 for ; Thu, 19 Apr 2018 15:11:51 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 8F4C23E6C12 for ; Thu, 19 Apr 2018 15:11:49 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id B873D6013C2 for ; Thu, 19 Apr 2018 15:11:45 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F3CDEAE03; Thu, 19 Apr 2018 13:11:44 +0000 (UTC) From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 19 Apr 2018 15:11:34 +0200 Message-Id: <20180419131135.23693-1-pvorel@suse.cz> X-Mailer: git-send-email 2.16.3 X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/2] network/in6_02: Don't use default value for LHOST_IFACES X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" In case of LHOST_IFACES not being defined was 'eth0' used as default. Although eth0 is common iface, we cannot guarantee it, therefore skip testing it. Also check sscanf return value to catch whitespace only. Signed-off-by: Petr Vorel --- Changes v1->v2: * Add check before rewriting into new API. * Check sscanf return value to catch whitespace only. NOTE: with LHOST_IFACES="lo" (or other from n2i) it's tested twice, but I ignore it. --- Not sure if I need to put all longer strings in tst_res on new line. --- testcases/network/lib6/in6_02.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/testcases/network/lib6/in6_02.c b/testcases/network/lib6/in6_02.c index 7cb362666..e1a71d987 100644 --- a/testcases/network/lib6/in6_02.c +++ b/testcases/network/lib6/in6_02.c @@ -34,7 +34,7 @@ static struct { int nonzero; } n2i[] = { { "lo", 1 }, - { "eth0", 1 }, + { NULL, 1 }, { "hoser75", 0 }, { "6", 0 }, }; @@ -80,6 +80,11 @@ void n2itest(void) char ifname[IF_NAMESIZE], *pifn; for (i = 0; i < N2I_COUNT; ++i) { + if (n2i[i].name == NULL) { + tst_resm(TCONF, "LHOST_IFACES not defined or invalid, skip testing it"); + return; + } + TEST(if_nametoindex(n2i[i].name)); if (!TEST_RETURN != !n2i[i].nonzero) { tst_resm(TFAIL, "if_nametoindex(\"%s\") %ld " @@ -256,22 +261,17 @@ void setup(void) { TEST_PAUSE; - tst_resm(TINFO, "get interface name from LHOST_IFACES var"); - char *ifnames = getenv("LHOST_IFACES"); - - if (!ifnames) { - tst_resm(TWARN, "LHOST_IFACES not defined, default to eth0"); + if (!ifnames) return; - } static char name[256]; + int ret; - sscanf(ifnames, "%255s", name); - - if (!strcmp(name, n2i[1].name)) + ret = sscanf(ifnames, "%255s", name); + if (ret == -1) return; - tst_resm(TINFO, "change default 'eth0' name to '%s'", name); + tst_resm(TINFO, "get interface name from LHOST_IFACES: '%s'", name); n2i[1].name = name; }