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