sysctl_net_ipv6.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem.
  4. *
  5. * Changes:
  6. * YOSHIFUJI Hideaki @USAGI: added icmp sysctl table.
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/sysctl.h>
  10. #include <linux/in6.h>
  11. #include <linux/ipv6.h>
  12. #include <linux/slab.h>
  13. #include <linux/export.h>
  14. #include <net/ndisc.h>
  15. #include <net/ipv6.h>
  16. #include <net/addrconf.h>
  17. #include <net/inet_frag.h>
  18. #ifdef CONFIG_NETLABEL
  19. #include <net/calipso.h>
  20. #endif
  21. static int one = 1;
  22. static int auto_flowlabels_min;
  23. static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX;
  24. static struct ctl_table ipv6_table_template[] = {
  25. {
  26. .procname = "bindv6only",
  27. .data = &init_net.ipv6.sysctl.bindv6only,
  28. .maxlen = sizeof(int),
  29. .mode = 0644,
  30. .proc_handler = proc_dointvec
  31. },
  32. {
  33. .procname = "anycast_src_echo_reply",
  34. .data = &init_net.ipv6.sysctl.anycast_src_echo_reply,
  35. .maxlen = sizeof(int),
  36. .mode = 0644,
  37. .proc_handler = proc_dointvec
  38. },
  39. {
  40. .procname = "flowlabel_consistency",
  41. .data = &init_net.ipv6.sysctl.flowlabel_consistency,
  42. .maxlen = sizeof(int),
  43. .mode = 0644,
  44. .proc_handler = proc_dointvec
  45. },
  46. {
  47. .procname = "auto_flowlabels",
  48. .data = &init_net.ipv6.sysctl.auto_flowlabels,
  49. .maxlen = sizeof(int),
  50. .mode = 0644,
  51. .proc_handler = proc_dointvec_minmax,
  52. .extra1 = &auto_flowlabels_min,
  53. .extra2 = &auto_flowlabels_max
  54. },
  55. {
  56. .procname = "fwmark_reflect",
  57. .data = &init_net.ipv6.sysctl.fwmark_reflect,
  58. .maxlen = sizeof(int),
  59. .mode = 0644,
  60. .proc_handler = proc_dointvec
  61. },
  62. {
  63. .procname = "idgen_retries",
  64. .data = &init_net.ipv6.sysctl.idgen_retries,
  65. .maxlen = sizeof(int),
  66. .mode = 0644,
  67. .proc_handler = proc_dointvec,
  68. },
  69. {
  70. .procname = "idgen_delay",
  71. .data = &init_net.ipv6.sysctl.idgen_delay,
  72. .maxlen = sizeof(int),
  73. .mode = 0644,
  74. .proc_handler = proc_dointvec_jiffies,
  75. },
  76. {
  77. .procname = "flowlabel_state_ranges",
  78. .data = &init_net.ipv6.sysctl.flowlabel_state_ranges,
  79. .maxlen = sizeof(int),
  80. .mode = 0644,
  81. .proc_handler = proc_dointvec
  82. },
  83. {
  84. .procname = "ip_nonlocal_bind",
  85. .data = &init_net.ipv6.sysctl.ip_nonlocal_bind,
  86. .maxlen = sizeof(int),
  87. .mode = 0644,
  88. .proc_handler = proc_dointvec
  89. },
  90. {
  91. .procname = "flowlabel_reflect",
  92. .data = &init_net.ipv6.sysctl.flowlabel_reflect,
  93. .maxlen = sizeof(int),
  94. .mode = 0644,
  95. .proc_handler = proc_dointvec,
  96. },
  97. { }
  98. };
  99. static struct ctl_table ipv6_rotable[] = {
  100. {
  101. .procname = "mld_max_msf",
  102. .data = &sysctl_mld_max_msf,
  103. .maxlen = sizeof(int),
  104. .mode = 0644,
  105. .proc_handler = proc_dointvec
  106. },
  107. {
  108. .procname = "mld_qrv",
  109. .data = &sysctl_mld_qrv,
  110. .maxlen = sizeof(int),
  111. .mode = 0644,
  112. .proc_handler = proc_dointvec_minmax,
  113. .extra1 = &one
  114. },
  115. #ifdef CONFIG_NETLABEL
  116. {
  117. .procname = "calipso_cache_enable",
  118. .data = &calipso_cache_enabled,
  119. .maxlen = sizeof(int),
  120. .mode = 0644,
  121. .proc_handler = proc_dointvec,
  122. },
  123. {
  124. .procname = "calipso_cache_bucket_size",
  125. .data = &calipso_cache_bucketsize,
  126. .maxlen = sizeof(int),
  127. .mode = 0644,
  128. .proc_handler = proc_dointvec,
  129. },
  130. #endif /* CONFIG_NETLABEL */
  131. { }
  132. };
  133. static int __net_init ipv6_sysctl_net_init(struct net *net)
  134. {
  135. struct ctl_table *ipv6_table;
  136. struct ctl_table *ipv6_route_table;
  137. struct ctl_table *ipv6_icmp_table;
  138. int err;
  139. err = -ENOMEM;
  140. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  141. GFP_KERNEL);
  142. if (!ipv6_table)
  143. goto out;
  144. ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
  145. ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply;
  146. ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency;
  147. ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels;
  148. ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect;
  149. ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries;
  150. ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay;
  151. ipv6_table[7].data = &net->ipv6.sysctl.flowlabel_state_ranges;
  152. ipv6_table[8].data = &net->ipv6.sysctl.ip_nonlocal_bind;
  153. ipv6_table[9].data = &net->ipv6.sysctl.flowlabel_reflect;
  154. ipv6_route_table = ipv6_route_sysctl_init(net);
  155. if (!ipv6_route_table)
  156. goto out_ipv6_table;
  157. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  158. if (!ipv6_icmp_table)
  159. goto out_ipv6_route_table;
  160. net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
  161. if (!net->ipv6.sysctl.hdr)
  162. goto out_ipv6_icmp_table;
  163. net->ipv6.sysctl.route_hdr =
  164. register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
  165. if (!net->ipv6.sysctl.route_hdr)
  166. goto out_unregister_ipv6_table;
  167. net->ipv6.sysctl.icmp_hdr =
  168. register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
  169. if (!net->ipv6.sysctl.icmp_hdr)
  170. goto out_unregister_route_table;
  171. err = 0;
  172. out:
  173. return err;
  174. out_unregister_route_table:
  175. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  176. out_unregister_ipv6_table:
  177. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  178. out_ipv6_icmp_table:
  179. kfree(ipv6_icmp_table);
  180. out_ipv6_route_table:
  181. kfree(ipv6_route_table);
  182. out_ipv6_table:
  183. kfree(ipv6_table);
  184. goto out;
  185. }
  186. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  187. {
  188. struct ctl_table *ipv6_table;
  189. struct ctl_table *ipv6_route_table;
  190. struct ctl_table *ipv6_icmp_table;
  191. ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
  192. ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
  193. ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
  194. unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
  195. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  196. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  197. kfree(ipv6_table);
  198. kfree(ipv6_route_table);
  199. kfree(ipv6_icmp_table);
  200. }
  201. static struct pernet_operations ipv6_sysctl_net_ops = {
  202. .init = ipv6_sysctl_net_init,
  203. .exit = ipv6_sysctl_net_exit,
  204. };
  205. static struct ctl_table_header *ip6_header;
  206. int ipv6_sysctl_register(void)
  207. {
  208. int err = -ENOMEM;
  209. ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
  210. if (!ip6_header)
  211. goto out;
  212. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  213. if (err)
  214. goto err_pernet;
  215. out:
  216. return err;
  217. err_pernet:
  218. unregister_net_sysctl_table(ip6_header);
  219. goto out;
  220. }
  221. void ipv6_sysctl_unregister(void)
  222. {
  223. unregister_net_sysctl_table(ip6_header);
  224. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  225. }