Fix IPv6 csum calculation in GTP-U encapsulation

The length field is included in the checksum. Therefor, we need
to update it before calculating the checksum.

Change-Id: Id23234efb80ea3747a0f8a5c7bf8621748d27635
Signed-off-by: Andreas Schultz <andreas.schultz@travelping.com>
diff --git a/src/plugins/gtpu/gtpu_encap.c b/src/plugins/gtpu/gtpu_encap.c
index 4442c42..5f52d5a 100644
--- a/src/plugins/gtpu/gtpu_encap.c
+++ b/src/plugins/gtpu/gtpu_encap.c
@@ -380,24 +380,6 @@
 	      udp3->length = new_l3;
 	      udp3->src_port = flow_hash3;
 
-	      /* IPv6 UDP checksum is mandatory */
-	      udp0->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b0,
-								 ip6_0, &bogus);
-	      if (udp0->checksum == 0)
-		udp0->checksum = 0xffff;
-	      udp1->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b1,
-                                                        ip6_1, &bogus);
-	      if (udp1->checksum == 0)
-		udp1->checksum = 0xffff;
-	      udp2->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b2,
-								 ip6_2, &bogus);
-	      if (udp2->checksum == 0)
-		udp2->checksum = 0xffff;
-	      udp3->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b3,
-                                                        ip6_3, &bogus);
-	      if (udp3->checksum == 0)
-		udp3->checksum = 0xffff;
-
 	      /* Fix GTPU length */
 	      gtpu0 = (gtpu_header_t *)(udp0+1);
 	      new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
@@ -419,6 +401,25 @@
 					     - sizeof (*ip6_3) - sizeof(*udp3)
 					     - GTPU_V1_HDR_LEN);
 	      gtpu3->length = new_l3;
+
+	      /* IPv6 UDP checksum is mandatory */
+	      udp0->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b0,
+								 ip6_0, &bogus);
+	      if (udp0->checksum == 0)
+		udp0->checksum = 0xffff;
+	      udp1->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b1,
+								 ip6_1, &bogus);
+	      if (udp1->checksum == 0)
+		udp1->checksum = 0xffff;
+	      udp2->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b2,
+								 ip6_2, &bogus);
+	      if (udp2->checksum == 0)
+		udp2->checksum = 0xffff;
+	      udp3->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b3,
+								 ip6_3, &bogus);
+	      if (udp3->checksum == 0)
+		udp3->checksum = 0xffff;
+
 	    }
 
           pkts_encapsulated += 4;
@@ -592,18 +593,18 @@
 	      udp0->length = new_l0;
 	      udp0->src_port = flow_hash0;
 
-	      /* IPv6 UDP checksum is mandatory */
-	      udp0->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b0,
-								 ip6_0, &bogus);
-	      if (udp0->checksum == 0)
-		udp0->checksum = 0xffff;
-
 	      /* Fix GTPU length */
 	      gtpu0 = (gtpu_header_t *)(udp0+1);
 	      new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain(vm, b0)
 					     - sizeof (*ip4_0) - sizeof(*udp0)
 					     - GTPU_V1_HDR_LEN);
 	      gtpu0->length = new_l0;
+
+	      /* IPv6 UDP checksum is mandatory */
+	      udp0->checksum = ip6_tcp_udp_icmp_compute_checksum(vm, b0,
+								 ip6_0, &bogus);
+	      if (udp0->checksum == 0)
+		udp0->checksum = 0xffff;
 	    }
 
           pkts_encapsulated ++;