gre: fix outer ip6 length 21/27921/3
authorAloys Augustin <aloaugus@cisco.com>
Thu, 16 Jul 2020 09:01:01 +0000 (11:01 +0200)
committerBenoît Ganne <bganne@cisco.com>
Thu, 16 Jul 2020 11:25:08 +0000 (11:25 +0000)
This updates the computation of the outer ip6 header payload_length
field in order to take into account the GRE header length.

Change-Id: Ie9f982521aeaef7279a9e329a33272d6fae0a428
Type: fix
Signed-off-by: Aloys Augustin <aloaugus@cisco.com>
src/vnet/gre/gre.c
test/test_gre.py

index db16fa9..83f1283 100644 (file)
@@ -339,7 +339,7 @@ gre46_fixup (vlib_main_t * vm,
    * at the midchain node */
   ip0->ip6.payload_length =
     clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
-                         sizeof (*ip0));
+                         sizeof (ip0->ip6));
   tunnel_encap_fixup_4o6 (flags, (ip4_header_t *) (ip0 + 1), &ip0->ip6);
 }
 
@@ -357,7 +357,7 @@ gre66_fixup (vlib_main_t * vm,
    * at the midchain node */
   ip0->ip6.payload_length =
     clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
-                         sizeof (*ip0));
+                         sizeof (ip0->ip6));
   tunnel_encap_fixup_6o6 (flags, (ip6_header_t *) (ip0 + 1), &ip0->ip6);
 }
 
@@ -365,15 +365,15 @@ static void
 grex6_fixup (vlib_main_t * vm,
             const ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
 {
-  ip6_header_t *ip0;
+  ip6_and_gre_header_t *ip0;
 
   ip0 = vlib_buffer_get_current (b0);
 
   /* Fixup the payload length field in the GRE tunnel encap that was applied
    * at the midchain node */
-  ip0->payload_length =
+  ip0->ip6.payload_length =
     clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) -
-                         sizeof (*ip0));
+                         sizeof (ip0->ip6));
 }
 
 /**
index 74dd5ed..858d943 100644 (file)
@@ -244,6 +244,7 @@ class TestGRE(VppTestCase):
                 self.assertEqual(rx_ip.src, tunnel_src)
                 self.assertEqual(rx_ip.dst, tunnel_dst)
                 self.assertEqual(rx_ip.tos, tos)
+                self.assertEqual(rx_ip.len, len(rx_ip))
 
                 rx_gre = rx[GRE]
                 rx_ip = rx_gre[IP]
@@ -278,6 +279,9 @@ class TestGRE(VppTestCase):
                 self.assertEqual(rx_ip.tc, tc)
 
                 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
+
+                self.assertEqual(rx_ip.plen, len(rx_gre))
+
                 rx_ip = rx_gre[IPv6]
 
                 self.assertEqual(rx_ip.src, tx_ip.src)
@@ -304,6 +308,9 @@ class TestGRE(VppTestCase):
                 self.assertEqual(rx_ip.dst, tunnel_dst)
 
                 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
+
+                self.assertEqual(rx_ip.plen, len(rx_gre))
+
                 tx_ip = tx[IP]
                 rx_ip = rx_gre[IP]
 
@@ -329,6 +336,7 @@ class TestGRE(VppTestCase):
 
                 self.assertEqual(rx_ip.src, tunnel_src)
                 self.assertEqual(rx_ip.dst, tunnel_dst)
+                self.assertEqual(rx_ip.len, len(rx_ip))
 
                 rx_gre = GRE(scapy.compat.raw(rx_ip[IP].payload))
                 rx_ip = rx_gre[IPv6]
@@ -356,6 +364,7 @@ class TestGRE(VppTestCase):
 
                 self.assertEqual(rx_ip.src, tunnel_src)
                 self.assertEqual(rx_ip.dst, tunnel_dst)
+                self.assertEqual(rx_ip.len, len(rx_ip))
 
                 rx_gre = rx[GRE]
                 rx_l2 = rx_gre[Ether]