Commit 76c42a29 authored by Mat Martineau's avatar Mat Martineau Committed by David S. Miller

mptcp: Use per-subflow storage for DATA_FIN sequence number

Instead of reading the MPTCP-level sequence number when sending DATA_FIN,
store the data in the subflow so it can be safely accessed when the
subflow TCP headers are written to the packet without the MPTCP-level
lock held. This also allows the MPTCP-level socket to close individual
subflows without closing the MPTCP connection.
Signed-off-by: default avatarMat Martineau <mathew.j.martineau@linux.intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1954b860
...@@ -312,7 +312,7 @@ static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow, ...@@ -312,7 +312,7 @@ static void mptcp_write_data_fin(struct mptcp_subflow_context *subflow,
*/ */
ext->use_map = 1; ext->use_map = 1;
ext->dsn64 = 1; ext->dsn64 = 1;
ext->data_seq = mptcp_sk(subflow->conn)->write_seq; ext->data_seq = subflow->data_fin_tx_seq;
ext->subflow_seq = 0; ext->subflow_seq = 0;
ext->data_len = 1; ext->data_len = 1;
} else { } else {
...@@ -354,8 +354,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb, ...@@ -354,8 +354,7 @@ static bool mptcp_established_options_dss(struct sock *sk, struct sk_buff *skb,
if (mpext) if (mpext)
opts->ext_copy = *mpext; opts->ext_copy = *mpext;
if (skb && tcp_fin && if (skb && tcp_fin && subflow->data_fin_tx_enable)
subflow->conn->sk_state != TCP_ESTABLISHED)
mptcp_write_data_fin(subflow, &opts->ext_copy); mptcp_write_data_fin(subflow, &opts->ext_copy);
ret = true; ret = true;
} }
......
...@@ -720,7 +720,8 @@ static void mptcp_cancel_work(struct sock *sk) ...@@ -720,7 +720,8 @@ static void mptcp_cancel_work(struct sock *sk)
sock_put(sk); sock_put(sk);
} }
static void mptcp_subflow_shutdown(struct sock *ssk, int how) static void mptcp_subflow_shutdown(struct sock *ssk, int how,
bool data_fin_tx_enable, u64 data_fin_tx_seq)
{ {
lock_sock(ssk); lock_sock(ssk);
...@@ -733,6 +734,14 @@ static void mptcp_subflow_shutdown(struct sock *ssk, int how) ...@@ -733,6 +734,14 @@ static void mptcp_subflow_shutdown(struct sock *ssk, int how)
tcp_disconnect(ssk, O_NONBLOCK); tcp_disconnect(ssk, O_NONBLOCK);
break; break;
default: default:
if (data_fin_tx_enable) {
struct mptcp_subflow_context *subflow;
subflow = mptcp_subflow_ctx(ssk);
subflow->data_fin_tx_seq = data_fin_tx_seq;
subflow->data_fin_tx_enable = 1;
}
ssk->sk_shutdown |= how; ssk->sk_shutdown |= how;
tcp_shutdown(ssk, how); tcp_shutdown(ssk, how);
break; break;
...@@ -749,6 +758,7 @@ static void mptcp_close(struct sock *sk, long timeout) ...@@ -749,6 +758,7 @@ static void mptcp_close(struct sock *sk, long timeout)
struct mptcp_subflow_context *subflow, *tmp; struct mptcp_subflow_context *subflow, *tmp;
struct mptcp_sock *msk = mptcp_sk(sk); struct mptcp_sock *msk = mptcp_sk(sk);
LIST_HEAD(conn_list); LIST_HEAD(conn_list);
u64 data_fin_tx_seq;
lock_sock(sk); lock_sock(sk);
...@@ -757,11 +767,15 @@ static void mptcp_close(struct sock *sk, long timeout) ...@@ -757,11 +767,15 @@ static void mptcp_close(struct sock *sk, long timeout)
list_splice_init(&msk->conn_list, &conn_list); list_splice_init(&msk->conn_list, &conn_list);
data_fin_tx_seq = msk->write_seq;
release_sock(sk); release_sock(sk);
list_for_each_entry_safe(subflow, tmp, &conn_list, node) { list_for_each_entry_safe(subflow, tmp, &conn_list, node) {
struct sock *ssk = mptcp_subflow_tcp_sock(subflow); struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
subflow->data_fin_tx_seq = data_fin_tx_seq;
subflow->data_fin_tx_enable = 1;
__mptcp_close_ssk(sk, ssk, subflow, timeout); __mptcp_close_ssk(sk, ssk, subflow, timeout);
} }
...@@ -854,7 +868,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err, ...@@ -854,7 +868,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err,
*err = -ENOBUFS; *err = -ENOBUFS;
local_bh_enable(); local_bh_enable();
release_sock(sk); release_sock(sk);
mptcp_subflow_shutdown(newsk, SHUT_RDWR + 1); mptcp_subflow_shutdown(newsk, SHUT_RDWR + 1, 0, 0);
tcp_close(newsk, 0); tcp_close(newsk, 0);
return NULL; return NULL;
} }
...@@ -1309,7 +1323,7 @@ static int mptcp_shutdown(struct socket *sock, int how) ...@@ -1309,7 +1323,7 @@ static int mptcp_shutdown(struct socket *sock, int how)
mptcp_for_each_subflow(msk, subflow) { mptcp_for_each_subflow(msk, subflow) {
struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow); struct sock *tcp_sk = mptcp_subflow_tcp_sock(subflow);
mptcp_subflow_shutdown(tcp_sk, how); mptcp_subflow_shutdown(tcp_sk, how, 1, msk->write_seq);
} }
out_unlock: out_unlock:
......
...@@ -125,7 +125,9 @@ struct mptcp_subflow_context { ...@@ -125,7 +125,9 @@ struct mptcp_subflow_context {
mpc_map : 1, mpc_map : 1,
data_avail : 1, data_avail : 1,
rx_eof : 1, rx_eof : 1,
data_fin_tx_enable : 1,
can_ack : 1; /* only after processing the remote a key */ can_ack : 1; /* only after processing the remote a key */
u64 data_fin_tx_seq;
struct sock *tcp_sock; /* tcp sk backpointer */ struct sock *tcp_sock; /* tcp sk backpointer */
struct sock *conn; /* parent mptcp_sock */ struct sock *conn; /* parent mptcp_sock */
......
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