[[RFC xdp-hints] 03/16] tools/bpf: Query XDP metadata BTF ID

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Saeed Mahameed <saeedm@xxxxxxxxxxxx>

When dumping bpf net information, also query XDP MD BTF attributes:

$ /usr/local/sbin/bpftool net
xdp:
mlx0(3) md_btf_id(1) md_btf_enabled(0)

tc:

flow_dissector:

Issue: 2114293
Change-Id: Ifef542ecf3defe4204947618c07cc3eac45b39f9
Signed-off-by: Saeed Mahameed <saeedm@xxxxxxxxxxxx>
---
 tools/bpf/bpftool/netlink_dumper.c | 21 +++++++++++++++++----
 tools/include/uapi/linux/if_link.h |  2 ++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/bpf/bpftool/netlink_dumper.c b/tools/bpf/bpftool/netlink_dumper.c
index 5f65140b003b..17807a3312ff 100644
--- a/tools/bpf/bpftool/netlink_dumper.c
+++ b/tools/bpf/bpftool/netlink_dumper.c
@@ -29,23 +29,36 @@ static void xdp_dump_prog_id(struct nlattr **tb, int attr,
 static int do_xdp_dump_one(struct nlattr *attr, unsigned int ifindex,
 			   const char *name)
 {
+	unsigned char mode = XDP_ATTACHED_NONE;
 	struct nlattr *tb[IFLA_XDP_MAX + 1];
-	unsigned char mode;
+	unsigned char md_btf_enabled = 0;
+	unsigned int md_btf_id = 0;
+	bool attached;
 
 	if (libbpf_nla_parse_nested(tb, IFLA_XDP_MAX, attr, NULL) < 0)
 		return -1;
 
-	if (!tb[IFLA_XDP_ATTACHED])
+	if (!tb[IFLA_XDP_ATTACHED] && !tb[IFLA_XDP_MD_BTF_ID])
 		return 0;
 
-	mode = libbpf_nla_getattr_u8(tb[IFLA_XDP_ATTACHED]);
-	if (mode == XDP_ATTACHED_NONE)
+	if (tb[IFLA_XDP_ATTACHED])
+		mode = libbpf_nla_getattr_u8(tb[IFLA_XDP_ATTACHED]);
+
+	if (tb[IFLA_XDP_MD_BTF_ID]) {
+		md_btf_id = libbpf_nla_getattr_u32(tb[IFLA_XDP_MD_BTF_ID]);
+		md_btf_enabled = libbpf_nla_getattr_u8(tb[IFLA_XDP_MD_BTF_STATE]);
+	}
+
+	attached = (mode != XDP_ATTACHED_NONE);
+	if (!attached && !md_btf_id)
 		return 0;
 
 	NET_START_OBJECT;
 	if (name)
 		NET_DUMP_STR("devname", "%s", name);
 	NET_DUMP_UINT("ifindex", "(%d)", ifindex);
+	NET_DUMP_UINT("md_btf_id", " md_btf_id(%d)", md_btf_id);
+	NET_DUMP_UINT("md_btf_enabled", " md_btf_enabled(%d)", md_btf_enabled);
 
 	if (mode == XDP_ATTACHED_MULTI) {
 		if (json_output) {
diff --git a/tools/include/uapi/linux/if_link.h b/tools/include/uapi/linux/if_link.h
index d208b2af697f..9b45bb3327c2 100644
--- a/tools/include/uapi/linux/if_link.h
+++ b/tools/include/uapi/linux/if_link.h
@@ -992,6 +992,8 @@ enum {
 	IFLA_XDP_SKB_PROG_ID,
 	IFLA_XDP_HW_PROG_ID,
 	IFLA_XDP_EXPECTED_FD,
+	IFLA_XDP_MD_BTF_ID,
+	IFLA_XDP_MD_BTF_STATE,
 	__IFLA_XDP_MAX,
 };
 
-- 
2.32.0




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux