blob: f1f1d1b232ba3e75ed28bf60f5eb111c56fa4852 [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 *
Xin Longfae8b6f2018-02-13 19:29:13 +08009 * This file contains sctp stream maniuplation primitives and helpers.
Xin Longa8386312017-01-06 22:18:33 +080010 *
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. */
Xin Long08f46072017-11-26 20:16:06 +080067 sctp_chunk_fail(ch, (__force __u32)SCTP_ERROR_INV_STRM);
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -030068 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 Leitner79d08952018-01-02 19:44:37 -0200159 ret = sctp_stream_alloc_out(stream, outcnt, gfp);
160 if (ret)
161 goto out;
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 Long0c3f6f62017-12-08 21:04:01 +0800170 sctp_stream_interleave_init(stream);
Xin Longff356412017-05-31 16:36:32 +0800171 if (!incnt)
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300172 goto out;
Xin Longff356412017-05-31 16:36:32 +0800173
Marcelo Ricardo Leitner79d08952018-01-02 19:44:37 -0200174 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 Longa8386312017-01-06 22:18:33 +0800181 }
182
Xin Longff356412017-05-31 16:36:32 +0800183 stream->incnt = incnt;
184
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300185out:
186 return ret;
Xin Longa8386312017-01-06 22:18:33 +0800187}
188
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300189int 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 Leitner5bbbbe32017-10-03 19:20:13 -0300198 return sctp_sched_init_sid(stream, sid, GFP_KERNEL);
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300199}
200
Xin Longa8386312017-01-06 22:18:33 +0800201void sctp_stream_free(struct sctp_stream *stream)
202{
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300203 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300204 int i;
205
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300206 sched->free(stream);
Marcelo Ricardo Leitnerf952be72017-10-03 19:20:11 -0300207 for (i = 0; i < stream->outcnt; i++)
208 kfree(stream->out[i].ext);
Xin Longa8386312017-01-06 22:18:33 +0800209 kfree(stream->out);
210 kfree(stream->in);
Xin Longa8386312017-01-06 22:18:33 +0800211}
212
213void sctp_stream_clear(struct sctp_stream *stream)
214{
215 int i;
216
Xin Long107e2422017-12-15 00:41:31 +0800217 for (i = 0; i < stream->outcnt; i++) {
218 stream->out[i].mid = 0;
219 stream->out[i].mid_uo = 0;
220 }
Xin Longa8386312017-01-06 22:18:33 +0800221
222 for (i = 0; i < stream->incnt; i++)
Xin Long107e2422017-12-15 00:41:31 +0800223 stream->in[i].mid = 0;
Xin Longa8386312017-01-06 22:18:33 +0800224}
Xin Long7f9d68a2017-01-18 00:44:47 +0800225
Xin Longcee360a2017-05-31 16:36:31 +0800226void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new)
227{
Marcelo Ricardo Leitner5bbbbe32017-10-03 19:20:13 -0300228 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 Longcee360a2017-05-31 16:36:31 +0800232 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 Leitner5bbbbe32017-10-03 19:20:13 -0300239 sched->sched_all(stream);
240
Xin Longcee360a2017-05-31 16:36:31 +0800241 new->out = NULL;
242 new->in = NULL;
Xin Long6a9a27d2018-04-26 15:21:44 +0800243 new->outcnt = 0;
244 new->incnt = 0;
Xin Longcee360a2017-05-31 16:36:31 +0800245}
246
Xin Long7f9d68a2017-01-18 00:44:47 +0800247static 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 Longd570a592017-11-25 21:05:33 +0800260static 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 Long7f9d68a2017-01-18 00:44:47 +0800284int sctp_send_reset_streams(struct sctp_association *asoc,
285 struct sctp_reset_streams *params)
286{
Xin Longcee360a2017-05-31 16:36:31 +0800287 struct sctp_stream *stream = &asoc->stream;
Xin Long7f9d68a2017-01-18 00:44:47 +0800288 __u16 i, str_nums, *str_list;
289 struct sctp_chunk *chunk;
290 int retval = -EINVAL;
Xin Long1da4fc92017-10-28 19:43:54 +0800291 __be16 *nstr_list;
Xin Long7f9d68a2017-01-18 00:44:47 +0800292 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 Long423852f2017-11-15 17:00:11 +0800312 if (str_nums) {
313 int param_len = 0;
Xin Long7f9d68a2017-01-18 00:44:47 +0800314
Xin Long423852f2017-11-15 17:00:11 +0800315 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 Long7f9d68a2017-01-18 00:44:47 +0800337
Xin Long1da4fc92017-10-28 19:43:54 +0800338 nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL);
339 if (!nstr_list) {
340 retval = -ENOMEM;
341 goto out;
342 }
Xin Long16e1a912017-02-17 12:45:40 +0800343
344 for (i = 0; i < str_nums; i++)
Xin Long1da4fc92017-10-28 19:43:54 +0800345 nstr_list[i] = htons(str_list[i]);
346
Xin Longd570a592017-11-25 21:05:33 +0800347 if (out && !sctp_stream_outq_is_empty(stream, str_nums, nstr_list)) {
348 retval = -EAGAIN;
349 goto out;
350 }
351
Xin Long1da4fc92017-10-28 19:43:54 +0800352 chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in);
353
354 kfree(nstr_list);
Xin Long16e1a912017-02-17 12:45:40 +0800355
Xin Long119aecb2017-02-09 01:18:16 +0800356 if (!chunk) {
357 retval = -ENOMEM;
Xin Long7f9d68a2017-01-18 00:44:47 +0800358 goto out;
Xin Long119aecb2017-02-09 01:18:16 +0800359 }
Xin Long7f9d68a2017-01-18 00:44:47 +0800360
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 Long7f9d68a2017-01-18 00:44:47 +0800371 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 Long119aecb2017-02-09 01:18:16 +0800378 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 Long7f9d68a2017-01-18 00:44:47 +0800390 }
391
Xin Long119aecb2017-02-09 01:18:16 +0800392 asoc->strreset_outstanding = out + in;
393
Xin Long7f9d68a2017-01-18 00:44:47 +0800394out:
395 return retval;
396}
Xin Longa92ce1a2017-02-09 01:18:18 +0800397
398int sctp_send_reset_assoc(struct sctp_association *asoc)
399{
Xin Longcee360a2017-05-31 16:36:31 +0800400 struct sctp_stream *stream = &asoc->stream;
Xin Longa92ce1a2017-02-09 01:18:18 +0800401 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 Long5c6144a2017-11-25 21:05:34 +0800412 if (!sctp_outq_is_empty(&asoc->outqueue))
413 return -EAGAIN;
414
Xin Longa92ce1a2017-02-09 01:18:18 +0800415 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 Longcee360a2017-05-31 16:36:31 +0800420 for (i = 0; i < stream->outcnt; i++)
421 stream->out[i].state = SCTP_STREAM_CLOSED;
Xin Longa92ce1a2017-02-09 01:18:18 +0800422
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 Longcee360a2017-05-31 16:36:31 +0800431 for (i = 0; i < stream->outcnt; i++)
432 stream->out[i].state = SCTP_STREAM_OPEN;
Xin Longa92ce1a2017-02-09 01:18:18 +0800433
434 return retval;
435 }
436
437 asoc->strreset_outstanding = 1;
438
439 return 0;
440}
Xin Long242bd2d2017-02-09 01:18:20 +0800441
442int sctp_send_add_streams(struct sctp_association *asoc,
443 struct sctp_add_streams *params)
444{
Xin Longcee360a2017-05-31 16:36:31 +0800445 struct sctp_stream *stream = &asoc->stream;
Xin Long242bd2d2017-02-09 01:18:20 +0800446 struct sctp_chunk *chunk = NULL;
Wei Yongjundc826732017-10-31 13:28:16 +0000447 int retval;
Xin Long242bd2d2017-02-09 01:18:20 +0800448 __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 Leitnere090abd2017-10-03 19:20:09 -0300473 retval = sctp_stream_alloc_out(stream, outcnt, GFP_KERNEL);
474 if (retval)
Xin Long242bd2d2017-02-09 01:18:20 +0800475 goto out;
Xin Long242bd2d2017-02-09 01:18:20 +0800476 }
477
Xin Long242bd2d2017-02-09 01:18:20 +0800478 chunk = sctp_make_strreset_addstrm(asoc, out, in);
Wei Yongjundc826732017-10-31 13:28:16 +0000479 if (!chunk) {
480 retval = -ENOMEM;
Xin Long242bd2d2017-02-09 01:18:20 +0800481 goto out;
Wei Yongjundc826732017-10-31 13:28:16 +0000482 }
Xin Long242bd2d2017-02-09 01:18:20 +0800483
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
499out:
500 return retval;
501}
Xin Long81054472017-02-17 12:45:39 +0800502
Xin Long3c918702017-06-30 11:52:16 +0800503static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param(
Xin Long1da4fc92017-10-28 19:43:54 +0800504 struct sctp_association *asoc, __be32 resp_seq,
Xin Long50a41592017-03-10 12:11:09 +0800505 __be16 type)
Xin Long81054472017-02-17 12:45:39 +0800506{
507 struct sctp_chunk *chunk = asoc->strreset_chunk;
508 struct sctp_reconf_chunk *hdr;
509 union sctp_params param;
510
Xin Long50a41592017-03-10 12:11:09 +0800511 if (!chunk)
Xin Long81054472017-02-17 12:45:39 +0800512 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 Long50a41592017-03-10 12:11:09 +0800522 if ((!resp_seq || req->request_seq == resp_seq) &&
523 (!type || type == req->param_hdr.type))
Xin Long81054472017-02-17 12:45:39 +0800524 return param.v;
525 }
526
527 return NULL;
528}
529
Xin Longe4dc99c2017-04-15 22:00:27 +0800530static 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 Long81054472017-02-17 12:45:39 +0800537struct 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 Longcee360a2017-05-31 16:36:31 +0800543 struct sctp_stream *stream = &asoc->stream;
Xin Long81054472017-02-17 12:45:39 +0800544 __u32 result = SCTP_STRRESET_DENIED;
Xin Long1da4fc92017-10-28 19:43:54 +0800545 __u16 i, nums, flags = 0;
546 __be16 *str_p = NULL;
Xin Long81054472017-02-17 12:45:39 +0800547 __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 Longe4dc99c2017-04-15 22:00:27 +0800554 goto err;
Xin Long81054472017-02-17 12:45:39 +0800555 }
556
Xin Longe4dc99c2017-04-15 22:00:27 +0800557 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
558 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long81054472017-02-17 12:45:39 +0800559 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longe4dc99c2017-04-15 22:00:27 +0800560 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 Long81054472017-02-17 12:45:39 +0800565 }
Xin Longe4dc99c2017-04-15 22:00:27 +0800566 asoc->strreset_inseq++;
Xin Long81054472017-02-17 12:45:39 +0800567
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 Long50a41592017-03-10 12:11:09 +0800576 if (!sctp_chunk_lookup_strreset_param(
577 asoc, outreq->response_seq,
578 SCTP_PARAM_RESET_IN_REQUEST)) {
Xin Long81054472017-02-17 12:45:39 +0800579 /* 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 Long50a41592017-03-10 12:11:09 +0800588 struct sctp_transport *t;
589
Xin Long81054472017-02-17 12:45:39 +0800590 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 Long3aa623d2017-11-25 21:05:32 +0800601 nums = (ntohs(param.p->length) - sizeof(*outreq)) / sizeof(__u16);
Xin Long81054472017-02-17 12:45:39 +0800602 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 Long107e2422017-12-15 00:41:31 +0800612 stream->in[ntohs(str_p[i])].mid = 0;
Xin Long81054472017-02-17 12:45:39 +0800613 } else {
614 for (i = 0; i < stream->incnt; i++)
Xin Long107e2422017-12-15 00:41:31 +0800615 stream->in[i].mid = 0;
Xin Long81054472017-02-17 12:45:39 +0800616 }
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
624out:
Xin Longe4dc99c2017-04-15 22:00:27 +0800625 sctp_update_strreset_result(asoc, result);
626err:
Xin Long81054472017-02-17 12:45:39 +0800627 return sctp_make_strreset_resp(asoc, result, request_seq);
628}
Xin Long16e1a912017-02-17 12:45:40 +0800629
630struct 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 Longcee360a2017-05-31 16:36:31 +0800636 struct sctp_stream *stream = &asoc->stream;
Xin Long16e1a912017-02-17 12:45:40 +0800637 __u32 result = SCTP_STRRESET_DENIED;
638 struct sctp_chunk *chunk = NULL;
Xin Long16e1a912017-02-17 12:45:40 +0800639 __u32 request_seq;
Xin Long1da4fc92017-10-28 19:43:54 +0800640 __u16 i, nums;
641 __be16 *str_p;
Xin Long16e1a912017-02-17 12:45:40 +0800642
643 request_seq = ntohl(inreq->request_seq);
Xin Longd0f025e2017-04-15 22:00:28 +0800644 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
645 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long16e1a912017-02-17 12:45:40 +0800646 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longd0f025e2017-04-15 22:00:28 +0800647 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 Long16e1a912017-02-17 12:45:40 +0800654 }
Xin Longd0f025e2017-04-15 22:00:28 +0800655 asoc->strreset_inseq++;
Xin Long16e1a912017-02-17 12:45:40 +0800656
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 Long3aa623d2017-11-25 21:05:32 +0800665 nums = (ntohs(param.p->length) - sizeof(*inreq)) / sizeof(__u16);
Xin Long16e1a912017-02-17 12:45:40 +0800666 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 Longd570a592017-11-25 21:05:33 +0800674 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 Long16e1a912017-02-17 12:45:40 +0800680 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 Longd0f025e2017-04-15 22:00:28 +0800696 result = SCTP_STRRESET_PERFORMED;
697
Xin Long16e1a912017-02-17 12:45:40 +0800698 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
699 SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC);
700
701out:
Xin Longd0f025e2017-04-15 22:00:28 +0800702 sctp_update_strreset_result(asoc, result);
703err:
Xin Long16e1a912017-02-17 12:45:40 +0800704 if (!chunk)
705 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
706
707 return chunk;
708}
Xin Long692787c2017-03-10 12:11:07 +0800709
710struct 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 Longcee360a2017-05-31 16:36:31 +0800717 struct sctp_stream *stream = &asoc->stream;
Xin Long692787c2017-03-10 12:11:07 +0800718 __u32 result = SCTP_STRRESET_DENIED;
719 __u32 request_seq;
720 __u16 i;
721
722 request_seq = ntohl(tsnreq->request_seq);
Xin Long6c801382017-04-15 22:00:29 +0800723 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
724 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long692787c2017-03-10 12:11:07 +0800725 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Long6c801382017-04-15 22:00:29 +0800726 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 Long52a39582017-11-25 21:05:36 +0800731 next_tsn = asoc->ctsn_ack_point + 1;
Xin Long6c801382017-04-15 22:00:29 +0800732 init_tsn =
733 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1;
734 }
735 goto err;
Xin Long692787c2017-03-10 12:11:07 +0800736 }
Xin Long5c6144a2017-11-25 21:05:34 +0800737
738 if (!sctp_outq_is_empty(&asoc->outqueue)) {
739 result = SCTP_STRRESET_IN_PROGRESS;
740 goto err;
741 }
742
Xin Long6c801382017-04-15 22:00:29 +0800743 asoc->strreset_inseq++;
Xin Long692787c2017-03-10 12:11:07 +0800744
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 Long159f2a72017-11-25 21:05:35 +0800753 /* 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 Long692787c2017-03-10 12:11:07 +0800757 */
758 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
Xin Long47b20a82017-12-15 00:41:28 +0800759 asoc->stream.si->report_ftsn(&asoc->ulpq, max_tsn_seen);
Xin Long692787c2017-03-10 12:11:07 +0800760
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 Long159f2a72017-11-25 21:05:35 +0800770 /* 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 Long692787c2017-03-10 12:11:07 +0800773 */
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 Long107e2422017-12-15 00:41:31 +0800788 for (i = 0; i < stream->outcnt; i++) {
789 stream->out[i].mid = 0;
790 stream->out[i].mid_uo = 0;
791 }
Xin Long692787c2017-03-10 12:11:07 +0800792 for (i = 0; i < stream->incnt; i++)
Xin Long107e2422017-12-15 00:41:31 +0800793 stream->in[i].mid = 0;
Xin Long692787c2017-03-10 12:11:07 +0800794
795 result = SCTP_STRRESET_PERFORMED;
796
797 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn,
798 next_tsn, GFP_ATOMIC);
799
800out:
Xin Long6c801382017-04-15 22:00:29 +0800801 sctp_update_strreset_result(asoc, result);
802err:
Xin Long692787c2017-03-10 12:11:07 +0800803 return sctp_make_strreset_tsnresp(asoc, result, request_seq,
804 next_tsn, init_tsn);
805}
Xin Long50a41592017-03-10 12:11:09 +0800806
807struct 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 Longcee360a2017-05-31 16:36:31 +0800813 struct sctp_stream *stream = &asoc->stream;
Xin Long50a41592017-03-10 12:11:09 +0800814 __u32 result = SCTP_STRRESET_DENIED;
Xin Long50a41592017-03-10 12:11:09 +0800815 __u32 request_seq, incnt;
Xin Longe4dc99c2017-04-15 22:00:27 +0800816 __u16 in, i;
Xin Long50a41592017-03-10 12:11:09 +0800817
818 request_seq = ntohl(addstrm->request_seq);
Xin Longe4dc99c2017-04-15 22:00:27 +0800819 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
820 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Long50a41592017-03-10 12:11:09 +0800821 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longe4dc99c2017-04-15 22:00:27 +0800822 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 Long50a41592017-03-10 12:11:09 +0800827 }
Xin Longe4dc99c2017-04-15 22:00:27 +0800828 asoc->strreset_inseq++;
Xin Long50a41592017-03-10 12:11:09 +0800829
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 Leitner1fdb8d82017-10-03 19:20:10 -0300861 if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC))
Xin Long50a41592017-03-10 12:11:09 +0800862 goto out;
863
Xin Long50a41592017-03-10 12:11:09 +0800864 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
871out:
Xin Longe4dc99c2017-04-15 22:00:27 +0800872 sctp_update_strreset_result(asoc, result);
873err:
Xin Long50a41592017-03-10 12:11:09 +0800874 return sctp_make_strreset_resp(asoc, result, request_seq);
875}
Xin Longc5c4ebb2017-03-10 12:11:10 +0800876
877struct 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 Longcee360a2017-05-31 16:36:31 +0800883 struct sctp_stream *stream = &asoc->stream;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800884 __u32 result = SCTP_STRRESET_DENIED;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800885 struct sctp_chunk *chunk = NULL;
886 __u32 request_seq, outcnt;
Xin Longd0f025e2017-04-15 22:00:28 +0800887 __u16 out, i;
Marcelo Ricardo Leitnere090abd2017-10-03 19:20:09 -0300888 int ret;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800889
890 request_seq = ntohl(addstrm->request_seq);
Xin Longd0f025e2017-04-15 22:00:28 +0800891 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
892 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
Xin Longc5c4ebb2017-03-10 12:11:10 +0800893 result = SCTP_STRRESET_ERR_BAD_SEQNO;
Xin Longd0f025e2017-04-15 22:00:28 +0800894 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 Longc5c4ebb2017-03-10 12:11:10 +0800901 }
Xin Longd0f025e2017-04-15 22:00:28 +0800902 asoc->strreset_inseq++;
Xin Longc5c4ebb2017-03-10 12:11:10 +0800903
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 Leitnere090abd2017-10-03 19:20:09 -0300917 ret = sctp_stream_alloc_out(stream, outcnt, GFP_ATOMIC);
918 if (ret)
Xin Longc5c4ebb2017-03-10 12:11:10 +0800919 goto out;
920
Xin Longc5c4ebb2017-03-10 12:11:10 +0800921 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 Longd0f025e2017-04-15 22:00:28 +0800931 result = SCTP_STRRESET_PERFORMED;
932
Xin Longc5c4ebb2017-03-10 12:11:10 +0800933 *evp = sctp_ulpevent_make_stream_change_event(asoc,
934 0, 0, ntohs(addstrm->number_of_streams), GFP_ATOMIC);
935
936out:
Xin Longd0f025e2017-04-15 22:00:28 +0800937 sctp_update_strreset_result(asoc, result);
938err:
Xin Longc5c4ebb2017-03-10 12:11:10 +0800939 if (!chunk)
940 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
941
942 return chunk;
943}
Xin Long11ae76e2017-03-10 12:11:11 +0800944
945struct sctp_chunk *sctp_process_strreset_resp(
946 struct sctp_association *asoc,
947 union sctp_params param,
948 struct sctp_ulpevent **evp)
949{
Xin Longcee360a2017-05-31 16:36:31 +0800950 struct sctp_stream *stream = &asoc->stream;
Xin Long11ae76e2017-03-10 12:11:11 +0800951 struct sctp_strreset_resp *resp = param.v;
Xin Long11ae76e2017-03-10 12:11:11 +0800952 struct sctp_transport *t;
953 __u16 i, nums, flags = 0;
Xin Long3c918702017-06-30 11:52:16 +0800954 struct sctp_paramhdr *req;
Xin Long11ae76e2017-03-10 12:11:11 +0800955 __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 Long1da4fc92017-10-28 19:43:54 +0800974 __be16 *str_p;
Xin Long11ae76e2017-03-10 12:11:11 +0800975
976 outreq = (struct sctp_strreset_outreq *)req;
Xin Longedb12f22017-04-15 21:56:57 +0800977 str_p = outreq->list_of_streams;
Xin Long3aa623d2017-11-25 21:05:32 +0800978 nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) /
979 sizeof(__u16);
Xin Long11ae76e2017-03-10 12:11:11 +0800980
981 if (result == SCTP_STRRESET_PERFORMED) {
982 if (nums) {
Xin Long107e2422017-12-15 00:41:31 +0800983 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 Long11ae76e2017-03-10 12:11:11 +0800987 } else {
Xin Long107e2422017-12-15 00:41:31 +0800988 for (i = 0; i < stream->outcnt; i++) {
989 stream->out[i].mid = 0;
990 stream->out[i].mid_uo = 0;
991 }
Xin Long11ae76e2017-03-10 12:11:11 +0800992 }
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 Long1da4fc92017-10-28 19:43:54 +08001004 __be16 *str_p;
Xin Long11ae76e2017-03-10 12:11:11 +08001005
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 Longedb12f22017-04-15 21:56:57 +08001011 str_p = inreq->list_of_streams;
Xin Long3aa623d2017-11-25 21:05:32 +08001012 nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) /
1013 sizeof(__u16);
Xin Long11ae76e2017-03-10 12:11:11 +08001014
Xin Long11ae76e2017-03-10 12:11:11 +08001015 *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 Long159f2a72017-11-25 21:05:35 +08001032 LIST_HEAD(temp);
Xin Long11ae76e2017-03-10 12:11:11 +08001033
Xin Long47b20a82017-12-15 00:41:28 +08001034 asoc->stream.si->report_ftsn(&asoc->ulpq, mtsn);
Xin Long11ae76e2017-03-10 12:11:11 +08001035
1036 sctp_tsnmap_init(&asoc->peer.tsn_map,
1037 SCTP_TSN_MAP_INITIAL,
1038 stsn, GFP_ATOMIC);
1039
Xin Long159f2a72017-11-25 21:05:35 +08001040 /* 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 Long11ae76e2017-03-10 12:11:11 +08001045 sctp_outq_free(&asoc->outqueue);
Xin Long159f2a72017-11-25 21:05:35 +08001046 list_splice_init(&temp, &asoc->outqueue.out_chunk_list);
Xin Long11ae76e2017-03-10 12:11:11 +08001047
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 Long107e2422017-12-15 00:41:31 +08001052 for (i = 0; i < stream->outcnt; i++) {
1053 stream->out[i].mid = 0;
1054 stream->out[i].mid_uo = 0;
1055 }
Xin Long11ae76e2017-03-10 12:11:11 +08001056 for (i = 0; i < stream->incnt; i++)
Xin Long107e2422017-12-15 00:41:31 +08001057 stream->in[i].mid = 0;
Xin Long11ae76e2017-03-10 12:11:11 +08001058 }
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}