Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /* Copyright (C) 2011-2020  B.A.T.M.A.N. contributors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Linus Lüssing, Marek Lindner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "bat_v_elp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/byteorder/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/nl80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/prandom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <net/cfg80211.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <uapi/linux/batadv_packet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "bat_algo.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "bat_v_ogm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include "hard-interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include "originator.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include "routing.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include "send.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * batadv_v_elp_start_timer() - restart timer for ELP periodic work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * @hard_iface: the interface for which the timer has to be reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static void batadv_v_elp_start_timer(struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	unsigned int msecs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	msecs += prandom_u32_max(2 * BATADV_JITTER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 			   msecs_to_jiffies(msecs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * batadv_v_elp_get_throughput() - get the throughput towards a neighbour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * @neigh: the neighbour for which the throughput has to be obtained
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * Return: The throughput towards the given neighbour in multiples of 100kpbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  *         (a value of '1' equals 0.1Mbps, '10' equals 1Mbps, etc).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	struct batadv_hard_iface *hard_iface = neigh->if_incoming;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct ethtool_link_ksettings link_settings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct net_device *real_netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	struct station_info sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	u32 throughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/* if the user specified a customised value for this interface, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 * return it directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	throughput =  atomic_read(&hard_iface->bat_v.throughput_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (throughput != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return throughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	/* if this is a wireless device, then ask its throughput through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 * cfg80211 API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	if (batadv_is_wifi_hardif(hard_iface)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (!batadv_is_cfg80211_hardif(hard_iface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			/* unsupported WiFi driver version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			goto default_throughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		real_netdev = batadv_get_real_netdev(hard_iface->net_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (!real_netdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			goto default_throughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		ret = cfg80211_get_station(real_netdev, neigh->addr, &sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			/* free the TID stats immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			cfg80211_sinfo_release_content(&sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		dev_put(real_netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		if (ret == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			/* Node is not associated anymore! It would be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			 * possible to delete this neighbor. For now set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			 * the throughput metric to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 			goto default_throughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		if (sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			return sinfo.expected_throughput / 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		/* try to estimate the expected throughput based on reported tx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		 * rates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			return cfg80211_calculate_bitrate(&sinfo.txrate) / 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		goto default_throughput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	/* if not a wifi interface, check if this device provides data via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * ethtool (e.g. an Ethernet adapter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	memset(&link_settings, 0, sizeof(link_settings));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	ret = __ethtool_get_link_ksettings(hard_iface->net_dev, &link_settings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		/* link characteristics might change over time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		if (link_settings.base.duplex == DUPLEX_FULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 			hard_iface->bat_v.flags |= BATADV_FULL_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			hard_iface->bat_v.flags &= ~BATADV_FULL_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		throughput = link_settings.base.speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		if (throughput && throughput != SPEED_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			return throughput * 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) default_throughput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (!(hard_iface->bat_v.flags & BATADV_WARNING_DEFAULT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		batadv_info(hard_iface->soft_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			    "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",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			    hard_iface->net_dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			    BATADV_THROUGHPUT_DEFAULT_VALUE / 10,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			    BATADV_THROUGHPUT_DEFAULT_VALUE % 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		hard_iface->bat_v.flags |= BATADV_WARNING_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/* if none of the above cases apply, return the base_throughput */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return BATADV_THROUGHPUT_DEFAULT_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * batadv_v_elp_throughput_metric_update() - worker updating the throughput
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  *  metric of a single hop neighbour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * @work: the work queue item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) void batadv_v_elp_throughput_metric_update(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	struct batadv_hardif_neigh_node_bat_v *neigh_bat_v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct batadv_hardif_neigh_node *neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	neigh_bat_v = container_of(work, struct batadv_hardif_neigh_node_bat_v,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				   metric_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	neigh = container_of(neigh_bat_v, struct batadv_hardif_neigh_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			     bat_v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	ewma_throughput_add(&neigh->bat_v.throughput,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			    batadv_v_elp_get_throughput(neigh));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* decrement refcounter to balance increment performed before scheduling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	 * this task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	batadv_hardif_neigh_put(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * batadv_v_elp_wifi_neigh_probe() - send link probing packets to a neighbour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * @neigh: the neighbour to probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * Sends a predefined number of unicast wifi packets to a given neighbour in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  * order to trigger the throughput estimation on this link by the RC algorithm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * Packets are sent only if there is not enough payload unicast traffic towards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  * this neighbour..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)  * Return: True on success and false in case of error during skb preparation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) batadv_v_elp_wifi_neigh_probe(struct batadv_hardif_neigh_node *neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	struct batadv_hard_iface *hard_iface = neigh->if_incoming;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	unsigned long last_tx_diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	int probe_len, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	int elp_skb_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	/* this probing routine is for Wifi neighbours only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (!batadv_is_wifi_hardif(hard_iface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	/* probe the neighbor only if no unicast packets have been sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	 * to it in the last 100 milliseconds: this is the rate control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	 * algorithm sampling interval (minstrel). In this way, if not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	 * enough traffic has been sent to the neighbor, batman-adv can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	 * generate 2 probe packets and push the RC algorithm to perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	 * the sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	last_tx_diff = jiffies_to_msecs(jiffies - neigh->bat_v.last_unicast_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (last_tx_diff <= BATADV_ELP_PROBE_MAX_TX_DIFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	probe_len = max_t(int, sizeof(struct batadv_elp_packet),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			  BATADV_ELP_MIN_PROBE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	for (i = 0; i < BATADV_ELP_PROBES_PER_NODE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		elp_skb_len = hard_iface->bat_v.elp_skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		skb = skb_copy_expand(hard_iface->bat_v.elp_skb, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 				      probe_len - elp_skb_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 				      GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		/* Tell the skb to get as big as the allocated space (we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		 * the packet to be exactly of that size to make the link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		 * throughput estimation effective.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		skb_put_zero(skb, probe_len - hard_iface->bat_v.elp_skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			   "Sending unicast (probe) ELP packet on interface %s to %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			   hard_iface->net_dev->name, neigh->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		batadv_send_skb_packet(skb, hard_iface, neigh->addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * batadv_v_elp_periodic_work() - ELP periodic task per interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  * @work: work queue item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * Emits broadcast ELP messages in regular intervals.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static void batadv_v_elp_periodic_work(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct batadv_hardif_neigh_node *hardif_neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct batadv_hard_iface_bat_v *bat_v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	struct batadv_elp_packet *elp_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct batadv_priv *bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	u32 elp_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	bat_v = container_of(work, struct batadv_hard_iface_bat_v, elp_wq.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	hard_iface = container_of(bat_v, struct batadv_hard_iface, bat_v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	bat_priv = netdev_priv(hard_iface->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_DEACTIVATING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	/* we are in the process of shutting this interface down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (hard_iface->if_status == BATADV_IF_NOT_IN_USE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	    hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	/* the interface was enabled but may not be ready yet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	if (hard_iface->if_status != BATADV_IF_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		goto restart_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	skb = skb_copy(hard_iface->bat_v.elp_skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		goto restart_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	elp_packet = (struct batadv_elp_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	elp_packet->seqno = htonl(atomic_read(&hard_iface->bat_v.elp_seqno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	elp_interval = atomic_read(&hard_iface->bat_v.elp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	elp_packet->elp_interval = htonl(elp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		   "Sending broadcast ELP packet on interface %s, seqno %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		   hard_iface->net_dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		   atomic_read(&hard_iface->bat_v.elp_seqno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	batadv_send_broadcast_skb(skb, hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	atomic_inc(&hard_iface->bat_v.elp_seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	/* The throughput metric is updated on each sent packet. This way, if a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 * node is dead and no longer sends packets, batman-adv is still able to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 * react timely to its death.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	 * The throughput metric is updated by following these steps:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	 * 1) if the hard_iface is wifi => send a number of unicast ELPs for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	 *    probing/sampling to each neighbor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	 * 2) update the throughput metric value of each neighbor (note that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	 *    value retrieved in this step might be 100ms old because the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	 *    probing packets at point 1) could still be in the HW queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	hlist_for_each_entry_rcu(hardif_neigh, &hard_iface->neigh_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		if (!batadv_v_elp_wifi_neigh_probe(hardif_neigh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 			/* if something goes wrong while probing, better to stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 			 * sending packets immediately and reschedule the task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		if (!kref_get_unless_zero(&hardif_neigh->refcount))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		/* Reading the estimated throughput from cfg80211 is a task that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		 * may sleep and that is not allowed in an rcu protected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		 * context. Therefore schedule a task for that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		ret = queue_work(batadv_event_workqueue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 				 &hardif_neigh->bat_v.metric_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			batadv_hardif_neigh_put(hardif_neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) restart_timer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	batadv_v_elp_start_timer(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)  * batadv_v_elp_iface_enable() - setup the ELP interface private resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)  * @hard_iface: interface for which the data has to be prepared
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)  * Return: 0 on success or a -ENOMEM in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) int batadv_v_elp_iface_enable(struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	static const size_t tvlv_padding = sizeof(__be32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	struct batadv_elp_packet *elp_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	unsigned char *elp_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	u32 random_seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	int res = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	size = ETH_HLEN + NET_IP_ALIGN + BATADV_ELP_HLEN + tvlv_padding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	hard_iface->bat_v.elp_skb = dev_alloc_skb(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	if (!hard_iface->bat_v.elp_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	skb_reserve(hard_iface->bat_v.elp_skb, ETH_HLEN + NET_IP_ALIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	elp_buff = skb_put_zero(hard_iface->bat_v.elp_skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 				BATADV_ELP_HLEN + tvlv_padding);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	elp_packet = (struct batadv_elp_packet *)elp_buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	elp_packet->packet_type = BATADV_ELP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	elp_packet->version = BATADV_COMPAT_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	/* randomize initial seqno to avoid collision */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	get_random_bytes(&random_seqno, sizeof(random_seqno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	atomic_set(&hard_iface->bat_v.elp_seqno, random_seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	/* assume full-duplex by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	hard_iface->bat_v.flags |= BATADV_FULL_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	/* warn the user (again) if there is no throughput data is available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	hard_iface->bat_v.flags &= ~BATADV_WARNING_DEFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	if (batadv_is_wifi_hardif(hard_iface))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		hard_iface->bat_v.flags &= ~BATADV_FULL_DUPLEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	INIT_DELAYED_WORK(&hard_iface->bat_v.elp_wq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			  batadv_v_elp_periodic_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	batadv_v_elp_start_timer(hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)  * batadv_v_elp_iface_disable() - release ELP interface private resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)  * @hard_iface: interface for which the resources have to be released
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) void batadv_v_elp_iface_disable(struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	cancel_delayed_work_sync(&hard_iface->bat_v.elp_wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	dev_kfree_skb(hard_iface->bat_v.elp_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	hard_iface->bat_v.elp_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)  * batadv_v_elp_iface_activate() - update the ELP buffer belonging to the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)  *  hard-interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * @primary_iface: the new primary interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  * @hard_iface: interface holding the to-be-updated buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) void batadv_v_elp_iface_activate(struct batadv_hard_iface *primary_iface,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 				 struct batadv_hard_iface *hard_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct batadv_elp_packet *elp_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	if (!hard_iface->bat_v.elp_skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	skb = hard_iface->bat_v.elp_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	elp_packet = (struct batadv_elp_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	ether_addr_copy(elp_packet->orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 			primary_iface->net_dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)  * batadv_v_elp_primary_iface_set() - change internal data to reflect the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)  *  primary interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)  * @primary_iface: the new primary interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) void batadv_v_elp_primary_iface_set(struct batadv_hard_iface *primary_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	struct batadv_hard_iface *hard_iface;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	/* update orig field of every elp iface belonging to this mesh */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		if (primary_iface->soft_iface != hard_iface->soft_iface)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		batadv_v_elp_iface_activate(primary_iface, hard_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)  * batadv_v_elp_neigh_update() - update an ELP neighbour node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)  * @neigh_addr: the neighbour interface address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)  * @if_incoming: the interface the packet was received through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)  * @elp_packet: the received ELP packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)  * Updates the ELP neighbour node state with the data received within the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)  * ELP packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static void batadv_v_elp_neigh_update(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 				      u8 *neigh_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 				      struct batadv_hard_iface *if_incoming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 				      struct batadv_elp_packet *elp_packet)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	struct batadv_neigh_node *neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	struct batadv_orig_node *orig_neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	struct batadv_hardif_neigh_node *hardif_neigh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	s32 seqno_diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	s32 elp_latest_seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	orig_neigh = batadv_v_ogm_orig_get(bat_priv, elp_packet->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	if (!orig_neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	neigh = batadv_neigh_node_get_or_create(orig_neigh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 						if_incoming, neigh_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	if (!neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		goto orig_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	hardif_neigh = batadv_hardif_neigh_get(if_incoming, neigh_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	if (!hardif_neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		goto neigh_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	elp_latest_seqno = hardif_neigh->bat_v.elp_latest_seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	seqno_diff = ntohl(elp_packet->seqno) - elp_latest_seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	/* known or older sequence numbers are ignored. However always adopt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	 * if the router seems to have been restarted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	if (seqno_diff < 1 && seqno_diff > -BATADV_ELP_MAX_AGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		goto hardif_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	neigh->last_seen = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	hardif_neigh->last_seen = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	hardif_neigh->bat_v.elp_latest_seqno = ntohl(elp_packet->seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	hardif_neigh->bat_v.elp_interval = ntohl(elp_packet->elp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) hardif_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	if (hardif_neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		batadv_hardif_neigh_put(hardif_neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) neigh_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	if (neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		batadv_neigh_node_put(neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) orig_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (orig_neigh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		batadv_orig_node_put(orig_neigh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)  * batadv_v_elp_packet_recv() - main ELP packet handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  * @skb: the received packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  * @if_incoming: the interface this packet was received through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  * Return: NET_RX_SUCCESS and consumes the skb if the packet was properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)  * processed or NET_RX_DROP in case of failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) int batadv_v_elp_packet_recv(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			     struct batadv_hard_iface *if_incoming)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct batadv_elp_packet *elp_packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	struct batadv_hard_iface *primary_if;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	bool res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	int ret = NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	res = batadv_check_management_packet(skb, if_incoming, BATADV_ELP_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		goto free_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		goto free_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	/* did we receive a B.A.T.M.A.N. V ELP packet on an interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	 * that does not have B.A.T.M.A.N. V ELP enabled ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	if (strcmp(bat_priv->algo_ops->name, "BATMAN_V") != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 		goto free_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	elp_packet = (struct batadv_elp_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 		   "Received ELP packet from %pM seqno %u ORIG: %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 		   ethhdr->h_source, ntohl(elp_packet->seqno),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		   elp_packet->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	if (!primary_if)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 		goto free_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	batadv_v_elp_neigh_update(bat_priv, ethhdr->h_source, if_incoming,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 				  elp_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	ret = NET_RX_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) free_skb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	if (ret == NET_RX_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 		consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }