blob: 29299dcabfbb77be13856478fb7feb667efcf854 [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):
28 * lksctp developers <lksctp-developers@lists.sourceforge.net>
29 *
30 * Or submit a bug report through the following website:
31 * http://www.sf.net/projects/lksctp
32 *
33 * Written or modified by:
34 * Mingqin Liu <liuming@us.ibm.com>
35 * Jon Grimm <jgrimm@us.ibm.com>
36 * Ardelle Fan <ardelle.fan@intel.com>
37 * Ryan Layer <rmlayer@us.ibm.com>
38 * Sridhar Samudrala <sri@us.ibm.com>
39 *
40 * Any bugs reported given to us we will try to fix... any fixes shared will
41 * be incorporated into the next SCTP release.
42 */
43
44#include <net/sctp/structs.h>
Adrian Bunk8c5955d2005-09-05 18:07:42 -070045#include <net/sctp/sctp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/sysctl.h>
47
Vladislav Yasevich3fd091e2006-08-22 13:29:17 -070048static int zero = 0;
49static int one = 1;
50static int timer_max = 86400000; /* ms in one day */
51static int int_max = INT_MAX;
Jean-Mickael Guerind48e0742009-05-13 00:03:20 +020052static int sack_timer_min = 1;
53static int sack_timer_max = 500;
Bhaskar Dutta72388432009-09-03 17:25:47 +053054static 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 -050055static int rwnd_scale_max = 16;
Xi Wang2692ba62011-12-16 12:44:15 +000056static unsigned long max_autoclose_min = 0;
57static unsigned long max_autoclose_max =
58 (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
59 ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Eric Dumazet8d987e52010-11-09 23:24:26 +000061extern long sysctl_sctp_mem[3];
Vlad Yasevich007e3932007-09-16 16:04:37 -070062extern int sysctl_sctp_rmem[3];
63extern int sysctl_sctp_wmem[3];
Neil Horman4d93df02007-08-15 16:07:44 -070064
Neil Horman3c681982012-10-24 09:20:03 +000065static int proc_sctp_do_hmac_alg(ctl_table *ctl,
66 int write,
67 void __user *buffer, size_t *lenp,
Neil Horman3c681982012-10-24 09:20:03 +000068 loff_t *ppos);
Vlad Yaseviche5eae4a2014-04-17 17:26:50 +020069static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
70 void __user *buffer, size_t *lenp,
71 loff_t *ppos);
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073static ctl_table sctp_table[] = {
74 {
Neil Horman4d93df02007-08-15 16:07:44 -070075 .procname = "sctp_mem",
76 .data = &sysctl_sctp_mem,
77 .maxlen = sizeof(sysctl_sctp_mem),
78 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +000079 .proc_handler = proc_doulongvec_minmax
Neil Horman4d93df02007-08-15 16:07:44 -070080 },
81 {
Neil Horman4d93df02007-08-15 16:07:44 -070082 .procname = "sctp_rmem",
83 .data = &sysctl_sctp_rmem,
84 .maxlen = sizeof(sysctl_sctp_rmem),
85 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080086 .proc_handler = proc_dointvec,
Neil Horman4d93df02007-08-15 16:07:44 -070087 },
88 {
Neil Horman4d93df02007-08-15 16:07:44 -070089 .procname = "sctp_wmem",
90 .data = &sysctl_sctp_wmem,
91 .maxlen = sizeof(sysctl_sctp_wmem),
92 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080093 .proc_handler = proc_dointvec,
Neil Horman4d93df02007-08-15 16:07:44 -070094 },
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +000095
96 { /* sentinel */ }
97};
98
99static ctl_table sctp_net_table[] = {
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -0700100 {
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000101 .procname = "rto_initial",
102 .data = &init_net.sctp.rto_initial,
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_min",
111 .data = &init_net.sctp.rto_min,
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_max",
120 .data = &init_net.sctp.rto_max,
121 .maxlen = sizeof(unsigned int),
122 .mode = 0644,
123 .proc_handler = proc_dointvec_minmax,
124 .extra1 = &one,
125 .extra2 = &timer_max
126 },
127 {
128 .procname = "rto_alpha_exp_divisor",
129 .data = &init_net.sctp.rto_alpha,
130 .maxlen = sizeof(int),
131 .mode = 0444,
132 .proc_handler = proc_dointvec,
133 },
134 {
135 .procname = "rto_beta_exp_divisor",
136 .data = &init_net.sctp.rto_beta,
137 .maxlen = sizeof(int),
138 .mode = 0444,
139 .proc_handler = proc_dointvec,
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 {
Neil Horman3c681982012-10-24 09:20:03 +0000158 .procname = "cookie_hmac_alg",
159 .maxlen = 8,
160 .mode = 0644,
161 .proc_handler = proc_sctp_do_hmac_alg,
162 },
163 {
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000164 .procname = "valid_cookie_life",
165 .data = &init_net.sctp.valid_cookie_life,
166 .maxlen = sizeof(unsigned int),
167 .mode = 0644,
168 .proc_handler = proc_dointvec_minmax,
169 .extra1 = &one,
170 .extra2 = &timer_max
171 },
172 {
173 .procname = "sack_timeout",
174 .data = &init_net.sctp.sack_timeout,
175 .maxlen = sizeof(int),
176 .mode = 0644,
177 .proc_handler = proc_dointvec_minmax,
178 .extra1 = &sack_timer_min,
179 .extra2 = &sack_timer_max,
180 },
181 {
182 .procname = "hb_interval",
183 .data = &init_net.sctp.hb_interval,
184 .maxlen = sizeof(unsigned int),
185 .mode = 0644,
186 .proc_handler = proc_dointvec_minmax,
187 .extra1 = &one,
188 .extra2 = &timer_max
189 },
190 {
191 .procname = "association_max_retrans",
192 .data = &init_net.sctp.max_retrans_association,
193 .maxlen = sizeof(int),
194 .mode = 0644,
195 .proc_handler = proc_dointvec_minmax,
196 .extra1 = &one,
197 .extra2 = &int_max
198 },
199 {
200 .procname = "path_max_retrans",
201 .data = &init_net.sctp.max_retrans_path,
202 .maxlen = sizeof(int),
203 .mode = 0644,
204 .proc_handler = proc_dointvec_minmax,
205 .extra1 = &one,
206 .extra2 = &int_max
207 },
208 {
209 .procname = "max_init_retransmits",
210 .data = &init_net.sctp.max_retrans_init,
211 .maxlen = sizeof(int),
212 .mode = 0644,
213 .proc_handler = proc_dointvec_minmax,
214 .extra1 = &one,
215 .extra2 = &int_max
216 },
217 {
218 .procname = "pf_retrans",
219 .data = &init_net.sctp.pf_retrans,
220 .maxlen = sizeof(int),
221 .mode = 0644,
222 .proc_handler = proc_dointvec_minmax,
223 .extra1 = &zero,
224 .extra2 = &int_max
225 },
226 {
227 .procname = "sndbuf_policy",
228 .data = &init_net.sctp.sndbuf_policy,
229 .maxlen = sizeof(int),
230 .mode = 0644,
231 .proc_handler = proc_dointvec,
232 },
233 {
234 .procname = "rcvbuf_policy",
235 .data = &init_net.sctp.rcvbuf_policy,
236 .maxlen = sizeof(int),
237 .mode = 0644,
238 .proc_handler = proc_dointvec,
239 },
240 {
241 .procname = "default_auto_asconf",
242 .data = &init_net.sctp.default_auto_asconf,
243 .maxlen = sizeof(int),
244 .mode = 0644,
245 .proc_handler = proc_dointvec,
246 },
247 {
248 .procname = "addip_enable",
249 .data = &init_net.sctp.addip_enable,
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -0700250 .maxlen = sizeof(int),
251 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800252 .proc_handler = proc_dointvec,
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -0700253 },
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400254 {
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400255 .procname = "addip_noauth_enable",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000256 .data = &init_net.sctp.addip_noauth,
257 .maxlen = sizeof(int),
258 .mode = 0644,
259 .proc_handler = proc_dointvec,
260 },
261 {
262 .procname = "prsctp_enable",
263 .data = &init_net.sctp.prsctp_enable,
264 .maxlen = sizeof(int),
265 .mode = 0644,
266 .proc_handler = proc_dointvec,
267 },
268 {
269 .procname = "auth_enable",
270 .data = &init_net.sctp.auth_enable,
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400271 .maxlen = sizeof(int),
272 .mode = 0644,
Vlad Yaseviche5eae4a2014-04-17 17:26:50 +0200273 .proc_handler = proc_sctp_do_auth,
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400274 },
Bhaskar Dutta72388432009-09-03 17:25:47 +0530275 {
Bhaskar Dutta72388432009-09-03 17:25:47 +0530276 .procname = "addr_scope_policy",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000277 .data = &init_net.sctp.scope_policy,
Bhaskar Dutta72388432009-09-03 17:25:47 +0530278 .maxlen = sizeof(int),
279 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800280 .proc_handler = proc_dointvec_minmax,
Bhaskar Dutta72388432009-09-03 17:25:47 +0530281 .extra1 = &zero,
282 .extra2 = &addr_scope_max,
283 },
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500284 {
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500285 .procname = "rwnd_update_shift",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000286 .data = &init_net.sctp.rwnd_upd_shift,
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500287 .maxlen = sizeof(int),
288 .mode = 0644,
289 .proc_handler = &proc_dointvec_minmax,
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500290 .extra1 = &one,
291 .extra2 = &rwnd_scale_max,
292 },
Xi Wang2692ba62011-12-16 12:44:15 +0000293 {
294 .procname = "max_autoclose",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000295 .data = &init_net.sctp.max_autoclose,
Xi Wang2692ba62011-12-16 12:44:15 +0000296 .maxlen = sizeof(unsigned long),
297 .mode = 0644,
298 .proc_handler = &proc_doulongvec_minmax,
299 .extra1 = &max_autoclose_min,
300 .extra2 = &max_autoclose_max,
301 },
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500302
Linus Torvaldsd7fc02c2009-12-08 07:55:01 -0800303 { /* sentinel */ }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304};
305
Neil Horman3c681982012-10-24 09:20:03 +0000306static int proc_sctp_do_hmac_alg(ctl_table *ctl,
307 int write,
308 void __user *buffer, size_t *lenp,
309 loff_t *ppos)
310{
311 struct net *net = current->nsproxy->net_ns;
312 char tmp[8];
313 ctl_table tbl;
314 int ret;
315 int changed = 0;
316 char *none = "none";
317
318 memset(&tbl, 0, sizeof(struct ctl_table));
319
320 if (write) {
321 tbl.data = tmp;
322 tbl.maxlen = 8;
323 } else {
324 tbl.data = net->sctp.sctp_hmac_alg ? : none;
325 tbl.maxlen = strlen(tbl.data);
326 }
327 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
328
329 if (write) {
330#ifdef CONFIG_CRYPTO_MD5
331 if (!strncmp(tmp, "md5", 3)) {
332 net->sctp.sctp_hmac_alg = "md5";
333 changed = 1;
334 }
335#endif
336#ifdef CONFIG_CRYPTO_SHA1
337 if (!strncmp(tmp, "sha1", 4)) {
338 net->sctp.sctp_hmac_alg = "sha1";
339 changed = 1;
340 }
341#endif
342 if (!strncmp(tmp, "none", 4)) {
343 net->sctp.sctp_hmac_alg = NULL;
344 changed = 1;
345 }
346
347 if (!changed)
348 ret = -EINVAL;
349 }
350
351 return ret;
352}
353
Vlad Yaseviche5eae4a2014-04-17 17:26:50 +0200354static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
355 void __user *buffer, size_t *lenp,
356 loff_t *ppos)
357{
358 struct net *net = current->nsproxy->net_ns;
359 struct ctl_table tbl;
360 int new_value, ret;
361
362 memset(&tbl, 0, sizeof(struct ctl_table));
363 tbl.maxlen = sizeof(unsigned int);
364
365 if (write)
366 tbl.data = &new_value;
367 else
368 tbl.data = &net->sctp.auth_enable;
369
370 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
Daniel Borkmanne9013d02014-06-18 23:46:31 +0200371 if (write && ret == 0) {
Vlad Yaseviche5eae4a2014-04-17 17:26:50 +0200372 struct sock *sk = net->sctp.ctl_sock;
373
374 net->sctp.auth_enable = new_value;
375 /* Update the value in the control socket */
376 lock_sock(sk);
377 sctp_sk(sk)->ep->auth_enable = new_value;
378 release_sock(sk);
379 }
380
381 return ret;
382}
383
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000384int sctp_sysctl_net_register(struct net *net)
385{
386 struct ctl_table *table;
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000387 int i;
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000388
389 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
390 if (!table)
391 return -ENOMEM;
392
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000393 for (i = 0; table[i].data; i++)
394 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
395
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000396 net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
397 return 0;
398}
399
400void sctp_sysctl_net_unregister(struct net *net)
401{
Vlad Yasevich5f19d122013-01-24 11:02:47 -0500402 struct ctl_table *table;
403
404 table = net->sctp.sysctl_header->ctl_table_arg;
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000405 unregister_net_sysctl_table(net->sctp.sysctl_header);
Vlad Yasevich5f19d122013-01-24 11:02:47 -0500406 kfree(table);
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409static struct ctl_table_header * sctp_sysctl_header;
410
411/* Sysctl registration. */
412void sctp_sysctl_register(void)
413{
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000414 sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
417/* Sysctl deregistration. */
418void sctp_sysctl_unregister(void)
419{
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000420 unregister_net_sysctl_table(sctp_sysctl_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}