Thomas Gleixner | 47505b8 | 2019-05-23 11:14:41 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 2 | /* SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * (C) Copyright IBM Corp. 2002, 2004 |
| 4 | * Copyright (c) 2002 Intel Corp. |
| 5 | * |
Vlad Yasevich | 60c778b | 2008-01-11 09:57:09 -0500 | [diff] [blame] | 6 | * This file is part of the SCTP kernel implementation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Sysctl related interfaces for SCTP. |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * Please send any bug reports or fixes you make to the |
| 11 | * email address(es): |
Daniel Borkmann | 91705c6 | 2013-07-23 14:51:47 +0200 | [diff] [blame] | 12 | * lksctp developers <linux-sctp@vger.kernel.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * Written or modified by: |
| 15 | * Mingqin Liu <liuming@us.ibm.com> |
| 16 | * Jon Grimm <jgrimm@us.ibm.com> |
| 17 | * Ardelle Fan <ardelle.fan@intel.com> |
| 18 | * Ryan Layer <rmlayer@us.ibm.com> |
| 19 | * Sridhar Samudrala <sri@us.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Daniel Borkmann | b58537a | 2014-06-15 00:59:14 +0200 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <net/sctp/structs.h> |
Adrian Bunk | 8c5955d | 2005-09-05 18:07:42 -0700 | [diff] [blame] | 25 | #include <net/sctp/sctp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/sysctl.h> |
| 27 | |
Vladislav Yasevich | 3fd091e | 2006-08-22 13:29:17 -0700 | [diff] [blame] | 28 | static int zero = 0; |
| 29 | static int one = 1; |
| 30 | static int timer_max = 86400000; /* ms in one day */ |
| 31 | static int int_max = INT_MAX; |
Jean-Mickael Guerin | d48e074 | 2009-05-13 00:03:20 +0200 | [diff] [blame] | 32 | static int sack_timer_min = 1; |
| 33 | static int sack_timer_max = 500; |
Xin Long | 701ef3e | 2017-08-05 19:59:53 +0800 | [diff] [blame] | 34 | static int addr_scope_max = SCTP_SCOPE_POLICY_MAX; |
Vlad Yasevich | 90f2f53 | 2009-11-23 15:53:57 -0500 | [diff] [blame] | 35 | static int rwnd_scale_max = 16; |
Daniel Borkmann | b58537a | 2014-06-15 00:59:14 +0200 | [diff] [blame] | 36 | static int rto_alpha_min = 0; |
| 37 | static int rto_beta_min = 0; |
| 38 | static int rto_alpha_max = 1000; |
| 39 | static int rto_beta_max = 1000; |
| 40 | |
Xi Wang | 2692ba6 | 2011-12-16 12:44:15 +0000 | [diff] [blame] | 41 | static unsigned long max_autoclose_min = 0; |
| 42 | static unsigned long max_autoclose_max = |
| 43 | (MAX_SCHEDULE_TIMEOUT / HZ > UINT_MAX) |
| 44 | ? UINT_MAX : MAX_SCHEDULE_TIMEOUT / HZ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
wangweidong | b486b22 | 2013-12-11 09:50:40 +0800 | [diff] [blame] | 46 | static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write, |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 47 | void __user *buffer, size_t *lenp, |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 48 | loff_t *ppos); |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 49 | static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write, |
| 50 | void __user *buffer, size_t *lenp, |
| 51 | loff_t *ppos); |
| 52 | static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, |
| 53 | void __user *buffer, size_t *lenp, |
| 54 | loff_t *ppos); |
Daniel Borkmann | b58537a | 2014-06-15 00:59:14 +0200 | [diff] [blame] | 55 | static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write, |
| 56 | void __user *buffer, size_t *lenp, |
| 57 | loff_t *ppos); |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 58 | static int proc_sctp_do_auth(struct ctl_table *ctl, int write, |
| 59 | void __user *buffer, size_t *lenp, |
| 60 | loff_t *ppos); |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 61 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 62 | static struct ctl_table sctp_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 64 | .procname = "sctp_mem", |
| 65 | .data = &sysctl_sctp_mem, |
| 66 | .maxlen = sizeof(sysctl_sctp_mem), |
| 67 | .mode = 0644, |
Eric Dumazet | 8d987e5 | 2010-11-09 23:24:26 +0000 | [diff] [blame] | 68 | .proc_handler = proc_doulongvec_minmax |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 69 | }, |
| 70 | { |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 71 | .procname = "sctp_rmem", |
| 72 | .data = &sysctl_sctp_rmem, |
| 73 | .maxlen = sizeof(sysctl_sctp_rmem), |
| 74 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 75 | .proc_handler = proc_dointvec, |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 76 | }, |
| 77 | { |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 78 | .procname = "sctp_wmem", |
| 79 | .data = &sysctl_sctp_wmem, |
| 80 | .maxlen = sizeof(sysctl_sctp_wmem), |
| 81 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 82 | .proc_handler = proc_dointvec, |
Neil Horman | 4d93df0 | 2007-08-15 16:07:44 -0700 | [diff] [blame] | 83 | }, |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 84 | |
| 85 | { /* sentinel */ } |
| 86 | }; |
| 87 | |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 88 | static struct ctl_table sctp_net_table[] = { |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame] | 89 | { |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 90 | .procname = "rto_initial", |
| 91 | .data = &init_net.sctp.rto_initial, |
| 92 | .maxlen = sizeof(unsigned int), |
| 93 | .mode = 0644, |
| 94 | .proc_handler = proc_dointvec_minmax, |
| 95 | .extra1 = &one, |
| 96 | .extra2 = &timer_max |
| 97 | }, |
| 98 | { |
| 99 | .procname = "rto_min", |
| 100 | .data = &init_net.sctp.rto_min, |
| 101 | .maxlen = sizeof(unsigned int), |
| 102 | .mode = 0644, |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 103 | .proc_handler = proc_sctp_do_rto_min, |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 104 | .extra1 = &one, |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 105 | .extra2 = &init_net.sctp.rto_max |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 106 | }, |
| 107 | { |
| 108 | .procname = "rto_max", |
| 109 | .data = &init_net.sctp.rto_max, |
| 110 | .maxlen = sizeof(unsigned int), |
| 111 | .mode = 0644, |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 112 | .proc_handler = proc_sctp_do_rto_max, |
| 113 | .extra1 = &init_net.sctp.rto_min, |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 114 | .extra2 = &timer_max |
| 115 | }, |
| 116 | { |
| 117 | .procname = "rto_alpha_exp_divisor", |
| 118 | .data = &init_net.sctp.rto_alpha, |
| 119 | .maxlen = sizeof(int), |
Daniel Borkmann | b58537a | 2014-06-15 00:59:14 +0200 | [diff] [blame] | 120 | .mode = 0644, |
| 121 | .proc_handler = proc_sctp_do_alpha_beta, |
| 122 | .extra1 = &rto_alpha_min, |
| 123 | .extra2 = &rto_alpha_max, |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 124 | }, |
| 125 | { |
| 126 | .procname = "rto_beta_exp_divisor", |
| 127 | .data = &init_net.sctp.rto_beta, |
| 128 | .maxlen = sizeof(int), |
Daniel Borkmann | b58537a | 2014-06-15 00:59:14 +0200 | [diff] [blame] | 129 | .mode = 0644, |
| 130 | .proc_handler = proc_sctp_do_alpha_beta, |
| 131 | .extra1 = &rto_beta_min, |
| 132 | .extra2 = &rto_beta_max, |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 133 | }, |
| 134 | { |
| 135 | .procname = "max_burst", |
| 136 | .data = &init_net.sctp.max_burst, |
| 137 | .maxlen = sizeof(int), |
| 138 | .mode = 0644, |
| 139 | .proc_handler = proc_dointvec_minmax, |
| 140 | .extra1 = &zero, |
| 141 | .extra2 = &int_max |
| 142 | }, |
| 143 | { |
| 144 | .procname = "cookie_preserve_enable", |
| 145 | .data = &init_net.sctp.cookie_preserve_enable, |
| 146 | .maxlen = sizeof(int), |
| 147 | .mode = 0644, |
| 148 | .proc_handler = proc_dointvec, |
| 149 | }, |
| 150 | { |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 151 | .procname = "cookie_hmac_alg", |
wangweidong | 22a1f514 | 2014-02-12 09:44:43 +0800 | [diff] [blame] | 152 | .data = &init_net.sctp.sctp_hmac_alg, |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 153 | .maxlen = 8, |
| 154 | .mode = 0644, |
| 155 | .proc_handler = proc_sctp_do_hmac_alg, |
| 156 | }, |
| 157 | { |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 158 | .procname = "valid_cookie_life", |
| 159 | .data = &init_net.sctp.valid_cookie_life, |
| 160 | .maxlen = sizeof(unsigned int), |
| 161 | .mode = 0644, |
| 162 | .proc_handler = proc_dointvec_minmax, |
| 163 | .extra1 = &one, |
| 164 | .extra2 = &timer_max |
| 165 | }, |
| 166 | { |
| 167 | .procname = "sack_timeout", |
| 168 | .data = &init_net.sctp.sack_timeout, |
| 169 | .maxlen = sizeof(int), |
| 170 | .mode = 0644, |
| 171 | .proc_handler = proc_dointvec_minmax, |
| 172 | .extra1 = &sack_timer_min, |
| 173 | .extra2 = &sack_timer_max, |
| 174 | }, |
| 175 | { |
| 176 | .procname = "hb_interval", |
| 177 | .data = &init_net.sctp.hb_interval, |
| 178 | .maxlen = sizeof(unsigned int), |
| 179 | .mode = 0644, |
| 180 | .proc_handler = proc_dointvec_minmax, |
| 181 | .extra1 = &one, |
| 182 | .extra2 = &timer_max |
| 183 | }, |
| 184 | { |
| 185 | .procname = "association_max_retrans", |
| 186 | .data = &init_net.sctp.max_retrans_association, |
| 187 | .maxlen = sizeof(int), |
| 188 | .mode = 0644, |
| 189 | .proc_handler = proc_dointvec_minmax, |
| 190 | .extra1 = &one, |
| 191 | .extra2 = &int_max |
| 192 | }, |
| 193 | { |
| 194 | .procname = "path_max_retrans", |
| 195 | .data = &init_net.sctp.max_retrans_path, |
| 196 | .maxlen = sizeof(int), |
| 197 | .mode = 0644, |
| 198 | .proc_handler = proc_dointvec_minmax, |
| 199 | .extra1 = &one, |
| 200 | .extra2 = &int_max |
| 201 | }, |
| 202 | { |
| 203 | .procname = "max_init_retransmits", |
| 204 | .data = &init_net.sctp.max_retrans_init, |
| 205 | .maxlen = sizeof(int), |
| 206 | .mode = 0644, |
| 207 | .proc_handler = proc_dointvec_minmax, |
| 208 | .extra1 = &one, |
| 209 | .extra2 = &int_max |
| 210 | }, |
| 211 | { |
| 212 | .procname = "pf_retrans", |
| 213 | .data = &init_net.sctp.pf_retrans, |
| 214 | .maxlen = sizeof(int), |
| 215 | .mode = 0644, |
| 216 | .proc_handler = proc_dointvec_minmax, |
| 217 | .extra1 = &zero, |
| 218 | .extra2 = &int_max |
| 219 | }, |
| 220 | { |
| 221 | .procname = "sndbuf_policy", |
| 222 | .data = &init_net.sctp.sndbuf_policy, |
| 223 | .maxlen = sizeof(int), |
| 224 | .mode = 0644, |
| 225 | .proc_handler = proc_dointvec, |
| 226 | }, |
| 227 | { |
| 228 | .procname = "rcvbuf_policy", |
| 229 | .data = &init_net.sctp.rcvbuf_policy, |
| 230 | .maxlen = sizeof(int), |
| 231 | .mode = 0644, |
| 232 | .proc_handler = proc_dointvec, |
| 233 | }, |
| 234 | { |
| 235 | .procname = "default_auto_asconf", |
| 236 | .data = &init_net.sctp.default_auto_asconf, |
| 237 | .maxlen = sizeof(int), |
| 238 | .mode = 0644, |
| 239 | .proc_handler = proc_dointvec, |
| 240 | }, |
| 241 | { |
| 242 | .procname = "addip_enable", |
| 243 | .data = &init_net.sctp.addip_enable, |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame] | 244 | .maxlen = sizeof(int), |
| 245 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 246 | .proc_handler = proc_dointvec, |
Vlad Yasevich | a29a5bd | 2007-09-16 19:31:35 -0700 | [diff] [blame] | 247 | }, |
Vlad Yasevich | 73d9c4f | 2007-10-24 17:24:26 -0400 | [diff] [blame] | 248 | { |
Vlad Yasevich | 73d9c4f | 2007-10-24 17:24:26 -0400 | [diff] [blame] | 249 | .procname = "addip_noauth_enable", |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 250 | .data = &init_net.sctp.addip_noauth, |
| 251 | .maxlen = sizeof(int), |
| 252 | .mode = 0644, |
| 253 | .proc_handler = proc_dointvec, |
| 254 | }, |
| 255 | { |
| 256 | .procname = "prsctp_enable", |
| 257 | .data = &init_net.sctp.prsctp_enable, |
| 258 | .maxlen = sizeof(int), |
| 259 | .mode = 0644, |
| 260 | .proc_handler = proc_dointvec, |
| 261 | }, |
| 262 | { |
Xin Long | c0d8bab | 2017-03-10 12:11:12 +0800 | [diff] [blame] | 263 | .procname = "reconf_enable", |
| 264 | .data = &init_net.sctp.reconf_enable, |
| 265 | .maxlen = sizeof(int), |
| 266 | .mode = 0644, |
| 267 | .proc_handler = proc_dointvec, |
| 268 | }, |
| 269 | { |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 270 | .procname = "auth_enable", |
| 271 | .data = &init_net.sctp.auth_enable, |
Vlad Yasevich | 73d9c4f | 2007-10-24 17:24:26 -0400 | [diff] [blame] | 272 | .maxlen = sizeof(int), |
| 273 | .mode = 0644, |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 274 | .proc_handler = proc_sctp_do_auth, |
Vlad Yasevich | 73d9c4f | 2007-10-24 17:24:26 -0400 | [diff] [blame] | 275 | }, |
Bhaskar Dutta | 7238843 | 2009-09-03 17:25:47 +0530 | [diff] [blame] | 276 | { |
Xin Long | 463118c | 2017-12-15 00:41:32 +0800 | [diff] [blame] | 277 | .procname = "intl_enable", |
| 278 | .data = &init_net.sctp.intl_enable, |
| 279 | .maxlen = sizeof(int), |
| 280 | .mode = 0644, |
| 281 | .proc_handler = proc_dointvec, |
| 282 | }, |
| 283 | { |
Bhaskar Dutta | 7238843 | 2009-09-03 17:25:47 +0530 | [diff] [blame] | 284 | .procname = "addr_scope_policy", |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 285 | .data = &init_net.sctp.scope_policy, |
Bhaskar Dutta | 7238843 | 2009-09-03 17:25:47 +0530 | [diff] [blame] | 286 | .maxlen = sizeof(int), |
| 287 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 288 | .proc_handler = proc_dointvec_minmax, |
Bhaskar Dutta | 7238843 | 2009-09-03 17:25:47 +0530 | [diff] [blame] | 289 | .extra1 = &zero, |
| 290 | .extra2 = &addr_scope_max, |
| 291 | }, |
Vlad Yasevich | 90f2f53 | 2009-11-23 15:53:57 -0500 | [diff] [blame] | 292 | { |
Vlad Yasevich | 90f2f53 | 2009-11-23 15:53:57 -0500 | [diff] [blame] | 293 | .procname = "rwnd_update_shift", |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 294 | .data = &init_net.sctp.rwnd_upd_shift, |
Vlad Yasevich | 90f2f53 | 2009-11-23 15:53:57 -0500 | [diff] [blame] | 295 | .maxlen = sizeof(int), |
| 296 | .mode = 0644, |
| 297 | .proc_handler = &proc_dointvec_minmax, |
Vlad Yasevich | 90f2f53 | 2009-11-23 15:53:57 -0500 | [diff] [blame] | 298 | .extra1 = &one, |
| 299 | .extra2 = &rwnd_scale_max, |
| 300 | }, |
Xi Wang | 2692ba6 | 2011-12-16 12:44:15 +0000 | [diff] [blame] | 301 | { |
| 302 | .procname = "max_autoclose", |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 303 | .data = &init_net.sctp.max_autoclose, |
Xi Wang | 2692ba6 | 2011-12-16 12:44:15 +0000 | [diff] [blame] | 304 | .maxlen = sizeof(unsigned long), |
| 305 | .mode = 0644, |
| 306 | .proc_handler = &proc_doulongvec_minmax, |
| 307 | .extra1 = &max_autoclose_min, |
| 308 | .extra2 = &max_autoclose_max, |
| 309 | }, |
Zhu Yanjun | 566178f | 2015-12-16 13:55:04 +0800 | [diff] [blame] | 310 | { |
| 311 | .procname = "pf_enable", |
| 312 | .data = &init_net.sctp.pf_enable, |
| 313 | .maxlen = sizeof(int), |
| 314 | .mode = 0644, |
| 315 | .proc_handler = proc_dointvec, |
| 316 | }, |
David S. Miller | 71acc0d | 2013-08-09 13:09:41 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | d7fc02c | 2009-12-08 07:55:01 -0800 | [diff] [blame] | 318 | { /* sentinel */ } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | }; |
| 320 | |
wangweidong | b486b22 | 2013-12-11 09:50:40 +0800 | [diff] [blame] | 321 | static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write, |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 322 | void __user *buffer, size_t *lenp, |
| 323 | loff_t *ppos) |
| 324 | { |
| 325 | struct net *net = current->nsproxy->net_ns; |
Joe Perches | fe2c633 | 2013-06-11 23:04:25 -0700 | [diff] [blame] | 326 | struct ctl_table tbl; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 327 | bool changed = false; |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 328 | char *none = "none"; |
Sasha Levin | 320f1a4 | 2016-01-07 14:52:43 -0500 | [diff] [blame] | 329 | char tmp[8] = {0}; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 330 | int ret; |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 331 | |
| 332 | memset(&tbl, 0, sizeof(struct ctl_table)); |
| 333 | |
| 334 | if (write) { |
| 335 | tbl.data = tmp; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 336 | tbl.maxlen = sizeof(tmp); |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 337 | } else { |
| 338 | tbl.data = net->sctp.sctp_hmac_alg ? : none; |
| 339 | tbl.maxlen = strlen(tbl.data); |
| 340 | } |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 341 | |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 342 | ret = proc_dostring(&tbl, write, buffer, lenp, ppos); |
| 343 | if (write && ret == 0) { |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 344 | #ifdef CONFIG_CRYPTO_MD5 |
| 345 | if (!strncmp(tmp, "md5", 3)) { |
| 346 | net->sctp.sctp_hmac_alg = "md5"; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 347 | changed = true; |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 348 | } |
| 349 | #endif |
| 350 | #ifdef CONFIG_CRYPTO_SHA1 |
| 351 | if (!strncmp(tmp, "sha1", 4)) { |
| 352 | net->sctp.sctp_hmac_alg = "sha1"; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 353 | changed = true; |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 354 | } |
| 355 | #endif |
| 356 | if (!strncmp(tmp, "none", 4)) { |
| 357 | net->sctp.sctp_hmac_alg = NULL; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 358 | changed = true; |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 359 | } |
Neil Horman | 3c68198 | 2012-10-24 09:20:03 +0000 | [diff] [blame] | 360 | if (!changed) |
| 361 | ret = -EINVAL; |
| 362 | } |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 367 | static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write, |
| 368 | void __user *buffer, size_t *lenp, |
| 369 | loff_t *ppos) |
| 370 | { |
| 371 | struct net *net = current->nsproxy->net_ns; |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 372 | unsigned int min = *(unsigned int *) ctl->extra1; |
| 373 | unsigned int max = *(unsigned int *) ctl->extra2; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 374 | struct ctl_table tbl; |
| 375 | int ret, new_value; |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 376 | |
| 377 | memset(&tbl, 0, sizeof(struct ctl_table)); |
| 378 | tbl.maxlen = sizeof(unsigned int); |
| 379 | |
| 380 | if (write) |
| 381 | tbl.data = &new_value; |
| 382 | else |
| 383 | tbl.data = &net->sctp.rto_min; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 384 | |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 385 | ret = proc_dointvec(&tbl, write, buffer, lenp, ppos); |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 386 | if (write && ret == 0) { |
| 387 | if (new_value > max || new_value < min) |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 388 | return -EINVAL; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 389 | |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 390 | net->sctp.rto_min = new_value; |
| 391 | } |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 392 | |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write, |
| 397 | void __user *buffer, size_t *lenp, |
| 398 | loff_t *ppos) |
| 399 | { |
| 400 | struct net *net = current->nsproxy->net_ns; |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 401 | unsigned int min = *(unsigned int *) ctl->extra1; |
| 402 | unsigned int max = *(unsigned int *) ctl->extra2; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 403 | struct ctl_table tbl; |
| 404 | int ret, new_value; |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 405 | |
| 406 | memset(&tbl, 0, sizeof(struct ctl_table)); |
| 407 | tbl.maxlen = sizeof(unsigned int); |
| 408 | |
| 409 | if (write) |
| 410 | tbl.data = &new_value; |
| 411 | else |
| 412 | tbl.data = &net->sctp.rto_max; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 413 | |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 414 | ret = proc_dointvec(&tbl, write, buffer, lenp, ppos); |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 415 | if (write && ret == 0) { |
| 416 | if (new_value > max || new_value < min) |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 417 | return -EINVAL; |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 418 | |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 419 | net->sctp.rto_max = new_value; |
| 420 | } |
Daniel Borkmann | ff5e92c | 2014-06-19 01:31:30 +0200 | [diff] [blame] | 421 | |
wangweidong | 4f3fdf3 | 2013-12-11 09:50:39 +0800 | [diff] [blame] | 422 | return ret; |
| 423 | } |
| 424 | |
Daniel Borkmann | b58537a | 2014-06-15 00:59:14 +0200 | [diff] [blame] | 425 | static int proc_sctp_do_alpha_beta(struct ctl_table *ctl, int write, |
| 426 | void __user *buffer, size_t *lenp, |
| 427 | loff_t *ppos) |
| 428 | { |
Daniel Borkmann | eaea2da | 2014-06-30 13:52:09 +0200 | [diff] [blame] | 429 | if (write) |
| 430 | pr_warn_once("Changing rto_alpha or rto_beta may lead to " |
| 431 | "suboptimal rtt/srtt estimations!\n"); |
Daniel Borkmann | b58537a | 2014-06-15 00:59:14 +0200 | [diff] [blame] | 432 | |
| 433 | return proc_dointvec_minmax(ctl, write, buffer, lenp, ppos); |
| 434 | } |
| 435 | |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 436 | static int proc_sctp_do_auth(struct ctl_table *ctl, int write, |
| 437 | void __user *buffer, size_t *lenp, |
| 438 | loff_t *ppos) |
| 439 | { |
| 440 | struct net *net = current->nsproxy->net_ns; |
| 441 | struct ctl_table tbl; |
| 442 | int new_value, ret; |
| 443 | |
| 444 | memset(&tbl, 0, sizeof(struct ctl_table)); |
| 445 | tbl.maxlen = sizeof(unsigned int); |
| 446 | |
| 447 | if (write) |
| 448 | tbl.data = &new_value; |
| 449 | else |
| 450 | tbl.data = &net->sctp.auth_enable; |
| 451 | |
| 452 | ret = proc_dointvec(&tbl, write, buffer, lenp, ppos); |
Daniel Borkmann | 24599e6 | 2014-06-18 23:46:31 +0200 | [diff] [blame] | 453 | if (write && ret == 0) { |
Vlad Yasevich | b14878c | 2014-04-17 17:26:50 +0200 | [diff] [blame] | 454 | struct sock *sk = net->sctp.ctl_sock; |
| 455 | |
| 456 | net->sctp.auth_enable = new_value; |
| 457 | /* Update the value in the control socket */ |
| 458 | lock_sock(sk); |
| 459 | sctp_sk(sk)->ep->auth_enable = new_value; |
| 460 | release_sock(sk); |
| 461 | } |
| 462 | |
| 463 | return ret; |
| 464 | } |
| 465 | |
Eric W. Biederman | ebb7e95 | 2012-08-07 07:23:59 +0000 | [diff] [blame] | 466 | int sctp_sysctl_net_register(struct net *net) |
| 467 | { |
wangweidong | eb9f370 | 2014-05-08 20:55:01 +0800 | [diff] [blame] | 468 | struct ctl_table *table; |
| 469 | int i; |
Eric W. Biederman | ebb7e95 | 2012-08-07 07:23:59 +0000 | [diff] [blame] | 470 | |
wangweidong | eb9f370 | 2014-05-08 20:55:01 +0800 | [diff] [blame] | 471 | table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL); |
| 472 | if (!table) |
| 473 | return -ENOMEM; |
Eric W. Biederman | ebb7e95 | 2012-08-07 07:23:59 +0000 | [diff] [blame] | 474 | |
wangweidong | eb9f370 | 2014-05-08 20:55:01 +0800 | [diff] [blame] | 475 | for (i = 0; table[i].data; i++) |
| 476 | table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp; |
Eric W. Biederman | e1fc3b1 | 2012-08-07 07:29:57 +0000 | [diff] [blame] | 477 | |
Eric W. Biederman | ebb7e95 | 2012-08-07 07:23:59 +0000 | [diff] [blame] | 478 | net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table); |
wangweidong | f66138c | 2014-05-08 20:55:02 +0800 | [diff] [blame] | 479 | if (net->sctp.sysctl_header == NULL) { |
| 480 | kfree(table); |
| 481 | return -ENOMEM; |
| 482 | } |
Eric W. Biederman | ebb7e95 | 2012-08-07 07:23:59 +0000 | [diff] [blame] | 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | void sctp_sysctl_net_unregister(struct net *net) |
| 487 | { |
Vlad Yasevich | 5f19d12 | 2013-01-24 11:02:47 -0500 | [diff] [blame] | 488 | struct ctl_table *table; |
| 489 | |
| 490 | table = net->sctp.sysctl_header->ctl_table_arg; |
Eric W. Biederman | ebb7e95 | 2012-08-07 07:23:59 +0000 | [diff] [blame] | 491 | unregister_net_sysctl_table(net->sctp.sysctl_header); |
Vlad Yasevich | 5f19d12 | 2013-01-24 11:02:47 -0500 | [diff] [blame] | 492 | kfree(table); |
Eric W. Biederman | ebb7e95 | 2012-08-07 07:23:59 +0000 | [diff] [blame] | 493 | } |
| 494 | |
wangweidong | 26ac8e5 | 2013-12-23 12:16:51 +0800 | [diff] [blame] | 495 | static struct ctl_table_header *sctp_sysctl_header; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
| 497 | /* Sysctl registration. */ |
| 498 | void sctp_sysctl_register(void) |
| 499 | { |
Eric W. Biederman | ec8f23c | 2012-04-19 13:44:49 +0000 | [diff] [blame] | 500 | sctp_sysctl_header = register_net_sysctl(&init_net, "net/sctp", sctp_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* Sysctl deregistration. */ |
| 504 | void sctp_sysctl_unregister(void) |
| 505 | { |
Eric W. Biederman | 5dd3df1 | 2012-04-19 13:24:33 +0000 | [diff] [blame] | 506 | unregister_net_sysctl_table(sctp_sysctl_header); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | } |