sysctl_net_ax25.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
  8. */
  9. #include <linux/mm.h>
  10. #include <linux/sysctl.h>
  11. #include <linux/spinlock.h>
  12. #include <net/ax25.h>
  13. static int min_ipdefmode[1], max_ipdefmode[] = {1};
  14. static int min_axdefmode[1], max_axdefmode[] = {1};
  15. static int min_backoff[1], max_backoff[] = {2};
  16. static int min_conmode[1], max_conmode[] = {2};
  17. static int min_window[] = {1}, max_window[] = {7};
  18. static int min_ewindow[] = {1}, max_ewindow[] = {63};
  19. static int min_t1[] = {1}, max_t1[] = {30000};
  20. static int min_t2[] = {1}, max_t2[] = {20000};
  21. static int min_t3[1], max_t3[] = {3600000};
  22. static int min_idle[1], max_idle[] = {65535000};
  23. static int min_n2[] = {1}, max_n2[] = {31};
  24. static int min_paclen[] = {1}, max_paclen[] = {512};
  25. static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
  26. #ifdef CONFIG_AX25_DAMA_SLAVE
  27. static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
  28. #endif
  29. static struct ctl_table_header *ax25_table_header;
  30. static ctl_table *ax25_table;
  31. static int ax25_table_size;
  32. static struct ctl_path ax25_path[] = {
  33. { .procname = "net", },
  34. { .procname = "ax25", },
  35. { }
  36. };
  37. static const ctl_table ax25_param_table[] = {
  38. {
  39. .procname = "ip_default_mode",
  40. .maxlen = sizeof(int),
  41. .mode = 0644,
  42. .proc_handler = proc_dointvec_minmax,
  43. .extra1 = &min_ipdefmode,
  44. .extra2 = &max_ipdefmode
  45. },
  46. {
  47. .procname = "ax25_default_mode",
  48. .maxlen = sizeof(int),
  49. .mode = 0644,
  50. .proc_handler = proc_dointvec_minmax,
  51. .extra1 = &min_axdefmode,
  52. .extra2 = &max_axdefmode
  53. },
  54. {
  55. .procname = "backoff_type",
  56. .maxlen = sizeof(int),
  57. .mode = 0644,
  58. .proc_handler = proc_dointvec_minmax,
  59. .extra1 = &min_backoff,
  60. .extra2 = &max_backoff
  61. },
  62. {
  63. .procname = "connect_mode",
  64. .maxlen = sizeof(int),
  65. .mode = 0644,
  66. .proc_handler = proc_dointvec_minmax,
  67. .extra1 = &min_conmode,
  68. .extra2 = &max_conmode
  69. },
  70. {
  71. .procname = "standard_window_size",
  72. .maxlen = sizeof(int),
  73. .mode = 0644,
  74. .proc_handler = proc_dointvec_minmax,
  75. .extra1 = &min_window,
  76. .extra2 = &max_window
  77. },
  78. {
  79. .procname = "extended_window_size",
  80. .maxlen = sizeof(int),
  81. .mode = 0644,
  82. .proc_handler = proc_dointvec_minmax,
  83. .extra1 = &min_ewindow,
  84. .extra2 = &max_ewindow
  85. },
  86. {
  87. .procname = "t1_timeout",
  88. .maxlen = sizeof(int),
  89. .mode = 0644,
  90. .proc_handler = proc_dointvec_minmax,
  91. .extra1 = &min_t1,
  92. .extra2 = &max_t1
  93. },
  94. {
  95. .procname = "t2_timeout",
  96. .maxlen = sizeof(int),
  97. .mode = 0644,
  98. .proc_handler = proc_dointvec_minmax,
  99. .extra1 = &min_t2,
  100. .extra2 = &max_t2
  101. },
  102. {
  103. .procname = "t3_timeout",
  104. .maxlen = sizeof(int),
  105. .mode = 0644,
  106. .proc_handler = proc_dointvec_minmax,
  107. .extra1 = &min_t3,
  108. .extra2 = &max_t3
  109. },
  110. {
  111. .procname = "idle_timeout",
  112. .maxlen = sizeof(int),
  113. .mode = 0644,
  114. .proc_handler = proc_dointvec_minmax,
  115. .extra1 = &min_idle,
  116. .extra2 = &max_idle
  117. },
  118. {
  119. .procname = "maximum_retry_count",
  120. .maxlen = sizeof(int),
  121. .mode = 0644,
  122. .proc_handler = proc_dointvec_minmax,
  123. .extra1 = &min_n2,
  124. .extra2 = &max_n2
  125. },
  126. {
  127. .procname = "maximum_packet_length",
  128. .maxlen = sizeof(int),
  129. .mode = 0644,
  130. .proc_handler = proc_dointvec_minmax,
  131. .extra1 = &min_paclen,
  132. .extra2 = &max_paclen
  133. },
  134. {
  135. .procname = "protocol",
  136. .maxlen = sizeof(int),
  137. .mode = 0644,
  138. .proc_handler = proc_dointvec_minmax,
  139. .extra1 = &min_proto,
  140. .extra2 = &max_proto
  141. },
  142. #ifdef CONFIG_AX25_DAMA_SLAVE
  143. {
  144. .procname = "dama_slave_timeout",
  145. .maxlen = sizeof(int),
  146. .mode = 0644,
  147. .proc_handler = proc_dointvec_minmax,
  148. .extra1 = &min_ds_timeout,
  149. .extra2 = &max_ds_timeout
  150. },
  151. #endif
  152. { } /* that's all, folks! */
  153. };
  154. void ax25_register_sysctl(void)
  155. {
  156. ax25_dev *ax25_dev;
  157. int n, k;
  158. spin_lock_bh(&ax25_dev_lock);
  159. for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
  160. ax25_table_size += sizeof(ctl_table);
  161. if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
  162. spin_unlock_bh(&ax25_dev_lock);
  163. return;
  164. }
  165. for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
  166. struct ctl_table *child = kmemdup(ax25_param_table,
  167. sizeof(ax25_param_table),
  168. GFP_ATOMIC);
  169. if (!child) {
  170. while (n--)
  171. kfree(ax25_table[n].child);
  172. kfree(ax25_table);
  173. spin_unlock_bh(&ax25_dev_lock);
  174. return;
  175. }
  176. ax25_table[n].child = ax25_dev->systable = child;
  177. ax25_table[n].procname = ax25_dev->dev->name;
  178. ax25_table[n].mode = 0555;
  179. for (k = 0; k < AX25_MAX_VALUES; k++)
  180. child[k].data = &ax25_dev->values[k];
  181. n++;
  182. }
  183. spin_unlock_bh(&ax25_dev_lock);
  184. ax25_table_header = register_sysctl_paths(ax25_path, ax25_table);
  185. }
  186. void ax25_unregister_sysctl(void)
  187. {
  188. ctl_table *p;
  189. unregister_sysctl_table(ax25_table_header);
  190. for (p = ax25_table; p->procname; p++)
  191. kfree(p->child);
  192. kfree(ax25_table);
  193. }