sysctl.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 <linux/sysctl.h>
  45. static ctl_handler sctp_sysctl_jiffies_ms;
  46. static long rto_timer_min = 1;
  47. static long rto_timer_max = 86400000; /* One day */
  48. static ctl_table sctp_table[] = {
  49. {
  50. .ctl_name = NET_SCTP_RTO_INITIAL,
  51. .procname = "rto_initial",
  52. .data = &sctp_rto_initial,
  53. .maxlen = sizeof(long),
  54. .mode = 0644,
  55. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  56. .strategy = &sctp_sysctl_jiffies_ms,
  57. .extra1 = &rto_timer_min,
  58. .extra2 = &rto_timer_max
  59. },
  60. {
  61. .ctl_name = NET_SCTP_RTO_MIN,
  62. .procname = "rto_min",
  63. .data = &sctp_rto_min,
  64. .maxlen = sizeof(long),
  65. .mode = 0644,
  66. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  67. .strategy = &sctp_sysctl_jiffies_ms,
  68. .extra1 = &rto_timer_min,
  69. .extra2 = &rto_timer_max
  70. },
  71. {
  72. .ctl_name = NET_SCTP_RTO_MAX,
  73. .procname = "rto_max",
  74. .data = &sctp_rto_max,
  75. .maxlen = sizeof(long),
  76. .mode = 0644,
  77. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  78. .strategy = &sctp_sysctl_jiffies_ms,
  79. .extra1 = &rto_timer_min,
  80. .extra2 = &rto_timer_max
  81. },
  82. {
  83. .ctl_name = NET_SCTP_VALID_COOKIE_LIFE,
  84. .procname = "valid_cookie_life",
  85. .data = &sctp_valid_cookie_life,
  86. .maxlen = sizeof(long),
  87. .mode = 0644,
  88. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  89. .strategy = &sctp_sysctl_jiffies_ms,
  90. .extra1 = &rto_timer_min,
  91. .extra2 = &rto_timer_max
  92. },
  93. {
  94. .ctl_name = NET_SCTP_MAX_BURST,
  95. .procname = "max_burst",
  96. .data = &sctp_max_burst,
  97. .maxlen = sizeof(int),
  98. .mode = 0644,
  99. .proc_handler = &proc_dointvec
  100. },
  101. {
  102. .ctl_name = NET_SCTP_ASSOCIATION_MAX_RETRANS,
  103. .procname = "association_max_retrans",
  104. .data = &sctp_max_retrans_association,
  105. .maxlen = sizeof(int),
  106. .mode = 0644,
  107. .proc_handler = &proc_dointvec
  108. },
  109. {
  110. .ctl_name = NET_SCTP_SNDBUF_POLICY,
  111. .procname = "sndbuf_policy",
  112. .data = &sctp_sndbuf_policy,
  113. .maxlen = sizeof(int),
  114. .mode = 0644,
  115. .proc_handler = &proc_dointvec
  116. },
  117. {
  118. .ctl_name = NET_SCTP_PATH_MAX_RETRANS,
  119. .procname = "path_max_retrans",
  120. .data = &sctp_max_retrans_path,
  121. .maxlen = sizeof(int),
  122. .mode = 0644,
  123. .proc_handler = &proc_dointvec
  124. },
  125. {
  126. .ctl_name = NET_SCTP_MAX_INIT_RETRANSMITS,
  127. .procname = "max_init_retransmits",
  128. .data = &sctp_max_retrans_init,
  129. .maxlen = sizeof(int),
  130. .mode = 0644,
  131. .proc_handler = &proc_dointvec
  132. },
  133. {
  134. .ctl_name = NET_SCTP_HB_INTERVAL,
  135. .procname = "hb_interval",
  136. .data = &sctp_hb_interval,
  137. .maxlen = sizeof(long),
  138. .mode = 0644,
  139. .proc_handler = &proc_doulongvec_ms_jiffies_minmax,
  140. .strategy = &sctp_sysctl_jiffies_ms,
  141. .extra1 = &rto_timer_min,
  142. .extra2 = &rto_timer_max
  143. },
  144. {
  145. .ctl_name = NET_SCTP_PRESERVE_ENABLE,
  146. .procname = "cookie_preserve_enable",
  147. .data = &sctp_cookie_preserve_enable,
  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_RTO_ALPHA,
  157. .procname = "rto_alpha_exp_divisor",
  158. .data = &sctp_rto_alpha,
  159. .maxlen = sizeof(int),
  160. .mode = 0644,
  161. .proc_handler = &proc_dointvec
  162. },
  163. {
  164. .ctl_name = NET_SCTP_RTO_BETA,
  165. .procname = "rto_beta_exp_divisor",
  166. .data = &sctp_rto_beta,
  167. .maxlen = sizeof(int),
  168. .mode = 0644,
  169. .proc_handler = &proc_dointvec
  170. },
  171. {
  172. .ctl_name = NET_SCTP_ADDIP_ENABLE,
  173. .procname = "addip_enable",
  174. .data = &sctp_addip_enable,
  175. .maxlen = sizeof(int),
  176. .mode = 0644,
  177. .proc_handler = &proc_dointvec
  178. },
  179. {
  180. .ctl_name = NET_SCTP_PRSCTP_ENABLE,
  181. .procname = "prsctp_enable",
  182. .data = &sctp_prsctp_enable,
  183. .maxlen = sizeof(int),
  184. .mode = 0644,
  185. .proc_handler = &proc_dointvec
  186. },
  187. { .ctl_name = 0 }
  188. };
  189. static ctl_table sctp_net_table[] = {
  190. {
  191. .ctl_name = NET_SCTP,
  192. .procname = "sctp",
  193. .mode = 0555,
  194. .child = sctp_table
  195. },
  196. { .ctl_name = 0 }
  197. };
  198. static ctl_table sctp_root_table[] = {
  199. {
  200. .ctl_name = CTL_NET,
  201. .procname = "net",
  202. .mode = 0555,
  203. .child = sctp_net_table
  204. },
  205. { .ctl_name = 0 }
  206. };
  207. static struct ctl_table_header * sctp_sysctl_header;
  208. /* Sysctl registration. */
  209. void sctp_sysctl_register(void)
  210. {
  211. sctp_sysctl_header = register_sysctl_table(sctp_root_table, 0);
  212. }
  213. /* Sysctl deregistration. */
  214. void sctp_sysctl_unregister(void)
  215. {
  216. unregister_sysctl_table(sctp_sysctl_header);
  217. }
  218. /* Strategy function to convert jiffies to milliseconds. */
  219. static int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen,
  220. void __user *oldval, size_t __user *oldlenp,
  221. void __user *newval, size_t newlen, void **context) {
  222. if (oldval) {
  223. size_t olen;
  224. if (oldlenp) {
  225. if (get_user(olen, oldlenp))
  226. return -EFAULT;
  227. if (olen != sizeof (int))
  228. return -EINVAL;
  229. }
  230. if (put_user((*(int *)(table->data) * 1000) / HZ,
  231. (int __user *)oldval) ||
  232. (oldlenp && put_user(sizeof (int), oldlenp)))
  233. return -EFAULT;
  234. }
  235. if (newval && newlen) {
  236. int new;
  237. if (newlen != sizeof (int))
  238. return -EINVAL;
  239. if (get_user(new, (int __user *)newval))
  240. return -EFAULT;
  241. *(int *)(table->data) = (new * HZ) / 1000;
  242. }
  243. return 1;
  244. }