sysctl_net_ipv6.c 3.5 KB

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