Skip to content

Commit d701ff8

Browse files
Pterosaurprsunny
authored andcommitted
[vxlanmgrd]: Fix for vxlanmgrd cannot correctly work after config reload (sonic-net#934)
* [vxlanmgrd]: Fix for vxlanmgrd cannot correctly work after config reload - What I did Clear old vxlan devices that were created at last time - Why I did it 1. "config reload" command will kill the swss container, which will make the vxlanmgrd loss the cache information. And to execute "ip link add xxx " command will fail after the vxlanmgrd process restart, because the vxlan device has been created. 2. The Vnet was deleted by modifying config_db.json, and then execute "config reload" command, which will kill vxlanmgrd process. And when vxlanmgrd restart again, it will cannot receive the delete message, because the redis database also was clear after "config reload". So those vxlan devices will become garbage until the kernel restart. - How I verified it Test it in Chassis topology. Signed-off-by: Ze Gan <[email protected]> * Change ip addr to ip link to reduce the output Signed-off-by: Ze Gan <[email protected]>
1 parent c72f9ab commit d701ff8

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

cfgmgr/vxlanmgr.cpp

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include <algorithm>
2+
#include <regex>
3+
#include <sstream>
4+
#include <string>
25
#include <net/if.h>
36

47
#include "logger.h"
@@ -155,6 +158,13 @@ VxlanMgr::VxlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb,
155158
m_stateVrfTable(stateDb, STATE_VRF_TABLE_NAME),
156159
m_stateVxlanTable(stateDb, STATE_VXLAN_TABLE_NAME)
157160
{
161+
// Clear old vxlan devices that were created at last time.
162+
clearAllVxlanDevices();
163+
}
164+
165+
VxlanMgr::~VxlanMgr()
166+
{
167+
clearAllVxlanDevices();
158168
}
159169

160170
void VxlanMgr::doTask(Consumer &consumer)
@@ -526,5 +536,38 @@ bool VxlanMgr::deleteVxlan(const VxlanInfo & info)
526536
return true;
527537
}
528538

529-
539+
void VxlanMgr::clearAllVxlanDevices()
540+
{
541+
std::string stdout;
542+
const std::string cmd = std::string("") + IP_CMD + " link";
543+
int ret = EXECUTE(cmd, stdout);
544+
if (ret != 0)
545+
{
546+
SWSS_LOG_ERROR("Cannot get devices by command : %s", cmd.c_str());
547+
return;
548+
}
549+
std::regex device_name_pattern("^\\d+:\\s+([^:]+)");
550+
std::smatch match_result;
551+
auto lines = tokenize(stdout, '\n');
552+
for (const std::string & line : lines)
553+
{
554+
if (!std::regex_search(line, match_result, device_name_pattern))
555+
{
556+
continue;
557+
}
558+
std::string res;
559+
std::string device_name = match_result[1];
560+
VxlanInfo info;
561+
if (device_name.find(VXLAN_NAME_PREFIX) == 0)
562+
{
563+
info.m_vxlan = device_name;
564+
cmdDeleteVxlan(info, res);
565+
}
566+
else if (device_name.find(VXLAN_IF_NAME_PREFIX) == 0)
567+
{
568+
info.m_vxlanIf = device_name;
569+
cmdDeleteVxlanIf(info, res);
570+
}
571+
}
572+
}
530573

cfgmgr/vxlanmgr.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class VxlanMgr : public Orch
2626
std::string m_vxlan;
2727
std::string m_vxlanIf;
2828
} VxlanInfo;
29-
29+
~VxlanMgr();
3030
private:
3131
void doTask(Consumer &consumer);
3232

@@ -51,6 +51,7 @@ class VxlanMgr : public Orch
5151
bool createVxlan(const VxlanInfo & info);
5252
bool deleteVxlan(const VxlanInfo & info);
5353

54+
void clearAllVxlanDevices();
5455

5556
ProducerStateTable m_appVxlanTunnelTable,m_appVxlanTunnelMapTable;
5657
Table m_cfgVxlanTunnelTable,m_cfgVnetTable,m_stateVrfTable,m_stateVxlanTable;

0 commit comments

Comments
 (0)