Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 05 Dec 2013 01:18:26 +0100
From:      Matthias Andree <matthias.andree@gmx.de>
To:        Ian Lepore <ian@FreeBSD.org>
Cc:        freebsd-hackers@FreeBSD.org
Subject:   Re: Asynchronous user-space notification of interface address changes?
Message-ID:  <529FC652.1060004@gmx.de>
In-Reply-To: <1386171248.58852.78.camel@revolution.hippie.lan>
References:  <529EF36A.2020906@gmx.de> <1386171248.58852.78.camel@revolution.hippie.lan>

next in thread | previous in thread | raw e-mail | index | archive | help
Am 04.12.2013 16:34, schrieb Ian Lepore:
> On Wed, 2013-12-04 at 10:18 +0100, Matthias Andree wrote:
>> Greetings,
>>
>> is there any sensible way to have a user-space application notified of
>> interface address changes (in the light of - but not limited to - IPv6
>> automatic configuration, with accept_rtadv or similar), preferably
>> without the application polling getifaddrs every five-ish seconds?
>>
>> It does not appear kevent/kqueue, or devctl, are up to the task.
>>
>> I am not asking for turnkey solutions (although I'll gladly take them),
>> a rough sketch or pointers will suffice.
>>
>> Thanks.
>>
>> Best regards
>> Matthias
> 
> Open a routing socket, select/poll for readability, handle incoming
> RTM_NEWADDR/RTM_DELADDR messages.  Example code in dhclient and faithd
> and I think ntpd among others.  Some info available in man 4 route.
> I've never done this, just remember seeing the code for it in dhclient.

Right on the spot, thank you.

Quick and dirty demo code to decode such messages at
<http://people.freebsd.org/~mandree/try-rtsock.c>; and sent off to the
dnsmasq-discuss mailing list.

I find the part on how exactly the message addresses are laid out a bit
too terse in route(4) and had to spy into natd.c to figure it out.
Perhaps I've overlooked something, but rounding up the sockaddr to the
next multiple of sizeof(long), or second-guessing to use sizeof(long) if
the length is 0, was not obvious to me from that manual page, or the
includes.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?529FC652.1060004>