batman-adv: remove extra layer between hash and hash element - hash bucket
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
#ifndef _NET_BATMAN_ADV_ORIGINATOR_H_
|
||||
#define _NET_BATMAN_ADV_ORIGINATOR_H_
|
||||
|
||||
#include "hash.h"
|
||||
|
||||
int originator_init(struct bat_priv *bat_priv);
|
||||
void originator_free(struct bat_priv *bat_priv);
|
||||
void purge_orig_ref(struct bat_priv *bat_priv);
|
||||
@@ -38,8 +40,10 @@ int orig_hash_del_if(struct batman_if *batman_if, int max_if_num);
|
||||
|
||||
|
||||
/* returns 1 if they are the same originator */
|
||||
static inline int compare_orig(void *data1, void *data2)
|
||||
static inline int compare_orig(struct hlist_node *node, void *data2)
|
||||
{
|
||||
void *data1 = container_of(node, struct orig_node, hash_entry);
|
||||
|
||||
return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
@@ -64,4 +68,33 @@ static inline int choose_orig(void *data, int32_t size)
|
||||
return hash % size;
|
||||
}
|
||||
|
||||
static inline struct orig_node *orig_hash_find(struct bat_priv *bat_priv,
|
||||
void *data)
|
||||
{
|
||||
struct hashtable_t *hash = bat_priv->orig_hash;
|
||||
struct hlist_head *head;
|
||||
struct hlist_node *node;
|
||||
struct orig_node *orig_node, *orig_node_tmp = NULL;
|
||||
int index;
|
||||
|
||||
if (!hash)
|
||||
return NULL;
|
||||
|
||||
index = choose_orig(data, hash->size);
|
||||
head = &hash->table[index];
|
||||
|
||||
rcu_read_lock();
|
||||
hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
|
||||
if (!compare_eth(orig_node, data))
|
||||
continue;
|
||||
|
||||
orig_node_tmp = orig_node;
|
||||
kref_get(&orig_node_tmp->refcount);
|
||||
break;
|
||||
}
|
||||
rcu_read_unlock();
|
||||
|
||||
return orig_node_tmp;
|
||||
}
|
||||
|
||||
#endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */
|
||||
|
Reference in New Issue
Block a user