[v3,5/5] batman-adv: Don't keep redundant TT change events

Message ID 71e47271e530851861441f55d102e55a7e5d1fc8.1732124716.git.repk@triplefau.lt (mailing list archive)
State Under Review
Delegated to: Antonio Quartulli
Headers
Series batman-adv: TT change events fixes and improvements |

Commit Message

Remi Pommarel Nov. 20, 2024, 5:47 p.m. UTC
  When adding a local TT twice within the same OGM interval (e.g. happens
when flag get updated), the flags of the first TT change entry is updated
with the second one and both change events is added to the change list.
This leads to having the same ADD change entry twice. Similarly a
DEL+DEL scenario is also creating twice the same event.

Deduplicate ADD+ADD or DEL+DEL scenarios to reduce the TT change events
that need to be sent in both OGM and TT response.

Signed-off-by: Remi Pommarel <repk@triplefau.lt>
---
 net/batman-adv/translation-table.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
  

Patch

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 39704af81169..4cc69a930b2c 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -477,7 +477,7 @@  static void batadv_tt_local_event(struct batadv_priv *bat_priv,
 
 	del_op_requested = flags & BATADV_TT_CLIENT_DEL;
 
-	/* check for ADD+DEL or DEL+ADD events */
+	/* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */
 	spin_lock_bh(&bat_priv->tt.changes_list_lock);
 	list_for_each_entry_safe(entry, safe, &bat_priv->tt.changes_list,
 				 list) {
@@ -497,17 +497,21 @@  static void batadv_tt_local_event(struct batadv_priv *bat_priv,
 		if (del_op_requested && !del_op_entry)
 			goto del;
 
-		/* this is a second add in the same originator interval. It
-		 * means that flags have been changed: update them!
+		/* this is a second add or del in the same originator interval.
+		 * It could mean that flags have been changed (e.g. double
+		 * add): update them
 		 */
-		if (!del_op_requested && !del_op_entry)
+		if (del_op_requested == del_op_entry) {
 			entry->change.flags = flags;
+			goto discard;
+		}
 
 		continue;
 del:
 		list_del(&entry->list);
 		kmem_cache_free(batadv_tt_change_cache, entry);
 		bat_priv->tt.local_changes--;
+discard:
 		kmem_cache_free(batadv_tt_change_cache, tt_change_node);
 		goto unlock;
 	}