Skip to content

Commit c1931c9

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
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
1 parent 026a4c2 commit c1931c9

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎include/uapi/linux/bpf.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,6 +4069,9 @@ struct bpf_link_info {
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‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8996,6 +8996,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link)
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 @@ static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,
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

0 commit comments

Comments
 (0)