diff --git a/net/socket/recvfrom.c b/net/socket/recvfrom.c index 9b893e0f9b..6b36dc7aa7 100644 --- a/net/socket/recvfrom.c +++ b/net/socket/recvfrom.c @@ -1038,6 +1038,7 @@ static void recvfrom_udp_terminate(FAR struct recvfrom_s *pstate, int result) sem_post(&pstate->rf_sem); } +#endif /* CONFIG_NET_UDP */ /**************************************************************************** * Function: recvfrom_udp_interrupt diff --git a/net/udp/Make.defs b/net/udp/Make.defs index 4cd7b9a1df..3b4d1062af 100644 --- a/net/udp/Make.defs +++ b/net/udp/Make.defs @@ -49,8 +49,8 @@ endif # Transport layer -NET_CSRCS += udp_conn.c udp_devpoll.c udp_send.c udp_input.c udp_callback.c -NET_CSRCS += udp_ipselect.c +NET_CSRCS += udp_conn.c udp_devpoll.c udp_send.c udp_input.c udp_finddev.c +NET_CSRCS += udp_callback.c udp_ipselect.c # Include UDP build support diff --git a/net/udp/udp.h b/net/udp/udp.h index 41c582a63b..fdc46a1709 100644 --- a/net/udp/udp.h +++ b/net/udp/udp.h @@ -334,6 +334,78 @@ int udp_ipv4_input(FAR struct net_driver_s *dev); int udp_ipv6_input(FAR struct net_driver_s *dev); #endif +/**************************************************************************** + * Function: 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). + * + * 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 + +/**************************************************************************** + * Function: 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). + * + * 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 + +/**************************************************************************** + * Function: udp_find_laddr_device + * + * 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); + +/**************************************************************************** + * Function: udp_find_raddr_device + * + * 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); + /**************************************************************************** * Function: udp_callback * diff --git a/net/udp/udp_finddev.c b/net/udp/udp_finddev.c new file mode 100644 index 0000000000..e8b66ad438 --- /dev/null +++ b/net/udp/udp_finddev.c @@ -0,0 +1,237 @@ +/**************************************************************************** + * net/udp/udp_finddev.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 +#if defined(CONFIG_NET) && defined(CONFIG_NET_UDP) + +#include +#include + +#include "netdev/netdev.h" +#include "udp/udp.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: 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). + * + * 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) +{ +#ifdef CONFIG_NETDEV_MULTINIC + FAR struct net_driver_s *dev; + + /* 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. + */ + + return netdev_findby_ipv4addr(conn->u.ipv4.laddr, ipv4addr); + +#else + /* There is only a single network device... the one at the head of the + * g_netdevices list. + */ + + return g_netdevices; +#endif +} +#endif /* CONFIG_NET_IPv4 */ + +/**************************************************************************** + * Function: 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). + * + * 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) +{ +#ifdef CONFIG_NETDEV_MULTINIC + FAR struct net_driver_s *dev; + + /* 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. + */ + + return netdev_findby_ipv6addr(conn->u.ipv6.laddr, ipv6addr); + +#else + /* There is only a single network device... the one at the head of the + * g_netdevices list. + */ + + return g_netdevices; +#endif +} +#endif /* CONFIG_NET_IPv6 */ + +/**************************************************************************** + * Function: udp_find_laddr_device + * + * 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) +{ +#ifdef CONFIG_NETDEV_MULTINIC + FAR struct net_driver_s *dev; + + /* 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 + { + return upd_find_ipv4_device(conn, conn->u.ipv4.laddr); + } +#endif + +#ifdef CONFIG_NET_IPv6 +#ifdef CONFIG_NET_IPv4 + else +#endif + { + return upd_find_ipv6_device(conn, conn->u.ipv6.laddr); + } +#endif + +#else + /* There is only a single network device... the one at the head of the + * g_netdevices list. + */ + + return g_netdevices; +#endif +} + +/**************************************************************************** + * Function: udp_find_raddr_device + * + * 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) +{ +#ifdef CONFIG_NETDEV_MULTINIC + FAR struct net_driver_s *dev; + + /* 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 + { + return upd_find_ipv4_device(conn, conn->u.ipv4.raddr); + } +#endif + +#ifdef CONFIG_NET_IPv6 +#ifdef CONFIG_NET_IPv4 + else +#endif + { + return upd_find_ipv6_device(conn, conn->u.ipv6.raddr); + } +#endif + +#else + /* There is only a single network device... the one at the head of the + * g_netdevices list. + */ + + return g_netdevices; +#endif +} + +#endif /* CONFIG_NET && CONFIG_NET_UDP */ diff --git a/net/udp/udp_sendto.c b/net/udp/udp_sendto.c index cba34bbddf..67ac8dcd16 100644 --- a/net/udp/udp_sendto.c +++ b/net/udp/udp_sendto.c @@ -405,11 +405,6 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, { FAR const struct sockaddr_in *into; - /* Get the device that will service this transfer. This may be the - * same device that the - -conn->u.ipv4.raddr - /* Make sure that the IP address mapping is in the ARP table */ into = (FAR const struct sockaddr_in *)to;