tcp: custom checksum calculations for Ipv4/Ipv6
[vpp.git] / src / vnet / ip / ip4_forward.c
index 3562f50..40c396c 100644 (file)
@@ -736,9 +736,11 @@ ip4_add_del_interface_address_internal (vlib_main_t * vm,
 
                        return
                          clib_error_create
-                         ("failed to add %U which conflicts with %U for interface %U",
+                         ("failed to add %U on %U which conflicts with %U for interface %U",
                           format_ip4_address_and_length, address,
                           address_length,
+                         format_vnet_sw_if_index_name, vnm,
+                         sw_if_index,
                           format_ip4_address_and_length, x,
                           ia->address_length,
                           format_vnet_sw_if_index_name, vnm,
@@ -1301,10 +1303,6 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
 {
   ip_csum_t sum0;
   u32 ip_header_length, payload_length_host_byte_order;
-  u32 n_this_buffer, n_bytes_left, n_ip_bytes_this_buffer;
-  u16 sum16;
-  u8 *data_this_buffer;
-  u8 length_odd;
 
   /* Initialize checksum with ip header. */
   ip_header_length = ip4_header_bytes (ip0);
@@ -1327,45 +1325,9 @@ ip4_tcp_udp_compute_checksum (vlib_main_t * vm, vlib_buffer_t * p0,
     sum0 =
       ip_csum_with_carry (sum0, clib_mem_unaligned (&ip0->src_address, u64));
 
-  n_bytes_left = n_this_buffer = payload_length_host_byte_order;
-  data_this_buffer = (u8 *) ip0 + ip_header_length;
-  n_ip_bytes_this_buffer =
-    p0->current_length - (((u8 *) ip0 - p0->data) - p0->current_data);
-  if (n_this_buffer + ip_header_length > n_ip_bytes_this_buffer)
-    {
-      n_this_buffer = n_ip_bytes_this_buffer > ip_header_length ?
-       n_ip_bytes_this_buffer - ip_header_length : 0;
-    }
-
-  while (1)
-    {
-      sum0 = ip_incremental_checksum (sum0, data_this_buffer, n_this_buffer);
-      n_bytes_left -= n_this_buffer;
-      if (n_bytes_left == 0)
-       break;
-
-      ASSERT (p0->flags & VLIB_BUFFER_NEXT_PRESENT);
-      if (!(p0->flags & VLIB_BUFFER_NEXT_PRESENT))
-       return 0xfefe;
-
-      length_odd = (n_this_buffer & 1);
-
-      p0 = vlib_get_buffer (vm, p0->next_buffer);
-      data_this_buffer = vlib_buffer_get_current (p0);
-      n_this_buffer = clib_min (p0->current_length, n_bytes_left);
-
-      if (PREDICT_FALSE (length_odd))
-       {
-         /* Prepend a 0 or the resulting checksum will be incorrect. */
-         data_this_buffer--;
-         n_this_buffer++;
-         n_bytes_left++;
-         data_this_buffer[0] = 0;
-       }
-    }
-
-  sum16 = ~ip_csum_fold (sum0);
-  return sum16;
+  return ip_calculate_l4_checksum (vm, p0, sum0,
+                                  payload_length_host_byte_order, (u8 *) ip0,
+                                  ip_header_length, NULL);
 }
 
 u32
@@ -1869,7 +1831,7 @@ VLIB_REGISTER_NODE (ip4_local_node) =
     [IP_LOCAL_NEXT_PUNT] = "ip4-punt",
     [IP_LOCAL_NEXT_UDP_LOOKUP] = "ip4-udp-lookup",
     [IP_LOCAL_NEXT_ICMP] = "ip4-icmp-input",
-    [IP_LOCAL_NEXT_REASSEMBLY] = "ip4-reassembly",
+    [IP_LOCAL_NEXT_REASSEMBLY] = "ip4-full-reassembly",
   },
 };
 /* *INDENT-ON* */