Skip to content

Commit

Permalink
net: fib_notifier: propagate extack down to the notifier block callback
Browse files Browse the repository at this point in the history
Since errors are propagated all the way up to the caller, propagate
possible extack of the caller all the way down to the notifier block
callback.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
jpirko authored and davem330 committed Oct 4, 2019
1 parent 3f9e5c1 commit b7a5955
Show file tree
Hide file tree
Showing 20 changed files with 105 additions and 61 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/lag_mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int mlx5_lag_mp_init(struct mlx5_lag *ldev)

mp->fib_nb.notifier_call = mlx5_lag_fib_event;
err = register_fib_notifier(&init_net, &mp->fib_nb,
mlx5_lag_fib_event_flush);
mlx5_lag_fib_event_flush, NULL);
if (err)
mp->fib_nb.notifier_call = NULL;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
Original file line number Diff line number Diff line change
Expand Up @@ -8135,7 +8135,7 @@ int mlxsw_sp_router_init(struct mlxsw_sp *mlxsw_sp)

mlxsw_sp->router->fib_nb.notifier_call = mlxsw_sp_router_fib_event;
err = register_fib_notifier(&init_net, &mlxsw_sp->router->fib_nb,
mlxsw_sp_router_fib_dump_flush);
mlxsw_sp_router_fib_dump_flush, NULL);
if (err)
goto err_register_fib_notifier;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/rocker/rocker_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2991,7 +2991,7 @@ static int rocker_probe(struct pci_dev *pdev, const struct pci_device_id *id)
* the device, so no need to pass a callback.
*/
rocker->fib_nb.notifier_call = rocker_router_fib_event;
err = register_fib_notifier(&init_net, &rocker->fib_nb, NULL);
err = register_fib_notifier(&init_net, &rocker->fib_nb, NULL, NULL);
if (err)
goto err_register_fib_notifier;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/netdevsim/fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ struct nsim_fib_data *nsim_fib_create(struct devlink *devlink)

data->fib_nb.notifier_call = nsim_fib_event_nb;
err = register_fib_notifier(&init_net, &data->fib_nb,
nsim_fib_dump_inconsistent);
nsim_fib_dump_inconsistent, NULL);
if (err) {
pr_err("Failed to register fib notifier\n");
goto err_out;
Expand Down
18 changes: 12 additions & 6 deletions include/linux/mroute_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ static inline int mr_call_vif_notifier(struct notifier_block *nb,
unsigned short family,
enum fib_event_type event_type,
struct vif_device *vif,
unsigned short vif_index, u32 tb_id)
unsigned short vif_index, u32 tb_id,
struct netlink_ext_ack *extack)
{
struct vif_entry_notifier_info info = {
.info = {
.family = family,
.extack = extack,
},
.dev = vif->dev,
.vif_index = vif_index,
Expand Down Expand Up @@ -172,11 +174,13 @@ struct mfc_entry_notifier_info {
static inline int mr_call_mfc_notifier(struct notifier_block *nb,
unsigned short family,
enum fib_event_type event_type,
struct mr_mfc *mfc, u32 tb_id)
struct mr_mfc *mfc, u32 tb_id,
struct netlink_ext_ack *extack)
{
struct mfc_entry_notifier_info info = {
.info = {
.family = family,
.extack = extack,
},
.mfc = mfc,
.tb_id = tb_id
Expand Down Expand Up @@ -295,10 +299,11 @@ int mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,

int mr_dump(struct net *net, struct notifier_block *nb, unsigned short family,
int (*rules_dump)(struct net *net,
struct notifier_block *nb),
struct notifier_block *nb,
struct netlink_ext_ack *extack),
struct mr_table *(*mr_iter)(struct net *net,
struct mr_table *mrt),
rwlock_t *mrt_lock);
rwlock_t *mrt_lock, struct netlink_ext_ack *extack);
#else
static inline void vif_device_init(struct vif_device *v,
struct net_device *dev,
Expand Down Expand Up @@ -349,10 +354,11 @@ mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb,
static inline int mr_dump(struct net *net, struct notifier_block *nb,
unsigned short family,
int (*rules_dump)(struct net *net,
struct notifier_block *nb),
struct notifier_block *nb,
struct netlink_ext_ack *extack),
struct mr_table *(*mr_iter)(struct net *net,
struct mr_table *mrt),
rwlock_t *mrt_lock)
rwlock_t *mrt_lock, struct netlink_ext_ack *extack)
{
return -EINVAL;
}
Expand Down
6 changes: 4 additions & 2 deletions include/net/fib_notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ struct fib_notifier_ops {
int family;
struct list_head list;
unsigned int (*fib_seq_read)(struct net *net);
int (*fib_dump)(struct net *net, struct notifier_block *nb);
int (*fib_dump)(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack);
struct module *owner;
struct rcu_head rcu;
};
Expand All @@ -40,7 +41,8 @@ int call_fib_notifier(struct notifier_block *nb,
int call_fib_notifiers(struct net *net, enum fib_event_type event_type,
struct fib_notifier_info *info);
int register_fib_notifier(struct net *net, struct notifier_block *nb,
void (*cb)(struct notifier_block *nb));
void (*cb)(struct notifier_block *nb),
struct netlink_ext_ack *extack);
int unregister_fib_notifier(struct net *net, struct notifier_block *nb);
struct fib_notifier_ops *
fib_notifier_ops_register(const struct fib_notifier_ops *tmpl, struct net *net);
Expand Down
3 changes: 2 additions & 1 deletion include/net/fib_rules.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ int fib_rules_lookup(struct fib_rules_ops *, struct flowi *, int flags,
int fib_default_rule_add(struct fib_rules_ops *, u32 pref, u32 table,
u32 flags);
bool fib_rule_matchall(const struct fib_rule *rule);
int fib_rules_dump(struct net *net, struct notifier_block *nb, int family);
int fib_rules_dump(struct net *net, struct notifier_block *nb, int family,
struct netlink_ext_ack *extack);
unsigned int fib_rules_seq_read(struct net *net, int family);

int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
Expand Down
9 changes: 6 additions & 3 deletions include/net/ip6_fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ int __net_init fib6_notifier_init(struct net *net);
void __net_exit fib6_notifier_exit(struct net *net);

unsigned int fib6_tables_seq_read(struct net *net);
int fib6_tables_dump(struct net *net, struct notifier_block *nb);
int fib6_tables_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack);

void fib6_update_sernum(struct net *net, struct fib6_info *rt);
void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt);
Expand All @@ -504,7 +505,8 @@ static inline bool fib6_metric_locked(struct fib6_info *f6i, int metric)
int fib6_rules_init(void);
void fib6_rules_cleanup(void);
bool fib6_rule_default(const struct fib_rule *rule);
int fib6_rules_dump(struct net *net, struct notifier_block *nb);
int fib6_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack);
unsigned int fib6_rules_seq_read(struct net *net);

static inline bool fib6_rules_early_flow_dissect(struct net *net,
Expand Down Expand Up @@ -537,7 +539,8 @@ static inline bool fib6_rule_default(const struct fib_rule *rule)
{
return true;
}
static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb)
static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return 0;
}
Expand Down
9 changes: 6 additions & 3 deletions include/net/ip_fib.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ int __net_init fib4_notifier_init(struct net *net);
void __net_exit fib4_notifier_exit(struct net *net);

void fib_info_notify_update(struct net *net, struct nl_info *info);
int fib_notify(struct net *net, struct notifier_block *nb);
int fib_notify(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack);

struct fib_table {
struct hlist_node tb_hlist;
Expand Down Expand Up @@ -315,7 +316,8 @@ static inline bool fib4_rule_default(const struct fib_rule *rule)
return true;
}

static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb)
static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return 0;
}
Expand Down Expand Up @@ -377,7 +379,8 @@ static inline int fib_lookup(struct net *net, struct flowi4 *flp,
}

bool fib4_rule_default(const struct fib_rule *rule);
int fib4_rules_dump(struct net *net, struct notifier_block *nb);
int fib4_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack);
unsigned int fib4_rules_seq_read(struct net *net);

static inline bool fib4_rules_early_flow_dissect(struct net *net,
Expand Down
10 changes: 6 additions & 4 deletions net/core/fib_notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ static unsigned int fib_seq_sum(struct net *net)
return fib_seq;
}

static int fib_net_dump(struct net *net, struct notifier_block *nb)
static int fib_net_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
struct fib_notifier_net *fn_net = net_generic(net, fib_notifier_net_id);
struct fib_notifier_ops *ops;
Expand All @@ -67,7 +68,7 @@ static int fib_net_dump(struct net *net, struct notifier_block *nb)
list_for_each_entry_rcu(ops, &fn_net->fib_notifier_ops, list) {
if (!try_module_get(ops->owner))
continue;
err = ops->fib_dump(net, nb);
err = ops->fib_dump(net, nb, extack);
module_put(ops->owner);
if (err)
goto unlock;
Expand Down Expand Up @@ -96,15 +97,16 @@ static bool fib_dump_is_consistent(struct net *net, struct notifier_block *nb,

#define FIB_DUMP_MAX_RETRIES 5
int register_fib_notifier(struct net *net, struct notifier_block *nb,
void (*cb)(struct notifier_block *nb))
void (*cb)(struct notifier_block *nb),
struct netlink_ext_ack *extack)
{
int retries = 0;
int err;

do {
unsigned int fib_seq = fib_seq_sum(net);

err = fib_net_dump(net, nb);
err = fib_net_dump(net, nb, extack);
if (err)
return err;

Expand Down
9 changes: 6 additions & 3 deletions net/core/fib_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,12 @@ EXPORT_SYMBOL_GPL(fib_rules_lookup);

static int call_fib_rule_notifier(struct notifier_block *nb,
enum fib_event_type event_type,
struct fib_rule *rule, int family)
struct fib_rule *rule, int family,
struct netlink_ext_ack *extack)
{
struct fib_rule_notifier_info info = {
.info.family = family,
.info.extack = extack,
.rule = rule,
};

Expand All @@ -350,7 +352,8 @@ static int call_fib_rule_notifiers(struct net *net,
}

/* Called with rcu_read_lock() */
int fib_rules_dump(struct net *net, struct notifier_block *nb, int family)
int fib_rules_dump(struct net *net, struct notifier_block *nb, int family,
struct netlink_ext_ack *extack)
{
struct fib_rules_ops *ops;
struct fib_rule *rule;
Expand All @@ -361,7 +364,7 @@ int fib_rules_dump(struct net *net, struct notifier_block *nb, int family)
return -EAFNOSUPPORT;
list_for_each_entry_rcu(rule, &ops->rules_list, list) {
err = call_fib_rule_notifier(nb, FIB_EVENT_RULE_ADD,
rule, family);
rule, family, extack);
if (err)
break;
}
Expand Down
7 changes: 4 additions & 3 deletions net/ipv4/fib_notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ static unsigned int fib4_seq_read(struct net *net)
return net->ipv4.fib_seq + fib4_rules_seq_read(net);
}

static int fib4_dump(struct net *net, struct notifier_block *nb)
static int fib4_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
int err;

err = fib4_rules_dump(net, nb);
err = fib4_rules_dump(net, nb, extack);
if (err)
return err;

return fib_notify(net, nb);
return fib_notify(net, nb, extack);
}

static const struct fib_notifier_ops fib4_notifier_ops_template = {
Expand Down
5 changes: 3 additions & 2 deletions net/ipv4/fib_rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ bool fib4_rule_default(const struct fib_rule *rule)
}
EXPORT_SYMBOL_GPL(fib4_rule_default);

int fib4_rules_dump(struct net *net, struct notifier_block *nb)
int fib4_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return fib_rules_dump(net, nb, AF_INET);
return fib_rules_dump(net, nb, AF_INET, extack);
}

unsigned int fib4_rules_seq_read(struct net *net)
Expand Down
20 changes: 13 additions & 7 deletions net/ipv4/fib_trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@

static int call_fib_entry_notifier(struct notifier_block *nb,
enum fib_event_type event_type, u32 dst,
int dst_len, struct fib_alias *fa)
int dst_len, struct fib_alias *fa,
struct netlink_ext_ack *extack)
{
struct fib_entry_notifier_info info = {
.info.extack = extack,
.dst = dst,
.dst_len = dst_len,
.fi = fa->fa_info,
Expand Down Expand Up @@ -2016,7 +2018,8 @@ void fib_info_notify_update(struct net *net, struct nl_info *info)
}

static int fib_leaf_notify(struct key_vector *l, struct fib_table *tb,
struct notifier_block *nb)
struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
struct fib_alias *fa;
int err;
Expand All @@ -2034,22 +2037,24 @@ static int fib_leaf_notify(struct key_vector *l, struct fib_table *tb,
continue;

err = call_fib_entry_notifier(nb, FIB_EVENT_ENTRY_ADD, l->key,
KEYLENGTH - fa->fa_slen, fa);
KEYLENGTH - fa->fa_slen,
fa, extack);
if (err)
return err;
}
return 0;
}

static int 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 netlink_ext_ack *extack)
{
struct trie *t = (struct trie *)tb->tb_data;
struct key_vector *l, *tp = t->kv;
t_key key = 0;
int err;

while ((l = leaf_walk_rcu(&tp, key)) != NULL) {
err = fib_leaf_notify(l, tb, nb);
err = fib_leaf_notify(l, tb, nb, extack);
if (err)
return err;

Expand All @@ -2061,7 +2066,8 @@ static int fib_table_notify(struct fib_table *tb, struct notifier_block *nb)
return 0;
}

int fib_notify(struct net *net, struct notifier_block *nb)
int fib_notify(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
unsigned int h;
int err;
Expand All @@ -2071,7 +2077,7 @@ int fib_notify(struct net *net, struct notifier_block *nb)
struct fib_table *tb;

hlist_for_each_entry_rcu(tb, head, tb_hlist) {
err = fib_table_notify(tb, nb);
err = fib_table_notify(tb, nb, extack);
if (err)
return err;
}
Expand Down
13 changes: 8 additions & 5 deletions net/ipv4/ipmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,10 @@ static void __net_exit ipmr_rules_exit(struct net *net)
rtnl_unlock();
}

static int ipmr_rules_dump(struct net *net, struct notifier_block *nb)
static int ipmr_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return fib_rules_dump(net, nb, RTNL_FAMILY_IPMR);
return fib_rules_dump(net, nb, RTNL_FAMILY_IPMR, extack);
}

static unsigned int ipmr_rules_seq_read(struct net *net)
Expand Down Expand Up @@ -336,7 +337,8 @@ static void __net_exit ipmr_rules_exit(struct net *net)
rtnl_unlock();
}

static int ipmr_rules_dump(struct net *net, struct notifier_block *nb)
static int ipmr_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return 0;
}
Expand Down Expand Up @@ -3040,10 +3042,11 @@ static unsigned int ipmr_seq_read(struct net *net)
return net->ipv4.ipmr_seq + ipmr_rules_seq_read(net);
}

static int ipmr_dump(struct net *net, struct notifier_block *nb)
static int ipmr_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack)
{
return mr_dump(net, nb, RTNL_FAMILY_IPMR, ipmr_rules_dump,
ipmr_mr_table_iter, &mrt_lock);
ipmr_mr_table_iter, &mrt_lock, extack);
}

static const struct fib_notifier_ops ipmr_notifier_ops_template = {
Expand Down
Loading

0 comments on commit b7a5955

Please sign in to comment.