blob: 919a5ce47515b17c63976bc7ee001b657760c606 [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
Joe Perchesfe2c6332013-06-11 23:04:25 -070032static const struct ctl_table ax25_param_table[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 .procname = "ip_default_mode",
35 .maxlen = sizeof(int),
36 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080037 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 .extra1 = &min_ipdefmode,
39 .extra2 = &max_ipdefmode
40 },
41 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 .procname = "ax25_default_mode",
43 .maxlen = sizeof(int),
44 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080045 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 .extra1 = &min_axdefmode,
47 .extra2 = &max_axdefmode
48 },
49 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 .procname = "backoff_type",
51 .maxlen = sizeof(int),
52 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080053 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .extra1 = &min_backoff,
55 .extra2 = &max_backoff
56 },
57 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 .procname = "connect_mode",
59 .maxlen = sizeof(int),
60 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080061 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 .extra1 = &min_conmode,
63 .extra2 = &max_conmode
64 },
65 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 .procname = "standard_window_size",
67 .maxlen = sizeof(int),
68 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080069 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 .extra1 = &min_window,
71 .extra2 = &max_window
72 },
73 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 .procname = "extended_window_size",
75 .maxlen = sizeof(int),
76 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080077 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 .extra1 = &min_ewindow,
79 .extra2 = &max_ewindow
80 },
81 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 .procname = "t1_timeout",
83 .maxlen = sizeof(int),
84 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080085 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 .extra1 = &min_t1,
87 .extra2 = &max_t1
88 },
89 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 .procname = "t2_timeout",
91 .maxlen = sizeof(int),
92 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -080093 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 .extra1 = &min_t2,
95 .extra2 = &max_t2
96 },
97 {
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 .procname = "t3_timeout",
99 .maxlen = sizeof(int),
100 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800101 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 .extra1 = &min_t3,
103 .extra2 = &max_t3
104 },
105 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 .procname = "idle_timeout",
107 .maxlen = sizeof(int),
108 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800109 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 .extra1 = &min_idle,
111 .extra2 = &max_idle
112 },
113 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 .procname = "maximum_retry_count",
115 .maxlen = sizeof(int),
116 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800117 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 .extra1 = &min_n2,
119 .extra2 = &max_n2
120 },
121 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 .procname = "maximum_packet_length",
123 .maxlen = sizeof(int),
124 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800125 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 .extra1 = &min_paclen,
127 .extra2 = &max_paclen
128 },
129 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .procname = "protocol",
131 .maxlen = sizeof(int),
132 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800133 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 .extra1 = &min_proto,
135 .extra2 = &max_proto
136 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700137#ifdef CONFIG_AX25_DAMA_SLAVE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 .procname = "dama_slave_timeout",
140 .maxlen = sizeof(int),
141 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800142 .proc_handler = proc_dointvec_minmax,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 .extra1 = &min_ds_timeout,
144 .extra2 = &max_ds_timeout
145 },
Ralf Baechleffb20842008-08-05 18:46:57 -0700146#endif
147
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800148 { } /* that's all, folks! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000151int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000153 char path[sizeof("net/ax25/") + IFNAMSIZ];
154 int k;
155 struct ctl_table *table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000157 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
158 if (!table)
159 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000161 for (k = 0; k < AX25_MAX_VALUES; k++)
162 table[k].data = &ax25_dev->values[k];
163
164 snprintf(path, sizeof(path), "net/ax25/%s", ax25_dev->dev->name);
165 ax25_dev->sysheader = register_net_sysctl(&init_net, path, table);
166 if (!ax25_dev->sysheader) {
167 kfree(table);
168 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 }
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000170 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000173void ax25_unregister_dev_sysctl(ax25_dev *ax25_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000175 struct ctl_table_header *header = ax25_dev->sysheader;
176 struct ctl_table *table;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Eric W. Biederman0ca7a4c2012-04-19 13:34:18 +0000178 if (header) {
179 ax25_dev->sysheader = NULL;
180 table = header->ctl_table_arg;
181 unregister_net_sysctl_table(header);
182 kfree(table);
183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}