[commits] [batman-adv] master: batman-adv: move hash_bytes into hash.h (f64999e)

postmaster at open-mesh.org postmaster at open-mesh.org
Mon Oct 15 23:18:30 CEST 2012


Repository : ssh://git@open-mesh.org/batman-adv

On branch  : master

>---------------------------------------------------------------

commit f64999e5d5c5b20af0f18f4ad304d3b6e2a420f2
Author: Simon Wunderlich <simon.wunderlich at s2003.tu-chemnitz.de>
Date:   Mon Oct 15 22:38:03 2012 +0200

    batman-adv: move hash_bytes into hash.h
    
    This function will be used by other parts of batman-adv as well.
    
    Reported-by: Marek Lindner <lindner_marek at yahoo.de>
    Reported-by: Sven Eckelmann <sven at narfation.org>
    Signed-off-by: Simon Wunderlich <siwu at hrz.tu-chemnitz.de>
    Signed-off-by: Marek Lindner <lindner_marek at yahoo.de>


>---------------------------------------------------------------

f64999e5d5c5b20af0f18f4ad304d3b6e2a420f2
 bridge_loop_avoidance.c |   20 ++++----------------
 hash.h                  |   18 ++++++++++++++++++
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 23a6359..758d921 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -37,26 +37,14 @@ static void batadv_bla_periodic_work(struct work_struct *work);
 static void batadv_bla_send_announce(struct batadv_priv *bat_priv,
 				     struct batadv_backbone_gw *backbone_gw);
 
-static inline void hash_bytes(uint32_t *hash, void *data, uint32_t size)
-{
-	const unsigned char *key = data;
-	int i;
-
-	for (i = 0; i < size; i++) {
-		*hash += key[i];
-		*hash += (*hash << 10);
-		*hash ^= (*hash >> 6);
-	}
-}
-
 /* return the index of the claim */
 static inline uint32_t batadv_choose_claim(const void *data, uint32_t size)
 {
 	struct batadv_claim *claim = (struct batadv_claim *)data;
 	uint32_t hash = 0;
 
-	hash_bytes(&hash, &claim->addr, sizeof(claim->addr));
-	hash_bytes(&hash, &claim->vid, sizeof(claim->vid));
+	batadv_hash_bytes(&hash, &claim->addr, sizeof(claim->addr));
+	batadv_hash_bytes(&hash, &claim->vid, sizeof(claim->vid));
 
 	hash += (hash << 3);
 	hash ^= (hash >> 11);
@@ -72,8 +60,8 @@ static inline uint32_t batadv_choose_backbone_gw(const void *data,
 	struct batadv_claim *claim = (struct batadv_claim *)data;
 	uint32_t hash = 0;
 
-	hash_bytes(&hash, &claim->addr, sizeof(claim->addr));
-	hash_bytes(&hash, &claim->vid, sizeof(claim->vid));
+	batadv_hash_bytes(&hash, &claim->addr, sizeof(claim->addr));
+	batadv_hash_bytes(&hash, &claim->vid, sizeof(claim->vid));
 
 	hash += (hash << 3);
 	hash ^= (hash >> 11);
diff --git a/hash.h b/hash.h
index 977de9c..f173427 100644
--- a/hash.h
+++ b/hash.h
@@ -82,6 +82,24 @@ static inline void batadv_hash_delete(struct batadv_hashtable *hash,
 }
 
 /**
+ *	batadv_hash_bytes - hash some bytes and add them to the previous hash
+ *	@hash: previous hash value
+ *	@data: data to be hashed
+ *	@size: number of bytes to be hashed
+ */
+static inline void batadv_hash_bytes(uint32_t *hash, void *data, uint32_t size)
+{
+	const unsigned char *key = data;
+	int i;
+
+	for (i = 0; i < size; i++) {
+		*hash += key[i];
+		*hash += (*hash << 10);
+		*hash ^= (*hash >> 6);
+	}
+}
+
+/**
  *	batadv_hash_add - adds data to the hashtable
  *	@hash: storage hash table
  *	@compare: callback to determine if 2 hash elements are identical



More information about the commits mailing list