batman-adv: 2014.0.0 updated stability fixes
[feed/routing.git] / batman-adv / patches / 0011-batman-adv-fix-TT-CRC-computation-by-ensuring-byte-o.patch
1 From be4385eacf30ad55a5cf4574768624ce8141a0c7 Mon Sep 17 00:00:00 2001
2 From: Antonio Quartulli <antonio@open-mesh.com>
3 Date: Tue, 11 Feb 2014 17:05:06 +0100
4 Subject: [PATCH 11/13] batman-adv: fix TT CRC computation by ensuring byte
5 order
6
7 When computing the CRC on a 2byte variable the order of
8 the bytes obviously alters the final result. This means
9 that computing the CRC over the same value on two archs
10 having different endianess leads to different numbers.
11
12 The global and local translation table CRC computation
13 routine makes this mistake while processing the clients
14 VIDs. The result is a continuous CRC mismatching between
15 nodes having different endianess.
16
17 Fix this by converting the VID to Network Order before
18 processing it. This guarantees that every node uses the same
19 byte order.
20
21 Introduced by 21a57f6e7a3b4455dfe68ee07a7b901d9e7f200b
22 ("batman-adv: make the TT CRC logic VLAN specific")
23
24 Reported-by: Russel Senior <russell@personaltelco.net>
25 Signed-off-by: Antonio Quartulli <antonio@open-mesh.com>
26 Tested-by: Russell Senior <russell@personaltelco.net>
27 Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
28 ---
29 translation-table.c | 16 ++++++++++++----
30 1 file changed, 12 insertions(+), 4 deletions(-)
31
32 diff --git a/translation-table.c b/translation-table.c
33 index 05c2a9b..24e3267 100644
34 --- a/translation-table.c
35 +++ b/translation-table.c
36 @@ -1961,6 +1961,7 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
37 struct hlist_head *head;
38 uint32_t i, crc_tmp, crc = 0;
39 uint8_t flags;
40 + __be16 tmp_vid;
41
42 for (i = 0; i < hash->size; i++) {
43 head = &hash->table[i];
44 @@ -1997,8 +1998,11 @@ static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
45 orig_node))
46 continue;
47
48 - crc_tmp = crc32c(0, &tt_common->vid,
49 - sizeof(tt_common->vid));
50 + /* use network order to read the VID: this ensures that
51 + * every node reads the bytes in the same order.
52 + */
53 + tmp_vid = htons(tt_common->vid);
54 + crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
55
56 /* compute the CRC on flags that have to be kept in sync
57 * among nodes
58 @@ -2032,6 +2036,7 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv,
59 struct hlist_head *head;
60 uint32_t i, crc_tmp, crc = 0;
61 uint8_t flags;
62 + __be16 tmp_vid;
63
64 for (i = 0; i < hash->size; i++) {
65 head = &hash->table[i];
66 @@ -2050,8 +2055,11 @@ static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv,
67 if (tt_common->flags & BATADV_TT_CLIENT_NEW)
68 continue;
69
70 - crc_tmp = crc32c(0, &tt_common->vid,
71 - sizeof(tt_common->vid));
72 + /* use network order to read the VID: this ensures that
73 + * every node reads the bytes in the same order.
74 + */
75 + tmp_vid = htons(tt_common->vid);
76 + crc_tmp = crc32c(0, &tmp_vid, sizeof(tmp_vid));
77
78 /* compute the CRC on flags that have to be kept in sync
79 * among nodes
80 --
81 1.9.0.rc3
82