b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] batman-adv: fix throughput detection for VLAN interfaces
@ 2026-07-05 12:21 Amitesh Singh
  2026-07-05 12:41 ` Sven Eckelmann
  0 siblings, 1 reply; 3+ messages in thread
From: Amitesh Singh @ 2026-07-05 12:21 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: marek.lindner, sw, antonio, sven, linux-kernel, amitesh.singh

From: Amitesh Singh <amitesh.singh@chargepoint.com>

batadv_v_elp_get_throughput() calls __ethtool_get_link_ksettings() to
determine the link speed of an Ethernet interface. Virtual interfaces
such as a VLAN on a bridge return success but with SPEED_UNKNOWN, so the
function falls through to the hardcoded default even when the underlying
physical device has a known speed.

Move rtnl_unlock() into each exit branch so the lock is still held
after the initial query. When the speed is unknown, walk the lower
device stack with netdev_walk_all_lower_dev() to find the first real
device that reports a valid speed, which covers DSA ports and physical
NICs sitting below a VLAN or bridge interface.

Signed-off-by: Amitesh Singh <amitesh.singh@chargepoint.com>
---
 net/batman-adv/bat_v_elp.c | 48 +++++++++++++++++++++++++++++++++++++-
 1 file changed, 47 insertions(+), 1 deletion(-)

diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
index 6ad6042a..3d4d82c5 100644
--- a/net/batman-adv/bat_v_elp.c
+++ b/net/batman-adv/bat_v_elp.c
@@ -70,6 +70,32 @@ static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
 			   msecs_to_jiffies(msecs));
 }
 
+/**
+ * batadv_v_elp_lower_dev_throughput() - netdev_walk_all_lower_dev callback
+ *  to query ethtool link speed on a lower device in the stack
+ * @dev: current lower device being visited
+ * @priv: nested priv; priv->data points to a u32 to receive the throughput
+ *  value in multiples of 100kbps
+ *
+ * Return: 1 to stop the walk once a valid speed is found, 0 to continue.
+ */
+static int batadv_v_elp_lower_dev_throughput(struct net_device *dev,
+					     struct netdev_nested_priv *priv)
+{
+	struct ethtool_link_ksettings settings;
+	u32 speed;
+
+	if (__ethtool_get_link_ksettings(dev, &settings) != 0)
+		return 0;
+
+	speed = settings.base.speed;
+	if (!speed || speed == SPEED_UNKNOWN)
+		return 0;
+
+	*(u32 *)priv->data = speed * 10;
+	return 1;
+}
+
 /**
  * batadv_v_elp_get_throughput() - get the throughput towards a neighbour
  * @neigh: the neighbour for which the throughput has to be obtained
@@ -167,7 +193,6 @@ static bool batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh,
 	 * ethtool (e.g. an Ethernet adapter)
 	 */
 	ret = __ethtool_get_link_ksettings(hard_iface->net_dev, &link_settings);
-	rtnl_unlock();
 	if (ret == 0) {
 		/* link characteristics might change over time */
 		if (link_settings.base.duplex == DUPLEX_FULL)
@@ -177,9 +202,30 @@ static bool batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh,
 
 		throughput = link_settings.base.speed;
 		if (throughput && throughput != SPEED_UNKNOWN) {
+			rtnl_unlock();
 			*pthroughput = throughput * 10;
 			return true;
 		}
+
+		/* Virtual interfaces (e.g. VLAN on bridge) don't report link
+		 * speed directly. Walk the lower device stack to find a real
+		 * device that does, such as a DSA port or physical NIC.
+		 */
+		throughput = 0;
+		{
+			struct netdev_nested_priv priv = { .data = &throughput };
+
+			netdev_walk_all_lower_dev(hard_iface->net_dev,
+						  batadv_v_elp_lower_dev_throughput,
+						  &priv);
+		}
+		rtnl_unlock();
+		if (throughput) {
+			*pthroughput = throughput;
+			return true;
+		}
+	} else {
+		rtnl_unlock();
 	}
 
 default_throughput:
-- 
2.43.0


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

* Re: [PATCH] batman-adv: fix throughput detection for VLAN interfaces
  2026-07-05 12:21 [PATCH] batman-adv: fix throughput detection for VLAN interfaces Amitesh Singh
@ 2026-07-05 12:41 ` Sven Eckelmann
  2026-07-05 12:48   ` Sven Eckelmann
  0 siblings, 1 reply; 3+ messages in thread
From: Sven Eckelmann @ 2026-07-05 12:41 UTC (permalink / raw)
  To: Amitesh Singh
  Cc: b.a.t.m.a.n, marek.lindner, sw, antonio, sven, linux-kernel,
	amitesh.singh

On Sun, 05 Jul 2026 17:51:34 +0530, Amitesh Singh <singh.amitesh@gmail.com> wrote:
> batadv_v_elp_get_throughput() calls __ethtool_get_link_ksettings() to
> determine the link speed of an Ethernet interface. Virtual interfaces
> such as a VLAN on a bridge return success but with SPEED_UNKNOWN, so the
> function falls through to the hardcoded default even when the underlying
> physical device has a known speed.
> 
> Move rtnl_unlock() into each exit branch so the lock is still held
> after the initial query. When the speed is unknown, walk the lower
> device stack with netdev_walk_all_lower_dev() to find the first real
> device that reports a valid speed, which covers DSA ports and physical
> NICs sitting below a VLAN or bridge interface.

Has to be reviewed by someone with B.A.T.M.A.N. V expertise, but:

What makes you think that the found port is then the port something is sent 
out (towards this specific neighbor)? The neighbor could be behind a 10Mbit/
Half port and you just found a 25000Mbit/Full port and stopped
netdev_walk_all_lower_dev

>
>
> diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
> index 6ad6042a..3d4d82c5 100644
> --- a/net/batman-adv/bat_v_elp.c
> +++ b/net/batman-adv/bat_v_elp.c
> @@ -70,6 +70,32 @@ static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
> [ ... skip 23 lines ... ]
> +		return 0;
> +
> +	*(u32 *)priv->data = speed * 10;
> +	return 1;
> +}
> +

Duplex handling was not copied to this function

> @@ -177,9 +202,30 @@ static bool batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh,
> [ ... skip 14 lines ... ]
> +			struct netdev_nested_priv priv = { .data = &throughput };
> +
> +			netdev_walk_all_lower_dev(hard_iface->net_dev,
> +						  batadv_v_elp_lower_dev_throughput,
> +						  &priv);
> +		}

Why this extra scope?

> +		rtnl_unlock();
> +		if (throughput) {
> +			*pthroughput = throughput;
> +			return true;
> +		}

Sashiko review:
https://sashiko.dev/#/patchset/20260705122134.62809-1-singh.amitesh%40gmail.com

-- 
Sven Eckelmann <sven@narfation.org>

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

* Re: [PATCH] batman-adv: fix throughput detection for VLAN interfaces
  2026-07-05 12:41 ` Sven Eckelmann
@ 2026-07-05 12:48   ` Sven Eckelmann
  0 siblings, 0 replies; 3+ messages in thread
From: Sven Eckelmann @ 2026-07-05 12:48 UTC (permalink / raw)
  To: Amitesh Singh
  Cc: b.a.t.m.a.n, marek.lindner, sw, antonio, linux-kernel,
	amitesh.singh

[-- Attachment #1: Type: text/plain, Size: 331 bytes --]

On Sunday, 5 July 2026 14:41:51 CEST Sven Eckelmann wrote:
> 
> Duplex handling was not copied to this function

Regarding this remark: duplex handling is also on top of the upper device and 
is not neighbor specific - this doesn't really make the handling easier.... 
but I think we can ignore this remark for now.

Regards,
	Sven

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

end of thread, other threads:[~2026-07-05 12:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-05 12:21 [PATCH] batman-adv: fix throughput detection for VLAN interfaces Amitesh Singh
2026-07-05 12:41 ` Sven Eckelmann
2026-07-05 12:48   ` 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).