tcp: add no csum offload config option 75/23575/4
authorFlorin Coras <fcoras@cisco.com>
Thu, 21 Nov 2019 02:34:58 +0000 (18:34 -0800)
committerDave Barach <openvpp@barachs.net>
Thu, 21 Nov 2019 20:12:24 +0000 (20:12 +0000)
Type: feature

Change-Id: I77b3ee74229f3c85e99f74bf9000cb5aedbc1760
Signed-off-by: Florin Coras <fcoras@cisco.com>
src/vnet/tcp/tcp.c
src/vnet/tcp/tcp.h
src/vnet/tcp/tcp_output.c

index 8672901..baa5c0d 100644 (file)
@@ -705,6 +705,9 @@ tcp_init_snd_vars (tcp_connection_t * tc)
   tc->snd_nxt = tc->iss + 1;
   tc->snd_una_max = tc->snd_nxt;
   tc->srtt = 100;              /* 100 ms */
+
+  if (!tcp_cfg.csum_offload)
+    tc->cfg_flags |= TCP_CFG_F_NO_CSUM_OFFLOAD;
 }
 
 void
@@ -1656,6 +1659,7 @@ tcp_configuration_init (void)
   tcp_cfg.initial_cwnd_multiplier = 0;
   tcp_cfg.enable_tx_pacing = 1;
   tcp_cfg.allow_tso = 0;
+  tcp_cfg.csum_offload = 1;
   tcp_cfg.cc_algo = TCP_CC_NEWRENO;
   tcp_cfg.rwnd_min_update_ack = 1;
 
@@ -1797,6 +1801,8 @@ tcp_config_fn (vlib_main_t * vm, unformat_input_t * input)
        tcp_cfg.enable_tx_pacing = 0;
       else if (unformat (input, "tso"))
        tcp_cfg.allow_tso = 1;
+      else if (unformat (input, "no-csum-offload"))
+       tcp_cfg.csum_offload = 0;
       else if (unformat (input, "cc-algo %U", unformat_tcp_cc_algo,
                         &tcp_cfg.cc_algo))
        ;
index e9247eb..299e76d 100644 (file)
@@ -558,6 +558,9 @@ typedef struct tcp_configuration_
   /** Allow use of TSO whenever available */
   u8 allow_tso;
 
+  /** Set if csum offloading is enabled */
+  u8 csum_offload;
+
   /** Default congestion control algorithm type */
   tcp_cc_algorithm_type_e cc_algo;
 
index c06bbf1..d6e1adc 100644 (file)
@@ -896,26 +896,15 @@ static void
 tcp_push_ip_hdr (tcp_worker_ctx_t * wrk, tcp_connection_t * tc,
                 vlib_buffer_t * b)
 {
-  tcp_header_t *th = vlib_buffer_get_current (b);
-  vlib_main_t *vm = wrk->vm;
   if (tc->c_is_ip4)
     {
-      ip4_header_t *ih;
-      ih = vlib_buffer_push_ip4 (vm, b, &tc->c_lcl_ip4,
-                                &tc->c_rmt_ip4, IP_PROTOCOL_TCP,
-                                tcp_csum_offload (tc));
-      th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ih);
+      vlib_buffer_push_ip4 (wrk->vm, b, &tc->c_lcl_ip4, &tc->c_rmt_ip4,
+                           IP_PROTOCOL_TCP, tcp_csum_offload (tc));
     }
   else
     {
-      ip6_header_t *ih;
-      int bogus = ~0;
-
-      ih = vlib_buffer_push_ip6_custom (vm, b, &tc->c_lcl_ip6,
-                                       &tc->c_rmt_ip6, IP_PROTOCOL_TCP,
-                                       tc->ipv6_flow_label);
-      th->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ih, &bogus);
-      ASSERT (!bogus);
+      vlib_buffer_push_ip6_custom (wrk->vm, b, &tc->c_lcl_ip6, &tc->c_rmt_ip6,
+                                  IP_PROTOCOL_TCP, tc->ipv6_flow_label);
     }
 }
 
@@ -2270,19 +2259,16 @@ always_inline void
 tcp_output_push_ip (vlib_main_t * vm, vlib_buffer_t * b0,
                    tcp_connection_t * tc0, u8 is_ip4)
 {
-  u8 __clib_unused *ih0;
-  tcp_header_t __clib_unused *th0 = vlib_buffer_get_current (b0);
-
-  TCP_EVT (TCP_EVT_OUTPUT, tc0, th0->flags, b0->current_length);
+  TCP_EVT (TCP_EVT_OUTPUT, tc0,
+          ((tcp_header_t *) vlib_buffer_get_current (b0))->flags,
+          b0->current_length);
 
   if (is_ip4)
-    ih0 = vlib_buffer_push_ip4 (vm, b0, &tc0->c_lcl_ip4, &tc0->c_rmt_ip4,
-                               IP_PROTOCOL_TCP, tcp_csum_offload (tc0));
+    vlib_buffer_push_ip4 (vm, b0, &tc0->c_lcl_ip4, &tc0->c_rmt_ip4,
+                         IP_PROTOCOL_TCP, tcp_csum_offload (tc0));
   else
-    ih0 =
-      vlib_buffer_push_ip6_custom (vm, b0, &tc0->c_lcl_ip6, &tc0->c_rmt_ip6,
-                                  IP_PROTOCOL_TCP, tc0->ipv6_flow_label);
-
+    vlib_buffer_push_ip6_custom (vm, b0, &tc0->c_lcl_ip6, &tc0->c_rmt_ip6,
+                                IP_PROTOCOL_TCP, tc0->ipv6_flow_label);
 }
 
 always_inline void