From patchwork Wed Aug 2 14:06:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 709171 Delivered-To: patch@linaro.org Received: by 2002:a5d:55c5:0:b0:317:2194:b2bc with SMTP id i5csp931220wrw; Wed, 2 Aug 2023 07:10:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3IUt0X+pHYCKaGlwgS26MsRouDWxd5ypNxkLMwYDq/RahFkRZ6zXCPMz6HdmIYhRzmPSH X-Received: by 2002:a05:600c:22d1:b0:3fa:77ed:9894 with SMTP id 17-20020a05600c22d100b003fa77ed9894mr4943357wmg.7.1690985445219; Wed, 02 Aug 2023 07:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690985445; cv=none; d=google.com; s=arc-20160816; b=t8F2svfCqCDrMbg3AzsWxiDgbHguZriTY0unx4h/lX0OpdGV320eiTudao/4D5GA6o 7QYX4mNFmkYZn2T/unjcQMYNbLUW51k0bXbE6WhulqC8erleeLmYvIo30Rcq72ug3xbc kLpZ/57vBB3DCbZxUpt9WgrFPDWFwI04KabHBVAD4SyvdkG4wtqXJRHxLNalsjdZeUP4 QKM7xgPJfZReZHO5ySi9TB8K/2TaqrKHg0AuFHFtLMqcx1dAKx0iErYMmTS332k2KNZR oO5GafbC6I/qyzAzcQ62A67aV8EmkGxPY2wZn+13MP3EnRqmBsGmL/QZFXpamrRbg/EW h5sw== 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=l8nVsuHIUN/0ayZzjvwElKSpd1z/2gXHWvytwVlu78M=; fh=KONqw1VFBW9nCv9imase+52c+XJ0MeVkzLj6SOLcJqQ=; b=KcnCo4UGwtExSjdAAfcLdQslwOB4pmXgf7oz5aHq9/1FtgL1fUrEfeF0eD9Fh8VJ5p 730raleNd72TV8BhG5Q8Taol1vFPiNprEDnENXUGkrB+CoZIEmgCesdfdJ17rG8VRqpj 7I/SimRnsi8gN6B2bcAhXz4QyMTaU1hZPRG+txAi4XDftfRIwAncVQmfExA+g/FSE6T1 0sl9B8fjARUYftJ6kRdUUCvMWg/Mxmli+8pWqduyAJERNXXpxgFZvd130nhBsqnx7KLn NZtSR6XWHTXpG2+ahvC1imMc2unkDT5oKL1fQHa5fp1M5s90kPF/cZfk2vjdn7XfrOnn qmgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X9eyngC7; 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 c16-20020adffb10000000b003175b99e12csi6978862wrr.654.2023.08.02.07.10.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:10:45 -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=X9eyngC7; 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 779B3868AB; Wed, 2 Aug 2023 16:09:45 +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="X9eyngC7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 181B986C7F; Wed, 2 Aug 2023 16:09:45 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) (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 B34A986898 for ; Wed, 2 Aug 2023 16:09:42 +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-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4fbf09a9139so11385293e87.2 for ; Wed, 02 Aug 2023 07:09:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690985382; x=1691590182; 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=l8nVsuHIUN/0ayZzjvwElKSpd1z/2gXHWvytwVlu78M=; b=X9eyngC7RmhA2Pzi/kJc5Yoq1GQAMzWAASiThEOfijozOIKZ2SdbXWYtVlWUIU7o/b HXaxmHJwzRBXQ9MdEV3bbDRapZ/FMgFl1KzRhPxnPMvHXkYkuhDfJKHcBSSsqxhY+1hG ic13JuqKtr4V8ogYEQnQp0XCYwhWwiIsCePxAKFQ9MqLmshtWuiL0sBka2ucO0N6wCUE GkOM75oKw1/QpyVmnl1dJDU7uELajt5NmLzpjZln+BuimijtX6m9NBy+yeXBQHjXMgNg uevAT6K36cwXInJ3V9uEU2t9YW7/tyXUVUvwoTFJkZ+Qc85hpWX+3lN+7Si/MyhgHMUy JzDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690985382; x=1691590182; 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=l8nVsuHIUN/0ayZzjvwElKSpd1z/2gXHWvytwVlu78M=; b=N+D99QAOpYzOvFpB6X77Ctn5VjlaND2NCkHq7I96BwIra4xU/IE0pjSa8wpDymE96+ YHV/QsLdjWsG82G0eyGtisfI4seLkx0YVS/tPOqYo98H0jOxpA0AaODNUhtaeUB1HfUV IczhP6Zk7dxrYM1+GPuzgkKlwS5+AEbf2sL3ouf/ciQAGUGLI1paYAATLOoOzT5eOy8W 5PXCpkzsW5owgwwl6+yQ60GwOyiG2bR6sbmY7dQ1hmcJPLoHUrCAUedSGpsF2L8p9lwo wC2xCFRsTBZjwvFDr3qADBFLRE6Wc//tnqoBitUr3jr1U0ptLeAMnBIXAvB6criB5c0/ wa/w== X-Gm-Message-State: ABy/qLaJr1smyHZVzKeiETzg0CYNqcQuWgTlX+IlfJ3sGtuYPUCyBhUe gjE6ERA2SRKARdunTeSWhf6zzhMqaThBywhFcO7Z1A== X-Received: by 2002:a19:ca52:0:b0:4fb:8eec:ce49 with SMTP id h18-20020a19ca52000000b004fb8eecce49mr4215926lfj.31.1690985381867; Wed, 02 Aug 2023 07:09:41 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id a12-20020a056512020c00b004fbbef8d4dbsm2982026lfo.121.2023.08.02.07.09.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Aug 2023 07:09:40 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@redhat.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, lwip-devel@nongnu.org, Maxim Uvarov Subject: [PATCHv5 07/13] net/lwip: implement ping cmd Date: Wed, 2 Aug 2023 20:06:52 +0600 Message-Id: <20230802140658.10319-8-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230802140658.10319-1-maxim.uvarov@linaro.org> References: <20230802140658.10319-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 Signed-off-by: Maxim Uvarov --- lib/lwip/Makefile | 1 + lib/lwip/apps/ping/Makefile | 11 ++++++++++ lib/lwip/apps/ping/lwip_ping.c | 37 ++++++++++++++++++++++++++++++++++ lib/lwip/apps/ping/lwip_ping.h | 24 ++++++++++++++++++++++ lib/lwip/apps/ping/ping.h | 35 ++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 lib/lwip/apps/ping/Makefile create mode 100644 lib/lwip/apps/ping/lwip_ping.c create mode 100644 lib/lwip/apps/ping/lwip_ping.h create mode 100644 lib/lwip/apps/ping/ping.h diff --git a/lib/lwip/Makefile b/lib/lwip/Makefile index ec6b728c8e..87ed99a230 100644 --- a/lib/lwip/Makefile +++ b/lib/lwip/Makefile @@ -67,5 +67,6 @@ obj-$(CONFIG_NET) += port/sys-arch.o obj-$(CONFIG_CMD_DHCP) += apps/dhcp/lwip-dhcp.o obj-$(CONFIG_CMD_DNS) += apps/dns/lwip-dns.o +obj-$(CONFIG_CMD_PING) += apps/ping/ obj-$(CONFIG_CMD_TFTPBOOT) += apps/tftp/ obj-$(CONFIG_CMD_WGET) += apps/http/ diff --git a/lib/lwip/apps/ping/Makefile b/lib/lwip/apps/ping/Makefile new file mode 100644 index 0000000000..0d0a811336 --- /dev/null +++ b/lib/lwip/apps/ping/Makefile @@ -0,0 +1,11 @@ +ccflags-y += -I$(srctree)/lib/lwip/port/include +ccflags-y += -I$(srctree)/lib/lwip/lwip-external/src/include -I$(srctree)/lib/lwip +ccflags-y += -I$(obj) + +.PHONY: $(obj)/ping.c +$(obj)/ping.o: $(obj)/ping.c +$(obj)/ping.c: + cp $(srctree)/lib/lwip/lwip-external/contrib/apps/ping/ping.c $(obj)/ping.c + +obj-$(CONFIG_CMD_PING) += ping.o +obj-$(CONFIG_CMD_PING) += lwip_ping.o diff --git a/lib/lwip/apps/ping/lwip_ping.c b/lib/lwip/apps/ping/lwip_ping.c new file mode 100644 index 0000000000..40658ab6fd --- /dev/null +++ b/lib/lwip/apps/ping/lwip_ping.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#include "lwip/opt.h" +#include "lwip/ip_addr.h" +#include "ping.h" + +#include + +static ip_addr_t ip_target; + +static int ulwip_ping_tmo(void) +{ + + printf("ping failed; host %s is not alive\n", ipaddr_ntoa(&ip_target)); + return 0; +} + +int lwip_ping_init(char *ping_addr) +{ + int err; + + err = ipaddr_aton(ping_addr, &ip_target); + if (err == 0) { + printf("wrong ping addr string \"%s\" \n", ping_addr); + return -1; + } + + ulwip_set_tmo(ulwip_ping_tmo); + + ping_init(&ip_target); + + return 0; +} diff --git a/lib/lwip/apps/ping/lwip_ping.h b/lib/lwip/apps/ping/lwip_ping.h new file mode 100644 index 0000000000..7f08095427 --- /dev/null +++ b/lib/lwip/apps/ping/lwip_ping.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * (C) Copyright 2023 Linaro Ltd. + */ + +#ifndef LWIP_PING_H +#define LWIP_PING_H + +#include + +/** + * PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used + */ +#ifndef PING_USE_SOCKETS +#define PING_USE_SOCKETS 0 +#endif + +int lwip_ping_init(char *ping_addr); + +void ping_raw_init(void); +void ping_send_now(void); + +#endif /* LWIP_PING_H */ diff --git a/lib/lwip/apps/ping/ping.h b/lib/lwip/apps/ping/ping.h new file mode 100644 index 0000000000..0dd4bd78c7 --- /dev/null +++ b/lib/lwip/apps/ping/ping.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include "../../../lwip/ulwip.h" + +#include "lwip/prot/ip4.h" + +#define ip4_print_parts(a, b, c, d) \ + printf("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d); + +#define ip4_print(ipaddr) \ + ip4_print_parts(\ + (u16_t)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \ + (u16_t)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0)) + + +#define LWIP_DEBUG 1 /* ping_time is under ifdef*/ +#define PING_RESULT(cond) { \ + if (cond == 1) { \ + printf("host "); \ + ip4_print(addr); \ + printf(" is alive\n"); \ + printf(" %"U32_F" ms\n", (sys_now() - ping_time)); \ + ulwip_exit(0); \ + } else { \ + printf("ping failed; host "); \ + ip4_print(addr); \ + printf(" is not alive\n"); \ + ulwip_exit(-1); \ + } \ + } while (0); + +#include "lwip/ip_addr.h" +void ping_init(const ip_addr_t *ping_addr);