blob: 2154d004d3dc82f9dfb051063421e1c2d3a2521d [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1996 Mike Shaver (shaver@zeroknowledge.com)
5 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/mm.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#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};
Ralf Baechlee1fdb5b2006-05-03 23:27:16 -070018static 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};
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static int min_n2[] = {1}, max_n2[] = {31};
23static int min_paclen[] = {1}, max_paclen[] = {512};
Ralf Baechle DL5RBc7c694d2006-03-19 13:20:06 -080024static int min_proto[1], max_proto[] = { AX25_PROTO_MAX };
Ingo Molnare14bec22008-11-25 16:58:19 -080025#ifdef CONFIG_AX25_DAMA_SLAVE
Ralf Baechlee1fdb5b2006-05-03 23:27:16 -070026static int min_ds_timeout[1], max_ds_timeout[] = {65535000};
Ingo Molnare14bec22008-11-25 16:58:19 -080027#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesfe2c6332013-06-11 23:04:25 -070029static const struct ctl_table ax25_param_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 .procname = "ip_default_mode",
32 .maxlen = sizeof(int),
33 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080034 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 .extra1 = &min_ipdefmode,
36 .extra2 = &max_ipdefmode
37 },
38 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 .procname = "ax25_default_mode",
40 .maxlen = sizeof(int),
41 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080042 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 .extra1 = &min_axdefmode,
44 .extra2 = &max_axdefmode
45 },
46 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 .procname = "backoff_type",
48 .maxlen = sizeof(int),
49 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080050 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 .extra1 = &min_backoff,
52 .extra2 = &max_backoff
53 },
54 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 .procname = "connect_mode",
56 .maxlen = sizeof(int),
57 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080058 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 .extra1 = &min_conmode,
60 .extra2 = &max_conmode
61 },
62 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 .procname = "standard_window_size",
64 .maxlen = sizeof(int),
65 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080066 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 .extra1 = &min_window,
68 .extra2 = &max_window
69 },
70 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 .procname = "extended_window_size",
72 .maxlen = sizeof(int),
73 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080074 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 .extra1 = &min_ewindow,
76 .extra2 = &max_ewindow
77 },
78 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 .procname = "t1_timeout",
80 .maxlen = sizeof(int),
81 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080082 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 .extra1 = &min_t1,
84 .extra2 = &max_t1
85 },
86 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 .procname = "t2_timeout",
88 .maxlen = sizeof(int),
89 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080090 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 .extra1 = &min_t2,
92 .extra2 = &max_t2
93 },
94 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 .procname = "t3_timeout",
96 .maxlen = sizeof(int),
97 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080098 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 .extra1 = &min_t3,
100 .extra2 = &max_t3
101 },
102 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 .procname = "idle_timeout",
104 .maxlen = sizeof(int),
105 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800106 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 .extra1 = &min_idle,
108 .extra2 = &max_idle
109 },
110 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 .procname = "maximum_retry_count",
112 .maxlen = sizeof(int),
113 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800114 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 .extra1 = &min_n2,
116 .extra2 = &max_n2
117 },
118 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .procname = "maximum_packet_length",
120 .maxlen = sizeof(int),
121 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800122 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 .extra1 = &min_paclen,
124 .extra2 = &max_paclen
125 },
126 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 .procname = "protocol",
128 .maxlen = sizeof(int),
129 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800130 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 .extra1 = &min_proto,
132 .extra2 = &max_proto
133 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700134#ifdef CONFIG_AX25_DAMA_SLAVE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 .procname = "dama_slave_timeout",
137 .maxlen = sizeof(int),
138 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800139 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 .extra1 = &min_ds_timeout,
141 .extra2 = &max_ds_timeout
142 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700143#endif
144
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800145 { } /* that's all, folks! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146};
147
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000148int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000150 char path[sizeof("net/ax25/") + IFNAMSIZ];
151 int k;
152 struct ctl_table *table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000154 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
155 if (!table)
156 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000158 for (k = 0; k < AX25_MAX_VALUES; k++)
159 table[k].data = &ax25_dev->values[k];
160
161 snprintf(path, sizeof(path), "net/ax25/%s", ax25_dev->dev->name);
162 ax25_dev->sysheader = register_net_sysctl(&init_net, path, table);
163 if (!ax25_dev->sysheader) {
164 kfree(table);
165 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000167 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000170void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000172 struct ctl_table_header *header = ax25_dev->sysheader;
173 struct ctl_table *table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000175 if (header) {
176 ax25_dev->sysheader = NULL;
177 table = header->ctl_table_arg;
178 unregister_net_sysctl_table(header);
179 kfree(table);
180 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}