sysctl_net_decnet.c 10 KB

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