sysctl_net_ipv6.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. .procname = "max_dst_opts_number",
  99. .data = &init_net.ipv6.sysctl.max_dst_opts_cnt,
  100. .maxlen = sizeof(int),
  101. .mode = 0644,
  102. .proc_handler = proc_dointvec
  103. },
  104. {
  105. .procname = "max_hbh_opts_number",
  106. .data = &init_net.ipv6.sysctl.max_hbh_opts_cnt,
  107. .maxlen = sizeof(int),
  108. .mode = 0644,
  109. .proc_handler = proc_dointvec
  110. },
  111. {
  112. .procname = "max_dst_opts_length",
  113. .data = &init_net.ipv6.sysctl.max_dst_opts_len,
  114. .maxlen = sizeof(int),
  115. .mode = 0644,
  116. .proc_handler = proc_dointvec
  117. },
  118. {
  119. .procname = "max_hbh_length",
  120. .data = &init_net.ipv6.sysctl.max_hbh_opts_len,
  121. .maxlen = sizeof(int),
  122. .mode = 0644,
  123. .proc_handler = proc_dointvec
  124. },
  125. { }
  126. };
  127. static struct ctl_table ipv6_rotable[] = {
  128. {
  129. .procname = "mld_max_msf",
  130. .data = &sysctl_mld_max_msf,
  131. .maxlen = sizeof(int),
  132. .mode = 0644,
  133. .proc_handler = proc_dointvec
  134. },
  135. {
  136. .procname = "mld_qrv",
  137. .data = &sysctl_mld_qrv,
  138. .maxlen = sizeof(int),
  139. .mode = 0644,
  140. .proc_handler = proc_dointvec_minmax,
  141. .extra1 = &one
  142. },
  143. #ifdef CONFIG_NETLABEL
  144. {
  145. .procname = "calipso_cache_enable",
  146. .data = &calipso_cache_enabled,
  147. .maxlen = sizeof(int),
  148. .mode = 0644,
  149. .proc_handler = proc_dointvec,
  150. },
  151. {
  152. .procname = "calipso_cache_bucket_size",
  153. .data = &calipso_cache_bucketsize,
  154. .maxlen = sizeof(int),
  155. .mode = 0644,
  156. .proc_handler = proc_dointvec,
  157. },
  158. #endif /* CONFIG_NETLABEL */
  159. { }
  160. };
  161. static int __net_init ipv6_sysctl_net_init(struct net *net)
  162. {
  163. struct ctl_table *ipv6_table;
  164. struct ctl_table *ipv6_route_table;
  165. struct ctl_table *ipv6_icmp_table;
  166. int err;
  167. err = -ENOMEM;
  168. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  169. GFP_KERNEL);
  170. if (!ipv6_table)
  171. goto out;
  172. ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
  173. ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply;
  174. ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency;
  175. ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels;
  176. ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect;
  177. ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries;
  178. ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay;
  179. ipv6_table[7].data = &net->ipv6.sysctl.flowlabel_state_ranges;
  180. ipv6_table[8].data = &net->ipv6.sysctl.ip_nonlocal_bind;
  181. ipv6_table[9].data = &net->ipv6.sysctl.flowlabel_reflect;
  182. ipv6_table[10].data = &net->ipv6.sysctl.max_dst_opts_cnt;
  183. ipv6_table[11].data = &net->ipv6.sysctl.max_hbh_opts_cnt;
  184. ipv6_table[12].data = &net->ipv6.sysctl.max_dst_opts_len;
  185. ipv6_table[13].data = &net->ipv6.sysctl.max_hbh_opts_len;
  186. ipv6_route_table = ipv6_route_sysctl_init(net);
  187. if (!ipv6_route_table)
  188. goto out_ipv6_table;
  189. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  190. if (!ipv6_icmp_table)
  191. goto out_ipv6_route_table;
  192. net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
  193. if (!net->ipv6.sysctl.hdr)
  194. goto out_ipv6_icmp_table;
  195. net->ipv6.sysctl.route_hdr =
  196. register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
  197. if (!net->ipv6.sysctl.route_hdr)
  198. goto out_unregister_ipv6_table;
  199. net->ipv6.sysctl.icmp_hdr =
  200. register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
  201. if (!net->ipv6.sysctl.icmp_hdr)
  202. goto out_unregister_route_table;
  203. err = 0;
  204. out:
  205. return err;
  206. out_unregister_route_table:
  207. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  208. out_unregister_ipv6_table:
  209. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  210. out_ipv6_icmp_table:
  211. kfree(ipv6_icmp_table);
  212. out_ipv6_route_table:
  213. kfree(ipv6_route_table);
  214. out_ipv6_table:
  215. kfree(ipv6_table);
  216. goto out;
  217. }
  218. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  219. {
  220. struct ctl_table *ipv6_table;
  221. struct ctl_table *ipv6_route_table;
  222. struct ctl_table *ipv6_icmp_table;
  223. ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
  224. ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
  225. ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
  226. unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
  227. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  228. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  229. kfree(ipv6_table);
  230. kfree(ipv6_route_table);
  231. kfree(ipv6_icmp_table);
  232. }
  233. static struct pernet_operations ipv6_sysctl_net_ops = {
  234. .init = ipv6_sysctl_net_init,
  235. .exit = ipv6_sysctl_net_exit,
  236. };
  237. static struct ctl_table_header *ip6_header;
  238. int ipv6_sysctl_register(void)
  239. {
  240. int err = -ENOMEM;
  241. ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
  242. if (!ip6_header)
  243. goto out;
  244. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  245. if (err)
  246. goto err_pernet;
  247. out:
  248. return err;
  249. err_pernet:
  250. unregister_net_sysctl_table(ip6_header);
  251. goto out;
  252. }
  253. void ipv6_sysctl_unregister(void)
  254. {
  255. unregister_net_sysctl_table(ip6_header);
  256. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  257. }