Skip to contentSkip to conversation

SIOCGIFCOUNT

RFC In review Andi Kleen 3 participants 7 messages Apr 20, 2007 – Apr 23, 2007

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

Hi,

A recent 32bit jdk spews these messages on x86-64

ioctl32(java:3877): Unknown cmd fd(3) cmd(00008938){00} arg(bfa4c844) on socket:[4470216] ..

0x8938 is SIOCGIFCOUNT. As far as I can see it is only defined in sockios.h, but not implemented?

Should it be removed from the include file or implemented?

I probably will add a dummy compat ioctl entry to shut the JDK up at least.

-Andi

maintainer
#1 lore raw

From: Andi Kleen <[email protected]>
Date: Sat, 21 Apr 2007 00:04:51 +0200

Quoted 4 lines

0x8938 is SIOCGIFCOUNT. As far as I can see it is only defined in sockios.h, but not implemented?

Should it be removed from the include file or implemented?

Unless we can be %100 certain not one build will break by removing it, we should keep it around.

Quoted 1 line

I probably will add a dummy compat ioctl entry to shut the JDK up at least.

Yes, but please do this generically so that the warning gets quieted on all compat platforms that might hit this.

Thanks.

author
#2 lore raw
Quoted 10 lines · On Saturday 21 April 2007 00:41:33 David Miller wrote:

From: Andi Kleen <[email protected]>
Date: Sat, 21 Apr 2007 00:04:51 +0200

Quoted 4 lines

0x8938 is SIOCGIFCOUNT. As far as I can see it is only defined in sockios.h, but not implemented?

Should it be removed from the include file or implemented?

Unless we can be %100 certain not one build will break by removing it, we should keep it around.

Ok, but should it not be implemented for the non compat case too? I assume java has some reason to call it.

-Andi

maintainer
#3 lore raw

From: Andi Kleen <[email protected]>
Date: Sat, 21 Apr 2007 11:48:52 +0200

Quoted 7 lines · On Saturday 21 April 2007 00:41:33 David Miller wrote:
Quoted 6 lines

From: Andi Kleen <[email protected]>
Date: Sat, 21 Apr 2007 00:04:51 +0200

Quoted 3 lines

0x8938 is SIOCGIFCOUNT. As far as I can see it is only defined in sockios.h, but not implemented?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Should it be removed from the include file or implemented?

Unless we can be %100 certain not one build will break by removing it, we should keep it around.

Ok, but should it not be implemented for the non compat case too? I assume java has some reason to call it.

It probably just is one of those silly:

#ifdef SIOCGIFCOUNT
	ret = try_to_use_SIOCGIFCOUNT();

#endif

type code blocks that we find in just about every wonky source tree out there.

There is no reason to add an implementation of it, and the compat layer should just return the same error code that the non-compat code will.

#4 lore raw

RFC 1/1 SIOCGIFCOUNT implementation

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.

---
 net/core/dev.c |   50 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 40 insertions(+), 10 deletions(-)
net/core/dev.c +40 -10
index 4dc93cc..6779aa4 100644
@@ -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;
Signature · 1 line
1.5.0.6
maintainer
#5 lore raw

Re: [RFC] SIOCGIFCOUNT implementation

From: Stephen Hemminger <[email protected]>
Date: Mon, 23 Apr 2007 14:12:26 -0700

Quoted 6 lines

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.

It makes no sense given that you can get this information with SIOCGIFCONF by supplying a NULL ifc.ifc_buf buffer. The equivalent of SIOCGIFCOUNT can be obtained by dividing ifc.ifc_len by the size of one interface entry.

Please also tell me what legacy application could actually use this thing when BSD itself doesn't even implement it?

A google code search for SIOCGIFCOUNT is fun too.

In fact SIOCGIFCOUNT aparently got removed in 2.2.x, so let's keep it that way.

There is no reason to add support for this, truly.

author
#6 lore raw

Re: [RFC] SIOCGIFCOUNT implementation

Quoted 3 lines

Please also tell me what legacy application could actually use this thing when BSD itself doesn't even implement it?

Some version of java seems to. I see a lot of:

ioctl32(java:30851): Unknown cmd fd(3) cmd(00008938){00} arg(bfbb87c4) on socket:[334628709]

But just rejecting it is probably ok.

-Andi