Commit 8590ceed authored by Roopa Prabhu's avatar Roopa Prabhu Committed by David S. Miller

nexthop: add support for notifiers

This patch adds nexthop add/del notifiers. To be used by
vxlan driver in a later patch. Could possibly be used by
switchdev drivers in the future.
Signed-off-by: default avatarRoopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1274e1cc
...@@ -14,5 +14,6 @@ struct netns_nexthop { ...@@ -14,5 +14,6 @@ struct netns_nexthop {
unsigned int seq; /* protected by rtnl_mutex */ unsigned int seq; /* protected by rtnl_mutex */
u32 last_id_allocated; u32 last_id_allocated;
struct atomic_notifier_head notifier_chain;
}; };
#endif #endif
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define __LINUX_NEXTHOP_H #define __LINUX_NEXTHOP_H
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/notifier.h>
#include <linux/route.h> #include <linux/route.h>
#include <linux/types.h> #include <linux/types.h>
#include <net/ip_fib.h> #include <net/ip_fib.h>
...@@ -102,6 +103,17 @@ struct nexthop { ...@@ -102,6 +103,17 @@ struct nexthop {
}; };
}; };
enum nexthop_event_type {
NEXTHOP_EVENT_ADD,
NEXTHOP_EVENT_DEL
};
int call_nexthop_notifier(struct notifier_block *nb, struct net *net,
enum nexthop_event_type event_type,
struct nexthop *nh);
int register_nexthop_notifier(struct net *net, struct notifier_block *nb);
int unregister_nexthop_notifier(struct net *net, struct notifier_block *nb);
/* caller is holding rcu or rtnl; no reference taken to nexthop */ /* caller is holding rcu or rtnl; no reference taken to nexthop */
struct nexthop *nexthop_find_by_id(struct net *net, u32 id); struct nexthop *nexthop_find_by_id(struct net *net, u32 id);
void nexthop_free_rcu(struct rcu_head *head); void nexthop_free_rcu(struct rcu_head *head);
......
...@@ -36,6 +36,17 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = { ...@@ -36,6 +36,17 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = {
[NHA_FDB] = { .type = NLA_FLAG }, [NHA_FDB] = { .type = NLA_FLAG },
}; };
static int call_nexthop_notifiers(struct net *net,
enum fib_event_type event_type,
struct nexthop *nh)
{
int err;
err = atomic_notifier_call_chain(&net->nexthop.notifier_chain,
event_type, nh);
return notifier_to_errno(err);
}
static unsigned int nh_dev_hashfn(unsigned int val) static unsigned int nh_dev_hashfn(unsigned int val)
{ {
unsigned int mask = NH_DEV_HASHSIZE - 1; unsigned int mask = NH_DEV_HASHSIZE - 1;
...@@ -826,6 +837,8 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh) ...@@ -826,6 +837,8 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)
bool do_flush = false; bool do_flush = false;
struct fib_info *fi; struct fib_info *fi;
call_nexthop_notifiers(net, NEXTHOP_EVENT_DEL, nh);
list_for_each_entry(fi, &nh->fi_list, nh_list) { list_for_each_entry(fi, &nh->fi_list, nh_list) {
fi->fib_flags |= RTNH_F_DEAD; fi->fib_flags |= RTNH_F_DEAD;
do_flush = true; do_flush = true;
...@@ -1865,6 +1878,19 @@ static struct notifier_block nh_netdev_notifier = { ...@@ -1865,6 +1878,19 @@ static struct notifier_block nh_netdev_notifier = {
.notifier_call = nh_netdev_event, .notifier_call = nh_netdev_event,
}; };
int register_nexthop_notifier(struct net *net, struct notifier_block *nb)
{
return atomic_notifier_chain_register(&net->nexthop.notifier_chain, nb);
}
EXPORT_SYMBOL(register_nexthop_notifier);
int unregister_nexthop_notifier(struct net *net, struct notifier_block *nb)
{
return atomic_notifier_chain_unregister(&net->nexthop.notifier_chain,
nb);
}
EXPORT_SYMBOL(unregister_nexthop_notifier);
static void __net_exit nexthop_net_exit(struct net *net) static void __net_exit nexthop_net_exit(struct net *net)
{ {
rtnl_lock(); rtnl_lock();
...@@ -1881,6 +1907,7 @@ static int __net_init nexthop_net_init(struct net *net) ...@@ -1881,6 +1907,7 @@ static int __net_init nexthop_net_init(struct net *net)
net->nexthop.devhash = kzalloc(sz, GFP_KERNEL); net->nexthop.devhash = kzalloc(sz, GFP_KERNEL);
if (!net->nexthop.devhash) if (!net->nexthop.devhash)
return -ENOMEM; return -ENOMEM;
ATOMIC_INIT_NOTIFIER_HEAD(&net->nexthop.notifier_chain);
return 0; return 0;
} }
......
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