sysctl.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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 <linux-sctp@vger.kernel.org>
  29. *
  30. * Written or modified by:
  31. * Mingqin Liu <liuming@us.ibm.com>
  32. * Jon Grimm <jgrimm@us.ibm.com>
  33. * Ardelle Fan <ardelle.fan@intel.com>
  34. * Ryan Layer <rmlayer@us.ibm.com>
  35. * Sridhar Samudrala <sri@us.ibm.com>
  36. */
  37. #include <net/sctp/structs.h>
  38. #include <net/sctp/sctp.h>
  39. #include <linux/sysctl.h>
  40. static int zero = 0;
  41. static int one = 1;
  42. static int timer_max = 86400000; /* ms in one day */
  43. static int int_max = INT_MAX;
  44. static int sack_timer_min = 1;
  45. static int sack_timer_max = 500;
  46. static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */
  47. static int rwnd_scale_max = 16;
  48. static unsigned long max_autoclose_min = 0;
  49. static unsigned long max_autoclose_max =
  50. (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
  51. ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
  52. extern long sysctl_sctp_mem[3];
  53. extern int sysctl_sctp_rmem[3];
  54. extern int sysctl_sctp_wmem[3];
  55. static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
  56. void __user *buffer, size_t *lenp,
  57. loff_t *ppos);
  58. static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
  59. void __user *buffer, size_t *lenp,
  60. loff_t *ppos);
  61. static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
  62. void __user *buffer, size_t *lenp,
  63. loff_t *ppos);
  64. static struct ctl_table sctp_table[] = {
  65. {
  66. .procname = "sctp_mem",
  67. .data = &sysctl_sctp_mem,
  68. .maxlen = sizeof(sysctl_sctp_mem),
  69. .mode = 0644,
  70. .proc_handler = proc_doulongvec_minmax
  71. },
  72. {
  73. .procname = "sctp_rmem",
  74. .data = &sysctl_sctp_rmem,
  75. .maxlen = sizeof(sysctl_sctp_rmem),
  76. .mode = 0644,
  77. .proc_handler = proc_dointvec,
  78. },
  79. {
  80. .procname = "sctp_wmem",
  81. .data = &sysctl_sctp_wmem,
  82. .maxlen = sizeof(sysctl_sctp_wmem),
  83. .mode = 0644,
  84. .proc_handler = proc_dointvec,
  85. },
  86. { /* sentinel */ }
  87. };
  88. static struct ctl_table sctp_net_table[] = {
  89. {
  90. .procname = "rto_initial",
  91. .data = &init_net.sctp.rto_initial,
  92. .maxlen = sizeof(unsigned int),
  93. .mode = 0644,
  94. .proc_handler = proc_dointvec_minmax,
  95. .extra1 = &one,
  96. .extra2 = &timer_max
  97. },
  98. {
  99. .procname = "rto_min",
  100. .data = &init_net.sctp.rto_min,
  101. .maxlen = sizeof(unsigned int),
  102. .mode = 0644,
  103. .proc_handler = proc_sctp_do_rto_min,
  104. .extra1 = &one,
  105. .extra2 = &init_net.sctp.rto_max
  106. },
  107. {
  108. .procname = "rto_max",
  109. .data = &init_net.sctp.rto_max,
  110. .maxlen = sizeof(unsigned int),
  111. .mode = 0644,
  112. .proc_handler = proc_sctp_do_rto_max,
  113. .extra1 = &init_net.sctp.rto_min,
  114. .extra2 = &timer_max
  115. },
  116. {
  117. .procname = "rto_alpha_exp_divisor",
  118. .data = &init_net.sctp.rto_alpha,
  119. .maxlen = sizeof(int),
  120. .mode = 0444,
  121. .proc_handler = proc_dointvec,
  122. },
  123. {
  124. .procname = "rto_beta_exp_divisor",
  125. .data = &init_net.sctp.rto_beta,
  126. .maxlen = sizeof(int),
  127. .mode = 0444,
  128. .proc_handler = proc_dointvec,
  129. },
  130. {
  131. .procname = "max_burst",
  132. .data = &init_net.sctp.max_burst,
  133. .maxlen = sizeof(int),
  134. .mode = 0644,
  135. .proc_handler = proc_dointvec_minmax,
  136. .extra1 = &zero,
  137. .extra2 = &int_max
  138. },
  139. {
  140. .procname = "cookie_preserve_enable",
  141. .data = &init_net.sctp.cookie_preserve_enable,
  142. .maxlen = sizeof(int),
  143. .mode = 0644,
  144. .proc_handler = proc_dointvec,
  145. },
  146. {
  147. .procname = "cookie_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;
  385. int i;
  386. table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
  387. if (!table)
  388. return -ENOMEM;
  389. for (i = 0; table[i].data; i++)
  390. table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
  391. net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
  392. return 0;
  393. }
  394. void sctp_sysctl_net_unregister(struct net *net)
  395. {
  396. struct ctl_table *table;
  397. table = net->sctp.sysctl_header->ctl_table_arg;
  398. unregister_net_sysctl_table(net->sctp.sysctl_header);
  399. kfree(table);
  400. }
  401. static struct ctl_table_header * sctp_sysctl_header;
  402. /* Sysctl registration. */
  403. void sctp_sysctl_register(void)
  404. {
  405. sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
  406. }
  407. /* Sysctl deregistration. */
  408. void sctp_sysctl_unregister(void)
  409. {
  410. unregister_net_sysctl_table(sctp_sysctl_header);
  411. }