blob: 9a19147902f175aeb8963d7a93b8a5c47d68524e [file] [log] [blame]
Thomas Gleixner47505b82019-05-23 11:14:41 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Vlad Yasevich60c778b2008-01-11 09:57:09 -05002/* SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * (C) Copyright IBM Corp. 2002, 2004
4 * Copyright (c) 2002 Intel Corp.
5 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -05006 * This file is part of the SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * Sysctl related interfaces for SCTP.
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * Please send any bug reports or fixes you make to the
11 * email address(es):
Daniel Borkmann91705c62013-07-23 14:51:47 +020012 * lksctp developers <linux-sctp@vger.kernel.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * 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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
21
Daniel Borkmannb58537a2014-06-15 00:59:14 +020022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <net/sctp/structs.h>
Adrian Bunk8c5955d2005-09-05 18:07:42 -070025#include <net/sctp/sctp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/sysctl.h>
27
Vladislav Yasevich3fd091e2006-08-22 13:29:17 -070028static int zero = 0;
29static int one = 1;
30static int timer_max = 86400000; /* ms in one day */
31static int int_max = INT_MAX;
Jean-Mickael Guerind48e0742009-05-13 00:03:20 +020032static int sack_timer_min = 1;
33static int sack_timer_max = 500;
Xin Long701ef3e2017-08-05 19:59:53 +080034static int addr_scope_max = SCTP_SCOPE_POLICY_MAX;
Vlad Yasevich90f2f532009-11-23 15:53:57 -050035static int rwnd_scale_max = 16;
Daniel Borkmannb58537a2014-06-15 00:59:14 +020036static int rto_alpha_min = 0;
37static int rto_beta_min = 0;
38static int rto_alpha_max = 1000;
39static int rto_beta_max = 1000;
40
Xi Wang2692ba62011-12-16 12:44:15 +000041static unsigned long max_autoclose_min = 0;
42static unsigned long max_autoclose_max =
43 (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
44 ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
wangweidongb486b222013-12-11 09:50:40 +080046static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
Neil Horman3c681982012-10-24 09:20:03 +000047 void __user *buffer, size_t *lenp,
Neil Horman3c681982012-10-24 09:20:03 +000048 loff_t *ppos);
wangweidong4f3fdf32013-12-11 09:50:39 +080049static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
50 void __user *buffer, size_t *lenp,
51 loff_t *ppos);
52static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
53 void __user *buffer, size_t *lenp,
54 loff_t *ppos);
Daniel Borkmannb58537a2014-06-15 00:59:14 +020055static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
56 void __user *buffer, size_t *lenp,
57 loff_t *ppos);
Vlad Yasevichb14878c2014-04-17 17:26:50 +020058static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
59 void __user *buffer, size_t *lenp,
60 loff_t *ppos);
wangweidong4f3fdf32013-12-11 09:50:39 +080061
Joe Perchesfe2c6332013-06-11 23:04:25 -070062static struct ctl_table sctp_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 {
Neil Horman4d93df02007-08-15 16:07:44 -070064 .procname = "sctp_mem",
65 .data = &sysctl_sctp_mem,
66 .maxlen = sizeof(sysctl_sctp_mem),
67 .mode = 0644,
Eric Dumazet8d987e52010-11-09 23:24:26 +000068 .proc_handler = proc_doulongvec_minmax
Neil Horman4d93df02007-08-15 16:07:44 -070069 },
70 {
Neil Horman4d93df02007-08-15 16:07:44 -070071 .procname = "sctp_rmem",
72 .data = &sysctl_sctp_rmem,
73 .maxlen = sizeof(sysctl_sctp_rmem),
74 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080075 .proc_handler = proc_dointvec,
Neil Horman4d93df02007-08-15 16:07:44 -070076 },
77 {
Neil Horman4d93df02007-08-15 16:07:44 -070078 .procname = "sctp_wmem",
79 .data = &sysctl_sctp_wmem,
80 .maxlen = sizeof(sysctl_sctp_wmem),
81 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080082 .proc_handler = proc_dointvec,
Neil Horman4d93df02007-08-15 16:07:44 -070083 },
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +000084
85 { /* sentinel */ }
86};
87
Joe Perchesfe2c6332013-06-11 23:04:25 -070088static struct ctl_table sctp_net_table[] = {
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -070089 {
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +000090 .procname = "rto_initial",
91 .data = &init_net.sctp.rto_initial,
92 .maxlen = sizeof(unsigned int),
93 .mode = 0644,
94 .proc_handler = proc_dointvec_minmax,
95 .extra1 = &one,
96 .extra2 = &timer_max
97 },
98 {
99 .procname = "rto_min",
100 .data = &init_net.sctp.rto_min,
101 .maxlen = sizeof(unsigned int),
102 .mode = 0644,
wangweidong4f3fdf32013-12-11 09:50:39 +0800103 .proc_handler = proc_sctp_do_rto_min,
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000104 .extra1 = &one,
wangweidong4f3fdf32013-12-11 09:50:39 +0800105 .extra2 = &init_net.sctp.rto_max
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000106 },
107 {
108 .procname = "rto_max",
109 .data = &init_net.sctp.rto_max,
110 .maxlen = sizeof(unsigned int),
111 .mode = 0644,
wangweidong4f3fdf32013-12-11 09:50:39 +0800112 .proc_handler = proc_sctp_do_rto_max,
113 .extra1 = &init_net.sctp.rto_min,
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000114 .extra2 = &timer_max
115 },
116 {
117 .procname = "rto_alpha_exp_divisor",
118 .data = &init_net.sctp.rto_alpha,
119 .maxlen = sizeof(int),
Daniel Borkmannb58537a2014-06-15 00:59:14 +0200120 .mode = 0644,
121 .proc_handler = proc_sctp_do_alpha_beta,
122 .extra1 = &rto_alpha_min,
123 .extra2 = &rto_alpha_max,
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000124 },
125 {
126 .procname = "rto_beta_exp_divisor",
127 .data = &init_net.sctp.rto_beta,
128 .maxlen = sizeof(int),
Daniel Borkmannb58537a2014-06-15 00:59:14 +0200129 .mode = 0644,
130 .proc_handler = proc_sctp_do_alpha_beta,
131 .extra1 = &rto_beta_min,
132 .extra2 = &rto_beta_max,
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000133 },
134 {
135 .procname = "max_burst",
136 .data = &init_net.sctp.max_burst,
137 .maxlen = sizeof(int),
138 .mode = 0644,
139 .proc_handler = proc_dointvec_minmax,
140 .extra1 = &zero,
141 .extra2 = &int_max
142 },
143 {
144 .procname = "cookie_preserve_enable",
145 .data = &init_net.sctp.cookie_preserve_enable,
146 .maxlen = sizeof(int),
147 .mode = 0644,
148 .proc_handler = proc_dointvec,
149 },
150 {
Neil Horman3c681982012-10-24 09:20:03 +0000151 .procname = "cookie_hmac_alg",
wangweidong22a1f5142014-02-12 09:44:43 +0800152 .data = &init_net.sctp.sctp_hmac_alg,
Neil Horman3c681982012-10-24 09:20:03 +0000153 .maxlen = 8,
154 .mode = 0644,
155 .proc_handler = proc_sctp_do_hmac_alg,
156 },
157 {
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000158 .procname = "valid_cookie_life",
159 .data = &init_net.sctp.valid_cookie_life,
160 .maxlen = sizeof(unsigned int),
161 .mode = 0644,
162 .proc_handler = proc_dointvec_minmax,
163 .extra1 = &one,
164 .extra2 = &timer_max
165 },
166 {
167 .procname = "sack_timeout",
168 .data = &init_net.sctp.sack_timeout,
169 .maxlen = sizeof(int),
170 .mode = 0644,
171 .proc_handler = proc_dointvec_minmax,
172 .extra1 = &sack_timer_min,
173 .extra2 = &sack_timer_max,
174 },
175 {
176 .procname = "hb_interval",
177 .data = &init_net.sctp.hb_interval,
178 .maxlen = sizeof(unsigned int),
179 .mode = 0644,
180 .proc_handler = proc_dointvec_minmax,
181 .extra1 = &one,
182 .extra2 = &timer_max
183 },
184 {
185 .procname = "association_max_retrans",
186 .data = &init_net.sctp.max_retrans_association,
187 .maxlen = sizeof(int),
188 .mode = 0644,
189 .proc_handler = proc_dointvec_minmax,
190 .extra1 = &one,
191 .extra2 = &int_max
192 },
193 {
194 .procname = "path_max_retrans",
195 .data = &init_net.sctp.max_retrans_path,
196 .maxlen = sizeof(int),
197 .mode = 0644,
198 .proc_handler = proc_dointvec_minmax,
199 .extra1 = &one,
200 .extra2 = &int_max
201 },
202 {
203 .procname = "max_init_retransmits",
204 .data = &init_net.sctp.max_retrans_init,
205 .maxlen = sizeof(int),
206 .mode = 0644,
207 .proc_handler = proc_dointvec_minmax,
208 .extra1 = &one,
209 .extra2 = &int_max
210 },
211 {
212 .procname = "pf_retrans",
213 .data = &init_net.sctp.pf_retrans,
214 .maxlen = sizeof(int),
215 .mode = 0644,
216 .proc_handler = proc_dointvec_minmax,
217 .extra1 = &zero,
218 .extra2 = &int_max
219 },
220 {
221 .procname = "sndbuf_policy",
222 .data = &init_net.sctp.sndbuf_policy,
223 .maxlen = sizeof(int),
224 .mode = 0644,
225 .proc_handler = proc_dointvec,
226 },
227 {
228 .procname = "rcvbuf_policy",
229 .data = &init_net.sctp.rcvbuf_policy,
230 .maxlen = sizeof(int),
231 .mode = 0644,
232 .proc_handler = proc_dointvec,
233 },
234 {
235 .procname = "default_auto_asconf",
236 .data = &init_net.sctp.default_auto_asconf,
237 .maxlen = sizeof(int),
238 .mode = 0644,
239 .proc_handler = proc_dointvec,
240 },
241 {
242 .procname = "addip_enable",
243 .data = &init_net.sctp.addip_enable,
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -0700244 .maxlen = sizeof(int),
245 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800246 .proc_handler = proc_dointvec,
Vlad Yasevicha29a5bd2007-09-16 19:31:35 -0700247 },
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400248 {
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400249 .procname = "addip_noauth_enable",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000250 .data = &init_net.sctp.addip_noauth,
251 .maxlen = sizeof(int),
252 .mode = 0644,
253 .proc_handler = proc_dointvec,
254 },
255 {
256 .procname = "prsctp_enable",
257 .data = &init_net.sctp.prsctp_enable,
258 .maxlen = sizeof(int),
259 .mode = 0644,
260 .proc_handler = proc_dointvec,
261 },
262 {
Xin Longc0d8bab2017-03-10 12:11:12 +0800263 .procname = "reconf_enable",
264 .data = &init_net.sctp.reconf_enable,
265 .maxlen = sizeof(int),
266 .mode = 0644,
267 .proc_handler = proc_dointvec,
268 },
269 {
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000270 .procname = "auth_enable",
271 .data = &init_net.sctp.auth_enable,
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400272 .maxlen = sizeof(int),
273 .mode = 0644,
Vlad Yasevichb14878c2014-04-17 17:26:50 +0200274 .proc_handler = proc_sctp_do_auth,
Vlad Yasevich73d9c4f2007-10-24 17:24:26 -0400275 },
Bhaskar Dutta72388432009-09-03 17:25:47 +0530276 {
Xin Long463118c2017-12-15 00:41:32 +0800277 .procname = "intl_enable",
278 .data = &init_net.sctp.intl_enable,
279 .maxlen = sizeof(int),
280 .mode = 0644,
281 .proc_handler = proc_dointvec,
282 },
283 {
Bhaskar Dutta72388432009-09-03 17:25:47 +0530284 .procname = "addr_scope_policy",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000285 .data = &init_net.sctp.scope_policy,
Bhaskar Dutta72388432009-09-03 17:25:47 +0530286 .maxlen = sizeof(int),
287 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800288 .proc_handler = proc_dointvec_minmax,
Bhaskar Dutta72388432009-09-03 17:25:47 +0530289 .extra1 = &zero,
290 .extra2 = &addr_scope_max,
291 },
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500292 {
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500293 .procname = "rwnd_update_shift",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000294 .data = &init_net.sctp.rwnd_upd_shift,
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500295 .maxlen = sizeof(int),
296 .mode = 0644,
297 .proc_handler = &proc_dointvec_minmax,
Vlad Yasevich90f2f532009-11-23 15:53:57 -0500298 .extra1 = &one,
299 .extra2 = &rwnd_scale_max,
300 },
Xi Wang2692ba62011-12-16 12:44:15 +0000301 {
302 .procname = "max_autoclose",
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000303 .data = &init_net.sctp.max_autoclose,
Xi Wang2692ba62011-12-16 12:44:15 +0000304 .maxlen = sizeof(unsigned long),
305 .mode = 0644,
306 .proc_handler = &proc_doulongvec_minmax,
307 .extra1 = &max_autoclose_min,
308 .extra2 = &max_autoclose_max,
309 },
Zhu Yanjun566178f2015-12-16 13:55:04 +0800310 {
311 .procname = "pf_enable",
312 .data = &init_net.sctp.pf_enable,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = proc_dointvec,
316 },
David S. Miller71acc0d2013-08-09 13:09:41 -0700317
Linus Torvaldsd7fc02c2009-12-08 07:55:01 -0800318 { /* sentinel */ }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319};
320
wangweidongb486b222013-12-11 09:50:40 +0800321static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
Neil Horman3c681982012-10-24 09:20:03 +0000322 void __user *buffer, size_t *lenp,
323 loff_t *ppos)
324{
325 struct net *net = current->nsproxy->net_ns;
Joe Perchesfe2c6332013-06-11 23:04:25 -0700326 struct ctl_table tbl;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200327 bool changed = false;
Neil Horman3c681982012-10-24 09:20:03 +0000328 char *none = "none";
Sasha Levin320f1a42016-01-07 14:52:43 -0500329 char tmp[8] = {0};
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200330 int ret;
Neil Horman3c681982012-10-24 09:20:03 +0000331
332 memset(&tbl, 0, sizeof(struct ctl_table));
333
334 if (write) {
335 tbl.data = tmp;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200336 tbl.maxlen = sizeof(tmp);
Neil Horman3c681982012-10-24 09:20:03 +0000337 } else {
338 tbl.data = net->sctp.sctp_hmac_alg ? : none;
339 tbl.maxlen = strlen(tbl.data);
340 }
Neil Horman3c681982012-10-24 09:20:03 +0000341
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200342 ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
343 if (write && ret == 0) {
Neil Horman3c681982012-10-24 09:20:03 +0000344#ifdef CONFIG_CRYPTO_MD5
345 if (!strncmp(tmp, "md5", 3)) {
346 net->sctp.sctp_hmac_alg = "md5";
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200347 changed = true;
Neil Horman3c681982012-10-24 09:20:03 +0000348 }
349#endif
350#ifdef CONFIG_CRYPTO_SHA1
351 if (!strncmp(tmp, "sha1", 4)) {
352 net->sctp.sctp_hmac_alg = "sha1";
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200353 changed = true;
Neil Horman3c681982012-10-24 09:20:03 +0000354 }
355#endif
356 if (!strncmp(tmp, "none", 4)) {
357 net->sctp.sctp_hmac_alg = NULL;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200358 changed = true;
Neil Horman3c681982012-10-24 09:20:03 +0000359 }
Neil Horman3c681982012-10-24 09:20:03 +0000360 if (!changed)
361 ret = -EINVAL;
362 }
363
364 return ret;
365}
366
wangweidong4f3fdf32013-12-11 09:50:39 +0800367static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
368 void __user *buffer, size_t *lenp,
369 loff_t *ppos)
370{
371 struct net *net = current->nsproxy->net_ns;
wangweidong4f3fdf32013-12-11 09:50:39 +0800372 unsigned int min = *(unsigned int *) ctl->extra1;
373 unsigned int max = *(unsigned int *) ctl->extra2;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200374 struct ctl_table tbl;
375 int ret, new_value;
wangweidong4f3fdf32013-12-11 09:50:39 +0800376
377 memset(&tbl, 0, sizeof(struct ctl_table));
378 tbl.maxlen = sizeof(unsigned int);
379
380 if (write)
381 tbl.data = &new_value;
382 else
383 tbl.data = &net->sctp.rto_min;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200384
wangweidong4f3fdf32013-12-11 09:50:39 +0800385 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200386 if (write && ret == 0) {
387 if (new_value > max || new_value < min)
wangweidong4f3fdf32013-12-11 09:50:39 +0800388 return -EINVAL;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200389
wangweidong4f3fdf32013-12-11 09:50:39 +0800390 net->sctp.rto_min = new_value;
391 }
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200392
wangweidong4f3fdf32013-12-11 09:50:39 +0800393 return ret;
394}
395
396static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
397 void __user *buffer, size_t *lenp,
398 loff_t *ppos)
399{
400 struct net *net = current->nsproxy->net_ns;
wangweidong4f3fdf32013-12-11 09:50:39 +0800401 unsigned int min = *(unsigned int *) ctl->extra1;
402 unsigned int max = *(unsigned int *) ctl->extra2;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200403 struct ctl_table tbl;
404 int ret, new_value;
wangweidong4f3fdf32013-12-11 09:50:39 +0800405
406 memset(&tbl, 0, sizeof(struct ctl_table));
407 tbl.maxlen = sizeof(unsigned int);
408
409 if (write)
410 tbl.data = &new_value;
411 else
412 tbl.data = &net->sctp.rto_max;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200413
wangweidong4f3fdf32013-12-11 09:50:39 +0800414 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200415 if (write && ret == 0) {
416 if (new_value > max || new_value < min)
wangweidong4f3fdf32013-12-11 09:50:39 +0800417 return -EINVAL;
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200418
wangweidong4f3fdf32013-12-11 09:50:39 +0800419 net->sctp.rto_max = new_value;
420 }
Daniel Borkmannff5e92c2014-06-19 01:31:30 +0200421
wangweidong4f3fdf32013-12-11 09:50:39 +0800422 return ret;
423}
424
Daniel Borkmannb58537a2014-06-15 00:59:14 +0200425static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write,
426 void __user *buffer, size_t *lenp,
427 loff_t *ppos)
428{
Daniel Borkmanneaea2da2014-06-30 13:52:09 +0200429 if (write)
430 pr_warn_once("Changing rto_alpha or rto_beta may lead to "
431 "suboptimal rtt/srtt estimations!\n");
Daniel Borkmannb58537a2014-06-15 00:59:14 +0200432
433 return proc_dointvec_minmax(ctl, write, buffer, lenp, ppos);
434}
435
Vlad Yasevichb14878c2014-04-17 17:26:50 +0200436static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
437 void __user *buffer, size_t *lenp,
438 loff_t *ppos)
439{
440 struct net *net = current->nsproxy->net_ns;
441 struct ctl_table tbl;
442 int new_value, ret;
443
444 memset(&tbl, 0, sizeof(struct ctl_table));
445 tbl.maxlen = sizeof(unsigned int);
446
447 if (write)
448 tbl.data = &new_value;
449 else
450 tbl.data = &net->sctp.auth_enable;
451
452 ret = proc_dointvec(&tbl, write, buffer, lenp, ppos);
Daniel Borkmann24599e62014-06-18 23:46:31 +0200453 if (write && ret == 0) {
Vlad Yasevichb14878c2014-04-17 17:26:50 +0200454 struct sock *sk = net->sctp.ctl_sock;
455
456 net->sctp.auth_enable = new_value;
457 /* Update the value in the control socket */
458 lock_sock(sk);
459 sctp_sk(sk)->ep->auth_enable = new_value;
460 release_sock(sk);
461 }
462
463 return ret;
464}
465
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000466int sctp_sysctl_net_register(struct net *net)
467{
wangweidongeb9f3702014-05-08 20:55:01 +0800468 struct ctl_table *table;
469 int i;
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000470
wangweidongeb9f3702014-05-08 20:55:01 +0800471 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
472 if (!table)
473 return -ENOMEM;
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000474
wangweidongeb9f3702014-05-08 20:55:01 +0800475 for (i = 0; table[i].data; i++)
476 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
Eric W. Biedermane1fc3b12012-08-07 07:29:57 +0000477
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000478 net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
wangweidongf66138c2014-05-08 20:55:02 +0800479 if (net->sctp.sysctl_header == NULL) {
480 kfree(table);
481 return -ENOMEM;
482 }
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000483 return 0;
484}
485
486void sctp_sysctl_net_unregister(struct net *net)
487{
Vlad Yasevich5f19d122013-01-24 11:02:47 -0500488 struct ctl_table *table;
489
490 table = net->sctp.sysctl_header->ctl_table_arg;
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000491 unregister_net_sysctl_table(net->sctp.sysctl_header);
Vlad Yasevich5f19d122013-01-24 11:02:47 -0500492 kfree(table);
Eric W. Biedermanebb7e952012-08-07 07:23:59 +0000493}
494
wangweidong26ac8e52013-12-23 12:16:51 +0800495static struct ctl_table_header *sctp_sysctl_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497/* Sysctl registration. */
498void sctp_sysctl_register(void)
499{
Eric W. Biedermanec8f23c2012-04-19 13:44:49 +0000500 sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
503/* Sysctl deregistration. */
504void sctp_sysctl_unregister(void)
505{
Eric W. Biederman5dd3df12012-04-19 13:24:33 +0000506 unregister_net_sysctl_table(sctp_sysctl_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507}