Commit 30b172ee authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'mptcp-mptcp-support-for-tcp_fastopen_connect'

Mat Martineau says:

====================
mptcp: MPTCP support for TCP_FASTOPEN_CONNECT

RFC 8684 appendix B describes how to use TCP Fast Open with MPTCP. This
series allows TFO use with MPTCP using the TCP_FASTOPEN_CONNECT socket
option. The scope here is limited to the initiator of the connection -
support for MSG_FASTOPEN and the listener side of the connection will be
in a separate series. The preexisting TCP fastopen code does most of the
work, so these changes mostly involve plumbing MPTCP through to those
TCP functions.

Patch 1 changes the MPTCP socket option code to pass the
TCP_FASTOPEN_CONNECT option through to the initial unconnected subflow.

Patch 2 exports the existing tcp_sendmsg_fastopen() function from tcp.c

Patch 3 adds the call to tcp_sendmsg_fastopen() from the MPTCP send
function.

Patch 4 modifies mptcp_poll() to handle the deferred TFO connection.
====================

Link: https://lore.kernel.org/r/20220926232739.76317-1-mathew.j.martineau@linux.intel.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 63a8bf85 a42cf9d1
...@@ -327,6 +327,8 @@ void tcp_remove_empty_skb(struct sock *sk); ...@@ -327,6 +327,8 @@ void tcp_remove_empty_skb(struct sock *sk);
int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw); int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw);
int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size); int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size);
int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size); int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size);
int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied,
size_t size, struct ubuf_info *uarg);
int tcp_sendpage(struct sock *sk, struct page *page, int offset, size_t size, int tcp_sendpage(struct sock *sk, struct page *page, int offset, size_t size,
int flags); int flags);
int tcp_sendpage_locked(struct sock *sk, struct page *page, int offset, int tcp_sendpage_locked(struct sock *sk, struct page *page, int offset,
......
...@@ -1162,9 +1162,8 @@ void tcp_free_fastopen_req(struct tcp_sock *tp) ...@@ -1162,9 +1162,8 @@ void tcp_free_fastopen_req(struct tcp_sock *tp)
} }
} }
static int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int tcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg, int *copied,
int *copied, size_t size, size_t size, struct ubuf_info *uarg)
struct ubuf_info *uarg)
{ {
struct tcp_sock *tp = tcp_sk(sk); struct tcp_sock *tp = tcp_sk(sk);
struct inet_sock *inet = inet_sk(sk); struct inet_sock *inet = inet_sk(sk);
......
...@@ -1677,6 +1677,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -1677,6 +1677,7 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
{ {
struct mptcp_sock *msk = mptcp_sk(sk); struct mptcp_sock *msk = mptcp_sk(sk);
struct page_frag *pfrag; struct page_frag *pfrag;
struct socket *ssock;
size_t copied = 0; size_t copied = 0;
int ret = 0; int ret = 0;
long timeo; long timeo;
...@@ -1690,6 +1691,27 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) ...@@ -1690,6 +1691,27 @@ static int mptcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
lock_sock(sk); lock_sock(sk);
ssock = __mptcp_nmpc_socket(msk);
if (unlikely(ssock && inet_sk(ssock->sk)->defer_connect)) {
struct sock *ssk = ssock->sk;
int copied_syn = 0;
lock_sock(ssk);
ret = tcp_sendmsg_fastopen(ssk, msg, &copied_syn, len, NULL);
copied += copied_syn;
if (ret == -EINPROGRESS && copied_syn > 0) {
/* reflect the new state on the MPTCP socket */
inet_sk_state_store(sk, inet_sk_state_load(ssk));
release_sock(ssk);
goto out;
} else if (ret) {
release_sock(ssk);
goto out;
}
release_sock(ssk);
}
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) { if ((1 << sk->sk_state) & ~(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) {
...@@ -3526,6 +3548,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr, ...@@ -3526,6 +3548,7 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,
do_connect: do_connect:
err = ssock->ops->connect(ssock, uaddr, addr_len, flags); err = ssock->ops->connect(ssock, uaddr, addr_len, flags);
inet_sk(sock->sk)->defer_connect = inet_sk(ssock->sk)->defer_connect;
sock->state = ssock->state; sock->state = ssock->state;
/* on successful connect, the msk state will be moved to established by /* on successful connect, the msk state will be moved to established by
...@@ -3676,6 +3699,9 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock, ...@@ -3676,6 +3699,9 @@ static __poll_t mptcp_poll(struct file *file, struct socket *sock,
if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) { if (state != TCP_SYN_SENT && state != TCP_SYN_RECV) {
mask |= mptcp_check_readable(msk); mask |= mptcp_check_readable(msk);
mask |= mptcp_check_writeable(msk); mask |= mptcp_check_writeable(msk);
} else if (state == TCP_SYN_SENT && inet_sk(sk)->defer_connect) {
/* cf tcp_poll() note about TFO */
mask |= EPOLLOUT | EPOLLWRNORM;
} }
if (sk->sk_shutdown == SHUTDOWN_MASK || state == TCP_CLOSE) if (sk->sk_shutdown == SHUTDOWN_MASK || state == TCP_CLOSE)
mask |= EPOLLHUP; mask |= EPOLLHUP;
......
...@@ -559,6 +559,7 @@ static bool mptcp_supported_sockopt(int level, int optname) ...@@ -559,6 +559,7 @@ static bool mptcp_supported_sockopt(int level, int optname)
case TCP_NOTSENT_LOWAT: case TCP_NOTSENT_LOWAT:
case TCP_TX_DELAY: case TCP_TX_DELAY:
case TCP_INQ: case TCP_INQ:
case TCP_FASTOPEN_CONNECT:
return true; return true;
} }
...@@ -567,7 +568,7 @@ static bool mptcp_supported_sockopt(int level, int optname) ...@@ -567,7 +568,7 @@ static bool mptcp_supported_sockopt(int level, int optname)
/* TCP_REPAIR, TCP_REPAIR_QUEUE, TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS, /* TCP_REPAIR, TCP_REPAIR_QUEUE, TCP_QUEUE_SEQ, TCP_REPAIR_OPTIONS,
* TCP_REPAIR_WINDOW are not supported, better avoid this mess * TCP_REPAIR_WINDOW are not supported, better avoid this mess
*/ */
/* TCP_FASTOPEN_KEY, TCP_FASTOPEN TCP_FASTOPEN_CONNECT, TCP_FASTOPEN_NO_COOKIE, /* TCP_FASTOPEN_KEY, TCP_FASTOPEN, TCP_FASTOPEN_NO_COOKIE,
* are not supported fastopen is currently unsupported * are not supported fastopen is currently unsupported
*/ */
} }
...@@ -768,6 +769,19 @@ static int mptcp_setsockopt_sol_tcp_defer(struct mptcp_sock *msk, sockptr_t optv ...@@ -768,6 +769,19 @@ static int mptcp_setsockopt_sol_tcp_defer(struct mptcp_sock *msk, sockptr_t optv
return tcp_setsockopt(listener->sk, SOL_TCP, TCP_DEFER_ACCEPT, optval, optlen); return tcp_setsockopt(listener->sk, SOL_TCP, TCP_DEFER_ACCEPT, optval, optlen);
} }
static int mptcp_setsockopt_sol_tcp_fastopen_connect(struct mptcp_sock *msk, sockptr_t optval,
unsigned int optlen)
{
struct socket *sock;
/* Limit to first subflow */
sock = __mptcp_nmpc_socket(msk);
if (!sock)
return -EINVAL;
return tcp_setsockopt(sock->sk, SOL_TCP, TCP_FASTOPEN_CONNECT, optval, optlen);
}
static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
sockptr_t optval, unsigned int optlen) sockptr_t optval, unsigned int optlen)
{ {
...@@ -796,6 +810,8 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, ...@@ -796,6 +810,8 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
return mptcp_setsockopt_sol_tcp_nodelay(msk, optval, optlen); return mptcp_setsockopt_sol_tcp_nodelay(msk, optval, optlen);
case TCP_DEFER_ACCEPT: case TCP_DEFER_ACCEPT:
return mptcp_setsockopt_sol_tcp_defer(msk, optval, optlen); return mptcp_setsockopt_sol_tcp_defer(msk, optval, optlen);
case TCP_FASTOPEN_CONNECT:
return mptcp_setsockopt_sol_tcp_fastopen_connect(msk, optval, optlen);
} }
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -1157,6 +1173,7 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname, ...@@ -1157,6 +1173,7 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname,
case TCP_INFO: case TCP_INFO:
case TCP_CC_INFO: case TCP_CC_INFO:
case TCP_DEFER_ACCEPT: case TCP_DEFER_ACCEPT:
case TCP_FASTOPEN_CONNECT:
return mptcp_getsockopt_first_sf_only(msk, SOL_TCP, optname, return mptcp_getsockopt_first_sf_only(msk, SOL_TCP, optname,
optval, optlen); optval, optlen);
case TCP_INQ: case TCP_INQ:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment