We have a need to listen for interface up/down events in Linux and the normal way to accomplish this is using a netlink socket (See: netlink(7) - Linux manual page). My question is: does it seem appropriate to build netlink socket support into SwiftNIO?
As an experiment I attempted to create a netlink socket and use
DatagramBootstrap.withBoundSocket to bootstrap this setup. However I ran into "unknown sockaddr family AF_NETLINK" errors. Pushing this even further I added netlink support to
SocketAddress as a simple proof of concept and was able to properly receive and decode netlink messages. The commit for that proof of concept is here: PoC: Add netlink socket address support · Austinpayne/swift-nio@b043722 · GitHub
I realize that normally netlink is received over a raw socket and that my proof of concept breaks the public API so I do not think it is the proper way. I am looking for guidance from the NIO maintainers on how this might be implemented. My initial thoughts are that 1) we would implement a
RawBootstrap class in NIO core that has less strict requirements for the socket address but would support netlink sockets (via
sockaddr_nl) and 2) actual netlink message parsing code would be implemented outside of NIO core, probably in a third-party package.
Thanks for your input!