sysctl_net_ipv6.c 3.5 KB

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