sysctl_net_ipv6.c 3.3 KB

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