tcp: Extract MSS calculation from tcp_synack

I plan to use it for recv window update decision logic.
This commit is contained in:
YAMAMOTO Takashi 2021-06-01 18:43:24 +09:00 committed by Xiang Xiao
parent 50f415d529
commit 1f6fdf04b7
2 changed files with 59 additions and 4 deletions

View File

@ -962,6 +962,22 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
void tcp_reset(FAR struct net_driver_s *dev);
/****************************************************************************
* Name: tcp_rx_mss
*
* Description:
* Return the MSS to advertize to the peer.
*
* Input Parameters:
* dev - The device driver structure
*
* Returned Value:
* The MSS value.
*
****************************************************************************/
uint16_t tcp_rx_mss(FAR struct net_driver_s *dev);
/****************************************************************************
* Name: tcp_synack
*

View File

@ -552,6 +552,45 @@ void tcp_reset(FAR struct net_driver_s *dev)
tcp_sendcomplete(dev, tcp);
}
/****************************************************************************
* Name: tcp_rx_mss
*
* Description:
* Return the MSS to advertize to the peer.
*
* Input Parameters:
* dev - The device driver structure
*
* Returned Value:
* The MSS value.
*
****************************************************************************/
uint16_t tcp_rx_mss(FAR struct net_driver_s *dev)
{
uint16_t tcp_mss;
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
if (IFF_IS_IPv6(dev->d_flags))
#endif
{
tcp_mss = TCP_IPv6_MSS(dev);
}
#endif /* CONFIG_NET_IPv6 */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
else
#endif
{
tcp_mss = TCP_IPv4_MSS(dev);
}
#endif /* CONFIG_NET_IPv4 */
return tcp_mss;
}
/****************************************************************************
* Name: tcp_synack
*
@ -588,10 +627,9 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
if (IFF_IS_IPv6(dev->d_flags))
#endif
{
/* Get the MSS value and offset TCP header address for this packet */
/* Get the offset TCP header address for this packet */
tcp = TCPIPv6BUF;
tcp_mss = TCP_IPv6_MSS(dev);
/* Set the packet length for the TCP Maximum Segment Size */
@ -604,10 +642,9 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
else
#endif
{
/* Get the MSS value and offset TCP header address for this packet */
/* Get the offset TCP header address for this packet */
tcp = TCPIPv4BUF;
tcp_mss = TCP_IPv4_MSS(dev);
/* Set the packet length for the TCP Maximum Segment Size */
@ -615,6 +652,8 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
}
#endif /* CONFIG_NET_IPv4 */
tcp_mss = tcp_rx_mss(dev);
/* Save the ACK bits */
tcp->flags = ack;