From patchwork Mon May 10 13:07:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 18303 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from diktynna.open-mesh.org (localhost [IPv6:::1]) by diktynna.open-mesh.org (Postfix) with ESMTP id 18FFF83ED0; Mon, 10 May 2021 15:15:05 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by diktynna.open-mesh.org (Postfix) with ESMTPS id C9DCF83E87 for ; Mon, 10 May 2021 15:15:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=narfation.org; s=20121; t=1620652067; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m1Sq9TusxZBFYp2VlNSWsV94tdJaY8qTuO4r9nK+8J0=; b=do9GvE6dkX2u4JP0Ye5g2DePIeJWQoFWcy4HbM4r8bw5XwD47WnTACt0i2t5E6b6OfgT/b 3J5fzwYnCfrBfPg01P7JFNopRYXyRAk3Hj4FQoRCu9uv4wZopO9mJdx+T/Y0fJzA/RlQY4 neMhg90UrgAHDQWU8+rY+0WwizvWDp4= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Cc: Sven Eckelmann Subject: [PATCH 2/4] batctl: neighbors: Get outgoing ifname from netlink Date: Mon, 10 May 2021 15:07:32 +0200 Message-Id: <20210510130734.41080-2-sven@narfation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210510130734.41080-1-sven@narfation.org> References: <20210510130734.41080-1-sven@narfation.org> MIME-Version: 1.0 ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1620652501; a=rsa-sha256; cv=none; b=mrnG0zoSeCJ6wrTMEFnLXhgVZZIROxl6pVBiIY2PFs/Pd/XPyxPw6JHTRY2jWlI2Jwl1y2 /9yBWOowN+2mt+AhZ2qHw8iRzktkEPwCHFEXK++8+EMohimsWsdx0nEGzlYio7V8JXg5jc ju8XTQs14Fj2sTX7ssrtiGoSfaMNXzA= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=narfation.org header.s=20121 header.b=do9GvE6d; spf=pass (diktynna.open-mesh.org: domain of sven@narfation.org designates 2a00:17d8:100::8b1 as permitted sender) smtp.mailfrom=sven@narfation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=open-mesh.org; s=20121; t=1620652501; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=m1Sq9TusxZBFYp2VlNSWsV94tdJaY8qTuO4r9nK+8J0=; b=zVup+xOkqFz5pCSw9WkuGNsNX3jQsiISIBhI5BRge3B5fus1dvG2lULZFjPh2hrdOB8VM8 G/c3YdncYmZ+Rc4yiDmxuZocqVqGKlMOZj/1w31HV/qNO5j2el1PedHtVkMN/hbBriIB8o KXJMgqhTapXmbMWaOkdK4NuaLVICCZM= Message-ID-Hash: 2VU4TGGKUUZEAAEHTUA2CKZPUOSDWD6J X-Message-ID-Hash: 2VU4TGGKUUZEAAEHTUA2CKZPUOSDWD6J X-MailFrom: sven@narfation.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-b.a.t.m.a.n.lists.open-mesh.org-0; header-match-b.a.t.m.a.n.lists.open-mesh.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: 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 neighbor table entry. batman-adv provides this functionality with Linux 5.14/batman-adv 2021.2. Signed-off-by: Sven Eckelmann --- neighbors.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/neighbors.c b/neighbors.c index af76d0f..3102b0e 100644 --- a/neighbors.c +++ b/neighbors.c @@ -36,10 +36,12 @@ static int neighbors_callback(struct nl_msg *msg, void *arg) struct nlmsghdr *nlh = nlmsg_hdr(msg); int last_seen_msecs, last_seen_secs; struct print_opts *opts = arg; + char ifname_buf[IF_NAMESIZE]; struct bat_host *bat_host; - char ifname[IF_NAMESIZE]; struct genlmsghdr *ghdr; + uint32_t ifindex; uint8_t *neigh; + char *ifname; if (!genlmsg_valid_hdr(nlh, 0)) { fputs("Received invalid data from kernel.\n", stderr); @@ -66,9 +68,16 @@ static int neighbors_callback(struct nl_msg *msg, void *arg) neigh = nla_data(attrs[BATADV_ATTR_NEIGH_ADDRESS]); bat_host = bat_hosts_find_by_mac((char *)neigh); - if (!if_indextoname(nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]), - ifname)) - ifname[0] = '\0'; + if (attrs[BATADV_ATTR_HARD_IFNAME]) { + ifname = nla_get_string(attrs[BATADV_ATTR_HARD_IFNAME]); + } else { + /* compatibility for Linux < 5.14/batman-adv < 2021.2 */ + ifindex = nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]); + if (!if_indextoname(ifindex, ifname_buf)) + ifname_buf[0] = '\0'; + + ifname = ifname_buf; + } last_seen_msecs = nla_get_u32(attrs[BATADV_ATTR_LAST_SEEN_MSECS]); last_seen_secs = last_seen_msecs / 1000;