Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
c0243892 IS |
2 | #include <linux/rtnetlink.h> |
3 | #include <linux/notifier.h> | |
04b1d4e5 | 4 | #include <linux/socket.h> |
c0243892 | 5 | #include <linux/kernel.h> |
864150df | 6 | #include <linux/export.h> |
c0243892 | 7 | #include <net/net_namespace.h> |
04b1d4e5 | 8 | #include <net/fib_notifier.h> |
c0243892 IS |
9 | #include <net/netns/ipv4.h> |
10 | #include <net/ip_fib.h> | |
11 | ||
7c550daf | 12 | int call_fib4_notifier(struct notifier_block *nb, |
04b1d4e5 IS |
13 | enum fib_event_type event_type, |
14 | struct fib_notifier_info *info) | |
c0243892 | 15 | { |
04b1d4e5 | 16 | info->family = AF_INET; |
7c550daf | 17 | return call_fib_notifier(nb, event_type, info); |
c0243892 IS |
18 | } |
19 | ||
04b1d4e5 IS |
20 | int call_fib4_notifiers(struct net *net, enum fib_event_type event_type, |
21 | struct fib_notifier_info *info) | |
c0243892 | 22 | { |
04b1d4e5 IS |
23 | ASSERT_RTNL(); |
24 | ||
25 | info->family = AF_INET; | |
c0243892 | 26 | net->ipv4.fib_seq++; |
04b1d4e5 | 27 | return call_fib_notifiers(net, event_type, info); |
c0243892 IS |
28 | } |
29 | ||
04b1d4e5 | 30 | static unsigned int fib4_seq_read(struct net *net) |
c0243892 | 31 | { |
04b1d4e5 | 32 | ASSERT_RTNL(); |
c0243892 | 33 | |
1b2a4440 | 34 | return net->ipv4.fib_seq + fib4_rules_seq_read(net); |
c0243892 IS |
35 | } |
36 | ||
b7a59557 JP |
37 | static int fib4_dump(struct net *net, struct notifier_block *nb, |
38 | struct netlink_ext_ack *extack) | |
c0243892 | 39 | { |
1b2a4440 IS |
40 | int err; |
41 | ||
b7a59557 | 42 | err = fib4_rules_dump(net, nb, extack); |
1b2a4440 IS |
43 | if (err) |
44 | return err; | |
45 | ||
b7a59557 | 46 | return fib_notify(net, nb, extack); |
c0243892 IS |
47 | } |
48 | ||
04b1d4e5 IS |
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, | |
864150df | 53 | .owner = THIS_MODULE, |
04b1d4e5 | 54 | }; |
c0243892 | 55 | |
04b1d4e5 IS |
56 | int __net_init fib4_notifier_init(struct net *net) |
57 | { | |
58 | struct fib_notifier_ops *ops; | |
c0243892 | 59 | |
04b1d4e5 | 60 | net->ipv4.fib_seq = 0; |
c0243892 | 61 | |
04b1d4e5 IS |
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; | |
c0243892 | 66 | |
04b1d4e5 | 67 | return 0; |
c0243892 | 68 | } |
c0243892 | 69 | |
04b1d4e5 | 70 | void __net_exit fib4_notifier_exit(struct net *net) |
c0243892 | 71 | { |
04b1d4e5 | 72 | fib_notifier_ops_unregister(net->ipv4.notifier_ops); |
c0243892 | 73 | } |