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

ip.h File Reference

#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/netif.h"

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

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

Go to the source code of this file.

Data Structures

struct  ip_hdr

Defines

#define IP_HLEN   40
#define IP_PROTO_ICMP   58
#define IP_PROTO_UDP   17
#define IP_PROTO_UDPLITE   170
#define IP_PROTO_TCP   6
#define IP_HDRINCL   NULL

Functions

void ip_init (void)
netifip_route (struct ip_addr *dest)
void ip_input (struct pbuf *p, struct netif *inp)
err_t ip_output (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, unsigned char ttl, unsigned char proto)
err_t ip_output_if (struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, unsigned char ttl, unsigned char proto, struct netif *netif)


Define Documentation

#define IP_HDRINCL   NULL
 

Definition at line 62 of file ipv6/lwip/ip.h.

#define IP_HLEN   40
 

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

#define IP_PROTO_ICMP   58
 

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

#define IP_PROTO_TCP   6
 

Definition at line 54 of file ipv6/lwip/ip.h.

#define IP_PROTO_UDP   17
 

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

#define IP_PROTO_UDPLITE   170
 

Definition at line 53 of file ipv6/lwip/ip.h.


Function Documentation

void ip_init void   ) 
 

Definition at line 75 of file ip.c.

00076 {
00077 }

void ip_input struct pbuf p,
struct netif inp
 

Definition at line 230 of file ip.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().

00230                                             {
00231   static struct ip_hdr *iphdr;
00232   static struct netif *netif;
00233   static u16_t iphdrlen;
00234   
00235 #ifdef IP_STATS
00236   ++lwip_stats.ip.recv;
00237 #endif /* IP_STATS */
00238   snmp_inc_ipinreceives();
00239 
00240   /* identify the IP header */
00241   iphdr = p->payload;
00242   if(IPH_V(iphdr) != 4) {
00243     DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %d\n", IPH_V(iphdr)));
00244 #if IP_DEBUG
00245     ip_debug_print(p);
00246 #endif /* IP_DEBUG */
00247     pbuf_free(p);
00248 #ifdef IP_STATS
00249     ++lwip_stats.ip.err;
00250     ++lwip_stats.ip.drop;
00251 #endif /* IP_STATS */
00252     snmp_inc_ipunknownprotos();
00253     return ERR_OK;
00254   }
00255   /* obtain IP header length in number of 32-bit words */
00256   iphdrlen = IPH_HL(iphdr);
00257   /* calculate IP header length in bytes */
00258   iphdrlen *= 4;
00259 
00260   /* header length exceeds first pbuf length? */  
00261   if(iphdrlen > p->len) {
00262     DEBUGF(IP_DEBUG | 2, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n",
00263       iphdrlen, p->len));
00264     /* free (drop) packet pbufs */
00265     pbuf_free(p);
00266 #ifdef IP_STATS
00267     ++lwip_stats.ip.lenerr;
00268     ++lwip_stats.ip.drop;
00269 #endif /* IP_STATS */
00270     snmp_inc_ipindiscards();
00271     return ERR_OK;
00272   }
00273 
00274   /* verify checksum */
00275   if(inet_chksum(iphdr, iphdrlen) != 0) {
00276 
00277     DEBUGF(IP_DEBUG | 2, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen)));
00278 #if IP_DEBUG
00279     ip_debug_print(p);
00280 #endif /* IP_DEBUG */
00281     pbuf_free(p);
00282 #ifdef IP_STATS
00283     ++lwip_stats.ip.chkerr;
00284     ++lwip_stats.ip.drop;
00285 #endif /* IP_STATS */
00286     snmp_inc_ipindiscards();
00287     return ERR_OK;
00288   }
00289   
00290   /* Trim pbuf. This should have been done at the netif layer,
00291      but we'll do it anyway just to be sure that its done. */
00292   pbuf_realloc(p, ntohs(IPH_LEN(iphdr)));
00293 
00294   /* is this packet for us? */
00295   for(netif = netif_list; netif != NULL; netif = netif->next) {
00296 
00297     DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%lx netif->ip_addr 0x%lx (0x%lx, 0x%lx, 0x%lx)\n",
00298                       iphdr->dest.addr, netif->ip_addr.addr,
00299                       iphdr->dest.addr & netif->netmask.addr,
00300                       netif->ip_addr.addr & netif->netmask.addr,
00301                       iphdr->dest.addr & ~(netif->netmask.addr)));
00302 
00303     /* interface configured? */
00304     if(!ip_addr_isany(&(netif->ip_addr)))
00305     {
00306       /* unicast to this interface address? */
00307       if(ip_addr_cmp(&(iphdr->dest), &(netif->ip_addr)) ||
00308         /* or broadcast matching this interface network address? */
00309         (ip_addr_isbroadcast(&(iphdr->dest), &(netif->netmask)) &&
00310          ip_addr_maskcmp(&(iphdr->dest), &(netif->ip_addr), &(netif->netmask))) ||
00311          /* or restricted broadcast? */
00312          ip_addr_cmp(&(iphdr->dest), IP_ADDR_BROADCAST)) {
00313          DEBUGF(IP_DEBUG, ("ip_input: packet accepted on interface %c%c\n",
00314                        netif->name[0], netif->name[1]));
00315          /* break out of for loop */
00316          break;
00317       }
00318     }
00319   }
00320 #if LWIP_DHCP
00321   /* Pass DHCP messages regardless of destination address. DHCP traffic is addressed
00322      using link layer addressing (such as Ethernet MAC) so we must not filter on IP.
00323      According to RFC 1542 section 3.1.1, referred by RFC 2131). */
00324   if(netif == NULL) {
00325     /* remote port is DHCP server? */
00326     if(IPH_PROTO(iphdr) == IP_PROTO_UDP) {
00327       DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %u\n",
00328         ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest)));
00329       if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) {
00330         DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: DHCP packet accepted.\n"));
00331         netif = inp;
00332       }
00333     }
00334   }
00335 #endif /* LWIP_DHCP */
00336         /* packet not for us? */  
00337   if(netif == NULL) {
00338     /* packet not for us, route or discard */
00339     DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n"));
00340 #if IP_FORWARD
00341     /* non-broadcast packet? */
00342     if(!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) {
00343       /* try to forward IP packet on (other) interfaces */
00344       ip_forward(p, iphdr, inp);
00345     }
00346     else
00347 #endif /* IP_FORWARD */
00348     {
00349       snmp_inc_ipindiscards();
00350     }
00351     pbuf_free(p);
00352     return ERR_OK;
00353   }
00354 
00355 #if IP_REASSEMBLY
00356   if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
00357     DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04x tot_len=%u len=%u MF=%u offset=%u), calling ip_reass()\n", ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8));
00358     p = ip_reass(p);
00359     if(p == NULL) {
00360       return ERR_OK;
00361     }
00362     iphdr = p->payload;
00363   }
00364 #else /* IP_REASSEMBLY */
00365   if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) {
00366     pbuf_free(p);
00367     DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n",
00368                   ntohs(IPH_OFFSET(iphdr))));
00369 #ifdef IP_STATS
00370     ++lwip_stats.ip.opterr;
00371     ++lwip_stats.ip.drop;
00372 #endif /* IP_STATS */
00373     snmp_inc_ipunknownprotos();
00374     return ERR_OK;
00375   }
00376 #endif /* IP_REASSEMBLY */
00377   
00378 #if IP_OPTIONS == 0
00379   if (iphdrlen > IP_HLEN) {
00380     DEBUGF(IP_DEBUG | 2, ("IP packet dropped since there were IP options (while IP_OPTIONS == 0).\n"));
00381     pbuf_free(p);    
00382 #ifdef IP_STATS
00383     ++lwip_stats.ip.opterr;
00384     ++lwip_stats.ip.drop;
00385 #endif /* IP_STATS */
00386     snmp_inc_ipunknownprotos();
00387     return ERR_OK;
00388   }  
00389 #endif /* IP_OPTIONS == 0 */
00390 
00391   /* send to upper layers */
00392 #if IP_DEBUG
00393   DEBUGF(IP_DEBUG, ("ip_input: \n"));
00394   ip_debug_print(p);
00395   DEBUGF(IP_DEBUG, ("ip_input: p->len %d p->tot_len %d\n", p->len, p->tot_len));
00396 #endif /* IP_DEBUG */   
00397 
00398   switch(IPH_PROTO(iphdr)) {
00399 #if LWIP_UDP > 0    
00400   case IP_PROTO_UDP:
00401     snmp_inc_ipindelivers();
00402     udp_input(p, inp);
00403     break;
00404 #endif /* LWIP_UDP */
00405 #if LWIP_TCP > 0    
00406   case IP_PROTO_TCP:
00407     snmp_inc_ipindelivers();
00408     tcp_input(p, inp);
00409     break;
00410 #endif /* LWIP_TCP */
00411   case IP_PROTO_ICMP:
00412     snmp_inc_ipindelivers();
00413     icmp_input(p, inp);
00414     break;
00415   default:
00416     /* send ICMP destination protocol unreachable unless is was a broadcast */
00417     if(!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask)) &&
00418        !ip_addr_ismulticast(&(iphdr->dest))) {
00419       p->payload = iphdr;
00420       icmp_dest_unreach(p, ICMP_DUR_PROTO);
00421     }
00422     pbuf_free(p);
00423 
00424     DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %d\n", IPH_PROTO(iphdr)));
00425 
00426 #ifdef IP_STATS
00427     ++lwip_stats.ip.proterr;
00428     ++lwip_stats.ip.drop;
00429 #endif /* IP_STATS */
00430     snmp_inc_ipunknownprotos();
00431 
00432   }
00433   return ERR_OK;
00434 }

Here is the call graph for this function:

err_t ip_output struct pbuf p,
struct ip_addr src,
struct ip_addr dest,
unsigned char  ttl,
unsigned char  proto
 

Referenced by icmp_dest_unreach(), and icmp_time_exceeded().

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

Referenced by icmp_input(), and ip_output().

struct netif* ip_route struct ip_addr dest  ) 
 

Definition at line 138 of file ip.c.

References ip_addr_maskcmp, netif_default, netif_list, and NULL.

Referenced by ip_forward(), and ip_output().

00139 {
00140   struct netif *netif;
00141 
00142   /* iterate through netifs */  
00143   for(netif = netif_list; netif != NULL; netif = netif->next) {
00144     /* network mask matches? */
00145     if(ip_addr_maskcmp(dest, &(netif->ip_addr), &(netif->netmask))) {
00146       /* return netif on which to forward IP packet */
00147       return netif;
00148     }
00149   }
00150   /* no matching netif found, use default netif */
00151   return netif_default;
00152 }


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