sysctl.c 9.1 KB

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