Skip to content

Commit

Permalink
batman-adv: fix TT CRC computation by ensuring byte order
Browse files Browse the repository at this point in the history
When computing the CRC on a 2byte variable the order of
the bytes obviously alters the final result. This means
that computing the CRC over the same value on two archs
having different endianess leads to different numbers.

The global and local translation table CRC computation
routine makes this mistake while processing the clients
VIDs. The result is a continuous CRC mismatching between
nodes having different endianess.

Fix this by converting the VID to Network Order before
processing it. This guarantees that every node uses the same
byte order.

Introduced by 7ea7b4a
("batman-adv: make the TT CRC logic VLAN specific")

Reported-by: Russel Senior <[email protected]>
Signed-off-by: Antonio Quartulli <[email protected]>
Tested-by: Russell Senior <[email protected]>
Signed-off-by: Marek Lindner <[email protected]>
  • Loading branch information
ordex committed Feb 17, 2014
1 parent b2262df commit a30e22c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions net/batman-adv/translation-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1975,6 +1975,7 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
struct hlist_head *head;
uint32_t i, crc_tmp, crc = 0;
uint8_t flags;
__be16 tmp_vid;

for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
Expand Down Expand Up @@ -2011,8 +2012,11 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
orig_node))
continue;

crc_tmp = crc32c(0, &tt_common->vid,
sizeof(tt_common->vid));
/* use network order to read the VID: this ensures that
* every node reads the bytes in the same order.
*/
tmp_vid = htons(tt_common->vid);
crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));

/* compute the CRC on flags that have to be kept in sync
* among nodes
Expand Down Expand Up @@ -2046,6 +2050,7 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv,
struct hlist_head *head;
uint32_t i, crc_tmp, crc = 0;
uint8_t flags;
__be16 tmp_vid;

for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
Expand All @@ -2064,8 +2069,11 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv,
if (tt_common->flags & BATADV_TT_CLIENT_NEW)
continue;

crc_tmp = crc32c(0, &tt_common->vid,
sizeof(tt_common->vid));
/* use network order to read the VID: this ensures that
* every node reads the bytes in the same order.
*/
tmp_vid = htons(tt_common->vid);
crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));

/* compute the CRC on flags that have to be kept in sync
* among nodes
Expand Down

0 comments on commit a30e22c

Please sign in to comment.