From patchwork Mon May 10 13:07:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 18304 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 909E483EDD; Mon, 10 May 2021 15:15:11 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by diktynna.open-mesh.org (Postfix) with ESMTPS id C3CCC81529 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=1620652065; 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; bh=Yr4fjz9A0y8N+SO/0aFjgwtdSqOJp11PlTma8VQPvWY=; b=E5m+KMnx57zkGfDLFDjDdFgiXYI0lebtDmyo/7bYWE2Fmtc/EWreK1yxbu18Hn/N2QDyfi iTCGEafuF5QLGBKrOrvXgpJk1kI8wLP8OalpELvrJvzaVBhL/9QgWzMCQNU/hdv3EjBiGl XkHuODKIFKyWv1LlyTkArTJYWZyHs50= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Cc: Sven Eckelmann Subject: [PATCH 1/4] batctl: originators: Get outgoing ifname from netlink Date: Mon, 10 May 2021 15:07:31 +0200 Message-Id: <20210510130734.41080-1-sven@narfation.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 ARC-Seal: i=1; s=20121; d=open-mesh.org; t=1620652502; a=rsa-sha256; cv=none; b=yt6juysR63xGJluxCm0YFVvBWv9L/9V+28n4ws6BOYxctTDEjDe/hCwZB61jRhOz0j3tC4 xTM22egdWUN4quOc3KZO74A2KQRXAf+B0AJhboyiXoAo2KJFIM7KVcVsCztsKUC/FWjRNt jf6jrn5BlcL+ECNvf31i8rUUqf5cKdY= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=narfation.org header.s=20121 header.b=E5m+KMnx; 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=1620652502; 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:dkim-signature; bh=Yr4fjz9A0y8N+SO/0aFjgwtdSqOJp11PlTma8VQPvWY=; b=MljDGEXu/6uzAG0nlrtFVeU4pSTGxpMqwGNuMTeQVkRlPRlR0mWJ+K6zG9Pp+qftDVu9Vc iXoxKU3Uk2v97nsqcY9ycqc9l2WX1e+SN+qxBJ3qCwcqVfbkEJ+Qdlb+fWygolm7uKbwQF FrSp8GJmFctDccDT1EAES23mzkjKvn0= Message-ID-Hash: IV2OFJ2KJX52K4ARZ5MIWZ2A42WOKJRO X-Message-ID-Hash: IV2OFJ2KJX52K4ARZ5MIWZ2A42WOKJRO 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 originator table entry. batman-adv provides this functionality with Linux 5.14/batman-adv 2021.2. Signed-off-by: Sven Eckelmann --- originators.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/originators.c b/originators.c index 8a29dd7..11ca4b9 100644 --- a/originators.c +++ b/originators.c @@ -40,12 +40,14 @@ static int originators_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; struct genlmsghdr *ghdr; - char ifname[IF_NAMESIZE]; + uint32_t ifindex; float last_seen; uint8_t *neigh; uint8_t *orig; + char *ifname; char c = ' '; uint8_t tq; @@ -74,9 +76,16 @@ static int originators_callback(struct nl_msg *msg, void *arg) orig = nla_data(attrs[BATADV_ATTR_ORIG_ADDRESS]); neigh = nla_data(attrs[BATADV_ATTR_NEIGH_ADDRESS]); - 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; + } if (attrs[BATADV_ATTR_FLAG_BEST]) c = '*'; 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; From patchwork Mon May 10 13:07:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 18302 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 6E86483E68; Mon, 10 May 2021 15:15:04 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [213.160.73.56]) by diktynna.open-mesh.org (Postfix) with ESMTPS id 9CED0807D5 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=1620652070; 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=hOiZCmVObJ8cm01LCdzLlLHRqWtvDRxGDiwx7tLhlzg=; b=ulKJygLKwftEUbU7t88tbHEaGuTy7q+nHgOwZdesBouBzGj0R1yrrgmmBB4h69QCsp7S8s cXrd4xWaX+HF2An46RqhLXVCzse1RhfV85Ei7I/He9UCq7BB1RLAScVttV97xKME+n8Zz0 mOGtA9NVTgyTSCpd0IliLtr62XVVum8= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Cc: Sven Eckelmann Subject: [PATCH 3/4] batctl: ping: Get outgoing ifname from netlink Date: Mon, 10 May 2021 15:07:33 +0200 Message-Id: <20210510130734.41080-3-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=uJfQFhoyH8XxhYXakAAsJSJfPfikc/Vod9ReuE55NW9gmGrHLwkfyPaFaLULEUntVrailV Ao0+n58LCw84NymJt4BpZaZpZ02/g1ZYULsqk96pjQ0nSbKqO6CC5Gbk4c7NcgC+XbxZud aosFl/gFkuxw2C/SYY4mO1lA134uQg4= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=narfation.org header.s=20121 header.b=ulKJygLK; spf=pass (diktynna.open-mesh.org: domain of sven@narfation.org designates 213.160.73.56 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=hOiZCmVObJ8cm01LCdzLlLHRqWtvDRxGDiwx7tLhlzg=; b=GSybpfelsSbEmrcZ1fGyVtDwjFiwKeY6BfJICGX8yaCOvIsJziTnJ3YQhvkfvwjuLJ6IBQ qqV6TJGg/1Ca2my/mOHBV27YLiAhc6aIvt0rnhtABTG802sKHRqODWmQYQck1+HkJPcZ0z V0pkqUWuBvRDrlLqGPmFB8isvBi9kzU= Message-ID-Hash: ENQJAZTSKO3KLIYRM47TGRTVOB3TJQ7E X-Message-ID-Hash: ENQJAZTSKO3KLIYRM47TGRTVOB3TJQ7E 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 originator table entry. batman-adv provides this functionality with Linux 5.14/batman-adv 2021.2. Signed-off-by: Sven Eckelmann --- 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; From patchwork Mon May 10 13:07:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 18306 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 AB96883EE8; Mon, 10 May 2021 15:15:23 +0200 (CEST) Received: from dvalin.narfation.org (dvalin.narfation.org [IPv6:2a00:17d8:100::8b1]) by diktynna.open-mesh.org (Postfix) with ESMTPS id C84BC83E68 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=1620652072; 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=kQkx43KxA4d+1FIGI7hfjNvvWtSnp9coinGS9U9qgD8=; b=BEDTal13th2GadSMwGoxsWKU25cfrYJ7nLPM7E1jsfKlQKZN4LooRaWBQFVsgqU8FMSkcs fSrKi7d1XcQcSHZF2YSpd/IJ29QwxZUoaerTL+OGEwkUnZo9QS9ddEb5ltXfAKILDiNAn0 Ioi3Jwy96CE9PUOkkmb/jtWbbiDx9Lk= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Cc: Sven Eckelmann Subject: [PATCH 4/4] batctl: event: Get ifname from netlink message Date: Mon, 10 May 2021 15:07:34 +0200 Message-Id: <20210510130734.41080-4-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=nDPXxJTjwjA4izT3R87nx7hSW4BmSiL3Qj9XrPd7vldet13WLwGxohv6RReTDGQe3K/BX/ 2AqUtYM6/3/LQQ7Y/bjV62aOcN1cZaTooO+z6etSLieo75IlKDmb8yd6z5g5H4v6bTG8fX t15tvDUG5CAxbl1f3Nu6FA3x2IySZHc= ARC-Authentication-Results: i=1; diktynna.open-mesh.org; dkim=pass header.d=narfation.org header.s=20121 header.b=BEDTal13; 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=kQkx43KxA4d+1FIGI7hfjNvvWtSnp9coinGS9U9qgD8=; b=WRj3iYtdqCIcu3BROq3d+ZwQdvmYTeGXmb4oJ3tn5yaBYbblk0G0dk1ZbxZMRcwLUC9Jdm uTc5aA86/rsF3urtWdUZfJdnA+ZPkwn+07+eyt46veN8YvhLrnjpS4eeLXcYTSTXVaPXy1 c9rc+clRaJyUCpbodFCh/c98RXDWl/4= Message-ID-Hash: BIB6XU3WMNBJMTRUOO74XLSPGWUQWSHB X-Message-ID-Hash: BIB6XU3WMNBJMTRUOO74XLSPGWUQWSHB 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 interface via a different syscall(s) when the kernel directly provides this information in the netlink message for this event. batman-adv provides this functionality with Linux 5.14/batman-adv 2021.2. Signed-off-by: Sven Eckelmann --- event.c | 52 ++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/event.c b/event.c index 955fe11..274f99f 100644 --- a/event.c +++ b/event.c @@ -174,10 +174,15 @@ static void event_parse_set_mesh(struct nlattr **attrs) ARRAY_SIZE(mesh_mandatory))) return; - mesh_ifindex = nla_get_u32(attrs[BATADV_ATTR_MESH_IFINDEX]); - meshif_name = if_indextoname(mesh_ifindex, meshif_buf); - if (!meshif_name) - return; + if (attrs[BATADV_ATTR_MESH_IFNAME]) { + meshif_name = nla_get_string(attrs[BATADV_ATTR_MESH_IFNAME]); + } else { + /* compatibility for Linux < 5.14/batman-adv < 2021.2 */ + mesh_ifindex = nla_get_u32(attrs[BATADV_ATTR_MESH_IFINDEX]); + meshif_name = if_indextoname(mesh_ifindex, meshif_buf); + if (!meshif_name) + return; + } printf("%s: set mesh:\n", meshif_name); @@ -305,15 +310,25 @@ static void event_parse_set_hardif(struct nlattr **attrs) ARRAY_SIZE(hardif_mandatory))) return; - mesh_ifindex = nla_get_u32(attrs[BATADV_ATTR_MESH_IFINDEX]); - meshif_name = if_indextoname(mesh_ifindex, meshif_buf); - if (!meshif_name) - return; + if (attrs[BATADV_ATTR_MESH_IFNAME]) { + meshif_name = nla_get_string(attrs[BATADV_ATTR_MESH_IFNAME]); + } else { + /* compatibility for Linux < 5.14/batman-adv < 2021.2 */ + mesh_ifindex = nla_get_u32(attrs[BATADV_ATTR_MESH_IFINDEX]); + meshif_name = if_indextoname(mesh_ifindex, meshif_buf); + if (!meshif_name) + return; + } - hardif_ifindex = nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]); - hardif_name = if_indextoname(hardif_ifindex, hardif_buf); - if (!hardif_name) - return; + if (attrs[BATADV_ATTR_MESH_IFNAME]) { + hardif_name = nla_get_string(attrs[BATADV_ATTR_HARD_IFNAME]); + } else { + /* compatibility for Linux < 5.14/batman-adv < 2021.2 */ + hardif_ifindex = nla_get_u32(attrs[BATADV_ATTR_HARD_IFINDEX]); + hardif_name = if_indextoname(hardif_ifindex, hardif_buf); + if (!hardif_name) + return; + } printf("%s (%s): set hardif:\n", meshif_name, hardif_name); @@ -350,10 +365,15 @@ static void event_parse_set_vlan(struct nlattr **attrs) ARRAY_SIZE(vlan_mandatory))) return; - mesh_ifindex = nla_get_u32(attrs[BATADV_ATTR_MESH_IFINDEX]); - meshif_name = if_indextoname(mesh_ifindex, meshif_buf); - if (!meshif_name) - return; + if (attrs[BATADV_ATTR_MESH_IFNAME]) { + meshif_name = nla_get_string(attrs[BATADV_ATTR_MESH_IFNAME]); + } else { + /* compatibility for Linux < 5.14/batman-adv < 2021.2 */ + mesh_ifindex = nla_get_u32(attrs[BATADV_ATTR_MESH_IFINDEX]); + meshif_name = if_indextoname(mesh_ifindex, meshif_buf); + if (!meshif_name) + return; + } vid = nla_get_u16(attrs[BATADV_ATTR_VLANID]);