Commit 327571cb authored by Hannes Frederic Sowa's avatar Hannes Frederic Sowa Committed by David S. Miller

ipv6: don't walk node's leaf during serial number update

Cc: YOSHIFUJI Hideaki <hideaki@yoshifuji.org>
Cc: Martin Lau <kafai@fb.com>
Signed-off-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 812918c4
...@@ -50,6 +50,7 @@ struct fib6_cleaner { ...@@ -50,6 +50,7 @@ struct fib6_cleaner {
struct fib6_walker w; struct fib6_walker w;
struct net *net; struct net *net;
int (*func)(struct rt6_info *, void *arg); int (*func)(struct rt6_info *, void *arg);
int sernum;
void *arg; void *arg;
}; };
...@@ -105,6 +106,10 @@ static int fib6_new_sernum(struct net *net) ...@@ -105,6 +106,10 @@ static int fib6_new_sernum(struct net *net)
return new; return new;
} }
enum {
FIB6_NO_SERNUM_CHANGE = 0,
};
/* /*
* Auxiliary address test functions for the radix tree. * Auxiliary address test functions for the radix tree.
* *
...@@ -1514,6 +1519,16 @@ static int fib6_clean_node(struct fib6_walker *w) ...@@ -1514,6 +1519,16 @@ static int fib6_clean_node(struct fib6_walker *w)
.nl_net = c->net, .nl_net = c->net,
}; };
if (c->sernum != FIB6_NO_SERNUM_CHANGE &&
w->node->fn_sernum != c->sernum)
w->node->fn_sernum = c->sernum;
if (!c->func) {
WARN_ON_ONCE(c->sernum == FIB6_NO_SERNUM_CHANGE);
w->leaf = NULL;
return 0;
}
for (rt = w->leaf; rt; rt = rt->dst.rt6_next) { for (rt = w->leaf; rt; rt = rt->dst.rt6_next) {
res = c->func(rt, c->arg); res = c->func(rt, c->arg);
if (res < 0) { if (res < 0) {
...@@ -1547,7 +1562,7 @@ static int fib6_clean_node(struct fib6_walker *w) ...@@ -1547,7 +1562,7 @@ static int fib6_clean_node(struct fib6_walker *w)
static void fib6_clean_tree(struct net *net, struct fib6_node *root, static void fib6_clean_tree(struct net *net, struct fib6_node *root,
int (*func)(struct rt6_info *, void *arg), int (*func)(struct rt6_info *, void *arg),
bool prune, void *arg) bool prune, int sernum, void *arg)
{ {
struct fib6_cleaner c; struct fib6_cleaner c;
...@@ -1557,14 +1572,16 @@ static void fib6_clean_tree(struct net *net, struct fib6_node *root, ...@@ -1557,14 +1572,16 @@ static void fib6_clean_tree(struct net *net, struct fib6_node *root,
c.w.count = 0; c.w.count = 0;
c.w.skip = 0; c.w.skip = 0;
c.func = func; c.func = func;
c.sernum = sernum;
c.arg = arg; c.arg = arg;
c.net = net; c.net = net;
fib6_walk(&c.w); fib6_walk(&c.w);
} }
void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg), static void __fib6_clean_all(struct net *net,
void *arg) int (*func)(struct rt6_info *, void *),
int sernum, void *arg)
{ {
struct fib6_table *table; struct fib6_table *table;
struct hlist_head *head; struct hlist_head *head;
...@@ -1576,13 +1593,19 @@ void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg), ...@@ -1576,13 +1593,19 @@ void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
hlist_for_each_entry_rcu(table, head, tb6_hlist) { hlist_for_each_entry_rcu(table, head, tb6_hlist) {
write_lock_bh(&table->tb6_lock); write_lock_bh(&table->tb6_lock);
fib6_clean_tree(net, &table->tb6_root, fib6_clean_tree(net, &table->tb6_root,
func, false, arg); func, false, sernum, arg);
write_unlock_bh(&table->tb6_lock); write_unlock_bh(&table->tb6_lock);
} }
} }
rcu_read_unlock(); rcu_read_unlock();
} }
void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *),
void *arg)
{
__fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg);
}
static int fib6_prune_clone(struct rt6_info *rt, void *arg) static int fib6_prune_clone(struct rt6_info *rt, void *arg)
{ {
if (rt->rt6i_flags & RTF_CACHE) { if (rt->rt6i_flags & RTF_CACHE) {
...@@ -1595,25 +1618,15 @@ static int fib6_prune_clone(struct rt6_info *rt, void *arg) ...@@ -1595,25 +1618,15 @@ static int fib6_prune_clone(struct rt6_info *rt, void *arg)
static void fib6_prune_clones(struct net *net, struct fib6_node *fn) static void fib6_prune_clones(struct net *net, struct fib6_node *fn)
{ {
fib6_clean_tree(net, fn, fib6_prune_clone, true, NULL); fib6_clean_tree(net, fn, fib6_prune_clone, true,
} FIB6_NO_SERNUM_CHANGE, NULL);
static int fib6_update_sernum(struct rt6_info *rt, void *arg)
{
int sernum = *(int *)arg;
if (rt->rt6i_node &&
rt->rt6i_node->fn_sernum != sernum)
rt->rt6i_node->fn_sernum = sernum;
return 0;
} }
static void fib6_flush_trees(struct net *net) static void fib6_flush_trees(struct net *net)
{ {
int new_sernum = fib6_new_sernum(net); int new_sernum = fib6_new_sernum(net);
fib6_clean_all(net, fib6_update_sernum, &new_sernum); __fib6_clean_all(net, NULL, new_sernum, NULL);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment