net: lwip: ping: set net_try_count to 1
authorJerome Forissier <jerome.forissier@linaro.org>
Mon, 4 Aug 2025 12:51:01 +0000 (14:51 +0200)
committerJerome Forissier <jerome.forissier@linaro.org>
Mon, 18 Aug 2025 13:47:58 +0000 (15:47 +0200)
The legacy network stack sets net_try_count to 1 at the beginning of the
net_loop() function. This is required for net_start_again() to work
properly. Therefore, set the variable accordingly in the do_ping()
function when NET_LWIP=y. This fixes an issue where a ping to an
unreachable destination would run twice on the same network device. For
example with qemu_arm64_lwip_defconfig:

 => dhcp
 DHCP client bound to address 10.0.2.15 (3 ms)
 => ping 10.0.0.1
 Using virtio-net#32 device
 ping failed; host 10.0.0.1 is not alive
 Using virtio-net#32 device
 ping failed; host 10.0.0.1 is not alive
 => QEMU: Terminated

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
cmd/lwip/ping.c
include/net-lwip.h
net/lwip/net-lwip.c

index 87f8e95..6d090fc 100644 (file)
@@ -170,6 +170,7 @@ int do_ping(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
        if (net_lwip_dns_resolve(argv[1], &addr))
                return CMD_RET_USAGE;
 
+       net_try_count = 1;
 restart:
        if (net_lwip_eth_start() < 0 || ping_loop(eth_get_dev(), &addr) < 0) {
                if (net_start_again() == 0)
index f54f234..e88e218 100644 (file)
@@ -18,6 +18,8 @@ extern size_t cacert_size;
 extern enum auth_mode cacert_auth_mode;
 extern bool cacert_initialized;
 
+extern int net_try_count;
+
 int set_cacert_builtin(void);
 
 enum proto_t {
index 74cbc7e..1a70ced 100644 (file)
@@ -27,7 +27,7 @@
 #if defined(CONFIG_API) || defined(CONFIG_EFI_LOADER)
 void (*push_packet)(void *, int len) = 0;
 #endif
-static int net_try_count;
+int net_try_count;
 static int net_restarted;
 int net_restart_wrap;
 static uchar net_pkt_buf[(PKTBUFSRX) * PKTSIZE_ALIGN + PKTALIGN];