Skip to content

Commit 0c6c9b1

Browse files
fomichevMartin KaFai Lau
authored andcommitted
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: 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>
1 parent a9c2a60 commit 0c6c9b1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

tools/net/ynl/generated/netdev-user.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,26 @@ const char *netdev_xdp_act_str(enum netdev_xdp_act value)
4545
return netdev_xdp_act_strmap[value];
4646
}
4747

48+
static const char * const netdev_xdp_rx_metadata_strmap[] = {
49+
[0] = "timestamp",
50+
[1] = "hash",
51+
};
52+
53+
const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value)
54+
{
55+
value = ffs(value) - 1;
56+
if (value < 0 || value >= (int)MNL_ARRAY_SIZE(netdev_xdp_rx_metadata_strmap))
57+
return NULL;
58+
return netdev_xdp_rx_metadata_strmap[value];
59+
}
60+
4861
/* Policies */
4962
struct ynl_policy_attr netdev_dev_policy[NETDEV_A_DEV_MAX + 1] = {
5063
[NETDEV_A_DEV_IFINDEX] = { .name = "ifindex", .type = YNL_PT_U32, },
5164
[NETDEV_A_DEV_PAD] = { .name = "pad", .type = YNL_PT_IGNORE, },
5265
[NETDEV_A_DEV_XDP_FEATURES] = { .name = "xdp-features", .type = YNL_PT_U64, },
5366
[NETDEV_A_DEV_XDP_ZC_MAX_SEGS] = { .name = "xdp-zc-max-segs", .type = YNL_PT_U32, },
67+
[NETDEV_A_DEV_XDP_RX_METADATA_FEATURES] = { .name = "xdp-rx-metadata-features", .type = YNL_PT_U64, },
5468
};
5569

5670
struct ynl_policy_nest netdev_dev_nest = {
@@ -97,6 +111,11 @@ int netdev_dev_get_rsp_parse(const struct nlmsghdr *nlh, void *data)
97111
return MNL_CB_ERROR;
98112
dst->_present.xdp_zc_max_segs = 1;
99113
dst->xdp_zc_max_segs = mnl_attr_get_u32(attr);
114+
} else if (type == NETDEV_A_DEV_XDP_RX_METADATA_FEATURES) {
115+
if (ynl_attr_validate(yarg, attr))
116+
return MNL_CB_ERROR;
117+
dst->_present.xdp_rx_metadata_features = 1;
118+
dst->xdp_rx_metadata_features = mnl_attr_get_u64(attr);
100119
}
101120
}
102121

tools/net/ynl/generated/netdev-user.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern const struct ynl_family ynl_netdev_family;
1818
/* Enums */
1919
const char *netdev_op_str(int op);
2020
const char *netdev_xdp_act_str(enum netdev_xdp_act value);
21+
const char *netdev_xdp_rx_metadata_str(enum netdev_xdp_rx_metadata value);
2122

2223
/* Common nested types */
2324
/* ============== NETDEV_CMD_DEV_GET ============== */
@@ -48,11 +49,13 @@ struct netdev_dev_get_rsp {
4849
__u32 ifindex:1;
4950
__u32 xdp_features:1;
5051
__u32 xdp_zc_max_segs:1;
52+
__u32 xdp_rx_metadata_features:1;
5153
} _present;
5254

5355
__u32 ifindex;
5456
__u64 xdp_features;
5557
__u32 xdp_zc_max_segs;
58+
__u64 xdp_rx_metadata_features;
5659
};
5760

5861
void netdev_dev_get_rsp_free(struct netdev_dev_get_rsp *rsp);

tools/net/ynl/samples/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ include ../Makefile.deps
44

55
CC=gcc
66
CFLAGS=-std=gnu11 -O2 -W -Wall -Wextra -Wno-unused-parameter -Wshadow \
7-
-I../lib/ -I../generated/ -idirafter $(UAPI_PATH)
7+
-I../../../include/uapi -I../lib/ -I../generated/ -idirafter $(UAPI_PATH)
88
ifeq ("$(DEBUG)","1")
99
CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
1010
endif

tools/net/ynl/samples/netdev.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ static void netdev_print_device(struct netdev_dev_get_rsp *d, unsigned int op)
3232
if (!d->_present.xdp_features)
3333
return;
3434

35-
printf("%llx:", d->xdp_features);
35+
printf("xdp-features (%llx):", d->xdp_features);
3636
for (int i = 0; d->xdp_features > 1U << i; i++) {
3737
if (d->xdp_features & (1U << i))
3838
printf(" %s", netdev_xdp_act_str(1 << i));
3939
}
4040

41+
printf(" xdp-rx-metadata-features (%llx):", d->xdp_rx_metadata_features);
42+
for (int i = 0; d->xdp_rx_metadata_features > 1U << i; i++) {
43+
if (d->xdp_rx_metadata_features & (1U << i))
44+
printf(" %s", netdev_xdp_rx_metadata_str(1 << i));
45+
}
46+
4147
printf(" xdp-zc-max-segs=%u", d->xdp_zc_max_segs);
4248

4349
name = netdev_op_str(op);

0 commit comments

Comments
 (0)