b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] batctl: originators: Get outgoing ifname from netlink
@ 2021-05-10 13:07 Sven Eckelmann
  2021-05-10 13:07 ` [PATCH 2/4] batctl: neighbors: " Sven Eckelmann
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Sven Eckelmann @ 2021-05-10 13:07 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann

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>
---
 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 = '*';
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] batctl: neighbors: Get outgoing ifname from netlink
  2021-05-10 13:07 [PATCH 1/4] batctl: originators: Get outgoing ifname from netlink Sven Eckelmann
@ 2021-05-10 13:07 ` Sven Eckelmann
  2021-05-10 13:07 ` [PATCH 3/4] batctl: ping: " Sven Eckelmann
  2021-05-10 13:07 ` [PATCH 4/4] batctl: event: Get ifname from netlink message Sven Eckelmann
  2 siblings, 0 replies; 4+ messages in thread
From: Sven Eckelmann @ 2021-05-10 13:07 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] batctl: ping: Get outgoing ifname from netlink
  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 ` Sven Eckelmann
  2021-05-10 13:07 ` [PATCH 4/4] batctl: event: Get ifname from netlink message Sven Eckelmann
  2 siblings, 0 replies; 4+ messages in thread
From: Sven Eckelmann @ 2021-05-10 13:07 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann

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 --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;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] batctl: event: Get ifname from netlink message
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Sven Eckelmann @ 2021-05-10 13:07 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Sven Eckelmann

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-05-10 13:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 4/4] batctl: event: Get ifname from netlink message Sven Eckelmann

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).