Skip to content

Commit 5d4e8bb

Browse files
Pterosaurprsunny
authored andcommitted
Fix traceroute issue (sonic-net#1113)
* Add commands to ensure that the ‘mac’ doesn’t change if an interface is enslaved to this master
1 parent f354798 commit 5d4e8bb

2 files changed

Lines changed: 51 additions & 1 deletion

File tree

cfgmgr/vxlanmgr.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ using namespace swss;
2424
#define VXLAN "vxlan"
2525
#define VXLAN_IF "vxlan_if"
2626

27+
#define SWITCH "switch"
28+
#define VXLAN_ROUTER_MAC "vxlan_router_mac"
29+
2730
#define VXLAN_NAME_PREFIX "Vxlan"
2831
#define VXLAN_IF_NAME_PREFIX "Brvxlan"
2932

@@ -86,6 +89,16 @@ static int cmdAddVxlanIntoVxlanIf(const swss::VxlanMgr::VxlanInfo & info, std::s
8689
<< shellquote(info.m_vxlanIf)
8790
<< " "
8891
<< shellquote(info.m_vxlan);
92+
if (!info.m_macAddress.empty())
93+
{
94+
// Change the MAC address of Vxlan bridge interface to ensure it's same with switch's.
95+
// Otherwise it will not response traceroute packets.
96+
// ip link set dev {{VXLAN_IF}} address {{MAC_ADDRESS}}
97+
cmd << " && " IP_CMD " link set dev "
98+
<< shellquote(info.m_vxlanIf)
99+
<< " address "
100+
<< shellquote(info.m_macAddress);
101+
}
89102
return swss::exec(cmd.str(), res);
90103
}
91104

@@ -155,6 +168,7 @@ VxlanMgr::VxlanMgr(DBConnector *cfgDb, DBConnector *appDb, DBConnector *stateDb,
155168
Orch(cfgDb, tables),
156169
m_appVxlanTunnelTable(appDb, APP_VXLAN_TUNNEL_TABLE_NAME),
157170
m_appVxlanTunnelMapTable(appDb, APP_VXLAN_TUNNEL_MAP_TABLE_NAME),
171+
m_appSwitchTable(appDb, APP_SWITCH_TABLE_NAME),
158172
m_cfgVxlanTunnelTable(cfgDb, CFG_VXLAN_TUNNEL_TABLE_NAME),
159173
m_cfgVnetTable(cfgDb, CFG_VNET_TABLE_NAME),
160174
m_stateVrfTable(stateDb, STATE_VRF_TABLE_NAME),
@@ -282,6 +296,16 @@ bool VxlanMgr::doVxlanCreateTask(const KeyOpFieldsValuesTuple & t)
282296
// Suspend this message util the vrf is created
283297
return false;
284298
}
299+
300+
// If the mac address has been set
301+
auto macAddress = getVxlanRouterMacAddress();
302+
if (macAddress.first)
303+
{
304+
SWSS_LOG_DEBUG("Mac address is not ready");
305+
// Suspend this message util the mac address is set
306+
return false;
307+
}
308+
info.m_macAddress = macAddress.second;
285309

286310
auto sourceIp = std::find_if(
287311
it->second.begin(),
@@ -432,6 +456,29 @@ bool VxlanMgr::isVxlanStateOk(const std::string & vxlanName)
432456
return false;
433457
}
434458

459+
std::pair<bool, std::string> VxlanMgr::getVxlanRouterMacAddress()
460+
{
461+
std::vector<FieldValueTuple> temp;
462+
463+
if (m_appSwitchTable.get(SWITCH, temp))
464+
{
465+
auto itr = std::find_if(
466+
temp.begin(),
467+
temp.end(),
468+
[](const FieldValueTuple &fvt) { return fvt.first == VXLAN_ROUTER_MAC; });
469+
if (itr != temp.end() && !(itr->second.empty()))
470+
{
471+
SWSS_LOG_DEBUG("Mac address %s is ready", itr->second.c_str());
472+
return std::make_pair(true, itr->second);
473+
}
474+
SWSS_LOG_DEBUG("Mac address will be automatically set");
475+
return std::make_pair(true, "");
476+
}
477+
478+
SWSS_LOG_DEBUG("Mac address is not ready");
479+
return std::make_pair(false, "");
480+
}
481+
435482
bool VxlanMgr::createVxlan(const VxlanInfo & info)
436483
{
437484
SWSS_LOG_ENTER();

cfgmgr/vxlanmgr.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <map>
99
#include <memory>
1010
#include <string>
11+
#include <utility>
1112

1213
namespace swss {
1314

@@ -25,6 +26,7 @@ class VxlanMgr : public Orch
2526
std::string m_vni;
2627
std::string m_vxlan;
2728
std::string m_vxlanIf;
29+
std::string m_macAddress;
2830
} VxlanInfo;
2931
~VxlanMgr();
3032
private:
@@ -47,14 +49,15 @@ class VxlanMgr : public Orch
4749
*/
4850
bool isVrfStateOk(const std::string & vrfName);
4951
bool isVxlanStateOk(const std::string & vxlanName);
52+
std::pair<bool, std::string> getVxlanRouterMacAddress();
5053

5154
bool createVxlan(const VxlanInfo & info);
5255
bool deleteVxlan(const VxlanInfo & info);
5356

5457
void clearAllVxlanDevices();
5558

5659
ProducerStateTable m_appVxlanTunnelTable,m_appVxlanTunnelMapTable;
57-
Table m_cfgVxlanTunnelTable,m_cfgVnetTable,m_stateVrfTable,m_stateVxlanTable;
60+
Table m_cfgVxlanTunnelTable,m_cfgVnetTable,m_stateVrfTable,m_stateVxlanTable, m_appSwitchTable;
5861

5962
/*
6063
* Vxlan Tunnel Cache

0 commit comments

Comments
 (0)