sysctl_net_ipv6.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem.
  3. *
  4. * Changes:
  5. * YOSHIFUJI Hideaki @USAGI: added icmp sysctl table.
  6. */
  7. #include <linux/mm.h>
  8. #include <linux/sysctl.h>
  9. #include <linux/in6.h>
  10. #include <linux/ipv6.h>
  11. #include <linux/slab.h>
  12. #include <linux/export.h>
  13. #include <net/ndisc.h>
  14. #include <net/ipv6.h>
  15. #include <net/addrconf.h>
  16. #include <net/inet_frag.h>
  17. static ctl_table ipv6_table_template[] = {
  18. {
  19. .procname = "bindv6only",
  20. .data = &init_net.ipv6.sysctl.bindv6only,
  21. .maxlen = sizeof(int),
  22. .mode = 0644,
  23. .proc_handler = proc_dointvec
  24. },
  25. { }
  26. };
  27. static ctl_table ipv6_rotable[] = {
  28. {
  29. .procname = "mld_max_msf",
  30. .data = &sysctl_mld_max_msf,
  31. .maxlen = sizeof(int),
  32. .mode = 0644,
  33. .proc_handler = proc_dointvec
  34. },
  35. { }
  36. };
  37. static int __net_init ipv6_sysctl_net_init(struct net *net)
  38. {
  39. struct ctl_table *ipv6_table;
  40. struct ctl_table *ipv6_route_table;
  41. struct ctl_table *ipv6_icmp_table;
  42. int err;
  43. err = -ENOMEM;
  44. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  45. GFP_KERNEL);
  46. if (!ipv6_table)
  47. goto out;
  48. ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
  49. /* Don't export sysctls to unprivileged users */
  50. if (net->user_ns != &init_user_ns)
  51. ipv6_table[0].procname = NULL;
  52. ipv6_route_table = ipv6_route_sysctl_init(net);
  53. if (!ipv6_route_table)
  54. goto out_ipv6_table;
  55. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  56. if (!ipv6_icmp_table)
  57. goto out_ipv6_route_table;
  58. net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
  59. if (!net->ipv6.sysctl.hdr)
  60. goto out_ipv6_icmp_table;
  61. net->ipv6.sysctl.route_hdr =
  62. register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
  63. if (!net->ipv6.sysctl.route_hdr)
  64. goto out_unregister_ipv6_table;
  65. net->ipv6.sysctl.icmp_hdr =
  66. register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
  67. if (!net->ipv6.sysctl.icmp_hdr)
  68. goto out_unregister_route_table;
  69. err = 0;
  70. out:
  71. return err;
  72. out_unregister_route_table:
  73. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  74. out_unregister_ipv6_table:
  75. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  76. out_ipv6_icmp_table:
  77. kfree(ipv6_icmp_table);
  78. out_ipv6_route_table:
  79. kfree(ipv6_route_table);
  80. out_ipv6_table:
  81. kfree(ipv6_table);
  82. goto out;
  83. }
  84. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  85. {
  86. struct ctl_table *ipv6_table;
  87. struct ctl_table *ipv6_route_table;
  88. struct ctl_table *ipv6_icmp_table;
  89. ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
  90. ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
  91. ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
  92. unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
  93. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  94. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  95. kfree(ipv6_table);
  96. kfree(ipv6_route_table);
  97. kfree(ipv6_icmp_table);
  98. }
  99. static struct pernet_operations ipv6_sysctl_net_ops = {
  100. .init = ipv6_sysctl_net_init,
  101. .exit = ipv6_sysctl_net_exit,
  102. };
  103. static struct ctl_table_header *ip6_header;
  104. int ipv6_sysctl_register(void)
  105. {
  106. int err = -ENOMEM;
  107. ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
  108. if (ip6_header == NULL)
  109. goto out;
  110. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  111. if (err)
  112. goto err_pernet;
  113. out:
  114. return err;
  115. err_pernet:
  116. unregister_net_sysctl_table(ip6_header);
  117. goto out;
  118. }
  119. void ipv6_sysctl_unregister(void)
  120. {
  121. unregister_net_sysctl_table(ip6_header);
  122. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  123. }