sysctl.c 9.1 KB

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