1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001 Intel Corp.
7 * This file is part of the SCTP kernel implementation
9 * This file contains sctp stream maniuplation primitives and helpers.
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)
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.
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/>.
27 * Please send any bug reports or fixes you make to the
29 * lksctp developers <linux-sctp@vger.kernel.org>
31 * Written or modified by:
32 * Xin Long <lucien.xin@gmail.com>
35 #include <linux/list.h>
36 #include <net/sctp/sctp.h>
37 #include <net/sctp/sm.h>
38 #include <net/sctp/stream_sched.h>
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.
44 static void sctp_stream_outq_migrate(struct sctp_stream *stream,
45 struct sctp_stream *new, __u16 outcnt)
47 struct sctp_association *asoc;
48 struct sctp_chunk *ch, *temp;
49 struct sctp_outq *outq;
52 asoc = container_of(stream, struct sctp_association, stream);
53 outq = &asoc->outqueue;
55 list_for_each_entry_safe(ch, temp, &outq->out_chunk_list, list) {
56 __u16 sid = sctp_chunk_stream_no(ch);
61 sctp_sched_dequeue_common(outq, ch);
62 /* No need to call dequeue_done here because
63 * the chunks are not scheduled by now.
66 /* Mark as failed send. */
67 sctp_chunk_fail(ch, (__force __u32)SCTP_ERROR_INV_STRM);
68 if (asoc->peer.prsctp_capable &&
69 SCTP_PR_PRIO_ENABLED(ch->sinfo.sinfo_flags))
70 asoc->sent_cnt_removable--;
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.
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;
87 for (i = outcnt; i < stream->outcnt; i++)
88 kfree(stream->out[i].ext);
91 static int sctp_stream_alloc_out(struct sctp_stream *stream, __u16 outcnt,
94 struct sctp_stream_out *out;
96 out = kmalloc_array(outcnt, sizeof(*out), gfp);
101 memcpy(out, stream->out, min(outcnt, stream->outcnt) *
106 if (outcnt > stream->outcnt)
107 memset(out + stream->outcnt, 0,
108 (outcnt - stream->outcnt) * sizeof(*out));
115 static int sctp_stream_alloc_in(struct sctp_stream *stream, __u16 incnt,
118 struct sctp_stream_in *in;
120 in = kmalloc_array(incnt, sizeof(*stream->in), gfp);
126 memcpy(in, stream->in, min(incnt, stream->incnt) *
131 if (incnt > stream->incnt)
132 memset(in + stream->incnt, 0,
133 (incnt - stream->incnt) * sizeof(*in));
140 int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
143 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
148 /* Initial stream->out size may be very big, so free it and alloc
149 * a new one with new outcnt to save memory if needed.
151 if (outcnt == stream->outcnt)
154 /* Filter out chunks queued on streams that won't exist anymore */
155 sched->unsched_all(stream);
156 sctp_stream_outq_migrate(stream, NULL, outcnt);
157 sched->sched_all(stream);
159 ret = sctp_stream_alloc_out(stream, outcnt, gfp);
163 stream->outcnt = outcnt;
164 for (i = 0; i < stream->outcnt; i++)
165 stream->out[i].state = SCTP_STREAM_OPEN;
170 sctp_stream_interleave_init(stream);
174 ret = sctp_stream_alloc_in(stream, incnt, gfp);
183 stream->incnt = incnt;
189 int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid)
191 struct sctp_stream_out_ext *soute;
193 soute = kzalloc(sizeof(*soute), GFP_KERNEL);
196 stream->out[sid].ext = soute;
198 return sctp_sched_init_sid(stream, sid, GFP_KERNEL);
201 void sctp_stream_free(struct sctp_stream *stream)
203 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
207 for (i = 0; i < stream->outcnt; i++)
208 kfree(stream->out[i].ext);
213 void sctp_stream_clear(struct sctp_stream *stream)
217 for (i = 0; i < stream->outcnt; i++) {
218 stream->out[i].mid = 0;
219 stream->out[i].mid_uo = 0;
222 for (i = 0; i < stream->incnt; i++)
223 stream->in[i].mid = 0;
226 void sctp_stream_update(struct sctp_stream *stream, struct sctp_stream *new)
228 struct sctp_sched_ops *sched = sctp_sched_ops_from_stream(stream);
230 sched->unsched_all(stream);
231 sctp_stream_outq_migrate(stream, new, new->outcnt);
232 sctp_stream_free(stream);
234 stream->out = new->out;
235 stream->in = new->in;
236 stream->outcnt = new->outcnt;
237 stream->incnt = new->incnt;
239 sched->sched_all(stream);
247 static int sctp_send_reconf(struct sctp_association *asoc,
248 struct sctp_chunk *chunk)
250 struct net *net = sock_net(asoc->base.sk);
253 retval = sctp_primitive_RECONF(net, asoc, chunk);
255 sctp_chunk_free(chunk);
260 static bool sctp_stream_outq_is_empty(struct sctp_stream *stream,
261 __u16 str_nums, __be16 *str_list)
263 struct sctp_association *asoc;
266 asoc = container_of(stream, struct sctp_association, stream);
267 if (!asoc->outqueue.out_qlen)
273 for (i = 0; i < str_nums; i++) {
274 __u16 sid = ntohs(str_list[i]);
276 if (stream->out[sid].ext &&
277 !list_empty(&stream->out[sid].ext->outq))
284 int sctp_send_reset_streams(struct sctp_association *asoc,
285 struct sctp_reset_streams *params)
287 struct sctp_stream *stream = &asoc->stream;
288 __u16 i, str_nums, *str_list;
289 struct sctp_chunk *chunk;
290 int retval = -EINVAL;
294 if (!asoc->peer.reconf_capable ||
295 !(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) {
296 retval = -ENOPROTOOPT;
300 if (asoc->strreset_outstanding) {
301 retval = -EINPROGRESS;
305 out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING;
306 in = params->srs_flags & SCTP_STREAM_RESET_INCOMING;
310 str_nums = params->srs_number_streams;
311 str_list = params->srs_stream_list;
316 for (i = 0; i < str_nums; i++)
317 if (str_list[i] >= stream->outcnt)
320 param_len = str_nums * sizeof(__u16) +
321 sizeof(struct sctp_strreset_outreq);
325 for (i = 0; i < str_nums; i++)
326 if (str_list[i] >= stream->incnt)
329 param_len += str_nums * sizeof(__u16) +
330 sizeof(struct sctp_strreset_inreq);
333 if (param_len > SCTP_MAX_CHUNK_LEN -
334 sizeof(struct sctp_reconf_chunk))
338 nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL);
344 for (i = 0; i < str_nums; i++)
345 nstr_list[i] = htons(str_list[i]);
347 if (out && !sctp_stream_outq_is_empty(stream, str_nums, nstr_list)) {
352 chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in);
363 for (i = 0; i < str_nums; i++)
364 stream->out[str_list[i]].state =
367 for (i = 0; i < stream->outcnt; i++)
368 stream->out[i].state = SCTP_STREAM_CLOSED;
371 asoc->strreset_chunk = chunk;
372 sctp_chunk_hold(asoc->strreset_chunk);
374 retval = sctp_send_reconf(asoc, chunk);
376 sctp_chunk_put(asoc->strreset_chunk);
377 asoc->strreset_chunk = NULL;
382 for (i = 0; i < str_nums; i++)
383 stream->out[str_list[i]].state =
386 for (i = 0; i < stream->outcnt; i++)
387 stream->out[i].state = SCTP_STREAM_OPEN;
392 asoc->strreset_outstanding = out + in;
398 int sctp_send_reset_assoc(struct sctp_association *asoc)
400 struct sctp_stream *stream = &asoc->stream;
401 struct sctp_chunk *chunk = NULL;
405 if (!asoc->peer.reconf_capable ||
406 !(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
409 if (asoc->strreset_outstanding)
412 if (!sctp_outq_is_empty(&asoc->outqueue))
415 chunk = sctp_make_strreset_tsnreq(asoc);
419 /* Block further xmit of data until this request is completed */
420 for (i = 0; i < stream->outcnt; i++)
421 stream->out[i].state = SCTP_STREAM_CLOSED;
423 asoc->strreset_chunk = chunk;
424 sctp_chunk_hold(asoc->strreset_chunk);
426 retval = sctp_send_reconf(asoc, chunk);
428 sctp_chunk_put(asoc->strreset_chunk);
429 asoc->strreset_chunk = NULL;
431 for (i = 0; i < stream->outcnt; i++)
432 stream->out[i].state = SCTP_STREAM_OPEN;
437 asoc->strreset_outstanding = 1;
442 int sctp_send_add_streams(struct sctp_association *asoc,
443 struct sctp_add_streams *params)
445 struct sctp_stream *stream = &asoc->stream;
446 struct sctp_chunk *chunk = NULL;
451 if (!asoc->peer.reconf_capable ||
452 !(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) {
453 retval = -ENOPROTOOPT;
457 if (asoc->strreset_outstanding) {
458 retval = -EINPROGRESS;
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 ||
473 retval = sctp_stream_alloc_out(stream, outcnt, GFP_KERNEL);
478 chunk = sctp_make_strreset_addstrm(asoc, out, in);
484 asoc->strreset_chunk = chunk;
485 sctp_chunk_hold(asoc->strreset_chunk);
487 retval = sctp_send_reconf(asoc, chunk);
489 sctp_chunk_put(asoc->strreset_chunk);
490 asoc->strreset_chunk = NULL;
494 stream->incnt = incnt;
495 stream->outcnt = outcnt;
497 asoc->strreset_outstanding = !!out + !!in;
503 static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param(
504 struct sctp_association *asoc, __be32 resp_seq,
507 struct sctp_chunk *chunk = asoc->strreset_chunk;
508 struct sctp_reconf_chunk *hdr;
509 union sctp_params param;
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.
520 struct sctp_strreset_tsnreq *req = param.v;
522 if ((!resp_seq || req->request_seq == resp_seq) &&
523 (!type || type == req->param_hdr.type))
530 static void sctp_update_strreset_result(struct sctp_association *asoc,
533 asoc->strreset_result[1] = asoc->strreset_result[0];
534 asoc->strreset_result[0] = result;
537 struct sctp_chunk *sctp_process_strreset_outreq(
538 struct sctp_association *asoc,
539 union sctp_params param,
540 struct sctp_ulpevent **evp)
542 struct sctp_strreset_outreq *outreq = param.v;
543 struct sctp_stream *stream = &asoc->stream;
544 __u32 result = SCTP_STRRESET_DENIED;
545 __u16 i, nums, flags = 0;
546 __be16 *str_p = NULL;
549 request_seq = ntohl(outreq->request_seq);
551 if (ntohl(outreq->send_reset_at_tsn) >
552 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map)) {
553 result = SCTP_STRRESET_IN_PROGRESS;
557 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
558 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
559 result = SCTP_STRRESET_ERR_BAD_SEQNO;
561 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
562 i = asoc->strreset_inseq - request_seq - 1;
563 result = asoc->strreset_result[i];
566 asoc->strreset_inseq++;
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.
572 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
575 if (asoc->strreset_chunk) {
576 if (!sctp_chunk_lookup_strreset_param(
577 asoc, outreq->response_seq,
578 SCTP_PARAM_RESET_IN_REQUEST)) {
579 /* same process with outstanding isn't 0 */
580 result = SCTP_STRRESET_ERR_IN_PROGRESS;
584 asoc->strreset_outstanding--;
585 asoc->strreset_outseq++;
587 if (!asoc->strreset_outstanding) {
588 struct sctp_transport *t;
590 t = asoc->strreset_chunk->transport;
591 if (del_timer(&t->reconf_timer))
592 sctp_transport_put(t);
594 sctp_chunk_put(asoc->strreset_chunk);
595 asoc->strreset_chunk = NULL;
598 flags = SCTP_STREAM_RESET_INCOMING_SSN;
601 nums = (ntohs(param.p->length) - sizeof(*outreq)) / sizeof(__u16);
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;
611 for (i = 0; i < nums; i++)
612 stream->in[ntohs(str_p[i])].mid = 0;
614 for (i = 0; i < stream->incnt; i++)
615 stream->in[i].mid = 0;
618 result = SCTP_STRRESET_PERFORMED;
620 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
621 flags | SCTP_STREAM_RESET_OUTGOING_SSN, nums, str_p,
625 sctp_update_strreset_result(asoc, result);
627 return sctp_make_strreset_resp(asoc, result, request_seq);
630 struct sctp_chunk *sctp_process_strreset_inreq(
631 struct sctp_association *asoc,
632 union sctp_params param,
633 struct sctp_ulpevent **evp)
635 struct sctp_strreset_inreq *inreq = param.v;
636 struct sctp_stream *stream = &asoc->stream;
637 __u32 result = SCTP_STRRESET_DENIED;
638 struct sctp_chunk *chunk = NULL;
643 request_seq = ntohl(inreq->request_seq);
644 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
645 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
646 result = SCTP_STRRESET_ERR_BAD_SEQNO;
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)
655 asoc->strreset_inseq++;
657 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
660 if (asoc->strreset_outstanding) {
661 result = SCTP_STRRESET_ERR_IN_PROGRESS;
665 nums = (ntohs(param.p->length) - sizeof(*inreq)) / sizeof(__u16);
666 str_p = inreq->list_of_streams;
667 for (i = 0; i < nums; i++) {
668 if (ntohs(str_p[i]) >= stream->outcnt) {
669 result = SCTP_STRRESET_ERR_WRONG_SSN;
674 if (!sctp_stream_outq_is_empty(stream, nums, str_p)) {
675 result = SCTP_STRRESET_IN_PROGRESS;
676 asoc->strreset_inseq--;
680 chunk = sctp_make_strreset_req(asoc, nums, str_p, 1, 0);
685 for (i = 0; i < nums; i++)
686 stream->out[ntohs(str_p[i])].state =
689 for (i = 0; i < stream->outcnt; i++)
690 stream->out[i].state = SCTP_STREAM_CLOSED;
692 asoc->strreset_chunk = chunk;
693 asoc->strreset_outstanding = 1;
694 sctp_chunk_hold(asoc->strreset_chunk);
696 result = SCTP_STRRESET_PERFORMED;
698 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
699 SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC);
702 sctp_update_strreset_result(asoc, result);
705 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
710 struct sctp_chunk *sctp_process_strreset_tsnreq(
711 struct sctp_association *asoc,
712 union sctp_params param,
713 struct sctp_ulpevent **evp)
715 __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen;
716 struct sctp_strreset_tsnreq *tsnreq = param.v;
717 struct sctp_stream *stream = &asoc->stream;
718 __u32 result = SCTP_STRRESET_DENIED;
722 request_seq = ntohl(tsnreq->request_seq);
723 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
724 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
725 result = SCTP_STRRESET_ERR_BAD_SEQNO;
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) {
731 next_tsn = asoc->ctsn_ack_point + 1;
733 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1;
738 if (!sctp_outq_is_empty(&asoc->outqueue)) {
739 result = SCTP_STRRESET_IN_PROGRESS;
743 asoc->strreset_inseq++;
745 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
748 if (asoc->strreset_outstanding) {
749 result = SCTP_STRRESET_ERR_IN_PROGRESS;
753 /* G4: The same processing as though a FWD-TSN chunk (as defined in
754 * [RFC3758]) with all streams affected and a new cumulative TSN
755 * ACK of the Receiver's Next TSN minus 1 were received MUST be
758 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
759 asoc->stream.si->report_ftsn(&asoc->ulpq, max_tsn_seen);
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.
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);
770 /* G3: The same processing as though a SACK chunk with no gap report
771 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
772 * received MUST be performed.
774 sctp_outq_free(&asoc->outqueue);
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.
781 next_tsn = asoc->next_tsn;
782 asoc->ctsn_ack_point = next_tsn - 1;
783 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
785 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
786 * incoming and outgoing streams.
788 for (i = 0; i < stream->outcnt; i++) {
789 stream->out[i].mid = 0;
790 stream->out[i].mid_uo = 0;
792 for (i = 0; i < stream->incnt; i++)
793 stream->in[i].mid = 0;
795 result = SCTP_STRRESET_PERFORMED;
797 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn,
798 next_tsn, GFP_ATOMIC);
801 sctp_update_strreset_result(asoc, result);
803 return sctp_make_strreset_tsnresp(asoc, result, request_seq,
807 struct sctp_chunk *sctp_process_strreset_addstrm_out(
808 struct sctp_association *asoc,
809 union sctp_params param,
810 struct sctp_ulpevent **evp)
812 struct sctp_strreset_addstrm *addstrm = param.v;
813 struct sctp_stream *stream = &asoc->stream;
814 __u32 result = SCTP_STRRESET_DENIED;
815 __u32 request_seq, incnt;
818 request_seq = ntohl(addstrm->request_seq);
819 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
820 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
821 result = SCTP_STRRESET_ERR_BAD_SEQNO;
823 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
824 i = asoc->strreset_inseq - request_seq - 1;
825 result = asoc->strreset_result[i];
828 asoc->strreset_inseq++;
830 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
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;
841 asoc->strreset_outstanding--;
842 asoc->strreset_outseq++;
844 if (!asoc->strreset_outstanding) {
845 struct sctp_transport *t;
847 t = asoc->strreset_chunk->transport;
848 if (del_timer(&t->reconf_timer))
849 sctp_transport_put(t);
851 sctp_chunk_put(asoc->strreset_chunk);
852 asoc->strreset_chunk = NULL;
856 in = ntohs(addstrm->number_of_streams);
857 incnt = stream->incnt + in;
858 if (!in || incnt > SCTP_MAX_STREAM)
861 if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC))
864 stream->incnt = incnt;
866 result = SCTP_STRRESET_PERFORMED;
868 *evp = sctp_ulpevent_make_stream_change_event(asoc,
869 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC);
872 sctp_update_strreset_result(asoc, result);
874 return sctp_make_strreset_resp(asoc, result, request_seq);
877 struct sctp_chunk *sctp_process_strreset_addstrm_in(
878 struct sctp_association *asoc,
879 union sctp_params param,
880 struct sctp_ulpevent **evp)
882 struct sctp_strreset_addstrm *addstrm = param.v;
883 struct sctp_stream *stream = &asoc->stream;
884 __u32 result = SCTP_STRRESET_DENIED;
885 struct sctp_chunk *chunk = NULL;
886 __u32 request_seq, outcnt;
890 request_seq = ntohl(addstrm->request_seq);
891 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
892 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
893 result = SCTP_STRRESET_ERR_BAD_SEQNO;
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)
902 asoc->strreset_inseq++;
904 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
907 if (asoc->strreset_outstanding) {
908 result = SCTP_STRRESET_ERR_IN_PROGRESS;
912 out = ntohs(addstrm->number_of_streams);
913 outcnt = stream->outcnt + out;
914 if (!out || outcnt > SCTP_MAX_STREAM)
917 ret = sctp_stream_alloc_out(stream, outcnt, GFP_ATOMIC);
921 chunk = sctp_make_strreset_addstrm(asoc, out, 0);
925 asoc->strreset_chunk = chunk;
926 asoc->strreset_outstanding = 1;
927 sctp_chunk_hold(asoc->strreset_chunk);
929 stream->outcnt = outcnt;
931 result = SCTP_STRRESET_PERFORMED;
933 *evp = sctp_ulpevent_make_stream_change_event(asoc,
934 0, 0, ntohs(addstrm->number_of_streams), GFP_ATOMIC);
937 sctp_update_strreset_result(asoc, result);
940 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
945 struct sctp_chunk *sctp_process_strreset_resp(
946 struct sctp_association *asoc,
947 union sctp_params param,
948 struct sctp_ulpevent **evp)
950 struct sctp_stream *stream = &asoc->stream;
951 struct sctp_strreset_resp *resp = param.v;
952 struct sctp_transport *t;
953 __u16 i, nums, flags = 0;
954 struct sctp_paramhdr *req;
957 req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0);
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)
966 else if (result == SCTP_STRRESET_DENIED)
967 flags = SCTP_STREAM_RESET_DENIED;
969 flags = SCTP_STREAM_RESET_FAILED;
972 if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) {
973 struct sctp_strreset_outreq *outreq;
976 outreq = (struct sctp_strreset_outreq *)req;
977 str_p = outreq->list_of_streams;
978 nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) /
981 if (result == SCTP_STRRESET_PERFORMED) {
983 for (i = 0; i < nums; i++) {
984 stream->out[ntohs(str_p[i])].mid = 0;
985 stream->out[ntohs(str_p[i])].mid_uo = 0;
988 for (i = 0; i < stream->outcnt; i++) {
989 stream->out[i].mid = 0;
990 stream->out[i].mid_uo = 0;
994 flags = SCTP_STREAM_RESET_OUTGOING_SSN;
997 for (i = 0; i < stream->outcnt; i++)
998 stream->out[i].state = SCTP_STREAM_OPEN;
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;
1006 /* if the result is performed, it's impossible for inreq */
1007 if (result == SCTP_STRRESET_PERFORMED)
1010 inreq = (struct sctp_strreset_inreq *)req;
1011 str_p = inreq->list_of_streams;
1012 nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) /
1015 *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
1016 nums, str_p, GFP_ATOMIC);
1017 } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) {
1018 struct sctp_strreset_resptsn *resptsn;
1021 /* check for resptsn, as sctp_verify_reconf didn't do it*/
1022 if (ntohs(param.p->length) != sizeof(*resptsn))
1025 resptsn = (struct sctp_strreset_resptsn *)resp;
1026 stsn = ntohl(resptsn->senders_next_tsn);
1027 rtsn = ntohl(resptsn->receivers_next_tsn);
1029 if (result == SCTP_STRRESET_PERFORMED) {
1030 __u32 mtsn = sctp_tsnmap_get_max_tsn_seen(
1031 &asoc->peer.tsn_map);
1034 asoc->stream.si->report_ftsn(&asoc->ulpq, mtsn);
1036 sctp_tsnmap_init(&asoc->peer.tsn_map,
1037 SCTP_TSN_MAP_INITIAL,
1040 /* Clean up sacked and abandoned queues only. As the
1041 * out_chunk_list may not be empty, splice it to temp,
1042 * then get it back after sctp_outq_free is done.
1044 list_splice_init(&asoc->outqueue.out_chunk_list, &temp);
1045 sctp_outq_free(&asoc->outqueue);
1046 list_splice_init(&temp, &asoc->outqueue.out_chunk_list);
1048 asoc->next_tsn = rtsn;
1049 asoc->ctsn_ack_point = asoc->next_tsn - 1;
1050 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
1052 for (i = 0; i < stream->outcnt; i++) {
1053 stream->out[i].mid = 0;
1054 stream->out[i].mid_uo = 0;
1056 for (i = 0; i < stream->incnt; i++)
1057 stream->in[i].mid = 0;
1060 for (i = 0; i < stream->outcnt; i++)
1061 stream->out[i].state = SCTP_STREAM_OPEN;
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;
1069 addstrm = (struct sctp_strreset_addstrm *)req;
1070 nums = ntohs(addstrm->number_of_streams);
1071 number = stream->outcnt - nums;
1073 if (result == SCTP_STRRESET_PERFORMED)
1074 for (i = number; i < stream->outcnt; i++)
1075 stream->out[i].state = SCTP_STREAM_OPEN;
1077 stream->outcnt = number;
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;
1084 /* if the result is performed, it's impossible for addstrm in
1087 if (result == SCTP_STRRESET_PERFORMED)
1090 addstrm = (struct sctp_strreset_addstrm *)req;
1091 nums = ntohs(addstrm->number_of_streams);
1093 *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
1094 nums, 0, GFP_ATOMIC);
1097 asoc->strreset_outstanding--;
1098 asoc->strreset_outseq++;
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);
1106 sctp_chunk_put(asoc->strreset_chunk);
1107 asoc->strreset_chunk = NULL;