blob: ebe0ef3f1d839c1715dcf3784e8d9148b62820e2 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#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};
Ralf Baechlee1fdb5b2006-05-03 23:27:16 -070021static 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};
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int min_n2[] = {1}, max_n2[] = {31};
26static int min_paclen[] = {1}, max_paclen[] = {512};
Ralf Baechle DL5RBc7c694d2006-03-19 13:20:06 -080027static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
Ingo Molnare14bec22008-11-25 16:58:19 -080028#ifdef CONFIG_AX25_DAMA_SLAVE
Ralf Baechlee1fdb5b2006-05-03 23:27:16 -070029static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
Ingo Molnare14bec22008-11-25 16:58:19 -080030#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32static struct ctl_table_header *ax25_table_header;
33
34static ctl_table *ax25_table;
35static int ax25_table_size;
36
Pavel Emelyanovc6995bd2008-01-09 00:32:21 -080037static struct ctl_path ax25_path[] = {
Eric W. Biedermanf8572d82009-11-05 13:32:03 -080038 { .procname = "net", },
39 { .procname = "ax25", },
Pavel Emelyanovc6995bd2008-01-09 00:32:21 -080040 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -070041};
Ralf Baechleffb20842008-08-05 18:46:57 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static const ctl_table ax25_param_table[] = {
44 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 .procname = "ip_default_mode",
46 .maxlen = sizeof(int),
47 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080048 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 .extra1 = &min_ipdefmode,
50 .extra2 = &max_ipdefmode
51 },
52 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 .procname = "ax25_default_mode",
54 .maxlen = sizeof(int),
55 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080056 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 .extra1 = &min_axdefmode,
58 .extra2 = &max_axdefmode
59 },
60 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 .procname = "backoff_type",
62 .maxlen = sizeof(int),
63 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080064 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 .extra1 = &min_backoff,
66 .extra2 = &max_backoff
67 },
68 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 .procname = "connect_mode",
70 .maxlen = sizeof(int),
71 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080072 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .extra1 = &min_conmode,
74 .extra2 = &max_conmode
75 },
76 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 .procname = "standard_window_size",
78 .maxlen = sizeof(int),
79 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080080 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 .extra1 = &min_window,
82 .extra2 = &max_window
83 },
84 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 .procname = "extended_window_size",
86 .maxlen = sizeof(int),
87 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080088 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 .extra1 = &min_ewindow,
90 .extra2 = &max_ewindow
91 },
92 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 .procname = "t1_timeout",
94 .maxlen = sizeof(int),
95 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080096 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 .extra1 = &min_t1,
98 .extra2 = &max_t1
99 },
100 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 .procname = "t2_timeout",
102 .maxlen = sizeof(int),
103 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800104 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 .extra1 = &min_t2,
106 .extra2 = &max_t2
107 },
108 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 .procname = "t3_timeout",
110 .maxlen = sizeof(int),
111 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800112 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 .extra1 = &min_t3,
114 .extra2 = &max_t3
115 },
116 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 .procname = "idle_timeout",
118 .maxlen = sizeof(int),
119 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800120 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 .extra1 = &min_idle,
122 .extra2 = &max_idle
123 },
124 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 .procname = "maximum_retry_count",
126 .maxlen = sizeof(int),
127 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800128 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 .extra1 = &min_n2,
130 .extra2 = &max_n2
131 },
132 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 .procname = "maximum_packet_length",
134 .maxlen = sizeof(int),
135 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800136 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 .extra1 = &min_paclen,
138 .extra2 = &max_paclen
139 },
140 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 .procname = "protocol",
142 .maxlen = sizeof(int),
143 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800144 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 .extra1 = &min_proto,
146 .extra2 = &max_proto
147 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700148#ifdef CONFIG_AX25_DAMA_SLAVE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 .procname = "dama_slave_timeout",
151 .maxlen = sizeof(int),
152 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800153 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 .extra1 = &min_ds_timeout,
155 .extra2 = &max_ds_timeout
156 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700157#endif
158
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800159 { } /* that's all, folks! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160};
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
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700171 if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 spin_unlock_bh(&ax25_dev_lock);
173 return;
174 }
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) {
Arnaldo Carvalho de Melo0459d702006-11-17 12:43:07 -0200177 struct ctl_table *child = kmemdup(ax25_param_table,
178 sizeof(ax25_param_table),
179 GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 ax25_table[n].child = ax25_dev->systable = child;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 ax25_table[n].procname = ax25_dev->dev->name;
189 ax25_table[n].mode = 0555;
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
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
Pavel Emelyanovc6995bd2008-01-09 00:32:21 -0800199 ax25_table_header = register_sysctl_paths(ax25_path, ax25_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200}
201
202void ax25_unregister_sysctl(void)
203{
204 ctl_table *p;
205 unregister_sysctl_table(ax25_table_header);
206
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800207 for (p = ax25_table; p->procname; p++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 kfree(p->child);
209 kfree(ax25_table);
210}