Provide silent variation of nl_cache_require()
Use in addr and tc layer to avoid warnings being printed if no cache is available.
This commit is contained in:
parent
f443be6e74
commit
4cb1666fe1
4 changed files with 17 additions and 9 deletions
|
@ -107,6 +107,7 @@ extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
|
|||
extern void nl_cache_mngt_provide(struct nl_cache *);
|
||||
extern void nl_cache_mngt_unprovide(struct nl_cache *);
|
||||
extern struct nl_cache * nl_cache_mngt_require(const char *);
|
||||
extern struct nl_cache * __nl_cache_mngt_require(const char *);
|
||||
|
||||
struct nl_cache_mngr;
|
||||
|
||||
|
|
|
@ -217,6 +217,17 @@ void nl_cache_mngt_unprovide(struct nl_cache *cache)
|
|||
ops->co_major_cache = NULL;
|
||||
}
|
||||
|
||||
struct nl_cache *__nl_cache_mngt_require(const char *name)
|
||||
{
|
||||
struct nl_cache_ops *ops;
|
||||
|
||||
ops = nl_cache_ops_lookup(name);
|
||||
if (ops)
|
||||
return ops->co_major_cache;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Demand the use of a global cache
|
||||
* @arg name name of the required object type
|
||||
|
@ -229,19 +240,15 @@ void nl_cache_mngt_unprovide(struct nl_cache *cache)
|
|||
*/
|
||||
struct nl_cache *nl_cache_mngt_require(const char *name)
|
||||
{
|
||||
struct nl_cache_ops *ops;
|
||||
struct nl_cache *cache;
|
||||
|
||||
ops = nl_cache_ops_lookup(name);
|
||||
if (!ops || !ops->co_major_cache) {
|
||||
if (!(cache = __nl_cache_mngt_require(name)))
|
||||
fprintf(stderr, "Application BUG: Your application must "
|
||||
"call nl_cache_mngt_provide() and\nprovide a valid "
|
||||
"%s cache to be used for internal lookups.\nSee the "
|
||||
" API documentation for more details.\n", name);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ops->co_major_cache;
|
||||
return cache;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
|
@ -294,7 +294,7 @@ static int addr_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
|
|||
addr->ce_mask |= ADDR_ATTR_ANYCAST;
|
||||
}
|
||||
|
||||
if ((link_cache = nl_cache_mngt_require("route/link"))) {
|
||||
if ((link_cache = __nl_cache_mngt_require("route/link"))) {
|
||||
struct rtnl_link *link;
|
||||
|
||||
if ((link = rtnl_link_get(link_cache, addr->a_ifindex))) {
|
||||
|
|
|
@ -176,7 +176,7 @@ compat_xstats:
|
|||
return err;
|
||||
}
|
||||
|
||||
if ((link_cache = nl_cache_mngt_require("route/link"))) {
|
||||
if ((link_cache = __nl_cache_mngt_require("route/link"))) {
|
||||
struct rtnl_link *link;
|
||||
|
||||
if ((link = rtnl_link_get(link_cache, tc->tc_ifindex))) {
|
||||
|
|
Loading…
Add table
Reference in a new issue