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,
137 void *buffer, size_t *lenp, loff_t *ppos)
139 char addr[DN_ASCBUF_LEN];
143 if (!*lenp || (*ppos && !write)) {
149 len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
150 memcpy(addr, buffer, len);
154 if (parse_addr(&dnaddr, addr))
157 dn_dev_devices_off();
159 decnet_address = dnaddr;
168 dn_addr2asc(le16_to_cpu(decnet_address), addr);
174 memcpy(buffer, addr, len);
181 static int dn_def_dev_handler(struct ctl_table *table, int write,
182 void *buffer, size_t *lenp, loff_t *ppos)
185 struct net_device *dev;
188 if (!*lenp || (*ppos && !write)) {
197 memcpy(devname, buffer, *lenp);
201 dev = dev_get_by_name(&init_net, devname);
205 if (dev->dn_ptr == NULL) {
210 if (dn_dev_set_default(dev, 1)) {
219 dev = dn_dev_get_default();
225 strcpy(devname, dev->name);
227 len = strlen(devname);
228 devname[len++] = '\n';
230 if (len > *lenp) len = *lenp;
232 memcpy(buffer, devname, len);
239 static struct ctl_table dn_table[] = {
241 .procname = "node_address",
244 .proc_handler = dn_node_address_handler,
247 .procname = "node_name",
251 .proc_handler = proc_dostring,
254 .procname = "default_device",
257 .proc_handler = dn_def_dev_handler,
260 .procname = "time_wait",
261 .data = &decnet_time_wait,
262 .maxlen = sizeof(int),
264 .proc_handler = proc_dointvec_minmax,
265 .extra1 = &min_decnet_time_wait,
266 .extra2 = &max_decnet_time_wait
269 .procname = "dn_count",
270 .data = &decnet_dn_count,
271 .maxlen = sizeof(int),
273 .proc_handler = proc_dointvec_minmax,
274 .extra1 = &min_state_count,
275 .extra2 = &max_state_count
278 .procname = "di_count",
279 .data = &decnet_di_count,
280 .maxlen = sizeof(int),
282 .proc_handler = proc_dointvec_minmax,
283 .extra1 = &min_state_count,
284 .extra2 = &max_state_count
287 .procname = "dr_count",
288 .data = &decnet_dr_count,
289 .maxlen = sizeof(int),
291 .proc_handler = proc_dointvec_minmax,
292 .extra1 = &min_state_count,
293 .extra2 = &max_state_count
296 .procname = "dst_gc_interval",
297 .data = &decnet_dst_gc_interval,
298 .maxlen = sizeof(int),
300 .proc_handler = proc_dointvec_minmax,
301 .extra1 = &min_decnet_dst_gc_interval,
302 .extra2 = &max_decnet_dst_gc_interval
305 .procname = "no_fc_max_cwnd",
306 .data = &decnet_no_fc_max_cwnd,
307 .maxlen = sizeof(int),
309 .proc_handler = proc_dointvec_minmax,
310 .extra1 = &min_decnet_no_fc_max_cwnd,
311 .extra2 = &max_decnet_no_fc_max_cwnd
314 .procname = "decnet_mem",
315 .data = &sysctl_decnet_mem,
316 .maxlen = sizeof(sysctl_decnet_mem),
318 .proc_handler = proc_doulongvec_minmax
321 .procname = "decnet_rmem",
322 .data = &sysctl_decnet_rmem,
323 .maxlen = sizeof(sysctl_decnet_rmem),
325 .proc_handler = proc_dointvec,
328 .procname = "decnet_wmem",
329 .data = &sysctl_decnet_wmem,
330 .maxlen = sizeof(sysctl_decnet_wmem),
332 .proc_handler = proc_dointvec,
336 .data = &decnet_debug_level,
337 .maxlen = sizeof(int),
339 .proc_handler = proc_dointvec,
344 void dn_register_sysctl(void)
346 dn_table_header = register_net_sysctl(&init_net, "net/decnet", dn_table);
349 void dn_unregister_sysctl(void)
351 unregister_net_sysctl_table(dn_table_header);
354 #else /* CONFIG_SYSCTL */
355 void dn_unregister_sysctl(void)
358 void dn_register_sysctl(void)