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
@@ -257,6 +257,15 @@ icmp_input(struct pbuf *p, struct netif *inp)
257257 default :
258258 if (type == ICMP_DUR ) {
259259 MIB2_STATS_INC (mib2 .icmpindestunreachs );
260+ #ifdef ICMP_DEST_UNREACH_CB
261+ /*
262+ * The callback receives the IP packet (not the ICMP message) so that
263+ * it can extract the source address for example
264+ */
265+ pbuf_add_header (p , IP_HLEN );
266+ ICMP_DEST_UNREACH_CB (code , p );
267+ pbuf_remove_header (p , IP_HLEN );
268+ #endif
260269 } else if (type == ICMP_TE ) {
261270 MIB2_STATS_INC (mib2 .icmpintimeexcds );
262271 } else if (type == ICMP_PP ) {
0 commit comments