From patchwork Fri Sep 8 13:53:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 720820 Delivered-To: patch@linaro.org Received: by 2002:adf:eec5:0:b0:31d:da82:a3b4 with SMTP id a5csp779136wrp; Fri, 8 Sep 2023 06:56:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExveQ2Gd8iOHmRG+jOYYE8oekSIG71IReOiiMnXmukyRfViC6IcxcuTneACmjOCkqUO/dy X-Received: by 2002:a5d:54c8:0:b0:317:5af3:caa4 with SMTP id x8-20020a5d54c8000000b003175af3caa4mr1836264wrv.38.1694181406812; Fri, 08 Sep 2023 06:56:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694181406; cv=none; d=google.com; s=arc-20160816; b=POyMPCHyV2UEG8AabWmy4pdZ/gRxNoB48jgnpif5GKJKszDfN/eEKzUtXHUhNw0hzC zeizazSRNcTQJ9GSqI9x1e2byjfQbcO2pC5KjCynH0IUrTvstX0hC3Qva1J2I9i9GJn8 0zjMhACiyq3Q+mog6yfTItlsLVm+ySmsaV7LvZx89kr/ZbKXErwRT/nQqWUwq8EwWpnx oXwwwPRWSgOh0G8BqbmcXlN+kV6u1jOnrLXSj/QJnTJ4FyuZxLPvkdII6uEjq8n2Qc3L juB1miWGA2/XhytmI/aJiQO9YUovrXWpLTvF5YcpkDV5vJMi2LFyX2ps9KFUgFe4I803 kq4A== 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=WSz/BUYMS3B2bmhO/W/vyl5g01v4ioz1ndySXjtZ3T8=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=xBtZHTP3+E/9Eu8HHnCscYPpM8DIL959w+edCscX0acg7+NTbq5L9dXRPNENDUe0M2 pvmSu14oPWBFRab8nOZM8BSbsCiGdxzuVGVMtk6dMm+xak2pZMvhkLEuaZ+0MAWSbBYU 7pItyLHxFZQlivrdFar+NJ4GH04/hH8OtyQ+pVjPpT7NjT6XYteHplVdZa4JbJobuCIA 7CERaPNC56VWs8JL3zdDTAxIAQOTHbyIUUA0lbJf2E13cwfUt6pyI2SIZy7FgoTpEkIT rousVj8uAzgzeucQcfeWj5wtU1Mp4fpMdhp+tvyBSfGl9OQVTeXTul6Mrk2DP0mPCfug G5Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KDL83fZP; 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 x1-20020adfdcc1000000b0031c680a7497si809099wrm.766.2023.09.08.06.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:56:46 -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=KDL83fZP; 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 2BB4B86A50; Fri, 8 Sep 2023 15:55:53 +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="KDL83fZP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EE66386A50; Fri, 8 Sep 2023 15:55:51 +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-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) (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 0841586A97 for ; Fri, 8 Sep 2023 15:55:49 +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-x230.google.com with SMTP id 38308e7fff4ca-2bd0d19a304so36993781fa.1 for ; Fri, 08 Sep 2023 06:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694181348; x=1694786148; 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=WSz/BUYMS3B2bmhO/W/vyl5g01v4ioz1ndySXjtZ3T8=; b=KDL83fZP/ZfQ8i6JiqavteDEpx90ob4IhFfwhVwsE492gtoz3Jg6qwfi+rrq7qC28D QzU5+FUlu+CtswzGkPodyv6GLFRG/MW3xrxLkvU9rmD0++9iiFvG5JSCX0XzcyAtx+nQ vsbHDjeQbLyQj4C+TJTYhW01cYwHLWXISo1QTaWnKZdVTzJR2FN9BmZy9QSjVfIpq2aJ 8e1vjNYX1naFxWy6DpLoPe7/1vlCZIOLnNn2Zi2hgy39LlUeziX4SNQtn9xALuChPjRL saWhCCXHxhQQOPAYLG87+ijXu5xzr5OZ1mmU0y9jZam18baCoSB40SRPsQq2M4KM2kcC Z3sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694181348; x=1694786148; 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=WSz/BUYMS3B2bmhO/W/vyl5g01v4ioz1ndySXjtZ3T8=; b=kQu3Oe4enS3h0ERgle551mHgDRMUl2ZJz/I9pS/a0ceRXFKTyteRCGvk/TyRyfoMOf 9luyIKSMIH9Nytas3YZ6xFiSPGFR+fUM/rWnNa+sNjKfnGCXxJog66EC4NKj1l1sPJKt GlbyWLrSXWHqn/n8iPrDOOETV+K30CIgwkxH6Gj0fm3bEkz5hc88O5i+qE++GhAcmkK/ PfxxPQtxjC5/0SSirl78dSXxNYi2b09UVDhVU6djrUiq9gQGGyvVGV55sRrdCErP1Ei9 b5qddydXHn5aViG7OktwvW/+DJginOB2Ox3V+xT7acJNAE5uVXpljhB7tVVQsOU/lqR2 WWIg== X-Gm-Message-State: AOJu0Yyoap6EtiAkBdKJwTEjIO9j0/lkG9Lfl+XJcbPrmXS1XaapSHdb 9RzPiN4kgJMAgq08zu+Ce/PYdVPjiOkRpfbVlsSC7g== X-Received: by 2002:a2e:9ad8:0:b0:2bd:16e6:e34a with SMTP id p24-20020a2e9ad8000000b002bd16e6e34amr1903702ljj.19.1694181347962; Fri, 08 Sep 2023 06:55:47 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id u14-20020a2e9f0e000000b002bcbae4c21fsm306907ljk.50.2023.09.08.06.55.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Sep 2023 06:55:47 -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: [PATCHv8 07/15] net/lwip: implement ping cmd Date: Fri, 8 Sep 2023 19:53:12 +0600 Message-Id: <20230908135320.7066-8-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230908135320.7066-1-maxim.uvarov@linaro.org> References: <20230908135320.7066-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 | 40 ++++++++++++++++++++++++++++++++++ net/lwip/apps/ping/lwip_ping.h | 15 +++++++++++++ net/lwip/apps/ping/ping.h | 19 ++++++++++++++++ 6 files changed, 102 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..231ea6473a --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.c @@ -0,0 +1,40 @@ +// 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) +{ + char *ping_addr = (char *)arg; + + log_err("ping failed; host %s is not alive\n", ping_addr); + 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);