Commit 0c6c9b10 authored by Stanislav Fomichev's avatar Stanislav Fomichev Committed by Martin KaFai Lau

tools: ynl: extend netdev sample to dump xdp-rx-metadata-features

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: default avatarStanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/r/20230913171350.369987-4-sdf@google.comSigned-off-by: default avatarMartin KaFai Lau <martin.lau@kernel.org>
parent a9c2a608
...@@ -45,12 +45,26 @@ const char *netdev_xdp_act_str(enum netdev_xdp_act value) ...@@ -45,12 +45,26 @@ const char *netdev_xdp_act_str(enum netdev_xdp_act value)
return netdev_xdp_act_strmap[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 */ /* Policies */
struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = { 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_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, },
[NETDEV_A_DEV_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, }, [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_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_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 = { struct ynl_policy_nest netdev_dev_nest = {
...@@ -97,6 +111,11 @@ int netdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data) ...@@ -97,6 +111,11 @@ int netdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
return MNL_CB_ERROR; return MNL_CB_ERROR;
dst->_present.xdp_zc_max_segs = 1; dst->_present.xdp_zc_max_segs = 1;
dst->xdp_zc_max_segs = mnl_attr_get_u32(attr); 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);
} }
} }
......
...@@ -18,6 +18,7 @@ extern const struct ynl_family ynl_netdev_family; ...@@ -18,6 +18,7 @@ extern const struct ynl_family ynl_netdev_family;
/* Enums */ /* Enums */
const char *netdev_op_str(int op); const char *netdev_op_str(int op);
const char *netdev_xdp_act_str(enum netdev_xdp_act value); 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 */ /* Common nested types */
/* ============== NETDEV_CMD_DEV_GET ============== */ /* ============== NETDEV_CMD_DEV_GET ============== */
...@@ -48,11 +49,13 @@ struct netdev_dev_get_rsp { ...@@ -48,11 +49,13 @@ struct netdev_dev_get_rsp {
__u32 ifindex:1; __u32 ifindex:1;
__u32 xdp_features:1; __u32 xdp_features:1;
__u32 xdp_zc_max_segs:1; __u32 xdp_zc_max_segs:1;
__u32 xdp_rx_metadata_features:1;
} _present; } _present;
__u32 ifindex; __u32 ifindex;
__u64 xdp_features; __u64 xdp_features;
__u32 xdp_zc_max_segs; __u32 xdp_zc_max_segs;
__u64 xdp_rx_metadata_features;
}; };
void netdev_dev_get_rsp_free(struct netdev_dev_get_rsp *rsp); void netdev_dev_get_rsp_free(struct netdev_dev_get_rsp *rsp);
......
...@@ -4,7 +4,7 @@ include ../Makefile.deps ...@@ -4,7 +4,7 @@ include ../Makefile.deps
CC=gcc CC=gcc
CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \ 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") ifeq ("$(DEBUG)","1")
CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
endif endif
......
...@@ -32,12 +32,18 @@ static void netdev_print_device(struct netdev_dev_get_rsp *d, unsigned int op) ...@@ -32,12 +32,18 @@ static void netdev_print_device(struct netdev_dev_get_rsp *d, unsigned int op)
if (!d->_present.xdp_features) if (!d->_present.xdp_features)
return; return;
printf("%llx:", d->xdp_features); printf("xdp-features (%llx):", d->xdp_features);
for (int i = 0; d->xdp_features > 1U << i; i++) { for (int i = 0; d->xdp_features > 1U << i; i++) {
if (d->xdp_features & (1U << i)) if (d->xdp_features & (1U << i))
printf(" %s", netdev_xdp_act_str(1 << 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); printf(" xdp-zc-max-segs=%u", d->xdp_zc_max_segs);
name = netdev_op_str(op); name = netdev_op_str(op);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment