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
, 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 int sctp_send_reset_streams(struct sctp_association
*asoc
,
258 struct sctp_reset_streams
*params
)
260 struct sctp_stream
*stream
= &asoc
->stream
;
261 __u16 i
, str_nums
, *str_list
;
262 struct sctp_chunk
*chunk
;
263 int retval
= -EINVAL
;
267 if (!asoc
->peer
.reconf_capable
||
268 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
)) {
269 retval
= -ENOPROTOOPT
;
273 if (asoc
->strreset_outstanding
) {
274 retval
= -EINPROGRESS
;
278 out
= params
->srs_flags
& SCTP_STREAM_RESET_OUTGOING
;
279 in
= params
->srs_flags
& SCTP_STREAM_RESET_INCOMING
;
283 str_nums
= params
->srs_number_streams
;
284 str_list
= params
->srs_stream_list
;
289 for (i
= 0; i
< str_nums
; i
++)
290 if (str_list
[i
] >= stream
->outcnt
)
293 param_len
= str_nums
* sizeof(__u16
) +
294 sizeof(struct sctp_strreset_outreq
);
298 for (i
= 0; i
< str_nums
; i
++)
299 if (str_list
[i
] >= stream
->incnt
)
302 param_len
+= str_nums
* sizeof(__u16
) +
303 sizeof(struct sctp_strreset_inreq
);
306 if (param_len
> SCTP_MAX_CHUNK_LEN
-
307 sizeof(struct sctp_reconf_chunk
))
311 nstr_list
= kcalloc(str_nums
, sizeof(__be16
), GFP_KERNEL
);
317 for (i
= 0; i
< str_nums
; i
++)
318 nstr_list
[i
] = htons(str_list
[i
]);
320 chunk
= sctp_make_strreset_req(asoc
, str_nums
, nstr_list
, out
, in
);
331 for (i
= 0; i
< str_nums
; i
++)
332 stream
->out
[str_list
[i
]].state
=
335 for (i
= 0; i
< stream
->outcnt
; i
++)
336 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
339 asoc
->strreset_chunk
= chunk
;
340 sctp_chunk_hold(asoc
->strreset_chunk
);
342 retval
= sctp_send_reconf(asoc
, chunk
);
344 sctp_chunk_put(asoc
->strreset_chunk
);
345 asoc
->strreset_chunk
= NULL
;
350 for (i
= 0; i
< str_nums
; i
++)
351 stream
->out
[str_list
[i
]].state
=
354 for (i
= 0; i
< stream
->outcnt
; i
++)
355 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
360 asoc
->strreset_outstanding
= out
+ in
;
366 int sctp_send_reset_assoc(struct sctp_association
*asoc
)
368 struct sctp_stream
*stream
= &asoc
->stream
;
369 struct sctp_chunk
*chunk
= NULL
;
373 if (!asoc
->peer
.reconf_capable
||
374 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
377 if (asoc
->strreset_outstanding
)
380 chunk
= sctp_make_strreset_tsnreq(asoc
);
384 /* Block further xmit of data until this request is completed */
385 for (i
= 0; i
< stream
->outcnt
; i
++)
386 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
388 asoc
->strreset_chunk
= chunk
;
389 sctp_chunk_hold(asoc
->strreset_chunk
);
391 retval
= sctp_send_reconf(asoc
, chunk
);
393 sctp_chunk_put(asoc
->strreset_chunk
);
394 asoc
->strreset_chunk
= NULL
;
396 for (i
= 0; i
< stream
->outcnt
; i
++)
397 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
402 asoc
->strreset_outstanding
= 1;
407 int sctp_send_add_streams(struct sctp_association
*asoc
,
408 struct sctp_add_streams
*params
)
410 struct sctp_stream
*stream
= &asoc
->stream
;
411 struct sctp_chunk
*chunk
= NULL
;
416 if (!asoc
->peer
.reconf_capable
||
417 !(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
)) {
418 retval
= -ENOPROTOOPT
;
422 if (asoc
->strreset_outstanding
) {
423 retval
= -EINPROGRESS
;
427 out
= params
->sas_outstrms
;
428 in
= params
->sas_instrms
;
429 outcnt
= stream
->outcnt
+ out
;
430 incnt
= stream
->incnt
+ in
;
431 if (outcnt
> SCTP_MAX_STREAM
|| incnt
> SCTP_MAX_STREAM
||
438 retval
= sctp_stream_alloc_out(stream
, outcnt
, GFP_KERNEL
);
443 chunk
= sctp_make_strreset_addstrm(asoc
, out
, in
);
449 asoc
->strreset_chunk
= chunk
;
450 sctp_chunk_hold(asoc
->strreset_chunk
);
452 retval
= sctp_send_reconf(asoc
, chunk
);
454 sctp_chunk_put(asoc
->strreset_chunk
);
455 asoc
->strreset_chunk
= NULL
;
459 stream
->incnt
= incnt
;
460 stream
->outcnt
= outcnt
;
462 asoc
->strreset_outstanding
= !!out
+ !!in
;
468 static struct sctp_paramhdr
*sctp_chunk_lookup_strreset_param(
469 struct sctp_association
*asoc
, __be32 resp_seq
,
472 struct sctp_chunk
*chunk
= asoc
->strreset_chunk
;
473 struct sctp_reconf_chunk
*hdr
;
474 union sctp_params param
;
479 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
480 sctp_walk_params(param
, hdr
, params
) {
481 /* sctp_strreset_tsnreq is actually the basic structure
482 * of all stream reconf params, so it's safe to use it
483 * to access request_seq.
485 struct sctp_strreset_tsnreq
*req
= param
.v
;
487 if ((!resp_seq
|| req
->request_seq
== resp_seq
) &&
488 (!type
|| type
== req
->param_hdr
.type
))
495 static void sctp_update_strreset_result(struct sctp_association
*asoc
,
498 asoc
->strreset_result
[1] = asoc
->strreset_result
[0];
499 asoc
->strreset_result
[0] = result
;
502 struct sctp_chunk
*sctp_process_strreset_outreq(
503 struct sctp_association
*asoc
,
504 union sctp_params param
,
505 struct sctp_ulpevent
**evp
)
507 struct sctp_strreset_outreq
*outreq
= param
.v
;
508 struct sctp_stream
*stream
= &asoc
->stream
;
509 __u32 result
= SCTP_STRRESET_DENIED
;
510 __u16 i
, nums
, flags
= 0;
511 __be16
*str_p
= NULL
;
514 request_seq
= ntohl(outreq
->request_seq
);
516 if (ntohl(outreq
->send_reset_at_tsn
) >
517 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
)) {
518 result
= SCTP_STRRESET_IN_PROGRESS
;
522 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
523 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
524 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
526 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
527 i
= asoc
->strreset_inseq
- request_seq
- 1;
528 result
= asoc
->strreset_result
[i
];
531 asoc
->strreset_inseq
++;
533 /* Check strreset_enable after inseq inc, as sender cannot tell
534 * the peer doesn't enable strreset after receiving response with
535 * result denied, as well as to keep consistent with bsd.
537 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
540 if (asoc
->strreset_chunk
) {
541 if (!sctp_chunk_lookup_strreset_param(
542 asoc
, outreq
->response_seq
,
543 SCTP_PARAM_RESET_IN_REQUEST
)) {
544 /* same process with outstanding isn't 0 */
545 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
549 asoc
->strreset_outstanding
--;
550 asoc
->strreset_outseq
++;
552 if (!asoc
->strreset_outstanding
) {
553 struct sctp_transport
*t
;
555 t
= asoc
->strreset_chunk
->transport
;
556 if (del_timer(&t
->reconf_timer
))
557 sctp_transport_put(t
);
559 sctp_chunk_put(asoc
->strreset_chunk
);
560 asoc
->strreset_chunk
= NULL
;
563 flags
= SCTP_STREAM_RESET_INCOMING_SSN
;
566 nums
= (ntohs(param
.p
->length
) - sizeof(*outreq
)) / 2;
568 str_p
= outreq
->list_of_streams
;
569 for (i
= 0; i
< nums
; i
++) {
570 if (ntohs(str_p
[i
]) >= stream
->incnt
) {
571 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
576 for (i
= 0; i
< nums
; i
++)
577 stream
->in
[ntohs(str_p
[i
])].ssn
= 0;
579 for (i
= 0; i
< stream
->incnt
; i
++)
580 stream
->in
[i
].ssn
= 0;
583 result
= SCTP_STRRESET_PERFORMED
;
585 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
586 flags
| SCTP_STREAM_RESET_OUTGOING_SSN
, nums
, str_p
,
590 sctp_update_strreset_result(asoc
, result
);
592 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
595 struct sctp_chunk
*sctp_process_strreset_inreq(
596 struct sctp_association
*asoc
,
597 union sctp_params param
,
598 struct sctp_ulpevent
**evp
)
600 struct sctp_strreset_inreq
*inreq
= param
.v
;
601 struct sctp_stream
*stream
= &asoc
->stream
;
602 __u32 result
= SCTP_STRRESET_DENIED
;
603 struct sctp_chunk
*chunk
= NULL
;
608 request_seq
= ntohl(inreq
->request_seq
);
609 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
610 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
611 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
613 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
614 i
= asoc
->strreset_inseq
- request_seq
- 1;
615 result
= asoc
->strreset_result
[i
];
616 if (result
== SCTP_STRRESET_PERFORMED
)
620 asoc
->strreset_inseq
++;
622 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
625 if (asoc
->strreset_outstanding
) {
626 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
630 nums
= (ntohs(param
.p
->length
) - sizeof(*inreq
)) / 2;
631 str_p
= inreq
->list_of_streams
;
632 for (i
= 0; i
< nums
; i
++) {
633 if (ntohs(str_p
[i
]) >= stream
->outcnt
) {
634 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
639 chunk
= sctp_make_strreset_req(asoc
, nums
, str_p
, 1, 0);
644 for (i
= 0; i
< nums
; i
++)
645 stream
->out
[ntohs(str_p
[i
])].state
=
648 for (i
= 0; i
< stream
->outcnt
; i
++)
649 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
651 asoc
->strreset_chunk
= chunk
;
652 asoc
->strreset_outstanding
= 1;
653 sctp_chunk_hold(asoc
->strreset_chunk
);
655 result
= SCTP_STRRESET_PERFORMED
;
657 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
658 SCTP_STREAM_RESET_INCOMING_SSN
, nums
, str_p
, GFP_ATOMIC
);
661 sctp_update_strreset_result(asoc
, result
);
664 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
669 struct sctp_chunk
*sctp_process_strreset_tsnreq(
670 struct sctp_association
*asoc
,
671 union sctp_params param
,
672 struct sctp_ulpevent
**evp
)
674 __u32 init_tsn
= 0, next_tsn
= 0, max_tsn_seen
;
675 struct sctp_strreset_tsnreq
*tsnreq
= param
.v
;
676 struct sctp_stream
*stream
= &asoc
->stream
;
677 __u32 result
= SCTP_STRRESET_DENIED
;
681 request_seq
= ntohl(tsnreq
->request_seq
);
682 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
683 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
684 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
686 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
687 i
= asoc
->strreset_inseq
- request_seq
- 1;
688 result
= asoc
->strreset_result
[i
];
689 if (result
== SCTP_STRRESET_PERFORMED
) {
690 next_tsn
= asoc
->next_tsn
;
692 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + 1;
696 asoc
->strreset_inseq
++;
698 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
701 if (asoc
->strreset_outstanding
) {
702 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
706 /* G3: The same processing as though a SACK chunk with no gap report
707 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
708 * received MUST be performed.
710 max_tsn_seen
= sctp_tsnmap_get_max_tsn_seen(&asoc
->peer
.tsn_map
);
711 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, max_tsn_seen
);
712 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
714 /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
715 * TSN that the peer should use to send the next DATA chunk. The
716 * value SHOULD be the smallest TSN not acknowledged by the
717 * receiver of the request plus 2^31.
719 init_tsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + (1 << 31);
720 sctp_tsnmap_init(&asoc
->peer
.tsn_map
, SCTP_TSN_MAP_INITIAL
,
721 init_tsn
, GFP_ATOMIC
);
723 /* G4: The same processing as though a FWD-TSN chunk (as defined in
724 * [RFC3758]) with all streams affected and a new cumulative TSN
725 * ACK of the Receiver's Next TSN minus 1 were received MUST be
728 sctp_outq_free(&asoc
->outqueue
);
730 /* G2: Compute an appropriate value for the local endpoint's next TSN,
731 * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
732 * chunk. The value SHOULD be the highest TSN sent by the receiver
733 * of the request plus 1.
735 next_tsn
= asoc
->next_tsn
;
736 asoc
->ctsn_ack_point
= next_tsn
- 1;
737 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
739 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
740 * incoming and outgoing streams.
742 for (i
= 0; i
< stream
->outcnt
; i
++)
743 stream
->out
[i
].ssn
= 0;
744 for (i
= 0; i
< stream
->incnt
; i
++)
745 stream
->in
[i
].ssn
= 0;
747 result
= SCTP_STRRESET_PERFORMED
;
749 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, 0, init_tsn
,
750 next_tsn
, GFP_ATOMIC
);
753 sctp_update_strreset_result(asoc
, result
);
755 return sctp_make_strreset_tsnresp(asoc
, result
, request_seq
,
759 struct sctp_chunk
*sctp_process_strreset_addstrm_out(
760 struct sctp_association
*asoc
,
761 union sctp_params param
,
762 struct sctp_ulpevent
**evp
)
764 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
765 struct sctp_stream
*stream
= &asoc
->stream
;
766 __u32 result
= SCTP_STRRESET_DENIED
;
767 __u32 request_seq
, incnt
;
770 request_seq
= ntohl(addstrm
->request_seq
);
771 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
772 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
773 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
775 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
776 i
= asoc
->strreset_inseq
- request_seq
- 1;
777 result
= asoc
->strreset_result
[i
];
780 asoc
->strreset_inseq
++;
782 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
785 if (asoc
->strreset_chunk
) {
786 if (!sctp_chunk_lookup_strreset_param(
787 asoc
, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS
)) {
788 /* same process with outstanding isn't 0 */
789 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
793 asoc
->strreset_outstanding
--;
794 asoc
->strreset_outseq
++;
796 if (!asoc
->strreset_outstanding
) {
797 struct sctp_transport
*t
;
799 t
= asoc
->strreset_chunk
->transport
;
800 if (del_timer(&t
->reconf_timer
))
801 sctp_transport_put(t
);
803 sctp_chunk_put(asoc
->strreset_chunk
);
804 asoc
->strreset_chunk
= NULL
;
808 in
= ntohs(addstrm
->number_of_streams
);
809 incnt
= stream
->incnt
+ in
;
810 if (!in
|| incnt
> SCTP_MAX_STREAM
)
813 if (sctp_stream_alloc_in(stream
, incnt
, GFP_ATOMIC
))
816 stream
->incnt
= incnt
;
818 result
= SCTP_STRRESET_PERFORMED
;
820 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
821 0, ntohs(addstrm
->number_of_streams
), 0, GFP_ATOMIC
);
824 sctp_update_strreset_result(asoc
, result
);
826 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
829 struct sctp_chunk
*sctp_process_strreset_addstrm_in(
830 struct sctp_association
*asoc
,
831 union sctp_params param
,
832 struct sctp_ulpevent
**evp
)
834 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
835 struct sctp_stream
*stream
= &asoc
->stream
;
836 __u32 result
= SCTP_STRRESET_DENIED
;
837 struct sctp_chunk
*chunk
= NULL
;
838 __u32 request_seq
, outcnt
;
842 request_seq
= ntohl(addstrm
->request_seq
);
843 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
844 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
845 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
847 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
848 i
= asoc
->strreset_inseq
- request_seq
- 1;
849 result
= asoc
->strreset_result
[i
];
850 if (result
== SCTP_STRRESET_PERFORMED
)
854 asoc
->strreset_inseq
++;
856 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
859 if (asoc
->strreset_outstanding
) {
860 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
864 out
= ntohs(addstrm
->number_of_streams
);
865 outcnt
= stream
->outcnt
+ out
;
866 if (!out
|| outcnt
> SCTP_MAX_STREAM
)
869 ret
= sctp_stream_alloc_out(stream
, outcnt
, GFP_ATOMIC
);
873 chunk
= sctp_make_strreset_addstrm(asoc
, out
, 0);
877 asoc
->strreset_chunk
= chunk
;
878 asoc
->strreset_outstanding
= 1;
879 sctp_chunk_hold(asoc
->strreset_chunk
);
881 stream
->outcnt
= outcnt
;
883 result
= SCTP_STRRESET_PERFORMED
;
885 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
886 0, 0, ntohs(addstrm
->number_of_streams
), GFP_ATOMIC
);
889 sctp_update_strreset_result(asoc
, result
);
892 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
897 struct sctp_chunk
*sctp_process_strreset_resp(
898 struct sctp_association
*asoc
,
899 union sctp_params param
,
900 struct sctp_ulpevent
**evp
)
902 struct sctp_stream
*stream
= &asoc
->stream
;
903 struct sctp_strreset_resp
*resp
= param
.v
;
904 struct sctp_transport
*t
;
905 __u16 i
, nums
, flags
= 0;
906 struct sctp_paramhdr
*req
;
909 req
= sctp_chunk_lookup_strreset_param(asoc
, resp
->response_seq
, 0);
913 result
= ntohl(resp
->result
);
914 if (result
!= SCTP_STRRESET_PERFORMED
) {
915 /* if in progress, do nothing but retransmit */
916 if (result
== SCTP_STRRESET_IN_PROGRESS
)
918 else if (result
== SCTP_STRRESET_DENIED
)
919 flags
= SCTP_STREAM_RESET_DENIED
;
921 flags
= SCTP_STREAM_RESET_FAILED
;
924 if (req
->type
== SCTP_PARAM_RESET_OUT_REQUEST
) {
925 struct sctp_strreset_outreq
*outreq
;
928 outreq
= (struct sctp_strreset_outreq
*)req
;
929 str_p
= outreq
->list_of_streams
;
930 nums
= (ntohs(outreq
->param_hdr
.length
) - sizeof(*outreq
)) / 2;
932 if (result
== SCTP_STRRESET_PERFORMED
) {
934 for (i
= 0; i
< nums
; i
++)
935 stream
->out
[ntohs(str_p
[i
])].ssn
= 0;
937 for (i
= 0; i
< stream
->outcnt
; i
++)
938 stream
->out
[i
].ssn
= 0;
941 flags
= SCTP_STREAM_RESET_OUTGOING_SSN
;
944 for (i
= 0; i
< stream
->outcnt
; i
++)
945 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
947 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
948 nums
, str_p
, GFP_ATOMIC
);
949 } else if (req
->type
== SCTP_PARAM_RESET_IN_REQUEST
) {
950 struct sctp_strreset_inreq
*inreq
;
953 /* if the result is performed, it's impossible for inreq */
954 if (result
== SCTP_STRRESET_PERFORMED
)
957 inreq
= (struct sctp_strreset_inreq
*)req
;
958 str_p
= inreq
->list_of_streams
;
959 nums
= (ntohs(inreq
->param_hdr
.length
) - sizeof(*inreq
)) / 2;
961 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
962 nums
, str_p
, GFP_ATOMIC
);
963 } else if (req
->type
== SCTP_PARAM_RESET_TSN_REQUEST
) {
964 struct sctp_strreset_resptsn
*resptsn
;
967 /* check for resptsn, as sctp_verify_reconf didn't do it*/
968 if (ntohs(param
.p
->length
) != sizeof(*resptsn
))
971 resptsn
= (struct sctp_strreset_resptsn
*)resp
;
972 stsn
= ntohl(resptsn
->senders_next_tsn
);
973 rtsn
= ntohl(resptsn
->receivers_next_tsn
);
975 if (result
== SCTP_STRRESET_PERFORMED
) {
976 __u32 mtsn
= sctp_tsnmap_get_max_tsn_seen(
977 &asoc
->peer
.tsn_map
);
979 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, mtsn
);
980 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
982 sctp_tsnmap_init(&asoc
->peer
.tsn_map
,
983 SCTP_TSN_MAP_INITIAL
,
986 sctp_outq_free(&asoc
->outqueue
);
988 asoc
->next_tsn
= rtsn
;
989 asoc
->ctsn_ack_point
= asoc
->next_tsn
- 1;
990 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
992 for (i
= 0; i
< stream
->outcnt
; i
++)
993 stream
->out
[i
].ssn
= 0;
994 for (i
= 0; i
< stream
->incnt
; i
++)
995 stream
->in
[i
].ssn
= 0;
998 for (i
= 0; i
< stream
->outcnt
; i
++)
999 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
1001 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, flags
,
1002 stsn
, rtsn
, GFP_ATOMIC
);
1003 } else if (req
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
) {
1004 struct sctp_strreset_addstrm
*addstrm
;
1007 addstrm
= (struct sctp_strreset_addstrm
*)req
;
1008 nums
= ntohs(addstrm
->number_of_streams
);
1009 number
= stream
->outcnt
- nums
;
1011 if (result
== SCTP_STRRESET_PERFORMED
)
1012 for (i
= number
; i
< stream
->outcnt
; i
++)
1013 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
1015 stream
->outcnt
= number
;
1017 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
1018 0, nums
, GFP_ATOMIC
);
1019 } else if (req
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
) {
1020 struct sctp_strreset_addstrm
*addstrm
;
1022 /* if the result is performed, it's impossible for addstrm in
1025 if (result
== SCTP_STRRESET_PERFORMED
)
1028 addstrm
= (struct sctp_strreset_addstrm
*)req
;
1029 nums
= ntohs(addstrm
->number_of_streams
);
1031 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
1032 nums
, 0, GFP_ATOMIC
);
1035 asoc
->strreset_outstanding
--;
1036 asoc
->strreset_outseq
++;
1038 /* remove everything for this reconf request */
1039 if (!asoc
->strreset_outstanding
) {
1040 t
= asoc
->strreset_chunk
->transport
;
1041 if (del_timer(&t
->reconf_timer
))
1042 sctp_transport_put(t
);
1044 sctp_chunk_put(asoc
->strreset_chunk
);
1045 asoc
->strreset_chunk
= NULL
;