public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h
@ 2012-10-15 20:23 Simon Wunderlich
  2012-10-15 20:23 ` [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: fix bla compare function Simon Wunderlich
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Simon Wunderlich @ 2012-10-15 20:23 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Simon Wunderlich

This function will be used by other parts of batman-adv as well.

Reported-by: Marek Lindner <lindner_marek@yahoo.de>
Reported-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
---
 bridge_loop_avoidance.c |   20 ++++----------------
 hash.h                  |   21 +++++++++++++++++++++
 2 files changed, 25 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..ddfa4d1 100644
--- a/hash.h
+++ b/hash.h
@@ -82,6 +82,27 @@ 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
+ *
+ *	Returns 0 on success, 1 if the element already is in the hash
+ *	and -1 on error.
+ */
+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
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: fix bla compare function
  2012-10-15 20:23 [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Simon Wunderlich
@ 2012-10-15 20:23 ` Simon Wunderlich
  2012-10-15 20:28 ` [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Marek Lindner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Simon Wunderlich @ 2012-10-15 20:23 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Simon Wunderlich

The address and the VLAN VID may not be packed in the respective
structs. Fix this by comparing the elements individually.

Reported-by: Marek Lindner <lindner_marek@yahoo.de>
Reported-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
---
 bridge_loop_avoidance.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 758d921..8313322 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -77,8 +77,10 @@ static int batadv_compare_backbone_gw(const struct hlist_node *node,
 {
 	const void *data1 = container_of(node, struct batadv_backbone_gw,
 					 hash_entry);
+	const struct batadv_backbone_gw *gw1 = data1, *gw2 = data2;
 
-	return (memcmp(data1, data2, ETH_ALEN + sizeof(short)) == 0 ? 1 : 0);
+	return (((memcmp(gw1->orig, gw2->orig, ETH_ALEN) == 0) &&
+		 (gw1->vid == gw2->vid)) ? 1 : 0);
 }
 
 /* compares address and vid of two claims */
@@ -87,8 +89,10 @@ static int batadv_compare_claim(const struct hlist_node *node,
 {
 	const void *data1 = container_of(node, struct batadv_claim,
 					 hash_entry);
+	const struct batadv_claim *cl1 = data1, *cl2 = data2;
 
-	return (memcmp(data1, data2, ETH_ALEN + sizeof(short)) == 0 ? 1 : 0);
+	return (((memcmp(cl1->addr, cl2->addr, ETH_ALEN) == 0) &&
+		 (cl1->vid == cl2->vid)) ? 1 : 0);
 }
 
 /* free a backbone gw */
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h
  2012-10-15 20:23 [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Simon Wunderlich
  2012-10-15 20:23 ` [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: fix bla compare function Simon Wunderlich
@ 2012-10-15 20:28 ` Marek Lindner
  2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 " Simon Wunderlich
  2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: fix bla compare function Simon Wunderlich
  3 siblings, 0 replies; 7+ messages in thread
From: Marek Lindner @ 2012-10-15 20:28 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking

On Tuesday, October 16, 2012 04:23:15 Simon Wunderlich wrote:
>  /**
> + *     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
> + *
> + *     Returns 0 on success, 1 if the element already is in the hash
> + *     and -1 on error.
> + */
> +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);
> +       }
> +}

Seems the function lacks the documented return behavior ..  ;-)

Cheers,
Marek

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: move hash_bytes into hash.h
  2012-10-15 20:23 [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Simon Wunderlich
  2012-10-15 20:23 ` [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: fix bla compare function Simon Wunderlich
  2012-10-15 20:28 ` [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Marek Lindner
@ 2012-10-15 20:38 ` Simon Wunderlich
  2012-10-15 21:19   ` Marek Lindner
  2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: fix bla compare function Simon Wunderlich
  3 siblings, 1 reply; 7+ messages in thread
From: Simon Wunderlich @ 2012-10-15 20:38 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Simon Wunderlich

This function will be used by other parts of batman-adv as well.

Reported-by: Marek Lindner <lindner_marek@yahoo.de>
Reported-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
---
 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
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: fix bla compare function
  2012-10-15 20:23 [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Simon Wunderlich
                   ` (2 preceding siblings ...)
  2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 " Simon Wunderlich
@ 2012-10-15 20:38 ` Simon Wunderlich
  2012-10-15 21:21   ` Marek Lindner
  3 siblings, 1 reply; 7+ messages in thread
From: Simon Wunderlich @ 2012-10-15 20:38 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Simon Wunderlich

The address and the VLAN VID may not be packed in the respective
structs. Fix this by comparing the elements individually.

Reported-by: Marek Lindner <lindner_marek@yahoo.de>
Reported-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
---
 bridge_loop_avoidance.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c
index 758d921..a617f2c 100644
--- a/bridge_loop_avoidance.c
+++ b/bridge_loop_avoidance.c
@@ -77,8 +77,15 @@ static int batadv_compare_backbone_gw(const struct hlist_node *node,
 {
 	const void *data1 = container_of(node, struct batadv_backbone_gw,
 					 hash_entry);
+	const struct batadv_backbone_gw *gw1 = data1, *gw2 = data2;
 
-	return (memcmp(data1, data2, ETH_ALEN + sizeof(short)) == 0 ? 1 : 0);
+	if (memcmp(gw1->orig, gw2->orig, ETH_ALEN))
+		return 0;
+
+	if (gw1->vid != gw2->vid)
+		return 0;
+
+	return 1;
 }
 
 /* compares address and vid of two claims */
@@ -87,8 +94,15 @@ static int batadv_compare_claim(const struct hlist_node *node,
 {
 	const void *data1 = container_of(node, struct batadv_claim,
 					 hash_entry);
+	const struct batadv_claim *cl1 = data1, *cl2 = data2;
 
-	return (memcmp(data1, data2, ETH_ALEN + sizeof(short)) == 0 ? 1 : 0);
+	if (memcmp(cl1->addr, cl2->addr, ETH_ALEN))
+		return 0;
+
+	if (cl1->vid != cl2->vid)
+		return 0;
+
+	return 1;
 }
 
 /* free a backbone gw */
-- 
1.7.10


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv2 1/2] batman-adv: move hash_bytes into hash.h
  2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 " Simon Wunderlich
@ 2012-10-15 21:19   ` Marek Lindner
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Lindner @ 2012-10-15 21:19 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Simon Wunderlich

On Tuesday, October 16, 2012 04:38:03 Simon Wunderlich wrote:
> This function will be used by other parts of batman-adv as well.
> 
> Reported-by: Marek Lindner <lindner_marek@yahoo.de>
> Reported-by: Sven Eckelmann <sven@narfation.org>
> Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
> ---
>  bridge_loop_avoidance.c |   20 ++++----------------
>  hash.h                  |   18 ++++++++++++++++++
>  2 files changed, 22 insertions(+), 16 deletions(-)

Applied in revision f64999e.

Thanks,
Marek

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: fix bla compare function
  2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: fix bla compare function Simon Wunderlich
@ 2012-10-15 21:21   ` Marek Lindner
  0 siblings, 0 replies; 7+ messages in thread
From: Marek Lindner @ 2012-10-15 21:21 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Simon Wunderlich

On Tuesday, October 16, 2012 04:38:04 Simon Wunderlich wrote:
> The address and the VLAN VID may not be packed in the respective
> structs. Fix this by comparing the elements individually.
> 
> Reported-by: Marek Lindner <lindner_marek@yahoo.de>
> Reported-by: Sven Eckelmann <sven@narfation.org>
> Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
> ---
>  bridge_loop_avoidance.c |   18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)

Applied in revision 923d5d1.

Thanks,
Marek

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-10-15 21:21 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-15 20:23 [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Simon Wunderlich
2012-10-15 20:23 ` [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: fix bla compare function Simon Wunderlich
2012-10-15 20:28 ` [B.A.T.M.A.N.] [PATCH 1/2] batman-adv: move hash_bytes into hash.h Marek Lindner
2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 " Simon Wunderlich
2012-10-15 21:19   ` Marek Lindner
2012-10-15 20:38 ` [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: fix bla compare function Simon Wunderlich
2012-10-15 21:21   ` Marek Lindner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox