From: Simon Wunderlich <sw@simonwunderlich.de>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
b.a.t.m.a.n@lists.open-mesh.org,
Sven Eckelmann <sven@narfation.org>,
Simon Wunderlich <sw@simonwunderlich.de>
Subject: [PATCH net-next 15/15] batman-adv: tt: drop ADD+DEL events of never announced clients
Date: Mon, 23 Nov 2026 18:18:27 +0100 [thread overview]
Message-ID: <20261123171827.3294525-16-sw@simonwunderlich.de> (raw)
In-Reply-To: <20261123171827.3294525-1-sw@simonwunderlich.de>
From: Sven Eckelmann <sven@narfation.org>
If a detected client was not yet announced, a DEL event can directly drop
the ADD event. The other nodes never heard about the client and don't need
a DEL for it. The entry can then also be removed from the local table
immediately instead of waiting for the commit of its DEL.
Only the initial ADD queued by batadv_tt_local_insert() can be cancelled.
The BATADV_TT_CLIENT_NEW flag of the entry is not enough to identify such a
change: batadv_tt_local_commit_changes_nolock() takes the queued changes
before it clears this flag. An ADD queued by batadv_tt_local_refresh() in
this window (for example for a changed BATADV_TT_CLIENT_WIFI flag) must
still be announced together with a following DEL because the initial ADD is
already on its way to the other nodes. Each change entry therefore stores
whether it is the initial ADD of its client.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/translation-table.c | 119 ++++++++++++++++++++++-------
net/batman-adv/types.h | 7 ++
2 files changed, 100 insertions(+), 26 deletions(-)
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index 998c7f285e1d..c17cfee6ff84 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -651,13 +651,20 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common)
}
/**
- * __batadv_tt_local_event() - store a local TT event (ADD/DEL) with given flags
+ * batadv_tt_local_event() - store a local TT event (ADD/DEL) with given flags
* @bat_priv: the bat priv with all the mesh interface information
* @common: the TT entry involved in the event
* @flags: flags of the TT entry combined with the event flags
+ * @initial_add: whether the ADD is the first one of a client which was never
+ * announced to the other nodes
+ * @cancelled: set to true if a DEL cancelled the initial ADD of the client and
+ * to false otherwise (optional)
*
* Only a single change per client is queued. It describes the latest state of
- * the client and a new event therefore replaces an already queued one.
+ * the client and a new event therefore replaces an already queued one. The
+ * only exception is a DEL for a client whose initial ADD is still queued. The
+ * other nodes don't need to know anything about such a client and the ADD is
+ * cancelled instead.
*
* The other nodes only learn about the modification of a local entry through
* the queued change. The caller must therefore not modify the entry in a way
@@ -669,12 +676,12 @@ static u16 batadv_tt_flags_get(struct batadv_tt_common_entry *common)
* The caller must hold the flags_lock of @common. The events of an entry are
* then queued in the same order in which its flags were modified.
*
- * Return: true if the event was stored, false if the memory for it could not
- * be allocated.
+ * Return: true if the event was stored (or cancelled a queued ADD), false if
+ * the memory for it could not be allocated.
*/
-static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
- const struct batadv_tt_common_entry *common,
- u8 flags)
+static bool batadv_tt_local_event(struct batadv_priv *bat_priv,
+ const struct batadv_tt_common_entry *common,
+ u8 flags, bool initial_add, bool *cancelled)
__must_hold(&common->flags_lock)
{
struct batadv_tt_change_node *tt_change_node;
@@ -685,6 +692,9 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
lockdep_assert_held(&common->flags_lock);
+ if (cancelled)
+ *cancelled = false;
+
tt_change_node = kmem_cache_alloc(batadv_tt_change_cache, GFP_ATOMIC);
if (!tt_change_node)
return false;
@@ -704,6 +714,7 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
flags &= ~BATADV_TT_CLIENT_ROAM;
tt_change_node->change.flags = flags;
+ tt_change_node->initial_add = initial_add && !del_op_requested;
/* check for ADD+DEL, DEL+ADD, ADD+ADD or DEL+DEL events */
spin_lock_bh(&bat_priv->tt.changes_list_lock);
@@ -716,12 +727,31 @@ static bool __batadv_tt_local_event(struct batadv_priv *bat_priv,
if (entry->change.vid != tt_change_node->change.vid)
continue;
- /* the other nodes may know the client with different
- * flags. A DEL+ADD must therefore still announce the
- * current flags and an ADD+DEL must still remove the
- * client. ADD+ADD and DEL+DEL only update the flags
- */
- entry->change.flags = flags;
+ if (del_op_requested && entry->initial_add) {
+ /* ADD+DEL of a client which was never announced (e.g.
+ * roaming of a client still in the NEW state) have no
+ * effect and can be removed.
+ */
+ list_del(&entry->list);
+ kmem_cache_free(batadv_tt_change_cache, entry);
+ changes--;
+ if (cancelled)
+ *cancelled = true;
+ } else {
+ /* the other nodes may know the client with different
+ * flags. A DEL+ADD must therefore still announce the
+ * current flags and an ADD+DEL must still remove the
+ * client. ADD+ADD and DEL+DEL only update the flags.
+ *
+ * The queued change keeps its initial_add state. An
+ * ADD which only updates the flags of a still queued
+ * initial ADD stays cancellable. But an ADD queued
+ * after the initial ADD was committed (and before the
+ * entry left the NEW state) must not become
+ * cancellable.
+ */
+ entry->change.flags = flags;
+ }
kmem_cache_free(batadv_tt_change_cache, tt_change_node);
goto update_changes;
@@ -1063,6 +1093,10 @@ batadv_tt_local_refresh_needed(struct batadv_tt_local_entry *tt_local,
* updated. An ADD event is queued when @announce is set, the pending removal
* was cancelled or a flag announced to the other nodes was modified.
*
+ * @announce is only set for an entry which is just being inserted. Its ADD is
+ * therefore the initial ADD of a client which was never announced to the other
+ * nodes.
+ *
* The entry is left untouched when the ADD event could not be queued. The
* other nodes would otherwise never be informed about the new state. An already
* hashed entry is simply refreshed again when the next packet of the client is
@@ -1083,6 +1117,7 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
{
struct batadv_tt_common_entry *common = &tt_local->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool initial_add = announce;
bool readded = false;
bool roamed = false;
u8 remote_flags;
@@ -1131,7 +1166,8 @@ batadv_tt_local_refresh_locked(struct batadv_priv *bat_priv,
* without a queued change which commits/announces it
*/
if (announce &&
- !__batadv_tt_local_event(bat_priv, common, flags))
+ !batadv_tt_local_event(bat_priv, common, flags,
+ initial_add, NULL))
return false;
common->flags = flags;
@@ -1883,6 +1919,11 @@ static void batadv_tt_local_unhash(struct batadv_priv *bat_priv,
* retry it. Such an entry is marked as del_unqueued instead. It stays in the
* local table until batadv_tt_local_purge_list() was able to queue its DEL.
*
+ * A client whose initial ADD is still queued was never announced to the other
+ * nodes. Its DEL cancels the ADD and the entry is removed from the local table
+ * right away. The caller has to drop the hash reference of the entry after it
+ * released the flags_lock.
+ *
* The caller must hold the flags_lock of @tt_local_entry and must not have
* released it since it checked that the entry has to be removed. Both the
* queue-then-mark order and this single flags_lock section are required.
@@ -1891,8 +1932,11 @@ static void batadv_tt_local_unhash(struct batadv_priv *bat_priv,
* must have ensured that the entry is still part of the local table. A DEL for
* an entry which was already purged could otherwise cancel the ADD of a new
* entry for the same client.
+ *
+ * Return: true if the entry was removed from the local table instead of being
+ * marked as pending, false otherwise.
*/
-static void
+static bool
batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
struct batadv_tt_local_entry *tt_local_entry,
u16 flags, const char *message)
@@ -1900,6 +1944,7 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
{
struct batadv_tt_common_entry *common = &tt_local_entry->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool cancelled;
bool queued;
u32 i;
@@ -1907,8 +1952,13 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
lockdep_assert_held(&hash->list_locks[i]);
lockdep_assert_held(&common->flags_lock);
- queued = __batadv_tt_local_event(bat_priv, common,
- common->flags | flags);
+ queued = batadv_tt_local_event(bat_priv, common, common->flags | flags,
+ false, &cancelled);
+ if (cancelled) {
+ /* the entry was never announced */
+ batadv_tt_local_unhash(bat_priv, tt_local_entry, message);
+ return true;
+ }
/* a failed attempt must not hide the still queued DEL of an already
* pending entry
@@ -1924,6 +1974,8 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
"Local tt entry (%pM, vid: %d) pending to be removed: %s\n",
tt_local_entry->common.key.addr,
batadv_print_vid(tt_local_entry->common.key.vid), message);
+
+ return false;
}
/**
@@ -1940,6 +1992,9 @@ batadv_tt_local_set_pending(struct batadv_priv *bat_priv,
* also applies to an entry which still carries BATADV_TT_CLIENT_NEW because its
* ADD might already have been taken for the next ttvn.
*
+ * Only an entry whose initial ADD is still queued is removed from the local
+ * table immediately. Nothing was announced about it to the other nodes.
+ *
* An entry which was already removed from the local table after it was looked
* up is ignored and BATADV_NO_FLAGS is stored in @curr_flags.
*
@@ -1956,6 +2011,7 @@ batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
spinlock_t *list_lock; /* protects write access to the hash lists */
struct batadv_tt_common_entry *common = &tt_local_entry->common;
struct batadv_hashtable *hash = bat_priv->tt.local_hash;
+ bool unhashed = false;
u16 flags;
u32 i;
@@ -1984,11 +2040,15 @@ batadv_tt_local_remove_entry(struct batadv_priv *bat_priv,
if (roaming)
flags |= BATADV_TT_CLIENT_ROAM;
- batadv_tt_local_set_pending(bat_priv, tt_local_entry, flags,
- message);
+ unhashed = batadv_tt_local_set_pending(bat_priv, tt_local_entry,
+ flags, message);
}
spin_unlock_bh(list_lock);
+
+ /* drop reference of removed hash entry */
+ if (unhashed)
+ batadv_tt_local_entry_put(tt_local_entry);
}
/**
@@ -2037,6 +2097,8 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
hlist_for_each_entry_safe(tt_common_entry, node_tmp, head,
hash_entry) {
+ bool unhashed = false;
+
tt_local_entry = container_of(tt_common_entry,
struct batadv_tt_local_entry,
common);
@@ -2046,10 +2108,10 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
if (tt_local_entry->common.flags & BATADV_TT_CLIENT_PENDING) {
/* but its removal must still be announced */
if (tt_local_entry->del_unqueued)
- batadv_tt_local_set_pending(bat_priv,
- tt_local_entry,
- BATADV_TT_CLIENT_DEL,
- "requeued");
+ unhashed = batadv_tt_local_set_pending(bat_priv,
+ tt_local_entry,
+ BATADV_TT_CLIENT_DEL,
+ "requeued");
break;
}
@@ -2060,10 +2122,15 @@ static void batadv_tt_local_purge_list(struct batadv_priv *bat_priv,
timeout))
break;
- batadv_tt_local_set_pending(bat_priv, tt_local_entry,
- BATADV_TT_CLIENT_DEL,
- "timed out");
+ unhashed = batadv_tt_local_set_pending(bat_priv,
+ tt_local_entry,
+ BATADV_TT_CLIENT_DEL,
+ "timed out");
}
+
+ /* drop reference of removed hash entry */
+ if (unhashed)
+ batadv_tt_local_entry_put(tt_local_entry);
}
}
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index d443143f190b..0a2db6583c11 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -2005,6 +2005,13 @@ struct batadv_tt_change_node {
/** @change: holds the actual translation table diff data */
struct batadv_tvlv_tt_change change;
+
+ /**
+ * @initial_add: the change is the initial ADD of a client which was
+ * never announced to the other nodes. A DEL of this client cancels
+ * the change instead of being queued
+ */
+ bool initial_add:1;
};
/**
--
2.47.3
prev parent reply other threads:[~2026-11-23 17:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 17:18 [PATCH net-next 00/15] pull request for net-next: batman-adv 2026-11-23 Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 01/15] batman-adv: document refcount of returned objects Simon Wunderlich
2026-11-23 17:23 ` netdev-bot+sinfo
2026-11-23 17:18 ` [PATCH net-next 02/15] batman-adv: mcast: use mla_lock also during mcast_free Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 03/15] batman-adv: mark functions inheriting critical sections Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 04/15] batman-adv: bla: register own backbone gw when claiming for local node Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 05/15] batman-adv: tt: unhash local entries with hlist_del_init_rcu() Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 06/15] batman-adv: tt: refresh local entry in single flags_lock section Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 07/15] batman-adv: tt: don't remove unhashed local entries Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 08/15] batman-adv: tt: don't queue local events for unhashed entries Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 09/15] batman-adv: tt: remove unannounced local entries via pending state Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 10/15] batman-adv: tt: keep local entry unchanged when ADD can't be queued Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 11/15] batman-adv: tt: requeue DEL of pending local entry after failed allocation Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 12/15] batman-adv: tt: extract removal of pending local entry Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 13/15] batman-adv: tt: commit only the announced local changes Simon Wunderlich
2026-11-23 17:18 ` [PATCH net-next 14/15] batman-adv: tt: avoid list_lock for unchanged local clients Simon Wunderlich
2026-11-23 17:18 ` Simon Wunderlich [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261123171827.3294525-16-sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sven@narfation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox