Commit 0ffa9e8d86d665f0f29343e45ecc09e2772ac646
Committed by
Antonio Quartulli
1 parent
c018ad3de6
batman-adv: use vid when computing local and global TT CRC
now that each TT entry is characterised by a VLAN ID, the latter has to be taken into consideration when computing the local/global table CRC as it would be theoretically possible to have the same client in two different VLANs Signed-off-by: Antonio Quartulli <antonio@open-mesh.com> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Showing 1 changed file with 31 additions and 4 deletions Side-by-side Diff
net/batman-adv/translation-table.c
... | ... | @@ -1506,6 +1506,24 @@ |
1506 | 1506 | * batadv_tt_global_crc - calculates the checksum of the local table belonging |
1507 | 1507 | * to the given orig_node |
1508 | 1508 | * @bat_priv: the bat priv with all the soft interface information |
1509 | + * @orig_node: originator for which the CRC should be computed | |
1510 | + * | |
1511 | + * This function computes the checksum for the global table corresponding to a | |
1512 | + * specific originator. In particular, the checksum is computed as follows: For | |
1513 | + * each client connected to the originator the CRC32C of the MAC address and the | |
1514 | + * VID is computed and then all the CRC32Cs of the various clients are xor'ed | |
1515 | + * together. | |
1516 | + * | |
1517 | + * The idea behind is that CRC32C should be used as much as possible in order to | |
1518 | + * produce a unique hash of the table, but since the order which is used to feed | |
1519 | + * the CRC32C function affects the result and since every node in the network | |
1520 | + * probably sorts the clients differently, the hash function cannot be directly | |
1521 | + * computed over the entire table. Hence the CRC32C is used only on | |
1522 | + * the single client entry, while all the results are then xor'ed together | |
1523 | + * because the XOR operation can combine them all while trying to reduce the | |
1524 | + * noise as much as possible. | |
1525 | + * | |
1526 | + * Returns the checksum of the global table of a given originator. | |
1509 | 1527 | */ |
1510 | 1528 | static uint32_t batadv_tt_global_crc(struct batadv_priv *bat_priv, |
1511 | 1529 | struct batadv_orig_node *orig_node) |
... | ... | @@ -1514,7 +1532,7 @@ |
1514 | 1532 | struct batadv_tt_common_entry *tt_common; |
1515 | 1533 | struct batadv_tt_global_entry *tt_global; |
1516 | 1534 | struct hlist_head *head; |
1517 | - uint32_t i, crc = 0; | |
1535 | + uint32_t i, crc_tmp, crc = 0; | |
1518 | 1536 | |
1519 | 1537 | for (i = 0; i < hash->size; i++) { |
1520 | 1538 | head = &hash->table[i]; |
... | ... | @@ -1545,7 +1563,9 @@ |
1545 | 1563 | orig_node)) |
1546 | 1564 | continue; |
1547 | 1565 | |
1548 | - crc ^= crc32c(0, tt_common->addr, ETH_ALEN); | |
1566 | + crc_tmp = crc32c(0, &tt_common->vid, | |
1567 | + sizeof(tt_common->vid)); | |
1568 | + crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN); | |
1549 | 1569 | } |
1550 | 1570 | rcu_read_unlock(); |
1551 | 1571 | } |
1552 | 1572 | |
... | ... | @@ -1556,13 +1576,18 @@ |
1556 | 1576 | /** |
1557 | 1577 | * batadv_tt_local_crc - calculates the checksum of the local table |
1558 | 1578 | * @bat_priv: the bat priv with all the soft interface information |
1579 | + * | |
1580 | + * For details about the computation, please refer to the documentation for | |
1581 | + * batadv_tt_global_crc(). | |
1582 | + * | |
1583 | + * Returns the checksum of the local table | |
1559 | 1584 | */ |
1560 | 1585 | static uint32_t batadv_tt_local_crc(struct batadv_priv *bat_priv) |
1561 | 1586 | { |
1562 | 1587 | struct batadv_hashtable *hash = bat_priv->tt.local_hash; |
1563 | 1588 | struct batadv_tt_common_entry *tt_common; |
1564 | 1589 | struct hlist_head *head; |
1565 | - uint32_t i, crc = 0; | |
1590 | + uint32_t i, crc_tmp, crc = 0; | |
1566 | 1591 | |
1567 | 1592 | for (i = 0; i < hash->size; i++) { |
1568 | 1593 | head = &hash->table[i]; |
... | ... | @@ -1575,7 +1600,9 @@ |
1575 | 1600 | if (tt_common->flags & BATADV_TT_CLIENT_NEW) |
1576 | 1601 | continue; |
1577 | 1602 | |
1578 | - crc ^= crc32c(0, tt_common->addr, ETH_ALEN); | |
1603 | + crc_tmp = crc32c(0, &tt_common->vid, | |
1604 | + sizeof(tt_common->vid)); | |
1605 | + crc ^= crc32c(crc_tmp, tt_common->addr, ETH_ALEN); | |
1579 | 1606 | } |
1580 | 1607 | rcu_read_unlock(); |
1581 | 1608 | } |