MTU: IP fragmentation added to ip4-rewrite and ip6-rewrite
[vpp.git] / src / vnet / ip / ip_frag.c
index 2af697e..1207ec5 100644 (file)
@@ -85,6 +85,12 @@ ip4_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
       return;
     }
 
+  if (p->flags & VLIB_BUFFER_NEXT_PRESENT)
+    {
+      *error = IP_FRAG_ERROR_MALFORMED;
+      return;
+    }
+
   if (ip4_is_fragment (ip4))
     {
       ip_frag_id = ip4->fragment_id;
@@ -131,6 +137,12 @@ ip4_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
            vnet_buffer (p)->sw_if_index[VLIB_RX];
          vnet_buffer (b)->sw_if_index[VLIB_TX] =
            vnet_buffer (p)->sw_if_index[VLIB_TX];
+         /* Copy Adj_index in case DPO based node is sending for the fragmentation,
+            the packet would be sent back to the proper DPO next node and Index */
+         vnet_buffer (b)->ip.adj_index[VLIB_RX] =
+           vnet_buffer (p)->ip.adj_index[VLIB_RX];
+         vnet_buffer (b)->ip.adj_index[VLIB_TX] =
+           vnet_buffer (p)->ip.adj_index[VLIB_TX];
          fip4 = (ip4_header_t *) (vlib_buffer_get_current (b) + offset);
 
          //Copy offset and ip4 header
@@ -336,6 +348,12 @@ ip6_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
       return;
     }
 
+  if (p->flags & VLIB_BUFFER_NEXT_PRESENT)
+    {
+      *error = IP_FRAG_ERROR_MALFORMED;
+      return;
+    }
+
   u8 has_more;
   u16 initial_offset;
   if (*next_header == IP_PROTOCOL_IPV6_FRAGMENTATION)
@@ -393,6 +411,14 @@ ip6_frag_do_fragment (vlib_main_t * vm, u32 pi, u32 ** buffer,
            vnet_buffer (p)->sw_if_index[VLIB_RX];
          vnet_buffer (b)->sw_if_index[VLIB_TX] =
            vnet_buffer (p)->sw_if_index[VLIB_TX];
+
+         /* Copy Adj_index in case DPO based node is sending for the fragmentation,
+            the packet would be sent back to the proper DPO next node and Index */
+         vnet_buffer (b)->ip.adj_index[VLIB_RX] =
+           vnet_buffer (p)->ip.adj_index[VLIB_RX];
+         vnet_buffer (b)->ip.adj_index[VLIB_TX] =
+           vnet_buffer (p)->ip.adj_index[VLIB_TX];
+
          clib_memcpy (vlib_buffer_get_current (b),
                       vlib_buffer_get_current (p), headers_len);
          clib_memcpy (vlib_buffer_get_current (b) + headers_len,