sysctl_net_ipv6.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. };
  56. static struct ctl_table ipv6_rotable[] = {
  57. {
  58. .procname = "mld_max_msf",
  59. .data = &sysctl_mld_max_msf,
  60. .maxlen = sizeof(int),
  61. .mode = 0644,
  62. .proc_handler = proc_dointvec
  63. },
  64. {
  65. .procname = "mld_qrv",
  66. .data = &sysctl_mld_qrv,
  67. .maxlen = sizeof(int),
  68. .mode = 0644,
  69. .proc_handler = proc_dointvec_minmax,
  70. .extra1 = &one
  71. },
  72. { }
  73. };
  74. static int __net_init ipv6_sysctl_net_init(struct net *net)
  75. {
  76. struct ctl_table *ipv6_table;
  77. struct ctl_table *ipv6_route_table;
  78. struct ctl_table *ipv6_icmp_table;
  79. int err;
  80. err = -ENOMEM;
  81. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  82. GFP_KERNEL);
  83. if (!ipv6_table)
  84. goto out;
  85. ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
  86. ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply;
  87. ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency;
  88. ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels;
  89. ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect;
  90. ipv6_route_table = ipv6_route_sysctl_init(net);
  91. if (!ipv6_route_table)
  92. goto out_ipv6_table;
  93. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  94. if (!ipv6_icmp_table)
  95. goto out_ipv6_route_table;
  96. net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table);
  97. if (!net->ipv6.sysctl.hdr)
  98. goto out_ipv6_icmp_table;
  99. net->ipv6.sysctl.route_hdr =
  100. register_net_sysctl(net, "net/ipv6/route", ipv6_route_table);
  101. if (!net->ipv6.sysctl.route_hdr)
  102. goto out_unregister_ipv6_table;
  103. net->ipv6.sysctl.icmp_hdr =
  104. register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table);
  105. if (!net->ipv6.sysctl.icmp_hdr)
  106. goto out_unregister_route_table;
  107. err = 0;
  108. out:
  109. return err;
  110. out_unregister_route_table:
  111. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  112. out_unregister_ipv6_table:
  113. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  114. out_ipv6_icmp_table:
  115. kfree(ipv6_icmp_table);
  116. out_ipv6_route_table:
  117. kfree(ipv6_route_table);
  118. out_ipv6_table:
  119. kfree(ipv6_table);
  120. goto out;
  121. }
  122. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  123. {
  124. struct ctl_table *ipv6_table;
  125. struct ctl_table *ipv6_route_table;
  126. struct ctl_table *ipv6_icmp_table;
  127. ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg;
  128. ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg;
  129. ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg;
  130. unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr);
  131. unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr);
  132. unregister_net_sysctl_table(net->ipv6.sysctl.hdr);
  133. kfree(ipv6_table);
  134. kfree(ipv6_route_table);
  135. kfree(ipv6_icmp_table);
  136. }
  137. static struct pernet_operations ipv6_sysctl_net_ops = {
  138. .init = ipv6_sysctl_net_init,
  139. .exit = ipv6_sysctl_net_exit,
  140. };
  141. static struct ctl_table_header *ip6_header;
  142. int ipv6_sysctl_register(void)
  143. {
  144. int err = -ENOMEM;
  145. ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable);
  146. if (ip6_header == NULL)
  147. goto out;
  148. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  149. if (err)
  150. goto err_pernet;
  151. out:
  152. return err;
  153. err_pernet:
  154. unregister_net_sysctl_table(ip6_header);
  155. goto out;
  156. }
  157. void ipv6_sysctl_unregister(void)
  158. {
  159. unregister_net_sysctl_table(ip6_header);
  160. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  161. }