summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroopa <roopa@cumulusnetworks.com>2012-12-20 18:32:00 -0800
committerThomas Graf <tgraf@suug.ch>2012-12-21 13:30:21 +0100
commit96bb7c9a4cdd10a2665c0f56120943e79e33c560 (patch)
treee868d385a5eb891dcbb4b9cf5d35d4cf2011e318
parent91ab1bea5eb8737c19256c04306afa4d3364344e (diff)
downloadlibnl-96bb7c9a4cdd10a2665c0f56120943e79e33c560.tar.gz
cache pickup: Avoid duplicates during cache pickup
This patch adds search and replace/update functionality to cache pickup_cb. This change is required to avoid duplicates getting into the cache during pickup. Also helps updating existing objects during cache pickup. We have seen this in cases of ipv6 equal cost multipath routes changes v1 to v2: - Updated documentation Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
-rw-r--r--lib/cache.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/cache.c b/lib/cache.c
index 36c45e1..883aa51 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -696,7 +696,21 @@ static int __cache_pickup(struct nl_sock *sk, struct nl_cache *cache,
static int pickup_cb(struct nl_object *c, struct nl_parser_param *p)
{
- return nl_cache_add((struct nl_cache *) p->pp_arg, c);
+ struct nl_cache *cache = (struct nl_cache *)p->pp_arg;
+ struct nl_object *old;
+
+ old = nl_cache_search(cache, c);
+ if (old) {
+ if (nl_object_update(old, c) == 0) {
+ nl_object_put(old);
+ return 0;
+ }
+
+ nl_cache_remove(old);
+ nl_object_put(old);
+ }
+
+ return nl_cache_add(cache, c);
}
/**
@@ -705,7 +719,10 @@ static int pickup_cb(struct nl_object *c, struct nl_parser_param *p)
* @arg cache Cache to put items into.
*
* Waits for netlink messages to arrive, parses them and puts them into
- * the specified cache.
+ * the specified cache. If an old object with same key attributes is
+ * present in the cache, it is replaced with the new object.
+ * If the old object type supports an update operation, an update is
+ * attempted before a replace.
*
* @return 0 on success or a negative error code.
*/
@@ -889,7 +906,10 @@ errout:
* @arg msg netlink message
*
* Parses a netlink message by calling the cache specific message parser
- * and adds the new element to the cache.
+ * and adds the new element to the cache. If an old object with same key
+ * attributes is present in the cache, it is replaced with the new object.
+ * If the old object type supports an update operation, an update is
+ * attempted before a replace.
*
* @return 0 or a negative error code.
*/