Skip to contentSkip to conversation

batman-adv: increase DAT DHT timeout

PATCH Superseded Linus Lüssing 1 participant 5 messages Sep 25 Batman advanced

v11 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v11 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/4).

PATCH 3/4 then increases the timeout for DAT DHT entries from 5 to 30 minutes.

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 v11:
- PATCH 1/4: NEW, simple restructuring in preparation for 2/5 (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 (4):
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

 include/uapi/linux/batman_adv.h        |   5 +
 net/batman-adv/distributed-arp-table.c | 762 +++++++++++++++++++------
 net/batman-adv/distributed-arp-table.h |  19 +-
 net/batman-adv/main.h                  |   3 +-
 net/batman-adv/netlink.c               |   5 +
 net/batman-adv/routing.c               |  12 +-
 net/batman-adv/types.h                 |   7 +-
 7 files changed, 627 insertions(+), 186 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH v11 1/4 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 | 178 ++++++++++++++-----------
 1 file changed, 102 insertions(+), 76 deletions(-)
net/batman-adv/distributed-arp-table.c +102 -76
index 74050bffedbc..9bd0677b7541 100644
@@ -738,6 +738,102 @@ 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: false if we should have but could not create an ARP reply
+ * (e.g. due to out-of-memory), true otherwise.
+ */
+static bool
+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 true;
+
+	/* 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 true;
+	}
+
+	skb = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src, hw_dst,
+					  hw_src, vid);
+	if (!skb)
+		return false;
+
+	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 true;
+}
+
 /**
  * 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 +1275,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 +1293,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;
@@ -1253,6 +1313,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 +1335,11 @@ 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)) {
+		ret = batadv_dat_arp_self_reply(bat_priv, ip_src, ip_dst,
+						hw_src, mac, vid, arp_len);
+		if (ret)
 			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");
 	} 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 v11 2/4 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 | 557 ++++++++++++++++++++-----
 net/batman-adv/distributed-arp-table.h |  19 +-
 net/batman-adv/netlink.c               |   5 +
 net/batman-adv/routing.c               |  12 +-
 net/batman-adv/types.h                 |   7 +-
 6 files changed, 498 insertions(+), 107 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 +460 -97

879 lines not on this page · raw message

net/batman-adv/distributed-arp-table.h +15 -4
index e7b75e82eb1d..f42bcea71e94 100644
@@ -31,13 +31,15 @@ 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,
 					unsigned short vid);
 void batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
-					struct sk_buff *skb, int hdr_size);
+					struct sk_buff *skb, int hdr_size,
+					bool is_dht_put);
 bool batadv_dat_drop_broadcast_packet(struct batadv_priv *bat_priv,
 				      struct batadv_forw_packet *forw_packet);
 
@@ -74,6 +76,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 +129,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;
 }
@@ -140,7 +144,8 @@ batadv_dat_snoop_outgoing_dhcp_ack(struct batadv_priv *bat_priv,
 
 static inline void
 batadv_dat_snoop_incoming_dhcp_ack(struct batadv_priv *bat_priv,
-				   struct sk_buff *skb, int hdr_size)
+				   struct sk_buff *skb, int hdr_size,
+				   bool is_dht_put)
 {
 }
 
@@ -176,6 +181,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 +5 -0
index 1177b3ceaf03..26584e0a2cc8 100644
@@ -1498,6 +1498,11 @@ 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,
+		.flags = GENL_ADMIN_PERM,
+		.dumpit = batadv_dat_dht_dump,
+	},
 	{
 		.cmd = BATADV_CMD_GET_MCAST_FLAGS,
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/routing.c +8 -4
index 6442f5d0cc93..61c8b830c6bc 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,10 +1115,11 @@ 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);
+		batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size,
+						   is_dht_put);
 
 		batadv_interface_rx(recv_if->mesh_iface, skb, hdr_size,
 				    orig_node);
@@ -1353,10 +1357,10 @@ 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);
+	batadv_dat_snoop_incoming_dhcp_ack(bat_priv, skb, hdr_size, false);
 
 	/* broadcast for me */
 	batadv_interface_rx(recv_if->mesh_iface, skb, hdr_size, orig_node);
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
#3 lore raw

PATCH v11 3/4 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 ec3214943d7c..7fc12323e9f7 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
#4 lore raw

PATCH v11 4/4 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 7fc12323e9f7..d7dd17fe83f9 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_check_self_candidate(struct batadv_priv *bat_priv,
@@ -822,6 +825,14 @@ static bool batadv_dat_check_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