Skip to content

Commit

Permalink
bpf: fix the printing of ifindex
Browse files Browse the repository at this point in the history
Save the ifindex before it gets zeroed so the invalid
ifindex can be printed out.

Signed-off-by: William Tu <u9012063@gmail.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
William Tu authored and David S. Miller committed Aug 3, 2017
1 parent f6c00a3 commit eb48d68
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2509,15 +2509,16 @@ int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp,
{
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
struct net_device *fwd;
u32 index = ri->ifindex;

if (ri->map)
return xdp_do_redirect_map(dev, xdp, xdp_prog);

fwd = dev_get_by_index_rcu(dev_net(dev), ri->ifindex);
fwd = dev_get_by_index_rcu(dev_net(dev), index);
ri->ifindex = 0;
ri->map = NULL;
if (unlikely(!fwd)) {
bpf_warn_invalid_xdp_redirect(ri->ifindex);
bpf_warn_invalid_xdp_redirect(index);
return -EINVAL;
}

Expand All @@ -2531,11 +2532,12 @@ int xdp_do_generic_redirect(struct net_device *dev, struct sk_buff *skb)
{
struct redirect_info *ri = this_cpu_ptr(&redirect_info);
unsigned int len;
u32 index = ri->ifindex;

dev = dev_get_by_index_rcu(dev_net(dev), ri->ifindex);
dev = dev_get_by_index_rcu(dev_net(dev), index);
ri->ifindex = 0;
if (unlikely(!dev)) {
bpf_warn_invalid_xdp_redirect(ri->ifindex);
bpf_warn_invalid_xdp_redirect(index);
goto err;
}

Expand Down

0 comments on commit eb48d68

Please sign in to comment.