Commit 44ce3511 authored by Paolo Abeni's avatar Paolo Abeni
Browse files

Merge tag 'batadv-net-pullrequest-20250207' of git://git.open-mesh.org/linux-merge

Simon Wunderlich says:

====================
Here are some batman-adv bugfixes:

 - Fix panic during interface removal in BATMAN V, by Andy Strohman

 - Cleanup BATMAN V/ELP metric handling, by Sven Eckelmann (2 patches)

 - Fix incorrect offset in batadv_tt_tvlv_ogm_handler_v1(),
   by Remi Pommarel

* tag 'batadv-net-pullrequest-20250207' of git://git.open-mesh.org/linux-merge:
  batman-adv: Fix incorrect offset in batadv_tt_tvlv_ogm_handler_v1()
  batman-adv: Drop unmanaged ELP metric worker
  batman-adv: Ignore neighbor throughput metrics in error case
  batman-adv: fix panic during interface removal
====================

Link: https://patch.msgid.link/20250207095823.26043-1-sw@simonwunderlich.de


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parents 2196ceea f4c9c2cc
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -113,8 +113,6 @@ static void
batadv_v_hardif_neigh_init(struct batadv_hardif_neigh_node *hardif_neigh)
{
	ewma_throughput_init(&hardif_neigh->bat_v.throughput);
	INIT_WORK(&hardif_neigh->bat_v.metric_work,
		  batadv_v_elp_throughput_metric_update);
}

/**
+86 −36
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <linux/if_ether.h>
#include <linux/jiffies.h>
#include <linux/kref.h>
#include <linux/list.h>
#include <linux/minmax.h>
#include <linux/netdevice.h>
#include <linux/nl80211.h>
@@ -26,6 +27,7 @@
#include <linux/rcupdate.h>
#include <linux/rtnetlink.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/stddef.h>
#include <linux/string.h>
#include <linux/types.h>
@@ -41,6 +43,18 @@
#include "routing.h"
#include "send.h"

/**
 * struct batadv_v_metric_queue_entry - list of hardif neighbors which require
 *  and metric update
 */
struct batadv_v_metric_queue_entry {
	/** @hardif_neigh: hardif neighbor scheduled for metric update */
	struct batadv_hardif_neigh_node *hardif_neigh;

	/** @list: list node for metric_queue */
	struct list_head list;
};

/**
 * batadv_v_elp_start_timer() - restart timer for ELP periodic work
 * @hard_iface: the interface for which the timer has to be reset
@@ -59,25 +73,36 @@ static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
/**
 * batadv_v_elp_get_throughput() - get the throughput towards a neighbour
 * @neigh: the neighbour for which the throughput has to be obtained
 * @pthroughput: calculated throughput towards the given neighbour in multiples
 *  of 100kpbs (a value of '1' equals 0.1Mbps, '10' equals 1Mbps, etc).
 *
 * Return: The throughput towards the given neighbour in multiples of 100kpbs
 *         (a value of '1' equals 0.1Mbps, '10' equals 1Mbps, etc).
 * Return: true when value behind @pthroughput was set
 */
static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
static bool batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh,
					u32 *pthroughput)
{
	struct batadv_hard_iface *hard_iface = neigh->if_incoming;
	struct net_device *soft_iface = hard_iface->soft_iface;
	struct ethtool_link_ksettings link_settings;
	struct net_device *real_netdev;
	struct station_info sinfo;
	u32 throughput;
	int ret;

	/* don't query throughput when no longer associated with any
	 * batman-adv interface
	 */
	if (!soft_iface)
		return false;

	/* if the user specified a customised value for this interface, then
	 * return it directly
	 */
	throughput =  atomic_read(&hard_iface->bat_v.throughput_override);
	if (throughput != 0)
		return throughput;
	if (throughput != 0) {
		*pthroughput = throughput;
		return true;
	}

	/* if this is a wireless device, then ask its throughput through
	 * cfg80211 API
@@ -104,27 +129,39 @@ static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
			 * possible to delete this neighbor. For now set
			 * the throughput metric to 0.
			 */
			return 0;
			*pthroughput = 0;
			return true;
		}
		if (ret)
			goto default_throughput;

		if (sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT))
			return sinfo.expected_throughput / 100;
		if (sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT)) {
			*pthroughput = sinfo.expected_throughput / 100;
			return true;
		}

		/* try to estimate the expected throughput based on reported tx
		 * rates
		 */
		if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE))
			return cfg80211_calculate_bitrate(&sinfo.txrate) / 3;
		if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
			*pthroughput = cfg80211_calculate_bitrate(&sinfo.txrate) / 3;
			return true;
		}

		goto default_throughput;
	}

	/* only use rtnl_trylock because the elp worker will be cancelled while
	 * the rntl_lock is held. the cancel_delayed_work_sync() would otherwise
	 * wait forever when the elp work_item was started and it is then also
	 * trying to rtnl_lock
	 */
	if (!rtnl_trylock())
		return false;

	/* if not a wifi interface, check if this device provides data via
	 * ethtool (e.g. an Ethernet adapter)
	 */
	rtnl_lock();
	ret = __ethtool_get_link_ksettings(hard_iface->net_dev, &link_settings);
	rtnl_unlock();
	if (ret == 0) {
@@ -135,13 +172,15 @@ static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
			hard_iface->bat_v.flags &= ~BATADV_FULL_DUPLEX;

		throughput = link_settings.base.speed;
		if (throughput && throughput != SPEED_UNKNOWN)
			return throughput * 10;
		if (throughput && throughput != SPEED_UNKNOWN) {
			*pthroughput = throughput * 10;
			return true;
		}
	}

default_throughput:
	if (!(hard_iface->bat_v.flags & BATADV_WARNING_DEFAULT)) {
		batadv_info(hard_iface->soft_iface,
		batadv_info(soft_iface,
			    "WiFi driver or ethtool info does not provide information about link speeds on interface %s, therefore defaulting to hardcoded throughput values of %u.%1u Mbps. Consider overriding the throughput manually or checking your driver.\n",
			    hard_iface->net_dev->name,
			    BATADV_THROUGHPUT_DEFAULT_VALUE / 10,
@@ -150,31 +189,26 @@ static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
	}

	/* if none of the above cases apply, return the base_throughput */
	return BATADV_THROUGHPUT_DEFAULT_VALUE;
	*pthroughput = BATADV_THROUGHPUT_DEFAULT_VALUE;
	return true;
}

/**
 * batadv_v_elp_throughput_metric_update() - worker updating the throughput
 *  metric of a single hop neighbour
 * @work: the work queue item
 * @neigh: the neighbour to probe
 */
void batadv_v_elp_throughput_metric_update(struct work_struct *work)
static void
batadv_v_elp_throughput_metric_update(struct batadv_hardif_neigh_node *neigh)
{
	struct batadv_hardif_neigh_node_bat_v *neigh_bat_v;
	struct batadv_hardif_neigh_node *neigh;

	neigh_bat_v = container_of(work, struct batadv_hardif_neigh_node_bat_v,
				   metric_work);
	neigh = container_of(neigh_bat_v, struct batadv_hardif_neigh_node,
			     bat_v);
	u32 throughput;
	bool valid;

	ewma_throughput_add(&neigh->bat_v.throughput,
			    batadv_v_elp_get_throughput(neigh));
	valid = batadv_v_elp_get_throughput(neigh, &throughput);
	if (!valid)
		return;

	/* decrement refcounter to balance increment performed before scheduling
	 * this task
	 */
	batadv_hardif_neigh_put(neigh);
	ewma_throughput_add(&neigh->bat_v.throughput, throughput);
}

/**
@@ -248,14 +282,16 @@ batadv_v_elp_wifi_neigh_probe(struct batadv_hardif_neigh_node *neigh)
 */
static void batadv_v_elp_periodic_work(struct work_struct *work)
{
	struct batadv_v_metric_queue_entry *metric_entry;
	struct batadv_v_metric_queue_entry *metric_safe;
	struct batadv_hardif_neigh_node *hardif_neigh;
	struct batadv_hard_iface *hard_iface;
	struct batadv_hard_iface_bat_v *bat_v;
	struct batadv_elp_packet *elp_packet;
	struct list_head metric_queue;
	struct batadv_priv *bat_priv;
	struct sk_buff *skb;
	u32 elp_interval;
	bool ret;

	bat_v = container_of(work, struct batadv_hard_iface_bat_v, elp_wq.work);
	hard_iface = container_of(bat_v, struct batadv_hard_iface, bat_v);
@@ -291,6 +327,8 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)

	atomic_inc(&hard_iface->bat_v.elp_seqno);

	INIT_LIST_HEAD(&metric_queue);

	/* The throughput metric is updated on each sent packet. This way, if a
	 * node is dead and no longer sends packets, batman-adv is still able to
	 * react timely to its death.
@@ -315,16 +353,28 @@ static void batadv_v_elp_periodic_work(struct work_struct *work)

		/* Reading the estimated throughput from cfg80211 is a task that
		 * may sleep and that is not allowed in an rcu protected
		 * context. Therefore schedule a task for that.
		 * context. Therefore add it to metric_queue and process it
		 * outside rcu protected context.
		 */
		ret = queue_work(batadv_event_workqueue,
				 &hardif_neigh->bat_v.metric_work);

		if (!ret)
		metric_entry = kzalloc(sizeof(*metric_entry), GFP_ATOMIC);
		if (!metric_entry) {
			batadv_hardif_neigh_put(hardif_neigh);
			continue;
		}

		metric_entry->hardif_neigh = hardif_neigh;
		list_add(&metric_entry->list, &metric_queue);
	}
	rcu_read_unlock();

	list_for_each_entry_safe(metric_entry, metric_safe, &metric_queue, list) {
		batadv_v_elp_throughput_metric_update(metric_entry->hardif_neigh);

		batadv_hardif_neigh_put(metric_entry->hardif_neigh);
		list_del(&metric_entry->list);
		kfree(metric_entry);
	}

restart_timer:
	batadv_v_elp_start_timer(hard_iface);
out:
+0 −2
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@
#include "main.h"

#include <linux/skbuff.h>
#include <linux/workqueue.h>

int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface);
void batadv_v_elp_iface_disable(struct batadv_hard_iface *hard_iface);
@@ -19,6 +18,5 @@ void batadv_v_elp_iface_activate(struct batadv_hard_iface *primary_iface,
void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface);
int batadv_v_elp_packet_recv(struct sk_buff *skb,
			     struct batadv_hard_iface *if_incoming);
void batadv_v_elp_throughput_metric_update(struct work_struct *work);

#endif /* _NET_BATMAN_ADV_BAT_V_ELP_H_ */
+5 −7
Original line number Diff line number Diff line
@@ -3937,23 +3937,21 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
	struct batadv_tvlv_tt_change *tt_change;
	struct batadv_tvlv_tt_data *tt_data;
	u16 num_entries, num_vlan;
	size_t flex_size;
	size_t tt_data_sz;

	if (tvlv_value_len < sizeof(*tt_data))
		return;

	tt_data = tvlv_value;
	tvlv_value_len -= sizeof(*tt_data);

	num_vlan = ntohs(tt_data->num_vlan);

	flex_size = flex_array_size(tt_data, vlan_data, num_vlan);
	if (tvlv_value_len < flex_size)
	tt_data_sz = struct_size(tt_data, vlan_data, num_vlan);
	if (tvlv_value_len < tt_data_sz)
		return;

	tt_change = (struct batadv_tvlv_tt_change *)((void *)tt_data
						     + flex_size);
	tvlv_value_len -= flex_size;
						     + tt_data_sz);
	tvlv_value_len -= tt_data_sz;

	num_entries = batadv_tt_entries(tvlv_value_len);

+0 −3
Original line number Diff line number Diff line
@@ -596,9 +596,6 @@ struct batadv_hardif_neigh_node_bat_v {
	 *  neighbor
	 */
	unsigned long last_unicast_tx;

	/** @metric_work: work queue callback item for metric update */
	struct work_struct metric_work;
};

/**