[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-hackers
Subject:    Re: Asynchronous user-space notification of interface address changes?
From:       Matthias Andree <matthias.andree () gmx ! de>
Date:       2013-12-05 0:18:26
Message-ID: 529FC652.1060004 () gmx ! de
[Download RAW message or body]

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.

_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic