|
@@ -38,14 +38,6 @@
|
|
#include <net/ip6_fib.h>
|
|
#include <net/ip6_fib.h>
|
|
#include <net/ip6_route.h>
|
|
#include <net/ip6_route.h>
|
|
|
|
|
|
-#define RT6_DEBUG 2
|
|
|
|
-
|
|
|
|
-#if RT6_DEBUG >= 3
|
|
|
|
-#define RT6_TRACE(x...) pr_debug(x)
|
|
|
|
-#else
|
|
|
|
-#define RT6_TRACE(x...) do { ; } while (0)
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
static struct kmem_cache *fib6_node_kmem __read_mostly;
|
|
static struct kmem_cache *fib6_node_kmem __read_mostly;
|
|
|
|
|
|
struct fib6_cleaner {
|
|
struct fib6_cleaner {
|
|
@@ -62,9 +54,12 @@ struct fib6_cleaner {
|
|
#define FWS_INIT FWS_L
|
|
#define FWS_INIT FWS_L
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-static void fib6_prune_clones(struct net *net, struct fib6_node *fn);
|
|
|
|
-static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn);
|
|
|
|
-static struct fib6_node *fib6_repair_tree(struct net *net, struct fib6_node *fn);
|
|
|
|
|
|
+static struct rt6_info *fib6_find_prefix(struct net *net,
|
|
|
|
+ struct fib6_table *table,
|
|
|
|
+ struct fib6_node *fn);
|
|
|
|
+static struct fib6_node *fib6_repair_tree(struct net *net,
|
|
|
|
+ struct fib6_table *table,
|
|
|
|
+ struct fib6_node *fn);
|
|
static int fib6_walk(struct net *net, struct fib6_walker *w);
|
|
static int fib6_walk(struct net *net, struct fib6_walker *w);
|
|
static int fib6_walk_continue(struct fib6_walker *w);
|
|
static int fib6_walk_continue(struct fib6_walker *w);
|
|
|
|
|
|
@@ -110,6 +105,20 @@ enum {
|
|
FIB6_NO_SERNUM_CHANGE = 0,
|
|
FIB6_NO_SERNUM_CHANGE = 0,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+void fib6_update_sernum(struct rt6_info *rt)
|
|
|
|
+{
|
|
|
|
+ struct fib6_table *table = rt->rt6i_table;
|
|
|
|
+ struct net *net = dev_net(rt->dst.dev);
|
|
|
|
+ struct fib6_node *fn;
|
|
|
|
+
|
|
|
|
+ spin_lock_bh(&table->tb6_lock);
|
|
|
|
+ fn = rcu_dereference_protected(rt->rt6i_node,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ if (fn)
|
|
|
|
+ fn->fn_sernum = fib6_new_sernum(net);
|
|
|
|
+ spin_unlock_bh(&table->tb6_lock);
|
|
|
|
+}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Auxiliary address test functions for the radix tree.
|
|
* Auxiliary address test functions for the radix tree.
|
|
*
|
|
*
|
|
@@ -140,18 +149,21 @@ static __be32 addr_bit_set(const void *token, int fn_bit)
|
|
addr[fn_bit >> 5];
|
|
addr[fn_bit >> 5];
|
|
}
|
|
}
|
|
|
|
|
|
-static struct fib6_node *node_alloc(void)
|
|
|
|
|
|
+static struct fib6_node *node_alloc(struct net *net)
|
|
{
|
|
{
|
|
struct fib6_node *fn;
|
|
struct fib6_node *fn;
|
|
|
|
|
|
fn = kmem_cache_zalloc(fib6_node_kmem, GFP_ATOMIC);
|
|
fn = kmem_cache_zalloc(fib6_node_kmem, GFP_ATOMIC);
|
|
|
|
+ if (fn)
|
|
|
|
+ net->ipv6.rt6_stats->fib_nodes++;
|
|
|
|
|
|
return fn;
|
|
return fn;
|
|
}
|
|
}
|
|
|
|
|
|
-static void node_free_immediate(struct fib6_node *fn)
|
|
|
|
|
|
+static void node_free_immediate(struct net *net, struct fib6_node *fn)
|
|
{
|
|
{
|
|
kmem_cache_free(fib6_node_kmem, fn);
|
|
kmem_cache_free(fib6_node_kmem, fn);
|
|
|
|
+ net->ipv6.rt6_stats->fib_nodes--;
|
|
}
|
|
}
|
|
|
|
|
|
static void node_free_rcu(struct rcu_head *head)
|
|
static void node_free_rcu(struct rcu_head *head)
|
|
@@ -161,9 +173,10 @@ static void node_free_rcu(struct rcu_head *head)
|
|
kmem_cache_free(fib6_node_kmem, fn);
|
|
kmem_cache_free(fib6_node_kmem, fn);
|
|
}
|
|
}
|
|
|
|
|
|
-static void node_free(struct fib6_node *fn)
|
|
|
|
|
|
+static void node_free(struct net *net, struct fib6_node *fn)
|
|
{
|
|
{
|
|
call_rcu(&fn->rcu, node_free_rcu);
|
|
call_rcu(&fn->rcu, node_free_rcu);
|
|
|
|
+ net->ipv6.rt6_stats->fib_nodes--;
|
|
}
|
|
}
|
|
|
|
|
|
void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
|
|
void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
|
|
@@ -185,9 +198,6 @@ void rt6_free_pcpu(struct rt6_info *non_pcpu_rt)
|
|
*ppcpu_rt = NULL;
|
|
*ppcpu_rt = NULL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- free_percpu(non_pcpu_rt->rt6i_pcpu);
|
|
|
|
- non_pcpu_rt->rt6i_pcpu = NULL;
|
|
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(rt6_free_pcpu);
|
|
EXPORT_SYMBOL_GPL(rt6_free_pcpu);
|
|
|
|
|
|
@@ -205,8 +215,7 @@ static void fib6_link_table(struct net *net, struct fib6_table *tb)
|
|
* Initialize table lock at a single place to give lockdep a key,
|
|
* Initialize table lock at a single place to give lockdep a key,
|
|
* tables aren't visible prior to being linked to the list.
|
|
* tables aren't visible prior to being linked to the list.
|
|
*/
|
|
*/
|
|
- rwlock_init(&tb->tb6_lock);
|
|
|
|
-
|
|
|
|
|
|
+ spin_lock_init(&tb->tb6_lock);
|
|
h = tb->tb6_id & (FIB6_TABLE_HASHSZ - 1);
|
|
h = tb->tb6_id & (FIB6_TABLE_HASHSZ - 1);
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -225,7 +234,8 @@ static struct fib6_table *fib6_alloc_table(struct net *net, u32 id)
|
|
table = kzalloc(sizeof(*table), GFP_ATOMIC);
|
|
table = kzalloc(sizeof(*table), GFP_ATOMIC);
|
|
if (table) {
|
|
if (table) {
|
|
table->tb6_id = id;
|
|
table->tb6_id = id;
|
|
- table->tb6_root.leaf = net->ipv6.ip6_null_entry;
|
|
|
|
|
|
+ rcu_assign_pointer(table->tb6_root.leaf,
|
|
|
|
+ net->ipv6.ip6_null_entry);
|
|
table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
|
|
table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
|
|
inet_peer_base_init(&table->tb6_peers);
|
|
inet_peer_base_init(&table->tb6_peers);
|
|
}
|
|
}
|
|
@@ -322,11 +332,8 @@ unsigned int fib6_tables_seq_read(struct net *net)
|
|
struct hlist_head *head = &net->ipv6.fib_table_hash[h];
|
|
struct hlist_head *head = &net->ipv6.fib_table_hash[h];
|
|
struct fib6_table *tb;
|
|
struct fib6_table *tb;
|
|
|
|
|
|
- hlist_for_each_entry_rcu(tb, head, tb6_hlist) {
|
|
|
|
- read_lock_bh(&tb->tb6_lock);
|
|
|
|
|
|
+ hlist_for_each_entry_rcu(tb, head, tb6_hlist)
|
|
fib_seq += tb->fib_seq;
|
|
fib_seq += tb->fib_seq;
|
|
- read_unlock_bh(&tb->tb6_lock);
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
rcu_read_unlock();
|
|
rcu_read_unlock();
|
|
|
|
|
|
@@ -372,7 +379,7 @@ static int fib6_node_dump(struct fib6_walker *w)
|
|
{
|
|
{
|
|
struct rt6_info *rt;
|
|
struct rt6_info *rt;
|
|
|
|
|
|
- for (rt = w->leaf; rt; rt = rt->dst.rt6_next)
|
|
|
|
|
|
+ for_each_fib6_walker_rt(w)
|
|
fib6_rt_dump(rt, w->args);
|
|
fib6_rt_dump(rt, w->args);
|
|
w->leaf = NULL;
|
|
w->leaf = NULL;
|
|
return 0;
|
|
return 0;
|
|
@@ -382,9 +389,9 @@ static void fib6_table_dump(struct net *net, struct fib6_table *tb,
|
|
struct fib6_walker *w)
|
|
struct fib6_walker *w)
|
|
{
|
|
{
|
|
w->root = &tb->tb6_root;
|
|
w->root = &tb->tb6_root;
|
|
- read_lock_bh(&tb->tb6_lock);
|
|
|
|
|
|
+ spin_lock_bh(&tb->tb6_lock);
|
|
fib6_walk(net, w);
|
|
fib6_walk(net, w);
|
|
- read_unlock_bh(&tb->tb6_lock);
|
|
|
|
|
|
+ spin_unlock_bh(&tb->tb6_lock);
|
|
}
|
|
}
|
|
|
|
|
|
/* Called with rcu_read_lock() */
|
|
/* Called with rcu_read_lock() */
|
|
@@ -421,7 +428,7 @@ static int fib6_dump_node(struct fib6_walker *w)
|
|
int res;
|
|
int res;
|
|
struct rt6_info *rt;
|
|
struct rt6_info *rt;
|
|
|
|
|
|
- for (rt = w->leaf; rt; rt = rt->dst.rt6_next) {
|
|
|
|
|
|
+ for_each_fib6_walker_rt(w) {
|
|
res = rt6_dump_route(rt, w->args);
|
|
res = rt6_dump_route(rt, w->args);
|
|
if (res < 0) {
|
|
if (res < 0) {
|
|
/* Frame is full, suspend walking */
|
|
/* Frame is full, suspend walking */
|
|
@@ -480,9 +487,9 @@ static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
|
|
w->count = 0;
|
|
w->count = 0;
|
|
w->skip = 0;
|
|
w->skip = 0;
|
|
|
|
|
|
- read_lock_bh(&table->tb6_lock);
|
|
|
|
|
|
+ spin_lock_bh(&table->tb6_lock);
|
|
res = fib6_walk(net, w);
|
|
res = fib6_walk(net, w);
|
|
- read_unlock_bh(&table->tb6_lock);
|
|
|
|
|
|
+ spin_unlock_bh(&table->tb6_lock);
|
|
if (res > 0) {
|
|
if (res > 0) {
|
|
cb->args[4] = 1;
|
|
cb->args[4] = 1;
|
|
cb->args[5] = w->root->fn_sernum;
|
|
cb->args[5] = w->root->fn_sernum;
|
|
@@ -497,9 +504,9 @@ static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
|
|
} else
|
|
} else
|
|
w->skip = 0;
|
|
w->skip = 0;
|
|
|
|
|
|
- read_lock_bh(&table->tb6_lock);
|
|
|
|
|
|
+ spin_lock_bh(&table->tb6_lock);
|
|
res = fib6_walk_continue(w);
|
|
res = fib6_walk_continue(w);
|
|
- read_unlock_bh(&table->tb6_lock);
|
|
|
|
|
|
+ spin_unlock_bh(&table->tb6_lock);
|
|
if (res <= 0) {
|
|
if (res <= 0) {
|
|
fib6_walker_unlink(net, w);
|
|
fib6_walker_unlink(net, w);
|
|
cb->args[4] = 0;
|
|
cb->args[4] = 0;
|
|
@@ -580,11 +587,13 @@ out:
|
|
* node.
|
|
* node.
|
|
*/
|
|
*/
|
|
|
|
|
|
-static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
|
|
|
- struct in6_addr *addr, int plen,
|
|
|
|
- int offset, int allow_create,
|
|
|
|
- int replace_required, int sernum,
|
|
|
|
- struct netlink_ext_ack *extack)
|
|
|
|
|
|
+static struct fib6_node *fib6_add_1(struct net *net,
|
|
|
|
+ struct fib6_table *table,
|
|
|
|
+ struct fib6_node *root,
|
|
|
|
+ struct in6_addr *addr, int plen,
|
|
|
|
+ int offset, int allow_create,
|
|
|
|
+ int replace_required,
|
|
|
|
+ struct netlink_ext_ack *extack)
|
|
{
|
|
{
|
|
struct fib6_node *fn, *in, *ln;
|
|
struct fib6_node *fn, *in, *ln;
|
|
struct fib6_node *pn = NULL;
|
|
struct fib6_node *pn = NULL;
|
|
@@ -599,7 +608,9 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
|
fn = root;
|
|
fn = root;
|
|
|
|
|
|
do {
|
|
do {
|
|
- key = (struct rt6key *)((u8 *)fn->leaf + offset);
|
|
|
|
|
|
+ struct rt6_info *leaf = rcu_dereference_protected(fn->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ key = (struct rt6key *)((u8 *)leaf + offset);
|
|
|
|
|
|
/*
|
|
/*
|
|
* Prefix match
|
|
* Prefix match
|
|
@@ -625,12 +636,10 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
|
if (plen == fn->fn_bit) {
|
|
if (plen == fn->fn_bit) {
|
|
/* clean up an intermediate node */
|
|
/* clean up an intermediate node */
|
|
if (!(fn->fn_flags & RTN_RTINFO)) {
|
|
if (!(fn->fn_flags & RTN_RTINFO)) {
|
|
- rt6_release(fn->leaf);
|
|
|
|
- fn->leaf = NULL;
|
|
|
|
|
|
+ RCU_INIT_POINTER(fn->leaf, NULL);
|
|
|
|
+ rt6_release(leaf);
|
|
}
|
|
}
|
|
|
|
|
|
- fn->fn_sernum = sernum;
|
|
|
|
-
|
|
|
|
return fn;
|
|
return fn;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -639,10 +648,13 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
|
*/
|
|
*/
|
|
|
|
|
|
/* Try to walk down on tree. */
|
|
/* Try to walk down on tree. */
|
|
- fn->fn_sernum = sernum;
|
|
|
|
dir = addr_bit_set(addr, fn->fn_bit);
|
|
dir = addr_bit_set(addr, fn->fn_bit);
|
|
pn = fn;
|
|
pn = fn;
|
|
- fn = dir ? fn->right : fn->left;
|
|
|
|
|
|
+ fn = dir ?
|
|
|
|
+ rcu_dereference_protected(fn->right,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock)) :
|
|
|
|
+ rcu_dereference_protected(fn->left,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
} while (fn);
|
|
} while (fn);
|
|
|
|
|
|
if (!allow_create) {
|
|
if (!allow_create) {
|
|
@@ -668,19 +680,17 @@ static struct fib6_node *fib6_add_1(struct fib6_node *root,
|
|
* Create new leaf node without children.
|
|
* Create new leaf node without children.
|
|
*/
|
|
*/
|
|
|
|
|
|
- ln = node_alloc();
|
|
|
|
|
|
+ ln = node_alloc(net);
|
|
|
|
|
|
if (!ln)
|
|
if (!ln)
|
|
return ERR_PTR(-ENOMEM);
|
|
return ERR_PTR(-ENOMEM);
|
|
ln->fn_bit = plen;
|
|
ln->fn_bit = plen;
|
|
-
|
|
|
|
- ln->parent = pn;
|
|
|
|
- ln->fn_sernum = sernum;
|
|
|
|
|
|
+ RCU_INIT_POINTER(ln->parent, pn);
|
|
|
|
|
|
if (dir)
|
|
if (dir)
|
|
- pn->right = ln;
|
|
|
|
|
|
+ rcu_assign_pointer(pn->right, ln);
|
|
else
|
|
else
|
|
- pn->left = ln;
|
|
|
|
|
|
+ rcu_assign_pointer(pn->left, ln);
|
|
|
|
|
|
return ln;
|
|
return ln;
|
|
|
|
|
|
@@ -694,7 +704,8 @@ insert_above:
|
|
* and the current
|
|
* and the current
|
|
*/
|
|
*/
|
|
|
|
|
|
- pn = fn->parent;
|
|
|
|
|
|
+ pn = rcu_dereference_protected(fn->parent,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
|
|
/* find 1st bit in difference between the 2 addrs.
|
|
/* find 1st bit in difference between the 2 addrs.
|
|
|
|
|
|
@@ -710,14 +721,14 @@ insert_above:
|
|
* (new leaf node)[ln] (old node)[fn]
|
|
* (new leaf node)[ln] (old node)[fn]
|
|
*/
|
|
*/
|
|
if (plen > bit) {
|
|
if (plen > bit) {
|
|
- in = node_alloc();
|
|
|
|
- ln = node_alloc();
|
|
|
|
|
|
+ in = node_alloc(net);
|
|
|
|
+ ln = node_alloc(net);
|
|
|
|
|
|
if (!in || !ln) {
|
|
if (!in || !ln) {
|
|
if (in)
|
|
if (in)
|
|
- node_free_immediate(in);
|
|
|
|
|
|
+ node_free_immediate(net, in);
|
|
if (ln)
|
|
if (ln)
|
|
- node_free_immediate(ln);
|
|
|
|
|
|
+ node_free_immediate(net, ln);
|
|
return ERR_PTR(-ENOMEM);
|
|
return ERR_PTR(-ENOMEM);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -731,31 +742,28 @@ insert_above:
|
|
|
|
|
|
in->fn_bit = bit;
|
|
in->fn_bit = bit;
|
|
|
|
|
|
- in->parent = pn;
|
|
|
|
|
|
+ RCU_INIT_POINTER(in->parent, pn);
|
|
in->leaf = fn->leaf;
|
|
in->leaf = fn->leaf;
|
|
- atomic_inc(&in->leaf->rt6i_ref);
|
|
|
|
-
|
|
|
|
- in->fn_sernum = sernum;
|
|
|
|
|
|
+ atomic_inc(&rcu_dereference_protected(in->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock))->rt6i_ref);
|
|
|
|
|
|
/* update parent pointer */
|
|
/* update parent pointer */
|
|
if (dir)
|
|
if (dir)
|
|
- pn->right = in;
|
|
|
|
|
|
+ rcu_assign_pointer(pn->right, in);
|
|
else
|
|
else
|
|
- pn->left = in;
|
|
|
|
|
|
+ rcu_assign_pointer(pn->left, in);
|
|
|
|
|
|
ln->fn_bit = plen;
|
|
ln->fn_bit = plen;
|
|
|
|
|
|
- ln->parent = in;
|
|
|
|
- fn->parent = in;
|
|
|
|
-
|
|
|
|
- ln->fn_sernum = sernum;
|
|
|
|
|
|
+ RCU_INIT_POINTER(ln->parent, in);
|
|
|
|
+ rcu_assign_pointer(fn->parent, in);
|
|
|
|
|
|
if (addr_bit_set(addr, bit)) {
|
|
if (addr_bit_set(addr, bit)) {
|
|
- in->right = ln;
|
|
|
|
- in->left = fn;
|
|
|
|
|
|
+ rcu_assign_pointer(in->right, ln);
|
|
|
|
+ rcu_assign_pointer(in->left, fn);
|
|
} else {
|
|
} else {
|
|
- in->left = ln;
|
|
|
|
- in->right = fn;
|
|
|
|
|
|
+ rcu_assign_pointer(in->left, ln);
|
|
|
|
+ rcu_assign_pointer(in->right, fn);
|
|
}
|
|
}
|
|
} else { /* plen <= bit */
|
|
} else { /* plen <= bit */
|
|
|
|
|
|
@@ -765,28 +773,26 @@ insert_above:
|
|
* (old node)[fn] NULL
|
|
* (old node)[fn] NULL
|
|
*/
|
|
*/
|
|
|
|
|
|
- ln = node_alloc();
|
|
|
|
|
|
+ ln = node_alloc(net);
|
|
|
|
|
|
if (!ln)
|
|
if (!ln)
|
|
return ERR_PTR(-ENOMEM);
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
ln->fn_bit = plen;
|
|
ln->fn_bit = plen;
|
|
|
|
|
|
- ln->parent = pn;
|
|
|
|
-
|
|
|
|
- ln->fn_sernum = sernum;
|
|
|
|
-
|
|
|
|
- if (dir)
|
|
|
|
- pn->right = ln;
|
|
|
|
- else
|
|
|
|
- pn->left = ln;
|
|
|
|
|
|
+ RCU_INIT_POINTER(ln->parent, pn);
|
|
|
|
|
|
if (addr_bit_set(&key->addr, plen))
|
|
if (addr_bit_set(&key->addr, plen))
|
|
- ln->right = fn;
|
|
|
|
|
|
+ RCU_INIT_POINTER(ln->right, fn);
|
|
else
|
|
else
|
|
- ln->left = fn;
|
|
|
|
|
|
+ RCU_INIT_POINTER(ln->left, fn);
|
|
|
|
+
|
|
|
|
+ rcu_assign_pointer(fn->parent, ln);
|
|
|
|
|
|
- fn->parent = ln;
|
|
|
|
|
|
+ if (dir)
|
|
|
|
+ rcu_assign_pointer(pn->right, ln);
|
|
|
|
+ else
|
|
|
|
+ rcu_assign_pointer(pn->left, ln);
|
|
}
|
|
}
|
|
return ln;
|
|
return ln;
|
|
}
|
|
}
|
|
@@ -832,6 +838,8 @@ static int fib6_commit_metrics(struct dst_entry *dst, struct mx6_config *mxc)
|
|
static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn,
|
|
static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn,
|
|
struct net *net)
|
|
struct net *net)
|
|
{
|
|
{
|
|
|
|
+ struct fib6_table *table = rt->rt6i_table;
|
|
|
|
+
|
|
if (atomic_read(&rt->rt6i_ref) != 1) {
|
|
if (atomic_read(&rt->rt6i_ref) != 1) {
|
|
/* This route is used as dummy address holder in some split
|
|
/* This route is used as dummy address holder in some split
|
|
* nodes. It is not leaked, but it still holds other resources,
|
|
* nodes. It is not leaked, but it still holds other resources,
|
|
@@ -840,12 +848,17 @@ static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn,
|
|
* to still alive ones.
|
|
* to still alive ones.
|
|
*/
|
|
*/
|
|
while (fn) {
|
|
while (fn) {
|
|
- if (!(fn->fn_flags & RTN_RTINFO) && fn->leaf == rt) {
|
|
|
|
- fn->leaf = fib6_find_prefix(net, fn);
|
|
|
|
- atomic_inc(&fn->leaf->rt6i_ref);
|
|
|
|
|
|
+ struct rt6_info *leaf = rcu_dereference_protected(fn->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct rt6_info *new_leaf;
|
|
|
|
+ if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) {
|
|
|
|
+ new_leaf = fib6_find_prefix(net, table, fn);
|
|
|
|
+ atomic_inc(&new_leaf->rt6i_ref);
|
|
|
|
+ rcu_assign_pointer(fn->leaf, new_leaf);
|
|
rt6_release(rt);
|
|
rt6_release(rt);
|
|
}
|
|
}
|
|
- fn = fn->parent;
|
|
|
|
|
|
+ fn = rcu_dereference_protected(fn->parent,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -857,9 +870,11 @@ static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn,
|
|
static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
|
|
static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
|
|
struct nl_info *info, struct mx6_config *mxc)
|
|
struct nl_info *info, struct mx6_config *mxc)
|
|
{
|
|
{
|
|
|
|
+ struct rt6_info *leaf = rcu_dereference_protected(fn->leaf,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
struct rt6_info *iter = NULL;
|
|
struct rt6_info *iter = NULL;
|
|
- struct rt6_info **ins;
|
|
|
|
- struct rt6_info **fallback_ins = NULL;
|
|
|
|
|
|
+ struct rt6_info __rcu **ins;
|
|
|
|
+ struct rt6_info __rcu **fallback_ins = NULL;
|
|
int replace = (info->nlh &&
|
|
int replace = (info->nlh &&
|
|
(info->nlh->nlmsg_flags & NLM_F_REPLACE));
|
|
(info->nlh->nlmsg_flags & NLM_F_REPLACE));
|
|
int add = (!info->nlh ||
|
|
int add = (!info->nlh ||
|
|
@@ -874,7 +889,9 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct rt6_info *rt,
|
|
|
|
|
|
ins = &fn->leaf;
|
|
ins = &fn->leaf;
|
|
|
|
|
|
- for (iter = fn->leaf; iter; iter = iter->dst.rt6_next) {
|
|
|
|
|
|
+ for (iter = leaf; iter;
|
|
|
|
+ iter = rcu_dereference_protected(iter->dst.rt6_next,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock))) {
|
|
/*
|
|
/*
|
|
* Search for duplicates
|
|
* Search for duplicates
|
|
*/
|
|
*/
|
|
@@ -936,7 +953,8 @@ next_iter:
|
|
if (fallback_ins && !found) {
|
|
if (fallback_ins && !found) {
|
|
/* No ECMP-able route found, replace first non-ECMP one */
|
|
/* No ECMP-able route found, replace first non-ECMP one */
|
|
ins = fallback_ins;
|
|
ins = fallback_ins;
|
|
- iter = *ins;
|
|
|
|
|
|
+ iter = rcu_dereference_protected(*ins,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
found++;
|
|
found++;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -950,7 +968,7 @@ next_iter:
|
|
struct rt6_info *sibling, *temp_sibling;
|
|
struct rt6_info *sibling, *temp_sibling;
|
|
|
|
|
|
/* Find the first route that have the same metric */
|
|
/* Find the first route that have the same metric */
|
|
- sibling = fn->leaf;
|
|
|
|
|
|
+ sibling = leaf;
|
|
while (sibling) {
|
|
while (sibling) {
|
|
if (sibling->rt6i_metric == rt->rt6i_metric &&
|
|
if (sibling->rt6i_metric == rt->rt6i_metric &&
|
|
rt6_qualify_for_ecmp(sibling)) {
|
|
rt6_qualify_for_ecmp(sibling)) {
|
|
@@ -958,7 +976,8 @@ next_iter:
|
|
&sibling->rt6i_siblings);
|
|
&sibling->rt6i_siblings);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- sibling = sibling->dst.rt6_next;
|
|
|
|
|
|
+ sibling = rcu_dereference_protected(sibling->dst.rt6_next,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
}
|
|
}
|
|
/* For each sibling in the list, increment the counter of
|
|
/* For each sibling in the list, increment the counter of
|
|
* siblings. BUG() if counters does not match, list of siblings
|
|
* siblings. BUG() if counters does not match, list of siblings
|
|
@@ -987,10 +1006,10 @@ add:
|
|
if (err)
|
|
if (err)
|
|
return err;
|
|
return err;
|
|
|
|
|
|
- rt->dst.rt6_next = iter;
|
|
|
|
- *ins = rt;
|
|
|
|
- rcu_assign_pointer(rt->rt6i_node, fn);
|
|
|
|
|
|
+ rcu_assign_pointer(rt->dst.rt6_next, iter);
|
|
atomic_inc(&rt->rt6i_ref);
|
|
atomic_inc(&rt->rt6i_ref);
|
|
|
|
+ rcu_assign_pointer(rt->rt6i_node, fn);
|
|
|
|
+ rcu_assign_pointer(*ins, rt);
|
|
call_fib6_entry_notifiers(info->nl_net, FIB_EVENT_ENTRY_ADD,
|
|
call_fib6_entry_notifiers(info->nl_net, FIB_EVENT_ENTRY_ADD,
|
|
rt);
|
|
rt);
|
|
if (!info->skip_notify)
|
|
if (!info->skip_notify)
|
|
@@ -1016,10 +1035,10 @@ add:
|
|
if (err)
|
|
if (err)
|
|
return err;
|
|
return err;
|
|
|
|
|
|
- *ins = rt;
|
|
|
|
|
|
+ atomic_inc(&rt->rt6i_ref);
|
|
rcu_assign_pointer(rt->rt6i_node, fn);
|
|
rcu_assign_pointer(rt->rt6i_node, fn);
|
|
rt->dst.rt6_next = iter->dst.rt6_next;
|
|
rt->dst.rt6_next = iter->dst.rt6_next;
|
|
- atomic_inc(&rt->rt6i_ref);
|
|
|
|
|
|
+ rcu_assign_pointer(*ins, rt);
|
|
call_fib6_entry_notifiers(info->nl_net, FIB_EVENT_ENTRY_REPLACE,
|
|
call_fib6_entry_notifiers(info->nl_net, FIB_EVENT_ENTRY_REPLACE,
|
|
rt);
|
|
rt);
|
|
if (!info->skip_notify)
|
|
if (!info->skip_notify)
|
|
@@ -1031,14 +1050,15 @@ add:
|
|
nsiblings = iter->rt6i_nsiblings;
|
|
nsiblings = iter->rt6i_nsiblings;
|
|
iter->rt6i_node = NULL;
|
|
iter->rt6i_node = NULL;
|
|
fib6_purge_rt(iter, fn, info->nl_net);
|
|
fib6_purge_rt(iter, fn, info->nl_net);
|
|
- if (fn->rr_ptr == iter)
|
|
|
|
|
|
+ if (rcu_access_pointer(fn->rr_ptr) == iter)
|
|
fn->rr_ptr = NULL;
|
|
fn->rr_ptr = NULL;
|
|
rt6_release(iter);
|
|
rt6_release(iter);
|
|
|
|
|
|
if (nsiblings) {
|
|
if (nsiblings) {
|
|
/* Replacing an ECMP route, remove all siblings */
|
|
/* Replacing an ECMP route, remove all siblings */
|
|
ins = &rt->dst.rt6_next;
|
|
ins = &rt->dst.rt6_next;
|
|
- iter = *ins;
|
|
|
|
|
|
+ iter = rcu_dereference_protected(*ins,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
while (iter) {
|
|
while (iter) {
|
|
if (iter->rt6i_metric > rt->rt6i_metric)
|
|
if (iter->rt6i_metric > rt->rt6i_metric)
|
|
break;
|
|
break;
|
|
@@ -1046,14 +1066,16 @@ add:
|
|
*ins = iter->dst.rt6_next;
|
|
*ins = iter->dst.rt6_next;
|
|
iter->rt6i_node = NULL;
|
|
iter->rt6i_node = NULL;
|
|
fib6_purge_rt(iter, fn, info->nl_net);
|
|
fib6_purge_rt(iter, fn, info->nl_net);
|
|
- if (fn->rr_ptr == iter)
|
|
|
|
|
|
+ if (rcu_access_pointer(fn->rr_ptr) == iter)
|
|
fn->rr_ptr = NULL;
|
|
fn->rr_ptr = NULL;
|
|
rt6_release(iter);
|
|
rt6_release(iter);
|
|
nsiblings--;
|
|
nsiblings--;
|
|
|
|
+ info->nl_net->ipv6.rt6_stats->fib_rt_entries--;
|
|
} else {
|
|
} else {
|
|
ins = &iter->dst.rt6_next;
|
|
ins = &iter->dst.rt6_next;
|
|
}
|
|
}
|
|
- iter = *ins;
|
|
|
|
|
|
+ iter = rcu_dereference_protected(*ins,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
}
|
|
}
|
|
WARN_ON(nsiblings != 0);
|
|
WARN_ON(nsiblings != 0);
|
|
}
|
|
}
|
|
@@ -1077,16 +1099,33 @@ void fib6_force_start_gc(struct net *net)
|
|
jiffies + net->ipv6.sysctl.ip6_rt_gc_interval);
|
|
jiffies + net->ipv6.sysctl.ip6_rt_gc_interval);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void fib6_update_sernum_upto_root(struct rt6_info *rt,
|
|
|
|
+ int sernum)
|
|
|
|
+{
|
|
|
|
+ struct fib6_node *fn = rcu_dereference_protected(rt->rt6i_node,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
|
|
+
|
|
|
|
+ /* paired with smp_rmb() in rt6_get_cookie_safe() */
|
|
|
|
+ smp_wmb();
|
|
|
|
+ while (fn) {
|
|
|
|
+ fn->fn_sernum = sernum;
|
|
|
|
+ fn = rcu_dereference_protected(fn->parent,
|
|
|
|
+ lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Add routing information to the routing tree.
|
|
* Add routing information to the routing tree.
|
|
* <destination addr>/<source addr>
|
|
* <destination addr>/<source addr>
|
|
* with source addr info in sub-trees
|
|
* with source addr info in sub-trees
|
|
|
|
+ * Need to own table->tb6_lock
|
|
*/
|
|
*/
|
|
|
|
|
|
int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
struct nl_info *info, struct mx6_config *mxc,
|
|
struct nl_info *info, struct mx6_config *mxc,
|
|
struct netlink_ext_ack *extack)
|
|
struct netlink_ext_ack *extack)
|
|
{
|
|
{
|
|
|
|
+ struct fib6_table *table = rt->rt6i_table;
|
|
struct fib6_node *fn, *pn = NULL;
|
|
struct fib6_node *fn, *pn = NULL;
|
|
int err = -ENOMEM;
|
|
int err = -ENOMEM;
|
|
int allow_create = 1;
|
|
int allow_create = 1;
|
|
@@ -1095,6 +1134,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
|
|
|
|
if (WARN_ON_ONCE(!atomic_read(&rt->dst.__refcnt)))
|
|
if (WARN_ON_ONCE(!atomic_read(&rt->dst.__refcnt)))
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
+ if (WARN_ON_ONCE(rt->rt6i_flags & RTF_CACHE))
|
|
|
|
+ return -EINVAL;
|
|
|
|
|
|
if (info->nlh) {
|
|
if (info->nlh) {
|
|
if (!(info->nlh->nlmsg_flags & NLM_F_CREATE))
|
|
if (!(info->nlh->nlmsg_flags & NLM_F_CREATE))
|
|
@@ -1105,9 +1146,10 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
if (!allow_create && !replace_required)
|
|
if (!allow_create && !replace_required)
|
|
pr_warn("RTM_NEWROUTE with no NLM_F_CREATE or NLM_F_REPLACE\n");
|
|
pr_warn("RTM_NEWROUTE with no NLM_F_CREATE or NLM_F_REPLACE\n");
|
|
|
|
|
|
- fn = fib6_add_1(root, &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
|
|
|
|
|
|
+ fn = fib6_add_1(info->nl_net, table, root,
|
|
|
|
+ &rt->rt6i_dst.addr, rt->rt6i_dst.plen,
|
|
offsetof(struct rt6_info, rt6i_dst), allow_create,
|
|
offsetof(struct rt6_info, rt6i_dst), allow_create,
|
|
- replace_required, sernum, extack);
|
|
|
|
|
|
+ replace_required, extack);
|
|
if (IS_ERR(fn)) {
|
|
if (IS_ERR(fn)) {
|
|
err = PTR_ERR(fn);
|
|
err = PTR_ERR(fn);
|
|
fn = NULL;
|
|
fn = NULL;
|
|
@@ -1120,7 +1162,7 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
if (rt->rt6i_src.plen) {
|
|
if (rt->rt6i_src.plen) {
|
|
struct fib6_node *sn;
|
|
struct fib6_node *sn;
|
|
|
|
|
|
- if (!fn->subtree) {
|
|
|
|
|
|
+ if (!rcu_access_pointer(fn->subtree)) {
|
|
struct fib6_node *sfn;
|
|
struct fib6_node *sfn;
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -1134,42 +1176,40 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
*/
|
|
*/
|
|
|
|
|
|
/* Create subtree root node */
|
|
/* Create subtree root node */
|
|
- sfn = node_alloc();
|
|
|
|
|
|
+ sfn = node_alloc(info->nl_net);
|
|
if (!sfn)
|
|
if (!sfn)
|
|
goto failure;
|
|
goto failure;
|
|
|
|
|
|
- sfn->leaf = info->nl_net->ipv6.ip6_null_entry;
|
|
|
|
atomic_inc(&info->nl_net->ipv6.ip6_null_entry->rt6i_ref);
|
|
atomic_inc(&info->nl_net->ipv6.ip6_null_entry->rt6i_ref);
|
|
|
|
+ rcu_assign_pointer(sfn->leaf,
|
|
|
|
+ info->nl_net->ipv6.ip6_null_entry);
|
|
sfn->fn_flags = RTN_ROOT;
|
|
sfn->fn_flags = RTN_ROOT;
|
|
- sfn->fn_sernum = sernum;
|
|
|
|
|
|
|
|
/* Now add the first leaf node to new subtree */
|
|
/* Now add the first leaf node to new subtree */
|
|
|
|
|
|
- sn = fib6_add_1(sfn, &rt->rt6i_src.addr,
|
|
|
|
- rt->rt6i_src.plen,
|
|
|
|
|
|
+ sn = fib6_add_1(info->nl_net, table, sfn,
|
|
|
|
+ &rt->rt6i_src.addr, rt->rt6i_src.plen,
|
|
offsetof(struct rt6_info, rt6i_src),
|
|
offsetof(struct rt6_info, rt6i_src),
|
|
- allow_create, replace_required, sernum,
|
|
|
|
- extack);
|
|
|
|
|
|
+ allow_create, replace_required, extack);
|
|
|
|
|
|
if (IS_ERR(sn)) {
|
|
if (IS_ERR(sn)) {
|
|
/* If it is failed, discard just allocated
|
|
/* If it is failed, discard just allocated
|
|
root, and then (in failure) stale node
|
|
root, and then (in failure) stale node
|
|
in main tree.
|
|
in main tree.
|
|
*/
|
|
*/
|
|
- node_free_immediate(sfn);
|
|
|
|
|
|
+ node_free_immediate(info->nl_net, sfn);
|
|
err = PTR_ERR(sn);
|
|
err = PTR_ERR(sn);
|
|
goto failure;
|
|
goto failure;
|
|
}
|
|
}
|
|
|
|
|
|
/* Now link new subtree to main tree */
|
|
/* Now link new subtree to main tree */
|
|
- sfn->parent = fn;
|
|
|
|
- fn->subtree = sfn;
|
|
|
|
|
|
+ rcu_assign_pointer(sfn->parent, fn);
|
|
|
|
+ rcu_assign_pointer(fn->subtree, sfn);
|
|
} else {
|
|
} else {
|
|
- sn = fib6_add_1(fn->subtree, &rt->rt6i_src.addr,
|
|
|
|
- rt->rt6i_src.plen,
|
|
|
|
|
|
+ sn = fib6_add_1(info->nl_net, table, FIB6_SUBTREE(fn),
|
|
|
|
+ &rt->rt6i_src.addr, rt->rt6i_src.plen,
|
|
offsetof(struct rt6_info, rt6i_src),
|
|
offsetof(struct rt6_info, rt6i_src),
|
|
- allow_create, replace_required, sernum,
|
|
|
|
- extack);
|
|
|
|
|
|
+ allow_create, replace_required, extack);
|
|
|
|
|
|
if (IS_ERR(sn)) {
|
|
if (IS_ERR(sn)) {
|
|
err = PTR_ERR(sn);
|
|
err = PTR_ERR(sn);
|
|
@@ -1177,9 +1217,9 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (!fn->leaf) {
|
|
|
|
- fn->leaf = rt;
|
|
|
|
|
|
+ if (!rcu_access_pointer(fn->leaf)) {
|
|
atomic_inc(&rt->rt6i_ref);
|
|
atomic_inc(&rt->rt6i_ref);
|
|
|
|
+ rcu_assign_pointer(fn->leaf, rt);
|
|
}
|
|
}
|
|
fn = sn;
|
|
fn = sn;
|
|
}
|
|
}
|
|
@@ -1187,9 +1227,8 @@ int fib6_add(struct fib6_node *root, struct rt6_info *rt,
|
|
|
|
|
|
err = fib6_add_rt2node(fn, rt, info, mxc);
|
|
err = fib6_add_rt2node(fn, rt, info, mxc);
|
|
if (!err) {
|
|
if (!err) {
|
|
|
|
+ fib6_update_sernum_upto_root(rt, sernum);
|
|
fib6_start_gc(info->nl_net, rt);
|
|
fib6_start_gc(info->nl_net, rt);
|
|
- if (!(rt->rt6i_flags & RTF_CACHE))
|
|
|
|
- fib6_prune_clones(info->nl_net, pn);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
out:
|
|
out:
|
|
@@ -1199,19 +1238,23 @@ out:
|
|
* If fib6_add_1 has cleared the old leaf pointer in the
|
|
* If fib6_add_1 has cleared the old leaf pointer in the
|
|
* super-tree leaf node we have to find a new one for it.
|
|
* super-tree leaf node we have to find a new one for it.
|
|
*/
|
|
*/
|
|
- if (pn != fn && pn->leaf == rt) {
|
|
|
|
- pn->leaf = NULL;
|
|
|
|
|
|
+ struct rt6_info *pn_leaf = rcu_dereference_protected(pn->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ if (pn != fn && pn_leaf == rt) {
|
|
|
|
+ pn_leaf = NULL;
|
|
|
|
+ RCU_INIT_POINTER(pn->leaf, NULL);
|
|
atomic_dec(&rt->rt6i_ref);
|
|
atomic_dec(&rt->rt6i_ref);
|
|
}
|
|
}
|
|
- if (pn != fn && !pn->leaf && !(pn->fn_flags & RTN_RTINFO)) {
|
|
|
|
- pn->leaf = fib6_find_prefix(info->nl_net, pn);
|
|
|
|
|
|
+ if (pn != fn && !pn_leaf && !(pn->fn_flags & RTN_RTINFO)) {
|
|
|
|
+ pn_leaf = fib6_find_prefix(info->nl_net, table, pn);
|
|
#if RT6_DEBUG >= 2
|
|
#if RT6_DEBUG >= 2
|
|
- if (!pn->leaf) {
|
|
|
|
- WARN_ON(pn->leaf == NULL);
|
|
|
|
- pn->leaf = info->nl_net->ipv6.ip6_null_entry;
|
|
|
|
|
|
+ if (!pn_leaf) {
|
|
|
|
+ WARN_ON(!pn_leaf);
|
|
|
|
+ pn_leaf = info->nl_net->ipv6.ip6_null_entry;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
- atomic_inc(&pn->leaf->rt6i_ref);
|
|
|
|
|
|
+ atomic_inc(&pn_leaf->rt6i_ref);
|
|
|
|
+ rcu_assign_pointer(pn->leaf, pn_leaf);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
goto failure;
|
|
goto failure;
|
|
@@ -1226,7 +1269,7 @@ failure:
|
|
* fn->leaf.
|
|
* fn->leaf.
|
|
*/
|
|
*/
|
|
if (fn && !(fn->fn_flags & (RTN_RTINFO|RTN_ROOT)))
|
|
if (fn && !(fn->fn_flags & (RTN_RTINFO|RTN_ROOT)))
|
|
- fib6_repair_tree(info->nl_net, fn);
|
|
|
|
|
|
+ fib6_repair_tree(info->nl_net, table, fn);
|
|
/* Always release dst as dst->__refcnt is guaranteed
|
|
/* Always release dst as dst->__refcnt is guaranteed
|
|
* to be taken before entering this function
|
|
* to be taken before entering this function
|
|
*/
|
|
*/
|
|
@@ -1264,7 +1307,8 @@ static struct fib6_node *fib6_lookup_1(struct fib6_node *root,
|
|
|
|
|
|
dir = addr_bit_set(args->addr, fn->fn_bit);
|
|
dir = addr_bit_set(args->addr, fn->fn_bit);
|
|
|
|
|
|
- next = dir ? fn->right : fn->left;
|
|
|
|
|
|
+ next = dir ? rcu_dereference(fn->right) :
|
|
|
|
+ rcu_dereference(fn->left);
|
|
|
|
|
|
if (next) {
|
|
if (next) {
|
|
fn = next;
|
|
fn = next;
|
|
@@ -1274,18 +1318,22 @@ static struct fib6_node *fib6_lookup_1(struct fib6_node *root,
|
|
}
|
|
}
|
|
|
|
|
|
while (fn) {
|
|
while (fn) {
|
|
- if (FIB6_SUBTREE(fn) || fn->fn_flags & RTN_RTINFO) {
|
|
|
|
|
|
+ struct fib6_node *subtree = FIB6_SUBTREE(fn);
|
|
|
|
+
|
|
|
|
+ if (subtree || fn->fn_flags & RTN_RTINFO) {
|
|
|
|
+ struct rt6_info *leaf = rcu_dereference(fn->leaf);
|
|
struct rt6key *key;
|
|
struct rt6key *key;
|
|
|
|
|
|
- key = (struct rt6key *) ((u8 *) fn->leaf +
|
|
|
|
- args->offset);
|
|
|
|
|
|
+ if (!leaf)
|
|
|
|
+ goto backtrack;
|
|
|
|
+
|
|
|
|
+ key = (struct rt6key *) ((u8 *)leaf + args->offset);
|
|
|
|
|
|
if (ipv6_prefix_equal(&key->addr, args->addr, key->plen)) {
|
|
if (ipv6_prefix_equal(&key->addr, args->addr, key->plen)) {
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
- if (fn->subtree) {
|
|
|
|
|
|
+ if (subtree) {
|
|
struct fib6_node *sfn;
|
|
struct fib6_node *sfn;
|
|
- sfn = fib6_lookup_1(fn->subtree,
|
|
|
|
- args + 1);
|
|
|
|
|
|
+ sfn = fib6_lookup_1(subtree, args + 1);
|
|
if (!sfn)
|
|
if (!sfn)
|
|
goto backtrack;
|
|
goto backtrack;
|
|
fn = sfn;
|
|
fn = sfn;
|
|
@@ -1295,18 +1343,18 @@ static struct fib6_node *fib6_lookup_1(struct fib6_node *root,
|
|
return fn;
|
|
return fn;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-#ifdef CONFIG_IPV6_SUBTREES
|
|
|
|
backtrack:
|
|
backtrack:
|
|
-#endif
|
|
|
|
if (fn->fn_flags & RTN_ROOT)
|
|
if (fn->fn_flags & RTN_ROOT)
|
|
break;
|
|
break;
|
|
|
|
|
|
- fn = fn->parent;
|
|
|
|
|
|
+ fn = rcu_dereference(fn->parent);
|
|
}
|
|
}
|
|
|
|
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/* called with rcu_read_lock() held
|
|
|
|
+ */
|
|
struct fib6_node *fib6_lookup(struct fib6_node *root, const struct in6_addr *daddr,
|
|
struct fib6_node *fib6_lookup(struct fib6_node *root, const struct in6_addr *daddr,
|
|
const struct in6_addr *saddr)
|
|
const struct in6_addr *saddr)
|
|
{
|
|
{
|
|
@@ -1337,54 +1385,84 @@ struct fib6_node *fib6_lookup(struct fib6_node *root, const struct in6_addr *dad
|
|
/*
|
|
/*
|
|
* Get node with specified destination prefix (and source prefix,
|
|
* Get node with specified destination prefix (and source prefix,
|
|
* if subtrees are used)
|
|
* if subtrees are used)
|
|
|
|
+ * exact_match == true means we try to find fn with exact match of
|
|
|
|
+ * the passed in prefix addr
|
|
|
|
+ * exact_match == false means we try to find fn with longest prefix
|
|
|
|
+ * match of the passed in prefix addr. This is useful for finding fn
|
|
|
|
+ * for cached route as it will be stored in the exception table under
|
|
|
|
+ * the node with longest prefix length.
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
|
|
static struct fib6_node *fib6_locate_1(struct fib6_node *root,
|
|
static struct fib6_node *fib6_locate_1(struct fib6_node *root,
|
|
const struct in6_addr *addr,
|
|
const struct in6_addr *addr,
|
|
- int plen, int offset)
|
|
|
|
|
|
+ int plen, int offset,
|
|
|
|
+ bool exact_match)
|
|
{
|
|
{
|
|
- struct fib6_node *fn;
|
|
|
|
|
|
+ struct fib6_node *fn, *prev = NULL;
|
|
|
|
|
|
for (fn = root; fn ; ) {
|
|
for (fn = root; fn ; ) {
|
|
- struct rt6key *key = (struct rt6key *)((u8 *)fn->leaf + offset);
|
|
|
|
|
|
+ struct rt6_info *leaf = rcu_dereference(fn->leaf);
|
|
|
|
+ struct rt6key *key;
|
|
|
|
+
|
|
|
|
+ /* This node is being deleted */
|
|
|
|
+ if (!leaf) {
|
|
|
|
+ if (plen <= fn->fn_bit)
|
|
|
|
+ goto out;
|
|
|
|
+ else
|
|
|
|
+ goto next;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ key = (struct rt6key *)((u8 *)leaf + offset);
|
|
|
|
|
|
/*
|
|
/*
|
|
* Prefix match
|
|
* Prefix match
|
|
*/
|
|
*/
|
|
if (plen < fn->fn_bit ||
|
|
if (plen < fn->fn_bit ||
|
|
!ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
|
|
!ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
|
|
- return NULL;
|
|
|
|
|
|
+ goto out;
|
|
|
|
|
|
if (plen == fn->fn_bit)
|
|
if (plen == fn->fn_bit)
|
|
return fn;
|
|
return fn;
|
|
|
|
|
|
|
|
+ prev = fn;
|
|
|
|
+
|
|
|
|
+next:
|
|
/*
|
|
/*
|
|
* We have more bits to go
|
|
* We have more bits to go
|
|
*/
|
|
*/
|
|
if (addr_bit_set(addr, fn->fn_bit))
|
|
if (addr_bit_set(addr, fn->fn_bit))
|
|
- fn = fn->right;
|
|
|
|
|
|
+ fn = rcu_dereference(fn->right);
|
|
else
|
|
else
|
|
- fn = fn->left;
|
|
|
|
|
|
+ fn = rcu_dereference(fn->left);
|
|
}
|
|
}
|
|
- return NULL;
|
|
|
|
|
|
+out:
|
|
|
|
+ if (exact_match)
|
|
|
|
+ return NULL;
|
|
|
|
+ else
|
|
|
|
+ return prev;
|
|
}
|
|
}
|
|
|
|
|
|
struct fib6_node *fib6_locate(struct fib6_node *root,
|
|
struct fib6_node *fib6_locate(struct fib6_node *root,
|
|
const struct in6_addr *daddr, int dst_len,
|
|
const struct in6_addr *daddr, int dst_len,
|
|
- const struct in6_addr *saddr, int src_len)
|
|
|
|
|
|
+ const struct in6_addr *saddr, int src_len,
|
|
|
|
+ bool exact_match)
|
|
{
|
|
{
|
|
struct fib6_node *fn;
|
|
struct fib6_node *fn;
|
|
|
|
|
|
fn = fib6_locate_1(root, daddr, dst_len,
|
|
fn = fib6_locate_1(root, daddr, dst_len,
|
|
- offsetof(struct rt6_info, rt6i_dst));
|
|
|
|
|
|
+ offsetof(struct rt6_info, rt6i_dst),
|
|
|
|
+ exact_match);
|
|
|
|
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
if (src_len) {
|
|
if (src_len) {
|
|
|
|
+ struct fib6_node *subtree = FIB6_SUBTREE(fn);
|
|
|
|
+
|
|
WARN_ON(saddr == NULL);
|
|
WARN_ON(saddr == NULL);
|
|
- if (fn && fn->subtree)
|
|
|
|
- fn = fib6_locate_1(fn->subtree, saddr, src_len,
|
|
|
|
- offsetof(struct rt6_info, rt6i_src));
|
|
|
|
|
|
+ if (fn && subtree)
|
|
|
|
+ fn = fib6_locate_1(subtree, saddr, src_len,
|
|
|
|
+ offsetof(struct rt6_info, rt6i_src),
|
|
|
|
+ exact_match);
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -1400,16 +1478,26 @@ struct fib6_node *fib6_locate(struct fib6_node *root,
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
|
|
|
|
-static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn)
|
|
|
|
|
|
+static struct rt6_info *fib6_find_prefix(struct net *net,
|
|
|
|
+ struct fib6_table *table,
|
|
|
|
+ struct fib6_node *fn)
|
|
{
|
|
{
|
|
|
|
+ struct fib6_node *child_left, *child_right;
|
|
|
|
+
|
|
if (fn->fn_flags & RTN_ROOT)
|
|
if (fn->fn_flags & RTN_ROOT)
|
|
return net->ipv6.ip6_null_entry;
|
|
return net->ipv6.ip6_null_entry;
|
|
|
|
|
|
while (fn) {
|
|
while (fn) {
|
|
- if (fn->left)
|
|
|
|
- return fn->left->leaf;
|
|
|
|
- if (fn->right)
|
|
|
|
- return fn->right->leaf;
|
|
|
|
|
|
+ child_left = rcu_dereference_protected(fn->left,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ child_right = rcu_dereference_protected(fn->right,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ if (child_left)
|
|
|
|
+ return rcu_dereference_protected(child_left->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ if (child_right)
|
|
|
|
+ return rcu_dereference_protected(child_right->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
|
|
fn = FIB6_SUBTREE(fn);
|
|
fn = FIB6_SUBTREE(fn);
|
|
}
|
|
}
|
|
@@ -1419,31 +1507,49 @@ static struct rt6_info *fib6_find_prefix(struct net *net, struct fib6_node *fn)
|
|
/*
|
|
/*
|
|
* Called to trim the tree of intermediate nodes when possible. "fn"
|
|
* Called to trim the tree of intermediate nodes when possible. "fn"
|
|
* is the node we want to try and remove.
|
|
* is the node we want to try and remove.
|
|
|
|
+ * Need to own table->tb6_lock
|
|
*/
|
|
*/
|
|
|
|
|
|
static struct fib6_node *fib6_repair_tree(struct net *net,
|
|
static struct fib6_node *fib6_repair_tree(struct net *net,
|
|
- struct fib6_node *fn)
|
|
|
|
|
|
+ struct fib6_table *table,
|
|
|
|
+ struct fib6_node *fn)
|
|
{
|
|
{
|
|
int children;
|
|
int children;
|
|
int nstate;
|
|
int nstate;
|
|
- struct fib6_node *child, *pn;
|
|
|
|
|
|
+ struct fib6_node *child;
|
|
struct fib6_walker *w;
|
|
struct fib6_walker *w;
|
|
int iter = 0;
|
|
int iter = 0;
|
|
|
|
|
|
for (;;) {
|
|
for (;;) {
|
|
|
|
+ struct fib6_node *fn_r = rcu_dereference_protected(fn->right,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct fib6_node *fn_l = rcu_dereference_protected(fn->left,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct fib6_node *pn = rcu_dereference_protected(fn->parent,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct fib6_node *pn_r = rcu_dereference_protected(pn->right,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct fib6_node *pn_l = rcu_dereference_protected(pn->left,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct rt6_info *fn_leaf = rcu_dereference_protected(fn->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct rt6_info *pn_leaf = rcu_dereference_protected(pn->leaf,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ struct rt6_info *new_fn_leaf;
|
|
|
|
+
|
|
RT6_TRACE("fixing tree: plen=%d iter=%d\n", fn->fn_bit, iter);
|
|
RT6_TRACE("fixing tree: plen=%d iter=%d\n", fn->fn_bit, iter);
|
|
iter++;
|
|
iter++;
|
|
|
|
|
|
WARN_ON(fn->fn_flags & RTN_RTINFO);
|
|
WARN_ON(fn->fn_flags & RTN_RTINFO);
|
|
WARN_ON(fn->fn_flags & RTN_TL_ROOT);
|
|
WARN_ON(fn->fn_flags & RTN_TL_ROOT);
|
|
- WARN_ON(fn->leaf);
|
|
|
|
|
|
+ WARN_ON(fn_leaf);
|
|
|
|
|
|
children = 0;
|
|
children = 0;
|
|
child = NULL;
|
|
child = NULL;
|
|
- if (fn->right)
|
|
|
|
- child = fn->right, children |= 1;
|
|
|
|
- if (fn->left)
|
|
|
|
- child = fn->left, children |= 2;
|
|
|
|
|
|
+ if (fn_r)
|
|
|
|
+ child = fn_r, children |= 1;
|
|
|
|
+ if (fn_l)
|
|
|
|
+ child = fn_l, children |= 2;
|
|
|
|
|
|
if (children == 3 || FIB6_SUBTREE(fn)
|
|
if (children == 3 || FIB6_SUBTREE(fn)
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
@@ -1451,36 +1557,36 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
|
|
|| (children && fn->fn_flags & RTN_ROOT)
|
|
|| (children && fn->fn_flags & RTN_ROOT)
|
|
#endif
|
|
#endif
|
|
) {
|
|
) {
|
|
- fn->leaf = fib6_find_prefix(net, fn);
|
|
|
|
|
|
+ new_fn_leaf = fib6_find_prefix(net, table, fn);
|
|
#if RT6_DEBUG >= 2
|
|
#if RT6_DEBUG >= 2
|
|
- if (!fn->leaf) {
|
|
|
|
- WARN_ON(!fn->leaf);
|
|
|
|
- fn->leaf = net->ipv6.ip6_null_entry;
|
|
|
|
|
|
+ if (!new_fn_leaf) {
|
|
|
|
+ WARN_ON(!new_fn_leaf);
|
|
|
|
+ new_fn_leaf = net->ipv6.ip6_null_entry;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
- atomic_inc(&fn->leaf->rt6i_ref);
|
|
|
|
- return fn->parent;
|
|
|
|
|
|
+ atomic_inc(&new_fn_leaf->rt6i_ref);
|
|
|
|
+ rcu_assign_pointer(fn->leaf, new_fn_leaf);
|
|
|
|
+ return pn;
|
|
}
|
|
}
|
|
|
|
|
|
- pn = fn->parent;
|
|
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
if (FIB6_SUBTREE(pn) == fn) {
|
|
if (FIB6_SUBTREE(pn) == fn) {
|
|
WARN_ON(!(fn->fn_flags & RTN_ROOT));
|
|
WARN_ON(!(fn->fn_flags & RTN_ROOT));
|
|
- FIB6_SUBTREE(pn) = NULL;
|
|
|
|
|
|
+ RCU_INIT_POINTER(pn->subtree, NULL);
|
|
nstate = FWS_L;
|
|
nstate = FWS_L;
|
|
} else {
|
|
} else {
|
|
WARN_ON(fn->fn_flags & RTN_ROOT);
|
|
WARN_ON(fn->fn_flags & RTN_ROOT);
|
|
#endif
|
|
#endif
|
|
- if (pn->right == fn)
|
|
|
|
- pn->right = child;
|
|
|
|
- else if (pn->left == fn)
|
|
|
|
- pn->left = child;
|
|
|
|
|
|
+ if (pn_r == fn)
|
|
|
|
+ rcu_assign_pointer(pn->right, child);
|
|
|
|
+ else if (pn_l == fn)
|
|
|
|
+ rcu_assign_pointer(pn->left, child);
|
|
#if RT6_DEBUG >= 2
|
|
#if RT6_DEBUG >= 2
|
|
else
|
|
else
|
|
WARN_ON(1);
|
|
WARN_ON(1);
|
|
#endif
|
|
#endif
|
|
if (child)
|
|
if (child)
|
|
- child->parent = pn;
|
|
|
|
|
|
+ rcu_assign_pointer(child->parent, pn);
|
|
nstate = FWS_R;
|
|
nstate = FWS_R;
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
}
|
|
}
|
|
@@ -1489,19 +1595,12 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
|
|
read_lock(&net->ipv6.fib6_walker_lock);
|
|
read_lock(&net->ipv6.fib6_walker_lock);
|
|
FOR_WALKERS(net, w) {
|
|
FOR_WALKERS(net, w) {
|
|
if (!child) {
|
|
if (!child) {
|
|
- if (w->root == fn) {
|
|
|
|
- w->root = w->node = NULL;
|
|
|
|
- RT6_TRACE("W %p adjusted by delroot 1\n", w);
|
|
|
|
- } else if (w->node == fn) {
|
|
|
|
|
|
+ if (w->node == fn) {
|
|
RT6_TRACE("W %p adjusted by delnode 1, s=%d/%d\n", w, w->state, nstate);
|
|
RT6_TRACE("W %p adjusted by delnode 1, s=%d/%d\n", w, w->state, nstate);
|
|
w->node = pn;
|
|
w->node = pn;
|
|
w->state = nstate;
|
|
w->state = nstate;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- if (w->root == fn) {
|
|
|
|
- w->root = child;
|
|
|
|
- RT6_TRACE("W %p adjusted by delroot 2\n", w);
|
|
|
|
- }
|
|
|
|
if (w->node == fn) {
|
|
if (w->node == fn) {
|
|
w->node = child;
|
|
w->node = child;
|
|
if (children&2) {
|
|
if (children&2) {
|
|
@@ -1516,33 +1615,39 @@ static struct fib6_node *fib6_repair_tree(struct net *net,
|
|
}
|
|
}
|
|
read_unlock(&net->ipv6.fib6_walker_lock);
|
|
read_unlock(&net->ipv6.fib6_walker_lock);
|
|
|
|
|
|
- node_free(fn);
|
|
|
|
|
|
+ node_free(net, fn);
|
|
if (pn->fn_flags & RTN_RTINFO || FIB6_SUBTREE(pn))
|
|
if (pn->fn_flags & RTN_RTINFO || FIB6_SUBTREE(pn))
|
|
return pn;
|
|
return pn;
|
|
|
|
|
|
- rt6_release(pn->leaf);
|
|
|
|
- pn->leaf = NULL;
|
|
|
|
|
|
+ RCU_INIT_POINTER(pn->leaf, NULL);
|
|
|
|
+ rt6_release(pn_leaf);
|
|
fn = pn;
|
|
fn = pn;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
|
|
|
|
- struct nl_info *info)
|
|
|
|
|
|
+static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn,
|
|
|
|
+ struct rt6_info __rcu **rtp, struct nl_info *info)
|
|
{
|
|
{
|
|
struct fib6_walker *w;
|
|
struct fib6_walker *w;
|
|
- struct rt6_info *rt = *rtp;
|
|
|
|
|
|
+ struct rt6_info *rt = rcu_dereference_protected(*rtp,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
struct net *net = info->nl_net;
|
|
struct net *net = info->nl_net;
|
|
|
|
|
|
RT6_TRACE("fib6_del_route\n");
|
|
RT6_TRACE("fib6_del_route\n");
|
|
|
|
|
|
|
|
+ WARN_ON_ONCE(rt->rt6i_flags & RTF_CACHE);
|
|
|
|
+
|
|
/* Unlink it */
|
|
/* Unlink it */
|
|
*rtp = rt->dst.rt6_next;
|
|
*rtp = rt->dst.rt6_next;
|
|
rt->rt6i_node = NULL;
|
|
rt->rt6i_node = NULL;
|
|
net->ipv6.rt6_stats->fib_rt_entries--;
|
|
net->ipv6.rt6_stats->fib_rt_entries--;
|
|
net->ipv6.rt6_stats->fib_discarded_routes++;
|
|
net->ipv6.rt6_stats->fib_discarded_routes++;
|
|
|
|
|
|
|
|
+ /* Flush all cached dst in exception table */
|
|
|
|
+ rt6_flush_exceptions(rt);
|
|
|
|
+
|
|
/* Reset round-robin state, if necessary */
|
|
/* Reset round-robin state, if necessary */
|
|
- if (fn->rr_ptr == rt)
|
|
|
|
|
|
+ if (rcu_access_pointer(fn->rr_ptr) == rt)
|
|
fn->rr_ptr = NULL;
|
|
fn->rr_ptr = NULL;
|
|
|
|
|
|
/* Remove this entry from other siblings */
|
|
/* Remove this entry from other siblings */
|
|
@@ -1561,20 +1666,19 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
|
|
FOR_WALKERS(net, w) {
|
|
FOR_WALKERS(net, w) {
|
|
if (w->state == FWS_C && w->leaf == rt) {
|
|
if (w->state == FWS_C && w->leaf == rt) {
|
|
RT6_TRACE("walker %p adjusted by delroute\n", w);
|
|
RT6_TRACE("walker %p adjusted by delroute\n", w);
|
|
- w->leaf = rt->dst.rt6_next;
|
|
|
|
|
|
+ w->leaf = rcu_dereference_protected(rt->dst.rt6_next,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
if (!w->leaf)
|
|
if (!w->leaf)
|
|
w->state = FWS_U;
|
|
w->state = FWS_U;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
read_unlock(&net->ipv6.fib6_walker_lock);
|
|
read_unlock(&net->ipv6.fib6_walker_lock);
|
|
|
|
|
|
- rt->dst.rt6_next = NULL;
|
|
|
|
-
|
|
|
|
/* If it was last route, expunge its radix tree node */
|
|
/* If it was last route, expunge its radix tree node */
|
|
- if (!fn->leaf) {
|
|
|
|
|
|
+ if (!rcu_access_pointer(fn->leaf)) {
|
|
fn->fn_flags &= ~RTN_RTINFO;
|
|
fn->fn_flags &= ~RTN_RTINFO;
|
|
net->ipv6.rt6_stats->fib_route_nodes--;
|
|
net->ipv6.rt6_stats->fib_route_nodes--;
|
|
- fn = fib6_repair_tree(net, fn);
|
|
|
|
|
|
+ fn = fib6_repair_tree(net, table, fn);
|
|
}
|
|
}
|
|
|
|
|
|
fib6_purge_rt(rt, fn, net);
|
|
fib6_purge_rt(rt, fn, net);
|
|
@@ -1585,12 +1689,15 @@ static void fib6_del_route(struct fib6_node *fn, struct rt6_info **rtp,
|
|
rt6_release(rt);
|
|
rt6_release(rt);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/* Need to own table->tb6_lock */
|
|
int fib6_del(struct rt6_info *rt, struct nl_info *info)
|
|
int fib6_del(struct rt6_info *rt, struct nl_info *info)
|
|
{
|
|
{
|
|
struct fib6_node *fn = rcu_dereference_protected(rt->rt6i_node,
|
|
struct fib6_node *fn = rcu_dereference_protected(rt->rt6i_node,
|
|
lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
lockdep_is_held(&rt->rt6i_table->tb6_lock));
|
|
|
|
+ struct fib6_table *table = rt->rt6i_table;
|
|
struct net *net = info->nl_net;
|
|
struct net *net = info->nl_net;
|
|
- struct rt6_info **rtp;
|
|
|
|
|
|
+ struct rt6_info __rcu **rtp;
|
|
|
|
+ struct rt6_info __rcu **rtp_next;
|
|
|
|
|
|
#if RT6_DEBUG >= 2
|
|
#if RT6_DEBUG >= 2
|
|
if (rt->dst.obsolete > 0) {
|
|
if (rt->dst.obsolete > 0) {
|
|
@@ -1603,28 +1710,22 @@ int fib6_del(struct rt6_info *rt, struct nl_info *info)
|
|
|
|
|
|
WARN_ON(!(fn->fn_flags & RTN_RTINFO));
|
|
WARN_ON(!(fn->fn_flags & RTN_RTINFO));
|
|
|
|
|
|
- if (!(rt->rt6i_flags & RTF_CACHE)) {
|
|
|
|
- struct fib6_node *pn = fn;
|
|
|
|
-#ifdef CONFIG_IPV6_SUBTREES
|
|
|
|
- /* clones of this route might be in another subtree */
|
|
|
|
- if (rt->rt6i_src.plen) {
|
|
|
|
- while (!(pn->fn_flags & RTN_ROOT))
|
|
|
|
- pn = pn->parent;
|
|
|
|
- pn = pn->parent;
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
- fib6_prune_clones(info->nl_net, pn);
|
|
|
|
- }
|
|
|
|
|
|
+ /* remove cached dst from exception table */
|
|
|
|
+ if (rt->rt6i_flags & RTF_CACHE)
|
|
|
|
+ return rt6_remove_exception_rt(rt);
|
|
|
|
|
|
/*
|
|
/*
|
|
* Walk the leaf entries looking for ourself
|
|
* Walk the leaf entries looking for ourself
|
|
*/
|
|
*/
|
|
|
|
|
|
- for (rtp = &fn->leaf; *rtp; rtp = &(*rtp)->dst.rt6_next) {
|
|
|
|
- if (*rtp == rt) {
|
|
|
|
- fib6_del_route(fn, rtp, info);
|
|
|
|
|
|
+ for (rtp = &fn->leaf; *rtp; rtp = rtp_next) {
|
|
|
|
+ struct rt6_info *cur = rcu_dereference_protected(*rtp,
|
|
|
|
+ lockdep_is_held(&table->tb6_lock));
|
|
|
|
+ if (rt == cur) {
|
|
|
|
+ fib6_del_route(table, fn, rtp, info);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
+ rtp_next = &cur->dst.rt6_next;
|
|
}
|
|
}
|
|
return -ENOENT;
|
|
return -ENOENT;
|
|
}
|
|
}
|
|
@@ -1651,22 +1752,22 @@ int fib6_del(struct rt6_info *rt, struct nl_info *info)
|
|
* 0 -> walk is complete.
|
|
* 0 -> walk is complete.
|
|
* >0 -> walk is incomplete (i.e. suspended)
|
|
* >0 -> walk is incomplete (i.e. suspended)
|
|
* <0 -> walk is terminated by an error.
|
|
* <0 -> walk is terminated by an error.
|
|
|
|
+ *
|
|
|
|
+ * This function is called with tb6_lock held.
|
|
*/
|
|
*/
|
|
|
|
|
|
static int fib6_walk_continue(struct fib6_walker *w)
|
|
static int fib6_walk_continue(struct fib6_walker *w)
|
|
{
|
|
{
|
|
- struct fib6_node *fn, *pn;
|
|
|
|
|
|
+ struct fib6_node *fn, *pn, *left, *right;
|
|
|
|
+
|
|
|
|
+ /* w->root should always be table->tb6_root */
|
|
|
|
+ WARN_ON_ONCE(!(w->root->fn_flags & RTN_TL_ROOT));
|
|
|
|
|
|
for (;;) {
|
|
for (;;) {
|
|
fn = w->node;
|
|
fn = w->node;
|
|
if (!fn)
|
|
if (!fn)
|
|
return 0;
|
|
return 0;
|
|
|
|
|
|
- if (w->prune && fn != w->root &&
|
|
|
|
- fn->fn_flags & RTN_RTINFO && w->state < FWS_C) {
|
|
|
|
- w->state = FWS_C;
|
|
|
|
- w->leaf = fn->leaf;
|
|
|
|
- }
|
|
|
|
switch (w->state) {
|
|
switch (w->state) {
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
case FWS_S:
|
|
case FWS_S:
|
|
@@ -1677,20 +1778,22 @@ static int fib6_walk_continue(struct fib6_walker *w)
|
|
w->state = FWS_L;
|
|
w->state = FWS_L;
|
|
#endif
|
|
#endif
|
|
case FWS_L:
|
|
case FWS_L:
|
|
- if (fn->left) {
|
|
|
|
- w->node = fn->left;
|
|
|
|
|
|
+ left = rcu_dereference_protected(fn->left, 1);
|
|
|
|
+ if (left) {
|
|
|
|
+ w->node = left;
|
|
w->state = FWS_INIT;
|
|
w->state = FWS_INIT;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
w->state = FWS_R;
|
|
w->state = FWS_R;
|
|
case FWS_R:
|
|
case FWS_R:
|
|
- if (fn->right) {
|
|
|
|
- w->node = fn->right;
|
|
|
|
|
|
+ right = rcu_dereference_protected(fn->right, 1);
|
|
|
|
+ if (right) {
|
|
|
|
+ w->node = right;
|
|
w->state = FWS_INIT;
|
|
w->state = FWS_INIT;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
w->state = FWS_C;
|
|
w->state = FWS_C;
|
|
- w->leaf = fn->leaf;
|
|
|
|
|
|
+ w->leaf = rcu_dereference_protected(fn->leaf, 1);
|
|
case FWS_C:
|
|
case FWS_C:
|
|
if (w->leaf && fn->fn_flags & RTN_RTINFO) {
|
|
if (w->leaf && fn->fn_flags & RTN_RTINFO) {
|
|
int err;
|
|
int err;
|
|
@@ -1712,7 +1815,9 @@ skip:
|
|
case FWS_U:
|
|
case FWS_U:
|
|
if (fn == w->root)
|
|
if (fn == w->root)
|
|
return 0;
|
|
return 0;
|
|
- pn = fn->parent;
|
|
|
|
|
|
+ pn = rcu_dereference_protected(fn->parent, 1);
|
|
|
|
+ left = rcu_dereference_protected(pn->left, 1);
|
|
|
|
+ right = rcu_dereference_protected(pn->right, 1);
|
|
w->node = pn;
|
|
w->node = pn;
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
#ifdef CONFIG_IPV6_SUBTREES
|
|
if (FIB6_SUBTREE(pn) == fn) {
|
|
if (FIB6_SUBTREE(pn) == fn) {
|
|
@@ -1721,13 +1826,13 @@ skip:
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
- if (pn->left == fn) {
|
|
|
|
|
|
+ if (left == fn) {
|
|
w->state = FWS_R;
|
|
w->state = FWS_R;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- if (pn->right == fn) {
|
|
|
|
|
|
+ if (right == fn) {
|
|
w->state = FWS_C;
|
|
w->state = FWS_C;
|
|
- w->leaf = w->node->leaf;
|
|
|
|
|
|
+ w->leaf = rcu_dereference_protected(w->node->leaf, 1);
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
#if RT6_DEBUG >= 2
|
|
#if RT6_DEBUG >= 2
|
|
@@ -1770,7 +1875,7 @@ static int fib6_clean_node(struct fib6_walker *w)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
- for (rt = w->leaf; rt; rt = rt->dst.rt6_next) {
|
|
|
|
|
|
+ for_each_fib6_walker_rt(w) {
|
|
res = c->func(rt, c->arg);
|
|
res = c->func(rt, c->arg);
|
|
if (res < 0) {
|
|
if (res < 0) {
|
|
w->leaf = rt;
|
|
w->leaf = rt;
|
|
@@ -1798,20 +1903,16 @@ static int fib6_clean_node(struct fib6_walker *w)
|
|
* func is called on each route.
|
|
* func is called on each route.
|
|
* It may return -1 -> delete this route.
|
|
* It may return -1 -> delete this route.
|
|
* 0 -> continue walking
|
|
* 0 -> continue walking
|
|
- *
|
|
|
|
- * prune==1 -> only immediate children of node (certainly,
|
|
|
|
- * ignoring pure split nodes) will be scanned.
|
|
|
|
*/
|
|
*/
|
|
|
|
|
|
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, int sernum, void *arg)
|
|
|
|
|
|
+ int sernum, void *arg)
|
|
{
|
|
{
|
|
struct fib6_cleaner c;
|
|
struct fib6_cleaner c;
|
|
|
|
|
|
c.w.root = root;
|
|
c.w.root = root;
|
|
c.w.func = fib6_clean_node;
|
|
c.w.func = fib6_clean_node;
|
|
- c.w.prune = prune;
|
|
|
|
c.w.count = 0;
|
|
c.w.count = 0;
|
|
c.w.skip = 0;
|
|
c.w.skip = 0;
|
|
c.func = func;
|
|
c.func = func;
|
|
@@ -1834,10 +1935,10 @@ static void __fib6_clean_all(struct net *net,
|
|
for (h = 0; h < FIB6_TABLE_HASHSZ; h++) {
|
|
for (h = 0; h < FIB6_TABLE_HASHSZ; h++) {
|
|
head = &net->ipv6.fib_table_hash[h];
|
|
head = &net->ipv6.fib_table_hash[h];
|
|
hlist_for_each_entry_rcu(table, head, tb6_hlist) {
|
|
hlist_for_each_entry_rcu(table, head, tb6_hlist) {
|
|
- write_lock_bh(&table->tb6_lock);
|
|
|
|
|
|
+ spin_lock_bh(&table->tb6_lock);
|
|
fib6_clean_tree(net, &table->tb6_root,
|
|
fib6_clean_tree(net, &table->tb6_root,
|
|
- func, false, sernum, arg);
|
|
|
|
- write_unlock_bh(&table->tb6_lock);
|
|
|
|
|
|
+ func, sernum, arg);
|
|
|
|
+ spin_unlock_bh(&table->tb6_lock);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
rcu_read_unlock();
|
|
rcu_read_unlock();
|
|
@@ -1849,22 +1950,6 @@ void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *),
|
|
__fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg);
|
|
__fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg);
|
|
}
|
|
}
|
|
|
|
|
|
-static int fib6_prune_clone(struct rt6_info *rt, void *arg)
|
|
|
|
-{
|
|
|
|
- if (rt->rt6i_flags & RTF_CACHE) {
|
|
|
|
- RT6_TRACE("pruning clone %p\n", rt);
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void fib6_prune_clones(struct net *net, struct fib6_node *fn)
|
|
|
|
-{
|
|
|
|
- fib6_clean_tree(net, fn, fib6_prune_clone, true,
|
|
|
|
- FIB6_NO_SERNUM_CHANGE, NULL);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
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);
|
|
@@ -1876,12 +1961,6 @@ static void fib6_flush_trees(struct net *net)
|
|
* Garbage collection
|
|
* Garbage collection
|
|
*/
|
|
*/
|
|
|
|
|
|
-struct fib6_gc_args
|
|
|
|
-{
|
|
|
|
- int timeout;
|
|
|
|
- int more;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
static int fib6_age(struct rt6_info *rt, void *arg)
|
|
static int fib6_age(struct rt6_info *rt, void *arg)
|
|
{
|
|
{
|
|
struct fib6_gc_args *gc_args = arg;
|
|
struct fib6_gc_args *gc_args = arg;
|
|
@@ -1890,9 +1969,6 @@ static int fib6_age(struct rt6_info *rt, void *arg)
|
|
/*
|
|
/*
|
|
* check addrconf expiration here.
|
|
* check addrconf expiration here.
|
|
* Routes are expired even if they are in use.
|
|
* Routes are expired even if they are in use.
|
|
- *
|
|
|
|
- * Also age clones. Note, that clones are aged out
|
|
|
|
- * only if they are not in use now.
|
|
|
|
*/
|
|
*/
|
|
|
|
|
|
if (rt->rt6i_flags & RTF_EXPIRES && rt->dst.expires) {
|
|
if (rt->rt6i_flags & RTF_EXPIRES && rt->dst.expires) {
|
|
@@ -1901,31 +1977,14 @@ static int fib6_age(struct rt6_info *rt, void *arg)
|
|
return -1;
|
|
return -1;
|
|
}
|
|
}
|
|
gc_args->more++;
|
|
gc_args->more++;
|
|
- } else if (rt->rt6i_flags & RTF_CACHE) {
|
|
|
|
- if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout))
|
|
|
|
- rt->dst.obsolete = DST_OBSOLETE_KILL;
|
|
|
|
- if (atomic_read(&rt->dst.__refcnt) == 1 &&
|
|
|
|
- rt->dst.obsolete == DST_OBSOLETE_KILL) {
|
|
|
|
- RT6_TRACE("aging clone %p\n", rt);
|
|
|
|
- return -1;
|
|
|
|
- } else if (rt->rt6i_flags & RTF_GATEWAY) {
|
|
|
|
- struct neighbour *neigh;
|
|
|
|
- __u8 neigh_flags = 0;
|
|
|
|
-
|
|
|
|
- neigh = dst_neigh_lookup(&rt->dst, &rt->rt6i_gateway);
|
|
|
|
- if (neigh) {
|
|
|
|
- neigh_flags = neigh->flags;
|
|
|
|
- neigh_release(neigh);
|
|
|
|
- }
|
|
|
|
- if (!(neigh_flags & NTF_ROUTER)) {
|
|
|
|
- RT6_TRACE("purging route %p via non-router but gateway\n",
|
|
|
|
- rt);
|
|
|
|
- return -1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- gc_args->more++;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* Also age clones in the exception table.
|
|
|
|
+ * Note, that clones are aged out
|
|
|
|
+ * only if they are not in use now.
|
|
|
|
+ */
|
|
|
|
+ rt6_age_exceptions(rt, gc_args, now);
|
|
|
|
+
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1993,7 +2052,8 @@ static int __net_init fib6_net_init(struct net *net)
|
|
goto out_fib_table_hash;
|
|
goto out_fib_table_hash;
|
|
|
|
|
|
net->ipv6.fib6_main_tbl->tb6_id = RT6_TABLE_MAIN;
|
|
net->ipv6.fib6_main_tbl->tb6_id = RT6_TABLE_MAIN;
|
|
- net->ipv6.fib6_main_tbl->tb6_root.leaf = net->ipv6.ip6_null_entry;
|
|
|
|
|
|
+ rcu_assign_pointer(net->ipv6.fib6_main_tbl->tb6_root.leaf,
|
|
|
|
+ net->ipv6.ip6_null_entry);
|
|
net->ipv6.fib6_main_tbl->tb6_root.fn_flags =
|
|
net->ipv6.fib6_main_tbl->tb6_root.fn_flags =
|
|
RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
|
|
RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
|
|
inet_peer_base_init(&net->ipv6.fib6_main_tbl->tb6_peers);
|
|
inet_peer_base_init(&net->ipv6.fib6_main_tbl->tb6_peers);
|
|
@@ -2004,7 +2064,8 @@ static int __net_init fib6_net_init(struct net *net)
|
|
if (!net->ipv6.fib6_local_tbl)
|
|
if (!net->ipv6.fib6_local_tbl)
|
|
goto out_fib6_main_tbl;
|
|
goto out_fib6_main_tbl;
|
|
net->ipv6.fib6_local_tbl->tb6_id = RT6_TABLE_LOCAL;
|
|
net->ipv6.fib6_local_tbl->tb6_id = RT6_TABLE_LOCAL;
|
|
- net->ipv6.fib6_local_tbl->tb6_root.leaf = net->ipv6.ip6_null_entry;
|
|
|
|
|
|
+ rcu_assign_pointer(net->ipv6.fib6_local_tbl->tb6_root.leaf,
|
|
|
|
+ net->ipv6.ip6_null_entry);
|
|
net->ipv6.fib6_local_tbl->tb6_root.fn_flags =
|
|
net->ipv6.fib6_local_tbl->tb6_root.fn_flags =
|
|
RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
|
|
RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
|
|
inet_peer_base_init(&net->ipv6.fib6_local_tbl->tb6_peers);
|
|
inet_peer_base_init(&net->ipv6.fib6_local_tbl->tb6_peers);
|
|
@@ -2134,7 +2195,9 @@ static int ipv6_route_yield(struct fib6_walker *w)
|
|
return 1;
|
|
return 1;
|
|
|
|
|
|
do {
|
|
do {
|
|
- iter->w.leaf = iter->w.leaf->dst.rt6_next;
|
|
|
|
|
|
+ iter->w.leaf = rcu_dereference_protected(
|
|
|
|
+ iter->w.leaf->dst.rt6_next,
|
|
|
|
+ lockdep_is_held(&iter->tbl->tb6_lock));
|
|
iter->skip--;
|
|
iter->skip--;
|
|
if (!iter->skip && iter->w.leaf)
|
|
if (!iter->skip && iter->w.leaf)
|
|
return 1;
|
|
return 1;
|
|
@@ -2199,7 +2262,7 @@ static void *ipv6_route_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
if (!v)
|
|
if (!v)
|
|
goto iter_table;
|
|
goto iter_table;
|
|
|
|
|
|
- n = ((struct rt6_info *)v)->dst.rt6_next;
|
|
|
|
|
|
+ n = rcu_dereference(((struct rt6_info *)v)->dst.rt6_next);
|
|
if (n) {
|
|
if (n) {
|
|
++*pos;
|
|
++*pos;
|
|
return n;
|
|
return n;
|
|
@@ -2207,9 +2270,9 @@ static void *ipv6_route_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
|
|
|
|
|
iter_table:
|
|
iter_table:
|
|
ipv6_route_check_sernum(iter);
|
|
ipv6_route_check_sernum(iter);
|
|
- read_lock(&iter->tbl->tb6_lock);
|
|
|
|
|
|
+ spin_lock_bh(&iter->tbl->tb6_lock);
|
|
r = fib6_walk_continue(&iter->w);
|
|
r = fib6_walk_continue(&iter->w);
|
|
- read_unlock(&iter->tbl->tb6_lock);
|
|
|
|
|
|
+ spin_unlock_bh(&iter->tbl->tb6_lock);
|
|
if (r > 0) {
|
|
if (r > 0) {
|
|
if (v)
|
|
if (v)
|
|
++*pos;
|
|
++*pos;
|