1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* SCTP kernel implementation
3 * (C) Copyright IBM Corp. 2001, 2004
4 * Copyright (c) 1999-2000 Cisco, Inc.
5 * Copyright (c) 1999-2001 Motorola, Inc.
6 * Copyright (c) 2001 Intel Corp.
8 * This file is part of the SCTP kernel implementation
10 * This file contains sctp stream maniuplation primitives and helpers.
12 * Please send any bug reports or fixes you make to the
16 * Written or modified by:
20 #include <linux/list.h>
21 #include <net/sctp/sctp.h>
22 #include <net/sctp/sm.h>
23 #include <net/sctp/stream_sched.h>
25 /* Migrates chunks from stream queues to new stream queues if needed,
26 * but not across associations. Also, removes those chunks to streams
27 * higher than the new max.
29 static void sctp_stream_outq_migrate(struct sctp_stream *stream,
30 struct sctp_stream *new, __u16 outcnt)
32 struct sctp_association *asoc;
33 struct sctp_chunk *ch, *temp;
34 struct sctp_outq *outq;
37 asoc = container_of(stream, struct sctp_association, stream);
38 outq = &asoc->outqueue;
40 list_for_each_entry_safe(ch, temp, &outq->out_chunk_list, list) {
41 __u16 sid = sctp_chunk_stream_no(ch);
46 sctp_sched_dequeue_common(outq, ch);
47 /* No need to call dequeue_done here because
48 * the chunks are not scheduled by now.
51 /* Mark as failed send. */
52 sctp_chunk_fail(ch, (__force __u32)SCTP_ERROR_INV_STRM);
53 if (asoc->peer.prsctp_capable &&
54 SCTP_PR_PRIO_ENABLED(ch->sinfo.sinfo_flags))
55 asoc->sent_cnt_removable--;
61 /* Here we actually move the old ext stuff into the new
62 * buffer, because we want to keep it. Then
63 * sctp_stream_update will swap ->out pointers.
65 for (i = 0; i < outcnt; i++) {
66 kfree(SCTP_SO(new, i)->ext);
67 SCTP_SO(new, i)->ext = SCTP_SO(stream, i)->ext;
68 SCTP_SO(stream, i)->ext = NULL;
72 for (i = outcnt; i < stream->outcnt; i++) {
73 kfree(SCTP_SO(stream, i)->ext);
74 SCTP_SO(stream, i)->ext = NULL;
78 static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt,
83 if (outcnt <= stream->outcnt)
86 ret = genradix_prealloc(&stream->out, outcnt, gfp);
90 stream->outcnt = outcnt;
94 static int sctp_stream_alloc_in(struct sctp_stream *stream, __u16 incnt,
99 if (incnt <= stream->incnt)
102 ret = genradix_prealloc(&stream->in, incnt, gfp);
106 stream->incnt = incnt;
110 int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
113 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
118 /* Initial stream->out size may be very big, so free it and alloc
119 * a new one with new outcnt to save memory if needed.
121 if (outcnt == stream->outcnt)
124 /* Filter out chunks queued on streams that won't exist anymore */
125 sched->unsched_all(stream);
126 sctp_stream_outq_migrate(stream, NULL, outcnt);
127 sched->sched_all(stream);
129 ret = sctp_stream_alloc_out(stream, outcnt, gfp);
133 for (i = 0; i < stream->outcnt; i++)
134 SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
137 sctp_stream_interleave_init(stream);
141 ret = sctp_stream_alloc_in(stream, incnt, gfp);
149 genradix_free(&stream->in);
151 genradix_free(&stream->out);
157 int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid)
159 struct sctp_stream_out_ext *soute;
162 soute = kzalloc(sizeof(*soute), GFP_KERNEL);
165 SCTP_SO(stream, sid)->ext = soute;
167 ret = sctp_sched_init_sid(stream, sid, GFP_KERNEL);
169 kfree(SCTP_SO(stream, sid)->ext);
170 SCTP_SO(stream, sid)->ext = NULL;
176 void sctp_stream_free(struct sctp_stream *stream)
178 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
182 for (i = 0; i < stream->outcnt; i++)
183 kfree(SCTP_SO(stream, i)->ext);
184 genradix_free(&stream->out);
185 genradix_free(&stream->in);
188 void sctp_stream_clear(struct sctp_stream *stream)
192 for (i = 0; i < stream->outcnt; i++) {
193 SCTP_SO(stream, i)->mid = 0;
194 SCTP_SO(stream, i)->mid_uo = 0;
197 for (i = 0; i < stream->incnt; i++)
198 SCTP_SI(stream, i)->mid = 0;
201 void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new)
203 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
205 sched->unsched_all(stream);
206 sctp_stream_outq_migrate(stream, new, new->outcnt);
207 sctp_stream_free(stream);
209 stream->out = new->out;
210 stream->in = new->in;
211 stream->outcnt = new->outcnt;
212 stream->incnt = new->incnt;
214 sched->sched_all(stream);
216 new->out.tree.root = NULL;
217 new->in.tree.root = NULL;
222 static int sctp_send_reconf(struct sctp_association *asoc,
223 struct sctp_chunk *chunk)
225 struct net *net = sock_net(asoc->base.sk);
228 retval = sctp_primitive_RECONF(net, asoc, chunk);
230 sctp_chunk_free(chunk);
235 static bool sctp_stream_outq_is_empty(struct sctp_stream *stream,
236 __u16 str_nums, __be16 *str_list)
238 struct sctp_association *asoc;
241 asoc = container_of(stream, struct sctp_association, stream);
242 if (!asoc->outqueue.out_qlen)
248 for (i = 0; i < str_nums; i++) {
249 __u16 sid = ntohs(str_list[i]);
251 if (SCTP_SO(stream, sid)->ext &&
252 !list_empty(&SCTP_SO(stream, sid)->ext->outq))
259 int sctp_send_reset_streams(struct sctp_association *asoc,
260 struct sctp_reset_streams *params)
262 struct sctp_stream *stream = &asoc->stream;
263 __u16 i, str_nums, *str_list;
264 struct sctp_chunk *chunk;
265 int retval = -EINVAL;
269 if (!asoc->peer.reconf_capable ||
270 !(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) {
271 retval = -ENOPROTOOPT;
275 if (asoc->strreset_outstanding) {
276 retval = -EINPROGRESS;
280 out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING;
281 in = params->srs_flags & SCTP_STREAM_RESET_INCOMING;
285 str_nums = params->srs_number_streams;
286 str_list = params->srs_stream_list;
291 for (i = 0; i < str_nums; i++)
292 if (str_list[i] >= stream->outcnt)
295 param_len = str_nums * sizeof(__u16) +
296 sizeof(struct sctp_strreset_outreq);
300 for (i = 0; i < str_nums; i++)
301 if (str_list[i] >= stream->incnt)
304 param_len += str_nums * sizeof(__u16) +
305 sizeof(struct sctp_strreset_inreq);
308 if (param_len > SCTP_MAX_CHUNK_LEN -
309 sizeof(struct sctp_reconf_chunk))
313 nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL);
319 for (i = 0; i < str_nums; i++)
320 nstr_list[i] = htons(str_list[i]);
322 if (out && !sctp_stream_outq_is_empty(stream, str_nums, nstr_list)) {
328 chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in);
339 for (i = 0; i < str_nums; i++)
340 SCTP_SO(stream, str_list[i])->state =
343 for (i = 0; i < stream->outcnt; i++)
344 SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED;
347 asoc->strreset_chunk = chunk;
348 sctp_chunk_hold(asoc->strreset_chunk);
350 retval = sctp_send_reconf(asoc, chunk);
352 sctp_chunk_put(asoc->strreset_chunk);
353 asoc->strreset_chunk = NULL;
358 for (i = 0; i < str_nums; i++)
359 SCTP_SO(stream, str_list[i])->state =
362 for (i = 0; i < stream->outcnt; i++)
363 SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
368 asoc->strreset_outstanding = out + in;
374 int sctp_send_reset_assoc(struct sctp_association *asoc)
376 struct sctp_stream *stream = &asoc->stream;
377 struct sctp_chunk *chunk = NULL;
381 if (!asoc->peer.reconf_capable ||
382 !(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
385 if (asoc->strreset_outstanding)
388 if (!sctp_outq_is_empty(&asoc->outqueue))
391 chunk = sctp_make_strreset_tsnreq(asoc);
395 /* Block further xmit of data until this request is completed */
396 for (i = 0; i < stream->outcnt; i++)
397 SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED;
399 asoc->strreset_chunk = chunk;
400 sctp_chunk_hold(asoc->strreset_chunk);
402 retval = sctp_send_reconf(asoc, chunk);
404 sctp_chunk_put(asoc->strreset_chunk);
405 asoc->strreset_chunk = NULL;
407 for (i = 0; i < stream->outcnt; i++)
408 SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
413 asoc->strreset_outstanding = 1;
418 int sctp_send_add_streams(struct sctp_association *asoc,
419 struct sctp_add_streams *params)
421 struct sctp_stream *stream = &asoc->stream;
422 struct sctp_chunk *chunk = NULL;
427 if (!asoc->peer.reconf_capable ||
428 !(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) {
429 retval = -ENOPROTOOPT;
433 if (asoc->strreset_outstanding) {
434 retval = -EINPROGRESS;
438 out = params->sas_outstrms;
439 in = params->sas_instrms;
440 outcnt = stream->outcnt + out;
441 incnt = stream->incnt + in;
442 if (outcnt > SCTP_MAX_STREAM || incnt > SCTP_MAX_STREAM ||
449 retval = sctp_stream_alloc_out(stream, outcnt, GFP_KERNEL);
454 chunk = sctp_make_strreset_addstrm(asoc, out, in);
460 asoc->strreset_chunk = chunk;
461 sctp_chunk_hold(asoc->strreset_chunk);
463 retval = sctp_send_reconf(asoc, chunk);
465 sctp_chunk_put(asoc->strreset_chunk);
466 asoc->strreset_chunk = NULL;
470 asoc->strreset_outstanding = !!out + !!in;
476 static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param(
477 struct sctp_association *asoc, __be32 resp_seq,
480 struct sctp_chunk *chunk = asoc->strreset_chunk;
481 struct sctp_reconf_chunk *hdr;
482 union sctp_params param;
487 hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
488 sctp_walk_params(param, hdr, params) {
489 /* sctp_strreset_tsnreq is actually the basic structure
490 * of all stream reconf params, so it's safe to use it
491 * to access request_seq.
493 struct sctp_strreset_tsnreq *req = param.v;
495 if ((!resp_seq || req->request_seq == resp_seq) &&
496 (!type || type == req->param_hdr.type))
503 static void sctp_update_strreset_result(struct sctp_association *asoc,
506 asoc->strreset_result[1] = asoc->strreset_result[0];
507 asoc->strreset_result[0] = result;
510 struct sctp_chunk *sctp_process_strreset_outreq(
511 struct sctp_association *asoc,
512 union sctp_params param,
513 struct sctp_ulpevent **evp)
515 struct sctp_strreset_outreq *outreq = param.v;
516 struct sctp_stream *stream = &asoc->stream;
517 __u32 result = SCTP_STRRESET_DENIED;
518 __be16 *str_p = NULL;
522 request_seq = ntohl(outreq->request_seq);
524 if (ntohl(outreq->send_reset_at_tsn) >
525 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map)) {
526 result = SCTP_STRRESET_IN_PROGRESS;
530 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
531 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
532 result = SCTP_STRRESET_ERR_BAD_SEQNO;
534 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
535 i = asoc->strreset_inseq - request_seq - 1;
536 result = asoc->strreset_result[i];
539 asoc->strreset_inseq++;
541 /* Check strreset_enable after inseq inc, as sender cannot tell
542 * the peer doesn't enable strreset after receiving response with
543 * result denied, as well as to keep consistent with bsd.
545 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
548 nums = (ntohs(param.p->length) - sizeof(*outreq)) / sizeof(__u16);
549 str_p = outreq->list_of_streams;
550 for (i = 0; i < nums; i++) {
551 if (ntohs(str_p[i]) >= stream->incnt) {
552 result = SCTP_STRRESET_ERR_WRONG_SSN;
557 if (asoc->strreset_chunk) {
558 if (!sctp_chunk_lookup_strreset_param(
559 asoc, outreq->response_seq,
560 SCTP_PARAM_RESET_IN_REQUEST)) {
561 /* same process with outstanding isn't 0 */
562 result = SCTP_STRRESET_ERR_IN_PROGRESS;
566 asoc->strreset_outstanding--;
567 asoc->strreset_outseq++;
569 if (!asoc->strreset_outstanding) {
570 struct sctp_transport *t;
572 t = asoc->strreset_chunk->transport;
573 if (del_timer(&t->reconf_timer))
574 sctp_transport_put(t);
576 sctp_chunk_put(asoc->strreset_chunk);
577 asoc->strreset_chunk = NULL;
582 for (i = 0; i < nums; i++)
583 SCTP_SI(stream, ntohs(str_p[i]))->mid = 0;
585 for (i = 0; i < stream->incnt; i++)
586 SCTP_SI(stream, i)->mid = 0;
588 result = SCTP_STRRESET_PERFORMED;
590 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
591 SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC);
594 sctp_update_strreset_result(asoc, result);
596 return sctp_make_strreset_resp(asoc, result, request_seq);
599 struct sctp_chunk *sctp_process_strreset_inreq(
600 struct sctp_association *asoc,
601 union sctp_params param,
602 struct sctp_ulpevent **evp)
604 struct sctp_strreset_inreq *inreq = param.v;
605 struct sctp_stream *stream = &asoc->stream;
606 __u32 result = SCTP_STRRESET_DENIED;
607 struct sctp_chunk *chunk = NULL;
612 request_seq = ntohl(inreq->request_seq);
613 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
614 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
615 result = SCTP_STRRESET_ERR_BAD_SEQNO;
617 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
618 i = asoc->strreset_inseq - request_seq - 1;
619 result = asoc->strreset_result[i];
620 if (result == SCTP_STRRESET_PERFORMED)
624 asoc->strreset_inseq++;
626 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
629 if (asoc->strreset_outstanding) {
630 result = SCTP_STRRESET_ERR_IN_PROGRESS;
634 nums = (ntohs(param.p->length) - sizeof(*inreq)) / sizeof(__u16);
635 str_p = inreq->list_of_streams;
636 for (i = 0; i < nums; i++) {
637 if (ntohs(str_p[i]) >= stream->outcnt) {
638 result = SCTP_STRRESET_ERR_WRONG_SSN;
643 if (!sctp_stream_outq_is_empty(stream, nums, str_p)) {
644 result = SCTP_STRRESET_IN_PROGRESS;
645 asoc->strreset_inseq--;
649 chunk = sctp_make_strreset_req(asoc, nums, str_p, 1, 0);
654 for (i = 0; i < nums; i++)
655 SCTP_SO(stream, ntohs(str_p[i]))->state =
658 for (i = 0; i < stream->outcnt; i++)
659 SCTP_SO(stream, i)->state = SCTP_STREAM_CLOSED;
661 asoc->strreset_chunk = chunk;
662 asoc->strreset_outstanding = 1;
663 sctp_chunk_hold(asoc->strreset_chunk);
665 result = SCTP_STRRESET_PERFORMED;
668 sctp_update_strreset_result(asoc, result);
671 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
676 struct sctp_chunk *sctp_process_strreset_tsnreq(
677 struct sctp_association *asoc,
678 union sctp_params param,
679 struct sctp_ulpevent **evp)
681 __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen;
682 struct sctp_strreset_tsnreq *tsnreq = param.v;
683 struct sctp_stream *stream = &asoc->stream;
684 __u32 result = SCTP_STRRESET_DENIED;
688 request_seq = ntohl(tsnreq->request_seq);
689 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
690 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
691 result = SCTP_STRRESET_ERR_BAD_SEQNO;
693 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
694 i = asoc->strreset_inseq - request_seq - 1;
695 result = asoc->strreset_result[i];
696 if (result == SCTP_STRRESET_PERFORMED) {
697 next_tsn = asoc->ctsn_ack_point + 1;
699 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1;
704 if (!sctp_outq_is_empty(&asoc->outqueue)) {
705 result = SCTP_STRRESET_IN_PROGRESS;
709 asoc->strreset_inseq++;
711 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
714 if (asoc->strreset_outstanding) {
715 result = SCTP_STRRESET_ERR_IN_PROGRESS;
719 /* G4: The same processing as though a FWD-TSN chunk (as defined in
720 * [RFC3758]) with all streams affected and a new cumulative TSN
721 * ACK of the Receiver's Next TSN minus 1 were received MUST be
724 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
725 asoc->stream.si->report_ftsn(&asoc->ulpq, max_tsn_seen);
727 /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
728 * TSN that the peer should use to send the next DATA chunk. The
729 * value SHOULD be the smallest TSN not acknowledged by the
730 * receiver of the request plus 2^31.
732 init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31);
733 sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
734 init_tsn, GFP_ATOMIC);
736 /* G3: The same processing as though a SACK chunk with no gap report
737 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
738 * received MUST be performed.
740 sctp_outq_free(&asoc->outqueue);
742 /* G2: Compute an appropriate value for the local endpoint's next TSN,
743 * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
744 * chunk. The value SHOULD be the highest TSN sent by the receiver
745 * of the request plus 1.
747 next_tsn = asoc->next_tsn;
748 asoc->ctsn_ack_point = next_tsn - 1;
749 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
751 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
752 * incoming and outgoing streams.
754 for (i = 0; i < stream->outcnt; i++) {
755 SCTP_SO(stream, i)->mid = 0;
756 SCTP_SO(stream, i)->mid_uo = 0;
758 for (i = 0; i < stream->incnt; i++)
759 SCTP_SI(stream, i)->mid = 0;
761 result = SCTP_STRRESET_PERFORMED;
763 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn,
764 next_tsn, GFP_ATOMIC);
767 sctp_update_strreset_result(asoc, result);
769 return sctp_make_strreset_tsnresp(asoc, result, request_seq,
773 struct sctp_chunk *sctp_process_strreset_addstrm_out(
774 struct sctp_association *asoc,
775 union sctp_params param,
776 struct sctp_ulpevent **evp)
778 struct sctp_strreset_addstrm *addstrm = param.v;
779 struct sctp_stream *stream = &asoc->stream;
780 __u32 result = SCTP_STRRESET_DENIED;
781 __u32 request_seq, incnt;
784 request_seq = ntohl(addstrm->request_seq);
785 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
786 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
787 result = SCTP_STRRESET_ERR_BAD_SEQNO;
789 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
790 i = asoc->strreset_inseq - request_seq - 1;
791 result = asoc->strreset_result[i];
794 asoc->strreset_inseq++;
796 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
799 in = ntohs(addstrm->number_of_streams);
800 incnt = stream->incnt + in;
801 if (!in || incnt > SCTP_MAX_STREAM)
804 if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC))
807 if (asoc->strreset_chunk) {
808 if (!sctp_chunk_lookup_strreset_param(
809 asoc, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS)) {
810 /* same process with outstanding isn't 0 */
811 result = SCTP_STRRESET_ERR_IN_PROGRESS;
815 asoc->strreset_outstanding--;
816 asoc->strreset_outseq++;
818 if (!asoc->strreset_outstanding) {
819 struct sctp_transport *t;
821 t = asoc->strreset_chunk->transport;
822 if (del_timer(&t->reconf_timer))
823 sctp_transport_put(t);
825 sctp_chunk_put(asoc->strreset_chunk);
826 asoc->strreset_chunk = NULL;
830 stream->incnt = incnt;
832 result = SCTP_STRRESET_PERFORMED;
834 *evp = sctp_ulpevent_make_stream_change_event(asoc,
835 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC);
838 sctp_update_strreset_result(asoc, result);
840 return sctp_make_strreset_resp(asoc, result, request_seq);
843 struct sctp_chunk *sctp_process_strreset_addstrm_in(
844 struct sctp_association *asoc,
845 union sctp_params param,
846 struct sctp_ulpevent **evp)
848 struct sctp_strreset_addstrm *addstrm = param.v;
849 struct sctp_stream *stream = &asoc->stream;
850 __u32 result = SCTP_STRRESET_DENIED;
851 struct sctp_chunk *chunk = NULL;
852 __u32 request_seq, outcnt;
856 request_seq = ntohl(addstrm->request_seq);
857 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
858 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
859 result = SCTP_STRRESET_ERR_BAD_SEQNO;
861 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
862 i = asoc->strreset_inseq - request_seq - 1;
863 result = asoc->strreset_result[i];
864 if (result == SCTP_STRRESET_PERFORMED)
868 asoc->strreset_inseq++;
870 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
873 if (asoc->strreset_outstanding) {
874 result = SCTP_STRRESET_ERR_IN_PROGRESS;
878 out = ntohs(addstrm->number_of_streams);
879 outcnt = stream->outcnt + out;
880 if (!out || outcnt > SCTP_MAX_STREAM)
883 ret = sctp_stream_alloc_out(stream, outcnt, GFP_ATOMIC);
887 chunk = sctp_make_strreset_addstrm(asoc, out, 0);
891 asoc->strreset_chunk = chunk;
892 asoc->strreset_outstanding = 1;
893 sctp_chunk_hold(asoc->strreset_chunk);
895 stream->outcnt = outcnt;
897 result = SCTP_STRRESET_PERFORMED;
900 sctp_update_strreset_result(asoc, result);
903 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
908 struct sctp_chunk *sctp_process_strreset_resp(
909 struct sctp_association *asoc,
910 union sctp_params param,
911 struct sctp_ulpevent **evp)
913 struct sctp_stream *stream = &asoc->stream;
914 struct sctp_strreset_resp *resp = param.v;
915 struct sctp_transport *t;
916 __u16 i, nums, flags = 0;
917 struct sctp_paramhdr *req;
920 req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0);
924 result = ntohl(resp->result);
925 if (result != SCTP_STRRESET_PERFORMED) {
926 /* if in progress, do nothing but retransmit */
927 if (result == SCTP_STRRESET_IN_PROGRESS)
929 else if (result == SCTP_STRRESET_DENIED)
930 flags = SCTP_STREAM_RESET_DENIED;
932 flags = SCTP_STREAM_RESET_FAILED;
935 if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) {
936 struct sctp_strreset_outreq *outreq;
939 outreq = (struct sctp_strreset_outreq *)req;
940 str_p = outreq->list_of_streams;
941 nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) /
944 if (result == SCTP_STRRESET_PERFORMED) {
945 struct sctp_stream_out *sout;
947 for (i = 0; i < nums; i++) {
948 sout = SCTP_SO(stream, ntohs(str_p[i]));
953 for (i = 0; i < stream->outcnt; i++) {
954 sout = SCTP_SO(stream, i);
961 flags |= SCTP_STREAM_RESET_OUTGOING_SSN;
963 for (i = 0; i < stream->outcnt; i++)
964 SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
966 *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
967 nums, str_p, GFP_ATOMIC);
968 } else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) {
969 struct sctp_strreset_inreq *inreq;
972 /* if the result is performed, it's impossible for inreq */
973 if (result == SCTP_STRRESET_PERFORMED)
976 inreq = (struct sctp_strreset_inreq *)req;
977 str_p = inreq->list_of_streams;
978 nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) /
981 flags |= SCTP_STREAM_RESET_INCOMING_SSN;
983 *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
984 nums, str_p, GFP_ATOMIC);
985 } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) {
986 struct sctp_strreset_resptsn *resptsn;
989 /* check for resptsn, as sctp_verify_reconf didn't do it*/
990 if (ntohs(param.p->length) != sizeof(*resptsn))
993 resptsn = (struct sctp_strreset_resptsn *)resp;
994 stsn = ntohl(resptsn->senders_next_tsn);
995 rtsn = ntohl(resptsn->receivers_next_tsn);
997 if (result == SCTP_STRRESET_PERFORMED) {
998 __u32 mtsn = sctp_tsnmap_get_max_tsn_seen(
999 &asoc->peer.tsn_map);
1002 asoc->stream.si->report_ftsn(&asoc->ulpq, mtsn);
1004 sctp_tsnmap_init(&asoc->peer.tsn_map,
1005 SCTP_TSN_MAP_INITIAL,
1008 /* Clean up sacked and abandoned queues only. As the
1009 * out_chunk_list may not be empty, splice it to temp,
1010 * then get it back after sctp_outq_free is done.
1012 list_splice_init(&asoc->outqueue.out_chunk_list, &temp);
1013 sctp_outq_free(&asoc->outqueue);
1014 list_splice_init(&temp, &asoc->outqueue.out_chunk_list);
1016 asoc->next_tsn = rtsn;
1017 asoc->ctsn_ack_point = asoc->next_tsn - 1;
1018 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
1020 for (i = 0; i < stream->outcnt; i++) {
1021 SCTP_SO(stream, i)->mid = 0;
1022 SCTP_SO(stream, i)->mid_uo = 0;
1024 for (i = 0; i < stream->incnt; i++)
1025 SCTP_SI(stream, i)->mid = 0;
1028 for (i = 0; i < stream->outcnt; i++)
1029 SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
1031 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags,
1032 stsn, rtsn, GFP_ATOMIC);
1033 } else if (req->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) {
1034 struct sctp_strreset_addstrm *addstrm;
1037 addstrm = (struct sctp_strreset_addstrm *)req;
1038 nums = ntohs(addstrm->number_of_streams);
1039 number = stream->outcnt - nums;
1041 if (result == SCTP_STRRESET_PERFORMED)
1042 for (i = number; i < stream->outcnt; i++)
1043 SCTP_SO(stream, i)->state = SCTP_STREAM_OPEN;
1045 stream->outcnt = number;
1047 *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
1048 0, nums, GFP_ATOMIC);
1049 } else if (req->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) {
1050 struct sctp_strreset_addstrm *addstrm;
1052 /* if the result is performed, it's impossible for addstrm in
1055 if (result == SCTP_STRRESET_PERFORMED)
1058 addstrm = (struct sctp_strreset_addstrm *)req;
1059 nums = ntohs(addstrm->number_of_streams);
1061 *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
1062 nums, 0, GFP_ATOMIC);
1065 asoc->strreset_outstanding--;
1066 asoc->strreset_outseq++;
1068 /* remove everything for this reconf request */
1069 if (!asoc->strreset_outstanding) {
1070 t = asoc->strreset_chunk->transport;
1071 if (del_timer(&t->reconf_timer))
1072 sctp_transport_put(t);
1074 sctp_chunk_put(asoc->strreset_chunk);
1075 asoc->strreset_chunk = NULL;