From patchwork Tue Nov 13 09:15:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 2520 Return-Path: Received: from contumacia.investici.org (contumacia.investici.org [178.255.144.35]) by open-mesh.org (Postfix) with ESMTPS id D4AB36012FD for ; Tue, 13 Nov 2012 10:16:30 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass reason="1024-bit key; insecure key" header.d=autistici.org header.i=@autistici.org header.b=dbKS1ceu; dkim-adsp=pass; dkim-atps=neutral Received: from [178.255.144.35] (contumacia [178.255.144.35]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 88856E8906; Tue, 13 Nov 2012 09:16:29 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 contumacia.investici.org 88856E8906 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1352798190; bh=xb6/Qd/R/f9A9zPM5+MXaH5e13uzP74wbwOfCAV1ZcE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=dbKS1ceuqz3tpw68fFPkOOH2f7qL6WlWiP+I/3cF/gNvhlHyEcGTBmgEvQ73Q4LgJ Z8TFwvzIOrh6J0wssuJ7pLyQaKwXqAaUwkDId/Nm092fMAPlvYkt1Wj1JRiQA60zQk 1Mi8RYadzwnnYMyBZaFnxaJrvjknPjTyLOTweYr8= From: Antonio Quartulli To: davem@davemloft.net Date: Tue, 13 Nov 2012 10:15:29 +0100 Message-Id: <1352798139-19458-2-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1352798139-19458-1-git-send-email-ordex@autistici.org> References: <1352798139-19458-1-git-send-email-ordex@autistici.org> Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, Simon Wunderlich Subject: [B.A.T.M.A.N.] [PATCH 01/11] 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: Tue, 13 Nov 2012 09:16:31 -0000 From: Simon Wunderlich 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 Signed-off-by: Antonio Quartulli --- 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);