[PATCH] link: Fall back to global provisioned link cache if object is not a cache resident
Thomas Graf
tgraf at suug.ch
Sat Nov 9 04:14:25 EST 2013
... if that fails, print ifindices directly.
Reported-by: Dan Williams <dcbw at redhat.com>
Signed-off-by: Thomas Graf <tgraf at suug.ch>
---
lib/route/link.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/lib/route/link.c b/lib/route/link.c
index 5733b29..6c99e22 100644
--- a/lib/route/link.c
+++ b/lib/route/link.c
@@ -650,6 +650,12 @@ static void link_dump_line(struct nl_object *obj, struct nl_dump_params *p)
char buf[128];
struct nl_cache *cache = obj->ce_cache;
struct rtnl_link *link = (struct rtnl_link *) obj;
+ int fetched_cache = 0;
+
+ if (!cache) {
+ cache = nl_cache_mngt_require_safe("route/link");
+ fetched_cache = 1;
+ }
nl_dump_line(p, "%s %s ", link->l_name,
nl_llproto2str(link->l_arptype, buf, sizeof(buf)));
@@ -658,10 +664,13 @@ static void link_dump_line(struct nl_object *obj, struct nl_dump_params *p)
nl_dump(p, "%s ", nl_addr2str(link->l_addr, buf, sizeof(buf)));
if (link->ce_mask & LINK_ATTR_MASTER) {
- struct rtnl_link *master = rtnl_link_get(cache, link->l_master);
- nl_dump(p, "master %s ", master ? master->l_name : "inv");
- if (master)
- rtnl_link_put(master);
+ if (cache) {
+ struct rtnl_link *master = rtnl_link_get(cache, link->l_master);
+ nl_dump(p, "master %s ", master ? master->l_name : "inv");
+ if (master)
+ rtnl_link_put(master);
+ } else
+ nl_dump(p, "master %d ", link->l_master);
}
rtnl_link_flags2str(link->l_flags, buf, sizeof(buf));
@@ -669,10 +678,13 @@ static void link_dump_line(struct nl_object *obj, struct nl_dump_params *p)
nl_dump(p, "<%s> ", buf);
if (link->ce_mask & LINK_ATTR_LINK) {
- struct rtnl_link *ll = rtnl_link_get(cache, link->l_link);
- nl_dump(p, "slave-of %s ", ll ? ll->l_name : "NONE");
- if (ll)
- rtnl_link_put(ll);
+ if (cache) {
+ struct rtnl_link *ll = rtnl_link_get(cache, link->l_link);
+ nl_dump(p, "slave-of %s ", ll ? ll->l_name : "NONE");
+ if (ll)
+ rtnl_link_put(ll);
+ } else
+ nl_dump(p, "slave-of %d ", link->l_link);
}
if (link->ce_mask & LINK_ATTR_GROUP)
@@ -684,6 +696,9 @@ static void link_dump_line(struct nl_object *obj, struct nl_dump_params *p)
do_foreach_af(link, af_dump_line, p);
nl_dump(p, "\n");
+
+ if (fetched_cache)
+ nl_cache_put(cache);
}
static void link_dump_details(struct nl_object *obj, struct nl_dump_params *p)
--
1.8.3.1
More information about the libnl
mailing list