xref: /openbmc/linux/net/sctp/sysctl.c (revision 05bcf503)
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 ctl_table sctp_table[] = {
66 	{
67 		.procname	= "sctp_mem",
68 		.data		= &sysctl_sctp_mem,
69 		.maxlen		= sizeof(sysctl_sctp_mem),
70 		.mode		= 0644,
71 		.proc_handler	= proc_doulongvec_minmax
72 	},
73 	{
74 		.procname	= "sctp_rmem",
75 		.data		= &sysctl_sctp_rmem,
76 		.maxlen		= sizeof(sysctl_sctp_rmem),
77 		.mode		= 0644,
78 		.proc_handler	= proc_dointvec,
79 	},
80 	{
81 		.procname	= "sctp_wmem",
82 		.data		= &sysctl_sctp_wmem,
83 		.maxlen		= sizeof(sysctl_sctp_wmem),
84 		.mode		= 0644,
85 		.proc_handler	= proc_dointvec,
86 	},
87 
88 	{ /* sentinel */ }
89 };
90 
91 static ctl_table sctp_net_table[] = {
92 	{
93 		.procname	= "rto_initial",
94 		.data		= &init_net.sctp.rto_initial,
95 		.maxlen		= sizeof(unsigned int),
96 		.mode		= 0644,
97 		.proc_handler	= proc_dointvec_minmax,
98 		.extra1         = &one,
99 		.extra2         = &timer_max
100 	},
101 	{
102 		.procname	= "rto_min",
103 		.data		= &init_net.sctp.rto_min,
104 		.maxlen		= sizeof(unsigned int),
105 		.mode		= 0644,
106 		.proc_handler	= proc_dointvec_minmax,
107 		.extra1         = &one,
108 		.extra2         = &timer_max
109 	},
110 	{
111 		.procname	= "rto_max",
112 		.data		= &init_net.sctp.rto_max,
113 		.maxlen		= sizeof(unsigned int),
114 		.mode		= 0644,
115 		.proc_handler	= proc_dointvec_minmax,
116 		.extra1         = &one,
117 		.extra2         = &timer_max
118 	},
119 	{
120 		.procname	= "rto_alpha_exp_divisor",
121 		.data		= &init_net.sctp.rto_alpha,
122 		.maxlen		= sizeof(int),
123 		.mode		= 0444,
124 		.proc_handler	= proc_dointvec,
125 	},
126 	{
127 		.procname	= "rto_beta_exp_divisor",
128 		.data		= &init_net.sctp.rto_beta,
129 		.maxlen		= sizeof(int),
130 		.mode		= 0444,
131 		.proc_handler	= proc_dointvec,
132 	},
133 	{
134 		.procname	= "max_burst",
135 		.data		= &init_net.sctp.max_burst,
136 		.maxlen		= sizeof(int),
137 		.mode		= 0644,
138 		.proc_handler	= proc_dointvec_minmax,
139 		.extra1		= &zero,
140 		.extra2		= &int_max
141 	},
142 	{
143 		.procname	= "cookie_preserve_enable",
144 		.data		= &init_net.sctp.cookie_preserve_enable,
145 		.maxlen		= sizeof(int),
146 		.mode		= 0644,
147 		.proc_handler	= proc_dointvec,
148 	},
149 	{
150 		.procname	= "valid_cookie_life",
151 		.data		= &init_net.sctp.valid_cookie_life,
152 		.maxlen		= sizeof(unsigned int),
153 		.mode		= 0644,
154 		.proc_handler	= proc_dointvec_minmax,
155 		.extra1         = &one,
156 		.extra2         = &timer_max
157 	},
158 	{
159 		.procname	= "sack_timeout",
160 		.data		= &init_net.sctp.sack_timeout,
161 		.maxlen		= sizeof(int),
162 		.mode		= 0644,
163 		.proc_handler	= proc_dointvec_minmax,
164 		.extra1         = &sack_timer_min,
165 		.extra2         = &sack_timer_max,
166 	},
167 	{
168 		.procname	= "hb_interval",
169 		.data		= &init_net.sctp.hb_interval,
170 		.maxlen		= sizeof(unsigned int),
171 		.mode		= 0644,
172 		.proc_handler	= proc_dointvec_minmax,
173 		.extra1         = &one,
174 		.extra2         = &timer_max
175 	},
176 	{
177 		.procname	= "association_max_retrans",
178 		.data		= &init_net.sctp.max_retrans_association,
179 		.maxlen		= sizeof(int),
180 		.mode		= 0644,
181 		.proc_handler	= proc_dointvec_minmax,
182 		.extra1		= &one,
183 		.extra2		= &int_max
184 	},
185 	{
186 		.procname	= "path_max_retrans",
187 		.data		= &init_net.sctp.max_retrans_path,
188 		.maxlen		= sizeof(int),
189 		.mode		= 0644,
190 		.proc_handler	= proc_dointvec_minmax,
191 		.extra1		= &one,
192 		.extra2		= &int_max
193 	},
194 	{
195 		.procname	= "max_init_retransmits",
196 		.data		= &init_net.sctp.max_retrans_init,
197 		.maxlen		= sizeof(int),
198 		.mode		= 0644,
199 		.proc_handler	= proc_dointvec_minmax,
200 		.extra1		= &one,
201 		.extra2		= &int_max
202 	},
203 	{
204 		.procname	= "pf_retrans",
205 		.data		= &init_net.sctp.pf_retrans,
206 		.maxlen		= sizeof(int),
207 		.mode		= 0644,
208 		.proc_handler	= proc_dointvec_minmax,
209 		.extra1		= &zero,
210 		.extra2		= &int_max
211 	},
212 	{
213 		.procname	= "sndbuf_policy",
214 		.data		= &init_net.sctp.sndbuf_policy,
215 		.maxlen		= sizeof(int),
216 		.mode		= 0644,
217 		.proc_handler	= proc_dointvec,
218 	},
219 	{
220 		.procname	= "rcvbuf_policy",
221 		.data		= &init_net.sctp.rcvbuf_policy,
222 		.maxlen		= sizeof(int),
223 		.mode		= 0644,
224 		.proc_handler	= proc_dointvec,
225 	},
226 	{
227 		.procname	= "default_auto_asconf",
228 		.data		= &init_net.sctp.default_auto_asconf,
229 		.maxlen		= sizeof(int),
230 		.mode		= 0644,
231 		.proc_handler	= proc_dointvec,
232 	},
233 	{
234 		.procname	= "addip_enable",
235 		.data		= &init_net.sctp.addip_enable,
236 		.maxlen		= sizeof(int),
237 		.mode		= 0644,
238 		.proc_handler	= proc_dointvec,
239 	},
240 	{
241 		.procname	= "addip_noauth_enable",
242 		.data		= &init_net.sctp.addip_noauth,
243 		.maxlen		= sizeof(int),
244 		.mode		= 0644,
245 		.proc_handler	= proc_dointvec,
246 	},
247 	{
248 		.procname	= "prsctp_enable",
249 		.data		= &init_net.sctp.prsctp_enable,
250 		.maxlen		= sizeof(int),
251 		.mode		= 0644,
252 		.proc_handler	= proc_dointvec,
253 	},
254 	{
255 		.procname	= "auth_enable",
256 		.data		= &init_net.sctp.auth_enable,
257 		.maxlen		= sizeof(int),
258 		.mode		= 0644,
259 		.proc_handler	= proc_dointvec,
260 	},
261 	{
262 		.procname	= "addr_scope_policy",
263 		.data		= &init_net.sctp.scope_policy,
264 		.maxlen		= sizeof(int),
265 		.mode		= 0644,
266 		.proc_handler	= proc_dointvec_minmax,
267 		.extra1		= &zero,
268 		.extra2		= &addr_scope_max,
269 	},
270 	{
271 		.procname	= "rwnd_update_shift",
272 		.data		= &init_net.sctp.rwnd_upd_shift,
273 		.maxlen		= sizeof(int),
274 		.mode		= 0644,
275 		.proc_handler	= &proc_dointvec_minmax,
276 		.extra1		= &one,
277 		.extra2		= &rwnd_scale_max,
278 	},
279 	{
280 		.procname	= "max_autoclose",
281 		.data		= &init_net.sctp.max_autoclose,
282 		.maxlen		= sizeof(unsigned long),
283 		.mode		= 0644,
284 		.proc_handler	= &proc_doulongvec_minmax,
285 		.extra1		= &max_autoclose_min,
286 		.extra2		= &max_autoclose_max,
287 	},
288 
289 	{ /* sentinel */ }
290 };
291 
292 int sctp_sysctl_net_register(struct net *net)
293 {
294 	struct ctl_table *table;
295 	int i;
296 
297 	table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
298 	if (!table)
299 		return -ENOMEM;
300 
301 	for (i = 0; table[i].data; i++)
302 		table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
303 
304 	net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
305 	return 0;
306 }
307 
308 void sctp_sysctl_net_unregister(struct net *net)
309 {
310 	unregister_net_sysctl_table(net->sctp.sysctl_header);
311 }
312 
313 static struct ctl_table_header * sctp_sysctl_header;
314 
315 /* Sysctl registration.  */
316 void sctp_sysctl_register(void)
317 {
318 	sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table);
319 }
320 
321 /* Sysctl deregistration.  */
322 void sctp_sysctl_unregister(void)
323 {
324 	unregister_net_sysctl_table(sctp_sysctl_header);
325 }
326