867d42537979d6c320c17aefa514c378f2f8fcc2
[linux-3.10.git] / net / ax25 / sysctl_net_ax25.c
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
14 static int min_ipdefmode[1],            max_ipdefmode[] = {1};
15 static int min_axdefmode[1],            max_axdefmode[] = {1};
16 static int min_backoff[1],              max_backoff[] = {2};
17 static int min_conmode[1],              max_conmode[] = {2};
18 static int min_window[] = {1},          max_window[] = {7};
19 static int min_ewindow[] = {1},         max_ewindow[] = {63};
20 static int min_t1[] = {1},              max_t1[] = {30000};
21 static int min_t2[] = {1},              max_t2[] = {20000};
22 static int min_t3[1],                   max_t3[] = {3600000};
23 static int min_idle[1],                 max_idle[] = {65535000};
24 static int min_n2[] = {1},              max_n2[] = {31};
25 static int min_paclen[] = {1},          max_paclen[] = {512};
26 static int min_proto[1],                max_proto[] = { AX25_PROTO_MAX };
27 static int min_ds_timeout[1],           max_ds_timeout[] = {65535000};
28
29 static struct ctl_table_header *ax25_table_header;
30
31 static ctl_table *ax25_table;
32 static int ax25_table_size;
33
34 static ctl_table ax25_dir_table[] = {
35         {
36                 .ctl_name       = NET_AX25,
37                 .procname       = "ax25",
38                 .mode           = 0555,
39         },
40         { .ctl_name = 0 }
41 };
42
43 static ctl_table ax25_root_table[] = {
44         {
45                 .ctl_name       = CTL_NET,
46                 .procname       = "net",
47                 .mode           = 0555,
48                 .child          = ax25_dir_table
49         },
50         { .ctl_name = 0 }
51 };
52
53 static const ctl_table ax25_param_table[] = {
54         {
55                 .ctl_name       = NET_AX25_IP_DEFAULT_MODE,
56                 .procname       = "ip_default_mode",
57                 .maxlen         = sizeof(int),
58                 .mode           = 0644,
59                 .proc_handler   = &proc_dointvec_minmax,
60                 .strategy       = &sysctl_intvec,
61                 .extra1         = &min_ipdefmode,
62                 .extra2         = &max_ipdefmode
63         },
64         {
65                 .ctl_name       = NET_AX25_DEFAULT_MODE,
66                 .procname       = "ax25_default_mode",
67                 .maxlen         = sizeof(int),
68                 .mode           = 0644,
69                 .proc_handler   = &proc_dointvec_minmax,
70                 .strategy       = &sysctl_intvec,
71                 .extra1         = &min_axdefmode,
72                 .extra2         = &max_axdefmode
73         },
74         {
75                 .ctl_name       = NET_AX25_BACKOFF_TYPE,
76                 .procname       = "backoff_type",
77                 .maxlen         = sizeof(int),
78                 .mode           = 0644,
79                 .proc_handler   = &proc_dointvec_minmax,
80                 .strategy       = &sysctl_intvec,
81                 .extra1         = &min_backoff,
82                 .extra2         = &max_backoff
83         },
84         {
85                 .ctl_name       = NET_AX25_CONNECT_MODE,
86                 .procname       = "connect_mode",
87                 .maxlen         = sizeof(int),
88                 .mode           = 0644,
89                 .proc_handler   = &proc_dointvec_minmax,
90                 .strategy       = &sysctl_intvec,
91                 .extra1         = &min_conmode,
92                 .extra2         = &max_conmode
93         },
94         {
95                 .ctl_name       = NET_AX25_STANDARD_WINDOW,
96                 .procname       = "standard_window_size",
97                 .maxlen         = sizeof(int),
98                 .mode           = 0644,
99                 .proc_handler   = &proc_dointvec_minmax,
100                 .strategy       = &sysctl_intvec,
101                 .extra1         = &min_window,
102                 .extra2         = &max_window
103         },
104         {
105                 .ctl_name       = NET_AX25_EXTENDED_WINDOW,
106                 .procname       = "extended_window_size",
107                 .maxlen         = sizeof(int),
108                 .mode           = 0644,
109                 .proc_handler   = &proc_dointvec_minmax,
110                 .strategy       = &sysctl_intvec,
111                 .extra1         = &min_ewindow,
112                 .extra2         = &max_ewindow
113         },
114         {
115                 .ctl_name       = NET_AX25_T1_TIMEOUT,
116                 .procname       = "t1_timeout",
117                 .maxlen         = sizeof(int),
118                 .mode           = 0644,
119                 .proc_handler   = &proc_dointvec_minmax,
120                 .strategy       = &sysctl_intvec,
121                 .extra1         = &min_t1,
122                 .extra2         = &max_t1
123         },
124         {
125                 .ctl_name       = NET_AX25_T2_TIMEOUT,
126                 .procname       = "t2_timeout",
127                 .maxlen         = sizeof(int),
128                 .mode           = 0644,
129                 .proc_handler   = &proc_dointvec_minmax,
130                 .strategy       = &sysctl_intvec,
131                 .extra1         = &min_t2,
132                 .extra2         = &max_t2
133         },
134         {
135                 .ctl_name       = NET_AX25_T3_TIMEOUT,
136                 .procname       = "t3_timeout",
137                 .maxlen         = sizeof(int),
138                 .mode           = 0644,
139                 .proc_handler   = &proc_dointvec_minmax,
140                 .strategy       = &sysctl_intvec,
141                 .extra1         = &min_t3,
142                 .extra2         = &max_t3
143         },
144         {
145                 .ctl_name       = NET_AX25_IDLE_TIMEOUT,
146                 .procname       = "idle_timeout",
147                 .maxlen         = sizeof(int),
148                 .mode           = 0644,
149                 .proc_handler   = &proc_dointvec_minmax,
150                 .strategy       = &sysctl_intvec,
151                 .extra1         = &min_idle,
152                 .extra2         = &max_idle
153         },
154         {
155                 .ctl_name       = NET_AX25_N2,
156                 .procname       = "maximum_retry_count",
157                 .maxlen         = sizeof(int),
158                 .mode           = 0644,
159                 .proc_handler   = &proc_dointvec_minmax,
160                 .strategy       = &sysctl_intvec,
161                 .extra1         = &min_n2,
162                 .extra2         = &max_n2
163         },
164         {
165                 .ctl_name       = NET_AX25_PACLEN,
166                 .procname       = "maximum_packet_length",
167                 .maxlen         = sizeof(int),
168                 .mode           = 0644,
169                 .proc_handler   = &proc_dointvec_minmax,
170                 .strategy       = &sysctl_intvec,
171                 .extra1         = &min_paclen,
172                 .extra2         = &max_paclen
173         },
174         {
175                 .ctl_name       = NET_AX25_PROTOCOL,
176                 .procname       = "protocol",
177                 .maxlen         = sizeof(int),
178                 .mode           = 0644,
179                 .proc_handler   = &proc_dointvec_minmax,
180                 .strategy       = &sysctl_intvec,
181                 .extra1         = &min_proto,
182                 .extra2         = &max_proto
183         },
184         {
185                 .ctl_name       = NET_AX25_DAMA_SLAVE_TIMEOUT,
186                 .procname       = "dama_slave_timeout",
187                 .maxlen         = sizeof(int),
188                 .mode           = 0644,
189                 .proc_handler   = &proc_dointvec_minmax,
190                 .strategy       = &sysctl_intvec,
191                 .extra1         = &min_ds_timeout,
192                 .extra2         = &max_ds_timeout
193         },
194         { .ctl_name = 0 }       /* that's all, folks! */
195 };
196
197 void ax25_register_sysctl(void)
198 {
199         ax25_dev *ax25_dev;
200         int n, k;
201
202         spin_lock_bh(&ax25_dev_lock);
203         for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
204                 ax25_table_size += sizeof(ctl_table);
205
206         if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
207                 spin_unlock_bh(&ax25_dev_lock);
208                 return;
209         }
210
211         for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
212                 ctl_table *child = kmalloc(sizeof(ax25_param_table), GFP_ATOMIC);
213                 if (!child) {
214                         while (n--)
215                                 kfree(ax25_table[n].child);
216                         kfree(ax25_table);
217                         spin_unlock_bh(&ax25_dev_lock);
218                         return;
219                 }
220                 memcpy(child, ax25_param_table, sizeof(ax25_param_table));
221                 ax25_table[n].child = ax25_dev->systable = child;
222                 ax25_table[n].ctl_name     = n + 1;
223                 ax25_table[n].procname     = ax25_dev->dev->name;
224                 ax25_table[n].mode         = 0555;
225
226 #ifndef CONFIG_AX25_DAMA_SLAVE
227                 /*
228                  * We do not wish to have a representation of this parameter
229                  * in /proc/sys/ when configured *not* to include the
230                  * AX.25 DAMA slave code, do we?
231                  */
232
233                 child[AX25_VALUES_DS_TIMEOUT].procname = NULL;
234 #endif
235
236                 child[AX25_MAX_VALUES].ctl_name = 0;    /* just in case... */
237
238                 for (k = 0; k < AX25_MAX_VALUES; k++)
239                         child[k].data = &ax25_dev->values[k];
240
241                 n++;
242         }
243         spin_unlock_bh(&ax25_dev_lock);
244
245         ax25_dir_table[0].child = ax25_table;
246
247         ax25_table_header = register_sysctl_table(ax25_root_table, 1);
248 }
249
250 void ax25_unregister_sysctl(void)
251 {
252         ctl_table *p;
253         unregister_sysctl_table(ax25_table_header);
254
255         ax25_dir_table[0].child = NULL;
256         for (p = ax25_table; p->ctl_name; p++)
257                 kfree(p->child);
258         kfree(ax25_table);
259 }