sysctl_net_decnet.c 10 KB

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