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>
14 #include <linux/config.h>
16 #include <linux/sysctl.h>
18 #include <linux/netdevice.h>
19 #include <linux/string.h>
20 #include <net/neighbour.h>
23 #include <asm/uaccess.h>
26 #include <net/dn_dev.h>
27 #include <net/dn_route.h>
30 int decnet_debug_level
= 0;
31 int decnet_time_wait
= 30;
32 int decnet_dn_count
= 3;
33 int decnet_di_count
= 5;
34 int decnet_dr_count
= 5;
35 extern int decnet_dst_gc_interval
;
36 static int min_decnet_time_wait
[] = { 5 };
37 static int max_decnet_time_wait
[] = { 600 };
38 static int min_state_count
[] = { 1 };
39 static int max_state_count
[] = { NSP_MAXRXTSHIFT
};
40 static int min_decnet_dst_gc_interval
[] = { 1 };
41 static int max_decnet_dst_gc_interval
[] = { 60 };
42 static char node_name
[7] = "???";
44 static struct ctl_table_header
*dn_table_header
= NULL
;
49 #define ISNUM(x) (((x) >= '0') && ((x) <= '9'))
50 #define ISLOWER(x) (((x) >= 'a') && ((x) <= 'z'))
51 #define ISUPPER(x) (((x) >= 'A') && ((x) <= 'Z'))
52 #define ISALPHA(x) (ISLOWER(x) || ISUPPER(x))
53 #define INVALID_END_CHAR(x) (ISNUM(x) || ISALPHA(x))
56 * Simple routine to parse an ascii DECnet address
57 * into a network order address.
59 static int parse_addr(dn_address
*addr
, char *str
)
61 dn_address area
, node
;
63 while(*str
&& !ISNUM(*str
)) str
++;
68 area
= (*str
++ - '0');
71 area
+= (*str
++ - '0');
83 node
+= (*str
++ - '0');
87 node
+= (*str
++ - '0');
91 node
+= (*str
++ - '0');
94 if ((node
> 1023) || (area
> 63))
97 if (INVALID_END_CHAR(*str
))
100 *addr
= dn_htons((area
<< 10) | node
);
105 static char *node2str(int n
)
108 case DN_RT_INFO_ENDN
:
110 case DN_RT_INFO_L1RT
:
111 return "Level 1 Router\n";
112 case DN_RT_INFO_L2RT
:
113 return "Level 2 Router\n";
119 static int dn_node_type_strategy(ctl_table
*table
, int *name
, int nlen
,
120 void *oldval
, size_t *oldlenp
,
121 void *newval
, size_t newlen
,
127 if (oldval
&& oldlenp
) {
128 if (get_user(len
, oldlenp
))
131 if (len
!= sizeof(int))
133 if (put_user(decnet_node_type
, (int *)oldval
))
138 if (newval
&& newlen
) {
139 if (newlen
!= sizeof(int))
142 if (get_user(type
, (int *)newval
))
146 case DN_RT_INFO_ENDN
: /* EndNode */
147 #ifdef CONFIG_DECNET_ROUTER
148 case DN_RT_INFO_L1RT
: /* Level 1 Router */
149 case DN_RT_INFO_L2RT
: /* Level 2 Router */
156 if (decnet_node_type
!= type
) {
157 dn_dev_devices_off();
158 decnet_node_type
= type
;
165 static int dn_node_type_handler(ctl_table
*table
, int write
,
167 void *buffer
, size_t *lenp
)
169 char *s
= node2str(decnet_node_type
);
172 if (!*lenp
|| (filp
->f_pos
&& !write
)) {
178 char c
= *(char *)buffer
;
185 type
= DN_RT_INFO_ENDN
;
187 #ifdef CONFIG_DECNET_ROUTER
190 type
= DN_RT_INFO_L1RT
;
194 type
= DN_RT_INFO_L2RT
;
196 #endif /* CONFIG_DECNET_ROUTER */
201 if (decnet_node_type
!= type
) {
202 dn_dev_devices_off();
203 decnet_node_type
= type
;
212 if (len
> *lenp
) len
= *lenp
;
214 if (copy_to_user(buffer
, s
, len
))
223 static int dn_node_address_strategy(ctl_table
*table
, int *name
, int nlen
,
224 void *oldval
, size_t *oldlenp
,
225 void *newval
, size_t newlen
,
231 if (oldval
&& oldlenp
) {
232 if (get_user(len
, oldlenp
))
235 if (len
!= sizeof(unsigned short))
237 if (put_user(decnet_address
, (unsigned short *)oldval
))
241 if (newval
&& newlen
) {
242 if (newlen
!= sizeof(unsigned short))
244 if (get_user(addr
, (unsigned short *)newval
))
247 dn_dev_devices_off();
249 decnet_address
= addr
;
250 dn_dn2eth(decnet_ether_address
, decnet_address
);
257 static int dn_node_address_handler(ctl_table
*table
, int write
,
259 void *buffer
, size_t *lenp
)
261 char addr
[DN_ASCBUF_LEN
];
265 if (!*lenp
|| (filp
->f_pos
&& !write
)) {
271 int len
= (*lenp
< DN_ASCBUF_LEN
) ? *lenp
: (DN_ASCBUF_LEN
-1);
273 if (copy_from_user(addr
, buffer
, len
))
278 if (parse_addr(&dnaddr
, buffer
))
281 dn_dev_devices_off();
283 decnet_address
= dnaddr
;
284 dn_dn2eth(decnet_ether_address
, decnet_address
);
293 dn_addr2asc(dn_ntohs(decnet_address
), addr
);
297 if (len
> *lenp
) len
= *lenp
;
299 if (copy_to_user(buffer
, addr
, len
))
309 static int dn_def_dev_strategy(ctl_table
*table
, int *name
, int nlen
,
310 void *oldval
, size_t *oldlenp
,
311 void *newval
, size_t newlen
,
315 struct device
*dev
= decnet_default_device
;
321 if (oldval
&& oldlenp
) {
322 if (get_user(len
, oldlenp
))
326 strcpy(devname
, dev
->name
);
328 namel
= strlen(devname
) + 1;
329 if (len
> namel
) len
= namel
;
331 if (copy_to_user(oldval
, devname
, len
))
334 if (put_user(len
, oldlenp
))
339 if (newval
&& newlen
) {
343 if (copy_from_user(devname
, newval
, newlen
))
348 if ((dev
= dev_get(devname
)) == NULL
)
351 if (dev
->dn_ptr
== NULL
)
354 decnet_default_device
= dev
;
361 static int dn_def_dev_handler(ctl_table
*table
, int write
,
363 void *buffer
, size_t *lenp
)
366 struct device
*dev
= decnet_default_device
;
369 if (!*lenp
|| (filp
->f_pos
&& !write
)) {
379 if (copy_from_user(devname
, buffer
, *lenp
))
384 if ((dev
= dev_get(devname
)) == NULL
)
387 if (dev
->dn_ptr
== NULL
)
390 decnet_default_device
= dev
;
391 filp
->f_pos
+= *lenp
;
401 strcpy(devname
, dev
->name
);
402 len
= strlen(devname
);
403 devname
[len
++] = '\n';
405 if (len
> *lenp
) len
= *lenp
;
407 if (copy_to_user(buffer
, devname
, len
))
416 static ctl_table dn_table
[] = {
417 {NET_DECNET_NODE_TYPE
, "node_type", NULL
, 1, 0644, NULL
,
418 dn_node_type_handler
, dn_node_type_strategy
, NULL
,
420 {NET_DECNET_NODE_ADDRESS
, "node_address", NULL
, 7, 0644, NULL
,
421 dn_node_address_handler
, dn_node_address_strategy
, NULL
,
423 {NET_DECNET_NODE_NAME
, "node_name", node_name
, 7, 0644, NULL
,
424 &proc_dostring
, &sysctl_string
, NULL
, NULL
, NULL
},
425 {NET_DECNET_DEFAULT_DEVICE
, "default_device", NULL
, 16, 0644, NULL
,
426 dn_def_dev_handler
, dn_def_dev_strategy
, NULL
, NULL
, NULL
},
427 {NET_DECNET_TIME_WAIT
, "time_wait", &decnet_time_wait
,
429 NULL
, &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
430 &min_decnet_time_wait
, &max_decnet_time_wait
},
431 {NET_DECNET_DN_COUNT
, "dn_count", &decnet_dn_count
,
433 NULL
, &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
434 &min_state_count
, &max_state_count
},
435 {NET_DECNET_DI_COUNT
, "di_count", &decnet_di_count
,
437 NULL
, &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
438 &min_state_count
, &max_state_count
},
439 {NET_DECNET_DR_COUNT
, "dr_count", &decnet_dr_count
,
441 NULL
, &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
442 &min_state_count
, &max_state_count
},
443 {NET_DECNET_DST_GC_INTERVAL
, "dst_gc_interval", &decnet_dst_gc_interval
,
445 NULL
, &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
446 &min_decnet_dst_gc_interval
, &max_decnet_dst_gc_interval
},
447 {NET_DECNET_DEBUG_LEVEL
, "debug", &decnet_debug_level
,
449 NULL
, &proc_dointvec
, &sysctl_intvec
, NULL
,
454 static ctl_table dn_dir_table
[] = {
455 {NET_DECNET
, "decnet", NULL
, 0, 0555, dn_table
},
459 static ctl_table dn_root_table
[] = {
460 {CTL_NET
, "net", NULL
, 0, 0555, dn_dir_table
},
464 void dn_register_sysctl(void)
466 dn_table_header
= register_sysctl_table(dn_root_table
, 1);
469 void dn_unregister_sysctl(void)
471 unregister_sysctl_table(dn_table_header
);