diff --git a/net/netdev/netdev_txnotify.c b/net/netdev/netdev_txnotify.c index b2fc18091b9..3bf5a080198 100644 --- a/net/netdev/netdev_txnotify.c +++ b/net/netdev/netdev_txnotify.c @@ -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 */ diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index 846fa663c20..62dfa05e9f7 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -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 * diff --git a/net/tcp/tcp_appsend.c b/net/tcp/tcp_appsend.c index 1f87f87431c..04e6526ac1e 100644 --- a/net/tcp/tcp_appsend.c +++ b/net/tcp/tcp_appsend.c @@ -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. diff --git a/net/tcp/tcp_close.c b/net/tcp/tcp_close.c index 39b5f802011..63afbe767e9 100644 --- a/net/tcp/tcp_close.c +++ b/net/tcp/tcp_close.c @@ -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 { diff --git a/net/tcp/tcp_devpoll.c b/net/tcp/tcp_devpoll.c index 3d7206c9b43..b01303d89c7 100644 --- a/net/tcp/tcp_devpoll.c +++ b/net/tcp/tcp_devpoll.c @@ -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); diff --git a/net/tcp/tcp_ipselect.c b/net/tcp/tcp_ipselect.c index 370abadb740..bb23bf825ea 100644 --- a/net/tcp/tcp_ipselect.c +++ b/net/tcp/tcp_ipselect.c @@ -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 */ diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 041b07fc1ae..416e0e5f215 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -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. */ diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index 9f095e69f50..5801d87ec19 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -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). diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index f3a9e3fd967..7ebe2cb598c 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -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). diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c index 931c2fd2726..de3ed740a11 100644 --- a/net/tcp/tcp_timer.c +++ b/net/tcp/tcp_timer.c @@ -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);