sysctl_net_core.c 3.5 KB

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