[PATCH] cache pickup: Avoid duplicates during cache pickup

roopa at cumulusnetworks.com roopa at cumulusnetworks.com
Thu Dec 13 00:45:59 EST 2012


From: roopa <roopa at cumulusnetworks.com>

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

Signed-off-by: Roopa Prabhu <roopa at cumulusnetworks.com>

---
 lib/cache.c |   16 +++++++++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/lib/cache.c b/lib/cache.c
index 8ba3d5b..283f1ac 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);
 }
 
 /**
-- 
1.7.2.5




More information about the libnl mailing list