Update code to compute checksum for buffer chains

Compute ICMP checksum for buffer chains
Fix checksum function for buffer chains

Change-Id: I39b845b94a63c3ab5fc9f6f9ab36cadbc67c104f
Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
diff --git a/src/plugins/nat/in2out.c b/src/plugins/nat/in2out.c
index 53aca8b..b610650 100755
--- a/src/plugins/nat/in2out.c
+++ b/src/plugins/nat/in2out.c
@@ -632,9 +632,11 @@
 
   if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
     {
-      sum0 = ip_incremental_checksum (0, icmp0,
-				      ntohs (ip0->length) -
-				      ip4_header_bytes (ip0));
+      sum0 = ip_incremental_checksum_buffer (sm->vlib_main, b0, (u8 *) icmp0 -
+					     (u8 *)
+					     vlib_buffer_get_current (b0),
+					     ntohs (ip0->length) -
+					     ip4_header_bytes (ip0), 0);
       checksum0 = ~ip_csum_fold (sum0);
       if (PREDICT_FALSE (checksum0 != 0 && checksum0 != 0xffff))
 	{
diff --git a/src/plugins/nat/out2in.c b/src/plugins/nat/out2in.c
index 985333f..67d831a 100755
--- a/src/plugins/nat/out2in.c
+++ b/src/plugins/nat/out2in.c
@@ -508,9 +508,11 @@
 
   if (PREDICT_TRUE (!ip4_is_fragment (ip0)))
     {
-      sum0 = ip_incremental_checksum (0, icmp0,
-				      ntohs (ip0->length) -
-				      ip4_header_bytes (ip0));
+      sum0 = ip_incremental_checksum_buffer (sm->vlib_main, b0, (u8 *) icmp0 -
+					     (u8 *)
+					     vlib_buffer_get_current (b0),
+					     ntohs (ip0->length) -
+					     ip4_header_bytes (ip0), 0);
       checksum0 = ~ip_csum_fold (sum0);
       if (checksum0 != 0 && checksum0 != 0xffff)
 	{
diff --git a/src/vnet/ip/ip.h b/src/vnet/ip/ip.h
index 50965d4..b114fcb 100644
--- a/src/vnet/ip/ip.h
+++ b/src/vnet/ip/ip.h
@@ -162,7 +162,7 @@
   void *h;
   u32 n;
 
-  n = clib_min (n_bytes_left, b->current_length);
+  n = clib_min (n_bytes_left, b->current_length - first_buffer_offset);
   h = vlib_buffer_get_current (b) + first_buffer_offset;
   sum = ip_incremental_checksum (sum, h, n);
   if (PREDICT_FALSE (b->flags & VLIB_BUFFER_NEXT_PRESENT))