sysctl.c 12 KB

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