fib6_notifier.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <linux/notifier.h>
  2. #include <linux/socket.h>
  3. #include <linux/kernel.h>
  4. #include <net/net_namespace.h>
  5. #include <net/fib_notifier.h>
  6. #include <net/netns/ipv6.h>
  7. #include <net/ip6_fib.h>
  8. int call_fib6_notifier(struct notifier_block *nb, struct net *net,
  9. enum fib_event_type event_type,
  10. struct fib_notifier_info *info)
  11. {
  12. info->family = AF_INET6;
  13. return call_fib_notifier(nb, net, event_type, info);
  14. }
  15. int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
  16. struct fib_notifier_info *info)
  17. {
  18. info->family = AF_INET6;
  19. return call_fib_notifiers(net, event_type, info);
  20. }
  21. static unsigned int fib6_seq_read(struct net *net)
  22. {
  23. return fib6_tables_seq_read(net) + fib6_rules_seq_read(net);
  24. }
  25. static int fib6_dump(struct net *net, struct notifier_block *nb)
  26. {
  27. int err;
  28. err = fib6_rules_dump(net, nb);
  29. if (err)
  30. return err;
  31. return fib6_tables_dump(net, nb);
  32. }
  33. static const struct fib_notifier_ops fib6_notifier_ops_template = {
  34. .family = AF_INET6,
  35. .fib_seq_read = fib6_seq_read,
  36. .fib_dump = fib6_dump,
  37. };
  38. int __net_init fib6_notifier_init(struct net *net)
  39. {
  40. struct fib_notifier_ops *ops;
  41. ops = fib_notifier_ops_register(&fib6_notifier_ops_template, net);
  42. if (IS_ERR(ops))
  43. return PTR_ERR(ops);
  44. net->ipv6.notifier_ops = ops;
  45. return 0;
  46. }
  47. void __net_exit fib6_notifier_exit(struct net *net)
  48. {
  49. fib_notifier_ops_unregister(net->ipv6.notifier_ops);
  50. }