* Network link detection
@ 2011-03-03 19:30 Nico Schümann
2011-03-03 20:03 ` Jesper Juhl
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Nico Schümann @ 2011-03-03 19:30 UTC (permalink / raw)
To: linux-kernel
Dear kernel developers,
currently I'm looking for a way to find out whether a network link went
down or up. Of course there is mii-tool, which can watch devices, too.
So for now, I created a small program that polls the MII_LINK_OK
flag with the SIOCGMIIREG ioctl - the same thing that mii-tools does.
But polling that often for a link change that occurs maybe once in a
month sounds like waste of energy.
Unfortunately, I was not able to find out a way to be notified about
link status changes asynchronously. Is there a way? I'm looking for
something like "inotify for link states".
There are some debug outputs as in drivers/net/natsemi.c:1672
printk(KERN_NOTICE "%s: link up.\n", dev->name);
so it would be quite easy to insert a notification.
If there is no way yet to get these notifications asynchronosly, would
there be real use for it or am I just missing something?
Thanks,
Nico
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: Network link detection
2011-03-03 19:30 Network link detection Nico Schümann
@ 2011-03-03 20:03 ` Jesper Juhl
2011-03-03 20:45 ` richard -rw- weinberger
2011-03-03 21:38 ` Chris Friesen
2011-03-03 22:07 ` Stephen Hemminger
2 siblings, 1 reply; 10+ messages in thread
From: Jesper Juhl @ 2011-03-03 20:03 UTC (permalink / raw)
To: Nico Schümann; +Cc: linux-kernel
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1075 bytes --]
On Thu, 3 Mar 2011, Nico Schümann wrote:
> Dear kernel developers,
>
> currently I'm looking for a way to find out whether a network link went
> down or up. Of course there is mii-tool, which can watch devices, too.
>
> So for now, I created a small program that polls the MII_LINK_OK
> flag with the SIOCGMIIREG ioctl - the same thing that mii-tools does.
> But polling that often for a link change that occurs maybe once in a
> month sounds like waste of energy.
>
> Unfortunately, I was not able to find out a way to be notified about
> link status changes asynchronously. Is there a way? I'm looking for
> something like "inotify for link states".
>
I guess you could use inotify to keep an eye on the 'carrier' file in
sysfs (for example, from my system;
/sys/devices/pci0000:00/0000:00:19.0/net/eth0/carrier )
That file will contain "0" if there is no link and "1" if there is a link.
--
Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
Plain text mails only, please.
Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Network link detection
2011-03-03 20:03 ` Jesper Juhl
@ 2011-03-03 20:45 ` richard -rw- weinberger
0 siblings, 0 replies; 10+ messages in thread
From: richard -rw- weinberger @ 2011-03-03 20:45 UTC (permalink / raw)
To: Jesper Juhl; +Cc: Nico Schümann, linux-kernel
On Thu, Mar 3, 2011 at 9:03 PM, Jesper Juhl <jj@chaosbits.net> wrote:
> On Thu, 3 Mar 2011, Nico Schümann wrote:
>
>> Dear kernel developers,
>>
>> currently I'm looking for a way to find out whether a network link went
>> down or up. Of course there is mii-tool, which can watch devices, too.
>>
>> So for now, I created a small program that polls the MII_LINK_OK
>> flag with the SIOCGMIIREG ioctl - the same thing that mii-tools does.
>> But polling that often for a link change that occurs maybe once in a
>> month sounds like waste of energy.
>>
>> Unfortunately, I was not able to find out a way to be notified about
>> link status changes asynchronously. Is there a way? I'm looking for
>> something like "inotify for link states".
>>
> I guess you could use inotify to keep an eye on the 'carrier' file in
> sysfs (for example, from my system;
> /sys/devices/pci0000:00/0000:00:19.0/net/eth0/carrier )
> That file will contain "0" if there is no link and "1" if there is a link.
Does sysfs support inotify?
I don't think so.
> --
> Jesper Juhl <jj@chaosbits.net> http://www.chaosbits.net/
> Plain text mails only, please.
> Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html
>
--
Thanks,
//richard
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Network link detection
2011-03-03 19:30 Network link detection Nico Schümann
2011-03-03 20:03 ` Jesper Juhl
@ 2011-03-03 21:38 ` Chris Friesen
2011-03-03 22:01 ` David Miller
2011-03-03 22:07 ` Stephen Hemminger
2 siblings, 1 reply; 10+ messages in thread
From: Chris Friesen @ 2011-03-03 21:38 UTC (permalink / raw)
To: Nico Schümann; +Cc: linux-kernel
On 03/03/2011 01:30 PM, Nico Schümann wrote:
> Dear kernel developers,
>
> currently I'm looking for a way to find out whether a network link went
> down or up. Of course there is mii-tool, which can watch devices, too.
>
> Unfortunately, I was not able to find out a way to be notified about
> link status changes asynchronously. Is there a way? I'm looking for
> something like "inotify for link states".
You might look at whether you could write a kernel module to register
for NETDEV_CHANGE notifications and pass that back to userspace.
Chris
--
Chris Friesen
Software Developer
GENBAND
chris.friesen@genband.com
www.genband.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Network link detection
2011-03-03 21:38 ` Chris Friesen
@ 2011-03-03 22:01 ` David Miller
2011-03-03 22:29 ` Nico Schümann
2011-03-03 23:54 ` Chris Friesen
0 siblings, 2 replies; 10+ messages in thread
From: David Miller @ 2011-03-03 22:01 UTC (permalink / raw)
To: chris.friesen; +Cc: dev, linux-kernel, netdev
From: Chris Friesen <chris.friesen@genband.com>
Date: Thu, 03 Mar 2011 15:38:35 -0600
> You might look at whether you could write a kernel module to register
> for NETDEV_CHANGE notifications and pass that back to userspace.
This is the kind of responses you get when you ask networking specific
questions and don't CC: netdev :-/
There is this thing called netlink, you can listen for arbitrary
network state change events on a socket, and get the link state
notifications you are looking for. It's in use by many real
applications like NetworkManager and co.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Network link detection
2011-03-03 22:01 ` David Miller
@ 2011-03-03 22:29 ` Nico Schümann
2011-03-07 19:49 ` Dan Williams
2011-03-03 23:54 ` Chris Friesen
1 sibling, 1 reply; 10+ messages in thread
From: Nico Schümann @ 2011-03-03 22:29 UTC (permalink / raw)
To: David Miller; +Cc: chris.friesen, linux-kernel, netdev
On Thu, Mar 03, 2011 at 02:01:06PM -0800, David Miller wrote:
> From: Chris Friesen <chris.friesen@genband.com>
> Date: Thu, 03 Mar 2011 15:38:35 -0600
>
> > You might look at whether you could write a kernel module to register
> > for NETDEV_CHANGE notifications and pass that back to userspace.
>
> This is the kind of responses you get when you ask networking specific
> questions and don't CC: netdev :-/
>
Thank you for CC.
> There is this thing called netlink, you can listen for arbitrary
> network state change events on a socket, and get the link state
> notifications you are looking for. It's in use by many real
> applications like NetworkManager and co.
That really looks like what I'm looking for. I was already wondering
where NetworkManager gets the link state changes from, but I just
expected it to poll. So now I'll read a bit of documentation and
hopefully get it work.
Thanks to everyone,
Nico
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Network link detection
2011-03-03 22:29 ` Nico Schümann
@ 2011-03-07 19:49 ` Dan Williams
0 siblings, 0 replies; 10+ messages in thread
From: Dan Williams @ 2011-03-07 19:49 UTC (permalink / raw)
To: Nico Schümann; +Cc: David Miller, chris.friesen, linux-kernel, netdev
On Thu, 2011-03-03 at 23:29 +0100, Nico Schümann wrote:
> On Thu, Mar 03, 2011 at 02:01:06PM -0800, David Miller wrote:
> > From: Chris Friesen <chris.friesen@genband.com>
> > Date: Thu, 03 Mar 2011 15:38:35 -0600
> >
> > > You might look at whether you could write a kernel module to register
> > > for NETDEV_CHANGE notifications and pass that back to userspace.
> >
> > This is the kind of responses you get when you ask networking specific
> > questions and don't CC: netdev :-/
> >
>
> Thank you for CC.
>
> > There is this thing called netlink, you can listen for arbitrary
> > network state change events on a socket, and get the link state
> > notifications you are looking for. It's in use by many real
> > applications like NetworkManager and co.
>
> That really looks like what I'm looking for. I was already wondering
> where NetworkManager gets the link state changes from, but I just
> expected it to poll. So now I'll read a bit of documentation and
> hopefully get it work.
http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/nm-netlink-monitor.c
NM uses libnl as the basic library for parsing netlink messages and
handling communication with the kernel. Which is why you'll see a lot
of nl_* calls in there. NM sets up the netlink connection using libnl,
then creates a GIOChannel to handle communication over the netlink
socket. When something comes in (to event_handler()) the code handles
error conditions on the socket, then dispatches to libnl for processing.
libnl then calls back into NM to handle the actual message in
event_msg_ready().
Dan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Network link detection
2011-03-03 22:01 ` David Miller
2011-03-03 22:29 ` Nico Schümann
@ 2011-03-03 23:54 ` Chris Friesen
1 sibling, 0 replies; 10+ messages in thread
From: Chris Friesen @ 2011-03-03 23:54 UTC (permalink / raw)
To: David Miller; +Cc: dev, linux-kernel, netdev
On 03/03/2011 04:01 PM, David Miller wrote:
> From: Chris Friesen <chris.friesen@genband.com>
> Date: Thu, 03 Mar 2011 15:38:35 -0600
>
>> You might look at whether you could write a kernel module to register
>> for NETDEV_CHANGE notifications and pass that back to userspace.
>
> This is the kind of responses you get when you ask networking specific
> questions and don't CC: netdev :-/
My apologies for misleading the original poster. I can only claim a
brain fart since I've actually used rtnetlink for other things.
> There is this thing called netlink, you can listen for arbitrary
> network state change events on a socket, and get the link state
> notifications you are looking for. It's in use by many real
> applications like NetworkManager and co.
For future reference then, to listen for link state notifications you'd
use NETLINK_ROUTE with nl_groups set to RTMGRP_LINK, and the link state
will be signaled in the if_flags field of received messages?
Chris
--
Chris Friesen
Software Developer
GENBAND
chris.friesen@genband.com
www.genband.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Network link detection
2011-03-03 19:30 Network link detection Nico Schümann
2011-03-03 20:03 ` Jesper Juhl
2011-03-03 21:38 ` Chris Friesen
@ 2011-03-03 22:07 ` Stephen Hemminger
2011-03-04 6:35 ` Nico Schümann
2 siblings, 1 reply; 10+ messages in thread
From: Stephen Hemminger @ 2011-03-03 22:07 UTC (permalink / raw)
To: linux-kernel
Simple answer is use netlink. That is what all real services use (NM, Quagga, ...)
Netlink can be hard to parse, so I recommend using a wrapper library.
Simplest example is the link-event example in libmnl
http://www.netfilter.org/projects/libmnl/index.html
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-03-07 19:47 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-03 19:30 Network link detection Nico Schümann
2011-03-03 20:03 ` Jesper Juhl
2011-03-03 20:45 ` richard -rw- weinberger
2011-03-03 21:38 ` Chris Friesen
2011-03-03 22:01 ` David Miller
2011-03-03 22:29 ` Nico Schümann
2011-03-07 19:49 ` Dan Williams
2011-03-03 23:54 ` Chris Friesen
2011-03-03 22:07 ` Stephen Hemminger
2011-03-04 6:35 ` Nico Schümann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox