* ipv4 route dump broken with multiple subnets
@ 2015-03-10 17:07 Sabrina Dubroca
2015-03-10 17:37 ` Alexander Duyck
2015-03-10 18:25 ` [net-next PATCH] fib_trie: Correctly handle case of key == 0 in leaf_walk_rcu Alexander Duyck
0 siblings, 2 replies; 5+ messages in thread
From: Sabrina Dubroca @ 2015-03-10 17:07 UTC (permalink / raw)
To: Alexander Duyck; +Cc: netdev
With this setup (no other address assigned):
ip link add type dummy
ip link set dummy0 up
ip a a 10.0.0.1/24 dev dummy0
route dump works:
# ip r
10.0.0.0/24 dev dummy0 proto kernel scope link src 10.0.0.1
If I add another address:
ip a a 10.0.1.1/24 dev dummy0
or a route:
ip r a 10.0.1.0/24 via 10.0.0.2
# ip r
<empty>
It's the same with /proc/net/route instead of ip route.
But with a default route the table appears again.
This patch seems to fix the problem, but I'm not sure it is correct.
---
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index 90955455884e..418043dc3a12 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1767,6 +1767,11 @@ int fib_table_dump(struct fib_table *tb, struct sk_buff *skb,
*/
int count = cb->args[2];
t_key key = cb->args[3];
+ if (!key) {
+ struct key_vector *n = get_child_rcu(tp, 0);
+ if (n)
+ key = n->key;
+ }
while ((l = leaf_walk_rcu(&tp, key)) != NULL) {
if (fn_trie_dump_leaf(l, tb, skb, cb) < 0) {
@@ -2276,10 +2281,12 @@ static struct key_vector *fib_route_get_idx(struct fib_route_iter *iter,
pos -= iter->pos;
key = iter->key;
} else {
+ struct key_vector *n;
t = (struct trie *)tb->tb_data;
iter->tnode = t->kv;
iter->pos = 0;
- key = 0;
+ n = rcu_dereference(t->kv->tnode[0]);
+ key = n ? n->key : 0;
}
while ((l = leaf_walk_rcu(tp, key)) != NULL) {
@@ -2308,6 +2315,7 @@ static void *fib_route_seq_start(struct seq_file *seq, loff_t *pos)
__acquires(RCU)
{
struct fib_route_iter *iter = seq->private;
+ struct key_vector *n;
struct fib_table *tb;
struct trie *t;
@@ -2323,9 +2331,15 @@ static void *fib_route_seq_start(struct seq_file *seq, loff_t *pos)
return fib_route_get_idx(iter, *pos);
t = (struct trie *)tb->tb_data;
- iter->tnode = t->kv;
+ n = rcu_dereference(t->kv->tnode[0]);
+ if (IS_TNODE(n)) {
+ iter->tnode = n;
+ iter->key = n->key;
+ } else {
+ iter->tnode = t->kv;
+ iter->key = 0;
+ }
iter->pos = 0;
- iter->key = 0;
return SEQ_START_TOKEN;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: ipv4 route dump broken with multiple subnets
2015-03-10 17:07 ipv4 route dump broken with multiple subnets Sabrina Dubroca
@ 2015-03-10 17:37 ` Alexander Duyck
2015-03-10 18:25 ` [net-next PATCH] fib_trie: Correctly handle case of key == 0 in leaf_walk_rcu Alexander Duyck
1 sibling, 0 replies; 5+ messages in thread
From: Alexander Duyck @ 2015-03-10 17:37 UTC (permalink / raw)
To: Sabrina Dubroca; +Cc: netdev
On 03/10/2015 10:07 AM, Sabrina Dubroca wrote:
> With this setup (no other address assigned):
>
> ip link add type dummy
> ip link set dummy0 up
> ip a a 10.0.0.1/24 dev dummy0
>
> route dump works:
>
> # ip r
> 10.0.0.0/24 dev dummy0 proto kernel scope link src 10.0.0.1
>
>
> If I add another address:
>
> ip a a 10.0.1.1/24 dev dummy0
>
> or a route:
>
> ip r a 10.0.1.0/24 via 10.0.0.2
>
> # ip r
> <empty>
>
> It's the same with /proc/net/route instead of ip route.
>
> But with a default route the table appears again.
>
>
> This patch seems to fix the problem, but I'm not sure it is correct.
It looks like I can reproduce it as well if I just add dummy, and then
drop the default route. I will look into it and should be able to tell
you what is going on in the next hour or two.
- Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
* [net-next PATCH] fib_trie: Correctly handle case of key == 0 in leaf_walk_rcu
2015-03-10 17:07 ipv4 route dump broken with multiple subnets Sabrina Dubroca
2015-03-10 17:37 ` Alexander Duyck
@ 2015-03-10 18:25 ` Alexander Duyck
2015-03-10 18:48 ` Sabrina Dubroca
1 sibling, 1 reply; 5+ messages in thread
From: Alexander Duyck @ 2015-03-10 18:25 UTC (permalink / raw)
To: netdev; +Cc: davem, sd
In the case of a trie that had no tnodes with a key of 0 the initial
look-up would fail resulting in an out-of-bounds cindex on the first tnode.
This resulted in an entire trie being skipped.
In order resolve this I have updated the cindex logic in the initial
look-up so that if the key is zero we will always traverse the child zero
path.
Fixes: 8be33e95 ("fib_trie: Fib walk rcu should take a tnode and key instead of a trie and a leaf")
Reported-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
---
net/ipv4/fib_trie.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index fcfa982..44cab1d 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -1530,7 +1530,7 @@ static struct key_vector *leaf_walk_rcu(struct key_vector **tn, t_key key)
do {
/* record parent and next child index */
pn = n;
- cindex = get_index(key, pn);
+ cindex = key ? get_index(key, pn) : 0;
if (cindex >> pn->bits)
break;
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [net-next PATCH] fib_trie: Correctly handle case of key == 0 in leaf_walk_rcu
2015-03-10 18:25 ` [net-next PATCH] fib_trie: Correctly handle case of key == 0 in leaf_walk_rcu Alexander Duyck
@ 2015-03-10 18:48 ` Sabrina Dubroca
2015-03-10 20:14 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Sabrina Dubroca @ 2015-03-10 18:48 UTC (permalink / raw)
To: Alexander Duyck; +Cc: netdev, davem
2015-03-10, 11:25:41 -0700, Alexander Duyck wrote:
> In the case of a trie that had no tnodes with a key of 0 the initial
> look-up would fail resulting in an out-of-bounds cindex on the first tnode.
> This resulted in an entire trie being skipped.
>
> In order resolve this I have updated the cindex logic in the initial
> look-up so that if the key is zero we will always traverse the child zero
> path.
>
> Fixes: 8be33e95 ("fib_trie: Fib walk rcu should take a tnode and key instead of a trie and a leaf")
> Reported-by: Sabrina Dubroca <sd@queasysnail.net>
> Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
> ---
Tested-by: Sabrina Dubroca <sd@queasysnail.net>
Thanks Alex.
--
Sabrina
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [net-next PATCH] fib_trie: Correctly handle case of key == 0 in leaf_walk_rcu
2015-03-10 18:48 ` Sabrina Dubroca
@ 2015-03-10 20:14 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2015-03-10 20:14 UTC (permalink / raw)
To: sd; +Cc: alexander.h.duyck, netdev
From: Sabrina Dubroca <sd@queasysnail.net>
Date: Tue, 10 Mar 2015 19:48:39 +0100
> 2015-03-10, 11:25:41 -0700, Alexander Duyck wrote:
>> In the case of a trie that had no tnodes with a key of 0 the initial
>> look-up would fail resulting in an out-of-bounds cindex on the first tnode.
>> This resulted in an entire trie being skipped.
>>
>> In order resolve this I have updated the cindex logic in the initial
>> look-up so that if the key is zero we will always traverse the child zero
>> path.
>>
>> Fixes: 8be33e95 ("fib_trie: Fib walk rcu should take a tnode and key instead of a trie and a leaf")
>> Reported-by: Sabrina Dubroca <sd@queasysnail.net>
>> Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
>> ---
>
> Tested-by: Sabrina Dubroca <sd@queasysnail.net>
Applied, thanks everyone.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-03-10 20:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-10 17:07 ipv4 route dump broken with multiple subnets Sabrina Dubroca
2015-03-10 17:37 ` Alexander Duyck
2015-03-10 18:25 ` [net-next PATCH] fib_trie: Correctly handle case of key == 0 in leaf_walk_rcu Alexander Duyck
2015-03-10 18:48 ` Sabrina Dubroca
2015-03-10 20:14 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).