Re: Network link detection

From: Dan Williams
Date: Mon Mar 07 2011 - 14:47:53 EST


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@xxxxxxxxxxx>
> > 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


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/