batman-adv: stop tp_meter sessions during mesh teardown
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 batman-adv: stop tp_meter sessions during mesh teardown
From: Jiexun Wang <[email protected]>
TP meter sessions are started asynchronously and 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(), refusing new sender/receiver setup once the mesh is no longer active, and waiting for sender threads to exit before teardown continues.
--- net/batman-adv/main.c | 1 + net/batman-adv/tp_meter.c | 112 +++++++++++++++++++++++++++++++------- net/batman-adv/tp_meter.h | 1 + net/batman-adv/types.h | 4 ++ 4 files changed, 97 insertions(+), 21 deletions(-)
net/batman-adv/main.c +1 -0
@@ -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 +91 -21
192 lines not on this page · raw message
net/batman-adv/tp_meter.h +1 -0
@@ -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
@@ -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
Sven Eckelmann
maintainerQuoted 7 lines · Ren Wei
[...]Reported-by Juefei Pu <[email protected]>Reported-by Xin Liu <[email protected]>Co-developed-by Luxing Yin <[email protected]>Signed-off-by Luxing Yin <[email protected]>Signed-off-by Jiexun Wang <[email protected]>Signed-off-by Ren Wei <[email protected]>
Thanks. I have some minor notes about the patch:
Quoted 10 lines
net/batman-adv/tp_meter.c +0
-0@@ -947,6 +964,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);
net/batman-adv/tp_meter.c void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, · line 976
Quoted 10 lines
net/batman-adv/tp_meter.c +7
-0+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);
Hm, this looks a little bit out of place. Maybe split it in a patch for handling the starting part (this) and the rest (the shutdown handling).
net/batman-adv/tp_meter.c void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, · line 995
Quoted 8 lines
net/batman-adv/tp_meter.c +0
-1@@ -966,7 +990,6 @@ void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst, bat_priv, session_cookie);return ; } - tp_vars =kmalloc_obj (*tp_vars,GFP_ATOMIC );if (!tp_vars) {spin_unlock_bh (&bat_priv->tp_list_lock);
Why was this changed?
net/batman-adv/tp_meter.c batadv_tp_init_recv(struct batadv_priv *bat_priv, · line 1367
Quoted 8 lines
net/batman-adv/tp_meter.c +0
-1@@ -1342,7 +1362,6 @@ batadv_tp_init_recv(struct batadv_priv *bat_priv, "Meter: too many ongoing sessions, aborting (RECV)\n"); goto out_unlock; } - tp_vars =kmalloc_obj (*tp_vars,GFP_ATOMIC );if (!tp_vars) goto out_unlock;
Why was this changed?
net/batman-adv/tp_meter.c void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb) · line 1517
Quoted 8 lines
net/batman-adv/tp_meter.c +0
-0@@ -1478,9 +1500,57 @@ void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb)[ ... skip 12 lines ... ]
net/batman-adv/tp_meter.c +6
-0+void batadv_tp_stop_all (struct batadv_priv *bat_priv) +{ +struct batadv_tp_vars *tp_vars[BATADV_TP_MAX_NUM ]; +struct batadv_tp_vars *tp_var; +int count =0 ; +int i;
size_t count = 0;size_t i;
Signature · 1 line
Sven Eckelmann <[email protected]>