Skip to content

Commit 4c47af4

Browse files
Daniel Borkmanndavem330
authored andcommitted
net: sctp: rework multihoming retransmission path selection to rfc4960
Problem statement: 1) both paths (primary path1 and alternate path2) are up after the association has been established i.e., HB packets are normally exchanged, 2) path2 gets inactive after path_max_retrans * max_rto timed out (i.e. path2 is down completely), 3) now, if a transmission times out on the only surviving/active path1 (any ~1sec network service impact could cause this like a channel bonding failover), then the retransmitted packets are sent over the inactive path2; this happens with partial failover and without it. Besides not being optimal in the above scenario, a small failure or timeout in the only existing path has the potential to cause long delays in the retransmission (depending on RTO_MAX) until the still active path is reselected. Further, when the T3-timeout occurs, we have active_patch == retrans_path, and even though the timeout occurred on the initial transmission of data, not a retransmit, we end up updating retransmit path. RFC4960, section 6.4. "Multi-Homed SCTP Endpoints" states under 6.4.1. "Failover from an Inactive Destination Address" the following: Some of the transport addresses of a multi-homed SCTP endpoint may become inactive due to either the occurrence of certain error conditions (see Section 8.2) or adjustments from the SCTP user. When there is outbound data to send and the primary path becomes inactive (e.g., due to failures), or where the SCTP user explicitly requests to send data to an inactive destination transport address, before reporting an error to its ULP, the SCTP endpoint should try to send the data to an alternate __active__ destination transport address if one exists. When retransmitting data that timed out, if the endpoint is multihomed, it should consider each source-destination address pair in its retransmission selection policy. When retransmitting timed-out data, the endpoint should attempt to pick the most divergent source-destination pair from the original source-destination pair to which the packet was transmitted. Note: Rules for picking the most divergent source-destination pair are an implementation decision and are not specified within this document. So, we should first reconsider to take the current active retransmission transport if we cannot find an alternative active one. If all of that fails, we can still round robin through unkown, partial failover, and inactive ones in the hope to find something still suitable. Commit 4141ddc ("sctp: retran_path update bug fix") broke that behaviour by selecting the next inactive transport when no other active transport was found besides the current assoc's peer.retran_path. Before commit 4141ddc, we would have traversed through the list until we reach our peer.retran_path again, and in case that is still in state SCTP_ACTIVE, we would take it and return. Only if that is not the case either, we take the next inactive transport. Besides all that, another issue is that transports in state SCTP_UNKNOWN could be preferred over transports in state SCTP_ACTIVE in case a SCTP_ACTIVE transport appears after SCTP_UNKNOWN in the transport list yielding a weaker transport state to be used in retransmission. This patch mostly reverts 4141ddc, but also rewrites this function to introduce more clarity and strictness into the code. A strict priority of transport states is enforced in this patch, hence selection is active > unkown > partial failover > inactive. Fixes: 4141ddc ("sctp: retran_path update bug fix") Signed-off-by: Daniel Borkmann <[email protected]> Cc: Gui Jianfeng <[email protected]> Acked-by: Vlad Yasevich <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b194c1f commit 4c47af4

File tree

1 file changed

+79
-50
lines changed

1 file changed

+79
-50
lines changed

net/sctp/associola.c

Lines changed: 79 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,78 +1239,107 @@ void sctp_assoc_update(struct sctp_association *asoc,
12391239
}
12401240

12411241
/* Update the retran path for sending a retransmitted packet.
1242-
* Round-robin through the active transports, else round-robin
1243-
* through the inactive transports as this is the next best thing
1244-
* we can try.
1242+
* See also RFC4960, 6.4. Multi-Homed SCTP Endpoints:
1243+
*
1244+
* When there is outbound data to send and the primary path
1245+
* becomes inactive (e.g., due to failures), or where the
1246+
* SCTP user explicitly requests to send data to an
1247+
* inactive destination transport address, before reporting
1248+
* an error to its ULP, the SCTP endpoint should try to send
1249+
* the data to an alternate active destination transport
1250+
* address if one exists.
1251+
*
1252+
* When retransmitting data that timed out, if the endpoint
1253+
* is multihomed, it should consider each source-destination
1254+
* address pair in its retransmission selection policy.
1255+
* When retransmitting timed-out data, the endpoint should
1256+
* attempt to pick the most divergent source-destination
1257+
* pair from the original source-destination pair to which
1258+
* the packet was transmitted.
1259+
*
1260+
* Note: Rules for picking the most divergent source-destination
1261+
* pair are an implementation decision and are not specified
1262+
* within this document.
1263+
*
1264+
* Our basic strategy is to round-robin transports in priorities
1265+
* according to sctp_state_prio_map[] e.g., if no such
1266+
* transport with state SCTP_ACTIVE exists, round-robin through
1267+
* SCTP_UNKNOWN, etc. You get the picture.
12451268
*/
1246-
void sctp_assoc_update_retran_path(struct sctp_association *asoc)
1269+
static const u8 sctp_trans_state_to_prio_map[] = {
1270+
[SCTP_ACTIVE] = 3, /* best case */
1271+
[SCTP_UNKNOWN] = 2,
1272+
[SCTP_PF] = 1,
1273+
[SCTP_INACTIVE] = 0, /* worst case */
1274+
};
1275+
1276+
static u8 sctp_trans_score(const struct sctp_transport *trans)
12471277
{
1248-
struct sctp_transport *t, *next;
1249-
struct list_head *head = &asoc->peer.transport_addr_list;
1250-
struct list_head *pos;
1278+
return sctp_trans_state_to_prio_map[trans->state];
1279+
}
12511280

1252-
if (asoc->peer.transport_count == 1)
1253-
return;
1281+
static struct sctp_transport *sctp_trans_elect_best(struct sctp_transport *curr,
1282+
struct sctp_transport *best)
1283+
{
1284+
if (best == NULL)
1285+
return curr;
12541286

1255-
/* Find the next transport in a round-robin fashion. */
1256-
t = asoc->peer.retran_path;
1257-
pos = &t->transports;
1258-
next = NULL;
1287+
return sctp_trans_score(curr) > sctp_trans_score(best) ? curr : best;
1288+
}
12591289

1260-
while (1) {
1261-
/* Skip the head. */
1262-
if (pos->next == head)
1263-
pos = head->next;
1264-
else
1265-
pos = pos->next;
1290+
void sctp_assoc_update_retran_path(struct sctp_association *asoc)
1291+
{
1292+
struct sctp_transport *trans = asoc->peer.retran_path;
1293+
struct sctp_transport *trans_next = NULL;
12661294

1267-
t = list_entry(pos, struct sctp_transport, transports);
1295+
/* We're done as we only have the one and only path. */
1296+
if (asoc->peer.transport_count == 1)
1297+
return;
1298+
/* If active_path and retran_path are the same and active,
1299+
* then this is the only active path. Use it.
1300+
*/
1301+
if (asoc->peer.active_path == asoc->peer.retran_path &&
1302+
asoc->peer.active_path->state == SCTP_ACTIVE)
1303+
return;
12681304

1269-
/* We have exhausted the list, but didn't find any
1270-
* other active transports. If so, use the next
1271-
* transport.
1272-
*/
1273-
if (t == asoc->peer.retran_path) {
1274-
t = next;
1305+
/* Iterate from retran_path's successor back to retran_path. */
1306+
for (trans = list_next_entry(trans, transports); 1;
1307+
trans = list_next_entry(trans, transports)) {
1308+
/* Manually skip the head element. */
1309+
if (&trans->transports == &asoc->peer.transport_addr_list)
1310+
continue;
1311+
if (trans->state == SCTP_UNCONFIRMED)
1312+
continue;
1313+
trans_next = sctp_trans_elect_best(trans, trans_next);
1314+
/* Active is good enough for immediate return. */
1315+
if (trans_next->state == SCTP_ACTIVE)
12751316
break;
1276-
}
1277-
1278-
/* Try to find an active transport. */
1279-
1280-
if ((t->state == SCTP_ACTIVE) ||
1281-
(t->state == SCTP_UNKNOWN)) {
1317+
/* We've reached the end, time to update path. */
1318+
if (trans == asoc->peer.retran_path)
12821319
break;
1283-
} else {
1284-
/* Keep track of the next transport in case
1285-
* we don't find any active transport.
1286-
*/
1287-
if (t->state != SCTP_UNCONFIRMED && !next)
1288-
next = t;
1289-
}
12901320
}
12911321

1292-
if (t)
1293-
asoc->peer.retran_path = t;
1294-
else
1295-
t = asoc->peer.retran_path;
1322+
if (trans_next != NULL)
1323+
asoc->peer.retran_path = trans_next;
12961324

1297-
pr_debug("%s: association:%p addr:%pISpc\n", __func__, asoc,
1298-
&t->ipaddr.sa);
1325+
pr_debug("%s: association:%p updated new path to addr:%pISpc\n",
1326+
__func__, asoc, &asoc->peer.retran_path->ipaddr.sa);
12991327
}
13001328

1301-
/* Choose the transport for sending retransmit packet. */
1302-
struct sctp_transport *sctp_assoc_choose_alter_transport(
1303-
struct sctp_association *asoc, struct sctp_transport *last_sent_to)
1329+
struct sctp_transport *
1330+
sctp_assoc_choose_alter_transport(struct sctp_association *asoc,
1331+
struct sctp_transport *last_sent_to)
13041332
{
13051333
/* If this is the first time packet is sent, use the active path,
13061334
* else use the retran path. If the last packet was sent over the
13071335
* retran path, update the retran path and use it.
13081336
*/
1309-
if (!last_sent_to)
1337+
if (last_sent_to == NULL) {
13101338
return asoc->peer.active_path;
1311-
else {
1339+
} else {
13121340
if (last_sent_to == asoc->peer.retran_path)
13131341
sctp_assoc_update_retran_path(asoc);
1342+
13141343
return asoc->peer.retran_path;
13151344
}
13161345
}

0 commit comments

Comments
 (0)