sysctl_net_ipv6.c 3.4 KB

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