blob: 62ee3fb34732840515de53d7932d8eebf09e54e8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/mm.h>
10#include <linux/sysctl.h>
11#include <linux/spinlock.h>
12#include <net/ax25.h>
13
14static int min_ipdefmode[1], max_ipdefmode[] = {1};
15static int min_axdefmode[1], max_axdefmode[] = {1};
16static int min_backoff[1], max_backoff[] = {2};
17static int min_conmode[1], max_conmode[] = {2};
18static int min_window[] = {1}, max_window[] = {7};
19static int min_ewindow[] = {1}, max_ewindow[] = {63};
Ralf Baechlee1fdb5b2006-05-03 23:27:16 -070020static int min_t1[] = {1}, max_t1[] = {30000};
21static int min_t2[] = {1}, max_t2[] = {20000};
22static int min_t3[1], max_t3[] = {3600000};
23static int min_idle[1], max_idle[] = {65535000};
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int min_n2[] = {1}, max_n2[] = {31};
25static int min_paclen[] = {1}, max_paclen[] = {512};
Ralf Baechle DL5RBc7c694d2006-03-19 13:20:06 -080026static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
Ingo Molnare14bec22008-11-25 16:58:19 -080027#ifdef CONFIG_AX25_DAMA_SLAVE
Ralf Baechlee1fdb5b2006-05-03 23:27:16 -070028static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
Ingo Molnare14bec22008-11-25 16:58:19 -080029#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31static struct ctl_table_header *ax25_table_header;
32
33static ctl_table *ax25_table;
34static int ax25_table_size;
35
Pavel Emelyanovc6995bd2008-01-09 00:32:21 -080036static struct ctl_path ax25_path[] = {
37 { .procname = "net", .ctl_name = CTL_NET, },
38 { .procname = "ax25", .ctl_name = NET_AX25, },
39 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
Ralf Baechleffb20842008-08-05 18:46:57 -070041
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static const ctl_table ax25_param_table[] = {
43 {
44 .ctl_name = NET_AX25_IP_DEFAULT_MODE,
45 .procname = "ip_default_mode",
46 .maxlen = sizeof(int),
47 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080048 .proc_handler = proc_dointvec_minmax,
49 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 .extra1 = &min_ipdefmode,
51 .extra2 = &max_ipdefmode
52 },
53 {
54 .ctl_name = NET_AX25_DEFAULT_MODE,
55 .procname = "ax25_default_mode",
56 .maxlen = sizeof(int),
57 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080058 .proc_handler = proc_dointvec_minmax,
59 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 .extra1 = &min_axdefmode,
61 .extra2 = &max_axdefmode
62 },
63 {
64 .ctl_name = NET_AX25_BACKOFF_TYPE,
65 .procname = "backoff_type",
66 .maxlen = sizeof(int),
67 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080068 .proc_handler = proc_dointvec_minmax,
69 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 .extra1 = &min_backoff,
71 .extra2 = &max_backoff
72 },
73 {
74 .ctl_name = NET_AX25_CONNECT_MODE,
75 .procname = "connect_mode",
76 .maxlen = sizeof(int),
77 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080078 .proc_handler = proc_dointvec_minmax,
79 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 .extra1 = &min_conmode,
81 .extra2 = &max_conmode
82 },
83 {
84 .ctl_name = NET_AX25_STANDARD_WINDOW,
85 .procname = "standard_window_size",
86 .maxlen = sizeof(int),
87 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080088 .proc_handler = proc_dointvec_minmax,
89 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 .extra1 = &min_window,
91 .extra2 = &max_window
92 },
93 {
94 .ctl_name = NET_AX25_EXTENDED_WINDOW,
95 .procname = "extended_window_size",
96 .maxlen = sizeof(int),
97 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080098 .proc_handler = proc_dointvec_minmax,
99 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 .extra1 = &min_ewindow,
101 .extra2 = &max_ewindow
102 },
103 {
104 .ctl_name = NET_AX25_T1_TIMEOUT,
105 .procname = "t1_timeout",
106 .maxlen = sizeof(int),
107 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800108 .proc_handler = proc_dointvec_minmax,
109 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 .extra1 = &min_t1,
111 .extra2 = &max_t1
112 },
113 {
114 .ctl_name = NET_AX25_T2_TIMEOUT,
115 .procname = "t2_timeout",
116 .maxlen = sizeof(int),
117 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800118 .proc_handler = proc_dointvec_minmax,
119 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 .extra1 = &min_t2,
121 .extra2 = &max_t2
122 },
123 {
124 .ctl_name = NET_AX25_T3_TIMEOUT,
125 .procname = "t3_timeout",
126 .maxlen = sizeof(int),
127 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800128 .proc_handler = proc_dointvec_minmax,
129 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .extra1 = &min_t3,
131 .extra2 = &max_t3
132 },
133 {
134 .ctl_name = NET_AX25_IDLE_TIMEOUT,
135 .procname = "idle_timeout",
136 .maxlen = sizeof(int),
137 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800138 .proc_handler = proc_dointvec_minmax,
139 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 .extra1 = &min_idle,
141 .extra2 = &max_idle
142 },
143 {
144 .ctl_name = NET_AX25_N2,
145 .procname = "maximum_retry_count",
146 .maxlen = sizeof(int),
147 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800148 .proc_handler = proc_dointvec_minmax,
149 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 .extra1 = &min_n2,
151 .extra2 = &max_n2
152 },
153 {
154 .ctl_name = NET_AX25_PACLEN,
155 .procname = "maximum_packet_length",
156 .maxlen = sizeof(int),
157 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800158 .proc_handler = proc_dointvec_minmax,
159 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 .extra1 = &min_paclen,
161 .extra2 = &max_paclen
162 },
163 {
164 .ctl_name = NET_AX25_PROTOCOL,
165 .procname = "protocol",
166 .maxlen = sizeof(int),
167 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800168 .proc_handler = proc_dointvec_minmax,
169 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 .extra1 = &min_proto,
171 .extra2 = &max_proto
172 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700173#ifdef CONFIG_AX25_DAMA_SLAVE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 {
175 .ctl_name = NET_AX25_DAMA_SLAVE_TIMEOUT,
176 .procname = "dama_slave_timeout",
177 .maxlen = sizeof(int),
178 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800179 .proc_handler = proc_dointvec_minmax,
180 .strategy = sysctl_intvec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 .extra1 = &min_ds_timeout,
182 .extra2 = &max_ds_timeout
183 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700184#endif
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 { .ctl_name = 0 } /* that's all, folks! */
187};
188
189void ax25_register_sysctl(void)
190{
191 ax25_dev *ax25_dev;
192 int n, k;
193
194 spin_lock_bh(&ax25_dev_lock);
195 for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
196 ax25_table_size += sizeof(ctl_table);
197
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700198 if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 spin_unlock_bh(&ax25_dev_lock);
200 return;
201 }
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
Arnaldo Carvalho de Melo0459d70a2006-11-17 12:43:07 -0200204 struct ctl_table *child = kmemdup(ax25_param_table,
205 sizeof(ax25_param_table),
206 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 if (!child) {
208 while (n--)
209 kfree(ax25_table[n].child);
210 kfree(ax25_table);
211 spin_unlock_bh(&ax25_dev_lock);
212 return;
213 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 ax25_table[n].child = ax25_dev->systable = child;
215 ax25_table[n].ctl_name = n + 1;
216 ax25_table[n].procname = ax25_dev->dev->name;
217 ax25_table[n].mode = 0555;
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 child[AX25_MAX_VALUES].ctl_name = 0; /* just in case... */
220
221 for (k = 0; k < AX25_MAX_VALUES; k++)
222 child[k].data = &ax25_dev->values[k];
223
224 n++;
225 }
226 spin_unlock_bh(&ax25_dev_lock);
227
Pavel Emelyanovc6995bd2008-01-09 00:32:21 -0800228 ax25_table_header = register_sysctl_paths(ax25_path, ax25_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
231void ax25_unregister_sysctl(void)
232{
233 ctl_table *p;
234 unregister_sysctl_table(ax25_table_header);
235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 for (p = ax25_table; p->ctl_name; p++)
237 kfree(p->child);
238 kfree(ax25_table);
239}