Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 1 | #include <linux/notifier.h> |
| 2 | #include <linux/socket.h> |
| 3 | #include <linux/kernel.h> |
Ido Schimmel | 864150d | 2017-09-01 12:15:17 +0300 | [diff] [blame] | 4 | #include <linux/export.h> |
Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 5 | #include <net/net_namespace.h> |
| 6 | #include <net/fib_notifier.h> |
| 7 | #include <net/netns/ipv6.h> |
| 8 | #include <net/ip6_fib.h> |
| 9 | |
Jiri Pirko | 7c550da | 2019-10-03 11:49:27 +0200 | [diff] [blame] | 10 | int call_fib6_notifier(struct notifier_block *nb, |
Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 11 | enum fib_event_type event_type, |
| 12 | struct fib_notifier_info *info) |
| 13 | { |
| 14 | info->family = AF_INET6; |
Jiri Pirko | 7c550da | 2019-10-03 11:49:27 +0200 | [diff] [blame] | 15 | return call_fib_notifier(nb, event_type, info); |
Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | int 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 | |
| 25 | static unsigned int fib6_seq_read(struct net *net) |
| 26 | { |
Ido Schimmel | e1ee0a5 | 2017-08-03 13:28:19 +0200 | [diff] [blame] | 27 | return fib6_tables_seq_read(net) + fib6_rules_seq_read(net); |
Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Jiri Pirko | b7a5955 | 2019-10-03 11:49:30 +0200 | [diff] [blame] | 30 | static int fib6_dump(struct net *net, struct notifier_block *nb, |
| 31 | struct netlink_ext_ack *extack) |
Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 32 | { |
Ido Schimmel | e1ee0a5 | 2017-08-03 13:28:19 +0200 | [diff] [blame] | 33 | int err; |
| 34 | |
Jiri Pirko | b7a5955 | 2019-10-03 11:49:30 +0200 | [diff] [blame] | 35 | err = fib6_rules_dump(net, nb, extack); |
Ido Schimmel | e1ee0a5 | 2017-08-03 13:28:19 +0200 | [diff] [blame] | 36 | if (err) |
| 37 | return err; |
| 38 | |
Jiri Pirko | b7a5955 | 2019-10-03 11:49:30 +0200 | [diff] [blame] | 39 | return fib6_tables_dump(net, nb, extack); |
Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static const struct fib_notifier_ops fib6_notifier_ops_template = { |
| 43 | .family = AF_INET6, |
| 44 | .fib_seq_read = fib6_seq_read, |
| 45 | .fib_dump = fib6_dump, |
Ido Schimmel | 864150d | 2017-09-01 12:15:17 +0300 | [diff] [blame] | 46 | .owner = THIS_MODULE, |
Ido Schimmel | 16ab6d7 | 2017-08-03 13:28:16 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | int __net_init fib6_notifier_init(struct net *net) |
| 50 | { |
| 51 | struct fib_notifier_ops *ops; |
| 52 | |
| 53 | ops = fib_notifier_ops_register(&fib6_notifier_ops_template, net); |
| 54 | if (IS_ERR(ops)) |
| 55 | return PTR_ERR(ops); |
| 56 | net->ipv6.notifier_ops = ops; |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | void __net_exit fib6_notifier_exit(struct net *net) |
| 62 | { |
| 63 | fib_notifier_ops_unregister(net->ipv6.notifier_ops); |
| 64 | } |