net/procfs and netdev: Fix some problems with ifconfig introduced with last changes. Also picks up one of Sebastien's changes that did not make it it before. net/udp: Fixes a DEBUGASSERT.

This commit is contained in:
Gregory Nutt 2018-06-25 16:55:45 -06:00
parent 65be13bffe
commit c439b93627
4 changed files with 30 additions and 16 deletions

View File

@ -225,7 +225,8 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr,
* Find a previously registered network device by assigned interface index.
*
* Input Parameters:
* ifindex - The interface index
* ifindex - The interface index. This is a one-based index and must be
* greater than zero.
*
* Returned Value:
* Pointer to driver on success; NULL on failure. This function will return
@ -243,7 +244,7 @@ FAR struct net_driver_s *netdev_findbyindex(int ifindex);
*
* Input Parameters:
* ifindex - The first interface index to check. Usually in a traversal
* this would be the previous inteface index plus 1.
* this would be the previous interface index plus 1.
*
* Returned Value:
* The interface index for the next network driver. -ENODEV is returned if

View File

@ -61,7 +61,8 @@
* Find a previously registered network device by assigned interface index.
*
* Input Parameters:
* ifindex - The interface index
* ifindex - The interface index. This is a one-based index and must be
* greater than zero.
*
* Returned Value:
* Pointer to driver on success; NULL on failure. This function will return
@ -80,8 +81,7 @@ FAR struct net_driver_s *netdev_findbyindex(int ifindex)
*/
DEBUGASSERT(ifindex > 0 && ifindex <= MAX_IFINDEX);
ifindex--;
if (ifindex < 0 || ifindex >= MAX_IFINDEX)
if (ifindex < 1 || ifindex > MAX_IFINDEX)
{
return NULL;
}
@ -92,7 +92,7 @@ FAR struct net_driver_s *netdev_findbyindex(int ifindex)
#ifdef CONFIG_NETDEV_IFINDEX
/* Check if this index has been assigned */
if ((g_devset & (1L << ifindex)) == 0)
if ((g_devset & (1L << (ifindex-1))) == 0)
{
/* This index has not been assigned */
@ -115,7 +115,8 @@ FAR struct net_driver_s *netdev_findbyindex(int ifindex)
* causing a given index to be meaningless (unless, of course, the
* caller keeps the network locked).
*/
if (i == ifindex)
if (i == (ifindex - 1))
#endif
{
net_unlock();
@ -135,7 +136,7 @@ FAR struct net_driver_s *netdev_findbyindex(int ifindex)
*
* Input Parameters:
* ifindex - The first interface index to check. Usually in a traversal
* this would be the previous inteface index plus 1.
* this would be the previous interface index plus 1.
*
* Returned Value:
* The interface index for the next network driver. -ENODEV is returned if

View File

@ -521,18 +521,24 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
else
#endif
{
int devndx = index - DEV_INDEX;
int ifindex = index - DEV_INDEX;
/* Correct for the fact that the interface is not zero based */
ifindex++;
#ifdef CONFIG_NETDEV_IFINDEX
/* Make sure the devndx is a valid interface index.
/* Make sure the ifindex is a valid interface index. If not,
* skip to the next valid index.
*
* REVISIT: That actual underlay indices may be space. The
* REVISIT: That actual underlying indices may be sparse. The
* way that level1->base.nentries is set-up assumes that
* the indexing is continuous and may cause entries to be lost.
* the indexing is continuous and this may cause entries to be
* lost in the output.
*/
devndx = netdev_nextindex(devndx);
if (devndx < 0)
ifindex = netdev_nextindex(ifindex);
if (ifindex < 0)
{
/* There are no more... one must have been unregistered */
@ -541,7 +547,13 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
#endif
/* Find the device corresponding to this device index */
dev = netdev_findbyindex(devndx);
dev = netdev_findbyindex(ifindex);
if (dev == NULL)
{
/* What happened? */
return -ENOENT;
}
/* Copy the device statistics file entry */

View File

@ -143,7 +143,7 @@ int udp_setsockopt(FAR struct socket *psock, int option,
ifindex = netdev_nametoindex(value);
if (ifindex >= 0)
{
DEBUGASSERT(ifindex > 0 && ifindex < MAX_IFINDEX);
DEBUGASSERT(ifindex > 0 && ifindex <= MAX_IFINDEX);
conn->boundto = ifindex;
}
else