sysctl_net_decnet.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. int 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 = dn_htons((area << 10) | node);
  111. return 0;
  112. }
  113. static int dn_node_address_strategy(ctl_table *table, int __user *name, int nlen,
  114. void __user *oldval, size_t __user *oldlenp,
  115. void __user *newval, size_t newlen)
  116. {
  117. size_t len;
  118. __le16 addr;
  119. if (oldval && oldlenp) {
  120. if (get_user(len, oldlenp))
  121. return -EFAULT;
  122. if (len) {
  123. if (len != sizeof(unsigned short))
  124. return -EINVAL;
  125. if (put_user(decnet_address, (__le16 __user *)oldval))
  126. return -EFAULT;
  127. }
  128. }
  129. if (newval && newlen) {
  130. if (newlen != sizeof(unsigned short))
  131. return -EINVAL;
  132. if (get_user(addr, (__le16 __user *)newval))
  133. return -EFAULT;
  134. dn_dev_devices_off();
  135. decnet_address = addr;
  136. dn_dev_devices_on();
  137. }
  138. return 0;
  139. }
  140. static int dn_node_address_handler(ctl_table *table, int write,
  141. struct file *filp,
  142. void __user *buffer,
  143. size_t *lenp, loff_t *ppos)
  144. {
  145. char addr[DN_ASCBUF_LEN];
  146. size_t len;
  147. __le16 dnaddr;
  148. if (!*lenp || (*ppos && !write)) {
  149. *lenp = 0;
  150. return 0;
  151. }
  152. if (write) {
  153. int len = (*lenp < DN_ASCBUF_LEN) ? *lenp : (DN_ASCBUF_LEN-1);
  154. if (copy_from_user(addr, buffer, len))
  155. return -EFAULT;
  156. addr[len] = 0;
  157. strip_it(addr);
  158. if (parse_addr(&dnaddr, addr))
  159. return -EINVAL;
  160. dn_dev_devices_off();
  161. decnet_address = dnaddr;
  162. dn_dev_devices_on();
  163. *ppos += len;
  164. return 0;
  165. }
  166. dn_addr2asc(dn_ntohs(decnet_address), addr);
  167. len = strlen(addr);
  168. addr[len++] = '\n';
  169. if (len > *lenp) len = *lenp;
  170. if (copy_to_user(buffer, addr, len))
  171. return -EFAULT;
  172. *lenp = len;
  173. *ppos += len;
  174. return 0;
  175. }
  176. static int dn_def_dev_strategy(ctl_table *table, int __user *name, int nlen,
  177. void __user *oldval, size_t __user *oldlenp,
  178. void __user *newval, size_t newlen)
  179. {
  180. size_t len;
  181. struct net_device *dev;
  182. char devname[17];
  183. size_t namel;
  184. int rv = 0;
  185. devname[0] = 0;
  186. if (oldval && oldlenp) {
  187. if (get_user(len, oldlenp))
  188. return -EFAULT;
  189. if (len) {
  190. dev = dn_dev_get_default();
  191. if (dev) {
  192. strcpy(devname, dev->name);
  193. dev_put(dev);
  194. }
  195. namel = strlen(devname) + 1;
  196. if (len > namel) len = namel;
  197. if (copy_to_user(oldval, devname, len))
  198. return -EFAULT;
  199. if (put_user(len, oldlenp))
  200. return -EFAULT;
  201. }
  202. }
  203. if (newval && newlen) {
  204. if (newlen > 16)
  205. return -E2BIG;
  206. if (copy_from_user(devname, newval, newlen))
  207. return -EFAULT;
  208. devname[newlen] = 0;
  209. dev = dev_get_by_name(devname);
  210. if (dev == NULL)
  211. return -ENODEV;
  212. rv = -ENODEV;
  213. if (dev->dn_ptr != NULL) {
  214. rv = dn_dev_set_default(dev, 1);
  215. if (rv)
  216. dev_put(dev);
  217. }
  218. }
  219. return rv;
  220. }
  221. static int dn_def_dev_handler(ctl_table *table, int write,
  222. struct file * filp,
  223. void __user *buffer,
  224. size_t *lenp, loff_t *ppos)
  225. {
  226. size_t len;
  227. struct net_device *dev;
  228. char devname[17];
  229. if (!*lenp || (*ppos && !write)) {
  230. *lenp = 0;
  231. return 0;
  232. }
  233. if (write) {
  234. if (*lenp > 16)
  235. return -E2BIG;
  236. if (copy_from_user(devname, buffer, *lenp))
  237. return -EFAULT;
  238. devname[*lenp] = 0;
  239. strip_it(devname);
  240. dev = dev_get_by_name(devname);
  241. if (dev == NULL)
  242. return -ENODEV;
  243. if (dev->dn_ptr == NULL) {
  244. dev_put(dev);
  245. return -ENODEV;
  246. }
  247. if (dn_dev_set_default(dev, 1)) {
  248. dev_put(dev);
  249. return -ENODEV;
  250. }
  251. *ppos += *lenp;
  252. return 0;
  253. }
  254. dev = dn_dev_get_default();
  255. if (dev == NULL) {
  256. *lenp = 0;
  257. return 0;
  258. }
  259. strcpy(devname, dev->name);
  260. dev_put(dev);
  261. len = strlen(devname);
  262. devname[len++] = '\n';
  263. if (len > *lenp) len = *lenp;
  264. if (copy_to_user(buffer, devname, len))
  265. return -EFAULT;
  266. *lenp = len;
  267. *ppos += len;
  268. return 0;
  269. }
  270. static ctl_table dn_table[] = {
  271. {
  272. .ctl_name = NET_DECNET_NODE_ADDRESS,
  273. .procname = "node_address",
  274. .maxlen = 7,
  275. .mode = 0644,
  276. .proc_handler = dn_node_address_handler,
  277. .strategy = dn_node_address_strategy,
  278. },
  279. {
  280. .ctl_name = NET_DECNET_NODE_NAME,
  281. .procname = "node_name",
  282. .data = node_name,
  283. .maxlen = 7,
  284. .mode = 0644,
  285. .proc_handler = &proc_dostring,
  286. .strategy = &sysctl_string,
  287. },
  288. {
  289. .ctl_name = NET_DECNET_DEFAULT_DEVICE,
  290. .procname = "default_device",
  291. .maxlen = 16,
  292. .mode = 0644,
  293. .proc_handler = dn_def_dev_handler,
  294. .strategy = dn_def_dev_strategy,
  295. },
  296. {
  297. .ctl_name = NET_DECNET_TIME_WAIT,
  298. .procname = "time_wait",
  299. .data = &decnet_time_wait,
  300. .maxlen = sizeof(int),
  301. .mode = 0644,
  302. .proc_handler = &proc_dointvec_minmax,
  303. .strategy = &sysctl_intvec,
  304. .extra1 = &min_decnet_time_wait,
  305. .extra2 = &max_decnet_time_wait
  306. },
  307. {
  308. .ctl_name = NET_DECNET_DN_COUNT,
  309. .procname = "dn_count",
  310. .data = &decnet_dn_count,
  311. .maxlen = sizeof(int),
  312. .mode = 0644,
  313. .proc_handler = &proc_dointvec_minmax,
  314. .strategy = &sysctl_intvec,
  315. .extra1 = &min_state_count,
  316. .extra2 = &max_state_count
  317. },
  318. {
  319. .ctl_name = NET_DECNET_DI_COUNT,
  320. .procname = "di_count",
  321. .data = &decnet_di_count,
  322. .maxlen = sizeof(int),
  323. .mode = 0644,
  324. .proc_handler = &proc_dointvec_minmax,
  325. .strategy = &sysctl_intvec,
  326. .extra1 = &min_state_count,
  327. .extra2 = &max_state_count
  328. },
  329. {
  330. .ctl_name = NET_DECNET_DR_COUNT,
  331. .procname = "dr_count",
  332. .data = &decnet_dr_count,
  333. .maxlen = sizeof(int),
  334. .mode = 0644,
  335. .proc_handler = &proc_dointvec_minmax,
  336. .strategy = &sysctl_intvec,
  337. .extra1 = &min_state_count,
  338. .extra2 = &max_state_count
  339. },
  340. {
  341. .ctl_name = NET_DECNET_DST_GC_INTERVAL,
  342. .procname = "dst_gc_interval",
  343. .data = &decnet_dst_gc_interval,
  344. .maxlen = sizeof(int),
  345. .mode = 0644,
  346. .proc_handler = &proc_dointvec_minmax,
  347. .strategy = &sysctl_intvec,
  348. .extra1 = &min_decnet_dst_gc_interval,
  349. .extra2 = &max_decnet_dst_gc_interval
  350. },
  351. {
  352. .ctl_name = NET_DECNET_NO_FC_MAX_CWND,
  353. .procname = "no_fc_max_cwnd",
  354. .data = &decnet_no_fc_max_cwnd,
  355. .maxlen = sizeof(int),
  356. .mode = 0644,
  357. .proc_handler = &proc_dointvec_minmax,
  358. .strategy = &sysctl_intvec,
  359. .extra1 = &min_decnet_no_fc_max_cwnd,
  360. .extra2 = &max_decnet_no_fc_max_cwnd
  361. },
  362. {
  363. .ctl_name = NET_DECNET_MEM,
  364. .procname = "decnet_mem",
  365. .data = &sysctl_decnet_mem,
  366. .maxlen = sizeof(sysctl_decnet_mem),
  367. .mode = 0644,
  368. .proc_handler = &proc_dointvec,
  369. .strategy = &sysctl_intvec,
  370. },
  371. {
  372. .ctl_name = NET_DECNET_RMEM,
  373. .procname = "decnet_rmem",
  374. .data = &sysctl_decnet_rmem,
  375. .maxlen = sizeof(sysctl_decnet_rmem),
  376. .mode = 0644,
  377. .proc_handler = &proc_dointvec,
  378. .strategy = &sysctl_intvec,
  379. },
  380. {
  381. .ctl_name = NET_DECNET_WMEM,
  382. .procname = "decnet_wmem",
  383. .data = &sysctl_decnet_wmem,
  384. .maxlen = sizeof(sysctl_decnet_wmem),
  385. .mode = 0644,
  386. .proc_handler = &proc_dointvec,
  387. .strategy = &sysctl_intvec,
  388. },
  389. {
  390. .ctl_name = NET_DECNET_DEBUG_LEVEL,
  391. .procname = "debug",
  392. .data = &decnet_debug_level,
  393. .maxlen = sizeof(int),
  394. .mode = 0644,
  395. .proc_handler = &proc_dointvec,
  396. .strategy = &sysctl_intvec,
  397. },
  398. {0}
  399. };
  400. static ctl_table dn_dir_table[] = {
  401. {
  402. .ctl_name = NET_DECNET,
  403. .procname = "decnet",
  404. .mode = 0555,
  405. .child = dn_table},
  406. {0}
  407. };
  408. static ctl_table dn_root_table[] = {
  409. {
  410. .ctl_name = CTL_NET,
  411. .procname = "net",
  412. .mode = 0555,
  413. .child = dn_dir_table
  414. },
  415. {0}
  416. };
  417. void dn_register_sysctl(void)
  418. {
  419. dn_table_header = register_sysctl_table(dn_root_table);
  420. }
  421. void dn_unregister_sysctl(void)
  422. {
  423. unregister_sysctl_table(dn_table_header);
  424. }
  425. #else /* CONFIG_SYSCTL */
  426. void dn_unregister_sysctl(void)
  427. {
  428. }
  429. void dn_register_sysctl(void)
  430. {
  431. }
  432. #endif