summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-06-29 10:14:05 (GMT)
committerThomas Haller <thaller@redhat.com>2016-07-08 10:02:07 (GMT)
commit13dec9ba95cd61bf251345f31ed181983107d9b1 (patch)
treec367a3bab5a490389a76d803a5a72956052f9e5b
parentfa2b73183bbb5bb13117ff3cfe9f87d22416692a (diff)
downloadlibnl-13dec9ba95cd61bf251345f31ed181983107d9b1.zip
libnl-13dec9ba95cd61bf251345f31ed181983107d9b1.tar.gz
libnl-13dec9ba95cd61bf251345f31ed181983107d9b1.tar.bz2
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 <thaller@redhat.com>
-rw-r--r--include/netlink-private/cache-api.h2
-rw-r--r--lib/cache.c4
-rw-r--r--lib/hashtable.c8
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);