1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* SCTP kernel implementation
3 * (C) Copyright IBM Corp. 2002, 2004
4 * Copyright (c) 2002 Intel Corp.
6 * This file is part of the SCTP kernel implementation
8 * Sysctl related interfaces for SCTP.
10 * Please send any bug reports or fixes you make to the
12 * lksctp developers <linux-sctp@vger.kernel.org>
14 * Written or modified by:
15 * Mingqin Liu <liuming@us.ibm.com>
16 * Jon Grimm <jgrimm@us.ibm.com>
17 * Ardelle Fan <ardelle.fan@intel.com>
18 * Ryan Layer <rmlayer@us.ibm.com>
19 * Sridhar Samudrala <sri@us.ibm.com>
22 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24 #include <net/sctp/structs.h>
25 #include <net/sctp/sctp.h>
26 #include <linux/sysctl.h>
28 static int timer_max = 86400000; /* ms in one day */
29 static int sack_timer_min = 1;
30 static int sack_timer_max = 500;
31 static int addr_scope_max = SCTP_SCOPE_POLICY_MAX;
32 static int rwnd_scale_max = 16;
33 static int rto_alpha_min = 0;
34 static int rto_beta_min = 0;
35 static int rto_alpha_max = 1000;
36 static int rto_beta_max = 1000;
37 static int pf_expose_max = SCTP_PF_EXPOSE_MAX;
38 static int ps_retrans_max = SCTP_PS_RETRANS_MAX;
39 static int udp_port_max = 65535;
41 static unsigned long max_autoclose_min = 0;
42 static unsigned long max_autoclose_max =
43 (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
44 ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
46 static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
47 void *buffer, size_t *lenp, loff_t *ppos);
48 static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
49 void *buffer, size_t *lenp, loff_t *ppos);
50 static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, void *buffer,
51 size_t *lenp, loff_t *ppos);
52 static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write, void *buffer,
53 size_t *lenp, loff_t *ppos);
54 static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
55 void *buffer, size_t *lenp, loff_t *ppos);
56 static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
57 void *buffer, size_t *lenp, loff_t *ppos);
58 static int proc_sctp_do_probe_interval(struct ctl_table *ctl, int write,
59 void *buffer, size_t *lenp, loff_t *ppos);
61 static struct ctl_table sctp_table[] = {
63 .procname = "sctp_mem",
64 .data = &sysctl_sctp_mem,
65 .maxlen = sizeof(sysctl_sctp_mem),
67 .proc_handler = proc_doulongvec_minmax
70 .procname = "sctp_rmem",
71 .data = &sysctl_sctp_rmem,
72 .maxlen = sizeof(sysctl_sctp_rmem),
74 .proc_handler = proc_dointvec,
77 .procname = "sctp_wmem",
78 .data = &sysctl_sctp_wmem,
79 .maxlen = sizeof(sysctl_sctp_wmem),
81 .proc_handler = proc_dointvec,
87 static struct ctl_table sctp_net_table[] = {
89 .procname = "rto_initial",
90 .data = &init_net.sctp.rto_initial,
91 .maxlen = sizeof(unsigned int),
93 .proc_handler = proc_dointvec_minmax,
98 .procname = "rto_min",
99 .data = &init_net.sctp.rto_min,
100 .maxlen = sizeof(unsigned int),
102 .proc_handler = proc_sctp_do_rto_min,
103 .extra1 = SYSCTL_ONE,
104 .extra2 = &init_net.sctp.rto_max
107 .procname = "rto_max",
108 .data = &init_net.sctp.rto_max,
109 .maxlen = sizeof(unsigned int),
111 .proc_handler = proc_sctp_do_rto_max,
112 .extra1 = &init_net.sctp.rto_min,
116 .procname = "rto_alpha_exp_divisor",
117 .data = &init_net.sctp.rto_alpha,
118 .maxlen = sizeof(int),
120 .proc_handler = proc_sctp_do_alpha_beta,
121 .extra1 = &rto_alpha_min,
122 .extra2 = &rto_alpha_max,
125 .procname = "rto_beta_exp_divisor",
126 .data = &init_net.sctp.rto_beta,
127 .maxlen = sizeof(int),
129 .proc_handler = proc_sctp_do_alpha_beta,
130 .extra1 = &rto_beta_min,
131 .extra2 = &rto_beta_max,
134 .procname = "max_burst",
135 .data = &init_net.sctp.max_burst,
136 .maxlen = sizeof(int),
138 .proc_handler = proc_dointvec_minmax,
139 .extra1 = SYSCTL_ZERO,
140 .extra2 = SYSCTL_INT_MAX,
143 .procname = "cookie_preserve_enable",
144 .data = &init_net.sctp.cookie_preserve_enable,
145 .maxlen = sizeof(int),
147 .proc_handler = proc_dointvec,
150 .procname = "cookie_hmac_alg",
151 .data = &init_net.sctp.sctp_hmac_alg,
154 .proc_handler = proc_sctp_do_hmac_alg,
157 .procname = "valid_cookie_life",
158 .data = &init_net.sctp.valid_cookie_life,
159 .maxlen = sizeof(unsigned int),
161 .proc_handler = proc_dointvec_minmax,
162 .extra1 = SYSCTL_ONE,
166 .procname = "sack_timeout",
167 .data = &init_net.sctp.sack_timeout,
168 .maxlen = sizeof(int),
170 .proc_handler = proc_dointvec_minmax,
171 .extra1 = &sack_timer_min,
172 .extra2 = &sack_timer_max,
175 .procname = "hb_interval",
176 .data = &init_net.sctp.hb_interval,
177 .maxlen = sizeof(unsigned int),
179 .proc_handler = proc_dointvec_minmax,
180 .extra1 = SYSCTL_ONE,
184 .procname = "association_max_retrans",
185 .data = &init_net.sctp.max_retrans_association,
186 .maxlen = sizeof(int),
188 .proc_handler = proc_dointvec_minmax,
189 .extra1 = SYSCTL_ONE,
190 .extra2 = SYSCTL_INT_MAX,
193 .procname = "path_max_retrans",
194 .data = &init_net.sctp.max_retrans_path,
195 .maxlen = sizeof(int),
197 .proc_handler = proc_dointvec_minmax,
198 .extra1 = SYSCTL_ONE,
199 .extra2 = SYSCTL_INT_MAX,
202 .procname = "max_init_retransmits",
203 .data = &init_net.sctp.max_retrans_init,
204 .maxlen = sizeof(int),
206 .proc_handler = proc_dointvec_minmax,
207 .extra1 = SYSCTL_ONE,
208 .extra2 = SYSCTL_INT_MAX,
211 .procname = "pf_retrans",
212 .data = &init_net.sctp.pf_retrans,
213 .maxlen = sizeof(int),
215 .proc_handler = proc_dointvec_minmax,
216 .extra1 = SYSCTL_ZERO,
217 .extra2 = &init_net.sctp.ps_retrans,
220 .procname = "ps_retrans",
221 .data = &init_net.sctp.ps_retrans,
222 .maxlen = sizeof(int),
224 .proc_handler = proc_dointvec_minmax,
225 .extra1 = &init_net.sctp.pf_retrans,
226 .extra2 = &ps_retrans_max,
229 .procname = "sndbuf_policy",
230 .data = &init_net.sctp.sndbuf_policy,
231 .maxlen = sizeof(int),
233 .proc_handler = proc_dointvec,
236 .procname = "rcvbuf_policy",
237 .data = &init_net.sctp.rcvbuf_policy,
238 .maxlen = sizeof(int),
240 .proc_handler = proc_dointvec,
243 .procname = "default_auto_asconf",
244 .data = &init_net.sctp.default_auto_asconf,
245 .maxlen = sizeof(int),
247 .proc_handler = proc_dointvec,
250 .procname = "addip_enable",
251 .data = &init_net.sctp.addip_enable,
252 .maxlen = sizeof(int),
254 .proc_handler = proc_dointvec,
257 .procname = "addip_noauth_enable",
258 .data = &init_net.sctp.addip_noauth,
259 .maxlen = sizeof(int),
261 .proc_handler = proc_dointvec,
264 .procname = "prsctp_enable",
265 .data = &init_net.sctp.prsctp_enable,
266 .maxlen = sizeof(int),
268 .proc_handler = proc_dointvec,
271 .procname = "reconf_enable",
272 .data = &init_net.sctp.reconf_enable,
273 .maxlen = sizeof(int),
275 .proc_handler = proc_dointvec,
278 .procname = "auth_enable",
279 .data = &init_net.sctp.auth_enable,
280 .maxlen = sizeof(int),
282 .proc_handler = proc_sctp_do_auth,
285 .procname = "intl_enable",
286 .data = &init_net.sctp.intl_enable,
287 .maxlen = sizeof(int),
289 .proc_handler = proc_dointvec,
292 .procname = "ecn_enable",
293 .data = &init_net.sctp.ecn_enable,
294 .maxlen = sizeof(int),
296 .proc_handler = proc_dointvec,
299 .procname = "plpmtud_probe_interval",
300 .data = &init_net.sctp.probe_interval,
301 .maxlen = sizeof(int),
303 .proc_handler = proc_sctp_do_probe_interval,
306 .procname = "udp_port",
307 .data = &init_net.sctp.udp_port,
308 .maxlen = sizeof(int),
310 .proc_handler = proc_sctp_do_udp_port,
311 .extra1 = SYSCTL_ZERO,
312 .extra2 = &udp_port_max,
315 .procname = "encap_port",
316 .data = &init_net.sctp.encap_port,
317 .maxlen = sizeof(int),
319 .proc_handler = proc_dointvec_minmax,
320 .extra1 = SYSCTL_ZERO,
321 .extra2 = &udp_port_max,
324 .procname = "addr_scope_policy",
325 .data = &init_net.sctp.scope_policy,
326 .maxlen = sizeof(int),
328 .proc_handler = proc_dointvec_minmax,
329 .extra1 = SYSCTL_ZERO,
330 .extra2 = &addr_scope_max,
333 .procname = "rwnd_update_shift",
334 .data = &init_net.sctp.rwnd_upd_shift,
335 .maxlen = sizeof(int),
337 .proc_handler = &proc_dointvec_minmax,
338 .extra1 = SYSCTL_ONE,
339 .extra2 = &rwnd_scale_max,
342 .procname = "max_autoclose",
343 .data = &init_net.sctp.max_autoclose,
344 .maxlen = sizeof(unsigned long),
346 .proc_handler = &proc_doulongvec_minmax,
347 .extra1 = &max_autoclose_min,
348 .extra2 = &max_autoclose_max,
351 .procname = "pf_enable",
352 .data = &init_net.sctp.pf_enable,
353 .maxlen = sizeof(int),
355 .proc_handler = proc_dointvec,
358 .procname = "pf_expose",
359 .data = &init_net.sctp.pf_expose,
360 .maxlen = sizeof(int),
362 .proc_handler = proc_dointvec_minmax,
363 .extra1 = SYSCTL_ZERO,
364 .extra2 = &pf_expose_max,
370 static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
371 void *buffer, size_t *lenp, loff_t *ppos)
373 struct net *net = current->nsproxy->net_ns;
374 struct ctl_table tbl;
375 bool changed = false;
380 memset(&tbl, 0, sizeof(struct ctl_table));
384 tbl.maxlen = sizeof(tmp);
386 tbl.data = net->sctp.sctp_hmac_alg ? : none;
387 tbl.maxlen = strlen(tbl.data);
390 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
391 if (write && ret == 0) {
392 #ifdef CONFIG_CRYPTO_MD5
393 if (!strncmp(tmp, "md5", 3)) {
394 net->sctp.sctp_hmac_alg = "md5";
398 #ifdef CONFIG_CRYPTO_SHA1
399 if (!strncmp(tmp, "sha1", 4)) {
400 net->sctp.sctp_hmac_alg = "sha1";
404 if (!strncmp(tmp, "none", 4)) {
405 net->sctp.sctp_hmac_alg = NULL;
415 static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
416 void *buffer, size_t *lenp, loff_t *ppos)
418 struct net *net = current->nsproxy->net_ns;
419 unsigned int min = *(unsigned int *) ctl->extra1;
420 unsigned int max = *(unsigned int *) ctl->extra2;
421 struct ctl_table tbl;
424 memset(&tbl, 0, sizeof(struct ctl_table));
425 tbl.maxlen = sizeof(unsigned int);
428 tbl.data = &new_value;
430 tbl.data = &net->sctp.rto_min;
432 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
433 if (write && ret == 0) {
434 if (new_value > max || new_value < min)
437 net->sctp.rto_min = new_value;
443 static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
444 void *buffer, size_t *lenp, loff_t *ppos)
446 struct net *net = current->nsproxy->net_ns;
447 unsigned int min = *(unsigned int *) ctl->extra1;
448 unsigned int max = *(unsigned int *) ctl->extra2;
449 struct ctl_table tbl;
452 memset(&tbl, 0, sizeof(struct ctl_table));
453 tbl.maxlen = sizeof(unsigned int);
456 tbl.data = &new_value;
458 tbl.data = &net->sctp.rto_max;
460 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
461 if (write && ret == 0) {
462 if (new_value > max || new_value < min)
465 net->sctp.rto_max = new_value;
471 static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
472 void *buffer, size_t *lenp, loff_t *ppos)
475 pr_warn_once("Changing rto_alpha or rto_beta may lead to "
476 "suboptimal rtt/srtt estimations!\n");
478 return proc_dointvec_minmax(ctl, write, buffer, lenp, ppos);
481 static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
482 void *buffer, size_t *lenp, loff_t *ppos)
484 struct net *net = current->nsproxy->net_ns;
485 struct ctl_table tbl;
488 memset(&tbl, 0, sizeof(struct ctl_table));
489 tbl.maxlen = sizeof(unsigned int);
492 tbl.data = &new_value;
494 tbl.data = &net->sctp.auth_enable;
496 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
497 if (write && ret == 0) {
498 struct sock *sk = net->sctp.ctl_sock;
500 net->sctp.auth_enable = new_value;
501 /* Update the value in the control socket */
503 sctp_sk(sk)->ep->auth_enable = new_value;
510 static int proc_sctp_do_udp_port(struct ctl_table *ctl, int write,
511 void *buffer, size_t *lenp, loff_t *ppos)
513 struct net *net = current->nsproxy->net_ns;
514 unsigned int min = *(unsigned int *)ctl->extra1;
515 unsigned int max = *(unsigned int *)ctl->extra2;
516 struct ctl_table tbl;
519 memset(&tbl, 0, sizeof(struct ctl_table));
520 tbl.maxlen = sizeof(unsigned int);
523 tbl.data = &new_value;
525 tbl.data = &net->sctp.udp_port;
527 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
528 if (write && ret == 0) {
529 struct sock *sk = net->sctp.ctl_sock;
531 if (new_value > max || new_value < min)
534 net->sctp.udp_port = new_value;
535 sctp_udp_sock_stop(net);
537 ret = sctp_udp_sock_start(net);
539 net->sctp.udp_port = 0;
542 /* Update the value in the control socket */
544 sctp_sk(sk)->udp_port = htons(net->sctp.udp_port);
551 static int proc_sctp_do_probe_interval(struct ctl_table *ctl, int write,
552 void *buffer, size_t *lenp, loff_t *ppos)
554 struct net *net = current->nsproxy->net_ns;
555 struct ctl_table tbl;
558 memset(&tbl, 0, sizeof(struct ctl_table));
559 tbl.maxlen = sizeof(unsigned int);
562 tbl.data = &new_value;
564 tbl.data = &net->sctp.probe_interval;
566 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
567 if (write && ret == 0) {
568 if (new_value && new_value < SCTP_PROBE_TIMER_MIN)
571 net->sctp.probe_interval = new_value;
577 int sctp_sysctl_net_register(struct net *net)
579 struct ctl_table *table;
582 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
586 for (i = 0; table[i].data; i++)
587 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
589 net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
590 if (net->sctp.sysctl_header == NULL) {
597 void sctp_sysctl_net_unregister(struct net *net)
599 struct ctl_table *table;
601 table = net->sctp.sysctl_header->ctl_table_arg;
602 unregister_net_sysctl_table(net->sctp.sysctl_header);
606 static struct ctl_table_header *sctp_sysctl_header;
608 /* Sysctl registration. */
609 void sctp_sysctl_register(void)
611 sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
614 /* Sysctl deregistration. */
615 void sctp_sysctl_unregister(void)
617 unregister_net_sysctl_table(sctp_sysctl_header);