236 |
/* identify the IP header */ |
/* identify the IP header */ |
237 |
iphdr = p->payload; |
iphdr = p->payload; |
238 |
if(IPH_V(iphdr) != 4) { |
if(IPH_V(iphdr) != 4) { |
239 |
DEBUGF(IP_DEBUG, ("IP packet dropped due to bad version number %d\n", IPH_V(iphdr))); |
DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %d\n", IPH_V(iphdr))); |
240 |
#if IP_DEBUG |
#if IP_DEBUG |
241 |
ip_debug_print(p); |
ip_debug_print(p); |
242 |
#endif /* IP_DEBUG */ |
#endif /* IP_DEBUG */ |
255 |
|
|
256 |
/* header length exceeds first pbuf length? */ |
/* header length exceeds first pbuf length? */ |
257 |
if(iphdrlen > p->len) { |
if(iphdrlen > p->len) { |
258 |
DEBUGF(IP_DEBUG, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n", |
DEBUGF(IP_DEBUG | 2, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n", |
259 |
iphdrlen, p->len)); |
iphdrlen, p->len)); |
260 |
/* free (drop) packet pbufs */ |
/* free (drop) packet pbufs */ |
261 |
pbuf_free(p); |
pbuf_free(p); |
270 |
/* verify checksum */ |
/* verify checksum */ |
271 |
if(inet_chksum(iphdr, iphdrlen) != 0) { |
if(inet_chksum(iphdr, iphdrlen) != 0) { |
272 |
|
|
273 |
DEBUGF(IP_DEBUG, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen))); |
DEBUGF(IP_DEBUG | 2, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen))); |
274 |
#if IP_DEBUG |
#if IP_DEBUG |
275 |
ip_debug_print(p); |
ip_debug_print(p); |
276 |
#endif /* IP_DEBUG */ |
#endif /* IP_DEBUG */ |
320 |
if(netif == NULL) { |
if(netif == NULL) { |
321 |
/* remote port is DHCP server? */ |
/* remote port is DHCP server? */ |
322 |
if(IPH_PROTO(iphdr) == IP_PROTO_UDP) { |
if(IPH_PROTO(iphdr) == IP_PROTO_UDP) { |
323 |
DEBUGF(IP_DEBUG, ("ip_input: UDP packet to DHCP client port %u\n", |
DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %u\n", |
324 |
ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest))); |
ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest))); |
325 |
if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) { |
if (ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest) == DHCP_CLIENT_PORT) { |
326 |
DEBUGF(IP_DEBUG, ("ip_input: DHCP packet accepted.\n")); |
DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: DHCP packet accepted.\n")); |
327 |
netif = inp; |
netif = inp; |
328 |
} |
} |
329 |
} |
} |
332 |
/* packet not for us? */ |
/* packet not for us? */ |
333 |
if(netif == NULL) { |
if(netif == NULL) { |
334 |
/* packet not for us, route or discard */ |
/* packet not for us, route or discard */ |
335 |
DEBUGF(IP_DEBUG, ("ip_input: packet not for us.\n")); |
DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: packet not for us.\n")); |
336 |
#if IP_FORWARD |
#if IP_FORWARD |
337 |
/* non-broadcast packet? */ |
/* non-broadcast packet? */ |
338 |
if(!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) { |
if(!ip_addr_isbroadcast(&(iphdr->dest), &(inp->netmask))) { |
360 |
#else /* IP_REASSEMBLY */ |
#else /* IP_REASSEMBLY */ |
361 |
if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { |
if((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { |
362 |
pbuf_free(p); |
pbuf_free(p); |
363 |
DEBUGF(IP_DEBUG, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", |
DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", |
364 |
ntohs(IPH_OFFSET(iphdr)))); |
ntohs(IPH_OFFSET(iphdr)))); |
365 |
#ifdef IP_STATS |
#ifdef IP_STATS |
366 |
++lwip_stats.ip.opterr; |
++lwip_stats.ip.opterr; |
372 |
#endif /* IP_REASSEMBLY */ |
#endif /* IP_REASSEMBLY */ |
373 |
|
|
374 |
#if IP_OPTIONS == 0 |
#if IP_OPTIONS == 0 |
375 |
if(iphdrlen > IP_HLEN) { |
if (iphdrlen > IP_HLEN) { |
376 |
DEBUGF(IP_DEBUG, ("IP packet dropped since there were IP options (while IP_OPTIONS == 0).\n")); |
DEBUGF(IP_DEBUG | 2, ("IP packet dropped since there were IP options (while IP_OPTIONS == 0).\n")); |
377 |
pbuf_free(p); |
pbuf_free(p); |
378 |
#ifdef IP_STATS |
#ifdef IP_STATS |
379 |
++lwip_stats.ip.opterr; |
++lwip_stats.ip.opterr; |
417 |
} |
} |
418 |
pbuf_free(p); |
pbuf_free(p); |
419 |
|
|
420 |
DEBUGF(IP_DEBUG, ("Unsupported transportation protocol %d\n", IPH_PROTO(iphdr))); |
DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %d\n", IPH_PROTO(iphdr))); |
421 |
|
|
422 |
#ifdef IP_STATS |
#ifdef IP_STATS |
423 |
++lwip_stats.ip.proterr; |
++lwip_stats.ip.proterr; |
450 |
|
|
451 |
if(dest != IP_HDRINCL) { |
if(dest != IP_HDRINCL) { |
452 |
if(pbuf_header(p, IP_HLEN)) { |
if(pbuf_header(p, IP_HLEN)) { |
453 |
DEBUGF(IP_DEBUG, ("ip_output: not enough room for IP header in pbuf\n")); |
DEBUGF(IP_DEBUG | 2, ("ip_output: not enough room for IP header in pbuf\n")); |
454 |
|
|
455 |
#ifdef IP_STATS |
#ifdef IP_STATS |
456 |
++lwip_stats.ip.err; |
++lwip_stats.ip.err; |
517 |
struct netif *netif; |
struct netif *netif; |
518 |
|
|
519 |
if((netif = ip_route(dest)) == NULL) { |
if((netif = ip_route(dest)) == NULL) { |
520 |
DEBUGF(IP_DEBUG, ("ip_output: No route to 0x%lx\n", dest->addr)); |
DEBUGF(IP_DEBUG | 2, ("ip_output: No route to 0x%lx\n", dest->addr)); |
521 |
|
|
522 |
#ifdef IP_STATS |
#ifdef IP_STATS |
523 |
++lwip_stats.ip.rterr; |
++lwip_stats.ip.rterr; |