Skip to content

Commit a0bb6ec

Browse files
committed
[portmgrd] prevent runtime exception (crash) in setting MTU on portchannel member (PR sonic-net#3432)
Do not attempt to set the MTU directly on PortChannel members as it will likely fail. The MTU gets inherited as part of the PortChannel. Signed-off-by: Brad House (@bradh352)
1 parent f8bd3a1 commit a0bb6ec

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

cfgmgr/portmgr.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,28 @@ PortMgr::PortMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb, c
2222
{
2323
}
2424

25+
bool PortMgr::isLag(const std::string &port)
26+
{
27+
SWSS_LOG_ENTER();
28+
29+
vector<string> keys;
30+
m_cfgLagMemberTable.getKeys(keys);
31+
32+
for (auto key: keys)
33+
{
34+
auto tokens = tokenize(key, config_db_key_delimiter);
35+
auto lag = tokens[0];
36+
auto member = tokens[1];
37+
38+
if (port == member)
39+
{
40+
return true;
41+
}
42+
}
43+
44+
return false;
45+
}
46+
2547
bool PortMgr::setPortMtu(const string &alias, const string &mtu)
2648
{
2749
stringstream cmd;
@@ -128,6 +150,7 @@ void PortMgr::doSendToIngressPortTask(Consumer &consumer)
128150

129151
}
130152

153+
131154
void PortMgr::doTask(Consumer &consumer)
132155
{
133156
SWSS_LOG_ENTER();
@@ -221,14 +244,18 @@ void PortMgr::doTask(Consumer &consumer)
221244

222245
if (!mtu.empty())
223246
{
224-
setPortMtu(alias, mtu);
225-
SWSS_LOG_NOTICE("Configure %s MTU to %s", alias.c_str(), mtu.c_str());
247+
if (isLag(alias)) {
248+
SWSS_LOG_NOTICE("Skipping Configure %s MTU to %s as interface is part of a PortChannel", alias.c_str(), mtu.c_str());
249+
} else {
250+
SWSS_LOG_NOTICE("Configure %s MTU to %s", alias.c_str(), mtu.c_str());
251+
setPortMtu(alias, mtu);
252+
}
226253
}
227254

228255
if (!admin_status.empty())
229256
{
230-
setPortAdminStatus(alias, admin_status == "up");
231257
SWSS_LOG_NOTICE("Configure %s admin status to %s", alias.c_str(), admin_status.c_str());
258+
setPortAdminStatus(alias, admin_status == "up");
232259
}
233260
}
234261
else if (op == DEL_COMMAND)

cfgmgr/portmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class PortMgr : public Orch
3737
bool setPortMtu(const std::string &alias, const std::string &mtu);
3838
bool setPortAdminStatus(const std::string &alias, const bool up);
3939
bool isPortStateOk(const std::string &alias);
40+
bool isLag(const std::string &port);
4041
};
4142

4243
}

0 commit comments

Comments
 (0)