From 62927865480946593771c0af0fd78247b6ee46fd Mon Sep 17 00:00:00 2001 From: Shuotian Cheng Date: Tue, 13 Nov 2018 16:15:38 -0800 Subject: [PATCH] [teammgrd]: Add kernel master check for port before enslaving (#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 --- cfgmgr/teammgr.cpp | 15 +++++++++++++-- cfgmgr/teammgr.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cfgmgr/teammgr.cpp b/cfgmgr/teammgr.cpp index 5d526e79df13..8d02dbd785d2 100644 --- a/cfgmgr/teammgr.cpp +++ b/cfgmgr/teammgr.cpp @@ -11,8 +11,9 @@ #include #include -#include #include +#include +#include using namespace std; using namespace swss; @@ -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(); @@ -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) { diff --git a/cfgmgr/teammgr.h b/cfgmgr/teammgr.h index 8ffb6de0e0db..73c0010f8728 100644 --- a/cfgmgr/teammgr.h +++ b/cfgmgr/teammgr.h @@ -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&);