Skip to content

Commit 8f4d3c4

Browse files
prsunnylguohan
authored andcommitted
Ignore "old" interface netlink messages during swss restart (sonic-net#389)
1 parent 4f2c3cd commit 8f4d3c4

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

portsyncd/linksync.cpp

+31-3
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,43 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
9090
nlmsg_type, key.c_str(), admin, oper, addrStr, ifindex, master);
9191
}
9292

93-
/* Insert or update the ifindex to key map */
94-
m_ifindexNameMap[ifindex] = key;
95-
9693
/* teamd instances are dealt in teamsyncd */
9794
if (type && !strcmp(type, TEAM_DRV_NAME))
9895
{
9996
return;
10097
}
10198

99+
/* In the event of swss restart, it is possible to get netlink messages during bridge
100+
* delete, interface delete etc which are part of cleanup. These netlink messages for
101+
* the front-panel interface must not be published or it will update the statedb with
102+
* old interface info and result in subsequent failures. A new interface creation shall
103+
* not have master or admin status iff_up. So if the first netlink message comes with these
104+
* values set, it is considered to be happening during a cleanup process.
105+
* Fix to ignore this and any further messages for this ifindex
106+
*/
107+
108+
static std::map<unsigned int, std::string> m_ifindexOldNameMap;
109+
if (m_ifindexNameMap.find(ifindex) == m_ifindexNameMap.end())
110+
{
111+
if (master)
112+
{
113+
m_ifindexOldNameMap[ifindex] = key;
114+
SWSS_LOG_INFO("nlmsg type:%d Ignoring for %d, master %d", nlmsg_type, ifindex, master);
115+
return;
116+
}
117+
else if (m_ifindexOldNameMap.find(ifindex) != m_ifindexOldNameMap.end())
118+
{
119+
if (m_ifindexOldNameMap[ifindex] == key)
120+
{
121+
SWSS_LOG_INFO("nlmsg type:%d Ignoring message for old interface %d", nlmsg_type, ifindex);
122+
return;
123+
}
124+
}
125+
}
126+
127+
/* Insert or update the ifindex to key map */
128+
m_ifindexNameMap[ifindex] = key;
129+
102130
vector<FieldValueTuple> fvVector;
103131
FieldValueTuple a("admin_status", admin ? "up" : "down");
104132
FieldValueTuple m("mtu", to_string(mtu));

0 commit comments

Comments
 (0)