sysctl.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /* SCTP kernel implementation
  2. * (C) Copyright IBM Corp. 2002, 2004
  3. * Copyright (c) 2002 Intel Corp.
  4. *
  5. * This file is part of the SCTP kernel implementation
  6. *
  7. * Sysctl related interfaces for SCTP.
  8. *
  9. * This SCTP 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. * This SCTP 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 int zero = 0;
  47. static int one = 1;
  48. static int timer_max = 86400000; /* ms in one day */
  49. static int int_max = INT_MAX;
  50. static int sack_timer_min = 1;
  51. static int sack_timer_max = 500;
  52. static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */
  53. static int rwnd_scale_max = 16;
  54. static unsigned long max_autoclose_min = 0;
  55. static unsigned long max_autoclose_max =
  56. (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
  57. ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
  58. extern long sysctl_sctp_mem[3];
  59. extern int sysctl_sctp_rmem[3];
  60. extern int sysctl_sctp_wmem[3];
  61. static int proc_sctp_do_hmac_alg(ctl_table *ctl,
  62. int write,
  63. void __user *buffer, size_t *lenp,
  64. loff_t *ppos);
  65. static ctl_table sctp_table[] = {
  66. {
  67. .procname = "sctp_mem",
  68. .data = &sysctl_sctp_mem,
  69. .maxlen = sizeof(sysctl_sctp_mem),
  70. .mode = 0644,
  71. .proc_handler = proc_doulongvec_minmax
  72. },
  73. {
  74. .procname = "sctp_rmem",
  75. .data = &sysctl_sctp_rmem,
  76. .maxlen = sizeof(sysctl_sctp_rmem),
  77. .mode = 0644,
  78. .proc_handler = proc_dointvec,
  79. },
  80. {
  81. .procname = "sctp_wmem",
  82. .data = &sysctl_sctp_wmem,
  83. .maxlen = sizeof(sysctl_sctp_wmem),
  84. .mode = 0644,
  85. .proc_handler = proc_dointvec,
  86. },
  87. { /* sentinel */ }
  88. };
  89. static ctl_table sctp_net_table[] = {
  90. {
  91. .procname = "rto_initial",
  92. .data = &init_net.sctp.rto_initial,
  93. .maxlen = sizeof(unsigned int),
  94. .mode = 0644,
  95. .proc_handler = proc_dointvec_minmax,
  96. .extra1 = &one,
  97. .extra2 = &timer_max
  98. },
  99. {
  100. .procname = "rto_min",
  101. .data = &init_net.sctp.rto_min,
  102. .maxlen = sizeof(unsigned int),
  103. .mode = 0644,
  104. .proc_handler = proc_dointvec_minmax,
  105. .extra1 = &one,
  106. .extra2 = &timer_max
  107. },
  108. {
  109. .procname = "rto_max",
  110. .data = &init_net.sctp.rto_max,
  111. .maxlen = sizeof(unsigned int),
  112. .mode = 0644,
  113. .proc_handler = proc_dointvec_minmax,
  114. .extra1 = &one,
  115. .extra2 = &timer_max
  116. },
  117. {
  118. .procname = "rto_alpha_exp_divisor",
  119. .data = &init_net.sctp.rto_alpha,
  120. .maxlen = sizeof(int),
  121. .mode = 0444,
  122. .proc_handler = proc_dointvec,
  123. },
  124. {
  125. .procname = "rto_beta_exp_divisor",
  126. .data = &init_net.sctp.rto_beta,
  127. .maxlen = sizeof(int),
  128. .mode = 0444,
  129. .proc_handler = proc_dointvec,
  130. },
  131. {
  132. .procname = "max_burst",
  133. .data = &init_net.sctp.max_burst,
  134. .maxlen = sizeof(int),
  135. .mode = 0644,
  136. .proc_handler = proc_dointvec_minmax,
  137. .extra1 = &zero,
  138. .extra2 = &int_max
  139. },
  140. {
  141. .procname = "cookie_preserve_enable",
  142. .data = &init_net.sctp.cookie_preserve_enable,
  143. .maxlen = sizeof(int),
  144. .mode = 0644,
  145. .proc_handler = proc_dointvec,
  146. },
  147. {
  148. .procname = "cookie_hmac_alg",
  149. .maxlen = 8,
  150. .mode = 0644,
  151. .proc_handler = proc_sctp_do_hmac_alg,
  152. },
  153. {
  154. .procname = "valid_cookie_life",
  155. .data = &init_net.sctp.valid_cookie_life,
  156. .maxlen = sizeof(unsigned int),
  157. .mode = 0644,
  158. .proc_handler = proc_dointvec_minmax,
  159. .extra1 = &one,
  160. .extra2 = &timer_max
  161. },
  162. {
  163. .procname = "sack_timeout",
  164. .data = &init_net.sctp.sack_timeout,
  165. .maxlen = sizeof(int),
  166. .mode = 0644,
  167. .proc_handler = proc_dointvec_minmax,
  168. .extra1 = &sack_timer_min,
  169. .extra2 = &sack_timer_max,
  170. },
  171. {
  172. .procname = "hb_interval",
  173. .data = &init_net.sctp.hb_interval,
  174. .maxlen = sizeof(unsigned int),
  175. .mode = 0644,
  176. .proc_handler = proc_dointvec_minmax,
  177. .extra1 = &one,
  178. .extra2 = &timer_max
  179. },
  180. {
  181. .procname = "association_max_retrans",
  182. .data = &init_net.sctp.max_retrans_association,
  183. .maxlen = sizeof(int),
  184. .mode = 0644,
  185. .proc_handler = proc_dointvec_minmax,
  186. .extra1 = &one,
  187. .extra2 = &int_max
  188. },
  189. {
  190. .procname = "path_max_retrans",
  191. .data = &init_net.sctp.max_retrans_path,
  192. .maxlen = sizeof(int),
  193. .mode = 0644,
  194. .proc_handler = proc_dointvec_minmax,
  195. .extra1 = &one,
  196. .extra2 = &int_max
  197. },
  198. {
  199. .procname = "max_init_retransmits",
  200. .data = &init_net.sctp.max_retrans_init,
  201. .maxlen = sizeof(int),
  202. .mode = 0644,
  203. .proc_handler = proc_dointvec_minmax,
  204. .extra1 = &one,
  205. .extra2 = &int_max
  206. },
  207. {
  208. .procname = "pf_retrans",
  209. .data = &init_net.sctp.pf_retrans,
  210. .maxlen = sizeof(int),
  211. .mode = 0644,
  212. .proc_handler = proc_dointvec_minmax,
  213. .extra1 = &zero,
  214. .extra2 = &int_max
  215. },
  216. {
  217. .procname = "sndbuf_policy",
  218. .data = &init_net.sctp.sndbuf_policy,
  219. .maxlen = sizeof(int),
  220. .mode = 0644,
  221. .proc_handler = proc_dointvec,
  222. },
  223. {
  224. .procname = "rcvbuf_policy",
  225. .data = &init_net.sctp.rcvbuf_policy,
  226. .maxlen = sizeof(int),
  227. .mode = 0644,
  228. .proc_handler = proc_dointvec,
  229. },
  230. {
  231. .procname = "default_auto_asconf",
  232. .data = &init_net.sctp.default_auto_asconf,
  233. .maxlen = sizeof(int),
  234. .mode = 0644,
  235. .proc_handler = proc_dointvec,
  236. },
  237. {
  238. .procname = "addip_enable",
  239. .data = &init_net.sctp.addip_enable,
  240. .maxlen = sizeof(int),
  241. .mode = 0644,
  242. .proc_handler = proc_dointvec,
  243. },
  244. {
  245. .procname = "addip_noauth_enable",
  246. .data = &init_net.sctp.addip_noauth,
  247. .maxlen = sizeof(int),
  248. .mode = 0644,
  249. .proc_handler = proc_dointvec,
  250. },
  251. {
  252. .procname = "prsctp_enable",
  253. .data = &init_net.sctp.prsctp_enable,
  254. .maxlen = sizeof(int),
  255. .mode = 0644,
  256. .proc_handler = proc_dointvec,
  257. },
  258. {
  259. .procname = "auth_enable",
  260. .data = &init_net.sctp.auth_enable,
  261. .maxlen = sizeof(int),
  262. .mode = 0644,
  263. .proc_handler = proc_dointvec,
  264. },
  265. {
  266. .procname = "addr_scope_policy",
  267. .data = &init_net.sctp.scope_policy,
  268. .maxlen = sizeof(int),
  269. .mode = 0644,
  270. .proc_handler = proc_dointvec_minmax,
  271. .extra1 = &zero,
  272. .extra2 = &addr_scope_max,
  273. },
  274. {
  275. .procname = "rwnd_update_shift",
  276. .data = &init_net.sctp.rwnd_upd_shift,
  277. .maxlen = sizeof(int),
  278. .mode = 0644,
  279. .proc_handler = &proc_dointvec_minmax,
  280. .extra1 = &one,
  281. .extra2 = &rwnd_scale_max,
  282. },
  283. {
  284. .procname = "max_autoclose",
  285. .data = &init_net.sctp.max_autoclose,
  286. .maxlen = sizeof(unsigned long),
  287. .mode = 0644,
  288. .proc_handler = &proc_doulongvec_minmax,
  289. .extra1 = &max_autoclose_min,
  290. .extra2 = &max_autoclose_max,
  291. },
  292. { /* sentinel */ }
  293. };
  294. static int proc_sctp_do_hmac_alg(ctl_table *ctl,
  295. int write,
  296. void __user *buffer, size_t *lenp,
  297. loff_t *ppos)
  298. {
  299. struct net *net = current->nsproxy->net_ns;
  300. char tmp[8];
  301. ctl_table tbl;
  302. int ret;
  303. int changed = 0;
  304. char *none = "none";
  305. memset(&tbl, 0, sizeof(struct ctl_table));
  306. if (write) {
  307. tbl.data = tmp;
  308. tbl.maxlen = 8;
  309. } else {
  310. tbl.data = net->sctp.sctp_hmac_alg ? : none;
  311. tbl.maxlen = strlen(tbl.data);
  312. }
  313. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  314. if (write) {
  315. #ifdef CONFIG_CRYPTO_MD5
  316. if (!strncmp(tmp, "md5", 3)) {
  317. net->sctp.sctp_hmac_alg = "md5";
  318. changed = 1;
  319. }
  320. #endif
  321. #ifdef CONFIG_CRYPTO_SHA1
  322. if (!strncmp(tmp, "sha1", 4)) {
  323. net->sctp.sctp_hmac_alg = "sha1";
  324. changed = 1;
  325. }
  326. #endif
  327. if (!strncmp(tmp, "none", 4)) {
  328. net->sctp.sctp_hmac_alg = NULL;
  329. changed = 1;
  330. }
  331. if (!changed)
  332. ret = -EINVAL;
  333. }
  334. return ret;
  335. }
  336. int sctp_sysctl_net_register(struct net *net)
  337. {
  338. struct ctl_table *table;
  339. int i;
  340. table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
  341. if (!table)
  342. return -ENOMEM;
  343. for (i = 0; table[i].data; i++)
  344. table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
  345. net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
  346. return 0;
  347. }
  348. void sctp_sysctl_net_unregister(struct net *net)
  349. {
  350. unregister_net_sysctl_table(net->sctp.sysctl_header);
  351. }
  352. static struct ctl_table_header * sctp_sysctl_header;
  353. /* Sysctl registration. */
  354. void sctp_sysctl_register(void)
  355. {
  356. sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
  357. }
  358. /* Sysctl deregistration. */
  359. void sctp_sysctl_unregister(void)
  360. {
  361. unregister_net_sysctl_table(sctp_sysctl_header);
  362. }