sysctl_net_ipv6.c 5.8 KB

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