hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/net/batman-adv/bat_v_elp.c
....@@ -1,19 +1,7 @@
11 // SPDX-License-Identifier: GPL-2.0
2
-/* Copyright (C) 2011-2018 B.A.T.M.A.N. contributors:
2
+/* Copyright (C) 2011-2020 B.A.T.M.A.N. contributors:
33 *
44 * Linus Lüssing, Marek Lindner
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of version 2 of the GNU General Public
8
- * License as published by the Free Software Foundation.
9
- *
10
- * This program is distributed in the hope that it will be useful, but
11
- * WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, see <http://www.gnu.org/licenses/>.
175 */
186
197 #include "bat_v_elp.h"
....@@ -32,6 +20,7 @@
3220 #include <linux/kref.h>
3321 #include <linux/netdevice.h>
3422 #include <linux/nl80211.h>
23
+#include <linux/prandom.h>
3524 #include <linux/random.h>
3625 #include <linux/rculist.h>
3726 #include <linux/rcupdate.h>
....@@ -61,7 +50,7 @@
6150 unsigned int msecs;
6251
6352 msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER;
64
- msecs += prandom_u32() % (2 * BATADV_JITTER);
53
+ msecs += prandom_u32_max(2 * BATADV_JITTER);
6554
6655 queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq,
6756 msecs_to_jiffies(msecs));
....@@ -72,7 +61,7 @@
7261 * @neigh: the neighbour for which the throughput has to be obtained
7362 *
7463 * Return: The throughput towards the given neighbour in multiples of 100kpbs
75
- * (a value of '1' equals to 0.1Mbps, '10' equals 1Mbps, etc).
64
+ * (a value of '1' equals 0.1Mbps, '10' equals 1Mbps, etc).
7665 */
7766 static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
7867 {
....@@ -119,10 +108,17 @@
119108 }
120109 if (ret)
121110 goto default_throughput;
122
- if (!(sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT)))
123
- goto default_throughput;
124111
125
- return sinfo.expected_throughput / 100;
112
+ if (sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT))
113
+ return sinfo.expected_throughput / 100;
114
+
115
+ /* try to estimate the expected throughput based on reported tx
116
+ * rates
117
+ */
118
+ if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE))
119
+ return cfg80211_calculate_bitrate(&sinfo.txrate) / 3;
120
+
121
+ goto default_throughput;
126122 }
127123
128124 /* if not a wifi interface, check if this device provides data via
....@@ -188,8 +184,8 @@
188184 *
189185 * Sends a predefined number of unicast wifi packets to a given neighbour in
190186 * order to trigger the throughput estimation on this link by the RC algorithm.
191
- * Packets are sent only if there there is not enough payload unicast traffic
192
- * towards this neighbour..
187
+ * Packets are sent only if there is not enough payload unicast traffic towards
188
+ * this neighbour..
193189 *
194190 * Return: True on success and false in case of error during skb preparation.
195191 */
....@@ -249,7 +245,7 @@
249245 * batadv_v_elp_periodic_work() - ELP periodic task per interface
250246 * @work: work queue item
251247 *
252
- * Emits broadcast ELP message in regular intervals.
248
+ * Emits broadcast ELP messages in regular intervals.
253249 */
254250 static void batadv_v_elp_periodic_work(struct work_struct *work)
255251 {
....@@ -504,7 +500,7 @@
504500 * @skb: the received packet
505501 * @if_incoming: the interface this packet was received through
506502 *
507
- * Return: NET_RX_SUCCESS and consumes the skb if the packet was peoperly
503
+ * Return: NET_RX_SUCCESS and consumes the skb if the packet was properly
508504 * processed or NET_RX_DROP in case of failure.
509505 */
510506 int batadv_v_elp_packet_recv(struct sk_buff *skb,