From patchwork Thu Sep 14 16:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 722565 Delivered-To: patch@linaro.org Received: by 2002:adf:f0d1:0:b0:31d:da82:a3b4 with SMTP id x17csp486022wro; Thu, 14 Sep 2023 09:22:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6A06C3DDyhhSd0I2leIZfhfKDYsjbW0rkDGrtyo7PuhM8+r64HlyRoVtzBLYhXTe0rRRN X-Received: by 2002:adf:e886:0:b0:31f:b138:5a0 with SMTP id d6-20020adfe886000000b0031fb13805a0mr4873986wrm.48.1694708536270; Thu, 14 Sep 2023 09:22:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694708536; cv=none; d=google.com; s=arc-20160816; b=e4kmrn1mNX+b1kD/2kFjjRpm1Yggd9KnaO449D89EApY78wBb9+NW7PCFKhN4HuVLw ueYirWEtVbwM45lirsOPuof2YJaog9uNaDKcZsbXrUbT6hlAO0EJmEmhB9WNaIdQoNzC BjUm8Z6W1hmK5r/eeWfZbg1OcALa2dXzaM13xWf1wl5HbH9+iQOJdR7jRI8ydn/FvNJd sUxgJiBvYhpLnMB6IQ545UYk5K6f5nDhEppbB5A5vaN3zb3TB/hFmwsFyTtzw8wlszmr UOapThWrm1ZojWf6HAgV/H/BhhR2LyZ/L0Y9hPxlHIfuxwbu1LMoqYIdektZZFiD2HWO obsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ej/bqt+mfyHFFKJj2NMu41mYOCWSZiMsqtww6RhsVjY=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=zV+F9XfACqQbEtdiR+syJ3eN6z3K0YLJHl+46tq13zj8GJLzzxrZZQXIA4MmXT9dtl PXkEMLxtHWYko1RiKrMfQfdDai9Us0VUWAmnC3JO+dcHNr2IqL1bCxo1Dxo4QW7OG5Hv 6D0XIfzrkrd+qfrm5R4iQ8oO/nPCDrGsYVo34EdkqairnSt5+X6zgnNErgb8LHnWB6wY l1n4HGZcXfyuoFVRUih5/+XR5ldoGpupCjM87JjIV2VGxUylmPw8waIETUQ7DFi5h11y eOaE05jD6wYI2JrGY/UWJVc3WW40OL73b6XOXHWjQsWO62vJUl+CN+WRNDFOSWutGofX fFZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L1dFDGKq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id z4-20020adff744000000b003175debc21fsi806102wrp.723.2023.09.14.09.22.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:22:16 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=L1dFDGKq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 0CC3286AE9; Thu, 14 Sep 2023 18:20:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="L1dFDGKq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F414886E6B; Thu, 14 Sep 2023 18:20:56 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id EC75086D45 for ; Thu, 14 Sep 2023 18:20:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2bfbd7d49e7so18458251fa.1 for ; Thu, 14 Sep 2023 09:20:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694708454; x=1695313254; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ej/bqt+mfyHFFKJj2NMu41mYOCWSZiMsqtww6RhsVjY=; b=L1dFDGKqXvvQs2ObFtoJaLAjRY/ezg9h1vwo5JXYF/z05JL8MOtZ4J5p7UYiLZQvPl fhkULb9+iWFnOI/JITgtXgPBX7seW1Yw19OXMYIM/1I1XIHG+UQUdxDZMSbb1d8GNWnV zm7O74PhRdRjV/8KVx/4FJ3m1t7pKgq8Gw7YzbITBnWy7GlRAFLbHI+FqwGGZmXJdNO+ mamtc1Q6vlstLJ0fLOMnwGX3bqCCOZScWUbMUHZGx3SbRiIyQI6uwgWn3w+08ZMLkPZK 5tvf9AOxHSa6SsjFa0qJyOqdL2ja9WC9LhNczik5pd4MRuUl8cKL2gNc2uXUkZ0x4hHm CIGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694708454; x=1695313254; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ej/bqt+mfyHFFKJj2NMu41mYOCWSZiMsqtww6RhsVjY=; b=ufjkT/seEzT9V5rDk7h1m3yaIu1vD3uIl/rgz+/FTf2xoJ9IY0hSdtd4dKl7kbmMHo m9DI0swoRMyfEgoZC/YGKY8YGkGm2/9Zlb7jGYt962h+rJO5O4Keo8Up81wsct08Xe9s 2jETOETTpoxJtBPw/vmNgq2MPRFSGxxaMP3pzm8EZ1Mnxg/SuQiQ+8ed539d+UQ7TAev ZXjnYoiYtkAfEsOBBGRyorFI8CEFj52OztTGfOuPQpkT+BdY4eeGOtLMJEfTF2f8MlWA m/8FtWovi8dN0yBrybwD4VRAGDgPpLuouW2LJL1SqqHHAkiJM1lUESpOoEOp4pzuNWgt ia3A== X-Gm-Message-State: AOJu0Ywe725GY9FK8h9lcdXkeV+2YCeeutKt6GpOScQoQ31Oagi5yKIB xY84engcOjc+HvOc0P2X5sxGE87MtO3S6fske36/ow== X-Received: by 2002:a2e:9f4e:0:b0:2b9:e831:f16a with SMTP id v14-20020a2e9f4e000000b002b9e831f16amr6140183ljk.26.1694708454104; Thu, 14 Sep 2023 09:20:54 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id z15-20020a2e8e8f000000b002ba7ae1f52asm346919ljk.0.2023.09.14.09.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:20:53 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv9 08/15] net/lwip: implement ping cmd Date: Thu, 14 Sep 2023 22:18:21 +0600 Message-Id: <20230914161828.3662-9-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230914161828.3662-1-maxim.uvarov@linaro.org> References: <20230914161828.3662-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean U-Boot recently got support for an alternative network stack using LWIP. Replace ping command with the LWIP variant while keeping the output and error messages identical. ping uses lwIP contrib/apps/ping/ping.c code. Custom timeout is used to get an error message on not modified example. lwIP timeouts are not yet implemented in U-Boot (#define LWIP_TIMERS 1) so that for now ping can not rechange itself for continuous pings and stops after the first request (the same behavior as the original ping.) Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 15 ++++++++++++++ net/lwip/Makefile | 1 + net/lwip/apps/ping/Makefile | 12 +++++++++++ net/lwip/apps/ping/lwip_ping.c | 38 ++++++++++++++++++++++++++++++++++ net/lwip/apps/ping/lwip_ping.h | 15 ++++++++++++++ net/lwip/apps/ping/ping.h | 19 +++++++++++++++++ 6 files changed, 100 insertions(+) create mode 100644 net/lwip/apps/ping/Makefile create mode 100644 net/lwip/apps/ping/lwip_ping.c create mode 100644 net/lwip/apps/ping/lwip_ping.h create mode 100644 net/lwip/apps/ping/ping.h diff --git a/include/net/lwip.h b/include/net/lwip.h index 85f08343fd..1e92f9871c 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -2,6 +2,8 @@ int do_lwip_dns(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_lwip_ping(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]); /** * ulwip_dns() - creates the DNS request to resolve a domain host name @@ -56,3 +58,16 @@ int ulwip_tftp(ulong addr, const char *filename); * Returns: 0 for success, !0 if error */ int ulwip_wget(ulong addr, char *url); + +/** + * ulwip_ping - create the ping request + * + * This function creates the ping for address provided in parameters. + * After this function you need to invoke the polling + * loop to process network communication. + * + * + * @ping_addr: IP address to ping + * Returns: 0 for success, !0 if error +*/ +int ulwip_ping(char *ping_addr); diff --git a/net/lwip/Makefile b/net/lwip/Makefile index 61042862e1..5839d125c2 100644 --- a/net/lwip/Makefile +++ b/net/lwip/Makefile @@ -67,3 +67,4 @@ obj-y += apps/dhcp/lwip-dhcp.o obj-y += apps/dns/lwip-dns.o obj-y += apps/tftp/ obj-y += apps/http/ +obj-y += apps/ping/ diff --git a/net/lwip/apps/ping/Makefile b/net/lwip/apps/ping/Makefile new file mode 100644 index 0000000000..e567c0dc3e --- /dev/null +++ b/net/lwip/apps/ping/Makefile @@ -0,0 +1,12 @@ +ccflags-y += -I$(srctree)/net/lwip/port/include +ccflags-y += -I$(srctree)/net/lwip/lwip-external/src/include -I$(srctree)/net/lwip +ccflags-y += -I$(obj) + +# ping.c includes "ping.h", copy it to local directory, to override ping.h +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/net/lwip/lwip-external/contrib/apps/ping/ping.c $(obj)/ping.c + +obj-y += ping.o +obj-y += lwip_ping.o diff --git a/net/lwip/apps/ping/lwip_ping.c b/net/lwip/apps/ping/lwip_ping.c new file mode 100644 index 0000000000..8e74b0a05b --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "lwip/timeouts.h" +#include +#include "ping.h" +#include "lwip_ping.h" + +#define PING_WAIT_MS 1000 + +static ip_addr_t ip_target; + +static void ping_tmo(void *arg) +{ + log_err("ping failed; host %s is not alive\n", (char *)arg); + ulwip_exit(1); +} + +int ulwip_ping(char *ping_addr) +{ + int err; + + err = ipaddr_aton(ping_addr, &ip_target); + if (!err) + return -ENOENT; + + sys_timeout(PING_WAIT_MS, ping_tmo, ping_addr); + + ping_init(&ip_target); + ping_send_now(); + + return 0; +} diff --git a/net/lwip/apps/ping/lwip_ping.h b/net/lwip/apps/ping/lwip_ping.h new file mode 100644 index 0000000000..0374f07d9e --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include + +void ping_raw_init(void); +void ping_send_now(void); + +#endif /* LWIP_PING_H */ diff --git a/net/lwip/apps/ping/ping.h b/net/lwip/apps/ping/ping.h new file mode 100644 index 0000000000..006a18c658 --- /dev/null +++ b/net/lwip/apps/ping/ping.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include "lwip/ip_addr.h" + +#define LWIP_DEBUG 1 /* ping_time is under ifdef*/ +#define PING_RESULT(cond) { \ + if (cond == 1) { \ + printf("host %s a alive\n", ipaddr_ntoa(addr)); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \ + ulwip_exit(-1); \ + } \ + } while (0); + +void ping_init(const ip_addr_t *ping_addr);