From 9efadaefc1cb0d467c2b98d7a58942805f76c07d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 24 Nov 2019 09:19:54 -0600 Subject: [PATCH] net/tcp: Be consistent with units of TIME_WAIT. Units were unspecified in tcp/Kconfig, but assumed to be in units of half seconds in tcp/timer.h. include/nuttx/netconfig does not indicate the units but is apparently assuming seconds. This commit unifies all delays to clearly specified units of seconds. --- include/nuttx/net/netconfig.h | 12 +++++++++++- net/tcp/Kconfig | 3 ++- net/tcp/tcp_timer.c | 6 +++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h index be06ca31f7..be43760a9a 100644 --- a/include/nuttx/net/netconfig.h +++ b/include/nuttx/net/netconfig.h @@ -533,7 +533,17 @@ # define MIN_TCP_MSS __MIN_TCP_MSS(__IPv6_HDRLEN) #endif -/* How long a connection should stay in the TIME_WAIT state. */ +/* How long a connection should stay in the TIME_WAIT state. + * + * TIME_WAIT is often also known as the 2MSL wait state. This is because + * the socket that transitions to TIME_WAIT stays there for a period that + * is 2 x Maximum Segment Lifetime in duration. The MSL is the maximum + * amount of time that any segment can remain valid on the network before + * being discarded. This time limit is ultimately bounded by the TTL field + * in the IP datagram that is used to transmit the TCP segment. RFC 793 + * specifies MSL as 2 minutes but most systems permit this value to be tuned. + * Here a default of 2 minutes is used, half the value specified by RFC 793. + */ #ifdef CONFIG_NET_TCP_WAIT_TIMEOUT # define TCP_TIME_WAIT_TIMEOUT CONFIG_NET_TCP_WAIT_TIMEOUT diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index a08098d721..e46d64beeb 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -51,7 +51,8 @@ config NET_TCP_WAIT_TIMEOUT int "TIME_WAIT Length of TCP/IP connections" default 120 ---help--- - TIME_WAIT Length of TCP/IP connections (all tasks) + TIME_WAIT Length of TCP/IP connections (all tasks). In units + of seconds. config NET_MAX_LISTENPORTS int "Number of listening ports" diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c index f9c901e494..934dea755d 100644 --- a/net/tcp/tcp_timer.c +++ b/net/tcp/tcp_timer.c @@ -73,7 +73,7 @@ * Input Parameters: * dev - The device driver structure to use in the send operation * conn - The TCP "connection" to poll for TX data - * hsed - The polling interval in halves of a second + * hsec - The polling interval in units of halves of a second * * Returned Value: * None @@ -143,11 +143,11 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, /* Check if the timer exceeds the timeout value */ - if (newtimer >= TCP_TIME_WAIT_TIMEOUT) + if (newtimer >= (TCP_TIME_WAIT_TIMEOUT * HSEC_PER_SEC)) { /* Set the timer to the maximum value */ - conn->timer = TCP_TIME_WAIT_TIMEOUT; + conn->timer = TCP_TIME_WAIT_TIMEOUT * HSEC_PER_SEC; /* The TCP connection was established and, hence, should be bound * to a device. Make sure that the polling device is the one that