Merge pull request #624 from ecsv/batadv-for-18.06
[feed/routing.git] / batman-adv / patches / 0040-batman-adv-Fix-DAT-candidate-selection-on-little-end.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Thu, 28 Nov 2019 12:43:49 +0100
3 Subject: batman-adv: Fix DAT candidate selection on little endian systems
4
5 The distributed arp table is using a DHT to store and retrieve MAC address
6 information for an IP address. This is done using unicast messages to
7 selected peers. The potential peers are looked up using the IP address and
8 the VID.
9
10 While the IP address is always stored in big endian byte order, it is not
11 the case of the VID. It can (depending on the host system) either be big
12 endian or little endian. The host must therefore always convert it to big
13 endian to ensure that all devices calculate the same peers for the same
14 lookup data.
15
16 Fixes: 3e26722bc9f2 ("batman-adv: make the Distributed ARP Table vlan aware")
17 Signed-off-by: Sven Eckelmann <sven@narfation.org>
18 Acked-by: Antonio Quartulli <a@unstable.cc>
19
20 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/728aea06f38e0e4d70f4f7d43698187f7f7055c5
21
22 diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
23 index a60bacf7120be88ba7626cf0a87dd34eef0a2eec..21783805a3afd974cebc7e640249402d637d731a 100644
24 --- a/net/batman-adv/distributed-arp-table.c
25 +++ b/net/batman-adv/distributed-arp-table.c
26 @@ -251,6 +251,7 @@ static u32 batadv_hash_dat(const void *data, u32 size)
27 u32 hash = 0;
28 const struct batadv_dat_entry *dat = data;
29 const unsigned char *key;
30 + __be16 vid;
31 u32 i;
32
33 key = (const unsigned char *)&dat->ip;
34 @@ -260,7 +261,8 @@ static u32 batadv_hash_dat(const void *data, u32 size)
35 hash ^= (hash >> 6);
36 }
37
38 - key = (const unsigned char *)&dat->vid;
39 + vid = htons(dat->vid);
40 + key = (__force const unsigned char *)&vid;
41 for (i = 0; i < sizeof(dat->vid); i++) {
42 hash += key[i];
43 hash += (hash << 10);