Skip to contentSkip to conversation

batman-adv: tt: commit sync flags of local entries with their ADD

PATCH New Sven Eckelmann 1 participant 1 message Nov 28 Batman advanced

lore
Share & tools
lore

Sven Eckelmann

author maintainer
#0 lore raw

PATCH 1/1 batman-adv: tt: commit sync flags of local entries with their ADD

batadv_tt_local_refresh() stores a changed WIFI or ISOLA flag in an already announced local entry right away. The other nodes only learn about it when the queued ADD is committed. But the CRC and the full table responses use the current flags of the entry:

CPU0 (commit) CPU1 (tx)
batadv_tt_local_commit_changes_nolock()

 |-takes the queued changes
 |                                      batadv_tt_local_add()
 |                                      \-batadv_tt_local_refresh()
 |                                        |-queues ADD for next ttvn
 |                                        \-stores the new flags in
 |                                          the entry
 |-batadv_tt_local_update_crc()
 | CRC contains the new flags

\-batadv_tt_tvlv_container_update()
Announced changes don't contain
the new flags

The CRC of the new ttvn doesn't match the announced changes. The other nodes detect the mismatch and have to request the full table.

A full table response has the same problem without the race. It contains the new flags when it is sent before the ADD is committed. But its CRC is the one of the last commit.

Store the sync flags of the last committed ADD in the local entry. They are updated by batadv_tt_local_commit_change() and are the only flags used for the CRC and the full table responses. The current flags of the entry are still used for everything else.

---
 net/batman-adv/translation-table.c | 89 ++++++++++++++++++++++++--------------
 net/batman-adv/types.h             |  7 +++
 2 files changed, 64 insertions(+), 32 deletions(-)
net/batman-adv/translation-table.c +57 -32
index 6102bdf6..05894b01 100644
@@ -1017,6 +1017,7 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,
 	last_seen = jiffies;
 	WRITE_ONCE(tt_local->last_seen, last_seen);
 	tt_local->del_unqueued = false;
+	tt_local->committed_flags = 0;
 	tt_local->common.added_at = last_seen;
 	tt_local->vlan = vlan;
 	spin_lock_init(&tt_local->common.flags_lock);
@@ -3473,6 +3474,39 @@ static u32 batadv_tt_global_crc(struct batadv_priv *bat_priv,
 	return crc;
 }
 
+/**
+ * batadv_tt_local_announced() - check if local entry is announced and get its
+ *  committed sync flags
+ * @tt_common: local TT entry to check
+ * @flags: a pointer to store the committed BATADV_TT_SYNC_MASK flags to
+ *  (optional). No other flags of the entry are returned
+ *
+ * The flags of an entry can be modified at any time by
+ * batadv_tt_local_refresh(). The other nodes only learn about it when the
+ * queued ADD is committed. The CRC and the full table responses must therefore
+ * use the flags of the last committed ADD and not the current ones.
+ *
+ * Return: true if the entry is part of the announced local table, false if it
+ * is still waiting for the commit of its ADD.
+ */
+static bool batadv_tt_local_announced(struct batadv_tt_common_entry *tt_common,
+				      u8 *flags)
+{
+	struct batadv_tt_local_entry *tt_local;
+	bool announced;
+
+	tt_local = container_of(tt_common, struct batadv_tt_local_entry,
+				common);
+
+	scoped_guard(spinlock_bh, &tt_common->flags_lock) {
+		announced = !(tt_common->flags & BATADV_TT_CLIENT_NEW);
+		if (announced && flags)
+			*flags = tt_local->committed_flags;
+	}
+
+	return announced;
+}
+
 /**
  * batadv_tt_local_crc() - calculates the checksum of the local table
  * @bat_priv: the bat priv with all the mesh interface information
@@ -3500,24 +3534,18 @@ static u32 batadv_tt_local_crc(struct batadv_priv *bat_priv,
 
 		rcu_read_lock();
 		hlist_for_each_entry_rcu(tt_common, head, hash_entry) {
-			u16 tt_flags;
-
 			/* compute the CRC only for entries belonging to the
 			 * VLAN identified by vid
 			 */
 			if (tt_common->key.vid != vid)
 				continue;
 
-			tt_flags = batadv_tt_flags_get(tt_common);
-
 			/* not yet committed clients have not to be taken into
 			 * account while computing the CRC
 			 */
-			if (tt_flags & BATADV_TT_CLIENT_NEW)
+			if (!batadv_tt_local_announced(tt_common, &flags))
 				continue;
 
-			flags = tt_flags & BATADV_TT_SYNC_MASK;
-
 			/* use network order to read the VID: this ensures that
 			 * every node reads the bytes in the same order.
 			 */
@@ -3675,10 +3703,11 @@ batadv_tt_req_node_new(struct batadv_priv *bat_priv,
 }
 
 /**
- * batadv_tt_local_valid() - verify local tt entry and get flags
+ * batadv_tt_local_valid() - verify local tt entry and get committed sync flags
  * @entry_ptr: to be checked local tt entry
  * @data_ptr: not used but definition required to satisfy the callback prototype
- * @flags: a pointer to store TT flags for this client to
+ * @flags: a pointer to store the committed BATADV_TT_SYNC_MASK flags of this
+ *  client to. No other flags of the entry are returned
  *
  * Checks the validity of the given local TT entry. If it is, then the provided
  * flags pointer is updated.
@@ -3690,20 +3719,8 @@ static bool batadv_tt_local_valid(void *entry_ptr,
 				  u8 *flags)
 {
 	struct batadv_tt_common_entry *tt_common_entry = entry_ptr;
-	u16 tt_flags;
 
-	tt_flags = batadv_tt_flags_get(tt_common_entry);
-	if (tt_flags & BATADV_TT_CLIENT_NEW)
-		return false;
-
-	/* the entry is (still) announced. A ROAM flag of an entry which is
-	 * pending to be removed must not be transmitted. Otherwise, the
-	 * receiver would handle it like a roaming advertisement
-	 */
-	if (flags)
-		*flags = tt_flags & ~BATADV_TT_CLIENT_ROAM;
-
-	return true;
+	return batadv_tt_local_announced(tt_common_entry, flags);
 }
 
 /**
@@ -3747,7 +3764,8 @@ static bool batadv_tt_global_valid(void *entry_ptr,
  * @hash: hash table containing the tt entries
  * @tt_len: expected tvlv tt data buffer length in number of bytes
  * @tvlv_buff: pointer to the buffer to fill with the TT data
- * @valid_cb: function to filter tt change entries and to return TT flags
+ * @valid_cb: function to filter tt change entries and to return committed
+ *  BATADV_TT_SYNC_MASK flags of this client
  * @cb_data: data passed to the filter function as argument
  *
  * Fills the tvlv buff with the tt entries from the specified hash. If valid_cb
@@ -4715,8 +4733,9 @@ batadv_tt_local_unhash_pending(struct batadv_priv *bat_priv,
  * committed with a later ttvn.
  *
  * An ADD finishes the BATADV_TT_CLIENT_NEW state of the entry and it is counted
- * as part of the local table from now on. A DEL removes the entry which is
- * marked as BATADV_TT_CLIENT_PENDING from the local table.
+ * as part of the local table from now on. Its sync flags are stored as the
+ * ones known by the other nodes. A DEL removes the entry which is marked as
+ * BATADV_TT_CLIENT_PENDING from the local table.
  *
  * The entry is not protected by bat_priv->tt.commit_lock against a concurrent
  * refresh and removal. The client of a committed DEL can therefore be detected
@@ -4742,7 +4761,9 @@ batadv_tt_local_commit_change(struct batadv_priv *bat_priv,
 	struct batadv_tt_common_entry_key key;
 	struct hlist_head *head;
 	bool committed = false;
+	bool unhashed = false;
 	bool del_op;
+	u8 flags;
 	u32 i;
 
 	lockdep_assert_held(&bat_priv->tt.commit_lock);
@@ -4764,8 +4785,14 @@ batadv_tt_local_commit_change(struct batadv_priv *bat_priv,
 		if (!batadv_compare_tt(&tt_common->hash_entry, &key))
 			continue;
 
+		tt_local = container_of(tt_common, struct batadv_tt_local_entry,
+					common);
+
 		scoped_guard(spinlock_bh, &tt_common->flags_lock) {
 			if (!del_op) {
+				flags = change->flags & BATADV_TT_SYNC_MASK;
+				tt_local->committed_flags = flags;
+
 				/* an ADD of an already committed entry only
 				 * announces new flags or cancels its removal
 				 */
@@ -4777,14 +4804,11 @@ batadv_tt_local_commit_change(struct batadv_priv *bat_priv,
 				break;
 			}
 
-			tt_local = container_of(tt_common,
-						struct batadv_tt_local_entry,
-						common);
-			if (batadv_tt_local_unhash_pending(bat_priv, tt_local))
+			unhashed = batadv_tt_local_unhash_pending(bat_priv,
+								  tt_local);
+			if (unhashed)
 				break;
 
-			tt_local = NULL;
-
 			/* The client was detected again after its DEL was
 			 * taken. The other nodes remove it with this ttvn and
 			 * only add it again with the still queued ADD. The
@@ -4806,7 +4830,8 @@ batadv_tt_local_commit_change(struct batadv_priv *bat_priv,
 	spin_unlock_bh(list_lock);
 
 	/* drop reference of removed hash entry */
-	batadv_tt_local_entry_put(tt_local);
+	if (unhashed)
+		batadv_tt_local_entry_put(tt_local);
 }
 
 /**
net/batman-adv/types.h +7 -0
index d443143f..aa678ac8 100644
@@ -1946,6 +1946,13 @@ struct batadv_tt_local_entry {
 	 */
 	bool del_unqueued;
 
+	/**
+	 * @committed_flags: BATADV_TT_SYNC_MASK flags of the last committed
+	 *  ADD. The other nodes know the client with these flags. Protected by
+	 *  common.flags_lock
+	 */
+	u8 committed_flags;
+
 	/** @vlan: mesh-interface vlan of the entry */
 	struct batadv_meshif_vlan *vlan;
 };

---
base-commit: d0395afd7a33fd0fcf7d71795fec9a5204d9e6bc
change-id: 20261128-tt-local-sync-flags-commit-755f8e5376dd

Best regards,

Signature · 1 line
Sven Eckelmann <[email protected]>