sysctl.c 13 KB

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