From patchwork Tue Sep 26 09:41:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 726410 Delivered-To: patch@linaro.org Received: by 2002:adf:ea87:0:b0:31d:da82:a3b4 with SMTP id s7csp2834474wrm; Tue, 26 Sep 2023 02:45:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdlaLWeuRnqtqI2HVJgPqOxSXr29tnWCflL/GExPTiX0zT2SKwtnqELaS7ZUP4I4bJDhZ7 X-Received: by 2002:a5d:634c:0:b0:320:a4e:6b83 with SMTP id b12-20020a5d634c000000b003200a4e6b83mr8091439wrw.31.1695721513969; Tue, 26 Sep 2023 02:45:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695721513; cv=none; d=google.com; s=arc-20160816; b=ZPJ3xvQ1xdBiNvcQbN48mTY0dKsaAO/br/znYZW4apR+C/imA54FpIIMNTQdKknRQT khzzFOseQu6xpde2U9jwtAJYRLmbFWFQ1rt64yoP8Od9h4PDzCzeLZ6Wh+MyIAL8M3po AW6OEhbwy3O6vehqxQ6vx++o4KlYPTNlWPi7wJpRMSF6E77IpwxSTHnFaUitQsLDrW1p h2nrUZA5aklGmSDeXkkqgek/dZ+NiwZMmfAdIrzN8yHBmJhCCWhSRYFy9ajJ9+FUgP/0 BUaO0g8J5Bued3gNDcwbOLSaRPEJAMZIuAL+K/CTuK/SuamqDONPfnI7sVOloHNu+dkN vIDw== 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=pH9eugOd8aFs3gNXR1JStyjAyyg8COenbqgCMOQgxEo=; fh=hYoOR0yg+Fo7S26X8ur5L+RaTmkyxWlAVaBypEC8A0g=; b=X/p1C2NaFMTV7OyLGPvipgXNgsrl15Ja8Y3jSGrLF0erRQJ4aWsFD8B3R5SB+Bgtjp KBQ+VYp0G1b8qbBTivGuBIQGkXQq3DuU1s7FklRaw6NvQlN3+zPFmSpxN6WYyhcF3Yx5 HWegzn/nUvkyw73Q/2I/1PrkrKadloQy7n2qlqanbEJMWl+qTwl151aEKbiJ/RUuLyWh 6XQqosjZYUJqkogMlkpUS+xHzJ0ulwgivPKV7x4ZGil13ScQZ8uQWZUL70EIEQsaiZnk IOIpi6wRIWRsXVfA/2QzCUO5syyJnmHgElxbEPrmeFrdztePMwl5Ypj89L7NUTd/B5eE e1Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tGoFxcYJ; 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 o18-20020a5d6852000000b0032006b01b8bsi5763932wrw.619.2023.09.26.02.45.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 02:45:13 -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=tGoFxcYJ; 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 08C0A86DDF; Tue, 26 Sep 2023 11:44:06 +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="tGoFxcYJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C4A5B86DD6; Tue, 26 Sep 2023 11:44:04 +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-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) (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 6DB2D86AF7 for ; Tue, 26 Sep 2023 11:44:02 +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-x229.google.com with SMTP id 38308e7fff4ca-2c15463ddd4so76407751fa.3 for ; Tue, 26 Sep 2023 02:44:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1695721441; x=1696326241; 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=pH9eugOd8aFs3gNXR1JStyjAyyg8COenbqgCMOQgxEo=; b=tGoFxcYJsfMH3ZGBsYqsh0d0TjpBD8fE359eoDOY7ueFFo/iqLb/SOU5XKmnQmRIlC D7duHa/bWA+kYZ5akVPA7NL00JwIA0CuVexqPSwUxyXkHHQ8EYz9Y/SOVPyeSb+w3axZ 4tV6J7ZQnwMZ98pZEJB7fV6tVxyHiqqMEqnSrLvwyPqPNmgmGPGHCAkiV9OYAAtoWpbq E+ug+MYUbu+naAbwrAdmUmLYGUrRwyu6fyE+/NDCfVXpAtzfZKTOPsDCzLU8xWi48Vpe q5s7WiWEpXBd7dnoezF4IqxiLYtjTPrxZzfT7JSDvquuUIo2fOJH/gDfqVG3EFcJjVAK 2COA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695721441; x=1696326241; 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=pH9eugOd8aFs3gNXR1JStyjAyyg8COenbqgCMOQgxEo=; b=MQybvS3BRY4uwtLZ+TauWYP/mmfD5Lj+Nd73H/Q81pTY4RWOvtuBgjUq0X28m6at22 IrnLu7NmzV07nSL+ny3KFbWRLxXwZ14qaKPASMBpt6QsFvu8pXaITE6H0nOasrhab5nt IyDZU3pmwtHAlnqjVmK/wr50Ci3RzZjjf60eh/OdnzF7lmAxhGHkDRD8adU6mxq7hUSU KHntuTiNoQkV4yM9vkcA/Xb14qb2SYjy7jkWD7uBEtSNkpGmejFXnFVMutGNciYMQ4is fGDoOMaUzZtB94oJa8luHx03JlBTmc5jKxfgP+jK+3kEYt8BmEO9HFyeKvCG0Llbt1bc 03Mg== X-Gm-Message-State: AOJu0YzbkPleAx3ISDQcWmZ/fuJCSY98KKy7RGh5PqwyzA8LstV5F2rh 7zWT87Pp2v+hsAXo5FXVD7QoCfp5cK6YnanOL3Bu8w== X-Received: by 2002:a05:6512:3ca2:b0:503:985:92c9 with SMTP id h34-20020a0565123ca200b00503098592c9mr9644492lfv.22.1695721441541; Tue, 26 Sep 2023 02:44:01 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id x6-20020ac25dc6000000b004fe09e6d1e7sm2131131lfq.110.2023.09.26.02.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 02:44:01 -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: [PATCHv10 09/15] net/lwip: implement ping cmd Date: Tue, 26 Sep 2023 15:41:18 +0600 Message-Id: <20230926094124.7024-10-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230926094124.7024-1-maxim.uvarov@linaro.org> References: <20230926094124.7024-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. There is pending lwip patch: https://lists.nongnu.org/archive/html/lwip-devel/2023-09/msg00004.html https://savannah.nongnu.org/bugs/?64697 Once applied, more clean way can be used, to unset pending timers and exit from the ping application: net/lwip/apps/ping/ping.h: #define PING_RESULT(cond) { \ .. - raw_remove(pcb); \ + ping_destroy(); \ 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 | 39 ++++++++++++++++++++++++++++++++++ net/lwip/apps/ping/lwip_ping.h | 15 +++++++++++++ net/lwip/apps/ping/ping.h | 27 +++++++++++++++++++++++ 6 files changed, 109 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..ba02e7ed47 --- /dev/null +++ b/net/lwip/apps/ping/lwip_ping.c @@ -0,0 +1,39 @@ +// 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 5000 + +static ip_addr_t ip_target; + +void ping_tmo(void *arg) +{ + log_err("ping_tmo: ping failed; host %s is not alive\n", + ipaddr_ntoa(&ip_target)); + 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, NULL); + + 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..5dd631f2f7 --- /dev/null +++ b/net/lwip/apps/ping/ping.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include "lwip/ip_addr.h" + +void ping_tmo(void *arg); + +#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)); \ + raw_remove(pcb); \ + sys_untimeout(ping_tmo, NULL); \ + sys_check_timeouts(); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host %s in not alive\n",\ + ipaddr_ntoa(addr)); \ + raw_remove(pcb); \ + sys_untimeout(ping_tmo, NULL); \ + sys_check_timeouts(); \ + ulwip_exit(-1); \ + } \ + } while (0); + +void ping_init(const ip_addr_t *ping_addr);