8080icmp_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