sysctl_net_ipv6.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 empty[1];
  18. static ctl_table ipv6_static_skeleton[] = {
  19. {
  20. .procname = "neigh",
  21. .maxlen = 0,
  22. .mode = 0555,
  23. .child = empty,
  24. },
  25. { }
  26. };
  27. static ctl_table ipv6_table_template[] = {
  28. {
  29. .procname = "route",
  30. .maxlen = 0,
  31. .mode = 0555,
  32. .child = ipv6_route_table_template
  33. },
  34. {
  35. .procname = "icmp",
  36. .maxlen = 0,
  37. .mode = 0555,
  38. .child = ipv6_icmp_table_template
  39. },
  40. {
  41. .procname = "bindv6only",
  42. .data = &init_net.ipv6.sysctl.bindv6only,
  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 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. };
  66. struct ctl_path net_ipv6_ctl_path[] = {
  67. { .procname = "net", },
  68. { .procname = "ipv6", },
  69. { },
  70. };
  71. EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
  72. static int __net_init ipv6_sysctl_net_init(struct net *net)
  73. {
  74. struct ctl_table *ipv6_table;
  75. struct ctl_table *ipv6_route_table;
  76. struct ctl_table *ipv6_icmp_table;
  77. int err;
  78. err = -ENOMEM;
  79. ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template),
  80. GFP_KERNEL);
  81. if (!ipv6_table)
  82. goto out;
  83. ipv6_route_table = ipv6_route_sysctl_init(net);
  84. if (!ipv6_route_table)
  85. goto out_ipv6_table;
  86. ipv6_table[0].child = ipv6_route_table;
  87. ipv6_icmp_table = ipv6_icmp_sysctl_init(net);
  88. if (!ipv6_icmp_table)
  89. goto out_ipv6_route_table;
  90. ipv6_table[1].child = ipv6_icmp_table;
  91. ipv6_table[2].data = &net->ipv6.sysctl.bindv6only;
  92. net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
  93. ipv6_table);
  94. if (!net->ipv6.sysctl.table)
  95. goto out_ipv6_icmp_table;
  96. err = 0;
  97. out:
  98. return err;
  99. out_ipv6_icmp_table:
  100. kfree(ipv6_icmp_table);
  101. out_ipv6_route_table:
  102. kfree(ipv6_route_table);
  103. out_ipv6_table:
  104. kfree(ipv6_table);
  105. goto out;
  106. }
  107. static void __net_exit ipv6_sysctl_net_exit(struct net *net)
  108. {
  109. struct ctl_table *ipv6_table;
  110. struct ctl_table *ipv6_route_table;
  111. struct ctl_table *ipv6_icmp_table;
  112. ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
  113. ipv6_route_table = ipv6_table[0].child;
  114. ipv6_icmp_table = ipv6_table[1].child;
  115. unregister_net_sysctl_table(net->ipv6.sysctl.table);
  116. kfree(ipv6_table);
  117. kfree(ipv6_route_table);
  118. kfree(ipv6_icmp_table);
  119. }
  120. static struct pernet_operations ipv6_sysctl_net_ops = {
  121. .init = ipv6_sysctl_net_init,
  122. .exit = ipv6_sysctl_net_exit,
  123. };
  124. static struct ctl_table_header *ip6_header;
  125. int ipv6_sysctl_register(void)
  126. {
  127. int err = -ENOMEM;
  128. ip6_header = register_net_sysctl_rotable(net_ipv6_ctl_path, ipv6_rotable);
  129. if (ip6_header == NULL)
  130. goto out;
  131. err = register_pernet_subsys(&ipv6_sysctl_net_ops);
  132. if (err)
  133. goto err_pernet;
  134. out:
  135. return err;
  136. err_pernet:
  137. unregister_net_sysctl_table(ip6_header);
  138. goto out;
  139. }
  140. void ipv6_sysctl_unregister(void)
  141. {
  142. unregister_net_sysctl_table(ip6_header);
  143. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  144. }
  145. static struct ctl_table_header *ip6_base;
  146. int ipv6_static_sysctl_register(void)
  147. {
  148. ip6_base = register_sysctl_paths(net_ipv6_ctl_path, ipv6_static_skeleton);
  149. if (ip6_base == NULL)
  150. return -ENOMEM;
  151. return 0;
  152. }
  153. void ipv6_static_sysctl_unregister(void)
  154. {
  155. unregister_net_sysctl_table(ip6_base);
  156. }