]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/blobdiff - src/core/ipv6/ip6.c
Fix bug #37959: ip6_debug_print prints plen, nexth, hoplim in wrong
[pes-rpp/rpp-lwip.git] / src / core / ipv6 / ip6.c
index bae27ecead151349bcd667beb9d41c1ecce12793..94e423a23007e4a2cb4835e4eeb41afd9eec0164 100644 (file)
@@ -347,7 +347,8 @@ ip6_input(struct pbuf *p, struct netif *inp)
   u8_t nexth;
   u16_t hlen; /* the current header length */
   u8_t i;
-#if IP_ACCEPT_LINK_LAYER_ADDRESSING
+#if 0 /*IP_ACCEPT_LINK_LAYER_ADDRESSING*/
+  @todo
   int check_ip_src=1;
 #endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
 
@@ -356,7 +357,7 @@ ip6_input(struct pbuf *p, struct netif *inp)
   /* identify the IP header */
   ip6hdr = (struct ip6_hdr *)p->payload;
   if (IP6H_V(ip6hdr) != 6) {
-    LWIP_DEBUGF(IP6_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IPv6 packet dropped due to bad version number %"U16_F"\n",
+    LWIP_DEBUGF(IP6_DEBUG | LWIP_DBG_LEVEL_WARNING, ("IPv6 packet dropped due to bad version number %"U32_F"\n",
         IP6H_V(ip6hdr)));
     pbuf_free(p);
     IP6_STATS_INC(ip6.err);
@@ -394,6 +395,9 @@ ip6_input(struct pbuf *p, struct netif *inp)
   /* current header pointer. */
   ip_data.current_ip6_header = ip6hdr;
 
+  /* In netif, used in case we need to send ICMPv6 packets back. */
+  ip_data.current_netif = inp;
+
   /* match packet against an interface, i.e. is this packet for us? */
   if (ip6_addr_ismulticast(ip6_current_dest_addr())) {
     /* Always joined to multicast if-local and link-local all-nodes group. */
@@ -407,9 +411,18 @@ ip6_input(struct pbuf *p, struct netif *inp)
     }
 #else /* LWIP_IPV6_MLD */
     else if (ip6_addr_issolicitednode(ip6_current_dest_addr())) {
-      /* Accept all solicited node packets when MLD is not enabled
+      /* Filter solicited node packets when MLD is not enabled
        * (for Neighbor discovery). */
-      netif = inp;
+      netif = NULL;
+      for (i = 0; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
+        if (ip6_addr_isvalid(netif_ip6_addr_state(inp, i)) &&
+            ip6_addr_cmp_solicitednode(ip6_current_dest_addr(), netif_ip6_addr(inp, i))) {
+          netif = inp;
+          LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: solicited node packet accepted on interface %c%c\n",
+              netif->name[0], netif->name[1]));
+          break;
+        }
+      }
     }
 #endif /* LWIP_IPV6_MLD */
     else {
@@ -434,6 +447,11 @@ ip6_input(struct pbuf *p, struct netif *inp)
           }
         }
       }
+      if (ip6_addr_islinklocal(ip6_current_dest_addr())) {
+        /* Do not match link-local addresses to other netifs. */
+        netif = NULL;
+        break;
+      }
       if (first) {
         first = 0;
         netif = netif_list;
@@ -446,7 +464,7 @@ ip6_input(struct pbuf *p, struct netif *inp)
     } while(netif != NULL);
 netif_found:
     LWIP_DEBUGF(IP6_DEBUG, ("ip6_input: packet accepted on interface %c%c\n",
-        netif->name[0], netif->name[1]));
+        netif ? netif->name[0] : 'X', netif? netif->name[1] : 'X'));
   }
 
   /* "::" packet source address? (used in duplicate address detection) */
@@ -476,7 +494,7 @@ netif_found:
   }
 
   /* current netif pointer. */
-  ip_data.current_netif = inp;
+  ip_data.current_netif = netif;
 
   /* Save next header type. */
   nexth = IP6H_NEXTH(ip6hdr);
@@ -497,7 +515,7 @@ netif_found:
       nexth = *((u8_t *)p->payload);
 
       /* Get the header length. */
-      hlen = 8 * (1 + *((u8_t *)p->payload) + 1);
+      hlen = 8 * (1 + *((u8_t *)p->payload + 1));
       ip_data.current_ip_header_tot_len += hlen;
 
       /* Skip over this header. */
@@ -520,7 +538,7 @@ netif_found:
       nexth = *((u8_t *)p->payload);
 
       /* Get the header length. */
-      hlen = 8 * (1 + *((u8_t *)p->payload) + 1);
+      hlen = 8 * (1 + *((u8_t *)p->payload + 1));
       ip_data.current_ip_header_tot_len += hlen;
 
       /* Skip over this header. */
@@ -543,7 +561,7 @@ netif_found:
       nexth = *((u8_t *)p->payload);
 
       /* Get the header length. */
-      hlen = 8 * (1 + *((u8_t *)p->payload) + 1);
+      hlen = 8 * (1 + *((u8_t *)p->payload + 1));
       ip_data.current_ip_header_tot_len += hlen;
 
       /* Skip over this header. */
@@ -823,12 +841,24 @@ ip6_output(struct pbuf *p, ip6_addr_t *src, ip6_addr_t *dest,
           u8_t hl, u8_t tc, u8_t nexth)
 {
   struct netif *netif;
+  struct ip6_hdr *ip6hdr;
+  ip6_addr_t src_addr, dest_addr;
 
   /* pbufs passed to IPv6 must have a ref-count of 1 as their payload pointer
      gets altered as the packet is passed down the stack */
   LWIP_ASSERT("p->ref == 1", p->ref == 1);
 
-  if ((netif = ip6_route(src, dest)) == NULL) {
+  if (dest != IP_HDRINCL) {
+    netif = ip6_route(src, dest);
+  } else {
+    /* IP header included in p, read addresses. */
+    ip6hdr = (struct ip6_hdr *)p->payload;
+    ip6_addr_copy(src_addr, ip6hdr->src);
+    ip6_addr_copy(dest_addr, ip6hdr->dest);
+    netif = ip6_route(&src_addr, &dest_addr);
+  }
+
+  if (netif == NULL) {
     LWIP_DEBUGF(IP6_DEBUG, ("ip6_output: no route for %"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F"\n",
         IP6_ADDR_BLOCK1(dest),
         IP6_ADDR_BLOCK2(dest),
@@ -871,13 +901,25 @@ ip6_output_hinted(struct pbuf *p, ip6_addr_t *src, ip6_addr_t *dest,
           u8_t hl, u8_t tc, u8_t nexth, u8_t *addr_hint)
 {
   struct netif *netif;
+  struct ip6_hdr *ip6hdr;
+  ip6_addr_t src_addr, dest_addr;
   err_t err;
 
   /* pbufs passed to IP must have a ref-count of 1 as their payload pointer
      gets altered as the packet is passed down the stack */
   LWIP_ASSERT("p->ref == 1", p->ref == 1);
 
-  if ((netif = ip6_route(src, dest)) == NULL) {
+  if (dest != IP_HDRINCL) {
+    netif = ip6_route(src, dest);
+  } else {
+    /* IP header included in p, read addresses. */
+    ip6hdr = (struct ip6_hdr *)p->payload;
+    ip6_addr_copy(src_addr, ip6hdr->src);
+    ip6_addr_copy(dest_addr, ip6hdr->dest);
+    netif = ip6_route(&src_addr, &dest_addr);
+  }
+
+  if (netif == NULL) {
     LWIP_DEBUGF(IP6_DEBUG, ("ip6_output: no route for %"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F":%"X16_F"\n",
         IP6_ADDR_BLOCK1(dest),
         IP6_ADDR_BLOCK2(dest),
@@ -954,9 +996,9 @@ ip6_debug_print(struct pbuf *p)
                     IP6H_FL(ip6hdr)));
   LWIP_DEBUGF(IP6_DEBUG, ("+-------------------------------+\n"));
   LWIP_DEBUGF(IP6_DEBUG, ("|     %5"U16_F"     |  %3"U16_F"  |  %3"U16_F"  | (plen, nexth, hopl)\n",
-                    ntohs(IP6H_PLEN(ip6hdr)),
-                    ntohs(IP6H_NEXTH(ip6hdr)),
-                    ntohs(IP6H_HOPLIM(ip6hdr))));
+                    IP6H_PLEN(ip6hdr),
+                    IP6H_NEXTH(ip6hdr),
+                    IP6H_HOPLIM(ip6hdr)));
   LWIP_DEBUGF(IP6_DEBUG, ("+-------------------------------+\n"));
   LWIP_DEBUGF(IP6_DEBUG, ("|  %4"X32_F" |  %4"X32_F" |  %4"X32_F" |  %4"X32_F" | (src)\n",
                     IP6_ADDR_BLOCK1(&(ip6hdr->src)),