sysctl_net_ipv6.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 struct ctl_table empty[1];
  18. static ctl_table ipv6_static_skeleton[] = {
  19. {
  20. .procname = "neigh",
  21. .maxlen = 0,
  22. .mode = 0555,
  23. .child = empty,
  24. },
  25. { }
  26. };
  27. static ctl_table ipv6_table_template[] = {
  28. {
  29. .procname = "route",
  30. .maxlen = 0,
  31. .mode = 0555,
  32. .child = ipv6_route_table_template
  33. },
  34. {
  35. .procname = "icmp",
  36. .maxlen = 0,
  37. .mode = 0555,
  38. .child = ipv6_icmp_table_template
  39. },
  40. {
  41. .procname = "bindv6only",
  42. .data = &init_net.ipv6.sysctl.bindv6only,
  43. .maxlen = sizeof(int),
  44. .mode = 0644,
  45. .proc_handler = proc_dointvec
  46. },
  47. { }
  48. };
  49. static ctl_table ipv6_rotable[] = {
  50. {
  51. .procname = "mld_max_msf",
  52. .data = &sysctl_mld_max_msf,
  53. .maxlen = sizeof(int),
  54. .mode = 0644,
  55. .proc_handler = proc_dointvec
  56. },
  57. { }
  58. };
  59. struct ctl_path net_ipv6_ctl_path[] = {
  60. { .procname = "net", },
  61. { .procname = "ipv6", },
  62. { },
  63. };
  64. EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
  65. static int __net_init ipv6_sysctl_net_init(struct net *net)
  66. {
  67. struct ctl_table *ipv6_table;
  68. struct ctl_table *ipv6_route_table;
  69. struct ctl_table *ipv6_icmp_table;
  70. int err;
  71. err = -ENOMEM;
  72. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  73. GFP_KERNEL);
  74. if (!ipv6_table)
  75. goto out;
  76. ipv6_route_table = ipv6_route_sysctl_init(net);
  77. if (!ipv6_route_table)
  78. goto out_ipv6_table;
  79. ipv6_table[0].child = ipv6_route_table;
  80. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  81. if (!ipv6_icmp_table)
  82. goto out_ipv6_route_table;
  83. ipv6_table[1].child = ipv6_icmp_table;
  84. ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
  85. net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
  86. ipv6_table);
  87. if (!net->ipv6.sysctl.table)
  88. goto out_ipv6_icmp_table;
  89. err = 0;
  90. out:
  91. return err;
  92. out_ipv6_icmp_table:
  93. kfree(ipv6_icmp_table);
  94. out_ipv6_route_table:
  95. kfree(ipv6_route_table);
  96. out_ipv6_table:
  97. kfree(ipv6_table);
  98. goto out;
  99. }
  100. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  101. {
  102. struct ctl_table *ipv6_table;
  103. struct ctl_table *ipv6_route_table;
  104. struct ctl_table *ipv6_icmp_table;
  105. ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
  106. ipv6_route_table = ipv6_table[0].child;
  107. ipv6_icmp_table = ipv6_table[1].child;
  108. unregister_net_sysctl_table(net->ipv6.sysctl.table);
  109. kfree(ipv6_table);
  110. kfree(ipv6_route_table);
  111. kfree(ipv6_icmp_table);
  112. }
  113. static struct pernet_operations ipv6_sysctl_net_ops = {
  114. .init = ipv6_sysctl_net_init,
  115. .exit = ipv6_sysctl_net_exit,
  116. };
  117. static struct ctl_table_header *ip6_header;
  118. int ipv6_sysctl_register(void)
  119. {
  120. int err = -ENOMEM;
  121. ip6_header = register_net_sysctl_rotable(net_ipv6_ctl_path, ipv6_rotable);
  122. if (ip6_header == NULL)
  123. goto out;
  124. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  125. if (err)
  126. goto err_pernet;
  127. out:
  128. return err;
  129. err_pernet:
  130. unregister_net_sysctl_table(ip6_header);
  131. goto out;
  132. }
  133. void ipv6_sysctl_unregister(void)
  134. {
  135. unregister_net_sysctl_table(ip6_header);
  136. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  137. }
  138. static struct ctl_table_header *ip6_base;
  139. int ipv6_static_sysctl_register(void)
  140. {
  141. ip6_base = register_sysctl_paths(net_ipv6_ctl_path, ipv6_static_skeleton);
  142. if (ip6_base == NULL)
  143. return -ENOMEM;
  144. return 0;
  145. }
  146. void ipv6_static_sysctl_unregister(void)
  147. {
  148. unregister_net_sysctl_table(ip6_base);
  149. }