tcp: accept conn inherits some properties of listener conn

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2023-03-09 12:37:43 +08:00 committed by Xiang Xiao
parent d416ead27c
commit bd4d7a1b76
3 changed files with 41 additions and 24 deletions

View File

@ -597,7 +597,8 @@ int tcp_remote_ipv6_device(FAR struct tcp_conn_s *conn);
****************************************************************************/
FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
FAR struct tcp_hdr_s *tcp);
FAR struct tcp_hdr_s *tcp,
FAR struct tcp_conn_s *listener);
/****************************************************************************
* Name: tcp_selectport

View File

@ -983,7 +983,8 @@ FAR struct tcp_conn_s *tcp_nextconn(FAR struct tcp_conn_s *conn)
****************************************************************************/
FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
FAR struct tcp_hdr_s *tcp)
FAR struct tcp_hdr_s *tcp,
FAR struct tcp_conn_s *listener)
{
FAR struct tcp_conn_s *conn;
uint8_t domain;
@ -1016,9 +1017,6 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
{
FAR struct ipv6_hdr_s *ip = IPv6BUF;
/* Set the IPv6 specific MSS and the IPv6 locally bound address */
conn->mss = TCP_IPv6_INITIAL_MSS(dev);
net_ipv6addr_copy(conn->u.ipv6.raddr, ip->srcipaddr);
net_ipv6addr_copy(conn->u.ipv6.laddr, ip->destipaddr);
@ -1044,9 +1042,6 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
{
FAR struct ipv4_hdr_s *ip = IPv4BUF;
/* Set the IPv6 specific MSS and the IPv4 bound remote address. */
conn->mss = TCP_IPv4_INITIAL_MSS(dev);
net_ipv4addr_copy(conn->u.ipv4.raddr,
net_ip4addr_conv32(ip->srcipaddr));
@ -1086,27 +1081,48 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
return NULL;
}
/* Inherits the necessary fields from listener conn for
* the new connection.
*/
#ifdef CONFIG_NET_SOCKOPTS
conn->sconn.s_rcvtimeo = listener->sconn.s_rcvtimeo;
conn->sconn.s_sndtimeo = listener->sconn.s_sndtimeo;
# ifdef CONFIG_NET_BINDTODEVICE
conn->sconn.s_boundto = listener->sconn.s_boundto;
# endif
#endif
conn->sconn.s_tos = listener->sconn.s_tos;
#if CONFIG_NET_RECV_BUFSIZE > 0
conn->rcv_bufs = listener->rcv_bufs;
#endif
#if CONFIG_NET_SEND_BUFSIZE > 0
conn->snd_bufs = listener->snd_bufs;
#endif
conn->mss = listener->mss;
/* Fill in the necessary fields for the new connection. */
conn->rto = TCP_RTO;
conn->sa = 0;
conn->sv = 4;
conn->nrtx = 0;
conn->lport = tcp->destport;
conn->rport = tcp->srcport;
conn->tcpstateflags = TCP_SYN_RCVD;
conn->rto = TCP_RTO;
conn->sa = 0;
conn->sv = 4;
conn->nrtx = 0;
conn->lport = tcp->destport;
conn->rport = tcp->srcport;
conn->tcpstateflags = TCP_SYN_RCVD;
tcp_initsequence(conn->sndseq);
#if !defined(CONFIG_NET_TCP_WRITE_BUFFERS)
conn->rexmit_seq = tcp_getsequence(conn->sndseq);
conn->rexmit_seq = tcp_getsequence(conn->sndseq);
#endif
conn->tx_unacked = 1;
conn->tx_unacked = 1;
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
conn->expired = 0;
conn->isn = 0;
conn->sent = 0;
conn->sndseq_max = 0;
conn->expired = 0;
conn->isn = 0;
conn->sent = 0;
conn->sndseq_max = 0;
#endif
/* rcvseq should be the seqno from the incoming packet + 1. */

View File

@ -748,9 +748,9 @@ static void tcp_input(FAR struct net_driver_s *dev, uint8_t domain,
#endif
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
if (tcp_islistener(&uaddr, tmp16, domain))
if ((conn = tcp_findlistener(&uaddr, tmp16, domain)) != NULL)
#else
if (tcp_islistener(&uaddr, tmp16))
if ((conn = tcp_findlistener(&uaddr, tmp16)) != NULL)
#endif
{
/* We matched the incoming packet with a connection in LISTEN.
@ -762,7 +762,7 @@ static void tcp_input(FAR struct net_driver_s *dev, uint8_t domain,
* any user application to accept it.
*/
conn = tcp_alloc_accept(dev, tcp);
conn = tcp_alloc_accept(dev, tcp, conn);
if (conn)
{
/* The connection structure was successfully allocated and has