44 #if LWIP_IPV4 && LWIP_ICMP 57 #ifndef LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN 58 #define LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN 1 62 #define ICMP_DEST_UNREACH_DATASIZE 8 64 static void icmp_send_response(
struct pbuf *p,
u8_t type,
u8_t code);
76 icmp_input(
struct pbuf *p,
struct netif *inp)
83 const struct ip_hdr *iphdr_in;
85 const ip4_addr_t* src;
90 iphdr_in = ip4_current_header();
91 hlen = IPH_HL(iphdr_in) * 4;
109 src = ip4_current_dest_addr();
112 #if LWIP_MULTICAST_PING 114 src = netif_ip4_addr(inp);
122 #if LWIP_BROADCAST_PING 124 src = netif_ip4_addr(inp);
135 #if CHECKSUM_CHECK_ICMP 146 #if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN 158 LWIP_ASSERT(
"check that first pbuf can hold struct the ICMP header",
164 LWIP_ASSERT(
"icmp_input: moving r->payload to icmp header failed\n", 0);
170 LWIP_ASSERT(
"icmp_input: copying to new pbuf failed\n", 0);
181 LWIP_ASSERT(
"icmp_input: restoring original p->payload failed\n", 0);
191 LWIP_ASSERT(
"Can't move over header in packet", 0);
194 struct ip_hdr *iphdr = (
struct ip_hdr*)p->
payload;
195 ip4_addr_copy(iphdr->src, *src);
196 ip4_addr_copy(iphdr->dest, *ip4_current_src_addr());
198 #if CHECKSUM_GEN_ICMP 207 #if LWIP_CHECKSUM_CTRL_PER_NETIF 218 IPH_CHKSUM_SET(iphdr, 0);
221 IPH_CHKSUM_SET(iphdr,
inet_chksum(iphdr, IP_HLEN));
271 #if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN || !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING 296 #if IP_FORWARD || IP_REASSEMBLY 308 icmp_send_response(p,
ICMP_TE, t);
322 icmp_send_response(
struct pbuf *p,
u8_t type,
u8_t code)
325 struct ip_hdr *iphdr;
328 ip4_addr_t iphdr_src;
342 LWIP_ASSERT(
"check that first pbuf can hold icmp message",
343 (q->
len >= (
sizeof(
struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE)));
345 iphdr = (
struct ip_hdr *)p->
payload;
347 ip4_addr_debug_print_val(
ICMP_DEBUG, iphdr->src);
349 ip4_addr_debug_print_val(
ICMP_DEBUG, iphdr->dest);
353 icmphdr->type = type;
354 icmphdr->code = code;
360 IP_HLEN + ICMP_DEST_UNREACH_DATASIZE);
362 ip4_addr_copy(iphdr_src, iphdr->src);
363 netif = ip4_route(&iphdr_src);
367 #if CHECKSUM_GEN_ICMP #define MIB2_STATS_INC(x)
#define ip_current_netif()
u8_t pbuf_header(struct pbuf *p, s16_t header_size_increment)
#define SMEMCPY(dst, src, len)
#define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
#define MEMCPY(dst, src, len)
#define ICMP_STATS_INC(x)
#define ip_addr_isbroadcast(addr, netif)
struct pbuf * pbuf_alloc(pbuf_layer layer, u16_t length, pbuf_type type)
#define ip_current_dest_addr()
#define ip_addr_ismulticast(ipaddr)
u16_t inet_chksum(const void *dataptr, u16_t len)
u16_t inet_chksum_pbuf(struct pbuf *p)
u8_t pbuf_free(struct pbuf *p)
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
#define PBUF_LINK_ENCAPSULATION_HLEN
#define LWIP_ASSERT(message, assertion)
#define LWIP_DEBUGF(debug, message)
#define ICMPH_TYPE_SET(hdr, t)