u-boot/net/lwip/icmp_unreach.c
Jerome Forissier 6b914d5596 net: lwip: add Kconfig option to show ICMP unreachable errors
Add Kconfig symbol LWIP_ICMP_SHOW_UNREACH which, when enabled, prints a
message to the console upon reception of ICMP unreachable messages. For
example:

 $ make qemu_arm64_lwip_defconfig
 $ qemu-system-aarch64 -M virt -cpu max -nographic -bios u-boot.bin
 [...]
 => dhcp
 DHCP client bound to address 10.0.2.15 (0 ms)
 => tftp 192.168.0.100:69:Image
 Using virtio-net#32 device
 TFTP from server 192.168.0.100; our IP address is 10.0.2.15
 Filename 'Image'.
 Load address: 0x40200000
 Loading: ICMP destination unreachable (host unreachable) from 192.168.0.16
 Timeout!
 => tftp 192.168.0.16:69:Image
 Using virtio-net#32 device
 TFTP from server 192.168.0.16; our IP address is 10.0.2.15
 Filename 'Image'.
 Load address: 0x40200000
 Loading: ICMP destination unreachable (port unreachable) from 192.168.0.16
 Timeout!
 =>

Submitted upstream as https://github.com/lwip-tcpip/lwip/pull/73.

Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
2025-08-18 14:08:57 +02:00

39 lines
878 B
C

// SPDX-License-Identifier: GPL-2.0+
/* Copyright (C) 2025 Linaro Ltd. */
#include <lwip/icmp.h>
#include <lwip/ip4_addr.h>
#include <lwip/pbuf.h>
#include <lwip/prot/ip4.h>
static const char *code_to_str(int code)
{
switch (code) {
case ICMP_DUR_NET:
return "network unreachable";
case ICMP_DUR_HOST:
return "host unreachable";
case ICMP_DUR_PROTO:
return "protocol unreachable";
case ICMP_DUR_PORT:
return "port unreachable";
case ICMP_DUR_FRAG:
return "fragmentation needed and DF set";
case ICMP_DUR_SR:
return "source route failed";
default:
break;
}
return "unknown cause";
}
void net_lwip_icmp_dest_unreach(int code, struct pbuf *p)
{
struct ip_hdr *iphdr = (struct ip_hdr *)p->payload;
ip4_addr_t src;
ip4_addr_copy(src, iphdr->src);
printf("ICMP destination unreachable (%s) from %s\n",
code_to_str(code), ip4addr_ntoa(&src));
}