[PATCH] orinoco replace hermes_write_words() with hermes_write_bytes()
[linux-2.6/sactl.git] / net / decnet / sysctl_net_decnet.c
blobbda5920215fd2f04c05bf85aa912add450e45596
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:
12 * Steve Whitehouse - C99 changes and default device handling
13 * Steve Whitehouse - Memory buffer settings, like the tcp ones
16 #include <linux/config.h>
17 #include <linux/mm.h>
18 #include <linux/sysctl.h>
19 #include <linux/fs.h>
20 #include <linux/netdevice.h>
21 #include <linux/string.h>
22 #include <net/neighbour.h>
23 #include <net/dst.h>
24 #include <net/flow.h>
26 #include <asm/uaccess.h>
28 #include <net/dn.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 };
46 #ifdef CONFIG_SYSCTL
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;
61 * ctype.h :-)
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)
71 for(;;) {
72 switch(*str) {
73 case ' ':
74 case '\n':
75 case '\r':
76 case ':':
77 *str = 0;
78 case 0:
79 return;
81 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)
91 __u16 area, node;
93 while(*str && !ISNUM(*str)) str++;
95 if (*str == 0)
96 return -1;
98 area = (*str++ - '0');
99 if (ISNUM(*str)) {
100 area *= 10;
101 area += (*str++ - '0');
104 if (*str++ != '.')
105 return -1;
107 if (!ISNUM(*str))
108 return -1;
110 node = *str++ - '0';
111 if (ISNUM(*str)) {
112 node *= 10;
113 node += (*str++ - '0');
115 if (ISNUM(*str)) {
116 node *= 10;
117 node += (*str++ - '0');
119 if (ISNUM(*str)) {
120 node *= 10;
121 node += (*str++ - '0');
124 if ((node > 1023) || (area > 63))
125 return -1;
127 if (INVALID_END_CHAR(*str))
128 return -1;
130 *addr = dn_htons((area << 10) | node);
132 return 0;
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,
139 void **context)
141 size_t len;
142 __le16 addr;
144 if (oldval && oldlenp) {
145 if (get_user(len, oldlenp))
146 return -EFAULT;
147 if (len) {
148 if (len != sizeof(unsigned short))
149 return -EINVAL;
150 if (put_user(decnet_address, (__le16 __user *)oldval))
151 return -EFAULT;
154 if (newval && newlen) {
155 if (newlen != sizeof(unsigned short))
156 return -EINVAL;
157 if (get_user(addr, (__le16 __user *)newval))
158 return -EFAULT;
160 dn_dev_devices_off();
162 decnet_address = addr;
164 dn_dev_devices_on();
166 return 0;
169 static int dn_node_address_handler(ctl_table *table, int write,
170 struct file *filp,
171 void __user *buffer,
172 size_t *lenp, loff_t *ppos)
174 char addr[DN_ASCBUF_LEN];
175 size_t len;
176 __le16 dnaddr;
178 if (!*lenp || (*ppos && !write)) {
179 *lenp = 0;
180 return 0;
183 if (write) {
184 int len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
186 if (copy_from_user(addr, buffer, len))
187 return -EFAULT;
189 addr[len] = 0;
190 strip_it(addr);
192 if (parse_addr(&dnaddr, addr))
193 return -EINVAL;
195 dn_dev_devices_off();
197 decnet_address = dnaddr;
199 dn_dev_devices_on();
201 *ppos += len;
203 return 0;
206 dn_addr2asc(dn_ntohs(decnet_address), addr);
207 len = strlen(addr);
208 addr[len++] = '\n';
210 if (len > *lenp) len = *lenp;
212 if (copy_to_user(buffer, addr, len))
213 return -EFAULT;
215 *lenp = len;
216 *ppos += len;
218 return 0;
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,
225 void **context)
227 size_t len;
228 struct net_device *dev;
229 char devname[17];
230 size_t namel;
231 int rv = 0;
233 devname[0] = 0;
235 if (oldval && oldlenp) {
236 if (get_user(len, oldlenp))
237 return -EFAULT;
238 if (len) {
239 dev = dn_dev_get_default();
240 if (dev) {
241 strcpy(devname, dev->name);
242 dev_put(dev);
245 namel = strlen(devname) + 1;
246 if (len > namel) len = namel;
248 if (copy_to_user(oldval, devname, len))
249 return -EFAULT;
251 if (put_user(len, oldlenp))
252 return -EFAULT;
256 if (newval && newlen) {
257 if (newlen > 16)
258 return -E2BIG;
260 if (copy_from_user(devname, newval, newlen))
261 return -EFAULT;
263 devname[newlen] = 0;
265 dev = dev_get_by_name(devname);
266 if (dev == NULL)
267 return -ENODEV;
269 rv = -ENODEV;
270 if (dev->dn_ptr != NULL) {
271 rv = dn_dev_set_default(dev, 1);
272 if (rv)
273 dev_put(dev);
277 return rv;
281 static int dn_def_dev_handler(ctl_table *table, int write,
282 struct file * filp,
283 void __user *buffer,
284 size_t *lenp, loff_t *ppos)
286 size_t len;
287 struct net_device *dev;
288 char devname[17];
290 if (!*lenp || (*ppos && !write)) {
291 *lenp = 0;
292 return 0;
295 if (write) {
296 if (*lenp > 16)
297 return -E2BIG;
299 if (copy_from_user(devname, buffer, *lenp))
300 return -EFAULT;
302 devname[*lenp] = 0;
303 strip_it(devname);
305 dev = dev_get_by_name(devname);
306 if (dev == NULL)
307 return -ENODEV;
309 if (dev->dn_ptr == NULL) {
310 dev_put(dev);
311 return -ENODEV;
314 if (dn_dev_set_default(dev, 1)) {
315 dev_put(dev);
316 return -ENODEV;
318 *ppos += *lenp;
320 return 0;
323 dev = dn_dev_get_default();
324 if (dev == NULL) {
325 *lenp = 0;
326 return 0;
329 strcpy(devname, dev->name);
330 dev_put(dev);
331 len = strlen(devname);
332 devname[len++] = '\n';
334 if (len > *lenp) len = *lenp;
336 if (copy_to_user(buffer, devname, len))
337 return -EFAULT;
339 *lenp = len;
340 *ppos += len;
342 return 0;
345 static ctl_table dn_table[] = {
347 .ctl_name = NET_DECNET_NODE_ADDRESS,
348 .procname = "node_address",
349 .maxlen = 7,
350 .mode = 0644,
351 .proc_handler = dn_node_address_handler,
352 .strategy = dn_node_address_strategy,
355 .ctl_name = NET_DECNET_NODE_NAME,
356 .procname = "node_name",
357 .data = node_name,
358 .maxlen = 7,
359 .mode = 0644,
360 .proc_handler = &proc_dostring,
361 .strategy = &sysctl_string,
364 .ctl_name = NET_DECNET_DEFAULT_DEVICE,
365 .procname = "default_device",
366 .maxlen = 16,
367 .mode = 0644,
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),
376 .mode = 0644,
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),
387 .mode = 0644,
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),
398 .mode = 0644,
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),
409 .mode = 0644,
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),
420 .mode = 0644,
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),
431 .mode = 0644,
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),
442 .mode = 0644,
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),
451 .mode = 0644,
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),
460 .mode = 0644,
461 .proc_handler = &proc_dointvec,
462 .strategy = &sysctl_intvec,
465 .ctl_name = NET_DECNET_DEBUG_LEVEL,
466 .procname = "debug",
467 .data = &decnet_debug_level,
468 .maxlen = sizeof(int),
469 .mode = 0644,
470 .proc_handler = &proc_dointvec,
471 .strategy = &sysctl_intvec,
476 static ctl_table dn_dir_table[] = {
478 .ctl_name = NET_DECNET,
479 .procname = "decnet",
480 .mode = 0555,
481 .child = dn_table},
485 static ctl_table dn_root_table[] = {
487 .ctl_name = CTL_NET,
488 .procname = "net",
489 .mode = 0555,
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)
513 #endif