Add logic to netdev_findbyaddr() to return the correct network device for the case where a broadcast address is used. This change caused trivial ripples through other files because additional parameters are required for netdev_findbyaddr() when CONFIG_NET_MULTINIC

This commit is contained in:
Gregory Nutt
2014-11-23 11:00:22 -06:00
parent 4f56aeb04e
commit b36dbe1d89
14 changed files with 150 additions and 51 deletions
+21 -4
View File
@@ -94,7 +94,12 @@ FAR struct net_driver_s *netdev_findbyname(FAR const char *ifname);
/* netdev_findbyaddr.c *******************************************************/
#if CONFIG_NSOCKET_DESCRIPTORS > 0
FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t addr);
#ifdef CONFIG_NET_MULTILINK
FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t lipaddr,
const net_ipaddr_t ripaddr);
#else
FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t ripaddr);
#endif
#endif
/* netdev_default.c ***********************************************************/
@@ -106,15 +111,27 @@ FAR struct net_driver_s *netdev_default(void);
/* netdev_txnotify.c *********************************************************/
#if CONFIG_NSOCKET_DESCRIPTORS > 0
void netdev_txnotify(const net_ipaddr_t addr);
# ifdef CONFIG_NET_MULTILINK
void netdev_txnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr);
# else
void netdev_txnotify(const net_ipaddr_t ripaddr);
# endif
#endif
/* netdev_rxnotify.c *********************************************************/
#if CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET_RXAVAIL)
void netdev_rxnotify(const net_ipaddr_t addr);
# ifdef CONFIG_NET_MULTILINK
void netdev_rxnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr);
# else
void netdev_rxnotify(const net_ipaddr_t ripaddr);
# endif
#else
# define netdev_rxnotify(addr)
# ifdef CONFIG_NET_MULTILINK
# define netdev_rxnotify(lipaddr,ripaddr)
# else
# define netdev_rxnotify(ripaddr)
# endif
#endif
/* netdev_count.c ************************************************************/
+58 -28
View File
@@ -49,6 +49,7 @@
#include <nuttx/net/ip.h>
#include "netdev/netdev.h"
#include "devif/devif.h"
#include "route/route.h"
/****************************************************************************
@@ -71,10 +72,6 @@
* Private Functions
****************************************************************************/
/****************************************************************************
* Function: netdev_maskcmp
****************************************************************************/
/****************************************************************************
* Function: netdev_finddevice
*
@@ -84,7 +81,7 @@
* (since a "down" device has no meaningful address).
*
* Parameters:
* addr - Pointer to the remote address of a connection
* ripaddr - Remote address of a connection to use in the lookup
*
* Returned Value:
* Pointer to driver on success; null on failure
@@ -94,7 +91,7 @@
*
****************************************************************************/
static FAR struct net_driver_s *netdev_finddevice(const net_ipaddr_t addr)
static FAR struct net_driver_s *netdev_finddevice(const net_ipaddr_t ripaddr)
{
FAR struct net_driver_s *dev;
@@ -109,7 +106,7 @@ static FAR struct net_driver_s *netdev_finddevice(const net_ipaddr_t addr)
{
/* Yes.. check for an address match (under the netmask) */
if (net_ipaddr_maskcmp(dev->d_ipaddr, addr, dev->d_netmask))
if (net_ipaddr_maskcmp(dev->d_ipaddr, ripaddr, dev->d_netmask))
{
/* Its a match */
@@ -137,7 +134,9 @@ static FAR struct net_driver_s *netdev_finddevice(const net_ipaddr_t addr)
* IP address.
*
* Parameters:
* addr - Pointer to the remote address of a connection
* lipaddr - Local, bound address of a connection. Used only if ripaddr
* is the broadcast address. Used only if CONFIG_NET_MULTILINK.
* ripaddr - Remote address of a connection to use in the lookup
*
* Returned Value:
* Pointer to driver on success; null on failure
@@ -147,7 +146,12 @@ static FAR struct net_driver_s *netdev_finddevice(const net_ipaddr_t addr)
*
****************************************************************************/
FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t addr)
#ifdef CONFIG_NET_MULTILINK
FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t lipaddr,
const net_ipaddr_t ripaddr)
#else
FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t ripaddr)
#endif
{
struct net_driver_s *dev;
#ifdef CONFIG_NET_ROUTE
@@ -155,9 +159,42 @@ FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t addr)
int ret;
#endif
/* First, see if the address maps to the a local network */
/* First, check if this is the broadcast IP address */
dev = netdev_finddevice(addr);
if (net_ipaddr_cmp(ripaddr, g_alloneaddr))
{
#ifdef CONFIG_NET_MULTILINK
/* Yes.. Check the local, bound address. Is it INADDR_ANY? */
if (net_ipaddr_cmp(lipaddr, g_allzeroaddr))
{
/* Yes.. In this case, I think we are supposed to send the
* broadcast packet out ALL local networks. I am not sure
* of that and, in any event, there is nothing we can do
* about that here.
*/
return NULL;
}
else
{
/* Return the device associated with the local address */
return netdev_finddevice(lipaddr);
}
#else
/* If there is only a single, registered network interface, then the
* decision is pretty easy. Use that device and its default router
* address.
*/
return g_netdevices;
#endif
}
/* Check if the address maps to a local network */
dev = netdev_finddevice(ripaddr);
if (dev)
{
return dev;
@@ -171,9 +208,9 @@ FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t addr)
*/
#ifdef CONFIG_NET_IPv6
ret = net_router(addr, router);
ret = net_router(ripaddr, router);
#else
ret = net_router(addr, &router);
ret = net_router(ripaddr, &router);
#endif
if (ret >= 0)
{
@@ -191,27 +228,20 @@ FAR struct net_driver_s *netdev_findbyaddr(const net_ipaddr_t addr)
/* The above lookup will fail if the packet is being sent out of our
* out subnet to a router and there is no routing information.
*
* However, if there is only a single, registered network interface, then
* the decision is pretty easy. Use that device and its default router
* address.
*
* REVISIT: This logic is lame. Also, in the case where the socket is
* bound to INADDRY_ANY, we should return the default network device
* (from netdev_default()).
*/
netdev_semtake();
if (g_netdevices && !g_netdevices->flink)
{
dev = g_netdevices;
}
#ifndef CONFIG_NET_MULTILINK
/* If there is only a single, registered network interface, then the
* decision is pretty easy. Use that device and its default router
* address. Hmmm... it is almost certainly wrong, however.
*/
netdev_semgive();
dev = g_netdevices;
#endif
/* If we will did not find the network device, then we might as well fail
* because we are not configured properly to determine the route to the
* target.
* destination.
*/
return dev;
+13 -4
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* net/netdev/netdev_rxnotify.c
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Copyright (C) 2013-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -81,7 +81,7 @@
* Notify the device driver that the application waits for RX data.
*
* Parameters:
* raddr - The remote address to send the data
* ripaddr - The remote address to send the data
*
* Returned Value:
* None
@@ -91,12 +91,21 @@
*
****************************************************************************/
void netdev_rxnotify(const net_ipaddr_t raddr)
#ifdef CONFIG_NET_MULTILINK
void netdev_rxnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr)
#else
void netdev_rxnotify(const net_ipaddr_t ripaddr)
#endif
{
FAR struct net_driver_s *dev;
/* Find the device driver that serves the subnet of the remote address */
struct net_driver_s *dev = netdev_findbyaddr(raddr);
#ifdef CONFIG_NET_MULTILINK
dev = netdev_findbyaddr(lipaddr, ripaddr);
#else
dev = netdev_findbyaddr(ripaddr);
#endif
if (dev && dev->d_rxavail)
{
+16 -6
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* net/netdev/netdev_txnotify.c
*
* Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2012, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -51,11 +51,11 @@
#include "netdev/netdev.h"
/****************************************************************************
* Definitions
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Priviate Types
* Private Types
****************************************************************************/
/****************************************************************************
@@ -81,7 +81,7 @@
* Notify the device driver that new TX data is available.
*
* Parameters:
* raddr - The remote address to send the data
* ripaddr - The remote address to send the data
*
* Returned Value:
* None
@@ -91,11 +91,21 @@
*
****************************************************************************/
void netdev_txnotify(const net_ipaddr_t raddr)
#ifdef CONFIG_NET_MULTILINK
void netdev_txnotify(const net_ipaddr_t lipaddr, const net_ipaddr_t ripaddr)
#else
void netdev_txnotify(const net_ipaddr_t ripaddr)
#endif
{
FAR struct net_driver_s *dev;
/* Find the device driver that serves the subnet of the remote address */
struct net_driver_s *dev = netdev_findbyaddr(raddr);
#ifdef CONFIG_NET_MULTILINK
dev = netdev_findbyaddr(lipaddr, ripaddr);
#else
dev = netdev_findbyaddr(ripaddr);
#endif
if (dev && dev->d_txavail)
{