History

bpf: Implement BPF XDP link-specific introspection APIs

Implement XDP link-specific show_fdinfo and link_info to emit ifindex.

Andrii Nakryiko committed 6 years ago

Commit c1931c91 parent 026a4c22 files · +34 −0Browse files

Unified · Split

2 files
  1. include/uapi/linux/bpf.h +3 −0
  2. net/core/dev.c +31 −0
include/uapi/linux/bpf.h+3−0
@@ -4069,6 +4069,9 @@ struct bpf_link_info { · 4068 unmodified lines
40694069 __u32 netns_ino;
40704070 __u32 attach_type;
40714071 } netns;
4072+ struct {
4073+ __u32 ifindex;
4074+ } xdp;
40724075 };
40734076 } __attribute__((aligned(8)));
40744077
net/core/dev.c+31−0
@@ -8996,6 +8996,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link) · 8995 unmodified lines
89968996 kfree(xdp_link);
89978997 }
89988998
8999+static void bpf_xdp_link_show_fdinfo(const struct bpf_link *link,
9000+ struct seq_file *seq)
9001+{
9002+ struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
9003+ u32 ifindex = 0;
9004+
9005+ rtnl_lock();
9006+ if (xdp_link->dev)
9007+ ifindex = xdp_link->dev->ifindex;
9008+ rtnl_unlock();
9009+
9010+ seq_printf(seq, "ifindex:\t%u\n", ifindex);
9011+}
9012+
9013+static int bpf_xdp_link_fill_link_info(const struct bpf_link *link,
9014+ struct bpf_link_info *info)
9015+{
9016+ struct bpf_xdp_link *xdp_link = container_of(link, struct bpf_xdp_link, link);
9017+ u32 ifindex = 0;
9018+
9019+ rtnl_lock();
9020+ if (xdp_link->dev)
9021+ ifindex = xdp_link->dev->ifindex;
9022+ rtnl_unlock();
9023+
9024+ info->xdp.ifindex = ifindex;
9025+ return 0;
9026+}
9027+
89999028 static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,
90009029 struct bpf_prog *old_prog)
90019030 {
@@ -9041,6 +9070,8 @@ out_unlock: · 39 unmodified lines
90419070 static const struct bpf_link_ops bpf_xdp_link_lops = {
90429071 .release = bpf_xdp_link_release,
90439072 .dealloc = bpf_xdp_link_dealloc,
9073+ .show_fdinfo = bpf_xdp_link_show_fdinfo,
9074+ .fill_link_info = bpf_xdp_link_fill_link_info,
90449075 .update_prog = bpf_xdp_link_update,
90459076 };
90469077