sysctl_net_ipv6.c 3.5 KB

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