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);
245 static int sctp_send_reconf(struct sctp_association *asoc,
246 struct sctp_chunk *chunk)
248 struct net *net = sock_net(asoc->base.sk);
251 retval = sctp_primitive_RECONF(net, asoc, chunk);
253 sctp_chunk_free(chunk);
258 static bool sctp_stream_outq_is_empty(struct sctp_stream *stream,
259 __u16 str_nums, __be16 *str_list)
261 struct sctp_association *asoc;
264 asoc = container_of(stream, struct sctp_association, stream);
265 if (!asoc->outqueue.out_qlen)
271 for (i = 0; i < str_nums; i++) {
272 __u16 sid = ntohs(str_list[i]);
274 if (stream->out[sid].ext &&
275 !list_empty(&stream->out[sid].ext->outq))
282 int sctp_send_reset_streams(struct sctp_association *asoc,
283 struct sctp_reset_streams *params)
285 struct sctp_stream *stream = &asoc->stream;
286 __u16 i, str_nums, *str_list;
287 struct sctp_chunk *chunk;
288 int retval = -EINVAL;
292 if (!asoc->peer.reconf_capable ||
293 !(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ)) {
294 retval = -ENOPROTOOPT;
298 if (asoc->strreset_outstanding) {
299 retval = -EINPROGRESS;
303 out = params->srs_flags & SCTP_STREAM_RESET_OUTGOING;
304 in = params->srs_flags & SCTP_STREAM_RESET_INCOMING;
308 str_nums = params->srs_number_streams;
309 str_list = params->srs_stream_list;
314 for (i = 0; i < str_nums; i++)
315 if (str_list[i] >= stream->outcnt)
318 param_len = str_nums * sizeof(__u16) +
319 sizeof(struct sctp_strreset_outreq);
323 for (i = 0; i < str_nums; i++)
324 if (str_list[i] >= stream->incnt)
327 param_len += str_nums * sizeof(__u16) +
328 sizeof(struct sctp_strreset_inreq);
331 if (param_len > SCTP_MAX_CHUNK_LEN -
332 sizeof(struct sctp_reconf_chunk))
336 nstr_list = kcalloc(str_nums, sizeof(__be16), GFP_KERNEL);
342 for (i = 0; i < str_nums; i++)
343 nstr_list[i] = htons(str_list[i]);
345 if (out && !sctp_stream_outq_is_empty(stream, str_nums, nstr_list)) {
350 chunk = sctp_make_strreset_req(asoc, str_nums, nstr_list, out, in);
361 for (i = 0; i < str_nums; i++)
362 stream->out[str_list[i]].state =
365 for (i = 0; i < stream->outcnt; i++)
366 stream->out[i].state = SCTP_STREAM_CLOSED;
369 asoc->strreset_chunk = chunk;
370 sctp_chunk_hold(asoc->strreset_chunk);
372 retval = sctp_send_reconf(asoc, chunk);
374 sctp_chunk_put(asoc->strreset_chunk);
375 asoc->strreset_chunk = NULL;
380 for (i = 0; i < str_nums; i++)
381 stream->out[str_list[i]].state =
384 for (i = 0; i < stream->outcnt; i++)
385 stream->out[i].state = SCTP_STREAM_OPEN;
390 asoc->strreset_outstanding = out + in;
396 int sctp_send_reset_assoc(struct sctp_association *asoc)
398 struct sctp_stream *stream = &asoc->stream;
399 struct sctp_chunk *chunk = NULL;
403 if (!asoc->peer.reconf_capable ||
404 !(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
407 if (asoc->strreset_outstanding)
410 if (!sctp_outq_is_empty(&asoc->outqueue))
413 chunk = sctp_make_strreset_tsnreq(asoc);
417 /* Block further xmit of data until this request is completed */
418 for (i = 0; i < stream->outcnt; i++)
419 stream->out[i].state = SCTP_STREAM_CLOSED;
421 asoc->strreset_chunk = chunk;
422 sctp_chunk_hold(asoc->strreset_chunk);
424 retval = sctp_send_reconf(asoc, chunk);
426 sctp_chunk_put(asoc->strreset_chunk);
427 asoc->strreset_chunk = NULL;
429 for (i = 0; i < stream->outcnt; i++)
430 stream->out[i].state = SCTP_STREAM_OPEN;
435 asoc->strreset_outstanding = 1;
440 int sctp_send_add_streams(struct sctp_association *asoc,
441 struct sctp_add_streams *params)
443 struct sctp_stream *stream = &asoc->stream;
444 struct sctp_chunk *chunk = NULL;
449 if (!asoc->peer.reconf_capable ||
450 !(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ)) {
451 retval = -ENOPROTOOPT;
455 if (asoc->strreset_outstanding) {
456 retval = -EINPROGRESS;
460 out = params->sas_outstrms;
461 in = params->sas_instrms;
462 outcnt = stream->outcnt + out;
463 incnt = stream->incnt + in;
464 if (outcnt > SCTP_MAX_STREAM || incnt > SCTP_MAX_STREAM ||
471 retval = sctp_stream_alloc_out(stream, outcnt, GFP_KERNEL);
476 chunk = sctp_make_strreset_addstrm(asoc, out, in);
482 asoc->strreset_chunk = chunk;
483 sctp_chunk_hold(asoc->strreset_chunk);
485 retval = sctp_send_reconf(asoc, chunk);
487 sctp_chunk_put(asoc->strreset_chunk);
488 asoc->strreset_chunk = NULL;
492 stream->incnt = incnt;
493 stream->outcnt = outcnt;
495 asoc->strreset_outstanding = !!out + !!in;
501 static struct sctp_paramhdr *sctp_chunk_lookup_strreset_param(
502 struct sctp_association *asoc, __be32 resp_seq,
505 struct sctp_chunk *chunk = asoc->strreset_chunk;
506 struct sctp_reconf_chunk *hdr;
507 union sctp_params param;
512 hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
513 sctp_walk_params(param, hdr, params) {
514 /* sctp_strreset_tsnreq is actually the basic structure
515 * of all stream reconf params, so it's safe to use it
516 * to access request_seq.
518 struct sctp_strreset_tsnreq *req = param.v;
520 if ((!resp_seq || req->request_seq == resp_seq) &&
521 (!type || type == req->param_hdr.type))
528 static void sctp_update_strreset_result(struct sctp_association *asoc,
531 asoc->strreset_result[1] = asoc->strreset_result[0];
532 asoc->strreset_result[0] = result;
535 struct sctp_chunk *sctp_process_strreset_outreq(
536 struct sctp_association *asoc,
537 union sctp_params param,
538 struct sctp_ulpevent **evp)
540 struct sctp_strreset_outreq *outreq = param.v;
541 struct sctp_stream *stream = &asoc->stream;
542 __u32 result = SCTP_STRRESET_DENIED;
543 __u16 i, nums, flags = 0;
544 __be16 *str_p = NULL;
547 request_seq = ntohl(outreq->request_seq);
549 if (ntohl(outreq->send_reset_at_tsn) >
550 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map)) {
551 result = SCTP_STRRESET_IN_PROGRESS;
555 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
556 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
557 result = SCTP_STRRESET_ERR_BAD_SEQNO;
559 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
560 i = asoc->strreset_inseq - request_seq - 1;
561 result = asoc->strreset_result[i];
564 asoc->strreset_inseq++;
566 /* Check strreset_enable after inseq inc, as sender cannot tell
567 * the peer doesn't enable strreset after receiving response with
568 * result denied, as well as to keep consistent with bsd.
570 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
573 if (asoc->strreset_chunk) {
574 if (!sctp_chunk_lookup_strreset_param(
575 asoc, outreq->response_seq,
576 SCTP_PARAM_RESET_IN_REQUEST)) {
577 /* same process with outstanding isn't 0 */
578 result = SCTP_STRRESET_ERR_IN_PROGRESS;
582 asoc->strreset_outstanding--;
583 asoc->strreset_outseq++;
585 if (!asoc->strreset_outstanding) {
586 struct sctp_transport *t;
588 t = asoc->strreset_chunk->transport;
589 if (del_timer(&t->reconf_timer))
590 sctp_transport_put(t);
592 sctp_chunk_put(asoc->strreset_chunk);
593 asoc->strreset_chunk = NULL;
596 flags = SCTP_STREAM_RESET_INCOMING_SSN;
599 nums = (ntohs(param.p->length) - sizeof(*outreq)) / sizeof(__u16);
601 str_p = outreq->list_of_streams;
602 for (i = 0; i < nums; i++) {
603 if (ntohs(str_p[i]) >= stream->incnt) {
604 result = SCTP_STRRESET_ERR_WRONG_SSN;
609 for (i = 0; i < nums; i++)
610 stream->in[ntohs(str_p[i])].mid = 0;
612 for (i = 0; i < stream->incnt; i++)
613 stream->in[i].mid = 0;
616 result = SCTP_STRRESET_PERFORMED;
618 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
619 flags | SCTP_STREAM_RESET_OUTGOING_SSN, nums, str_p,
623 sctp_update_strreset_result(asoc, result);
625 return sctp_make_strreset_resp(asoc, result, request_seq);
628 struct sctp_chunk *sctp_process_strreset_inreq(
629 struct sctp_association *asoc,
630 union sctp_params param,
631 struct sctp_ulpevent **evp)
633 struct sctp_strreset_inreq *inreq = param.v;
634 struct sctp_stream *stream = &asoc->stream;
635 __u32 result = SCTP_STRRESET_DENIED;
636 struct sctp_chunk *chunk = NULL;
641 request_seq = ntohl(inreq->request_seq);
642 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
643 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
644 result = SCTP_STRRESET_ERR_BAD_SEQNO;
646 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
647 i = asoc->strreset_inseq - request_seq - 1;
648 result = asoc->strreset_result[i];
649 if (result == SCTP_STRRESET_PERFORMED)
653 asoc->strreset_inseq++;
655 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_STREAM_REQ))
658 if (asoc->strreset_outstanding) {
659 result = SCTP_STRRESET_ERR_IN_PROGRESS;
663 nums = (ntohs(param.p->length) - sizeof(*inreq)) / sizeof(__u16);
664 str_p = inreq->list_of_streams;
665 for (i = 0; i < nums; i++) {
666 if (ntohs(str_p[i]) >= stream->outcnt) {
667 result = SCTP_STRRESET_ERR_WRONG_SSN;
672 if (!sctp_stream_outq_is_empty(stream, nums, str_p)) {
673 result = SCTP_STRRESET_IN_PROGRESS;
674 asoc->strreset_inseq--;
678 chunk = sctp_make_strreset_req(asoc, nums, str_p, 1, 0);
683 for (i = 0; i < nums; i++)
684 stream->out[ntohs(str_p[i])].state =
687 for (i = 0; i < stream->outcnt; i++)
688 stream->out[i].state = SCTP_STREAM_CLOSED;
690 asoc->strreset_chunk = chunk;
691 asoc->strreset_outstanding = 1;
692 sctp_chunk_hold(asoc->strreset_chunk);
694 result = SCTP_STRRESET_PERFORMED;
696 *evp = sctp_ulpevent_make_stream_reset_event(asoc,
697 SCTP_STREAM_RESET_INCOMING_SSN, nums, str_p, GFP_ATOMIC);
700 sctp_update_strreset_result(asoc, result);
703 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
708 struct sctp_chunk *sctp_process_strreset_tsnreq(
709 struct sctp_association *asoc,
710 union sctp_params param,
711 struct sctp_ulpevent **evp)
713 __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen;
714 struct sctp_strreset_tsnreq *tsnreq = param.v;
715 struct sctp_stream *stream = &asoc->stream;
716 __u32 result = SCTP_STRRESET_DENIED;
720 request_seq = ntohl(tsnreq->request_seq);
721 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
722 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
723 result = SCTP_STRRESET_ERR_BAD_SEQNO;
725 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
726 i = asoc->strreset_inseq - request_seq - 1;
727 result = asoc->strreset_result[i];
728 if (result == SCTP_STRRESET_PERFORMED) {
729 next_tsn = asoc->ctsn_ack_point + 1;
731 sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1;
736 if (!sctp_outq_is_empty(&asoc->outqueue)) {
737 result = SCTP_STRRESET_IN_PROGRESS;
741 asoc->strreset_inseq++;
743 if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
746 if (asoc->strreset_outstanding) {
747 result = SCTP_STRRESET_ERR_IN_PROGRESS;
751 /* G4: The same processing as though a FWD-TSN chunk (as defined in
752 * [RFC3758]) with all streams affected and a new cumulative TSN
753 * ACK of the Receiver's Next TSN minus 1 were received MUST be
756 max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
757 asoc->stream.si->report_ftsn(&asoc->ulpq, max_tsn_seen);
759 /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
760 * TSN that the peer should use to send the next DATA chunk. The
761 * value SHOULD be the smallest TSN not acknowledged by the
762 * receiver of the request plus 2^31.
764 init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31);
765 sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
766 init_tsn, GFP_ATOMIC);
768 /* G3: The same processing as though a SACK chunk with no gap report
769 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
770 * received MUST be performed.
772 sctp_outq_free(&asoc->outqueue);
774 /* G2: Compute an appropriate value for the local endpoint's next TSN,
775 * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
776 * chunk. The value SHOULD be the highest TSN sent by the receiver
777 * of the request plus 1.
779 next_tsn = asoc->next_tsn;
780 asoc->ctsn_ack_point = next_tsn - 1;
781 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
783 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
784 * incoming and outgoing streams.
786 for (i = 0; i < stream->outcnt; i++) {
787 stream->out[i].mid = 0;
788 stream->out[i].mid_uo = 0;
790 for (i = 0; i < stream->incnt; i++)
791 stream->in[i].mid = 0;
793 result = SCTP_STRRESET_PERFORMED;
795 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn,
796 next_tsn, GFP_ATOMIC);
799 sctp_update_strreset_result(asoc, result);
801 return sctp_make_strreset_tsnresp(asoc, result, request_seq,
805 struct sctp_chunk *sctp_process_strreset_addstrm_out(
806 struct sctp_association *asoc,
807 union sctp_params param,
808 struct sctp_ulpevent **evp)
810 struct sctp_strreset_addstrm *addstrm = param.v;
811 struct sctp_stream *stream = &asoc->stream;
812 __u32 result = SCTP_STRRESET_DENIED;
813 __u32 request_seq, incnt;
816 request_seq = ntohl(addstrm->request_seq);
817 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
818 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
819 result = SCTP_STRRESET_ERR_BAD_SEQNO;
821 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
822 i = asoc->strreset_inseq - request_seq - 1;
823 result = asoc->strreset_result[i];
826 asoc->strreset_inseq++;
828 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
831 if (asoc->strreset_chunk) {
832 if (!sctp_chunk_lookup_strreset_param(
833 asoc, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS)) {
834 /* same process with outstanding isn't 0 */
835 result = SCTP_STRRESET_ERR_IN_PROGRESS;
839 asoc->strreset_outstanding--;
840 asoc->strreset_outseq++;
842 if (!asoc->strreset_outstanding) {
843 struct sctp_transport *t;
845 t = asoc->strreset_chunk->transport;
846 if (del_timer(&t->reconf_timer))
847 sctp_transport_put(t);
849 sctp_chunk_put(asoc->strreset_chunk);
850 asoc->strreset_chunk = NULL;
854 in = ntohs(addstrm->number_of_streams);
855 incnt = stream->incnt + in;
856 if (!in || incnt > SCTP_MAX_STREAM)
859 if (sctp_stream_alloc_in(stream, incnt, GFP_ATOMIC))
862 stream->incnt = incnt;
864 result = SCTP_STRRESET_PERFORMED;
866 *evp = sctp_ulpevent_make_stream_change_event(asoc,
867 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC);
870 sctp_update_strreset_result(asoc, result);
872 return sctp_make_strreset_resp(asoc, result, request_seq);
875 struct sctp_chunk *sctp_process_strreset_addstrm_in(
876 struct sctp_association *asoc,
877 union sctp_params param,
878 struct sctp_ulpevent **evp)
880 struct sctp_strreset_addstrm *addstrm = param.v;
881 struct sctp_stream *stream = &asoc->stream;
882 __u32 result = SCTP_STRRESET_DENIED;
883 struct sctp_chunk *chunk = NULL;
884 __u32 request_seq, outcnt;
888 request_seq = ntohl(addstrm->request_seq);
889 if (TSN_lt(asoc->strreset_inseq, request_seq) ||
890 TSN_lt(request_seq, asoc->strreset_inseq - 2)) {
891 result = SCTP_STRRESET_ERR_BAD_SEQNO;
893 } else if (TSN_lt(request_seq, asoc->strreset_inseq)) {
894 i = asoc->strreset_inseq - request_seq - 1;
895 result = asoc->strreset_result[i];
896 if (result == SCTP_STRRESET_PERFORMED)
900 asoc->strreset_inseq++;
902 if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
905 if (asoc->strreset_outstanding) {
906 result = SCTP_STRRESET_ERR_IN_PROGRESS;
910 out = ntohs(addstrm->number_of_streams);
911 outcnt = stream->outcnt + out;
912 if (!out || outcnt > SCTP_MAX_STREAM)
915 ret = sctp_stream_alloc_out(stream, outcnt, GFP_ATOMIC);
919 chunk = sctp_make_strreset_addstrm(asoc, out, 0);
923 asoc->strreset_chunk = chunk;
924 asoc->strreset_outstanding = 1;
925 sctp_chunk_hold(asoc->strreset_chunk);
927 stream->outcnt = outcnt;
929 result = SCTP_STRRESET_PERFORMED;
931 *evp = sctp_ulpevent_make_stream_change_event(asoc,
932 0, 0, ntohs(addstrm->number_of_streams), GFP_ATOMIC);
935 sctp_update_strreset_result(asoc, result);
938 chunk = sctp_make_strreset_resp(asoc, result, request_seq);
943 struct sctp_chunk *sctp_process_strreset_resp(
944 struct sctp_association *asoc,
945 union sctp_params param,
946 struct sctp_ulpevent **evp)
948 struct sctp_stream *stream = &asoc->stream;
949 struct sctp_strreset_resp *resp = param.v;
950 struct sctp_transport *t;
951 __u16 i, nums, flags = 0;
952 struct sctp_paramhdr *req;
955 req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0);
959 result = ntohl(resp->result);
960 if (result != SCTP_STRRESET_PERFORMED) {
961 /* if in progress, do nothing but retransmit */
962 if (result == SCTP_STRRESET_IN_PROGRESS)
964 else if (result == SCTP_STRRESET_DENIED)
965 flags = SCTP_STREAM_RESET_DENIED;
967 flags = SCTP_STREAM_RESET_FAILED;
970 if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) {
971 struct sctp_strreset_outreq *outreq;
974 outreq = (struct sctp_strreset_outreq *)req;
975 str_p = outreq->list_of_streams;
976 nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) /
979 if (result == SCTP_STRRESET_PERFORMED) {
981 for (i = 0; i < nums; i++) {
982 stream->out[ntohs(str_p[i])].mid = 0;
983 stream->out[ntohs(str_p[i])].mid_uo = 0;
986 for (i = 0; i < stream->outcnt; i++) {
987 stream->out[i].mid = 0;
988 stream->out[i].mid_uo = 0;
992 flags = SCTP_STREAM_RESET_OUTGOING_SSN;
995 for (i = 0; i < stream->outcnt; i++)
996 stream->out[i].state = SCTP_STREAM_OPEN;
998 *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
999 nums, str_p, GFP_ATOMIC);
1000 } else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) {
1001 struct sctp_strreset_inreq *inreq;
1004 /* if the result is performed, it's impossible for inreq */
1005 if (result == SCTP_STRRESET_PERFORMED)
1008 inreq = (struct sctp_strreset_inreq *)req;
1009 str_p = inreq->list_of_streams;
1010 nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) /
1013 *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
1014 nums, str_p, GFP_ATOMIC);
1015 } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) {
1016 struct sctp_strreset_resptsn *resptsn;
1019 /* check for resptsn, as sctp_verify_reconf didn't do it*/
1020 if (ntohs(param.p->length) != sizeof(*resptsn))
1023 resptsn = (struct sctp_strreset_resptsn *)resp;
1024 stsn = ntohl(resptsn->senders_next_tsn);
1025 rtsn = ntohl(resptsn->receivers_next_tsn);
1027 if (result == SCTP_STRRESET_PERFORMED) {
1028 __u32 mtsn = sctp_tsnmap_get_max_tsn_seen(
1029 &asoc->peer.tsn_map);
1032 asoc->stream.si->report_ftsn(&asoc->ulpq, mtsn);
1034 sctp_tsnmap_init(&asoc->peer.tsn_map,
1035 SCTP_TSN_MAP_INITIAL,
1038 /* Clean up sacked and abandoned queues only. As the
1039 * out_chunk_list may not be empty, splice it to temp,
1040 * then get it back after sctp_outq_free is done.
1042 list_splice_init(&asoc->outqueue.out_chunk_list, &temp);
1043 sctp_outq_free(&asoc->outqueue);
1044 list_splice_init(&temp, &asoc->outqueue.out_chunk_list);
1046 asoc->next_tsn = rtsn;
1047 asoc->ctsn_ack_point = asoc->next_tsn - 1;
1048 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
1050 for (i = 0; i < stream->outcnt; i++) {
1051 stream->out[i].mid = 0;
1052 stream->out[i].mid_uo = 0;
1054 for (i = 0; i < stream->incnt; i++)
1055 stream->in[i].mid = 0;
1058 for (i = 0; i < stream->outcnt; i++)
1059 stream->out[i].state = SCTP_STREAM_OPEN;
1061 *evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags,
1062 stsn, rtsn, GFP_ATOMIC);
1063 } else if (req->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) {
1064 struct sctp_strreset_addstrm *addstrm;
1067 addstrm = (struct sctp_strreset_addstrm *)req;
1068 nums = ntohs(addstrm->number_of_streams);
1069 number = stream->outcnt - nums;
1071 if (result == SCTP_STRRESET_PERFORMED)
1072 for (i = number; i < stream->outcnt; i++)
1073 stream->out[i].state = SCTP_STREAM_OPEN;
1075 stream->outcnt = number;
1077 *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
1078 0, nums, GFP_ATOMIC);
1079 } else if (req->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) {
1080 struct sctp_strreset_addstrm *addstrm;
1082 /* if the result is performed, it's impossible for addstrm in
1085 if (result == SCTP_STRRESET_PERFORMED)
1088 addstrm = (struct sctp_strreset_addstrm *)req;
1089 nums = ntohs(addstrm->number_of_streams);
1091 *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
1092 nums, 0, GFP_ATOMIC);
1095 asoc->strreset_outstanding--;
1096 asoc->strreset_outseq++;
1098 /* remove everything for this reconf request */
1099 if (!asoc->strreset_outstanding) {
1100 t = asoc->strreset_chunk->transport;
1101 if (del_timer(&t->reconf_timer))
1102 sctp_transport_put(t);
1104 sctp_chunk_put(asoc->strreset_chunk);
1105 asoc->strreset_chunk = NULL;