From patchwork Tue Oct 30 21:01:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sven Eckelmann X-Patchwork-Id: 17603 X-Patchwork-Delegate: sw@simonwunderlich.de Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 12CD883115; Tue, 30 Oct 2018 22:01:53 +0100 (CET) Authentication-Results: open-mesh.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=narfation.org header.i=@narfation.org header.b="1qEeOjZz"; dkim-atps=neutral Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=79.140.41.39; helo=v3-1039.vlinux.de; envelope-from=sven@narfation.org; receiver= Received: from v3-1039.vlinux.de (narfation.org [79.140.41.39]) by open-mesh.org (Postfix) with ESMTPS id B3356830EE for ; Tue, 30 Oct 2018 22:01:43 +0100 (CET) Received: from sven-desktop.home.narfation.org (p200300C593D31FFD0000000000004065.dip0.t-ipconnect.de [IPv6:2003:c5:93d3:1ffd::4065]) by v3-1039.vlinux.de (Postfix) with ESMTPSA id 425CE110116; Tue, 30 Oct 2018 22:01:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=narfation.org; s=20121; t=1540933303; bh=8aTGMcmvdbJ7a9Sx8mCY3xSEpKVlAWXnvyEZ88zY16c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1qEeOjZz8g7XJ5gtMfJXqBhzpX9ddPoTNmQweS2yskTuOshlOMfS34KkSgk2cn+AV HiBOiGwuMykzHpE6GW7wbzqw8yvr3p8HAGYwPzqcOwMQFN/7S8igPQpElgHK7Xtd1K dWA3GGpzEvpoOWAVAR57kw63YTaR/CZ0/iLH5xis= From: Sven Eckelmann To: b.a.t.m.a.n@lists.open-mesh.org Date: Tue, 30 Oct 2018 22:01:25 +0100 Message-Id: <20181030210130.18152-5-sven@narfation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181030210130.18152-1-sven@narfation.org> References: <20181030210130.18152-1-sven@narfation.org> MIME-Version: 1.0 Subject: [B.A.T.M.A.N.] [PATCH 4/9] batman-adv: Store modification counter via hash helpers X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" Multiple datastructures use the hash helper functions to add and remove entries from the simple hlist based hashes. These are often also dumped to userspace via netlink and thus should have a generation sequence counter. Reported-by: Matthias Schiffer Signed-off-by: Sven Eckelmann --- net/batman-adv/hash.c | 2 ++ net/batman-adv/hash.h | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c index 7b49e400..9194f4d8 100644 --- a/net/batman-adv/hash.c +++ b/net/batman-adv/hash.c @@ -32,6 +32,8 @@ static void batadv_hash_init(struct batadv_hashtable *hash) INIT_HLIST_HEAD(&hash->table[i]); spin_lock_init(&hash->list_locks[i]); } + + atomic_set(&hash->generation, 0); } /** diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h index 9490a7ca..0e36fa1c 100644 --- a/net/batman-adv/hash.h +++ b/net/batman-adv/hash.h @@ -21,6 +21,7 @@ #include "main.h" +#include #include #include #include @@ -58,6 +59,9 @@ struct batadv_hashtable { /** @size: size of hashtable */ u32 size; + + /** @generation: current (generation) sequence number */ + atomic_t generation; }; /* allocates and clears the hash */ @@ -112,6 +116,7 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash, /* no duplicate found in list, add new element */ hlist_add_head_rcu(data_node, head); + atomic_inc(&hash->generation); ret = 0; @@ -154,6 +159,7 @@ static inline void *batadv_hash_remove(struct batadv_hashtable *hash, data_save = node; hlist_del_rcu(node); + atomic_inc(&hash->generation); break; } spin_unlock_bh(&hash->list_locks[index]);