mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 23:03:27 +08:00
net/udp: If the interface index of the device bound to a UDP socket is no longer valid because the device has been unregistered, then un-bind the UDP socket.
This commit is contained in:
@@ -470,7 +470,7 @@ static int automount_interrupt(FAR const struct automount_lower_s *lower,
|
|||||||
ret = work_cancel(LPWORK, &priv->work);
|
ret = work_cancel(LPWORK, &priv->work);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* NOTE: Currently, work_cancel only returns success */
|
/* NOTE: Probably -ENOENT which means only that work is not queued. */
|
||||||
|
|
||||||
ferr("ERROR: Failed to cancel work: %d\n", ret);
|
ferr("ERROR: Failed to cancel work: %d\n", ret);
|
||||||
}
|
}
|
||||||
|
|||||||
+60
-42
@@ -49,6 +49,58 @@
|
|||||||
#include "inet/inet.h"
|
#include "inet/inet.h"
|
||||||
#include "udp/udp.h"
|
#include "udp/udp.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: upd_bound_device
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* If the UDP socket is bound to a device, return the reference to the
|
||||||
|
* bound device.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* conn - UDP connection structure (not currently used).
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* A reference to the bound device. If the retained interface index no
|
||||||
|
* longer refers to a valid device, this function will unbind the device
|
||||||
|
* and return NULL
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NET_UDP_BINDTODEVICE
|
||||||
|
FAR struct net_driver_s *upd_bound_device(FAR struct udp_conn_s *conn)
|
||||||
|
{
|
||||||
|
FAR struct net_driver_s *dev = NULL;
|
||||||
|
|
||||||
|
/* Is the UDP socket bound to a device? */
|
||||||
|
|
||||||
|
if (conn->boundto != 0)
|
||||||
|
{
|
||||||
|
/* Yes..This socket has been bound to an interface. Convert the
|
||||||
|
* interface index into a device structure reference.
|
||||||
|
*/
|
||||||
|
|
||||||
|
dev = netdev_findbyindex(conn->boundto);
|
||||||
|
if (dev == NULL)
|
||||||
|
{
|
||||||
|
/* No device? It must have been unregistered. Un-bind the UDP
|
||||||
|
* socket.
|
||||||
|
*/
|
||||||
|
|
||||||
|
conn->bounto = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dev;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define upd_bound_device(c) NULL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -167,17 +219,9 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
|
|||||||
|
|
||||||
if (conn->u.ipv4.laddr == 0) /* INADDR_ANY */
|
if (conn->u.ipv4.laddr == 0) /* INADDR_ANY */
|
||||||
{
|
{
|
||||||
FAR struct net_driver_s *dev = NULL;
|
/* Return the device bound to this UDP socket, if any */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_UDP_BINDTODEVICE
|
return upd_bound_device(conn);
|
||||||
if (conn->boundto != 0)
|
|
||||||
{
|
|
||||||
/* This socket has been bound to an interface */
|
|
||||||
|
|
||||||
dev = netdev_findbyindex(conn->boundto);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return dev;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -199,19 +243,10 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FAR struct net_driver_s *dev = NULL;
|
|
||||||
|
|
||||||
/* Not a suitable IPv4 unicast address for device lookup */
|
/* Not a suitable IPv4 unicast address for device lookup */
|
||||||
|
/* Return the device bound to this UDP socket, if any */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_UDP_BINDTODEVICE
|
return upd_bound_device(conn);
|
||||||
if (conn->boundto != 0)
|
|
||||||
{
|
|
||||||
/* This socket has been bound to an interface */
|
|
||||||
|
|
||||||
dev = netdev_findbyindex(conn->boundto);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return dev;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -236,17 +271,9 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
|
|||||||
|
|
||||||
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
|
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_unspecaddr))
|
||||||
{
|
{
|
||||||
FAR struct net_driver_s *dev = NULL;
|
/* Return the device bound to this UDP socket, if any */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_UDP_BINDTODEVICE
|
return upd_bound_device(conn);
|
||||||
if (conn->boundto != 0)
|
|
||||||
{
|
|
||||||
/* This socket has been bound to an interface */
|
|
||||||
|
|
||||||
dev = netdev_findbyindex(conn->boundto);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return dev;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -268,19 +295,10 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FAR struct net_driver_s *dev = NULL;
|
|
||||||
|
|
||||||
/* Not a suitable IPv6 unicast address for device lookup */
|
/* Not a suitable IPv6 unicast address for device lookup */
|
||||||
|
/* Return the device bound to this UDP socket, if any */
|
||||||
|
|
||||||
#ifdef CONFIG_NET_UDP_BINDTODEVICE
|
return upd_bound_device(conn);
|
||||||
if (conn->boundto != 0)
|
|
||||||
{
|
|
||||||
/* This socket has been bound to an interface */
|
|
||||||
|
|
||||||
dev = netdev_findbyindex(conn->boundto);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return dev;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user