Implement XDP link-specific show_fdinfo and link_info to emit ifindex.
Unified · Split
| @@ -4069,6 +4069,9 @@ struct bpf_link_info { · 4068 unmodified lines | ||
| 4069 | 4069 | __u32 netns_ino; |
| 4070 | 4070 | __u32 attach_type; |
| 4071 | 4071 | } netns; |
| 4072 | + struct { | |
| 4073 | + __u32 ifindex; | |
| 4074 | + } xdp; | |
| 4072 | 4075 | }; |
| 4073 | 4076 | } __attribute__((aligned(8))); |
| 4074 | 4077 | |
| @@ -8996,6 +8996,35 @@ static void bpf_xdp_link_dealloc(struct bpf_link *link) · 8995 unmodified lines | ||
| 8996 | 8996 | kfree(xdp_link); |
| 8997 | 8997 | } |
| 8998 | 8998 | |
| 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 | + | |
| 8999 | 9028 | static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog, |
| 9000 | 9029 | struct bpf_prog *old_prog) |
| 9001 | 9030 | { |
| @@ -9041,6 +9070,8 @@ out_unlock: · 39 unmodified lines | ||
| 9041 | 9070 | static const struct bpf_link_ops bpf_xdp_link_lops = { |
| 9042 | 9071 | .release = bpf_xdp_link_release, |
| 9043 | 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 | 9075 | .update_prog = bpf_xdp_link_update, |
| 9045 | 9076 | }; |
| 9046 | 9077 | |