pull request for net-next: batman-adv 2026-09-07
Subsystems (3)
Simon Wunderlich
maintainercover pull request for net-next: batman-adv 2026-09-07
Dear net maintainers,
here is another cleanup pull request of batman-adv to go into net-next.
Please pull or let me know of any problem!
Thank you,
Simon
The following changes since commit 799152bcf6cbe4393eb03690925a382cefae303c:
batman-adv: tt: decrement count for committed client on local_remove (2026-08-30 20:05:57 +0200)
are available in the Git repository at:
https://git.open-mesh.org/batadv.git tags/batadv-next-pullrequest-20260907
for you to fetch changes up to 6d7f71ae4cdcbb22f541638057299fe26c451e65:
batman-adv: correct batadv_hash_remove kdoc return type (2026-09-06 20:05:31 +0200)
----------------------------------------------------------------
This cleanup patchset includes the following patches, all by Sven Eckelmann:
- translation table cleanups (12 patches)
- kerneldoc fixes noted by sashiko (3 patches)
----------------------------------------------------------------
Sven Eckelmann (15):
batman-adv: tt: look up wifi state of incoming interface in helper
batman-adv: tt: extract allocation of new local entries
batman-adv: tt: replace forward gotos in batadv_tt_local_add()
batman-adv: tt: extract refresh of existing local entries
batman-adv: tt: extract update of dynamic client flags
batman-adv: tt: extract allocation of new global entries
batman-adv: tt: extract merging of flags into existing global entries
batman-adv: tt: replace add_orig_entry goto in batadv_tt_global_add()
batman-adv: tt: extract removal of the superseded local entry
batman-adv: tt: extract marking of a removed local entry
batman-adv: tt: extract immediate purge of a local entry
batman-adv: tt: drop the cleanup label from batadv_tt_local_remove()
batman-adv: tt: clarify kernel doc for batadv_tt_local_set_pending_event()
batman-adv: bat_iv: fix ogm_neigh_is_sob parameters references
batman-adv: correct batadv_hash_remove kdoc return type
net/batman-adv/bat_iv_ogm.c | 4 +- net/batman-adv/hash.h | 2 +- net/batman-adv/translation-table.c | 655 +++++++++++++++++++++++-------------- 3 files changed, 420 insertions(+), 241 deletions(-)
Simon Wunderlich
maintainerPATCH 1/15 batman-adv: tt: look up wifi state of incoming interface in helper
From: Sven Eckelmann <[email protected]>
batadv_tt_local_add() only needs to know whether the client was seen on a wifi interface. But it kept the net_device reference of the incoming interface alive until its own cleanup section, together with a "net" and an "in_dev" variable which are of no interest to the rest of the function.
Move the lookup to a small helper which acquires and releases the net_device reference itself.
--- net/batman-adv/translation-table.c | 41 +++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-)
net/batman-adv/translation-table.c +29 -12
@@ -41,6 +41,7 @@#include <linux/string.h> #include <linux/workqueue.h> #include <net/genetlink.h> +#include <net/net_namespace.h> #include <net/netlink.h> #include <uapi/linux/batadv_packet.h> #include <uapi/linux/batman_adv.h>
@@ -693,6 +694,32 @@ static void batadv_tt_local_add_roam(struct batadv_priv *bat_priv,batadv_tt_global_free (bat_priv, tt_global,"Roaming canceled" ); } +/** +* batadv_tt_iif_is_wifi() - check whether a client is connected via wifi +* @net: namespace to search the incoming interface in +* @ifindex: index of the interface where the client is connected to +* +* Return: true if @ifindex refers to a wifi interface, false otherwise (which +* includes the case of an unknown or missing incoming interface). +*/ +static bool batadv_tt_iif_is_wifi (struct net *net,int ifindex) +{ +struct net_device *in_dev; +u32 wifi_flags; + +if (ifindex ==BATADV_NULL_IFINDEX ) +return false; + + in_dev =dev_get_by_index (net, ifindex); +if (!in_dev) +return false; + + wifi_flags =batadv_netdev_get_wifi_flags (in_dev); +dev_put (in_dev); + +return batadv_is_wifi (wifi_flags); +} +/** * batadv_tt_local_add() - add a new client to the local table or update an * existing client
@@ -712,12 +739,10 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,struct batadv_priv *bat_priv =netdev_priv (mesh_iface);struct batadv_tt_global_entry *tt_global =NULL ;struct batadv_tt_local_entry *tt_local; -struct net *net =dev_net (mesh_iface); -struct net_device *in_dev =NULL ;struct batadv_meshif_vlan *vlan;bool roamed_back = false; -bool iif_is_wifi = false;int packet_size_max; +bool iif_is_wifi;bool ret = false;u8 remote_flags;int hash_added;
@@ -725,14 +750,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,u32 match_mark;bool modified; -if (ifindex !=BATADV_NULL_IFINDEX ) - in_dev =dev_get_by_index (net, ifindex); - -if (in_dev) { -u32 wifi_flags =batadv_netdev_get_wifi_flags (in_dev); - - iif_is_wifi =batadv_is_wifi (wifi_flags); - } + iif_is_wifi =batadv_tt_iif_is_wifi (dev_net (mesh_iface), ifindex); tt_local =batadv_tt_local_hash_find (bat_priv, addr, vid);
@@ -881,7 +899,6 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, ret = true; out: -dev_put (in_dev);batadv_tt_local_entry_put (tt_local);batadv_tt_global_entry_put (tt_global);return ret;
Signature · 1 line
2.47.3
Re: [PATCH net-next 01/15] batman-adv: tt: look up wifi state of incoming interface in helper
This series was applied to netdev/net-next.git (main) by Sven Eckelmann <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Sven Eckelmann <[email protected]>:
Quoted 8 lines · On Mon, 7 Sep 2026 10:18:10 +0200 you wrote:
From: Sven Eckelmann <[email protected]>
batadv_tt_local_add()only needs to know whether the client was seen on a wifi interface. But it kept thenet_devicereference of the incoming interface alive until its own cleanup section, together with a "net" and an "in_dev" variable which are of no interest to the rest of the function.[...]
Here is the summary with links:
- [net-next,01/15] batman-adv: tt: look up wifi state of incoming interface in helper
https://git.kernel.org/netdev/net-next/c/3273a5cd2d74 - [net-next,02/15] batman-adv: tt: extract allocation of new local entries https://git.kernel.org/netdev/net-next/c/defa87f5ce75 - [net-next,03/15] batman-adv: tt: replace forward gotos in batadv_tt_local_add() https://git.kernel.org/netdev/net-next/c/a5e5d2709d10 - [net-next,04/15] batman-adv: tt: extract refresh of existing local entries https://git.kernel.org/netdev/net-next/c/ec6edeb755ec - [net-next,05/15] batman-adv: tt: extract update of dynamic client flags https://git.kernel.org/netdev/net-next/c/d72e16b1c5d5 - [net-next,06/15] batman-adv: tt: extract allocation of new global entries https://git.kernel.org/netdev/net-next/c/d9017aeb40c1 - [net-next,07/15] batman-adv: tt: extract merging of flags into existing global entries https://git.kernel.org/netdev/net-next/c/b535e61347ba - [net-next,08/15] batman-adv: tt: replace add_orig_entry goto in batadv_tt_global_add() https://git.kernel.org/netdev/net-next/c/3f8e8b42f639 - [net-next,09/15] batman-adv: tt: extract removal of the superseded local entry https://git.kernel.org/netdev/net-next/c/228c70d51b10 - [net-next,10/15] batman-adv: tt: extract marking of a removed local entry https://git.kernel.org/netdev/net-next/c/5e02403a4c2e - [net-next,11/15] batman-adv: tt: extract immediate purge of a local entry https://git.kernel.org/netdev/net-next/c/931de98d3960 - [net-next,12/15] batman-adv: tt: drop the cleanup label from batadv_tt_local_remove() https://git.kernel.org/netdev/net-next/c/926013fd40f6 - [net-next,13/15] batman-adv: tt: clarify kernel doc for batadv_tt_local_set_pending_event() https://git.kernel.org/netdev/net-next/c/857fbd765c65 - [net-next,14/15] batman-adv: bat_iv: fix ogm_neigh_is_sob parameters references https://git.kernel.org/netdev/net-next/c/271f3730fc87 - [net-next,15/15] batman-adv: correct batadv_hash_remove kdoc return type https://git.kernel.org/netdev/net-next/c/6d7f71ae4cdc
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Simon Wunderlich
maintainerPATCH 2/15 batman-adv: tt: extract allocation of new local entries
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The code which allocates and initializes a brand new local TT entry makes up more than a third of batadv_tt_local_add(). It only shares the addr, vid and iif_is_wifi parameters with the rest of the function.
Move it to batadv_tt_local_create(), which returns the fully initialized entry. The error paths become plain returns.
The insertion into bat_priv->tt.local_hash intentionally stays in batadv_tt_local_add(), keeping the extra reference for the hash next to the error handling which has to drop it again.
--- net/batman-adv/translation-table.c | 135 +++++++++++++++++------------ 1 file changed, 79 insertions(+), 56 deletions(-)
net/batman-adv/translation-table.c +79 -56
@@ -720,6 +720,84 @@ static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex)return batadv_is_wifi (wifi_flags); } +/** +* batadv_tt_local_create() - allocate and initialize a local TT entry +* @mesh_iface: netdev struct of the mesh interface +* @addr: the mac address of the client to add +* @vid: VLAN identifier +* @iif_is_wifi: whether the client is connected via a wifi interface +* +* The returned entry is not yet part of bat_priv->tt.local_hash. It is marked +* as BATADV_TT_CLIENT_NEW to avoid sending it in a full table response going +* out before the next ttvn increment (consistency check). +* +* Return: the new entry with an initialized reference counter on success, NULL +* otherwise. +*/ +static struct batadv_tt_local_entry * +batadv_tt_local_create (struct net_device *mesh_iface,const u8 *addr, +unsigned short vid,bool iif_is_wifi) +{ +struct batadv_priv *bat_priv =netdev_priv (mesh_iface); +struct batadv_tt_local_entry *tt_local; +struct batadv_meshif_vlan *vlan; +int packet_size_max; +int table_size; + +/* Ignore the client if we cannot send it in a full table response. */ + table_size =batadv_tt_local_table_transmit_size (bat_priv); + table_size +=batadv_tt_len (1 ); + packet_size_max =READ_ONCE (bat_priv->packet_size_max); +if (table_size > packet_size_max) { +net_ratelimited_function (batadv_info, mesh_iface, +"Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n" , + table_size, packet_size_max, addr); +return NULL ; + } + + tt_local =kmem_cache_alloc (batadv_tl_cache,GFP_ATOMIC ); +if (!tt_local) +return NULL ; + +/* increase the refcounter of the related vlan */ + vlan =batadv_meshif_vlan_get (bat_priv, vid); +if (!vlan) { +net_ratelimited_function (batadv_info, mesh_iface, +"adding TT local entry %pM to non-existent VLAN %d\n" , + addr,batadv_print_vid (vid)); +kmem_cache_free (batadv_tl_cache, tt_local); +return NULL ; + } + +batadv_dbg (BATADV_DBG_TT , bat_priv, +"Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n" , + addr,batadv_print_vid (vid), + (u8 )atomic_read (&bat_priv->tt.vn)); + +ether_addr_copy (tt_local->common.addr, addr); + tt_local->common.vid = vid; +kref_init (&tt_local->common.refcount); + tt_local->last_seen = jiffies; + tt_local->common.added_at = tt_local->last_seen; + tt_local->vlan = vlan; +spin_lock_init (&tt_local->common.flags_lock); + + scoped_guard(spinlock_bh, &tt_local->common.flags_lock) { + tt_local->common.flags =BATADV_TT_CLIENT_NEW ; +if (iif_is_wifi) + tt_local->common.flags |=BATADV_TT_CLIENT_WIFI ; + +/* the batman interface mac and multicast addresses should never +* be purged +*/ +if (batadv_compare_eth (addr, mesh_iface->dev_addr) || +is_multicast_ether_addr (addr)) + tt_local->common.flags |=BATADV_TT_CLIENT_NOPURGE ; + } + +return tt_local; +} +/** * batadv_tt_local_add() - add a new client to the local table or update an * existing client
@@ -739,14 +817,11 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,struct batadv_priv *bat_priv =netdev_priv (mesh_iface);struct batadv_tt_global_entry *tt_global =NULL ;struct batadv_tt_local_entry *tt_local; -struct batadv_meshif_vlan *vlan;bool roamed_back = false; -int packet_size_max;bool iif_is_wifi;bool ret = false;u8 remote_flags;int hash_added; -int table_size;u32 match_mark;bool modified;
@@ -793,62 +868,10 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, goto check_roaming; } -/* Ignore the client if we cannot send it in a full table response. */ - table_size =batadv_tt_local_table_transmit_size (bat_priv); - table_size +=batadv_tt_len (1 ); - packet_size_max =READ_ONCE (bat_priv->packet_size_max); -if (table_size > packet_size_max) { -net_ratelimited_function (batadv_info, mesh_iface, -"Local translation table size (%i) exceeds maximum packet size (%i); Ignoring new local tt entry: %pM\n" , - table_size, packet_size_max, addr); - goto out; - } - - tt_local =kmem_cache_alloc (batadv_tl_cache,GFP_ATOMIC ); + tt_local =batadv_tt_local_create (mesh_iface, addr, vid, iif_is_wifi);if (!tt_local) goto out; -/* increase the refcounter of the related vlan */ - vlan =batadv_meshif_vlan_get (bat_priv, vid); -if (!vlan) { -net_ratelimited_function (batadv_info, mesh_iface, -"adding TT local entry %pM to non-existent VLAN %d\n" , - addr,batadv_print_vid (vid)); -kmem_cache_free (batadv_tl_cache, tt_local); - tt_local =NULL ; - goto out; - } - -batadv_dbg (BATADV_DBG_TT , bat_priv, -"Creating new local tt entry: %pM (vid: %d, ttvn: %d)\n" , - addr,batadv_print_vid (vid), - (u8 )atomic_read (&bat_priv->tt.vn)); - -ether_addr_copy (tt_local->common.addr, addr); - tt_local->common.vid = vid; -kref_init (&tt_local->common.refcount); - tt_local->last_seen = jiffies; - tt_local->common.added_at = tt_local->last_seen; - tt_local->vlan = vlan; -spin_lock_init (&tt_local->common.flags_lock); - -spin_lock_bh (&tt_local->common.flags_lock); -/* The local entry has to be marked as NEW to avoid to send it in -* a full table response going out before the next ttvn increment -* (consistency check) -*/ - tt_local->common.flags =BATADV_TT_CLIENT_NEW ; -if (iif_is_wifi) - tt_local->common.flags |=BATADV_TT_CLIENT_WIFI ; - -/* the batman interface mac and multicast addresses should never be -* purged -*/ -if (batadv_compare_eth (addr, mesh_iface->dev_addr) || -is_multicast_ether_addr (addr)) - tt_local->common.flags |=BATADV_TT_CLIENT_NOPURGE ; -spin_unlock_bh (&tt_local->common.flags_lock); -kref_get (&tt_local->common.refcount); hash_added = batadv_hash_add(bat_priv->tt.local_hash, batadv_compare_tt, batadv_choose_tt, &tt_local->common,
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 3/15 batman-adv: tt: replace forward gotos in batadv_tt_local_add()
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
batadv_tt_local_add() used two labels in the middle of the function to express which parts of the common tail have to be executed: "add_event" to announce a (re-)added client and "check_roaming" to skip that announcement. Jumping forward into the middle of a function makes it hard to see which path ends up sending an ADD event. Especially since the PENDING branch reached "add_event" while the branch right below it reached "check_roaming" instead.
Express the same in an "added" variable and turn the two client cases into a plain if/else. The PENDING check returned early before the ROAM check could run, so it becomes an "else if".
--- net/batman-adv/translation-table.c | 43 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 23 deletions(-)
net/batman-adv/translation-table.c +20 -23
@@ -818,6 +818,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,struct batadv_tt_global_entry *tt_global =NULL ;struct batadv_tt_local_entry *tt_local;bool roamed_back = false; +bool added = false;bool iif_is_wifi;bool ret = false;u8 remote_flags;
@@ -846,12 +847,8 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,* flag can be reset like it was never enqueued */ tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING ; -spin_unlock_bh (&tt_local->common.flags_lock); - - goto add_event; - } - -if (tt_local->common.flags &BATADV_TT_CLIENT_ROAM ) { + added = true; + }else if (tt_local->common.flags &BATADV_TT_CLIENT_ROAM ) {batadv_dbg (BATADV_DBG_TT , bat_priv,"Roaming client %pM (vid: %d) came back to its original location\n" , addr,batadv_print_vid (vid));
@@ -864,29 +861,29 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, roamed_back = true; }spin_unlock_bh (&tt_local->common.flags_lock); + }else { + tt_local =batadv_tt_local_create (mesh_iface, addr, vid, iif_is_wifi); +if (!tt_local) + goto out; - goto check_roaming; - } - - tt_local =batadv_tt_local_create (mesh_iface, addr, vid, iif_is_wifi); -if (!tt_local) - goto out; +kref_get (&tt_local->common.refcount); + hash_added =batadv_hash_add (bat_priv->tt.local_hash, batadv_compare_tt, + batadv_choose_tt, &tt_local->common, + &tt_local->common.hash_entry); -kref_get (&tt_local->common.refcount); - hash_added =batadv_hash_add (bat_priv->tt.local_hash, batadv_compare_tt, - batadv_choose_tt, &tt_local->common, - &tt_local->common.hash_entry); +if (unlikely (hash_added !=0 )) { +/* remove the reference for the hash */ +batadv_tt_local_entry_put (tt_local); + goto out; + } -if (unlikely (hash_added !=0 )) { -/* remove the reference for the hash */ -batadv_tt_local_entry_put (tt_local); - goto out; + added = true; } -add_event: -batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); +/* announce the (re-)added client to the mesh */ +if (added) +batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); -check_roaming:batadv_tt_local_add_roam (bat_priv, tt_global, roamed_back);spin_lock_bh (&tt_local->common.flags_lock);
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 4/15 batman-adv: tt: extract refresh of existing local entries
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The handling of a client which is already part of the local translation table is independent from the rest of batadv_tt_local_add(): it only refreshes last_seen and evaluates the PENDING and ROAM flags of the entry which was just looked up.
Move it to batadv_tt_local_add_existing(). It reports via its return value whether the client has to be announced to the mesh again and whether the client roamed back to its original location.
--- net/batman-adv/translation-table.c | 78 +++++++++++++++++++----------- 1 file changed, 51 insertions(+), 27 deletions(-)
net/batman-adv/translation-table.c +51 -27
@@ -720,6 +720,55 @@ static bool batadv_tt_iif_is_wifi(struct net *net, int ifindex)return batadv_is_wifi (wifi_flags); } +/** +* batadv_tt_local_add_existing() - refresh an already known local TT entry +* @bat_priv: the bat priv with all the mesh interface information +* @tt_local: the local TT entry which was found in the local table +* @roamed_back: set to true when the client returned to its original location +* +* Return: true when the client has to be announced to the mesh again, false +* otherwise. +*/ +static bool batadv_tt_local_add_existing (struct batadv_priv *bat_priv, +struct batadv_tt_local_entry *tt_local, +bool *roamed_back) +{ +struct batadv_tt_common_entry *common = &tt_local->common; + + tt_local->last_seen = jiffies; + + scoped_guard(spinlock_bh, &common->flags_lock) { +if (common->flags &BATADV_TT_CLIENT_PENDING ) { +batadv_dbg (BATADV_DBG_TT , bat_priv, +"Re-adding pending client %pM (vid: %d)\n" , + common->addr,batadv_print_vid (common->vid)); +/* whatever the reason why the PENDING flag was set, +* this is a client which was enqueued to be removed in +* this orig_interval. Since it popped up again, the +* flag can be reset like it was never enqueued +*/ + common->flags &= ~BATADV_TT_CLIENT_PENDING ; + +return true; + } + +if (common->flags &BATADV_TT_CLIENT_ROAM ) { +batadv_dbg (BATADV_DBG_TT , bat_priv, +"Roaming client %pM (vid: %d) came back to its original location\n" , + common->addr,batadv_print_vid (common->vid)); +/* the ROAM flag is set because this client roamed away +* and the node got a roaming_advertisement message. Now +* that the client popped up again at its original +* location such flag can be unset +*/ + common->flags &= ~BATADV_TT_CLIENT_ROAM ; + *roamed_back = true; + } + } + +return false; +} +/** * batadv_tt_local_create() - allocate and initialize a local TT entry * @mesh_iface: netdev struct of the mesh interface
@@ -834,33 +883,8 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr, tt_global =batadv_tt_global_hash_find (bat_priv, addr, vid);if (tt_local) { - tt_local->last_seen = jiffies; - -spin_lock_bh (&tt_local->common.flags_lock); -if (tt_local->common.flags &BATADV_TT_CLIENT_PENDING ) { -batadv_dbg (BATADV_DBG_TT , bat_priv, -"Re-adding pending client %pM (vid: %d)\n" , - addr,batadv_print_vid (vid)); -/* whatever the reason why the PENDING flag was set, -* this is a client which was enqueued to be removed in -* this orig_interval. Since it popped up again, the -* flag can be reset like it was never enqueued -*/ - tt_local->common.flags &= ~BATADV_TT_CLIENT_PENDING ; - added = true; - }else if (tt_local->common.flags &BATADV_TT_CLIENT_ROAM ) { -batadv_dbg (BATADV_DBG_TT , bat_priv, -"Roaming client %pM (vid: %d) came back to its original location\n" , - addr,batadv_print_vid (vid)); -/* the ROAM flag is set because this client roamed away -* and the node got a roaming_advertisement message. Now -* that the client popped up again at its original -* location such flag can be unset -*/ - tt_local->common.flags &= ~BATADV_TT_CLIENT_ROAM ; - roamed_back = true; - } -spin_unlock_bh (&tt_local->common.flags_lock); + added =batadv_tt_local_add_existing (bat_priv, tt_local, + &roamed_back); }else { tt_local =batadv_tt_local_create (mesh_iface, addr, vid, iif_is_wifi);if (!tt_local)
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 5/15 batman-adv: tt: extract update of dynamic client flags
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The WIFI and ISOLA flags are re-evaluated on every batadv_tt_local_add() call, no matter whether a new entry was created or an existing one was refreshed. It is mostly isolated from the rest of the batadv_tt_local_add().
Move it to batadv_tt_local_update_flags(). To allow the caller to trigger the queuing of ADD events, it returns whether one of the flags announced to the other nodes actually changed.
--- net/batman-adv/translation-table.c | 79 +++++++++++++++++++----------- 1 file changed, 50 insertions(+), 29 deletions(-)
net/batman-adv/translation-table.c +50 -29
@@ -847,6 +847,55 @@ batadv_tt_local_create(struct net_device *mesh_iface, const u8 *addr,return tt_local; } +/** +* batadv_tt_local_update_flags() - update the dynamic flags of a local entry +* @bat_priv: the bat priv with all the mesh interface information +* @tt_local: the local TT entry to update +* @iif_is_wifi: whether the client is connected via a wifi interface +* @mark: the value contained in the skb->mark field of the received packet (if +* any) +* +* Return: true if a flag announced to the other nodes was modified, false +* otherwise. +*/ +static bool +batadv_tt_local_update_flags (struct batadv_priv *bat_priv, +struct batadv_tt_local_entry *tt_local, +bool iif_is_wifi,u32 mark) +{ +struct batadv_tt_common_entry *common = &tt_local->common; +u8 remote_flags; +u32 match_mark; +bool modified; + + scoped_guard(spinlock_bh, &common->flags_lock) { +/* store the current remote flags before altering them. This +* helps understanding is flags are changing or not +*/ + remote_flags = common->flags &BATADV_TT_REMOTE_MASK ; + +if (iif_is_wifi) + common->flags |=BATADV_TT_CLIENT_WIFI ; +else + common->flags &= ~BATADV_TT_CLIENT_WIFI ; + +/* check the mark in the skb: if it's equal to the configured +* isolation_mark, it means the packet is coming from an +* isolated non-mesh client +*/ + match_mark = (mark & bat_priv->isolation_mark_mask); +if (bat_priv->isolation_mark_mask && + match_mark == bat_priv->isolation_mark) + common->flags |=BATADV_TT_CLIENT_ISOLA ; +else + common->flags &= ~BATADV_TT_CLIENT_ISOLA ; + + modified = remote_flags ^ (common->flags &BATADV_TT_REMOTE_MASK ); + } + +return modified; +} +/** * batadv_tt_local_add() - add a new client to the local table or update an * existing client
@@ -870,10 +919,7 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,bool added = false;bool iif_is_wifi;bool ret = false; -u8 remote_flags;int hash_added; -u32 match_mark; -bool modified; iif_is_wifi =batadv_tt_iif_is_wifi (dev_net (mesh_iface), ifindex);
@@ -910,35 +956,10 @@ bool batadv_tt_local_add(struct net_device *mesh_iface, const u8 *addr,batadv_tt_local_add_roam (bat_priv, tt_global, roamed_back); -spin_lock_bh (&tt_local->common.flags_lock); -/* store the current remote flags before altering them. This helps -* understanding is flags are changing or not -*/ - remote_flags = tt_local->common.flags &BATADV_TT_REMOTE_MASK ; - -if (iif_is_wifi) - tt_local->common.flags |=BATADV_TT_CLIENT_WIFI ; -else - tt_local->common.flags &= ~BATADV_TT_CLIENT_WIFI ; - -/* check the mark in the skb: if it's equal to the configured -* isolation_mark, it means the packet is coming from an isolated -* non-mesh client -*/ - match_mark = (mark & bat_priv->isolation_mark_mask); -if (bat_priv->isolation_mark_mask && - match_mark == bat_priv->isolation_mark) - tt_local->common.flags |=BATADV_TT_CLIENT_ISOLA ; -else - tt_local->common.flags &= ~BATADV_TT_CLIENT_ISOLA ; - - modified = remote_flags ^ (tt_local->common.flags &BATADV_TT_REMOTE_MASK ); -spin_unlock_bh (&tt_local->common.flags_lock); -/* if any "dynamic" flag has been modified, resend an ADD event for this * entry so that all the nodes can get the new flags */ -if (modified) +if (batadv_tt_local_update_flags (bat_priv, tt_local, iif_is_wifi, mark))batadv_tt_local_event (bat_priv, tt_local,BATADV_NO_FLAGS ); ret = true;
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 6/15 batman-adv: tt: extract allocation of new global entries
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The code which allocates and initializes a brand new global TT entry makes up a third of batadv_tt_global_add() and only needs the tt_addr, vid and flags arguments. It is also the only part of the "new entry" branch which does not deal with the global hash.
Move it to batadv_tt_global_create() and let it return the initialized entry.
--- net/batman-adv/translation-table.c | 76 ++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 25 deletions(-)
net/batman-adv/translation-table.c +51 -25
@@ -1832,6 +1832,56 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,spin_unlock_bh (&tt_global->list_lock); } +/** +* batadv_tt_global_create() - allocate and initialize a global TT entry +* @tt_addr: the mac address of the non-mesh client +* @vid: VLAN identifier +* @flags: TT flags that have to be set for this non-mesh client +* +* The returned entry is not yet part of bat_priv->tt.global_hash and has an +* empty originator list. +* +* Return: the new entry with an initialized reference counter on success, NULL +* otherwise. +*/ +static struct batadv_tt_global_entry * +batadv_tt_global_create (const unsigned char *tt_addr,unsigned short vid, +u16 flags) +{ +struct batadv_tt_global_entry *tt_global_entry; +struct batadv_tt_common_entry *common; + + tt_global_entry =kmem_cache_zalloc (batadv_tg_cache,GFP_ATOMIC ); +if (!tt_global_entry) +return NULL ; + + common = &tt_global_entry->common; +ether_addr_copy (common->addr, tt_addr); + common->vid = vid; +spin_lock_init (&common->flags_lock); + +if (!is_multicast_ether_addr (common->addr)) { +scoped_guard (spinlock_bh, &common->flags_lock) + common->flags = flags & (~BATADV_TT_SYNC_MASK); + } + + tt_global_entry->roam_at =0 ; +/* node must store current time in case of roaming. This is +* needed to purge this entry out on timeout (if nobody claims +* it) +*/ +if (flags &BATADV_TT_CLIENT_ROAM ) + tt_global_entry->roam_at = jiffies; +kref_init (&common->refcount); + common->added_at = jiffies; + +INIT_HLIST_HEAD (&tt_global_entry->orig_list); +atomic_set (&tt_global_entry->orig_list_count,0 ); +spin_lock_init (&tt_global_entry->list_lock); + +return tt_global_entry; +} +/** * batadv_tt_global_add() - add a new TT global entry or update an existing one * @bat_priv: the bat priv with all the mesh interface information
@@ -1883,35 +1933,11 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, }if (!tt_global_entry) { - tt_global_entry =kmem_cache_zalloc (batadv_tg_cache, -GFP_ATOMIC ); + tt_global_entry =batadv_tt_global_create (tt_addr, vid, flags);if (!tt_global_entry) goto out; common = &tt_global_entry->common; -ether_addr_copy (common->addr, tt_addr); - common->vid = vid; -spin_lock_init (&common->flags_lock); - -if (!is_multicast_ether_addr (common->addr)) { -spin_lock_bh (&common->flags_lock); - common->flags = flags & (~BATADV_TT_SYNC_MASK ); -spin_unlock_bh (&common->flags_lock); - } - - tt_global_entry->roam_at =0 ; -/* node must store current time in case of roaming. This is -* needed to purge this entry out on timeout (if nobody claims -* it) -*/ -if (flags &BATADV_TT_CLIENT_ROAM ) - tt_global_entry->roam_at = jiffies; -kref_init (&common->refcount); - common->added_at = jiffies; - -INIT_HLIST_HEAD (&tt_global_entry->orig_list); -atomic_set (&tt_global_entry->orig_list_count,0 ); -spin_lock_init (&tt_global_entry->list_lock);kref_get (&common->refcount); hash_added = batadv_hash_add(bat_priv->tt.global_hash,
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 7/15 batman-adv: tt: extract merging of flags into existing global entries
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
When an already known global TT entry is announced again, its flags have to be merged with the announced ones. Two of the merge steps also decide whether the originator list has to be purged before the announced originator is added.
Move this to batadv_tt_global_merge_flags() and let it report via its return value whether the originator list has to be purged.
--- net/batman-adv/translation-table.c | 87 ++++++++++++++++++------------ 1 file changed, 52 insertions(+), 35 deletions(-)
net/batman-adv/translation-table.c +52 -35
@@ -1832,6 +1832,57 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,spin_unlock_bh (&tt_global->list_lock); } +/** +* batadv_tt_global_merge_flags() - merge announced flags into a global TT entry +* @tt_global_entry: the global TT entry to update +* @flags: TT flags announced for this non-mesh client +* +* Return: true if the originator list of @tt_global_entry has to be purged +* before the announced originator is added, false otherwise. +*/ +static bool +batadv_tt_global_merge_flags (struct batadv_tt_global_entry *tt_global_entry, +u16 flags) +{ +struct batadv_tt_common_entry *common = &tt_global_entry->common; +bool delete = false; + + scoped_guard(spinlock_bh, &common->flags_lock) { +/* if the client was temporary added before receiving the first +* OGM announcing it, we have to clear the TEMP flag. Also, +* remove the previous temporary orig node and re-add it +* if required. If the orig entry changed, the new one which +* is a non-temporary entry is preferred. +*/ +if (common->flags &BATADV_TT_CLIENT_TEMP ) { + delete = true; + common->flags &= ~BATADV_TT_CLIENT_TEMP ; + } + +/* the change can carry possible "attribute" flags like the +* TT_CLIENT_TEMP, therefore they have to be copied in the +* client entry +*/ +if (!is_multicast_ether_addr (common->addr)) + common->flags |= flags & (~BATADV_TT_SYNC_MASK ); + +/* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only +* one originator left in the list and we previously received a +* delete + roaming change for this originator. +* +* We should first delete the old originator before adding the +* new one. +*/ +if (common->flags &BATADV_TT_CLIENT_ROAM ) { + delete = true; + tt_global_entry->roam_at =0 ; + common->flags &= ~BATADV_TT_CLIENT_ROAM ; + } + } + +return delete; +} +/** * batadv_tt_global_create() - allocate and initialize a global TT entry * @tt_addr: the mac address of the non-mesh client
@@ -1974,41 +2025,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, goto add_orig_entry; } - delete = false; - -spin_lock_bh (&common->flags_lock); -/* if the client was temporary added before receiving the first -* OGM announcing it, we have to clear the TEMP flag. Also, -* remove the previous temporary orig node and re-add it -* if required. If the orig entry changed, the new one which -* is a non-temporary entry is preferred. -*/ -if (common->flags &BATADV_TT_CLIENT_TEMP ) { - delete = true; - common->flags &= ~BATADV_TT_CLIENT_TEMP ; - } - -/* the change can carry possible "attribute" flags like the -* TT_CLIENT_TEMP, therefore they have to be copied in the -* client entry -*/ -if (!is_multicast_ether_addr (common->addr)) - common->flags |= flags & (~BATADV_TT_SYNC_MASK ); - -/* If there is the BATADV_TT_CLIENT_ROAM flag set, there is only -* one originator left in the list and we previously received a -* delete + roaming change for this originator. -* -* We should first delete the old originator before adding the -* new one. -*/ -if (common->flags &BATADV_TT_CLIENT_ROAM ) { - delete = true; - tt_global_entry->roam_at =0 ; - common->flags &= ~BATADV_TT_CLIENT_ROAM ; - } -spin_unlock_bh (&common->flags_lock); - + delete =batadv_tt_global_merge_flags (tt_global_entry, flags);if (delete)batadv_tt_global_del_orig_list (tt_global_entry); }
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 8/15 batman-adv: tt: replace add_orig_entry goto in batadv_tt_global_add()
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The "add_orig_entry" label was only used to skip the flag merging of the non-temporary path. Which means that the code jumping to it and the code below it are the two halves of an if/else.
Both halves now only decide whether the originator list has to be purged, so turn them into an if/else and purge the list at a single place.
--- net/batman-adv/translation-table.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/batman-adv/translation-table.c +5 -4
@@ -2021,15 +2021,16 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,if (batadv_tt_global_entry_has_orig (tt_global_entry, orig_node,NULL )) goto out_remove; -batadv_tt_global_del_orig_list (tt_global_entry); - goto add_orig_entry; + + delete = true; + }else { + delete =batadv_tt_global_merge_flags (tt_global_entry, flags); } - delete =batadv_tt_global_merge_flags (tt_global_entry, flags);if (delete)batadv_tt_global_del_orig_list (tt_global_entry); } -add_orig_entry: +/* add the new orig_entry (if needed) or update it */ batadv_tt_global_orig_entry_add (tt_global_entry, orig_node, ttvn, flags &BATADV_TT_SYNC_MASK );
Signature · 1 line
2.47.3
A message that is not in the archive (sent off-list or not yet received): [email protected]
Sven Eckelmann
maintainerRe: [PATCH net-next 08/15] batman-adv: tt: replace add_orig_entry goto in batadv_tt_global_add()
On Tuesday, 8 September 2026 10:27:01 CEST [email protected] wrote:
[...]
Quoted 49 lines
This commit refactors
batadv_tt_global_add()by removing theadd_orig_entrylabel and turning the flag merging and list purging logic into a more direct if/else structure.Quoted 9 lines
net/batman-adv/translation-table.c +0
-1@@ -2021,15 +2021,16 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv,if (batadv_tt_global_entry_has_orig (tt_global_entry, orig_node,NULL )) goto out_remove; -batadv_tt_global_del_orig_list (tt_global_entry);net/batman-adv/translation-table.c static bool batadv_tt_global_add(struct batadv_priv *bat_priv, · line 2031
Quoted 10 lines
net/batman-adv/translation-table.c +4
-2- goto add_orig_entry; + + delete = true; + }else { + delete =batadv_tt_global_merge_flags (tt_global_entry, flags); } - delete =batadv_tt_global_merge_flags (tt_global_entry, flags);if (delete)batadv_tt_global_del_orig_list (tt_global_entry);[Severity: High]
This is a pre-existing issue, but this patch preserves and refactors the vulnerable code structure without resolving an underlying race condition.Could this lead to a Time-of-Check to Time-of-Use race that permanently drops a valid originator from the global translation table?
For example, if two CPUs concurrently execute
batadv_tt_global_add()for the same translation table entry:CPU 0 (adding a temporary client):
Evaluatesglobal_flagswithout locking and sets delete = true.CPU 1 (adding a non-temporary client):
Merges its non-temporary flags, clears the TEMP flag, purges the list, and adds its non-temporary originator.CPU 0 (resuming based on its stale delete snapshot):
Incorrectly purges CPU 1's newly added non-temporary originator and adds its own temporary one.Because the TEMP flag was cleared by CPU 1, the entry might never timeout or update correctly, potentially causing a permanent routing blackhole for the affected client.
Quoted 7 lines
A similar race appears to exist between two non-temporary additions. If CPU 1 is preempted after
batadv_tt_global_merge_flags()returns true, CPU 2 might return false from the merge and add its originator. When CPU 1 resumes, it would purge CPU 2's originator based on the stale delete boolean.Is additional synchronization needed around the delete decision and the list purging to prevent these concurrent additions from stepping on each other?
Same as last time: https://www.open-mesh.org/issues/474
Regards,
Sven
Simon Wunderlich
maintainerPATCH 9/15 batman-adv: tt: extract removal of the superseded local entry
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
A client which was announced by another originator is no longer a local client. The code which drops it from the local table and takes over its WIFI flag is the second cleanup stage of batadv_tt_global_add() and needed its own goto to skip over the multicast case.
Move it to batadv_tt_global_purge_local().
--- net/batman-adv/translation-table.c | 61 ++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 20 deletions(-)
net/batman-adv/translation-table.c +41 -20
@@ -1832,6 +1832,46 @@ batadv_tt_global_orig_entry_add(struct batadv_tt_global_entry *tt_global,spin_unlock_bh (&tt_global->list_lock); } +/** +* batadv_tt_global_purge_local() - drop the local entry of an announced client +* @bat_priv: the bat priv with all the mesh interface information +* @tt_global_entry: the global TT entry of the announced client +* @flags: TT flags announced for this non-mesh client +* +* A client which is announced by another originator is no longer a local +* client. Remove it from the local table and take over the WIFI flag it was +* tracked with. +*/ +static void +batadv_tt_global_purge_local (struct batadv_priv *bat_priv, +struct batadv_tt_global_entry *tt_global_entry, +u16 flags) +{ +struct batadv_tt_common_entry *common = &tt_global_entry->common; +u16 local_flags; + +/* Do not remove multicast addresses from the local hash on +* global additions +*/ +if (is_multicast_ether_addr (common->addr)) +return ; + +/* remove address from local hash if present */ + local_flags =batadv_tt_local_remove (bat_priv, common->addr, common->vid, +"global tt received" , + flags &BATADV_TT_CLIENT_ROAM ); + + scoped_guard(spinlock_bh, &common->flags_lock) { + common->flags |= local_flags &BATADV_TT_CLIENT_WIFI ; + +if (!(flags &BATADV_TT_CLIENT_ROAM )) +/* this is a normal global add. Therefore the client is +* not in a roaming state anymore. +*/ + common->flags &= ~BATADV_TT_CLIENT_ROAM ; + } +} +/** * batadv_tt_global_merge_flags() - merge announced flags into a global TT entry * @tt_global_entry: the global TT entry to update
@@ -2042,26 +2082,7 @@ static bool batadv_tt_global_add(struct batadv_priv *bat_priv, ret = true; out_remove: -/* Do not remove multicast addresses from the local hash on -* global additions -*/ -if (is_multicast_ether_addr (tt_addr)) - goto out; - -/* remove address from local hash if present */ - local_flags =batadv_tt_local_remove (bat_priv, tt_addr, vid, -"global tt received" , - flags &BATADV_TT_CLIENT_ROAM ); - -spin_lock_bh (&tt_global_entry->common.flags_lock); - tt_global_entry->common.flags |= local_flags &BATADV_TT_CLIENT_WIFI ; - -if (!(flags &BATADV_TT_CLIENT_ROAM )) -/* this is a normal global add. Therefore the client is not in a -* roaming state anymore. -*/ - tt_global_entry->common.flags &= ~BATADV_TT_CLIENT_ROAM ; -spin_unlock_bh (&tt_global_entry->common.flags_lock); +batadv_tt_global_purge_local (bat_priv, tt_global_entry, flags); out:batadv_tt_global_entry_put (tt_global_entry);
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerRe: [PATCH net-next 09/15] batman-adv: tt: extract removal of the superseded local entry
[...]
Quoted 28 lines
Quoted 10 lines
+/**
+ *batadv_tt_global_purge_local()- drop the local entry of an announced client
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @tt_global_entry: the global TT entry of the announced client
+ * @flags: TT flags announced for this non-mesh client
+ *
+ * A client which is announced by another originator is no longer a local
+ * client. Remove it from the local table and take over the WIFI flag it was
+ * tracked with.
+ */Discovered by: opus-5 · Missed by: sonnet-5, gpt-5-6-sol, sashiko-gemini · Confirmed by: gpt-5-6-sol This isn't a bug, but should the new kernel-doc for
batadv_tt_global_purge_local()mention the two things the body actually
does beyond the summary?The doc says removal from the local table happens, but multicast addresses take an early return and nothing is removed:
if (is_multicast_ether_addr(common->addr)) return;The doc also does not mention that the global entry's own flags are modified, not just the inherited WIFI flag:
if (!(flags & BATADV_TT_CLIENT_ROAM)) common->flags &= ~BATADV_TT_CLIENT_ROAM;
Quoted 8 lines
Since
flags_lockis documented in structbatadv_tt_common_entryas protecting both @flags and @batadv_tt_global_entry.roam_at, a reader of the new standalone helper might not expect the namepurge_local()to also reset the global roaming state.Both behaviours are unchanged from the previous inline code under the
out_removelabel inbatadv_tt_global_add(), so this is only about the description of the new helper.
See https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/
Regards,
Sven
Simon Wunderlich
maintainerPATCH 10/15 batman-adv: tt: extract marking of a removed local entry
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The first locked section of batadv_tt_local_remove() does three things at once
* it snapshots the flags for the return value
* it marks the client as ROAMed
* it decides whether the entry has to survive until the next ttvn increment
But this complex locked section is in the middle of the function and cannot be written as scoped_guard() due to goto's in this routine.
Move it to batadv_tt_local_mark_removed() and report the decision via its return value. But leave the batadv_tt_local_set_pending_event() flag assembly outside the function because it has no locking requirements.
--- net/batman-adv/translation-table.c | 48 ++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 13 deletions(-)
net/batman-adv/translation-table.c +35 -13
@@ -1443,6 +1443,38 @@ batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv, batadv_print_vid(tt_local_entry->common.vid), message); } +/** +* batadv_tt_local_mark_removed() - mark a local entry as removed +* @tt_local_entry: local TT entry to mark +* @roaming: true if the deletion is due to a roaming event +* @curr_flags: pointer to store the flags of the entry before it was marked +* +* Return: true if the entry has to be kept in the local table until the next +* ttvn increment, false if it can be purged immediately. +*/ +static bool +batadv_tt_local_mark_removed (struct batadv_tt_local_entry *tt_local_entry, +bool roaming,u16 *curr_flags) +{ +struct batadv_tt_common_entry *common = &tt_local_entry->common; +bool pending = false; + + scoped_guard(spinlock_bh, &common->flags_lock) { + *curr_flags = common->flags; + +/* mark the local client as ROAMed */ +if (roaming) + common->flags |=BATADV_TT_CLIENT_ROAM ; + +if (!(common->flags &BATADV_TT_CLIENT_NEW )) { + common->flags |=BATADV_TT_CLIENT_PENDING ; + pending = true; + } + } + +return pending; +} +/** * batadv_tt_local_remove() - logically remove an entry from the local table * @bat_priv: the bat priv with all the mesh interface information
@@ -1467,26 +1499,16 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,if (!tt_local_entry) goto out; -spin_lock_bh (&tt_local_entry->common.flags_lock); - curr_flags = tt_local_entry->common.flags; - flags =BATADV_TT_CLIENT_DEL ;/* if this global entry addition is due to a roaming, the node has to * mark the local entry as "roamed" in order to correctly reroute * packets later */ -if (roaming) { +if (roaming) flags |=BATADV_TT_CLIENT_ROAM ; -/* mark the local client as ROAMed */ - tt_local_entry->common.flags |=BATADV_TT_CLIENT_ROAM ; - } - -if (!(tt_local_entry->common.flags &BATADV_TT_CLIENT_NEW )) { - tt_local_entry->common.flags |=BATADV_TT_CLIENT_PENDING ; - pending = true; - } -spin_unlock_bh (&tt_local_entry->common.flags_lock); + pending =batadv_tt_local_mark_removed (tt_local_entry, roaming, + &curr_flags);if (pending) {batadv_tt_local_set_pending_event (bat_priv, tt_local_entry, flags, message);
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerRe: [PATCH net-next 10/15] batman-adv: tt: extract marking of a removed local entry
[...]
Quoted 31 lines
Discovered by: opus-5, old-prompts · Missed by: gpt-5-6-sol, sashiko-gemini
Two comments in
batadv_tt_local_remove()look like they no longer match the code after the move.First, the untouched comment further down in
batadv_tt_local_remove()still refers to a check "above":net/batman-adv/translation-table.c:batadv_tt_local_remove() { ... /* batadv_tt_local_transition_new() may have committed the entry and * thus counted it in the local table size since the BATADV_TT_CLIENT_NEW * check above. */ if (!(batadv_tt_flags_get(&tt_local_entry->common) & BATADV_TT_CLIENT_NEW)) batadv_tt_local_size_dec(bat_priv, tt_local_entry->common.vid); ... }After this patch there is no
BATADV_TT_CLIENT_NEWtest left anywhere above that point in this function; the only one is now inside the new helper:net/batman-adv/translation-table.c:batadv_tt_local_mark_removed() { ... if (!(common->flags & BATADV_TT_CLIENT_NEW)) { common->flags |= BATADV_TT_CLIENT_PENDING; pending = true; } ... }
Quoted 2 lines
Should the wording be updated in this patch to name the helper, so the size-accounting race stays traceable from the function it is documented in?
See patch 11 "batman-adv: tt: extract immediate purge of a local entry"
Quoted 11 lines
Second, the retained comment above the "if (roaming)" line still says the node "has to mark the local entry as roamed", but the code it now precedes only assembles the announcement flag word; the actual
common->flags|=BATADV_TT_CLIENT_ROAMhappens in thebatadv_tt_local_mark_removed()call two lines below. Would it read better moved or reworded so it describes the flag assembly?No functional change is apparent here: flags is fully computed before the call,
*curr_flagsis written unconditionally inside the guard socurr_flagsis always initialized for the caller, and the helper is only reached after the !tt_local_entry early goto.
See https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/
Regards,
Sven
Simon Wunderlich
maintainerPATCH 11/15 batman-adv: tt: extract immediate purge of a local entry
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
A client which was added after the last ttvn increment was never announced and can be dropped from the local table right away. The code doing so is the second half of batadv_tt_local_remove() and needed a goto to skip the accounting when the entry was already gone from the hash.
Move it to batadv_tt_local_remove_now().
--- net/batman-adv/translation-table.c | 57 +++++++++++++++++++----------- 1 file changed, 37 insertions(+), 20 deletions(-)
net/batman-adv/translation-table.c +37 -20
@@ -1475,6 +1475,42 @@ batadv_tt_local_mark_removed(struct batadv_tt_local_entry *tt_local_entry,return pending; } +/** +* batadv_tt_local_remove_now() - purge a local entry which was never announced +* @bat_priv: the bat priv with all the mesh interface information +* @tt_local_entry: local TT entry to purge +* +* A client which was added right after the last ttvn increment was never sent +* to the other nodes. It can therefore be dropped from the local table without +* waiting for the next ttvn increment. +*/ +static void +batadv_tt_local_remove_now (struct batadv_priv *bat_priv, +struct batadv_tt_local_entry *tt_local_entry) +{ +struct batadv_tt_common_entry *common = &tt_local_entry->common; +struct hlist_node *tt_removed_node; + +batadv_tt_local_event (bat_priv, tt_local_entry,BATADV_TT_CLIENT_DEL ); + +/* remove exactly this object when still present in hash */ + tt_removed_node =batadv_hash_remove (bat_priv->tt.local_hash, + batadv_compare_tt_entry, + batadv_choose_tt, common); +if (!tt_removed_node) +return ; + +/* batadv_tt_local_transition_new() may have committed the entry and +* thus counted it in the local table size since the +* BATADV_TT_CLIENT_NEW check in batadv_tt_local_mark_removed(). +*/ +if (!(batadv_tt_flags_get (common) &BATADV_TT_CLIENT_NEW )) +batadv_tt_local_size_dec (bat_priv, common->vid); + +/* drop reference of remove hash entry */ +batadv_tt_local_entry_put (tt_local_entry); +} +/** * batadv_tt_local_remove() - logically remove an entry from the local table * @bat_priv: the bat priv with all the mesh interface information
@@ -1490,7 +1526,6 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, bool roaming) {struct batadv_tt_local_entry *tt_local_entry; -struct hlist_node *tt_removed_node;u16 curr_flags =BATADV_NO_FLAGS ;bool pending = false;u16 flags;
@@ -1518,25 +1553,7 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,/* if this client has been added right now, it is possible to * immediately purge it */ -batadv_tt_local_event (bat_priv, tt_local_entry,BATADV_TT_CLIENT_DEL ); - -/* remove exactly this object when still present in hash */ - tt_removed_node =batadv_hash_remove (bat_priv->tt.local_hash, - batadv_compare_tt_entry, - batadv_choose_tt, - &tt_local_entry->common); -if (!tt_removed_node) - goto out; - -/* batadv_tt_local_transition_new() may have committed the entry and -* thus counted it in the local table size since the BATADV_TT_CLIENT_NEW -* check above. -*/ -if (!(batadv_tt_flags_get (&tt_local_entry->common) &BATADV_TT_CLIENT_NEW )) -batadv_tt_local_size_dec (bat_priv, tt_local_entry->common.vid); - -/* drop reference of remove hash entry */ -batadv_tt_local_entry_put (tt_local_entry); +batadv_tt_local_remove_now (bat_priv, tt_local_entry); out:batadv_tt_local_entry_put (tt_local_entry);
Signature · 1 line
2.47.3
Sven Eckelmann
maintainerRe: [PATCH net-next 11/15] batman-adv: tt: extract immediate purge of a local entry
[...]
Quoted 35 lines
Discovered by: opus-5 · Missed by: opus-4-7, gpt-5-6-sol, sashiko-gemini · Confirmed by: gpt-5-6-sol Is the "was never announced" wording in this new kernel doc a bit too
strong? The body of the same function documents the opposite case a few
lines later:net/batman-adv/translation-table.c:batadv_tt_local_remove_now() { /* batadv_tt_local_transition_new() may have committed the entry and * thus counted it in the local table size since the * BATADV_TT_CLIENT_NEW check in batadv_tt_local_mark_removed(). */ if (!(batadv_tt_flags_get(common) & BATADV_TT_CLIENT_NEW)) batadv_tt_local_size_dec(bat_priv, common->vid); }
batadv_tt_local_mark_removed()dropscommon->flags_lockbefore returning andbatadv_tt_local_remove()holds no other lock, whilebatadv_tt_local_transition_new()only holds the locallist_lockandflags_lock:
batadv_tt_local_commit_changes_nolock()
batadv_tt_local_transition_new()/* clearsBATADV_TT_CLIENT_NEW,batadv_tt_local_size_inc() */
batadv_tt_local_update_crc()
atomic_inc(&bat_priv->tt.vn)So in that window the entry can be committed, counted and announced under the current ttvn, and
batadv_tt_local_remove_now()still unlinks it frombat_priv->tt.local_hashinstead of leaving itBATADV_TT_CLIENT_PENDINGuntil the next ttvn increment, as described bybatadv_tt_local_set_pending_event():* Schedule the TT change announcement for the entry. The entry is kept in the
* local table until the next TTVN increment so that a consistency-check
* response can still be answered.
Quoted 5 lines
Would it make sense either to soften the new kernel doc (and the matching sentence in the commit message, "A client which was added after the last ttvn increment was never announced and can be dropped from the local table right away") to mention that the entry may already have been committed, or to fall back to the pending path when the NEW flag turns out to be cleared?
See https://patchwork.open-mesh.org/project/b.a.t.m.a.n./patch/[email protected]/
Regards,
Sven
Simon Wunderlich
maintainerPATCH 12/15 batman-adv: tt: drop the cleanup label from batadv_tt_local_remove()
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
With both locked sections moved to their own helpers, the only thing left in the cleanup section is the reference of the looked up entry. The "out" label is therefore only reached with a valid entry, except for the lookup failure at the very beginning.
Return BATADV_NO_FLAGS directly when there is no entry and let the two remaining cases be an if/else.
--- net/batman-adv/translation-table.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
net/batman-adv/translation-table.c +10 -16
@@ -1526,13 +1526,12 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr, bool roaming) {struct batadv_tt_local_entry *tt_local_entry; -u16 curr_flags =BATADV_NO_FLAGS ; -bool pending = false; +u16 curr_flags;u16 flags; tt_local_entry =batadv_tt_local_hash_find (bat_priv, addr, vid);if (!tt_local_entry) - goto out; +return BATADV_NO_FLAGS ; flags =BATADV_TT_CLIENT_DEL ;/* if this global entry addition is due to a roaming, the node has to
@@ -1542,20 +1541,15 @@ u16 batadv_tt_local_remove(struct batadv_priv *bat_priv, const u8 *addr,if (roaming) flags |=BATADV_TT_CLIENT_ROAM ; - pending =batadv_tt_local_mark_removed (tt_local_entry, roaming, - &curr_flags); -if (pending) { -batadv_tt_local_set_pending_event (bat_priv, tt_local_entry, flags, - message); - goto out; - } - -/* if this client has been added right now, it is possible to -* immediately purge it -*/ -batadv_tt_local_remove_now (bat_priv, tt_local_entry); +if (batadv_tt_local_mark_removed (tt_local_entry, roaming, &curr_flags)) +batadv_tt_local_set_pending_event (bat_priv, tt_local_entry, + flags, message); +else +/* if this client has been added right now, it is possible to +* immediately purge it +*/ +batadv_tt_local_remove_now (bat_priv, tt_local_entry); -out:batadv_tt_local_entry_put (tt_local_entry);return curr_flags;
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 13/15 batman-adv: tt: clarify kernel doc for batadv_tt_local_set_pending_event()
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The function batadv_tt_local_set_pending_event() is no longer setting the BATADV_TT_CLIENT_PENDING because it must be done with the flags_lock held. The kernel-doc must therefore correctly state that the flag must already be set.
--- net/batman-adv/translation-table.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/batman-adv/translation-table.c +3 -4
@@ -1422,13 +1422,12 @@ int batadv_tt_local_dump(struct sk_buff *msg, struct netlink_callback *cb)/** * batadv_tt_local_set_pending_event() - trigger events for TT pending removal * @bat_priv: the bat priv with all the mesh interface information -* @tt_local_entry: local TT entry to mark +* @tt_local_entry: local TT entry which was marked as BATADV_TT_CLIENT_PENDING * @flags: TT change flags to announce together with the pending removal * @message: debug message describing the reason for the change * -* Schedule the TT change announcement for the entry. The entry is kept in the -* local table until the next TTVN increment so that a consistency-check -* response can still be answered. +* Schedule the TT change announcement for the entry. The caller must already +* have added BATADV_TT_CLIENT_PENDING to the @tt_local_entry */ static void batadv_tt_local_set_pending_event(struct batadv_priv *bat_priv,
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 14/15 batman-adv: bat_iv: fix ogm_neigh_is_sob parameters references
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
The batadv_iv_ogm_neigh_is_sob() kernel-doc summary line is still referencing the old parameter names "neigh1" and "neigh2". But these are now called "candidate" and "reference".
--- net/batman-adv/bat_iv_ogm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/batman-adv/bat_iv_ogm.c +2 -2
@@ -2422,8 +2422,8 @@ static int batadv_iv_ogm_neigh_cmp(struct batadv_neigh_node *neigh1, }/** -* batadv_iv_ogm_neigh_is_sob() - check if neigh1 is similarly good or better -* than neigh2 from the metric prospective +* batadv_iv_ogm_neigh_is_sob() - check if @candidate is similarly good or +* better than @reference from the metric prospective * @candidate: the first neighbor object of the comparison * @if_outgoing_cand: outgoing interface for the @candidate neighbor * @reference: the second neighbor object of the comparison
Signature · 1 line
2.47.3
Simon Wunderlich
maintainerPATCH 15/15 batman-adv: correct batadv_hash_remove kdoc return type
In reply to Simon WunderlichFrom: Sven Eckelmann <[email protected]>
Not the data is returned after a batadv_hash_remove() but the pointer to the hlist_node which was used to look up the entry in the hash.
--- net/batman-adv/hash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/batman-adv/hash.h +1 -1
@@ -137,7 +137,7 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash,* data could be the structure you use with just the key filled, we just need * the key for comparing. * -* Return: returns pointer to data on success, so you can remove the used +* Return: returns pointer to hlist_node on success, so you can remove the used * structure yourself, or NULL on error */ static inline void *batadv_hash_remove(struct batadv_hashtable *hash,
Signature · 1 line
2.47.3