Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions portsyncd/linksync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "dbconnector.h"
#include "producerstatetable.h"
#include "tokenize.h"
#include "exec.h"

#include "linkcache.h"
#include "portsyncd/linksync.h"
Expand All @@ -28,6 +29,13 @@ const string LAG_PREFIX = "PortChannel";
extern set<string> g_portSet;
extern bool g_init;

struct if_nameindex
{
unsigned int if_index;
char *if_name;
};
extern "C" { extern struct if_nameindex *if_nameindex (void) __THROW; }

LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
m_portTableProducer(appl_db, APP_PORT_TABLE_NAME),
m_portTable(appl_db, APP_PORT_TABLE_NAME),
Expand All @@ -49,6 +57,37 @@ LinkSync::LinkSync(DBConnector *appl_db, DBConnector *state_db) :
}
}
}

struct if_nameindex *if_ni, *idx_p;
if_ni = if_nameindex();
if (if_ni == NULL)
{
return;
}

for (idx_p = if_ni; ! (idx_p->if_index == 0 && idx_p->if_name == NULL); idx_p++)
{
string key = idx_p->if_name;
if (key.compare(0, INTFS_PREFIX.length(), INTFS_PREFIX))
{
continue;
}

m_ifindexOldNameMap[idx_p->if_index] = key;

//Bring down the existing kernel interfaces before notifying ConfigDone
string cmd, res;
cout << "Executing ip link set " << key << " down - ifindex " << idx_p->if_index << endl;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use swss_log

cmd = "ip link set " + key + " down ";
try
{
swss::exec(cmd, res);
}
catch (...)
{
// Ignore error in this flow ;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should log error here.

}
}
}

void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
Expand Down Expand Up @@ -105,16 +144,9 @@ void LinkSync::onMsg(int nlmsg_type, struct nl_object *obj)
* Fix to ignore this and any further messages for this ifindex
*/

static std::map<unsigned int, std::string> m_ifindexOldNameMap;
if (m_ifindexNameMap.find(ifindex) == m_ifindexNameMap.end())
{
if (master)
{
m_ifindexOldNameMap[ifindex] = key;
SWSS_LOG_INFO("nlmsg type:%d Ignoring for %d, master %d", nlmsg_type, ifindex, master);
return;
}
else if (m_ifindexOldNameMap.find(ifindex) != m_ifindexOldNameMap.end())
if (m_ifindexOldNameMap.find(ifindex) != m_ifindexOldNameMap.end())
{
if (m_ifindexOldNameMap[ifindex] == key)
{
Expand Down
1 change: 1 addition & 0 deletions portsyncd/linksync.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LinkSync : public NetMsg
Table m_portTable, m_statePortTable;

std::map<unsigned int, std::string> m_ifindexNameMap;
std::map<unsigned int, std::string> m_ifindexOldNameMap;
};

}
Expand Down