batman-adv: increase DAT DHT timeout
v14 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 v14:
- PATCH 2/5:
- remove wrong @hw_dst kerneldoc for batadv_dat_dht_get_self_reply() and batadv_dat_forward_dht_get()
- PATCH 5/5:
- remove an extra newline in batadv_packet.h
- fix compilation with DAT=n by adding the new flags argument to the batadv_dat_inc_counter() stub, too
Changelog v13:
- PATCH 2/5:
- remove .validate for BATADV_CMD_GET_DAT_DHT again
- moved BATADV_CMD_GET_DAT_DHT to end of batadv_netlink_ops
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 | 16 +- include/uapi/linux/batman_adv.h | 5 + net/batman-adv/distributed-arp-table.c | 887 ++++++++++++++++++++----- net/batman-adv/distributed-arp-table.h | 26 +- net/batman-adv/main.h | 3 +- net/batman-adv/mesh-interface.c | 4 + net/batman-adv/netlink.c | 5 + 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, 807 insertions(+), 199 deletions(-)
Signature · 1 line
2.55.0
PATCH v14 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
@@ -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
PATCH v14 2/5 batman-adv: split DAT cache into DAT cache and DAT DHT
In reply to Linus LüssingSimilar 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 | 579 ++++++++++++++++++++----- net/batman-adv/distributed-arp-table.h | 13 +- net/batman-adv/netlink.c | 5 + net/batman-adv/routing.c | 7 +- net/batman-adv/types.h | 7 +- 6 files changed, 507 insertions(+), 109 deletions(-)
include/uapi/linux/batman_adv.h +5 -0
@@ -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 +476 -103
908 lines not on this page · raw message
net/batman-adv/distributed-arp-table.h +11 -2
@@ -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 +5 -0
@@ -1535,6 +1535,11 @@ static const struct genl_small_ops batadv_netlink_ops[] = { .internal_flags = BATADV_FLAG_NEED_MESH | BATADV_FLAG_NEED_VLAN, }, + { + .cmd = BATADV_CMD_GET_DAT_DHT, + .flags = GENL_UNS_ADMIN_PERM, + .dumpit = batadv_dat_dht_dump, + }, };struct genl_family batadv_netlink_family__ro_after_init = {
net/batman-adv/routing.c +5 -2
@@ -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
@@ -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
PATCH v14 3/5 batman-adv: increase DAT DHT timeout
In reply to Linus LüssingCurrently, 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
@@ -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
@@ -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
PATCH v14 4/5 batman-adv: avoid superfluous DAT DHT_PUT if self-candidate
In reply to Linus LüssingIf 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
@@ -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
PATCH v14 5/5 batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT
In reply to Linus LüssingWe 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 | 16 +++- net/batman-adv/distributed-arp-table.c | 124 ++++++++++++++++++++++--- net/batman-adv/distributed-arp-table.h | 17 +++- 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(+), 29 deletions(-)
include/uapi/linux/batadv_packet.h +14 -2
@@ -70,6 +70,18 @@ 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 +445,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 +13 -4
@@ -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; }
@@ -186,7 +195,7 @@ batadv_dat_dht_dump(struct sk_buff *msg, struct netlink_callback *cb) }static inline void batadv_dat_inc_counter (struct batadv_priv *bat_priv, -u8 subtype) +u8 subtype,u8 flags) { }
net/batman-adv/mesh-interface.c +4 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [batadv,v14 5/5] batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT
Quoted 2 lines · On Tue, Oct 06, 2026 at 07:02:00PM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] batadv: CPU exhaustion DoS via O(N) candidate selection in softirq
I think we have this situation already for ARP Replies, even without this patchset (though limited to the local node)? And avoiding that seems like it would need quite some rework.
Besides, at least in Gluon we have ARP ratelimiting via ebtables anyway, as we've had some devices, probably some funny mobile apps, scanning the full /20 IP range, leading to a lot of ARP traffic:
https://github.com/freifunk-gluon/gluon/tree/main/package/gluon-ebtables-limit-arp
So we wouldn't be (that) affected and I think any larger and especially publically accessible batman-adv network should configure such rate-limiting via netfilter anyway.
Quoted 1 line
- [Medium] batadv: UAPI source compatibility breakage via reserved field rename
I would have thought that for a field called "reserved" it would be clear that it'd be subject to change in the future.
Or should I introduce a "struct batadv_unicast_4addr_v2_packet"?
Quoted 84 lines
--
commit
ad436b7e22433bb29047a461fbcafbd08d11c4a3
Author: Linus Lüssing <[email protected]>batman-adv: avoid superfluous DAT
DHT_PUTadditions to local DATThis commit adds a flag to
DHT_PUTmessages to indicate which pair is supposed to be added to the local DHT. This avoids populating the local DHT with unnecessary entries that will likely never be queried.Quoted 4 lines
include/uapi/linux/batadv_packet.h +0
-0[ ... ]
include/uapi/linux/batadv_packet.h struct batadv_unicast_packet { · line 454
Quoted 13 lines
include/uapi/linux/batadv_packet.h +2
-2@@ -445,13 +445,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;[Severity: Medium]
Does renaming the reserved field to flags in the UAPI structurebatadv_unicast_4addr_packetbreak source compatibility? Any user-space applications referencing the old reserved field name might fail to compile after this change.Quoted 7 lines
include/uapi/linux/batadv_packet.h +0
-0/* "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 +0
-0[ ... ]
net/batman-adv/distributed-arp-table.c static inline void · line 574
Quoted 11 lines
net/batman-adv/distributed-arp-table.c +7
-0@@ -562,6 +565,20 @@ static inline void batadv_dat_dht_entry_add(struct batadv_priv *bat_priv, __be32 ip, u8 *mac_addr, unsigned short vid) { +/* Happens if a new node just beat us as a candidate, an old node +* does not have the more specific candidate selection enhancements yet +* or if future protocol enhancements, which this node does not have +* yet, added new/other candidate selections. For compatibility reasons +* do not bail out here. +*/ +if (!batadv_dat_dht_check_self_is_candidate (bat_priv, ip, vid)) {[Severity: High]
Does callingbatadv_dat_dht_check_self_is_candidate()unconditionally inbatadv_dat_dht_entry_add()during the receive path introduce a denial of service vector?Looking at
batadv_dat_dht_check_self_is_candidate(), it callsbatadv_dat_select_candidates()which performs aGFP_ATOMICallocation and iterates over the originator hash. Sincebatadv_dat_dht_entry_add()can be triggered from softirq context when processing incoming packets, could an attacker send a flood ofDHT_PUTmessages to exhaust CPU resources and memory?Quoted 10 lines
net/batman-adv/distributed-arp-table.c +7
-0+batadv_inc_counter (bat_priv, +BATADV_CNT_DAT_DHT_ADD_NOT_CANDIDATE ); +batadv_dbg (BATADV_DBG_DAT , bat_priv, +"Adding %pI4 %pM (vid: %d), although we are not a candidate\n" , + &ip, mac_addr,batadv_print_vid (vid)); + } +batadv_dat_entry_add (bat_priv, bat_priv->dat.dht_hash, ip, mac_addr, vid,"dht" ); }Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Sven Eckelmann
maintainerRe: [batadv,v14 5/5] batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT
Quoted 4 lines · On Wednesday, 7 October 2026 03:08:03 CEST Linus Lüssing wrote:
Quoted 1 line
- [Medium] batadv: UAPI source compatibility breakage via reserved field rename
I would have thought that for a field called "reserved" it would be clear that it'd be subject to change in the future.
To play the devils advocate: But programs would still fail when they manually initialize this field to 0.
Quoted 1 line
Or should I introduce a "struct
batadv_unicast_4addr_v2_packet"?
Usually, you have a couple of bytes marked as a reserved array. And then they reduce the number of bytes by X and add a new field. You can discuss if this is correct or not (because then suddenly the new field would no longer be initialized).
But for example, in commit c07d3aede2b2 ("fscrypt: add support for hardware- wrapped keys") or commit 38a435800945 ("habanalabs: expose device security status using info ioctl") or 91233ad71186 ("vhost: support ASID in IOTLB API"), exactly your approach was taken.
You could in theory (to make it compile in all situations), also use an anonymous union around flags and reserved to ensure the byte can be accessed with both names.
To also support your point, please check
https://docs.kernel.org/dev-tools/checkuapi.html - which also considers "reserved" as ok:
95 # Common padding field names which can be expanded into
96 # without worrying about users.
Regards,
Sven
Re: [batadv,v14 5/5] batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT
Quoted 8 lines · Sven Eckelmann
Quoted 4 lines · On Wednesday, 7 October 2026 03:08:03 CEST Linus Lüssing wrote:
Quoted 1 line
- [Medium] batadv: UAPI source compatibility breakage via reserved field rename
I would have thought that for a field called "reserved" it would be clear that it'd be subject to change in the future.
To play the devils advocate: But programs would still fail when they manually initialize this field to 0.
On the other hand I'm thinking they should have memset() the struct to zero in the first place, instead of manually setting a reserved field to 0.
Similar to ioctl()'s for instance, where there too you should memset/zero the full struct, passed argument, I believe, instead of just zero'ing individual fields as there might be new fields getting appended in the future.
Interestingly, include/uapi/linux/ethtool.h has an explicit note for this:
``` 26 /* Note on reserved space. 27 * Reserved fields must not be accessed directly by user space because 28 * they may be replaced by a different field in the future. They must 29 * be initialized to zero before making the request, e.g. via memset 30 * of the entire structure or implicitly by not being set in a structure 31 * initializer. 32 */ ```
Which we don't have in batadv_packet.h though. (So technically, someone could complain about such a rename because we don't have such a note?)
Re: [batadv,v14 5/5] batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT
Quoted 7 lines · Linus Lüssing
Quoted 6 lines · Sven Eckelmann
Quoted 4 lines · On Wednesday, 7 October 2026 03:08:03 CEST Linus Lüssing wrote:
Quoted 1 line
- [Medium] batadv: UAPI source compatibility breakage via reserved field rename
I would have thought that for a field called "reserved" it would be clear that it'd be subject to change in the future.
Quoted 6 lines
Quoted 2 lines
To play the devils advocate: But programs would still fail when they manually initialize this field to 0.
On the other hand I'm thinking they should have
memset()the struct to zero in the first place, instead of manually setting a reserved field to 0.
There is another general case advantage of memset. I've not looked to see if it is actually applicable here. It will also clear any padding bytes, if there are holes in the structure due to alignment. If the padding bytes have always been zeroed, you can make use of them later.
Also, for kernel to userspace copies, you avoid leaking bits of the stack to userspace, both in the padding holes, and any fields in the structure which don't get explicitly set.
memset of a small structure, less than a cache line in length, probably costs the same as setting a single element. Fetching it into cache is the expensive part, once in the cache it is nearly free to use.
Andrew
Sven Eckelmann
maintainerHi,
please go through the lists of things reported Sashiko
(https://netdev-ai.bots.linux.dev/sashiko/ like). Either write a rebuttal to this mailing list or fix them (when they are valid).
Critical: 0 High: 0 Medium: 4 Low: 5
--- Patch [1] batman-adv: move local ARP reply code to subfunctions --- [Low] batman-adv: inaccurate kernel-doc for batadv_dat_arp_self_reply() [Low] batman-adv: DAT local ARP reply RX_BYTES counts request size with headers twice
--- Patch [2] batman-adv: split DAT cache into DAT cache and DAT DHT --- [Medium] batman-adv: batadv_dat_init() leaks cache_hash when dht_hash allocation fails [Medium] batman-adv: incoming ARP requests no longer answered from DAT cache entries [Low] batman-adv: free-slot self-candidate makes DHT_PUT drop a non-displaced remote candidate
--- Patch [5] batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT --- [Medium] batman-adv: batadv_dat_dht_entry_add() runs full candidate selection per insert [Medium] batman-adv: dat_dht_add_not_candidate counter inflated on selection failure/race [Low] batman-adv: wire flags bitmask stored in enum batadv_subtype_flags variable [Low] batman-adv: typo 'specfic' in new counter kernel-doc
Inline Review:
--- Patch [1]: batman-adv: move local ARP reply code to subfunctions --- commit 09dfd5b76d0f3b8d56db5de7e0690d47cb2538a3
Author: Linus Lüssing <[email protected]>
batman-adv: move local ARP reply code to subfunctions
This commit moves the local ARP reply checks and generation out of batadv_dat_snoop_outgoing_arp_request() into a new helper, batadv_dat_arp_self_reply(), and moves batadv_dat_arp_create_reply() earlier in the file. It is described as preparation for reuse in the DAT cache/DHT split, with no functional change.
Quoted 4 lines
net/batman-adv/distributed-arp-table.c +0
-0
[ ... ]
Quoted 7 lines
+/**
+ *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
[Severity: Low]
Is this description of hw_dst accurate? The only caller, batadv_dat_snoop_outgoing_arp_request(), passes the MAC resolved from the DAT entry:
u64_mac = atomic64_read(&dat_entry->mac_addr);
u64_to_ether_addr(u64_mac, mac);
rep = batadv_dat_arp_self_reply(bat_priv, ip_src, ip_dst,
hw_src, mac, vid, arp_len);The Ethernet destination of an ARP request is normally broadcast, and its ARP target MAC is usually zero, so neither matches what is passed here.
Quoted 6 lines
+ * @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.
[Severity: Low]
Does this summary match what batadv_bla_check_claim() does? That function also returns true when bridge_loop_avoidance is disabled, when there is no primary_if, and when nobody has claimed the address:
if (!READ_ONCE(bat_priv->bridge_loop_avoidance))
return ret;
primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if)
return ret;In all of those cases a reply is still built and passed to netif_rx(). The in-body comment ("If BLA is enabled, only send ARP replies if ...") describes this correctly, but the kernel-doc summary contradicts it.
Quoted 3 lines
+ *
+ * Return: 0 if we transmitted an ARP reply,-ENOMEMif we should have but
+ * could not create an ARP reply (e.g. due to out-of-memory),-EACCSS
^^^^^^
[Severity: Low]
This isn't a bug, but -EACCSS looks like a typo for -EACCES, which is what both suppression paths return.
The later batadv_dat_dht_get_self_reply() caller added in this series relies on this contract, and the typo and the BLA wording remain unchanged at the end of the series.
Quoted 2 lines
+ * otherwise (because the client is local or due to BLA suppression).
+ */
[ ... ]
net/batman-adv/distributed-arp-table.c bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, · line 1319
Quoted 5 lines
net/batman-adv/distributed-arp-table.c +1
-0@@ -1254,6 +1316,7 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, goto out; vid =batadv_dat_get_vid (skb, &hdr_size); + arg_len = skb->len +ETH_HLEN + hdr_size;
[Severity: Low]
Does this count the Ethernet and VLAN headers twice?
The caller, batadv_interface_tx(), does pskb_may_pull(skb, ETH_HLEN) and skb_reset_mac_header(skb) but never pulls the Ethernet header, so skb->data still points at it here. batadv_arp_get_type() relies on that:
ethhdr = (struct ethhdr *)(skb->data + hdr_size);
So skb->len already includes ETH_HLEN, plus VLAN_HLEN for tagged frames, and arp_len adds them again. This value is then passed to batadv_dat_arp_self_reply() and accounted as BATADV_CNT_RX_BYTES for the injected reply skb.
This problem wasn't introduced by this patch, since the parent commit used the same skb->len + ETH_HLEN + hdr_size expression. However, the new kernel-doc describes the parameter as "ARP packet size, including ethernet frame", which this value does not match. It is also the size of the request rather than of the reply created by arp_create().
The same arp_len computation is carried through the rest of the series and is also passed to batadv_dat_dht_get_self_reply() and batadv_dat_forward_dht_get(), so it is not fixed later on.
net/batman-adv/distributed-arp-table.c bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, · line 1320
Quoted 2 lines
net/batman-adv/distributed-arp-table.c +0
-0type =batadv_arp_get_type (bat_priv, skb, hdr_size);
[ ... ]
--- Patch [2]: batman-adv: split DAT cache into DAT cache and DAT DHT --- commit fb097bd3187273b7cdbbd2182627f3eff6e3b55b
Author: Linus Lüssing <[email protected]>
batman-adv: split DAT cache into DAT cache and DAT DHT
This commit splits the single DAT hash table into a locally maintained DAT cache and a separate DAT DHT table, similar to the translation table split. It adds a self-candidate check so the local node can store DHT_PUT data and answer DHT_GET requests locally, and adds a new BATADV_CMD_GET_DAT_DHT netlink dump command.
Quoted 4 lines
net/batman-adv/distributed-arp-table.c +0
-0
[ ... ]
Quoted 5 lines
net/batman-adv/distributed-arp-table.c +5
-0+static bool batadv_dat_cmp_self_candidate (struct batadv_priv *bat_priv, +struct batadv_dat_candidate *cands, +batadv_dat_addr_t ip_key, +batadv_dat_addr_t last_max) +{
[ ... ]
net/batman-adv/distributed-arp-table.c
Quoted 7 lines
net/batman-adv/distributed-arp-table.c +7
-0+ last_cand = &cands[BATADV_DAT_CANDIDATES_NUM -1 ]; + +/* a free slot? then it is for us */ +if (last_cand->type ==BATADV_DAT_CANDIDATE_NOT_FOUND ) { + ret = true; + goto out; + }
[Severity: Low]
This returns the same true for "filled an empty slot" as for "displaced the last remote candidate by distance". Can callers tell those two cases apart?
In this patch it is harmless, since batadv_dat_forward_data() still sends to every remote candidate. But the later patch in the series, "batman-adv:
avoid superfluous DAT DHT_PUT if self-candidate", adds this to batadv_dat_forward_dht_put():
if (self_is_candidate) {
for (i = BATADV_DAT_CANDIDATES_NUM - 1; i >= 0; i--) {
if (cands[i].type != BATADV_DAT_CANDIDATE_ORIG)
continue;
batadv_orig_node_put(cands[i].orig_node);
cands[i].type = BATADV_DAT_CANDIDATE_NOT_FOUND;
cands[i].orig_node = NULL;
break;
}
}With only one remote originator, batadv_choose_next_candidate() fills cands[0] and leaves cands[1..2] as NOT_FOUND. The free slot branch here returns true, and the loop above then clears cands[0]. No DHT_PUT is sent at all, even though that remote node is a legitimate candidate. With two remote originators, one of them is dropped and the entry is replicated on two nodes instead of three.
Would it make sense for batadv_dat_cmp_self_candidate() to report whether a remote candidate was actually displaced, so the later patch only drops a candidate in that case?
[ ... ]
Quoted 1 line
net/batman-adv/distributed-arp-table.c +0
-0@@ -966,37 +1246,77 @@ static void batadv_dat_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
[ ... ]
net/batman-adv/distributed-arp-table.c
Quoted 11 lines
net/batman-adv/distributed-arp-table.c +11
-0+int batadv_dat_init (struct batadv_priv *bat_priv) +{ +int ret; + + ret =batadv_dat_cache_hash_init (bat_priv); +if (ret <0 ) +return ret; + + ret =batadv_dat_dht_hash_init (bat_priv); +if (ret <0 ) +return ret;
[Severity: Medium]
Does this leak bat_priv->dat.cache_hash when batadv_dat_dht_hash_init() fails?
batadv_hash_new() uses GFP_ATOMIC, so the second allocation can fail after the first one succeeded. The caller does not clean up DAT on this path:
net/batman-adv/main.c:batadv_mesh_init() {
...
err_dat:
batadv_bla_free(bat_priv);
...
}The unwind only frees BLA, TT, BATMAN V and originator state, and never calls batadv_dat_free(). Before this patch DAT had a single allocation, so nothing was left behind on failure.
The same sequence is still present at the end of the series. Should this call batadv_dat_hash_free(&bat_priv->dat.cache_hash) before returning?
[ ... ]
net/batman-adv/distributed-arp-table.c bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, · line 1778
Quoted 11 lines
net/batman-adv/distributed-arp-table.c +2
-2@@ -1402,9 +1771,9 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,batadv_dbg_arp (bat_priv, skb, hdr_size,"Parsing incoming ARP REQUEST" ); -batadv_dat_entry_add (bat_priv, ip_src, hw_src, vid); +batadv_dat_cache_entry_add (bat_priv, ip_src, hw_src, vid); - dat_entry =batadv_dat_entry_hash_find (bat_priv, ip_dst, vid); + dat_entry =batadv_dat_dht_entry_find (bat_priv, ip_dst, vid);if (!dat_entry) goto out;
[Severity: Medium]
Is this narrowing of the reply source intended?
Before this patch the lookup used the single table that held every snooped mapping. Now only dht_hash entries can produce a BATADV_P_DAT_CACHE_REPLY. Mappings that only go into cache_hash are no longer used to answer remote requests. That includes mappings from:
batadv_dat_snoop_incoming_dhcp_ack()
the ip_src of incoming and outgoing ARP requests broadcast ARP replies (is_dht_put == false) non-PUT unicast ARP replies
This lookup is reached for DHT_GET unicast packets via batadv_recv_unicast_packet() and for broadcast ARP requests via batadv_recv_bcast_packet().
For example, a DHT candidate whose local client issued ARP requests used to answer DHT_GETs for that client. Now it can only do so if it also received a DHT_PUT for that IP. Requests that used to be answered from the cache now fall back to the mesh-wide broadcast, so ARP resolution still works but DAT suppresses fewer floods.
The commit message describes the split as being for monitoring and debugging and for future differing properties, and does not mention this behavior change. The later patches in the series ("batman-adv: increase DAT DHT timeout", "batman-adv: avoid superfluous DAT DHT_PUT if self-candidate" and "batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT") leave this lookup unchanged and reduce DHT population further.
Should this also consult cache_hash, or should the commit message document the change?
--- Patch [5]: batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT --- commit ec02a0f413dd03663ce3423d2702fa902d3f318d
Author: Linus Lüssing <[email protected]>
batman-adv: avoid superfluous DAT DHT_PUT additions to local DAT
This adds NO_SRC/NO_DST flags to the unicast 4addr header of DHT_PUT messages, so a receiving node only adds the sender or the target MAC/IP pair to its local DHT. It also adds a self-candidate check with a new counter and new ethtool counters for received DHT_PUTs.
Quoted 4 lines
net/batman-adv/distributed-arp-table.c +0
-0
[ ... ]
net/batman-adv/distributed-arp-table.c static inline void · line 574
Quoted 11 lines
net/batman-adv/distributed-arp-table.c +7
-0@@ -562,6 +565,20 @@ static inline void batadv_dat_dht_entry_add(struct batadv_priv *bat_priv, __be32 ip, u8 *mac_addr, unsigned short vid) { +/* Happens if a new node just beat us as a candidate, an old node +* does not have the more specific candidate selection enhancements yet +* or if future protocol enhancements, which this node does not have +* yet, added new/other candidate selections. For compatibility reasons +* do not bail out here. +*/ +if (!batadv_dat_dht_check_self_is_candidate (bat_priv, ip, vid)) {
[Severity: Medium]
Is it worth running a full candidate selection on every DHT insert here? The result only feeds a counter and a debug message, and the entry is added either way.
batadv_dat_dht_check_self_is_candidate() callsbatadv_dat_select_candidates(), which does:
res = kmalloc_objs(*res, BATADV_DAT_CANDIDATES_NUM, GFP_ATOMIC);
...
for (select = 0; select < BATADV_DAT_CANDIDATES_NUM; select++)
batadv_choose_next_candidate(bat_priv, res, select, ip_key,
&last_max);Each batadv_choose_next_candidate() round walks the whole orig_hash with kref get/put on the orig_nodes, and batadv_dat_cmp_self_candidate() then does a primary_if get/put.
On the RX side this runs in softirq context:
batadv_recv_unicast_packet()
batadv_dat_snoop_incoming_arp_reply()
batadv_dat_dht_entry_add()
batadv_dat_dht_check_self_is_candidate()
batadv_dat_select_candidates()
A DHT_PUT with flags == 0 (sent by every legacy node, and by any mesh peer that chooses to) sets both is_dht_put_src and is_dht_put_dst. That means two allocations and 6 orig_hash walks per received packet, where previously this was only a hash lookup and insert. There is no rate limiting, and the cost scales with the size of the mesh.
On the TX side, batadv_dat_forward_dht_put() already computed self_is_candidate and only calls batadv_dat_dht_entry_add() when it is true:
if (self_is_candidate)
batadv_dat_dht_entry_add(bat_priv, ip, hw_addr, vid);The callee then recomputes the same selection. So every snooped outgoing ARP reply (batadv_dat_snoop_outgoing_arp_reply()) and DHCP ACK (batadv_dat_put_dhcp()) does this work twice.
Could the known result be passed down from the TX caller, and the RX-side recheck be gated (for example behind the debug log level) or dropped?
The commit message describes only the new wire flag. It doesn't mention this check, its cost, or the new ethtool counters (dat_put_src_rx, dat_put_dst_rx, dat_put_noflags_rx, dat_dht_add_not_candidate). Should those be described there as well?
net/batman-adv/distributed-arp-table.c static inline void · line 576
Quoted 2 lines
net/batman-adv/distributed-arp-table.c +2
-0+batadv_inc_counter (bat_priv, +BATADV_CNT_DAT_DHT_ADD_NOT_CANDIDATE );
[Severity: Medium]
Can this counter be bumped when we actually are a candidate?
batadv_dat_select_candidates() returns NULL without writing *self_is_candidate when bat_priv->orig_hash is NULL or when the GFP_ATOMIC allocation fails:
if (!bat_priv->orig_hash)
return NULL;
res = kmalloc_objs(*res, BATADV_DAT_CANDIDATES_NUM, GFP_ATOMIC);
if (!res)
return NULL;batadv_dat_dht_check_self_is_candidate() initialises self_is_candidate to false and returns it unchanged. That makes a failure look the same as a genuine "not a candidate" result. batadv_dat_cmp_self_candidate() also yields false when batadv_primary_if_get_selected() returns NULL.
On the TX path there is also a window between the two selections. batadv_dat_forward_dht_put() has seen self_is_candidate == true. The recheck in batadv_dat_dht_entry_add() then runs in separate RCU sections. A concurrent orig_hash add or purge, or a primary_if change, can make the second answer differ from the first.
In all of these cases the counter is incremented and "although we are not a candidate" is logged. Memory pressure, which the RX path above can help to cause, and benign races would both inflate dat_dht_add_not_candidate. Would that make it unreliable as a diagnostic for candidate selection mismatches?
Quoted 8 lines
net/batman-adv/distributed-arp-table.c +5
-0+batadv_dbg (BATADV_DBG_DAT , bat_priv, +"Adding %pI4 %pM (vid: %d), although we are not a candidate\n" , + &ip, mac_addr,batadv_print_vid (vid)); + } +batadv_dat_entry_add (bat_priv, bat_priv->dat.dht_hash, ip, mac_addr, vid,"dht" ); }
[ ... ]
net/batman-adv/routing.c int batadv_recv_unicast_packet(struct sk_buff *skb, · line 1048
Quoted 9 lines
net/batman-adv/routing.c +1
-0@@ -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;
[Severity: Low]
This isn't a bug, but should flags be a u8 rather than enum batadv_subtype_flags?
It holds the raw on-wire byte. That can be 0x03 or contain unknown future bits, and neither is a valid enumerator. It is then passed as u8 to batadv_dat_inc_counter(), while the send path uses int for the same value.
Quoted 4 lines
net/batman-adv/routing.c +2
-1enum batadv_subtype subtype; -bool is_dht_put = false; +bool is_dht_put_src = false; +bool is_dht_put_dst = false;
[ ... ]
net/batman-adv/types.h enum batadv_counters { · line 979
Quoted 10 lines
net/batman-adv/types.h +2
-0@@ -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
[Severity: Low]
Typo: specfic -> specific.
net/batman-adv/types.h enum batadv_counters { · line 985
Quoted 6 lines
net/batman-adv/types.h +6
-0+* packet counter +*/ + BATADV_CNT_DAT_PUT_SRC_RX, + +/** +* @BATADV_CNT_DAT_PUT_DST_RX: received destination-specfic dht PUT
[Severity: Low]
Same typo here: specfic -> specific.
Quoted 3 lines
net/batman-adv/types.h +3
-0+* traffic packet counter +*/ + BATADV_CNT_DAT_PUT_DST_RX,
[ ... ]