From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 5 00:23:41 2013 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A36AA208 for ; Thu, 5 Dec 2013 00:23:41 +0000 (UTC) Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3BA2C1DC0 for ; Thu, 5 Dec 2013 00:23:40 +0000 (UTC) Received: from mandree.no-ip.org ([78.49.75.28]) by mail.gmx.com (mrgmx003) with ESMTPSA (Nemesis) id 0MQhyf-1WB9u23VOv-00U2Bm for ; Thu, 05 Dec 2013 01:18:28 +0100 Received: from [IPv6:::1] (localhost6.localdomain6 [IPv6:::1]) by apollo.emma.line.org (Postfix) with ESMTP id 110B723D02A; Thu, 5 Dec 2013 01:18:27 +0100 (CET) Message-ID: <529FC652.1060004@gmx.de> Date: Thu, 05 Dec 2013 01:18:26 +0100 From: Matthias Andree User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: Ian Lepore Subject: Re: Asynchronous user-space notification of interface address changes? References: <529EF36A.2020906@gmx.de> <1386171248.58852.78.camel@revolution.hippie.lan> In-Reply-To: <1386171248.58852.78.camel@revolution.hippie.lan> X-Enigmail-Version: 1.5.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:kuEcSoy8dmiW1b7DnTdanFu8vYsQQu8cECPW3eiM+Zo4YUo98dO /TQOhxWrS/kUTZv+WADVywvlx2siw+g6QMKs/3udusNnA/aTTMSF5v7iAXvef1eZV4yn//z ZLSBEUPaQ/oQbKV1JTvvJy7USH/UgnuH/8yg0kjHmkv23N+0DoXUgVMOeparuNNiK+nNl7n KL60wfDMVoMnc2+woEgFw== Cc: freebsd-hackers@FreeBSD.org X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Dec 2013 00:23:41 -0000 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 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.