net/procfs: Fix a design REVISIT from the integration the IFINDEX logic and the existing ifconfig/procfs logic.

This commit is contained in:
Gregory Nutt
2018-06-25 17:42:56 -06:00
parent bdb73a60ca
commit e2c442cdcb
2 changed files with 22 additions and 13 deletions
+19 -13
View File
@@ -521,29 +521,35 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir)
else else
#endif #endif
{ {
int ifindex = index - DEV_INDEX; int ifindex;
/* Correct for the fact that the interface is not zero based */
ifindex++;
#ifdef CONFIG_NETDEV_IFINDEX #ifdef CONFIG_NETDEV_IFINDEX
/* Make sure the ifindex is a valid interface index. If not, /* For the first network device, ifindex will be zero. We have
* skip to the next valid index. * to take some special action to get the correct starting
* * ifindex.
* REVISIT: That actual underlying indices may be sparse. The
* way that level1->base.nentries is set-up assumes that
* the indexing is continuous and this may cause entries to be
* lost in the output.
*/ */
ifindex = netdev_nextindex(ifindex); if (level1->ifindex == 0)
{
ifindex = netdev_nextindex(1);
}
else
{
ifindex = netdev_nextindex(level1->ifindex);
}
if (ifindex < 0) if (ifindex < 0)
{ {
/* There are no more... one must have been unregistered */ /* There are no more... one must have been unregistered */
return -ENOENT; return -ENOENT;
} }
level1->ifindex = ifindex + 1;
#else
/* Get the raw index, accounting for 1 based indexing */
ifindex = index - DEV_INDEX + 1;
#endif #endif
/* Find the device corresponding to this device index */ /* Find the device corresponding to this device index */
+3
View File
@@ -97,6 +97,9 @@ struct netprocfs_level1_s
{ {
struct procfs_dir_priv_s base; /* Base directory private data */ struct procfs_dir_priv_s base; /* Base directory private data */
char name[NAME_MAX + 1]; /* Name of last node visited */ char name[NAME_MAX + 1]; /* Name of last node visited */
#ifdef CONFIG_NETDEV_IFINDEX
uint8_t ifindex; /* Next ifindex to visit */
#endif
}; };
/* Line generating function type */ /* Line generating function type */