Skip to content

Commit

Permalink
[teammgrd]: Add kernel master check for port before enslaving (sonic-…
Browse files Browse the repository at this point in the history
…net#681)

Check if the port is already enslaved, and prevent extra movement
that triggers a link flap when adding the port into the port channel.

Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng authored Nov 14, 2018
1 parent a42ef4c commit 6292786
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cfgmgr/teammgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include <sstream>
#include <thread>

#include <sys/ioctl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/stat.h>

using namespace std;
using namespace swss;
Expand Down Expand Up @@ -237,6 +238,16 @@ bool TeamMgr::checkPortIffUp(const string &port)
return ifr.ifr_flags & IFF_UP;
}

bool TeamMgr::isPortEnslaved(const string &port)
{
SWSS_LOG_ENTER();

struct stat buf;
string path = "/sys/class/net/" + port + "/master";

return lstat(path.c_str(), &buf) == 0;
}

bool TeamMgr::findPortMaster(string &master, const string &port)
{
SWSS_LOG_ENTER();
Expand Down Expand Up @@ -280,7 +291,7 @@ void TeamMgr::doPortUpdateTask(Consumer &consumer)
SWSS_LOG_INFO("Received port %s state update", alias.c_str());

string lag;
if (findPortMaster(lag, alias))
if (!isPortEnslaved(alias) && findPortMaster(lag, alias))
{
if (addLagMember(lag, alias) == task_need_retry)
{
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/teammgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TeamMgr : public Orch
bool setLagAdminStatus(const string &alias, const string &admin_status);
bool setLagMtu(const string &alias, const string &mtu);

bool isPortEnslaved(const string &);
bool findPortMaster(string &, const string &);
bool checkPortIffUp(const string &);
bool isPortStateOk(const string&);
Expand Down

0 comments on commit 6292786

Please sign in to comment.