cfd420b0572c98cb99dc9217b668f01be3050acd
[GitHub/MotorolaMobilityLLC/kernel-slsi.git] / net / ipv4 / fib_notifier.c
1 #include <linux/rtnetlink.h>
2 #include <linux/notifier.h>
3 #include <linux/socket.h>
4 #include <linux/kernel.h>
5 #include <linux/export.h>
6 #include <net/net_namespace.h>
7 #include <net/fib_notifier.h>
8 #include <net/netns/ipv4.h>
9 #include <net/ip_fib.h>
10
11 int call_fib4_notifier(struct notifier_block *nb, struct net *net,
12 enum fib_event_type event_type,
13 struct fib_notifier_info *info)
14 {
15 info->family = AF_INET;
16 return call_fib_notifier(nb, net, event_type, info);
17 }
18
19 int call_fib4_notifiers(struct net *net, enum fib_event_type event_type,
20 struct fib_notifier_info *info)
21 {
22 ASSERT_RTNL();
23
24 info->family = AF_INET;
25 net->ipv4.fib_seq++;
26 return call_fib_notifiers(net, event_type, info);
27 }
28
29 static unsigned int fib4_seq_read(struct net *net)
30 {
31 ASSERT_RTNL();
32
33 return net->ipv4.fib_seq + fib4_rules_seq_read(net);
34 }
35
36 static int fib4_dump(struct net *net, struct notifier_block *nb)
37 {
38 int err;
39
40 err = fib4_rules_dump(net, nb);
41 if (err)
42 return err;
43
44 fib_notify(net, nb);
45
46 return 0;
47 }
48
49 static const struct fib_notifier_ops fib4_notifier_ops_template = {
50 .family = AF_INET,
51 .fib_seq_read = fib4_seq_read,
52 .fib_dump = fib4_dump,
53 .owner = THIS_MODULE,
54 };
55
56 int __net_init fib4_notifier_init(struct net *net)
57 {
58 struct fib_notifier_ops *ops;
59
60 net->ipv4.fib_seq = 0;
61
62 ops = fib_notifier_ops_register(&fib4_notifier_ops_template, net);
63 if (IS_ERR(ops))
64 return PTR_ERR(ops);
65 net->ipv4.notifier_ops = ops;
66
67 return 0;
68 }
69
70 void __net_exit fib4_notifier_exit(struct net *net)
71 {
72 fib_notifier_ops_unregister(net->ipv4.notifier_ops);
73 }