Update code to compute checksum for buffer chains 15/15015/2
authorJuraj Sloboda <jsloboda@cisco.com>
Wed, 26 Sep 2018 12:25:32 +0000 (14:25 +0200)
committerJuraj Sloboda <jsloboda@cisco.com>
Tue, 2 Oct 2018 09:00:09 +0000 (09:00 +0000)
Compute ICMP checksum for buffer chains
Fix checksum function for buffer chains

Change-Id: I39b845b94a63c3ab5fc9f6f9ab36cadbc67c104f
Signed-off-by: Juraj Sloboda <jsloboda@cisco.com>
src/plugins/nat/in2out.c
src/plugins/nat/out2in.c
src/vnet/ip/ip.h

index 53aca8b..b610650 100755 (executable)
@@ -632,9 +632,11 @@ icmp_in2out (snat_main_t * sm,
 
   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))
        {
index 985333f..67d831a 100755 (executable)
@@ -508,9 +508,11 @@ icmp_out2in (snat_main_t * sm,
 
   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)
        {
index 50965d4..b114fcb 100644 (file)
@@ -162,7 +162,7 @@ ip_incremental_checksum_buffer (vlib_main_t * vm,
   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))