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
,
45 /* Initial stream->out size may be very big, so free it and alloc
46 * a new one with new outcnt to save memory if needed.
48 if (outcnt
== stream
->outcnt
)
53 stream
->out
= kcalloc(outcnt
, sizeof(*stream
->out
), gfp
);
57 stream
->outcnt
= outcnt
;
58 for (i
= 0; i
< stream
->outcnt
; i
++)
59 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
65 stream
->in
= kcalloc(incnt
, sizeof(*stream
->in
), gfp
);
72 stream
->incnt
= incnt
;
77 void sctp_stream_free(struct sctp_stream
*stream
)
83 void sctp_stream_clear(struct sctp_stream
*stream
)
87 for (i
= 0; i
< stream
->outcnt
; i
++)
88 stream
->out
[i
].ssn
= 0;
90 for (i
= 0; i
< stream
->incnt
; i
++)
91 stream
->in
[i
].ssn
= 0;
94 void sctp_stream_update(struct sctp_stream
*stream
, struct sctp_stream
*new)
96 sctp_stream_free(stream
);
98 stream
->out
= new->out
;
100 stream
->outcnt
= new->outcnt
;
101 stream
->incnt
= new->incnt
;
107 static int sctp_send_reconf(struct sctp_association
*asoc
,
108 struct sctp_chunk
*chunk
)
110 struct net
*net
= sock_net(asoc
->base
.sk
);
113 retval
= sctp_primitive_RECONF(net
, asoc
, chunk
);
115 sctp_chunk_free(chunk
);
120 int sctp_send_reset_streams(struct sctp_association
*asoc
,
121 struct sctp_reset_streams
*params
)
123 struct sctp_stream
*stream
= &asoc
->stream
;
124 __u16 i
, str_nums
, *str_list
;
125 struct sctp_chunk
*chunk
;
126 int retval
= -EINVAL
;
130 if (!asoc
->peer
.reconf_capable
||
131 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
)) {
132 retval
= -ENOPROTOOPT
;
136 if (asoc
->strreset_outstanding
) {
137 retval
= -EINPROGRESS
;
141 out
= params
->srs_flags
& SCTP_STREAM_RESET_OUTGOING
;
142 in
= params
->srs_flags
& SCTP_STREAM_RESET_INCOMING
;
146 str_nums
= params
->srs_number_streams
;
147 str_list
= params
->srs_stream_list
;
149 for (i
= 0; i
< str_nums
; i
++)
150 if (str_list
[i
] >= stream
->outcnt
)
154 for (i
= 0; i
< str_nums
; i
++)
155 if (str_list
[i
] >= stream
->incnt
)
158 nstr_list
= kcalloc(str_nums
, sizeof(__be16
), GFP_KERNEL
);
164 for (i
= 0; i
< str_nums
; i
++)
165 nstr_list
[i
] = htons(str_list
[i
]);
167 chunk
= sctp_make_strreset_req(asoc
, str_nums
, nstr_list
, out
, in
);
178 for (i
= 0; i
< str_nums
; i
++)
179 stream
->out
[str_list
[i
]].state
=
182 for (i
= 0; i
< stream
->outcnt
; i
++)
183 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
186 asoc
->strreset_chunk
= chunk
;
187 sctp_chunk_hold(asoc
->strreset_chunk
);
189 retval
= sctp_send_reconf(asoc
, chunk
);
191 sctp_chunk_put(asoc
->strreset_chunk
);
192 asoc
->strreset_chunk
= NULL
;
197 for (i
= 0; i
< str_nums
; i
++)
198 stream
->out
[str_list
[i
]].state
=
201 for (i
= 0; i
< stream
->outcnt
; i
++)
202 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
207 asoc
->strreset_outstanding
= out
+ in
;
213 int sctp_send_reset_assoc(struct sctp_association
*asoc
)
215 struct sctp_stream
*stream
= &asoc
->stream
;
216 struct sctp_chunk
*chunk
= NULL
;
220 if (!asoc
->peer
.reconf_capable
||
221 !(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
224 if (asoc
->strreset_outstanding
)
227 if (!sctp_outq_is_empty(&asoc
->outqueue
))
230 chunk
= sctp_make_strreset_tsnreq(asoc
);
234 /* Block further xmit of data until this request is completed */
235 for (i
= 0; i
< stream
->outcnt
; i
++)
236 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
238 asoc
->strreset_chunk
= chunk
;
239 sctp_chunk_hold(asoc
->strreset_chunk
);
241 retval
= sctp_send_reconf(asoc
, chunk
);
243 sctp_chunk_put(asoc
->strreset_chunk
);
244 asoc
->strreset_chunk
= NULL
;
246 for (i
= 0; i
< stream
->outcnt
; i
++)
247 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
252 asoc
->strreset_outstanding
= 1;
257 int sctp_send_add_streams(struct sctp_association
*asoc
,
258 struct sctp_add_streams
*params
)
260 struct sctp_stream
*stream
= &asoc
->stream
;
261 struct sctp_chunk
*chunk
= NULL
;
262 int retval
= -ENOMEM
;
266 if (!asoc
->peer
.reconf_capable
||
267 !(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
)) {
268 retval
= -ENOPROTOOPT
;
272 if (asoc
->strreset_outstanding
) {
273 retval
= -EINPROGRESS
;
277 out
= params
->sas_outstrms
;
278 in
= params
->sas_instrms
;
279 outcnt
= stream
->outcnt
+ out
;
280 incnt
= stream
->incnt
+ in
;
281 if (outcnt
> SCTP_MAX_STREAM
|| incnt
> SCTP_MAX_STREAM
||
288 struct sctp_stream_out
*streamout
;
290 streamout
= krealloc(stream
->out
, outcnt
* sizeof(*streamout
),
295 memset(streamout
+ stream
->outcnt
, 0, out
* sizeof(*streamout
));
296 stream
->out
= streamout
;
299 chunk
= sctp_make_strreset_addstrm(asoc
, out
, in
);
303 asoc
->strreset_chunk
= chunk
;
304 sctp_chunk_hold(asoc
->strreset_chunk
);
306 retval
= sctp_send_reconf(asoc
, chunk
);
308 sctp_chunk_put(asoc
->strreset_chunk
);
309 asoc
->strreset_chunk
= NULL
;
313 stream
->outcnt
= outcnt
;
315 asoc
->strreset_outstanding
= !!out
+ !!in
;
321 static struct sctp_paramhdr
*sctp_chunk_lookup_strreset_param(
322 struct sctp_association
*asoc
, __be32 resp_seq
,
325 struct sctp_chunk
*chunk
= asoc
->strreset_chunk
;
326 struct sctp_reconf_chunk
*hdr
;
327 union sctp_params param
;
332 hdr
= (struct sctp_reconf_chunk
*)chunk
->chunk_hdr
;
333 sctp_walk_params(param
, hdr
, params
) {
334 /* sctp_strreset_tsnreq is actually the basic structure
335 * of all stream reconf params, so it's safe to use it
336 * to access request_seq.
338 struct sctp_strreset_tsnreq
*req
= param
.v
;
340 if ((!resp_seq
|| req
->request_seq
== resp_seq
) &&
341 (!type
|| type
== req
->param_hdr
.type
))
348 static void sctp_update_strreset_result(struct sctp_association
*asoc
,
351 asoc
->strreset_result
[1] = asoc
->strreset_result
[0];
352 asoc
->strreset_result
[0] = result
;
355 struct sctp_chunk
*sctp_process_strreset_outreq(
356 struct sctp_association
*asoc
,
357 union sctp_params param
,
358 struct sctp_ulpevent
**evp
)
360 struct sctp_strreset_outreq
*outreq
= param
.v
;
361 struct sctp_stream
*stream
= &asoc
->stream
;
362 __u32 result
= SCTP_STRRESET_DENIED
;
363 __be16
*str_p
= NULL
;
367 request_seq
= ntohl(outreq
->request_seq
);
369 if (ntohl(outreq
->send_reset_at_tsn
) >
370 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
)) {
371 result
= SCTP_STRRESET_IN_PROGRESS
;
375 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
376 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
377 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
379 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
380 i
= asoc
->strreset_inseq
- request_seq
- 1;
381 result
= asoc
->strreset_result
[i
];
384 asoc
->strreset_inseq
++;
386 /* Check strreset_enable after inseq inc, as sender cannot tell
387 * the peer doesn't enable strreset after receiving response with
388 * result denied, as well as to keep consistent with bsd.
390 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
393 nums
= (ntohs(param
.p
->length
) - sizeof(*outreq
)) / sizeof(__u16
);
394 str_p
= outreq
->list_of_streams
;
395 for (i
= 0; i
< nums
; i
++) {
396 if (ntohs(str_p
[i
]) >= stream
->incnt
) {
397 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
402 if (asoc
->strreset_chunk
) {
403 if (!sctp_chunk_lookup_strreset_param(
404 asoc
, outreq
->response_seq
,
405 SCTP_PARAM_RESET_IN_REQUEST
)) {
406 /* same process with outstanding isn't 0 */
407 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
411 asoc
->strreset_outstanding
--;
412 asoc
->strreset_outseq
++;
414 if (!asoc
->strreset_outstanding
) {
415 struct sctp_transport
*t
;
417 t
= asoc
->strreset_chunk
->transport
;
418 if (del_timer(&t
->reconf_timer
))
419 sctp_transport_put(t
);
421 sctp_chunk_put(asoc
->strreset_chunk
);
422 asoc
->strreset_chunk
= NULL
;
427 for (i
= 0; i
< nums
; i
++)
428 stream
->in
[ntohs(str_p
[i
])].ssn
= 0;
430 for (i
= 0; i
< stream
->incnt
; i
++)
431 stream
->in
[i
].ssn
= 0;
433 result
= SCTP_STRRESET_PERFORMED
;
435 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
,
436 SCTP_STREAM_RESET_INCOMING_SSN
, nums
, str_p
, GFP_ATOMIC
);
439 sctp_update_strreset_result(asoc
, result
);
441 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
444 struct sctp_chunk
*sctp_process_strreset_inreq(
445 struct sctp_association
*asoc
,
446 union sctp_params param
,
447 struct sctp_ulpevent
**evp
)
449 struct sctp_strreset_inreq
*inreq
= param
.v
;
450 struct sctp_stream
*stream
= &asoc
->stream
;
451 __u32 result
= SCTP_STRRESET_DENIED
;
452 struct sctp_chunk
*chunk
= NULL
;
457 request_seq
= ntohl(inreq
->request_seq
);
458 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
459 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
460 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
462 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
463 i
= asoc
->strreset_inseq
- request_seq
- 1;
464 result
= asoc
->strreset_result
[i
];
465 if (result
== SCTP_STRRESET_PERFORMED
)
469 asoc
->strreset_inseq
++;
471 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_STREAM_REQ
))
474 if (asoc
->strreset_outstanding
) {
475 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
479 nums
= (ntohs(param
.p
->length
) - sizeof(*inreq
)) / 2;
480 str_p
= inreq
->list_of_streams
;
481 for (i
= 0; i
< nums
; i
++) {
482 if (ntohs(str_p
[i
]) >= stream
->outcnt
) {
483 result
= SCTP_STRRESET_ERR_WRONG_SSN
;
488 chunk
= sctp_make_strreset_req(asoc
, nums
, str_p
, 1, 0);
493 for (i
= 0; i
< nums
; i
++)
494 stream
->out
[ntohs(str_p
[i
])].state
=
497 for (i
= 0; i
< stream
->outcnt
; i
++)
498 stream
->out
[i
].state
= SCTP_STREAM_CLOSED
;
500 asoc
->strreset_chunk
= chunk
;
501 asoc
->strreset_outstanding
= 1;
502 sctp_chunk_hold(asoc
->strreset_chunk
);
504 result
= SCTP_STRRESET_PERFORMED
;
507 sctp_update_strreset_result(asoc
, result
);
510 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
515 struct sctp_chunk
*sctp_process_strreset_tsnreq(
516 struct sctp_association
*asoc
,
517 union sctp_params param
,
518 struct sctp_ulpevent
**evp
)
520 __u32 init_tsn
= 0, next_tsn
= 0, max_tsn_seen
;
521 struct sctp_strreset_tsnreq
*tsnreq
= param
.v
;
522 struct sctp_stream
*stream
= &asoc
->stream
;
523 __u32 result
= SCTP_STRRESET_DENIED
;
527 request_seq
= ntohl(tsnreq
->request_seq
);
528 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
529 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
530 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
532 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
533 i
= asoc
->strreset_inseq
- request_seq
- 1;
534 result
= asoc
->strreset_result
[i
];
535 if (result
== SCTP_STRRESET_PERFORMED
) {
536 next_tsn
= asoc
->ctsn_ack_point
+ 1;
538 sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + 1;
543 if (!sctp_outq_is_empty(&asoc
->outqueue
)) {
544 result
= SCTP_STRRESET_IN_PROGRESS
;
548 asoc
->strreset_inseq
++;
550 if (!(asoc
->strreset_enable
& SCTP_ENABLE_RESET_ASSOC_REQ
))
553 if (asoc
->strreset_outstanding
) {
554 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
558 /* G4: The same processing as though a FWD-TSN chunk (as defined in
559 * [RFC3758]) with all streams affected and a new cumulative TSN
560 * ACK of the Receiver's Next TSN minus 1 were received MUST be
563 max_tsn_seen
= sctp_tsnmap_get_max_tsn_seen(&asoc
->peer
.tsn_map
);
564 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, max_tsn_seen
);
565 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
567 /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
568 * TSN that the peer should use to send the next DATA chunk. The
569 * value SHOULD be the smallest TSN not acknowledged by the
570 * receiver of the request plus 2^31.
572 init_tsn
= sctp_tsnmap_get_ctsn(&asoc
->peer
.tsn_map
) + (1 << 31);
573 sctp_tsnmap_init(&asoc
->peer
.tsn_map
, SCTP_TSN_MAP_INITIAL
,
574 init_tsn
, GFP_ATOMIC
);
576 /* G3: The same processing as though a SACK chunk with no gap report
577 * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
578 * received MUST be performed.
580 sctp_outq_free(&asoc
->outqueue
);
582 /* G2: Compute an appropriate value for the local endpoint's next TSN,
583 * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
584 * chunk. The value SHOULD be the highest TSN sent by the receiver
585 * of the request plus 1.
587 next_tsn
= asoc
->next_tsn
;
588 asoc
->ctsn_ack_point
= next_tsn
- 1;
589 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
591 /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
592 * incoming and outgoing streams.
594 for (i
= 0; i
< stream
->outcnt
; i
++)
595 stream
->out
[i
].ssn
= 0;
596 for (i
= 0; i
< stream
->incnt
; i
++)
597 stream
->in
[i
].ssn
= 0;
599 result
= SCTP_STRRESET_PERFORMED
;
601 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, 0, init_tsn
,
602 next_tsn
, GFP_ATOMIC
);
605 sctp_update_strreset_result(asoc
, result
);
607 return sctp_make_strreset_tsnresp(asoc
, result
, request_seq
,
611 struct sctp_chunk
*sctp_process_strreset_addstrm_out(
612 struct sctp_association
*asoc
,
613 union sctp_params param
,
614 struct sctp_ulpevent
**evp
)
616 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
617 struct sctp_stream
*stream
= &asoc
->stream
;
618 __u32 result
= SCTP_STRRESET_DENIED
;
619 struct sctp_stream_in
*streamin
;
620 __u32 request_seq
, incnt
;
623 request_seq
= ntohl(addstrm
->request_seq
);
624 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
625 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
626 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
628 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
629 i
= asoc
->strreset_inseq
- request_seq
- 1;
630 result
= asoc
->strreset_result
[i
];
633 asoc
->strreset_inseq
++;
635 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
638 in
= ntohs(addstrm
->number_of_streams
);
639 incnt
= stream
->incnt
+ in
;
640 if (!in
|| incnt
> SCTP_MAX_STREAM
)
643 streamin
= krealloc(stream
->in
, incnt
* sizeof(*streamin
),
648 if (asoc
->strreset_chunk
) {
649 if (!sctp_chunk_lookup_strreset_param(
650 asoc
, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS
)) {
651 /* same process with outstanding isn't 0 */
652 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
656 asoc
->strreset_outstanding
--;
657 asoc
->strreset_outseq
++;
659 if (!asoc
->strreset_outstanding
) {
660 struct sctp_transport
*t
;
662 t
= asoc
->strreset_chunk
->transport
;
663 if (del_timer(&t
->reconf_timer
))
664 sctp_transport_put(t
);
666 sctp_chunk_put(asoc
->strreset_chunk
);
667 asoc
->strreset_chunk
= NULL
;
671 memset(streamin
+ stream
->incnt
, 0, in
* sizeof(*streamin
));
672 stream
->in
= streamin
;
673 stream
->incnt
= incnt
;
675 result
= SCTP_STRRESET_PERFORMED
;
677 *evp
= sctp_ulpevent_make_stream_change_event(asoc
,
678 0, ntohs(addstrm
->number_of_streams
), 0, GFP_ATOMIC
);
681 sctp_update_strreset_result(asoc
, result
);
683 return sctp_make_strreset_resp(asoc
, result
, request_seq
);
686 struct sctp_chunk
*sctp_process_strreset_addstrm_in(
687 struct sctp_association
*asoc
,
688 union sctp_params param
,
689 struct sctp_ulpevent
**evp
)
691 struct sctp_strreset_addstrm
*addstrm
= param
.v
;
692 struct sctp_stream
*stream
= &asoc
->stream
;
693 __u32 result
= SCTP_STRRESET_DENIED
;
694 struct sctp_stream_out
*streamout
;
695 struct sctp_chunk
*chunk
= NULL
;
696 __u32 request_seq
, outcnt
;
699 request_seq
= ntohl(addstrm
->request_seq
);
700 if (TSN_lt(asoc
->strreset_inseq
, request_seq
) ||
701 TSN_lt(request_seq
, asoc
->strreset_inseq
- 2)) {
702 result
= SCTP_STRRESET_ERR_BAD_SEQNO
;
704 } else if (TSN_lt(request_seq
, asoc
->strreset_inseq
)) {
705 i
= asoc
->strreset_inseq
- request_seq
- 1;
706 result
= asoc
->strreset_result
[i
];
707 if (result
== SCTP_STRRESET_PERFORMED
)
711 asoc
->strreset_inseq
++;
713 if (!(asoc
->strreset_enable
& SCTP_ENABLE_CHANGE_ASSOC_REQ
))
716 if (asoc
->strreset_outstanding
) {
717 result
= SCTP_STRRESET_ERR_IN_PROGRESS
;
721 out
= ntohs(addstrm
->number_of_streams
);
722 outcnt
= stream
->outcnt
+ out
;
723 if (!out
|| outcnt
> SCTP_MAX_STREAM
)
726 streamout
= krealloc(stream
->out
, outcnt
* sizeof(*streamout
),
731 memset(streamout
+ stream
->outcnt
, 0, out
* sizeof(*streamout
));
732 stream
->out
= streamout
;
734 chunk
= sctp_make_strreset_addstrm(asoc
, out
, 0);
738 asoc
->strreset_chunk
= chunk
;
739 asoc
->strreset_outstanding
= 1;
740 sctp_chunk_hold(asoc
->strreset_chunk
);
742 stream
->outcnt
= outcnt
;
744 result
= SCTP_STRRESET_PERFORMED
;
747 sctp_update_strreset_result(asoc
, result
);
750 chunk
= sctp_make_strreset_resp(asoc
, result
, request_seq
);
755 struct sctp_chunk
*sctp_process_strreset_resp(
756 struct sctp_association
*asoc
,
757 union sctp_params param
,
758 struct sctp_ulpevent
**evp
)
760 struct sctp_stream
*stream
= &asoc
->stream
;
761 struct sctp_strreset_resp
*resp
= param
.v
;
762 struct sctp_transport
*t
;
763 __u16 i
, nums
, flags
= 0;
764 struct sctp_paramhdr
*req
;
767 req
= sctp_chunk_lookup_strreset_param(asoc
, resp
->response_seq
, 0);
771 result
= ntohl(resp
->result
);
772 if (result
!= SCTP_STRRESET_PERFORMED
) {
773 /* if in progress, do nothing but retransmit */
774 if (result
== SCTP_STRRESET_IN_PROGRESS
)
776 else if (result
== SCTP_STRRESET_DENIED
)
777 flags
= SCTP_STREAM_RESET_DENIED
;
779 flags
= SCTP_STREAM_RESET_FAILED
;
782 if (req
->type
== SCTP_PARAM_RESET_OUT_REQUEST
) {
783 struct sctp_strreset_outreq
*outreq
;
786 outreq
= (struct sctp_strreset_outreq
*)req
;
787 str_p
= outreq
->list_of_streams
;
788 nums
= (ntohs(outreq
->param_hdr
.length
) - sizeof(*outreq
)) / 2;
790 if (result
== SCTP_STRRESET_PERFORMED
) {
792 for (i
= 0; i
< nums
; i
++)
793 stream
->out
[ntohs(str_p
[i
])].ssn
= 0;
795 for (i
= 0; i
< stream
->outcnt
; i
++)
796 stream
->out
[i
].ssn
= 0;
800 flags
|= SCTP_STREAM_RESET_OUTGOING_SSN
;
802 for (i
= 0; i
< stream
->outcnt
; i
++)
803 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
805 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
806 nums
, str_p
, GFP_ATOMIC
);
807 } else if (req
->type
== SCTP_PARAM_RESET_IN_REQUEST
) {
808 struct sctp_strreset_inreq
*inreq
;
811 /* if the result is performed, it's impossible for inreq */
812 if (result
== SCTP_STRRESET_PERFORMED
)
815 inreq
= (struct sctp_strreset_inreq
*)req
;
816 str_p
= inreq
->list_of_streams
;
817 nums
= (ntohs(inreq
->param_hdr
.length
) - sizeof(*inreq
)) / 2;
819 flags
|= SCTP_STREAM_RESET_INCOMING_SSN
;
821 *evp
= sctp_ulpevent_make_stream_reset_event(asoc
, flags
,
822 nums
, str_p
, GFP_ATOMIC
);
823 } else if (req
->type
== SCTP_PARAM_RESET_TSN_REQUEST
) {
824 struct sctp_strreset_resptsn
*resptsn
;
827 /* check for resptsn, as sctp_verify_reconf didn't do it*/
828 if (ntohs(param
.p
->length
) != sizeof(*resptsn
))
831 resptsn
= (struct sctp_strreset_resptsn
*)resp
;
832 stsn
= ntohl(resptsn
->senders_next_tsn
);
833 rtsn
= ntohl(resptsn
->receivers_next_tsn
);
835 if (result
== SCTP_STRRESET_PERFORMED
) {
836 __u32 mtsn
= sctp_tsnmap_get_max_tsn_seen(
837 &asoc
->peer
.tsn_map
);
840 sctp_ulpq_reasm_flushtsn(&asoc
->ulpq
, mtsn
);
841 sctp_ulpq_abort_pd(&asoc
->ulpq
, GFP_ATOMIC
);
843 sctp_tsnmap_init(&asoc
->peer
.tsn_map
,
844 SCTP_TSN_MAP_INITIAL
,
847 /* Clean up sacked and abandoned queues only. As the
848 * out_chunk_list may not be empty, splice it to temp,
849 * then get it back after sctp_outq_free is done.
851 list_splice_init(&asoc
->outqueue
.out_chunk_list
, &temp
);
852 sctp_outq_free(&asoc
->outqueue
);
853 list_splice_init(&temp
, &asoc
->outqueue
.out_chunk_list
);
855 asoc
->next_tsn
= rtsn
;
856 asoc
->ctsn_ack_point
= asoc
->next_tsn
- 1;
857 asoc
->adv_peer_ack_point
= asoc
->ctsn_ack_point
;
859 for (i
= 0; i
< stream
->outcnt
; i
++)
860 stream
->out
[i
].ssn
= 0;
861 for (i
= 0; i
< stream
->incnt
; i
++)
862 stream
->in
[i
].ssn
= 0;
865 for (i
= 0; i
< stream
->outcnt
; i
++)
866 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
868 *evp
= sctp_ulpevent_make_assoc_reset_event(asoc
, flags
,
869 stsn
, rtsn
, GFP_ATOMIC
);
870 } else if (req
->type
== SCTP_PARAM_RESET_ADD_OUT_STREAMS
) {
871 struct sctp_strreset_addstrm
*addstrm
;
874 addstrm
= (struct sctp_strreset_addstrm
*)req
;
875 nums
= ntohs(addstrm
->number_of_streams
);
876 number
= stream
->outcnt
- nums
;
878 if (result
== SCTP_STRRESET_PERFORMED
)
879 for (i
= number
; i
< stream
->outcnt
; i
++)
880 stream
->out
[i
].state
= SCTP_STREAM_OPEN
;
882 stream
->outcnt
= number
;
884 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
885 0, nums
, GFP_ATOMIC
);
886 } else if (req
->type
== SCTP_PARAM_RESET_ADD_IN_STREAMS
) {
887 struct sctp_strreset_addstrm
*addstrm
;
889 /* if the result is performed, it's impossible for addstrm in
892 if (result
== SCTP_STRRESET_PERFORMED
)
895 addstrm
= (struct sctp_strreset_addstrm
*)req
;
896 nums
= ntohs(addstrm
->number_of_streams
);
898 *evp
= sctp_ulpevent_make_stream_change_event(asoc
, flags
,
899 nums
, 0, GFP_ATOMIC
);
902 asoc
->strreset_outstanding
--;
903 asoc
->strreset_outseq
++;
905 /* remove everything for this reconf request */
906 if (!asoc
->strreset_outstanding
) {
907 t
= asoc
->strreset_chunk
->transport
;
908 if (del_timer(&t
->reconf_timer
))
909 sctp_transport_put(t
);
911 sctp_chunk_put(asoc
->strreset_chunk
);
912 asoc
->strreset_chunk
= NULL
;