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 * These functions manipulate sctp tsn mapping array.
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 i
= 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
;
173 i
= sctp_stream_alloc_in(stream
, incnt
, gfp
);
179 stream
->incnt
= incnt
;
190 int sctp_stream_init_ext(struct sctp_stream
*stream
, __u16 sid
)
192 struct sctp_stream_out_ext
*soute
;
194 soute
= kzalloc(sizeof(*soute
), GFP_KERNEL
);
197 stream
->out
[sid
].ext
= soute
;
199 return sctp_sched_init_sid(stream
, sid
, GFP_KERNEL
);
202 void sctp_stream_free(struct sctp_stream
*stream
)
204 struct sctp_sched_ops
*sched
= sctp_sched_ops_from_stream(stream
);
208 for (i
= 0; i
< stream
->outcnt
; i
++)
209 kfree(stream
->out
[i
].ext
);
214 void sctp_stream_clear(struct sctp_stream
*stream
)
218 for (i
= 0; i
< stream
->outcnt
; i
++)
219 stream
->out
[i
].ssn
= 0;
221 for (i
= 0; i
< stream
->incnt
; i
++)
222 stream
->in
[i
].ssn
= 0;
225 void sctp_stream_update(struct sctp_stream
*stream
, struct sctp_stream
*new)
227 struct sctp_sched_ops
*sched
= sctp_sched_ops_from_stream(stream
);
229 sched
->unsched_all(stream
);
230 sctp_stream_outq_migrate(stream
, new, new->outcnt
);
231 sctp_stream_free(stream
);
233 stream
->out
= new->out
;
234 stream
->in
= new->in
;
235 stream
->outcnt
= new->outcnt
;
236 stream
->incnt
= new->incnt
;
238 sched
->sched_all(stream
);
244 static int sctp_send_reconf(struct sctp_association
*asoc
,
245 struct sctp_chunk
*chunk
)
247 struct net
*net
= sock_net(asoc
->base
.sk
);
250 retval
= sctp_primitive_RECONF(net
, asoc
, chunk
);
252 sctp_chunk_free(chunk
);
257 static bool sctp_stream_outq_is_empty(struct sctp_stream
*stream
,
258 __u16 str_nums
, __be16
*str_list
)
260 struct sctp_association
*asoc
;
263 asoc
= container_of(stream
, struct sctp_association
, stream
);
264 if (!asoc
->outqueue
.out_qlen
)
270 for (i
= 0; i
< str_nums
; i
++) {
271 __u16 sid
= ntohs(str_list
[i
]);
273 if (stream
->out
[sid
].ext
&&
274 !list_empty(&stream
->out
[sid
].ext
->outq
))
281 int sctp_send_reset_streams(struct sctp_association
*asoc
,
282 struct sctp_reset_streams
*params
)
284 struct sctp_stream
*stream
= &asoc
->stream
;
285 __u16 i
, str_nums
, *str_list
;
286 struct sctp_chunk
*chunk
;
287 int retval
= -EINVAL
;
291 if (!asoc
->peer
.reconf_capable
||
292 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
)) {
293 retval
= -ENOPROTOOPT
;
297 if (asoc
->strreset_outstanding
) {
298 retval
= -EINPROGRESS
;
302 out
= params
->srs_flags
& SCTP_STREAM_RESET_OUTGOING
;
303 in
= params
->srs_flags
& SCTP_STREAM_RESET_INCOMING
;
307 str_nums
= params
->srs_number_streams
;
308 str_list
= params
->srs_stream_list
;
313 for (i
= 0; i
< str_nums
; i
++)
314 if (str_list
[i
] >= stream
->outcnt
)
317 param_len
= str_nums
* sizeof(__u16
) +
318 sizeof(struct sctp_strreset_outreq
);
322 for (i
= 0; i
< str_nums
; i
++)
323 if (str_list
[i
] >= stream
->incnt
)
326 param_len
+= str_nums
* sizeof(__u16
) +
327 sizeof(struct sctp_strreset_inreq
);
330 if (param_len
> SCTP_MAX_CHUNK_LEN
-
331 sizeof(struct sctp_reconf_chunk
))
335 nstr_list
= kcalloc(str_nums
, sizeof(__be16
), GFP_KERNEL
);
341 for (i
= 0; i
< str_nums
; i
++)
342 nstr_list
[i
] = htons(str_list
[i
]);
344 if (out
&& !sctp_stream_outq_is_empty(stream
, str_nums
, nstr_list
)) {
349 chunk
= sctp_make_strreset_req(asoc
, str_nums
, nstr_list
, out
, in
);
360 for (i
= 0; i
< str_nums
; i
++)
361 stream
->out
[str_list
[i
]].state
=
364 for (i
= 0; i
< stream
->outcnt
; i
++)
365 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
368 asoc
->strreset_chunk
= chunk
;
369 sctp_chunk_hold(asoc
->strreset_chunk
);
371 retval
= sctp_send_reconf(asoc
, chunk
);
373 sctp_chunk_put(asoc
->strreset_chunk
);
374 asoc
->strreset_chunk
= NULL
;
379 for (i
= 0; i
< str_nums
; i
++)
380 stream
->out
[str_list
[i
]].state
=
383 for (i
= 0; i
< stream
->outcnt
; i
++)
384 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
389 asoc
->strreset_outstanding
= out
+ in
;
395 int sctp_send_reset_assoc(struct sctp_association
*asoc
)
397 struct sctp_stream
*stream
= &asoc
->stream
;
398 struct sctp_chunk
*chunk
= NULL
;
402 if (!asoc
->peer
.reconf_capable
||
403 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
406 if (asoc
->strreset_outstanding
)
409 if (!sctp_outq_is_empty(&asoc
->outqueue
))
412 chunk
= sctp_make_strreset_tsnreq(asoc
);
416 /* Block further xmit of data until this request is completed */
417 for (i
= 0; i
< stream
->outcnt
; i
++)
418 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
420 asoc
->strreset_chunk
= chunk
;
421 sctp_chunk_hold(asoc
->strreset_chunk
);
423 retval
= sctp_send_reconf(asoc
, chunk
);
425 sctp_chunk_put(asoc
->strreset_chunk
);
426 asoc
->strreset_chunk
= NULL
;
428 for (i
= 0; i
< stream
->outcnt
; i
++)
429 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
434 asoc
->strreset_outstanding
= 1;
439 int sctp_send_add_streams(struct sctp_association
*asoc
,
440 struct sctp_add_streams
*params
)
442 struct sctp_stream
*stream
= &asoc
->stream
;
443 struct sctp_chunk
*chunk
= NULL
;
448 if (!asoc
->peer
.reconf_capable
||
449 !(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
)) {
450 retval
= -ENOPROTOOPT
;
454 if (asoc
->strreset_outstanding
) {
455 retval
= -EINPROGRESS
;
459 out
= params
->sas_outstrms
;
460 in
= params
->sas_instrms
;
461 outcnt
= stream
->outcnt
+ out
;
462 incnt
= stream
->incnt
+ in
;
463 if (outcnt
> SCTP_MAX_STREAM
|| incnt
> SCTP_MAX_STREAM
||
470 retval
= sctp_stream_alloc_out(stream
, outcnt
, GFP_KERNEL
);
475 chunk
= sctp_make_strreset_addstrm(asoc
, out
, in
);
481 asoc
->strreset_chunk
= chunk
;
482 sctp_chunk_hold(asoc
->strreset_chunk
);
484 retval
= sctp_send_reconf(asoc
, chunk
);
486 sctp_chunk_put(asoc
->strreset_chunk
);
487 asoc
->strreset_chunk
= NULL
;
491 stream
->incnt
= incnt
;
492 stream
->outcnt
= outcnt
;
494 asoc
->strreset_outstanding
= !!out
+ !!in
;
500 static struct sctp_paramhdr
*sctp_chunk_lookup_strreset_param(
501 struct sctp_association
*asoc
, __be32 resp_seq
,
504 struct sctp_chunk
*chunk
= asoc
->strreset_chunk
;
505 struct sctp_reconf_chunk
*hdr
;
506 union sctp_params param
;
511 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
512 sctp_walk_params(param
, hdr
, params
) {
513 /* sctp_strreset_tsnreq is actually the basic structure
514 * of all stream reconf params, so it's safe to use it
515 * to access request_seq.
517 struct sctp_strreset_tsnreq
*req
= param
.v
;
519 if ((!resp_seq
|| req
->request_seq
== resp_seq
) &&
520 (!type
|| type
== req
->param_hdr
.type
))
527 static void sctp_update_strreset_result(struct sctp_association
*asoc
,
530 asoc
->strreset_result
[1] = asoc
->strreset_result
[0];
531 asoc
->strreset_result
[0] = result
;
534 struct sctp_chunk
*sctp_process_strreset_outreq(
535 struct sctp_association
*asoc
,
536 union sctp_params param
,
537 struct sctp_ulpevent
**evp
)
539 struct sctp_strreset_outreq
*outreq
= param
.v
;
540 struct sctp_stream
*stream
= &asoc
->stream
;
541 __u32 result
= SCTP_STRRESET_DENIED
;
542 __u16 i
, nums
, flags
= 0;
543 __be16
*str_p
= NULL
;
546 request_seq
= ntohl(outreq
->request_seq
);
548 if (ntohl(outreq
->send_reset_at_tsn
) >
549 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
)) {
550 result
= SCTP_STRRESET_IN_PROGRESS
;
554 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
555 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
556 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
558 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
559 i
= asoc
->strreset_inseq
- request_seq
- 1;
560 result
= asoc
->strreset_result
[i
];
563 asoc
->strreset_inseq
++;
565 /* Check strreset_enable after inseq inc, as sender cannot tell
566 * the peer doesn't enable strreset after receiving response with
567 * result denied, as well as to keep consistent with bsd.
569 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
572 if (asoc
->strreset_chunk
) {
573 if (!sctp_chunk_lookup_strreset_param(
574 asoc
, outreq
->response_seq
,
575 SCTP_PARAM_RESET_IN_REQUEST
)) {
576 /* same process with outstanding isn't 0 */
577 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
581 asoc
->strreset_outstanding
--;
582 asoc
->strreset_outseq
++;
584 if (!asoc
->strreset_outstanding
) {
585 struct sctp_transport
*t
;
587 t
= asoc
->strreset_chunk
->transport
;
588 if (del_timer(&t
->reconf_timer
))
589 sctp_transport_put(t
);
591 sctp_chunk_put(asoc
->strreset_chunk
);
592 asoc
->strreset_chunk
= NULL
;
595 flags
= SCTP_STREAM_RESET_INCOMING_SSN
;
598 nums
= (ntohs(param
.p
->length
) - sizeof(*outreq
)) / sizeof(__u16
);
600 str_p
= outreq
->list_of_streams
;
601 for (i
= 0; i
< nums
; i
++) {
602 if (ntohs(str_p
[i
]) >= stream
->incnt
) {
603 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
608 for (i
= 0; i
< nums
; i
++)
609 stream
->in
[ntohs(str_p
[i
])].ssn
= 0;
611 for (i
= 0; i
< stream
->incnt
; i
++)
612 stream
->in
[i
].ssn
= 0;
615 result
= SCTP_STRRESET_PERFORMED
;
617 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
618 flags
| SCTP_STREAM_RESET_OUTGOING_SSN
, nums
, str_p
,
622 sctp_update_strreset_result(asoc
, result
);
624 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
627 struct sctp_chunk
*sctp_process_strreset_inreq(
628 struct sctp_association
*asoc
,
629 union sctp_params param
,
630 struct sctp_ulpevent
**evp
)
632 struct sctp_strreset_inreq
*inreq
= param
.v
;
633 struct sctp_stream
*stream
= &asoc
->stream
;
634 __u32 result
= SCTP_STRRESET_DENIED
;
635 struct sctp_chunk
*chunk
= NULL
;
640 request_seq
= ntohl(inreq
->request_seq
);
641 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
642 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
643 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
645 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
646 i
= asoc
->strreset_inseq
- request_seq
- 1;
647 result
= asoc
->strreset_result
[i
];
648 if (result
== SCTP_STRRESET_PERFORMED
)
652 asoc
->strreset_inseq
++;
654 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
657 if (asoc
->strreset_outstanding
) {
658 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
662 nums
= (ntohs(param
.p
->length
) - sizeof(*inreq
)) / sizeof(__u16
);
663 str_p
= inreq
->list_of_streams
;
664 for (i
= 0; i
< nums
; i
++) {
665 if (ntohs(str_p
[i
]) >= stream
->outcnt
) {
666 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
671 if (!sctp_stream_outq_is_empty(stream
, nums
, str_p
)) {
672 result
= SCTP_STRRESET_IN_PROGRESS
;
673 asoc
->strreset_inseq
--;
677 chunk
= sctp_make_strreset_req(asoc
, nums
, str_p
, 1, 0);
682 for (i
= 0; i
< nums
; i
++)
683 stream
->out
[ntohs(str_p
[i
])].state
=
686 for (i
= 0; i
< stream
->outcnt
; i
++)
687 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
689 asoc
->strreset_chunk
= chunk
;
690 asoc
->strreset_outstanding
= 1;
691 sctp_chunk_hold(asoc
->strreset_chunk
);
693 result
= SCTP_STRRESET_PERFORMED
;
695 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
696 SCTP_STREAM_RESET_INCOMING_SSN
, nums
, str_p
, GFP_ATOMIC
);
699 sctp_update_strreset_result(asoc
, result
);
702 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
707 struct sctp_chunk
*sctp_process_strreset_tsnreq(
708 struct sctp_association
*asoc
,
709 union sctp_params param
,
710 struct sctp_ulpevent
**evp
)
712 __u32 init_tsn
= 0, next_tsn
= 0, max_tsn_seen
;
713 struct sctp_strreset_tsnreq
*tsnreq
= param
.v
;
714 struct sctp_stream
*stream
= &asoc
->stream
;
715 __u32 result
= SCTP_STRRESET_DENIED
;
719 request_seq
= ntohl(tsnreq
->request_seq
);
720 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
721 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
722 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
724 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
725 i
= asoc
->strreset_inseq
- request_seq
- 1;
726 result
= asoc
->strreset_result
[i
];
727 if (result
== SCTP_STRRESET_PERFORMED
) {
728 next_tsn
= asoc
->ctsn_ack_point
+ 1;
730 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + 1;
735 if (!sctp_outq_is_empty(&asoc
->outqueue
)) {
736 result
= SCTP_STRRESET_IN_PROGRESS
;
740 asoc
->strreset_inseq
++;
742 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
745 if (asoc
->strreset_outstanding
) {
746 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
750 /* G4: The same processing as though a FWD-TSN chunk (as defined in
751 * [RFC3758]) with all streams affected and a new cumulative TSN
752 * ACK of the Receiver's Next TSN minus 1 were received MUST be
755 max_tsn_seen
= sctp_tsnmap_get_max_tsn_seen(&asoc
->peer
.tsn_map
);
756 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, max_tsn_seen
);
757 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
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
].ssn
= 0;
788 for (i
= 0; i
< stream
->incnt
; i
++)
789 stream
->in
[i
].ssn
= 0;
791 result
= SCTP_STRRESET_PERFORMED
;
793 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, 0, init_tsn
,
794 next_tsn
, GFP_ATOMIC
);
797 sctp_update_strreset_result(asoc
, result
);
799 return sctp_make_strreset_tsnresp(asoc
, result
, request_seq
,
803 struct sctp_chunk
*sctp_process_strreset_addstrm_out(
804 struct sctp_association
*asoc
,
805 union sctp_params param
,
806 struct sctp_ulpevent
**evp
)
808 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
809 struct sctp_stream
*stream
= &asoc
->stream
;
810 __u32 result
= SCTP_STRRESET_DENIED
;
811 __u32 request_seq
, incnt
;
814 request_seq
= ntohl(addstrm
->request_seq
);
815 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
816 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
817 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
819 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
820 i
= asoc
->strreset_inseq
- request_seq
- 1;
821 result
= asoc
->strreset_result
[i
];
824 asoc
->strreset_inseq
++;
826 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
829 if (asoc
->strreset_chunk
) {
830 if (!sctp_chunk_lookup_strreset_param(
831 asoc
, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS
)) {
832 /* same process with outstanding isn't 0 */
833 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
837 asoc
->strreset_outstanding
--;
838 asoc
->strreset_outseq
++;
840 if (!asoc
->strreset_outstanding
) {
841 struct sctp_transport
*t
;
843 t
= asoc
->strreset_chunk
->transport
;
844 if (del_timer(&t
->reconf_timer
))
845 sctp_transport_put(t
);
847 sctp_chunk_put(asoc
->strreset_chunk
);
848 asoc
->strreset_chunk
= NULL
;
852 in
= ntohs(addstrm
->number_of_streams
);
853 incnt
= stream
->incnt
+ in
;
854 if (!in
|| incnt
> SCTP_MAX_STREAM
)
857 if (sctp_stream_alloc_in(stream
, incnt
, GFP_ATOMIC
))
860 stream
->incnt
= incnt
;
862 result
= SCTP_STRRESET_PERFORMED
;
864 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
865 0, ntohs(addstrm
->number_of_streams
), 0, GFP_ATOMIC
);
868 sctp_update_strreset_result(asoc
, result
);
870 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
873 struct sctp_chunk
*sctp_process_strreset_addstrm_in(
874 struct sctp_association
*asoc
,
875 union sctp_params param
,
876 struct sctp_ulpevent
**evp
)
878 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
879 struct sctp_stream
*stream
= &asoc
->stream
;
880 __u32 result
= SCTP_STRRESET_DENIED
;
881 struct sctp_chunk
*chunk
= NULL
;
882 __u32 request_seq
, outcnt
;
886 request_seq
= ntohl(addstrm
->request_seq
);
887 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
888 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
889 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
891 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
892 i
= asoc
->strreset_inseq
- request_seq
- 1;
893 result
= asoc
->strreset_result
[i
];
894 if (result
== SCTP_STRRESET_PERFORMED
)
898 asoc
->strreset_inseq
++;
900 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
903 if (asoc
->strreset_outstanding
) {
904 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
908 out
= ntohs(addstrm
->number_of_streams
);
909 outcnt
= stream
->outcnt
+ out
;
910 if (!out
|| outcnt
> SCTP_MAX_STREAM
)
913 ret
= sctp_stream_alloc_out(stream
, outcnt
, GFP_ATOMIC
);
917 chunk
= sctp_make_strreset_addstrm(asoc
, out
, 0);
921 asoc
->strreset_chunk
= chunk
;
922 asoc
->strreset_outstanding
= 1;
923 sctp_chunk_hold(asoc
->strreset_chunk
);
925 stream
->outcnt
= outcnt
;
927 result
= SCTP_STRRESET_PERFORMED
;
929 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
930 0, 0, ntohs(addstrm
->number_of_streams
), GFP_ATOMIC
);
933 sctp_update_strreset_result(asoc
, result
);
936 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
941 struct sctp_chunk
*sctp_process_strreset_resp(
942 struct sctp_association
*asoc
,
943 union sctp_params param
,
944 struct sctp_ulpevent
**evp
)
946 struct sctp_stream
*stream
= &asoc
->stream
;
947 struct sctp_strreset_resp
*resp
= param
.v
;
948 struct sctp_transport
*t
;
949 __u16 i
, nums
, flags
= 0;
950 struct sctp_paramhdr
*req
;
953 req
= sctp_chunk_lookup_strreset_param(asoc
, resp
->response_seq
, 0);
957 result
= ntohl(resp
->result
);
958 if (result
!= SCTP_STRRESET_PERFORMED
) {
959 /* if in progress, do nothing but retransmit */
960 if (result
== SCTP_STRRESET_IN_PROGRESS
)
962 else if (result
== SCTP_STRRESET_DENIED
)
963 flags
= SCTP_STREAM_RESET_DENIED
;
965 flags
= SCTP_STREAM_RESET_FAILED
;
968 if (req
->type
== SCTP_PARAM_RESET_OUT_REQUEST
) {
969 struct sctp_strreset_outreq
*outreq
;
972 outreq
= (struct sctp_strreset_outreq
*)req
;
973 str_p
= outreq
->list_of_streams
;
974 nums
= (ntohs(outreq
->param_hdr
.length
) - sizeof(*outreq
)) /
977 if (result
== SCTP_STRRESET_PERFORMED
) {
979 for (i
= 0; i
< nums
; i
++)
980 stream
->out
[ntohs(str_p
[i
])].ssn
= 0;
982 for (i
= 0; i
< stream
->outcnt
; i
++)
983 stream
->out
[i
].ssn
= 0;
986 flags
= SCTP_STREAM_RESET_OUTGOING_SSN
;
989 for (i
= 0; i
< stream
->outcnt
; i
++)
990 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
992 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
993 nums
, str_p
, GFP_ATOMIC
);
994 } else if (req
->type
== SCTP_PARAM_RESET_IN_REQUEST
) {
995 struct sctp_strreset_inreq
*inreq
;
998 /* if the result is performed, it's impossible for inreq */
999 if (result
== SCTP_STRRESET_PERFORMED
)
1002 inreq
= (struct sctp_strreset_inreq
*)req
;
1003 str_p
= inreq
->list_of_streams
;
1004 nums
= (ntohs(inreq
->param_hdr
.length
) - sizeof(*inreq
)) /
1007 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
1008 nums
, str_p
, GFP_ATOMIC
);
1009 } else if (req
->type
== SCTP_PARAM_RESET_TSN_REQUEST
) {
1010 struct sctp_strreset_resptsn
*resptsn
;
1013 /* check for resptsn, as sctp_verify_reconf didn't do it*/
1014 if (ntohs(param
.p
->length
) != sizeof(*resptsn
))
1017 resptsn
= (struct sctp_strreset_resptsn
*)resp
;
1018 stsn
= ntohl(resptsn
->senders_next_tsn
);
1019 rtsn
= ntohl(resptsn
->receivers_next_tsn
);
1021 if (result
== SCTP_STRRESET_PERFORMED
) {
1022 __u32 mtsn
= sctp_tsnmap_get_max_tsn_seen(
1023 &asoc
->peer
.tsn_map
);
1026 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, mtsn
);
1027 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
1029 sctp_tsnmap_init(&asoc
->peer
.tsn_map
,
1030 SCTP_TSN_MAP_INITIAL
,
1033 /* Clean up sacked and abandoned queues only. As the
1034 * out_chunk_list may not be empty, splice it to temp,
1035 * then get it back after sctp_outq_free is done.
1037 list_splice_init(&asoc
->outqueue
.out_chunk_list
, &temp
);
1038 sctp_outq_free(&asoc
->outqueue
);
1039 list_splice_init(&temp
, &asoc
->outqueue
.out_chunk_list
);
1041 asoc
->next_tsn
= rtsn
;
1042 asoc
->ctsn_ack_point
= asoc
->next_tsn
- 1;
1043 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
1045 for (i
= 0; i
< stream
->outcnt
; i
++)
1046 stream
->out
[i
].ssn
= 0;
1047 for (i
= 0; i
< stream
->incnt
; i
++)
1048 stream
->in
[i
].ssn
= 0;
1051 for (i
= 0; i
< stream
->outcnt
; i
++)
1052 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
1054 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, flags
,
1055 stsn
, rtsn
, GFP_ATOMIC
);
1056 } else if (req
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
) {
1057 struct sctp_strreset_addstrm
*addstrm
;
1060 addstrm
= (struct sctp_strreset_addstrm
*)req
;
1061 nums
= ntohs(addstrm
->number_of_streams
);
1062 number
= stream
->outcnt
- nums
;
1064 if (result
== SCTP_STRRESET_PERFORMED
)
1065 for (i
= number
; i
< stream
->outcnt
; i
++)
1066 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
1068 stream
->outcnt
= number
;
1070 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
1071 0, nums
, GFP_ATOMIC
);
1072 } else if (req
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
) {
1073 struct sctp_strreset_addstrm
*addstrm
;
1075 /* if the result is performed, it's impossible for addstrm in
1078 if (result
== SCTP_STRRESET_PERFORMED
)
1081 addstrm
= (struct sctp_strreset_addstrm
*)req
;
1082 nums
= ntohs(addstrm
->number_of_streams
);
1084 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
1085 nums
, 0, GFP_ATOMIC
);
1088 asoc
->strreset_outstanding
--;
1089 asoc
->strreset_outseq
++;
1091 /* remove everything for this reconf request */
1092 if (!asoc
->strreset_outstanding
) {
1093 t
= asoc
->strreset_chunk
->transport
;
1094 if (del_timer(&t
->reconf_timer
))
1095 sctp_transport_put(t
);
1097 sctp_chunk_put(asoc
->strreset_chunk
);
1098 asoc
->strreset_chunk
= NULL
;