From owner-freebsd-net@freebsd.org Thu Apr 30 16:40:42 2020 Return-Path: Delivered-To: freebsd-net@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8F2292C2881 for ; Thu, 30 Apr 2020 16:40:42 +0000 (UTC) (envelope-from mail@s14u.de) Received: from s14u.de (s14u.de [IPv6:2a01:488:66:1000:57e6:e52:0:1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 49Ch2d3d4Nz3J5K for ; Thu, 30 Apr 2020 16:40:41 +0000 (UTC) (envelope-from mail@s14u.de) Received: from p200300caef39ee00a0c15050aec8212c.dip0.t-ipconnect.de ([2003:ca:ef39:ee00:a0c1:5050:aec8:212c]) by s14u.de with esmtpsa (TLS1.2:ECDHE_ECDSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1jUCEp-0007GY-0P for freebsd-net@freebsd.org; Thu, 30 Apr 2020 18:40:39 +0200 From: Steffen Christgau Subject: Notification about tentative IPv6 address from route socket To: freebsd-net@freebsd.org Message-ID: <4f3a314a-f938-476b-f75e-e495756a5488@s14u.de> Date: Thu, 30 Apr 2020 18:40:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam_score: -1.0 X-Spam_score_int: -9 X-Spam_bar: - X-Spam_report: Spam detection software, running on the system "lvps87-230-14-82.dedicated.hosteurope.de", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Hi everybody, I'm quiet new in developing applications with support for FreeBSD, so please excuse if that question has an obvious answer which I can't see at the moment. I'm developing a small daemon which should detect and handle changes of IP addresses in order to open new sockets and close them when addresses come and go. I implemented this so far by using PF_ROUTE [...] Content analysis details: (-1.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP X-Rspamd-Queue-Id: 49Ch2d3d4Nz3J5K X-Spamd-Bar: + Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of mail@s14u.de designates 2a01:488:66:1000:57e6:e52:0:1 as permitted sender) smtp.mailfrom=mail@s14u.de X-Spamd-Result: default: False [1.97 / 15.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+a]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; DMARC_NA(0.00)[s14u.de]; NEURAL_SPAM_MEDIUM(0.20)[0.201,0]; RCPT_COUNT_ONE(0.00)[1]; IP_SCORE(1.23)[ipnet: 2a01:488::/32(3.71), asn: 20773(2.47), country: DE(-0.02)]; NEURAL_SPAM_LONG(0.84)[0.838,0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:20773, ipnet:2a01:488::/32, country:DE]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Apr 2020 16:40:42 -0000 Hi everybody, I'm quiet new in developing applications with support for FreeBSD, so please excuse if that question has an obvious answer which I can't see at the moment. I'm developing a small daemon which should detect and handle changes of IP addresses in order to open new sockets and close them when addresses come and go. I implemented this so far by using PF_ROUTE sockets on FreeBSD 12.1. This works quiet well and I'm able to see additions and deletions of addresses. For IPv6, however, I get notified about an address which is tentative (I use ifconfig to add an link-local address manually) and I - understandably - cannot bind a socket to that address. While I assume that I can check for the address being tentative with ioctl(fd, SIOCGIFAFLAG_IN6, ...), I'd like to ask the following: 1) Is there a way to get notified about the address being available for usage (i.e. not tentative anymore, not duplicated) without _polling_ via ioctl? My application is currently almost completely event driven and integrating such a repeated timeout based detection of tentative/duplicated addresses appears a little awkward. In addition blocking until the address state changes is not really an option. 2) I know FreeBSD is not Linux, but on Linux with netlink sockets I get notified about a) the address appearing (including flags) and b) some time later the address being not tentative anymore (detectable via flags). I wonder why the route socket on FreeBSD reports an address that is currently hardly to use. On the other hand, I understand that RTM_NEWADDR does exactly what is documented, i.e. to notify about an "address being added to iface". Nevertheless, wouldn't it make sense to tell an application that a change for an address takes place? I couldn't observe such a behavior for IPv6 on FreeBSD. If there is currently no really such notification, the kernel could emit a new message like RTM_ADDRCHANGE or it may repeats the emission of RTM_NEWADDR (which might confuse existing applications). Also the addition of an address flags field to ifa_msghdr message might be beneficial. It would also avoid additional ioctl calls and the boilerplate required around that. Just thinking aloud... However, if there is already a notification-based mechanism to get informed about a ready-to-use IPv6 address, could you please provide me a pointer to that? Looking forward for your responses. Regards, Steffen