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

ip6.c File Reference

#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/ip.h"
#include "lwip/inet.h"
#include "lwip/netif.h"
#include "lwip/icmp.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/stats.h"
#include "arch/perf.h"

Include dependency graph for ip6.c:

Go to the source code of this file.

Functions

void ip_init (void)
netifip_route (struct ip_addr *dest)
void ip_forward (struct pbuf *p, struct ip_hdr *iphdr)
void ip_input (struct pbuf *p, struct netif *inp)
err_t ip_output_if (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto, struct netif *netif)
err_t ip_output (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t proto)


Function Documentation

void ip_forward struct pbuf p,
struct ip_hdr iphdr
[static]
 

Definition at line 96 of file ip6.c.

References DEBUGF, ip_hdr::dest, ip_hdr::hoplim, ICMP_TE_TTL, icmp_time_exceeded(), ip_addr_debug_print, IP_DEBUG, IP_PROTO_ICMP, ip_route(), ip_hdr::nexthdr, NULL, and pbuf_free().

Referenced by ip_input().

00097 {
00098   struct netif *netif;
00099   
00100   PERF_START;
00101   
00102   if((netif = ip_route((struct ip_addr *)&(iphdr->dest))) == NULL) {
00103 
00104     DEBUGF(IP_DEBUG, ("ip_input: no forwarding route found for "));
00105 #if IP_DEBUG
00106     ip_addr_debug_print(&(iphdr->dest));
00107 #endif /* IP_DEBUG */
00108     DEBUGF(IP_DEBUG, ("\n"));
00109     pbuf_free(p);
00110     return;
00111   }
00112   /* Decrement TTL and send ICMP if ttl == 0. */
00113   if(--iphdr->hoplim == 0) {
00114     /* Don't send ICMP messages in response to ICMP messages */
00115     if(iphdr->nexthdr != IP_PROTO_ICMP) {
00116       icmp_time_exceeded(p, ICMP_TE_TTL);
00117     }
00118     pbuf_free(p);
00119     return;       
00120   }
00121   
00122   /* Incremental update of the IP checksum. */
00123   /*  if (iphdr->chksum >= htons(0xffff - 0x100)) {
00124     iphdr->chksum += htons(0x100) + 1;
00125   } else {
00126     iphdr->chksum += htons(0x100);
00127     }*/
00128   
00129 
00130   DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to "));
00131 #if IP_DEBUG
00132   ip_addr_debug_print(&(iphdr->dest));
00133 #endif /* IP_DEBUG */
00134   DEBUGF(IP_DEBUG, ("\n"));
00135 
00136 #ifdef IP_STATS
00137   ++lwip_stats.ip.fw;
00138   ++lwip_stats.ip.xmit;
00139 #endif /* IP_STATS */
00140 
00141   PERF_STOP("ip_forward");
00142   
00143   netif->output(netif, p, (struct ip_addr *)&(iphdr->dest));
00144 }

Here is the call graph for this function:

void ip_init void   ) 
 

Definition at line 63 of file ip6.c.

00064 {
00065 }

void ip_input struct pbuf p,
struct netif inp
 

Definition at line 157 of file ip6.c.

References ip_addr::addr, DBG_TRACE, DEBUGF, ip_hdr::dest, DHCP_CLIENT_PORT, ERR_OK, htons, icmp_dest_unreach(), ICMP_DUR_PROTO, icmp_input(), inet_chksum(), IP_ADDR_BROADCAST, ip_addr_cmp, ip_addr_debug_print, ip_addr_isany, ip_addr_isbroadcast, ip_addr_ismulticast, ip_addr_maskcmp, IP_DEBUG, ip_forward(), IP_HLEN, IP_MF, IP_OFFMASK, IP_PROTO_ICMP, IP_PROTO_TCP, IP_PROTO_UDP, ip_reass(), IPH_HL, IPH_ID, IPH_LEN, IPH_OFFSET, IPH_PROTO, IPH_V, pbuf::len, netif_list, netif::netmask, ntohs, NULL, pbuf::payload, pbuf_free(), pbuf_header(), pbuf_realloc(), snmp_inc_ipindelivers, snmp_inc_ipindiscards, snmp_inc_ipinreceives, snmp_inc_ipunknownprotos, tcp_input(), pbuf::tot_len, u16_t, u8_t, and udp_input().

Referenced by tcpip_thread().

00157                                             {
00158   struct ip_hdr *iphdr;
00159   struct netif *netif;
00160 
00161   
00162   PERF_START;
00163 
00164 #if IP_DEBUG
00165   ip_debug_print(p);
00166 #endif /* IP_DEBUG */
00167 
00168   
00169 #ifdef IP_STATS
00170   ++lwip_stats.ip.recv;
00171 #endif /* IP_STATS */
00172   
00173   /* identify the IP header */
00174   iphdr = p->payload;
00175 
00176   
00177   if(iphdr->v != 6) {
00178     DEBUGF(IP_DEBUG, ("IP packet dropped due to bad version number\n"));
00179 #if IP_DEBUG
00180     ip_debug_print(p);
00181 #endif /* IP_DEBUG */
00182     pbuf_free(p);
00183 #ifdef IP_STATS
00184     ++lwip_stats.ip.err;
00185     ++lwip_stats.ip.drop;
00186 #endif /* IP_STATS */
00187     return;
00188   }
00189   
00190   /* is this packet for us? */
00191   for(netif = netif_list; netif != NULL; netif = netif->next) {
00192 #if IP_DEBUG
00193     DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest "));
00194     ip_addr_debug_print(&(iphdr->dest));
00195     DEBUGF(IP_DEBUG, ("netif->ip_addr "));
00196     ip_addr_debug_print(&(netif->ip_addr));
00197     DEBUGF(IP_DEBUG, ("\n"));
00198 #endif /* IP_DEBUG */
00199     if(ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr))) {
00200       break;
00201     }
00202   }
00203 
00204   
00205   if(netif == NULL) {
00206     /* packet not for us, route or discard */
00207 #ifdef IP_FORWARD
00208     ip_forward(p, iphdr);
00209 #endif
00210     pbuf_free(p);
00211     return;
00212   }
00213 
00214   pbuf_realloc(p, IP_HLEN + ntohs(iphdr->len));
00215   
00216   /* send to upper layers */
00217 #if IP_DEBUG
00218   /*  DEBUGF("ip_input: \n");
00219   ip_debug_print(p);
00220   DEBUGF("ip_input: p->len %u p->tot_len %u\n", p->len, p->tot_len);*/
00221 #endif /* IP_DEBUG */
00222    
00223 
00224   pbuf_header(p, -IP_HLEN);
00225 
00226   switch(iphdr->nexthdr) {
00227   case IP_PROTO_UDP:
00228     udp_input(p);
00229     break;
00230   case IP_PROTO_TCP:
00231     tcp_input(p);
00232     break;
00233   case IP_PROTO_ICMP:
00234     icmp_input(p, inp);
00235     break;
00236   default:
00237     /* send ICMP destination protocol unreachable */
00238     icmp_dest_unreach(p, ICMP_DUR_PROTO);
00239     pbuf_free(p);
00240     DEBUGF(IP_DEBUG, ("Unsupported transportation protocol %u\n",
00241                       iphdr->nexthdr));
00242 
00243 #ifdef IP_STATS
00244     ++lwip_stats.ip.proterr;
00245     ++lwip_stats.ip.drop;
00246 #endif /* IP_STATS */
00247 
00248   }
00249   PERF_STOP("ip_input");
00250 }

Here is the call graph for this function:

err_t ip_output struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
u8_t  ttl,
u8_t  proto
 

Definition at line 322 of file ip6.c.

References ip_addr::addr, DEBUGF, ERR_RTE, IP_DEBUG, ip_output_if(), ip_route(), NULL, and u8_t.

00324 {
00325   struct netif *netif;
00326   if((netif = ip_route(dest)) == NULL) {
00327     DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%lx\n", dest->addr));
00328 #ifdef IP_STATS
00329     ++lwip_stats.ip.rterr;
00330 #endif /* IP_STATS */
00331     return ERR_RTE;
00332   }
00333 
00334   return ip_output_if(p, src, dest, ttl, proto, netif);
00335 }

Here is the call graph for this function:

err_t ip_output_if struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
u8_t  ttl,
u8_t  proto,
struct netif netif
 

Definition at line 261 of file ip6.c.

References DEBUGF, ERR_BUF, htons, netif::ip_addr, ip_addr_isany, ip_addr_set, IP_DEBUG, IP_HDRINCL, IP_HLEN, pbuf::len, netif::name, netif::output, pbuf::payload, pbuf_header(), pbuf::tot_len, and u8_t.

00264 {
00265   struct ip_hdr *iphdr;
00266 
00267   PERF_START;
00268 
00269   printf("len %u tot_len %u\n", p->len, p->tot_len);
00270   if(pbuf_header(p, IP_HLEN)) {
00271     DEBUGF(IP_DEBUG, ("ip_output: not enough room for IP header in pbuf\n"));
00272 #ifdef IP_STATS
00273     ++lwip_stats.ip.err;
00274 #endif /* IP_STATS */
00275 
00276     return ERR_BUF;
00277   }
00278   printf("len %u tot_len %u\n", p->len, p->tot_len);
00279   
00280   iphdr = p->payload;
00281   
00282 
00283   if(dest != IP_HDRINCL) {
00284     printf("!IP_HDRLINCL\n");
00285     iphdr->hoplim = ttl;
00286     iphdr->nexthdr = proto;
00287     iphdr->len = htons(p->tot_len - IP_HLEN);
00288     ip_addr_set(&(iphdr->dest), dest);
00289 
00290     iphdr->v = 6;
00291 
00292     if(ip_addr_isany(src)) {
00293       ip_addr_set(&(iphdr->src), &(netif->ip_addr));
00294     } else {
00295       ip_addr_set(&(iphdr->src), src);
00296     }
00297     
00298   } else {
00299     dest = &(iphdr->dest);
00300   }
00301 
00302 #ifdef IP_STATS
00303   ++lwip_stats.ip.xmit;
00304 #endif /* IP_STATS */
00305 
00306   DEBUGF(IP_DEBUG, ("ip_output_if: %c%c (len %u)\n", netif->name[0], netif->name[1], p->tot_len));
00307 #if IP_DEBUG
00308   ip_debug_print(p);
00309 #endif /* IP_DEBUG */
00310 
00311   PERF_STOP("ip_output_if");
00312   return netif->output(netif, p, dest);  
00313 }

Here is the call graph for this function:

struct netif* ip_route struct ip_addr dest  ) 
 

Definition at line 75 of file ip6.c.

References ip_addr_maskcmp, netif_default, netif_list, and NULL.

Referenced by ip_forward(), and ip_output().

00076 {
00077   struct netif *netif;
00078   
00079   for(netif = netif_list; netif != NULL; netif = netif->next) {
00080     if(ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
00081       return netif;
00082     }
00083   }
00084 
00085   return netif_default;
00086 }


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