sysctl_net_decnet.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  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.
  6. *
  7. * DECnet sysctl support functions
  8. *
  9. * Author: Steve Whitehouse <SteveW@ACM.org>
  10. *
  11. *
  12. * Changes:
  13. * Steve Whitehouse - C99 changes and default device handling
  14. * Steve Whitehouse - Memory buffer settings, like the tcp ones
  15. *
  16. */
  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>
  25. #include <linux/uaccess.h>
  26. #include <net/dn.h>
  27. #include <net/dn_dev.h>
  28. #include <net/dn_route.h>
  29. int decnet_debug_level;
  30. int decnet_time_wait = 30;
  31. int decnet_dn_count = 1;
  32. int decnet_di_count = 3;
  33. int decnet_dr_count = 3;
  34. int decnet_log_martians = 1;
  35. int decnet_no_fc_max_cwnd = NSP_MIN_WINDOW;
  36. /* Reasonable defaults, I hope, based on tcp's defaults */
  37. long sysctl_decnet_mem[3] = { 768 << 3, 1024 << 3, 1536 << 3 };
  38. int sysctl_decnet_wmem[3] = { 4 * 1024, 16 * 1024, 128 * 1024 };
  39. int sysctl_decnet_rmem[3] = { 4 * 1024, 87380, 87380 * 2 };
  40. #ifdef CONFIG_SYSCTL
  41. extern int decnet_dst_gc_interval;
  42. static int min_decnet_time_wait[] = { 5 };
  43. static int max_decnet_time_wait[] = { 600 };
  44. static int min_state_count[] = { 1 };
  45. static int max_state_count[] = { NSP_MAXRXTSHIFT };
  46. static int min_decnet_dst_gc_interval[] = { 1 };
  47. static int max_decnet_dst_gc_interval[] = { 60 };
  48. static int min_decnet_no_fc_max_cwnd[] = { NSP_MIN_WINDOW };
  49. static int max_decnet_no_fc_max_cwnd[] = { NSP_MAX_WINDOW };
  50. static char node_name[7] = "???";
  51. static struct ctl_table_header *dn_table_header = NULL;
  52. /*
  53. * ctype.h :-)
  54. */
  55. #define ISNUM(x) (((x) >= '0') && ((x) <= '9'))
  56. #define ISLOWER(x) (((x) >= 'a') && ((x) <= 'z'))
  57. #define ISUPPER(x) (((x) >= 'A') && ((x) <= 'Z'))
  58. #define ISALPHA(x) (ISLOWER(x) || ISUPPER(x))
  59. #define INVALID_END_CHAR(x) (ISNUM(x) || ISALPHA(x))
  60. static void strip_it(char *str)
  61. {
  62. for(;;) {
  63. switch (*str) {
  64. case ' ':
  65. case '\n':
  66. case '\r':
  67. case ':':
  68. *str = 0;
  69. /* Fallthrough */
  70. case 0:
  71. return;
  72. }
  73. str++;
  74. }
  75. }
  76. /*
  77. * Simple routine to parse an ascii DECnet address
  78. * into a network order address.
  79. */
  80. static int parse_addr(__le16 *addr, char *str)
  81. {
  82. __u16 area, node;
  83. while(*str && !ISNUM(*str)) str++;
  84. if (*str == 0)
  85. return -1;
  86. area = (*str++ - '0');
  87. if (ISNUM(*str)) {
  88. area *= 10;
  89. area += (*str++ - '0');
  90. }
  91. if (*str++ != '.')
  92. return -1;
  93. if (!ISNUM(*str))
  94. return -1;
  95. node = *str++ - '0';
  96. if (ISNUM(*str)) {
  97. node *= 10;
  98. node += (*str++ - '0');
  99. }
  100. if (ISNUM(*str)) {
  101. node *= 10;
  102. node += (*str++ - '0');
  103. }
  104. if (ISNUM(*str)) {
  105. node *= 10;
  106. node += (*str++ - '0');
  107. }
  108. if ((node > 1023) || (area > 63))
  109. return -1;
  110. if (INVALID_END_CHAR(*str))
  111. return -1;
  112. *addr = cpu_to_le16((area << 10) | node);
  113. return 0;
  114. }
  115. static int dn_node_address_handler(struct ctl_table *table, int write,
  116. void __user *buffer,
  117. size_t *lenp, loff_t *ppos)
  118. {
  119. char addr[DN_ASCBUF_LEN];
  120. size_t len;
  121. __le16 dnaddr;
  122. if (!*lenp || (*ppos && !write)) {
  123. *lenp = 0;
  124. return 0;
  125. }
  126. if (write) {
  127. len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
  128. if (copy_from_user(addr, buffer, len))
  129. return -EFAULT;
  130. addr[len] = 0;
  131. strip_it(addr);
  132. if (parse_addr(&dnaddr, addr))
  133. return -EINVAL;
  134. dn_dev_devices_off();
  135. decnet_address = dnaddr;
  136. dn_dev_devices_on();
  137. *ppos += len;
  138. return 0;
  139. }
  140. dn_addr2asc(le16_to_cpu(decnet_address), addr);
  141. len = strlen(addr);
  142. addr[len++] = '\n';
  143. if (len > *lenp) len = *lenp;
  144. if (copy_to_user(buffer, addr, len))
  145. return -EFAULT;
  146. *lenp = len;
  147. *ppos += len;
  148. return 0;
  149. }
  150. static int dn_def_dev_handler(struct ctl_table *table, int write,
  151. void __user *buffer,
  152. size_t *lenp, loff_t *ppos)
  153. {
  154. size_t len;
  155. struct net_device *dev;
  156. char devname[17];
  157. if (!*lenp || (*ppos && !write)) {
  158. *lenp = 0;
  159. return 0;
  160. }
  161. if (write) {
  162. if (*lenp > 16)
  163. return -E2BIG;
  164. if (copy_from_user(devname, buffer, *lenp))
  165. return -EFAULT;
  166. devname[*lenp] = 0;
  167. strip_it(devname);
  168. dev = dev_get_by_name(&init_net, devname);
  169. if (dev == NULL)
  170. return -ENODEV;
  171. if (dev->dn_ptr == NULL) {
  172. dev_put(dev);
  173. return -ENODEV;
  174. }
  175. if (dn_dev_set_default(dev, 1)) {
  176. dev_put(dev);
  177. return -ENODEV;
  178. }
  179. *ppos += *lenp;
  180. return 0;
  181. }
  182. dev = dn_dev_get_default();
  183. if (dev == NULL) {
  184. *lenp = 0;
  185. return 0;
  186. }
  187. strcpy(devname, dev->name);
  188. dev_put(dev);
  189. len = strlen(devname);
  190. devname[len++] = '\n';
  191. if (len > *lenp) len = *lenp;
  192. if (copy_to_user(buffer, devname, len))
  193. return -EFAULT;
  194. *lenp = len;
  195. *ppos += len;
  196. return 0;
  197. }
  198. static struct ctl_table dn_table[] = {
  199. {
  200. .procname = "node_address",
  201. .maxlen = 7,
  202. .mode = 0644,
  203. .proc_handler = dn_node_address_handler,
  204. },
  205. {
  206. .procname = "node_name",
  207. .data = node_name,
  208. .maxlen = 7,
  209. .mode = 0644,
  210. .proc_handler = proc_dostring,
  211. },
  212. {
  213. .procname = "default_device",
  214. .maxlen = 16,
  215. .mode = 0644,
  216. .proc_handler = dn_def_dev_handler,
  217. },
  218. {
  219. .procname = "time_wait",
  220. .data = &decnet_time_wait,
  221. .maxlen = sizeof(int),
  222. .mode = 0644,
  223. .proc_handler = proc_dointvec_minmax,
  224. .extra1 = &min_decnet_time_wait,
  225. .extra2 = &max_decnet_time_wait
  226. },
  227. {
  228. .procname = "dn_count",
  229. .data = &decnet_dn_count,
  230. .maxlen = sizeof(int),
  231. .mode = 0644,
  232. .proc_handler = proc_dointvec_minmax,
  233. .extra1 = &min_state_count,
  234. .extra2 = &max_state_count
  235. },
  236. {
  237. .procname = "di_count",
  238. .data = &decnet_di_count,
  239. .maxlen = sizeof(int),
  240. .mode = 0644,
  241. .proc_handler = proc_dointvec_minmax,
  242. .extra1 = &min_state_count,
  243. .extra2 = &max_state_count
  244. },
  245. {
  246. .procname = "dr_count",
  247. .data = &decnet_dr_count,
  248. .maxlen = sizeof(int),
  249. .mode = 0644,
  250. .proc_handler = proc_dointvec_minmax,
  251. .extra1 = &min_state_count,
  252. .extra2 = &max_state_count
  253. },
  254. {
  255. .procname = "dst_gc_interval",
  256. .data = &decnet_dst_gc_interval,
  257. .maxlen = sizeof(int),
  258. .mode = 0644,
  259. .proc_handler = proc_dointvec_minmax,
  260. .extra1 = &min_decnet_dst_gc_interval,
  261. .extra2 = &max_decnet_dst_gc_interval
  262. },
  263. {
  264. .procname = "no_fc_max_cwnd",
  265. .data = &decnet_no_fc_max_cwnd,
  266. .maxlen = sizeof(int),
  267. .mode = 0644,
  268. .proc_handler = proc_dointvec_minmax,
  269. .extra1 = &min_decnet_no_fc_max_cwnd,
  270. .extra2 = &max_decnet_no_fc_max_cwnd
  271. },
  272. {
  273. .procname = "decnet_mem",
  274. .data = &sysctl_decnet_mem,
  275. .maxlen = sizeof(sysctl_decnet_mem),
  276. .mode = 0644,
  277. .proc_handler = proc_doulongvec_minmax
  278. },
  279. {
  280. .procname = "decnet_rmem",
  281. .data = &sysctl_decnet_rmem,
  282. .maxlen = sizeof(sysctl_decnet_rmem),
  283. .mode = 0644,
  284. .proc_handler = proc_dointvec,
  285. },
  286. {
  287. .procname = "decnet_wmem",
  288. .data = &sysctl_decnet_wmem,
  289. .maxlen = sizeof(sysctl_decnet_wmem),
  290. .mode = 0644,
  291. .proc_handler = proc_dointvec,
  292. },
  293. {
  294. .procname = "debug",
  295. .data = &decnet_debug_level,
  296. .maxlen = sizeof(int),
  297. .mode = 0644,
  298. .proc_handler = proc_dointvec,
  299. },
  300. { }
  301. };
  302. void dn_register_sysctl(void)
  303. {
  304. dn_table_header = register_net_sysctl(&init_net, "net/decnet", dn_table);
  305. }
  306. void dn_unregister_sysctl(void)
  307. {
  308. unregister_net_sysctl_table(dn_table_header);
  309. }
  310. #else /* CONFIG_SYSCTL */
  311. void dn_unregister_sysctl(void)
  312. {
  313. }
  314. void dn_register_sysctl(void)
  315. {
  316. }
  317. #endif