Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

icmp.h File Reference

#include "lwip/arch.h"
#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/netif.h"

Include dependency graph for ipv6/lwip/icmp.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  icmp_dur_hdr
struct  icmp_echo_hdr
struct  icmp_te_hdr

Defines

#define ICMP6_DUR   1
#define ICMP6_TE   3
#define ICMP6_ECHO   128
#define ICMP6_ER   129

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)


Define Documentation

#define ICMP6_DUR   1
 

Definition at line 49 of file ipv6/lwip/icmp.h.

Referenced by icmp_dest_unreach().

#define ICMP6_ECHO   128
 

Definition at line 51 of file ipv6/lwip/icmp.h.

Referenced by icmp_input().

#define ICMP6_ER   129
 

Definition at line 52 of file ipv6/lwip/icmp.h.

Referenced by icmp_input().

#define ICMP6_TE   3
 

Definition at line 50 of file ipv6/lwip/icmp.h.

Referenced by icmp_time_exceeded().


Enumeration Type Documentation

enum icmp_dur_type
 

Enumeration values:
ICMP_DUR_NET 
ICMP_DUR_HOST 
ICMP_DUR_PROTO 
ICMP_DUR_PORT 
ICMP_DUR_FRAG 
ICMP_DUR_SR 

Definition at line 55 of file ipv6/lwip/icmp.h.

00055                    {
00056   ICMP_DUR_NET = 0,    /* net unreachable */
00057   ICMP_DUR_HOST = 1,   /* host unreachable */
00058   ICMP_DUR_PROTO = 2,  /* protocol unreachable */
00059   ICMP_DUR_PORT = 3,   /* port unreachable */
00060   ICMP_DUR_FRAG = 4,   /* fragmentation needed and DF set */
00061   ICMP_DUR_SR = 5      /* source route failed */
00062 };

enum icmp_te_type
 

Enumeration values:
ICMP_TE_TTL 
ICMP_TE_FRAG 

Definition at line 64 of file ipv6/lwip/icmp.h.

00064                   {
00065   ICMP_TE_TTL = 0,     /* time to live exceeded in transit */
00066   ICMP_TE_FRAG = 1     /* fragment reassembly time exceeded */
00067 };


Function Documentation

void icmp_dest_unreach struct pbuf p,
enum icmp_dur_type  t
 

Definition at line 138 of file icmp.c.

References ICMP6_DUR, ICMP_DUR, ICMPH_CODE_SET, ICMPH_TYPE_SET, inet_chksum(), IP_HLEN, ip_output(), IP_PROTO_ICMP, NULL, pbuf::payload, pbuf_alloc(), pbuf_free(), PBUF_IP, PBUF_RAM, snmp_inc_icmpoutdestunreachs, and snmp_inc_icmpoutmsgs.

Referenced by ip_input().

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 }

Here is the call graph for this function:

void icmp_input struct pbuf p,
struct netif inp
 

Definition at line 52 of file icmp.c.

References ip_addr::addr, DEBUGF, DEMO_DEBUG, htons, ICMP6_ECHO, ICMP6_ER, ICMP_DEBUG, ICMP_ECHO, ICMP_ER, ICMPH_TYPE_SET, inet_chksum_pbuf(), inet_chksum_pseudo(), ip_addr_isbroadcast, ip_addr_ismulticast, ip_addr_set, IP_HDRINCL, IP_HLEN, ip_output_if(), IP_PROTO_ICMP, IPH_HL, IPH_TTL, pbuf::len, netif::netmask, pbuf::payload, pbuf_free(), pbuf_header(), s16_t, snmp_inc_icmpinerrors, snmp_inc_icmpinmsgs, snmp_inc_icmpoutechoreps, snmp_inc_icmpoutmsgs, pbuf::tot_len, u16_t, and u8_t.

Referenced by ip_input().

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 }

Here is the call graph for this function:

void icmp_time_exceeded struct pbuf p,
enum icmp_te_type  t
 

Definition at line 148 of file icmp6.c.

References DEBUGF, ICMP6_TE, ICMP_DEBUG, inet_chksum(), IP_HLEN, ip_output(), IP_PROTO_ICMP, NULL, pbuf::payload, pbuf_alloc(), pbuf_free(), PBUF_IP, and PBUF_RAM.

Referenced by ip_forward().

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 }

Here is the call graph for this function:


Generated on Wed Jan 14 12:59:04 2004 for RTL-lwIP-0.4 by doxygen 1.3.4