From ee9ddb03fb4637610aceeccf14608442b0b26d9a Mon Sep 17 00:00:00 2001 From: Saeed Mahameed Date: Tue, 9 Apr 2019 14:52:02 -0700 Subject: [PATCH] tools/bpf: Query XDP metadata BTF ID 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: Signed-off-by: Saeed Mahameed Signed-off-by: Aravindhan Gunasekaran --- 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 0242f31e339c..ac1923196135 100644 --- a/tools/include/uapi/linux/if_link.h +++ b/tools/include/uapi/linux/if_link.h @@ -1213,6 +1213,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, };