summaryrefslogtreecommitdiffstats
path: root/lib/cache.c
diff options
context:
space:
mode:
authorRoopa Prabhu <roopa@cumulusnetworks.com>2016-06-18 22:30:06 (GMT)
committerThomas Haller <thaller@redhat.com>2016-07-08 10:02:07 (GMT)
commit1db12c9e3208c98332cf169eb689a985d77c9a05 (patch)
tree16d8aa47c593f4794fb97ee21c0cfff20bfc0f67 /lib/cache.c
parentb7d458c1939913c46b32c7643b412767b87d98c2 (diff)
downloadlibnl-1db12c9e3208c98332cf169eb689a985d77c9a05.zip
libnl-1db12c9e3208c98332cf169eb689a985d77c9a05.tar.gz
libnl-1db12c9e3208c98332cf169eb689a985d77c9a05.tar.bz2
cache: modify nl_cache_search to look at cache provided attributes for search
This patch adds a new cache operation co_cache_search_attrs_get to request for attributes to use in the search. This gives the cache an opportunity to use search attributes based on netlink message flags. This is mainly to give the route cache an ability to decide on the cache inclusion depending on the netlink header flags like NLM_F_APPEND and NLM_F_REPLACE. Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Diffstat (limited to 'lib/cache.c')
-rw-r--r--lib/cache.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/cache.c b/lib/cache.c
index ba5fa72..960459d 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -1043,6 +1043,21 @@ restart:
* @name Utillities
* @{
*/
+static struct nl_object *__cache_fast_lookup_mask(struct nl_cache *cache,
+ struct nl_object *needle,
+ uint32_t mask)
+{
+ struct nl_object *obj;
+
+ obj = nl_hash_table_lookup_mask(cache->hashtable, needle, mask);
+ if (obj) {
+ nl_object_get(obj);
+ return obj;
+ }
+
+ return NULL;
+}
+
static struct nl_object *__cache_fast_lookup(struct nl_cache *cache,
struct nl_object *needle)
{
@@ -1061,6 +1076,40 @@ static struct nl_object *__cache_fast_lookup(struct nl_cache *cache,
* Search object in cache
* @arg cache Cache
* @arg needle Object to look for.
+ * @arg mask Attribute mask to use during object comparision
+ *
+ * Searches the cache for an object which matches the object \p needle.
+ * The function nl_object_diff_mask() is used to determine if the
+ * objects match. If a matching object is found, the reference counter
+ * is incremented and the object is returned.
+ *
+ * Therefore, if an object is returned, the reference to the object
+ * must be returned by calling nl_object_put() after usage.
+ *
+ * @return Reference to object or NULL if not found.
+ */
+struct nl_object *nl_cache_search_mask(struct nl_cache *cache,
+ struct nl_object *needle, uint32_t mask)
+{
+ struct nl_object *obj;
+
+ if (cache->hashtable)
+ return __cache_fast_lookup_mask(cache, needle, mask);
+
+ nl_list_for_each_entry(obj, &cache->c_items, ce_list) {
+ if (!nl_object_diff_mask(obj, needle, mask)) {
+ nl_object_get(obj);
+ return obj;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Search object in cache
+ * @arg cache Cache
+ * @arg needle Object to look for.
*
* Searches the cache for an object which matches the object \p needle.
* The function nl_object_identical() is used to determine if the
@@ -1076,6 +1125,13 @@ struct nl_object *nl_cache_search(struct nl_cache *cache,
struct nl_object *needle)
{
struct nl_object *obj;
+ uint32_t mask;
+
+ if (cache->c_ops->co_cache_search_attrs_get) {
+ mask = cache->c_ops->co_cache_search_attrs_get(cache, needle);
+ if (mask)
+ return nl_cache_search_mask(cache, needle, mask);
+ }
if (cache->hashtable)
return __cache_fast_lookup(cache, needle);