With iproute2 on Linux, gre/gretap interfaces are setup with ip link add
, which for GRE needs remote
and optionally local
attributes specifying the endpoints. However, I can't find any way to read back these attributes. ip link show
doesn't show them, and they don't seem to be represented anywhere in the data structures returned by the C function getifaddrs
(e.g. if I wanted to implement my own tool to get them). I'm working with an environment where there are a very large number of such interfaces, and I need to be able to find the one associated with a particular remote address. Is there any way to do that without storing the mapping somewhere out-of-band?
To get all information from an interface, you can use
ip
's-details
option:If you want to use this in scripts, you really should use
-json
along thejq
tool. Very basic example (without any check):If you want to implement this directly in your tools using available system calls and functions, you should start by taking a look there:
rtnetlink (7)
- Linux IPv4 routing socket (it's a lot more than just IPv4)for interfaces it's probably RTM_GETLINK
rtnetlink (3)
- macros to manipulate rtnetlink messagesYou can run
strace
on theip
command to just see the kind of system calls and structures in use.Some documentation found around:
networking:generic_netlink_howto
There are higher libraries built on top of this such as libnl too.