blob: 05f82baaa99ef13dcd419b91fd4460eba54a6ab6 [file] [log] [blame]
Ido Schimmel16ab6d72017-08-03 13:28:16 +02001#include <linux/notifier.h>
2#include <linux/socket.h>
3#include <linux/kernel.h>
Ido Schimmel864150d2017-09-01 12:15:17 +03004#include <linux/export.h>
Ido Schimmel16ab6d72017-08-03 13:28:16 +02005#include <net/net_namespace.h>
6#include <net/fib_notifier.h>
7#include <net/netns/ipv6.h>
8#include <net/ip6_fib.h>
9
10int call_fib6_notifier(struct notifier_block *nb, struct net *net,
11 enum fib_event_type event_type,
12 struct fib_notifier_info *info)
13{
14 info->family = AF_INET6;
15 return call_fib_notifier(nb, net, event_type, info);
16}
17
18int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
19 struct fib_notifier_info *info)
20{
21 info->family = AF_INET6;
22 return call_fib_notifiers(net, event_type, info);
23}
24
25static unsigned int fib6_seq_read(struct net *net)
26{
Ido Schimmele1ee0a52017-08-03 13:28:19 +020027 return fib6_tables_seq_read(net) + fib6_rules_seq_read(net);
Ido Schimmel16ab6d72017-08-03 13:28:16 +020028}
29
30static int fib6_dump(struct net *net, struct notifier_block *nb)
31{
Ido Schimmele1ee0a52017-08-03 13:28:19 +020032 int err;
33
34 err = fib6_rules_dump(net, nb);
35 if (err)
36 return err;
37
38 return fib6_tables_dump(net, nb);
Ido Schimmel16ab6d72017-08-03 13:28:16 +020039}
40
41static const struct fib_notifier_ops fib6_notifier_ops_template = {
42 .family = AF_INET6,
43 .fib_seq_read = fib6_seq_read,
44 .fib_dump = fib6_dump,
Ido Schimmel864150d2017-09-01 12:15:17 +030045 .owner = THIS_MODULE,
Ido Schimmel16ab6d72017-08-03 13:28:16 +020046};
47
48int __net_init fib6_notifier_init(struct net *net)
49{
50 struct fib_notifier_ops *ops;
51
52 ops = fib_notifier_ops_register(&fib6_notifier_ops_template, net);
53 if (IS_ERR(ops))
54 return PTR_ERR(ops);
55 net->ipv6.notifier_ops = ops;
56
57 return 0;
58}
59
60void __net_exit fib6_notifier_exit(struct net *net)
61{
62 fib_notifier_ops_unregister(net->ipv6.notifier_ops);
63}