Skip to contentSkip to conversation

batman-adv: increase DAT DHT timeout

PATCH Superseded Linus Lüssing 2 participants 7 messages Oct 3 Batman advanced

v12 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v12 cover batman-adv: increase DAT DHT timeout

This patchset increases the DAT DHT timeout to reduce the amount of broadcasted ARP Replies.

To increase the timeout only for DAT DHT entries added via DHT-PUT but not for any other entry in the DAT cache the DAT cache and DAT DHT concepts are split into two separate hash tables (PATCH 2/5).

PATCH 3/5 then increases the timeout for DAT DHT entries from 5 to 30 minutes, the main performance enhancement and goal of this patchset.

PATCH 4/5 and 5/5 are some small tweaks for a few unnecessary DHT additions which we can now detect and avoid.

The motivation for this patchset is based on the observations made here:
https://www.open-mesh.org/projects/batman-adv/wiki/DAT_DHCP_Snooping

In tests at Freifunk Lübeck with ~180 mesh nodes and Gluon this reduced the ARP broadcast overhead, measured over 7 days, as follows:

- Total: 6677.66 bits/s -> 677.26 bits/s => -89.86%

                   11.92 pkts/s   -> 1.21 pkts/s   => -89.85%
- from gateways: 5618.02 bits/s   -> 212.28        => -96.22%
                   10.03 pkts/s   -> 0.38 pkts/s   => -96.21%

Also see graphics and a few more test details here:
- https://www.open-mesh.org/projects/batman-adv/wiki/DAT_DHCP_Snooping#Result-2

Regards,
Linus

---

Changelog v12:
- PATCH 0/5:
- added mentioning of PATCH 4/5 and 5/5 in the summary
- PATCH 1/5 (was: 1/4):
- fix triggering of the "ARP request replied locally" debug message by changing the batadv_dat_arp_self_reply() return type from bool to int, ensuring to (keep) only trigger(ing) it when netif_rx()'ing
- PATCH 2/5 (was: 2/4):
- consistently use a "cands" variable name for the candidate array instead of sometimes calling it "cand", sometimes "cands"
- add missing kerneldoc for batadv_dat_forward_data()'s "cands" function argument
- renaming batadv_dat_check_self_candidate() to batadv_dat_cmp_self_candidate()
- fix unprivileged DAT_DHT netlink usage
- add netlink .validate (and .resv_start_op for compat) for uniform netlink ops
- adjust batadv_dat_dht_get_self_reply() to new batadv_dat_arp_self_reply() int return type
(also avoiding an automatic type conversion from int
to bool by that)
- fix memory leak / missing orig_node put in batadv_dat_forward_dht_get() if one self is a
candidate, move orig-node put from batadv_dat_forward_data() to separate batadv_dat_candidates_free() function, called later
- revert "update local DHT on DHCP ACKs received via DHT_PUTs, too" from v11 as we never send DHT_PUT messages with a DHCP payload, sashiko.dev seems to have missed that these are always ARP Replies
- PATCH 3/5 (was: 3/4): unchanged
- PATCH 4/5 (was: 4/4): unchanged
- PATCH 5/5: NEW, avoid superfluous DAT DHT_PUT additions to local DAT

Changelog v11:
- PATCH 1/4: NEW, simple restructuring in preparation for 2/4 (no functional change)
- PATCH 2/4 (was: 1/2):
- update local DHT on DHCP ACKs received via DHT_PUTs, too
- added self-candidate checks (batadv_dat_check_self_candidate()):
- update local DHT from/on own DHT_PUT if we are a DAT candidate
- (try to) reply to own DHT_GET from own DHT first if we are a selected DAT candidate
- PATCH 3/4 (was 2/2): unchanged
- PATCH 4/4: NEW, avoid superfluous DAT DHT_PUT if self-candidate

Changelog v10:
- PATCH 1/3: removed, already applied
- PATCH 0/2: cover letter: removed test time period and "v5" reference
- PATCH 1/2:
- fixed kerneldoc in batadv_dat_hash_free(),
replaced "bat_priv" with "hash"
- added missing kerneldoc in batadv_dat_snoop_incoming_arp_reply() for is_dht_put
- rebase to current main branch:
- adopted new bat_priv kernel doc description,
"soft interface" -> "mesh interface"
- adopted variable rename from soft_iface to mesh_iface

Changelog v9:
- PATCH 1/3:
- fixed typo in a comment: ENOENT -> ENONET

Changelog v8:
- PATCH 1/3:
- fixing / cleaning up includes
- fixing function kernel doc titles
- fixing bugs introduced in v7 in the error handling of batadv_orig_dump() and batadv_neigh_dump(), using a goto pattern with more explicit labels

Changelog v7:
- adding PATCH 1/3 to add the batadv_netlink_get_softif() wrapper to reduce the amount of duplicate code, both in the current code base but also for the next PATCH 2/3

Changelog v6:
- removed renaming+deprecation of BATADV_P_DAT_CACHE_REPLY in PATCH 1/2
- small commit message rewording in PATCH 1/2

Changelog v5:
- rebased to current main branch
-> removed now obsolete debugfs code

Changelog v4:
- rebased to: acfc9a214d01695
("batman-adv: genetlink: make policy common to family")

Changelog v3:

formerly:
"batman-adv: Increase purge timeout on DAT DHT candidates"
https://patchwork.open-mesh.org/patch/17728/
- fixed the potential jiffies overflow and jiffies initialization issues by replacing the last_dht_update timeout variable with a split of DAT cache and DAT DHT into two separate hash tables -> instead of maintaining two timeouts in one DAT entry two DAT entries are created and maintained in their respective DAT cache and DAT DHT hash tables

Changelog v2:

formerly:
"batman-adv: Increase DHCP snooped DAT entry purge timeout in DHT"
(https://patchwork.open-mesh.org/patch/17364/)
- removed the extended timeouts flag in the DHT-PUT messages introduced in v1 again
- removed DHCP dependency

Linus Lüssing (5):
batman-adv: move local ARP reply code to subfunctions
batman-adv: split DAT cache into DAT cache and DAT DHT
batman-adv: increase DAT DHT timeout
batman-adv: avoid superfluous DAT DHT_PUT if self-candidate
batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT

 include/uapi/linux/batadv_packet.h     |  17 +-
 include/uapi/linux/batman_adv.h        |   5 +
 net/batman-adv/distributed-arp-table.c | 889 ++++++++++++++++++++-----
 net/batman-adv/distributed-arp-table.h |  24 +-
 net/batman-adv/main.h                  |   3 +-
 net/batman-adv/mesh-interface.c        |   4 +
 net/batman-adv/netlink.c               |   8 +-
 net/batman-adv/routing.c               |  18 +-
 net/batman-adv/send.c                  |   8 +-
 net/batman-adv/send.h                  |   3 +-
 net/batman-adv/types.h                 |  31 +-
 11 files changed, 811 insertions(+), 199 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v12 1/5 batman-adv: move local ARP reply code to subfunctions

Shorten the length of batadv_dat_snoop_outgoing_arp_request() by moving the checks for and generation of a local ARP reply to a new subfunction. This is also in preparation for reuseability for the DAT cache/DHT split.

No functional change.

---
 net/batman-adv/distributed-arp-table.c | 181 ++++++++++++++-----------
 1 file changed, 105 insertions(+), 76 deletions(-)
net/batman-adv/distributed-arp-table.c +105 -76
index 74050bffedbc..1a0eb9d9812e 100644
@@ -738,6 +738,103 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst,
 	return res;
 }
 
+/**
+ * batadv_dat_arp_create_reply() - create an ARP Reply
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @ip_src: ARP sender IP
+ * @ip_dst: ARP target IP
+ * @hw_src: Ethernet source and ARP sender MAC
+ * @hw_dst: Ethernet destination and ARP target MAC
+ * @vid: VLAN identifier (optional, set to zero otherwise)
+ *
+ * Creates an ARP Reply from the given values, optionally encapsulated in a
+ * VLAN header.
+ *
+ * Return: An skb containing an ARP Reply.
+ */
+static struct sk_buff *
+batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,
+			    __be32 ip_dst, u8 *hw_src, u8 *hw_dst,
+			    unsigned short vid)
+{
+	struct sk_buff *skb;
+
+	skb = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_dst, bat_priv->mesh_iface,
+			 ip_src, hw_dst, hw_src, hw_dst);
+	if (!skb)
+		return NULL;
+
+	skb_reset_mac_header(skb);
+
+	if (vid & BATADV_VLAN_HAS_TAG)
+		skb = vlan_insert_tag(skb, htons(ETH_P_8021Q),
+				      vid & VLAN_VID_MASK);
+
+	return skb;
+}
+
+/**
+ * batadv_dat_arp_self_reply() - (maybe) reply to a local ARP request
+ * @bat_priv: the bat priv with all the mesh interface information
+ * @ip_src: ARP request sender IP (and ARP reply target IP)
+ * @ip_dst: ARP request target IP (and ARP reply sender IP)
+ * @hw_src: Ethernet source and ARP sender MAC of ARP request
+ * @hw_dst: Ethernet destination and ARP target MAC of ARP request
+ * @vid: VLAN identifier (optional, set to zero otherwise)
+ * @arp_len: ARP packet size, including ethernet frame
+ *
+ * If the ARP request target is not a local client and if BLA is
+ * enabled and we have BLA claimed this target then generate and reply
+ * with an ARP reply locally on our mesh interface.
+ *
+ * Return: 0 if we transmitted an ARP reply, -ENOMEM if we should have but
+ * could not create an ARP reply (e.g. due to out-of-memory), -EACCSS
+ * otherwise (because the client is local or due to BLA suppression).
+ */
+static int
+batadv_dat_arp_self_reply(struct batadv_priv *bat_priv, __be32 ip_src,
+			  __be32 ip_dst, u8 *hw_src, u8 *hw_dst,
+			  unsigned short vid, unsigned int arp_len)
+{
+	struct sk_buff *skb;
+
+	/* If the ARP request is destined for a local client the local
+	 * client will answer itself. DAT would only generate a
+	 * duplicate packet.
+	 *
+	 * Moreover, if the mesh-interface is enslaved into a bridge, an
+	 * additional DAT answer may trigger kernel warnings about
+	 * a packet coming from the wrong port.
+	 */
+	if (batadv_is_my_client(bat_priv, hw_dst, vid))
+		return -EACCES;
+
+	/* If BLA is enabled, only send ARP replies if we have claimed
+	 * the destination for the ARP request or if no one else of
+	 * the backbone gws belonging to our backbone has claimed the
+	 * destination.
+	 */
+	if (!batadv_bla_check_claim(bat_priv, hw_dst, vid)) {
+		batadv_dbg(BATADV_DBG_DAT, bat_priv,
+			   "Device %pM claimed by another backbone gw. Don't send ARP reply!",
+			   hw_dst);
+		return -EACCES;
+	}
+
+	skb = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src, hw_dst,
+					  hw_src, vid);
+	if (!skb)
+		return -ENOMEM;
+
+	skb->protocol = eth_type_trans(skb, bat_priv->mesh_iface);
+
+	batadv_inc_counter(bat_priv, BATADV_CNT_RX);
+	batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES, arp_len);
+
+	netif_rx(skb);
+	return 0;
+}
+
 /**
  * batadv_dat_forward_data() - copy and send payload to the selected candidates
  * @bat_priv: the bat priv with all the mesh interface information
@@ -1179,41 +1276,6 @@ static unsigned short batadv_dat_get_vid(struct sk_buff *skb, int *hdr_size)
 	return vid;
 }
 
-/**
- * batadv_dat_arp_create_reply() - create an ARP Reply
- * @bat_priv: the bat priv with all the mesh interface information
- * @ip_src: ARP sender IP
- * @ip_dst: ARP target IP
- * @hw_src: Ethernet source and ARP sender MAC
- * @hw_dst: Ethernet destination and ARP target MAC
- * @vid: VLAN identifier (optional, set to zero otherwise)
- *
- * Creates an ARP Reply from the given values, optionally encapsulated in a
- * VLAN header.
- *
- * Return: An skb containing an ARP Reply.
- */
-static struct sk_buff *
-batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,
-			    __be32 ip_dst, u8 *hw_src, u8 *hw_dst,
-			    unsigned short vid)
-{
-	struct sk_buff *skb;
-
-	skb = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_dst, bat_priv->mesh_iface,
-			 ip_src, hw_dst, hw_src, hw_dst);
-	if (!skb)
-		return NULL;
-
-	skb_reset_mac_header(skb);
-
-	if (vid & BATADV_VLAN_HAS_TAG)
-		skb = vlan_insert_tag(skb, htons(ETH_P_8021Q),
-				      vid & VLAN_VID_MASK);
-
-	return skb;
-}
-
 /**
  * batadv_dat_snoop_outgoing_arp_request() - snoop the ARP request and try to
  * answer using DAT
@@ -1232,10 +1294,9 @@ batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,
 bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
 					   struct sk_buff *skb)
 {
-	struct net_device *mesh_iface = bat_priv->mesh_iface;
 	struct batadv_dat_entry *dat_entry = NULL;
 	u8 mac[ETH_ALEN] __aligned(2);
-	struct sk_buff *skb_new;
+	unsigned int arp_len;
 	unsigned short vid;
 	bool ret = false;
 	int hdr_size = 0;
@@ -1244,6 +1305,7 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
 	u16 type = 0;
 	u64 u64_mac;
 	u8 *hw_src;
+	int rep;
 
 	if (!READ_ONCE(bat_priv->distributed_arp_table))
 		goto out;
@@ -1253,6 +1315,7 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
 		goto out;
 
 	vid = batadv_dat_get_vid(skb, &hdr_size);
+	arp_len = skb->len + ETH_HLEN + hdr_size;
 
 	type = batadv_arp_get_type(bat_priv, skb, hdr_size);
 	/* If the node gets an ARP_REQUEST it has to send a DHT_GET unicast
@@ -1274,46 +1337,12 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
 		u64_mac = atomic64_read(&dat_entry->mac_addr);
 		u64_to_ether_addr(u64_mac, mac);
 
-		/* If the ARP request is destined for a local client the local
-		 * client will answer itself. DAT would only generate a
-		 * duplicate packet.
-		 *
-		 * Moreover, if the mesh-interface is enslaved into a bridge, an
-		 * additional DAT answer may trigger kernel warnings about
-		 * a packet coming from the wrong port.
-		 */
-		if (batadv_is_my_client(bat_priv, mac, vid)) {
-			ret = true;
-			goto out;
-		}
-
-		/* If BLA is enabled, only send ARP replies if we have claimed
-		 * the destination for the ARP request or if no one else of
-		 * the backbone gws belonging to our backbone has claimed the
-		 * destination.
-		 */
-		if (!batadv_bla_check_claim(bat_priv, mac, vid)) {
+		rep = batadv_dat_arp_self_reply(bat_priv, ip_src, ip_dst,
+						hw_src, mac, vid, arp_len);
+		if (!rep)
 			batadv_dbg(BATADV_DBG_DAT, bat_priv,
-				   "Device %pM claimed by another backbone gw. Don't send ARP reply!",
-				   mac);
-			ret = true;
-			goto out;
-		}
-
-		skb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,
-						      mac, hw_src, vid);
-		if (!skb_new)
-			goto out;
-
-		skb_new->protocol = eth_type_trans(skb_new, mesh_iface);
-
-		batadv_inc_counter(bat_priv, BATADV_CNT_RX);
-		batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
-				   skb->len + ETH_HLEN + hdr_size);
-
-		netif_rx(skb_new);
-		batadv_dbg(BATADV_DBG_DAT, bat_priv, "ARP request replied locally\n");
-		ret = true;
+				   "ARP request replied locally\n");
+		ret = (rep != -ENOMEM);
 	} else {
 		/* Send the request to the DHT */
 		ret = batadv_dat_forward_data(bat_priv, skb, ip_dst, vid,
Signature · 1 line
2.55.0
#2 lore raw

PATCH v12 2/5 batman-adv: split DAT cache into DAT cache and DAT DHT

In reply to Linus Lüssing

Similar to the translation table split the (mostly) locally maintained DAT cache and the DAT DHT concepts into two separate tables.

This eases the monitoring and debugging regarding the origin of DAT entries. And allows to apply differing properties to entries in the DAT cache and DAT DHT in the future, like distinct timeouts.

---
 include/uapi/linux/batman_adv.h        |   5 +
 net/batman-adv/distributed-arp-table.c | 581 ++++++++++++++++++++-----
 net/batman-adv/distributed-arp-table.h |  13 +-
 net/batman-adv/netlink.c               |   8 +-
 net/batman-adv/routing.c               |   7 +-
 net/batman-adv/types.h                 |   7 +-
 6 files changed, 511 insertions(+), 110 deletions(-)
include/uapi/linux/batman_adv.h +5 -0
index 936bcac270b5..7379c1509f77 100644
@@ -613,6 +613,11 @@ enum batadv_nl_commands {
 	 */
 	BATADV_CMD_SET_VLAN,
 
+	/**
+	 * @BATADV_CMD_GET_DAT_DHT: Query list of DAT DHT entries
+	 */
+	BATADV_CMD_GET_DAT_DHT,
+
 	/* add new commands above here */
 
 	/**
net/batman-adv/distributed-arp-table.c +478 -103

910 lines not on this page · raw message

net/batman-adv/distributed-arp-table.h +11 -2
index e7b75e82eb1d..ad81b7db921e 100644
@@ -31,7 +31,8 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
 void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
 					 struct sk_buff *skb);
 bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
-					 struct sk_buff *skb, int hdr_size);
+					 struct sk_buff *skb, int hdr_size,
+					 bool is_dht_put);
 void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
 					struct sk_buff *skb,
 					__be16 proto,
@@ -74,6 +75,7 @@ batadv_dat_init_own_addr(struct batadv_priv *bat_priv,
 int batadv_dat_init(struct batadv_priv *bat_priv);
 void batadv_dat_free(struct batadv_priv *bat_priv);
 int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb);
+int batadv_dat_dht_dump(struct sk_buff *msg, struct netlink_callback *cb);
 
 /**
  * batadv_dat_inc_counter() - increment the correct DAT packet counter
@@ -126,7 +128,8 @@ batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
 
 static inline bool
 batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
-				    struct sk_buff *skb, int hdr_size)
+				    struct sk_buff *skb, int hdr_size,
+				    bool is_dht_put)
 {
 	return false;
 }
@@ -176,6 +179,12 @@ batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb)
 	return -EOPNOTSUPP;
 }
 
+static inline int
+batadv_dat_dht_dump(struct sk_buff *msg, struct netlink_callback *cb)
+{
+	return -EOPNOTSUPP;
+}
+
 static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
 					  u8 subtype)
 {
net/batman-adv/netlink.c +7 -1
index 1177b3ceaf03..5250c3d1805e 100644
@@ -1498,6 +1498,12 @@ static const struct genl_small_ops batadv_netlink_ops[] = {
 		.flags = GENL_UNS_ADMIN_PERM,
 		.dumpit = batadv_dat_cache_dump,
 	},
+	{
+		.cmd = BATADV_CMD_GET_DAT_DHT,
+		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+		.flags = GENL_UNS_ADMIN_PERM,
+		.dumpit = batadv_dat_dht_dump,
+	},
 	{
 		.cmd = BATADV_CMD_GET_MCAST_FLAGS,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
@@ -1550,7 +1556,7 @@ struct genl_family batadv_netlink_family __ro_after_init = {
 	.small_ops = batadv_netlink_ops,
 	.n_small_ops = ARRAY_SIZE(batadv_netlink_ops),
 #if LINUX_VERSION_IS_GEQ(6, 1, 0) // UGLY_HACK_NEW
-	.resv_start_op = BATADV_CMD_SET_VLAN + 1,
+	.resv_start_op = BATADV_CMD_GET_DAT_DHT + 1,
 #endif // UGLY_HACK_STOP
 	.mcgrps = batadv_netlink_mcgrps,
 	.n_mcgrps = ARRAY_SIZE(batadv_netlink_mcgrps),
net/batman-adv/routing.c +5 -2
index 6442f5d0cc93..5cf26e8b3257 100644
@@ -1046,6 +1046,7 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 	struct batadv_orig_node *orig_node = NULL;
 	int hdr_size = sizeof(*unicast_packet);
 	enum batadv_subtype subtype;
+	bool is_dht_put = false;
 	int ret = NET_RX_DROP;
 	u8 *orig_addr_gw;
 	u8 *orig_addr;
@@ -1105,6 +1106,8 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 				orig_addr = unicast_4addr_packet->src;
 				orig_node = batadv_orig_hash_find(bat_priv,
 								  orig_addr);
+			} else if (subtype == BATADV_P_DAT_DHT_PUT) {
+				is_dht_put = true;
 			}
 		}
 
@@ -1112,7 +1115,7 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 							  hdr_size))
 			goto rx_success;
 		if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb,
-							hdr_size))
+							hdr_size, is_dht_put))
 			goto rx_success;
 
 		batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);
@@ -1353,7 +1356,7 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
 
 	if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
 		goto rx_success;
-	if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size))
+	if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size, false))
 		goto rx_success;
 
 	batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);
net/batman-adv/types.h +5 -2
index c19caa84e692..045727c3adc0 100644
@@ -1211,8 +1211,11 @@ struct batadv_priv_dat {
 	/** @addr: node DAT address */
 	batadv_dat_addr_t addr;
 
-	/** @hash: hashtable representing the local ARP cache */
-	struct batadv_hashtable *hash;
+	/** @cache_hash: hashtable representing the local ARP cache */
+	struct batadv_hashtable *cache_hash;
+
+	/** @dht_hash: hashtable representing the local DAT DHT */
+	struct batadv_hashtable *dht_hash;
 
 	/** @work: work queue callback item for cache purging */
 	struct delayed_work work;
Signature · 1 line
2.55.0
maintainer
#3 lore raw

Re: [batadv,v12 2/5] batman-adv: split DAT cache into DAT cache and DAT DHT

net/batman-adv/netlink.c struct genl_family batadv_netlink_family __ro_after_init = { · line 1560

Quoted 4 lines · On Saturday, 3 October 2026 09:26:25 CEST Linus Lüssing wrote:

#if LINUX_VERSION_IS_GEQ(6, 1, 0) // UGLY_HACK_NEW

net/batman-adv/netlink.c +1 -1
-       .resv_start_op = BATADV_CMD_SET_VLAN + 1,
+       .resv_start_op = BATADV_CMD_GET_DAT_DHT + 1,
 #endif // UGLY_HACK_STOP

No, this field is never to be changed for new commands.

* @resv_start_op: first operation for which reserved fields of the header
* can be validated and policies are required (see below);
* new families should leave this field at zero
[...]
* Attribute policies (the combination of @policy and @maxattr fields)
* can be attached at the family level or at the operation level.
* If both are present the per-operation policy takes precedence.
* For operations before @resv_start_op lack of policy means that the core
* will perform no attribute parsing or validation. For newer operations
* if policy is not provided core will reject all TLV attributes.

You should make sure that your new op has an appropriate policy and the client does the right thing. The former is already the case because the family policy is inherited.

See

* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=9c5d03d362519f36cd551aec596388f895c93d2d
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4fa86555d1cd338afc6e6308cc1ff890a014ec8c
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ce48ebdd56513fa5ad9dab683a96399e00dbf464

Quoted 4 lines
net/batman-adv/netlink.c +0 -0
@@ -1498,6 +1498,12 @@ static const struct genl_small_ops batadv_netlink_ops[] = {
                .flags = GENL_UNS_ADMIN_PERM,
                .dumpit = batadv_dat_cache_dump,

net/batman-adv/netlink.c static const struct genl_small_ops batadv_netlink_ops[] = { · line 1509

Quoted 10 lines
net/batman-adv/netlink.c +6 -0
        },
+       {
+               .cmd = BATADV_CMD_GET_DAT_DHT,
+               .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
+               .flags = GENL_UNS_ADMIN_PERM,
+               .dumpit = batadv_dat_dht_dump,
+       },
        {
                .cmd = BATADV_CMD_GET_MCAST_FLAGS,
                .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,

Please keep it in the enum batadv_nl_commands order.

Regards,
Sven

#4 lore raw

PATCH v12 3/5 batman-adv: increase DAT DHT timeout

In reply to Linus Lüssing

Currently, the DHT_GET messages of the DAT will likely be left unanswered due to the following issues:

When a node has a matching DAT Cache entry for a local ARP Request then this node will answer it directly with the information provided by the cache. This however, will likely lead to missing ARP Replies from the original host. Which in turn leads to the DAT DHT not being updated.

Then the local DAT cache entry will time out, triggering a unicasted DHT_GET. However, as the 5min. timeout has passed, the DAT DHT candidates will likely have purged their entry, too.

So basically this results in an ARP Request broadcast fallback every five minutes.

A second issue is that it is quite common that a host which has long gone offline will be tried to be contacted by another one at some remote period larger than the current 5min. timeout. This too leads to flooded ARP Requests.

With this patch the purge timeout for DAT DHT entries is increased to 30min to reduce the number of DAT ARP broadcast fallbacks.

---
 net/batman-adv/distributed-arp-table.c | 22 +++++++++++++++++-----
 net/batman-adv/main.h                  |  3 ++-
 2 files changed, 19 insertions(+), 6 deletions(-)
net/batman-adv/distributed-arp-table.c +17 -5
index af08812c7ecd..321df338fb8d 100644
@@ -199,15 +199,27 @@ static void batadv_dat_entry_put(struct batadv_dat_entry *dat_entry)
 }
 
 /**
- * batadv_dat_to_purge() - check whether a dat_entry has to be purged or not
+ * batadv_dat_cache_to_purge() - check if a cache entry has to be purged or not
  * @dat_entry: the entry to check
  *
  * Return: true if the entry has to be purged now, false otherwise.
  */
-static bool batadv_dat_to_purge(struct batadv_dat_entry *dat_entry)
+static bool batadv_dat_cache_to_purge(struct batadv_dat_entry *dat_entry)
 {
 	return batadv_has_timed_out(dat_entry->last_update,
-				    BATADV_DAT_ENTRY_TIMEOUT);
+				    BATADV_DAT_CACHE_ENTRY_TIMEOUT);
+}
+
+/**
+ * batadv_dat_dht_to_purge() - check if a DHT entry has to be purged or not
+ * @dat_entry: the entry to check
+ *
+ * Return: true if the entry has to be purged now, false otherwise.
+ */
+static bool batadv_dat_dht_to_purge(struct batadv_dat_entry *dat_entry)
+{
+	return batadv_has_timed_out(dat_entry->last_update,
+				    BATADV_DAT_DHT_ENTRY_TIMEOUT);
 }
 
 /**
@@ -268,8 +280,8 @@ static void batadv_dat_purge(struct work_struct *work)
 	priv_dat = container_of(delayed_work, struct batadv_priv_dat, work);
 	bat_priv = container_of(priv_dat, struct batadv_priv, dat);
 
-	__batadv_dat_purge(bat_priv->dat.cache_hash, batadv_dat_to_purge);
-	__batadv_dat_purge(bat_priv->dat.dht_hash, batadv_dat_to_purge);
+	__batadv_dat_purge(bat_priv->dat.cache_hash, batadv_dat_cache_to_purge);
+	__batadv_dat_purge(bat_priv->dat.dht_hash, batadv_dat_dht_to_purge);
 	batadv_dat_start_timer(bat_priv);
 }
 
net/batman-adv/main.h +2 -1
index e738758ee4a7..17af6322e157 100644
@@ -36,7 +36,8 @@
 #define BATADV_TT_WORK_PERIOD 5000 /* 5 seconds */
 #define BATADV_ORIG_WORK_PERIOD 1000 /* 1 second */
 #define BATADV_MCAST_WORK_PERIOD 500 /* 0.5 seconds */
-#define BATADV_DAT_ENTRY_TIMEOUT (5 * 60000) /* 5 mins in milliseconds */
+#define BATADV_DAT_CACHE_ENTRY_TIMEOUT (5 * 60000) /* 5 mins in milliseconds */
+#define BATADV_DAT_DHT_ENTRY_TIMEOUT (30 * 60000) /* 30 mins in milliseconds */
 /* sliding packet range of received originator messages in sequence numbers
  * (should be a multiple of our word size)
  */
Signature · 1 line
2.55.0
#5 lore raw

PATCH v12 4/5 batman-adv: avoid superfluous DAT DHT_PUT if self-candidate

In reply to Linus Lüssing

If we are one of the three closest DAT DHT candidates for a given IPv4 address then three DHT_PUTs to three remote DAT DHT candidates, especially the last selected DAT DHT candidate, is unnecessary: A DAT DHT_GET from another node would typically not get to it anyway and would reach us instead. Because the remote node will take us into account, while we so far don't take ourself into account in batadv_choose_next_candidate().

Instead of reworking batadv_choose_next_candidate() to take ourself into account, too, simply, potentially kick out the "worst" remote candidate at the end of calculation if we are a better candidate. To avoid an unnecessary DAT DHT_PUT / DHT_GET transmission.

---
 net/batman-adv/distributed-arp-table.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
net/batman-adv/distributed-arp-table.c +11 -0
index 321df338fb8d..52dff46a7c52 100644
@@ -779,6 +779,9 @@ static void batadv_choose_next_candidate(struct batadv_priv *bat_priv,
  * Check if we are a better candidate than the last placed, selected DHT
  * candidate for the given IP address key.
  *
+ * If we are a better candidate then deselects the last placed, selected
+ * DHT candidate.
+ *
  * Return: true if we are a better candidate, false otherwise.
  */
 static bool batadv_dat_cmp_self_candidate(struct batadv_priv *bat_priv,
@@ -822,6 +825,14 @@ static bool batadv_dat_cmp_self_candidate(struct batadv_priv *bat_priv,
 	    memcmp(own_orig_addr, last_cand->orig_node->orig, ETH_ALEN) >= 0)
 		goto out;
 
+	/* deselect last placed, selected candidate, we take its spot */
+	batadv_dbg(BATADV_DBG_DAT, bat_priv,
+		   "%s(): deselecting %pM for hash(IP)=%u\n",
+		   __func__, last_cand->orig_node->orig, ip_key);
+
+	last_cand->type = BATADV_DAT_CANDIDATE_NOT_FOUND;
+	batadv_orig_node_put(last_cand->orig_node);
+
 	ret = true;
 out:
 	if (ret)
Signature · 1 line
2.55.0
#6 lore raw

PATCH v12 5/5 batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT

In reply to Linus Lüssing

We send DHT_PUT ARP Replies to (typically) three DAT DHT candidates for the sender MAC/IP pair and another three for the target MAC/IP pair to likely different DAT DHT candidates. On the DHT_PUT receiving side we would then add both the sender MAC/IP and target MAC/IP to the local DHT, even if we are not actually a selected DAT candidate for one of the pairs.

This way we typically unnecessarily populate our local DHT with superfluous entries. Entries which no DAT DHT_GET will likely ever query from us.

To avoid these unnecessary local DHT additions add a flag to DHT_PUT messages to indicate which pair is supposed to be added to the local DHT.

---
 include/uapi/linux/batadv_packet.h     |  17 +++-
 net/batman-adv/distributed-arp-table.c | 124 ++++++++++++++++++++++---
 net/batman-adv/distributed-arp-table.h |  15 ++-
 net/batman-adv/mesh-interface.c        |   4 +
 net/batman-adv/routing.c               |  19 +++-
 net/batman-adv/send.c                  |   8 +-
 net/batman-adv/send.h                  |   3 +-
 net/batman-adv/types.h                 |  24 +++++
 8 files changed, 186 insertions(+), 28 deletions(-)
include/uapi/linux/batadv_packet.h +15 -2
index 32436560ecc8..6f4783887d37 100644
@@ -70,6 +70,19 @@ enum batadv_subtype {
 	BATADV_P_DAT_CACHE_REPLY	= 0x04,
 };
 
+/**
+ * enum batadv_subtype_flags - unicast4addr packet subtype specific flags
+ * @BATADV_P_DAT_DHT_PUT_NO_SRC: do not add sender IP/MAC from DHT_PUT ARP Reply
+ *  to local DHT
+ * @BATADV_P_DAT_DHT_PUT_NO_DST: do not add target IP/MAC from DHT_PUT ARP Reply
+ *  to local DHT
+ */
+enum batadv_subtype_flags {
+	BATADV_P_DAT_DHT_PUT_NO_SRC	= 0x01,
+	BATADV_P_DAT_DHT_PUT_NO_DST	= 0x02,
+};
+
+
 /* this file is included by batctl which needs these defines */
 #define BATADV_COMPAT_VERSION 15
 
@@ -433,13 +446,13 @@ struct batadv_unicast_packet {
  * @u: common unicast packet header
  * @src: address of the source
  * @subtype: packet subtype
- * @reserved: reserved byte for alignment
+ * @flags: packet subtype specific flags
  */
 struct batadv_unicast_4addr_packet {
 	struct batadv_unicast_packet u;
 	__u8 src[ETH_ALEN];
 	__u8 subtype;
-	__u8 reserved;
+	__u8 flags;
 	/* "4 bytes boundary + 2 bytes" long to make the payload after the
 	 * following ethernet header again 4 bytes boundary aligned
 	 */
net/batman-adv/distributed-arp-table.c +110 -14

221 lines not on this page · raw message

net/batman-adv/distributed-arp-table.h +12 -3
index ad81b7db921e..d955fcb27ae0 100644
@@ -32,7 +32,8 @@ void batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
 					 struct sk_buff *skb);
 bool batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
 					 struct sk_buff *skb, int hdr_size,
-					 bool is_dht_put);
+					 bool is_dht_put_src,
+					 bool is_dht_put_dst);
 void batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
 					struct sk_buff *skb,
 					__be16 proto,
@@ -81,11 +82,12 @@ int batadv_dat_dht_dump(struct sk_buff *msg, struct netlink_callback *cb);
  * batadv_dat_inc_counter() - increment the correct DAT packet counter
  * @bat_priv: the bat priv with all the mesh interface information
  * @subtype: the 4addr subtype of the packet to be counted
+ * @flags: packet subtype specific flags
  *
  * Updates the ethtool statistics for the received packet if it is a DAT subtype
  */
 static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
-					  u8 subtype)
+					  u8 subtype, u8 flags)
 {
 	switch (subtype) {
 	case BATADV_P_DAT_DHT_GET:
@@ -95,6 +97,13 @@ static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv,
 	case BATADV_P_DAT_DHT_PUT:
 		batadv_inc_counter(bat_priv,
 				   BATADV_CNT_DAT_PUT_RX);
+		if (!flags)
+			batadv_inc_counter(bat_priv,
+					   BATADV_CNT_DAT_PUT_NOFLAGS_RX);
+		if (!(flags & BATADV_P_DAT_DHT_PUT_NO_SRC))
+			batadv_inc_counter(bat_priv, BATADV_CNT_DAT_PUT_SRC_RX);
+		if (!(flags & BATADV_P_DAT_DHT_PUT_NO_DST))
+			batadv_inc_counter(bat_priv, BATADV_CNT_DAT_PUT_DST_RX);
 		break;
 	}
 }
@@ -129,7 +138,7 @@ batadv_dat_snoop_outgoing_arp_reply(struct batadv_priv *bat_priv,
 static inline bool
 batadv_dat_snoop_incoming_arp_reply(struct batadv_priv *bat_priv,
 				    struct sk_buff *skb, int hdr_size,
-				    bool is_dht_put)
+				    bool is_dht_put_src, bool is_dht_put_dst)
 {
 	return false;
 }
net/batman-adv/mesh-interface.c +4 -0
index 41d148634034..bdf9c21b0da2 100644
@@ -1005,7 +1005,11 @@ static const struct {
 	{ "dat_get_rx" },
 	{ "dat_put_tx" },
 	{ "dat_put_rx" },
+	{ "dat_put_src_rx" },
+	{ "dat_put_dst_rx" },
+	{ "dat_put_noflags_rx" },
 	{ "dat_cached_reply_tx" },
+	{ "dat_dht_add_not_candidate" },
 #endif
 };
 
net/batman-adv/routing.c +14 -5
index 5cf26e8b3257..8dd4094d134b 100644
@@ -1045,8 +1045,10 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 	struct batadv_orig_node *orig_node_gw = NULL;
 	struct batadv_orig_node *orig_node = NULL;
 	int hdr_size = sizeof(*unicast_packet);
+	enum batadv_subtype_flags flags;
 	enum batadv_subtype subtype;
-	bool is_dht_put = false;
+	bool is_dht_put_src = false;
+	bool is_dht_put_dst = false;
 	int ret = NET_RX_DROP;
 	u8 *orig_addr_gw;
 	u8 *orig_addr;
@@ -1094,7 +1096,8 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 			unicast_4addr_packet =
 				(struct batadv_unicast_4addr_packet *)skb->data;
 			subtype = unicast_4addr_packet->subtype;
-			batadv_dat_inc_counter(bat_priv, subtype);
+			flags = unicast_4addr_packet->flags;
+			batadv_dat_inc_counter(bat_priv, subtype, flags);
 
 			/* Only payload data should be considered for speedy
 			 * join. For example, DAT also uses unicast 4addr
@@ -1107,7 +1110,10 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 				orig_node = batadv_orig_hash_find(bat_priv,
 								  orig_addr);
 			} else if (subtype == BATADV_P_DAT_DHT_PUT) {
-				is_dht_put = true;
+				if (!(flags & BATADV_P_DAT_DHT_PUT_NO_SRC))
+					is_dht_put_src = true;
+				if (!(flags & BATADV_P_DAT_DHT_PUT_NO_DST))
+					is_dht_put_dst = true;
 			}
 		}
 
@@ -1115,7 +1121,9 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
 							  hdr_size))
 			goto rx_success;
 		if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb,
-							hdr_size, is_dht_put))
+							hdr_size,
+							is_dht_put_src,
+							is_dht_put_dst))
 			goto rx_success;
 
 		batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);
@@ -1356,7 +1364,8 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
 
 	if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size))
 		goto rx_success;
-	if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size, false))
+	if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size, false,
+						false))
 		goto rx_success;
 
 	batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size);
net/batman-adv/send.c +5 -3
index 929b6dd34c10..e6ebe311f79d 100644
@@ -263,13 +263,15 @@ static bool batadv_send_skb_prepare_unicast(struct sk_buff *skb,
  * @skb: the skb containing the payload to encapsulate
  * @orig: the destination node
  * @packet_subtype: the unicast 4addr packet subtype to use
+ * @flags: packet subtype specific flags to set
  *
  * Return: false if the payload could not be encapsulated or true otherwise.
  */
 bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
 					   struct sk_buff *skb,
 					   struct batadv_orig_node *orig,
-					   int packet_subtype)
+					   int packet_subtype,
+					   int flags)
 {
 	struct batadv_unicast_4addr_packet *uc_4addr_packet;
 	struct batadv_hard_iface *primary_if;
@@ -291,7 +293,7 @@ bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
 	uc_4addr_packet->u.packet_type = BATADV_UNICAST_4ADDR;
 	ether_addr_copy(uc_4addr_packet->src, primary_if->net_dev->dev_addr);
 	uc_4addr_packet->subtype = packet_subtype;
-	uc_4addr_packet->reserved = 0;
+	uc_4addr_packet->flags = flags;
 
 	ret = true;
 out:
@@ -337,7 +339,7 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
 	case BATADV_UNICAST_4ADDR:
 		if (!batadv_send_skb_prepare_unicast_4addr(bat_priv, skb,
 							   orig_node,
-							   packet_subtype))
+							   packet_subtype, 0))
 			goto out;
 		break;
 	default:
net/batman-adv/send.h +2 -1
index 3415afec4a0c..7481c4fa0681 100644
@@ -53,7 +53,8 @@ batadv_purge_outstanding_packets(struct batadv_priv *bat_priv,
 bool batadv_send_skb_prepare_unicast_4addr(struct batadv_priv *bat_priv,
 					   struct sk_buff *skb,
 					   struct batadv_orig_node *orig_node,
-					   int packet_subtype);
+					   int packet_subtype,
+					   int flags);
 int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
 			    struct sk_buff *skb, int packet_type,
 			    int packet_subtype,
net/batman-adv/types.h +24 -0
index 045727c3adc0..68b753bb32f6 100644
@@ -975,11 +975,35 @@ enum batadv_counters {
 	/** @BATADV_CNT_DAT_PUT_RX: received dht PUT traffic packet counter */
 	BATADV_CNT_DAT_PUT_RX,
 
+	/**
+	 * @BATADV_CNT_DAT_PUT_SRC_RX: received source-specfic dht PUT traffic
+	 *  packet counter
+	 */
+	BATADV_CNT_DAT_PUT_SRC_RX,
+
+	/**
+	 * @BATADV_CNT_DAT_PUT_DST_RX: received destination-specfic dht PUT
+	 *  traffic packet counter
+	 */
+	BATADV_CNT_DAT_PUT_DST_RX,
+
+	/**
+	 * @BATADV_CNT_DAT_PUT_NOFLAGS_RX: received unspecific/unflagged dht PUT
+	 *  traffic packet counter
+	 */
+	BATADV_CNT_DAT_PUT_NOFLAGS_RX,
+
 	/**
 	 * @BATADV_CNT_DAT_CACHED_REPLY_TX: transmitted dat cache reply traffic
 	 *  packet counter
 	 */
 	BATADV_CNT_DAT_CACHED_REPLY_TX,
+
+	/**
+	 * @BATADV_CNT_DAT_DHT_ADD_NOT_CANDIDATE: counter for local DHT
+	 *  additions without (supposedly) being a selected candidate
+	 */
+	BATADV_CNT_DAT_DHT_ADD_NOT_CANDIDATE,
 #endif
 
 	/** @BATADV_CNT_NUM: number of traffic counters */
Signature · 1 line
2.55.0