sysctl_net_ax25.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * Copyright (C) 1996 Mike Shaver ([email protected])
  5. */
  6. #include <linux/mm.h>
  7. #include <linux/slab.h>
  8. #include <linux/sysctl.h>
  9. #include <linux/spinlock.h>
  10. #include <net/ax25.h>
  11. static int min_ipdefmode[1], max_ipdefmode[] = {1};
  12. static int min_axdefmode[1], max_axdefmode[] = {1};
  13. static int min_backoff[1], max_backoff[] = {2};
  14. static int min_conmode[1], max_conmode[] = {2};
  15. static int min_window[] = {1}, max_window[] = {7};
  16. static int min_ewindow[] = {1}, max_ewindow[] = {63};
  17. static int min_t1[] = {1}, max_t1[] = {30000};
  18. static int min_t2[] = {1}, max_t2[] = {20000};
  19. static int min_t3[1], max_t3[] = {3600000};
  20. static int min_idle[1], max_idle[] = {65535000};
  21. static int min_n2[] = {1}, max_n2[] = {31};
  22. static int min_paclen[] = {1}, max_paclen[] = {512};
  23. static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
  24. #ifdef CONFIG_AX25_DAMA_SLAVE
  25. static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
  26. #endif
  27. static const struct ctl_table ax25_param_table[] = {
  28. {
  29. .procname = "ip_default_mode",
  30. .maxlen = sizeof(int),
  31. .mode = 0644,
  32. .proc_handler = proc_dointvec_minmax,
  33. .extra1 = &min_ipdefmode,
  34. .extra2 = &max_ipdefmode
  35. },
  36. {
  37. .procname = "ax25_default_mode",
  38. .maxlen = sizeof(int),
  39. .mode = 0644,
  40. .proc_handler = proc_dointvec_minmax,
  41. .extra1 = &min_axdefmode,
  42. .extra2 = &max_axdefmode
  43. },
  44. {
  45. .procname = "backoff_type",
  46. .maxlen = sizeof(int),
  47. .mode = 0644,
  48. .proc_handler = proc_dointvec_minmax,
  49. .extra1 = &min_backoff,
  50. .extra2 = &max_backoff
  51. },
  52. {
  53. .procname = "connect_mode",
  54. .maxlen = sizeof(int),
  55. .mode = 0644,
  56. .proc_handler = proc_dointvec_minmax,
  57. .extra1 = &min_conmode,
  58. .extra2 = &max_conmode
  59. },
  60. {
  61. .procname = "standard_window_size",
  62. .maxlen = sizeof(int),
  63. .mode = 0644,
  64. .proc_handler = proc_dointvec_minmax,
  65. .extra1 = &min_window,
  66. .extra2 = &max_window
  67. },
  68. {
  69. .procname = "extended_window_size",
  70. .maxlen = sizeof(int),
  71. .mode = 0644,
  72. .proc_handler = proc_dointvec_minmax,
  73. .extra1 = &min_ewindow,
  74. .extra2 = &max_ewindow
  75. },
  76. {
  77. .procname = "t1_timeout",
  78. .maxlen = sizeof(int),
  79. .mode = 0644,
  80. .proc_handler = proc_dointvec_minmax,
  81. .extra1 = &min_t1,
  82. .extra2 = &max_t1
  83. },
  84. {
  85. .procname = "t2_timeout",
  86. .maxlen = sizeof(int),
  87. .mode = 0644,
  88. .proc_handler = proc_dointvec_minmax,
  89. .extra1 = &min_t2,
  90. .extra2 = &max_t2
  91. },
  92. {
  93. .procname = "t3_timeout",
  94. .maxlen = sizeof(int),
  95. .mode = 0644,
  96. .proc_handler = proc_dointvec_minmax,
  97. .extra1 = &min_t3,
  98. .extra2 = &max_t3
  99. },
  100. {
  101. .procname = "idle_timeout",
  102. .maxlen = sizeof(int),
  103. .mode = 0644,
  104. .proc_handler = proc_dointvec_minmax,
  105. .extra1 = &min_idle,
  106. .extra2 = &max_idle
  107. },
  108. {
  109. .procname = "maximum_retry_count",
  110. .maxlen = sizeof(int),
  111. .mode = 0644,
  112. .proc_handler = proc_dointvec_minmax,
  113. .extra1 = &min_n2,
  114. .extra2 = &max_n2
  115. },
  116. {
  117. .procname = "maximum_packet_length",
  118. .maxlen = sizeof(int),
  119. .mode = 0644,
  120. .proc_handler = proc_dointvec_minmax,
  121. .extra1 = &min_paclen,
  122. .extra2 = &max_paclen
  123. },
  124. {
  125. .procname = "protocol",
  126. .maxlen = sizeof(int),
  127. .mode = 0644,
  128. .proc_handler = proc_dointvec_minmax,
  129. .extra1 = &min_proto,
  130. .extra2 = &max_proto
  131. },
  132. #ifdef CONFIG_AX25_DAMA_SLAVE
  133. {
  134. .procname = "dama_slave_timeout",
  135. .maxlen = sizeof(int),
  136. .mode = 0644,
  137. .proc_handler = proc_dointvec_minmax,
  138. .extra1 = &min_ds_timeout,
  139. .extra2 = &max_ds_timeout
  140. },
  141. #endif
  142. { } /* that's all, folks! */
  143. };
  144. int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
  145. {
  146. char path[sizeof("net/ax25/") + IFNAMSIZ];
  147. int k;
  148. struct ctl_table *table;
  149. table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
  150. if (!table)
  151. return -ENOMEM;
  152. for (k = 0; k < AX25_MAX_VALUES; k++)
  153. table[k].data = &ax25_dev->values[k];
  154. snprintf(path, sizeof(path), "net/ax25/%s", ax25_dev->dev->name);
  155. ax25_dev->sysheader = register_net_sysctl(&init_net, path, table);
  156. if (!ax25_dev->sysheader) {
  157. kfree(table);
  158. return -ENOMEM;
  159. }
  160. return 0;
  161. }
  162. void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev)
  163. {
  164. struct ctl_table_header *header = ax25_dev->sysheader;
  165. struct ctl_table *table;
  166. if (header) {
  167. ax25_dev->sysheader = NULL;
  168. table = header->ctl_table_arg;
  169. unregister_net_sysctl_table(header);
  170. kfree(table);
  171. }
  172. }