diff mbox series

[3/4] batctl: ping: Get outgoing ifname from netlink

Message ID 20210510130734.41080-3-sven@narfation.org
State Accepted, archived
Delegated to: Simon Wunderlich
Headers show
Series [1/4] batctl: originators: Get outgoing ifname from netlink | expand

Commit Message

Sven Eckelmann May 10, 2021, 1:07 p.m. UTC
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 mbox series

Patch

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;