Skip to content

Commit

Permalink
net/tcp: Set the default TCP MSS to the value required by RFC 879 and…
Browse files Browse the repository at this point in the history
… never change it under any circumstance unless the remote host requests a larger MSS via an option the TCP header.
  • Loading branch information
gregory-nutt committed Jul 5, 2018
1 parent f39c611 commit 73c4b16
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 deletions.
45 changes: 28 additions & 17 deletions include/nuttx/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,40 +107,51 @@
#define TCP_MAX_HDRLEN 60 /* Maximum size of TCP header */

#ifdef CONFIG_NET_IPv4
# define IPv4TCP_HDRLEN (TCP_HDRLEN + IPv4_HDRLEN) /* Size of IPv4 + TCP header */
# define IPv4TCP_HDRLEN (TCP_HDRLEN + IPv4_HDRLEN) /* Size of IPv4 + TCP header */
#endif

#ifdef CONFIG_NET_IPv6
# define IPv6TCP_HDRLEN (TCP_HDRLEN + IPv6_HDRLEN) /* Size of IPv4 + TCP header */
# define IPv6TCP_HDRLEN (TCP_HDRLEN + IPv6_HDRLEN) /* Size of IPv4 + TCP header */
#endif

/* Initial minimum MSS according to RFC 879
*
* There have been some assumptions made about using other than the
* default size for datagrams with some unfortunate results.
* The default TCP Maximum Segment Sizes (MSS) are defined below.is 536. If
* a host wishes to set the maximum segment size to a value other than the
* default, the maximum segment size is specified as a TCP option, initially
* in the TCP SYN packet during the TCP handshake. The value cannot be
* changed after the connection is established.
*
* HOSTS MUST NOT SEND DATAGRAMS LARGER THAN 576 OCTETS UNLESS THEY
* HAVE SPECIFIC KNOWLEDGE THAT THE DESTINATION HOST IS PREPARED TO
* ACCEPT LARGER DATAGRAMS.
* These defaults correspond to the minimum MTU values:
*
* This is a long established rule.
* IPv4: MTU=576; MSS=536 (MTU - IPv4_HDRLEN - TCP_HDRLEN)
* IPv6: MTU=1280; MSS=1200 (MTU - IPv5_HDRLEN - TCP_HDRLEN)
*/

#define TCP_INITIAL_MSS(d,h) (TCP_MSS(d,h) > 576 ? 576 : TCP_MSS(d,h))
#define TCP_DEFAULT_IPv4_MSS 536
#define TCP_DEFAULT_IPv6_MSS 1200

#define MIN_TCP_INITIAL_MSS(h) (__MIN_TCP_MSS(h) > 576 ? 576 : __MIN_TCP_MSS(h))
#define MAX_TCP_INITIAL_MSS(h) (__MAX_TCP_MSS(h) > 576 ? 576 : __MAX_TCP_MSS(h))
/* However, we do need to make allowance for certain links such as SLIP that
* have unusually small MTUs.
*/

#ifdef CONFIG_NET_IPv4
# define TCP_IPv4_INITIAL_MSS(d) TCP_INITIAL_MSS(d,IPv4_HDRLEN)
# define MIN_IPv4_TCP_INITIAL_MSS MIN_TCP_INITIAL_MSS(IPv4_HDRLEN)
# define MAX_IPv4_TCP_INITIAL_MSS MAX_TCP_INITIAL_MSS(IPv4_HDRLEN)
# define TCP_IPv4_INITIAL_MSS(d) \
(TCP_MSS(d,IPv4_HDRLEN) > 536 ? 536 : TCP_MSS(d,IPv4_HDRLEN))

# define MIN_IPv4_TCP_INITIAL_MSS \
(__MIN_TCP_MSS(IPv4_HDRLEN) > 536 ? 536 : __MIN_TCP_MSS(IPv4_HDRLEN))
# define MAX_IPv4_TCP_INITIAL_MSS \
(__MAX_TCP_MSS(IPv4_HDRLEN) > 536 ? 536 : __MAX_TCP_MSS(h))
#endif

#ifdef CONFIG_NET_IPv6
# define TCP_IPv6_INITIAL_MSS(d) TCP_INITIAL_MSS(d,IPv6_HDRLEN)
# define MIN_IPv6_TCP_INITIAL_MSS MIN_TCP_INITIAL_MSS(IPv6_HDRLEN)
# define MAX_IPv6_TCP_INITIAL_MSS MAX_TCP_INITIAL_MSS(IPv6_HDRLEN)
# define TCP_IPv6_INITIAL_MSS(d) \
(TCP_MSS(d,IPv6_HDRLEN) > 1200 ? 1200 : TCP_MSS(d,IPv6_HDRLEN))
# define MIN_IPv6_TCP_INITIAL_MSS \
(__MIN_TCP_MSS(IPv6_HDRLEN) > 1200 ? 1200 : __MIN_TCP_MSS(IPv6_HDRLEN))
# define MAX_IPv6_TCP_INITIAL_MSS \
(__MAX_TCP_MSS(IPv6_HDRLEN) > 1200 ? 1200 : __MAX_TCP_MSS(IPv6_HDRLEN))
#endif

/****************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions net/tcp/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ void tcp_initialize(void);
* Description:
* Find a free TCP/IP connection structure and allocate it
* for use. This is normally something done by the implementation of the
* socket() API but is also called from the driver level when a TCP
* packet is received while "listening"
* socket() API but is also called from the event processing logic when a
* TCP packet is received while "listening"
*
****************************************************************************/

Expand Down
2 changes: 1 addition & 1 deletion net/tcp/tcp_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ void tcp_initialize(void)
* Description:
* Find a free TCP/IP connection structure and allocate it
* for use. This is normally something done by the implementation of the
* socket() API but is also called from the even procressing lock when a
* socket() API but is also called from the event processing logic when a
* TCP packet is received while "listening"
*
****************************************************************************/
Expand Down
27 changes: 1 addition & 26 deletions net/tcp/tcp_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,36 +264,11 @@ static uint16_t psock_connect_eventhandler(FAR struct net_driver_s *dev,

psock_teardown_callbacks(pstate, pstate->tc_result);

/* When we set up the connection structure, we did not know the size
* of the initial MSS. Now that the connection is associated with a
* network device, we now know the size of link layer header and can
* determine the correct initial MSS.
*/

DEBUGASSERT(pstate->tc_conn);

#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (pstate->tc_conn->domain == PF_INET)
#endif
{
pstate->tc_conn->mss = TCP_IPv4_INITIAL_MSS(dev);
}
#endif /* CONFIG_NET_IPv4 */

#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
pstate->tc_conn->mss = TCP_IPv6_INITIAL_MSS(dev);
}
#endif /* CONFIG_NET_IPv6 */

/* We now have to filter all outgoing transfers so that they use only
* the MSS of this device.
*/

DEBUGASSERT(pstate->tc_conn != NULL);
DEBUGASSERT(pstate->tc_conn->dev == NULL ||
pstate->tc_conn->dev == dev);
pstate->tc_conn->dev = dev;
Expand Down

0 comments on commit 73c4b16

Please sign in to comment.