batman-adv: Merge bugfixes from 2017.4
[feed/routing.git] / batman-adv / patches / 0018-batman-adv-Accept-only-filled-wifi-station-info.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Fri, 9 Jun 2017 17:06:51 +0200
3 Subject: [PATCH] batman-adv: Accept only filled wifi station info
4
5 The wifi driver can decide to not provide parts of the station info. For
6 example, the expected throughput of the station can be omitted when the
7 used rate control doesn't provide this kind of information.
8
9 The B.A.T.M.A.N. V implementation must therefore check the filled bitfield
10 before it tries to access the expected_throughput of the returned
11 station_info.
12
13 Reported-by: Alvaro Antelo <alvaro.antelo@gmail.com>
14 Fixes: 5c3245172c01 ("batman-adv: ELP - compute the metric based on the estimated throughput")
15 Signed-off-by: Sven Eckelmann <sven@narfation.org>
16 Reviewed-by: Marek Lindner <mareklindner@neomailbox.ch>
17 Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
18
19 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/1e26904b364ceffe9ca7d6da7412e70fb2a04178
20 ---
21 compat-include/linux/nl80211.h | 14 ++++++++++++++
22 compat-include/uapi/linux/nl80211.h | 16 ++++++++++++++++
23 net/batman-adv/bat_v_elp.c | 4 ++++
24 3 files changed, 34 insertions(+)
25 create mode 100644 compat-include/linux/nl80211.h
26 create mode 100644 compat-include/uapi/linux/nl80211.h
27
28 diff --git a/compat-include/linux/nl80211.h b/compat-include/linux/nl80211.h
29 new file mode 100644
30 index 0000000000000000000000000000000000000000..e6654df8cd67caa52a16a1f709141d7415b9f523
31 --- /dev/null
32 +++ b/compat-include/linux/nl80211.h
33 @@ -0,0 +1,14 @@
34 +#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_NL80211_H_
35 +#define _NET_BATMAN_ADV_COMPAT_LINUX_NL80211_H_
36 +
37 +#include <linux/version.h>
38 +#include_next <linux/nl80211.h>
39 +
40 +#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)
41 +
42 +/* Linux 3.15 misses the uapi include.... */
43 +#include <uapi/linux/nl80211.h>
44 +
45 +#endif /* < KERNEL_VERSION(3, 16, 0) */
46 +
47 +#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_NL80211_H_ */
48 diff --git a/compat-include/uapi/linux/nl80211.h b/compat-include/uapi/linux/nl80211.h
49 new file mode 100644
50 index 0000000000000000000000000000000000000000..06f5625af21360be5718a1a6f7e8949f6739c927
51 --- /dev/null
52 +++ b/compat-include/uapi/linux/nl80211.h
53 @@ -0,0 +1,16 @@
54 +#ifndef _NET_BATMAN_ADV_COMPAT_UAPI_LINUX_NL80211_H_
55 +#define _NET_BATMAN_ADV_COMPAT_UAPI_LINUX_NL80211_H_
56 +
57 +#include <linux/version.h>
58 +#include_next <uapi/linux/nl80211.h>
59 +
60 +#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
61 +
62 +/* for batadv_v_elp_get_throughput which would have used
63 + * STATION_INFO_EXPECTED_THROUGHPUT in Linux 4.0.0
64 + */
65 +#define NL80211_STA_INFO_EXPECTED_THROUGHPUT 28
66 +
67 +#endif /* < KERNEL_VERSION(4, 0, 0) */
68 +
69 +#endif /* _NET_BATMAN_ADV_COMPAT_UAPI_LINUX_NL80211_H_ */
70 diff --git a/net/batman-adv/bat_v_elp.c b/net/batman-adv/bat_v_elp.c
71 index 7c54a9291c9eaed75dfdfdfbd200f84c51576cb3..06b2924f4cb7dde54bab97ad2d28aecd9b1a4ceb 100644
72 --- a/net/batman-adv/bat_v_elp.c
73 +++ b/net/batman-adv/bat_v_elp.c
74 @@ -19,6 +19,7 @@
75 #include "main.h"
76
77 #include <linux/atomic.h>
78 +#include <linux/bitops.h>
79 #include <linux/byteorder/generic.h>
80 #include <linux/errno.h>
81 #include <linux/etherdevice.h>
82 @@ -29,6 +30,7 @@
83 #include <linux/kernel.h>
84 #include <linux/kref.h>
85 #include <linux/netdevice.h>
86 +#include <linux/nl80211.h>
87 #include <linux/random.h>
88 #include <linux/rculist.h>
89 #include <linux/rcupdate.h>
90 @@ -111,6 +113,8 @@ static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh)
91 }
92 if (ret)
93 goto default_throughput;
94 + if (!(sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT)))
95 + goto default_throughput;
96
97 return sinfo.expected_throughput / 100;
98 }