blob: f288fc4aef9bcd64a16add98a0b7ed86acb232da [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 };
Ralf Baechlee1fdb5b2006-05-03 23:27:16 -070027static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29static struct ctl_table_header *ax25_table_header;
30
31static ctl_table *ax25_table;
32static int ax25_table_size;
33
Pavel Emelyanovc6995bd2008-01-09 00:32:21 -080034static struct ctl_path ax25_path[] = {
35 { .procname = "net", .ctl_name = CTL_NET, },
36 { .procname = "ax25", .ctl_name = NET_AX25, },
37 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -070038};
Ralf Baechleffb20842008-08-05 18:46:57 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static const ctl_table ax25_param_table[] = {
41 {
42 .ctl_name = NET_AX25_IP_DEFAULT_MODE,
43 .procname = "ip_default_mode",
44 .maxlen = sizeof(int),
45 .mode = 0644,
46 .proc_handler = &proc_dointvec_minmax,
47 .strategy = &sysctl_intvec,
48 .extra1 = &min_ipdefmode,
49 .extra2 = &max_ipdefmode
50 },
51 {
52 .ctl_name = NET_AX25_DEFAULT_MODE,
53 .procname = "ax25_default_mode",
54 .maxlen = sizeof(int),
55 .mode = 0644,
56 .proc_handler = &proc_dointvec_minmax,
57 .strategy = &sysctl_intvec,
58 .extra1 = &min_axdefmode,
59 .extra2 = &max_axdefmode
60 },
61 {
62 .ctl_name = NET_AX25_BACKOFF_TYPE,
63 .procname = "backoff_type",
64 .maxlen = sizeof(int),
65 .mode = 0644,
66 .proc_handler = &proc_dointvec_minmax,
67 .strategy = &sysctl_intvec,
68 .extra1 = &min_backoff,
69 .extra2 = &max_backoff
70 },
71 {
72 .ctl_name = NET_AX25_CONNECT_MODE,
73 .procname = "connect_mode",
74 .maxlen = sizeof(int),
75 .mode = 0644,
76 .proc_handler = &proc_dointvec_minmax,
77 .strategy = &sysctl_intvec,
78 .extra1 = &min_conmode,
79 .extra2 = &max_conmode
80 },
81 {
82 .ctl_name = NET_AX25_STANDARD_WINDOW,
83 .procname = "standard_window_size",
84 .maxlen = sizeof(int),
85 .mode = 0644,
86 .proc_handler = &proc_dointvec_minmax,
87 .strategy = &sysctl_intvec,
88 .extra1 = &min_window,
89 .extra2 = &max_window
90 },
91 {
92 .ctl_name = NET_AX25_EXTENDED_WINDOW,
93 .procname = "extended_window_size",
94 .maxlen = sizeof(int),
95 .mode = 0644,
96 .proc_handler = &proc_dointvec_minmax,
97 .strategy = &sysctl_intvec,
98 .extra1 = &min_ewindow,
99 .extra2 = &max_ewindow
100 },
101 {
102 .ctl_name = NET_AX25_T1_TIMEOUT,
103 .procname = "t1_timeout",
104 .maxlen = sizeof(int),
105 .mode = 0644,
106 .proc_handler = &proc_dointvec_minmax,
107 .strategy = &sysctl_intvec,
108 .extra1 = &min_t1,
109 .extra2 = &max_t1
110 },
111 {
112 .ctl_name = NET_AX25_T2_TIMEOUT,
113 .procname = "t2_timeout",
114 .maxlen = sizeof(int),
115 .mode = 0644,
116 .proc_handler = &proc_dointvec_minmax,
117 .strategy = &sysctl_intvec,
118 .extra1 = &min_t2,
119 .extra2 = &max_t2
120 },
121 {
122 .ctl_name = NET_AX25_T3_TIMEOUT,
123 .procname = "t3_timeout",
124 .maxlen = sizeof(int),
125 .mode = 0644,
126 .proc_handler = &proc_dointvec_minmax,
127 .strategy = &sysctl_intvec,
128 .extra1 = &min_t3,
129 .extra2 = &max_t3
130 },
131 {
132 .ctl_name = NET_AX25_IDLE_TIMEOUT,
133 .procname = "idle_timeout",
134 .maxlen = sizeof(int),
135 .mode = 0644,
136 .proc_handler = &proc_dointvec_minmax,
137 .strategy = &sysctl_intvec,
138 .extra1 = &min_idle,
139 .extra2 = &max_idle
140 },
141 {
142 .ctl_name = NET_AX25_N2,
143 .procname = "maximum_retry_count",
144 .maxlen = sizeof(int),
145 .mode = 0644,
146 .proc_handler = &proc_dointvec_minmax,
147 .strategy = &sysctl_intvec,
148 .extra1 = &min_n2,
149 .extra2 = &max_n2
150 },
151 {
152 .ctl_name = NET_AX25_PACLEN,
153 .procname = "maximum_packet_length",
154 .maxlen = sizeof(int),
155 .mode = 0644,
156 .proc_handler = &proc_dointvec_minmax,
157 .strategy = &sysctl_intvec,
158 .extra1 = &min_paclen,
159 .extra2 = &max_paclen
160 },
161 {
162 .ctl_name = NET_AX25_PROTOCOL,
163 .procname = "protocol",
164 .maxlen = sizeof(int),
165 .mode = 0644,
166 .proc_handler = &proc_dointvec_minmax,
167 .strategy = &sysctl_intvec,
168 .extra1 = &min_proto,
169 .extra2 = &max_proto
170 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700171#ifdef CONFIG_AX25_DAMA_SLAVE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 {
173 .ctl_name = NET_AX25_DAMA_SLAVE_TIMEOUT,
174 .procname = "dama_slave_timeout",
175 .maxlen = sizeof(int),
176 .mode = 0644,
177 .proc_handler = &proc_dointvec_minmax,
178 .strategy = &sysctl_intvec,
179 .extra1 = &min_ds_timeout,
180 .extra2 = &max_ds_timeout
181 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700182#endif
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 { .ctl_name = 0 } /* that's all, folks! */
185};
186
187void ax25_register_sysctl(void)
188{
189 ax25_dev *ax25_dev;
190 int n, k;
191
192 spin_lock_bh(&ax25_dev_lock);
193 for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
194 ax25_table_size += sizeof(ctl_table);
195
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700196 if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 spin_unlock_bh(&ax25_dev_lock);
198 return;
199 }
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 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 -0200202 struct ctl_table *child = kmemdup(ax25_param_table,
203 sizeof(ax25_param_table),
204 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 if (!child) {
206 while (n--)
207 kfree(ax25_table[n].child);
208 kfree(ax25_table);
209 spin_unlock_bh(&ax25_dev_lock);
210 return;
211 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 ax25_table[n].child = ax25_dev->systable = child;
213 ax25_table[n].ctl_name = n + 1;
214 ax25_table[n].procname = ax25_dev->dev->name;
215 ax25_table[n].mode = 0555;
216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 child[AX25_MAX_VALUES].ctl_name = 0; /* just in case... */
218
219 for (k = 0; k < AX25_MAX_VALUES; k++)
220 child[k].data = &ax25_dev->values[k];
221
222 n++;
223 }
224 spin_unlock_bh(&ax25_dev_lock);
225
Pavel Emelyanovc6995bd2008-01-09 00:32:21 -0800226 ax25_table_header = register_sysctl_paths(ax25_path, ax25_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229void ax25_unregister_sysctl(void)
230{
231 ctl_table *p;
232 unregister_sysctl_table(ax25_table_header);
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 for (p = ax25_table; p->ctl_name; p++)
235 kfree(p->child);
236 kfree(ax25_table);
237}