batman-adv: increase DAT DHT timeout
v7 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/3).
PATCH 3/3 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 this year 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
These patches (v5) have been applied in this mesh network without issues for 3 months now.
Regards,
Linus
---
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
PATCH v7 1/3 batman-adv: netlink: reduce duplicate code by returning interfaces
Reduce duplicate code by using netlink helpers which return the soft/hard interface directly. Instead of returning an interface index which we are typically not interested in.
--- net/batman-adv/bridge_loop_avoidance.c | 30 +---- net/batman-adv/distributed-arp-table.c | 15 +-- net/batman-adv/gateway_client.c | 15 +-- net/batman-adv/multicast.c | 14 +-- net/batman-adv/netlink.c | 146 +++++++++++++++++-------- net/batman-adv/netlink.h | 5 +- net/batman-adv/originator.c | 80 ++++---------- net/batman-adv/translation-table.c | 28 +---- 8 files changed, 150 insertions(+), 183 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +6 -24
@@ -2233,25 +2233,16 @@ int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb) {struct batadv_hard_iface *primary_if =NULL ;int portid =NETLINK_CB (cb->skb).portid; -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_hashtable *hash;struct batadv_priv *bat_priv;int bucket = cb->args[0 ];int idx = cb->args[1 ]; -int ifindex;int ret =0 ; - ifindex =batadv_netlink_get_ifindex (cb->nlh, -BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface); hash = bat_priv->bla.claim_hash;
@@ -2403,25 +2394,16 @@ int batadv_bla_backbone_dump(struct sk_buff *msg, struct netlink_callback *cb) {struct batadv_hard_iface *primary_if =NULL ;int portid =NETLINK_CB (cb->skb).portid; -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_hashtable *hash;struct batadv_priv *bat_priv;int bucket = cb->args[0 ];int idx = cb->args[1 ]; -int ifindex;int ret =0 ; - ifindex =batadv_netlink_get_ifindex (cb->nlh, -BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface); hash = bat_priv->bla.backbone_hash;
net/batman-adv/distributed-arp-table.c +3 -12
@@ -937,25 +937,16 @@ int batadv_dat_cache_dump(struct sk_buff *msg, struct netlink_callback *cb) {struct batadv_hard_iface *primary_if =NULL ;int portid =NETLINK_CB (cb->skb).portid; -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_hashtable *hash;struct batadv_priv *bat_priv;int bucket = cb->args[0 ];int idx = cb->args[1 ]; -int ifindex;int ret =0 ; - ifindex =batadv_netlink_get_ifindex (cb->nlh, -BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface); hash = bat_priv->dat.hash;
net/batman-adv/gateway_client.c +3 -12
@@ -502,22 +502,13 @@ void batadv_gw_node_free(struct batadv_priv *bat_priv)int batadv_gw_dump (struct sk_buff *msg,struct netlink_callback *cb) {struct batadv_hard_iface *primary_if =NULL ; -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_priv *bat_priv; -int ifindex;int ret; - ifindex =batadv_netlink_get_ifindex (cb->nlh, -BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface);
net/batman-adv/multicast.c +3 -11
@@ -2112,21 +2112,13 @@ batadv_mcast_netlink_get_primary(struct netlink_callback *cb, struct batadv_hard_iface **primary_if) {struct batadv_hard_iface *hard_iface =NULL ; -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_priv *bat_priv; -int ifindex;int ret =0 ; - ifindex =batadv_netlink_get_ifindex (cb->nlh,BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface);
net/batman-adv/netlink.c +103 -43
231 lines not on this page · raw message
net/batman-adv/netlink.h +4 -1
@@ -15,7 +15,10 @@void batadv_netlink_register (void );void batadv_netlink_unregister (void ); -int batadv_netlink_get_ifindex (const struct nlmsghdr *nlh,int attrtype); +struct net_device *batadv_netlink_get_softif (struct netlink_callback *cb); +struct batadv_hard_iface * +batadv_netlink_get_hardif (struct batadv_priv *bat_priv, +struct netlink_callback *cb); int batadv_netlink_tpmeter_notify(struct batadv_priv *bat_priv, const u8 *dst, u8 result, u32 test_time, u64 total_bytes,
net/batman-adv/originator.c +22 -58
140 lines not on this page · raw message
net/batman-adv/translation-table.c +6 -22
@@ -1161,26 +1161,18 @@ batadv_tt_local_dump_bucket(struct sk_buff *msg, u32 portid,*/ int batadv_tt_local_dump (struct sk_buff *msg,struct netlink_callback *cb) { -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_priv *bat_priv;struct batadv_hard_iface *primary_if =NULL ;struct batadv_hashtable *hash;int ret; -int ifindex;int bucket = cb->args[0 ];int idx = cb->args[1 ];int portid =NETLINK_CB (cb->skb).portid; - ifindex =batadv_netlink_get_ifindex (cb->nlh,BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface);
@@ -1936,28 +1928,20 @@ batadv_tt_global_dump_bucket(struct sk_buff *msg, u32 portid, u32 seq,*/ int batadv_tt_global_dump (struct sk_buff *msg,struct netlink_callback *cb) { -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_priv *bat_priv;struct batadv_hard_iface *primary_if =NULL ;struct batadv_hashtable *hash;struct hlist_head *head;int ret; -int ifindex;int bucket = cb->args[0 ];int idx = cb->args[1 ];int sub = cb->args[2 ];int portid =NETLINK_CB (cb->skb).portid; - ifindex =batadv_netlink_get_ifindex (cb->nlh,BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface);
Signature · 1 line
2.45.2
Sven Eckelmann
maintainerRe: [PATCH v7 1/3] batman-adv: netlink: reduce duplicate code by returning interfaces
On Saturday, 30 November 2024 00:46:32 GMT+1 Linus Lüssing wrote:
[...]
Quoted 16 lines
net/batman-adv/bridge_loop_avoidance.c +0
-5@@ -2233,25 +2233,16 @@ int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb) {struct batadv_hard_iface *primary_if =NULL ;int portid =NETLINK_CB (cb->skb).portid; -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface;struct batadv_hashtable *hash;struct batadv_priv *bat_priv;int bucket = cb->args[0 ];int idx = cb->args[1 ]; -int ifindex;int ret =0 ; - ifindex =batadv_netlink_get_ifindex (cb->nlh, -BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex)
net/batman-adv/bridge_loop_avoidance.c int batadv_bla_claim_dump(struct sk_buff *msg, struct netlink_callback *cb) · line 2245
Quoted 10 lines
net/batman-adv/bridge_loop_avoidance.c +3
-7-return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface);
To use these helpers, you need to "#include <linux/err.h>" in various files. There are also other changes needed. Here an overview:
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index c38a1ac9..fa8a8246 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -12,6 +12,7 @@
#include <linux/compiler.h>
#include <linux/container_of.h>
#include <linux/crc16.h>
+#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/gfp.h>
@@ -38,7 +39,6 @@
#include <net/arp.h>
#include <net/genetlink.h>
#include <net/netlink.h>
-#include <net/sock.h>
#include <uapi/linux/batadv_packet.h>
#include <uapi/linux/batman_adv.h>
@@ -47,7 +47,6 @@
#include "log.h"
#include "netlink.h"
#include "originator.h"
-#include "soft-interface.h"
#include "translation-table.h"
static const u8 batadv_announce_mac[4] = {0x43, 0x05, 0x43, 0x05};
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 67bb3b17..ff660758 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -11,6 +11,7 @@
#include <linux/bitops.h>
#include <linux/byteorder/generic.h>
#include <linux/container_of.h>
+#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/gfp.h>
@@ -36,7 +37,6 @@
#include <net/arp.h>
#include <net/genetlink.h>
#include <net/netlink.h>
-#include <net/sock.h>
#include <uapi/linux/batman_adv.h>
#include "bridge_loop_avoidance.h"
@@ -46,7 +46,6 @@
#include "netlink.h"
#include "originator.h"
#include "send.h"
-#include "soft-interface.h"
#include "translation-table.h"
#include "tvlv.h"
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index dc57b54b..8afdc711 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -10,6 +10,7 @@
#include <linux/atomic.h>
#include <linux/byteorder/generic.h>
#include <linux/container_of.h>
+#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/gfp.h>
@@ -31,7 +32,6 @@
#include <linux/sprintf.h>
#include <linux/stddef.h>
#include <linux/udp.h>
-#include <net/sock.h>
#include <uapi/linux/batadv_packet.h>
#include <uapi/linux/batman_adv.h>
@@ -40,7 +40,6 @@
#include "netlink.h"
#include "originator.h"
#include "routing.h"
-#include "soft-interface.h"
#include "translation-table.h"
/* These are the offsets of the "hw type" and "hw address length" in the dhcp
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index 17b302db..5b13010d 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -12,6 +12,7 @@
#include <linux/bug.h>
#include <linux/byteorder/generic.h>
#include <linux/container_of.h>
+#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/gfp.h>
@@ -46,7 +47,6 @@
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/netlink.h>
-#include <net/sock.h>
#include <uapi/linux/batadv_packet.h>
#include <uapi/linux/batman_adv.h>
@@ -56,7 +56,6 @@
#include "log.h"
#include "netlink.h"
#include "send.h"
-#include "soft-interface.h"
#include "translation-table.h"
#include "tvlv.h"
diff --git a/net/batman-adv/originator.c b/net/batman-adv/originator.c
index 145eb110..972003d3 100644
--- a/net/batman-adv/originator.c
+++ b/net/batman-adv/originator.c
@@ -9,6 +9,7 @@
#include <linux/atomic.h>
#include <linux/container_of.h>
+#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/gfp.h>
@@ -26,9 +27,7 @@
#include <linux/spinlock.h>
#include <linux/stddef.h>
#include <linux/workqueue.h>
-#include <net/sock.h>
#include <uapi/linux/batadv_packet.h>
-#include <uapi/linux/batman_adv.h>
#include "bat_algo.h"
#include "distributed-arp-table.h"
@@ -41,7 +40,6 @@
#include "netlink.h"
#include "network-coding.h"
#include "routing.h"
-#include "soft-interface.h"
#include "translation-table.h"
/* hash class keys */
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c
index d464569e..a7680858 100644
--- a/net/batman-adv/translation-table.c
+++ b/net/batman-adv/translation-table.c
@@ -15,6 +15,7 @@
#include <linux/compiler.h>
#include <linux/container_of.h>
#include <linux/crc32c.h>
+#include <linux/err.h>
#include <linux/errno.h>
#include <linux/etherdevice.h>
#include <linux/gfp.h>
@@ -39,7 +40,6 @@
#include <linux/workqueue.h>
#include <net/genetlink.h>
#include <net/netlink.h>
-#include <net/sock.h>
#include <uapi/linux/batadv_packet.h>
#include <uapi/linux/batman_adv.h>[...]
Quoted 6 lines
net/batman-adv/netlink.c +1
-1@@ -1150,23 +1137,17 @@ static int batadv_netlink_set_vlan(struct sk_buff *skb, struct genl_info *info) }/** -* batadv_get_softif_from_info() - Retrieve soft interface from genl attributes +* batadv_netlink_get_softif_from_info() - Retrieve soft interface from ifindex
net/batman-adv/netlink.c static int batadv_netlink_set_vlan(struct sk_buff *skb, struct genl_info *info) · line 1148
Quoted 10 lines
net/batman-adv/netlink.c +2
-2* @net: the applicable net namespace -* @info: receiver information +* @ifindex: index of the soft interface * * Return: Pointer to soft interface (with increased refcnt) on success, error * pointer on error */ static struct net_device * -batadv_get_softif_from_info (struct net *net,struct genl_info *info) +batadv_netlink_get_softif_from_ifindex (struct net *net,int ifindex)
I think you wanted to document batadv_netlink_get_softif_from_ifindex here and not batadv_netlink_get_softif_from_info
[...]
Quoted 5 lines
net/batman-adv/netlink.c +0
-1@@ -1184,28 +1165,61 @@ batadv_get_softif_from_info(struct net *net, struct genl_info *info) }/** -* batadv_get_hardif_from_info() - Retrieve hardif from genl attributes
net/batman-adv/netlink.c batadv_get_softif_from_info(struct net *net, struct genl_info *info) · line 1176
Quoted 10 lines
net/batman-adv/netlink.c +6
-1-* @bat_priv: the bat priv with all the soft interface information +* batadv_get_softif_from_info() - Retrieve soft interface from genl attributes * @net: the applicable net namespace * @info: receiver information * +* Return: Pointer to soft interface (with increased refcnt) on success, error +* pointer on error +*/ +static struct net_device * +batadv_netlink_get_softif_from_info (struct net *net,struct genl_info *info)
I think you wanted to document batadv_netlink_get_softif_from_info here and not batadv_get_softif_from_info
[...]
Quoted 5 lines
net/batman-adv/netlink.c +5
-0+/** +* batadv_netlink_get_hardif_from_info() - Retrieve hard interface from ifindex +* @bat_priv: the bat priv with all the soft interface information +* @net: the applicable net namespace +* @ifindex: index of the hard interface
net/batman-adv/netlink.c batadv_get_softif_from_info(struct net *net, struct genl_info *info) · line 1218
Quoted 10 lines
net/batman-adv/netlink.c +3
-2+* * Return: Pointer to hard interface (with increased refcnt) on success, error * pointer on error */ static struct batadv_hard_iface * -batadv_get_hardif_from_info (struct batadv_priv *bat_priv,struct net *net, -struct genl_info *info) +batadv_netlink_get_hardif_from_ifindex (struct batadv_priv *bat_priv, +struct net *net,int ifindex) {
I think you wanted to document batadv_netlink_get_hardif_from_ifindex here and not batadv_netlink_get_hardif_from_info
[...]
Quoted 6 lines
net/batman-adv/netlink.c +2
-0@@ -1229,6 +1243,51 @@ batadv_get_hardif_from_info(struct batadv_priv *bat_priv, struct net *net,return ERR_PTR (-EINVAL ); } +/** +* batadv_get_hardif_from_info() - Retrieve hardif from genl attributes
net/batman-adv/netlink.c batadv_get_hardif_from_info(struct batadv_priv *bat_priv, struct net *net, · line 1257
Quoted 10 lines
net/batman-adv/netlink.c +10
-0+* @bat_priv: the bat priv with all the soft interface information +* @net: the applicable net namespace +* @info: receiver information +* +* Return: Pointer to hard interface (with increased refcnt) on success, error +* pointer on error +*/ +static struct batadv_hard_iface * +batadv_netlink_get_hardif_from_info (struct batadv_priv *bat_priv, +struct net *net,struct genl_info *info)
I think you wanted to document batadv_netlink_get_hardif_from_info here and not batadv_get_hardif_from_info
[...]
net/batman-adv/originator.c batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node, · line 759
Quoted 13 lines
net/batman-adv/originator.c +1
-3@@ -755,24 +755,15 @@ batadv_neigh_node_get_or_create(struct batadv_orig_node *orig_node,*/ int batadv_hardif_neigh_dump (struct sk_buff *msg,struct netlink_callback *cb) { -struct net *net =sock_net (cb->skb->sk);struct net_device *soft_iface; -struct net_device *hard_iface =NULL ; -struct batadv_hard_iface *hardif =BATADV_IF_DEFAULT ; +struct batadv_hard_iface *hard_iface;
hard_iface is no longer initialized but you will use it after a goto (see below).
Quoted 21 lines
net/batman-adv/originator.c +3
-10struct batadv_priv *bat_priv;struct batadv_hard_iface *primary_if =NULL ;int ret; -int ifindex, hard_ifindex; - ifindex =batadv_netlink_get_ifindex (cb->nlh,BATADV_ATTR_MESH_IFINDEX ); -if (!ifindex) -return -EINVAL ; - - soft_iface =dev_get_by_index (net, ifindex); -if (!soft_iface || !batadv_softif_is_valid (soft_iface)) { - ret = -ENODEV ; - goto out; - } + soft_iface =batadv_netlink_get_softif (cb); +if (IS_ERR (soft_iface)) +return PTR_ERR (soft_iface); bat_priv =netdev_priv (soft_iface);
net/batman-adv/originator.c int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) · line 774
Quoted 2 lines
net/batman-adv/originator.c +0
-0@@ -782,22 +773,14 @@ int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) goto out; }
The goto here seems to be rather problematic... see below for more details
Quoted 30 lines
net/batman-adv/originator.c +5
-14- hard_ifindex =batadv_netlink_get_ifindex (cb->nlh, -BATADV_ATTR_HARD_IFINDEX ); -if (hard_ifindex) { - hard_iface =dev_get_by_index (net, hard_ifindex); -if (hard_iface) - hardif =batadv_hardif_get_by_netdev (hard_iface); - -if (!hardif) { - ret = -ENODEV ; + hard_iface =batadv_netlink_get_hardif (bat_priv, cb); +if (IS_ERR (hard_iface)) { +if (PTR_ERR (hard_iface) != -ENONET ) { + ret =PTR_ERR (hard_iface); goto out; } -if (hardif->soft_iface != soft_iface) { - ret = -ENOENT ; - goto out; - } + hard_iface =BATADV_IF_DEFAULT ; }if (!bat_priv->algo_ops->neigh.dump) {@@ -805,13 +788,12 @@ int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) goto out; } - bat_priv->algo_ops->neigh.dump (msg, cb, bat_priv, hardif);
net/batman-adv/originator.c int batadv_hardif_neigh_dump(struct sk_buff *msg, struct netlink_callback *cb) · line 798
Quoted 10 lines
net/batman-adv/originator.c +2
-2+ bat_priv->algo_ops->neigh.dump (msg, cb, bat_priv, hard_iface); ret = msg->len; out: -batadv_hardif_put (hardif); -dev_put (hard_iface); +batadv_hardif_put (hard_iface);batadv_hardif_put (primary_if);dev_put (soft_iface);
You will now give batadv_hardif_put an unitialized value for hard_iface when following goto is used:
[...]
primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if || primary_if->if_status != BATADV_IF_ACTIVE) {
ret = -ENOENT;
goto out;
}
hard_iface = batadv_netlink_get_hardif(bat_priv, cb);[...]
This is also the reason why a non-descriptive, single return goto labels should be avoided [1].
Kind regards,
Sven
[1] https://www.kernel.org/doc/html/v6.12/process/coding-style.html#centralized-exiting-of-functions
PATCH v7 2/3 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 | 316 +++++++++++++++++++------ net/batman-adv/distributed-arp-table.h | 13 +- net/batman-adv/netlink.c | 5 + net/batman-adv/routing.c | 8 +- net/batman-adv/types.h | 7 +- 6 files changed, 269 insertions(+), 85 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 +238 -78
557 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
@@ -1502,6 +1502,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 +5 -3
@@ -943,10 +943,10 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,struct batadv_unicast_4addr_packet *unicast_4addr_packet;u8 *orig_addr, *orig_addr_gw;struct batadv_orig_node *orig_node =NULL , *orig_node_gw =NULL ; +bool is4addr, is_gw, is_dht_put = false;int check, hdr_size =sizeof (*unicast_packet);enum batadv_subtype subtype;int ret =NET_RX_DROP ; -bool is4addr, is_gw; unicast_packet = (struct batadv_unicast_packet *)skb->data; is4addr = unicast_packet->packet_type ==BATADV_UNICAST_4ADDR ;
@@ -1005,6 +1005,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; } }
@@ -1012,7 +1014,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);
@@ -1249,7 +1251,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
@@ -1231,8 +1231,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.45.2
PATCH v7 3/3 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
@@ -133,15 +133,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 ); }/**
@@ -202,8 +214,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
@@ -38,7 +38,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.45.2