Import 2.3.4pre2
[davej-history.git] / net / decnet / sysctl_net_decnet.c
blob134ac585b99eee6e6f70edd274034f1f6039560b
1 /*
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>
11 * Changes:
14 #include <linux/config.h>
15 #include <linux/mm.h>
16 #include <linux/sysctl.h>
17 #include <linux/fs.h>
18 #include <linux/netdevice.h>
19 #include <linux/string.h>
20 #include <net/neighbour.h>
21 #include <net/dst.h>
23 #include <asm/uaccess.h>
25 #include <net/dn.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;
47 * ctype.h :-)
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++;
65 if (*str == 0)
66 return -1;
68 area = (*str++ - '0');
69 if (ISNUM(*str)) {
70 area *= 10;
71 area += (*str++ - '0');
74 if (*str++ != '.')
75 return -1;
77 if (!ISNUM(*str))
78 return -1;
80 node = *str++ - '0';
81 if (ISNUM(*str)) {
82 node *= 10;
83 node += (*str++ - '0');
85 if (ISNUM(*str)) {
86 node *= 10;
87 node += (*str++ - '0');
89 if (ISNUM(*str)) {
90 node *= 10;
91 node += (*str++ - '0');
94 if ((node > 1023) || (area > 63))
95 return -1;
97 if (INVALID_END_CHAR(*str))
98 return -1;
100 *addr = dn_htons((area << 10) | node);
102 return 0;
105 static char *node2str(int n)
107 switch(n) {
108 case DN_RT_INFO_ENDN:
109 return "EndNode\n";
110 case DN_RT_INFO_L1RT:
111 return "Level 1 Router\n";
112 case DN_RT_INFO_L2RT:
113 return "Level 2 Router\n";
116 return "Unknown\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,
122 void **context)
124 int len;
125 int type;
127 if (oldval && oldlenp) {
128 if (get_user(len, oldlenp))
129 return -EFAULT;
130 if (len) {
131 if (len != sizeof(int))
132 return -EINVAL;
133 if (put_user(decnet_node_type, (int *)oldval))
134 return -EFAULT;
138 if (newval && newlen) {
139 if (newlen != sizeof(int))
140 return -EINVAL;
142 if (get_user(type, (int *)newval))
143 return -EFAULT;
145 switch(type) {
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 */
150 #endif
151 break;
152 default:
153 return -EINVAL;
156 if (decnet_node_type != type) {
157 dn_dev_devices_off();
158 decnet_node_type = type;
159 dn_dev_devices_on();
162 return 0;
165 static int dn_node_type_handler(ctl_table *table, int write,
166 struct file * filp,
167 void *buffer, size_t *lenp)
169 char *s = node2str(decnet_node_type);
170 int len = strlen(s);
172 if (!*lenp || (filp->f_pos && !write)) {
173 *lenp = 0;
174 return 0;
177 if (write) {
178 char c = *(char *)buffer;
179 int type = 0;
181 switch(c) {
182 case 'e':
183 case 'E':
184 case '0':
185 type = DN_RT_INFO_ENDN;
186 break;
187 #ifdef CONFIG_DECNET_ROUTER
188 case 'r':
189 case '1':
190 type = DN_RT_INFO_L1RT;
191 break;
192 case 'R':
193 case '2':
194 type = DN_RT_INFO_L2RT;
195 break;
196 #endif /* CONFIG_DECNET_ROUTER */
197 default:
198 return -EINVAL;
201 if (decnet_node_type != type) {
202 dn_dev_devices_off();
203 decnet_node_type = type;
204 dn_dev_devices_on();
207 filp->f_pos += 1;
209 return 0;
212 if (len > *lenp) len = *lenp;
214 if (copy_to_user(buffer, s, len))
215 return -EFAULT;
217 *lenp = len;
218 filp->f_pos += len;
220 return 0;
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,
226 void **context)
228 int len;
229 dn_address addr;
231 if (oldval && oldlenp) {
232 if (get_user(len, oldlenp))
233 return -EFAULT;
234 if (len) {
235 if (len != sizeof(unsigned short))
236 return -EINVAL;
237 if (put_user(decnet_address, (unsigned short *)oldval))
238 return -EFAULT;
241 if (newval && newlen) {
242 if (newlen != sizeof(unsigned short))
243 return -EINVAL;
244 if (get_user(addr, (unsigned short *)newval))
245 return -EFAULT;
247 dn_dev_devices_off();
249 decnet_address = addr;
250 dn_dn2eth(decnet_ether_address, decnet_address);
252 dn_dev_devices_on();
254 return 0;
257 static int dn_node_address_handler(ctl_table *table, int write,
258 struct file *filp,
259 void *buffer, size_t *lenp)
261 char addr[DN_ASCBUF_LEN];
262 int len;
263 dn_address dnaddr;
265 if (!*lenp || (filp->f_pos && !write)) {
266 *lenp = 0;
267 return 0;
270 if (write) {
271 int len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
273 if (copy_from_user(addr, buffer, len))
274 return -EFAULT;
276 addr[len] = 0;
278 if (parse_addr(&dnaddr, buffer))
279 return -EINVAL;
281 dn_dev_devices_off();
283 decnet_address = dnaddr;
284 dn_dn2eth(decnet_ether_address, decnet_address);
286 dn_dev_devices_on();
288 filp->f_pos += len;
290 return 0;
293 dn_addr2asc(dn_ntohs(decnet_address), addr);
294 len = strlen(addr);
295 addr[len++] = '\n';
297 if (len > *lenp) len = *lenp;
299 if (copy_to_user(buffer, addr, len))
300 return -EFAULT;
302 *lenp = len;
303 filp->f_pos += len;
305 return 0;
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,
312 void **context)
314 size_t len;
315 struct device *dev = decnet_default_device;
316 char devname[17];
317 size_t namel;
319 devname[0] = 0;
321 if (oldval && oldlenp) {
322 if (get_user(len, oldlenp))
323 return -EFAULT;
324 if (len) {
325 if (dev)
326 strcpy(devname, dev->name);
328 namel = strlen(devname) + 1;
329 if (len > namel) len = namel;
331 if (copy_to_user(oldval, devname, len))
332 return -EFAULT;
334 if (put_user(len, oldlenp))
335 return -EFAULT;
339 if (newval && newlen) {
340 if (newlen > 16)
341 return -E2BIG;
343 if (copy_from_user(devname, newval, newlen))
344 return -EFAULT;
346 devname[newlen] = 0;
348 if ((dev = dev_get(devname)) == NULL)
349 return -ENODEV;
351 if (dev->dn_ptr == NULL)
352 return -ENODEV;
354 decnet_default_device = dev;
357 return 0;
361 static int dn_def_dev_handler(ctl_table *table, int write,
362 struct file * filp,
363 void *buffer, size_t *lenp)
365 int len;
366 struct device *dev = decnet_default_device;
367 char devname[17];
369 if (!*lenp || (filp->f_pos && !write)) {
370 *lenp = 0;
371 return 0;
374 if (write) {
376 if (*lenp > 16)
377 return -E2BIG;
379 if (copy_from_user(devname, buffer, *lenp))
380 return -EFAULT;
382 devname[*lenp] = 0;
384 if ((dev = dev_get(devname)) == NULL)
385 return -ENODEV;
387 if (dev->dn_ptr == NULL)
388 return -ENODEV;
390 decnet_default_device = dev;
391 filp->f_pos += *lenp;
393 return 0;
396 if (dev == NULL) {
397 *lenp = 0;
398 return 0;
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))
408 return -EFAULT;
410 *lenp = len;
411 filp->f_pos += len;
413 return 0;
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,
419 NULL, NULL},
420 {NET_DECNET_NODE_ADDRESS, "node_address", NULL, 7, 0644, NULL,
421 dn_node_address_handler, dn_node_address_strategy, NULL,
422 NULL, 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,
428 sizeof(int), 0644,
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,
432 sizeof(int), 0644,
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,
436 sizeof(int), 0644,
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,
440 sizeof(int), 0644,
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,
444 sizeof(int), 0644,
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,
448 sizeof(int), 0644,
449 NULL, &proc_dointvec, &sysctl_intvec, NULL,
450 NULL, 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);