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
4069 __u32 netns_ino;4069 __u32 netns_ino;
4070 __u32 attach_type;4070 __u32 attach_type;
4071 } netns;4071 } netns;
4072 struct {
4073 __u32 ifindex;
4074 } xdp;
4072 };4075 };
4073} __attribute__((aligned(8)));4076} __attribute__((aligned(8)));
4074 4077
net/core/dev.c+31−0
@@ -8996,6 +8996,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link) · 8995 unmodified lines
8996 kfree(xdp_link);8996 kfree(xdp_link);
8997}8997}
8998 8998
8999static 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
9013static 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
8999static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,9028static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,
9000 struct bpf_prog *old_prog)9029 struct bpf_prog *old_prog)
9001{9030{
@@ -9041,6 +9070,8 @@ out_unlock: · 39 unmodified lines
9041static const struct bpf_link_ops bpf_xdp_link_lops = {9070static const struct bpf_link_ops bpf_xdp_link_lops = {
9042 .release = bpf_xdp_link_release,9071 .release = bpf_xdp_link_release,
9043 .dealloc = bpf_xdp_link_dealloc,9072 .dealloc = bpf_xdp_link_dealloc,
9073 .show_fdinfo = bpf_xdp_link_show_fdinfo,
9074 .fill_link_info = bpf_xdp_link_fill_link_info,
9044 .update_prog = bpf_xdp_link_update,9075 .update_prog = bpf_xdp_link_update,
9045};9076};
9046 9077