🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Simon Wunderlich Sat, 14 Nov 2026 09:15
[PATCH net-next 02/15] batman-adv: bla: use dedicated key type for backbone gateway hash
#16174
Author: Simon Wunderlich
Date: Sat, 14 Nov 2026 09:15
372 lines
23209 bytes
From: Sven Eckelmann <sven@narfation.org>

batadv_backbone_hash_find() creates a dummy struct batadv_bla_backbone_gw
on the stack and only fills orig and vid for the lookup. Which members
are part of the key is only visible in the hash and compare callbacks.

Move orig and vid into a new struct batadv_bla_backbone_gw_key, embedded as
batadv_bla_backbone_gw::key. The helpers are only using this key for
hashing/comparison.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
 net/batman-adv/bridge_loop_avoidance.c | 103 ++++++++++++-------------
 net/batman-adv/types.h                 |  13 +++-
 2 files changed, 62 insertions(+), 54 deletions(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index a5ac7ba24e834..cc7a98fbc3d2a 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -77,42 +77,41 @@ static inline u32 batadv_choose_claim(const void *data, u32 size)
 
 /**
  * batadv_choose_backbone_gw() - choose the right bucket for a backbone gateway.
- * @data: data to hash
+ * @data: &struct batadv_bla_backbone_gw_key to hash
  * @size: size of the hash table
  *
  * Return: the hash index of the backbone gateway
  */
 static inline u32 batadv_choose_backbone_gw(const void *data, u32 size)
 {
-	const struct batadv_bla_backbone_gw *gw;
+	const struct batadv_bla_backbone_gw_key *key = data;
 	u32 hash = 0;
 
-	gw = data;
-	hash = jhash(&gw->orig, sizeof(gw->orig), hash);
-	hash = jhash(&gw->vid, sizeof(gw->vid), hash);
+	hash = jhash(&key->orig, sizeof(key->orig), hash);
+	hash = jhash(&key->vid, sizeof(key->vid), hash);
 
 	return hash % size;
 }
 
 /**
- * batadv_compare_backbone_gw() - compare address and vid of two backbone gws
- * @node: list node of the first entry to compare
- * @data2: pointer to the second backbone gateway
+ * batadv_compare_backbone_gw() - compare key of a backbone gw with a search key
+ * @node: list node of the backbone gateway to compare
+ * @data2: &struct batadv_bla_backbone_gw_key to compare with
  *
- * Return: true if the backbones have the same data, false otherwise
+ * Return: true if the backbone gateway has the given key, false otherwise
  */
 static bool batadv_compare_backbone_gw(const struct hlist_node *node,
 				       const void *data2)
 {
-	const void *data1 = container_of(node, struct batadv_bla_backbone_gw,
-					 hash_entry);
-	const struct batadv_bla_backbone_gw *gw1 = data1;
-	const struct batadv_bla_backbone_gw *gw2 = data2;
+	const struct batadv_bla_backbone_gw_key *key = data2;
+	const struct batadv_bla_backbone_gw *gw;
+
+	gw = container_of(node, struct batadv_bla_backbone_gw, hash_entry);
 
-	if (!batadv_compare_eth(gw1->orig, gw2->orig))
+	if (!batadv_compare_eth(gw->key.orig, key->orig))
 		return false;
 
-	if (gw1->vid != gw2->vid)
+	if (gw->key.vid != key->vid)
 		return false;
 
 	return true;
@@ -261,24 +260,23 @@ batadv_backbone_hash_find(struct batadv_priv *bat_priv, const u8 *addr,
 {
 	struct batadv_hashtable *hash = bat_priv->bla.backbone_hash;
 	struct batadv_bla_backbone_gw *backbone_gw_tmp = NULL;
-	struct batadv_bla_backbone_gw search_entry;
 	struct batadv_bla_backbone_gw *backbone_gw;
+	struct batadv_bla_backbone_gw_key key;
 	struct hlist_head *head;
 	int index;
 
 	if (!hash)
 		return NULL;
 
-	ether_addr_copy(search_entry.orig, addr);
-	search_entry.vid = vid;
+	ether_addr_copy(key.orig, addr);
+	key.vid = vid;
 
-	index = batadv_choose_backbone_gw(&search_entry, hash->size);
+	index = batadv_choose_backbone_gw(&key, hash->size);
 	head = &hash->table[index];
 
 	rcu_read_lock();
 	hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
-		if (!batadv_compare_backbone_gw(&backbone_gw->hash_entry,
-						&search_entry))
+		if (!batadv_compare_backbone_gw(&backbone_gw->hash_entry, &key))
 			continue;
 
 		if (!kref_get_unless_zero(&backbone_gw->refcount))
@@ -462,9 +460,9 @@ static void batadv_bla_loopdetect_report(struct work_struct *work)
 
 	batadv_info(bat_priv->mesh_iface,
 		    "Possible loop on VLAN %d detected which can't be handled by BLA - please check your network setup!\n",
-		    batadv_print_vid(backbone_gw->vid));
+		    batadv_print_vid(backbone_gw->key.vid));
 	snprintf(vid_str, sizeof(vid_str), "%d",
-		 batadv_print_vid(backbone_gw->vid));
+		 batadv_print_vid(backbone_gw->key.vid));
 	vid_str[sizeof(vid_str) - 1] = 0;
 
 	batadv_throw_uevent(bat_priv, BATADV_UEV_BLA, BATADV_UEV_LOOPDETECT,
@@ -503,21 +501,21 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, const u8 *orig,
 	if (!entry)
 		return NULL;
 
-	entry->vid = vid;
+	entry->key.vid = vid;
 	WRITE_ONCE(entry->lasttime, jiffies);
 	entry->crc = BATADV_BLA_CRC_INIT;
 	entry->bat_priv = bat_priv;
 	spin_lock_init(&entry->crc_lock);
 	entry->state = BATADV_BLA_BACKBONE_GW_SYNCED;
 	entry->wait_periods = 0;
-	ether_addr_copy(entry->orig, orig);
+	ether_addr_copy(entry->key.orig, orig);
 	INIT_WORK(&entry->report_work, batadv_bla_loopdetect_report);
 	kref_init(&entry->refcount);
 
 	kref_get(&entry->refcount);
 	hash_added = batadv_hash_add(bat_priv->bla.backbone_hash,
 				     batadv_compare_backbone_gw,
-				     batadv_choose_backbone_gw, entry,
+				     batadv_choose_backbone_gw, &entry->key,
 				     &entry->hash_entry);
 
 	if (unlikely(hash_added != 0)) {
@@ -641,11 +639,11 @@ static void batadv_bla_send_request(struct batadv_bla_backbone_gw *backbone_gw)
 	batadv_bla_del_backbone_claims(backbone_gw);
 
 	batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
-		   "Sending REQUEST to %pM\n", backbone_gw->orig);
+		   "Sending REQUEST to %pM\n", backbone_gw->key.orig);
 
 	/* send request */
-	batadv_bla_send_claim(backbone_gw->bat_priv, backbone_gw->orig,
-			      backbone_gw->vid, BATADV_CLAIM_TYPE_REQUEST);
+	batadv_bla_send_claim(backbone_gw->bat_priv, backbone_gw->key.orig,
+			      backbone_gw->key.vid, BATADV_CLAIM_TYPE_REQUEST);
 
 	/* no local broadcasts should be sent or received, for now. */
 	spin_lock_bh(&backbone_gw->bat_priv->bla.num_requests_lock);
@@ -673,7 +671,7 @@ static void batadv_bla_send_announce(struct batadv_priv *bat_priv,
 	spin_unlock_bh(&backbone_gw->crc_lock);
 	memcpy(&mac[4], &crc, 2);
 
-	batadv_bla_send_claim(bat_priv, mac, backbone_gw->vid,
+	batadv_bla_send_claim(bat_priv, mac, backbone_gw->key.vid,
 			      BATADV_CLAIM_TYPE_ANNOUNCE);
 }
 
@@ -761,7 +759,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
 		batadv_dbg(BATADV_DBG_BLA, bat_priv,
 			   "%s(): changing ownership for %pM, vid %d to gw %pM\n",
 			   __func__, mac, batadv_print_vid(vid),
-			   backbone_gw->orig);
+			   backbone_gw->key.orig);
 
 		/* add claim address to new backbone_gw */
 		spin_lock_bh(&backbone_gw->crc_lock);
@@ -875,7 +873,7 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv,
 
 	batadv_dbg(BATADV_DBG_BLA, bat_priv,
 		   "%s(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n",
-		   __func__, batadv_print_vid(vid), backbone_gw->orig, crc);
+		   __func__, batadv_print_vid(vid), backbone_gw->key.orig, crc);
 
 	spin_lock_bh(&backbone_gw->crc_lock);
 	backbone_crc = backbone_gw->crc;
@@ -884,8 +882,8 @@ static bool batadv_handle_announce(struct batadv_priv *bat_priv,
 	if (backbone_crc != crc) {
 		batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
 			   "%s(): CRC FAILED for %pM/%d (my = %#.4x, sent = %#.4x)\n",
-			   __func__, backbone_gw->orig,
-			   batadv_print_vid(backbone_gw->vid),
+			   __func__, backbone_gw->key.orig,
+			   batadv_print_vid(backbone_gw->key.vid),
 			   backbone_crc, crc);
 
 		batadv_bla_send_request(backbone_gw);
@@ -1272,7 +1270,7 @@ static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now)
 
 				batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
 					   "%s(): backbone gw %pM timed out\n",
-					   __func__, backbone_gw->orig);
+					   __func__, backbone_gw->key.orig);
 
 purge_now:
 				purged = true;
@@ -1343,7 +1341,7 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,
 			if (now)
 				goto purge_now;
 
-			if (!batadv_compare_eth(backbone_gw->orig,
+			if (!batadv_compare_eth(backbone_gw->key.orig,
 						primary_if->net_dev->dev_addr))
 				goto skip;
 
@@ -1360,7 +1358,7 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,
 				   claim->key.addr, claim->key.vid);
 
 			batadv_handle_unclaim(bat_priv, primary_if,
-					      backbone_gw->orig,
+					      backbone_gw->key.orig,
 					      claim->key.addr, claim->key.vid);
 skip:
 			batadv_backbone_gw_put(backbone_gw);
@@ -1411,11 +1409,11 @@ void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
 		rcu_read_lock();
 		hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
 			/* own orig still holds the old value. */
-			if (!batadv_compare_eth(backbone_gw->orig,
+			if (!batadv_compare_eth(backbone_gw->key.orig,
 						oldif->net_dev->dev_addr))
 				continue;
 
-			ether_addr_copy(backbone_gw->orig,
+			ether_addr_copy(backbone_gw->key.orig,
 					primary_if->net_dev->dev_addr);
 			/* send an announce frame so others will ask for our
 			 * claims and update their tables.
@@ -1441,9 +1439,10 @@ batadv_bla_send_loopdetect(struct batadv_priv *bat_priv,
 			   struct batadv_bla_backbone_gw *backbone_gw)
 {
 	batadv_dbg(BATADV_DBG_BLA, bat_priv, "Send loopdetect frame for vid %d\n",
-		   backbone_gw->vid);
+		   backbone_gw->key.vid);
 	batadv_bla_send_claim(bat_priv, bat_priv->bla.loopdetect_addr,
-			      backbone_gw->vid, BATADV_CLAIM_TYPE_LOOPDETECT);
+			      backbone_gw->key.vid,
+			      BATADV_CLAIM_TYPE_LOOPDETECT);
 }
 
 /**
@@ -1524,7 +1523,7 @@ static void batadv_bla_periodic_work(struct work_struct *work)
 
 		rcu_read_lock();
 		hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
-			if (!batadv_compare_eth(backbone_gw->orig,
+			if (!batadv_compare_eth(backbone_gw->key.orig,
 						primary_if->net_dev->dev_addr))
 				continue;
 
@@ -1810,8 +1809,8 @@ bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv,
 
 		rcu_read_lock();
 		hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
-			if (batadv_compare_eth(backbone_gw->orig, orig) &&
-			    backbone_gw->vid == vid) {
+			if (batadv_compare_eth(backbone_gw->key.orig, orig) &&
+			    backbone_gw->key.vid == vid) {
 				rcu_read_unlock();
 				return true;
 			}
@@ -2031,7 +2030,7 @@ bool batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
 
 	/* if it is our own claim ... */
 	backbone_gw = batadv_bla_claim_get_backbone_gw(claim);
-	own_claim = batadv_compare_eth(backbone_gw->orig,
+	own_claim = batadv_compare_eth(backbone_gw->key.orig,
 				       primary_if->net_dev->dev_addr);
 	batadv_backbone_gw_put(backbone_gw);
 
@@ -2135,7 +2134,7 @@ bool batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
 
 	/* check if we are responsible. */
 	backbone_gw = batadv_bla_claim_get_backbone_gw(claim);
-	client_roamed = batadv_compare_eth(backbone_gw->orig,
+	client_roamed = batadv_compare_eth(backbone_gw->key.orig,
 					   primary_if->net_dev->dev_addr);
 	batadv_backbone_gw_put(backbone_gw);
 
@@ -2221,7 +2220,7 @@ batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid,
 
 	backbone_gw = batadv_bla_claim_get_backbone_gw(claim);
 
-	is_own = batadv_compare_eth(backbone_gw->orig, primary_addr);
+	is_own = batadv_compare_eth(backbone_gw->key.orig, primary_addr);
 
 	spin_lock_bh(&backbone_gw->crc_lock);
 	backbone_crc = backbone_gw->crc;
@@ -2236,7 +2235,7 @@ batadv_bla_claim_dump_entry(struct sk_buff *msg, u32 portid,
 	if (nla_put(msg, BATADV_ATTR_BLA_ADDRESS, ETH_ALEN, claim->key.addr) ||
 	    nla_put_u16(msg, BATADV_ATTR_BLA_VID, claim->key.vid) ||
 	    nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN,
-		    backbone_gw->orig) ||
+		    backbone_gw->key.orig) ||
 	    nla_put_u16(msg, BATADV_ATTR_BLA_CRC,
 			backbone_crc)) {
 		genlmsg_cancel(msg, hdr);
@@ -2383,7 +2382,7 @@ batadv_bla_backbone_dump_entry(struct sk_buff *msg, u32 portid,
 
 	genl_dump_check_consistent(cb, hdr);
 
-	is_own = batadv_compare_eth(backbone_gw->orig, primary_addr);
+	is_own = batadv_compare_eth(backbone_gw->key.orig, primary_addr);
 
 	spin_lock_bh(&backbone_gw->crc_lock);
 	backbone_crc = backbone_gw->crc;
@@ -2399,8 +2398,8 @@ batadv_bla_backbone_dump_entry(struct sk_buff *msg, u32 portid,
 		}
 
 	if (nla_put(msg, BATADV_ATTR_BLA_BACKBONE, ETH_ALEN,
-		    backbone_gw->orig) ||
-	    nla_put_u16(msg, BATADV_ATTR_BLA_VID, backbone_gw->vid) ||
+		    backbone_gw->key.orig) ||
+	    nla_put_u16(msg, BATADV_ATTR_BLA_VID, backbone_gw->key.vid) ||
 	    nla_put_u16(msg, BATADV_ATTR_BLA_CRC,
 			backbone_crc) ||
 	    nla_put_u32(msg, BATADV_ATTR_LAST_SEEN_MSECS, msecs)) {
@@ -2552,7 +2551,7 @@ bool batadv_bla_check_claim(struct batadv_priv *bat_priv,
 	if (claim) {
 		backbone_gw = batadv_bla_claim_get_backbone_gw(claim);
 
-		if (!batadv_compare_eth(backbone_gw->orig,
+		if (!batadv_compare_eth(backbone_gw->key.orig,
 					primary_if->net_dev->dev_addr))
 			ret = false;
 
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 9d43e9cac0cc6..aae9c38a96b48 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -1788,9 +1788,10 @@ enum batadv_bla_backbone_gw_state {
 };
 
 /**
- * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
+ * struct batadv_bla_backbone_gw_key - key of a backbone gateway in
+ *  &batadv_priv_bla.backbone_hash
  */
-struct batadv_bla_backbone_gw {
+struct batadv_bla_backbone_gw_key {
 	/**
 	 * @orig: originator address of backbone node (mac address of primary
 	 *  iface)
@@ -1799,6 +1800,14 @@ struct batadv_bla_backbone_gw {
 
 	/** @vid: vlan id this gateway was detected on */
 	unsigned short vid;
+};
+
+/**
+ * struct batadv_bla_backbone_gw - batman-adv gateway bridged into the LAN
+ */
+struct batadv_bla_backbone_gw {
+	/** @key: hash key identifying the backbone gateway */
+	struct batadv_bla_backbone_gw_key key;
 
 	/** @hash_entry: hlist node for &batadv_priv_bla.backbone_hash */
 	struct hlist_node hash_entry;
-- 
2.47.3
Re: [PATCH net-next 02/15] batman-adv: bla: use dedicated key type for backbone gateway hash
#16595
Author: Sven Eckelmann
Date: Sun, 15 Nov 2026 09:37
47 lines
9794 bytes
--nextPart6047506.DvuYhMxLoT
Content-Transfer-Encoding: 7Bit
Content-Type: text/plain; charset="utf-8"; protected-headers="v1"
From: Sven Eckelmann <sven@narfation.org>
Date: Sun, 15 Nov 2026 10:37:39 +0100
Message-ID: <13009955.O9o76ZdvQC@sven-desktop>
In-Reply-To: <sashiko-outbox-215348@kernel.org>
MIME-Version: 1.0

On Sunday, 15 November 2026 10:24:42 CET sashiko-bot@kernel.org wrote:
[...]
> [Severity: Medium]
> This problem wasn't introduced by this patch, but should
> batadv_bla_purge_backbone_gw() and batadv_bla_del_backbone_claims()
> [1] increment hash->generation when removing entries with
> hlist_del_rcu()?
> 
> Netlink dumps such as batadv_bla_backbone_dump() and
> batadv_bla_claim_dump() set cb->seq from atomic_read(&hash->generation) and
> rely on genl_dump_check_consistent() to flag concurrent table changes with
> NLM_F_DUMP_INTR.  Because these bulk deletions (as well as
> __batadv_dat_purge() and batadv_purge_orig_ref()) unlink entries directly
> without bumping hash->generation, a concurrent netlink dump can miss
> NLM_F_DUMP_INTR and return an inconsistent snapshot to userspace.

This is done in the "increase hash generation when purging entries" patches in 
this series.

And it is absolutely unrelated to this patch.

Regards,
	Sven
--nextPart6047506.DvuYhMxLoT
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part.
Content-Transfer-Encoding: 7Bit

-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQS81G/PswftH/OW8cVND3cr0xT1ywUCavl9YwAKCRBND3cr0xT1
yyY4AQCqj6pW6rJ265sQV3f8auxGfvDlUuerS5OMIji8HgG76QEA7hVNDYG02lCD
WQlSSI2FSAkxM1Od6pw/IX65AhH3pA0=
=eLP7
-----END PGP SIGNATURE-----

--nextPart6047506.DvuYhMxLoT--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads