[PATCH net-next] bpf: fix the printing of ifindex

Subsystems: bpf [general] (safe dynamic programs and tools), bpf [networking] (tcx & tc bpf, sock_addr), networking [general], the rest

STALE3360d

4 messages, 4 authors, 2017-08-03 · open the first message on its own page

[PATCH net-next] bpf: fix the printing of ifindex

From: William Tu <hidden>
Date: 2017-08-02 15:44:02

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

Signed-off-by: William Tu <redacted>
---
 net/core/filter.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index 7e9708653c6f..78d00933dbe7 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -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;
 	}
 
-- 
2.7.4

Re: [PATCH net-next] bpf: fix the printing of ifindex

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2017-08-02 15:53:47

On 08/02/2017 05:43 PM, William Tu wrote:
Save the ifindex before it gets zeroed so the invalid
ifindex can be printed out.

Signed-off-by: William Tu <redacted>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
quoted hunk
  net/core/filter.c | 10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index 7e9708653c6f..78d00933dbe7 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -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;
Unrelated, but setting ri->map to NULL is not really needed here
given we have the ri->map test earlier.
quoted hunk
  	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;
  	}

Re: [PATCH net-next] bpf: fix the printing of ifindex

From: John Fastabend <john.fastabend@gmail.com>
Date: 2017-08-02 16:06:43

On 08/02/2017 08:43 AM, William Tu wrote:
Save the ifindex before it gets zeroed so the invalid
ifindex can be printed out.

Signed-off-by: William Tu <redacted>
---

Thanks!

Acked-by: John Fastabend <john.fastabend@gmail.com>

Re: [PATCH net-next] bpf: fix the printing of ifindex

From: David Miller <davem@davemloft.net>
Date: 2017-08-03 16:25:48

From: William Tu <redacted>
Date: Wed,  2 Aug 2017 08:43:52 -0700
Save the ifindex before it gets zeroed so the invalid
ifindex can be printed out.

Signed-off-by: William Tu <redacted>
Applied, thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help