net: tcp2: Add a TIME_WAIT timer and state

In order to support TIME_WAIT state during the TCP connection
termination, add a TIME_WAIT timer and the corresponding state.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
This commit is contained in:
Oleg Zhurakivskyy 2020-03-26 11:24:43 +02:00 committed by Jukka Rissanen
commit 52fca0a8d2
2 changed files with 18 additions and 1 deletions

View file

@ -253,6 +253,8 @@ static int tcp_conn_unref(struct tcp *conn)
tcp_send_queue_flush(conn);
k_delayed_work_cancel(&conn->timewait_timer);
tcp_free(conn->src);
tcp_free(conn->dst);
@ -612,6 +614,15 @@ fail:
}
}
static void tcp_timewait_timeout(struct k_work *work)
{
struct tcp *conn = CONTAINER_OF(work, struct tcp, timewait_timer);
NET_DBG("conn: %p %s", conn, log_strdup(tcp_conn_state(conn, NULL)));
tcp_conn_unref(conn);
}
static void tcp_conn_ref(struct tcp *conn)
{
int ref_count = atomic_inc(&conn->ref_count) + 1;
@ -641,6 +652,8 @@ static struct tcp *tcp_conn_alloc(void)
k_delayed_work_init(&conn->send_timer, tcp_send_process);
k_delayed_work_init(&conn->timewait_timer, tcp_timewait_timeout);
tcp_conn_ref(conn);
sys_slist_append(&tcp_conns, (sys_snode_t *)conn);
@ -916,10 +929,13 @@ next_state:
case TCP_CLOSED:
tcp_conn_unref(conn);
break;
case TCP_TIME_WAIT:
case TCP_CLOSING:
case TCP_FIN_WAIT_1:
case TCP_FIN_WAIT_2:
case TCP_TIME_WAIT:
k_delayed_work_submit(&conn->timewait_timer,
K_MSEC(CONFIG_NET_TCP_TIME_WAIT_DELAY));
break;
default:
NET_ASSERT(false, "%s is unimplemented",
tcp_state_to_str(conn->state, true));

View file

@ -135,6 +135,7 @@ struct tcp { /* TCP connection */
sys_slist_t send_queue;
bool in_retransmission;
size_t send_retries;
struct k_delayed_work timewait_timer;
struct net_if *iface;
net_tcp_accept_cb_t accept_cb;
atomic_t ref_count;