summaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2020-07-21 23:45:59 -0700
committerAlexei Starovoitov <ast@kernel.org>2020-07-25 20:37:02 -0700
commitc1931c9784ebb5787c0784c112fb8baa5e8455b3 (patch)
tree756ccc0946ea3286cd4649937ec912fd20642434 /net
parent026a4c28e1db3b0cb99cd9a3e495d4a8b632fa74 (diff)
bpf: Implement BPF XDP link-specific introspection APIs
Implement XDP link-specific show_fdinfo and link_info to emit ifindex. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200722064603.3350758-7-andriin@fb.com
Diffstat (limited to 'net')
-rw-r--r--net/core/dev.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 49f284f51a22..82ce0920b172 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8996,6 +8996,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link)
kfree(xdp_link);
}
+static void bpf_xdp_link_show_fdinfo(const struct bpf_link *link,
+ struct seq_file *seq)
+{
+ struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
+ u32 ifindex = 0;
+
+ rtnl_lock();
+ if (xdp_link->dev)
+ ifindex = xdp_link->dev->ifindex;
+ rtnl_unlock();
+
+ seq_printf(seq, "ifindex:\t%u\n", ifindex);
+}
+
+static int bpf_xdp_link_fill_link_info(const struct bpf_link *link,
+ struct bpf_link_info *info)
+{
+ struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
+ u32 ifindex = 0;
+
+ rtnl_lock();
+ if (xdp_link->dev)
+ ifindex = xdp_link->dev->ifindex;
+ rtnl_unlock();
+
+ info->xdp.ifindex = ifindex;
+ return 0;
+}
+
static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,
struct bpf_prog *old_prog)
{
@@ -9041,6 +9070,8 @@ out_unlock:
static const struct bpf_link_ops bpf_xdp_link_lops = {
.release = bpf_xdp_link_release,
.dealloc = bpf_xdp_link_dealloc,
+ .show_fdinfo = bpf_xdp_link_show_fdinfo,
+ .fill_link_info = bpf_xdp_link_fill_link_info,
.update_prog = bpf_xdp_link_update,
};