sysctl_net_ipv6.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. {
  39. .ctl_name = NET_IPV6_MLD_MAX_MSF,
  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. { .ctl_name = 0 }
  47. };
  48. struct ctl_path net_ipv6_ctl_path[] = {
  49. { .procname = "net", .ctl_name = CTL_NET, },
  50. { .procname = "ipv6", .ctl_name = NET_IPV6, },
  51. { },
  52. };
  53. EXPORT_SYMBOL_GPL(net_ipv6_ctl_path);
  54. static int 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. /* We don't want this value to be per namespace, it should be global
  75. to all namespaces, so make it read-only when we are not in the
  76. init network namespace */
  77. if (net != &init_net)
  78. ipv6_table[3].mode = 0444;
  79. net->ipv6.sysctl.table = register_net_sysctl_table(net, net_ipv6_ctl_path,
  80. ipv6_table);
  81. if (!net->ipv6.sysctl.table)
  82. goto out_ipv6_icmp_table;
  83. err = 0;
  84. out:
  85. return err;
  86. out_ipv6_icmp_table:
  87. kfree(ipv6_icmp_table);
  88. out_ipv6_route_table:
  89. kfree(ipv6_route_table);
  90. out_ipv6_table:
  91. kfree(ipv6_table);
  92. goto out;
  93. }
  94. static void ipv6_sysctl_net_exit(struct net *net)
  95. {
  96. struct ctl_table *ipv6_table;
  97. struct ctl_table *ipv6_route_table;
  98. struct ctl_table *ipv6_icmp_table;
  99. ipv6_table = net->ipv6.sysctl.table->ctl_table_arg;
  100. ipv6_route_table = ipv6_table[0].child;
  101. ipv6_icmp_table = ipv6_table[1].child;
  102. unregister_net_sysctl_table(net->ipv6.sysctl.table);
  103. kfree(ipv6_table);
  104. kfree(ipv6_route_table);
  105. kfree(ipv6_icmp_table);
  106. }
  107. static struct pernet_operations ipv6_sysctl_net_ops = {
  108. .init = ipv6_sysctl_net_init,
  109. .exit = ipv6_sysctl_net_exit,
  110. };
  111. int ipv6_sysctl_register(void)
  112. {
  113. return register_pernet_subsys(&ipv6_sysctl_net_ops);
  114. }
  115. void ipv6_sysctl_unregister(void)
  116. {
  117. unregister_pernet_subsys(&ipv6_sysctl_net_ops);
  118. }