Commit 05abd7bc authored by Sven Eckelmann's avatar Sven Eckelmann Committed by Simon Wunderlich

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: default avatarMatthias Schiffer <mschiffer@universe-factory.net>
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
Signed-off-by: default avatarSimon Wunderlich <sw@simonwunderlich.de>
parent fb69be69
...@@ -32,6 +32,8 @@ static void batadv_hash_init(struct batadv_hashtable *hash) ...@@ -32,6 +32,8 @@ static void batadv_hash_init(struct batadv_hashtable *hash)
INIT_HLIST_HEAD(&hash->table[i]); INIT_HLIST_HEAD(&hash->table[i]);
spin_lock_init(&hash->list_locks[i]); spin_lock_init(&hash->list_locks[i]);
} }
atomic_set(&hash->generation, 0);
} }
/** /**
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "main.h" #include "main.h"
#include <linux/atomic.h>
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/rculist.h> #include <linux/rculist.h>
...@@ -58,6 +59,9 @@ struct batadv_hashtable { ...@@ -58,6 +59,9 @@ struct batadv_hashtable {
/** @size: size of hashtable */ /** @size: size of hashtable */
u32 size; u32 size;
/** @generation: current (generation) sequence number */
atomic_t generation;
}; };
/* allocates and clears the hash */ /* allocates and clears the hash */
...@@ -112,6 +116,7 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash, ...@@ -112,6 +116,7 @@ static inline int batadv_hash_add(struct batadv_hashtable *hash,
/* no duplicate found in list, add new element */ /* no duplicate found in list, add new element */
hlist_add_head_rcu(data_node, head); hlist_add_head_rcu(data_node, head);
atomic_inc(&hash->generation);
ret = 0; ret = 0;
...@@ -154,6 +159,7 @@ static inline void *batadv_hash_remove(struct batadv_hashtable *hash, ...@@ -154,6 +159,7 @@ static inline void *batadv_hash_remove(struct batadv_hashtable *hash,
data_save = node; data_save = node;
hlist_del_rcu(node); hlist_del_rcu(node);
atomic_inc(&hash->generation);
break; break;
} }
spin_unlock_bh(&hash->list_locks[index]); spin_unlock_bh(&hash->list_locks[index]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment