sysctl_net_ipv6.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 <net/ndisc.h>
  12. #include <net/ipv6.h>
  13. #include <net/addrconf.h>
  14. #include <net/inet_frag.h>
  15. static ctl_table ipv6_table_template[] = {
  16. {
  17. .ctl_name = NET_IPV6_ROUTE,
  18. .procname = "route",
  19. .maxlen = 0,
  20. .mode = 0555,
  21. .child = ipv6_route_table_template
  22. },
  23. {
  24. .ctl_name = NET_IPV6_ICMP,
  25. .procname = "icmp",
  26. .maxlen = 0,
  27. .mode = 0555,
  28. .child = ipv6_icmp_table_template
  29. },
  30. {
  31. .ctl_name = NET_IPV6_BINDV6ONLY,
  32. .procname = "bindv6only",
  33. .data = &init_net.ipv6.sysctl.bindv6only,
  34. .maxlen = sizeof(int),
  35. .mode = 0644,
  36. .proc_handler = &proc_dointvec
  37. },
  38. {
  39. .ctl_name = NET_IPV6_IP6FRAG_HIGH_THRESH,
  40. .procname = "ip6frag_high_thresh",
  41. .data = &init_net.ipv6.sysctl.frags.high_thresh,
  42. .maxlen = sizeof(int),
  43. .mode = 0644,
  44. .proc_handler = &proc_dointvec
  45. },
  46. {
  47. .ctl_name = NET_IPV6_IP6FRAG_LOW_THRESH,
  48. .procname = "ip6frag_low_thresh",
  49. .data = &init_net.ipv6.sysctl.frags.low_thresh,
  50. .maxlen = sizeof(int),
  51. .mode = 0644,
  52. .proc_handler = &proc_dointvec
  53. },
  54. {
  55. .ctl_name = NET_IPV6_IP6FRAG_TIME,
  56. .procname = "ip6frag_time",
  57. .data = &init_net.ipv6.sysctl.frags.timeout,
  58. .maxlen = sizeof(int),
  59. .mode = 0644,
  60. .proc_handler = &proc_dointvec_jiffies,
  61. .strategy = &sysctl_jiffies,
  62. },
  63. {
  64. .ctl_name = NET_IPV6_IP6FRAG_SECRET_INTERVAL,
  65. .procname = "ip6frag_secret_interval",
  66. .data = &init_net.ipv6.sysctl.frags.secret_interval,
  67. .maxlen = sizeof(int),
  68. .mode = 0644,
  69. .proc_handler = &proc_dointvec_jiffies,
  70. .strategy = &sysctl_jiffies
  71. },
  72. {
  73. .ctl_name = NET_IPV6_MLD_MAX_MSF,
  74. .procname = "mld_max_msf",
  75. .data = &sysctl_mld_max_msf,
  76. .maxlen = sizeof(int),
  77. .mode = 0644,
  78. .proc_handler = &proc_dointvec
  79. },
  80. { .ctl_name = 0 }
  81. };
  82. struct ctl_path net_ipv6_ctl_path[] = {
  83. { .procname = "net", .ctl_name = CTL_NET, },
  84. { .procname = "ipv6", .ctl_name = NET_IPV6, },
  85. { },
  86. };
  87. EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
  88. static int ipv6_sysctl_net_init(struct net *net)
  89. {
  90. struct ctl_table *ipv6_table;
  91. struct ctl_table *ipv6_route_table;
  92. struct ctl_table *ipv6_icmp_table;
  93. int err;
  94. err = -ENOMEM;
  95. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  96. GFP_KERNEL);
  97. if (!ipv6_table)
  98. goto out;
  99. ipv6_route_table = ipv6_route_sysctl_init(net);
  100. if (!ipv6_route_table)
  101. goto out_ipv6_table;
  102. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  103. if (!ipv6_icmp_table)
  104. goto out_ipv6_route_table;
  105. ipv6_route_table[0].data = &net->ipv6.sysctl.flush_delay;
  106. /* ipv6_route_table[1].data will be handled when we have
  107. routes per namespace */
  108. ipv6_route_table[2].data = &net->ipv6.sysctl.ip6_rt_max_size;
  109. ipv6_route_table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval;
  110. ipv6_route_table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout;
  111. ipv6_route_table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval;
  112. ipv6_route_table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity;
  113. ipv6_route_table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires;
  114. ipv6_route_table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss;
  115. ipv6_table[0].child = ipv6_route_table;
  116. ipv6_icmp_table[0].data = &net->ipv6.sysctl.icmpv6_time;
  117. ipv6_table[1].child = ipv6_icmp_table;
  118. ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
  119. ipv6_table[3].data = &net->ipv6.sysctl.frags.high_thresh;
  120. ipv6_table[4].data = &net->ipv6.sysctl.frags.low_thresh;
  121. ipv6_table[5].data = &net->ipv6.sysctl.frags.timeout;
  122. ipv6_table[6].data = &net->ipv6.sysctl.frags.secret_interval;
  123. /* We don't want this value to be per namespace, it should be global
  124. to all namespaces, so make it read-only when we are not in the
  125. init network namespace */
  126. if (net != &init_net)
  127. ipv6_table[7].mode = 0444;
  128. net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
  129. ipv6_table);
  130. if (!net->ipv6.sysctl.table)
  131. return -ENOMEM;
  132. if (!net->ipv6.sysctl.table)
  133. goto out_ipv6_icmp_table;
  134. err = 0;
  135. out:
  136. return err;
  137. out_ipv6_icmp_table:
  138. kfree(ipv6_icmp_table);
  139. out_ipv6_route_table:
  140. kfree(ipv6_route_table);
  141. out_ipv6_table:
  142. kfree(ipv6_table);
  143. goto out;
  144. }
  145. static void ipv6_sysctl_net_exit(struct net *net)
  146. {
  147. struct ctl_table *ipv6_table;
  148. struct ctl_table *ipv6_route_table;
  149. struct ctl_table *ipv6_icmp_table;
  150. ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
  151. ipv6_route_table = ipv6_table[0].child;
  152. ipv6_icmp_table = ipv6_table[1].child;
  153. unregister_net_sysctl_table(net->ipv6.sysctl.table);
  154. kfree(ipv6_table);
  155. kfree(ipv6_route_table);
  156. kfree(ipv6_icmp_table);
  157. }
  158. static struct pernet_operations ipv6_sysctl_net_ops = {
  159. .init = ipv6_sysctl_net_init,
  160. .exit = ipv6_sysctl_net_exit,
  161. };
  162. int ipv6_sysctl_register(void)
  163. {
  164. return register_pernet_subsys(&ipv6_sysctl_net_ops);
  165. }
  166. void ipv6_sysctl_unregister(void)
  167. {
  168. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  169. }