sysctl_net_ipv6.c 4.2 KB

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