|
@@ -267,18 +267,6 @@ int sctp_send_add_streams(struct sctp_association *asoc,
|
|
|
stream->out = streamout;
|
|
|
}
|
|
|
|
|
|
- if (in) {
|
|
|
- struct sctp_stream_in *streamin;
|
|
|
-
|
|
|
- streamin = krealloc(stream->in, incnt * sizeof(*streamin),
|
|
|
- GFP_KERNEL);
|
|
|
- if (!streamin)
|
|
|
- goto out;
|
|
|
-
|
|
|
- memset(streamin + stream->incnt, 0, in * sizeof(*streamin));
|
|
|
- stream->in = streamin;
|
|
|
- }
|
|
|
-
|
|
|
chunk = sctp_make_strreset_addstrm(asoc, out, in);
|
|
|
if (!chunk)
|
|
|
goto out;
|
|
@@ -303,13 +291,14 @@ out:
|
|
|
}
|
|
|
|
|
|
static sctp_paramhdr_t *sctp_chunk_lookup_strreset_param(
|
|
|
- struct sctp_association *asoc, __u32 resp_seq)
|
|
|
+ struct sctp_association *asoc, __u32 resp_seq,
|
|
|
+ __be16 type)
|
|
|
{
|
|
|
struct sctp_chunk *chunk = asoc->strreset_chunk;
|
|
|
struct sctp_reconf_chunk *hdr;
|
|
|
union sctp_params param;
|
|
|
|
|
|
- if (ntohl(resp_seq) != asoc->strreset_outseq || !chunk)
|
|
|
+ if (!chunk)
|
|
|
return NULL;
|
|
|
|
|
|
hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
|
|
@@ -320,7 +309,8 @@ static sctp_paramhdr_t *sctp_chunk_lookup_strreset_param(
|
|
|
*/
|
|
|
struct sctp_strreset_tsnreq *req = param.v;
|
|
|
|
|
|
- if (req->request_seq == resp_seq)
|
|
|
+ if ((!resp_seq || req->request_seq == resp_seq) &&
|
|
|
+ (!type || type == req->param_hdr.type))
|
|
|
return param.v;
|
|
|
}
|
|
|
|
|
@@ -361,13 +351,9 @@ struct sctp_chunk *sctp_process_strreset_outreq(
|
|
|
goto out;
|
|
|
|
|
|
if (asoc->strreset_chunk) {
|
|
|
- sctp_paramhdr_t *param_hdr;
|
|
|
- struct sctp_transport *t;
|
|
|
-
|
|
|
- param_hdr = sctp_chunk_lookup_strreset_param(
|
|
|
- asoc, outreq->response_seq);
|
|
|
- if (!param_hdr || param_hdr->type !=
|
|
|
- SCTP_PARAM_RESET_IN_REQUEST) {
|
|
|
+ if (!sctp_chunk_lookup_strreset_param(
|
|
|
+ asoc, outreq->response_seq,
|
|
|
+ SCTP_PARAM_RESET_IN_REQUEST)) {
|
|
|
/* same process with outstanding isn't 0 */
|
|
|
result = SCTP_STRRESET_ERR_IN_PROGRESS;
|
|
|
goto out;
|
|
@@ -377,6 +363,8 @@ struct sctp_chunk *sctp_process_strreset_outreq(
|
|
|
asoc->strreset_outseq++;
|
|
|
|
|
|
if (!asoc->strreset_outstanding) {
|
|
|
+ struct sctp_transport *t;
|
|
|
+
|
|
|
t = asoc->strreset_chunk->transport;
|
|
|
if (del_timer(&t->reconf_timer))
|
|
|
sctp_transport_put(t);
|
|
@@ -477,3 +465,367 @@ out:
|
|
|
|
|
|
return chunk;
|
|
|
}
|
|
|
+
|
|
|
+struct sctp_chunk *sctp_process_strreset_tsnreq(
|
|
|
+ struct sctp_association *asoc,
|
|
|
+ union sctp_params param,
|
|
|
+ struct sctp_ulpevent **evp)
|
|
|
+{
|
|
|
+ __u32 init_tsn = 0, next_tsn = 0, max_tsn_seen;
|
|
|
+ struct sctp_strreset_tsnreq *tsnreq = param.v;
|
|
|
+ struct sctp_stream *stream = asoc->stream;
|
|
|
+ __u32 result = SCTP_STRRESET_DENIED;
|
|
|
+ __u32 request_seq;
|
|
|
+ __u16 i;
|
|
|
+
|
|
|
+ request_seq = ntohl(tsnreq->request_seq);
|
|
|
+ if (request_seq > asoc->strreset_inseq) {
|
|
|
+ result = SCTP_STRRESET_ERR_BAD_SEQNO;
|
|
|
+ goto out;
|
|
|
+ } else if (request_seq == asoc->strreset_inseq) {
|
|
|
+ asoc->strreset_inseq++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!(asoc->strreset_enable & SCTP_ENABLE_RESET_ASSOC_REQ))
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ if (asoc->strreset_outstanding) {
|
|
|
+ result = SCTP_STRRESET_ERR_IN_PROGRESS;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* G3: The same processing as though a SACK chunk with no gap report
|
|
|
+ * and a cumulative TSN ACK of the Sender's Next TSN minus 1 were
|
|
|
+ * received MUST be performed.
|
|
|
+ */
|
|
|
+ max_tsn_seen = sctp_tsnmap_get_max_tsn_seen(&asoc->peer.tsn_map);
|
|
|
+ sctp_ulpq_reasm_flushtsn(&asoc->ulpq, max_tsn_seen);
|
|
|
+ sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
|
|
|
+
|
|
|
+ /* G1: Compute an appropriate value for the Receiver's Next TSN -- the
|
|
|
+ * TSN that the peer should use to send the next DATA chunk. The
|
|
|
+ * value SHOULD be the smallest TSN not acknowledged by the
|
|
|
+ * receiver of the request plus 2^31.
|
|
|
+ */
|
|
|
+ init_tsn = sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + (1 << 31);
|
|
|
+ sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
|
|
|
+ init_tsn, GFP_ATOMIC);
|
|
|
+
|
|
|
+ /* G4: The same processing as though a FWD-TSN chunk (as defined in
|
|
|
+ * [RFC3758]) with all streams affected and a new cumulative TSN
|
|
|
+ * ACK of the Receiver's Next TSN minus 1 were received MUST be
|
|
|
+ * performed.
|
|
|
+ */
|
|
|
+ sctp_outq_free(&asoc->outqueue);
|
|
|
+
|
|
|
+ /* G2: Compute an appropriate value for the local endpoint's next TSN,
|
|
|
+ * i.e., the next TSN assigned by the receiver of the SSN/TSN reset
|
|
|
+ * chunk. The value SHOULD be the highest TSN sent by the receiver
|
|
|
+ * of the request plus 1.
|
|
|
+ */
|
|
|
+ next_tsn = asoc->next_tsn;
|
|
|
+ asoc->ctsn_ack_point = next_tsn - 1;
|
|
|
+ asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
|
|
|
+
|
|
|
+ /* G5: The next expected and outgoing SSNs MUST be reset to 0 for all
|
|
|
+ * incoming and outgoing streams.
|
|
|
+ */
|
|
|
+ for (i = 0; i < stream->outcnt; i++)
|
|
|
+ stream->out[i].ssn = 0;
|
|
|
+ for (i = 0; i < stream->incnt; i++)
|
|
|
+ stream->in[i].ssn = 0;
|
|
|
+
|
|
|
+ result = SCTP_STRRESET_PERFORMED;
|
|
|
+
|
|
|
+ *evp = sctp_ulpevent_make_assoc_reset_event(asoc, 0, init_tsn,
|
|
|
+ next_tsn, GFP_ATOMIC);
|
|
|
+
|
|
|
+out:
|
|
|
+ return sctp_make_strreset_tsnresp(asoc, result, request_seq,
|
|
|
+ next_tsn, init_tsn);
|
|
|
+}
|
|
|
+
|
|
|
+struct sctp_chunk *sctp_process_strreset_addstrm_out(
|
|
|
+ struct sctp_association *asoc,
|
|
|
+ union sctp_params param,
|
|
|
+ struct sctp_ulpevent **evp)
|
|
|
+{
|
|
|
+ struct sctp_strreset_addstrm *addstrm = param.v;
|
|
|
+ struct sctp_stream *stream = asoc->stream;
|
|
|
+ __u32 result = SCTP_STRRESET_DENIED;
|
|
|
+ struct sctp_stream_in *streamin;
|
|
|
+ __u32 request_seq, incnt;
|
|
|
+ __u16 in;
|
|
|
+
|
|
|
+ request_seq = ntohl(addstrm->request_seq);
|
|
|
+ if (request_seq > asoc->strreset_inseq) {
|
|
|
+ result = SCTP_STRRESET_ERR_BAD_SEQNO;
|
|
|
+ goto out;
|
|
|
+ } else if (request_seq == asoc->strreset_inseq) {
|
|
|
+ asoc->strreset_inseq++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ if (asoc->strreset_chunk) {
|
|
|
+ if (!sctp_chunk_lookup_strreset_param(
|
|
|
+ asoc, 0, SCTP_PARAM_RESET_ADD_IN_STREAMS)) {
|
|
|
+ /* same process with outstanding isn't 0 */
|
|
|
+ result = SCTP_STRRESET_ERR_IN_PROGRESS;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ asoc->strreset_outstanding--;
|
|
|
+ asoc->strreset_outseq++;
|
|
|
+
|
|
|
+ if (!asoc->strreset_outstanding) {
|
|
|
+ struct sctp_transport *t;
|
|
|
+
|
|
|
+ t = asoc->strreset_chunk->transport;
|
|
|
+ if (del_timer(&t->reconf_timer))
|
|
|
+ sctp_transport_put(t);
|
|
|
+
|
|
|
+ sctp_chunk_put(asoc->strreset_chunk);
|
|
|
+ asoc->strreset_chunk = NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ in = ntohs(addstrm->number_of_streams);
|
|
|
+ incnt = stream->incnt + in;
|
|
|
+ if (!in || incnt > SCTP_MAX_STREAM)
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ streamin = krealloc(stream->in, incnt * sizeof(*streamin),
|
|
|
+ GFP_ATOMIC);
|
|
|
+ if (!streamin)
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ memset(streamin + stream->incnt, 0, in * sizeof(*streamin));
|
|
|
+ stream->in = streamin;
|
|
|
+ stream->incnt = incnt;
|
|
|
+
|
|
|
+ result = SCTP_STRRESET_PERFORMED;
|
|
|
+
|
|
|
+ *evp = sctp_ulpevent_make_stream_change_event(asoc,
|
|
|
+ 0, ntohs(addstrm->number_of_streams), 0, GFP_ATOMIC);
|
|
|
+
|
|
|
+out:
|
|
|
+ return sctp_make_strreset_resp(asoc, result, request_seq);
|
|
|
+}
|
|
|
+
|
|
|
+struct sctp_chunk *sctp_process_strreset_addstrm_in(
|
|
|
+ struct sctp_association *asoc,
|
|
|
+ union sctp_params param,
|
|
|
+ struct sctp_ulpevent **evp)
|
|
|
+{
|
|
|
+ struct sctp_strreset_addstrm *addstrm = param.v;
|
|
|
+ struct sctp_stream *stream = asoc->stream;
|
|
|
+ __u32 result = SCTP_STRRESET_DENIED;
|
|
|
+ struct sctp_stream_out *streamout;
|
|
|
+ struct sctp_chunk *chunk = NULL;
|
|
|
+ __u32 request_seq, outcnt;
|
|
|
+ __u16 out;
|
|
|
+
|
|
|
+ request_seq = ntohl(addstrm->request_seq);
|
|
|
+ if (request_seq > asoc->strreset_inseq) {
|
|
|
+ result = SCTP_STRRESET_ERR_BAD_SEQNO;
|
|
|
+ goto out;
|
|
|
+ } else if (request_seq == asoc->strreset_inseq) {
|
|
|
+ asoc->strreset_inseq++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!(asoc->strreset_enable & SCTP_ENABLE_CHANGE_ASSOC_REQ))
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ if (asoc->strreset_outstanding) {
|
|
|
+ result = SCTP_STRRESET_ERR_IN_PROGRESS;
|
|
|
+ goto out;
|
|
|
+ }
|
|
|
+
|
|
|
+ out = ntohs(addstrm->number_of_streams);
|
|
|
+ outcnt = stream->outcnt + out;
|
|
|
+ if (!out || outcnt > SCTP_MAX_STREAM)
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ streamout = krealloc(stream->out, outcnt * sizeof(*streamout),
|
|
|
+ GFP_ATOMIC);
|
|
|
+ if (!streamout)
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ memset(streamout + stream->outcnt, 0, out * sizeof(*streamout));
|
|
|
+ stream->out = streamout;
|
|
|
+
|
|
|
+ chunk = sctp_make_strreset_addstrm(asoc, out, 0);
|
|
|
+ if (!chunk)
|
|
|
+ goto out;
|
|
|
+
|
|
|
+ asoc->strreset_chunk = chunk;
|
|
|
+ asoc->strreset_outstanding = 1;
|
|
|
+ sctp_chunk_hold(asoc->strreset_chunk);
|
|
|
+
|
|
|
+ stream->outcnt = outcnt;
|
|
|
+
|
|
|
+ *evp = sctp_ulpevent_make_stream_change_event(asoc,
|
|
|
+ 0, 0, ntohs(addstrm->number_of_streams), GFP_ATOMIC);
|
|
|
+
|
|
|
+out:
|
|
|
+ if (!chunk)
|
|
|
+ chunk = sctp_make_strreset_resp(asoc, result, request_seq);
|
|
|
+
|
|
|
+ return chunk;
|
|
|
+}
|
|
|
+
|
|
|
+struct sctp_chunk *sctp_process_strreset_resp(
|
|
|
+ struct sctp_association *asoc,
|
|
|
+ union sctp_params param,
|
|
|
+ struct sctp_ulpevent **evp)
|
|
|
+{
|
|
|
+ struct sctp_strreset_resp *resp = param.v;
|
|
|
+ struct sctp_stream *stream = asoc->stream;
|
|
|
+ struct sctp_transport *t;
|
|
|
+ __u16 i, nums, flags = 0;
|
|
|
+ sctp_paramhdr_t *req;
|
|
|
+ __u32 result;
|
|
|
+
|
|
|
+ req = sctp_chunk_lookup_strreset_param(asoc, resp->response_seq, 0);
|
|
|
+ if (!req)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ result = ntohl(resp->result);
|
|
|
+ if (result != SCTP_STRRESET_PERFORMED) {
|
|
|
+ /* if in progress, do nothing but retransmit */
|
|
|
+ if (result == SCTP_STRRESET_IN_PROGRESS)
|
|
|
+ return NULL;
|
|
|
+ else if (result == SCTP_STRRESET_DENIED)
|
|
|
+ flags = SCTP_STREAM_RESET_DENIED;
|
|
|
+ else
|
|
|
+ flags = SCTP_STREAM_RESET_FAILED;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (req->type == SCTP_PARAM_RESET_OUT_REQUEST) {
|
|
|
+ struct sctp_strreset_outreq *outreq;
|
|
|
+ __u16 *str_p = NULL;
|
|
|
+
|
|
|
+ outreq = (struct sctp_strreset_outreq *)req;
|
|
|
+ nums = (ntohs(outreq->param_hdr.length) - sizeof(*outreq)) / 2;
|
|
|
+
|
|
|
+ if (result == SCTP_STRRESET_PERFORMED) {
|
|
|
+ if (nums) {
|
|
|
+ str_p = outreq->list_of_streams;
|
|
|
+ for (i = 0; i < nums; i++)
|
|
|
+ stream->out[ntohs(str_p[i])].ssn = 0;
|
|
|
+ } else {
|
|
|
+ for (i = 0; i < stream->outcnt; i++)
|
|
|
+ stream->out[i].ssn = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ flags = SCTP_STREAM_RESET_OUTGOING_SSN;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i = 0; i < stream->outcnt; i++)
|
|
|
+ stream->out[i].state = SCTP_STREAM_OPEN;
|
|
|
+
|
|
|
+ *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
|
|
|
+ nums, str_p, GFP_ATOMIC);
|
|
|
+ } else if (req->type == SCTP_PARAM_RESET_IN_REQUEST) {
|
|
|
+ struct sctp_strreset_inreq *inreq;
|
|
|
+ __u16 *str_p = NULL;
|
|
|
+
|
|
|
+ /* if the result is performed, it's impossible for inreq */
|
|
|
+ if (result == SCTP_STRRESET_PERFORMED)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ inreq = (struct sctp_strreset_inreq *)req;
|
|
|
+ nums = (ntohs(inreq->param_hdr.length) - sizeof(*inreq)) / 2;
|
|
|
+
|
|
|
+ str_p = inreq->list_of_streams;
|
|
|
+ *evp = sctp_ulpevent_make_stream_reset_event(asoc, flags,
|
|
|
+ nums, str_p, GFP_ATOMIC);
|
|
|
+ } else if (req->type == SCTP_PARAM_RESET_TSN_REQUEST) {
|
|
|
+ struct sctp_strreset_resptsn *resptsn;
|
|
|
+ __u32 stsn, rtsn;
|
|
|
+
|
|
|
+ /* check for resptsn, as sctp_verify_reconf didn't do it*/
|
|
|
+ if (ntohs(param.p->length) != sizeof(*resptsn))
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ resptsn = (struct sctp_strreset_resptsn *)resp;
|
|
|
+ stsn = ntohl(resptsn->senders_next_tsn);
|
|
|
+ rtsn = ntohl(resptsn->receivers_next_tsn);
|
|
|
+
|
|
|
+ if (result == SCTP_STRRESET_PERFORMED) {
|
|
|
+ __u32 mtsn = sctp_tsnmap_get_max_tsn_seen(
|
|
|
+ &asoc->peer.tsn_map);
|
|
|
+
|
|
|
+ sctp_ulpq_reasm_flushtsn(&asoc->ulpq, mtsn);
|
|
|
+ sctp_ulpq_abort_pd(&asoc->ulpq, GFP_ATOMIC);
|
|
|
+
|
|
|
+ sctp_tsnmap_init(&asoc->peer.tsn_map,
|
|
|
+ SCTP_TSN_MAP_INITIAL,
|
|
|
+ stsn, GFP_ATOMIC);
|
|
|
+
|
|
|
+ sctp_outq_free(&asoc->outqueue);
|
|
|
+
|
|
|
+ asoc->next_tsn = rtsn;
|
|
|
+ asoc->ctsn_ack_point = asoc->next_tsn - 1;
|
|
|
+ asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
|
|
|
+
|
|
|
+ for (i = 0; i < stream->outcnt; i++)
|
|
|
+ stream->out[i].ssn = 0;
|
|
|
+ for (i = 0; i < stream->incnt; i++)
|
|
|
+ stream->in[i].ssn = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i = 0; i < stream->outcnt; i++)
|
|
|
+ stream->out[i].state = SCTP_STREAM_OPEN;
|
|
|
+
|
|
|
+ *evp = sctp_ulpevent_make_assoc_reset_event(asoc, flags,
|
|
|
+ stsn, rtsn, GFP_ATOMIC);
|
|
|
+ } else if (req->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS) {
|
|
|
+ struct sctp_strreset_addstrm *addstrm;
|
|
|
+ __u16 number;
|
|
|
+
|
|
|
+ addstrm = (struct sctp_strreset_addstrm *)req;
|
|
|
+ nums = ntohs(addstrm->number_of_streams);
|
|
|
+ number = stream->outcnt - nums;
|
|
|
+
|
|
|
+ if (result == SCTP_STRRESET_PERFORMED)
|
|
|
+ for (i = number; i < stream->outcnt; i++)
|
|
|
+ stream->out[i].state = SCTP_STREAM_OPEN;
|
|
|
+ else
|
|
|
+ stream->outcnt = number;
|
|
|
+
|
|
|
+ *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
|
|
|
+ 0, nums, GFP_ATOMIC);
|
|
|
+ } else if (req->type == SCTP_PARAM_RESET_ADD_IN_STREAMS) {
|
|
|
+ struct sctp_strreset_addstrm *addstrm;
|
|
|
+
|
|
|
+ /* if the result is performed, it's impossible for addstrm in
|
|
|
+ * request.
|
|
|
+ */
|
|
|
+ if (result == SCTP_STRRESET_PERFORMED)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ addstrm = (struct sctp_strreset_addstrm *)req;
|
|
|
+ nums = ntohs(addstrm->number_of_streams);
|
|
|
+
|
|
|
+ *evp = sctp_ulpevent_make_stream_change_event(asoc, flags,
|
|
|
+ nums, 0, GFP_ATOMIC);
|
|
|
+ }
|
|
|
+
|
|
|
+ asoc->strreset_outstanding--;
|
|
|
+ asoc->strreset_outseq++;
|
|
|
+
|
|
|
+ /* remove everything for this reconf request */
|
|
|
+ if (!asoc->strreset_outstanding) {
|
|
|
+ t = asoc->strreset_chunk->transport;
|
|
|
+ if (del_timer(&t->reconf_timer))
|
|
|
+ sctp_transport_put(t);
|
|
|
+
|
|
|
+ sctp_chunk_put(asoc->strreset_chunk);
|
|
|
+ asoc->strreset_chunk = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+}
|