[RFC PATCH 5/5] Make cache manager event handling continue looking if a cache returned NL_SKIP
roopa at cumulusnetworks.com
roopa at cumulusnetworks.com
Mon Nov 5 08:37:38 EST 2012
From: roopa <roopa at cumulusnetworks.com>
Today libnl event_input only looks through the first cache that supports
the input msgtype.
This patch makes cache manager continue looking through caches if a particular
cache returned NL_SKIP. Also changes include_cb to return NL_SKIP if the
cache event_filter returns anything other than NL_OK (This is required to
support the above)
This change is required to support more than one cache handing the
same msg type. In the current context it is bridge_link and link caches.
link and bridge link cache handle the same msg types but with different
families. The link cache cache_include returns NL_SKIP if it receives
a msg of family AF_BRIDGE. With this patch cache manager will continue
to look through more caches that support the msgtype.
Signed-off-by: Roopa Prabhu <roopa at cumulusnetworks.com>
Reviewed-by: Wilson Kok <wkok at cumulusnetworks.com>
Reviewed-by: Nolan Leake <nolan at cumulusnetworks.com>
Reviewed-by: Shrijeet Mukherjee <shm at cumulusnetworks.com>
---
lib/cache_mngr.c | 36 +++++++++++++++++++++++++-----------
1 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c
index cdf2b7b..856c6e8 100644
--- a/lib/cache_mngr.c
+++ b/lib/cache_mngr.c
@@ -46,6 +46,7 @@ static int include_cb(struct nl_object *obj, struct nl_parser_param *p)
{
struct nl_cache_assoc *ca = p->pp_arg;
struct nl_cache_ops *ops = ca->ca_cache->c_ops;
+ int err;
NL_DBG(2, "Including object %p into cache %p\n", obj, ca->ca_cache);
#ifdef NL_DEBUG
@@ -54,8 +55,8 @@ static int include_cb(struct nl_object *obj, struct nl_parser_param *p)
#endif
if (ops->co_event_filter)
- if (ops->co_event_filter(ca->ca_cache, obj) != NL_OK)
- return 0;
+ if ((err = ops->co_event_filter(ca->ca_cache, obj)) != NL_OK)
+ return err;
if (ops->co_include_event)
return ops->co_include_event(ca->ca_cache, obj, ca->ca_change,
@@ -71,6 +72,7 @@ static int event_input(struct nl_msg *msg, void *arg)
int type = nlmsg_hdr(msg)->nlmsg_type;
struct nl_cache_ops *ops;
int i, n;
+ int err;
struct nl_parser_param p = {
.pp_cb = include_cb,
};
@@ -89,19 +91,31 @@ static int event_input(struct nl_msg *msg, void *arg)
if (mngr->cm_assocs[i].ca_cache) {
ops = mngr->cm_assocs[i].ca_cache->c_ops;
for (n = 0; ops->co_msgtypes[n].mt_id >= 0; n++)
- if (ops->co_msgtypes[n].mt_id == type)
- goto found;
+ if (ops->co_msgtypes[n].mt_id == type) {
+ NL_DBG(2, "Associated message %p to cache %p\n",
+ msg, mngr->cm_assocs[i].ca_cache);
+
+ p.pp_arg = &mngr->cm_assocs[i];
+
+ err = nl_cache_parse(ops, NULL,
+ nlmsg_hdr(msg), &p);
+ if (err == NL_SKIP) {
+ /*
+ * If this cache skipped the msg, Look for
+ * the msg type in other caches
+ */
+ NL_DBG(2, "Skip associating message %p to "
+ "cache %p\n", msg,
+ mngr->cm_assocs[i].ca_cache);
+ continue;
+ }
+ else
+ return err;
+ }
}
}
return NL_SKIP;
-
-found:
- NL_DBG(2, "Associated message %p to cache %p\n",
- msg, mngr->cm_assocs[i].ca_cache);
- p.pp_arg = &mngr->cm_assocs[i];
-
- return nl_cache_parse(ops, NULL, nlmsg_hdr(msg), &p);
}
/**
--
1.7.2.5
More information about the libnl
mailing list