From 516536625fb6bd3b3d28cf4bc47b29e9b352cf30 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Sat, 21 Apr 2012 15:48:37 +0200 Subject: [PATCH] cache_mngr: Provide nl_cache_mngr_info() to pring cache manager details Useful for debugging and testing --- include/netlink/cache.h | 2 ++ lib/cache_mngr.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/netlink/cache.h b/include/netlink/cache.h index e42f692..1e2bb9d 100644 --- a/include/netlink/cache.h +++ b/include/netlink/cache.h @@ -127,6 +127,8 @@ extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *); extern int nl_cache_mngr_poll(struct nl_cache_mngr *, int); extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *); +extern void nl_cache_mngr_info(struct nl_cache_mngr *, + struct nl_dump_params *); extern void nl_cache_mngr_free(struct nl_cache_mngr *); #ifdef __cplusplus diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c index 9388f40..15b545d 100644 --- a/lib/cache_mngr.c +++ b/lib/cache_mngr.c @@ -367,6 +367,48 @@ int nl_cache_mngr_data_ready(struct nl_cache_mngr *mngr) return nread; } +/** + * Print information about cache manager + * @arg mngr Cache manager + * @arg p Dumping parameters + * + * Prints information about the cache manager including all managed caches. + * + * @note This is a debugging function. + */ +void nl_cache_mngr_info(struct nl_cache_mngr *mngr, struct nl_dump_params *p) +{ + char buf[128]; + int i; + + nl_dump_line(p, "cache-manager <%p>\n", mngr); + nl_dump_line(p, " .protocol = %s\n", + nl_nlfamily2str(mngr->cm_protocol, buf, sizeof(buf))); + nl_dump_line(p, " .flags = %#x\n", mngr->cm_flags); + nl_dump_line(p, " .nassocs = %u\n", mngr->cm_nassocs); + nl_dump_line(p, " .sock = <%p>\n", mngr->cm_sock); + + for (i = 0; i < mngr->cm_nassocs; i++) { + struct nl_cache_assoc *assoc = &mngr->cm_assocs[i]; + + if (assoc->ca_cache) { + nl_dump_line(p, " .cache[%d] = <%p> {\n", i, assoc->ca_cache); + nl_dump_line(p, " .name = %s\n", assoc->ca_cache->c_ops->co_name); + nl_dump_line(p, " .change_func = <%p>\n", assoc->ca_change); + nl_dump_line(p, " .change_data = <%p>\n", assoc->ca_change_data); + nl_dump_line(p, " .nitems = %u\n", nl_cache_nitems(assoc->ca_cache)); + nl_dump_line(p, " .objects = {\n"); + + p->dp_prefix += 6; + nl_cache_dump(assoc->ca_cache, p); + p->dp_prefix -= 6; + + nl_dump_line(p, " }\n"); + nl_dump_line(p, " }\n"); + } + } +} + /** * Free cache manager and all caches. * @arg mngr Cache manager.