Merge branch develop-3.10 into develop-3.10-next
[firefly-linux-kernel-4.4.55.git] / net / sctp / sysctl.c
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 <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>
45 #include <net/sctp/sctp.h>
46 #include <linux/sysctl.h>
47
48 static int zero = 0;
49 static int one = 1;
50 static int timer_max = 86400000; /* ms in one day */
51 static int int_max = INT_MAX;
52 static int sack_timer_min = 1;
53 static int sack_timer_max = 500;
54 static int addr_scope_max = 3; /* check sctp_scope_policy_t in include/net/sctp/constants.h for max entries */
55 static int rwnd_scale_max = 16;
56 static unsigned long max_autoclose_min = 0;
57 static unsigned long max_autoclose_max =
58         (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX)
59         ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ;
60
61 extern long sysctl_sctp_mem[3];
62 extern int sysctl_sctp_rmem[3];
63 extern int sysctl_sctp_wmem[3];
64
65 static int proc_sctp_do_hmac_alg(ctl_table *ctl,
66                                 int write,
67                                 void __user *buffer, size_t *lenp,
68                                 loff_t *ppos);
69 static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
70                              void __user *buffer, size_t *lenp,
71                              loff_t *ppos);
72
73 static ctl_table sctp_table[] = {
74         {
75                 .procname       = "sctp_mem",
76                 .data           = &sysctl_sctp_mem,
77                 .maxlen         = sizeof(sysctl_sctp_mem),
78                 .mode           = 0644,
79                 .proc_handler   = proc_doulongvec_minmax
80         },
81         {
82                 .procname       = "sctp_rmem",
83                 .data           = &sysctl_sctp_rmem,
84                 .maxlen         = sizeof(sysctl_sctp_rmem),
85                 .mode           = 0644,
86                 .proc_handler   = proc_dointvec,
87         },
88         {
89                 .procname       = "sctp_wmem",
90                 .data           = &sysctl_sctp_wmem,
91                 .maxlen         = sizeof(sysctl_sctp_wmem),
92                 .mode           = 0644,
93                 .proc_handler   = proc_dointvec,
94         },
95
96         { /* sentinel */ }
97 };
98
99 static ctl_table sctp_net_table[] = {
100         {
101                 .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         {
158                 .procname       = "cookie_hmac_alg",
159                 .maxlen         = 8,
160                 .mode           = 0644,
161                 .proc_handler   = proc_sctp_do_hmac_alg,
162         },
163         {
164                 .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,
250                 .maxlen         = sizeof(int),
251                 .mode           = 0644,
252                 .proc_handler   = proc_dointvec,
253         },
254         {
255                 .procname       = "addip_noauth_enable",
256                 .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,
271                 .maxlen         = sizeof(int),
272                 .mode           = 0644,
273                 .proc_handler   = proc_sctp_do_auth,
274         },
275         {
276                 .procname       = "addr_scope_policy",
277                 .data           = &init_net.sctp.scope_policy,
278                 .maxlen         = sizeof(int),
279                 .mode           = 0644,
280                 .proc_handler   = proc_dointvec_minmax,
281                 .extra1         = &zero,
282                 .extra2         = &addr_scope_max,
283         },
284         {
285                 .procname       = "rwnd_update_shift",
286                 .data           = &init_net.sctp.rwnd_upd_shift,
287                 .maxlen         = sizeof(int),
288                 .mode           = 0644,
289                 .proc_handler   = &proc_dointvec_minmax,
290                 .extra1         = &one,
291                 .extra2         = &rwnd_scale_max,
292         },
293         {
294                 .procname       = "max_autoclose",
295                 .data           = &init_net.sctp.max_autoclose,
296                 .maxlen         = sizeof(unsigned long),
297                 .mode           = 0644,
298                 .proc_handler   = &proc_doulongvec_minmax,
299                 .extra1         = &max_autoclose_min,
300                 .extra2         = &max_autoclose_max,
301         },
302
303         { /* sentinel */ }
304 };
305
306 static 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
354 static 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);
371         if (write && ret == 0) {
372                 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
384 int sctp_sysctl_net_register(struct net *net)
385 {
386         struct ctl_table *table;
387         int i;
388
389         table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
390         if (!table)
391                 return -ENOMEM;
392
393         for (i = 0; table[i].data; i++)
394                 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
395
396         net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
397         return 0;
398 }
399
400 void sctp_sysctl_net_unregister(struct net *net)
401 {
402         struct ctl_table *table;
403
404         table = net->sctp.sysctl_header->ctl_table_arg;
405         unregister_net_sysctl_table(net->sctp.sysctl_header);
406         kfree(table);
407 }
408
409 static struct ctl_table_header * sctp_sysctl_header;
410
411 /* Sysctl registration.  */
412 void sctp_sysctl_register(void)
413 {
414         sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
415 }
416
417 /* Sysctl deregistration.  */
418 void sctp_sysctl_unregister(void)
419 {
420         unregister_net_sysctl_table(sctp_sysctl_header);
421 }