blob: 26b0ab1e9f560b75d046c687fabf27dfed1b4f48 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * DECnet An implementation of the DECnet protocol suite for the LINUX
3 * operating system. DECnet is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * DECnet sysctl support functions
7 *
8 * Author: Steve Whitehouse <SteveW@ACM.org>
9 *
10 *
11 * Changes:
12 * Steve Whitehouse - C99 changes and default device handling
Steven Whitehouse1f12bcc2005-12-05 13:42:06 -080013 * Steve Whitehouse - Memory buffer settings, like the tcp ones
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 *
15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/mm.h>
17#include <linux/sysctl.h>
18#include <linux/fs.h>
19#include <linux/netdevice.h>
20#include <linux/string.h>
21#include <net/neighbour.h>
22#include <net/dst.h>
23#include <net/flow.h>
24
25#include <asm/uaccess.h>
26
27#include <net/dn.h>
28#include <net/dn_dev.h>
29#include <net/dn_route.h>
30
31
32int decnet_debug_level;
33int decnet_time_wait = 30;
34int decnet_dn_count = 1;
35int decnet_di_count = 3;
36int decnet_dr_count = 3;
37int decnet_log_martians = 1;
38int decnet_no_fc_max_cwnd = NSP_MIN_WINDOW;
39
Steven Whitehouse1f12bcc2005-12-05 13:42:06 -080040/* Reasonable defaults, I hope, based on tcp's defaults */
41int sysctl_decnet_mem[3] = { 768 << 3, 1024 << 3, 1536 << 3 };
42int sysctl_decnet_wmem[3] = { 4 * 1024, 16 * 1024, 128 * 1024 };
43int sysctl_decnet_rmem[3] = { 4 * 1024, 87380, 87380 * 2 };
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#ifdef CONFIG_SYSCTL
46extern int decnet_dst_gc_interval;
47static int min_decnet_time_wait[] = { 5 };
48static int max_decnet_time_wait[] = { 600 };
49static int min_state_count[] = { 1 };
50static int max_state_count[] = { NSP_MAXRXTSHIFT };
51static int min_decnet_dst_gc_interval[] = { 1 };
52static int max_decnet_dst_gc_interval[] = { 60 };
53static int min_decnet_no_fc_max_cwnd[] = { NSP_MIN_WINDOW };
54static int max_decnet_no_fc_max_cwnd[] = { NSP_MAX_WINDOW };
55static char node_name[7] = "???";
56
57static struct ctl_table_header *dn_table_header = NULL;
58
59/*
60 * ctype.h :-)
61 */
62#define ISNUM(x) (((x) >= '0') && ((x) <= '9'))
63#define ISLOWER(x) (((x) >= 'a') && ((x) <= 'z'))
64#define ISUPPER(x) (((x) >= 'A') && ((x) <= 'Z'))
65#define ISALPHA(x) (ISLOWER(x) || ISUPPER(x))
66#define INVALID_END_CHAR(x) (ISNUM(x) || ISALPHA(x))
67
68static void strip_it(char *str)
69{
70 for(;;) {
71 switch(*str) {
72 case ' ':
73 case '\n':
74 case '\r':
75 case ':':
76 *str = 0;
77 case 0:
78 return;
79 }
80 str++;
81 }
82}
83
84/*
85 * Simple routine to parse an ascii DECnet address
86 * into a network order address.
87 */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080088static int parse_addr(__le16 *addr, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080090 __u16 area, node;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 while(*str && !ISNUM(*str)) str++;
93
94 if (*str == 0)
95 return -1;
96
97 area = (*str++ - '0');
98 if (ISNUM(*str)) {
99 area *= 10;
100 area += (*str++ - '0');
101 }
102
103 if (*str++ != '.')
104 return -1;
105
106 if (!ISNUM(*str))
107 return -1;
108
109 node = *str++ - '0';
110 if (ISNUM(*str)) {
111 node *= 10;
112 node += (*str++ - '0');
113 }
114 if (ISNUM(*str)) {
115 node *= 10;
116 node += (*str++ - '0');
117 }
118 if (ISNUM(*str)) {
119 node *= 10;
120 node += (*str++ - '0');
121 }
122
123 if ((node > 1023) || (area > 63))
124 return -1;
125
126 if (INVALID_END_CHAR(*str))
127 return -1;
128
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800129 *addr = cpu_to_le16((area << 10) | node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 return 0;
132}
133
134
Alexey Dobriyanf221e722008-10-15 22:04:23 -0700135static int dn_node_address_strategy(ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800137 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
139 size_t len;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800140 __le16 addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 if (oldval && oldlenp) {
143 if (get_user(len, oldlenp))
144 return -EFAULT;
145 if (len) {
146 if (len != sizeof(unsigned short))
147 return -EINVAL;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800148 if (put_user(decnet_address, (__le16 __user *)oldval))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 return -EFAULT;
150 }
151 }
152 if (newval && newlen) {
153 if (newlen != sizeof(unsigned short))
154 return -EINVAL;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800155 if (get_user(addr, (__le16 __user *)newval))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 return -EFAULT;
157
158 dn_dev_devices_off();
159
160 decnet_address = addr;
161
162 dn_dev_devices_on();
163 }
164 return 0;
165}
166
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900167static int dn_node_address_handler(ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 void __user *buffer,
169 size_t *lenp, loff_t *ppos)
170{
171 char addr[DN_ASCBUF_LEN];
172 size_t len;
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800173 __le16 dnaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 if (!*lenp || (*ppos && !write)) {
176 *lenp = 0;
177 return 0;
178 }
179
180 if (write) {
Hannes Edere57c6242009-02-25 10:32:39 +0000181 len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 if (copy_from_user(addr, buffer, len))
184 return -EFAULT;
185
186 addr[len] = 0;
187 strip_it(addr);
188
189 if (parse_addr(&dnaddr, addr))
190 return -EINVAL;
191
192 dn_dev_devices_off();
193
194 decnet_address = dnaddr;
195
196 dn_dev_devices_on();
197
198 *ppos += len;
199
200 return 0;
201 }
202
Harvey Harrisonc4106aa2008-11-27 00:12:47 -0800203 dn_addr2asc(le16_to_cpu(decnet_address), addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 len = strlen(addr);
205 addr[len++] = '\n';
206
207 if (len > *lenp) len = *lenp;
208
209 if (copy_to_user(buffer, addr, len))
210 return -EFAULT;
211
212 *lenp = len;
213 *ppos += len;
214
215 return 0;
216}
217
218
Alexey Dobriyanf221e722008-10-15 22:04:23 -0700219static int dn_def_dev_strategy(ctl_table *table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 void __user *oldval, size_t __user *oldlenp,
Alexey Dobriyan1f29bcd2006-12-10 02:19:10 -0800221 void __user *newval, size_t newlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 size_t len;
224 struct net_device *dev;
225 char devname[17];
226 size_t namel;
227 int rv = 0;
228
229 devname[0] = 0;
230
231 if (oldval && oldlenp) {
232 if (get_user(len, oldlenp))
233 return -EFAULT;
234 if (len) {
235 dev = dn_dev_get_default();
236 if (dev) {
237 strcpy(devname, dev->name);
238 dev_put(dev);
239 }
240
241 namel = strlen(devname) + 1;
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900242 if (len > namel) len = namel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 if (copy_to_user(oldval, devname, len))
245 return -EFAULT;
246
247 if (put_user(len, oldlenp))
248 return -EFAULT;
249 }
250 }
251
252 if (newval && newlen) {
253 if (newlen > 16)
254 return -E2BIG;
255
256 if (copy_from_user(devname, newval, newlen))
257 return -EFAULT;
258
259 devname[newlen] = 0;
260
Eric W. Biederman881d9662007-09-17 11:56:21 -0700261 dev = dev_get_by_name(&init_net, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 if (dev == NULL)
263 return -ENODEV;
264
265 rv = -ENODEV;
266 if (dev->dn_ptr != NULL) {
267 rv = dn_dev_set_default(dev, 1);
268 if (rv)
269 dev_put(dev);
270 }
271 }
272
273 return rv;
274}
275
276
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900277static int dn_def_dev_handler(ctl_table *table, int write,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 void __user *buffer,
279 size_t *lenp, loff_t *ppos)
280{
281 size_t len;
282 struct net_device *dev;
283 char devname[17];
284
285 if (!*lenp || (*ppos && !write)) {
286 *lenp = 0;
287 return 0;
288 }
289
290 if (write) {
291 if (*lenp > 16)
292 return -E2BIG;
293
294 if (copy_from_user(devname, buffer, *lenp))
295 return -EFAULT;
296
297 devname[*lenp] = 0;
298 strip_it(devname);
299
Eric W. Biederman881d9662007-09-17 11:56:21 -0700300 dev = dev_get_by_name(&init_net, devname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (dev == NULL)
302 return -ENODEV;
303
304 if (dev->dn_ptr == NULL) {
305 dev_put(dev);
306 return -ENODEV;
307 }
308
309 if (dn_dev_set_default(dev, 1)) {
310 dev_put(dev);
311 return -ENODEV;
312 }
313 *ppos += *lenp;
314
315 return 0;
316 }
317
318 dev = dn_dev_get_default();
319 if (dev == NULL) {
320 *lenp = 0;
321 return 0;
322 }
323
324 strcpy(devname, dev->name);
325 dev_put(dev);
326 len = strlen(devname);
327 devname[len++] = '\n';
328
329 if (len > *lenp) len = *lenp;
330
331 if (copy_to_user(buffer, devname, len))
332 return -EFAULT;
333
334 *lenp = len;
335 *ppos += len;
336
337 return 0;
338}
339
340static ctl_table dn_table[] = {
341 {
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900342 .ctl_name = NET_DECNET_NODE_ADDRESS,
343 .procname = "node_address",
344 .maxlen = 7,
345 .mode = 0644,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 .proc_handler = dn_node_address_handler,
347 .strategy = dn_node_address_strategy,
348 },
349 {
350 .ctl_name = NET_DECNET_NODE_NAME,
351 .procname = "node_name",
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900352 .data = node_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 .maxlen = 7,
354 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800355 .proc_handler = proc_dostring,
356 .strategy = sysctl_string,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 },
358 {
359 .ctl_name = NET_DECNET_DEFAULT_DEVICE,
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900360 .procname = "default_device",
361 .maxlen = 16,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 .mode = 0644,
363 .proc_handler = dn_def_dev_handler,
364 .strategy = dn_def_dev_strategy,
365 },
366 {
367 .ctl_name = NET_DECNET_TIME_WAIT,
368 .procname = "time_wait",
369 .data = &decnet_time_wait,
370 .maxlen = sizeof(int),
371 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800372 .proc_handler = proc_dointvec_minmax,
373 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 .extra1 = &min_decnet_time_wait,
375 .extra2 = &max_decnet_time_wait
376 },
377 {
378 .ctl_name = NET_DECNET_DN_COUNT,
379 .procname = "dn_count",
380 .data = &decnet_dn_count,
381 .maxlen = sizeof(int),
382 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800383 .proc_handler = proc_dointvec_minmax,
384 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 .extra1 = &min_state_count,
386 .extra2 = &max_state_count
387 },
388 {
389 .ctl_name = NET_DECNET_DI_COUNT,
390 .procname = "di_count",
391 .data = &decnet_di_count,
392 .maxlen = sizeof(int),
393 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800394 .proc_handler = proc_dointvec_minmax,
395 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 .extra1 = &min_state_count,
397 .extra2 = &max_state_count
398 },
399 {
400 .ctl_name = NET_DECNET_DR_COUNT,
401 .procname = "dr_count",
402 .data = &decnet_dr_count,
403 .maxlen = sizeof(int),
404 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800405 .proc_handler = proc_dointvec_minmax,
406 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 .extra1 = &min_state_count,
408 .extra2 = &max_state_count
409 },
410 {
411 .ctl_name = NET_DECNET_DST_GC_INTERVAL,
412 .procname = "dst_gc_interval",
413 .data = &decnet_dst_gc_interval,
414 .maxlen = sizeof(int),
415 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800416 .proc_handler = proc_dointvec_minmax,
417 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 .extra1 = &min_decnet_dst_gc_interval,
419 .extra2 = &max_decnet_dst_gc_interval
420 },
421 {
422 .ctl_name = NET_DECNET_NO_FC_MAX_CWND,
423 .procname = "no_fc_max_cwnd",
424 .data = &decnet_no_fc_max_cwnd,
425 .maxlen = sizeof(int),
426 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800427 .proc_handler = proc_dointvec_minmax,
428 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 .extra1 = &min_decnet_no_fc_max_cwnd,
430 .extra2 = &max_decnet_no_fc_max_cwnd
431 },
Steven Whitehouse1f12bcc2005-12-05 13:42:06 -0800432 {
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900433 .ctl_name = NET_DECNET_MEM,
434 .procname = "decnet_mem",
435 .data = &sysctl_decnet_mem,
436 .maxlen = sizeof(sysctl_decnet_mem),
437 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800438 .proc_handler = proc_dointvec,
439 .strategy = sysctl_intvec,
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900440 },
441 {
442 .ctl_name = NET_DECNET_RMEM,
443 .procname = "decnet_rmem",
444 .data = &sysctl_decnet_rmem,
445 .maxlen = sizeof(sysctl_decnet_rmem),
446 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800447 .proc_handler = proc_dointvec,
448 .strategy = sysctl_intvec,
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900449 },
450 {
451 .ctl_name = NET_DECNET_WMEM,
452 .procname = "decnet_wmem",
453 .data = &sysctl_decnet_wmem,
454 .maxlen = sizeof(sysctl_decnet_wmem),
455 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800456 .proc_handler = proc_dointvec,
457 .strategy = sysctl_intvec,
YOSHIFUJI Hideaki429eb0f2007-02-09 23:24:40 +0900458 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 {
460 .ctl_name = NET_DECNET_DEBUG_LEVEL,
461 .procname = "debug",
462 .data = &decnet_debug_level,
463 .maxlen = sizeof(int),
464 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800465 .proc_handler = proc_dointvec,
466 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 },
468 {0}
469};
470
Pavel Emelyanov3151a9a2008-01-09 00:31:49 -0800471static struct ctl_path dn_path[] = {
472 { .procname = "net", .ctl_name = CTL_NET, },
473 { .procname = "decnet", .ctl_name = NET_DECNET, },
474 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475};
476
477void dn_register_sysctl(void)
478{
Pavel Emelyanov3151a9a2008-01-09 00:31:49 -0800479 dn_table_header = register_sysctl_paths(dn_path, dn_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480}
481
482void dn_unregister_sysctl(void)
483{
484 unregister_sysctl_table(dn_table_header);
485}
486
487#else /* CONFIG_SYSCTL */
488void dn_unregister_sysctl(void)
489{
490}
491void dn_register_sysctl(void)
492{
493}
494
495#endif