query whether IP address is bound?

Felipe Gasper felipe at felipegasper.com
Fri Nov 23 15:38:49 UTC 2018


Hi David,

Yeah I was a bit afraid D-Bus wouldn’t be authoritative enough of a source for the information, but I thought it worth asking anyway.

ioctl has the same problem for me as RtNetlink, where it only knows how to list the IP addresses rather than doing a lookup. But, I suppose that’s it.

Thank you!

-FG

> On Nov 23, 2018, at 10:23 AM, David Sommerseth <dbus at lists.topphemmelig.net> wrote:
> 
>> On 23/11/2018 14:59, Felipe Gasper wrote:
>> Hi all,
>> 
>> I’m looking for a way to query whether the (Linux) kernel has a specific
>> IP address bound. Forking is not an option. I’d like to avoid directly
>> enumerating every IP address on the machine, which appears to be the only way
>> that RtNetlink facilitates this. (I’d love to be contradicted on that!)
> 
> I believe this is basically going outside the scope of D-Bus itself, but I've
> played with similar things as I did some contribution to python-ethtool way
> too many years ago.
> 
> Basically, the Linux kernel provides two ways to retrieve IP and network
> configurations. You've found one, using Netlink and the other one is an older
> approach using ioctl calls.  The latter one is not recommended as it does not
> really support IPv6 and also handles multiple IP addresses on a single
> interface in a horrendous way - often you cannot get all the information you
> need.  The Netlink interface (while quite tricky to work with, due to the
> flexibility of the protocol) is by far the best approach.  Also worth
> thinet-tools uses ioctl calls, iirc and iproute2 uses Netlink.
> 
> There are some Netlink libraries which tries to make things easier.  I've
> played with the libnl libraries, and I find them cumbersome and needlessly
> complicated, due to this callback approach.  In the OpenVPN community we have
> some code for review which implements a simpler interface to Netlink (it is
> even called that: SITNL - Simplified Interface To NetLink) [1].  It does not
> implement the code to retrieve IP addresses (only adding and removing them),
> but you might get some inspiration from this code.
> 
> [1] <https://patchwork.openvpn.net/patch/551/>
> 
> 
>> Does the usual suite of D-Bus interfaces on a Linux machine have any
>> function that checks this? I’m looking through NetworkManager but only see
>> logic for listing the addresses. Or do folks here have any other ideas for
>> how I might approach this?
> Querying NetworkManager probably works reasonably well on systems which uses
> NM for managing the various devices.  But if an interface is configured to be
> managed outside if NM, you might not get this information from NM.  In
> addition, there are systems who don't have NM installed as well.
> 
> 
> -- 
> kind regards,
> 
> David Sommerseth
> OpenVPN Inc
> 



More information about the dbus mailing list