From 13dec9ba95cd61bf251345f31ed181983107d9b1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 29 Jun 2016 12:14:05 +0200 Subject: hashtable: let caller decide whether to append/prepend object to hashtable nl_hash_table_add() should not ask the object whether to append/prepend. Instead, the caller should decide on that. Add an internal function _nl_hash_table_add() which accepts an @append argument. Signed-off-by: Thomas Haller --- include/netlink-private/cache-api.h | 2 ++ lib/cache.c | 4 +++- lib/hashtable.c | 8 ++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/netlink-private/cache-api.h b/include/netlink-private/cache-api.h index 7ab4bc7..2beebed 100644 --- a/include/netlink-private/cache-api.h +++ b/include/netlink-private/cache-api.h @@ -288,6 +288,8 @@ struct nl_hash_table { struct nl_hash_node **nodes; }; +int _nl_hash_table_add(struct nl_hash_table *ht, struct nl_object *obj, int append); + /** @} */ #ifdef __cplusplus diff --git a/lib/cache.c b/lib/cache.c index 960459d..f0a626c 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -438,7 +438,9 @@ static int __cache_add(struct nl_cache *cache, struct nl_object *obj) obj->ce_cache = cache; if (cache->hashtable) { - ret = nl_hash_table_add(cache->hashtable, obj); + ret = _nl_hash_table_add(cache->hashtable, obj, + (obj->ce_msgflags & NLM_F_APPEND) || + (obj->ce_flags & NL_OBJ_DUMP)); if (ret < 0) { obj->ce_cache = NULL; return ret; diff --git a/lib/hashtable.c b/lib/hashtable.c index 7652e6b..f0449b6 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -164,6 +164,11 @@ struct nl_object* nl_hash_table_lookup_mask(nl_hash_table_t *ht, */ int nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj) { + return _nl_hash_table_add(ht, obj, 0); +} + +int _nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj, int append) +{ nl_hash_node_t *node, *head; uint32_t key_hash; @@ -199,8 +204,7 @@ int nl_hash_table_add(nl_hash_table_t *ht, struct nl_object *obj) node->key_size = sizeof(uint32_t); nl_init_list_head(&node->list); - if ((obj->ce_msgflags & NLM_F_APPEND) || - (obj->ce_flags & NL_OBJ_DUMP)) + if (append) nl_list_add_tail(&node->list, &ht->nodes[key_hash]->list); else nl_list_add_head(&node->list, &ht->nodes[key_hash]->list); -- cgit v0.12