Skip to content

Commit e698ffd

Browse files
committed
icmp: allow reporting ICMP destination unreachable
Allow reporting ICMP destination unreachable messages via a user-defined callback. Signed-off-by: Jerome Forissier <[email protected]>
1 parent 4599f55 commit e698ffd

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/core/ipv4/icmp.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ void
8080
icmp_input(struct pbuf *p, struct netif *inp)
8181
{
8282
u8_t type;
83-
#ifdef LWIP_DEBUG
83+
#if defined(LWIP_DEBUG) || defined(ICMP_DEST_UNREACH_CB)
8484
u8_t code;
85-
#endif /* LWIP_DEBUG */
85+
#endif
8686
struct icmp_echo_hdr *iecho;
8787
const struct ip_hdr *iphdr_in;
8888
u16_t hlen;
@@ -103,11 +103,11 @@ icmp_input(struct pbuf *p, struct netif *inp)
103103
}
104104

105105
type = *((u8_t *)p->payload);
106-
#ifdef LWIP_DEBUG
106+
#if defined(LWIP_DEBUG) || defined(ICMP_DEST_UNREACH_CB)
107107
code = *(((u8_t *)p->payload) + 1);
108108
/* if debug is enabled but debug statement below is somehow disabled: */
109109
LWIP_UNUSED_ARG(code);
110-
#endif /* LWIP_DEBUG */
110+
#endif
111111
switch (type) {
112112
case ICMP_ER:
113113
/* This is OK, echo reply might have been parsed by a raw PCB
@@ -258,6 +258,15 @@ icmp_input(struct pbuf *p, struct netif *inp)
258258
default:
259259
if (type == ICMP_DUR) {
260260
MIB2_STATS_INC(mib2.icmpindestunreachs);
261+
#ifdef ICMP_DEST_UNREACH_CB
262+
/*
263+
* The callback receives the IP packet (not the ICMP message) so that
264+
* it can extract the source address for example
265+
*/
266+
pbuf_add_header(p, IP_HLEN);
267+
ICMP_DEST_UNREACH_CB(code, p);
268+
pbuf_remove_header(p, IP_HLEN);
269+
#endif
261270
} else if (type == ICMP_TE) {
262271
MIB2_STATS_INC(mib2.icmpintimeexcds);
263272
} else if (type == ICMP_PP) {

0 commit comments

Comments
 (0)