2727#include "routing.h"
2828#include "bridge_loop_avoidance.h"
2929
30- #include <linux/crc16 .h>
30+ #include <linux/crc32c .h>
3131
3232/* hash class keys */
3333static 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)
409409
410410 tt_data -> flags = BATADV_TT_OGM_DIFF ;
411411 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 );
413413
414414 if (tt_diff_len == 0 )
415415 goto container_register ;
@@ -481,7 +481,7 @@ int batadv_tt_local_seq_print_text(struct seq_file *seq, void *offset)
481481 goto out ;
482482
483483 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" ,
485485 net_dev -> name , (uint8_t )atomic_read (& bat_priv -> tt .vn ),
486486 bat_priv -> tt .local_crc );
487487 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,
993993 if (best_entry ) {
994994 last_ttvn = atomic_read (& best_entry -> orig_node -> last_ttvn );
995995 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" ,
997997 '*' , tt_global_entry -> common .addr ,
998998 best_entry -> ttvn , best_entry -> orig_node -> orig ,
999999 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)
10371037 seq_printf (seq ,
10381038 "Globally announced TT entries received via the mesh %s\n" ,
10391039 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" ,
10411041 "Client" , "(TTVN)" , "Originator" , "(Curr TTVN)" , "CRC" ,
10421042 "Flags" );
10431043
@@ -1394,17 +1394,19 @@ struct batadv_orig_node *batadv_transtable_search(struct batadv_priv *bat_priv,
13941394 return orig_node ;
13951395}
13961396
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 ,
13991403 struct batadv_orig_node * orig_node )
14001404{
1401- uint16_t total = 0 , total_one ;
14021405 struct batadv_hashtable * hash = bat_priv -> tt .global_hash ;
14031406 struct batadv_tt_common_entry * tt_common ;
14041407 struct batadv_tt_global_entry * tt_global ;
14051408 struct hlist_head * head ;
1406- uint32_t i ;
1407- int j ;
1409+ uint32_t i , crc = 0 ;
14081410
14091411 for (i = 0 ; i < hash -> size ; i ++ ) {
14101412 head = & hash -> table [i ];
@@ -1435,27 +1437,24 @@ static uint16_t batadv_tt_global_crc(struct batadv_priv *bat_priv,
14351437 orig_node ))
14361438 continue ;
14371439
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 );
14431441 }
14441442 rcu_read_unlock ();
14451443 }
14461444
1447- return total ;
1445+ return crc ;
14481446}
14491447
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 )
14521453{
1453- uint16_t total = 0 , total_one ;
14541454 struct batadv_hashtable * hash = bat_priv -> tt .local_hash ;
14551455 struct batadv_tt_common_entry * tt_common ;
14561456 struct hlist_head * head ;
1457- uint32_t i ;
1458- int j ;
1457+ uint32_t i , crc = 0 ;
14591458
14601459 for (i = 0 ; i < hash -> size ; i ++ ) {
14611460 head = & hash -> table [i ];
@@ -1467,16 +1466,13 @@ static uint16_t batadv_tt_local_crc(struct batadv_priv *bat_priv)
14671466 */
14681467 if (tt_common -> flags & BATADV_TT_CLIENT_NEW )
14691468 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 );
14751471 }
14761472 rcu_read_unlock ();
14771473 }
14781474
1479- return total ;
1475+ return crc ;
14801476}
14811477
14821478static void batadv_tt_req_list_free (struct batadv_priv * bat_priv )
@@ -1662,9 +1658,18 @@ batadv_tt_tvlv_generate(struct batadv_priv *bat_priv,
16621658 return tvlv_tt_data ;
16631659}
16641660
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+ */
16651670static int batadv_send_tt_request (struct batadv_priv * bat_priv ,
16661671 struct batadv_orig_node * dst_orig_node ,
1667- uint8_t ttvn , uint16_t tt_crc ,
1672+ uint8_t ttvn , uint32_t tt_crc ,
16681673 bool full_table )
16691674{
16701675 struct batadv_tvlv_tt_data * tvlv_tt_data = NULL ;
@@ -1689,7 +1694,7 @@ static int batadv_send_tt_request(struct batadv_priv *bat_priv,
16891694
16901695 tvlv_tt_data -> flags = BATADV_TT_REQUEST ;
16911696 tvlv_tt_data -> ttvn = ttvn ;
1692- tvlv_tt_data -> crc = htons (tt_crc );
1697+ tvlv_tt_data -> crc = htonl (tt_crc );
16931698
16941699 if (full_table )
16951700 tvlv_tt_data -> flags |= BATADV_TT_FULL_TABLE ;
@@ -1756,7 +1761,7 @@ static bool batadv_send_other_tt_response(struct batadv_priv *bat_priv,
17561761
17571762 /* this node doesn't have the requested data */
17581763 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 ))
17601765 goto out ;
17611766
17621767 /* 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,
24042409 * @tt_buff: buffer holding the tt information
24052410 * @tt_num_changes: number of tt changes inside the tt buffer
24062411 * @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
24082413 */
24092414static void batadv_tt_update_orig (struct batadv_priv * bat_priv ,
24102415 struct batadv_orig_node * orig_node ,
24112416 const unsigned char * tt_buff ,
24122417 uint16_t tt_num_changes , uint8_t ttvn ,
2413- uint16_t tt_crc )
2418+ uint32_t tt_crc )
24142419{
24152420 uint8_t orig_ttvn = (uint8_t )atomic_read (& orig_node -> last_ttvn );
24162421 bool full_table = true;
@@ -2464,7 +2469,7 @@ static void batadv_tt_update_orig(struct batadv_priv *bat_priv,
24642469 orig_node -> tt_crc != tt_crc ) {
24652470request_table :
24662471 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" ,
24682473 orig_node -> orig , ttvn , orig_ttvn , tt_crc ,
24692474 orig_node -> tt_crc , tt_num_changes );
24702475 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,
25722577
25732578 batadv_tt_update_orig (bat_priv , orig ,
25742579 (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 ));
25762581}
25772582
25782583/**
0 commit comments