sysctl.c 11 KB

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