Skip to contentSkip to conversation

batman-adv: reject new tp_meter sessions during teardown

PATCH Applied Ren Wei 4 participants 6 messages Apr 27 – May 3

Subsystems (3)
lore
Share & tools
lore

Ren Wei

author
#0 lore raw

PATCH v2 1/2 batman-adv: reject new tp_meter sessions during teardown

From: Jiexun Wang <[email protected]>

Prevent tp_meter from starting new sender or receiver sessions after mesh_state has left BATADV_MESH_ACTIVE.

Fixes 33a3bb4a3345 ("batman-adv: throughput meter implementation")

---
Changes in v2:
- Split the original fix into setup-side and teardown-side patches

 net/batman-adv/tp_meter.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
net/batman-adv/tp_meter.c +16 -1
index 2e42f6b348c8..d9a80e459c2e 100644
@@ -947,6 +947,13 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
 
 	/* look for an already existing test towards this node */
 	spin_lock_bh(&bat_priv->tp_list_lock);
+	if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) {
+		spin_unlock_bh(&bat_priv->tp_list_lock);
+		batadv_tp_batctl_error_notify(BATADV_TP_REASON_DST_UNREACHABLE,
+					      dst, bat_priv, session_cookie);
+		return;
+	}
+
 	tp_vars = batadv_tp_list_find(bat_priv, dst);
 	if (tp_vars) {
 		spin_unlock_bh(&bat_priv->tp_list_lock);
@@ -1329,9 +1336,12 @@ static struct batadv_tp_vars *
 batadv_tp_init_recv(struct batadv_priv *bat_priv,
 		    const struct batadv_icmp_tp_packet *icmp)
 {
-	struct batadv_tp_vars *tp_vars;
+	struct batadv_tp_vars *tp_vars = NULL;
 
 	spin_lock_bh(&bat_priv->tp_list_lock);
+	if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
+		goto out_unlock;
+
 	tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig,
 					      icmp->session);
 	if (tp_vars)
@@ -1464,6 +1474,9 @@ void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb)
 {
 	struct batadv_icmp_tp_packet *icmp;
 
+	if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
+		goto out;
+
 	icmp = (struct batadv_icmp_tp_packet *)skb->data;
 
 	switch (icmp->subtype) {
@@ -1478,6 +1491,8 @@ void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb)
 			   "Received unknown TP Metric packet type %u\n",
 			   icmp->subtype);
 	}
+
+out:
 	consume_skb(skb);
 }
 
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 2/2 batman-adv: stop tp_meter sessions during mesh teardown

From: Jiexun Wang <[email protected]>

TP meter sessions remain linked on bat_priv->tp_list after the netlink request has already finished. When the mesh interface is removed, batadv_mesh_free() currently tears down the mesh without first draining these sessions.

A running sender thread or a late incoming tp_meter packet can then keep processing against a mesh instance which is already shutting down. Synchronize tp_meter with the mesh lifetime by stopping all active sessions from batadv_mesh_free() and waiting for sender threads to exit before teardown continues.

Fixes 33a3bb4a3345 ("batman-adv: throughput meter implementation")

---
Changes in v2:
- Split the original fix and keep only teardown-side session draining here
- Change batadv_tp_stop_all() loop indices to size_t
- Restore blank lines unintentionally removed in v1

 net/batman-adv/main.c     |  1 +
 net/batman-adv/tp_meter.c | 93 +++++++++++++++++++++++++++++++--------
 net/batman-adv/tp_meter.h |  1 +
 net/batman-adv/types.h    |  4 ++
 4 files changed, 81 insertions(+), 18 deletions(-)
net/batman-adv/main.c +1 -0
index 3a35aadd8b41..a4d33ee0fda5 100644
@@ -249,6 +249,7 @@ void batadv_mesh_free(struct net_device *mesh_iface)
 	atomic_set(&bat_priv->mesh_state, BATADV_MESH_DEACTIVATING);
 
 	batadv_purge_outstanding_packets(bat_priv, NULL);
+	batadv_tp_stop_all(bat_priv);
 
 	batadv_gw_node_free(bat_priv);
 
net/batman-adv/tp_meter.c +75 -18

138 lines not on this page · raw message

net/batman-adv/tp_meter.h +1 -0
index f0046d366eac..4e97cd10cd02 100644
@@ -17,6 +17,7 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
 		     u32 test_length, u32 *cookie);
 void batadv_tp_stop(struct batadv_priv *bat_priv, const u8 *dst,
 		    u8 return_value);
+void batadv_tp_stop_all(struct batadv_priv *bat_priv);
 void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb);
 
 #endif /* _NET_BATMAN_ADV_TP_METER_H_ */
net/batman-adv/types.h +4 -0
index 8fc5fe0e9b05..daa06f421154 100644
@@ -14,6 +14,7 @@
 #include <linux/average.h>
 #include <linux/bitops.h>
 #include <linux/compiler.h>
+#include <linux/completion.h>
 #include <linux/if.h>
 #include <linux/if_ether.h>
 #include <linux/kref.h>
@@ -1328,6 +1329,9 @@ struct batadv_tp_vars {
 	/** @finish_work: work item for the finishing procedure */
 	struct delayed_work finish_work;
 
+	/** @finished: completion signaled when a sender thread exits */
+	struct completion finished;
+
 	/** @test_length: test length in milliseconds */
 	u32 test_length;
 
Signature · 1 line
2.34.1
maintainer Applied
#2 lore raw
In reply to Ren Wei
Quoted 2 lines · Ren Wei

Prevent tp_meter from starting new sender or receiver sessions after mesh_state has left BATADV_MESH_ACTIVE.

Applied, thanks!

[1/2] batman-adv: reject new tp_meter sessions during teardown

      commit: https://git.open-mesh.org/linux-merge.git/commit/?h=base/net&id=f68c93519b3e59a8039bdab9f930681a8e64f97e
[2/2] batman-adv: stop tp_meter sessions during mesh teardown
      commit: https://git.open-mesh.org/linux-merge.git/commit/?h=base/net&id=bff1888c2c5d7453c40940fdbe3215746817f7d9

Best regards,

Signature · 1 line
Sven Eckelmann <[email protected]>
reviewer
#3 lore raw
In reply to Ren Wei
Quoted 15 lines · Ren Wei

From: Jiexun Wang <[email protected]>

Prevent tp_meter from starting new sender or receiver sessions after mesh_state has left BATADV_MESH_ACTIVE.

Fixes 33a3bb4a3345 ("batman-adv: throughput meter implementation")
Quoted 3 lines

---
Changes in v2:
- Split the original fix into setup-side and teardown-side patches

Hi Ren,

An AI generated review of this patch-set is available on sashiko.dev. Could you take a look over that. I expect that some follow-up patches are warranted.

maintainer
#4 lore raw

On Tuesday, 28 April 2026 20:30:28 CEST Simon Horman wrote:
[...]

Quoted 6 lines

Hi Ren,

An AI generated review of this patch-set is available on sashiko.dev. Could you take a look over that. I expect that some follow-up patches are warranted.

I have some question regarding sashiko.dev - not sure if you can answer this. When I get a patch for review (the the newest one from Ren), sashiko marked it as "Embargoed" and I can't see it in b4. I have no idea why this is the case and I am unsure what I should do in this case:

* ignore sashiko
* wait until sashiko lifts the embargo
* ...

Maybe there is some document which explains it further and you can just point me in the right direction.

And just a question from Simon: sashiko.dev is meant as read-only platform, right? So, no way to write a rebuttal for wrong statements, correct?

Regards,
Sven