Loading...
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/slab.h>
11#include <linux/sysctl.h>
12#include <linux/spinlock.h>
13#include <net/ax25.h>
14
15static int min_ipdefmode[1], max_ipdefmode[] = {1};
16static int min_axdefmode[1], max_axdefmode[] = {1};
17static int min_backoff[1], max_backoff[] = {2};
18static int min_conmode[1], max_conmode[] = {2};
19static int min_window[] = {1}, max_window[] = {7};
20static int min_ewindow[] = {1}, max_ewindow[] = {63};
21static int min_t1[] = {1}, max_t1[] = {30000};
22static int min_t2[] = {1}, max_t2[] = {20000};
23static int min_t3[1], max_t3[] = {3600000};
24static int min_idle[1], max_idle[] = {65535000};
25static int min_n2[] = {1}, max_n2[] = {31};
26static int min_paclen[] = {1}, max_paclen[] = {512};
27static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
28#ifdef CONFIG_AX25_DAMA_SLAVE
29static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
30#endif
31
32static struct ctl_table_header *ax25_table_header;
33
34static ctl_table *ax25_table;
35static int ax25_table_size;
36
37static struct ctl_path ax25_path[] = {
38 { .procname = "net", },
39 { .procname = "ax25", },
40 { }
41};
42
43static const ctl_table ax25_param_table[] = {
44 {
45 .procname = "ip_default_mode",
46 .maxlen = sizeof(int),
47 .mode = 0644,
48 .proc_handler = proc_dointvec_minmax,
49 .extra1 = &min_ipdefmode,
50 .extra2 = &max_ipdefmode
51 },
52 {
53 .procname = "ax25_default_mode",
54 .maxlen = sizeof(int),
55 .mode = 0644,
56 .proc_handler = proc_dointvec_minmax,
57 .extra1 = &min_axdefmode,
58 .extra2 = &max_axdefmode
59 },
60 {
61 .procname = "backoff_type",
62 .maxlen = sizeof(int),
63 .mode = 0644,
64 .proc_handler = proc_dointvec_minmax,
65 .extra1 = &min_backoff,
66 .extra2 = &max_backoff
67 },
68 {
69 .procname = "connect_mode",
70 .maxlen = sizeof(int),
71 .mode = 0644,
72 .proc_handler = proc_dointvec_minmax,
73 .extra1 = &min_conmode,
74 .extra2 = &max_conmode
75 },
76 {
77 .procname = "standard_window_size",
78 .maxlen = sizeof(int),
79 .mode = 0644,
80 .proc_handler = proc_dointvec_minmax,
81 .extra1 = &min_window,
82 .extra2 = &max_window
83 },
84 {
85 .procname = "extended_window_size",
86 .maxlen = sizeof(int),
87 .mode = 0644,
88 .proc_handler = proc_dointvec_minmax,
89 .extra1 = &min_ewindow,
90 .extra2 = &max_ewindow
91 },
92 {
93 .procname = "t1_timeout",
94 .maxlen = sizeof(int),
95 .mode = 0644,
96 .proc_handler = proc_dointvec_minmax,
97 .extra1 = &min_t1,
98 .extra2 = &max_t1
99 },
100 {
101 .procname = "t2_timeout",
102 .maxlen = sizeof(int),
103 .mode = 0644,
104 .proc_handler = proc_dointvec_minmax,
105 .extra1 = &min_t2,
106 .extra2 = &max_t2
107 },
108 {
109 .procname = "t3_timeout",
110 .maxlen = sizeof(int),
111 .mode = 0644,
112 .proc_handler = proc_dointvec_minmax,
113 .extra1 = &min_t3,
114 .extra2 = &max_t3
115 },
116 {
117 .procname = "idle_timeout",
118 .maxlen = sizeof(int),
119 .mode = 0644,
120 .proc_handler = proc_dointvec_minmax,
121 .extra1 = &min_idle,
122 .extra2 = &max_idle
123 },
124 {
125 .procname = "maximum_retry_count",
126 .maxlen = sizeof(int),
127 .mode = 0644,
128 .proc_handler = proc_dointvec_minmax,
129 .extra1 = &min_n2,
130 .extra2 = &max_n2
131 },
132 {
133 .procname = "maximum_packet_length",
134 .maxlen = sizeof(int),
135 .mode = 0644,
136 .proc_handler = proc_dointvec_minmax,
137 .extra1 = &min_paclen,
138 .extra2 = &max_paclen
139 },
140 {
141 .procname = "protocol",
142 .maxlen = sizeof(int),
143 .mode = 0644,
144 .proc_handler = proc_dointvec_minmax,
145 .extra1 = &min_proto,
146 .extra2 = &max_proto
147 },
148#ifdef CONFIG_AX25_DAMA_SLAVE
149 {
150 .procname = "dama_slave_timeout",
151 .maxlen = sizeof(int),
152 .mode = 0644,
153 .proc_handler = proc_dointvec_minmax,
154 .extra1 = &min_ds_timeout,
155 .extra2 = &max_ds_timeout
156 },
157#endif
158
159 { } /* that's all, folks! */
160};
161
162void ax25_register_sysctl(void)
163{
164 ax25_dev *ax25_dev;
165 int n, k;
166
167 spin_lock_bh(&ax25_dev_lock);
168 for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next)
169 ax25_table_size += sizeof(ctl_table);
170
171 if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
172 spin_unlock_bh(&ax25_dev_lock);
173 return;
174 }
175
176 for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
177 struct ctl_table *child = kmemdup(ax25_param_table,
178 sizeof(ax25_param_table),
179 GFP_ATOMIC);
180 if (!child) {
181 while (n--)
182 kfree(ax25_table[n].child);
183 kfree(ax25_table);
184 spin_unlock_bh(&ax25_dev_lock);
185 return;
186 }
187 ax25_table[n].child = ax25_dev->systable = child;
188 ax25_table[n].procname = ax25_dev->dev->name;
189 ax25_table[n].mode = 0555;
190
191
192 for (k = 0; k < AX25_MAX_VALUES; k++)
193 child[k].data = &ax25_dev->values[k];
194
195 n++;
196 }
197 spin_unlock_bh(&ax25_dev_lock);
198
199 ax25_table_header = register_sysctl_paths(ax25_path, ax25_table);
200}
201
202void ax25_unregister_sysctl(void)
203{
204 ctl_table *p;
205 unregister_sysctl_table(ax25_table_header);
206
207 for (p = ax25_table; p->procname; p++)
208 kfree(p->child);
209 kfree(ax25_table);
210}
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 *
4 * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
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
12static int min_ipdefmode[1], max_ipdefmode[] = {1};
13static int min_axdefmode[1], max_axdefmode[] = {1};
14static int min_backoff[1], max_backoff[] = {2};
15static int min_conmode[1], max_conmode[] = {2};
16static int min_window[] = {1}, max_window[] = {7};
17static int min_ewindow[] = {1}, max_ewindow[] = {63};
18static int min_t1[] = {1}, max_t1[] = {30000};
19static int min_t2[] = {1}, max_t2[] = {20000};
20static int min_t3[1], max_t3[] = {3600000};
21static int min_idle[1], max_idle[] = {65535000};
22static int min_n2[] = {1}, max_n2[] = {31};
23static int min_paclen[] = {1}, max_paclen[] = {512};
24static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
25#ifdef CONFIG_AX25_DAMA_SLAVE
26static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
27#endif
28
29static const struct ctl_table ax25_param_table[] = {
30 {
31 .procname = "ip_default_mode",
32 .maxlen = sizeof(int),
33 .mode = 0644,
34 .proc_handler = proc_dointvec_minmax,
35 .extra1 = &min_ipdefmode,
36 .extra2 = &max_ipdefmode
37 },
38 {
39 .procname = "ax25_default_mode",
40 .maxlen = sizeof(int),
41 .mode = 0644,
42 .proc_handler = proc_dointvec_minmax,
43 .extra1 = &min_axdefmode,
44 .extra2 = &max_axdefmode
45 },
46 {
47 .procname = "backoff_type",
48 .maxlen = sizeof(int),
49 .mode = 0644,
50 .proc_handler = proc_dointvec_minmax,
51 .extra1 = &min_backoff,
52 .extra2 = &max_backoff
53 },
54 {
55 .procname = "connect_mode",
56 .maxlen = sizeof(int),
57 .mode = 0644,
58 .proc_handler = proc_dointvec_minmax,
59 .extra1 = &min_conmode,
60 .extra2 = &max_conmode
61 },
62 {
63 .procname = "standard_window_size",
64 .maxlen = sizeof(int),
65 .mode = 0644,
66 .proc_handler = proc_dointvec_minmax,
67 .extra1 = &min_window,
68 .extra2 = &max_window
69 },
70 {
71 .procname = "extended_window_size",
72 .maxlen = sizeof(int),
73 .mode = 0644,
74 .proc_handler = proc_dointvec_minmax,
75 .extra1 = &min_ewindow,
76 .extra2 = &max_ewindow
77 },
78 {
79 .procname = "t1_timeout",
80 .maxlen = sizeof(int),
81 .mode = 0644,
82 .proc_handler = proc_dointvec_minmax,
83 .extra1 = &min_t1,
84 .extra2 = &max_t1
85 },
86 {
87 .procname = "t2_timeout",
88 .maxlen = sizeof(int),
89 .mode = 0644,
90 .proc_handler = proc_dointvec_minmax,
91 .extra1 = &min_t2,
92 .extra2 = &max_t2
93 },
94 {
95 .procname = "t3_timeout",
96 .maxlen = sizeof(int),
97 .mode = 0644,
98 .proc_handler = proc_dointvec_minmax,
99 .extra1 = &min_t3,
100 .extra2 = &max_t3
101 },
102 {
103 .procname = "idle_timeout",
104 .maxlen = sizeof(int),
105 .mode = 0644,
106 .proc_handler = proc_dointvec_minmax,
107 .extra1 = &min_idle,
108 .extra2 = &max_idle
109 },
110 {
111 .procname = "maximum_retry_count",
112 .maxlen = sizeof(int),
113 .mode = 0644,
114 .proc_handler = proc_dointvec_minmax,
115 .extra1 = &min_n2,
116 .extra2 = &max_n2
117 },
118 {
119 .procname = "maximum_packet_length",
120 .maxlen = sizeof(int),
121 .mode = 0644,
122 .proc_handler = proc_dointvec_minmax,
123 .extra1 = &min_paclen,
124 .extra2 = &max_paclen
125 },
126 {
127 .procname = "protocol",
128 .maxlen = sizeof(int),
129 .mode = 0644,
130 .proc_handler = proc_dointvec_minmax,
131 .extra1 = &min_proto,
132 .extra2 = &max_proto
133 },
134#ifdef CONFIG_AX25_DAMA_SLAVE
135 {
136 .procname = "dama_slave_timeout",
137 .maxlen = sizeof(int),
138 .mode = 0644,
139 .proc_handler = proc_dointvec_minmax,
140 .extra1 = &min_ds_timeout,
141 .extra2 = &max_ds_timeout
142 },
143#endif
144};
145
146int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
147{
148 char path[sizeof("net/ax25/") + IFNAMSIZ];
149 int k;
150 struct ctl_table *table;
151
152 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
153 if (!table)
154 return -ENOMEM;
155
156 BUILD_BUG_ON(ARRAY_SIZE(ax25_param_table) != AX25_MAX_VALUES);
157 for (k = 0; k < AX25_MAX_VALUES; k++)
158 table[k].data = &ax25_dev->values[k];
159
160 snprintf(path, sizeof(path), "net/ax25/%s", ax25_dev->dev->name);
161 ax25_dev->sysheader = register_net_sysctl_sz(&init_net, path, table,
162 ARRAY_SIZE(ax25_param_table));
163 if (!ax25_dev->sysheader) {
164 kfree(table);
165 return -ENOMEM;
166 }
167 return 0;
168}
169
170void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev)
171{
172 struct ctl_table_header *header = ax25_dev->sysheader;
173 const struct ctl_table *table;
174
175 if (header) {
176 ax25_dev->sysheader = NULL;
177 table = header->ctl_table_arg;
178 unregister_net_sysctl_table(header);
179 kfree(table);
180 }
181}