sysctl.c 12 KB

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