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
16 #include <linux/config.h>
18 #include <linux/sysctl.h>
20 #include <linux/netdevice.h>
21 #include <linux/string.h>
22 #include <net/neighbour.h>
26 #include <asm/uaccess.h>
29 #include <net/dn_dev.h>
30 #include <net/dn_route.h>
33 int decnet_debug_level
;
34 int decnet_time_wait
= 30;
35 int decnet_dn_count
= 1;
36 int decnet_di_count
= 3;
37 int decnet_dr_count
= 3;
38 int decnet_log_martians
= 1;
39 int decnet_no_fc_max_cwnd
= NSP_MIN_WINDOW
;
41 /* Reasonable defaults, I hope, based on tcp's defaults */
42 int sysctl_decnet_mem
[3] = { 768 << 3, 1024 << 3, 1536 << 3 };
43 int sysctl_decnet_wmem
[3] = { 4 * 1024, 16 * 1024, 128 * 1024 };
44 int sysctl_decnet_rmem
[3] = { 4 * 1024, 87380, 87380 * 2 };
47 extern int decnet_dst_gc_interval
;
48 static int min_decnet_time_wait
[] = { 5 };
49 static int max_decnet_time_wait
[] = { 600 };
50 static int min_state_count
[] = { 1 };
51 static int max_state_count
[] = { NSP_MAXRXTSHIFT
};
52 static int min_decnet_dst_gc_interval
[] = { 1 };
53 static int max_decnet_dst_gc_interval
[] = { 60 };
54 static int min_decnet_no_fc_max_cwnd
[] = { NSP_MIN_WINDOW
};
55 static int max_decnet_no_fc_max_cwnd
[] = { NSP_MAX_WINDOW
};
56 static char node_name
[7] = "???";
58 static struct ctl_table_header
*dn_table_header
= NULL
;
63 #define ISNUM(x) (((x) >= '0') && ((x) <= '9'))
64 #define ISLOWER(x) (((x) >= 'a') && ((x) <= 'z'))
65 #define ISUPPER(x) (((x) >= 'A') && ((x) <= 'Z'))
66 #define ISALPHA(x) (ISLOWER(x) || ISUPPER(x))
67 #define INVALID_END_CHAR(x) (ISNUM(x) || ISALPHA(x))
69 static void strip_it(char *str
)
86 * Simple routine to parse an ascii DECnet address
87 * into a network order address.
89 static int parse_addr(__le16
*addr
, char *str
)
93 while(*str
&& !ISNUM(*str
)) str
++;
98 area
= (*str
++ - '0');
101 area
+= (*str
++ - '0');
113 node
+= (*str
++ - '0');
117 node
+= (*str
++ - '0');
121 node
+= (*str
++ - '0');
124 if ((node
> 1023) || (area
> 63))
127 if (INVALID_END_CHAR(*str
))
130 *addr
= dn_htons((area
<< 10) | node
);
136 static int dn_node_address_strategy(ctl_table
*table
, int __user
*name
, int nlen
,
137 void __user
*oldval
, size_t __user
*oldlenp
,
138 void __user
*newval
, size_t newlen
,
144 if (oldval
&& oldlenp
) {
145 if (get_user(len
, oldlenp
))
148 if (len
!= sizeof(unsigned short))
150 if (put_user(decnet_address
, (__le16 __user
*)oldval
))
154 if (newval
&& newlen
) {
155 if (newlen
!= sizeof(unsigned short))
157 if (get_user(addr
, (__le16 __user
*)newval
))
160 dn_dev_devices_off();
162 decnet_address
= addr
;
169 static int dn_node_address_handler(ctl_table
*table
, int write
,
172 size_t *lenp
, loff_t
*ppos
)
174 char addr
[DN_ASCBUF_LEN
];
178 if (!*lenp
|| (*ppos
&& !write
)) {
184 int len
= (*lenp
< DN_ASCBUF_LEN
) ? *lenp
: (DN_ASCBUF_LEN
-1);
186 if (copy_from_user(addr
, buffer
, len
))
192 if (parse_addr(&dnaddr
, addr
))
195 dn_dev_devices_off();
197 decnet_address
= dnaddr
;
206 dn_addr2asc(dn_ntohs(decnet_address
), addr
);
210 if (len
> *lenp
) len
= *lenp
;
212 if (copy_to_user(buffer
, addr
, len
))
222 static int dn_def_dev_strategy(ctl_table
*table
, int __user
*name
, int nlen
,
223 void __user
*oldval
, size_t __user
*oldlenp
,
224 void __user
*newval
, size_t newlen
,
228 struct net_device
*dev
;
235 if (oldval
&& oldlenp
) {
236 if (get_user(len
, oldlenp
))
239 dev
= dn_dev_get_default();
241 strcpy(devname
, dev
->name
);
245 namel
= strlen(devname
) + 1;
246 if (len
> namel
) len
= namel
;
248 if (copy_to_user(oldval
, devname
, len
))
251 if (put_user(len
, oldlenp
))
256 if (newval
&& newlen
) {
260 if (copy_from_user(devname
, newval
, newlen
))
265 dev
= dev_get_by_name(devname
);
270 if (dev
->dn_ptr
!= NULL
) {
271 rv
= dn_dev_set_default(dev
, 1);
281 static int dn_def_dev_handler(ctl_table
*table
, int write
,
284 size_t *lenp
, loff_t
*ppos
)
287 struct net_device
*dev
;
290 if (!*lenp
|| (*ppos
&& !write
)) {
299 if (copy_from_user(devname
, buffer
, *lenp
))
305 dev
= dev_get_by_name(devname
);
309 if (dev
->dn_ptr
== NULL
) {
314 if (dn_dev_set_default(dev
, 1)) {
323 dev
= dn_dev_get_default();
329 strcpy(devname
, dev
->name
);
331 len
= strlen(devname
);
332 devname
[len
++] = '\n';
334 if (len
> *lenp
) len
= *lenp
;
336 if (copy_to_user(buffer
, devname
, len
))
345 static ctl_table dn_table
[] = {
347 .ctl_name
= NET_DECNET_NODE_ADDRESS
,
348 .procname
= "node_address",
351 .proc_handler
= dn_node_address_handler
,
352 .strategy
= dn_node_address_strategy
,
355 .ctl_name
= NET_DECNET_NODE_NAME
,
356 .procname
= "node_name",
360 .proc_handler
= &proc_dostring
,
361 .strategy
= &sysctl_string
,
364 .ctl_name
= NET_DECNET_DEFAULT_DEVICE
,
365 .procname
= "default_device",
368 .proc_handler
= dn_def_dev_handler
,
369 .strategy
= dn_def_dev_strategy
,
372 .ctl_name
= NET_DECNET_TIME_WAIT
,
373 .procname
= "time_wait",
374 .data
= &decnet_time_wait
,
375 .maxlen
= sizeof(int),
377 .proc_handler
= &proc_dointvec_minmax
,
378 .strategy
= &sysctl_intvec
,
379 .extra1
= &min_decnet_time_wait
,
380 .extra2
= &max_decnet_time_wait
383 .ctl_name
= NET_DECNET_DN_COUNT
,
384 .procname
= "dn_count",
385 .data
= &decnet_dn_count
,
386 .maxlen
= sizeof(int),
388 .proc_handler
= &proc_dointvec_minmax
,
389 .strategy
= &sysctl_intvec
,
390 .extra1
= &min_state_count
,
391 .extra2
= &max_state_count
394 .ctl_name
= NET_DECNET_DI_COUNT
,
395 .procname
= "di_count",
396 .data
= &decnet_di_count
,
397 .maxlen
= sizeof(int),
399 .proc_handler
= &proc_dointvec_minmax
,
400 .strategy
= &sysctl_intvec
,
401 .extra1
= &min_state_count
,
402 .extra2
= &max_state_count
405 .ctl_name
= NET_DECNET_DR_COUNT
,
406 .procname
= "dr_count",
407 .data
= &decnet_dr_count
,
408 .maxlen
= sizeof(int),
410 .proc_handler
= &proc_dointvec_minmax
,
411 .strategy
= &sysctl_intvec
,
412 .extra1
= &min_state_count
,
413 .extra2
= &max_state_count
416 .ctl_name
= NET_DECNET_DST_GC_INTERVAL
,
417 .procname
= "dst_gc_interval",
418 .data
= &decnet_dst_gc_interval
,
419 .maxlen
= sizeof(int),
421 .proc_handler
= &proc_dointvec_minmax
,
422 .strategy
= &sysctl_intvec
,
423 .extra1
= &min_decnet_dst_gc_interval
,
424 .extra2
= &max_decnet_dst_gc_interval
427 .ctl_name
= NET_DECNET_NO_FC_MAX_CWND
,
428 .procname
= "no_fc_max_cwnd",
429 .data
= &decnet_no_fc_max_cwnd
,
430 .maxlen
= sizeof(int),
432 .proc_handler
= &proc_dointvec_minmax
,
433 .strategy
= &sysctl_intvec
,
434 .extra1
= &min_decnet_no_fc_max_cwnd
,
435 .extra2
= &max_decnet_no_fc_max_cwnd
438 .ctl_name
= NET_DECNET_MEM
,
439 .procname
= "decnet_mem",
440 .data
= &sysctl_decnet_mem
,
441 .maxlen
= sizeof(sysctl_decnet_mem
),
443 .proc_handler
= &proc_dointvec
,
444 .strategy
= &sysctl_intvec
,
447 .ctl_name
= NET_DECNET_RMEM
,
448 .procname
= "decnet_rmem",
449 .data
= &sysctl_decnet_rmem
,
450 .maxlen
= sizeof(sysctl_decnet_rmem
),
452 .proc_handler
= &proc_dointvec
,
453 .strategy
= &sysctl_intvec
,
456 .ctl_name
= NET_DECNET_WMEM
,
457 .procname
= "decnet_wmem",
458 .data
= &sysctl_decnet_wmem
,
459 .maxlen
= sizeof(sysctl_decnet_wmem
),
461 .proc_handler
= &proc_dointvec
,
462 .strategy
= &sysctl_intvec
,
465 .ctl_name
= NET_DECNET_DEBUG_LEVEL
,
467 .data
= &decnet_debug_level
,
468 .maxlen
= sizeof(int),
470 .proc_handler
= &proc_dointvec
,
471 .strategy
= &sysctl_intvec
,
476 static ctl_table dn_dir_table
[] = {
478 .ctl_name
= NET_DECNET
,
479 .procname
= "decnet",
485 static ctl_table dn_root_table
[] = {
490 .child
= dn_dir_table
495 void dn_register_sysctl(void)
497 dn_table_header
= register_sysctl_table(dn_root_table
, 1);
500 void dn_unregister_sysctl(void)
502 unregister_sysctl_table(dn_table_header
);
505 #else /* CONFIG_SYSCTL */
506 void dn_unregister_sysctl(void)
509 void dn_register_sysctl(void)