sysctl.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. .data = &init_net.sctp.sctp_hmac_alg,
  148. .maxlen = 8,
  149. .mode = 0644,
  150. .proc_handler = proc_sctp_do_hmac_alg,
  151. },
  152. {
  153. .procname = "valid_cookie_life",
  154. .data = &init_net.sctp.valid_cookie_life,
  155. .maxlen = sizeof(unsigned int),
  156. .mode = 0644,
  157. .proc_handler = proc_dointvec_minmax,
  158. .extra1 = &one,
  159. .extra2 = &timer_max
  160. },
  161. {
  162. .procname = "sack_timeout",
  163. .data = &init_net.sctp.sack_timeout,
  164. .maxlen = sizeof(int),
  165. .mode = 0644,
  166. .proc_handler = proc_dointvec_minmax,
  167. .extra1 = &sack_timer_min,
  168. .extra2 = &sack_timer_max,
  169. },
  170. {
  171. .procname = "hb_interval",
  172. .data = &init_net.sctp.hb_interval,
  173. .maxlen = sizeof(unsigned int),
  174. .mode = 0644,
  175. .proc_handler = proc_dointvec_minmax,
  176. .extra1 = &one,
  177. .extra2 = &timer_max
  178. },
  179. {
  180. .procname = "association_max_retrans",
  181. .data = &init_net.sctp.max_retrans_association,
  182. .maxlen = sizeof(int),
  183. .mode = 0644,
  184. .proc_handler = proc_dointvec_minmax,
  185. .extra1 = &one,
  186. .extra2 = &int_max
  187. },
  188. {
  189. .procname = "path_max_retrans",
  190. .data = &init_net.sctp.max_retrans_path,
  191. .maxlen = sizeof(int),
  192. .mode = 0644,
  193. .proc_handler = proc_dointvec_minmax,
  194. .extra1 = &one,
  195. .extra2 = &int_max
  196. },
  197. {
  198. .procname = "max_init_retransmits",
  199. .data = &init_net.sctp.max_retrans_init,
  200. .maxlen = sizeof(int),
  201. .mode = 0644,
  202. .proc_handler = proc_dointvec_minmax,
  203. .extra1 = &one,
  204. .extra2 = &int_max
  205. },
  206. {
  207. .procname = "pf_retrans",
  208. .data = &init_net.sctp.pf_retrans,
  209. .maxlen = sizeof(int),
  210. .mode = 0644,
  211. .proc_handler = proc_dointvec_minmax,
  212. .extra1 = &zero,
  213. .extra2 = &int_max
  214. },
  215. {
  216. .procname = "sndbuf_policy",
  217. .data = &init_net.sctp.sndbuf_policy,
  218. .maxlen = sizeof(int),
  219. .mode = 0644,
  220. .proc_handler = proc_dointvec,
  221. },
  222. {
  223. .procname = "rcvbuf_policy",
  224. .data = &init_net.sctp.rcvbuf_policy,
  225. .maxlen = sizeof(int),
  226. .mode = 0644,
  227. .proc_handler = proc_dointvec,
  228. },
  229. {
  230. .procname = "default_auto_asconf",
  231. .data = &init_net.sctp.default_auto_asconf,
  232. .maxlen = sizeof(int),
  233. .mode = 0644,
  234. .proc_handler = proc_dointvec,
  235. },
  236. {
  237. .procname = "addip_enable",
  238. .data = &init_net.sctp.addip_enable,
  239. .maxlen = sizeof(int),
  240. .mode = 0644,
  241. .proc_handler = proc_dointvec,
  242. },
  243. {
  244. .procname = "addip_noauth_enable",
  245. .data = &init_net.sctp.addip_noauth,
  246. .maxlen = sizeof(int),
  247. .mode = 0644,
  248. .proc_handler = proc_dointvec,
  249. },
  250. {
  251. .procname = "prsctp_enable",
  252. .data = &init_net.sctp.prsctp_enable,
  253. .maxlen = sizeof(int),
  254. .mode = 0644,
  255. .proc_handler = proc_dointvec,
  256. },
  257. {
  258. .procname = "auth_enable",
  259. .data = &init_net.sctp.auth_enable,
  260. .maxlen = sizeof(int),
  261. .mode = 0644,
  262. .proc_handler = proc_dointvec,
  263. },
  264. {
  265. .procname = "addr_scope_policy",
  266. .data = &init_net.sctp.scope_policy,
  267. .maxlen = sizeof(int),
  268. .mode = 0644,
  269. .proc_handler = proc_dointvec_minmax,
  270. .extra1 = &zero,
  271. .extra2 = &addr_scope_max,
  272. },
  273. {
  274. .procname = "rwnd_update_shift",
  275. .data = &init_net.sctp.rwnd_upd_shift,
  276. .maxlen = sizeof(int),
  277. .mode = 0644,
  278. .proc_handler = &proc_dointvec_minmax,
  279. .extra1 = &one,
  280. .extra2 = &rwnd_scale_max,
  281. },
  282. {
  283. .procname = "max_autoclose",
  284. .data = &init_net.sctp.max_autoclose,
  285. .maxlen = sizeof(unsigned long),
  286. .mode = 0644,
  287. .proc_handler = &proc_doulongvec_minmax,
  288. .extra1 = &max_autoclose_min,
  289. .extra2 = &max_autoclose_max,
  290. },
  291. { /* sentinel */ }
  292. };
  293. static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
  294. void __user *buffer, size_t *lenp,
  295. loff_t *ppos)
  296. {
  297. struct net *net = current->nsproxy->net_ns;
  298. char tmp[8];
  299. struct ctl_table tbl;
  300. int ret;
  301. int changed = 0;
  302. char *none = "none";
  303. memset(&tbl, 0, sizeof(struct ctl_table));
  304. if (write) {
  305. tbl.data = tmp;
  306. tbl.maxlen = 8;
  307. } else {
  308. tbl.data = net->sctp.sctp_hmac_alg ? : none;
  309. tbl.maxlen = strlen(tbl.data);
  310. }
  311. ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
  312. if (write) {
  313. #ifdef CONFIG_CRYPTO_MD5
  314. if (!strncmp(tmp, "md5", 3)) {
  315. net->sctp.sctp_hmac_alg = "md5";
  316. changed = 1;
  317. }
  318. #endif
  319. #ifdef CONFIG_CRYPTO_SHA1
  320. if (!strncmp(tmp, "sha1", 4)) {
  321. net->sctp.sctp_hmac_alg = "sha1";
  322. changed = 1;
  323. }
  324. #endif
  325. if (!strncmp(tmp, "none", 4)) {
  326. net->sctp.sctp_hmac_alg = NULL;
  327. changed = 1;
  328. }
  329. if (!changed)
  330. ret = -EINVAL;
  331. }
  332. return ret;
  333. }
  334. static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
  335. void __user *buffer, size_t *lenp,
  336. loff_t *ppos)
  337. {
  338. struct net *net = current->nsproxy->net_ns;
  339. int new_value;
  340. struct ctl_table tbl;
  341. unsigned int min = *(unsigned int *) ctl->extra1;
  342. unsigned int max = *(unsigned int *) ctl->extra2;
  343. int ret;
  344. memset(&tbl, 0, sizeof(struct ctl_table));
  345. tbl.maxlen = sizeof(unsigned int);
  346. if (write)
  347. tbl.data = &new_value;
  348. else
  349. tbl.data = &net->sctp.rto_min;
  350. ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
  351. if (write) {
  352. if (ret || new_value > max || new_value < min)
  353. return -EINVAL;
  354. net->sctp.rto_min = new_value;
  355. }
  356. return ret;
  357. }
  358. static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
  359. void __user *buffer, size_t *lenp,
  360. loff_t *ppos)
  361. {
  362. struct net *net = current->nsproxy->net_ns;
  363. int new_value;
  364. struct ctl_table tbl;
  365. unsigned int min = *(unsigned int *) ctl->extra1;
  366. unsigned int max = *(unsigned int *) ctl->extra2;
  367. int ret;
  368. memset(&tbl, 0, sizeof(struct ctl_table));
  369. tbl.maxlen = sizeof(unsigned int);
  370. if (write)
  371. tbl.data = &new_value;
  372. else
  373. tbl.data = &net->sctp.rto_max;
  374. ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
  375. if (write) {
  376. if (ret || new_value > max || new_value < min)
  377. return -EINVAL;
  378. net->sctp.rto_max = new_value;
  379. }
  380. return ret;
  381. }
  382. int sctp_sysctl_net_register(struct net *net)
  383. {
  384. struct ctl_table *table = sctp_net_table;
  385. if (!net_eq(net, &init_net)) {
  386. int i;
  387. table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
  388. if (!table)
  389. return -ENOMEM;
  390. for (i = 0; table[i].data; i++)
  391. table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
  392. }
  393. net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
  394. return 0;
  395. }
  396. void sctp_sysctl_net_unregister(struct net *net)
  397. {
  398. struct ctl_table *table;
  399. table = net->sctp.sysctl_header->ctl_table_arg;
  400. unregister_net_sysctl_table(net->sctp.sysctl_header);
  401. kfree(table);
  402. }
  403. static struct ctl_table_header *sctp_sysctl_header;
  404. /* Sysctl registration. */
  405. void sctp_sysctl_register(void)
  406. {
  407. sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
  408. }
  409. /* Sysctl deregistration. */
  410. void sctp_sysctl_unregister(void)
  411. {
  412. unregister_net_sysctl_table(sctp_sysctl_header);
  413. }