blob: 09c797a10aaa12d33e0d7a1064570bfc8962ae60 [file] [log] [blame]
Xin Longa8386312017-01-06 22:18:33 +08001/* 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 *
9 * These functions manipulate sctp tsn mapping array.
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 Leitner5bbbbe32017-10-03 19:20:13 -030035#include <linux/list.h>
Xin Longa8386312017-01-06 22:18:33 +080036#include <net/sctp/sctp.h>
Xin Long7f9d68a2017-01-18 00:44:47 +080037#include <net/sctp/sm.h>
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -030038#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 */
44static 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. */
67 sctp_chunk_fail(ch, SCTP_ERROR_INV_STRM);
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 Longa8386312017-01-06 22:18:33 +080090
Marcelo Ricardo Leitnere090abd2017-10-03 19:20:09 -030091static 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 Leitner1fdb8d82017-10-03 19:20:10 -0300115static 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 Longff356412017-05-31 16:36:32 +0800140int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
141 gfp_t gfp)
Xin Longa8386312017-01-06 22:18:33 +0800142{
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300143 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
144 int i, ret = 0;
Xin Long3dbcc102017-03-30 01:00:53 +0800145
Marcelo Ricardo Leitner1ae2eaa2017-10-03 19:20:08 -0300146 gfp |= __GFP_NOWARN;
147
Xin Long3dbcc102017-03-30 01:00:53 +0800148 /* Initial stream->out size may be very big, so free it and alloc
Marcelo Ricardo Leitner1ae2eaa2017-10-03 19:20:08 -0300149 * a new one with new outcnt to save memory if needed.
Xin Long3dbcc102017-03-30 01:00:53 +0800150 */
Marcelo Ricardo Leitner1ae2eaa2017-10-03 19:20:08 -0300151 if (outcnt == stream->outcnt)
152 goto in;
153
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300154 /* 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 Leitnere090abd2017-10-03 19:20:09 -0300159 i = sctp_stream_alloc_out(stream, outcnt, gfp);
160 if (i)
161 return i;
Xin Long3dbcc102017-03-30 01:00:53 +0800162
Xin Longff356412017-05-31 16:36:32 +0800163 stream->outcnt = outcnt;
Xin Long3dbcc102017-03-30 01:00:53 +0800164 for (i = 0; i < stream->outcnt; i++)
165 stream->out[i].state = SCTP_STREAM_OPEN;
166
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300167 sched->init(stream);
168
Marcelo Ricardo Leitner1ae2eaa2017-10-03 19:20:08 -0300169in:
Xin Longff356412017-05-31 16:36:32 +0800170 if (!incnt)
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300171 goto out;
Xin Longff356412017-05-31 16:36:32 +0800172
Marcelo Ricardo Leitner1fdb8d82017-10-03 19:20:10 -0300173 i = sctp_stream_alloc_in(stream, incnt, gfp);
174 if (i) {
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300175 ret = -ENOMEM;
176 goto free;
Xin Longa8386312017-01-06 22:18:33 +0800177 }
178
Xin Longff356412017-05-31 16:36:32 +0800179 stream->incnt = incnt;
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300180 goto out;
Xin Longff356412017-05-31 16:36:32 +0800181
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300182free:
183 sched->free(stream);
184 kfree(stream->out);
185 stream->out = NULL;
186out:
187 return ret;
Xin Longa8386312017-01-06 22:18:33 +0800188}
189
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300190int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid)
191{
192 struct sctp_stream_out_ext *soute;
193
194 soute = kzalloc(sizeof(*soute), GFP_KERNEL);
195 if (!soute)
196 return -ENOMEM;
197 stream->out[sid].ext = soute;
198
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300199 return sctp_sched_init_sid(stream, sid, GFP_KERNEL);
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300200}
201
Xin Longa8386312017-01-06 22:18:33 +0800202void sctp_stream_free(struct sctp_stream *stream)
203{
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300204 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300205 int i;
206
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300207 sched->free(stream);
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300208 for (i = 0; i < stream->outcnt; i++)
209 kfree(stream->out[i].ext);
Xin Longa8386312017-01-06 22:18:33 +0800210 kfree(stream->out);
211 kfree(stream->in);
Xin Longa8386312017-01-06 22:18:33 +0800212}
213
214void sctp_stream_clear(struct sctp_stream *stream)
215{
216 int i;
217
218 for (i = 0; i < stream->outcnt; i++)
219 stream->out[i].ssn = 0;
220
221 for (i = 0; i < stream->incnt; i++)
222 stream->in[i].ssn = 0;
223}
Xin Long7f9d68a2017-01-18 00:44:47 +0800224
Xin Longcee360a2017-05-31 16:36:31 +0800225void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new)
226{
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300227 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
228
229 sched->unsched_all(stream);
230 sctp_stream_outq_migrate(stream, new, new->outcnt);
Xin Longcee360a2017-05-31 16:36:31 +0800231 sctp_stream_free(stream);
232
233 stream->out = new->out;
234 stream->in = new->in;
235 stream->outcnt = new->outcnt;
236 stream->incnt = new->incnt;
237
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300238 sched->sched_all(stream);
239
Xin Longcee360a2017-05-31 16:36:31 +0800240 new->out = NULL;
241 new->in = NULL;
242}
243
Xin Long7f9d68a2017-01-18 00:44:47 +0800244static int sctp_send_reconf(struct sctp_association *asoc,
245 struct sctp_chunk *chunk)
246{
247 struct net *net = sock_net(asoc->base.sk);
248 int retval = 0;
249
250 retval = sctp_primitive_RECONF(net, asoc, chunk);
251 if (retval)
252 sctp_chunk_free(chunk);
253
254 return retval;
255}
256
257int sctp_send_reset_streams(struct sctp_association *asoc,
258 struct sctp_reset_streams *params)
259{
Xin Longcee360a2017-05-31 16:36:31 +0800260 struct sctp_stream *stream = &asoc->stream;
Xin Long7f9d68a2017-01-18 00:44:47 +0800261 __u16 i, str_nums, *str_list;
262 struct sctp_chunk *chunk;
263 int retval = -EINVAL;
Xin Long1da4fc92017-10-28 19:43:54 +0800264 __be16 *nstr_list;
Xin Long7f9d68a2017-01-18 00:44:47 +0800265 bool out, in;
266
267 if (!asoc->peer.reconf_capable ||
268 !(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) {
269 retval = -ENOPROTOOPT;
270 goto out;
271 }
272
273 if (asoc->strreset_outstanding) {
274 retval = -EINPROGRESS;
275 goto out;
276 }
277
278 out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING;
279 in = params->srs_flags & SCTP_STREAM_RESET_INCOMING;
280 if (!out && !in)
281 goto out;
282
283 str_nums = params->srs_number_streams;
284 str_list = params->srs_stream_list;
Xin Long423852f2017-11-15 17:00:11 +0800285 if (str_nums) {
286 int param_len = 0;
Xin Long7f9d68a2017-01-18 00:44:47 +0800287
Xin Long423852f2017-11-15 17:00:11 +0800288 if (out) {
289 for (i = 0; i < str_nums; i++)
290 if (str_list[i] >= stream->outcnt)
291 goto out;
292
293 param_len = str_nums * sizeof(__u16) +
294 sizeof(struct sctp_strreset_outreq);
295 }
296
297 if (in) {
298 for (i = 0; i < str_nums; i++)
299 if (str_list[i] >= stream->incnt)
300 goto out;
301
302 param_len += str_nums * sizeof(__u16) +
303 sizeof(struct sctp_strreset_inreq);
304 }
305
306 if (param_len > SCTP_MAX_CHUNK_LEN -
307 sizeof(struct sctp_reconf_chunk))
308 goto out;
309 }
Xin Long7f9d68a2017-01-18 00:44:47 +0800310
Xin Long1da4fc92017-10-28 19:43:54 +0800311 nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL);
312 if (!nstr_list) {
313 retval = -ENOMEM;
314 goto out;
315 }
Xin Long16e1a912017-02-17 12:45:40 +0800316
317 for (i = 0; i < str_nums; i++)
Xin Long1da4fc92017-10-28 19:43:54 +0800318 nstr_list[i] = htons(str_list[i]);
319
320 chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in);
321
322 kfree(nstr_list);
Xin Long16e1a912017-02-17 12:45:40 +0800323
Xin Long119aecb2017-02-09 01:18:16 +0800324 if (!chunk) {
325 retval = -ENOMEM;
Xin Long7f9d68a2017-01-18 00:44:47 +0800326 goto out;
Xin Long119aecb2017-02-09 01:18:16 +0800327 }
Xin Long7f9d68a2017-01-18 00:44:47 +0800328
329 if (out) {
330 if (str_nums)
331 for (i = 0; i < str_nums; i++)
332 stream->out[str_list[i]].state =
333 SCTP_STREAM_CLOSED;
334 else
335 for (i = 0; i < stream->outcnt; i++)
336 stream->out[i].state = SCTP_STREAM_CLOSED;
337 }
338
Xin Long7f9d68a2017-01-18 00:44:47 +0800339 asoc->strreset_chunk = chunk;
340 sctp_chunk_hold(asoc->strreset_chunk);
341
342 retval = sctp_send_reconf(asoc, chunk);
343 if (retval) {
344 sctp_chunk_put(asoc->strreset_chunk);
345 asoc->strreset_chunk = NULL;
Xin Long119aecb2017-02-09 01:18:16 +0800346 if (!out)
347 goto out;
348
349 if (str_nums)
350 for (i = 0; i < str_nums; i++)
351 stream->out[str_list[i]].state =
352 SCTP_STREAM_OPEN;
353 else
354 for (i = 0; i < stream->outcnt; i++)
355 stream->out[i].state = SCTP_STREAM_OPEN;
356
357 goto out;
Xin Long7f9d68a2017-01-18 00:44:47 +0800358 }
359
Xin Long119aecb2017-02-09 01:18:16 +0800360 asoc->strreset_outstanding = out + in;
361
Xin Long7f9d68a2017-01-18 00:44:47 +0800362out:
363 return retval;
364}
Xin Longa92ce1a2017-02-09 01:18:18 +0800365
366int sctp_send_reset_assoc(struct sctp_association *asoc)
367{
Xin Longcee360a2017-05-31 16:36:31 +0800368 struct sctp_stream *stream = &asoc->stream;
Xin Longa92ce1a2017-02-09 01:18:18 +0800369 struct sctp_chunk *chunk = NULL;
370 int retval;
371 __u16 i;
372
373 if (!asoc->peer.reconf_capable ||
374 !(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
375 return -ENOPROTOOPT;
376
377 if (asoc->strreset_outstanding)
378 return -EINPROGRESS;
379
380 chunk = sctp_make_strreset_tsnreq(asoc);
381 if (!chunk)
382 return -ENOMEM;
383
384 /* Block further xmit of data until this request is completed */
Xin Longcee360a2017-05-31 16:36:31 +0800385 for (i = 0; i < stream->outcnt; i++)
386 stream->out[i].state = SCTP_STREAM_CLOSED;
Xin Longa92ce1a2017-02-09 01:18:18 +0800387
388 asoc->strreset_chunk = chunk;
389 sctp_chunk_hold(asoc->strreset_chunk);
390
391 retval = sctp_send_reconf(asoc, chunk);
392 if (retval) {
393 sctp_chunk_put(asoc->strreset_chunk);
394 asoc->strreset_chunk = NULL;
395
Xin Longcee360a2017-05-31 16:36:31 +0800396 for (i = 0; i < stream->outcnt; i++)
397 stream->out[i].state = SCTP_STREAM_OPEN;
Xin Longa92ce1a2017-02-09 01:18:18 +0800398
399 return retval;
400 }
401
402 asoc->strreset_outstanding = 1;
403
404 return 0;
405}
Xin Long242bd2d2017-02-09 01:18:20 +0800406
407int sctp_send_add_streams(struct sctp_association *asoc,
408 struct sctp_add_streams *params)
409{
Xin Longcee360a2017-05-31 16:36:31 +0800410 struct sctp_stream *stream = &asoc->stream;
Xin Long242bd2d2017-02-09 01:18:20 +0800411 struct sctp_chunk *chunk = NULL;
Wei Yongjundc826732017-10-31 13:28:16 +0000412 int retval;
Xin Long242bd2d2017-02-09 01:18:20 +0800413 __u32 outcnt, incnt;
414 __u16 out, in;
415
416 if (!asoc->peer.reconf_capable ||
417 !(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) {
418 retval = -ENOPROTOOPT;
419 goto out;
420 }
421
422 if (asoc->strreset_outstanding) {
423 retval = -EINPROGRESS;
424 goto out;
425 }
426
427 out = params->sas_outstrms;
428 in = params->sas_instrms;
429 outcnt = stream->outcnt + out;
430 incnt = stream->incnt + in;
431 if (outcnt > SCTP_MAX_STREAM || incnt > SCTP_MAX_STREAM ||
432 (!out && !in)) {
433 retval = -EINVAL;
434 goto out;
435 }
436
437 if (out) {
Marcelo Ricardo Leitnere090abd2017-10-03 19:20:09 -0300438 retval = sctp_stream_alloc_out(stream, outcnt, GFP_KERNEL);
439 if (retval)
Xin Long242bd2d2017-02-09 01:18:20 +0800440 goto out;
Xin Long242bd2d2017-02-09 01:18:20 +0800441 }
442
Xin Long242bd2d2017-02-09 01:18:20 +0800443 chunk = sctp_make_strreset_addstrm(asoc, out, in);
Wei Yongjundc826732017-10-31 13:28:16 +0000444 if (!chunk) {
445 retval = -ENOMEM;
Xin Long242bd2d2017-02-09 01:18:20 +0800446 goto out;
Wei Yongjundc826732017-10-31 13:28:16 +0000447 }
Xin Long242bd2d2017-02-09 01:18:20 +0800448
449 asoc->strreset_chunk = chunk;
450 sctp_chunk_hold(asoc->strreset_chunk);
451
452 retval = sctp_send_reconf(asoc, chunk);
453 if (retval) {
454 sctp_chunk_put(asoc->strreset_chunk);
455 asoc->strreset_chunk = NULL;
456 goto out;
457 }
458
459 stream->incnt = incnt;
460 stream->outcnt = outcnt;
461
462 asoc->strreset_outstanding = !!out + !!in;
463
464out:
465 return retval;
466}
Xin Long81054472017-02-17 12:45:39 +0800467
Xin Long3c918702017-06-30 11:52:16 +0800468static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param(
Xin Long1da4fc92017-10-28 19:43:54 +0800469 struct sctp_association *asoc, __be32 resp_seq,
Xin Long50a41592017-03-10 12:11:09 +0800470 __be16 type)
Xin Long81054472017-02-17 12:45:39 +0800471{
472 struct sctp_chunk *chunk = asoc->strreset_chunk;
473 struct sctp_reconf_chunk *hdr;
474 union sctp_params param;
475
Xin Long50a41592017-03-10 12:11:09 +0800476 if (!chunk)
Xin Long81054472017-02-17 12:45:39 +0800477 return NULL;
478
479 hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
480 sctp_walk_params(param, hdr, params) {
481 /* sctp_strreset_tsnreq is actually the basic structure
482 * of all stream reconf params, so it's safe to use it
483 * to access request_seq.
484 */
485 struct sctp_strreset_tsnreq *req = param.v;
486
Xin Long50a41592017-03-10 12:11:09 +0800487 if ((!resp_seq || req->request_seq == resp_seq) &&
488 (!type || type == req->param_hdr.type))
Xin Long81054472017-02-17 12:45:39 +0800489 return param.v;
490 }
491
492 return NULL;
493}
494
Xin Longe4dc99c2017-04-15 22:00:27 +0800495static void sctp_update_strreset_result(struct sctp_association *asoc,
496 __u32 result)
497{
498 asoc->strreset_result[1] = asoc->strreset_result[0];
499 asoc->strreset_result[0] = result;
500}
501
Xin Long81054472017-02-17 12:45:39 +0800502struct sctp_chunk *sctp_process_strreset_outreq(
503 struct sctp_association *asoc,
504 union sctp_params param,
505 struct sctp_ulpevent **evp)
506{
507 struct sctp_strreset_outreq *outreq = param.v;
Xin Longcee360a2017-05-31 16:36:31 +0800508 struct sctp_stream *stream = &asoc->stream;
Xin Long81054472017-02-17 12:45:39 +0800509 __u32 result = SCTP_STRRESET_DENIED;
Xin Long1da4fc92017-10-28 19:43:54 +0800510 __u16 i, nums, flags = 0;
511 __be16 *str_p = NULL;
Xin Long81054472017-02-17 12:45:39 +0800512 __u32 request_seq;
513
514 request_seq = ntohl(outreq->request_seq);
515
516 if (ntohl(outreq->send_reset_at_tsn) >
517 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map)) {
518 result = SCTP_STRRESET_IN_PROGRESS;
Xin Longe4dc99c2017-04-15 22:00:27 +0800519 goto err;
Xin Long81054472017-02-17 12:45:39 +0800520 }
521
Xin Longe4dc99c2017-04-15 22:00:27 +0800522 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
523 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long81054472017-02-17 12:45:39 +0800524 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longe4dc99c2017-04-15 22:00:27 +0800525 goto err;
526 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
527 i = asoc->strreset_inseq - request_seq - 1;
528 result = asoc->strreset_result[i];
529 goto err;
Xin Long81054472017-02-17 12:45:39 +0800530 }
Xin Longe4dc99c2017-04-15 22:00:27 +0800531 asoc->strreset_inseq++;
Xin Long81054472017-02-17 12:45:39 +0800532
533 /* Check strreset_enable after inseq inc, as sender cannot tell
534 * the peer doesn't enable strreset after receiving response with
535 * result denied, as well as to keep consistent with bsd.
536 */
537 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
538 goto out;
539
540 if (asoc->strreset_chunk) {
Xin Long50a41592017-03-10 12:11:09 +0800541 if (!sctp_chunk_lookup_strreset_param(
542 asoc, outreq->response_seq,
543 SCTP_PARAM_RESET_IN_REQUEST)) {
Xin Long81054472017-02-17 12:45:39 +0800544 /* same process with outstanding isn't 0 */
545 result = SCTP_STRRESET_ERR_IN_PROGRESS;
546 goto out;
547 }
548
549 asoc->strreset_outstanding--;
550 asoc->strreset_outseq++;
551
552 if (!asoc->strreset_outstanding) {
Xin Long50a41592017-03-10 12:11:09 +0800553 struct sctp_transport *t;
554
Xin Long81054472017-02-17 12:45:39 +0800555 t = asoc->strreset_chunk->transport;
556 if (del_timer(&t->reconf_timer))
557 sctp_transport_put(t);
558
559 sctp_chunk_put(asoc->strreset_chunk);
560 asoc->strreset_chunk = NULL;
561 }
562
563 flags = SCTP_STREAM_RESET_INCOMING_SSN;
564 }
565
Xin Long3aa623d2017-11-25 21:05:32 +0800566 nums = (ntohs(param.p->length) - sizeof(*outreq)) / sizeof(__u16);
Xin Long81054472017-02-17 12:45:39 +0800567 if (nums) {
568 str_p = outreq->list_of_streams;
569 for (i = 0; i < nums; i++) {
570 if (ntohs(str_p[i]) >= stream->incnt) {
571 result = SCTP_STRRESET_ERR_WRONG_SSN;
572 goto out;
573 }
574 }
575
576 for (i = 0; i < nums; i++)
577 stream->in[ntohs(str_p[i])].ssn = 0;
578 } else {
579 for (i = 0; i < stream->incnt; i++)
580 stream->in[i].ssn = 0;
581 }
582
583 result = SCTP_STRRESET_PERFORMED;
584
585 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
586 flags | SCTP_STREAM_RESET_OUTGOING_SSN, nums, str_p,
587 GFP_ATOMIC);
588
589out:
Xin Longe4dc99c2017-04-15 22:00:27 +0800590 sctp_update_strreset_result(asoc, result);
591err:
Xin Long81054472017-02-17 12:45:39 +0800592 return sctp_make_strreset_resp(asoc, result, request_seq);
593}
Xin Long16e1a912017-02-17 12:45:40 +0800594
595struct sctp_chunk *sctp_process_strreset_inreq(
596 struct sctp_association *asoc,
597 union sctp_params param,
598 struct sctp_ulpevent **evp)
599{
600 struct sctp_strreset_inreq *inreq = param.v;
Xin Longcee360a2017-05-31 16:36:31 +0800601 struct sctp_stream *stream = &asoc->stream;
Xin Long16e1a912017-02-17 12:45:40 +0800602 __u32 result = SCTP_STRRESET_DENIED;
603 struct sctp_chunk *chunk = NULL;
Xin Long16e1a912017-02-17 12:45:40 +0800604 __u32 request_seq;
Xin Long1da4fc92017-10-28 19:43:54 +0800605 __u16 i, nums;
606 __be16 *str_p;
Xin Long16e1a912017-02-17 12:45:40 +0800607
608 request_seq = ntohl(inreq->request_seq);
Xin Longd0f025e2017-04-15 22:00:28 +0800609 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
610 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long16e1a912017-02-17 12:45:40 +0800611 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longd0f025e2017-04-15 22:00:28 +0800612 goto err;
613 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
614 i = asoc->strreset_inseq - request_seq - 1;
615 result = asoc->strreset_result[i];
616 if (result == SCTP_STRRESET_PERFORMED)
617 return NULL;
618 goto err;
Xin Long16e1a912017-02-17 12:45:40 +0800619 }
Xin Longd0f025e2017-04-15 22:00:28 +0800620 asoc->strreset_inseq++;
Xin Long16e1a912017-02-17 12:45:40 +0800621
622 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
623 goto out;
624
625 if (asoc->strreset_outstanding) {
626 result = SCTP_STRRESET_ERR_IN_PROGRESS;
627 goto out;
628 }
629
Xin Long3aa623d2017-11-25 21:05:32 +0800630 nums = (ntohs(param.p->length) - sizeof(*inreq)) / sizeof(__u16);
Xin Long16e1a912017-02-17 12:45:40 +0800631 str_p = inreq->list_of_streams;
632 for (i = 0; i < nums; i++) {
633 if (ntohs(str_p[i]) >= stream->outcnt) {
634 result = SCTP_STRRESET_ERR_WRONG_SSN;
635 goto out;
636 }
637 }
638
639 chunk = sctp_make_strreset_req(asoc, nums, str_p, 1, 0);
640 if (!chunk)
641 goto out;
642
643 if (nums)
644 for (i = 0; i < nums; i++)
645 stream->out[ntohs(str_p[i])].state =
646 SCTP_STREAM_CLOSED;
647 else
648 for (i = 0; i < stream->outcnt; i++)
649 stream->out[i].state = SCTP_STREAM_CLOSED;
650
651 asoc->strreset_chunk = chunk;
652 asoc->strreset_outstanding = 1;
653 sctp_chunk_hold(asoc->strreset_chunk);
654
Xin Longd0f025e2017-04-15 22:00:28 +0800655 result = SCTP_STRRESET_PERFORMED;
656
Xin Long16e1a912017-02-17 12:45:40 +0800657 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
658 SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC);
659
660out:
Xin Longd0f025e2017-04-15 22:00:28 +0800661 sctp_update_strreset_result(asoc, result);
662err:
Xin Long16e1a912017-02-17 12:45:40 +0800663 if (!chunk)
664 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
665
666 return chunk;
667}
Xin Long692787c2017-03-10 12:11:07 +0800668
669struct sctp_chunk *sctp_process_strreset_tsnreq(
670 struct sctp_association *asoc,
671 union sctp_params param,
672 struct sctp_ulpevent **evp)
673{
674 __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen;
675 struct sctp_strreset_tsnreq *tsnreq = param.v;
Xin Longcee360a2017-05-31 16:36:31 +0800676 struct sctp_stream *stream = &asoc->stream;
Xin Long692787c2017-03-10 12:11:07 +0800677 __u32 result = SCTP_STRRESET_DENIED;
678 __u32 request_seq;
679 __u16 i;
680
681 request_seq = ntohl(tsnreq->request_seq);
Xin Long6c801382017-04-15 22:00:29 +0800682 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
683 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long692787c2017-03-10 12:11:07 +0800684 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Long6c801382017-04-15 22:00:29 +0800685 goto err;
686 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
687 i = asoc->strreset_inseq - request_seq - 1;
688 result = asoc->strreset_result[i];
689 if (result == SCTP_STRRESET_PERFORMED) {
690 next_tsn = asoc->next_tsn;
691 init_tsn =
692 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1;
693 }
694 goto err;
Xin Long692787c2017-03-10 12:11:07 +0800695 }
Xin Long6c801382017-04-15 22:00:29 +0800696 asoc->strreset_inseq++;
Xin Long692787c2017-03-10 12:11:07 +0800697
698 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
699 goto out;
700
701 if (asoc->strreset_outstanding) {
702 result = SCTP_STRRESET_ERR_IN_PROGRESS;
703 goto out;
704 }
705
706 /* G3: The same processing as though a SACK chunk with no gap report
707 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
708 * received MUST be performed.
709 */
710 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
711 sctp_ulpq_reasm_flushtsn(&asoc->ulpq, max_tsn_seen);
712 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
713
714 /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
715 * TSN that the peer should use to send the next DATA chunk. The
716 * value SHOULD be the smallest TSN not acknowledged by the
717 * receiver of the request plus 2^31.
718 */
719 init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31);
720 sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
721 init_tsn, GFP_ATOMIC);
722
723 /* G4: The same processing as though a FWD-TSN chunk (as defined in
724 * [RFC3758]) with all streams affected and a new cumulative TSN
725 * ACK of the Receiver's Next TSN minus 1 were received MUST be
726 * performed.
727 */
728 sctp_outq_free(&asoc->outqueue);
729
730 /* G2: Compute an appropriate value for the local endpoint's next TSN,
731 * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
732 * chunk. The value SHOULD be the highest TSN sent by the receiver
733 * of the request plus 1.
734 */
735 next_tsn = asoc->next_tsn;
736 asoc->ctsn_ack_point = next_tsn - 1;
737 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
738
739 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
740 * incoming and outgoing streams.
741 */
742 for (i = 0; i < stream->outcnt; i++)
743 stream->out[i].ssn = 0;
744 for (i = 0; i < stream->incnt; i++)
745 stream->in[i].ssn = 0;
746
747 result = SCTP_STRRESET_PERFORMED;
748
749 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn,
750 next_tsn, GFP_ATOMIC);
751
752out:
Xin Long6c801382017-04-15 22:00:29 +0800753 sctp_update_strreset_result(asoc, result);
754err:
Xin Long692787c2017-03-10 12:11:07 +0800755 return sctp_make_strreset_tsnresp(asoc, result, request_seq,
756 next_tsn, init_tsn);
757}
Xin Long50a41592017-03-10 12:11:09 +0800758
759struct sctp_chunk *sctp_process_strreset_addstrm_out(
760 struct sctp_association *asoc,
761 union sctp_params param,
762 struct sctp_ulpevent **evp)
763{
764 struct sctp_strreset_addstrm *addstrm = param.v;
Xin Longcee360a2017-05-31 16:36:31 +0800765 struct sctp_stream *stream = &asoc->stream;
Xin Long50a41592017-03-10 12:11:09 +0800766 __u32 result = SCTP_STRRESET_DENIED;
Xin Long50a41592017-03-10 12:11:09 +0800767 __u32 request_seq, incnt;
Xin Longe4dc99c2017-04-15 22:00:27 +0800768 __u16 in, i;
Xin Long50a41592017-03-10 12:11:09 +0800769
770 request_seq = ntohl(addstrm->request_seq);
Xin Longe4dc99c2017-04-15 22:00:27 +0800771 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
772 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long50a41592017-03-10 12:11:09 +0800773 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longe4dc99c2017-04-15 22:00:27 +0800774 goto err;
775 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
776 i = asoc->strreset_inseq - request_seq - 1;
777 result = asoc->strreset_result[i];
778 goto err;
Xin Long50a41592017-03-10 12:11:09 +0800779 }
Xin Longe4dc99c2017-04-15 22:00:27 +0800780 asoc->strreset_inseq++;
Xin Long50a41592017-03-10 12:11:09 +0800781
782 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
783 goto out;
784
785 if (asoc->strreset_chunk) {
786 if (!sctp_chunk_lookup_strreset_param(
787 asoc, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS)) {
788 /* same process with outstanding isn't 0 */
789 result = SCTP_STRRESET_ERR_IN_PROGRESS;
790 goto out;
791 }
792
793 asoc->strreset_outstanding--;
794 asoc->strreset_outseq++;
795
796 if (!asoc->strreset_outstanding) {
797 struct sctp_transport *t;
798
799 t = asoc->strreset_chunk->transport;
800 if (del_timer(&t->reconf_timer))
801 sctp_transport_put(t);
802
803 sctp_chunk_put(asoc->strreset_chunk);
804 asoc->strreset_chunk = NULL;
805 }
806 }
807
808 in = ntohs(addstrm->number_of_streams);
809 incnt = stream->incnt + in;
810 if (!in || incnt > SCTP_MAX_STREAM)
811 goto out;
812
Marcelo Ricardo Leitner1fdb8d82017-10-03 19:20:10 -0300813 if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC))
Xin Long50a41592017-03-10 12:11:09 +0800814 goto out;
815
Xin Long50a41592017-03-10 12:11:09 +0800816 stream->incnt = incnt;
817
818 result = SCTP_STRRESET_PERFORMED;
819
820 *evp = sctp_ulpevent_make_stream_change_event(asoc,
821 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC);
822
823out:
Xin Longe4dc99c2017-04-15 22:00:27 +0800824 sctp_update_strreset_result(asoc, result);
825err:
Xin Long50a41592017-03-10 12:11:09 +0800826 return sctp_make_strreset_resp(asoc, result, request_seq);
827}
Xin Longc5c4ebb2017-03-10 12:11:10 +0800828
829struct sctp_chunk *sctp_process_strreset_addstrm_in(
830 struct sctp_association *asoc,
831 union sctp_params param,
832 struct sctp_ulpevent **evp)
833{
834 struct sctp_strreset_addstrm *addstrm = param.v;
Xin Longcee360a2017-05-31 16:36:31 +0800835 struct sctp_stream *stream = &asoc->stream;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800836 __u32 result = SCTP_STRRESET_DENIED;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800837 struct sctp_chunk *chunk = NULL;
838 __u32 request_seq, outcnt;
Xin Longd0f025e2017-04-15 22:00:28 +0800839 __u16 out, i;
Marcelo Ricardo Leitnere090abd2017-10-03 19:20:09 -0300840 int ret;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800841
842 request_seq = ntohl(addstrm->request_seq);
Xin Longd0f025e2017-04-15 22:00:28 +0800843 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
844 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Longc5c4ebb2017-03-10 12:11:10 +0800845 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longd0f025e2017-04-15 22:00:28 +0800846 goto err;
847 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
848 i = asoc->strreset_inseq - request_seq - 1;
849 result = asoc->strreset_result[i];
850 if (result == SCTP_STRRESET_PERFORMED)
851 return NULL;
852 goto err;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800853 }
Xin Longd0f025e2017-04-15 22:00:28 +0800854 asoc->strreset_inseq++;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800855
856 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
857 goto out;
858
859 if (asoc->strreset_outstanding) {
860 result = SCTP_STRRESET_ERR_IN_PROGRESS;
861 goto out;
862 }
863
864 out = ntohs(addstrm->number_of_streams);
865 outcnt = stream->outcnt + out;
866 if (!out || outcnt > SCTP_MAX_STREAM)
867 goto out;
868
Marcelo Ricardo Leitnere090abd2017-10-03 19:20:09 -0300869 ret = sctp_stream_alloc_out(stream, outcnt, GFP_ATOMIC);
870 if (ret)
Xin Longc5c4ebb2017-03-10 12:11:10 +0800871 goto out;
872
Xin Longc5c4ebb2017-03-10 12:11:10 +0800873 chunk = sctp_make_strreset_addstrm(asoc, out, 0);
874 if (!chunk)
875 goto out;
876
877 asoc->strreset_chunk = chunk;
878 asoc->strreset_outstanding = 1;
879 sctp_chunk_hold(asoc->strreset_chunk);
880
881 stream->outcnt = outcnt;
882
Xin Longd0f025e2017-04-15 22:00:28 +0800883 result = SCTP_STRRESET_PERFORMED;
884
Xin Longc5c4ebb2017-03-10 12:11:10 +0800885 *evp = sctp_ulpevent_make_stream_change_event(asoc,
886 0, 0, ntohs(addstrm->number_of_streams), GFP_ATOMIC);
887
888out:
Xin Longd0f025e2017-04-15 22:00:28 +0800889 sctp_update_strreset_result(asoc, result);
890err:
Xin Longc5c4ebb2017-03-10 12:11:10 +0800891 if (!chunk)
892 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
893
894 return chunk;
895}
Xin Long11ae76e2017-03-10 12:11:11 +0800896
897struct sctp_chunk *sctp_process_strreset_resp(
898 struct sctp_association *asoc,
899 union sctp_params param,
900 struct sctp_ulpevent **evp)
901{
Xin Longcee360a2017-05-31 16:36:31 +0800902 struct sctp_stream *stream = &asoc->stream;
Xin Long11ae76e2017-03-10 12:11:11 +0800903 struct sctp_strreset_resp *resp = param.v;
Xin Long11ae76e2017-03-10 12:11:11 +0800904 struct sctp_transport *t;
905 __u16 i, nums, flags = 0;
Xin Long3c918702017-06-30 11:52:16 +0800906 struct sctp_paramhdr *req;
Xin Long11ae76e2017-03-10 12:11:11 +0800907 __u32 result;
908
909 req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0);
910 if (!req)
911 return NULL;
912
913 result = ntohl(resp->result);
914 if (result != SCTP_STRRESET_PERFORMED) {
915 /* if in progress, do nothing but retransmit */
916 if (result == SCTP_STRRESET_IN_PROGRESS)
917 return NULL;
918 else if (result == SCTP_STRRESET_DENIED)
919 flags = SCTP_STREAM_RESET_DENIED;
920 else
921 flags = SCTP_STREAM_RESET_FAILED;
922 }
923
924 if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) {
925 struct sctp_strreset_outreq *outreq;
Xin Long1da4fc92017-10-28 19:43:54 +0800926 __be16 *str_p;
Xin Long11ae76e2017-03-10 12:11:11 +0800927
928 outreq = (struct sctp_strreset_outreq *)req;
Xin Longedb12f22017-04-15 21:56:57 +0800929 str_p = outreq->list_of_streams;
Xin Long3aa623d2017-11-25 21:05:32 +0800930 nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) /
931 sizeof(__u16);
Xin Long11ae76e2017-03-10 12:11:11 +0800932
933 if (result == SCTP_STRRESET_PERFORMED) {
934 if (nums) {
Xin Long11ae76e2017-03-10 12:11:11 +0800935 for (i = 0; i < nums; i++)
936 stream->out[ntohs(str_p[i])].ssn = 0;
937 } else {
938 for (i = 0; i < stream->outcnt; i++)
939 stream->out[i].ssn = 0;
940 }
941
942 flags = SCTP_STREAM_RESET_OUTGOING_SSN;
943 }
944
945 for (i = 0; i < stream->outcnt; i++)
946 stream->out[i].state = SCTP_STREAM_OPEN;
947
948 *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
949 nums, str_p, GFP_ATOMIC);
950 } else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) {
951 struct sctp_strreset_inreq *inreq;
Xin Long1da4fc92017-10-28 19:43:54 +0800952 __be16 *str_p;
Xin Long11ae76e2017-03-10 12:11:11 +0800953
954 /* if the result is performed, it's impossible for inreq */
955 if (result == SCTP_STRRESET_PERFORMED)
956 return NULL;
957
958 inreq = (struct sctp_strreset_inreq *)req;
Xin Longedb12f22017-04-15 21:56:57 +0800959 str_p = inreq->list_of_streams;
Xin Long3aa623d2017-11-25 21:05:32 +0800960 nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) /
961 sizeof(__u16);
Xin Long11ae76e2017-03-10 12:11:11 +0800962
Xin Long11ae76e2017-03-10 12:11:11 +0800963 *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
964 nums, str_p, GFP_ATOMIC);
965 } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) {
966 struct sctp_strreset_resptsn *resptsn;
967 __u32 stsn, rtsn;
968
969 /* check for resptsn, as sctp_verify_reconf didn't do it*/
970 if (ntohs(param.p->length) != sizeof(*resptsn))
971 return NULL;
972
973 resptsn = (struct sctp_strreset_resptsn *)resp;
974 stsn = ntohl(resptsn->senders_next_tsn);
975 rtsn = ntohl(resptsn->receivers_next_tsn);
976
977 if (result == SCTP_STRRESET_PERFORMED) {
978 __u32 mtsn = sctp_tsnmap_get_max_tsn_seen(
979 &asoc->peer.tsn_map);
980
981 sctp_ulpq_reasm_flushtsn(&asoc->ulpq, mtsn);
982 sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
983
984 sctp_tsnmap_init(&asoc->peer.tsn_map,
985 SCTP_TSN_MAP_INITIAL,
986 stsn, GFP_ATOMIC);
987
988 sctp_outq_free(&asoc->outqueue);
989
990 asoc->next_tsn = rtsn;
991 asoc->ctsn_ack_point = asoc->next_tsn - 1;
992 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
993
994 for (i = 0; i < stream->outcnt; i++)
995 stream->out[i].ssn = 0;
996 for (i = 0; i < stream->incnt; i++)
997 stream->in[i].ssn = 0;
998 }
999
1000 for (i = 0; i < stream->outcnt; i++)
1001 stream->out[i].state = SCTP_STREAM_OPEN;
1002
1003 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags,
1004 stsn, rtsn, GFP_ATOMIC);
1005 } else if (req->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) {
1006 struct sctp_strreset_addstrm *addstrm;
1007 __u16 number;
1008
1009 addstrm = (struct sctp_strreset_addstrm *)req;
1010 nums = ntohs(addstrm->number_of_streams);
1011 number = stream->outcnt - nums;
1012
1013 if (result == SCTP_STRRESET_PERFORMED)
1014 for (i = number; i < stream->outcnt; i++)
1015 stream->out[i].state = SCTP_STREAM_OPEN;
1016 else
1017 stream->outcnt = number;
1018
1019 *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
1020 0, nums, GFP_ATOMIC);
1021 } else if (req->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) {
1022 struct sctp_strreset_addstrm *addstrm;
1023
1024 /* if the result is performed, it's impossible for addstrm in
1025 * request.
1026 */
1027 if (result == SCTP_STRRESET_PERFORMED)
1028 return NULL;
1029
1030 addstrm = (struct sctp_strreset_addstrm *)req;
1031 nums = ntohs(addstrm->number_of_streams);
1032
1033 *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
1034 nums, 0, GFP_ATOMIC);
1035 }
1036
1037 asoc->strreset_outstanding--;
1038 asoc->strreset_outseq++;
1039
1040 /* remove everything for this reconf request */
1041 if (!asoc->strreset_outstanding) {
1042 t = asoc->strreset_chunk->transport;
1043 if (del_timer(&t->reconf_timer))
1044 sctp_transport_put(t);
1045
1046 sctp_chunk_put(asoc->strreset_chunk);
1047 asoc->strreset_chunk = NULL;
1048 }
1049
1050 return NULL;
1051}