Skip to content

Commit abc9b4e

Browse files
Tuong Liendavem330
authored andcommitted
tipc: fix retrans failure due to wrong destination
When a user message is sent, TIPC will check if the socket has faced a congestion at link layer. If that happens, it will make a sleep to wait for the congestion to disappear. This leaves a gap for other users to take over the socket (e.g. multi threads) since the socket is released as well. Also, in case of connectionless (e.g. SOCK_RDM), user is free to send messages to various destinations (e.g. via 'sendto()'), then the socket's preformatted header has to be updated correspondingly prior to the actual payload message building. Unfortunately, the latter action is done before the first action which causes a condition issue that the destination of a certain message can be modified incorrectly in the middle, leading to wrong destination when that message is built. Consequently, when the message is sent to the link layer, it gets stuck there forever because the peer node will simply reject it. After a number of retransmission attempts, the link is eventually taken down and the retransmission failure is reported. This commit fixes the problem by rearranging the order of actions to prevent the race condition from occurring, so the message building is 'atomic' and its header will not be modified by anyone. Fixes: 365ad35 ("tipc: reduce risk of user starvation during link congestion") Acked-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: Tuong Lien <tuong.t.lien@dektech.com.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dca4a17 commit abc9b4e

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

‎net/tipc/socket.c‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,8 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
13641364
struct tipc_msg *hdr = &tsk->phdr;
13651365
struct tipc_name_seq *seq;
13661366
struct sk_buff_head pkts;
1367-
u32 dport, dnode = 0;
1368-
u32 type, inst;
1367+
u32 dport = 0, dnode = 0;
1368+
u32 type = 0, inst = 0;
13691369
int mtu, rc;
13701370

13711371
if (unlikely(dlen > TIPC_MAX_USER_MSG_SIZE))
@@ -1418,23 +1418,11 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
14181418
type = dest->addr.name.name.type;
14191419
inst = dest->addr.name.name.instance;
14201420
dnode = dest->addr.name.domain;
1421-
msg_set_type(hdr, TIPC_NAMED_MSG);
1422-
msg_set_hdr_sz(hdr, NAMED_H_SIZE);
1423-
msg_set_nametype(hdr, type);
1424-
msg_set_nameinst(hdr, inst);
1425-
msg_set_lookup_scope(hdr, tipc_node2scope(dnode));
14261421
dport = tipc_nametbl_translate(net, type, inst, &dnode);
1427-
msg_set_destnode(hdr, dnode);
1428-
msg_set_destport(hdr, dport);
14291422
if (unlikely(!dport && !dnode))
14301423
return -EHOSTUNREACH;
14311424
} else if (dest->addrtype == TIPC_ADDR_ID) {
14321425
dnode = dest->addr.id.node;
1433-
msg_set_type(hdr, TIPC_DIRECT_MSG);
1434-
msg_set_lookup_scope(hdr, 0);
1435-
msg_set_destnode(hdr, dnode);
1436-
msg_set_destport(hdr, dest->addr.id.ref);
1437-
msg_set_hdr_sz(hdr, BASIC_H_SIZE);
14381426
} else {
14391427
return -EINVAL;
14401428
}
@@ -1445,6 +1433,22 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen)
14451433
if (unlikely(rc))
14461434
return rc;
14471435

1436+
if (dest->addrtype == TIPC_ADDR_NAME) {
1437+
msg_set_type(hdr, TIPC_NAMED_MSG);
1438+
msg_set_hdr_sz(hdr, NAMED_H_SIZE);
1439+
msg_set_nametype(hdr, type);
1440+
msg_set_nameinst(hdr, inst);
1441+
msg_set_lookup_scope(hdr, tipc_node2scope(dnode));
1442+
msg_set_destnode(hdr, dnode);
1443+
msg_set_destport(hdr, dport);
1444+
} else { /* TIPC_ADDR_ID */
1445+
msg_set_type(hdr, TIPC_DIRECT_MSG);
1446+
msg_set_lookup_scope(hdr, 0);
1447+
msg_set_destnode(hdr, dnode);
1448+
msg_set_destport(hdr, dest->addr.id.ref);
1449+
msg_set_hdr_sz(hdr, BASIC_H_SIZE);
1450+
}
1451+
14481452
__skb_queue_head_init(&pkts);
14491453
mtu = tipc_node_get_mtu(net, dnode, tsk->portid, false);
14501454
rc = tipc_msg_build(hdr, m, 0, dlen, mtu, &pkts);

0 commit comments

Comments
 (0)