From patchwork Mon Oct 15 20:38:03 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 2359 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 8BD6C601347 for ; Mon, 15 Oct 2012 22:38:27 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass reason="1024-bit key; insecure key" header.i=@tu-chemnitz.de header.b=zVKSRDX6; 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=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Fg4/ByjvscLNGXySMT5gTdOhVIzqq64Hls1sK8FgoTQ=; b=zVKSRDX6ubVSAu3aALZ3LnMIjpHAIKFM7JtRr8jX8d4e1PIJmQJJGvaWZegrFXGaKBUajs9kUH7C/pmlknyCfZeEqIOLiFiFc52nEM7rMiT738UQQcnPgaYH+uwUvgFr4T2xki4zn93Lw2xbV4oEsuc6RiPPBBofcjw3ZO99sXM=; Received: from p57aa1adf.dip0.t-ipconnect.de ([87.170.26.223] helo=pandem0nium) by cora.hrz.tu-chemnitz.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.80) (envelope-from ) id 1TNrQg-000615-IJ; Mon, 15 Oct 2012 22:38:27 +0200 Received: from dotslash by pandem0nium with local (Exim 4.72) (envelope-from ) id 1TNrQV-0006C4-6b; Mon, 15 Oct 2012 22:38:15 +0200 From: Simon Wunderlich To: b.a.t.m.a.n@lists.open-mesh.org Date: Mon, 15 Oct 2012 22:38:03 +0200 Message-Id: <1350333484-23781-1-git-send-email-siwu@hrz.tu-chemnitz.de> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1350332596-23684-1-git-send-email-siwu@hrz.tu-chemnitz.de> References: <1350332596-23684-1-git-send-email-siwu@hrz.tu-chemnitz.de> X-purgate: clean X-purgate-type: clean X-purgate-ID: 154106::1350333506-00000CD1-C9F86032/0-0/0-0 X-Scan-AV: cora.hrz.tu-chemnitz.de; 2012-10-15 22:38:26; e5fd0567f2bb07aba2de63cbd311fba2 X-Scan-SA: cora.hrz.tu-chemnitz.de; 2012-10-15 22:38:27; 4961cf9d7bde9076ba69db7a6e54df6c 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.] [PATCHv2 1/2] batman-adv: move hash_bytes into hash.h 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: Mon, 15 Oct 2012 20:38:27 -0000 This function will be used by other parts of batman-adv as well. Reported-by: Marek Lindner Reported-by: Sven Eckelmann Signed-off-by: Simon Wunderlich --- 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