From: Stephen Hemminger <shemminger@linux-foundation.org>
To: David Miller <davem@davemloft.net>
Cc: ak@suse.de, netdev@vger.kernel.org
Subject: [RFC] SIOCGIFCOUNT implementation
Date: Mon, 23 Apr 2007 14:12:26 -0700 [thread overview]
Message-ID: <20070423141226.1c2127ce@localhost.localdomain> (raw)
In-Reply-To: <20070421.104047.41636018.davem@davemloft.net>
Trivial implementation of SIOCGIFCOUNT.
If you search the archives, this was suggested and rejected
6 years ago. But there maybe legacy Unix applications that
could actually use it.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
---
net/core/dev.c | 50 ++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index 4dc93cc..6779aa4 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1987,7 +1987,7 @@ int register_gifconf(unsigned int family, gifconf_func_t * gifconf)
* match. --pb
*/
-static int dev_ifname(struct ifreq __user *arg)
+static int dev_ifname(void __user *arg)
{
struct net_device *dev;
struct ifreq ifr;
@@ -2020,7 +2020,7 @@ static int dev_ifname(struct ifreq __user *arg)
* Thus we will need a 'compatibility mode'.
*/
-static int dev_ifconf(char __user *arg)
+static int dev_ifconf(void __user *arg)
{
struct ifconf ifc;
struct net_device *dev;
@@ -2071,6 +2071,32 @@ static int dev_ifconf(char __user *arg)
return copy_to_user(arg, &ifc, sizeof(struct ifconf)) ? -EFAULT : 0;
}
+/*
+ * Perform SIOCGIFCONF give estimate of number of interfaces.
+ * This show the poor design of Berkeley ioctl interface because number
+ * of interfaces can change at any time.
+ */
+static int dev_ifcount(char __user *arg)
+{
+ struct ifconf ifc;
+ struct net_device *dev;
+ int i, total = 0;
+
+ for (dev = dev_base; dev; dev = dev->next)
+ for (i = 0; i < NPROTO; i++)
+ if (gifconf_list[i]) {
+ int done = gifconf_list[i](dev, NULL, 0);
+ if (done > 0)
+ total += done;
+
+ }
+
+ memset(&ifc, 0, sizeof(ifc));
+ ifc.ifc_len = total;
+ return copy_to_user(arg, &ifc, sizeof(struct ifconf)) ? -EFAULT : 0;
+}
+
+
#ifdef CONFIG_PROC_FS
/*
* This is invoked by the /proc filesystem handler to display a device
@@ -2643,19 +2669,23 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
int ret;
char *colon;
- /* One special case: SIOCGIFCONF takes ifconf argument
- and requires shared lock, because it sleeps writing
- to user space.
- */
+ /* Special case ioctl's that don't relate to a specific device */
+ switch(cmd) {
+ case SIOCGIFCONF:
+ rtnl_lock();
+ ret = dev_ifconf(arg);
+ rtnl_unlock();
+ return ret;
- if (cmd == SIOCGIFCONF) {
+ case SIOCGIFCOUNT:
rtnl_lock();
- ret = dev_ifconf((char __user *) arg);
+ ret = dev_ifcount(arg);
rtnl_unlock();
return ret;
+
+ case SIOCGIFNAME:
+ return dev_ifname(arg);
}
- if (cmd == SIOCGIFNAME)
- return dev_ifname((struct ifreq __user *)arg);
if (copy_from_user(&ifr, arg, sizeof(struct ifreq)))
return -EFAULT;
--
1.5.0.6
next prev parent reply other threads:[~2007-04-23 21:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-20 22:04 SIOCGIFCOUNT Andi Kleen
2007-04-20 22:41 ` SIOCGIFCOUNT David Miller
2007-04-21 9:48 ` SIOCGIFCOUNT Andi Kleen
2007-04-21 17:40 ` SIOCGIFCOUNT David Miller
2007-04-23 21:12 ` Stephen Hemminger [this message]
2007-04-23 21:26 ` [RFC] SIOCGIFCOUNT implementation David Miller
2007-04-23 21:30 ` Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070423141226.1c2127ce@localhost.localdomain \
--to=shemminger@linux-foundation.org \
--cc=ak@suse.de \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).