Skip to content

Commit

Permalink
[intfmgr]: Add GARP support (sonic-net#1503)
Browse files Browse the repository at this point in the history
* Get `grat_arp` value from config DB and enable kernel `arp_accept` if enabled
  • Loading branch information
theasianpianist authored and daall committed Dec 7, 2020
1 parent 69dac4d commit 0cd6f84
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions cfgmgr/intfmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,36 @@ void IntfMgr::removeSubIntfState(const string &alias)
}
}

bool IntfMgr::setIntfGratArp(const string &alias, const string &grat_arp)
{
/*
* Enable gratuitous ARP by accepting unsolicited ARP replies
*/
stringstream cmd;
string res;
string garp_enabled;

if (grat_arp == "enabled")
{
garp_enabled = "1";
}
else if (grat_arp == "disabled")
{
garp_enabled = "0";
}
else
{
SWSS_LOG_ERROR("GARP state is invalid: \"%s\"", grat_arp.c_str());
return false;
}

cmd << ECHO_CMD << " " << garp_enabled << " > /proc/sys/net/ipv4/conf/" << alias << "/arp_accept";
EXEC_WITH_ERROR_THROW(cmd.str(), res);

SWSS_LOG_INFO("ARP accept set to \"%s\" on interface \"%s\"", grat_arp.c_str(), alias.c_str());
return true;
}

bool IntfMgr::setIntfProxyArp(const string &alias, const string &proxy_arp)
{
stringstream cmd;
Expand Down Expand Up @@ -374,6 +404,7 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
string adminStatus = "";
string nat_zone = "";
string proxy_arp = "";
string grat_arp = "";

for (auto idx : data)
{
Expand All @@ -396,6 +427,10 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
{
proxy_arp = value;
}
else if (field == "grat_arp")
{
grat_arp = value;
}

if (field == "nat_zone")
{
Expand Down Expand Up @@ -474,6 +509,21 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
}
}

if (!grat_arp.empty())
{
if (!setIntfGratArp(alias, grat_arp))
{
SWSS_LOG_ERROR("Failed to set ARP accept to \"%s\" state for the \"%s\" interface", grat_arp.c_str(), alias.c_str());
return false;
}

if (!alias.compare(0, strlen(VLAN_PREFIX), VLAN_PREFIX))
{
FieldValueTuple fvTuple("grat_arp", grat_arp);
data.push_back(fvTuple);
}
}

if (!subIntfAlias.empty())
{
if (m_subIntfList.find(subIntfAlias) == m_subIntfList.end())
Expand Down
1 change: 1 addition & 0 deletions cfgmgr/intfmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class IntfMgr : public Orch
void removeSubIntfState(const std::string &alias);

bool setIntfProxyArp(const std::string &alias, const std::string &proxy_arp);
bool setIntfGratArp(const std::string &alias, const std::string &grat_arp);
};

}
Expand Down

0 comments on commit 0cd6f84

Please sign in to comment.