From a5cdc4e69bbde7042d40fb8649fa9e4195dfbdcb Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 5 Jul 2021 17:03:15 +0800 Subject: [PATCH] net/tcp: change the tcp optdata to dynamic arrays Signed-off-by: chao.an --- include/nuttx/net/tcp.h | 2 +- net/tcp/tcp_send.c | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/nuttx/net/tcp.h b/include/nuttx/net/tcp.h index e209ea5ef7..9bd37e156a 100644 --- a/include/nuttx/net/tcp.h +++ b/include/nuttx/net/tcp.h @@ -171,7 +171,7 @@ struct tcp_hdr_s uint8_t wnd[2]; uint16_t tcpchksum; uint8_t urgp[2]; - uint8_t optdata[4]; + uint8_t optdata[0]; }; /* The structure holding the TCP/IP statistics that are gathered if diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 8ca9ae226a..0c3747f413 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -628,6 +628,7 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, { struct tcp_hdr_s *tcp; uint16_t tcp_mss; + int16_t optlen = 0; /* Get values that vary with the underlying IP domain */ @@ -642,7 +643,7 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, /* Set the packet length for the TCP Maximum Segment Size */ - dev->d_len = IPv6TCP_HDRLEN + TCP_OPT_MSS_LEN; + dev->d_len = IPv6TCP_HDRLEN; } #endif /* CONFIG_NET_IPv6 */ @@ -657,7 +658,7 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, /* Set the packet length for the TCP Maximum Segment Size */ - dev->d_len = IPv4TCP_HDRLEN + TCP_OPT_MSS_LEN; + dev->d_len = IPv4TCP_HDRLEN; } #endif /* CONFIG_NET_IPv4 */ @@ -669,11 +670,12 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn, /* We send out the TCP Maximum Segment Size option with our ACK. */ - tcp->optdata[0] = TCP_OPT_MSS; - tcp->optdata[1] = TCP_OPT_MSS_LEN; - tcp->optdata[2] = tcp_mss >> 8; - tcp->optdata[3] = tcp_mss & 0xff; - tcp->tcpoffset = ((TCP_HDRLEN + TCP_OPT_MSS_LEN) / 4) << 4; + tcp->optdata[optlen++] = TCP_OPT_MSS; + tcp->optdata[optlen++] = TCP_OPT_MSS_LEN; + tcp->optdata[optlen++] = tcp_mss >> 8; + tcp->optdata[optlen++] = tcp_mss & 0xff; + tcp->tcpoffset = ((TCP_HDRLEN + optlen) / 4) << 4; + dev->d_len += optlen; /* Complete the common portions of the TCP message */