netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* looking for help with scanning of IPv6 interfaces
@ 2002-11-15 17:38 Michael Richardson
  2002-11-15 19:00 ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Richardson @ 2002-11-15 17:38 UTC (permalink / raw)
  To: netdev

-----BEGIN PGP SIGNED MESSAGE-----


1) Awhile ago there was a flame war about using SIOCGIFCONF/SIOCGLIFCONF
to get lists of interfaces. This was suggested as being a bad way.

2) bind 9.3snapshot is able to get a list of IPv4 addresses with SIOCGIFCONF,

3) it is not able to get IPv6 addresses with SIOCGLIFCONF.

Marc Andrews, sitting next to me, asked if I knew what the offical magic
was. Can someone point me that officially blessed way to do this?

]       ON HUMILITY: to err is human. To moo, bovine.           |  firewalls  [
]   Michael Richardson, Sandelman Software Works, Ottawa, ON    |net architect[
] mcr@sandelman.ottawa.on.ca http://www.sandelman.ottawa.on.ca/ |device driver[
] panic("Just another Debian GNU/Linux using, kernel hacking, security guy"); [
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
Comment: Finger me for keys

iQCVAwUBPdUxAoqHRg3pndX9AQEp3QQAzdLmpHCTKpQB2i6GKLC/jMts/YxiPpuS
M7gf6xW9Ofoycq5QG28RUSwtkw3BR7sWuGFYBHXstjYau7dyInftCdpdvLA6q3xJ
lOakb35mQBqYBS3yyHjEJX0sUo6S1J5ApkPinnGDaQlpJEQaju/AVAJtun8VovUz
TkbL+BO53zc=
=kG1L
-----END PGP SIGNATURE-----

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

* Re: looking for help with scanning of IPv6 interfaces
  2002-11-15 17:38 looking for help with scanning of IPv6 interfaces Michael Richardson
@ 2002-11-15 19:00 ` Andi Kleen
  2002-11-15 22:46   ` Donald Becker
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2002-11-15 19:00 UTC (permalink / raw)
  To: Michael Richardson; +Cc: netdev

On Fri, Nov 15, 2002 at 12:38:12PM -0500, Michael Richardson wrote:
> 1) Awhile ago there was a flame war about using SIOCGIFCONF/SIOCGLIFCONF
> to get lists of interfaces. This was suggested as being a bad way.
> 
> 2) bind 9.3snapshot is able to get a list of IPv4 addresses with SIOCGIFCONF,
> 
> 3) it is not able to get IPv6 addresses with SIOCGLIFCONF.
> 
> Marc Andrews, sitting next to me, asked if I knew what the offical magic
> was. Can someone point me that officially blessed way to do this?

Physical devices are read using /proc/net/dev

If you want IPv6 addresses you can read and parse /proc/net/if_inet6 

That is the old fashioned way.
 
The new fashioned one is to query them using rtnetlink. You use a RTM_GETADDR
NLM_F_REQUEST query with wildcard (NLM_F_ROOT) to get a full list.
See the netlink,rtnetlink, libnetlink manpages and iproute2 as an example. 
It is easier when you use libnetlink.

-Andi

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

* Re: looking for help with scanning of IPv6 interfaces
  2002-11-15 19:00 ` Andi Kleen
@ 2002-11-15 22:46   ` Donald Becker
  2002-11-15 22:52     ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Donald Becker @ 2002-11-15 22:46 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Michael Richardson, netdev

On Fri, 15 Nov 2002, Andi Kleen wrote:
> On Fri, Nov 15, 2002 at 12:38:12PM -0500, Michael Richardson wrote:
> > 1) Awhile ago there was a flame war about using SIOCGIFCONF/SIOCGLIFCONF
> > to get lists of interfaces. This was suggested as being a bad way.
...
> > Marc Andrews, sitting next to me, asked if I knew what the offical magic
> > was. Can someone point me that officially blessed way to do this?

Here is a comment and our standard snippet of code to do this:
________________
    char linebuf[400];	/* Max possible line is 192 chars. */
    FILE *fp;
    int ifnum;

    /* Yes, the only list of physical network interfaces is /proc/net/dev.
     * Through 2.4.19, there is no other way to get 'dev_base' from the
     * kernel.  The ioctl(..SIOCGIFCONF..) call comes closes, but only
     * returns a value for interfaces once assigned a protocol address.
     */
    fp = fopen("/proc/net/dev", "r");
    if (fp == NULL) {
	fprintf(stderr, "Failed to open /proc/net/dev.\n");
	return 0;
    }

    /* The format of /proc/net/dev is "%6s:%8lu ..." */

    ifnum = 0;
    while (fgets(linebuf, sizeof linebuf, fp) && (ifnum < max_numifs)) {
	struct ifreq ifr, ifrq_index, ifrq_hwaddr;
	char *p, *ifname;
	int flags;

	/* This is approximately sscanf(linebuf, "%s:", ifnamebuf). */
	p = index(linebuf, ':');
	if (!p) continue;
	*p = 0;
	/* Skip leading space. */
	for (ifname = linebuf; isspace(*ifname); ifname++)
	    ;

	strncpy(ifr.ifr_name, ifname, sizeof ifr.ifr_name);
	/* Get the interface flags */
	if (ioctl(sockfd, SIOCGIFFLAGS, &ifr)) {
	    fprintf(stderr, "Failed to get information about network "
		    "interface %s.\n   SIOCGIFFLAGS: %s\n", 
		    ifname, strerror(errno));
	    continue;
	}
	if (ifr.ifr_flags & IFF_LOOPBACK)
	    continue;
	flags = ifr.ifr_flags;

	strncpy(ifrq_index.ifr_name, ifname, sizeof ifr.ifr_name);
	strncpy(ifrq_hwaddr.ifr_name, ifname, sizeof ifr.ifr_name);
	if (ioctl(sockfd, SIOCGIFINDEX, &ifrq_index) < 0
	    || ioctl(sockfd, SIOCGIFHWADDR, &ifrq_hwaddr) < 0 ) {
	    fprintf(stderr, "Failed to get address information for network "
		    "interface %s: %s\n", 
		    ifname, strerror(errno));
	}
________________

> Physical devices are read using /proc/net/dev
...
> That is the old fashioned way.
>  
> The new fashioned one is to query them using rtnetlink. You use a RTM_GETADDR
> NLM_F_REQUEST query with wildcard (NLM_F_ROOT) to get a full list.
> See the netlink,rtnetlink, libnetlink manpages and iproute2 as an example. 
> It is easier when you use libnetlink.

Do you have a snippet of code?
What kernel version does this start working?

Of course for code that needs to work with already deployed systems, you
need to have code for the old method around anyway...

-- 
Donald Becker				becker@scyld.com
Scyld Computing Corporation		http://www.scyld.com
410 Severn Ave. Suite 210		Scyld Beowulf cluster system
Annapolis MD 21403			410-990-9993

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

* Re: looking for help with scanning of IPv6 interfaces
  2002-11-15 22:46   ` Donald Becker
@ 2002-11-15 22:52     ` Andi Kleen
  2002-11-19  2:31       ` jamal
  0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2002-11-15 22:52 UTC (permalink / raw)
  To: Donald Becker; +Cc: Andi Kleen, Michael Richardson, netdev

> > Physical devices are read using /proc/net/dev
> ...
> > That is the old fashioned way.
> >  
> > The new fashioned one is to query them using rtnetlink. You use a RTM_GETADDR
> > NLM_F_REQUEST query with wildcard (NLM_F_ROOT) to get a full list.
> > See the netlink,rtnetlink, libnetlink manpages and iproute2 as an example. 
> > It is easier when you use libnetlink.
> 
> Do you have a snippet of code?

Check iproute2 or zebra source. iproute2 has a libnetlink which is quite useful.

I also wrote some manpages (netlink(3),netlink(7),rtnetlink(7) etc, but 
admittedly they are not very good) 

> What kernel version does this start working?

Somewhere in Linux 2.1.<late number> 
> 
> Of course for code that needs to work with already deployed systems, you
> need to have code for the old method around anyway...

Only when you still want to support 2.0. Ok some people do not enable
netlink in their kernel configuration, but many modern distributions
require it for booting now (because the network init scripts use iproute2),
so this shouldn't be a big issue anymore.

-Andi

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

* Re: looking for help with scanning of IPv6 interfaces
  2002-11-15 22:52     ` Andi Kleen
@ 2002-11-19  2:31       ` jamal
  0 siblings, 0 replies; 5+ messages in thread
From: jamal @ 2002-11-19  2:31 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Donald Becker, Michael Richardson, netdev




You forgot the draft, Andi. Although doesnt document every little detail
(someone should) -- it goes a long way to describe the architecture and
concepts behind netlink.
A not final version:
ftp://oa.znyx.com/pub/jamal/draft-ietf-forces-netlink-04.txt

cheers,
jamal

On Fri, 15 Nov 2002, Andi Kleen wrote:

> > > Physical devices are read using /proc/net/dev
> > ...
> > > That is the old fashioned way.
> > >
> > > The new fashioned one is to query them using rtnetlink. You use a RTM_GETADDR
> > > NLM_F_REQUEST query with wildcard (NLM_F_ROOT) to get a full list.
> > > See the netlink,rtnetlink, libnetlink manpages and iproute2 as an example.
> > > It is easier when you use libnetlink.
> >
> > Do you have a snippet of code?
>
> Check iproute2 or zebra source. iproute2 has a libnetlink which is quite useful.
>
> I also wrote some manpages (netlink(3),netlink(7),rtnetlink(7) etc, but
> admittedly they are not very good)
>
> > What kernel version does this start working?
>
> Somewhere in Linux 2.1.<late number>
> >
> > Of course for code that needs to work with already deployed systems, you
> > need to have code for the old method around anyway...
>
> Only when you still want to support 2.0. Ok some people do not enable
> netlink in their kernel configuration, but many modern distributions
> require it for booting now (because the network init scripts use iproute2),
> so this shouldn't be a big issue anymore.
>
> -Andi
>
>

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

end of thread, other threads:[~2002-11-19  2:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-11-15 17:38 looking for help with scanning of IPv6 interfaces Michael Richardson
2002-11-15 19:00 ` Andi Kleen
2002-11-15 22:46   ` Donald Becker
2002-11-15 22:52     ` Andi Kleen
2002-11-19  2:31       ` jamal

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