Commit 2c8d85182348021fc0a1bed193a4be4161dc8364
Committed by
David S. Miller
1 parent
eb8895debe
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
tipc: set sk_err correctly when connection fails
Should a connect fail, if the publication/server is unavailable or due to some other error, a positive value will be returned and errno is never set. If the application code checks for an explicit zero return from connect (success) or a negative return (failure), it will not catch the error and subsequent send() calls will fail as shown from the strace snippet below. socket(0x1e /* PF_??? */, SOCK_SEQPACKET, 0) = 3 connect(3, {sa_family=0x1e /* AF_??? */, sa_data="\2\1\322\4\0\0\322\4\0\0\0\0\0\0"}, 16) = 111 sendto(3, "test", 4, 0, NULL, 0) = -1 EPIPE (Broken pipe) The reason for this behaviour is that TIPC wrongly inverts error codes set in sk_err. Signed-off-by: Erik Hugne <erik.hugne@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 2 additions and 2 deletions Side-by-side Diff
net/tipc/socket.c
... | ... | @@ -1257,7 +1257,7 @@ |
1257 | 1257 | /* Accept only ACK or NACK message */ |
1258 | 1258 | if (unlikely(msg_errcode(msg))) { |
1259 | 1259 | sock->state = SS_DISCONNECTING; |
1260 | - sk->sk_err = -ECONNREFUSED; | |
1260 | + sk->sk_err = ECONNREFUSED; | |
1261 | 1261 | retval = TIPC_OK; |
1262 | 1262 | break; |
1263 | 1263 | } |
... | ... | @@ -1268,7 +1268,7 @@ |
1268 | 1268 | res = auto_connect(sock, msg); |
1269 | 1269 | if (res) { |
1270 | 1270 | sock->state = SS_DISCONNECTING; |
1271 | - sk->sk_err = res; | |
1271 | + sk->sk_err = -res; | |
1272 | 1272 | retval = TIPC_OK; |
1273 | 1273 | break; |
1274 | 1274 | } |