From e2c442cdcb84385612bc51e3f07e195a71fb3639 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 25 Jun 2018 17:42:56 -0600 Subject: [PATCH] net/procfs: Fix a design REVISIT from the integration the IFINDEX logic and the existing ifconfig/procfs logic. --- net/procfs/net_procfs.c | 32 +++++++++++++++++++------------- net/procfs/procfs.h | 3 +++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/net/procfs/net_procfs.c b/net/procfs/net_procfs.c index cb36b6f9aa..63fa2a4881 100644 --- a/net/procfs/net_procfs.c +++ b/net/procfs/net_procfs.c @@ -521,29 +521,35 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir) else #endif { - int ifindex = index - DEV_INDEX; - - /* Correct for the fact that the interface is not zero based */ - - ifindex++; + int ifindex; #ifdef CONFIG_NETDEV_IFINDEX - /* Make sure the ifindex is a valid interface index. If not, - * skip to the next valid index. - * - * 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. + /* For the first network device, ifindex will be zero. We have + * to take some special action to get the correct starting + * ifindex. */ - ifindex = netdev_nextindex(ifindex); + if (level1->ifindex == 0) + { + ifindex = netdev_nextindex(1); + } + else + { + ifindex = netdev_nextindex(level1->ifindex); + } + if (ifindex < 0) { /* There are no more... one must have been unregistered */ return -ENOENT; } + + level1->ifindex = ifindex + 1; +#else + /* Get the raw index, accounting for 1 based indexing */ + + ifindex = index - DEV_INDEX + 1; #endif /* Find the device corresponding to this device index */ diff --git a/net/procfs/procfs.h b/net/procfs/procfs.h index 3b80fbbe5a..0b67a214b7 100644 --- a/net/procfs/procfs.h +++ b/net/procfs/procfs.h @@ -97,6 +97,9 @@ struct netprocfs_level1_s { struct procfs_dir_priv_s base; /* Base directory private data */ 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 */