Commit 4fdbb0ef authored by Marcelo Ricardo Leitner's avatar Marcelo Ricardo Leitner Committed by David S. Miller

sctp: rework switch cases in sctp_outq_flush_data

Remove an inner one, which tended to be error prone due to the cascading
and it can be replaced by a simple if ().

Rework the outer one so that the actual flush code is not inside it. Now
we first validate if we can or cannot send data, return if not, and then
the flush code.
Suggested-by: default avatarXin Long <lucien.xin@gmail.com>
Signed-off-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6605f694
...@@ -1058,122 +1058,117 @@ static void sctp_outq_flush_data(struct sctp_outq *q, ...@@ -1058,122 +1058,117 @@ static void sctp_outq_flush_data(struct sctp_outq *q,
* chunk. * chunk.
*/ */
if (!packet || !packet->has_cookie_echo) if (!packet || !packet->has_cookie_echo)
break; return;
/* fallthru */ /* fallthru */
case SCTP_STATE_ESTABLISHED: case SCTP_STATE_ESTABLISHED:
case SCTP_STATE_SHUTDOWN_PENDING: case SCTP_STATE_SHUTDOWN_PENDING:
case SCTP_STATE_SHUTDOWN_RECEIVED: case SCTP_STATE_SHUTDOWN_RECEIVED:
/* break;
* RFC 2960 6.1 Transmission of DATA Chunks
*
* C) When the time comes for the sender to transmit,
* before sending new DATA chunks, the sender MUST
* first transmit any outstanding DATA chunks which
* are marked for retransmission (limited by the
* current cwnd).
*/
if (!list_empty(&q->retransmit)) {
if (!sctp_outq_flush_rtx(q, _transport, transport_list,
rtx_timeout, gfp))
break;
/* We may have switched current transport */
transport = *_transport;
packet = &transport->packet;
}
/* Apply Max.Burst limitation to the current transport in default:
* case it will be used for new data. We are going to /* Do nothing. */
* rest it before we return, but we want to apply the limit return;
* to the currently queued data. }
*/
if (transport)
sctp_transport_burst_limited(transport);
/* Finally, transmit new packets. */
while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
__u32 sid = ntohs(chunk->subh.data_hdr->stream);
/* Has this chunk expired? */
if (sctp_chunk_abandoned(chunk)) {
sctp_sched_dequeue_done(q, chunk);
sctp_chunk_fail(chunk, 0);
sctp_chunk_free(chunk);
continue;
}
if (asoc->stream.out[sid].state == SCTP_STREAM_CLOSED) { /*
sctp_outq_head_data(q, chunk); * RFC 2960 6.1 Transmission of DATA Chunks
break; *
} * C) When the time comes for the sender to transmit,
* before sending new DATA chunks, the sender MUST
* first transmit any outstanding DATA chunks which
* are marked for retransmission (limited by the
* current cwnd).
*/
if (!list_empty(&q->retransmit)) {
if (!sctp_outq_flush_rtx(q, _transport, transport_list,
rtx_timeout, gfp))
return;
/* We may have switched current transport */
transport = *_transport;
packet = &transport->packet;
}
if (sctp_outq_select_transport(chunk, asoc, _transport, /* Apply Max.Burst limitation to the current transport in
transport_list)) { * case it will be used for new data. We are going to
transport = *_transport; * rest it before we return, but we want to apply the limit
packet = &transport->packet; * to the currently queued data.
} */
if (transport)
sctp_transport_burst_limited(transport);
pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p " /* Finally, transmit new packets. */
"skb->users:%d\n", while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
__func__, q, chunk, chunk && chunk->chunk_hdr ? __u32 sid = ntohs(chunk->subh.data_hdr->stream);
sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
"illegal chunk", ntohl(chunk->subh.data_hdr->tsn),
chunk->skb ? chunk->skb->head : NULL, chunk->skb ?
refcount_read(&chunk->skb->users) : -1);
/* Add the chunk to the packet. */
status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp);
switch (status) {
case SCTP_XMIT_OK:
break;
case SCTP_XMIT_PMTU_FULL: /* Has this chunk expired? */
case SCTP_XMIT_RWND_FULL: if (sctp_chunk_abandoned(chunk)) {
case SCTP_XMIT_DELAY: sctp_sched_dequeue_done(q, chunk);
/* We could not append this chunk, so put sctp_chunk_fail(chunk, 0);
* the chunk back on the output queue. sctp_chunk_free(chunk);
*/ continue;
pr_debug("%s: could not transmit tsn:0x%x, status:%d\n", }
__func__, ntohl(chunk->subh.data_hdr->tsn),
status);
sctp_outq_head_data(q, chunk); if (asoc->stream.out[sid].state == SCTP_STREAM_CLOSED) {
return; sctp_outq_head_data(q, chunk);
} break;
}
/* The sender is in the SHUTDOWN-PENDING state, if (sctp_outq_select_transport(chunk, asoc, _transport,
* The sender MAY set the I-bit in the DATA transport_list)) {
* chunk header. transport = *_transport;
*/ packet = &transport->packet;
if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING) }
chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
asoc->stats.ouodchunks++;
else
asoc->stats.oodchunks++;
/* Only now it's safe to consider this pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p "
* chunk as sent, sched-wise. "skb->users:%d\n",
__func__, q, chunk, chunk && chunk->chunk_hdr ?
sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
"illegal chunk", ntohl(chunk->subh.data_hdr->tsn),
chunk->skb ? chunk->skb->head : NULL, chunk->skb ?
refcount_read(&chunk->skb->users) : -1);
/* Add the chunk to the packet. */
status = sctp_packet_transmit_chunk(packet, chunk, 0, gfp);
if (status != SCTP_XMIT_OK) {
/* We could not append this chunk, so put
* the chunk back on the output queue.
*/ */
sctp_sched_dequeue_done(q, chunk); pr_debug("%s: could not transmit tsn:0x%x, status:%d\n",
__func__, ntohl(chunk->subh.data_hdr->tsn),
status);
list_add_tail(&chunk->transmitted_list, sctp_outq_head_data(q, chunk);
&transport->transmitted); break;
}
sctp_transport_reset_t3_rtx(transport); /* The sender is in the SHUTDOWN-PENDING state,
transport->last_time_sent = jiffies; * The sender MAY set the I-bit in the DATA
* chunk header.
*/
if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
asoc->stats.ouodchunks++;
else
asoc->stats.oodchunks++;
/* Only let one DATA chunk get bundled with a /* Only now it's safe to consider this
* COOKIE-ECHO chunk. * chunk as sent, sched-wise.
*/ */
if (packet->has_cookie_echo) sctp_sched_dequeue_done(q, chunk);
break;
}
break;
default: list_add_tail(&chunk->transmitted_list,
/* Do nothing. */ &transport->transmitted);
break;
sctp_transport_reset_t3_rtx(transport);
transport->last_time_sent = jiffies;
/* Only let one DATA chunk get bundled with a
* COOKIE-ECHO chunk.
*/
if (packet->has_cookie_echo)
break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment