From patchwork Tue Sep 27 22:53:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Shytyi X-Patchwork-Id: 12991456 X-Patchwork-Delegate: pabeni@redhat.com Received: from sender11-of-o51.zoho.eu (sender11-of-o51.zoho.eu [31.186.226.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2472E4C94 for ; Tue, 27 Sep 2022 22:54:22 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1664319258; cv=none; d=zohomail.eu; s=zohoarc; b=KL+BtACxdnkvlTVkOSPuZXqnP5BYBI6aCCTriAOJugm4bG/N+v9QZYeTyDKn4vVuyJoHgtXeTFywn98XYOUvoG3dgHB/5RBq1IwisC8mF9tAQbuhQo6fA0Us2j53QtMZSRYSaQKD3gwWi3ADWJPkH+NghcxNxjNYxFQodyOpkxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1664319258; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=4pwWAZoUy/AWF7AAjotjTrwZ5Kzq6ua8imvf56tRp4I=; b=RJzVHnqSNSLcQwoWSYdxqVFRgage8uojazSdGkoMPXsNsNkR6kQVHbY8toYEy90cIRIwcnv2dNUG/a6tAgCulbmX5aewnAZqt5usDITjFHbEymnULQ6K/yzOcgUvovrcVwOS873yyc+J/tLnPlO10Z/uH99oL0Yo7Po97eyiyq4= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=shytyi.net; spf=pass smtp.mailfrom=dmytro@shytyi.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1664319258; s=hs; d=shytyi.net; i=dmytro@shytyi.net; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=4pwWAZoUy/AWF7AAjotjTrwZ5Kzq6ua8imvf56tRp4I=; b=JfjtfkKk3DZBlGaSKLzTBWHcfHea2RNEbuZzUtpZPw66PmP1Bal6J9AL2r7IutjP UPNfAYbBHo5b8RKzg6vgl6CiEZ9OuialF8lPPNVnd1zKFG7GhiL9GYaYHpmVAyFg/WE IJAjZA1XeuZePCyQPdgXL4s+aNkszeGOPNirvk48= Received: from localhost.localdomain (243.34.22.93.rev.sfr.net [93.22.34.243]) by mx.zoho.eu with SMTPS id 1664319256917110.94208261457095; Wed, 28 Sep 2022 00:54:16 +0200 (CEST) From: Dmytro Shytyi To: mptcp@lists.linux.dev Cc: Dmytro Shytyi , Benjamin Hesmans Message-ID: <20220927225341.14165-2-dmytro@shytyi.net> Subject: [RFC PATCH mptcp-next v12 1/7] mptcp: introduce MSG_FASTOPEN flag. Date: Tue, 27 Sep 2022 22:53:35 +0000 X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220927225341.14165-1-dmytro@shytyi.net> References: <20220927225341.14165-1-dmytro@shytyi.net> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ZohoMailClient: External In the following patches we will analyse the MSG_FASTOPEN flag in the mptcp_sendmsg() and invoke the MPTFO. Signed-of-by: Benjamin Hesmans Signed-off-by: Dmytro Shytyi --- include/net/mptcp.h | 9 +++++++++ include/net/tcp.h | 3 +++ net/ipv4/tcp.c | 20 ++++++++++++++++---- net/mptcp/protocol.c | 19 +++++++++++-------- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index c25939b2af68..ccf2b42837a1 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -150,6 +150,8 @@ void mptcp_write_options(struct tcphdr *th, __be32 *ptr, struct tcp_sock *tp, struct mptcp_out_options *opts); void mptcp_diag_fill_info(struct mptcp_sock *msk, struct mptcp_info *info); +int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags); +struct sock *mptcp_subflow_conn_sock(struct sock *sk); /* move the skb extension owership, with the assumption that 'to' is * newly allocated @@ -286,6 +288,13 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, static inline void mptcp_space(const struct sock *ssk, int *s, int *fs) { } static inline void mptcp_seq_show(struct seq_file *seq) { } +static inline int mptcp_stream_connect(struct socket *sock, + struct sockaddr *uaddr, + int addr_len, + int flags) +{ + +} static inline int mptcp_subflow_init_cookie_req(struct request_sock *req, const struct sock *sk_listener, diff --git a/include/net/tcp.h b/include/net/tcp.h index 4f71cc15ff8e..e53d26d74dec 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1757,6 +1757,9 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb, struct request_sock *req, struct tcp_fastopen_cookie *foc, const struct dst_entry *dst); +int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, + int *copied, size_t size, + struct ubuf_info *uarg); void tcp_fastopen_init_key_once(struct net *net); bool tcp_fastopen_cookie_check(struct sock *sk, u16 *mss, struct tcp_fastopen_cookie *cookie); diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 5237a3f08c94..daa611671d9a 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1162,8 +1162,9 @@ void tcp_free_fastopen_req(struct tcp_sock *tp) } } -int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, - size_t size, struct ubuf_info *uarg) +int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, + int *copied, size_t size, + struct ubuf_info *uarg) { struct tcp_sock *tp = tcp_sk(sk); struct inet_sock *inet = inet_sk(sk); @@ -1196,8 +1197,19 @@ int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied, } } flags = (msg->msg_flags & MSG_DONTWAIT) ? O_NONBLOCK : 0; - err = __inet_stream_connect(sk->sk_socket, uaddr, - msg->msg_namelen, flags, 1); + if (!sk_is_mptcp(sk)) { + err = __inet_stream_connect(sk->sk_socket, uaddr, + msg->msg_namelen, flags, 1); + } else { + struct sock *parent = mptcp_subflow_conn_sock(sk); + + release_sock(sk); + release_sock(parent); + err = mptcp_stream_connect(sk->sk_socket, uaddr, + msg->msg_namelen, msg->msg_flags); + lock_sock(parent); + lock_sock(sk); + } /* fastopen_req could already be freed in __inet_stream_connect * if the connection times out or gets rst */ diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 8feb684408f7..0db50712bad7 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -58,6 +58,12 @@ static void __mptcp_check_send_data_fin(struct sock *sk); DEFINE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions); static struct net_device mptcp_napi_dev; +struct sock * +mptcp_subflow_conn_sock(struct sock *sk) +{ + return ((mptcp_subflow_ctx(sk))->conn); +} + /* If msk has an initial subflow socket, and the MP_CAPABLE handshake has not * completed yet or has failed, return the subflow socket. * Otherwise return NULL. @@ -1673,17 +1679,14 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) int ret = 0; long timeo; - /* we don't support FASTOPEN yet */ - if (msg->msg_flags & MSG_FASTOPEN) - return -EOPNOTSUPP; - /* silently ignore everything else */ - msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL; + msg->msg_flags &= MSG_MORE | MSG_DONTWAIT | MSG_NOSIGNAL | MSG_FASTOPEN; lock_sock(sk); ssock = __mptcp_nmpc_socket(msk); - if (unlikely(ssock && inet_sk(ssock->sk)->defer_connect)) { + if (unlikely(ssock && (inet_sk(ssock->sk)->defer_connect || + msg->msg_flags & MSG_FASTOPEN))) { struct sock *ssk = ssock->sk; int copied_syn = 0; @@ -3568,8 +3571,8 @@ static void mptcp_subflow_early_fallback(struct mptcp_sock *msk, __mptcp_do_fallback(msk); } -static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, - int addr_len, int flags) +int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, + int addr_len, int flags) { struct mptcp_sock *msk = mptcp_sk(sock->sk); struct mptcp_subflow_context *subflow;