sysctl_net_ipv6.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. struct ctl_path net_ipv6_ctl_path[] = {
  38. { .procname = "net", },
  39. { .procname = "ipv6", },
  40. { },
  41. };
  42. EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
  43. static int __net_init ipv6_sysctl_net_init(struct net *net)
  44. {
  45. struct ctl_table *ipv6_table;
  46. struct ctl_table *ipv6_route_table;
  47. struct ctl_table *ipv6_icmp_table;
  48. int err;
  49. err = -ENOMEM;
  50. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  51. GFP_KERNEL);
  52. if (!ipv6_table)
  53. goto out;
  54. ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
  55. ipv6_route_table = ipv6_route_sysctl_init(net);
  56. if (!ipv6_route_table)
  57. goto out_ipv6_table;
  58. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  59. if (!ipv6_icmp_table)
  60. goto out_ipv6_route_table;
  61. net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
  62. if (!net->ipv6.sysctl.hdr)
  63. goto out_ipv6_icmp_table;
  64. net->ipv6.sysctl.route_hdr =
  65. register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
  66. if (!net->ipv6.sysctl.route_hdr)
  67. goto out_unregister_ipv6_table;
  68. net->ipv6.sysctl.icmp_hdr =
  69. register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
  70. if (!net->ipv6.sysctl.icmp_hdr)
  71. goto out_unregister_route_table;
  72. err = 0;
  73. out:
  74. return err;
  75. out_unregister_route_table:
  76. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  77. out_unregister_ipv6_table:
  78. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  79. out_ipv6_icmp_table:
  80. kfree(ipv6_icmp_table);
  81. out_ipv6_route_table:
  82. kfree(ipv6_route_table);
  83. out_ipv6_table:
  84. kfree(ipv6_table);
  85. goto out;
  86. }
  87. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  88. {
  89. struct ctl_table *ipv6_table;
  90. struct ctl_table *ipv6_route_table;
  91. struct ctl_table *ipv6_icmp_table;
  92. ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
  93. ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
  94. ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
  95. unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
  96. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  97. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  98. kfree(ipv6_table);
  99. kfree(ipv6_route_table);
  100. kfree(ipv6_icmp_table);
  101. }
  102. static struct pernet_operations ipv6_sysctl_net_ops = {
  103. .init = ipv6_sysctl_net_init,
  104. .exit = ipv6_sysctl_net_exit,
  105. };
  106. static struct ctl_table_header *ip6_header;
  107. int ipv6_sysctl_register(void)
  108. {
  109. int err = -ENOMEM;
  110. ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
  111. if (ip6_header == NULL)
  112. goto out;
  113. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  114. if (err)
  115. goto err_pernet;
  116. out:
  117. return err;
  118. err_pernet:
  119. unregister_net_sysctl_table(ip6_header);
  120. goto out;
  121. }
  122. void ipv6_sysctl_unregister(void)
  123. {
  124. unregister_net_sysctl_table(ip6_header);
  125. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  126. }