fib6_notifier.c 1.5 KB

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