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