sysctl_net_decnet.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. case 0:
  69. return;
  70. }
  71. str++;
  72. }
  73. }
  74. /*
  75. * Simple routine to parse an ascii DECnet address
  76. * into a network order address.
  77. */
  78. static int parse_addr(__le16 *addr, char *str)
  79. {
  80. __u16 area, node;
  81. while(*str && !ISNUM(*str)) str++;
  82. if (*str == 0)
  83. return -1;
  84. area = (*str++ - '0');
  85. if (ISNUM(*str)) {
  86. area *= 10;
  87. area += (*str++ - '0');
  88. }
  89. if (*str++ != '.')
  90. return -1;
  91. if (!ISNUM(*str))
  92. return -1;
  93. node = *str++ - '0';
  94. if (ISNUM(*str)) {
  95. node *= 10;
  96. node += (*str++ - '0');
  97. }
  98. if (ISNUM(*str)) {
  99. node *= 10;
  100. node += (*str++ - '0');
  101. }
  102. if (ISNUM(*str)) {
  103. node *= 10;
  104. node += (*str++ - '0');
  105. }
  106. if ((node > 1023) || (area > 63))
  107. return -1;
  108. if (INVALID_END_CHAR(*str))
  109. return -1;
  110. *addr = cpu_to_le16((area << 10) | node);
  111. return 0;
  112. }
  113. static int dn_node_address_handler(ctl_table *table, int write,
  114. void __user *buffer,
  115. size_t *lenp, loff_t *ppos)
  116. {
  117. char addr[DN_ASCBUF_LEN];
  118. size_t len;
  119. __le16 dnaddr;
  120. if (!*lenp || (*ppos && !write)) {
  121. *lenp = 0;
  122. return 0;
  123. }
  124. if (write) {
  125. len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
  126. if (copy_from_user(addr, buffer, len))
  127. return -EFAULT;
  128. addr[len] = 0;
  129. strip_it(addr);
  130. if (parse_addr(&dnaddr, addr))
  131. return -EINVAL;
  132. dn_dev_devices_off();
  133. decnet_address = dnaddr;
  134. dn_dev_devices_on();
  135. *ppos += len;
  136. return 0;
  137. }
  138. dn_addr2asc(le16_to_cpu(decnet_address), addr);
  139. len = strlen(addr);
  140. addr[len++] = '\n';
  141. if (len > *lenp) len = *lenp;
  142. if (copy_to_user(buffer, addr, len))
  143. return -EFAULT;
  144. *lenp = len;
  145. *ppos += len;
  146. return 0;
  147. }
  148. static int dn_def_dev_handler(ctl_table *table, int write,
  149. void __user *buffer,
  150. size_t *lenp, loff_t *ppos)
  151. {
  152. size_t len;
  153. struct net_device *dev;
  154. char devname[17];
  155. if (!*lenp || (*ppos && !write)) {
  156. *lenp = 0;
  157. return 0;
  158. }
  159. if (write) {
  160. if (*lenp > 16)
  161. return -E2BIG;
  162. if (copy_from_user(devname, buffer, *lenp))
  163. return -EFAULT;
  164. devname[*lenp] = 0;
  165. strip_it(devname);
  166. dev = dev_get_by_name(&init_net, devname);
  167. if (dev == NULL)
  168. return -ENODEV;
  169. if (dev->dn_ptr == NULL) {
  170. dev_put(dev);
  171. return -ENODEV;
  172. }
  173. if (dn_dev_set_default(dev, 1)) {
  174. dev_put(dev);
  175. return -ENODEV;
  176. }
  177. *ppos += *lenp;
  178. return 0;
  179. }
  180. dev = dn_dev_get_default();
  181. if (dev == NULL) {
  182. *lenp = 0;
  183. return 0;
  184. }
  185. strcpy(devname, dev->name);
  186. dev_put(dev);
  187. len = strlen(devname);
  188. devname[len++] = '\n';
  189. if (len > *lenp) len = *lenp;
  190. if (copy_to_user(buffer, devname, len))
  191. return -EFAULT;
  192. *lenp = len;
  193. *ppos += len;
  194. return 0;
  195. }
  196. static ctl_table dn_table[] = {
  197. {
  198. .procname = "node_address",
  199. .maxlen = 7,
  200. .mode = 0644,
  201. .proc_handler = dn_node_address_handler,
  202. },
  203. {
  204. .procname = "node_name",
  205. .data = node_name,
  206. .maxlen = 7,
  207. .mode = 0644,
  208. .proc_handler = proc_dostring,
  209. },
  210. {
  211. .procname = "default_device",
  212. .maxlen = 16,
  213. .mode = 0644,
  214. .proc_handler = dn_def_dev_handler,
  215. },
  216. {
  217. .procname = "time_wait",
  218. .data = &decnet_time_wait,
  219. .maxlen = sizeof(int),
  220. .mode = 0644,
  221. .proc_handler = proc_dointvec_minmax,
  222. .extra1 = &min_decnet_time_wait,
  223. .extra2 = &max_decnet_time_wait
  224. },
  225. {
  226. .procname = "dn_count",
  227. .data = &decnet_dn_count,
  228. .maxlen = sizeof(int),
  229. .mode = 0644,
  230. .proc_handler = proc_dointvec_minmax,
  231. .extra1 = &min_state_count,
  232. .extra2 = &max_state_count
  233. },
  234. {
  235. .procname = "di_count",
  236. .data = &decnet_di_count,
  237. .maxlen = sizeof(int),
  238. .mode = 0644,
  239. .proc_handler = proc_dointvec_minmax,
  240. .extra1 = &min_state_count,
  241. .extra2 = &max_state_count
  242. },
  243. {
  244. .procname = "dr_count",
  245. .data = &decnet_dr_count,
  246. .maxlen = sizeof(int),
  247. .mode = 0644,
  248. .proc_handler = proc_dointvec_minmax,
  249. .extra1 = &min_state_count,
  250. .extra2 = &max_state_count
  251. },
  252. {
  253. .procname = "dst_gc_interval",
  254. .data = &decnet_dst_gc_interval,
  255. .maxlen = sizeof(int),
  256. .mode = 0644,
  257. .proc_handler = proc_dointvec_minmax,
  258. .extra1 = &min_decnet_dst_gc_interval,
  259. .extra2 = &max_decnet_dst_gc_interval
  260. },
  261. {
  262. .procname = "no_fc_max_cwnd",
  263. .data = &decnet_no_fc_max_cwnd,
  264. .maxlen = sizeof(int),
  265. .mode = 0644,
  266. .proc_handler = proc_dointvec_minmax,
  267. .extra1 = &min_decnet_no_fc_max_cwnd,
  268. .extra2 = &max_decnet_no_fc_max_cwnd
  269. },
  270. {
  271. .procname = "decnet_mem",
  272. .data = &sysctl_decnet_mem,
  273. .maxlen = sizeof(sysctl_decnet_mem),
  274. .mode = 0644,
  275. .proc_handler = proc_doulongvec_minmax
  276. },
  277. {
  278. .procname = "decnet_rmem",
  279. .data = &sysctl_decnet_rmem,
  280. .maxlen = sizeof(sysctl_decnet_rmem),
  281. .mode = 0644,
  282. .proc_handler = proc_dointvec,
  283. },
  284. {
  285. .procname = "decnet_wmem",
  286. .data = &sysctl_decnet_wmem,
  287. .maxlen = sizeof(sysctl_decnet_wmem),
  288. .mode = 0644,
  289. .proc_handler = proc_dointvec,
  290. },
  291. {
  292. .procname = "debug",
  293. .data = &decnet_debug_level,
  294. .maxlen = sizeof(int),
  295. .mode = 0644,
  296. .proc_handler = proc_dointvec,
  297. },
  298. { }
  299. };
  300. static struct ctl_path dn_path[] = {
  301. { .procname = "net", },
  302. { .procname = "decnet", },
  303. { }
  304. };
  305. void dn_register_sysctl(void)
  306. {
  307. dn_table_header = register_sysctl_paths(dn_path, dn_table);
  308. }
  309. void dn_unregister_sysctl(void)
  310. {
  311. unregister_sysctl_table(dn_table_header);
  312. }
  313. #else /* CONFIG_SYSCTL */
  314. void dn_unregister_sysctl(void)
  315. {
  316. }
  317. void dn_register_sysctl(void)
  318. {
  319. }
  320. #endif