[maint] batman-adv: Fix DAT candidate selection on little endian systems
diff mbox series

Message ID 20191128114349.7794-1-sven@narfation.org
State Accepted, archived
Delegated to: Simon Wunderlich
Headers show
Series
  • [maint] batman-adv: Fix DAT candidate selection on little endian systems
Related show

Commit Message

Sven Eckelmann Nov. 28, 2019, 11:43 a.m. UTC
The distributed arp table is using a DHT to store and retrieve MAC address
information for an IP address. This is done using unicast messages to
selected peers. The potential peers are looked up using the IP address and
the VID.

While the IP address is always stored in big endian byte order, it is not
the case of the VID. It can (depending on the host system) either be big
endian or little endian. The host must therefore always convert it to big
endian to ensure that all devices calculate the same peers for the same
lookup data.

Fixes: 3e26722bc9f2 ("batman-adv: make the Distributed ARP Table vlan aware")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
 net/batman-adv/distributed-arp-table.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Antonio Quartulli Nov. 28, 2019, 1:19 p.m. UTC | #1
Hi,

On 28/11/2019 12:43, Sven Eckelmann wrote:
> The distributed arp table is using a DHT to store and retrieve MAC address
> information for an IP address. This is done using unicast messages to
> selected peers. The potential peers are looked up using the IP address and
> the VID.
> 
> While the IP address is always stored in big endian byte order, it is not
> the case of the VID. It can (depending on the host system) either be big
> endian or little endian. The host must therefore always convert it to big
> endian to ensure that all devices calculate the same peers for the same
> lookup data.
> 
> Fixes: 3e26722bc9f2 ("batman-adv: make the Distributed ARP Table vlan aware")
> Signed-off-by: Sven Eckelmann <sven@narfation.org>

Thanks a lot for fixing this subtle bug.

Acked-by: Antonio Quartulli <a@unstable.cc>

Patch
diff mbox series

diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index 5004e38f..581b3181 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -287,6 +287,7 @@  static u32 batadv_hash_dat(const void *data, u32 size)
 	u32 hash = 0;
 	const struct batadv_dat_entry *dat = data;
 	const unsigned char *key;
+	__be16 vid;
 	u32 i;
 
 	key = (__force const unsigned char *)&dat->ip;
@@ -296,7 +297,8 @@  static u32 batadv_hash_dat(const void *data, u32 size)
 		hash ^= (hash >> 6);
 	}
 
-	key = (const unsigned char *)&dat->vid;
+	vid = htons(dat->vid);
+	key = (__force const unsigned char *)&vid;
 	for (i = 0; i < sizeof(dat->vid); i++) {
 		hash += key[i];
 		hash += (hash << 10);