From patchwork Thu Aug 30 16:22:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 2277 Return-Path: Received: from cora.hrz.tu-chemnitz.de (cora.hrz.tu-chemnitz.de [134.109.228.40]) by open-mesh.org (Postfix) with ESMTPS id 767236003FC for ; Thu, 30 Aug 2012 18:22:18 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass reason="1024-bit key; insecure key" header.i=@tu-chemnitz.de header.b=wObZOPoT; dkim-adsp=none (insecure policy); dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tu-chemnitz.de; s=dkim2010; h=Message-Id:Date:Subject:Cc:To:From; bh=tPu3HwmmxOcg/88LhPDw2oMXZr+BLS+L/Ejb4/3XoR4=; b=wObZOPoTAsDpIZ8WgZB0AnvDo07YSXLA2ulywMUu/7j/qBsbbNJDHuV8XgSPdidG62zk+mu9CAesFTSEl2sSRChF+xzEMnUtDL4x/ZcUJUgETTm1Vo1ODQaMWLzpDab6v2dZStTj28XycpcsI27UzZXCRJ7xxnHq7pijF8BO71w=; Received: from p57aa17e6.dip0.t-ipconnect.de ([87.170.23.230] helo=pandem0nium) by cora.hrz.tu-chemnitz.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.80) (envelope-from ) id 1T77VZ-0005Mu-BU; Thu, 30 Aug 2012 18:22:18 +0200 Received: from dotslash by pandem0nium with local (Exim 4.72) (envelope-from ) id 1T77Vn-00013B-L8; Thu, 30 Aug 2012 18:22:31 +0200 From: Simon Wunderlich To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 30 Aug 2012 18:22:27 +0200 Message-Id: <1346343747-4010-1-git-send-email-siwu@hrz.tu-chemnitz.de> X-Mailer: git-send-email 1.7.2.5 X-purgate: clean X-purgate-type: clean X-purgate-ID: 154106::1346343737-000070F6-62954B42/0-0/0-0 X-Scan-AV: cora.hrz.tu-chemnitz.de; 2012-08-30 18:22:17; d2324596656c00a271c7a8005bb6a4a6 X-Scan-SA: cora.hrz.tu-chemnitz.de; 2012-08-30 18:22:18; 54b76e7afd4439aa7a91e024528be34c X-Spam-Score: -1.0 (-) X-Spam-Report: --- Textanalyse SpamAssassin 3.3.1 (-1.0 Punkte) Fragen an/questions to: Postmaster TU Chemnitz * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP --- Ende Textanalyse Cc: Simon Wunderlich Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: don't rely on positions in struct for hashing X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 30 Aug 2012 16:22:18 -0000 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 Signed-off-by: Simon Wunderlich --- bridge_loop_avoidance.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index 0921509..7e62c79 100644 --- a/bridge_loop_avoidance.c +++ b/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);