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 static struct flex_array
*fa_alloc(size_t elem_size
, size_t elem_count
,
43 struct flex_array
*result
;
46 result
= flex_array_alloc(elem_size
, elem_count
, gfp
);
48 err
= flex_array_prealloc(result
, 0, elem_count
, gfp
);
50 flex_array_free(result
);
58 static void fa_free(struct flex_array
*fa
)
64 static void fa_copy(struct flex_array
*fa
, struct flex_array
*from
,
65 size_t index
, size_t count
)
70 elem
= flex_array_get(from
, index
);
71 flex_array_put(fa
, index
, elem
, 0);
76 static void fa_zero(struct flex_array
*fa
, size_t index
, size_t count
)
81 elem
= flex_array_get(fa
, index
);
82 memset(elem
, 0, fa
->element_size
);
87 /* Migrates chunks from stream queues to new stream queues if needed,
88 * but not across associations. Also, removes those chunks to streams
89 * higher than the new max.
91 static void sctp_stream_outq_migrate(struct sctp_stream
*stream
,
92 struct sctp_stream
*new, __u16 outcnt
)
94 struct sctp_association
*asoc
;
95 struct sctp_chunk
*ch
, *temp
;
96 struct sctp_outq
*outq
;
99 asoc
= container_of(stream
, struct sctp_association
, stream
);
100 outq
= &asoc
->outqueue
;
102 list_for_each_entry_safe(ch
, temp
, &outq
->out_chunk_list
, list
) {
103 __u16 sid
= sctp_chunk_stream_no(ch
);
108 sctp_sched_dequeue_common(outq
, ch
);
109 /* No need to call dequeue_done here because
110 * the chunks are not scheduled by now.
113 /* Mark as failed send. */
114 sctp_chunk_fail(ch
, (__force __u32
)SCTP_ERROR_INV_STRM
);
115 if (asoc
->peer
.prsctp_capable
&&
116 SCTP_PR_PRIO_ENABLED(ch
->sinfo
.sinfo_flags
))
117 asoc
->sent_cnt_removable
--;
123 /* Here we actually move the old ext stuff into the new
124 * buffer, because we want to keep it. Then
125 * sctp_stream_update will swap ->out pointers.
127 for (i
= 0; i
< outcnt
; i
++) {
128 kfree(SCTP_SO(new, i
)->ext
);
129 SCTP_SO(new, i
)->ext
= SCTP_SO(stream
, i
)->ext
;
130 SCTP_SO(stream
, i
)->ext
= NULL
;
134 for (i
= outcnt
; i
< stream
->outcnt
; i
++)
135 kfree(SCTP_SO(stream
, i
)->ext
);
138 static int sctp_stream_alloc_out(struct sctp_stream
*stream
, __u16 outcnt
,
141 struct flex_array
*out
;
142 size_t elem_size
= sizeof(struct sctp_stream_out
);
144 out
= fa_alloc(elem_size
, outcnt
, gfp
);
149 fa_copy(out
, stream
->out
, 0, min(outcnt
, stream
->outcnt
));
150 fa_free(stream
->out
);
153 if (outcnt
> stream
->outcnt
)
154 fa_zero(out
, stream
->outcnt
, (outcnt
- stream
->outcnt
));
161 static int sctp_stream_alloc_in(struct sctp_stream
*stream
, __u16 incnt
,
164 struct flex_array
*in
;
165 size_t elem_size
= sizeof(struct sctp_stream_in
);
167 in
= fa_alloc(elem_size
, incnt
, gfp
);
172 fa_copy(in
, stream
->in
, 0, min(incnt
, stream
->incnt
));
176 if (incnt
> stream
->incnt
)
177 fa_zero(in
, stream
->incnt
, (incnt
- stream
->incnt
));
184 int sctp_stream_init(struct sctp_stream
*stream
, __u16 outcnt
, __u16 incnt
,
187 struct sctp_sched_ops
*sched
= sctp_sched_ops_from_stream(stream
);
192 /* Initial stream->out size may be very big, so free it and alloc
193 * a new one with new outcnt to save memory if needed.
195 if (outcnt
== stream
->outcnt
)
198 /* Filter out chunks queued on streams that won't exist anymore */
199 sched
->unsched_all(stream
);
200 sctp_stream_outq_migrate(stream
, NULL
, outcnt
);
201 sched
->sched_all(stream
);
203 ret
= sctp_stream_alloc_out(stream
, outcnt
, gfp
);
207 stream
->outcnt
= outcnt
;
208 for (i
= 0; i
< stream
->outcnt
; i
++)
209 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_OPEN
;
214 sctp_stream_interleave_init(stream
);
218 ret
= sctp_stream_alloc_in(stream
, incnt
, gfp
);
221 fa_free(stream
->out
);
227 stream
->incnt
= incnt
;
233 int sctp_stream_init_ext(struct sctp_stream
*stream
, __u16 sid
)
235 struct sctp_stream_out_ext
*soute
;
237 soute
= kzalloc(sizeof(*soute
), GFP_KERNEL
);
240 SCTP_SO(stream
, sid
)->ext
= soute
;
242 return sctp_sched_init_sid(stream
, sid
, GFP_KERNEL
);
245 void sctp_stream_free(struct sctp_stream
*stream
)
247 struct sctp_sched_ops
*sched
= sctp_sched_ops_from_stream(stream
);
251 for (i
= 0; i
< stream
->outcnt
; i
++)
252 kfree(SCTP_SO(stream
, i
)->ext
);
253 fa_free(stream
->out
);
257 void sctp_stream_clear(struct sctp_stream
*stream
)
261 for (i
= 0; i
< stream
->outcnt
; i
++) {
262 SCTP_SO(stream
, i
)->mid
= 0;
263 SCTP_SO(stream
, i
)->mid_uo
= 0;
266 for (i
= 0; i
< stream
->incnt
; i
++)
267 SCTP_SI(stream
, i
)->mid
= 0;
270 void sctp_stream_update(struct sctp_stream
*stream
, struct sctp_stream
*new)
272 struct sctp_sched_ops
*sched
= sctp_sched_ops_from_stream(stream
);
274 sched
->unsched_all(stream
);
275 sctp_stream_outq_migrate(stream
, new, new->outcnt
);
276 sctp_stream_free(stream
);
278 stream
->out
= new->out
;
279 stream
->in
= new->in
;
280 stream
->outcnt
= new->outcnt
;
281 stream
->incnt
= new->incnt
;
283 sched
->sched_all(stream
);
291 static int sctp_send_reconf(struct sctp_association
*asoc
,
292 struct sctp_chunk
*chunk
)
294 struct net
*net
= sock_net(asoc
->base
.sk
);
297 retval
= sctp_primitive_RECONF(net
, asoc
, chunk
);
299 sctp_chunk_free(chunk
);
304 static bool sctp_stream_outq_is_empty(struct sctp_stream
*stream
,
305 __u16 str_nums
, __be16
*str_list
)
307 struct sctp_association
*asoc
;
310 asoc
= container_of(stream
, struct sctp_association
, stream
);
311 if (!asoc
->outqueue
.out_qlen
)
317 for (i
= 0; i
< str_nums
; i
++) {
318 __u16 sid
= ntohs(str_list
[i
]);
320 if (SCTP_SO(stream
, sid
)->ext
&&
321 !list_empty(&SCTP_SO(stream
, sid
)->ext
->outq
))
328 int sctp_send_reset_streams(struct sctp_association
*asoc
,
329 struct sctp_reset_streams
*params
)
331 struct sctp_stream
*stream
= &asoc
->stream
;
332 __u16 i
, str_nums
, *str_list
;
333 struct sctp_chunk
*chunk
;
334 int retval
= -EINVAL
;
338 if (!asoc
->peer
.reconf_capable
||
339 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
)) {
340 retval
= -ENOPROTOOPT
;
344 if (asoc
->strreset_outstanding
) {
345 retval
= -EINPROGRESS
;
349 out
= params
->srs_flags
& SCTP_STREAM_RESET_OUTGOING
;
350 in
= params
->srs_flags
& SCTP_STREAM_RESET_INCOMING
;
354 str_nums
= params
->srs_number_streams
;
355 str_list
= params
->srs_stream_list
;
360 for (i
= 0; i
< str_nums
; i
++)
361 if (str_list
[i
] >= stream
->outcnt
)
364 param_len
= str_nums
* sizeof(__u16
) +
365 sizeof(struct sctp_strreset_outreq
);
369 for (i
= 0; i
< str_nums
; i
++)
370 if (str_list
[i
] >= stream
->incnt
)
373 param_len
+= str_nums
* sizeof(__u16
) +
374 sizeof(struct sctp_strreset_inreq
);
377 if (param_len
> SCTP_MAX_CHUNK_LEN
-
378 sizeof(struct sctp_reconf_chunk
))
382 nstr_list
= kcalloc(str_nums
, sizeof(__be16
), GFP_KERNEL
);
388 for (i
= 0; i
< str_nums
; i
++)
389 nstr_list
[i
] = htons(str_list
[i
]);
391 if (out
&& !sctp_stream_outq_is_empty(stream
, str_nums
, nstr_list
)) {
396 chunk
= sctp_make_strreset_req(asoc
, str_nums
, nstr_list
, out
, in
);
407 for (i
= 0; i
< str_nums
; i
++)
408 SCTP_SO(stream
, str_list
[i
])->state
=
411 for (i
= 0; i
< stream
->outcnt
; i
++)
412 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_CLOSED
;
415 asoc
->strreset_chunk
= chunk
;
416 sctp_chunk_hold(asoc
->strreset_chunk
);
418 retval
= sctp_send_reconf(asoc
, chunk
);
420 sctp_chunk_put(asoc
->strreset_chunk
);
421 asoc
->strreset_chunk
= NULL
;
426 for (i
= 0; i
< str_nums
; i
++)
427 SCTP_SO(stream
, str_list
[i
])->state
=
430 for (i
= 0; i
< stream
->outcnt
; i
++)
431 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_OPEN
;
436 asoc
->strreset_outstanding
= out
+ in
;
442 int sctp_send_reset_assoc(struct sctp_association
*asoc
)
444 struct sctp_stream
*stream
= &asoc
->stream
;
445 struct sctp_chunk
*chunk
= NULL
;
449 if (!asoc
->peer
.reconf_capable
||
450 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
453 if (asoc
->strreset_outstanding
)
456 if (!sctp_outq_is_empty(&asoc
->outqueue
))
459 chunk
= sctp_make_strreset_tsnreq(asoc
);
463 /* Block further xmit of data until this request is completed */
464 for (i
= 0; i
< stream
->outcnt
; i
++)
465 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_CLOSED
;
467 asoc
->strreset_chunk
= chunk
;
468 sctp_chunk_hold(asoc
->strreset_chunk
);
470 retval
= sctp_send_reconf(asoc
, chunk
);
472 sctp_chunk_put(asoc
->strreset_chunk
);
473 asoc
->strreset_chunk
= NULL
;
475 for (i
= 0; i
< stream
->outcnt
; i
++)
476 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_OPEN
;
481 asoc
->strreset_outstanding
= 1;
486 int sctp_send_add_streams(struct sctp_association
*asoc
,
487 struct sctp_add_streams
*params
)
489 struct sctp_stream
*stream
= &asoc
->stream
;
490 struct sctp_chunk
*chunk
= NULL
;
495 if (!asoc
->peer
.reconf_capable
||
496 !(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
)) {
497 retval
= -ENOPROTOOPT
;
501 if (asoc
->strreset_outstanding
) {
502 retval
= -EINPROGRESS
;
506 out
= params
->sas_outstrms
;
507 in
= params
->sas_instrms
;
508 outcnt
= stream
->outcnt
+ out
;
509 incnt
= stream
->incnt
+ in
;
510 if (outcnt
> SCTP_MAX_STREAM
|| incnt
> SCTP_MAX_STREAM
||
517 retval
= sctp_stream_alloc_out(stream
, outcnt
, GFP_KERNEL
);
522 chunk
= sctp_make_strreset_addstrm(asoc
, out
, in
);
528 asoc
->strreset_chunk
= chunk
;
529 sctp_chunk_hold(asoc
->strreset_chunk
);
531 retval
= sctp_send_reconf(asoc
, chunk
);
533 sctp_chunk_put(asoc
->strreset_chunk
);
534 asoc
->strreset_chunk
= NULL
;
538 stream
->incnt
= incnt
;
539 stream
->outcnt
= outcnt
;
541 asoc
->strreset_outstanding
= !!out
+ !!in
;
547 static struct sctp_paramhdr
*sctp_chunk_lookup_strreset_param(
548 struct sctp_association
*asoc
, __be32 resp_seq
,
551 struct sctp_chunk
*chunk
= asoc
->strreset_chunk
;
552 struct sctp_reconf_chunk
*hdr
;
553 union sctp_params param
;
558 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
559 sctp_walk_params(param
, hdr
, params
) {
560 /* sctp_strreset_tsnreq is actually the basic structure
561 * of all stream reconf params, so it's safe to use it
562 * to access request_seq.
564 struct sctp_strreset_tsnreq
*req
= param
.v
;
566 if ((!resp_seq
|| req
->request_seq
== resp_seq
) &&
567 (!type
|| type
== req
->param_hdr
.type
))
574 static void sctp_update_strreset_result(struct sctp_association
*asoc
,
577 asoc
->strreset_result
[1] = asoc
->strreset_result
[0];
578 asoc
->strreset_result
[0] = result
;
581 struct sctp_chunk
*sctp_process_strreset_outreq(
582 struct sctp_association
*asoc
,
583 union sctp_params param
,
584 struct sctp_ulpevent
**evp
)
586 struct sctp_strreset_outreq
*outreq
= param
.v
;
587 struct sctp_stream
*stream
= &asoc
->stream
;
588 __u32 result
= SCTP_STRRESET_DENIED
;
589 __u16 i
, nums
, flags
= 0;
590 __be16
*str_p
= NULL
;
593 request_seq
= ntohl(outreq
->request_seq
);
595 if (ntohl(outreq
->send_reset_at_tsn
) >
596 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
)) {
597 result
= SCTP_STRRESET_IN_PROGRESS
;
601 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
602 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
603 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
605 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
606 i
= asoc
->strreset_inseq
- request_seq
- 1;
607 result
= asoc
->strreset_result
[i
];
610 asoc
->strreset_inseq
++;
612 /* Check strreset_enable after inseq inc, as sender cannot tell
613 * the peer doesn't enable strreset after receiving response with
614 * result denied, as well as to keep consistent with bsd.
616 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
619 if (asoc
->strreset_chunk
) {
620 if (!sctp_chunk_lookup_strreset_param(
621 asoc
, outreq
->response_seq
,
622 SCTP_PARAM_RESET_IN_REQUEST
)) {
623 /* same process with outstanding isn't 0 */
624 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
628 asoc
->strreset_outstanding
--;
629 asoc
->strreset_outseq
++;
631 if (!asoc
->strreset_outstanding
) {
632 struct sctp_transport
*t
;
634 t
= asoc
->strreset_chunk
->transport
;
635 if (del_timer(&t
->reconf_timer
))
636 sctp_transport_put(t
);
638 sctp_chunk_put(asoc
->strreset_chunk
);
639 asoc
->strreset_chunk
= NULL
;
642 flags
= SCTP_STREAM_RESET_INCOMING_SSN
;
645 nums
= (ntohs(param
.p
->length
) - sizeof(*outreq
)) / sizeof(__u16
);
647 str_p
= outreq
->list_of_streams
;
648 for (i
= 0; i
< nums
; i
++) {
649 if (ntohs(str_p
[i
]) >= stream
->incnt
) {
650 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
655 for (i
= 0; i
< nums
; i
++)
656 SCTP_SI(stream
, ntohs(str_p
[i
]))->mid
= 0;
658 for (i
= 0; i
< stream
->incnt
; i
++)
659 SCTP_SI(stream
, i
)->mid
= 0;
662 result
= SCTP_STRRESET_PERFORMED
;
664 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
665 flags
| SCTP_STREAM_RESET_OUTGOING_SSN
, nums
, str_p
,
669 sctp_update_strreset_result(asoc
, result
);
671 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
674 struct sctp_chunk
*sctp_process_strreset_inreq(
675 struct sctp_association
*asoc
,
676 union sctp_params param
,
677 struct sctp_ulpevent
**evp
)
679 struct sctp_strreset_inreq
*inreq
= param
.v
;
680 struct sctp_stream
*stream
= &asoc
->stream
;
681 __u32 result
= SCTP_STRRESET_DENIED
;
682 struct sctp_chunk
*chunk
= NULL
;
687 request_seq
= ntohl(inreq
->request_seq
);
688 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
689 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
690 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
692 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
693 i
= asoc
->strreset_inseq
- request_seq
- 1;
694 result
= asoc
->strreset_result
[i
];
695 if (result
== SCTP_STRRESET_PERFORMED
)
699 asoc
->strreset_inseq
++;
701 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
704 if (asoc
->strreset_outstanding
) {
705 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
709 nums
= (ntohs(param
.p
->length
) - sizeof(*inreq
)) / sizeof(__u16
);
710 str_p
= inreq
->list_of_streams
;
711 for (i
= 0; i
< nums
; i
++) {
712 if (ntohs(str_p
[i
]) >= stream
->outcnt
) {
713 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
718 if (!sctp_stream_outq_is_empty(stream
, nums
, str_p
)) {
719 result
= SCTP_STRRESET_IN_PROGRESS
;
720 asoc
->strreset_inseq
--;
724 chunk
= sctp_make_strreset_req(asoc
, nums
, str_p
, 1, 0);
729 for (i
= 0; i
< nums
; i
++)
730 SCTP_SO(stream
, ntohs(str_p
[i
]))->state
=
733 for (i
= 0; i
< stream
->outcnt
; i
++)
734 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_CLOSED
;
736 asoc
->strreset_chunk
= chunk
;
737 asoc
->strreset_outstanding
= 1;
738 sctp_chunk_hold(asoc
->strreset_chunk
);
740 result
= SCTP_STRRESET_PERFORMED
;
742 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
743 SCTP_STREAM_RESET_INCOMING_SSN
, nums
, str_p
, GFP_ATOMIC
);
746 sctp_update_strreset_result(asoc
, result
);
749 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
754 struct sctp_chunk
*sctp_process_strreset_tsnreq(
755 struct sctp_association
*asoc
,
756 union sctp_params param
,
757 struct sctp_ulpevent
**evp
)
759 __u32 init_tsn
= 0, next_tsn
= 0, max_tsn_seen
;
760 struct sctp_strreset_tsnreq
*tsnreq
= param
.v
;
761 struct sctp_stream
*stream
= &asoc
->stream
;
762 __u32 result
= SCTP_STRRESET_DENIED
;
766 request_seq
= ntohl(tsnreq
->request_seq
);
767 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
768 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
769 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
771 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
772 i
= asoc
->strreset_inseq
- request_seq
- 1;
773 result
= asoc
->strreset_result
[i
];
774 if (result
== SCTP_STRRESET_PERFORMED
) {
775 next_tsn
= asoc
->ctsn_ack_point
+ 1;
777 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + 1;
782 if (!sctp_outq_is_empty(&asoc
->outqueue
)) {
783 result
= SCTP_STRRESET_IN_PROGRESS
;
787 asoc
->strreset_inseq
++;
789 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
792 if (asoc
->strreset_outstanding
) {
793 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
797 /* G4: The same processing as though a FWD-TSN chunk (as defined in
798 * [RFC3758]) with all streams affected and a new cumulative TSN
799 * ACK of the Receiver's Next TSN minus 1 were received MUST be
802 max_tsn_seen
= sctp_tsnmap_get_max_tsn_seen(&asoc
->peer
.tsn_map
);
803 asoc
->stream
.si
->report_ftsn(&asoc
->ulpq
, max_tsn_seen
);
805 /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
806 * TSN that the peer should use to send the next DATA chunk. The
807 * value SHOULD be the smallest TSN not acknowledged by the
808 * receiver of the request plus 2^31.
810 init_tsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + (1 << 31);
811 sctp_tsnmap_init(&asoc
->peer
.tsn_map
, SCTP_TSN_MAP_INITIAL
,
812 init_tsn
, GFP_ATOMIC
);
814 /* G3: The same processing as though a SACK chunk with no gap report
815 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
816 * received MUST be performed.
818 sctp_outq_free(&asoc
->outqueue
);
820 /* G2: Compute an appropriate value for the local endpoint's next TSN,
821 * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
822 * chunk. The value SHOULD be the highest TSN sent by the receiver
823 * of the request plus 1.
825 next_tsn
= asoc
->next_tsn
;
826 asoc
->ctsn_ack_point
= next_tsn
- 1;
827 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
829 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
830 * incoming and outgoing streams.
832 for (i
= 0; i
< stream
->outcnt
; i
++) {
833 SCTP_SO(stream
, i
)->mid
= 0;
834 SCTP_SO(stream
, i
)->mid_uo
= 0;
836 for (i
= 0; i
< stream
->incnt
; i
++)
837 SCTP_SI(stream
, i
)->mid
= 0;
839 result
= SCTP_STRRESET_PERFORMED
;
841 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, 0, init_tsn
,
842 next_tsn
, GFP_ATOMIC
);
845 sctp_update_strreset_result(asoc
, result
);
847 return sctp_make_strreset_tsnresp(asoc
, result
, request_seq
,
851 struct sctp_chunk
*sctp_process_strreset_addstrm_out(
852 struct sctp_association
*asoc
,
853 union sctp_params param
,
854 struct sctp_ulpevent
**evp
)
856 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
857 struct sctp_stream
*stream
= &asoc
->stream
;
858 __u32 result
= SCTP_STRRESET_DENIED
;
859 __u32 request_seq
, incnt
;
862 request_seq
= ntohl(addstrm
->request_seq
);
863 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
864 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
865 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
867 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
868 i
= asoc
->strreset_inseq
- request_seq
- 1;
869 result
= asoc
->strreset_result
[i
];
872 asoc
->strreset_inseq
++;
874 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
877 if (asoc
->strreset_chunk
) {
878 if (!sctp_chunk_lookup_strreset_param(
879 asoc
, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS
)) {
880 /* same process with outstanding isn't 0 */
881 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
885 asoc
->strreset_outstanding
--;
886 asoc
->strreset_outseq
++;
888 if (!asoc
->strreset_outstanding
) {
889 struct sctp_transport
*t
;
891 t
= asoc
->strreset_chunk
->transport
;
892 if (del_timer(&t
->reconf_timer
))
893 sctp_transport_put(t
);
895 sctp_chunk_put(asoc
->strreset_chunk
);
896 asoc
->strreset_chunk
= NULL
;
900 in
= ntohs(addstrm
->number_of_streams
);
901 incnt
= stream
->incnt
+ in
;
902 if (!in
|| incnt
> SCTP_MAX_STREAM
)
905 if (sctp_stream_alloc_in(stream
, incnt
, GFP_ATOMIC
))
908 stream
->incnt
= incnt
;
910 result
= SCTP_STRRESET_PERFORMED
;
912 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
913 0, ntohs(addstrm
->number_of_streams
), 0, GFP_ATOMIC
);
916 sctp_update_strreset_result(asoc
, result
);
918 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
921 struct sctp_chunk
*sctp_process_strreset_addstrm_in(
922 struct sctp_association
*asoc
,
923 union sctp_params param
,
924 struct sctp_ulpevent
**evp
)
926 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
927 struct sctp_stream
*stream
= &asoc
->stream
;
928 __u32 result
= SCTP_STRRESET_DENIED
;
929 struct sctp_chunk
*chunk
= NULL
;
930 __u32 request_seq
, outcnt
;
934 request_seq
= ntohl(addstrm
->request_seq
);
935 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
936 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
937 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
939 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
940 i
= asoc
->strreset_inseq
- request_seq
- 1;
941 result
= asoc
->strreset_result
[i
];
942 if (result
== SCTP_STRRESET_PERFORMED
)
946 asoc
->strreset_inseq
++;
948 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
951 if (asoc
->strreset_outstanding
) {
952 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
956 out
= ntohs(addstrm
->number_of_streams
);
957 outcnt
= stream
->outcnt
+ out
;
958 if (!out
|| outcnt
> SCTP_MAX_STREAM
)
961 ret
= sctp_stream_alloc_out(stream
, outcnt
, GFP_ATOMIC
);
965 chunk
= sctp_make_strreset_addstrm(asoc
, out
, 0);
969 asoc
->strreset_chunk
= chunk
;
970 asoc
->strreset_outstanding
= 1;
971 sctp_chunk_hold(asoc
->strreset_chunk
);
973 stream
->outcnt
= outcnt
;
975 result
= SCTP_STRRESET_PERFORMED
;
977 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
978 0, 0, ntohs(addstrm
->number_of_streams
), GFP_ATOMIC
);
981 sctp_update_strreset_result(asoc
, result
);
984 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
989 struct sctp_chunk
*sctp_process_strreset_resp(
990 struct sctp_association
*asoc
,
991 union sctp_params param
,
992 struct sctp_ulpevent
**evp
)
994 struct sctp_stream
*stream
= &asoc
->stream
;
995 struct sctp_strreset_resp
*resp
= param
.v
;
996 struct sctp_transport
*t
;
997 __u16 i
, nums
, flags
= 0;
998 struct sctp_paramhdr
*req
;
1001 req
= sctp_chunk_lookup_strreset_param(asoc
, resp
->response_seq
, 0);
1005 result
= ntohl(resp
->result
);
1006 if (result
!= SCTP_STRRESET_PERFORMED
) {
1007 /* if in progress, do nothing but retransmit */
1008 if (result
== SCTP_STRRESET_IN_PROGRESS
)
1010 else if (result
== SCTP_STRRESET_DENIED
)
1011 flags
= SCTP_STREAM_RESET_DENIED
;
1013 flags
= SCTP_STREAM_RESET_FAILED
;
1016 if (req
->type
== SCTP_PARAM_RESET_OUT_REQUEST
) {
1017 struct sctp_strreset_outreq
*outreq
;
1020 outreq
= (struct sctp_strreset_outreq
*)req
;
1021 str_p
= outreq
->list_of_streams
;
1022 nums
= (ntohs(outreq
->param_hdr
.length
) - sizeof(*outreq
)) /
1025 if (result
== SCTP_STRRESET_PERFORMED
) {
1026 struct sctp_stream_out
*sout
;
1028 for (i
= 0; i
< nums
; i
++) {
1029 sout
= SCTP_SO(stream
, ntohs(str_p
[i
]));
1034 for (i
= 0; i
< stream
->outcnt
; i
++) {
1035 sout
= SCTP_SO(stream
, i
);
1041 flags
= SCTP_STREAM_RESET_OUTGOING_SSN
;
1044 for (i
= 0; i
< stream
->outcnt
; i
++)
1045 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_OPEN
;
1047 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
1048 nums
, str_p
, GFP_ATOMIC
);
1049 } else if (req
->type
== SCTP_PARAM_RESET_IN_REQUEST
) {
1050 struct sctp_strreset_inreq
*inreq
;
1053 /* if the result is performed, it's impossible for inreq */
1054 if (result
== SCTP_STRRESET_PERFORMED
)
1057 inreq
= (struct sctp_strreset_inreq
*)req
;
1058 str_p
= inreq
->list_of_streams
;
1059 nums
= (ntohs(inreq
->param_hdr
.length
) - sizeof(*inreq
)) /
1062 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
1063 nums
, str_p
, GFP_ATOMIC
);
1064 } else if (req
->type
== SCTP_PARAM_RESET_TSN_REQUEST
) {
1065 struct sctp_strreset_resptsn
*resptsn
;
1068 /* check for resptsn, as sctp_verify_reconf didn't do it*/
1069 if (ntohs(param
.p
->length
) != sizeof(*resptsn
))
1072 resptsn
= (struct sctp_strreset_resptsn
*)resp
;
1073 stsn
= ntohl(resptsn
->senders_next_tsn
);
1074 rtsn
= ntohl(resptsn
->receivers_next_tsn
);
1076 if (result
== SCTP_STRRESET_PERFORMED
) {
1077 __u32 mtsn
= sctp_tsnmap_get_max_tsn_seen(
1078 &asoc
->peer
.tsn_map
);
1081 asoc
->stream
.si
->report_ftsn(&asoc
->ulpq
, mtsn
);
1083 sctp_tsnmap_init(&asoc
->peer
.tsn_map
,
1084 SCTP_TSN_MAP_INITIAL
,
1087 /* Clean up sacked and abandoned queues only. As the
1088 * out_chunk_list may not be empty, splice it to temp,
1089 * then get it back after sctp_outq_free is done.
1091 list_splice_init(&asoc
->outqueue
.out_chunk_list
, &temp
);
1092 sctp_outq_free(&asoc
->outqueue
);
1093 list_splice_init(&temp
, &asoc
->outqueue
.out_chunk_list
);
1095 asoc
->next_tsn
= rtsn
;
1096 asoc
->ctsn_ack_point
= asoc
->next_tsn
- 1;
1097 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
1099 for (i
= 0; i
< stream
->outcnt
; i
++) {
1100 SCTP_SO(stream
, i
)->mid
= 0;
1101 SCTP_SO(stream
, i
)->mid_uo
= 0;
1103 for (i
= 0; i
< stream
->incnt
; i
++)
1104 SCTP_SI(stream
, i
)->mid
= 0;
1107 for (i
= 0; i
< stream
->outcnt
; i
++)
1108 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_OPEN
;
1110 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, flags
,
1111 stsn
, rtsn
, GFP_ATOMIC
);
1112 } else if (req
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
) {
1113 struct sctp_strreset_addstrm
*addstrm
;
1116 addstrm
= (struct sctp_strreset_addstrm
*)req
;
1117 nums
= ntohs(addstrm
->number_of_streams
);
1118 number
= stream
->outcnt
- nums
;
1120 if (result
== SCTP_STRRESET_PERFORMED
)
1121 for (i
= number
; i
< stream
->outcnt
; i
++)
1122 SCTP_SO(stream
, i
)->state
= SCTP_STREAM_OPEN
;
1124 stream
->outcnt
= number
;
1126 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
1127 0, nums
, GFP_ATOMIC
);
1128 } else if (req
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
) {
1129 struct sctp_strreset_addstrm
*addstrm
;
1131 /* if the result is performed, it's impossible for addstrm in
1134 if (result
== SCTP_STRRESET_PERFORMED
)
1137 addstrm
= (struct sctp_strreset_addstrm
*)req
;
1138 nums
= ntohs(addstrm
->number_of_streams
);
1140 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
1141 nums
, 0, GFP_ATOMIC
);
1144 asoc
->strreset_outstanding
--;
1145 asoc
->strreset_outseq
++;
1147 /* remove everything for this reconf request */
1148 if (!asoc
->strreset_outstanding
) {
1149 t
= asoc
->strreset_chunk
->transport
;
1150 if (del_timer(&t
->reconf_timer
))
1151 sctp_transport_put(t
);
1153 sctp_chunk_put(asoc
->strreset_chunk
);
1154 asoc
->strreset_chunk
= NULL
;