Microchip® Advanced Software Framework

icmp.c File Reference

ICMP - Internet Control Message Protocol.

#include "lwip/opt.h"
#include "lwip/icmp.h"
#include "lwip/inet_chksum.h"
#include "lwip/ip.h"
#include "lwip/def.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include <string.h>

Macros

#define ICMP_DEST_UNREACH_DATASIZE   8
 
#define LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN   1
 Small optimization: set to 0 if incoming PBUF_POOL pbuf always can be used to modify and send a response packet (and to 1 if this is not the case, e.g. More...
 

Functions

void icmp_dest_unreach (struct pbuf *p, enum icmp_dur_type t)
 Send an icmp 'destination unreachable' packet, called from ip_input() if the transport layer protocol is unknown and from udp_input() if the local port is not bound. More...
 
void icmp_input (struct pbuf *p, struct netif *inp)
 Processes ICMP input packets, called from ip_input(). More...
 
static void icmp_send_response (struct pbuf *p, u8_t type, u8_t code)
 Send an icmp packet in response to an incoming packet. More...
 
void icmp_time_exceeded (struct pbuf *p, enum icmp_te_type t)
 Send a 'time exceeded' packet, called from ip_forward() if TTL is 0. More...
 

#define ICMP_DEST_UNREACH_DATASIZE   8

Referenced by icmp_send_response().

#define LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN   1

Small optimization: set to 0 if incoming PBUF_POOL pbuf always can be used to modify and send a response packet (and to 1 if this is not the case, e.g.

when link header is stripped of when receiving)

void icmp_dest_unreach ( struct pbuf p,
enum icmp_dur_type  t 
)

Send an icmp 'destination unreachable' packet, called from ip_input() if the transport layer protocol is unknown and from udp_input() if the local port is not bound.

Parameters
pthe input packet for which the 'unreachable' should be sent, p->payload pointing to the IP header
ttype of the 'unreachable' packet

References ICMP_DUR, and icmp_send_response().

Referenced by ip_input(), and udp_input().

void icmp_input ( struct pbuf p,
struct netif inp 
)

Processes ICMP input packets, called from ip_input().

Currently only processes icmp echo requests and sends out the echo response.

Parameters
pthe icmp echo request packet, p->payload pointing to the ip header
inpthe netif on which this packet was received

References current_iphdr_dest, ERR_OK, ICMP_DEBUG, ICMP_ECHO, ICMP_ER, ICMP_STATS_INC, ICMPH_TYPE_SET, if(), inet_chksum(), inet_chksum_pbuf(), ip_addr_copy, ip_addr_isbroadcast, ip_addr_ismulticast, ip_current_dest_addr, ip_current_src_addr, IP_HDRINCL, IP_HLEN, ip_output_if(), IP_PROTO_ICMP, IPH_CHKSUM_SET, IPH_HL, IPH_TTL_SET, iphdr, pbuf::len, LWIP_ASSERT, LWIP_DEBUGF, NULL, pbuf::payload, pbuf_alloc(), pbuf_copy(), pbuf_free(), pbuf_header(), PBUF_IP_HLEN, PBUF_LINK, PBUF_RAM, PP_HTONS, S16_F, snmp_inc_icmpinerrors, snmp_inc_icmpinmsgs, snmp_inc_icmpoutechoreps, snmp_inc_icmpoutmsgs, pbuf::tot_len, and U16_F.

Referenced by ip_input().

static void icmp_send_response ( struct pbuf p,
u8_t  type,
u8_t  code 
)
static

Send an icmp packet in response to an incoming packet.

Parameters
pthe input packet for which the 'unreachable' should be sent, p->payload pointing to the IP header
typeType of the ICMP header
codeCode of the ICMP header

References ICMP_DEBUG, ICMP_DEST_UNREACH_DATASIZE, ICMP_STATS_INC, inet_chksum(), ip_addr_copy, ip_addr_debug_print, IP_HLEN, ip_output(), IP_PROTO_ICMP, iphdr, pbuf::len, LWIP_ASSERT, LWIP_DEBUGF, NULL, pbuf::payload, pbuf_alloc(), pbuf_free(), PBUF_IP, PBUF_RAM, snmp_inc_icmpoutmsgs, and snmp_inc_icmpouttimeexcds.

Referenced by icmp_dest_unreach(), and icmp_time_exceeded().

void icmp_time_exceeded ( struct pbuf p,
enum icmp_te_type  t 
)

Send a 'time exceeded' packet, called from ip_forward() if TTL is 0.

Parameters
pthe input packet for which the 'time exceeded' should be sent, p->payload pointing to the IP header
ttype of the 'time exceeded' packet

References icmp_send_response(), and ICMP_TE.

Referenced by ip_reass_free_complete_datagram().