48 #include "lwip/icmp.h"
63 #ifndef LWIP_INLINE_IP_CHKSUM
64 #define LWIP_INLINE_IP_CHKSUM 1
66 #if LWIP_INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
67 #define CHECKSUM_GEN_IP_INLINE 1
69 #define CHECKSUM_GEN_IP_INLINE 0
72 #if LWIP_DHCP || defined(LWIP_IP_ACCEPT_UDP_PORT)
73 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 1
80 #if LWIP_DHCP && defined(LWIP_IP_ACCEPT_UDP_PORT)
82 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (((port) == PP_NTOHS(DHCP_CLIENT_PORT)) \
83 || (LWIP_IP_ACCEPT_UDP_PORT(port)))
84 #elif defined(LWIP_IP_ACCEPT_UDP_PORT)
86 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) (LWIP_IP_ACCEPT_UDP_PORT(dst_port))
89 #define IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(port) ((port) == PP_NTOHS(DHCP_CLIENT_PORT))
93 #define IP_ACCEPT_LINK_LAYER_ADDRESSING 0
177 LWIP_DEBUGF(
IP_DEBUG, (
"ip_forward: no forwarding route for %"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
" found\n",
210 LWIP_DEBUGF(
IP_DEBUG, (
"ip_forward: forwarding packet to %"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
"\n",
248 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
257 if (
IPH_V(iphdr) != 4) {
268 iphdr_hlen =
IPH_HL(iphdr);
275 if ((iphdr_hlen > p->
len) || (iphdr_len > p->
tot_len)) {
276 if (iphdr_hlen > p->
len) {
278 (
"IP header (len %"U16_F
") does not fit in first pbuf (len %"U16_F
"), IP packet dropped.\n",
279 iphdr_hlen, p->
len));
283 (
"IP (len %"U16_F
") is longer than pbuf (len %"U16_F
"), IP packet dropped.\n",
295 #if CHECKSUM_CHECK_IP
299 (
"Checksum (0x%"X16_F") failed, IP packet dropped.\n",
inet_chksum(iphdr, iphdr_hlen)));
354 if ((netif->autoip !=
NULL) &&
372 }
while(netif !=
NULL);
375 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
388 struct udp_hdr *udphdr = (
struct udp_hdr *)((
u8_t *)iphdr + iphdr_hlen);
390 ntohs(udphdr->dest)));
391 if (IP_ACCEPT_LINK_LAYER_ADDRESSED_PORT(udphdr->dest)) {
401 #if IP_ACCEPT_LINK_LAYER_ADDRESSING
426 ip_forward(p, iphdr, inp);
439 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",
460 #if IP_OPTIONS_ALLOWED == 0
484 current_header = iphdr;
488 if (raw_input(p, inp) == 0)
538 current_netif =
NULL;
539 current_header =
NULL;
574 u8_t proto,
struct netif *netif)
577 return ip_output_if_opt(p, src, dest, ttl, tos, proto, netif,
NULL, 0);
587 u8_t ttl,
u8_t tos,
u8_t proto,
struct netif *netif,
void *ip_options,
593 #if CHECKSUM_GEN_IP_INLINE
607 u16_t optlen_aligned = 0;
609 #if CHECKSUM_GEN_IP_INLINE
613 optlen_aligned = ((optlen + 3) & ~3);
614 ip_hlen += optlen_aligned;
623 if (optlen < optlen_aligned) {
625 memset(((
char*)p->
payload) + optlen, 0, optlen_aligned - optlen);
627 #if CHECKSUM_GEN_IP_INLINE
628 for (i = 0; i < optlen_aligned/2; i++) {
644 LWIP_ASSERT(
"check that first pbuf can hold struct ip_hdr",
649 #if CHECKSUM_GEN_IP_INLINE
655 #if CHECKSUM_GEN_IP_INLINE
661 #if CHECKSUM_GEN_IP_INLINE
662 chk_sum += iphdr->_v_hl_tos;
665 #if CHECKSUM_GEN_IP_INLINE
666 chk_sum += iphdr->_len;
670 #if CHECKSUM_GEN_IP_INLINE
671 chk_sum += iphdr->_id;
682 #if CHECKSUM_GEN_IP_INLINE
685 chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
686 chk_sum = (chk_sum >> 16) + chk_sum;
688 iphdr->_chksum = chk_sum;
711 return netif_loop_output(netif, p, dest);
715 netif_loop_output(netif, p, dest);
722 return ip_frag(p, netif, dest);
727 return netif->
output(netif, p, dest);
764 return ip_output_if(p, src, dest, ttl, tos, proto, netif);
767 #if LWIP_NETIF_HWADDRHINT
804 netif->addr_hint = addr_hint;
805 err =
ip_output_if(p, src, dest, ttl, tos, proto, netif);
806 netif->addr_hint =
NULL;
832 LWIP_DEBUGF(
IP_DEBUG, (
"| %5"U16_F
" |%"U16_F
"%"U16_F
"%"U16_F
"| %4"U16_F
" | (id, flags, offset)\n",