Skip to content

Commit

Permalink
[netlink]refill netlink cache when failing to get the link object by …
Browse files Browse the repository at this point in the history
…name. (#506)

**Why I did it**
The getLinkByName may fail because of the outdated netlink cache

**How I did it**
Refill the netlink cache when we fail to get link object.
  • Loading branch information
wangshengjun authored Jul 29, 2021
1 parent 22b8715 commit f89b2ac
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/linkcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,13 @@ string LinkCache::ifindexToName(int ifindex)

struct rtnl_link* LinkCache::getLinkByName(const char *name)
{
return rtnl_link_get_by_name(m_link_cache, name);
struct rtnl_link* link = NULL;
link = rtnl_link_get_by_name(m_link_cache, name);
if(NULL == link)
{
/* Trying to refill cache */
nl_cache_refill(m_nl_sock ,m_link_cache);
link = rtnl_link_get_by_name(m_link_cache, name);
}
return link;
}

0 comments on commit f89b2ac

Please sign in to comment.