Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/mm.h> |
| 10 | #include <linux/sysctl.h> |
| 11 | #include <linux/spinlock.h> |
| 12 | #include <net/ax25.h> |
| 13 | |
| 14 | static int min_ipdefmode[1], max_ipdefmode[] = {1}; |
| 15 | static int min_axdefmode[1], max_axdefmode[] = {1}; |
| 16 | static int min_backoff[1], max_backoff[] = {2}; |
| 17 | static int min_conmode[1], max_conmode[] = {2}; |
| 18 | static int min_window[] = {1}, max_window[] = {7}; |
| 19 | static int min_ewindow[] = {1}, max_ewindow[] = {63}; |
Ralf Baechle | e1fdb5b | 2006-05-03 23:27:16 -0700 | [diff] [blame] | 20 | static int min_t1[] = {1}, max_t1[] = {30000}; |
| 21 | static int min_t2[] = {1}, max_t2[] = {20000}; |
| 22 | static int min_t3[1], max_t3[] = {3600000}; |
| 23 | static int min_idle[1], max_idle[] = {65535000}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static int min_n2[] = {1}, max_n2[] = {31}; |
| 25 | static int min_paclen[] = {1}, max_paclen[] = {512}; |
Ralf Baechle DL5RB | c7c694d | 2006-03-19 13:20:06 -0800 | [diff] [blame] | 26 | static int min_proto[1], max_proto[] = { AX25_PROTO_MAX }; |
Ingo Molnar | e14bec2 | 2008-11-25 16:58:19 -0800 | [diff] [blame] | 27 | #ifdef CONFIG_AX25_DAMA_SLAVE |
Ralf Baechle | e1fdb5b | 2006-05-03 23:27:16 -0700 | [diff] [blame] | 28 | static int min_ds_timeout[1], max_ds_timeout[] = {65535000}; |
Ingo Molnar | e14bec2 | 2008-11-25 16:58:19 -0800 | [diff] [blame] | 29 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | static struct ctl_table_header *ax25_table_header; |
| 32 | |
| 33 | static ctl_table *ax25_table; |
| 34 | static int ax25_table_size; |
| 35 | |
Pavel Emelyanov | c6995bd | 2008-01-09 00:32:21 -0800 | [diff] [blame] | 36 | static struct ctl_path ax25_path[] = { |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 37 | { .procname = "net", }, |
| 38 | { .procname = "ax25", }, |
Pavel Emelyanov | c6995bd | 2008-01-09 00:32:21 -0800 | [diff] [blame] | 39 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | }; |
Ralf Baechle | ffb2084 | 2008-08-05 18:46:57 -0700 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static const ctl_table ax25_param_table[] = { |
| 43 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | .procname = "ip_default_mode", |
| 45 | .maxlen = sizeof(int), |
| 46 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 47 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | .extra1 = &min_ipdefmode, |
| 49 | .extra2 = &max_ipdefmode |
| 50 | }, |
| 51 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | .procname = "ax25_default_mode", |
| 53 | .maxlen = sizeof(int), |
| 54 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 55 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | .extra1 = &min_axdefmode, |
| 57 | .extra2 = &max_axdefmode |
| 58 | }, |
| 59 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | .procname = "backoff_type", |
| 61 | .maxlen = sizeof(int), |
| 62 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 63 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | .extra1 = &min_backoff, |
| 65 | .extra2 = &max_backoff |
| 66 | }, |
| 67 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | .procname = "connect_mode", |
| 69 | .maxlen = sizeof(int), |
| 70 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 71 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .extra1 = &min_conmode, |
| 73 | .extra2 = &max_conmode |
| 74 | }, |
| 75 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | .procname = "standard_window_size", |
| 77 | .maxlen = sizeof(int), |
| 78 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 79 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | .extra1 = &min_window, |
| 81 | .extra2 = &max_window |
| 82 | }, |
| 83 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | .procname = "extended_window_size", |
| 85 | .maxlen = sizeof(int), |
| 86 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 87 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | .extra1 = &min_ewindow, |
| 89 | .extra2 = &max_ewindow |
| 90 | }, |
| 91 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | .procname = "t1_timeout", |
| 93 | .maxlen = sizeof(int), |
| 94 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 95 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | .extra1 = &min_t1, |
| 97 | .extra2 = &max_t1 |
| 98 | }, |
| 99 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | .procname = "t2_timeout", |
| 101 | .maxlen = sizeof(int), |
| 102 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 103 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | .extra1 = &min_t2, |
| 105 | .extra2 = &max_t2 |
| 106 | }, |
| 107 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | .procname = "t3_timeout", |
| 109 | .maxlen = sizeof(int), |
| 110 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 111 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | .extra1 = &min_t3, |
| 113 | .extra2 = &max_t3 |
| 114 | }, |
| 115 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | .procname = "idle_timeout", |
| 117 | .maxlen = sizeof(int), |
| 118 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 119 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | .extra1 = &min_idle, |
| 121 | .extra2 = &max_idle |
| 122 | }, |
| 123 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | .procname = "maximum_retry_count", |
| 125 | .maxlen = sizeof(int), |
| 126 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 127 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | .extra1 = &min_n2, |
| 129 | .extra2 = &max_n2 |
| 130 | }, |
| 131 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | .procname = "maximum_packet_length", |
| 133 | .maxlen = sizeof(int), |
| 134 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 135 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | .extra1 = &min_paclen, |
| 137 | .extra2 = &max_paclen |
| 138 | }, |
| 139 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | .procname = "protocol", |
| 141 | .maxlen = sizeof(int), |
| 142 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 143 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | .extra1 = &min_proto, |
| 145 | .extra2 = &max_proto |
| 146 | }, |
Ralf Baechle | ffb2084 | 2008-08-05 18:46:57 -0700 | [diff] [blame] | 147 | #ifdef CONFIG_AX25_DAMA_SLAVE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | .procname = "dama_slave_timeout", |
| 150 | .maxlen = sizeof(int), |
| 151 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 152 | .proc_handler = proc_dointvec_minmax, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | .extra1 = &min_ds_timeout, |
| 154 | .extra2 = &max_ds_timeout |
| 155 | }, |
Ralf Baechle | ffb2084 | 2008-08-05 18:46:57 -0700 | [diff] [blame] | 156 | #endif |
| 157 | |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 158 | { } /* that's all, folks! */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | void ax25_register_sysctl(void) |
| 162 | { |
| 163 | ax25_dev *ax25_dev; |
| 164 | int n, k; |
| 165 | |
| 166 | spin_lock_bh(&ax25_dev_lock); |
| 167 | for (ax25_table_size = sizeof(ctl_table), ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) |
| 168 | ax25_table_size += sizeof(ctl_table); |
| 169 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 170 | if ((ax25_table = kzalloc(ax25_table_size, GFP_ATOMIC)) == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | spin_unlock_bh(&ax25_dev_lock); |
| 172 | return; |
| 173 | } |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | for (n = 0, ax25_dev = ax25_dev_list; ax25_dev != NULL; ax25_dev = ax25_dev->next) { |
Arnaldo Carvalho de Melo | 0459d70a | 2006-11-17 12:43:07 -0200 | [diff] [blame] | 176 | struct ctl_table *child = kmemdup(ax25_param_table, |
| 177 | sizeof(ax25_param_table), |
| 178 | GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | if (!child) { |
| 180 | while (n--) |
| 181 | kfree(ax25_table[n].child); |
| 182 | kfree(ax25_table); |
| 183 | spin_unlock_bh(&ax25_dev_lock); |
| 184 | return; |
| 185 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | ax25_table[n].child = ax25_dev->systable = child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | ax25_table[n].procname = ax25_dev->dev->name; |
| 188 | ax25_table[n].mode = 0555; |
| 189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | for (k = 0; k < AX25_MAX_VALUES; k++) |
| 192 | child[k].data = &ax25_dev->values[k]; |
| 193 | |
| 194 | n++; |
| 195 | } |
| 196 | spin_unlock_bh(&ax25_dev_lock); |
| 197 | |
Pavel Emelyanov | c6995bd | 2008-01-09 00:32:21 -0800 | [diff] [blame] | 198 | ax25_table_header = register_sysctl_paths(ax25_path, ax25_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | void ax25_unregister_sysctl(void) |
| 202 | { |
| 203 | ctl_table *p; |
| 204 | unregister_sysctl_table(ax25_table_header); |
| 205 | |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 206 | for (p = ax25_table; p->procname; p++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | kfree(p->child); |
| 208 | kfree(ax25_table); |
| 209 | } |