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 <net/sctp/sctp.h>
36 #include <net/sctp/sm.h>
38 int sctp_stream_init(struct sctp_stream
*stream
, __u16 outcnt
, __u16 incnt
,
43 /* Initial stream->out size may be very big, so free it and alloc
44 * a new one with new outcnt to save memory.
48 stream
->out
= kcalloc(outcnt
, sizeof(*stream
->out
), gfp
);
52 stream
->outcnt
= outcnt
;
53 for (i
= 0; i
< stream
->outcnt
; i
++)
54 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
59 stream
->in
= kcalloc(incnt
, sizeof(*stream
->in
), gfp
);
66 stream
->incnt
= incnt
;
71 void sctp_stream_free(struct sctp_stream
*stream
)
77 void sctp_stream_clear(struct sctp_stream
*stream
)
81 for (i
= 0; i
< stream
->outcnt
; i
++)
82 stream
->out
[i
].ssn
= 0;
84 for (i
= 0; i
< stream
->incnt
; i
++)
85 stream
->in
[i
].ssn
= 0;
88 void sctp_stream_update(struct sctp_stream
*stream
, struct sctp_stream
*new)
90 sctp_stream_free(stream
);
92 stream
->out
= new->out
;
94 stream
->outcnt
= new->outcnt
;
95 stream
->incnt
= new->incnt
;
101 static int sctp_send_reconf(struct sctp_association
*asoc
,
102 struct sctp_chunk
*chunk
)
104 struct net
*net
= sock_net(asoc
->base
.sk
);
107 retval
= sctp_primitive_RECONF(net
, asoc
, chunk
);
109 sctp_chunk_free(chunk
);
114 int sctp_send_reset_streams(struct sctp_association
*asoc
,
115 struct sctp_reset_streams
*params
)
117 struct sctp_stream
*stream
= &asoc
->stream
;
118 __u16 i
, str_nums
, *str_list
;
119 struct sctp_chunk
*chunk
;
120 int retval
= -EINVAL
;
124 if (!asoc
->peer
.reconf_capable
||
125 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
)) {
126 retval
= -ENOPROTOOPT
;
130 if (asoc
->strreset_outstanding
) {
131 retval
= -EINPROGRESS
;
135 out
= params
->srs_flags
& SCTP_STREAM_RESET_OUTGOING
;
136 in
= params
->srs_flags
& SCTP_STREAM_RESET_INCOMING
;
140 str_nums
= params
->srs_number_streams
;
141 str_list
= params
->srs_stream_list
;
143 for (i
= 0; i
< str_nums
; i
++)
144 if (str_list
[i
] >= stream
->outcnt
)
148 for (i
= 0; i
< str_nums
; i
++)
149 if (str_list
[i
] >= stream
->incnt
)
152 nstr_list
= kcalloc(str_nums
, sizeof(__be16
), GFP_KERNEL
);
158 for (i
= 0; i
< str_nums
; i
++)
159 nstr_list
[i
] = htons(str_list
[i
]);
161 chunk
= sctp_make_strreset_req(asoc
, str_nums
, nstr_list
, out
, in
);
172 for (i
= 0; i
< str_nums
; i
++)
173 stream
->out
[str_list
[i
]].state
=
176 for (i
= 0; i
< stream
->outcnt
; i
++)
177 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
180 asoc
->strreset_chunk
= chunk
;
181 sctp_chunk_hold(asoc
->strreset_chunk
);
183 retval
= sctp_send_reconf(asoc
, chunk
);
185 sctp_chunk_put(asoc
->strreset_chunk
);
186 asoc
->strreset_chunk
= NULL
;
191 for (i
= 0; i
< str_nums
; i
++)
192 stream
->out
[str_list
[i
]].state
=
195 for (i
= 0; i
< stream
->outcnt
; i
++)
196 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
201 asoc
->strreset_outstanding
= out
+ in
;
207 int sctp_send_reset_assoc(struct sctp_association
*asoc
)
209 struct sctp_stream
*stream
= &asoc
->stream
;
210 struct sctp_chunk
*chunk
= NULL
;
214 if (!asoc
->peer
.reconf_capable
||
215 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
218 if (asoc
->strreset_outstanding
)
221 chunk
= sctp_make_strreset_tsnreq(asoc
);
225 /* Block further xmit of data until this request is completed */
226 for (i
= 0; i
< stream
->outcnt
; i
++)
227 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
229 asoc
->strreset_chunk
= chunk
;
230 sctp_chunk_hold(asoc
->strreset_chunk
);
232 retval
= sctp_send_reconf(asoc
, chunk
);
234 sctp_chunk_put(asoc
->strreset_chunk
);
235 asoc
->strreset_chunk
= NULL
;
237 for (i
= 0; i
< stream
->outcnt
; i
++)
238 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
243 asoc
->strreset_outstanding
= 1;
248 int sctp_send_add_streams(struct sctp_association
*asoc
,
249 struct sctp_add_streams
*params
)
251 struct sctp_stream
*stream
= &asoc
->stream
;
252 struct sctp_chunk
*chunk
= NULL
;
253 int retval
= -ENOMEM
;
257 if (!asoc
->peer
.reconf_capable
||
258 !(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
)) {
259 retval
= -ENOPROTOOPT
;
263 if (asoc
->strreset_outstanding
) {
264 retval
= -EINPROGRESS
;
268 out
= params
->sas_outstrms
;
269 in
= params
->sas_instrms
;
270 outcnt
= stream
->outcnt
+ out
;
271 incnt
= stream
->incnt
+ in
;
272 if (outcnt
> SCTP_MAX_STREAM
|| incnt
> SCTP_MAX_STREAM
||
279 struct sctp_stream_out
*streamout
;
281 streamout
= krealloc(stream
->out
, outcnt
* sizeof(*streamout
),
286 memset(streamout
+ stream
->outcnt
, 0, out
* sizeof(*streamout
));
287 stream
->out
= streamout
;
290 chunk
= sctp_make_strreset_addstrm(asoc
, out
, in
);
294 asoc
->strreset_chunk
= chunk
;
295 sctp_chunk_hold(asoc
->strreset_chunk
);
297 retval
= sctp_send_reconf(asoc
, chunk
);
299 sctp_chunk_put(asoc
->strreset_chunk
);
300 asoc
->strreset_chunk
= NULL
;
304 stream
->incnt
= incnt
;
305 stream
->outcnt
= outcnt
;
307 asoc
->strreset_outstanding
= !!out
+ !!in
;
313 static struct sctp_paramhdr
*sctp_chunk_lookup_strreset_param(
314 struct sctp_association
*asoc
, __be32 resp_seq
,
317 struct sctp_chunk
*chunk
= asoc
->strreset_chunk
;
318 struct sctp_reconf_chunk
*hdr
;
319 union sctp_params param
;
324 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
325 sctp_walk_params(param
, hdr
, params
) {
326 /* sctp_strreset_tsnreq is actually the basic structure
327 * of all stream reconf params, so it's safe to use it
328 * to access request_seq.
330 struct sctp_strreset_tsnreq
*req
= param
.v
;
332 if ((!resp_seq
|| req
->request_seq
== resp_seq
) &&
333 (!type
|| type
== req
->param_hdr
.type
))
340 static void sctp_update_strreset_result(struct sctp_association
*asoc
,
343 asoc
->strreset_result
[1] = asoc
->strreset_result
[0];
344 asoc
->strreset_result
[0] = result
;
347 struct sctp_chunk
*sctp_process_strreset_outreq(
348 struct sctp_association
*asoc
,
349 union sctp_params param
,
350 struct sctp_ulpevent
**evp
)
352 struct sctp_strreset_outreq
*outreq
= param
.v
;
353 struct sctp_stream
*stream
= &asoc
->stream
;
354 __u32 result
= SCTP_STRRESET_DENIED
;
355 __u16 i
, nums
, flags
= 0;
356 __be16
*str_p
= NULL
;
359 request_seq
= ntohl(outreq
->request_seq
);
361 if (ntohl(outreq
->send_reset_at_tsn
) >
362 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
)) {
363 result
= SCTP_STRRESET_IN_PROGRESS
;
367 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
368 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
369 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
371 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
372 i
= asoc
->strreset_inseq
- request_seq
- 1;
373 result
= asoc
->strreset_result
[i
];
376 asoc
->strreset_inseq
++;
378 /* Check strreset_enable after inseq inc, as sender cannot tell
379 * the peer doesn't enable strreset after receiving response with
380 * result denied, as well as to keep consistent with bsd.
382 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
385 if (asoc
->strreset_chunk
) {
386 if (!sctp_chunk_lookup_strreset_param(
387 asoc
, outreq
->response_seq
,
388 SCTP_PARAM_RESET_IN_REQUEST
)) {
389 /* same process with outstanding isn't 0 */
390 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
394 asoc
->strreset_outstanding
--;
395 asoc
->strreset_outseq
++;
397 if (!asoc
->strreset_outstanding
) {
398 struct sctp_transport
*t
;
400 t
= asoc
->strreset_chunk
->transport
;
401 if (del_timer(&t
->reconf_timer
))
402 sctp_transport_put(t
);
404 sctp_chunk_put(asoc
->strreset_chunk
);
405 asoc
->strreset_chunk
= NULL
;
408 flags
= SCTP_STREAM_RESET_INCOMING_SSN
;
411 nums
= (ntohs(param
.p
->length
) - sizeof(*outreq
)) / 2;
413 str_p
= outreq
->list_of_streams
;
414 for (i
= 0; i
< nums
; i
++) {
415 if (ntohs(str_p
[i
]) >= stream
->incnt
) {
416 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
421 for (i
= 0; i
< nums
; i
++)
422 stream
->in
[ntohs(str_p
[i
])].ssn
= 0;
424 for (i
= 0; i
< stream
->incnt
; i
++)
425 stream
->in
[i
].ssn
= 0;
428 result
= SCTP_STRRESET_PERFORMED
;
430 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
431 flags
| SCTP_STREAM_RESET_OUTGOING_SSN
, nums
, str_p
,
435 sctp_update_strreset_result(asoc
, result
);
437 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
440 struct sctp_chunk
*sctp_process_strreset_inreq(
441 struct sctp_association
*asoc
,
442 union sctp_params param
,
443 struct sctp_ulpevent
**evp
)
445 struct sctp_strreset_inreq
*inreq
= param
.v
;
446 struct sctp_stream
*stream
= &asoc
->stream
;
447 __u32 result
= SCTP_STRRESET_DENIED
;
448 struct sctp_chunk
*chunk
= NULL
;
453 request_seq
= ntohl(inreq
->request_seq
);
454 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
455 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
456 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
458 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
459 i
= asoc
->strreset_inseq
- request_seq
- 1;
460 result
= asoc
->strreset_result
[i
];
461 if (result
== SCTP_STRRESET_PERFORMED
)
465 asoc
->strreset_inseq
++;
467 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
470 if (asoc
->strreset_outstanding
) {
471 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
475 nums
= (ntohs(param
.p
->length
) - sizeof(*inreq
)) / 2;
476 str_p
= inreq
->list_of_streams
;
477 for (i
= 0; i
< nums
; i
++) {
478 if (ntohs(str_p
[i
]) >= stream
->outcnt
) {
479 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
484 chunk
= sctp_make_strreset_req(asoc
, nums
, str_p
, 1, 0);
489 for (i
= 0; i
< nums
; i
++)
490 stream
->out
[ntohs(str_p
[i
])].state
=
493 for (i
= 0; i
< stream
->outcnt
; i
++)
494 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
496 asoc
->strreset_chunk
= chunk
;
497 asoc
->strreset_outstanding
= 1;
498 sctp_chunk_hold(asoc
->strreset_chunk
);
500 result
= SCTP_STRRESET_PERFORMED
;
502 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
503 SCTP_STREAM_RESET_INCOMING_SSN
, nums
, str_p
, GFP_ATOMIC
);
506 sctp_update_strreset_result(asoc
, result
);
509 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
514 struct sctp_chunk
*sctp_process_strreset_tsnreq(
515 struct sctp_association
*asoc
,
516 union sctp_params param
,
517 struct sctp_ulpevent
**evp
)
519 __u32 init_tsn
= 0, next_tsn
= 0, max_tsn_seen
;
520 struct sctp_strreset_tsnreq
*tsnreq
= param
.v
;
521 struct sctp_stream
*stream
= &asoc
->stream
;
522 __u32 result
= SCTP_STRRESET_DENIED
;
526 request_seq
= ntohl(tsnreq
->request_seq
);
527 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
528 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
529 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
531 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
532 i
= asoc
->strreset_inseq
- request_seq
- 1;
533 result
= asoc
->strreset_result
[i
];
534 if (result
== SCTP_STRRESET_PERFORMED
) {
535 next_tsn
= asoc
->next_tsn
;
537 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + 1;
541 asoc
->strreset_inseq
++;
543 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
546 if (asoc
->strreset_outstanding
) {
547 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
551 /* G3: The same processing as though a SACK chunk with no gap report
552 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
553 * received MUST be performed.
555 max_tsn_seen
= sctp_tsnmap_get_max_tsn_seen(&asoc
->peer
.tsn_map
);
556 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, max_tsn_seen
);
557 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
559 /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
560 * TSN that the peer should use to send the next DATA chunk. The
561 * value SHOULD be the smallest TSN not acknowledged by the
562 * receiver of the request plus 2^31.
564 init_tsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + (1 << 31);
565 sctp_tsnmap_init(&asoc
->peer
.tsn_map
, SCTP_TSN_MAP_INITIAL
,
566 init_tsn
, GFP_ATOMIC
);
568 /* G4: The same processing as though a FWD-TSN chunk (as defined in
569 * [RFC3758]) with all streams affected and a new cumulative TSN
570 * ACK of the Receiver's Next TSN minus 1 were received MUST be
573 sctp_outq_free(&asoc
->outqueue
);
575 /* G2: Compute an appropriate value for the local endpoint's next TSN,
576 * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
577 * chunk. The value SHOULD be the highest TSN sent by the receiver
578 * of the request plus 1.
580 next_tsn
= asoc
->next_tsn
;
581 asoc
->ctsn_ack_point
= next_tsn
- 1;
582 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
584 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
585 * incoming and outgoing streams.
587 for (i
= 0; i
< stream
->outcnt
; i
++)
588 stream
->out
[i
].ssn
= 0;
589 for (i
= 0; i
< stream
->incnt
; i
++)
590 stream
->in
[i
].ssn
= 0;
592 result
= SCTP_STRRESET_PERFORMED
;
594 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, 0, init_tsn
,
595 next_tsn
, GFP_ATOMIC
);
598 sctp_update_strreset_result(asoc
, result
);
600 return sctp_make_strreset_tsnresp(asoc
, result
, request_seq
,
604 struct sctp_chunk
*sctp_process_strreset_addstrm_out(
605 struct sctp_association
*asoc
,
606 union sctp_params param
,
607 struct sctp_ulpevent
**evp
)
609 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
610 struct sctp_stream
*stream
= &asoc
->stream
;
611 __u32 result
= SCTP_STRRESET_DENIED
;
612 struct sctp_stream_in
*streamin
;
613 __u32 request_seq
, incnt
;
616 request_seq
= ntohl(addstrm
->request_seq
);
617 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
618 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
619 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
621 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
622 i
= asoc
->strreset_inseq
- request_seq
- 1;
623 result
= asoc
->strreset_result
[i
];
626 asoc
->strreset_inseq
++;
628 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
631 if (asoc
->strreset_chunk
) {
632 if (!sctp_chunk_lookup_strreset_param(
633 asoc
, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS
)) {
634 /* same process with outstanding isn't 0 */
635 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
639 asoc
->strreset_outstanding
--;
640 asoc
->strreset_outseq
++;
642 if (!asoc
->strreset_outstanding
) {
643 struct sctp_transport
*t
;
645 t
= asoc
->strreset_chunk
->transport
;
646 if (del_timer(&t
->reconf_timer
))
647 sctp_transport_put(t
);
649 sctp_chunk_put(asoc
->strreset_chunk
);
650 asoc
->strreset_chunk
= NULL
;
654 in
= ntohs(addstrm
->number_of_streams
);
655 incnt
= stream
->incnt
+ in
;
656 if (!in
|| incnt
> SCTP_MAX_STREAM
)
659 streamin
= krealloc(stream
->in
, incnt
* sizeof(*streamin
),
664 memset(streamin
+ stream
->incnt
, 0, in
* sizeof(*streamin
));
665 stream
->in
= streamin
;
666 stream
->incnt
= incnt
;
668 result
= SCTP_STRRESET_PERFORMED
;
670 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
671 0, ntohs(addstrm
->number_of_streams
), 0, GFP_ATOMIC
);
674 sctp_update_strreset_result(asoc
, result
);
676 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
679 struct sctp_chunk
*sctp_process_strreset_addstrm_in(
680 struct sctp_association
*asoc
,
681 union sctp_params param
,
682 struct sctp_ulpevent
**evp
)
684 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
685 struct sctp_stream
*stream
= &asoc
->stream
;
686 __u32 result
= SCTP_STRRESET_DENIED
;
687 struct sctp_stream_out
*streamout
;
688 struct sctp_chunk
*chunk
= NULL
;
689 __u32 request_seq
, outcnt
;
692 request_seq
= ntohl(addstrm
->request_seq
);
693 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
694 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
695 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
697 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
698 i
= asoc
->strreset_inseq
- request_seq
- 1;
699 result
= asoc
->strreset_result
[i
];
700 if (result
== SCTP_STRRESET_PERFORMED
)
704 asoc
->strreset_inseq
++;
706 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
709 if (asoc
->strreset_outstanding
) {
710 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
714 out
= ntohs(addstrm
->number_of_streams
);
715 outcnt
= stream
->outcnt
+ out
;
716 if (!out
|| outcnt
> SCTP_MAX_STREAM
)
719 streamout
= krealloc(stream
->out
, outcnt
* sizeof(*streamout
),
724 memset(streamout
+ stream
->outcnt
, 0, out
* sizeof(*streamout
));
725 stream
->out
= streamout
;
727 chunk
= sctp_make_strreset_addstrm(asoc
, out
, 0);
731 asoc
->strreset_chunk
= chunk
;
732 asoc
->strreset_outstanding
= 1;
733 sctp_chunk_hold(asoc
->strreset_chunk
);
735 stream
->outcnt
= outcnt
;
737 result
= SCTP_STRRESET_PERFORMED
;
739 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
740 0, 0, ntohs(addstrm
->number_of_streams
), GFP_ATOMIC
);
743 sctp_update_strreset_result(asoc
, result
);
746 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
751 struct sctp_chunk
*sctp_process_strreset_resp(
752 struct sctp_association
*asoc
,
753 union sctp_params param
,
754 struct sctp_ulpevent
**evp
)
756 struct sctp_stream
*stream
= &asoc
->stream
;
757 struct sctp_strreset_resp
*resp
= param
.v
;
758 struct sctp_transport
*t
;
759 __u16 i
, nums
, flags
= 0;
760 struct sctp_paramhdr
*req
;
763 req
= sctp_chunk_lookup_strreset_param(asoc
, resp
->response_seq
, 0);
767 result
= ntohl(resp
->result
);
768 if (result
!= SCTP_STRRESET_PERFORMED
) {
769 /* if in progress, do nothing but retransmit */
770 if (result
== SCTP_STRRESET_IN_PROGRESS
)
772 else if (result
== SCTP_STRRESET_DENIED
)
773 flags
= SCTP_STREAM_RESET_DENIED
;
775 flags
= SCTP_STREAM_RESET_FAILED
;
778 if (req
->type
== SCTP_PARAM_RESET_OUT_REQUEST
) {
779 struct sctp_strreset_outreq
*outreq
;
782 outreq
= (struct sctp_strreset_outreq
*)req
;
783 str_p
= outreq
->list_of_streams
;
784 nums
= (ntohs(outreq
->param_hdr
.length
) - sizeof(*outreq
)) / 2;
786 if (result
== SCTP_STRRESET_PERFORMED
) {
788 for (i
= 0; i
< nums
; i
++)
789 stream
->out
[ntohs(str_p
[i
])].ssn
= 0;
791 for (i
= 0; i
< stream
->outcnt
; i
++)
792 stream
->out
[i
].ssn
= 0;
795 flags
= SCTP_STREAM_RESET_OUTGOING_SSN
;
798 for (i
= 0; i
< stream
->outcnt
; i
++)
799 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
801 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
802 nums
, str_p
, GFP_ATOMIC
);
803 } else if (req
->type
== SCTP_PARAM_RESET_IN_REQUEST
) {
804 struct sctp_strreset_inreq
*inreq
;
807 /* if the result is performed, it's impossible for inreq */
808 if (result
== SCTP_STRRESET_PERFORMED
)
811 inreq
= (struct sctp_strreset_inreq
*)req
;
812 str_p
= inreq
->list_of_streams
;
813 nums
= (ntohs(inreq
->param_hdr
.length
) - sizeof(*inreq
)) / 2;
815 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
816 nums
, str_p
, GFP_ATOMIC
);
817 } else if (req
->type
== SCTP_PARAM_RESET_TSN_REQUEST
) {
818 struct sctp_strreset_resptsn
*resptsn
;
821 /* check for resptsn, as sctp_verify_reconf didn't do it*/
822 if (ntohs(param
.p
->length
) != sizeof(*resptsn
))
825 resptsn
= (struct sctp_strreset_resptsn
*)resp
;
826 stsn
= ntohl(resptsn
->senders_next_tsn
);
827 rtsn
= ntohl(resptsn
->receivers_next_tsn
);
829 if (result
== SCTP_STRRESET_PERFORMED
) {
830 __u32 mtsn
= sctp_tsnmap_get_max_tsn_seen(
831 &asoc
->peer
.tsn_map
);
833 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, mtsn
);
834 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
836 sctp_tsnmap_init(&asoc
->peer
.tsn_map
,
837 SCTP_TSN_MAP_INITIAL
,
840 sctp_outq_free(&asoc
->outqueue
);
842 asoc
->next_tsn
= rtsn
;
843 asoc
->ctsn_ack_point
= asoc
->next_tsn
- 1;
844 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
846 for (i
= 0; i
< stream
->outcnt
; i
++)
847 stream
->out
[i
].ssn
= 0;
848 for (i
= 0; i
< stream
->incnt
; i
++)
849 stream
->in
[i
].ssn
= 0;
852 for (i
= 0; i
< stream
->outcnt
; i
++)
853 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
855 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, flags
,
856 stsn
, rtsn
, GFP_ATOMIC
);
857 } else if (req
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
) {
858 struct sctp_strreset_addstrm
*addstrm
;
861 addstrm
= (struct sctp_strreset_addstrm
*)req
;
862 nums
= ntohs(addstrm
->number_of_streams
);
863 number
= stream
->outcnt
- nums
;
865 if (result
== SCTP_STRRESET_PERFORMED
)
866 for (i
= number
; i
< stream
->outcnt
; i
++)
867 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
869 stream
->outcnt
= number
;
871 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
872 0, nums
, GFP_ATOMIC
);
873 } else if (req
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
) {
874 struct sctp_strreset_addstrm
*addstrm
;
876 /* if the result is performed, it's impossible for addstrm in
879 if (result
== SCTP_STRRESET_PERFORMED
)
882 addstrm
= (struct sctp_strreset_addstrm
*)req
;
883 nums
= ntohs(addstrm
->number_of_streams
);
885 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
886 nums
, 0, GFP_ATOMIC
);
889 asoc
->strreset_outstanding
--;
890 asoc
->strreset_outseq
++;
892 /* remove everything for this reconf request */
893 if (!asoc
->strreset_outstanding
) {
894 t
= asoc
->strreset_chunk
->transport
;
895 if (del_timer(&t
->reconf_timer
))
896 sctp_transport_put(t
);
898 sctp_chunk_put(asoc
->strreset_chunk
);
899 asoc
->strreset_chunk
= NULL
;