sysctl_net_ipv6.c 4.4 KB

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