]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tools: ynl: extend netdev sample to dump xdp-rx-metadata-features
authorStanislav Fomichev <sdf@google.com>
Wed, 13 Sep 2023 17:13:50 +0000 (10:13 -0700)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 15 Sep 2023 18:26:58 +0000 (11:26 -0700)
The tool can be used to verify that everything works end to end.

Unrelated updates:
- include tools/include/uapi to pick the latest kernel uapi headers
- print "xdp-features" and "xdp-rx-metadata-features" so it's clear
  which bitmask is being dumped

Cc: netdev@vger.kernel.org
Cc: Willem de Bruijn <willemb@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20230913171350.369987-4-sdf@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/net/ynl/generated/netdev-user.c
tools/net/ynl/generated/netdev-user.h
tools/net/ynl/samples/Makefile
tools/net/ynl/samples/netdev.c

index 68b408ca0f7f18b048364e38ab369f885503632a..b5ffe8cd1144ad7b6105f76f2769553f66a523e2 100644 (file)
@@ -45,12 +45,26 @@ const char *netdev_xdp_act_str(enum netdev_xdp_act value)
        return netdev_xdp_act_strmap[value];
 }
 
+static const char * const netdev_xdp_rx_metadata_strmap[] = {
+       [0] = "timestamp",
+       [1] = "hash",
+};
+
+const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value)
+{
+       value = ffs(value) - 1;
+       if (value < 0 || value >= (int)MNL_ARRAY_SIZE(netdev_xdp_rx_metadata_strmap))
+               return NULL;
+       return netdev_xdp_rx_metadata_strmap[value];
+}
+
 /* Policies */
 struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = {
        [NETDEV_A_DEV_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, },
        [NETDEV_A_DEV_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, },
        [NETDEV_A_DEV_XDP_FEATURES] = { .name = "xdp-features", .type = YNL_PT_U64, },
        [NETDEV_A_DEV_XDP_ZC_MAX_SEGS] = { .name = "xdp-zc-max-segs", .type = YNL_PT_U32, },
+       [NETDEV_A_DEV_XDP_RX_METADATA_FEATURES] = { .name = "xdp-rx-metadata-features", .type = YNL_PT_U64, },
 };
 
 struct ynl_policy_nest netdev_dev_nest = {
@@ -97,6 +111,11 @@ int netdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
                                return MNL_CB_ERROR;
                        dst->_present.xdp_zc_max_segs = 1;
                        dst->xdp_zc_max_segs = mnl_attr_get_u32(attr);
+               } else if (type == NETDEV_A_DEV_XDP_RX_METADATA_FEATURES) {
+                       if (ynl_attr_validate(yarg, attr))
+                               return MNL_CB_ERROR;
+                       dst->_present.xdp_rx_metadata_features = 1;
+                       dst->xdp_rx_metadata_features = mnl_attr_get_u64(attr);
                }
        }
 
index 0952d3261f4d51d86509eea376e6931af65b02a8..b4351ff3459551901fc7e84916982b630d68f208 100644 (file)
@@ -18,6 +18,7 @@ extern const struct ynl_family ynl_netdev_family;
 /* Enums */
 const char *netdev_op_str(int op);
 const char *netdev_xdp_act_str(enum netdev_xdp_act value);
+const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value);
 
 /* Common nested types */
 /* ============== NETDEV_CMD_DEV_GET ============== */
@@ -48,11 +49,13 @@ struct netdev_dev_get_rsp {
                __u32 ifindex:1;
                __u32 xdp_features:1;
                __u32 xdp_zc_max_segs:1;
+               __u32 xdp_rx_metadata_features:1;
        } _present;
 
        __u32 ifindex;
        __u64 xdp_features;
        __u32 xdp_zc_max_segs;
+       __u64 xdp_rx_metadata_features;
 };
 
 void netdev_dev_get_rsp_free(struct netdev_dev_get_rsp *rsp);
index f2db8bb7830952ee51cfa7d62e3a6ccefe442340..32abbc0af39eb98a9d9a22054281bd31be7eb6b3 100644 (file)
@@ -4,7 +4,7 @@ include ../Makefile.deps
 
 CC=gcc
 CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
-       -I../lib/ -I../generated/ -idirafter $(UAPI_PATH)
+       -I../../../include/uapi -I../lib/ -I../generated/ -idirafter $(UAPI_PATH)
 ifeq ("$(DEBUG)","1")
   CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
 endif
index 06433400ddddb3b9b7a0d61c57702191c0ed9f86..b828225daad041136524013e2595fae285f636a1 100644 (file)
@@ -32,12 +32,18 @@ static void netdev_print_device(struct netdev_dev_get_rsp *d, unsigned int op)
        if (!d->_present.xdp_features)
                return;
 
-       printf("%llx:", d->xdp_features);
+       printf("xdp-features (%llx):", d->xdp_features);
        for (int i = 0; d->xdp_features > 1U << i; i++) {
                if (d->xdp_features & (1U << i))
                        printf(" %s", netdev_xdp_act_str(1 << i));
        }
 
+       printf(" xdp-rx-metadata-features (%llx):", d->xdp_rx_metadata_features);
+       for (int i = 0; d->xdp_rx_metadata_features > 1U << i; i++) {
+               if (d->xdp_rx_metadata_features & (1U << i))
+                       printf(" %s", netdev_xdp_rx_metadata_str(1 << i));
+       }
+
        printf(" xdp-zc-max-segs=%u", d->xdp_zc_max_segs);
 
        name = netdev_op_str(op);