b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <ordex@autistici.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Subject: [B.A.T.M.A.N.] [PATCH 01/11] batman-adv: don't rely on positions in struct for hashing
Date: Tue, 13 Nov 2012 10:15:29 +0100	[thread overview]
Message-ID: <1352798139-19458-2-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1352798139-19458-1-git-send-email-ordex@autistici.org>

From: Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>

The hash functions in the bridge loop avoidance code expects the
VLAN vid to be right after the mac address, but this is not guaranteed.

Fix this by explicitly hashing over the right fields of the struct.

Reported-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 net/batman-adv/bridge_loop_avoidance.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 29a5542..decc042 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -37,18 +37,26 @@ 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)
 {
-	const unsigned char *key = data;
+	struct batadv_claim *claim = (struct batadv_claim *)data;
 	uint32_t hash = 0;
-	size_t i;
 
-	for (i = 0; i < ETH_ALEN + sizeof(short); i++) {
-		hash += key[i];
-		hash += (hash << 10);
-		hash ^= (hash >> 6);
-	}
+	hash_bytes(&hash, &claim->addr, sizeof(claim->addr));
+	hash_bytes(&hash, &claim->vid, sizeof(claim->vid));
 
 	hash += (hash << 3);
 	hash ^= (hash >> 11);
@@ -61,15 +69,11 @@ static inline uint32_t batadv_choose_claim(const void *data, uint32_t size)
 static inline uint32_t batadv_choose_backbone_gw(const void *data,
 						 uint32_t size)
 {
-	const unsigned char *key = data;
+	struct batadv_claim *claim = (struct batadv_claim *)data;
 	uint32_t hash = 0;
-	size_t i;
 
-	for (i = 0; i < ETH_ALEN + sizeof(short); i++) {
-		hash += key[i];
-		hash += (hash << 10);
-		hash ^= (hash >> 6);
-	}
+	hash_bytes(&hash, &claim->addr, sizeof(claim->addr));
+	hash_bytes(&hash, &claim->vid, sizeof(claim->vid));
 
 	hash += (hash << 3);
 	hash ^= (hash >> 11);
-- 
1.8.0


  reply	other threads:[~2012-11-13  9:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-13  9:15 [B.A.T.M.A.N.] pull request: batman-adv 2012-11-13 Antonio Quartulli
2012-11-13  9:15 ` Antonio Quartulli [this message]
2012-11-13 19:24   ` [B.A.T.M.A.N.] [PATCH 01/11] batman-adv: don't rely on positions in struct for hashing David Miller
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 02/11] batman-adv: fix wrong spinlock inline comment Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 03/11] batman-adv: prevent using any virtual device created on batman-adv as hard-interface Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 04/11] batman-adv: send announcement when backbone gw is registered Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 05/11] batman-adv: allow bla traffic only after first worker period Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 06/11] batman-adv: wait multiple periods before activating bla Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 07/11] batman-adv: substitute tt_poss_change with a per-tt_entry flag Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 08/11] batman-adv: refactor code to simplify long lines Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 09/11] batman-adv: refactor tt_global_del_struct() Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 10/11] batman-adv: roaming handling mechanism redesign Antonio Quartulli
2012-11-13  9:15 ` [B.A.T.M.A.N.] [PATCH 11/11] batman-adv: Remove instant overwritten variable initialization Antonio Quartulli
2012-11-14 20:16 [B.A.T.M.A.N.] pull request: batman-adv 2012-11-14 Antonio Quartulli
2012-11-14 20:16 ` [B.A.T.M.A.N.] [PATCH 01/11] batman-adv: don't rely on positions in struct for hashing Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1352798139-19458-2-git-send-email-ordex@autistici.org \
    --to=ordex@autistici.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=siwu@hrz.tu-chemnitz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).