Skip to content

Commit 6920b85

Browse files
mjmartineaudavem330
authored andcommitted
mptcp: Add mptcp_close_state() helper
This will be used to transition to the appropriate state on close and determine if a DATA_FIN needs to be sent for that state transition. Signed-off-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3721b9b commit 6920b85

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

net/mptcp/protocol.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,33 @@ static void mptcp_subflow_shutdown(struct sock *ssk, int how)
14981498
release_sock(ssk);
14991499
}
15001500

1501+
static const unsigned char new_state[16] = {
1502+
/* current state: new state: action: */
1503+
[0 /* (Invalid) */] = TCP_CLOSE,
1504+
[TCP_ESTABLISHED] = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
1505+
[TCP_SYN_SENT] = TCP_CLOSE,
1506+
[TCP_SYN_RECV] = TCP_FIN_WAIT1 | TCP_ACTION_FIN,
1507+
[TCP_FIN_WAIT1] = TCP_FIN_WAIT1,
1508+
[TCP_FIN_WAIT2] = TCP_FIN_WAIT2,
1509+
[TCP_TIME_WAIT] = TCP_CLOSE, /* should not happen ! */
1510+
[TCP_CLOSE] = TCP_CLOSE,
1511+
[TCP_CLOSE_WAIT] = TCP_LAST_ACK | TCP_ACTION_FIN,
1512+
[TCP_LAST_ACK] = TCP_LAST_ACK,
1513+
[TCP_LISTEN] = TCP_CLOSE,
1514+
[TCP_CLOSING] = TCP_CLOSING,
1515+
[TCP_NEW_SYN_RECV] = TCP_CLOSE, /* should not happen ! */
1516+
};
1517+
1518+
static int mptcp_close_state(struct sock *sk)
1519+
{
1520+
int next = (int)new_state[sk->sk_state];
1521+
int ns = next & TCP_STATE_MASK;
1522+
1523+
inet_sk_state_store(sk, ns);
1524+
1525+
return next & TCP_ACTION_FIN;
1526+
}
1527+
15011528
static void mptcp_close(struct sock *sk, long timeout)
15021529
{
15031530
struct mptcp_subflow_context *subflow, *tmp;

0 commit comments

Comments
 (0)