LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] Trivial patch for SIOCGIFCOUNT
@ 2001-10-09 13:23 BALBIR SINGH
  2001-10-09 22:37 ` David S. Miller
  0 siblings, 1 reply; 4+ messages in thread
From: BALBIR SINGH @ 2001-10-09 13:23 UTC (permalink / raw)
  To: Alan Cox, Linus Torvalds, linux-kernel, David S. Miller

[-- Attachment #1: Type: text/plain, Size: 2283 bytes --]

Hello Linus, Alan, David,
	To make the API orthogonal, I have included a patch for SIOCGIFCOUNT,
which currently returns -EINVAL. The only reason I am providing this patch
is to make the API complete and make it easier to port applications from
other UNIX like OS'es.

I have verified and am sure that this patch works. The priority of this patch
is not very high, but it would be good to have a orthogonal/complete API.

The patch is against 2.4.2-2 (official rh 7.1). I can provide one against 2.4.10
or 2.4.10-pre16 if required.

--- dev.c.org   Tue Oct  9 18:46:01 2001
+++ dev.c       Tue Oct  9 18:36:39 2001
@@ -1651,6 +1651,40 @@
 }

 /*
+ * Implement the SIOCGIFCOUNT, ioctl to keep the API orthogonal.
+ * Basically taken from dev_ifconf - Balbir
+ */
+static int dev_ifcount(char *arg)
+{
+       struct net_device *dev;
+       int i;
+       unsigned int total;
+
+       total = 0;
+       /*
+        * May be introducing something like for_each_netdev(dev)
+        * on the lines of for_each_pci_dev would be useful here.
+        */
+       for (dev = dev_base; dev != NULL; dev = dev->next) {
+               for (i = 0; i < NPROTO; i++) {
+                       if (gifconf_list[i]) {
+                               int done;
+
+                               done = gifconf_list[i](dev, NULL, 0);
+                               if (done < 0)
+                                       return -EFAULT;
+                               total++;
+                       }
+               }
+       }
+
+       if (copy_to_user(arg, &total, sizeof(int)))
+               return -EFAULT;
+
+       return 0;
+}
+
+/*
  *     This is invoked by the /proc filesystem handler to display a device
  *     in detail.
  */
@@ -2218,6 +2252,18 @@
                rtnl_shunlock();
                return ret;
        }
+
+       /*
+        * We do not need an exclusive lock for returning the count,
+        * shared lock is fine with us.
+        */
+       if (cmd == SIOCGIFCOUNT) {
+               rtnl_shlock();
+               ret = dev_ifcount((char *)arg);
+               rtnl_shunlock();
+               return ret;
+       }
+
        if (cmd == SIOCGIFNAME) {
                return dev_ifname((struct ifreq *)arg);
        }

Comments, rejections, etc
Balbir



[-- Attachment #2: Wipro_Disclaimer.txt --]
[-- Type: text/plain, Size: 853 bytes --]

----------------------------------------------------------------------------------------------------------------------
Information transmitted by this E-MAIL is proprietary to Wipro and/or its Customers and
is intended for use only by the individual or entity to which it is
addressed, and may contain information that is privileged, confidential or
exempt from disclosure under applicable law. If you are not the intended
recipient or it appears that this mail has been forwarded to you without
proper authority, you are notified that any use or dissemination of this
information in any manner is strictly prohibited. In such cases, please
notify us immediately at mailto:mailadmin@wipro.com and delete this mail
from your records.
----------------------------------------------------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Trivial patch for SIOCGIFCOUNT
  2001-10-09 13:23 [PATCH] Trivial patch for SIOCGIFCOUNT BALBIR SINGH
@ 2001-10-09 22:37 ` David S. Miller
  2001-10-10  5:36   ` BALBIR SINGH
  0 siblings, 1 reply; 4+ messages in thread
From: David S. Miller @ 2001-10-09 22:37 UTC (permalink / raw)
  To: balbir.singh; +Cc: alan, torvalds, linux-kernel

   From: "BALBIR SINGH" <balbir.singh@wipro.com>
   Date: Tue, 09 Oct 2001 18:53:47 +0530

   	To make the API orthogonal, I have included a patch for SIOCGIFCOUNT,
   which currently returns -EINVAL. The only reason I am providing this patch
   is to make the API complete and make it easier to port applications from
   other UNIX like OS'es.

There is no need for this change, and _EVEN_ if we put this
change in today every APP out there would _STILL_ need to deal with
all existing kernels which do not have SIOCGIFCOUNT implemented.

Furthermore, SIOCGIFCOUNT also gives no new functionality that does
not exist already.  SIOCGIFCONF with a zero size with give the
behavior necessary to get the same answer as a SIOCGIFCOUNT would
provide.  As far as I am aware, every system providing BSD sockets
provides this SIOCGIFCONF "feature".

Therefore, it is already quite easy to make applications portable
between Linux and other BSD socket based systems.  Simply use the
SIOCGIFCONF method throughout.

Franks a lot,
David S. Miller
davem@redhat.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Trivial patch for SIOCGIFCOUNT
  2001-10-09 22:37 ` David S. Miller
@ 2001-10-10  5:36   ` BALBIR SINGH
  2001-10-10 18:31     ` kuznet
  0 siblings, 1 reply; 4+ messages in thread
From: BALBIR SINGH @ 2001-10-10  5:36 UTC (permalink / raw)
  To: David S. Miller; +Cc: alan, torvalds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1834 bytes --]

David S. Miller wrote:

>   From: "BALBIR SINGH" <balbir.singh@wipro.com>
>   Date: Tue, 09 Oct 2001 18:53:47 +0530
>
>   	To make the API orthogonal, I have included a patch for SIOCGIFCOUNT,
>   which currently returns -EINVAL. The only reason I am providing this patch
>   is to make the API complete and make it easier to port applications from
>   other UNIX like OS'es.
>
>There is no need for this change, and _EVEN_ if we put this
>change in today every APP out there would _STILL_ need to deal with
>all existing kernels which do not have SIOCGIFCOUNT implemented.
>
>Furthermore, SIOCGIFCOUNT also gives no new functionality that does
>not exist already.  SIOCGIFCONF with a zero size with give the
>behavior necessary to get the same answer as a SIOCGIFCOUNT would
>provide.  As far as I am aware, every system providing BSD sockets
>provides this SIOCGIFCONF "feature".
>
>Therefore, it is already quite easy to make applications portable
>between Linux and other BSD socket based systems.  Simply use the
>SIOCGIFCONF method throughout.
>
I had mentioned even earlier, the same functionality can be obtained otherwise.
I was talking about porting from SUN, HP-UX, AIX, etc. I have had people coming
to me and telling me that SIOCGIFNUM (equivalent to SIOCGIFCOUNT) does not exist
and I have had to ask them to use SIOCGIFCONF, if ifc.ifc_len and ifc.ifc_buf set
to '0', to obtain the total size. Again, it is not a must it should be around.
But since the ioctl is there, it might be good to have it work the way some one
reading a man page would expect it to work, or if somebody wanted to port some
application from Sun, HP-UX or AIX would just do

#define SIOCGIFNUM SIOCGIFCOUNT

and get his application to compile without changing the code

Regards,
Balbir

>
>Franks a lot,
>David S. Miller
>davem@redhat.com
>
>




[-- Attachment #2: Wipro_Disclaimer.txt --]
[-- Type: text/plain, Size: 853 bytes --]

----------------------------------------------------------------------------------------------------------------------
Information transmitted by this E-MAIL is proprietary to Wipro and/or its Customers and
is intended for use only by the individual or entity to which it is
addressed, and may contain information that is privileged, confidential or
exempt from disclosure under applicable law. If you are not the intended
recipient or it appears that this mail has been forwarded to you without
proper authority, you are notified that any use or dissemination of this
information in any manner is strictly prohibited. In such cases, please
notify us immediately at mailto:mailadmin@wipro.com and delete this mail
from your records.
----------------------------------------------------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Trivial patch for SIOCGIFCOUNT
  2001-10-10  5:36   ` BALBIR SINGH
@ 2001-10-10 18:31     ` kuznet
  0 siblings, 0 replies; 4+ messages in thread
From: kuznet @ 2001-10-10 18:31 UTC (permalink / raw)
  To: BALBIR SINGH; +Cc: linux-kernel

Hello!

> application from Sun, HP-UX or AIX would just do
> 
> #define SIOCGIFNUM SIOCGIFCOUNT

Grrr.... Listen what the hell did you call this ioctl with _another_ name,
absent both in BSD and in SVR4??? :-)

I remember the patch doing the same thing and I zapped this crap
exactly because it was another linuxish hack moving from bsd api
and not moving closer to svr4.

Alexey

PS. Well, and did you think about one thing: "linux" port of any application
which does not work with linuxes can smell a bit anti-social for many people,
who do not compile from sources. And for all the people, if the port is binary.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-10 18:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-09 13:23 [PATCH] Trivial patch for SIOCGIFCOUNT BALBIR SINGH
2001-10-09 22:37 ` David S. Miller
2001-10-10  5:36   ` BALBIR SINGH
2001-10-10 18:31     ` kuznet

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).