Repository : ssh://git@diktynna/batctl
On branch : master
commit 426e48c8d9caa5972f305169641236e857be8c03 Author: Sven Eckelmann sven@narfation.org Date: Mon May 10 15:07:33 2021 +0200
batctl: ping: Get outgoing ifname from netlink
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
426e48c8d9caa5972f305169641236e857be8c03 netlink.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/netlink.c b/netlink.c index b8bca30..c821d0f 100644 --- a/netlink.c +++ b/netlink.c @@ -693,9 +693,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;