net/tcp: reuse common api to replace some ip select code

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an 2023-01-29 13:11:57 +08:00 committed by Xiang Xiao
parent 2b30f17607
commit 98e1f9c36d
10 changed files with 59 additions and 280 deletions

View File

@ -57,17 +57,9 @@
#ifdef CONFIG_NET_IPv4
void netdev_ipv4_txnotify(in_addr_t lipaddr, in_addr_t ripaddr)
{
FAR struct net_driver_s *dev;
/* Find the device driver that serves the subnet of the remote address */
dev = netdev_findby_ripv4addr(lipaddr, ripaddr);
if (dev && dev->d_txavail)
{
/* Notify the device driver that new TX data is available. */
dev->d_txavail(dev);
}
netdev_txnotify_dev(netdev_findby_ripv4addr(lipaddr, ripaddr));
}
#endif /* CONFIG_NET_IPv4 */
@ -91,17 +83,9 @@ void netdev_ipv4_txnotify(in_addr_t lipaddr, in_addr_t ripaddr)
void netdev_ipv6_txnotify(FAR const net_ipv6addr_t lipaddr,
FAR const net_ipv6addr_t ripaddr)
{
FAR struct net_driver_s *dev;
/* Find the device driver that serves the subnet of the remote address */
dev = netdev_findby_ripv6addr(lipaddr, ripaddr);
if (dev && dev->d_txavail)
{
/* Notify the device driver that new TX data is available. */
dev->d_txavail(dev);
}
netdev_txnotify_dev(netdev_findby_ripv6addr(lipaddr, ripaddr));
}
#endif /* CONFIG_NET_IPv6 */

View File

@ -781,6 +781,16 @@ void tcp_ipv4_select(FAR struct net_driver_s *dev);
void tcp_ipv6_select(FAR struct net_driver_s *dev);
#endif
/****************************************************************************
* Name: tcp_ip_select
*
* Description:
* Configure to send or receive an TCP IPv[4|6] packet for connection
*
****************************************************************************/
void tcp_ip_select(FAR struct tcp_conn_s *conn);
/****************************************************************************
* Name: tcp_setsequence
*

View File

@ -162,25 +162,7 @@ void tcp_appsend(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
* this TCP connection.
*/
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET)
#endif
{
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
hdrlen = IPv4TCP_HDRLEN;
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
DEBUGASSERT(IFF_IS_IPv6(dev->d_flags));
hdrlen = IPv6TCP_HDRLEN;
}
#endif /* CONFIG_NET_IPv6 */
hdrlen = tcpip_hdrsize(conn);
/* Check If the device went down */
@ -298,25 +280,7 @@ void tcp_rexmit(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
* this TCP connection.
*/
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET)
#endif
{
DEBUGASSERT(IFF_IS_IPv4(dev->d_flags));
hdrlen = IPv4TCP_HDRLEN;
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
DEBUGASSERT(IFF_IS_IPv6(dev->d_flags));
hdrlen = IPv6TCP_HDRLEN;
}
#endif /* CONFIG_NET_IPv6 */
hdrlen = tcpip_hdrsize(conn);
/* If the application has data to be sent, or if the incoming packet had
* new data in it, we must send out a packet.

View File

@ -191,53 +191,6 @@ end_wait:
return flags;
}
/****************************************************************************
* Name: tcp_close_txnotify
*
* Description:
* Notify the appropriate device driver that we have data ready to
* be sent (TCP)
*
* Input Parameters:
* psock - Socket state structure
* conn - The TCP connection structure
*
* Returned Value:
* None
*
****************************************************************************/
static inline void tcp_close_txnotify(FAR struct socket *psock,
FAR struct tcp_conn_s *conn)
{
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
/* If both IPv4 and IPv6 support are enabled, then we will need to select
* the device driver using the appropriate IP domain.
*/
if (psock->s_domain == PF_INET)
#endif
{
/* Notify the device driver that send data is available */
netdev_ipv4_txnotify(conn->u.ipv4.laddr, conn->u.ipv4.raddr);
}
#endif /* CONFIG_NET_IPv4 */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else /* if (psock->s_domain == PF_INET6) */
#endif /* CONFIG_NET_IPv4 */
{
/* Notify the device driver that send data is available */
DEBUGASSERT(psock->s_domain == PF_INET6);
netdev_ipv6_txnotify(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
}
#endif /* CONFIG_NET_IPv6 */
}
/****************************************************************************
* Name: tcp_close_disconnect
*
@ -316,7 +269,7 @@ static inline int tcp_close_disconnect(FAR struct socket *psock)
/* Notify the device driver of the availability of TX data */
tcp_close_txnotify(psock, conn);
tcp_send_txnotify(psock, conn);
}
else
{

View File

@ -115,22 +115,8 @@ void tcp_poll(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
* setup may not actually be used.
*/
#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NET_IPv4)
if (conn->domain == PF_INET)
{
tcp_ipv4_select(dev);
}
else
{
tcp_ipv6_select(dev);
}
tcp_ip_select(conn);
#elif defined(CONFIG_NET_IPv4)
tcp_ipv4_select(dev);
#else /* if defined(CONFIG_NET_IPv6) */
tcp_ipv6_select(dev);
#endif
/* Perform the callback */
result = tcp_callback(dev, conn, TCP_POLL);

View File

@ -80,4 +80,31 @@ void tcp_ipv6_select(FAR struct net_driver_s *dev)
}
#endif /* CONFIG_NET_IPv6 */
/****************************************************************************
* Name: tcp_ip_select
*
* Description:
* Configure to send or receive an TCP IPv[4|6] packet for connection
*
****************************************************************************/
void tcp_ip_select(FAR struct tcp_conn_s *conn)
{
#if defined(CONFIG_NET_IPv6) && defined(CONFIG_NET_IPv4)
if (conn->domain == PF_INET)
{
tcp_ipv4_select(conn->dev);
}
else
{
tcp_ipv6_select(conn->dev);
}
#elif defined(CONFIG_NET_IPv4)
tcp_ipv4_select(conn->dev);
#else /* if defined(CONFIG_NET_IPv6) */
tcp_ipv6_select(conn->dev);
#endif
}
#endif /* CONFIG_NET */

View File

@ -575,43 +575,21 @@ void tcp_synack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
return;
}
/* Get values that vary with the underlying IP domain */
/* Get the offset TCP header address for this packet */
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
if (IFF_IS_IPv6(dev->d_flags))
#endif
{
/* Get the offset TCP header address for this packet */
tcp = tcp_header(dev);
tcp = TCPIPv6BUF;
/* Set the packet length for the TCP Maximum Segment Size */
/* Set the packet length for the TCP Maximum Segment Size */
dev->d_len = tcpip_hdrsize(conn);
dev->d_len = IPv6TCP_HDRLEN;
}
#endif /* CONFIG_NET_IPv6 */
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
else
#endif
{
/* Get the offset TCP header address for this packet */
tcp = TCPIPv4BUF;
/* Set the packet length for the TCP Maximum Segment Size */
dev->d_len = IPv4TCP_HDRLEN;
}
#endif /* CONFIG_NET_IPv4 */
/* Set the packet length for the TCP Maximum Segment Size */
tcp_mss = tcp_rx_mss(dev);
/* Save the ACK bits */
tcp->flags = ack;
tcp->flags = ack;
/* We send out the TCP Maximum Segment Size option with our ACK. */

View File

@ -317,48 +317,6 @@ static inline void psock_lost_connection(FAR struct tcp_conn_s *conn,
}
}
/****************************************************************************
* Name: send_ipselect
*
* Description:
* If both IPv4 and IPv6 support are enabled, then we will need to select
* which one to use when generating the outgoing packet. If only one
* domain is selected, then the setup is already in place and we need do
* nothing.
*
* Input Parameters:
* dev - The structure of the network driver that caused the event
* psock - Socket state structure
*
* Returned Value:
* None
*
* Assumptions:
* The network is locked
*
****************************************************************************/
#ifdef NEED_IPDOMAIN_SUPPORT
static inline void send_ipselect(FAR struct net_driver_s *dev,
FAR struct tcp_conn_s *conn)
{
/* Which domain the socket support */
if (conn->domain == PF_INET)
{
/* Select the IPv4 domain */
tcp_ipv4_select(dev);
}
else /* if (conn->domain == PF_INET6) */
{
/* Select the IPv6 domain */
tcp_ipv6_select(dev);
}
}
#endif
/****************************************************************************
* Name: parse_sack
*
@ -774,7 +732,7 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
* place and we need do nothing.
*/
send_ipselect(dev, conn);
tcp_ip_select(conn);
#endif
/* Then set-up to send that amount of data. (this won't actually
* happen until the polling cycle completes).
@ -1043,15 +1001,15 @@ static uint16_t psock_send_eventhandler(FAR struct net_driver_s *dev,
tcp_setsequence(conn->sndseq, TCP_WBSEQNO(wrb) + TCP_WBSENT(wrb));
#ifdef NEED_IPDOMAIN_SUPPORT
#ifdef NEED_IPDOMAIN_SUPPORT
/* If both IPv4 and IPv6 support are enabled, then we will need to
* select which one to use when generating the outgoing packet.
* If only one domain is selected, then the setup is already in
* place and we need do nothing.
*/
send_ipselect(dev, conn);
#endif
tcp_ip_select(conn);
#endif
/* Then set-up to send that amount of data with the offset
* corresponding to the amount of data already sent. (this
* won't actually happen until the polling cycle completes).

View File

@ -101,48 +101,6 @@ struct send_s
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: tcpsend_ipselect
*
* Description:
* If both IPv4 and IPv6 support are enabled, then we will need to select
* which one to use when generating the outgoing packet. If only one
* domain is selected, then the setup is already in place and we need do
* nothing.
*
* Input Parameters:
* dev - The structure of the network driver that caused the event
* pstate - sendto state structure
*
* Returned Value:
* None
*
* Assumptions:
* The network is locked.
*
****************************************************************************/
#ifdef NEED_IPDOMAIN_SUPPORT
static inline void tcpsend_ipselect(FAR struct net_driver_s *dev,
FAR struct tcp_conn_s *conn)
{
/* Which domain does the socket support */
if (conn->domain == PF_INET)
{
/* Select the IPv4 domain */
tcp_ipv4_select(dev);
}
else /* if (conn->domain == PF_INET6) */
{
/* Select the IPv6 domain */
tcp_ipv6_select(dev);
}
}
#endif
/****************************************************************************
* Name: tcpsend_eventhandler
*
@ -319,7 +277,7 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev,
* place and we need do nothing.
*/
tcpsend_ipselect(dev, conn);
tcp_ip_select(conn);
#endif
/* Then set-up to send that amount of data. (this won't actually
* happen until the polling cycle completes).
@ -401,7 +359,7 @@ static uint16_t tcpsend_eventhandler(FAR struct net_driver_s *dev,
* place and we need do nothing.
*/
tcpsend_ipselect(dev, conn);
tcp_ip_select(conn);
#endif
/* Then set-up to send that amount of data. (this won't actually
* happen until the polling cycle completes).

View File

@ -330,30 +330,14 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
/* Set up for the callback. We can't know in advance if the application
* is going to send a IPv4 or an IPv6 packet, so this setup may not
* actually be used. Furthermore, the TCP logic is required to call
* tcp_ipv4_select() or tcp_ipv6_select() prior to sending any packets.
* tcp_ip_select() prior to sending any packets.
* We will try to set the correct value here basic on the binding of
* the connection.
*/
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET)
#endif
{
hdrlen = IPv4TCP_HDRLEN;
tcp_ipv4_select(dev);
}
#endif /* CONFIG_NET_IPv4 */
tcp_ip_select(conn);
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
hdrlen = IPv6TCP_HDRLEN;
tcp_ipv6_select(dev);
}
#endif /* CONFIG_NET_IPv6 */
hdrlen = tcpip_hdrsize(conn);
/* Increase the TCP sequence number */
@ -640,29 +624,6 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
}
else
{
unsigned int tcpiplen;
/* No.. we need to send another probe.
* Get the size of the IP and TCP header.
*/
#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET)
#endif
{
tcpiplen = IPv4_HDRLEN + TCP_HDRLEN;
}
#endif
#ifdef CONFIG_NET_IPv6
#ifdef CONFIG_NET_IPv4
else
#endif
{
tcpiplen = IPv6_HDRLEN + TCP_HDRLEN;
}
#endif
/* And send the probe.
* The packet we send must have these properties:
*
@ -679,7 +640,7 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
saveseq = tcp_getsequence(conn->sndseq);
tcp_setsequence(conn->sndseq, saveseq - 1);
tcp_send(dev, conn, TCP_ACK, tcpiplen);
tcp_send(dev, conn, TCP_ACK, hdrlen);
tcp_setsequence(conn->sndseq, saveseq);