Merge acpi-2.6.12 to-akpm
[linux-2.6] / net / sctp / sysctl.c
1 /* SCTP kernel reference Implementation
2  * (C) Copyright IBM Corp. 2002, 2004
3  * Copyright (c) 2002 Intel Corp.
4  *
5  * This file is part of the SCTP kernel reference Implementation
6  *
7  * Sysctl related interfaces for SCTP.
8  *
9  * The SCTP reference implementation is free software;
10  * you can redistribute it and/or modify it under the terms of
11  * the GNU General Public License as published by
12  * the Free Software Foundation; either version 2, or (at your option)
13  * any later version.
14  *
15  * The SCTP reference implementation is distributed in the hope that it
16  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17  *                 ************************
18  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * See the GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with GNU CC; see the file COPYING.  If not, write to
23  * the Free Software Foundation, 59 Temple Place - Suite 330,
24  * Boston, MA 02111-1307, USA.
25  *
26  * Please send any bug reports or fixes you make to the
27  * email address(es):
28  *    lksctp developers <lksctp-developers@lists.sourceforge.net>
29  *
30  * Or submit a bug report through the following website:
31  *    http://www.sf.net/projects/lksctp
32  *
33  * Written or modified by:
34  *    Mingqin Liu           <liuming@us.ibm.com>
35  *    Jon Grimm             <jgrimm@us.ibm.com>
36  *    Ardelle Fan           <ardelle.fan@intel.com>
37  *    Ryan Layer            <rmlayer@us.ibm.com>
38  *    Sridhar Samudrala     <sri@us.ibm.com>
39  *
40  * Any bugs reported given to us we will try to fix... any fixes shared will
41  * be incorporated into the next SCTP release.
42  */
43
44 #include <net/sctp/structs.h>
45 #include <linux/sysctl.h>
46
47 static ctl_handler sctp_sysctl_jiffies_ms;
48 static long rto_timer_min = 1;
49 static long rto_timer_max = 86400000; /* One day */
50 static long sack_timer_min = 1;
51 static long sack_timer_max = 500;
52
53 static ctl_table sctp_table[] = {
54         {
55                 .ctl_name       = NET_SCTP_RTO_INITIAL,
56                 .procname       = "rto_initial",
57                 .data           = &sctp_rto_initial,
58                 .maxlen         = sizeof(long),
59                 .mode           = 0644,
60                 .proc_handler   = &proc_doulongvec_ms_jiffies_minmax,
61                 .strategy       = &sctp_sysctl_jiffies_ms,
62                 .extra1         = &rto_timer_min,
63                 .extra2         = &rto_timer_max
64         },
65         {
66                 .ctl_name       = NET_SCTP_RTO_MIN,
67                 .procname       = "rto_min",
68                 .data           = &sctp_rto_min,
69                 .maxlen         = sizeof(long),
70                 .mode           = 0644,
71                 .proc_handler   = &proc_doulongvec_ms_jiffies_minmax,
72                 .strategy       = &sctp_sysctl_jiffies_ms,
73                 .extra1         = &rto_timer_min,
74                 .extra2         = &rto_timer_max
75         },
76         {
77                 .ctl_name       = NET_SCTP_RTO_MAX,
78                 .procname       = "rto_max",
79                 .data           = &sctp_rto_max,
80                 .maxlen         = sizeof(long),
81                 .mode           = 0644,
82                 .proc_handler   = &proc_doulongvec_ms_jiffies_minmax,
83                 .strategy       = &sctp_sysctl_jiffies_ms,
84                 .extra1         = &rto_timer_min,
85                 .extra2         = &rto_timer_max
86         },
87         {
88                 .ctl_name       = NET_SCTP_VALID_COOKIE_LIFE,
89                 .procname       = "valid_cookie_life",
90                 .data           = &sctp_valid_cookie_life,
91                 .maxlen         = sizeof(long),
92                 .mode           = 0644,
93                 .proc_handler   = &proc_doulongvec_ms_jiffies_minmax,
94                 .strategy       = &sctp_sysctl_jiffies_ms,
95                 .extra1         = &rto_timer_min,
96                 .extra2         = &rto_timer_max
97         },
98         {
99                 .ctl_name       = NET_SCTP_MAX_BURST,
100                 .procname       = "max_burst",
101                 .data           = &sctp_max_burst,
102                 .maxlen         = sizeof(int),
103                 .mode           = 0644,
104                 .proc_handler   = &proc_dointvec
105         },
106         {
107                 .ctl_name       = NET_SCTP_ASSOCIATION_MAX_RETRANS,
108                 .procname       = "association_max_retrans",
109                 .data           = &sctp_max_retrans_association,
110                 .maxlen         = sizeof(int),
111                 .mode           = 0644,
112                 .proc_handler   = &proc_dointvec
113         },
114         {
115                 .ctl_name       = NET_SCTP_SNDBUF_POLICY,
116                 .procname       = "sndbuf_policy",
117                 .data           = &sctp_sndbuf_policy,
118                 .maxlen         = sizeof(int),
119                 .mode           = 0644,
120                 .proc_handler   = &proc_dointvec
121         },
122         {
123                 .ctl_name       = NET_SCTP_PATH_MAX_RETRANS,
124                 .procname       = "path_max_retrans",
125                 .data           = &sctp_max_retrans_path,
126                 .maxlen         = sizeof(int),
127                 .mode           = 0644,
128                 .proc_handler   = &proc_dointvec
129         },
130         {
131                 .ctl_name       = NET_SCTP_MAX_INIT_RETRANSMITS,
132                 .procname       = "max_init_retransmits",
133                 .data           = &sctp_max_retrans_init,
134                 .maxlen         = sizeof(int),
135                 .mode           = 0644,
136                 .proc_handler   = &proc_dointvec
137         },
138         {
139                 .ctl_name       = NET_SCTP_HB_INTERVAL,
140                 .procname       = "hb_interval",
141                 .data           = &sctp_hb_interval,
142                 .maxlen         = sizeof(long),
143                 .mode           = 0644,
144                 .proc_handler   = &proc_doulongvec_ms_jiffies_minmax,
145                 .strategy       = &sctp_sysctl_jiffies_ms,
146                 .extra1         = &rto_timer_min,
147                 .extra2         = &rto_timer_max
148         },
149         {
150                 .ctl_name       = NET_SCTP_PRESERVE_ENABLE,
151                 .procname       = "cookie_preserve_enable",
152                 .data           = &sctp_cookie_preserve_enable,
153                 .maxlen         = sizeof(long),
154                 .mode           = 0644,
155                 .proc_handler   = &proc_doulongvec_ms_jiffies_minmax,
156                 .strategy       = &sctp_sysctl_jiffies_ms,
157                 .extra1         = &rto_timer_min,
158                 .extra2         = &rto_timer_max
159         },
160         {
161                 .ctl_name       = NET_SCTP_RTO_ALPHA,
162                 .procname       = "rto_alpha_exp_divisor",
163                 .data           = &sctp_rto_alpha,
164                 .maxlen         = sizeof(int),
165                 .mode           = 0644,
166                 .proc_handler   = &proc_dointvec
167         },
168         {
169                 .ctl_name       = NET_SCTP_RTO_BETA,
170                 .procname       = "rto_beta_exp_divisor",
171                 .data           = &sctp_rto_beta,
172                 .maxlen         = sizeof(int),
173                 .mode           = 0644,
174                 .proc_handler   = &proc_dointvec
175         },
176         {
177                 .ctl_name       = NET_SCTP_ADDIP_ENABLE,
178                 .procname       = "addip_enable",
179                 .data           = &sctp_addip_enable,
180                 .maxlen         = sizeof(int),
181                 .mode           = 0644,
182                 .proc_handler   = &proc_dointvec
183         },
184         {
185                 .ctl_name       = NET_SCTP_PRSCTP_ENABLE,
186                 .procname       = "prsctp_enable",
187                 .data           = &sctp_prsctp_enable,
188                 .maxlen         = sizeof(int),
189                 .mode           = 0644,
190                 .proc_handler   = &proc_dointvec
191         },
192         {
193                 .ctl_name       = NET_SCTP_SACK_TIMEOUT,
194                 .procname       = "sack_timeout",
195                 .data           = &sctp_sack_timeout,
196                 .maxlen         = sizeof(long),
197                 .mode           = 0644,
198                 .proc_handler   = &proc_doulongvec_ms_jiffies_minmax,
199                 .strategy       = &sctp_sysctl_jiffies_ms,
200                 .extra1         = &sack_timer_min,
201                 .extra2         = &sack_timer_max,
202         },
203         { .ctl_name = 0 }
204 };
205
206 static ctl_table sctp_net_table[] = {
207         {
208                 .ctl_name       = NET_SCTP,
209                 .procname       = "sctp",
210                 .mode           = 0555,
211                 .child          = sctp_table
212         },
213         { .ctl_name = 0 }
214 };
215
216 static ctl_table sctp_root_table[] = {
217         {
218                 .ctl_name       = CTL_NET,
219                 .procname       = "net",
220                 .mode           = 0555,
221                 .child          = sctp_net_table
222         },
223         { .ctl_name = 0 }
224 };
225
226 static struct ctl_table_header * sctp_sysctl_header;
227
228 /* Sysctl registration.  */
229 void sctp_sysctl_register(void)
230 {
231         sctp_sysctl_header = register_sysctl_table(sctp_root_table, 0);
232 }
233
234 /* Sysctl deregistration.  */
235 void sctp_sysctl_unregister(void)
236 {
237         unregister_sysctl_table(sctp_sysctl_header);
238 }
239
240 /* Strategy function to convert jiffies to milliseconds.  */
241 static int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen,
242                 void __user *oldval, size_t __user *oldlenp,
243                 void __user *newval, size_t newlen, void **context) {
244
245         if (oldval) {
246                 size_t olen;
247
248                 if (oldlenp) {
249                         if (get_user(olen, oldlenp))
250                                 return -EFAULT;
251
252                         if (olen != sizeof (int))
253                                 return -EINVAL;
254                 }
255                 if (put_user((*(int *)(table->data) * 1000) / HZ,
256                         (int __user *)oldval) ||
257                     (oldlenp && put_user(sizeof (int), oldlenp)))
258                         return -EFAULT;
259         }
260         if (newval && newlen) {
261                 int new;
262
263                 if (newlen != sizeof (int))
264                         return -EINVAL;
265
266                 if (get_user(new, (int __user *)newval))
267                         return -EFAULT;
268
269                 *(int *)(table->data) = (new * HZ) / 1000;
270         }
271         return 1;
272 }