27
27
#include "routing.h"
28
28
#include "bridge_loop_avoidance.h"
29
29
30
- #include <linux/crc16 .h>
30
+ #include <linux/crc32c .h>
31
31
32
32
/* hash class keys */
33
33
static struct lock_class_key batadv_tt_local_hash_lock_class_key ;
@@ -409,7 +409,7 @@ static void batadv_tt_tvlv_container_update(struct batadv_priv *bat_priv)
409
409
410
410
tt_data -> flags = BATADV_TT_OGM_DIFF ;
411
411
tt_data -> ttvn = atomic_read (& bat_priv -> tt .vn );
412
- tt_data -> crc = htons (bat_priv -> tt .local_crc );
412
+ tt_data -> crc = htonl (bat_priv -> tt .local_crc );
413
413
414
414
if (tt_diff_len == 0 )
415
415
goto container_register ;
@@ -481,7 +481,7 @@ int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset)
481
481
goto out ;
482
482
483
483
seq_printf (seq ,
484
- "Locally retrieved addresses (from %s) announced via TT (TTVN: %u CRC: %#.4x ):\n" ,
484
+ "Locally retrieved addresses (from %s) announced via TT (TTVN: %u CRC: %#.8x ):\n" ,
485
485
net_dev -> name , (uint8_t )atomic_read (& bat_priv -> tt .vn ),
486
486
bat_priv -> tt .local_crc );
487
487
seq_printf (seq , " %-13s %-7s %-10s\n" , "Client" , "Flags" ,
@@ -993,7 +993,7 @@ batadv_tt_global_print_entry(struct batadv_tt_global_entry *tt_global_entry,
993
993
if (best_entry ) {
994
994
last_ttvn = atomic_read (& best_entry -> orig_node -> last_ttvn );
995
995
seq_printf (seq ,
996
- " %c %pM (%3u) via %pM (%3u) (%#.4x ) [%c%c%c]\n" ,
996
+ " %c %pM (%3u) via %pM (%3u) (%#.8x ) [%c%c%c]\n" ,
997
997
'*' , tt_global_entry -> common .addr ,
998
998
best_entry -> ttvn , best_entry -> orig_node -> orig ,
999
999
last_ttvn , best_entry -> orig_node -> tt_crc ,
@@ -1037,7 +1037,7 @@ int batadv_tt_global_seq_print_text(struct seq_file *seq, void *offset)
1037
1037
seq_printf (seq ,
1038
1038
"Globally announced TT entries received via the mesh %s\n" ,
1039
1039
net_dev -> name );
1040
- seq_printf (seq , " %-13s %s %-15s %s (%-6s ) %s\n" ,
1040
+ seq_printf (seq , " %-13s %s %-15s %s (%-10s ) %s\n" ,
1041
1041
"Client" , "(TTVN)" , "Originator" , "(Curr TTVN)" , "CRC" ,
1042
1042
"Flags" );
1043
1043
@@ -1394,17 +1394,19 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
1394
1394
return orig_node ;
1395
1395
}
1396
1396
1397
- /* Calculates the checksum of the local table of a given orig_node */
1398
- static uint16_t batadv_tt_global_crc (struct batadv_priv * bat_priv ,
1397
+ /**
1398
+ * batadv_tt_global_crc - calculates the checksum of the local table belonging
1399
+ * to the given orig_node
1400
+ * @bat_priv: the bat priv with all the soft interface information
1401
+ */
1402
+ static uint32_t batadv_tt_global_crc (struct batadv_priv * bat_priv ,
1399
1403
struct batadv_orig_node * orig_node )
1400
1404
{
1401
- uint16_t total = 0 , total_one ;
1402
1405
struct batadv_hashtable * hash = bat_priv -> tt .global_hash ;
1403
1406
struct batadv_tt_common_entry * tt_common ;
1404
1407
struct batadv_tt_global_entry * tt_global ;
1405
1408
struct hlist_head * head ;
1406
- uint32_t i ;
1407
- int j ;
1409
+ uint32_t i , crc = 0 ;
1408
1410
1409
1411
for (i = 0 ; i < hash -> size ; i ++ ) {
1410
1412
head = & hash -> table [i ];
@@ -1435,27 +1437,24 @@ static uint16_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
1435
1437
orig_node ))
1436
1438
continue ;
1437
1439
1438
- total_one = 0 ;
1439
- for (j = 0 ; j < ETH_ALEN ; j ++ )
1440
- total_one = crc16_byte (total_one ,
1441
- tt_common -> addr [j ]);
1442
- total ^= total_one ;
1440
+ crc ^= crc32c (0 , tt_common -> addr , ETH_ALEN );
1443
1441
}
1444
1442
rcu_read_unlock ();
1445
1443
}
1446
1444
1447
- return total ;
1445
+ return crc ;
1448
1446
}
1449
1447
1450
- /* Calculates the checksum of the local table */
1451
- static uint16_t batadv_tt_local_crc (struct batadv_priv * bat_priv )
1448
+ /**
1449
+ * batadv_tt_local_crc - calculates the checksum of the local table
1450
+ * @bat_priv: the bat priv with all the soft interface information
1451
+ */
1452
+ static uint32_t batadv_tt_local_crc (struct batadv_priv * bat_priv )
1452
1453
{
1453
- uint16_t total = 0 , total_one ;
1454
1454
struct batadv_hashtable * hash = bat_priv -> tt .local_hash ;
1455
1455
struct batadv_tt_common_entry * tt_common ;
1456
1456
struct hlist_head * head ;
1457
- uint32_t i ;
1458
- int j ;
1457
+ uint32_t i , crc = 0 ;
1459
1458
1460
1459
for (i = 0 ; i < hash -> size ; i ++ ) {
1461
1460
head = & hash -> table [i ];
@@ -1467,16 +1466,13 @@ static uint16_t batadv_tt_local_crc(struct batadv_priv *bat_priv)
1467
1466
*/
1468
1467
if (tt_common -> flags & BATADV_TT_CLIENT_NEW )
1469
1468
continue ;
1470
- total_one = 0 ;
1471
- for (j = 0 ; j < ETH_ALEN ; j ++ )
1472
- total_one = crc16_byte (total_one ,
1473
- tt_common -> addr [j ]);
1474
- total ^= total_one ;
1469
+
1470
+ crc ^= crc32c (0 , tt_common -> addr , ETH_ALEN );
1475
1471
}
1476
1472
rcu_read_unlock ();
1477
1473
}
1478
1474
1479
- return total ;
1475
+ return crc ;
1480
1476
}
1481
1477
1482
1478
static void batadv_tt_req_list_free (struct batadv_priv * bat_priv )
@@ -1662,9 +1658,18 @@ batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
1662
1658
return tvlv_tt_data ;
1663
1659
}
1664
1660
1661
+ /**
1662
+ * batadv_send_tt_request - send a TT Request message to a given node
1663
+ * @bat_priv: the bat priv with all the soft interface information
1664
+ * @dst_orig_node: the destination of the message
1665
+ * @ttvn: the version number that the source of the message is looking for
1666
+ * @tt_crc: the CRC associated with the version number
1667
+ * @full_table: ask for the entire translation table if true, while only for the
1668
+ * last TT diff otherwise
1669
+ */
1665
1670
static int batadv_send_tt_request (struct batadv_priv * bat_priv ,
1666
1671
struct batadv_orig_node * dst_orig_node ,
1667
- uint8_t ttvn , uint16_t tt_crc ,
1672
+ uint8_t ttvn , uint32_t tt_crc ,
1668
1673
bool full_table )
1669
1674
{
1670
1675
struct batadv_tvlv_tt_data * tvlv_tt_data = NULL ;
@@ -1689,7 +1694,7 @@ static int batadv_send_tt_request(struct batadv_priv *bat_priv,
1689
1694
1690
1695
tvlv_tt_data -> flags = BATADV_TT_REQUEST ;
1691
1696
tvlv_tt_data -> ttvn = ttvn ;
1692
- tvlv_tt_data -> crc = htons (tt_crc );
1697
+ tvlv_tt_data -> crc = htonl (tt_crc );
1693
1698
1694
1699
if (full_table )
1695
1700
tvlv_tt_data -> flags |= BATADV_TT_FULL_TABLE ;
@@ -1756,7 +1761,7 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
1756
1761
1757
1762
/* this node doesn't have the requested data */
1758
1763
if (orig_ttvn != req_ttvn ||
1759
- tt_data -> crc != htons (req_dst_orig_node -> tt_crc ))
1764
+ tt_data -> crc != htonl (req_dst_orig_node -> tt_crc ))
1760
1765
goto out ;
1761
1766
1762
1767
/* If the full table has been explicitly requested */
@@ -2404,13 +2409,13 @@ bool batadv_is_ap_isolated(struct batadv_priv *bat_priv, uint8_t *src,
2404
2409
* @tt_buff: buffer holding the tt information
2405
2410
* @tt_num_changes: number of tt changes inside the tt buffer
2406
2411
* @ttvn: translation table version number of this changeset
2407
- * @tt_crc: crc16 checksum of orig node's translation table
2412
+ * @tt_crc: crc32 checksum of orig node's translation table
2408
2413
*/
2409
2414
static void batadv_tt_update_orig (struct batadv_priv * bat_priv ,
2410
2415
struct batadv_orig_node * orig_node ,
2411
2416
const unsigned char * tt_buff ,
2412
2417
uint16_t tt_num_changes , uint8_t ttvn ,
2413
- uint16_t tt_crc )
2418
+ uint32_t tt_crc )
2414
2419
{
2415
2420
uint8_t orig_ttvn = (uint8_t )atomic_read (& orig_node -> last_ttvn );
2416
2421
bool full_table = true;
@@ -2464,7 +2469,7 @@ static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
2464
2469
orig_node -> tt_crc != tt_crc ) {
2465
2470
request_table :
2466
2471
batadv_dbg (BATADV_DBG_TT , bat_priv ,
2467
- "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u crc: %#.4x last_crc: %#.4x num_changes: %u)\n" ,
2472
+ "TT inconsistency for %pM. Need to retrieve the correct information (ttvn: %u last_ttvn: %u crc: %#.8x last_crc: %#.8x num_changes: %u)\n" ,
2468
2473
orig_node -> orig , ttvn , orig_ttvn , tt_crc ,
2469
2474
orig_node -> tt_crc , tt_num_changes );
2470
2475
batadv_send_tt_request (bat_priv , orig_node , ttvn ,
@@ -2572,7 +2577,7 @@ static void batadv_tt_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
2572
2577
2573
2578
batadv_tt_update_orig (bat_priv , orig ,
2574
2579
(unsigned char * )(tt_data + 1 ),
2575
- num_entries , tt_data -> ttvn , ntohs (tt_data -> crc ));
2580
+ num_entries , tt_data -> ttvn , ntohl (tt_data -> crc ));
2576
2581
}
2577
2582
2578
2583
/**
0 commit comments