af_packet: show host interface offload flags 87/42887/4
authorMohsin Kazmi <[email protected]>
Tue, 20 May 2025 15:29:50 +0000 (15:29 +0000)
committerFlorin Coras <[email protected]>
Wed, 21 May 2025 18:06:05 +0000 (18:06 +0000)
Type: improvement

This patch implements support to show host interface offload
flags at the time of creation. It also shows host interface
offload flags at the time of calling given function through
'show hardware'.

Before:
  Host Interface Offload:
    creation time:
     rx checksum
     tx checksum
     tcp segmentation offload
     generic segemanttaion offload
    now:
     rx checksum
     tx checksum
     tcp segmentation offload
     generic segemanttaion offload

After changing the offloads on the veth using ethtool command ('ethtool -K veth1 rx off tx off'):
  Host Interface Offload:
    creation time:
     rx checksum
     tx checksum
     tcp segmentation offload
     generic segemanttaion offload
    now:
     generic segemanttaion offload

Signed-off-by: Mohsin Kazmi <[email protected]>
Change-Id: Ia38d35e7a70206781afad42f0333e47bac8fedc9

src/plugins/af_packet/af_packet.c
src/plugins/af_packet/af_packet.h
src/plugins/af_packet/device.c

index f3a1f49..e3e67fb 100644 (file)
@@ -61,20 +61,6 @@ VNET_HW_INTERFACE_CLASS (af_packet_ip_device_hw_interface_class, static) = {
 /*defined in net/if.h but clashes with dpdk headers */
 unsigned int if_nametoindex (const char *ifname);
 
-#define AF_PACKET_OFFLOAD_FLAG_RXCKSUM (1 << 0)
-#define AF_PACKET_OFFLOAD_FLAG_TXCKSUM (1 << 1)
-#define AF_PACKET_OFFLOAD_FLAG_SG      (1 << 2)
-#define AF_PACKET_OFFLOAD_FLAG_TSO     (1 << 3)
-#define AF_PACKET_OFFLOAD_FLAG_UFO     (1 << 4)
-#define AF_PACKET_OFFLOAD_FLAG_GSO     (1 << 5)
-#define AF_PACKET_OFFLOAD_FLAG_GRO     (1 << 6)
-
-#define AF_PACKET_OFFLOAD_FLAG_MASK                                           \
-  (AF_PACKET_OFFLOAD_FLAG_RXCKSUM | AF_PACKET_OFFLOAD_FLAG_TXCKSUM |          \
-   AF_PACKET_OFFLOAD_FLAG_SG | AF_PACKET_OFFLOAD_FLAG_TSO |                   \
-   AF_PACKET_OFFLOAD_FLAG_UFO | AF_PACKET_OFFLOAD_FLAG_GSO |                  \
-   AF_PACKET_OFFLOAD_FLAG_GRO)
-
 #define AF_PACKET_IOCTL(fd, a, ...)                                           \
   if (ioctl (fd, a, __VA_ARGS__) < 0)                                         \
     {                                                                         \
@@ -83,7 +69,7 @@ unsigned int if_nametoindex (const char *ifname);
       goto done;                                                              \
     }
 
-static u32
+u32
 af_packet_get_if_capabilities (u8 *host_if_name)
 {
   struct ifreq ifr;
index e66a111..9b7c55c 100644 (file)
@@ -48,6 +48,28 @@ typedef enum
   AF_PACKET_IF_FLAGS_VERSION_2 = 8,
 } af_packet_if_flags_t;
 
+#define foreach_af_packet_offload_flag                                        \
+  _ (RXCKSUM, 0, "rx checksum")                                               \
+  _ (TXCKSUM, 1, "tx checksum")                                               \
+  _ (SG, 2, "scatter-gather")                                                 \
+  _ (TSO, 3, "tcp segmentation offload")                                      \
+  _ (UFO, 4, "udp fragmentation offload")                                     \
+  _ (GSO, 5, "generic segmentation offload")                                  \
+  _ (GRO, 6, "generic receive offload")
+
+typedef enum
+{
+#define _(o, n, s) AF_PACKET_OFFLOAD_FLAG_##o = (1 << n),
+  foreach_af_packet_offload_flag
+#undef _
+} af_packet_offload_flag_t;
+
+#define AF_PACKET_OFFLOAD_FLAG_MASK                                           \
+  (AF_PACKET_OFFLOAD_FLAG_RXCKSUM | AF_PACKET_OFFLOAD_FLAG_TXCKSUM |          \
+   AF_PACKET_OFFLOAD_FLAG_SG | AF_PACKET_OFFLOAD_FLAG_TSO |                   \
+   AF_PACKET_OFFLOAD_FLAG_UFO | AF_PACKET_OFFLOAD_FLAG_GSO |                  \
+   AF_PACKET_OFFLOAD_FLAG_GRO)
+
 typedef struct
 {
   u32 sw_if_index;
@@ -122,7 +144,7 @@ typedef struct
   u8 is_qdisc_bypass_enabled;
   u8 is_fanout_enabled;
   int *fds;
-  u32 host_interface_oflags;
+  af_packet_offload_flag_t host_interface_oflags;
 } af_packet_if_t;
 
 typedef struct
@@ -168,6 +190,7 @@ int af_packet_delete_if (u8 *host_if_name);
 int af_packet_set_l4_cksum_offload (u32 sw_if_index, u8 set);
 int af_packet_enable_disable_qdisc_bypass (u32 sw_if_index, u8 enable_disable);
 int af_packet_dump_ifs (af_packet_if_detail_t ** out_af_packet_ifs);
+u32 af_packet_get_if_capabilities (u8 *host_if_name);
 
 format_function_t format_af_packet_device_name;
 
index 79e3d7b..797666a 100644 (file)
@@ -100,6 +100,21 @@ format_af_packet_device_name (u8 * s, va_list * args)
 }
 #endif /* CLIB_MARCH_VARIANT */
 
+static u8 *
+format_af_packet_offload_flag (u8 *s, va_list *args)
+{
+  af_packet_offload_flag_t af_oflags =
+    va_arg (*args, af_packet_offload_flag_t);
+  u32 indent = va_arg (*args, u32);
+
+#define _(o, n, str)                                                          \
+  if (af_oflags & AF_PACKET_OFFLOAD_FLAG_##o)                                 \
+    s = format (s, "\n%U%s", format_white_space, indent + 3, str);
+  foreach_af_packet_offload_flag
+#undef _
+    return s;
+}
+
 static u8 *
 format_af_packet_device (u8 * s, va_list * args)
 {
@@ -121,6 +136,13 @@ format_af_packet_device (u8 * s, va_list * args)
     s = format (s, "\n%Ucksum-gso-enabled", format_white_space, indent + 2);
   if (apif->is_fanout_enabled)
     s = format (s, "\n%Ufanout-enabled", format_white_space, indent + 2);
+  s = format (s, "\n%UHost Interface Offload:", format_white_space, indent);
+  s = format (s, "\n%Ucreation time:%U", format_white_space, indent + 2,
+             format_af_packet_offload_flag, apif->host_interface_oflags,
+             indent);
+  s = format (s, "\n%Unow:%U", format_white_space, indent + 2,
+             format_af_packet_offload_flag,
+             af_packet_get_if_capabilities (apif->host_if_name), indent);
 
   vec_foreach (rx_queue, apif->rx_queues)
     {