0001 #include <linux/notifier.h>
0002 #include <linux/socket.h>
0003 #include <linux/kernel.h>
0004 #include <linux/export.h>
0005 #include <net/net_namespace.h>
0006 #include <net/fib_notifier.h>
0007 #include <net/netns/ipv6.h>
0008 #include <net/ip6_fib.h>
0009
0010 int call_fib6_notifier(struct notifier_block *nb,
0011 enum fib_event_type event_type,
0012 struct fib_notifier_info *info)
0013 {
0014 info->family = AF_INET6;
0015 return call_fib_notifier(nb, event_type, info);
0016 }
0017
0018 int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
0019 struct fib_notifier_info *info)
0020 {
0021 info->family = AF_INET6;
0022 return call_fib_notifiers(net, event_type, info);
0023 }
0024
0025 static unsigned int fib6_seq_read(struct net *net)
0026 {
0027 return fib6_tables_seq_read(net) + fib6_rules_seq_read(net);
0028 }
0029
0030 static int fib6_dump(struct net *net, struct notifier_block *nb,
0031 struct netlink_ext_ack *extack)
0032 {
0033 int err;
0034
0035 err = fib6_rules_dump(net, nb, extack);
0036 if (err)
0037 return err;
0038
0039 return fib6_tables_dump(net, nb, extack);
0040 }
0041
0042 static const struct fib_notifier_ops fib6_notifier_ops_template = {
0043 .family = AF_INET6,
0044 .fib_seq_read = fib6_seq_read,
0045 .fib_dump = fib6_dump,
0046 .owner = THIS_MODULE,
0047 };
0048
0049 int __net_init fib6_notifier_init(struct net *net)
0050 {
0051 struct fib_notifier_ops *ops;
0052
0053 ops = fib_notifier_ops_register(&fib6_notifier_ops_template, net);
0054 if (IS_ERR(ops))
0055 return PTR_ERR(ops);
0056 net->ipv6.notifier_ops = ops;
0057
0058 return 0;
0059 }
0060
0061 void __net_exit fib6_notifier_exit(struct net *net)
0062 {
0063 fib_notifier_ops_unregister(net->ipv6.notifier_ops);
0064 }