0001
0002 #include <linux/rtnetlink.h>
0003 #include <linux/notifier.h>
0004 #include <linux/socket.h>
0005 #include <linux/kernel.h>
0006 #include <linux/export.h>
0007 #include <net/net_namespace.h>
0008 #include <net/fib_notifier.h>
0009 #include <net/ip_fib.h>
0010
0011 int call_fib4_notifier(struct notifier_block *nb,
0012 enum fib_event_type event_type,
0013 struct fib_notifier_info *info)
0014 {
0015 info->family = AF_INET;
0016 return call_fib_notifier(nb, event_type, info);
0017 }
0018
0019 int call_fib4_notifiers(struct net *net, enum fib_event_type event_type,
0020 struct fib_notifier_info *info)
0021 {
0022 ASSERT_RTNL();
0023
0024 info->family = AF_INET;
0025 net->ipv4.fib_seq++;
0026 return call_fib_notifiers(net, event_type, info);
0027 }
0028
0029 static unsigned int fib4_seq_read(struct net *net)
0030 {
0031 ASSERT_RTNL();
0032
0033 return net->ipv4.fib_seq + fib4_rules_seq_read(net);
0034 }
0035
0036 static int fib4_dump(struct net *net, struct notifier_block *nb,
0037 struct netlink_ext_ack *extack)
0038 {
0039 int err;
0040
0041 err = fib4_rules_dump(net, nb, extack);
0042 if (err)
0043 return err;
0044
0045 return fib_notify(net, nb, extack);
0046 }
0047
0048 static const struct fib_notifier_ops fib4_notifier_ops_template = {
0049 .family = AF_INET,
0050 .fib_seq_read = fib4_seq_read,
0051 .fib_dump = fib4_dump,
0052 .owner = THIS_MODULE,
0053 };
0054
0055 int __net_init fib4_notifier_init(struct net *net)
0056 {
0057 struct fib_notifier_ops *ops;
0058
0059 net->ipv4.fib_seq = 0;
0060
0061 ops = fib_notifier_ops_register(&fib4_notifier_ops_template, net);
0062 if (IS_ERR(ops))
0063 return PTR_ERR(ops);
0064 net->ipv4.notifier_ops = ops;
0065
0066 return 0;
0067 }
0068
0069 void __net_exit fib4_notifier_exit(struct net *net)
0070 {
0071 fib_notifier_ops_unregister(net->ipv4.notifier_ops);
0072 }