diff options
author | Marek Lindner <lindner_marek@yahoo.de> | 2011-02-18 07:28:09 -0500 |
---|---|---|
committer | Marek Lindner <lindner_marek@yahoo.de> | 2011-03-05 06:52:00 -0500 |
commit | 7aadf889e897155c45cda230d2a6701ad1fbff61 (patch) | |
tree | 4a31df411c29844afe25ccde17d2ff9e618241c1 /net/batman-adv/originator.h | |
parent | 39901e716275da4e831b40f9e45a1b61d6a776dc (diff) |
batman-adv: remove extra layer between hash and hash element - hash bucket
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv/originator.h')
-rw-r--r-- | net/batman-adv/originator.h | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/net/batman-adv/originator.h b/net/batman-adv/originator.h index 84d96e2eea47..b4b9a09259fd 100644 --- a/net/batman-adv/originator.h +++ b/net/batman-adv/originator.h | |||
@@ -22,6 +22,8 @@ | |||
22 | #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_ | 22 | #ifndef _NET_BATMAN_ADV_ORIGINATOR_H_ |
23 | #define _NET_BATMAN_ADV_ORIGINATOR_H_ | 23 | #define _NET_BATMAN_ADV_ORIGINATOR_H_ |
24 | 24 | ||
25 | #include "hash.h" | ||
26 | |||
25 | int originator_init(struct bat_priv *bat_priv); | 27 | int originator_init(struct bat_priv *bat_priv); |
26 | void originator_free(struct bat_priv *bat_priv); | 28 | void originator_free(struct bat_priv *bat_priv); |
27 | void purge_orig_ref(struct bat_priv *bat_priv); | 29 | 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); | |||
38 | 40 | ||
39 | 41 | ||
40 | /* returns 1 if they are the same originator */ | 42 | /* returns 1 if they are the same originator */ |
41 | static inline int compare_orig(void *data1, void *data2) | 43 | static inline int compare_orig(struct hlist_node *node, void *data2) |
42 | { | 44 | { |
45 | void *data1 = container_of(node, struct orig_node, hash_entry); | ||
46 | |||
43 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); | 47 | return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); |
44 | } | 48 | } |
45 | 49 | ||
@@ -64,4 +68,33 @@ static inline int choose_orig(void *data, int32_t size) | |||
64 | return hash % size; | 68 | return hash % size; |
65 | } | 69 | } |
66 | 70 | ||
71 | static inline struct orig_node *orig_hash_find(struct bat_priv *bat_priv, | ||
72 | void *data) | ||
73 | { | ||
74 | struct hashtable_t *hash = bat_priv->orig_hash; | ||
75 | struct hlist_head *head; | ||
76 | struct hlist_node *node; | ||
77 | struct orig_node *orig_node, *orig_node_tmp = NULL; | ||
78 | int index; | ||
79 | |||
80 | if (!hash) | ||
81 | return NULL; | ||
82 | |||
83 | index = choose_orig(data, hash->size); | ||
84 | head = &hash->table[index]; | ||
85 | |||
86 | rcu_read_lock(); | ||
87 | hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) { | ||
88 | if (!compare_eth(orig_node, data)) | ||
89 | continue; | ||
90 | |||
91 | orig_node_tmp = orig_node; | ||
92 | kref_get(&orig_node_tmp->refcount); | ||
93 | break; | ||
94 | } | ||
95 | rcu_read_unlock(); | ||
96 | |||
97 | return orig_node_tmp; | ||
98 | } | ||
99 | |||
67 | #endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */ | 100 | #endif /* _NET_BATMAN_ADV_ORIGINATOR_H_ */ |