Skip to content

Commit ce7ca79

Browse files
D. Wythedavem330
authored andcommitted
net/smc: fix fallback failed while sendmsg with fastopen
Before determining whether the msg has unsupported options, it has been prematurely terminated by the wrong status check. For the application, the general usages of MSG_FASTOPEN likes fd = socket(...) /* rather than connect */ sendto(fd, data, len, MSG_FASTOPEN) Hence, We need to check the flag before state check, because the sock state here is always SMC_INIT when applications tries MSG_FASTOPEN. Once we found unsupported options, fallback it to TCP. Fixes: ee9dfbe ("net/smc: handle sockopts forcing fallback") Signed-off-by: D. Wythe <alibuda@linux.alibaba.com> Signed-off-by: Simon Horman <simon.horman@corigine.com> v2 -> v1: Optimize code style Reviewed-by: Tony Lu <tonylu@linux.alibaba.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 37d9df2 commit ce7ca79

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

net/smc/af_smc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2657,16 +2657,14 @@ static int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
26572657
{
26582658
struct sock *sk = sock->sk;
26592659
struct smc_sock *smc;
2660-
int rc = -EPIPE;
2660+
int rc;
26612661

26622662
smc = smc_sk(sk);
26632663
lock_sock(sk);
2664-
if ((sk->sk_state != SMC_ACTIVE) &&
2665-
(sk->sk_state != SMC_APPCLOSEWAIT1) &&
2666-
(sk->sk_state != SMC_INIT))
2667-
goto out;
26682664

2665+
/* SMC does not support connect with fastopen */
26692666
if (msg->msg_flags & MSG_FASTOPEN) {
2667+
/* not connected yet, fallback */
26702668
if (sk->sk_state == SMC_INIT && !smc->connect_nonblock) {
26712669
rc = smc_switch_to_fallback(smc, SMC_CLC_DECL_OPTUNSUPP);
26722670
if (rc)
@@ -2675,6 +2673,11 @@ static int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
26752673
rc = -EINVAL;
26762674
goto out;
26772675
}
2676+
} else if ((sk->sk_state != SMC_ACTIVE) &&
2677+
(sk->sk_state != SMC_APPCLOSEWAIT1) &&
2678+
(sk->sk_state != SMC_INIT)) {
2679+
rc = -EPIPE;
2680+
goto out;
26782681
}
26792682

26802683
if (smc->use_fallback) {

0 commit comments

Comments
 (0)