Skip to contentSkip to conversation

bpf: fix the printing of ifindex

PATCH Applied William Tu 4 participants 4 messages Aug 2, 2017 – Aug 3, 2017

Subsystems (4)
lore
Share & tools
lore

William Tu

author
#0 lore raw

PATCH 1/1 bpf: fix the printing of ifindex

Save the ifindex before it gets zeroed so the invalid ifindex can be printed out.

---
 net/core/filter.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
net/core/filter.c +6 -4
index 7e9708653c6f..78d00933dbe7 100644
@@ -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;
 	}
 
@@ -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;
 	}
 
Signature · 1 line
2.7.4
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · William Tu

Save the ifindex before it gets zeroed so the invalid ifindex can be printed out.

Quoted 10 lines
  net/core/filter.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
net/core/filter.c +0 -0
index 7e9708653c6f..78d00933dbe7 100644
@@ -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);

net/core/filter.c int xdp_do_redirect(struct net_device *dev, struct xdp_buff *xdp, · line 2519

Quoted 10 lines
net/core/filter.c +2 -1
  	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;

Unrelated, but setting ri->map to NULL is not really needed here given we have the ri->map test earlier.

Quoted 22 lines
net/core/filter.c +4 -3
  	if (unlikely(!fwd)) {
-		bpf_warn_invalid_xdp_redirect(ri->ifindex);
+		bpf_warn_invalid_xdp_redirect(index);
  		return -EINVAL;
  	}
 
@@ -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;
  	}