[v4,3/5] batman-adv: Do not let TT changes list grows indefinitely

Message ID 7a8b08f7c9e63281cb4dbc6d43926ec5e953a306.1732290614.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. 22, 2024, 3:52 p.m. UTC
  When TT changes list is too big to fit in packet due to MTU size, an
empty OGM is sent expected other node to send TT request to get the
changes. The issue is that tt.last_changeset was not built thus the
originator was responding with previous changes to those TT requests
(see batadv_send_my_tt_response). Also the changes list was never
cleaned up effectively never ending growing from this point onwards,
repeatedly sending the same TT response changes over and over, and
creating a new empty OGM every OGM interval expecting for the local
changes to be purged.

When there is more TT changes that can fit in packet, drop all changes,
send empty OGM and wait for TT request so we can respond with a full
table instead.

Fixes: e1bf0c14096f ("batman-adv: tvlv - convert tt data sent within OGMs")
Signed-off-by: Remi Pommarel <repk@triplefau.lt>
---
 net/batman-adv/translation-table.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
  

Comments

Antonio Quartulli Nov. 22, 2024, 3:57 p.m. UTC | #1
On 22/11/2024 16:52, Remi Pommarel wrote:
> When TT changes list is too big to fit in packet due to MTU size, an
> empty OGM is sent expected other node to send TT request to get the
> changes. The issue is that tt.last_changeset was not built thus the
> originator was responding with previous changes to those TT requests
> (see batadv_send_my_tt_response). Also the changes list was never
> cleaned up effectively never ending growing from this point onwards,
> repeatedly sending the same TT response changes over and over, and
> creating a new empty OGM every OGM interval expecting for the local
> changes to be purged.
> 
> When there is more TT changes that can fit in packet, drop all changes,
> send empty OGM and wait for TT request so we can respond with a full
> table instead.
> 
> Fixes: e1bf0c14096f ("batman-adv: tvlv - convert tt data sent within OGMs")
> Signed-off-by: Remi Pommarel <repk@triplefau.lt>

Acked-by: Antonio Quartulli <Antonio@mandelbit.com>
  

Patch

diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index bbab7491c83f..53dea8ae96e4 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -990,6 +990,7 @@  static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
 	int tt_diff_len, tt_change_len = 0;
 	int tt_diff_entries_num = 0;
 	int tt_diff_entries_count = 0;
+	bool drop_changes = false;
 	size_t tt_extra_len = 0;
 	u16 tvlv_len;
 
@@ -997,10 +998,17 @@  static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
 	tt_diff_len = batadv_tt_len(tt_diff_entries_num);
 
 	/* if we have too many changes for one packet don't send any
-	 * and wait for the tt table request which will be fragmented
+	 * and wait for the tt table request so we can reply with the full
+	 * (fragmented) table.
+	 *
+	 * The local change history should still be cleaned up so the next
+	 * TT round can start again with a clean state.
 	 */
-	if (tt_diff_len > bat_priv->soft_iface->mtu)
+	if (tt_diff_len > bat_priv->soft_iface->mtu) {
 		tt_diff_len = 0;
+		tt_diff_entries_num = 0;
+		drop_changes = true;
+	}
 
 	tvlv_len = batadv_tt_prepare_tvlv_local_data(bat_priv, &tt_data,
 						     &tt_change, &tt_diff_len);
@@ -1009,7 +1017,7 @@  static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
 
 	tt_data->flags = BATADV_TT_OGM_DIFF;
 
-	if (tt_diff_len == 0)
+	if (!drop_changes && tt_diff_len == 0)
 		goto container_register;
 
 	spin_lock_bh(&bat_priv->tt.changes_list_lock);