sysctl.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* SCTP kernel reference Implementation
  2. * (C) Copyright IBM Corp. 2002, 2004
  3. * Copyright (c) 2002 Intel Corp.
  4. *
  5. * This file is part of the SCTP kernel reference Implementation
  6. *
  7. * Sysctl related interfaces for SCTP.
  8. *
  9. * The SCTP reference implementation is free software;
  10. * you can redistribute it and/or modify it under the terms of
  11. * the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2, or (at your option)
  13. * any later version.
  14. *
  15. * The SCTP reference implementation is distributed in the hope that it
  16. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  17. * ************************
  18. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. * See the GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with GNU CC; see the file COPYING. If not, write to
  23. * the Free Software Foundation, 59 Temple Place - Suite 330,
  24. * Boston, MA 02111-1307, USA.
  25. *
  26. * Please send any bug reports or fixes you make to the
  27. * email address(es):
  28. * lksctp developers <lksctp-developers@lists.sourceforge.net>
  29. *
  30. * Or submit a bug report through the following website:
  31. * http://www.sf.net/projects/lksctp
  32. *
  33. * Written or modified by:
  34. * Mingqin Liu <liuming@us.ibm.com>
  35. * Jon Grimm <jgrimm@us.ibm.com>
  36. * Ardelle Fan <ardelle.fan@intel.com>
  37. * Ryan Layer <rmlayer@us.ibm.com>
  38. * Sridhar Samudrala <sri@us.ibm.com>
  39. *
  40. * Any bugs reported given to us we will try to fix... any fixes shared will
  41. * be incorporated into the next SCTP release.
  42. */
  43. #include <net/sctp/structs.h>
  44. #include <net/sctp/sctp.h>
  45. #include <linux/sysctl.h>
  46. static ctl_handler sctp_sysctl_jiffies_ms;
  47. static long rto_timer_min = 1;
  48. static long rto_timer_max = 86400000; /* One day */
  49. static long sack_timer_min = 1;
  50. static long sack_timer_max = 500;
  51. static ctl_table sctp_table[] = {
  52. {
  53. .ctl_name = NET_SCTP_RTO_INITIAL,
  54. .procname = "rto_initial",
  55. .data = &sctp_rto_initial,
  56. .maxlen = sizeof(long),
  57. .mode = 0644,
  58. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  59. .strategy = &sctp_sysctl_jiffies_ms,
  60. .extra1 = &rto_timer_min,
  61. .extra2 = &rto_timer_max
  62. },
  63. {
  64. .ctl_name = NET_SCTP_RTO_MIN,
  65. .procname = "rto_min",
  66. .data = &sctp_rto_min,
  67. .maxlen = sizeof(long),
  68. .mode = 0644,
  69. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  70. .strategy = &sctp_sysctl_jiffies_ms,
  71. .extra1 = &rto_timer_min,
  72. .extra2 = &rto_timer_max
  73. },
  74. {
  75. .ctl_name = NET_SCTP_RTO_MAX,
  76. .procname = "rto_max",
  77. .data = &sctp_rto_max,
  78. .maxlen = sizeof(long),
  79. .mode = 0644,
  80. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  81. .strategy = &sctp_sysctl_jiffies_ms,
  82. .extra1 = &rto_timer_min,
  83. .extra2 = &rto_timer_max
  84. },
  85. {
  86. .ctl_name = NET_SCTP_VALID_COOKIE_LIFE,
  87. .procname = "valid_cookie_life",
  88. .data = &sctp_valid_cookie_life,
  89. .maxlen = sizeof(long),
  90. .mode = 0644,
  91. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  92. .strategy = &sctp_sysctl_jiffies_ms,
  93. .extra1 = &rto_timer_min,
  94. .extra2 = &rto_timer_max
  95. },
  96. {
  97. .ctl_name = NET_SCTP_MAX_BURST,
  98. .procname = "max_burst",
  99. .data = &sctp_max_burst,
  100. .maxlen = sizeof(int),
  101. .mode = 0644,
  102. .proc_handler = &proc_dointvec
  103. },
  104. {
  105. .ctl_name = NET_SCTP_ASSOCIATION_MAX_RETRANS,
  106. .procname = "association_max_retrans",
  107. .data = &sctp_max_retrans_association,
  108. .maxlen = sizeof(int),
  109. .mode = 0644,
  110. .proc_handler = &proc_dointvec
  111. },
  112. {
  113. .ctl_name = NET_SCTP_SNDBUF_POLICY,
  114. .procname = "sndbuf_policy",
  115. .data = &sctp_sndbuf_policy,
  116. .maxlen = sizeof(int),
  117. .mode = 0644,
  118. .proc_handler = &proc_dointvec
  119. },
  120. {
  121. .ctl_name = NET_SCTP_RCVBUF_POLICY,
  122. .procname = "rcvbuf_policy",
  123. .data = &sctp_rcvbuf_policy,
  124. .maxlen = sizeof(int),
  125. .mode = 0644,
  126. .proc_handler = &proc_dointvec
  127. },
  128. {
  129. .ctl_name = NET_SCTP_PATH_MAX_RETRANS,
  130. .procname = "path_max_retrans",
  131. .data = &sctp_max_retrans_path,
  132. .maxlen = sizeof(int),
  133. .mode = 0644,
  134. .proc_handler = &proc_dointvec
  135. },
  136. {
  137. .ctl_name = NET_SCTP_MAX_INIT_RETRANSMITS,
  138. .procname = "max_init_retransmits",
  139. .data = &sctp_max_retrans_init,
  140. .maxlen = sizeof(int),
  141. .mode = 0644,
  142. .proc_handler = &proc_dointvec
  143. },
  144. {
  145. .ctl_name = NET_SCTP_HB_INTERVAL,
  146. .procname = "hb_interval",
  147. .data = &sctp_hb_interval,
  148. .maxlen = sizeof(long),
  149. .mode = 0644,
  150. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  151. .strategy = &sctp_sysctl_jiffies_ms,
  152. .extra1 = &rto_timer_min,
  153. .extra2 = &rto_timer_max
  154. },
  155. {
  156. .ctl_name = NET_SCTP_PRESERVE_ENABLE,
  157. .procname = "cookie_preserve_enable",
  158. .data = &sctp_cookie_preserve_enable,
  159. .maxlen = sizeof(int),
  160. .mode = 0644,
  161. .proc_handler = &proc_dointvec
  162. },
  163. {
  164. .ctl_name = NET_SCTP_RTO_ALPHA,
  165. .procname = "rto_alpha_exp_divisor",
  166. .data = &sctp_rto_alpha,
  167. .maxlen = sizeof(int),
  168. .mode = 0644,
  169. .proc_handler = &proc_dointvec
  170. },
  171. {
  172. .ctl_name = NET_SCTP_RTO_BETA,
  173. .procname = "rto_beta_exp_divisor",
  174. .data = &sctp_rto_beta,
  175. .maxlen = sizeof(int),
  176. .mode = 0644,
  177. .proc_handler = &proc_dointvec
  178. },
  179. {
  180. .ctl_name = NET_SCTP_ADDIP_ENABLE,
  181. .procname = "addip_enable",
  182. .data = &sctp_addip_enable,
  183. .maxlen = sizeof(int),
  184. .mode = 0644,
  185. .proc_handler = &proc_dointvec
  186. },
  187. {
  188. .ctl_name = NET_SCTP_PRSCTP_ENABLE,
  189. .procname = "prsctp_enable",
  190. .data = &sctp_prsctp_enable,
  191. .maxlen = sizeof(int),
  192. .mode = 0644,
  193. .proc_handler = &proc_dointvec
  194. },
  195. {
  196. .ctl_name = NET_SCTP_SACK_TIMEOUT,
  197. .procname = "sack_timeout",
  198. .data = &sctp_sack_timeout,
  199. .maxlen = sizeof(long),
  200. .mode = 0644,
  201. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  202. .strategy = &sctp_sysctl_jiffies_ms,
  203. .extra1 = &sack_timer_min,
  204. .extra2 = &sack_timer_max,
  205. },
  206. { .ctl_name = 0 }
  207. };
  208. static ctl_table sctp_net_table[] = {
  209. {
  210. .ctl_name = NET_SCTP,
  211. .procname = "sctp",
  212. .mode = 0555,
  213. .child = sctp_table
  214. },
  215. { .ctl_name = 0 }
  216. };
  217. static ctl_table sctp_root_table[] = {
  218. {
  219. .ctl_name = CTL_NET,
  220. .procname = "net",
  221. .mode = 0555,
  222. .child = sctp_net_table
  223. },
  224. { .ctl_name = 0 }
  225. };
  226. static struct ctl_table_header * sctp_sysctl_header;
  227. /* Sysctl registration. */
  228. void sctp_sysctl_register(void)
  229. {
  230. sctp_sysctl_header = register_sysctl_table(sctp_root_table, 0);
  231. }
  232. /* Sysctl deregistration. */
  233. void sctp_sysctl_unregister(void)
  234. {
  235. unregister_sysctl_table(sctp_sysctl_header);
  236. }
  237. /* Strategy function to convert jiffies to milliseconds. */
  238. static int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen,
  239. void __user *oldval, size_t __user *oldlenp,
  240. void __user *newval, size_t newlen, void **context) {
  241. if (oldval) {
  242. size_t olen;
  243. if (oldlenp) {
  244. if (get_user(olen, oldlenp))
  245. return -EFAULT;
  246. if (olen != sizeof (int))
  247. return -EINVAL;
  248. }
  249. if (put_user((*(int *)(table->data) * 1000) / HZ,
  250. (int __user *)oldval) ||
  251. (oldlenp && put_user(sizeof (int), oldlenp)))
  252. return -EFAULT;
  253. }
  254. if (newval && newlen) {
  255. int new;
  256. if (newlen != sizeof (int))
  257. return -EINVAL;
  258. if (get_user(new, (int __user *)newval))
  259. return -EFAULT;
  260. *(int *)(table->data) = (new * HZ) / 1000;
  261. }
  262. return 1;
  263. }