Commit 55c894f7 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: fib_notifier: propagate possible error during fib notifier registration

Unlike events for registered notifier, during the registration, the
errors that happened for the block being registered are not propagated
up to the caller. Make sure the error is propagated for FIB rules and
entries.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7c550daf
...@@ -229,7 +229,7 @@ int __net_init fib4_notifier_init(struct net *net); ...@@ -229,7 +229,7 @@ int __net_init fib4_notifier_init(struct net *net);
void __net_exit fib4_notifier_exit(struct net *net); void __net_exit fib4_notifier_exit(struct net *net);
void fib_info_notify_update(struct net *net, struct nl_info *info); void fib_info_notify_update(struct net *net, struct nl_info *info);
void fib_notify(struct net *net, struct notifier_block *nb); int fib_notify(struct net *net, struct notifier_block *nb);
struct fib_table { struct fib_table {
struct hlist_node tb_hlist; struct hlist_node tb_hlist;
......
...@@ -354,15 +354,20 @@ int fib_rules_dump(struct net *net, struct notifier_block *nb, int family) ...@@ -354,15 +354,20 @@ int fib_rules_dump(struct net *net, struct notifier_block *nb, int family)
{ {
struct fib_rules_ops *ops; struct fib_rules_ops *ops;
struct fib_rule *rule; struct fib_rule *rule;
int err = 0;
ops = lookup_rules_ops(net, family); ops = lookup_rules_ops(net, family);
if (!ops) if (!ops)
return -EAFNOSUPPORT; return -EAFNOSUPPORT;
list_for_each_entry_rcu(rule, &ops->rules_list, list) list_for_each_entry_rcu(rule, &ops->rules_list, list) {
call_fib_rule_notifier(nb, FIB_EVENT_RULE_ADD, rule, family); err = call_fib_rule_notifier(nb, FIB_EVENT_RULE_ADD,
rule, family);
if (err)
break;
}
rules_ops_put(ops); rules_ops_put(ops);
return 0; return err;
} }
EXPORT_SYMBOL_GPL(fib_rules_dump); EXPORT_SYMBOL_GPL(fib_rules_dump);
......
...@@ -42,9 +42,7 @@ static int fib4_dump(struct net *net, struct notifier_block *nb) ...@@ -42,9 +42,7 @@ static int fib4_dump(struct net *net, struct notifier_block *nb)
if (err) if (err)
return err; return err;
fib_notify(net, nb); return fib_notify(net, nb);
return 0;
} }
static const struct fib_notifier_ops fib4_notifier_ops_template = { static const struct fib_notifier_ops fib4_notifier_ops_template = {
......
...@@ -2015,10 +2015,11 @@ void fib_info_notify_update(struct net *net, struct nl_info *info) ...@@ -2015,10 +2015,11 @@ void fib_info_notify_update(struct net *net, struct nl_info *info)
} }
} }
static void fib_leaf_notify(struct key_vector *l, struct fib_table *tb, static int fib_leaf_notify(struct key_vector *l, struct fib_table *tb,
struct notifier_block *nb) struct notifier_block *nb)
{ {
struct fib_alias *fa; struct fib_alias *fa;
int err;
hlist_for_each_entry_rcu(fa, &l->leaf, fa_list) { hlist_for_each_entry_rcu(fa, &l->leaf, fa_list) {
struct fib_info *fi = fa->fa_info; struct fib_info *fi = fa->fa_info;
...@@ -2032,38 +2033,50 @@ static void fib_leaf_notify(struct key_vector *l, struct fib_table *tb, ...@@ -2032,38 +2033,50 @@ static void fib_leaf_notify(struct key_vector *l, struct fib_table *tb,
if (tb->tb_id != fa->tb_id) if (tb->tb_id != fa->tb_id)
continue; continue;
call_fib_entry_notifier(nb, FIB_EVENT_ENTRY_ADD, l->key, err = call_fib_entry_notifier(nb, FIB_EVENT_ENTRY_ADD, l->key,
KEYLENGTH - fa->fa_slen, fa); KEYLENGTH - fa->fa_slen, fa);
if (err)
return err;
} }
return 0;
} }
static void fib_table_notify(struct fib_table *tb, struct notifier_block *nb) static int fib_table_notify(struct fib_table *tb, struct notifier_block *nb)
{ {
struct trie *t = (struct trie *)tb->tb_data; struct trie *t = (struct trie *)tb->tb_data;
struct key_vector *l, *tp = t->kv; struct key_vector *l, *tp = t->kv;
t_key key = 0; t_key key = 0;
int err;
while ((l = leaf_walk_rcu(&tp, key)) != NULL) { while ((l = leaf_walk_rcu(&tp, key)) != NULL) {
fib_leaf_notify(l, tb, nb); err = fib_leaf_notify(l, tb, nb);
if (err)
return err;
key = l->key + 1; key = l->key + 1;
/* stop in case of wrap around */ /* stop in case of wrap around */
if (key < l->key) if (key < l->key)
break; break;
} }
return 0;
} }
void fib_notify(struct net *net, struct notifier_block *nb) int fib_notify(struct net *net, struct notifier_block *nb)
{ {
unsigned int h; unsigned int h;
int err;
for (h = 0; h < FIB_TABLE_HASHSZ; h++) { for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
struct hlist_head *head = &net->ipv4.fib_table_hash[h]; struct hlist_head *head = &net->ipv4.fib_table_hash[h];
struct fib_table *tb; struct fib_table *tb;
hlist_for_each_entry_rcu(tb, head, tb_hlist) hlist_for_each_entry_rcu(tb, head, tb_hlist) {
fib_table_notify(tb, nb); err = fib_table_notify(tb, nb);
if (err)
return err;
}
} }
return 0;
} }
static void __trie_free_rcu(struct rcu_head *head) static void __trie_free_rcu(struct rcu_head *head)
......
...@@ -409,17 +409,25 @@ int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family, ...@@ -409,17 +409,25 @@ int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family,
if (!v->dev) if (!v->dev)
continue; continue;
mr_call_vif_notifier(nb, family, err = mr_call_vif_notifier(nb, family,
FIB_EVENT_VIF_ADD, FIB_EVENT_VIF_ADD,
v, vifi, mrt->id); v, vifi, mrt->id);
if (err)
break;
} }
read_unlock(mrt_lock); read_unlock(mrt_lock);
if (err)
return err;
/* Notify on table MFC entries */ /* Notify on table MFC entries */
list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list) list_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list) {
mr_call_mfc_notifier(nb, family, err = mr_call_mfc_notifier(nb, family,
FIB_EVENT_ENTRY_ADD, FIB_EVENT_ENTRY_ADD,
mfc, mrt->id); mfc, mrt->id);
if (err)
return err;
}
} }
return 0; return 0;
......
...@@ -403,30 +403,37 @@ struct fib6_dump_arg { ...@@ -403,30 +403,37 @@ struct fib6_dump_arg {
struct notifier_block *nb; struct notifier_block *nb;
}; };
static void fib6_rt_dump(struct fib6_info *rt, struct fib6_dump_arg *arg) static int fib6_rt_dump(struct fib6_info *rt, struct fib6_dump_arg *arg)
{ {
if (rt == arg->net->ipv6.fib6_null_entry) if (rt == arg->net->ipv6.fib6_null_entry)
return; return 0;
call_fib6_entry_notifier(arg->nb, FIB_EVENT_ENTRY_ADD, rt); return call_fib6_entry_notifier(arg->nb, FIB_EVENT_ENTRY_ADD, rt);
} }
static int fib6_node_dump(struct fib6_walker *w) static int fib6_node_dump(struct fib6_walker *w)
{ {
struct fib6_info *rt; struct fib6_info *rt;
int err = 0;
for_each_fib6_walker_rt(w) for_each_fib6_walker_rt(w) {
fib6_rt_dump(rt, w->args); err = fib6_rt_dump(rt, w->args);
if (err)
break;
}
w->leaf = NULL; w->leaf = NULL;
return 0; return err;
} }
static void fib6_table_dump(struct net *net, struct fib6_table *tb, static int fib6_table_dump(struct net *net, struct fib6_table *tb,
struct fib6_walker *w) struct fib6_walker *w)
{ {
int err;
w->root = &tb->tb6_root; w->root = &tb->tb6_root;
spin_lock_bh(&tb->tb6_lock); spin_lock_bh(&tb->tb6_lock);
fib6_walk(net, w); err = fib6_walk(net, w);
spin_unlock_bh(&tb->tb6_lock); spin_unlock_bh(&tb->tb6_lock);
return err;
} }
/* Called with rcu_read_lock() */ /* Called with rcu_read_lock() */
...@@ -435,6 +442,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb) ...@@ -435,6 +442,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb)
struct fib6_dump_arg arg; struct fib6_dump_arg arg;
struct fib6_walker *w; struct fib6_walker *w;
unsigned int h; unsigned int h;
int err = 0;
w = kzalloc(sizeof(*w), GFP_ATOMIC); w = kzalloc(sizeof(*w), GFP_ATOMIC);
if (!w) if (!w)
...@@ -449,13 +457,17 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb) ...@@ -449,13 +457,17 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb)
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) hlist_for_each_entry_rcu(tb, head, tb6_hlist) {
fib6_table_dump(net, tb, w); err = fib6_table_dump(net, tb, w);
if (err < 0)
goto out;
}
} }
out:
kfree(w); kfree(w);
return 0; return err;
} }
static int fib6_dump_node(struct fib6_walker *w) static int fib6_dump_node(struct fib6_walker *w)
......
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