#include "lwip/arch.h"
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/netif.h"
Include dependency graph for ipv4/lwip/icmp.h:
Go to the source code of this file.
Data Structures | |
struct | icmp_dur_hdr |
struct | icmp_echo_hdr |
struct | icmp_te_hdr |
Defines | |
#define | ICMP_ER 0 |
#define | ICMP_DUR 3 |
#define | ICMP_SQ 4 |
#define | ICMP_RD 5 |
#define | ICMP_ECHO 8 |
#define | ICMP_TE 11 |
#define | ICMP_PP 12 |
#define | ICMP_TS 13 |
#define | ICMP_TSR 14 |
#define | ICMP_IRQ 15 |
#define | ICMP_IR 16 |
#define | ICMPH_TYPE(hdr) (ntohs((hdr)->_type_code) >> 8) |
#define | ICMPH_CODE(hdr) (ntohs((hdr)->_type_code) & 0xff) |
#define | ICMPH_TYPE_SET(hdr, type) ((hdr)->_type_code = htons(ICMPH_CODE(hdr) | ((type) << 8))) |
#define | ICMPH_CODE_SET(hdr, code) ((hdr)->_type_code = htons((code) | (ICMPH_TYPE(hdr) << 8))) |
Enumerations | |
enum | icmp_dur_type { ICMP_DUR_NET = 0, ICMP_DUR_HOST = 1, ICMP_DUR_PROTO = 2, ICMP_DUR_PORT = 3, ICMP_DUR_FRAG = 4, ICMP_DUR_SR = 5 } |
enum | icmp_te_type { ICMP_TE_TTL = 0, ICMP_TE_FRAG = 1 } |
Functions | |
void | icmp_input (struct pbuf *p, struct netif *inp) |
void | icmp_dest_unreach (struct pbuf *p, enum icmp_dur_type t) |
void | icmp_time_exceeded (struct pbuf *p, enum icmp_te_type t) |
Variables | |
PACK_STRUCT_BEGIN struct icmp_echo_hdr | PACK_STRUCT_STRUCT |
|
Definition at line 50 of file ipv4/lwip/icmp.h. Referenced by icmp_dest_unreach(). |
|
Definition at line 53 of file ipv4/lwip/icmp.h. Referenced by icmp_input(). |
|
Definition at line 49 of file ipv4/lwip/icmp.h. Referenced by icmp_input(). |
|
Definition at line 59 of file ipv4/lwip/icmp.h. |
|
Definition at line 58 of file ipv4/lwip/icmp.h. |
|
Definition at line 55 of file ipv4/lwip/icmp.h. |
|
Definition at line 52 of file ipv4/lwip/icmp.h. |
|
Definition at line 51 of file ipv4/lwip/icmp.h. |
|
Definition at line 54 of file ipv4/lwip/icmp.h. |
|
Definition at line 56 of file ipv4/lwip/icmp.h. |
|
Definition at line 57 of file ipv4/lwip/icmp.h. |
|
Definition at line 112 of file ipv4/lwip/icmp.h. |
|
Definition at line 115 of file ipv4/lwip/icmp.h. Referenced by icmp_dest_unreach(). |
|
Definition at line 111 of file ipv4/lwip/icmp.h. |
|
Definition at line 114 of file ipv4/lwip/icmp.h. Referenced by icmp_dest_unreach(), and icmp_input(). |
|
Definition at line 61 of file ipv4/lwip/icmp.h.
00061 { 00062 ICMP_DUR_NET = 0, /* net unreachable */ 00063 ICMP_DUR_HOST = 1, /* host unreachable */ 00064 ICMP_DUR_PROTO = 2, /* protocol unreachable */ 00065 ICMP_DUR_PORT = 3, /* port unreachable */ 00066 ICMP_DUR_FRAG = 4, /* fragmentation needed and DF set */ 00067 ICMP_DUR_SR = 5 /* source route failed */ 00068 }; |
|
Definition at line 70 of file ipv4/lwip/icmp.h.
00070 { 00071 ICMP_TE_TTL = 0, /* time to live exceeded in transit */ 00072 ICMP_TE_FRAG = 1 /* fragment reassembly time exceeded */ 00073 }; |
|
Definition at line 138 of file icmp.c.
00139 { 00140 struct pbuf *q; 00141 struct ip_hdr *iphdr; 00142 struct icmp_dur_hdr *idur; 00143 00144 q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM); 00145 /* ICMP header + IP header + 8 bytes of data */ 00146 00147 iphdr = p->payload; 00148 00149 idur = q->payload; 00150 ICMPH_TYPE_SET(idur, ICMP_DUR); 00151 ICMPH_CODE_SET(idur, t); 00152 00153 memcpy((char *)q->payload + 8, p->payload, IP_HLEN + 8); 00154 00155 /* calculate checksum */ 00156 idur->chksum = 0; 00157 idur->chksum = inet_chksum(idur, q->len); 00158 #ifdef ICMP_STATS 00159 ++lwip_stats.icmp.xmit; 00160 #endif /* ICMP_STATS */ 00161 /* increase number of messages attempted to send */ 00162 snmp_inc_icmpoutmsgs(); 00163 /* increase number of destination unreachable messages attempted to send */ 00164 snmp_inc_icmpoutdestunreachs(); 00165 00166 ip_output(q, NULL, &(iphdr->src), 00167 ICMP_TTL, IP_PROTO_ICMP); 00168 pbuf_free(q); 00169 } |
|
Definition at line 52 of file icmp.c.
00053 { 00054 unsigned char type; 00055 struct icmp_echo_hdr *iecho; 00056 struct ip_hdr *iphdr; 00057 struct ip_addr tmpaddr; 00058 u16_t hlen; 00059 00060 #ifdef ICMP_STATS 00061 ++lwip_stats.icmp.recv; 00062 #endif /* ICMP_STATS */ 00063 snmp_inc_icmpinmsgs(); 00064 00065 00066 iphdr = p->payload; 00067 hlen = IPH_HL(iphdr) * 4; 00068 pbuf_header(p, -((s16_t)hlen)); 00069 00070 type = *((u8_t *)p->payload); 00071 00072 switch(type) { 00073 case ICMP_ECHO: 00074 if(ip_addr_isbroadcast(&iphdr->dest, &inp->netmask) || 00075 ip_addr_ismulticast(&iphdr->dest)) { 00076 DEBUGF(ICMP_DEBUG, ("Smurf.\n")); 00077 #ifdef ICMP_STATS 00078 ++lwip_stats.icmp.err; 00079 #endif /* ICMP_STATS */ 00080 pbuf_free(p); 00081 return; 00082 } 00083 DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n")); 00084 DEBUGF(DEMO_DEBUG, ("Pong!\n")); 00085 if(p->tot_len < sizeof(struct icmp_echo_hdr)) { 00086 DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n")); 00087 pbuf_free(p); 00088 #ifdef ICMP_STATS 00089 ++lwip_stats.icmp.lenerr; 00090 #endif /* ICMP_STATS */ 00091 snmp_inc_icmpinerrors(); 00092 00093 return; 00094 } 00095 iecho = p->payload; 00096 if(inet_chksum_pbuf(p) != 0) { 00097 DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n")); 00098 pbuf_free(p); 00099 #ifdef ICMP_STATS 00100 ++lwip_stats.icmp.chkerr; 00101 #endif /* ICMP_STATS */ 00102 snmp_inc_icmpinerrors(); 00103 return; 00104 } 00105 tmpaddr.addr = iphdr->src.addr; 00106 iphdr->src.addr = iphdr->dest.addr; 00107 iphdr->dest.addr = tmpaddr.addr; 00108 ICMPH_TYPE_SET(iecho, ICMP_ER); 00109 /* adjust the checksum */ 00110 if(iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) { 00111 iecho->chksum += htons(ICMP_ECHO << 8) + 1; 00112 } else { 00113 iecho->chksum += htons(ICMP_ECHO << 8); 00114 } 00115 #ifdef ICMP_STATS 00116 ++lwip_stats.icmp.xmit; 00117 #endif /* ICMP_STATS */ 00118 /* increase number of messages attempted to send */ 00119 snmp_inc_icmpoutmsgs(); 00120 /* increase number of echo replies attempted to send */ 00121 snmp_inc_icmpoutechoreps(); 00122 00123 pbuf_header(p, hlen); 00124 ip_output_if(p, &(iphdr->src), IP_HDRINCL, 00125 IPH_TTL(iphdr), IP_PROTO_ICMP, inp); 00126 break; 00127 default: 00128 DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type not supported.\n")); 00129 #ifdef ICMP_STATS 00130 ++lwip_stats.icmp.proterr; 00131 ++lwip_stats.icmp.drop; 00132 #endif /* ICMP_STATS */ 00133 } 00134 pbuf_free(p); 00135 } |
|
Definition at line 148 of file icmp6.c.
00149 { 00150 struct pbuf *q; 00151 struct ip_hdr *iphdr; 00152 struct icmp_te_hdr *tehdr; 00153 00154 DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded\n")); 00155 00156 q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM); 00157 00158 iphdr = p->payload; 00159 00160 tehdr = q->payload; 00161 tehdr->type = (char)ICMP6_TE; 00162 tehdr->icode = (char)t; 00163 00164 /* copy fields from original packet */ 00165 memcpy((char *)q->payload + 8, (char *)p->payload, IP_HLEN + 8); 00166 00167 /* calculate checksum */ 00168 tehdr->chksum = 0; 00169 tehdr->chksum = inet_chksum(tehdr, q->len); 00170 #ifdef ICMP_STATS 00171 ++lwip_stats.icmp.xmit; 00172 #endif /* ICMP_STATS */ 00173 ip_output(q, NULL, 00174 (struct ip_addr *)&(iphdr->src), ICMP_TTL, IP_PROTO_ICMP); 00175 pbuf_free(q); 00176 } |
|
|