xref: /linux/net/ipv6/fib6_notifier.c (revision c411ed854584a71b0e86ac3019b60e4789d88086)
1 #include <linux/notifier.h>
2 #include <linux/socket.h>
3 #include <linux/kernel.h>
4 #include <net/net_namespace.h>
5 #include <net/fib_notifier.h>
6 #include <net/netns/ipv6.h>
7 #include <net/ip6_fib.h>
8 
9 int call_fib6_notifier(struct notifier_block *nb, struct net *net,
10 		       enum fib_event_type event_type,
11 		       struct fib_notifier_info *info)
12 {
13 	info->family = AF_INET6;
14 	return call_fib_notifier(nb, net, event_type, info);
15 }
16 
17 int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
18 			struct fib_notifier_info *info)
19 {
20 	info->family = AF_INET6;
21 	return call_fib_notifiers(net, event_type, info);
22 }
23 
24 static unsigned int fib6_seq_read(struct net *net)
25 {
26 	return fib6_tables_seq_read(net) + fib6_rules_seq_read(net);
27 }
28 
29 static int fib6_dump(struct net *net, struct notifier_block *nb)
30 {
31 	int err;
32 
33 	err = fib6_rules_dump(net, nb);
34 	if (err)
35 		return err;
36 
37 	return fib6_tables_dump(net, nb);
38 }
39 
40 static const struct fib_notifier_ops fib6_notifier_ops_template = {
41 	.family		= AF_INET6,
42 	.fib_seq_read	= fib6_seq_read,
43 	.fib_dump	= fib6_dump,
44 };
45 
46 int __net_init fib6_notifier_init(struct net *net)
47 {
48 	struct fib_notifier_ops *ops;
49 
50 	ops = fib_notifier_ops_register(&fib6_notifier_ops_template, net);
51 	if (IS_ERR(ops))
52 		return PTR_ERR(ops);
53 	net->ipv6.notifier_ops = ops;
54 
55 	return 0;
56 }
57 
58 void __net_exit fib6_notifier_exit(struct net *net)
59 {
60 	fib_notifier_ops_unregister(net->ipv6.notifier_ops);
61 }
62