sysctl_net_decnet.c 7.2 KB

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