devices: add cli support for checksum and gso disable 92/35892/6
authorMohsin Kazmi <sykazmi@cisco.com>
Tue, 5 Apr 2022 12:43:13 +0000 (12:43 +0000)
committerBeno�t Ganne <bganne@cisco.com>
Thu, 7 Apr 2022 11:22:41 +0000 (11:22 +0000)
Type: improvement

Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Change-Id: I33a29cf11998736347eca5016eee112619d847c1

src/vnet/devices/af_packet/af_packet.c
src/vnet/devices/af_packet/af_packet.h
src/vnet/devices/af_packet/af_packet_api.c
src/vnet/devices/af_packet/cli.c
src/vnet/devices/af_packet/device.c

index a8ab944..fd2f6fc 100644 (file)
@@ -191,7 +191,7 @@ af_packet_set_tx_queues (vlib_main_t *vm, af_packet_if_t *apif)
 static int
 create_packet_v3_sock (int host_if_index, tpacket_req3_t *rx_req,
                       tpacket_req3_t *tx_req, int *fd, af_packet_ring_t *ring,
-                      u8 *is_cksum_gso_enabled, u32 fanout_id, u8 is_fanout,
+                      u32 fanout_id, u8 is_fanout,
                       af_packet_if_flags_t *flags)
 {
   af_packet_main_t *apm = &af_packet_main;
@@ -250,16 +250,21 @@ create_packet_v3_sock (int host_if_index, tpacket_req3_t *rx_req,
       goto error;
     }
 
-  int opt2 = 1;
-  if (setsockopt (*fd, SOL_PACKET, PACKET_VNET_HDR, &opt2, sizeof (opt2)) < 0)
+  if (*flags & AF_PACKET_IF_FLAGS_CKSUM_GSO)
     {
-      vlib_log_debug (
-       apm->log_class,
-       "Failed to set packet vnet hdr error handling option: %s (errno %d)",
-       strerror (errno), errno);
+
+      int opt2 = 1;
+      if (setsockopt (*fd, SOL_PACKET, PACKET_VNET_HDR, &opt2, sizeof (opt2)) <
+         0)
+       {
+         // remove the flag
+         *flags &= ~AF_PACKET_IF_FLAGS_CKSUM_GSO;
+         vlib_log_debug (apm->log_class,
+                         "Failed to set packet vnet hdr error handling "
+                         "option: %s (errno %d)",
+                         strerror (errno), errno);
+       }
     }
-  else
-    *is_cksum_gso_enabled = 1;
 
 #if defined(PACKET_QDISC_BYPASS)
   if (*flags & AF_PACKET_IF_FLAGS_QDISC_BYPASS)
@@ -347,7 +352,6 @@ af_packet_queue_init (vlib_main_t *vm, af_packet_if_t *apif,
   u32 rx_frames_per_block, tx_frames_per_block;
   u32 rx_frame_size, tx_frame_size;
   u32 i = 0;
-  u8 is_cksum_gso_enabled = 0;
 
   if (rx_queue)
     {
@@ -391,9 +395,9 @@ af_packet_queue_init (vlib_main_t *vm, af_packet_if_t *apif,
 
   if (rx_queue || tx_queue)
     {
-      ret = create_packet_v3_sock (apif->host_if_index, rx_req, tx_req, &fd,
-                                  &ring, &is_cksum_gso_enabled,
-                                  apif->dev_instance, is_fanout, &arg->flags);
+      ret =
+       create_packet_v3_sock (apif->host_if_index, rx_req, tx_req, &fd, &ring,
+                              apif->dev_instance, is_fanout, &arg->flags);
 
       if (ret != 0)
        goto error;
@@ -434,9 +438,6 @@ af_packet_queue_init (vlib_main_t *vm, af_packet_if_t *apif,
       clib_spinlock_init (&tx_queue->lockp);
     }
 
-  if (queue_id == 0)
-    apif->is_cksum_gso_enabled = is_cksum_gso_enabled;
-
   return 0;
 error:
   vlib_log_err (apm->log_class, "Failed to set queue %u error", queue_id);
@@ -648,6 +649,9 @@ af_packet_create_if (af_packet_create_if_arg_t *arg)
   apif->is_qdisc_bypass_enabled =
     (arg->flags & AF_PACKET_IF_FLAGS_QDISC_BYPASS);
 
+  if (arg->flags & AF_PACKET_IF_FLAGS_CKSUM_GSO)
+    apif->is_cksum_gso_enabled = 1;
+
   if (apif->is_cksum_gso_enabled)
     caps |= VNET_HW_IF_CAP_TCP_GSO | VNET_HW_IF_CAP_TX_IP4_CKSUM |
            VNET_HW_IF_CAP_TX_TCP_CKSUM | VNET_HW_IF_CAP_TX_UDP_CKSUM;
index 2b05125..64daaa1 100644 (file)
@@ -35,6 +35,7 @@ typedef enum
 typedef enum
 {
   AF_PACKET_IF_FLAGS_QDISC_BYPASS = 1,
+  AF_PACKET_IF_FLAGS_CKSUM_GSO = 2,
 } af_packet_if_flags_t;
 
 typedef struct
index 2a58ba7..d991a2e 100644 (file)
@@ -48,7 +48,7 @@ vl_api_af_packet_create_t_handler (vl_api_af_packet_create_t * mp)
   arg->hw_addr = mp->use_random_hw_addr ? 0 : mp->hw_addr;
   arg->mode = AF_PACKET_IF_MODE_ETHERNET;
   // Default flags
-  arg->flags = AF_PACKET_IF_FLAGS_QDISC_BYPASS;
+  arg->flags = AF_PACKET_IF_FLAGS_QDISC_BYPASS | AF_PACKET_IF_FLAGS_CKSUM_GSO;
   rv = af_packet_create_if (arg);
 
   vec_free (arg->host_if_name);
@@ -80,7 +80,7 @@ vl_api_af_packet_create_v2_t_handler (vl_api_af_packet_create_v2_t *mp)
   arg->hw_addr = mp->use_random_hw_addr ? 0 : mp->hw_addr;
   arg->mode = AF_PACKET_IF_MODE_ETHERNET;
   // Default flags
-  arg->flags = AF_PACKET_IF_FLAGS_QDISC_BYPASS;
+  arg->flags = AF_PACKET_IF_FLAGS_QDISC_BYPASS | AF_PACKET_IF_FLAGS_CKSUM_GSO;
 
   if (mp->num_rx_queues > 1)
     arg->num_rxqs = clib_net_to_host_u16 (mp->num_rx_queues);
index 443a1d5..e730659 100644 (file)
@@ -59,7 +59,7 @@ af_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
   arg->num_txqs = 1;
 
   // Default flags
-  arg->flags = AF_PACKET_IF_FLAGS_QDISC_BYPASS;
+  arg->flags = AF_PACKET_IF_FLAGS_QDISC_BYPASS | AF_PACKET_IF_FLAGS_CKSUM_GSO;
 
   /* Get a line of input. */
   if (!unformat_user (input, unformat_line_input, line_input))
@@ -85,6 +85,8 @@ af_packet_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
        ;
       else if (unformat (line_input, "qdisc-bypass-disable"))
        arg->flags &= ~AF_PACKET_IF_FLAGS_QDISC_BYPASS;
+      else if (unformat (line_input, "cksum-gso-disable"))
+       arg->flags &= ~AF_PACKET_IF_FLAGS_CKSUM_GSO;
       else if (unformat (line_input, "mode ip"))
        arg->mode = AF_PACKET_IF_MODE_IP;
       else if (unformat (line_input, "hw-addr %U", unformat_ethernet_address,
@@ -160,7 +162,7 @@ VLIB_CLI_COMMAND (af_packet_create_command, static) = {
   .path = "create host-interface",
   .short_help = "create host-interface name <ifname> [num-rx-queues <n>] "
                "[num-tx-queues <n>] [hw-addr <mac-addr>] [mode ip] "
-               "[qdisc-bypass-disable]",
+               "[qdisc-bypass-disable] [cksum-gso-disable]",
   .function = af_packet_create_command_fn,
 };
 
index 214aa01..822dcdc 100644 (file)
@@ -95,6 +95,8 @@ format_af_packet_device (u8 * s, va_list * args)
   s = format (s, "\n%UFEATURES:", format_white_space, indent);
   if (apif->is_qdisc_bypass_enabled)
     s = format (s, "\n%Uqdisc-bpass-enabled", format_white_space, indent + 2);
+  if (apif->is_cksum_gso_enabled)
+    s = format (s, "\n%Ucksum-gso-enabled", format_white_space, indent + 2);
 
   vec_foreach (rx_queue, apif->rx_queues)
     {