sysctl_net_ipv6.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 int one = 1;
  18. static struct ctl_table ipv6_table_template[] = {
  19. {
  20. .procname = "bindv6only",
  21. .data = &init_net.ipv6.sysctl.bindv6only,
  22. .maxlen = sizeof(int),
  23. .mode = 0644,
  24. .proc_handler = proc_dointvec
  25. },
  26. {
  27. .procname = "anycast_src_echo_reply",
  28. .data = &init_net.ipv6.sysctl.anycast_src_echo_reply,
  29. .maxlen = sizeof(int),
  30. .mode = 0644,
  31. .proc_handler = proc_dointvec
  32. },
  33. {
  34. .procname = "flowlabel_consistency",
  35. .data = &init_net.ipv6.sysctl.flowlabel_consistency,
  36. .maxlen = sizeof(int),
  37. .mode = 0644,
  38. .proc_handler = proc_dointvec
  39. },
  40. {
  41. .procname = "auto_flowlabels",
  42. .data = &init_net.ipv6.sysctl.auto_flowlabels,
  43. .maxlen = sizeof(int),
  44. .mode = 0644,
  45. .proc_handler = proc_dointvec
  46. },
  47. {
  48. .procname = "fwmark_reflect",
  49. .data = &init_net.ipv6.sysctl.fwmark_reflect,
  50. .maxlen = sizeof(int),
  51. .mode = 0644,
  52. .proc_handler = proc_dointvec
  53. },
  54. {
  55. .procname = "idgen_retries",
  56. .data = &init_net.ipv6.sysctl.idgen_retries,
  57. .maxlen = sizeof(int),
  58. .mode = 0644,
  59. .proc_handler = proc_dointvec,
  60. },
  61. {
  62. .procname = "idgen_delay",
  63. .data = &init_net.ipv6.sysctl.idgen_delay,
  64. .maxlen = sizeof(int),
  65. .mode = 0644,
  66. .proc_handler = proc_dointvec_jiffies,
  67. },
  68. { }
  69. };
  70. static struct ctl_table ipv6_rotable[] = {
  71. {
  72. .procname = "mld_max_msf",
  73. .data = &sysctl_mld_max_msf,
  74. .maxlen = sizeof(int),
  75. .mode = 0644,
  76. .proc_handler = proc_dointvec
  77. },
  78. {
  79. .procname = "mld_qrv",
  80. .data = &sysctl_mld_qrv,
  81. .maxlen = sizeof(int),
  82. .mode = 0644,
  83. .proc_handler = proc_dointvec_minmax,
  84. .extra1 = &one
  85. },
  86. { }
  87. };
  88. static int __net_init ipv6_sysctl_net_init(struct net *net)
  89. {
  90. struct ctl_table *ipv6_table;
  91. struct ctl_table *ipv6_route_table;
  92. struct ctl_table *ipv6_icmp_table;
  93. int err;
  94. err = -ENOMEM;
  95. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  96. GFP_KERNEL);
  97. if (!ipv6_table)
  98. goto out;
  99. ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
  100. ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply;
  101. ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency;
  102. ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels;
  103. ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect;
  104. ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries;
  105. ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay;
  106. ipv6_route_table = ipv6_route_sysctl_init(net);
  107. if (!ipv6_route_table)
  108. goto out_ipv6_table;
  109. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  110. if (!ipv6_icmp_table)
  111. goto out_ipv6_route_table;
  112. net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
  113. if (!net->ipv6.sysctl.hdr)
  114. goto out_ipv6_icmp_table;
  115. net->ipv6.sysctl.route_hdr =
  116. register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
  117. if (!net->ipv6.sysctl.route_hdr)
  118. goto out_unregister_ipv6_table;
  119. net->ipv6.sysctl.icmp_hdr =
  120. register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
  121. if (!net->ipv6.sysctl.icmp_hdr)
  122. goto out_unregister_route_table;
  123. err = 0;
  124. out:
  125. return err;
  126. out_unregister_route_table:
  127. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  128. out_unregister_ipv6_table:
  129. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  130. out_ipv6_icmp_table:
  131. kfree(ipv6_icmp_table);
  132. out_ipv6_route_table:
  133. kfree(ipv6_route_table);
  134. out_ipv6_table:
  135. kfree(ipv6_table);
  136. goto out;
  137. }
  138. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  139. {
  140. struct ctl_table *ipv6_table;
  141. struct ctl_table *ipv6_route_table;
  142. struct ctl_table *ipv6_icmp_table;
  143. ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
  144. ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
  145. ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
  146. unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
  147. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  148. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  149. kfree(ipv6_table);
  150. kfree(ipv6_route_table);
  151. kfree(ipv6_icmp_table);
  152. }
  153. static struct pernet_operations ipv6_sysctl_net_ops = {
  154. .init = ipv6_sysctl_net_init,
  155. .exit = ipv6_sysctl_net_exit,
  156. };
  157. static struct ctl_table_header *ip6_header;
  158. int ipv6_sysctl_register(void)
  159. {
  160. int err = -ENOMEM;
  161. ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
  162. if (!ip6_header)
  163. goto out;
  164. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  165. if (err)
  166. goto err_pernet;
  167. out:
  168. return err;
  169. err_pernet:
  170. unregister_net_sysctl_table(ip6_header);
  171. goto out;
  172. }
  173. void ipv6_sysctl_unregister(void)
  174. {
  175. unregister_net_sysctl_table(ip6_header);
  176. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  177. }