summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2018-10-30 17:01:25 -0400
committerSimon Wunderlich <sw@simonwunderlich.de>2018-11-12 04:41:51 -0500
commit05abd7bcc9cdbedf9deff27fe0766c70c4f2ae0d (patch)
treec389b27c0b16e602363268f48f34f0188e1d912f
parentfb69be697916a2d0a9badcdef7f20fcfad1233bc (diff)
batman-adv: Store modification counter via hash helpers
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 <mschiffer@universe-factory.net> Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
-rw-r--r--net/batman-adv/hash.c2
-rw-r--r--net/batman-adv/hash.h6
2 files changed, 8 insertions, 0 deletions
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c
index 7b49e4001778..9194f4d891b1 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)
32 INIT_HLIST_HEAD(&hash->table[i]); 32 INIT_HLIST_HEAD(&hash->table[i]);
33 spin_lock_init(&hash->list_locks[i]); 33 spin_lock_init(&hash->list_locks[i]);
34 } 34 }
35
36 atomic_set(&hash->generation, 0);
35} 37}
36 38
37/** 39/**
diff --git a/net/batman-adv/hash.h b/net/batman-adv/hash.h
index 9490a7ca2ba6..0e36fa1c7c3e 100644
--- a/net/batman-adv/hash.h
+++ b/net/batman-adv/hash.h
@@ -21,6 +21,7 @@
21 21
22#include "main.h" 22#include "main.h"
23 23
24#include <linux/atomic.h>
24#include <linux/compiler.h> 25#include <linux/compiler.h>
25#include <linux/list.h> 26#include <linux/list.h>
26#include <linux/rculist.h> 27#include <linux/rculist.h>
@@ -58,6 +59,9 @@ struct batadv_hashtable {
58 59
59 /** @size: size of hashtable */ 60 /** @size: size of hashtable */
60 u32 size; 61 u32 size;
62
63 /** @generation: current (generation) sequence number */
64 atomic_t generation;
61}; 65};
62 66
63/* allocates and clears the hash */ 67/* allocates and clears the hash */
@@ -112,6 +116,7 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash,
112 116
113 /* no duplicate found in list, add new element */ 117 /* no duplicate found in list, add new element */
114 hlist_add_head_rcu(data_node, head); 118 hlist_add_head_rcu(data_node, head);
119 atomic_inc(&hash->generation);
115 120
116 ret = 0; 121 ret = 0;
117 122
@@ -154,6 +159,7 @@ static inline void *batadv_hash_remove(struct batadv_hashtable *hash,
154 159
155 data_save = node; 160 data_save = node;
156 hlist_del_rcu(node); 161 hlist_del_rcu(node);
162 atomic_inc(&hash->generation);
157 break; 163 break;
158 } 164 }
159 spin_unlock_bh(&hash->list_locks[index]); 165 spin_unlock_bh(&hash->list_locks[index]);