1 // SPDX-License-Identifier: GPL-2.0
3 * DECnet An implementation of the DECnet protocol suite for the LINUX
4 * operating system. DECnet is implemented using the BSD Socket
5 * interface as the means of communication with the user level.
7 * DECnet sysctl support functions
9 * Author: Steve Whitehouse <SteveW@ACM.org>
13 * Steve Whitehouse - C99 changes and default device handling
14 * Steve Whitehouse - Memory buffer settings, like the tcp ones
18 #include <linux/sysctl.h>
20 #include <linux/netdevice.h>
21 #include <linux/string.h>
22 #include <net/neighbour.h>
26 #include <linux/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 long 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)
87 * Simple routine to parse an ascii DECnet address
88 * into a network order address.
90 static int parse_addr(__le16 *addr, char *str)
94 while(*str && !ISNUM(*str)) str++;
99 area = (*str++ - '0');
102 area += (*str++ - '0');
114 node += (*str++ - '0');
118 node += (*str++ - '0');
122 node += (*str++ - '0');
125 if ((node > 1023) || (area > 63))
128 if (INVALID_END_CHAR(*str))
131 *addr = cpu_to_le16((area << 10) | node);
136 static int dn_node_address_handler(struct ctl_table *table, int write,
138 size_t *lenp, loff_t *ppos)
140 char addr[DN_ASCBUF_LEN];
144 if (!*lenp || (*ppos && !write)) {
150 len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
152 if (copy_from_user(addr, buffer, len))
158 if (parse_addr(&dnaddr, addr))
161 dn_dev_devices_off();
163 decnet_address = dnaddr;
172 dn_addr2asc(le16_to_cpu(decnet_address), addr);
176 if (len > *lenp) len = *lenp;
178 if (copy_to_user(buffer, addr, len))
187 static int dn_def_dev_handler(struct ctl_table *table, int write,
189 size_t *lenp, loff_t *ppos)
192 struct net_device *dev;
195 if (!*lenp || (*ppos && !write)) {
204 if (copy_from_user(devname, buffer, *lenp))
210 dev = dev_get_by_name(&init_net, devname);
214 if (dev->dn_ptr == NULL) {
219 if (dn_dev_set_default(dev, 1)) {
228 dev = dn_dev_get_default();
234 strcpy(devname, dev->name);
236 len = strlen(devname);
237 devname[len++] = '\n';
239 if (len > *lenp) len = *lenp;
241 if (copy_to_user(buffer, devname, len))
250 static struct ctl_table dn_table[] = {
252 .procname = "node_address",
255 .proc_handler = dn_node_address_handler,
258 .procname = "node_name",
262 .proc_handler = proc_dostring,
265 .procname = "default_device",
268 .proc_handler = dn_def_dev_handler,
271 .procname = "time_wait",
272 .data = &decnet_time_wait,
273 .maxlen = sizeof(int),
275 .proc_handler = proc_dointvec_minmax,
276 .extra1 = &min_decnet_time_wait,
277 .extra2 = &max_decnet_time_wait
280 .procname = "dn_count",
281 .data = &decnet_dn_count,
282 .maxlen = sizeof(int),
284 .proc_handler = proc_dointvec_minmax,
285 .extra1 = &min_state_count,
286 .extra2 = &max_state_count
289 .procname = "di_count",
290 .data = &decnet_di_count,
291 .maxlen = sizeof(int),
293 .proc_handler = proc_dointvec_minmax,
294 .extra1 = &min_state_count,
295 .extra2 = &max_state_count
298 .procname = "dr_count",
299 .data = &decnet_dr_count,
300 .maxlen = sizeof(int),
302 .proc_handler = proc_dointvec_minmax,
303 .extra1 = &min_state_count,
304 .extra2 = &max_state_count
307 .procname = "dst_gc_interval",
308 .data = &decnet_dst_gc_interval,
309 .maxlen = sizeof(int),
311 .proc_handler = proc_dointvec_minmax,
312 .extra1 = &min_decnet_dst_gc_interval,
313 .extra2 = &max_decnet_dst_gc_interval
316 .procname = "no_fc_max_cwnd",
317 .data = &decnet_no_fc_max_cwnd,
318 .maxlen = sizeof(int),
320 .proc_handler = proc_dointvec_minmax,
321 .extra1 = &min_decnet_no_fc_max_cwnd,
322 .extra2 = &max_decnet_no_fc_max_cwnd
325 .procname = "decnet_mem",
326 .data = &sysctl_decnet_mem,
327 .maxlen = sizeof(sysctl_decnet_mem),
329 .proc_handler = proc_doulongvec_minmax
332 .procname = "decnet_rmem",
333 .data = &sysctl_decnet_rmem,
334 .maxlen = sizeof(sysctl_decnet_rmem),
336 .proc_handler = proc_dointvec,
339 .procname = "decnet_wmem",
340 .data = &sysctl_decnet_wmem,
341 .maxlen = sizeof(sysctl_decnet_wmem),
343 .proc_handler = proc_dointvec,
347 .data = &decnet_debug_level,
348 .maxlen = sizeof(int),
350 .proc_handler = proc_dointvec,
355 void dn_register_sysctl(void)
357 dn_table_header = register_net_sysctl(&init_net, "net/decnet", dn_table);
360 void dn_unregister_sysctl(void)
362 unregister_net_sysctl_table(dn_table_header);
365 #else /* CONFIG_SYSCTL */
366 void dn_unregister_sysctl(void)
369 void dn_register_sysctl(void)