Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 1 | /* SCTP kernel implementation |
| 2 | * (C) Copyright IBM Corp. 2001, 2004 |
| 3 | * Copyright (c) 1999-2000 Cisco, Inc. |
| 4 | * Copyright (c) 1999-2001 Motorola, Inc. |
| 5 | * Copyright (c) 2001 Intel Corp. |
| 6 | * |
| 7 | * This file is part of the SCTP kernel implementation |
| 8 | * |
Xin Long | fae8b6f | 2018-02-13 19:29:13 +0800 | [diff] [blame] | 9 | * This file contains sctp stream maniuplation primitives and helpers. |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 10 | * |
| 11 | * This SCTP implementation is free software; |
| 12 | * you can redistribute it and/or modify it under the terms of |
| 13 | * the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2, or (at your option) |
| 15 | * any later version. |
| 16 | * |
| 17 | * This SCTP implementation is distributed in the hope that it |
| 18 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
| 19 | * ************************ |
| 20 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 21 | * See the GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with GNU CC; see the file COPYING. If not, see |
| 25 | * <http://www.gnu.org/licenses/>. |
| 26 | * |
| 27 | * Please send any bug reports or fixes you make to the |
| 28 | * email address(es): |
| 29 | * lksctp developers <linux-sctp@vger.kernel.org> |
| 30 | * |
| 31 | * Written or modified by: |
| 32 | * Xin Long <lucien.xin@gmail.com> |
| 33 | */ |
| 34 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 35 | #include <linux/list.h> |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 36 | #include <net/sctp/sctp.h> |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 37 | #include <net/sctp/sm.h> |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 38 | #include <net/sctp/stream_sched.h> |
| 39 | |
| 40 | /* Migrates chunks from stream queues to new stream queues if needed, |
| 41 | * but not across associations. Also, removes those chunks to streams |
| 42 | * higher than the new max. |
| 43 | */ |
| 44 | static void sctp_stream_outq_migrate(struct sctp_stream *stream, |
| 45 | struct sctp_stream *new, __u16 outcnt) |
| 46 | { |
| 47 | struct sctp_association *asoc; |
| 48 | struct sctp_chunk *ch, *temp; |
| 49 | struct sctp_outq *outq; |
| 50 | int i; |
| 51 | |
| 52 | asoc = container_of(stream, struct sctp_association, stream); |
| 53 | outq = &asoc->outqueue; |
| 54 | |
| 55 | list_for_each_entry_safe(ch, temp, &outq->out_chunk_list, list) { |
| 56 | __u16 sid = sctp_chunk_stream_no(ch); |
| 57 | |
| 58 | if (sid < outcnt) |
| 59 | continue; |
| 60 | |
| 61 | sctp_sched_dequeue_common(outq, ch); |
| 62 | /* No need to call dequeue_done here because |
| 63 | * the chunks are not scheduled by now. |
| 64 | */ |
| 65 | |
| 66 | /* Mark as failed send. */ |
Xin Long | 08f4607 | 2017-11-26 20:16:06 +0800 | [diff] [blame] | 67 | sctp_chunk_fail(ch, (__force __u32)SCTP_ERROR_INV_STRM); |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 68 | if (asoc->peer.prsctp_capable && |
| 69 | SCTP_PR_PRIO_ENABLED(ch->sinfo.sinfo_flags)) |
| 70 | asoc->sent_cnt_removable--; |
| 71 | |
| 72 | sctp_chunk_free(ch); |
| 73 | } |
| 74 | |
| 75 | if (new) { |
| 76 | /* Here we actually move the old ext stuff into the new |
| 77 | * buffer, because we want to keep it. Then |
| 78 | * sctp_stream_update will swap ->out pointers. |
| 79 | */ |
| 80 | for (i = 0; i < outcnt; i++) { |
| 81 | kfree(new->out[i].ext); |
| 82 | new->out[i].ext = stream->out[i].ext; |
| 83 | stream->out[i].ext = NULL; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | for (i = outcnt; i < stream->outcnt; i++) |
| 88 | kfree(stream->out[i].ext); |
| 89 | } |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 90 | |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 91 | static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt, |
| 92 | gfp_t gfp) |
| 93 | { |
| 94 | struct sctp_stream_out *out; |
| 95 | |
| 96 | out = kmalloc_array(outcnt, sizeof(*out), gfp); |
| 97 | if (!out) |
| 98 | return -ENOMEM; |
| 99 | |
| 100 | if (stream->out) { |
| 101 | memcpy(out, stream->out, min(outcnt, stream->outcnt) * |
| 102 | sizeof(*out)); |
| 103 | kfree(stream->out); |
| 104 | } |
| 105 | |
| 106 | if (outcnt > stream->outcnt) |
| 107 | memset(out + stream->outcnt, 0, |
| 108 | (outcnt - stream->outcnt) * sizeof(*out)); |
| 109 | |
| 110 | stream->out = out; |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Marcelo Ricardo Leitner | 1fdb8d8 | 2017-10-03 19:20:10 -0300 | [diff] [blame] | 115 | static int sctp_stream_alloc_in(struct sctp_stream *stream, __u16 incnt, |
| 116 | gfp_t gfp) |
| 117 | { |
| 118 | struct sctp_stream_in *in; |
| 119 | |
| 120 | in = kmalloc_array(incnt, sizeof(*stream->in), gfp); |
| 121 | |
| 122 | if (!in) |
| 123 | return -ENOMEM; |
| 124 | |
| 125 | if (stream->in) { |
| 126 | memcpy(in, stream->in, min(incnt, stream->incnt) * |
| 127 | sizeof(*in)); |
| 128 | kfree(stream->in); |
| 129 | } |
| 130 | |
| 131 | if (incnt > stream->incnt) |
| 132 | memset(in + stream->incnt, 0, |
| 133 | (incnt - stream->incnt) * sizeof(*in)); |
| 134 | |
| 135 | stream->in = in; |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 140 | int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt, |
| 141 | gfp_t gfp) |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 142 | { |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 143 | struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); |
| 144 | int i, ret = 0; |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 145 | |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 146 | gfp |= __GFP_NOWARN; |
| 147 | |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 148 | /* Initial stream->out size may be very big, so free it and alloc |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 149 | * a new one with new outcnt to save memory if needed. |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 150 | */ |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 151 | if (outcnt == stream->outcnt) |
| 152 | goto in; |
| 153 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 154 | /* Filter out chunks queued on streams that won't exist anymore */ |
| 155 | sched->unsched_all(stream); |
| 156 | sctp_stream_outq_migrate(stream, NULL, outcnt); |
| 157 | sched->sched_all(stream); |
| 158 | |
Marcelo Ricardo Leitner | 79d0895 | 2018-01-02 19:44:37 -0200 | [diff] [blame] | 159 | ret = sctp_stream_alloc_out(stream, outcnt, gfp); |
| 160 | if (ret) |
| 161 | goto out; |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 162 | |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 163 | stream->outcnt = outcnt; |
Xin Long | 3dbcc10 | 2017-03-30 01:00:53 +0800 | [diff] [blame] | 164 | for (i = 0; i < stream->outcnt; i++) |
| 165 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 166 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 167 | sched->init(stream); |
| 168 | |
Marcelo Ricardo Leitner | 1ae2eaa | 2017-10-03 19:20:08 -0300 | [diff] [blame] | 169 | in: |
Xin Long | 0c3f6f6 | 2017-12-08 21:04:01 +0800 | [diff] [blame] | 170 | sctp_stream_interleave_init(stream); |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 171 | if (!incnt) |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 172 | goto out; |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 173 | |
Marcelo Ricardo Leitner | 79d0895 | 2018-01-02 19:44:37 -0200 | [diff] [blame] | 174 | ret = sctp_stream_alloc_in(stream, incnt, gfp); |
| 175 | if (ret) { |
| 176 | sched->free(stream); |
| 177 | kfree(stream->out); |
| 178 | stream->out = NULL; |
| 179 | stream->outcnt = 0; |
| 180 | goto out; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 181 | } |
| 182 | |
Xin Long | ff35641 | 2017-05-31 16:36:32 +0800 | [diff] [blame] | 183 | stream->incnt = incnt; |
| 184 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 185 | out: |
| 186 | return ret; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 187 | } |
| 188 | |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 189 | int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid) |
| 190 | { |
| 191 | struct sctp_stream_out_ext *soute; |
| 192 | |
| 193 | soute = kzalloc(sizeof(*soute), GFP_KERNEL); |
| 194 | if (!soute) |
| 195 | return -ENOMEM; |
| 196 | stream->out[sid].ext = soute; |
| 197 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 198 | return sctp_sched_init_sid(stream, sid, GFP_KERNEL); |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 199 | } |
| 200 | |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 201 | void sctp_stream_free(struct sctp_stream *stream) |
| 202 | { |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 203 | struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 204 | int i; |
| 205 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 206 | sched->free(stream); |
Marcelo Ricardo Leitner | f952be7 | 2017-10-03 19:20:11 -0300 | [diff] [blame] | 207 | for (i = 0; i < stream->outcnt; i++) |
| 208 | kfree(stream->out[i].ext); |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 209 | kfree(stream->out); |
| 210 | kfree(stream->in); |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void sctp_stream_clear(struct sctp_stream *stream) |
| 214 | { |
| 215 | int i; |
| 216 | |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 217 | for (i = 0; i < stream->outcnt; i++) { |
| 218 | stream->out[i].mid = 0; |
| 219 | stream->out[i].mid_uo = 0; |
| 220 | } |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 221 | |
| 222 | for (i = 0; i < stream->incnt; i++) |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 223 | stream->in[i].mid = 0; |
Xin Long | a838631 | 2017-01-06 22:18:33 +0800 | [diff] [blame] | 224 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 225 | |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 226 | void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new) |
| 227 | { |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 228 | struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream); |
| 229 | |
| 230 | sched->unsched_all(stream); |
| 231 | sctp_stream_outq_migrate(stream, new, new->outcnt); |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 232 | sctp_stream_free(stream); |
| 233 | |
| 234 | stream->out = new->out; |
| 235 | stream->in = new->in; |
| 236 | stream->outcnt = new->outcnt; |
| 237 | stream->incnt = new->incnt; |
| 238 | |
Marcelo Ricardo Leitner | 5bbbbe3 | 2017-10-03 19:20:13 -0300 | [diff] [blame] | 239 | sched->sched_all(stream); |
| 240 | |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 241 | new->out = NULL; |
| 242 | new->in = NULL; |
Xin Long | 6a9a27d | 2018-04-26 15:21:44 +0800 | [diff] [blame] | 243 | new->outcnt = 0; |
| 244 | new->incnt = 0; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 245 | } |
| 246 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 247 | static int sctp_send_reconf(struct sctp_association *asoc, |
| 248 | struct sctp_chunk *chunk) |
| 249 | { |
| 250 | struct net *net = sock_net(asoc->base.sk); |
| 251 | int retval = 0; |
| 252 | |
| 253 | retval = sctp_primitive_RECONF(net, asoc, chunk); |
| 254 | if (retval) |
| 255 | sctp_chunk_free(chunk); |
| 256 | |
| 257 | return retval; |
| 258 | } |
| 259 | |
Xin Long | d570a59 | 2017-11-25 21:05:33 +0800 | [diff] [blame] | 260 | static bool sctp_stream_outq_is_empty(struct sctp_stream *stream, |
| 261 | __u16 str_nums, __be16 *str_list) |
| 262 | { |
| 263 | struct sctp_association *asoc; |
| 264 | __u16 i; |
| 265 | |
| 266 | asoc = container_of(stream, struct sctp_association, stream); |
| 267 | if (!asoc->outqueue.out_qlen) |
| 268 | return true; |
| 269 | |
| 270 | if (!str_nums) |
| 271 | return false; |
| 272 | |
| 273 | for (i = 0; i < str_nums; i++) { |
| 274 | __u16 sid = ntohs(str_list[i]); |
| 275 | |
| 276 | if (stream->out[sid].ext && |
| 277 | !list_empty(&stream->out[sid].ext->outq)) |
| 278 | return false; |
| 279 | } |
| 280 | |
| 281 | return true; |
| 282 | } |
| 283 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 284 | int sctp_send_reset_streams(struct sctp_association *asoc, |
| 285 | struct sctp_reset_streams *params) |
| 286 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 287 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 288 | __u16 i, str_nums, *str_list; |
| 289 | struct sctp_chunk *chunk; |
| 290 | int retval = -EINVAL; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 291 | __be16 *nstr_list; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 292 | bool out, in; |
| 293 | |
| 294 | if (!asoc->peer.reconf_capable || |
| 295 | !(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) { |
| 296 | retval = -ENOPROTOOPT; |
| 297 | goto out; |
| 298 | } |
| 299 | |
| 300 | if (asoc->strreset_outstanding) { |
| 301 | retval = -EINPROGRESS; |
| 302 | goto out; |
| 303 | } |
| 304 | |
| 305 | out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING; |
| 306 | in = params->srs_flags & SCTP_STREAM_RESET_INCOMING; |
| 307 | if (!out && !in) |
| 308 | goto out; |
| 309 | |
| 310 | str_nums = params->srs_number_streams; |
| 311 | str_list = params->srs_stream_list; |
Xin Long | 423852f | 2017-11-15 17:00:11 +0800 | [diff] [blame] | 312 | if (str_nums) { |
| 313 | int param_len = 0; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 314 | |
Xin Long | 423852f | 2017-11-15 17:00:11 +0800 | [diff] [blame] | 315 | if (out) { |
| 316 | for (i = 0; i < str_nums; i++) |
| 317 | if (str_list[i] >= stream->outcnt) |
| 318 | goto out; |
| 319 | |
| 320 | param_len = str_nums * sizeof(__u16) + |
| 321 | sizeof(struct sctp_strreset_outreq); |
| 322 | } |
| 323 | |
| 324 | if (in) { |
| 325 | for (i = 0; i < str_nums; i++) |
| 326 | if (str_list[i] >= stream->incnt) |
| 327 | goto out; |
| 328 | |
| 329 | param_len += str_nums * sizeof(__u16) + |
| 330 | sizeof(struct sctp_strreset_inreq); |
| 331 | } |
| 332 | |
| 333 | if (param_len > SCTP_MAX_CHUNK_LEN - |
| 334 | sizeof(struct sctp_reconf_chunk)) |
| 335 | goto out; |
| 336 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 337 | |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 338 | nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL); |
| 339 | if (!nstr_list) { |
| 340 | retval = -ENOMEM; |
| 341 | goto out; |
| 342 | } |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 343 | |
| 344 | for (i = 0; i < str_nums; i++) |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 345 | nstr_list[i] = htons(str_list[i]); |
| 346 | |
Xin Long | d570a59 | 2017-11-25 21:05:33 +0800 | [diff] [blame] | 347 | if (out && !sctp_stream_outq_is_empty(stream, str_nums, nstr_list)) { |
| 348 | retval = -EAGAIN; |
| 349 | goto out; |
| 350 | } |
| 351 | |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 352 | chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in); |
| 353 | |
| 354 | kfree(nstr_list); |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 355 | |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 356 | if (!chunk) { |
| 357 | retval = -ENOMEM; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 358 | goto out; |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 359 | } |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 360 | |
| 361 | if (out) { |
| 362 | if (str_nums) |
| 363 | for (i = 0; i < str_nums; i++) |
| 364 | stream->out[str_list[i]].state = |
| 365 | SCTP_STREAM_CLOSED; |
| 366 | else |
| 367 | for (i = 0; i < stream->outcnt; i++) |
| 368 | stream->out[i].state = SCTP_STREAM_CLOSED; |
| 369 | } |
| 370 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 371 | asoc->strreset_chunk = chunk; |
| 372 | sctp_chunk_hold(asoc->strreset_chunk); |
| 373 | |
| 374 | retval = sctp_send_reconf(asoc, chunk); |
| 375 | if (retval) { |
| 376 | sctp_chunk_put(asoc->strreset_chunk); |
| 377 | asoc->strreset_chunk = NULL; |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 378 | if (!out) |
| 379 | goto out; |
| 380 | |
| 381 | if (str_nums) |
| 382 | for (i = 0; i < str_nums; i++) |
| 383 | stream->out[str_list[i]].state = |
| 384 | SCTP_STREAM_OPEN; |
| 385 | else |
| 386 | for (i = 0; i < stream->outcnt; i++) |
| 387 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 388 | |
| 389 | goto out; |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 390 | } |
| 391 | |
Xin Long | 119aecb | 2017-02-09 01:18:16 +0800 | [diff] [blame] | 392 | asoc->strreset_outstanding = out + in; |
| 393 | |
Xin Long | 7f9d68a | 2017-01-18 00:44:47 +0800 | [diff] [blame] | 394 | out: |
| 395 | return retval; |
| 396 | } |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 397 | |
| 398 | int sctp_send_reset_assoc(struct sctp_association *asoc) |
| 399 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 400 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 401 | struct sctp_chunk *chunk = NULL; |
| 402 | int retval; |
| 403 | __u16 i; |
| 404 | |
| 405 | if (!asoc->peer.reconf_capable || |
| 406 | !(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ)) |
| 407 | return -ENOPROTOOPT; |
| 408 | |
| 409 | if (asoc->strreset_outstanding) |
| 410 | return -EINPROGRESS; |
| 411 | |
Xin Long | 5c6144a | 2017-11-25 21:05:34 +0800 | [diff] [blame] | 412 | if (!sctp_outq_is_empty(&asoc->outqueue)) |
| 413 | return -EAGAIN; |
| 414 | |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 415 | chunk = sctp_make_strreset_tsnreq(asoc); |
| 416 | if (!chunk) |
| 417 | return -ENOMEM; |
| 418 | |
| 419 | /* Block further xmit of data until this request is completed */ |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 420 | for (i = 0; i < stream->outcnt; i++) |
| 421 | stream->out[i].state = SCTP_STREAM_CLOSED; |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 422 | |
| 423 | asoc->strreset_chunk = chunk; |
| 424 | sctp_chunk_hold(asoc->strreset_chunk); |
| 425 | |
| 426 | retval = sctp_send_reconf(asoc, chunk); |
| 427 | if (retval) { |
| 428 | sctp_chunk_put(asoc->strreset_chunk); |
| 429 | asoc->strreset_chunk = NULL; |
| 430 | |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 431 | for (i = 0; i < stream->outcnt; i++) |
| 432 | stream->out[i].state = SCTP_STREAM_OPEN; |
Xin Long | a92ce1a | 2017-02-09 01:18:18 +0800 | [diff] [blame] | 433 | |
| 434 | return retval; |
| 435 | } |
| 436 | |
| 437 | asoc->strreset_outstanding = 1; |
| 438 | |
| 439 | return 0; |
| 440 | } |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 441 | |
| 442 | int sctp_send_add_streams(struct sctp_association *asoc, |
| 443 | struct sctp_add_streams *params) |
| 444 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 445 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 446 | struct sctp_chunk *chunk = NULL; |
Wei Yongjun | dc82673 | 2017-10-31 13:28:16 +0000 | [diff] [blame] | 447 | int retval; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 448 | __u32 outcnt, incnt; |
| 449 | __u16 out, in; |
| 450 | |
| 451 | if (!asoc->peer.reconf_capable || |
| 452 | !(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) { |
| 453 | retval = -ENOPROTOOPT; |
| 454 | goto out; |
| 455 | } |
| 456 | |
| 457 | if (asoc->strreset_outstanding) { |
| 458 | retval = -EINPROGRESS; |
| 459 | goto out; |
| 460 | } |
| 461 | |
| 462 | out = params->sas_outstrms; |
| 463 | in = params->sas_instrms; |
| 464 | outcnt = stream->outcnt + out; |
| 465 | incnt = stream->incnt + in; |
| 466 | if (outcnt > SCTP_MAX_STREAM || incnt > SCTP_MAX_STREAM || |
| 467 | (!out && !in)) { |
| 468 | retval = -EINVAL; |
| 469 | goto out; |
| 470 | } |
| 471 | |
| 472 | if (out) { |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 473 | retval = sctp_stream_alloc_out(stream, outcnt, GFP_KERNEL); |
| 474 | if (retval) |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 475 | goto out; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 476 | } |
| 477 | |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 478 | chunk = sctp_make_strreset_addstrm(asoc, out, in); |
Wei Yongjun | dc82673 | 2017-10-31 13:28:16 +0000 | [diff] [blame] | 479 | if (!chunk) { |
| 480 | retval = -ENOMEM; |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 481 | goto out; |
Wei Yongjun | dc82673 | 2017-10-31 13:28:16 +0000 | [diff] [blame] | 482 | } |
Xin Long | 242bd2d | 2017-02-09 01:18:20 +0800 | [diff] [blame] | 483 | |
| 484 | asoc->strreset_chunk = chunk; |
| 485 | sctp_chunk_hold(asoc->strreset_chunk); |
| 486 | |
| 487 | retval = sctp_send_reconf(asoc, chunk); |
| 488 | if (retval) { |
| 489 | sctp_chunk_put(asoc->strreset_chunk); |
| 490 | asoc->strreset_chunk = NULL; |
| 491 | goto out; |
| 492 | } |
| 493 | |
| 494 | stream->incnt = incnt; |
| 495 | stream->outcnt = outcnt; |
| 496 | |
| 497 | asoc->strreset_outstanding = !!out + !!in; |
| 498 | |
| 499 | out: |
| 500 | return retval; |
| 501 | } |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 502 | |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 503 | static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param( |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 504 | struct sctp_association *asoc, __be32 resp_seq, |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 505 | __be16 type) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 506 | { |
| 507 | struct sctp_chunk *chunk = asoc->strreset_chunk; |
| 508 | struct sctp_reconf_chunk *hdr; |
| 509 | union sctp_params param; |
| 510 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 511 | if (!chunk) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 512 | return NULL; |
| 513 | |
| 514 | hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr; |
| 515 | sctp_walk_params(param, hdr, params) { |
| 516 | /* sctp_strreset_tsnreq is actually the basic structure |
| 517 | * of all stream reconf params, so it's safe to use it |
| 518 | * to access request_seq. |
| 519 | */ |
| 520 | struct sctp_strreset_tsnreq *req = param.v; |
| 521 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 522 | if ((!resp_seq || req->request_seq == resp_seq) && |
| 523 | (!type || type == req->param_hdr.type)) |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 524 | return param.v; |
| 525 | } |
| 526 | |
| 527 | return NULL; |
| 528 | } |
| 529 | |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 530 | static void sctp_update_strreset_result(struct sctp_association *asoc, |
| 531 | __u32 result) |
| 532 | { |
| 533 | asoc->strreset_result[1] = asoc->strreset_result[0]; |
| 534 | asoc->strreset_result[0] = result; |
| 535 | } |
| 536 | |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 537 | struct sctp_chunk *sctp_process_strreset_outreq( |
| 538 | struct sctp_association *asoc, |
| 539 | union sctp_params param, |
| 540 | struct sctp_ulpevent **evp) |
| 541 | { |
| 542 | struct sctp_strreset_outreq *outreq = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 543 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 544 | __u32 result = SCTP_STRRESET_DENIED; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 545 | __u16 i, nums, flags = 0; |
| 546 | __be16 *str_p = NULL; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 547 | __u32 request_seq; |
| 548 | |
| 549 | request_seq = ntohl(outreq->request_seq); |
| 550 | |
| 551 | if (ntohl(outreq->send_reset_at_tsn) > |
| 552 | sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map)) { |
| 553 | result = SCTP_STRRESET_IN_PROGRESS; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 554 | goto err; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 555 | } |
| 556 | |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 557 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 558 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 559 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 560 | goto err; |
| 561 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 562 | i = asoc->strreset_inseq - request_seq - 1; |
| 563 | result = asoc->strreset_result[i]; |
| 564 | goto err; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 565 | } |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 566 | asoc->strreset_inseq++; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 567 | |
| 568 | /* Check strreset_enable after inseq inc, as sender cannot tell |
| 569 | * the peer doesn't enable strreset after receiving response with |
| 570 | * result denied, as well as to keep consistent with bsd. |
| 571 | */ |
| 572 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) |
| 573 | goto out; |
| 574 | |
| 575 | if (asoc->strreset_chunk) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 576 | if (!sctp_chunk_lookup_strreset_param( |
| 577 | asoc, outreq->response_seq, |
| 578 | SCTP_PARAM_RESET_IN_REQUEST)) { |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 579 | /* same process with outstanding isn't 0 */ |
| 580 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 581 | goto out; |
| 582 | } |
| 583 | |
| 584 | asoc->strreset_outstanding--; |
| 585 | asoc->strreset_outseq++; |
| 586 | |
| 587 | if (!asoc->strreset_outstanding) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 588 | struct sctp_transport *t; |
| 589 | |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 590 | t = asoc->strreset_chunk->transport; |
| 591 | if (del_timer(&t->reconf_timer)) |
| 592 | sctp_transport_put(t); |
| 593 | |
| 594 | sctp_chunk_put(asoc->strreset_chunk); |
| 595 | asoc->strreset_chunk = NULL; |
| 596 | } |
| 597 | |
| 598 | flags = SCTP_STREAM_RESET_INCOMING_SSN; |
| 599 | } |
| 600 | |
Xin Long | 3aa623d | 2017-11-25 21:05:32 +0800 | [diff] [blame] | 601 | nums = (ntohs(param.p->length) - sizeof(*outreq)) / sizeof(__u16); |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 602 | if (nums) { |
| 603 | str_p = outreq->list_of_streams; |
| 604 | for (i = 0; i < nums; i++) { |
| 605 | if (ntohs(str_p[i]) >= stream->incnt) { |
| 606 | result = SCTP_STRRESET_ERR_WRONG_SSN; |
| 607 | goto out; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | for (i = 0; i < nums; i++) |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 612 | stream->in[ntohs(str_p[i])].mid = 0; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 613 | } else { |
| 614 | for (i = 0; i < stream->incnt; i++) |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 615 | stream->in[i].mid = 0; |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | result = SCTP_STRRESET_PERFORMED; |
| 619 | |
| 620 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, |
| 621 | flags | SCTP_STREAM_RESET_OUTGOING_SSN, nums, str_p, |
| 622 | GFP_ATOMIC); |
| 623 | |
| 624 | out: |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 625 | sctp_update_strreset_result(asoc, result); |
| 626 | err: |
Xin Long | 8105447 | 2017-02-17 12:45:39 +0800 | [diff] [blame] | 627 | return sctp_make_strreset_resp(asoc, result, request_seq); |
| 628 | } |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 629 | |
| 630 | struct sctp_chunk *sctp_process_strreset_inreq( |
| 631 | struct sctp_association *asoc, |
| 632 | union sctp_params param, |
| 633 | struct sctp_ulpevent **evp) |
| 634 | { |
| 635 | struct sctp_strreset_inreq *inreq = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 636 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 637 | __u32 result = SCTP_STRRESET_DENIED; |
| 638 | struct sctp_chunk *chunk = NULL; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 639 | __u32 request_seq; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 640 | __u16 i, nums; |
| 641 | __be16 *str_p; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 642 | |
| 643 | request_seq = ntohl(inreq->request_seq); |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 644 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 645 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 646 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 647 | goto err; |
| 648 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 649 | i = asoc->strreset_inseq - request_seq - 1; |
| 650 | result = asoc->strreset_result[i]; |
| 651 | if (result == SCTP_STRRESET_PERFORMED) |
| 652 | return NULL; |
| 653 | goto err; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 654 | } |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 655 | asoc->strreset_inseq++; |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 656 | |
| 657 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) |
| 658 | goto out; |
| 659 | |
| 660 | if (asoc->strreset_outstanding) { |
| 661 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 662 | goto out; |
| 663 | } |
| 664 | |
Xin Long | 3aa623d | 2017-11-25 21:05:32 +0800 | [diff] [blame] | 665 | nums = (ntohs(param.p->length) - sizeof(*inreq)) / sizeof(__u16); |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 666 | str_p = inreq->list_of_streams; |
| 667 | for (i = 0; i < nums; i++) { |
| 668 | if (ntohs(str_p[i]) >= stream->outcnt) { |
| 669 | result = SCTP_STRRESET_ERR_WRONG_SSN; |
| 670 | goto out; |
| 671 | } |
| 672 | } |
| 673 | |
Xin Long | d570a59 | 2017-11-25 21:05:33 +0800 | [diff] [blame] | 674 | if (!sctp_stream_outq_is_empty(stream, nums, str_p)) { |
| 675 | result = SCTP_STRRESET_IN_PROGRESS; |
| 676 | asoc->strreset_inseq--; |
| 677 | goto err; |
| 678 | } |
| 679 | |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 680 | chunk = sctp_make_strreset_req(asoc, nums, str_p, 1, 0); |
| 681 | if (!chunk) |
| 682 | goto out; |
| 683 | |
| 684 | if (nums) |
| 685 | for (i = 0; i < nums; i++) |
| 686 | stream->out[ntohs(str_p[i])].state = |
| 687 | SCTP_STREAM_CLOSED; |
| 688 | else |
| 689 | for (i = 0; i < stream->outcnt; i++) |
| 690 | stream->out[i].state = SCTP_STREAM_CLOSED; |
| 691 | |
| 692 | asoc->strreset_chunk = chunk; |
| 693 | asoc->strreset_outstanding = 1; |
| 694 | sctp_chunk_hold(asoc->strreset_chunk); |
| 695 | |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 696 | result = SCTP_STRRESET_PERFORMED; |
| 697 | |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 698 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, |
| 699 | SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC); |
| 700 | |
| 701 | out: |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 702 | sctp_update_strreset_result(asoc, result); |
| 703 | err: |
Xin Long | 16e1a91 | 2017-02-17 12:45:40 +0800 | [diff] [blame] | 704 | if (!chunk) |
| 705 | chunk = sctp_make_strreset_resp(asoc, result, request_seq); |
| 706 | |
| 707 | return chunk; |
| 708 | } |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 709 | |
| 710 | struct sctp_chunk *sctp_process_strreset_tsnreq( |
| 711 | struct sctp_association *asoc, |
| 712 | union sctp_params param, |
| 713 | struct sctp_ulpevent **evp) |
| 714 | { |
| 715 | __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen; |
| 716 | struct sctp_strreset_tsnreq *tsnreq = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 717 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 718 | __u32 result = SCTP_STRRESET_DENIED; |
| 719 | __u32 request_seq; |
| 720 | __u16 i; |
| 721 | |
| 722 | request_seq = ntohl(tsnreq->request_seq); |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 723 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 724 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 725 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 726 | goto err; |
| 727 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 728 | i = asoc->strreset_inseq - request_seq - 1; |
| 729 | result = asoc->strreset_result[i]; |
| 730 | if (result == SCTP_STRRESET_PERFORMED) { |
Xin Long | 52a3958 | 2017-11-25 21:05:36 +0800 | [diff] [blame] | 731 | next_tsn = asoc->ctsn_ack_point + 1; |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 732 | init_tsn = |
| 733 | sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1; |
| 734 | } |
| 735 | goto err; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 736 | } |
Xin Long | 5c6144a | 2017-11-25 21:05:34 +0800 | [diff] [blame] | 737 | |
| 738 | if (!sctp_outq_is_empty(&asoc->outqueue)) { |
| 739 | result = SCTP_STRRESET_IN_PROGRESS; |
| 740 | goto err; |
| 741 | } |
| 742 | |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 743 | asoc->strreset_inseq++; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 744 | |
| 745 | if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ)) |
| 746 | goto out; |
| 747 | |
| 748 | if (asoc->strreset_outstanding) { |
| 749 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 750 | goto out; |
| 751 | } |
| 752 | |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 753 | /* G4: The same processing as though a FWD-TSN chunk (as defined in |
| 754 | * [RFC3758]) with all streams affected and a new cumulative TSN |
| 755 | * ACK of the Receiver's Next TSN minus 1 were received MUST be |
| 756 | * performed. |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 757 | */ |
| 758 | max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map); |
Xin Long | 47b20a8 | 2017-12-15 00:41:28 +0800 | [diff] [blame] | 759 | asoc->stream.si->report_ftsn(&asoc->ulpq, max_tsn_seen); |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 760 | |
| 761 | /* G1: Compute an appropriate value for the Receiver's Next TSN -- the |
| 762 | * TSN that the peer should use to send the next DATA chunk. The |
| 763 | * value SHOULD be the smallest TSN not acknowledged by the |
| 764 | * receiver of the request plus 2^31. |
| 765 | */ |
| 766 | init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31); |
| 767 | sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL, |
| 768 | init_tsn, GFP_ATOMIC); |
| 769 | |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 770 | /* G3: The same processing as though a SACK chunk with no gap report |
| 771 | * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were |
| 772 | * received MUST be performed. |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 773 | */ |
| 774 | sctp_outq_free(&asoc->outqueue); |
| 775 | |
| 776 | /* G2: Compute an appropriate value for the local endpoint's next TSN, |
| 777 | * i.e., the next TSN assigned by the receiver of the SSN/TSN reset |
| 778 | * chunk. The value SHOULD be the highest TSN sent by the receiver |
| 779 | * of the request plus 1. |
| 780 | */ |
| 781 | next_tsn = asoc->next_tsn; |
| 782 | asoc->ctsn_ack_point = next_tsn - 1; |
| 783 | asoc->adv_peer_ack_point = asoc->ctsn_ack_point; |
| 784 | |
| 785 | /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all |
| 786 | * incoming and outgoing streams. |
| 787 | */ |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 788 | for (i = 0; i < stream->outcnt; i++) { |
| 789 | stream->out[i].mid = 0; |
| 790 | stream->out[i].mid_uo = 0; |
| 791 | } |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 792 | for (i = 0; i < stream->incnt; i++) |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 793 | stream->in[i].mid = 0; |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 794 | |
| 795 | result = SCTP_STRRESET_PERFORMED; |
| 796 | |
| 797 | *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn, |
| 798 | next_tsn, GFP_ATOMIC); |
| 799 | |
| 800 | out: |
Xin Long | 6c80138 | 2017-04-15 22:00:29 +0800 | [diff] [blame] | 801 | sctp_update_strreset_result(asoc, result); |
| 802 | err: |
Xin Long | 692787c | 2017-03-10 12:11:07 +0800 | [diff] [blame] | 803 | return sctp_make_strreset_tsnresp(asoc, result, request_seq, |
| 804 | next_tsn, init_tsn); |
| 805 | } |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 806 | |
| 807 | struct sctp_chunk *sctp_process_strreset_addstrm_out( |
| 808 | struct sctp_association *asoc, |
| 809 | union sctp_params param, |
| 810 | struct sctp_ulpevent **evp) |
| 811 | { |
| 812 | struct sctp_strreset_addstrm *addstrm = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 813 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 814 | __u32 result = SCTP_STRRESET_DENIED; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 815 | __u32 request_seq, incnt; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 816 | __u16 in, i; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 817 | |
| 818 | request_seq = ntohl(addstrm->request_seq); |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 819 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 820 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 821 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 822 | goto err; |
| 823 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 824 | i = asoc->strreset_inseq - request_seq - 1; |
| 825 | result = asoc->strreset_result[i]; |
| 826 | goto err; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 827 | } |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 828 | asoc->strreset_inseq++; |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 829 | |
| 830 | if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) |
| 831 | goto out; |
| 832 | |
| 833 | if (asoc->strreset_chunk) { |
| 834 | if (!sctp_chunk_lookup_strreset_param( |
| 835 | asoc, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS)) { |
| 836 | /* same process with outstanding isn't 0 */ |
| 837 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 838 | goto out; |
| 839 | } |
| 840 | |
| 841 | asoc->strreset_outstanding--; |
| 842 | asoc->strreset_outseq++; |
| 843 | |
| 844 | if (!asoc->strreset_outstanding) { |
| 845 | struct sctp_transport *t; |
| 846 | |
| 847 | t = asoc->strreset_chunk->transport; |
| 848 | if (del_timer(&t->reconf_timer)) |
| 849 | sctp_transport_put(t); |
| 850 | |
| 851 | sctp_chunk_put(asoc->strreset_chunk); |
| 852 | asoc->strreset_chunk = NULL; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | in = ntohs(addstrm->number_of_streams); |
| 857 | incnt = stream->incnt + in; |
| 858 | if (!in || incnt > SCTP_MAX_STREAM) |
| 859 | goto out; |
| 860 | |
Marcelo Ricardo Leitner | 1fdb8d8 | 2017-10-03 19:20:10 -0300 | [diff] [blame] | 861 | if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC)) |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 862 | goto out; |
| 863 | |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 864 | stream->incnt = incnt; |
| 865 | |
| 866 | result = SCTP_STRRESET_PERFORMED; |
| 867 | |
| 868 | *evp = sctp_ulpevent_make_stream_change_event(asoc, |
| 869 | 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC); |
| 870 | |
| 871 | out: |
Xin Long | e4dc99c | 2017-04-15 22:00:27 +0800 | [diff] [blame] | 872 | sctp_update_strreset_result(asoc, result); |
| 873 | err: |
Xin Long | 50a4159 | 2017-03-10 12:11:09 +0800 | [diff] [blame] | 874 | return sctp_make_strreset_resp(asoc, result, request_seq); |
| 875 | } |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 876 | |
| 877 | struct sctp_chunk *sctp_process_strreset_addstrm_in( |
| 878 | struct sctp_association *asoc, |
| 879 | union sctp_params param, |
| 880 | struct sctp_ulpevent **evp) |
| 881 | { |
| 882 | struct sctp_strreset_addstrm *addstrm = param.v; |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 883 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 884 | __u32 result = SCTP_STRRESET_DENIED; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 885 | struct sctp_chunk *chunk = NULL; |
| 886 | __u32 request_seq, outcnt; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 887 | __u16 out, i; |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 888 | int ret; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 889 | |
| 890 | request_seq = ntohl(addstrm->request_seq); |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 891 | if (TSN_lt(asoc->strreset_inseq, request_seq) || |
| 892 | TSN_lt(request_seq, asoc->strreset_inseq - 2)) { |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 893 | result = SCTP_STRRESET_ERR_BAD_SEQNO; |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 894 | goto err; |
| 895 | } else if (TSN_lt(request_seq, asoc->strreset_inseq)) { |
| 896 | i = asoc->strreset_inseq - request_seq - 1; |
| 897 | result = asoc->strreset_result[i]; |
| 898 | if (result == SCTP_STRRESET_PERFORMED) |
| 899 | return NULL; |
| 900 | goto err; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 901 | } |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 902 | asoc->strreset_inseq++; |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 903 | |
| 904 | if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) |
| 905 | goto out; |
| 906 | |
| 907 | if (asoc->strreset_outstanding) { |
| 908 | result = SCTP_STRRESET_ERR_IN_PROGRESS; |
| 909 | goto out; |
| 910 | } |
| 911 | |
| 912 | out = ntohs(addstrm->number_of_streams); |
| 913 | outcnt = stream->outcnt + out; |
| 914 | if (!out || outcnt > SCTP_MAX_STREAM) |
| 915 | goto out; |
| 916 | |
Marcelo Ricardo Leitner | e090abd | 2017-10-03 19:20:09 -0300 | [diff] [blame] | 917 | ret = sctp_stream_alloc_out(stream, outcnt, GFP_ATOMIC); |
| 918 | if (ret) |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 919 | goto out; |
| 920 | |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 921 | chunk = sctp_make_strreset_addstrm(asoc, out, 0); |
| 922 | if (!chunk) |
| 923 | goto out; |
| 924 | |
| 925 | asoc->strreset_chunk = chunk; |
| 926 | asoc->strreset_outstanding = 1; |
| 927 | sctp_chunk_hold(asoc->strreset_chunk); |
| 928 | |
| 929 | stream->outcnt = outcnt; |
| 930 | |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 931 | result = SCTP_STRRESET_PERFORMED; |
| 932 | |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 933 | *evp = sctp_ulpevent_make_stream_change_event(asoc, |
| 934 | 0, 0, ntohs(addstrm->number_of_streams), GFP_ATOMIC); |
| 935 | |
| 936 | out: |
Xin Long | d0f025e | 2017-04-15 22:00:28 +0800 | [diff] [blame] | 937 | sctp_update_strreset_result(asoc, result); |
| 938 | err: |
Xin Long | c5c4ebb | 2017-03-10 12:11:10 +0800 | [diff] [blame] | 939 | if (!chunk) |
| 940 | chunk = sctp_make_strreset_resp(asoc, result, request_seq); |
| 941 | |
| 942 | return chunk; |
| 943 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 944 | |
| 945 | struct sctp_chunk *sctp_process_strreset_resp( |
| 946 | struct sctp_association *asoc, |
| 947 | union sctp_params param, |
| 948 | struct sctp_ulpevent **evp) |
| 949 | { |
Xin Long | cee360a | 2017-05-31 16:36:31 +0800 | [diff] [blame] | 950 | struct sctp_stream *stream = &asoc->stream; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 951 | struct sctp_strreset_resp *resp = param.v; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 952 | struct sctp_transport *t; |
| 953 | __u16 i, nums, flags = 0; |
Xin Long | 3c91870 | 2017-06-30 11:52:16 +0800 | [diff] [blame] | 954 | struct sctp_paramhdr *req; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 955 | __u32 result; |
| 956 | |
| 957 | req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0); |
| 958 | if (!req) |
| 959 | return NULL; |
| 960 | |
| 961 | result = ntohl(resp->result); |
| 962 | if (result != SCTP_STRRESET_PERFORMED) { |
| 963 | /* if in progress, do nothing but retransmit */ |
| 964 | if (result == SCTP_STRRESET_IN_PROGRESS) |
| 965 | return NULL; |
| 966 | else if (result == SCTP_STRRESET_DENIED) |
| 967 | flags = SCTP_STREAM_RESET_DENIED; |
| 968 | else |
| 969 | flags = SCTP_STREAM_RESET_FAILED; |
| 970 | } |
| 971 | |
| 972 | if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) { |
| 973 | struct sctp_strreset_outreq *outreq; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 974 | __be16 *str_p; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 975 | |
| 976 | outreq = (struct sctp_strreset_outreq *)req; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 977 | str_p = outreq->list_of_streams; |
Xin Long | 3aa623d | 2017-11-25 21:05:32 +0800 | [diff] [blame] | 978 | nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) / |
| 979 | sizeof(__u16); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 980 | |
| 981 | if (result == SCTP_STRRESET_PERFORMED) { |
| 982 | if (nums) { |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 983 | for (i = 0; i < nums; i++) { |
| 984 | stream->out[ntohs(str_p[i])].mid = 0; |
| 985 | stream->out[ntohs(str_p[i])].mid_uo = 0; |
| 986 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 987 | } else { |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 988 | for (i = 0; i < stream->outcnt; i++) { |
| 989 | stream->out[i].mid = 0; |
| 990 | stream->out[i].mid_uo = 0; |
| 991 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | flags = SCTP_STREAM_RESET_OUTGOING_SSN; |
| 995 | } |
| 996 | |
| 997 | for (i = 0; i < stream->outcnt; i++) |
| 998 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 999 | |
| 1000 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags, |
| 1001 | nums, str_p, GFP_ATOMIC); |
| 1002 | } else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) { |
| 1003 | struct sctp_strreset_inreq *inreq; |
Xin Long | 1da4fc9 | 2017-10-28 19:43:54 +0800 | [diff] [blame] | 1004 | __be16 *str_p; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1005 | |
| 1006 | /* if the result is performed, it's impossible for inreq */ |
| 1007 | if (result == SCTP_STRRESET_PERFORMED) |
| 1008 | return NULL; |
| 1009 | |
| 1010 | inreq = (struct sctp_strreset_inreq *)req; |
Xin Long | edb12f2 | 2017-04-15 21:56:57 +0800 | [diff] [blame] | 1011 | str_p = inreq->list_of_streams; |
Xin Long | 3aa623d | 2017-11-25 21:05:32 +0800 | [diff] [blame] | 1012 | nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) / |
| 1013 | sizeof(__u16); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1014 | |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1015 | *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags, |
| 1016 | nums, str_p, GFP_ATOMIC); |
| 1017 | } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) { |
| 1018 | struct sctp_strreset_resptsn *resptsn; |
| 1019 | __u32 stsn, rtsn; |
| 1020 | |
| 1021 | /* check for resptsn, as sctp_verify_reconf didn't do it*/ |
| 1022 | if (ntohs(param.p->length) != sizeof(*resptsn)) |
| 1023 | return NULL; |
| 1024 | |
| 1025 | resptsn = (struct sctp_strreset_resptsn *)resp; |
| 1026 | stsn = ntohl(resptsn->senders_next_tsn); |
| 1027 | rtsn = ntohl(resptsn->receivers_next_tsn); |
| 1028 | |
| 1029 | if (result == SCTP_STRRESET_PERFORMED) { |
| 1030 | __u32 mtsn = sctp_tsnmap_get_max_tsn_seen( |
| 1031 | &asoc->peer.tsn_map); |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 1032 | LIST_HEAD(temp); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1033 | |
Xin Long | 47b20a8 | 2017-12-15 00:41:28 +0800 | [diff] [blame] | 1034 | asoc->stream.si->report_ftsn(&asoc->ulpq, mtsn); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1035 | |
| 1036 | sctp_tsnmap_init(&asoc->peer.tsn_map, |
| 1037 | SCTP_TSN_MAP_INITIAL, |
| 1038 | stsn, GFP_ATOMIC); |
| 1039 | |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 1040 | /* Clean up sacked and abandoned queues only. As the |
| 1041 | * out_chunk_list may not be empty, splice it to temp, |
| 1042 | * then get it back after sctp_outq_free is done. |
| 1043 | */ |
| 1044 | list_splice_init(&asoc->outqueue.out_chunk_list, &temp); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1045 | sctp_outq_free(&asoc->outqueue); |
Xin Long | 159f2a7 | 2017-11-25 21:05:35 +0800 | [diff] [blame] | 1046 | list_splice_init(&temp, &asoc->outqueue.out_chunk_list); |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1047 | |
| 1048 | asoc->next_tsn = rtsn; |
| 1049 | asoc->ctsn_ack_point = asoc->next_tsn - 1; |
| 1050 | asoc->adv_peer_ack_point = asoc->ctsn_ack_point; |
| 1051 | |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1052 | for (i = 0; i < stream->outcnt; i++) { |
| 1053 | stream->out[i].mid = 0; |
| 1054 | stream->out[i].mid_uo = 0; |
| 1055 | } |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1056 | for (i = 0; i < stream->incnt; i++) |
Xin Long | 107e242 | 2017-12-15 00:41:31 +0800 | [diff] [blame] | 1057 | stream->in[i].mid = 0; |
Xin Long | 11ae76e | 2017-03-10 12:11:11 +0800 | [diff] [blame] | 1058 | } |
| 1059 | |
| 1060 | for (i = 0; i < stream->outcnt; i++) |
| 1061 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 1062 | |
| 1063 | *evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags, |
| 1064 | stsn, rtsn, GFP_ATOMIC); |
| 1065 | } else if (req->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) { |
| 1066 | struct sctp_strreset_addstrm *addstrm; |
| 1067 | __u16 number; |
| 1068 | |
| 1069 | addstrm = (struct sctp_strreset_addstrm *)req; |
| 1070 | nums = ntohs(addstrm->number_of_streams); |
| 1071 | number = stream->outcnt - nums; |
| 1072 | |
| 1073 | if (result == SCTP_STRRESET_PERFORMED) |
| 1074 | for (i = number; i < stream->outcnt; i++) |
| 1075 | stream->out[i].state = SCTP_STREAM_OPEN; |
| 1076 | else |
| 1077 | stream->outcnt = number; |
| 1078 | |
| 1079 | *evp = sctp_ulpevent_make_stream_change_event(asoc, flags, |
| 1080 | 0, nums, GFP_ATOMIC); |
| 1081 | } else if (req->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) { |
| 1082 | struct sctp_strreset_addstrm *addstrm; |
| 1083 | |
| 1084 | /* if the result is performed, it's impossible for addstrm in |
| 1085 | * request. |
| 1086 | */ |
| 1087 | if (result == SCTP_STRRESET_PERFORMED) |
| 1088 | return NULL; |
| 1089 | |
| 1090 | addstrm = (struct sctp_strreset_addstrm *)req; |
| 1091 | nums = ntohs(addstrm->number_of_streams); |
| 1092 | |
| 1093 | *evp = sctp_ulpevent_make_stream_change_event(asoc, flags, |
| 1094 | nums, 0, GFP_ATOMIC); |
| 1095 | } |
| 1096 | |
| 1097 | asoc->strreset_outstanding--; |
| 1098 | asoc->strreset_outseq++; |
| 1099 | |
| 1100 | /* remove everything for this reconf request */ |
| 1101 | if (!asoc->strreset_outstanding) { |
| 1102 | t = asoc->strreset_chunk->transport; |
| 1103 | if (del_timer(&t->reconf_timer)) |
| 1104 | sctp_transport_put(t); |
| 1105 | |
| 1106 | sctp_chunk_put(asoc->strreset_chunk); |
| 1107 | asoc->strreset_chunk = NULL; |
| 1108 | } |
| 1109 | |
| 1110 | return NULL; |
| 1111 | } |