There is no need to gather the interface name for an outgoing interface via a different syscall(s) when the kernel directly provides this information in the netlink message for this originator table entry.
batman-adv provides this functionality with Linux 5.14/batman-adv 2021.2.
Signed-off-by: Sven Eckelmann sven@narfation.org --- netlink.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/netlink.c b/netlink.c index 31c9b01..4e616b6 100644 --- a/netlink.c +++ b/netlink.c @@ -728,9 +728,16 @@ static int get_nexthop_netlink_cb(struct nl_msg *msg, void *arg)
/* save result */ memcpy(opts->nexthop, neigh, ETH_ALEN); - ifname = if_indextoname(index, opts->ifname); - if (!ifname) - return NL_OK; + + if (attrs[BATADV_ATTR_HARD_IFNAME]) { + ifname = nla_get_string(attrs[BATADV_ATTR_HARD_IFNAME]); + strncpy(opts->ifname, ifname, IFNAMSIZ); + } else { + /* compatibility for Linux < 5.14/batman-adv < 2021.2 */ + ifname = if_indextoname(index, opts->ifname); + if (!ifname) + return NL_OK; + }
opts->found = true; opts->query_opts.err = 0;