]>
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 | ||
04b1d4e5 IS |
12 | int call_fib4_notifier(struct notifier_block *nb, struct net *net, |
13 | enum fib_event_type event_type, | |
14 | struct fib_notifier_info *info) | |
c0243892 | 15 | { |
04b1d4e5 IS |
16 | info->family = AF_INET; |
17 | return call_fib_notifier(nb, net, 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 | ||
04b1d4e5 | 37 | static int fib4_dump(struct net *net, struct notifier_block *nb) |
c0243892 | 38 | { |
1b2a4440 IS |
39 | int err; |
40 | ||
41 | err = fib4_rules_dump(net, nb); | |
42 | if (err) | |
43 | return err; | |
44 | ||
04b1d4e5 IS |
45 | fib_notify(net, nb); |
46 | ||
47 | return 0; | |
c0243892 IS |
48 | } |
49 | ||
04b1d4e5 IS |
50 | static const struct fib_notifier_ops fib4_notifier_ops_template = { |
51 | .family = AF_INET, | |
52 | .fib_seq_read = fib4_seq_read, | |
53 | .fib_dump = fib4_dump, | |
864150df | 54 | .owner = THIS_MODULE, |
04b1d4e5 | 55 | }; |
c0243892 | 56 | |
04b1d4e5 IS |
57 | int __net_init fib4_notifier_init(struct net *net) |
58 | { | |
59 | struct fib_notifier_ops *ops; | |
c0243892 | 60 | |
04b1d4e5 | 61 | net->ipv4.fib_seq = 0; |
c0243892 | 62 | |
04b1d4e5 IS |
63 | ops = fib_notifier_ops_register(&fib4_notifier_ops_template, net); |
64 | if (IS_ERR(ops)) | |
65 | return PTR_ERR(ops); | |
66 | net->ipv4.notifier_ops = ops; | |
c0243892 | 67 | |
04b1d4e5 | 68 | return 0; |
c0243892 | 69 | } |
c0243892 | 70 | |
04b1d4e5 | 71 | void __net_exit fib4_notifier_exit(struct net *net) |
c0243892 | 72 | { |
04b1d4e5 | 73 | fib_notifier_ops_unregister(net->ipv4.notifier_ops); |
c0243892 | 74 | } |