U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jerome Forissier <jerome.forissier@linaro.org>
To: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: u-boot@lists.denx.de, Javier Tia <javier.tia@linaro.org>,
	Maxim Uvarov <muvarov@gmail.com>, Tom Rini <trini@konsulko.com>,
	Simon Glass <sjg@chromium.org>,
	Eddie James <eajames@linux.ibm.com>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	AKASHI Takahiro <akashi.tkhro@gmail.com>,
	Michal Simek <michal.simek@amd.com>,
	Francis Laniel <francis.laniel@amarulasolutions.com>,
	Peter Robinson <pbrobinson@gmail.com>
Subject: Re: [PATCH v3 05/12] net-lwip: add ping command
Date: Fri, 7 Jun 2024 09:55:11 +0200	[thread overview]
Message-ID: <f50ca00a-b68d-4841-8be4-e6f89d5a9c42@linaro.org> (raw)
In-Reply-To: <CAC_iWj+b3wq=7t++3UAtcjDtmN9itgXu2sODD4nqkR82gTbGDg@mail.gmail.com>



On 6/6/24 19:45, Ilias Apalodimas wrote:
> On Thu, 6 Jun 2024 at 20:02, Ilias Apalodimas
> <ilias.apalodimas@linaro.org> wrote:
>>
>> On Thu, 6 Jun 2024 at 19:53, Ilias Apalodimas
>> <ilias.apalodimas@linaro.org> wrote:
>>>
>>> [...]
>>>
>>>> +static int ping_raw_init(void *recv_arg)
>>>> +{
>>>> +       ping_pcb = raw_new(IP_PROTO_ICMP);
>>>> +       if (!ping_pcb)
>>>> +               return -ENOMEM;
>>>> +
>>>> +       raw_recv(ping_pcb, ping_recv, recv_arg);
>>>> +       raw_bind(ping_pcb, IP_ADDR_ANY);
>>>> +
>>>> +       return 0;
>>>> +}
>>>> +
>>>> +static void ping_raw_stop(void)
>>>> +{
>>>> +       if (ping_pcb != NULL) {
>>>
>>> nits, but we usually do if (!ping_pcb) for NULL pointers and variables
>>> that have a value of 0.
>>> Please change it in other files as well
>>>
>>>
>>>> +               raw_remove(ping_pcb);
>>>> +               ping_pcb = NULL;
>>>> +       }
>>>> +}
>>>> +
>>>> +static void ping_prepare_echo(struct icmp_echo_hdr *iecho)
>>>> +{
>>>> +       ICMPH_TYPE_SET(iecho, ICMP_ECHO);
>>>> +       ICMPH_CODE_SET(iecho, 0);
>>>> +       iecho->chksum = 0;
>>>> +       iecho->id = PING_ID;
>>>> +       iecho->seqno = lwip_htons(++ping_seq_num);
>>>> +
>>>> +       iecho->chksum = inet_chksum(iecho, sizeof(*iecho));
>>>> +}
>>>> +
>>>> +static void ping_send_icmp(struct raw_pcb *raw, const ip_addr_t *addr)
>>>> +{
>>>> +       struct pbuf *p;
>>>> +       struct icmp_echo_hdr *iecho;
>>>> +       size_t ping_size = sizeof(struct icmp_echo_hdr);
>>>> +
>>>> +       p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM);
>>>> +       if (!p)
>>>> +               return;
>>>> +
>>>> +       if ((p->len == p->tot_len) && (p->next == NULL)) {
>>>
>>> && !p->next
>>>
>>>> +               iecho = (struct icmp_echo_hdr *)p->payload;
>>>> +               ping_prepare_echo(iecho);
>>>> +               raw_sendto(raw, p, addr);
>>>> +       }
>>>> +
>>>> +       pbuf_free(p);
>>>> +}
>>>> +
>>>> +static void ping_send(void *arg)
>>>> +{
>>>> +       struct raw_pcb *pcb = (struct raw_pcb *)arg;
>>>> +
>>>> +       ping_send_icmp(pcb, ping_target);
>>>> +       sys_timeout(PING_DELAY_MS, ping_send, ping_pcb);
>>>> +}
>>>> +
>>>> +static int ping_loop(const ip_addr_t* addr)
>>>> +{
>>>> +       bool alive;
>>>> +       ulong start;
>>>> +       int ret;
>>>> +
>>>> +       printf("Using %s device\n", eth_get_name());
>>>> +
>>>> +       ret = ping_raw_init(&alive);
>>>> +       if (ret < 0)
>>>> +               return ret;
>>>> +       ping_target = addr;
>>>> +       ping_seq_num = 0;
>>>> +
>>>> +       start = get_timer(0);
>>>> +       ping_send(ping_pcb);
>>>> +
>>>> +       do {
>>>> +               eth_rx();
>>>> +               if (alive)
>>>> +                       break;
>>>> +               sys_check_timeouts();
>>>> +               if (ctrlc()) {
>>>> +                       printf("\nAbort\n");
>>>> +                       break;
>>>> +               }
>>>> +       } while (get_timer(start) < PING_TIMEOUT_MS);
>>>
>>> I am a bit confused about what happens here.
>>> ping_send() will send the packet, but it will also schedule itself to
>>> rerun after 1 ms and send another ping?
>>>
>>>> +
>>>> +       sys_untimeout(ping_send, ping_pcb);
>>>
>>> So we need the sys_untimeout() because we queued 2 pings? Because
>>> sys_timeout() is supposed to be an one shot.
>>
>> Ah nvm, I misread that. We always reschedule ping_send_icmp(), that's
>> why we have to delete it here
> 
> Ok so looking at it a bit more. Why do we have to schedule contunuous pings?
> We just have to send one packet and wait for the response no?

We could send just one packet as NET does, but if there's packet loss then
the ping command will report the host is unreachable. I think it is safer
to allow for a few retries for better reliability. The code for one packet
would be marginally simpler anyways. What I can do however is use a send
counter rather than a timeout.

Thanks,
-- 
Jerome


  reply	other threads:[~2024-06-07  7:55 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06 13:35 [PATCH v3 00/12] Introduce the lwIP network stack Jerome Forissier
2024-06-06 13:35 ` [PATCH v3 01/12] net: introduce alternative implementation as net-lwip/ Jerome Forissier
2024-06-06 13:35 ` [PATCH v3 02/12] net-lwip: build lwIP Jerome Forissier
2024-06-06 15:50   ` Ilias Apalodimas
2024-06-06 13:35 ` [PATCH v3 03/12] net-lwip: add DHCP support and dhcp commmand Jerome Forissier
2024-06-06 13:35 ` [PATCH v3 04/12] net-lwip: add TFTP support and tftpboot command Jerome Forissier
2024-06-06 13:36 ` [PATCH v3 05/12] net-lwip: add ping command Jerome Forissier
2024-06-06 16:53   ` Ilias Apalodimas
2024-06-06 17:02     ` Ilias Apalodimas
2024-06-06 17:45       ` Ilias Apalodimas
2024-06-07  7:55         ` Jerome Forissier [this message]
2024-06-06 13:36 ` [PATCH v3 06/12] net-lwip: add dns command Jerome Forissier
2024-06-06 15:46   ` Ilias Apalodimas
2024-06-06 15:59     ` Jerome Forissier
2024-06-06 16:02       ` Ilias Apalodimas
2024-06-06 16:21         ` Jerome Forissier
2024-06-06 13:36 ` [PATCH v3 07/12] net-lwip: add wget command Jerome Forissier
2024-06-06 15:41   ` Ilias Apalodimas
2024-06-07  9:23     ` Jerome Forissier
2024-06-06 13:36 ` [PATCH v3 08/12] test: dm: dsa, eth: disable tests when CONFIG_NET_LWIP=y Jerome Forissier
2024-06-06 13:36 ` [PATCH v3 09/12] cmd: bdinfo: enable -e when CONFIG_CMD_NET_LWIP=y Jerome Forissier
2024-06-06 13:36 ` [PATCH v3 10/12] configs: add qemu_arm64_lwip_defconfig Jerome Forissier
2024-06-06 13:36 ` [PATCH v3 11/12] MAINTAINERS: net-lwip: add myself as a maintainer Jerome Forissier
2024-06-06 13:36 ` [PATCH v3 12/12] CI: add qemu_arm64_lwip to the test matrix Jerome Forissier
2024-06-06 16:56 ` [PATCH v3 00/12] Introduce the lwIP network stack Tom Rini
2024-06-07  9:11   ` Jerome Forissier
2024-06-07 13:52     ` 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=f50ca00a-b68d-4841-8be4-e6f89d5a9c42@linaro.org \
    --to=jerome.forissier@linaro.org \
    --cc=akashi.tkhro@gmail.com \
    --cc=eajames@linux.ibm.com \
    --cc=francis.laniel@amarulasolutions.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=javier.tia@linaro.org \
    --cc=michal.simek@amd.com \
    --cc=mkorpershoek@baylibre.com \
    --cc=muvarov@gmail.com \
    --cc=pbrobinson@gmail.com \
    --cc=sjg@chromium.org \
    --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