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.
6 * DECnet sysctl support functions
8 * Author: Steve Whitehouse <SteveW@ACM.org>
12 * Steve Whitehouse - C99 changes and default device handling
13 * Steve Whitehouse - Memory buffer settings, like the tcp ones
17 #include <linux/sysctl.h>
19 #include <linux/netdevice.h>
20 #include <linux/string.h>
21 #include <net/neighbour.h>
25 #include <asm/uaccess.h>
28 #include <net/dn_dev.h>
29 #include <net/dn_route.h>
32 int decnet_debug_level
;
33 int decnet_time_wait
= 30;
34 int decnet_dn_count
= 1;
35 int decnet_di_count
= 3;
36 int decnet_dr_count
= 3;
37 int decnet_log_martians
= 1;
38 int decnet_no_fc_max_cwnd
= NSP_MIN_WINDOW
;
40 /* Reasonable defaults, I hope, based on tcp's defaults */
41 int sysctl_decnet_mem
[3] = { 768 << 3, 1024 << 3, 1536 << 3 };
42 int sysctl_decnet_wmem
[3] = { 4 * 1024, 16 * 1024, 128 * 1024 };
43 int sysctl_decnet_rmem
[3] = { 4 * 1024, 87380, 87380 * 2 };
46 extern int decnet_dst_gc_interval
;
47 static int min_decnet_time_wait
[] = { 5 };
48 static int max_decnet_time_wait
[] = { 600 };
49 static int min_state_count
[] = { 1 };
50 static int max_state_count
[] = { NSP_MAXRXTSHIFT
};
51 static int min_decnet_dst_gc_interval
[] = { 1 };
52 static int max_decnet_dst_gc_interval
[] = { 60 };
53 static int min_decnet_no_fc_max_cwnd
[] = { NSP_MIN_WINDOW
};
54 static int max_decnet_no_fc_max_cwnd
[] = { NSP_MAX_WINDOW
};
55 static char node_name
[7] = "???";
57 static struct ctl_table_header
*dn_table_header
= NULL
;
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))
68 static void strip_it(char *str
)
85 * Simple routine to parse an ascii DECnet address
86 * into a network order address.
88 static int parse_addr(__le16
*addr
, char *str
)
92 while(*str
&& !ISNUM(*str
)) str
++;
97 area
= (*str
++ - '0');
100 area
+= (*str
++ - '0');
112 node
+= (*str
++ - '0');
116 node
+= (*str
++ - '0');
120 node
+= (*str
++ - '0');
123 if ((node
> 1023) || (area
> 63))
126 if (INVALID_END_CHAR(*str
))
129 *addr
= cpu_to_le16((area
<< 10) | node
);
135 static int dn_node_address_strategy(ctl_table
*table
,
136 void __user
*oldval
, size_t __user
*oldlenp
,
137 void __user
*newval
, size_t newlen
)
142 if (oldval
&& oldlenp
) {
143 if (get_user(len
, oldlenp
))
146 if (len
!= sizeof(unsigned short))
148 if (put_user(decnet_address
, (__le16 __user
*)oldval
))
152 if (newval
&& newlen
) {
153 if (newlen
!= sizeof(unsigned short))
155 if (get_user(addr
, (__le16 __user
*)newval
))
158 dn_dev_devices_off();
160 decnet_address
= addr
;
167 static int dn_node_address_handler(ctl_table
*table
, int write
,
169 size_t *lenp
, loff_t
*ppos
)
171 char addr
[DN_ASCBUF_LEN
];
175 if (!*lenp
|| (*ppos
&& !write
)) {
181 len
= (*lenp
< DN_ASCBUF_LEN
) ? *lenp
: (DN_ASCBUF_LEN
-1);
183 if (copy_from_user(addr
, buffer
, len
))
189 if (parse_addr(&dnaddr
, addr
))
192 dn_dev_devices_off();
194 decnet_address
= dnaddr
;
203 dn_addr2asc(le16_to_cpu(decnet_address
), addr
);
207 if (len
> *lenp
) len
= *lenp
;
209 if (copy_to_user(buffer
, addr
, len
))
219 static int dn_def_dev_strategy(ctl_table
*table
,
220 void __user
*oldval
, size_t __user
*oldlenp
,
221 void __user
*newval
, size_t newlen
)
224 struct net_device
*dev
;
231 if (oldval
&& oldlenp
) {
232 if (get_user(len
, oldlenp
))
235 dev
= dn_dev_get_default();
237 strcpy(devname
, dev
->name
);
241 namel
= strlen(devname
) + 1;
242 if (len
> namel
) len
= namel
;
244 if (copy_to_user(oldval
, devname
, len
))
247 if (put_user(len
, oldlenp
))
252 if (newval
&& newlen
) {
256 if (copy_from_user(devname
, newval
, newlen
))
261 dev
= dev_get_by_name(&init_net
, devname
);
266 if (dev
->dn_ptr
!= NULL
)
267 rv
= dn_dev_set_default(dev
, 1);
276 static int dn_def_dev_handler(ctl_table
*table
, int write
,
278 size_t *lenp
, loff_t
*ppos
)
281 struct net_device
*dev
;
284 if (!*lenp
|| (*ppos
&& !write
)) {
293 if (copy_from_user(devname
, buffer
, *lenp
))
299 dev
= dev_get_by_name(&init_net
, devname
);
303 if (dev
->dn_ptr
== NULL
) {
308 if (dn_dev_set_default(dev
, 1)) {
317 dev
= dn_dev_get_default();
323 strcpy(devname
, dev
->name
);
325 len
= strlen(devname
);
326 devname
[len
++] = '\n';
328 if (len
> *lenp
) len
= *lenp
;
330 if (copy_to_user(buffer
, devname
, len
))
339 static ctl_table dn_table
[] = {
341 .ctl_name
= NET_DECNET_NODE_ADDRESS
,
342 .procname
= "node_address",
345 .proc_handler
= dn_node_address_handler
,
346 .strategy
= dn_node_address_strategy
,
349 .ctl_name
= NET_DECNET_NODE_NAME
,
350 .procname
= "node_name",
354 .proc_handler
= proc_dostring
,
355 .strategy
= sysctl_string
,
358 .ctl_name
= NET_DECNET_DEFAULT_DEVICE
,
359 .procname
= "default_device",
362 .proc_handler
= dn_def_dev_handler
,
363 .strategy
= dn_def_dev_strategy
,
366 .ctl_name
= NET_DECNET_TIME_WAIT
,
367 .procname
= "time_wait",
368 .data
= &decnet_time_wait
,
369 .maxlen
= sizeof(int),
371 .proc_handler
= proc_dointvec_minmax
,
372 .strategy
= sysctl_intvec
,
373 .extra1
= &min_decnet_time_wait
,
374 .extra2
= &max_decnet_time_wait
377 .ctl_name
= NET_DECNET_DN_COUNT
,
378 .procname
= "dn_count",
379 .data
= &decnet_dn_count
,
380 .maxlen
= sizeof(int),
382 .proc_handler
= proc_dointvec_minmax
,
383 .strategy
= sysctl_intvec
,
384 .extra1
= &min_state_count
,
385 .extra2
= &max_state_count
388 .ctl_name
= NET_DECNET_DI_COUNT
,
389 .procname
= "di_count",
390 .data
= &decnet_di_count
,
391 .maxlen
= sizeof(int),
393 .proc_handler
= proc_dointvec_minmax
,
394 .strategy
= sysctl_intvec
,
395 .extra1
= &min_state_count
,
396 .extra2
= &max_state_count
399 .ctl_name
= NET_DECNET_DR_COUNT
,
400 .procname
= "dr_count",
401 .data
= &decnet_dr_count
,
402 .maxlen
= sizeof(int),
404 .proc_handler
= proc_dointvec_minmax
,
405 .strategy
= sysctl_intvec
,
406 .extra1
= &min_state_count
,
407 .extra2
= &max_state_count
410 .ctl_name
= NET_DECNET_DST_GC_INTERVAL
,
411 .procname
= "dst_gc_interval",
412 .data
= &decnet_dst_gc_interval
,
413 .maxlen
= sizeof(int),
415 .proc_handler
= proc_dointvec_minmax
,
416 .strategy
= sysctl_intvec
,
417 .extra1
= &min_decnet_dst_gc_interval
,
418 .extra2
= &max_decnet_dst_gc_interval
421 .ctl_name
= NET_DECNET_NO_FC_MAX_CWND
,
422 .procname
= "no_fc_max_cwnd",
423 .data
= &decnet_no_fc_max_cwnd
,
424 .maxlen
= sizeof(int),
426 .proc_handler
= proc_dointvec_minmax
,
427 .strategy
= sysctl_intvec
,
428 .extra1
= &min_decnet_no_fc_max_cwnd
,
429 .extra2
= &max_decnet_no_fc_max_cwnd
432 .ctl_name
= NET_DECNET_MEM
,
433 .procname
= "decnet_mem",
434 .data
= &sysctl_decnet_mem
,
435 .maxlen
= sizeof(sysctl_decnet_mem
),
437 .proc_handler
= proc_dointvec
,
438 .strategy
= sysctl_intvec
,
441 .ctl_name
= NET_DECNET_RMEM
,
442 .procname
= "decnet_rmem",
443 .data
= &sysctl_decnet_rmem
,
444 .maxlen
= sizeof(sysctl_decnet_rmem
),
446 .proc_handler
= proc_dointvec
,
447 .strategy
= sysctl_intvec
,
450 .ctl_name
= NET_DECNET_WMEM
,
451 .procname
= "decnet_wmem",
452 .data
= &sysctl_decnet_wmem
,
453 .maxlen
= sizeof(sysctl_decnet_wmem
),
455 .proc_handler
= proc_dointvec
,
456 .strategy
= sysctl_intvec
,
459 .ctl_name
= NET_DECNET_DEBUG_LEVEL
,
461 .data
= &decnet_debug_level
,
462 .maxlen
= sizeof(int),
464 .proc_handler
= proc_dointvec
,
465 .strategy
= sysctl_intvec
,
470 static struct ctl_path dn_path
[] = {
471 { .procname
= "net", .ctl_name
= CTL_NET
, },
472 { .procname
= "decnet", .ctl_name
= NET_DECNET
, },
476 void dn_register_sysctl(void)
478 dn_table_header
= register_sysctl_paths(dn_path
, dn_table
);
481 void dn_unregister_sysctl(void)
483 unregister_sysctl_table(dn_table_header
);
486 #else /* CONFIG_SYSCTL */
487 void dn_unregister_sysctl(void)
490 void dn_register_sysctl(void)