First of all it is logical.

And I found that sk_stream_wait_connect can be called if a socket
isn't in the TCP_ESTABLISHED state. In this case we get -EPIPE.

Cc: "David S. Miller" <[email protected]>
Cc: Alexey Kuznetsov <[email protected]>
Cc: James Morris <[email protected]>
Cc: Hideaki YOSHIFUJI <[email protected]>
Cc: Patrick McHardy <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: Cyrill Gorcunov <[email protected]>
Signed-off-by: Andrey Vagin <[email protected]>
---
 net/ipv4/tcp.c | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 267adb7..4cd0e87 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1084,6 +1084,23 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, 
struct msghdr *msg,
        lock_sock(sk);
 
        flags = msg->msg_flags;
+
+       if (unlikely(tp->repair)) {
+               err = -EINVAL;
+               if (tp->repair_queue == TCP_NO_QUEUE)
+                       goto out_err;
+
+               if (sk->sk_state != TCP_ESTABLISHED)
+                       goto out_err;
+
+               if (tp->repair_queue == TCP_RECV_QUEUE) {
+                       copied = tcp_send_rcvq(sk, msg, size);
+                       goto out;
+               }
+
+               /* 'common' sending to sendq */
+       }
+
        if (flags & MSG_FASTOPEN) {
                err = tcp_sendmsg_fastopen(sk, msg, &copied_syn, size);
                if (err == -EINPROGRESS && copied_syn > 0)
@@ -1105,22 +1122,6 @@ int tcp_sendmsg(struct kiocb *iocb, struct sock *sk, 
struct msghdr *msg,
                        goto do_error;
        }
 
-       if (unlikely(tp->repair)) {
-               err = -EINVAL;
-               if (tp->repair_queue == TCP_NO_QUEUE)
-                       goto out_err;
-
-               if (sk->sk_state != TCP_ESTABLISHED)
-                       goto out_err;
-
-               if (tp->repair_queue == TCP_RECV_QUEUE) {
-                       copied = tcp_send_rcvq(sk, msg, size);
-                       goto out;
-               }
-
-               /* 'common' sending to sendq */
-       }
-
        /* This should be in poll */
        clear_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags);
 
-- 
1.8.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to