blob: 6b36561a1b3b7cceab5f5a4a9dce7aa2bc362266 [file] [log] [blame]
Vlad Yasevich60c778b2008-01-11 09:57:09 -05001/* SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * (C) Copyright IBM Corp. 2002, 2004
3 * Copyright (c) 2002 Intel Corp.
4 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -05005 * This file is part of the SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * Sysctl related interfaces for SCTP.
8 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -05009 * This SCTP implementation is free software;
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050015 * This SCTP implementation is distributed in the hope that it
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * 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):
Daniel Borkmann91705c62013-07-23 14:51:47 +020028 * lksctp developers <linux-sctp@vger.kernel.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 */
37
38#include <net/sctp/structs.h>
Adrian Bunk8c5955d2005-09-05 18:07:42 -070039#include <net/sctp/sctp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/sysctl.h>
41
Vladislav Yasevich3fd091e2006-08-22 13:29:17 -070042static int zero = 0;
43static int one = 1;
44static int timer_max = 86400000; /* ms in one day */
45static int int_max = INT_MAX;
Jean-Mickael Guerind48e0742009-05-13 00:03:20 +020046static int sack_timer_min = 1;
47static int sack_timer_max = 500;
Bhaskar Dutta72388432009-09-03 17:25:47 +053048static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */
Vlad Yasevich90f2f532009-11-23 15:53:57 -050049static int rwnd_scale_max = 16;
Xi Wang2692ba62011-12-16 12:44:15 +000050static unsigned long max_autoclose_min = 0;
51static unsigned long max_autoclose_max =
52 (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
53 ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Eric Dumazet8d987e52010-11-09 23:24:26 +000055extern long sysctl_sctp_mem[3];
Vlad Yasevich007e3932007-09-16 16:04:37 -070056extern int sysctl_sctp_rmem[3];
57extern int sysctl_sctp_wmem[3];
Neil Horman4d93df02007-08-15 16:07:44 -070058
Joe Perchesfe2c6332013-06-11 23:04:25 -070059static int proc_sctp_do_hmac_alg(struct ctl_table *ctl,
Neil Horman3c681982012-10-24 09:20:03 +000060 int write,
61 void __user *buffer, size_t *lenp,
62
63 loff_t *ppos);
Joe Perchesfe2c6332013-06-11 23:04:25 -070064static struct ctl_table sctp_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 {
Neil Horman4d93df02007-08-15 16:07:44 -070066 .procname = "sctp_mem",
67 .data = &sysctl_sctp_mem,
68 .maxlen = sizeof(sysctl_sctp_mem),
69 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +000070 .proc_handler = proc_doulongvec_minmax
Neil Horman4d93df02007-08-15 16:07:44 -070071 },
72 {
Neil Horman4d93df02007-08-15 16:07:44 -070073 .procname = "sctp_rmem",
74 .data = &sysctl_sctp_rmem,
75 .maxlen = sizeof(sysctl_sctp_rmem),
76 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080077 .proc_handler = proc_dointvec,
Neil Horman4d93df02007-08-15 16:07:44 -070078 },
79 {
Neil Horman4d93df02007-08-15 16:07:44 -070080 .procname = "sctp_wmem",
81 .data = &sysctl_sctp_wmem,
82 .maxlen = sizeof(sysctl_sctp_wmem),
83 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080084 .proc_handler = proc_dointvec,
Neil Horman4d93df02007-08-15 16:07:44 -070085 },
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +000086
87 { /* sentinel */ }
88};
89
Joe Perchesfe2c6332013-06-11 23:04:25 -070090static struct ctl_table sctp_net_table[] = {
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -070091 {
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +000092 .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_dointvec_minmax,
106 .extra1 = &one,
107 .extra2 = &timer_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_dointvec_minmax,
115 .extra1 = &one,
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 {
Neil Horman3c681982012-10-24 09:20:03 +0000149 .procname = "cookie_hmac_alg",
150 .maxlen = 8,
151 .mode = 0644,
152 .proc_handler = proc_sctp_do_hmac_alg,
153 },
154 {
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000155 .procname = "valid_cookie_life",
156 .data = &init_net.sctp.valid_cookie_life,
157 .maxlen = sizeof(unsigned int),
158 .mode = 0644,
159 .proc_handler = proc_dointvec_minmax,
160 .extra1 = &one,
161 .extra2 = &timer_max
162 },
163 {
164 .procname = "sack_timeout",
165 .data = &init_net.sctp.sack_timeout,
166 .maxlen = sizeof(int),
167 .mode = 0644,
168 .proc_handler = proc_dointvec_minmax,
169 .extra1 = &sack_timer_min,
170 .extra2 = &sack_timer_max,
171 },
172 {
173 .procname = "hb_interval",
174 .data = &init_net.sctp.hb_interval,
175 .maxlen = sizeof(unsigned int),
176 .mode = 0644,
177 .proc_handler = proc_dointvec_minmax,
178 .extra1 = &one,
179 .extra2 = &timer_max
180 },
181 {
182 .procname = "association_max_retrans",
183 .data = &init_net.sctp.max_retrans_association,
184 .maxlen = sizeof(int),
185 .mode = 0644,
186 .proc_handler = proc_dointvec_minmax,
187 .extra1 = &one,
188 .extra2 = &int_max
189 },
190 {
191 .procname = "path_max_retrans",
192 .data = &init_net.sctp.max_retrans_path,
193 .maxlen = sizeof(int),
194 .mode = 0644,
195 .proc_handler = proc_dointvec_minmax,
196 .extra1 = &one,
197 .extra2 = &int_max
198 },
199 {
200 .procname = "max_init_retransmits",
201 .data = &init_net.sctp.max_retrans_init,
202 .maxlen = sizeof(int),
203 .mode = 0644,
204 .proc_handler = proc_dointvec_minmax,
205 .extra1 = &one,
206 .extra2 = &int_max
207 },
208 {
209 .procname = "pf_retrans",
210 .data = &init_net.sctp.pf_retrans,
211 .maxlen = sizeof(int),
212 .mode = 0644,
213 .proc_handler = proc_dointvec_minmax,
214 .extra1 = &zero,
215 .extra2 = &int_max
216 },
217 {
218 .procname = "sndbuf_policy",
219 .data = &init_net.sctp.sndbuf_policy,
220 .maxlen = sizeof(int),
221 .mode = 0644,
222 .proc_handler = proc_dointvec,
223 },
224 {
225 .procname = "rcvbuf_policy",
226 .data = &init_net.sctp.rcvbuf_policy,
227 .maxlen = sizeof(int),
228 .mode = 0644,
229 .proc_handler = proc_dointvec,
230 },
231 {
232 .procname = "default_auto_asconf",
233 .data = &init_net.sctp.default_auto_asconf,
234 .maxlen = sizeof(int),
235 .mode = 0644,
236 .proc_handler = proc_dointvec,
237 },
238 {
239 .procname = "addip_enable",
240 .data = &init_net.sctp.addip_enable,
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -0700241 .maxlen = sizeof(int),
242 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800243 .proc_handler = proc_dointvec,
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -0700244 },
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400245 {
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400246 .procname = "addip_noauth_enable",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000247 .data = &init_net.sctp.addip_noauth,
248 .maxlen = sizeof(int),
249 .mode = 0644,
250 .proc_handler = proc_dointvec,
251 },
252 {
253 .procname = "prsctp_enable",
254 .data = &init_net.sctp.prsctp_enable,
255 .maxlen = sizeof(int),
256 .mode = 0644,
257 .proc_handler = proc_dointvec,
258 },
259 {
260 .procname = "auth_enable",
261 .data = &init_net.sctp.auth_enable,
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400262 .maxlen = sizeof(int),
263 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800264 .proc_handler = proc_dointvec,
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400265 },
Bhaskar Dutta72388432009-09-03 17:25:47 +0530266 {
Bhaskar Dutta72388432009-09-03 17:25:47 +0530267 .procname = "addr_scope_policy",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000268 .data = &init_net.sctp.scope_policy,
Bhaskar Dutta72388432009-09-03 17:25:47 +0530269 .maxlen = sizeof(int),
270 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800271 .proc_handler = proc_dointvec_minmax,
Bhaskar Dutta72388432009-09-03 17:25:47 +0530272 .extra1 = &zero,
273 .extra2 = &addr_scope_max,
274 },
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500275 {
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500276 .procname = "rwnd_update_shift",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000277 .data = &init_net.sctp.rwnd_upd_shift,
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500278 .maxlen = sizeof(int),
279 .mode = 0644,
280 .proc_handler = &proc_dointvec_minmax,
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500281 .extra1 = &one,
282 .extra2 = &rwnd_scale_max,
283 },
Xi Wang2692ba62011-12-16 12:44:15 +0000284 {
285 .procname = "max_autoclose",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000286 .data = &init_net.sctp.max_autoclose,
Xi Wang2692ba62011-12-16 12:44:15 +0000287 .maxlen = sizeof(unsigned long),
288 .mode = 0644,
289 .proc_handler = &proc_doulongvec_minmax,
290 .extra1 = &max_autoclose_min,
291 .extra2 = &max_autoclose_max,
292 },
David S. Miller71acc0d2013-08-09 13:09:41 -0700293
Linus Torvaldsd7fc02c2009-12-08 07:55:01 -0800294 { /* sentinel */ }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295};
296
Joe Perchesfe2c6332013-06-11 23:04:25 -0700297static int proc_sctp_do_hmac_alg(struct ctl_table *ctl,
Neil Horman3c681982012-10-24 09:20:03 +0000298 int write,
299 void __user *buffer, size_t *lenp,
300 loff_t *ppos)
301{
302 struct net *net = current->nsproxy->net_ns;
303 char tmp[8];
Joe Perchesfe2c6332013-06-11 23:04:25 -0700304 struct ctl_table tbl;
Neil Horman3c681982012-10-24 09:20:03 +0000305 int ret;
306 int changed = 0;
307 char *none = "none";
308
309 memset(&tbl, 0, sizeof(struct ctl_table));
310
311 if (write) {
312 tbl.data = tmp;
313 tbl.maxlen = 8;
314 } else {
315 tbl.data = net->sctp.sctp_hmac_alg ? : none;
316 tbl.maxlen = strlen(tbl.data);
317 }
318 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
319
320 if (write) {
321#ifdef CONFIG_CRYPTO_MD5
322 if (!strncmp(tmp, "md5", 3)) {
323 net->sctp.sctp_hmac_alg = "md5";
324 changed = 1;
325 }
326#endif
327#ifdef CONFIG_CRYPTO_SHA1
328 if (!strncmp(tmp, "sha1", 4)) {
329 net->sctp.sctp_hmac_alg = "sha1";
330 changed = 1;
331 }
332#endif
333 if (!strncmp(tmp, "none", 4)) {
334 net->sctp.sctp_hmac_alg = NULL;
335 changed = 1;
336 }
337
338 if (!changed)
339 ret = -EINVAL;
340 }
341
342 return ret;
343}
344
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000345int sctp_sysctl_net_register(struct net *net)
346{
347 struct ctl_table *table;
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000348 int i;
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000349
350 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
351 if (!table)
352 return -ENOMEM;
353
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000354 for (i = 0; table[i].data; i++)
355 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
356
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000357 net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
358 return 0;
359}
360
361void sctp_sysctl_net_unregister(struct net *net)
362{
Vlad Yasevich5f19d122013-01-24 11:02:47 -0500363 struct ctl_table *table;
364
365 table = net->sctp.sysctl_header->ctl_table_arg;
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000366 unregister_net_sysctl_table(net->sctp.sysctl_header);
Vlad Yasevich5f19d122013-01-24 11:02:47 -0500367 kfree(table);
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000368}
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370static struct ctl_table_header * sctp_sysctl_header;
371
372/* Sysctl registration. */
373void sctp_sysctl_register(void)
374{
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000375 sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
378/* Sysctl deregistration. */
379void sctp_sysctl_unregister(void)
380{
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000381 unregister_net_sysctl_table(sctp_sysctl_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}