Before and after an IPv6 address is assigned, it goes through various states, such as tentative address, duplicate address, and preferred address. These address states are applicable to both manually and automatically configured addresses. I have a situation when using network interface in tentative state a request to time of day server blocks indefinitely. (When calling rdate utility from within python script). By experiments I managed to to conclude that calling rdate when tentative state of the interface is the problem.
I see that
ip-monitor
command can be used and found some interesting ideas here with AF_NETLINK socket On Linux: how can I programmatically determine if a NIC interface is enabled and plugged in?
I'm trying to setup some asynchronous call (preferably in python3) which will return once the interface is ready and rdate can resume. And the netlink socket seems just the tool for the problem. Having read this and netlink(7) I see that I need something like
s = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
But I cannot find proper information on which struct fields/device flags to check once got output from socket. In netdevice(7) I found
IFF_UP Interface is running.
But I'm not sure whether this will not be true in tentative state too.
Of course the easy way is just looping with a sleep and checking with
ip a show dev devName
until the state is valid, but I keep it as last resort in case I fail with asynchronous call.