b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 4/4] batctl: event: Get ifname from netlink message
Date: Mon, 10 May 2021 15:07:34 +0200	[thread overview]
Message-ID: <20210510130734.41080-4-sven@narfation.org> (raw)
In-Reply-To: <20210510130734.41080-1-sven@narfation.org>

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 <sven@narfation.org>
---
 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]);
 
-- 
2.30.2


      parent reply	other threads:[~2021-05-10 13:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10 13:07 [PATCH 1/4] batctl: originators: Get outgoing ifname from netlink Sven Eckelmann
2021-05-10 13:07 ` [PATCH 2/4] batctl: neighbors: " Sven Eckelmann
2021-05-10 13:07 ` [PATCH 3/4] batctl: ping: " Sven Eckelmann
2021-05-10 13:07 ` Sven Eckelmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210510130734.41080-4-sven@narfation.org \
    --to=sven@narfation.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).