110 |
/* Find network interface where to forward this IP packet to. */ |
/* Find network interface where to forward this IP packet to. */ |
111 |
netif = ip_route((struct ip_addr *)&(iphdr->dest)); |
netif = ip_route((struct ip_addr *)&(iphdr->dest)); |
112 |
if (netif == NULL) { |
if (netif == NULL) { |
113 |
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%lx found\n", |
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: no forwarding route for 0x%"X32_F" found\n", |
114 |
iphdr->dest.addr)); |
iphdr->dest.addr)); |
115 |
snmp_inc_ipnoroutes(); |
snmp_inc_ipnoroutes(); |
116 |
return (struct netif *)NULL; |
return (struct netif *)NULL; |
142 |
IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100)); |
IPH_CHKSUM_SET(iphdr, IPH_CHKSUM(iphdr) + htons(0x100)); |
143 |
} |
} |
144 |
|
|
145 |
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to 0x%lx\n", |
LWIP_DEBUGF(IP_DEBUG, ("ip_forward: forwarding packet to 0x%"X32_F"\n", |
146 |
iphdr->dest.addr)); |
iphdr->dest.addr)); |
147 |
|
|
148 |
IP_STATS_INC(ip.fw); |
IP_STATS_INC(ip.fw); |
181 |
/* identify the IP header */ |
/* identify the IP header */ |
182 |
iphdr = p->payload; |
iphdr = p->payload; |
183 |
if (IPH_V(iphdr) != 4) { |
if (IPH_V(iphdr) != 4) { |
184 |
LWIP_DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %u\n", IPH_V(iphdr))); |
LWIP_DEBUGF(IP_DEBUG | 1, ("IP packet dropped due to bad version number %"U16_F"\n", IPH_V(iphdr))); |
185 |
ip_debug_print(p); |
ip_debug_print(p); |
186 |
pbuf_free(p); |
pbuf_free(p); |
187 |
IP_STATS_INC(ip.err); |
IP_STATS_INC(ip.err); |
196 |
|
|
197 |
/* header length exceeds first pbuf length? */ |
/* header length exceeds first pbuf length? */ |
198 |
if (iphdrlen > p->len) { |
if (iphdrlen > p->len) { |
199 |
LWIP_DEBUGF(IP_DEBUG | 2, ("IP header (len %u) does not fit in first pbuf (len %u), IP packet droppped.\n", |
LWIP_DEBUGF(IP_DEBUG | 2, ("IP header (len %"U16_F") does not fit in first pbuf (len %"U16_F"), IP packet droppped.\n", |
200 |
iphdrlen, p->len)); |
iphdrlen, p->len)); |
201 |
/* free (drop) packet pbufs */ |
/* free (drop) packet pbufs */ |
202 |
pbuf_free(p); |
pbuf_free(p); |
210 |
#if CHECKSUM_CHECK_IP |
#if CHECKSUM_CHECK_IP |
211 |
if (inet_chksum(iphdr, iphdrlen) != 0) { |
if (inet_chksum(iphdr, iphdrlen) != 0) { |
212 |
|
|
213 |
LWIP_DEBUGF(IP_DEBUG | 2, ("Checksum (0x%x) failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen))); |
LWIP_DEBUGF(IP_DEBUG | 2, ("Checksum (0x%"X16_F") failed, IP packet dropped.\n", inet_chksum(iphdr, iphdrlen))); |
214 |
ip_debug_print(p); |
ip_debug_print(p); |
215 |
pbuf_free(p); |
pbuf_free(p); |
216 |
IP_STATS_INC(ip.chkerr); |
IP_STATS_INC(ip.chkerr); |
227 |
/* match packet against an interface, i.e. is this packet for us? */ |
/* match packet against an interface, i.e. is this packet for us? */ |
228 |
for (netif = netif_list; netif != NULL; netif = netif->next) { |
for (netif = netif_list; netif != NULL; netif = netif->next) { |
229 |
|
|
230 |
LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%lx netif->ip_addr 0x%lx (0x%lx, 0x%lx, 0x%lx)\n", |
LWIP_DEBUGF(IP_DEBUG, ("ip_input: iphdr->dest 0x%"X32_F" netif->ip_addr 0x%"X32_F" (0x%"X32_F", 0x%"X32_F", 0x%"X32_F")\n", |
231 |
iphdr->dest.addr, netif->ip_addr.addr, |
iphdr->dest.addr, netif->ip_addr.addr, |
232 |
iphdr->dest.addr & netif->netmask.addr, |
iphdr->dest.addr & netif->netmask.addr, |
233 |
netif->ip_addr.addr & netif->netmask.addr, |
netif->ip_addr.addr & netif->netmask.addr, |
255 |
if (netif == NULL) { |
if (netif == NULL) { |
256 |
/* remote port is DHCP server? */ |
/* remote port is DHCP server? */ |
257 |
if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { |
if (IPH_PROTO(iphdr) == IP_PROTO_UDP) { |
258 |
LWIP_DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %u\n", |
LWIP_DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: UDP packet to DHCP client port %"U16_F"\n", |
259 |
ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest))); |
ntohs(((struct udp_hdr *)((u8_t *)iphdr + iphdrlen))->dest))); |
260 |
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) { |
261 |
LWIP_DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: DHCP packet accepted.\n")); |
LWIP_DEBUGF(IP_DEBUG | DBG_TRACE | 1, ("ip_input: DHCP packet accepted.\n")); |
285 |
/* packet consists of multiple fragments? */ |
/* packet consists of multiple fragments? */ |
286 |
if ((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { |
if ((IPH_OFFSET(iphdr) & htons(IP_OFFMASK | IP_MF)) != 0) { |
287 |
#if IP_REASSEMBLY /* packet fragment reassembly code present? */ |
#if IP_REASSEMBLY /* packet fragment reassembly code present? */ |
288 |
LWIP_DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04x tot_len=%u len=%u MF=%u offset=%u), calling ip_reass()\n", |
LWIP_DEBUGF(IP_DEBUG, ("IP packet is a fragment (id=0x%04"X16_F" tot_len=%"U16_F" len=%"U16_F" MF=%"U16_F" offset=%"U16_F"), calling ip_reass()\n", |
289 |
ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8)); |
ntohs(IPH_ID(iphdr)), p->tot_len, ntohs(IPH_LEN(iphdr)), !!(IPH_OFFSET(iphdr) & htons(IP_MF)), (ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)*8)); |
290 |
/* reassemble the packet*/ |
/* reassemble the packet*/ |
291 |
p = ip_reass(p); |
p = ip_reass(p); |
296 |
iphdr = p->payload; |
iphdr = p->payload; |
297 |
#else /* IP_REASSEMBLY == 0, no packet fragment reassembly code present */ |
#else /* IP_REASSEMBLY == 0, no packet fragment reassembly code present */ |
298 |
pbuf_free(p); |
pbuf_free(p); |
299 |
LWIP_DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%x) (while IP_REASSEMBLY == 0).\n", |
LWIP_DEBUGF(IP_DEBUG | 2, ("IP packet dropped since it was fragmented (0x%"X16_F") (while IP_REASSEMBLY == 0).\n", |
300 |
ntohs(IPH_OFFSET(iphdr)))); |
ntohs(IPH_OFFSET(iphdr)))); |
301 |
IP_STATS_INC(ip.opterr); |
IP_STATS_INC(ip.opterr); |
302 |
IP_STATS_INC(ip.drop); |
IP_STATS_INC(ip.drop); |
319 |
/* send to upper layers */ |
/* send to upper layers */ |
320 |
LWIP_DEBUGF(IP_DEBUG, ("ip_input: \n")); |
LWIP_DEBUGF(IP_DEBUG, ("ip_input: \n")); |
321 |
ip_debug_print(p); |
ip_debug_print(p); |
322 |
LWIP_DEBUGF(IP_DEBUG, ("ip_input: p->len %d p->tot_len %d\n", p->len, p->tot_len)); |
LWIP_DEBUGF(IP_DEBUG, ("ip_input: p->len %"U16_F" p->tot_len %"U16_F"\n", p->len, p->tot_len)); |
323 |
|
|
324 |
#if LWIP_RAW |
#if LWIP_RAW |
325 |
/* raw input did not eat the packet? */ |
/* raw input did not eat the packet? */ |
353 |
} |
} |
354 |
pbuf_free(p); |
pbuf_free(p); |
355 |
|
|
356 |
LWIP_DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %d\n", IPH_PROTO(iphdr))); |
LWIP_DEBUGF(IP_DEBUG | 2, ("Unsupported transport protocol %"U16_F"\n", IPH_PROTO(iphdr))); |
357 |
|
|
358 |
IP_STATS_INC(ip.proterr); |
IP_STATS_INC(ip.proterr); |
359 |
IP_STATS_INC(ip.drop); |
IP_STATS_INC(ip.drop); |
427 |
|
|
428 |
IP_STATS_INC(ip.xmit); |
IP_STATS_INC(ip.xmit); |
429 |
|
|
430 |
LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%u\n", netif->name[0], netif->name[1], netif->num)); |
LWIP_DEBUGF(IP_DEBUG, ("ip_output_if: %c%c%"U16_F"\n", netif->name[0], netif->name[1], netif->num)); |
431 |
ip_debug_print(p); |
ip_debug_print(p); |
432 |
|
|
433 |
LWIP_DEBUGF(IP_DEBUG, ("netif->output()")); |
LWIP_DEBUGF(IP_DEBUG, ("netif->output()")); |
447 |
struct netif *netif; |
struct netif *netif; |
448 |
|
|
449 |
if ((netif = ip_route(dest)) == NULL) { |
if ((netif = ip_route(dest)) == NULL) { |
450 |
LWIP_DEBUGF(IP_DEBUG | 2, ("ip_output: No route to 0x%lx\n", dest->addr)); |
LWIP_DEBUGF(IP_DEBUG | 2, ("ip_output: No route to 0x%"X32_F"\n", dest->addr)); |
451 |
|
|
452 |
IP_STATS_INC(ip.rterr); |
IP_STATS_INC(ip.rterr); |
453 |
snmp_inc_ipoutdiscards(); |
snmp_inc_ipoutdiscards(); |
468 |
|
|
469 |
LWIP_DEBUGF(IP_DEBUG, ("IP header:\n")); |
LWIP_DEBUGF(IP_DEBUG, ("IP header:\n")); |
470 |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
471 |
LWIP_DEBUGF(IP_DEBUG, ("|%2d |%2d | 0x%02x | %5u | (v, hl, tos, len)\n", |
LWIP_DEBUGF(IP_DEBUG, ("|%2"S16_F" |%2"S16_F" | 0x%02"X16_F" | %5"U16_F" | (v, hl, tos, len)\n", |
472 |
IPH_V(iphdr), |
IPH_V(iphdr), |
473 |
IPH_HL(iphdr), |
IPH_HL(iphdr), |
474 |
IPH_TOS(iphdr), |
IPH_TOS(iphdr), |
475 |
ntohs(IPH_LEN(iphdr)))); |
ntohs(IPH_LEN(iphdr)))); |
476 |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
477 |
LWIP_DEBUGF(IP_DEBUG, ("| %5u |%u%u%u| %4u | (id, flags, offset)\n", |
LWIP_DEBUGF(IP_DEBUG, ("| %5"U16_F" |%"U16_F"%"U16_F"%"U16_F"| %4"U16_F" | (id, flags, offset)\n", |
478 |
ntohs(IPH_ID(iphdr)), |
ntohs(IPH_ID(iphdr)), |
479 |
ntohs(IPH_OFFSET(iphdr)) >> 15 & 1, |
ntohs(IPH_OFFSET(iphdr)) >> 15 & 1, |
480 |
ntohs(IPH_OFFSET(iphdr)) >> 14 & 1, |
ntohs(IPH_OFFSET(iphdr)) >> 14 & 1, |
481 |
ntohs(IPH_OFFSET(iphdr)) >> 13 & 1, |
ntohs(IPH_OFFSET(iphdr)) >> 13 & 1, |
482 |
ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)); |
ntohs(IPH_OFFSET(iphdr)) & IP_OFFMASK)); |
483 |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
484 |
LWIP_DEBUGF(IP_DEBUG, ("| %3u | %3u | 0x%04x | (ttl, proto, chksum)\n", |
LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | 0x%04"X16_F" | (ttl, proto, chksum)\n", |
485 |
IPH_TTL(iphdr), |
IPH_TTL(iphdr), |
486 |
IPH_PROTO(iphdr), |
IPH_PROTO(iphdr), |
487 |
ntohs(IPH_CHKSUM(iphdr)))); |
ntohs(IPH_CHKSUM(iphdr)))); |
488 |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
489 |
LWIP_DEBUGF(IP_DEBUG, ("| %3u | %3u | %3u | %3u | (src)\n", |
LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (src)\n", |
490 |
ip4_addr1(&iphdr->src), |
ip4_addr1(&iphdr->src), |
491 |
ip4_addr2(&iphdr->src), |
ip4_addr2(&iphdr->src), |
492 |
ip4_addr3(&iphdr->src), |
ip4_addr3(&iphdr->src), |
493 |
ip4_addr4(&iphdr->src))); |
ip4_addr4(&iphdr->src))); |
494 |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
LWIP_DEBUGF(IP_DEBUG, ("+-------------------------------+\n")); |
495 |
LWIP_DEBUGF(IP_DEBUG, ("| %3u | %3u | %3u | %3u | (dest)\n", |
LWIP_DEBUGF(IP_DEBUG, ("| %3"U16_F" | %3"U16_F" | %3"U16_F" | %3"U16_F" | (dest)\n", |
496 |
ip4_addr1(&iphdr->dest), |
ip4_addr1(&iphdr->dest), |
497 |
ip4_addr2(&iphdr->dest), |
ip4_addr2(&iphdr->dest), |
498 |
ip4_addr3(&iphdr->dest), |
ip4_addr3(&iphdr->dest), |