}
#define sntp_format_time sntp_format_time
+
+#ifdef CONFIG_LWIP_ICMP_SHOW_UNREACH
+struct pbuf;
+void net_lwip_icmp_dest_unreach(int code, struct pbuf *p);
+
+#define ICMP_DEST_UNREACH_CB(_c, _p) net_lwip_icmp_dest_unreach(_c, _p)
+#endif
#endif /* LWIP_ARCH_CC_H */
#define IP_DEFAULT_TTL 255
+#if defined(CONFIG_PROT_ICMP_LWIP)
+#define LWIP_ICMP 1
+#else
#define LWIP_ICMP 0
+#endif
#if defined(CONFIG_PROT_RAW_LWIP)
#define LWIP_RAW 1
if NET_LWIP
+config LWIP_ICMP_SHOW_UNREACH
+ bool "Print ICMP Destination Unreachable messages"
+ default y
+ depends on CMD_TFTPBOOT || CMD_SNTP
+ select PROT_ICMP_LWIP
+ help
+ Prints a message whenever an ICMP Destination Unreachable message is
+ received while running a network command that sends requests via UDP.
+ Enabling this can make troubleshooting easier.
+
config LWIP_DEBUG
bool "Enable debug traces in the lwIP library"
help
bool
select PROT_UDP_LWIP
+config PROT_ICMP_LWIP
+ bool
+
config PROT_RAW_LWIP
bool
obj-$(CONFIG_$(PHASE_)DM_ETH) += net-lwip.o
obj-$(CONFIG_CMD_DHCP) += dhcp.o
+obj-$(CONFIG_LWIP_ICMP_SHOW_UNREACH) += icmp_unreach.o
obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
obj-$(CONFIG_WGET) += wget.o
--- /dev/null
+// 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));
+}