sysctl_net_core.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* -*- linux-c -*-
  2. * sysctl_net_core.c: sysctl interface to net core subsystem.
  3. *
  4. * Begun April 1, 1996, Mike Shaver.
  5. * Added /proc/sys/net/core directory entry (empty =) ). [MS]
  6. */
  7. #include <linux/mm.h>
  8. #include <linux/sysctl.h>
  9. #include <linux/module.h>
  10. #include <linux/socket.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/ratelimit.h>
  13. #include <linux/init.h>
  14. #include <net/ip.h>
  15. #include <net/sock.h>
  16. static struct ctl_table net_core_table[] = {
  17. #ifdef CONFIG_NET
  18. {
  19. .procname = "wmem_max",
  20. .data = &sysctl_wmem_max,
  21. .maxlen = sizeof(int),
  22. .mode = 0644,
  23. .proc_handler = proc_dointvec
  24. },
  25. {
  26. .procname = "rmem_max",
  27. .data = &sysctl_rmem_max,
  28. .maxlen = sizeof(int),
  29. .mode = 0644,
  30. .proc_handler = proc_dointvec
  31. },
  32. {
  33. .procname = "wmem_default",
  34. .data = &sysctl_wmem_default,
  35. .maxlen = sizeof(int),
  36. .mode = 0644,
  37. .proc_handler = proc_dointvec
  38. },
  39. {
  40. .procname = "rmem_default",
  41. .data = &sysctl_rmem_default,
  42. .maxlen = sizeof(int),
  43. .mode = 0644,
  44. .proc_handler = proc_dointvec
  45. },
  46. {
  47. .procname = "dev_weight",
  48. .data = &weight_p,
  49. .maxlen = sizeof(int),
  50. .mode = 0644,
  51. .proc_handler = proc_dointvec
  52. },
  53. {
  54. .procname = "netdev_max_backlog",
  55. .data = &netdev_max_backlog,
  56. .maxlen = sizeof(int),
  57. .mode = 0644,
  58. .proc_handler = proc_dointvec
  59. },
  60. {
  61. .procname = "message_cost",
  62. .data = &net_ratelimit_state.interval,
  63. .maxlen = sizeof(int),
  64. .mode = 0644,
  65. .proc_handler = proc_dointvec_jiffies,
  66. },
  67. {
  68. .procname = "message_burst",
  69. .data = &net_ratelimit_state.burst,
  70. .maxlen = sizeof(int),
  71. .mode = 0644,
  72. .proc_handler = proc_dointvec,
  73. },
  74. {
  75. .procname = "optmem_max",
  76. .data = &sysctl_optmem_max,
  77. .maxlen = sizeof(int),
  78. .mode = 0644,
  79. .proc_handler = proc_dointvec
  80. },
  81. #endif /* CONFIG_NET */
  82. {
  83. .procname = "netdev_budget",
  84. .data = &netdev_budget,
  85. .maxlen = sizeof(int),
  86. .mode = 0644,
  87. .proc_handler = proc_dointvec
  88. },
  89. {
  90. .procname = "warnings",
  91. .data = &net_msg_warn,
  92. .maxlen = sizeof(int),
  93. .mode = 0644,
  94. .proc_handler = proc_dointvec
  95. },
  96. { }
  97. };
  98. static struct ctl_table netns_core_table[] = {
  99. {
  100. .procname = "somaxconn",
  101. .data = &init_net.core.sysctl_somaxconn,
  102. .maxlen = sizeof(int),
  103. .mode = 0644,
  104. .proc_handler = proc_dointvec
  105. },
  106. { }
  107. };
  108. __net_initdata struct ctl_path net_core_path[] = {
  109. { .procname = "net", },
  110. { .procname = "core", },
  111. { },
  112. };
  113. static __net_init int sysctl_core_net_init(struct net *net)
  114. {
  115. struct ctl_table *tbl;
  116. net->core.sysctl_somaxconn = SOMAXCONN;
  117. tbl = netns_core_table;
  118. if (!net_eq(net, &init_net)) {
  119. tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
  120. if (tbl == NULL)
  121. goto err_dup;
  122. tbl[0].data = &net->core.sysctl_somaxconn;
  123. }
  124. net->core.sysctl_hdr = register_net_sysctl_table(net,
  125. net_core_path, tbl);
  126. if (net->core.sysctl_hdr == NULL)
  127. goto err_reg;
  128. return 0;
  129. err_reg:
  130. if (tbl != netns_core_table)
  131. kfree(tbl);
  132. err_dup:
  133. return -ENOMEM;
  134. }
  135. static __net_exit void sysctl_core_net_exit(struct net *net)
  136. {
  137. struct ctl_table *tbl;
  138. tbl = net->core.sysctl_hdr->ctl_table_arg;
  139. unregister_net_sysctl_table(net->core.sysctl_hdr);
  140. BUG_ON(tbl == netns_core_table);
  141. kfree(tbl);
  142. }
  143. static __net_initdata struct pernet_operations sysctl_core_ops = {
  144. .init = sysctl_core_net_init,
  145. .exit = sysctl_core_net_exit,
  146. };
  147. static __init int sysctl_core_init(void)
  148. {
  149. static struct ctl_table empty[1];
  150. register_sysctl_paths(net_core_path, empty);
  151. register_net_sysctl_rotable(net_core_path, net_core_table);
  152. return register_pernet_subsys(&sysctl_core_ops);
  153. }
  154. fs_initcall(sysctl_core_init);