public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Maxim Uvarov <maxim.uvarov@linaro.org>
Cc: u-boot@lists.denx.de, pbrobinson@gmail.com,
	joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com,
	goldsimon@gmx.de
Subject: Re: [PATCHv8 07/15] net/lwip: implement ping cmd
Date: Wed, 13 Sep 2023 09:28:46 +0300	[thread overview]
Message-ID: <ZQFWniubZjEPfAp+@hera> (raw)
In-Reply-To: <20230908135320.7066-8-maxim.uvarov@linaro.org>

On Fri, Sep 08, 2023 at 07:53:12PM +0600, Maxim Uvarov wrote:
> 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 <maxim.uvarov@linaro.org>
> ---
>  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. <maxim.uvarov@linaro.org>
> + */
> +
> +#include "lwip/opt.h"
> +#include "lwip/ip_addr.h"
> +#include "lwip/timeouts.h"
> +#include <linux/errno.h>
> +#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);

just cast (char *)arg directly on log_err

> +	ulwip_exit(1);
> +}
> +

[...]

> +	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. <maxim.uvarov@linaro.org>
> + */
> +
> +#ifndef LWIP_PING_H
> +#define LWIP_PING_H
> +
> +#include <lwip/ip_addr.h>
> +
> +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 <net/ulwip.h>
> +#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);
> --
> 2.30.2
>

Thanks
/Ilias

  reply	other threads:[~2023-09-13  6:28 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 13:53 [PATCHv8 00/15] net/lwip: add lwip library for the network stack Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 01/15] net/lwip: add doc/develop/net_lwip.rst Maxim Uvarov
2023-09-12  7:40   ` Ilias Apalodimas
2023-09-08 13:53 ` [PATCHv8 02/15] net/lwip: integrate lwIP library Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 03/15] net/lwip: implement dns cmd Maxim Uvarov
2023-09-13  5:56   ` Ilias Apalodimas
2023-09-13  8:32     ` Simon Goldschmidt
2023-09-13 13:46       ` Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 04/15] net/lwip: implement dhcp cmd Maxim Uvarov
2023-09-13  6:07   ` Ilias Apalodimas
2023-09-13  8:35     ` Simon Goldschmidt
2023-09-08 13:53 ` [PATCHv8 05/15] net/lwip: implement tftp cmd Maxim Uvarov
2023-09-13  6:15   ` Ilias Apalodimas
2023-09-13  8:38     ` Simon Goldschmidt
2023-09-13 13:38       ` Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 06/15] net/lwip: implement wget cmd Maxim Uvarov
2023-09-13  6:25   ` Ilias Apalodimas
2023-09-08 13:53 ` [PATCHv8 07/15] net/lwip: implement ping cmd Maxim Uvarov
2023-09-13  6:28   ` Ilias Apalodimas [this message]
2023-09-08 13:53 ` [PATCHv8 08/15] net/lwip: add lwIP configuration Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 09/15] net/lwip: implement lwIP port to U-Boot Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 10/15] net/lwip: update .gitignore with lwIP Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 11/15] net/lwip: connection between cmd and lwip apps Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 12/15] net/lwip: replace original net commands with lwip Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 13/15] net/lwip: split net.h to net.h, arp.h and eth.h Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 14/15] net/lwip: drop old net/wget Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 15/15] net/lwip/wget add port selection Maxim Uvarov
2023-09-13  6:30   ` Ilias Apalodimas
2023-09-08 13:59 ` [PATCHv8 00/15] net/lwip: add lwip library for the network stack Tom Rini
2023-09-12 11:41   ` Maxim Uvarov
2023-09-12 19:26     ` Simon Glass
2023-09-13  7:31       ` Maxim Uvarov
2023-09-13  7:53         ` Ilias Apalodimas
2023-09-13  8:43           ` Simon Goldschmidt
2023-09-13 10:06             ` Peter Robinson
2023-09-13 13:14               ` Tom Rini
2023-09-13 13:34                 ` Maxim Uvarov
2023-09-21 16:29                   ` Simon Glass
2023-09-22 10:56                     ` Simon Goldschmidt
2023-09-22 16:13                       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZQFWniubZjEPfAp+@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=goldsimon@gmx.de \
    --cc=joe.hershberger@ni.com \
    --cc=maxim.uvarov@linaro.org \
    --cc=pbrobinson@gmail.com \
    --cc=rfried.dev@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox