mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
TCP: Fix tcp_findlistner() in dual stack mode
Signed-off-by: Masayuki Ishikawa <masayuki.ishikawa@gmail.com>
This commit is contained in:
@@ -708,7 +708,11 @@ void tcp_listen_initialize(void);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno, uint8_t domain);
|
||||||
|
#else
|
||||||
FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno);
|
FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: tcp_unlisten
|
* Name: tcp_unlisten
|
||||||
@@ -747,7 +751,11 @@ int tcp_listen(FAR struct tcp_conn_s *conn);
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
bool tcp_islistener(uint16_t portno, uint8_t domain);
|
||||||
|
#else
|
||||||
bool tcp_islistener(uint16_t portno);
|
bool tcp_islistener(uint16_t portno);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: tcp_accept_connection
|
* Name: tcp_accept_connection
|
||||||
|
|||||||
@@ -96,6 +96,18 @@ static void tcp_input(FAR struct net_driver_s *dev, unsigned int iplen)
|
|||||||
int len;
|
int len;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
uint8_t domain = PF_UNSPEC;
|
||||||
|
if (iplen == IPv4_HDRLEN)
|
||||||
|
{
|
||||||
|
domain = PF_INET;
|
||||||
|
}
|
||||||
|
else if (iplen == IPv6_HDRLEN)
|
||||||
|
{
|
||||||
|
domain = PF_INET6;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NET_STATISTICS
|
#ifdef CONFIG_NET_STATISTICS
|
||||||
/* Bump up the count of TCP packets received */
|
/* Bump up the count of TCP packets received */
|
||||||
|
|
||||||
@@ -165,7 +177,11 @@ static void tcp_input(FAR struct net_driver_s *dev, unsigned int iplen)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
tmp16 = tcp->destport;
|
tmp16 = tcp->destport;
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
if (tcp_islistener(tmp16, domain))
|
||||||
|
#else
|
||||||
if (tcp_islistener(tmp16))
|
if (tcp_islistener(tmp16))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
/* We matched the incoming packet with a connection in LISTEN.
|
/* We matched the incoming packet with a connection in LISTEN.
|
||||||
* We now need to create a new connection and send a SYNACK in
|
* We now need to create a new connection and send a SYNACK in
|
||||||
@@ -327,7 +343,11 @@ found:
|
|||||||
|
|
||||||
/* Notify the listener for the connection of the reset event */
|
/* Notify the listener for the connection of the reset event */
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
listener = tcp_findlistener(conn->lport, domain);
|
||||||
|
#else
|
||||||
listener = tcp_findlistener(conn->lport);
|
listener = tcp_findlistener(conn->lport);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* We must free this TCP connection structure; this connection
|
/* We must free this TCP connection structure; this connection
|
||||||
* will never be established.
|
* will never be established.
|
||||||
|
|||||||
@@ -77,7 +77,11 @@ static FAR struct tcp_conn_s *tcp_listenports[CONFIG_NET_MAX_LISTENPORTS];
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno, uint8_t domain)
|
||||||
|
#else
|
||||||
FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno)
|
FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
int ndx;
|
int ndx;
|
||||||
|
|
||||||
@@ -90,7 +94,11 @@ FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
FAR struct tcp_conn_s *conn = tcp_listenports[ndx];
|
FAR struct tcp_conn_s *conn = tcp_listenports[ndx];
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
if (conn && conn->lport == portno && conn->domain == domain)
|
||||||
|
#else
|
||||||
if (conn && conn->lport == portno)
|
if (conn && conn->lport == portno)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
/* Yes.. we found a listener on this port */
|
/* Yes.. we found a listener on this port */
|
||||||
|
|
||||||
@@ -183,7 +191,11 @@ int tcp_listen(FAR struct tcp_conn_s *conn)
|
|||||||
|
|
||||||
/* First, check if there is already a socket listening on this port */
|
/* First, check if there is already a socket listening on this port */
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
if (tcp_islistener(conn->lport, conn->domain))
|
||||||
|
#else
|
||||||
if (tcp_islistener(conn->lport))
|
if (tcp_islistener(conn->lport))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
/* Yes, then we must refuse this request */
|
/* Yes, then we must refuse this request */
|
||||||
|
|
||||||
@@ -229,10 +241,17 @@ int tcp_listen(FAR struct tcp_conn_s *conn)
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
bool tcp_islistener(uint16_t portno, uint8_t domain)
|
||||||
|
{
|
||||||
|
return tcp_findlistener(portno, domain) != NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
bool tcp_islistener(uint16_t portno)
|
bool tcp_islistener(uint16_t portno)
|
||||||
{
|
{
|
||||||
return tcp_findlistener(portno) != NULL;
|
return tcp_findlistener(portno) != NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: tcp_accept_connection
|
* Name: tcp_accept_connection
|
||||||
@@ -256,7 +275,11 @@ int tcp_accept_connection(FAR struct net_driver_s *dev,
|
|||||||
* connection.
|
* connection.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
listener = tcp_findlistener(portno, conn->domain);
|
||||||
|
#else
|
||||||
listener = tcp_findlistener(portno);
|
listener = tcp_findlistener(portno);
|
||||||
|
#endif
|
||||||
if (listener != NULL)
|
if (listener != NULL)
|
||||||
{
|
{
|
||||||
/* Yes, there is a listener. Is it accepting connections now? */
|
/* Yes, there is a listener. Is it accepting connections now? */
|
||||||
|
|||||||
@@ -235,7 +235,11 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
|
|||||||
|
|
||||||
/* Find the listener for this connection. */
|
/* Find the listener for this connection. */
|
||||||
|
|
||||||
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
||||||
|
listener = tcp_findlistener(conn->lport, conn->domain);
|
||||||
|
#else
|
||||||
listener = tcp_findlistener(conn->lport);
|
listener = tcp_findlistener(conn->lport);
|
||||||
|
#endif
|
||||||
if (listener != NULL)
|
if (listener != NULL)
|
||||||
{
|
{
|
||||||
/* We call tcp_callback() for the connection with
|
/* We call tcp_callback() for the connection with
|
||||||
|
|||||||
Reference in New Issue
Block a user