2017-03-10 15:56:18 +08:00
|
|
|
#include <linux/rtnetlink.h>
|
|
|
|
#include <linux/notifier.h>
|
2017-08-03 19:28:11 +08:00
|
|
|
#include <linux/socket.h>
|
2017-03-10 15:56:18 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <net/net_namespace.h>
|
2017-08-03 19:28:11 +08:00
|
|
|
#include <net/fib_notifier.h>
|
2017-03-10 15:56:18 +08:00
|
|
|
#include <net/netns/ipv4.h>
|
|
|
|
#include <net/ip_fib.h>
|
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
int call_fib4_notifier(struct notifier_block *nb, struct net *net,
|
|
|
|
enum fib_event_type event_type,
|
|
|
|
struct fib_notifier_info *info)
|
2017-03-10 15:56:18 +08:00
|
|
|
{
|
2017-08-03 19:28:11 +08:00
|
|
|
info->family = AF_INET;
|
|
|
|
return call_fib_notifier(nb, net, event_type, info);
|
2017-03-10 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
int call_fib4_notifiers(struct net *net, enum fib_event_type event_type,
|
|
|
|
struct fib_notifier_info *info)
|
2017-03-10 15:56:18 +08:00
|
|
|
{
|
2017-08-03 19:28:11 +08:00
|
|
|
ASSERT_RTNL();
|
|
|
|
|
|
|
|
info->family = AF_INET;
|
2017-03-10 15:56:18 +08:00
|
|
|
net->ipv4.fib_seq++;
|
2017-08-03 19:28:11 +08:00
|
|
|
return call_fib_notifiers(net, event_type, info);
|
2017-03-10 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
static unsigned int fib4_seq_read(struct net *net)
|
2017-03-10 15:56:18 +08:00
|
|
|
{
|
2017-08-03 19:28:11 +08:00
|
|
|
ASSERT_RTNL();
|
2017-03-10 15:56:18 +08:00
|
|
|
|
2017-08-03 19:28:14 +08:00
|
|
|
return net->ipv4.fib_seq + fib4_rules_seq_read(net);
|
2017-03-10 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
static int fib4_dump(struct net *net, struct notifier_block *nb)
|
2017-03-10 15:56:18 +08:00
|
|
|
{
|
2017-08-03 19:28:14 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = fib4_rules_dump(net, nb);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
fib_notify(net, nb);
|
|
|
|
|
|
|
|
return 0;
|
2017-03-10 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
static const struct fib_notifier_ops fib4_notifier_ops_template = {
|
|
|
|
.family = AF_INET,
|
|
|
|
.fib_seq_read = fib4_seq_read,
|
|
|
|
.fib_dump = fib4_dump,
|
|
|
|
};
|
2017-03-10 15:56:18 +08:00
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
int __net_init fib4_notifier_init(struct net *net)
|
|
|
|
{
|
|
|
|
struct fib_notifier_ops *ops;
|
2017-03-10 15:56:18 +08:00
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
net->ipv4.fib_seq = 0;
|
2017-03-10 15:56:18 +08:00
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
ops = fib_notifier_ops_register(&fib4_notifier_ops_template, net);
|
|
|
|
if (IS_ERR(ops))
|
|
|
|
return PTR_ERR(ops);
|
|
|
|
net->ipv4.notifier_ops = ops;
|
2017-03-10 15:56:18 +08:00
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
return 0;
|
2017-03-10 15:56:18 +08:00
|
|
|
}
|
|
|
|
|
2017-08-03 19:28:11 +08:00
|
|
|
void __net_exit fib4_notifier_exit(struct net *net)
|
2017-03-10 15:56:18 +08:00
|
|
|
{
|
2017-08-03 19:28:11 +08:00
|
|
|
fib_notifier_ops_unregister(net->ipv4.notifier_ops);
|
2017-03-10 15:56:18 +08:00
|
|
|
}
|