Fix a typo introduced in 1b6990b69f. Also some minor design improvment.

This commit is contained in:
Gregory Nutt 2018-06-22 10:09:47 -06:00
parent 1b6990b69f
commit 66db9f09f6
2 changed files with 77 additions and 138 deletions

View File

@ -477,46 +477,6 @@ int udp_ipv4_input(FAR struct net_driver_s *dev);
int udp_ipv6_input(FAR struct net_driver_s *dev); int udp_ipv6_input(FAR struct net_driver_s *dev);
#endif #endif
/****************************************************************************
* Name: udp_find_ipv4_device
*
* Description:
* Select the network driver to use with the IPv4 UDP transaction.
*
* Input Parameters:
* conn - UDP connection structure (not currently used).
* ipv4addr - The IPv4 address to use in the device selection.
*
* Returned Value:
* A pointer to the network driver to use.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv4
FAR struct net_driver_s *udp_find_ipv4_device(FAR struct udp_conn_s *conn,
in_addr_t ipv4addr);
#endif
/****************************************************************************
* Name: udp_find_ipv6_device
*
* Description:
* Select the network driver to use with the IPv6 UDP transaction.
*
* Input Parameters:
* conn - UDP connection structure (not currently used).
* ipv6addr - The IPv6 address to use in the device selection.
*
* Returned Value:
* A pointer to the network driver to use.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv6
FAR struct net_driver_s *udp_find_ipv6_device(FAR struct udp_conn_s *conn,
net_ipv6addr_t ipv6addr);
#endif
/**************************************************************************** /****************************************************************************
* Name: udp_find_laddr_device * Name: udp_find_laddr_device
* *

View File

@ -53,86 +53,6 @@
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: udp_find_ipv4_device
*
* Description:
* Select the network driver to use with the IPv4 UDP transaction.
*
* Input Parameters:
* conn - UDP connection structure (not currently used).
* ipv4addr - The IPv4 address to use in the device selection.
*
* Returned Value:
* A pointer to the network driver to use.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv4
FAR struct net_driver_s *udp_find_ipv4_device(FAR struct udp_conn_s *conn,
in_addr_t ipv4addr)
{
/* Return NULL if the address is INADDR_ANY. In this case, there may
* be multiple devices that can provide data so the exceptional events
* from any particular device are not important.
*
* Of course, it would be a problem if this is the remote address of
* sendto().
*/
if (net_ipv4addr_cmp(ipv4addr, INADDR_ANY))
{
return NULL;
}
/* We need to select the device that is going to route the UDP packet
* based on the provided IP address.
*/
return netdev_findby_ipv4addr(conn->u.ipv4.laddr, ipv4addr);
}
#endif /* CONFIG_NET_IPv4 */
/****************************************************************************
* Name: udp_find_ipv6_device
*
* Description:
* Select the network driver to use with the IPv6 UDP transaction.
*
* Input Parameters:
* conn - UDP connection structure (not currently used).
* ipv6addr - The IPv6 address to use in the device selection.
*
* Returned Value:
* A pointer to the network driver to use.
*
****************************************************************************/
#ifdef CONFIG_NET_IPv6
FAR struct net_driver_s *udp_find_ipv6_device(FAR struct udp_conn_s *conn,
net_ipv6addr_t ipv6addr)
{
/* Return NULL if the address is IN6ADDR_ANY. In this case, there may
* be multiple devices that can provide data so the exceptional events
* from any particular device are not important.
*
* Of course, it would be a problem if this is the remote address of
* sendto().
*/
if (net_ipv6addr_cmp(ipv6addr, g_ipv6_allzeroaddr))
{
return NULL;
}
/* We need to select the device that is going to route the UDP packet
* based on the provided IP address.
*/
return netdev_findby_ipv6addr(conn->u.ipv6.laddr, ipv6addr);
}
#endif /* CONFIG_NET_IPv6 */
/**************************************************************************** /****************************************************************************
* Name: udp_find_laddr_device * Name: udp_find_laddr_device
* *
@ -140,6 +60,9 @@ FAR struct net_driver_s *udp_find_ipv6_device(FAR struct udp_conn_s *conn,
* Select the network driver to use with the UDP transaction using the * Select the network driver to use with the UDP transaction using the
* locally bound IP address. * locally bound IP address.
* *
* This is currently used in the UDP network poll setup to determine
* which device is being polled.
*
* Input Parameters: * Input Parameters:
* conn - UDP connection structure (not currently used). * conn - UDP connection structure (not currently used).
* *
@ -159,7 +82,20 @@ FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn)
if (conn->domain == PF_INET) if (conn->domain == PF_INET)
#endif #endif
{ {
return udp_find_ipv4_device(conn, conn->u.ipv4.laddr); /* Make sure that the socket is bound to some non-zero, local
* address. Zero is used as an indication that the laddr is
* uninitialized and that the socket is, hence, not bound.
*/
if (conn->u.ipv4.laddr == 0)
{
return NULL;
}
else
{
return netdev_findby_ipv4addr(conn->u.ipv4.laddr,
conn->u.ipv4.laddr);
}
} }
#endif #endif
@ -168,7 +104,20 @@ FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn)
else else
#endif #endif
{ {
return udp_find_ipv6_device(conn, conn->u.ipv6.laddr); /* Make sure that the socket is bound to some non-zero, local
* address. Zero is used as an indication that the laddr is
* uninitialized and that the socket is, hence, not bound.
*/
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr))
{
return NULL;
}
else
{
return netdev_findby_ipv6addr(conn->u.ipv6.laddr,
conn->u.ipv6.laddr);
}
} }
#endif #endif
} }
@ -180,6 +129,9 @@ FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn)
* Select the network driver to use with the UDP transaction using the * Select the network driver to use with the UDP transaction using the
* remote IP address. * remote IP address.
* *
* This function is called for UDP sendto() in order to determine which
* network device that the UDP pack should be sent on.
*
* Input Parameters: * Input Parameters:
* conn - UDP connection structure. * conn - UDP connection structure.
* *
@ -201,22 +153,34 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
{ {
/* Check if the remote, destination address is the broadcast /* Check if the remote, destination address is the broadcast
* or multicast address. In this is the case select the device * or multicast address. In this is the case select the device
* using the locally bound address. * using the locally bound address (assuming that there is one).
*
* REVISIT: This logic is to handle the case where UDP broadcast
* is used when there are multiple devices. In this case we can
* select the device using the bound address address. It is a
* kludge for the unsupported SO_BINDTODEVICE socket option
*/ */
if (conn->u.ipv4.raddr == INADDR_BROADCAST || if (conn->u.ipv4.raddr == INADDR_BROADCAST ||
IN_MULTICAST(conn->u.ipv4.raddr)) IN_MULTICAST(conn->u.ipv4.raddr))
{ {
return udp_find_ipv6_device(conn, conn->u.ipv6.laddr); /* Make sure that the socket is bound to some non-zero, local
* address. Zero is used as an indication that the laddr is
* uninitialized and that the socket is, hence, not bound.
*/
if (conn->u.ipv4.laddr == 0)
{
return NULL;
}
else
{
return netdev_findby_ipv4addr(conn->u.ipv4.laddr,
conn->u.ipv4.laddr);
}
} }
/* Normal lookup using the remote address */
else else
{ {
return udp_find_ipv4_device(conn, conn->u.ipv4.raddr); return netdev_findby_ipv4addr(conn->u.ipv4.laddr,
conn->u.ipv4.raddr);
} }
} }
#endif #endif
@ -228,13 +192,11 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
{ {
/* Check if the remote, destination address is a multicast /* Check if the remote, destination address is a multicast
* address. In this is the case select the device * address. In this is the case select the device
* using the locally bound address. The general form of an * using the locally bound address (assuming that there is one).
* reserved IPv6 multicast address is: ff0x::xx/16.
* *
* REVISIT: This logic is to handle the case where UDP broadcast * The general form of all well-known, reserved IPv6 multicast
* is used when there are multiple devices. In this case we can * addresses is: ff0x::xx/16 (which does not include all possible
* select the device using the bound address address. It is a * multicast addresses).
* kludge for the unsupported SO_BINDTODEVICE socket option
*/ */
if ((conn->u.ipv6.laddr[0] & HTONS(0xfff0)) == HTONS(0xff00) && if ((conn->u.ipv6.laddr[0] & HTONS(0xfff0)) == HTONS(0xff00) &&
@ -242,11 +204,28 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
conn->u.ipv6.laddr[3] == 0 && conn->u.ipv6.laddr[4] == 0 && conn->u.ipv6.laddr[3] == 0 && conn->u.ipv6.laddr[4] == 0 &&
conn->u.ipv6.laddr[5] == 0 && conn->u.ipv6.laddr[6] == 0) conn->u.ipv6.laddr[5] == 0 && conn->u.ipv6.laddr[6] == 0)
{ {
return udp_find_ipv6_device(conn, conn->u.ipv6.laddr); /* Make sure that the socket is bound to some non-zero, local
* address. Zero is used as an indication that the laddr is
* uninitialized and that the socket is, hence, not bound.
*/
if (net_ipv6addr_cmp(conn->u.ipv6.laddr, g_ipv6_allzeroaddr))
{
return NULL;
}
else
{
return netdev_findby_ipv6addr(conn->u.ipv6.laddr,
conn->u.ipv6.laddr);
}
} }
/* Normal lookup using the remote address */
else else
{ {
return udp_find_ipv6_device(conn, conn->u.ipv6.raddr); return netdev_findby_ipv6addr(conn->u.ipv6.laddr,
conn->u.ipv6.raddr);
} }
} }
#endif #endif