2015-05-29 18:45:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/udp/udp_finddev.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP)
|
|
|
|
|
2015-05-30 17:12:27 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2015-05-29 18:45:41 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
#include <nuttx/net/ip.h>
|
|
|
|
|
|
|
|
#include "netdev/netdev.h"
|
2017-08-07 19:50:50 +02:00
|
|
|
#include "inet/inet.h"
|
2015-05-29 18:45:41 +02:00
|
|
|
#include "udp/udp.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: udp_find_ipv4_device
|
2015-05-29 18:45:41 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Select the network driver to use with the IPv4 UDP transaction.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - UDP connection structure (not currently used).
|
2015-05-30 17:12:27 +02:00
|
|
|
* ipv4addr - The IPv4 address to use in the device selection.
|
2015-05-29 18:45:41 +02:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2015-05-30 17:12:27 +02:00
|
|
|
/* 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.
|
2015-05-29 22:56:44 +02:00
|
|
|
*
|
|
|
|
* Of course, it would be a problem if this is the remote address of
|
|
|
|
* sendto().
|
|
|
|
*/
|
|
|
|
|
2015-05-30 17:12:27 +02:00
|
|
|
if (net_ipv4addr_cmp(ipv4addr, INADDR_ANY))
|
2015-05-29 22:56:44 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-08 22:24:12 +02:00
|
|
|
/* We need to select the device that is going to route the UDP packet
|
|
|
|
* based on the provided IP address.
|
2015-05-29 18:45:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return netdev_findby_ipv4addr(conn->u.ipv4.laddr, ipv4addr);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: udp_find_ipv6_device
|
2015-05-29 18:45:41 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Select the network driver to use with the IPv6 UDP transaction.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - UDP connection structure (not currently used).
|
2015-05-30 17:12:27 +02:00
|
|
|
* ipv6addr - The IPv6 address to use in the device selection.
|
2015-05-29 18:45:41 +02:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
{
|
2015-05-30 17:12:27 +02:00
|
|
|
/* 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.
|
2015-05-29 22:56:44 +02:00
|
|
|
*
|
|
|
|
* Of course, it would be a problem if this is the remote address of
|
|
|
|
* sendto().
|
|
|
|
*/
|
|
|
|
|
2015-05-29 23:16:11 +02:00
|
|
|
if (net_ipv6addr_cmp(ipv6addr, g_ipv6_allzeroaddr))
|
2015-05-29 22:56:44 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-08-08 22:24:12 +02:00
|
|
|
/* We need to select the device that is going to route the UDP packet
|
|
|
|
* based on the provided IP address.
|
2015-05-29 18:45:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return netdev_findby_ipv6addr(conn->u.ipv6.laddr, ipv6addr);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: udp_find_laddr_device
|
2015-05-29 18:45:41 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Select the network driver to use with the UDP transaction using the
|
|
|
|
* locally bound IP address.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - UDP connection structure (not currently used).
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A pointer to the network driver to use.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn)
|
|
|
|
{
|
|
|
|
/* There are multiple network devices. We need to select the device that
|
|
|
|
* is going to route the UDP packet based on the provided IP address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (conn->domain == PF_INET)
|
|
|
|
#endif
|
|
|
|
{
|
2015-05-30 17:12:27 +02:00
|
|
|
return udp_find_ipv4_device(conn, conn->u.ipv4.laddr);
|
2015-05-29 18:45:41 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2015-05-30 17:12:27 +02:00
|
|
|
return udp_find_ipv6_device(conn, conn->u.ipv6.laddr);
|
2015-05-29 18:45:41 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: udp_find_raddr_device
|
2015-05-29 18:45:41 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Select the network driver to use with the UDP transaction using the
|
|
|
|
* remote IP address.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - UDP connection structure (not currently used).
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A pointer to the network driver to use.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn)
|
|
|
|
{
|
2017-08-08 22:24:12 +02:00
|
|
|
/* We need to select the device that is going to route the UDP packet
|
|
|
|
* based on the provided IP address.
|
2015-05-29 18:45:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (conn->domain == PF_INET)
|
|
|
|
#endif
|
|
|
|
{
|
2015-05-30 17:12:27 +02:00
|
|
|
return udp_find_ipv4_device(conn, conn->u.ipv4.raddr);
|
2015-05-29 18:45:41 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2015-05-30 17:12:27 +02:00
|
|
|
return udp_find_ipv6_device(conn, conn->u.ipv6.raddr);
|
2015-05-29 18:45:41 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_UDP */
|