Skip to content

Commit 4798584

Browse files
author
Volodymyr Samotiy
authored
[proxy_arp] Implement proxy ARP feature (#1285)
* [proxy_arp] Implement proxy ARP feature Signed-off-by: Volodymyr Samotiy <[email protected]>
1 parent 727a518 commit 4798584

File tree

5 files changed

+174
-13
lines changed

5 files changed

+174
-13
lines changed

cfgmgr/intfmgr.cpp

+49-1
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,33 @@ void IntfMgr::removeSubIntfState(const string &alias)
272272
}
273273
}
274274

275+
bool IntfMgr::setIntfProxyArp(const string &alias, const string &proxy_arp)
276+
{
277+
stringstream cmd;
278+
string res;
279+
string proxy_arp_pvlan;
280+
281+
if (proxy_arp == "enabled")
282+
{
283+
proxy_arp_pvlan = "1";
284+
}
285+
else if (proxy_arp == "disabled")
286+
{
287+
proxy_arp_pvlan = "0";
288+
}
289+
else
290+
{
291+
SWSS_LOG_ERROR("Proxy ARP state is invalid: \"%s\"", proxy_arp.c_str());
292+
return false;
293+
}
294+
295+
cmd << ECHO_CMD << " " << proxy_arp_pvlan << " > /proc/sys/net/ipv4/conf/" << alias << "/proxy_arp_pvlan";
296+
EXEC_WITH_ERROR_THROW(cmd.str(), res);
297+
298+
SWSS_LOG_INFO("Proxy ARP set to \"%s\" on interface \"%s\"", proxy_arp.c_str(), alias.c_str());
299+
return true;
300+
}
301+
275302
bool IntfMgr::isIntfStateOk(const string &alias)
276303
{
277304
vector<FieldValueTuple> temp;
@@ -346,6 +373,8 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
346373
string mtu = "";
347374
string adminStatus = "";
348375
string nat_zone = "";
376+
string proxy_arp = "";
377+
349378
for (auto idx : data)
350379
{
351380
const auto &field = fvField(idx);
@@ -363,6 +392,10 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
363392
{
364393
adminStatus = value;
365394
}
395+
else if (field == "proxy_arp")
396+
{
397+
proxy_arp = value;
398+
}
366399

367400
if (field == "nat_zone")
368401
{
@@ -420,7 +453,22 @@ bool IntfMgr::doIntfGeneralTask(const vector<string>& keys,
420453
FieldValueTuple fvTuple("mac_addr", MacAddress().to_string());
421454
data.push_back(fvTuple);
422455
}
423-
456+
457+
if (!proxy_arp.empty())
458+
{
459+
if (!setIntfProxyArp(alias, proxy_arp))
460+
{
461+
SWSS_LOG_ERROR("Failed to set proxy ARP to \"%s\" state for the \"%s\" interface", proxy_arp.c_str(), alias.c_str());
462+
return false;
463+
}
464+
465+
if (!alias.compare(0, strlen(VLAN_PREFIX), VLAN_PREFIX))
466+
{
467+
FieldValueTuple fvTuple("proxy_arp", proxy_arp);
468+
data.push_back(fvTuple);
469+
}
470+
}
471+
424472
if (!subIntfAlias.empty())
425473
{
426474
if (m_subIntfList.find(subIntfAlias) == m_subIntfList.end())

cfgmgr/intfmgr.h

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class IntfMgr : public Orch
4646
void removeHostSubIntf(const std::string &subIntf);
4747
void setSubIntfStateOk(const std::string &alias);
4848
void removeSubIntfState(const std::string &alias);
49+
50+
bool setIntfProxyArp(const std::string &alias, const std::string &proxy_arp);
4951
};
5052

5153
}

orchagent/intfsorch.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ extern sai_router_interface_api_t* sai_router_intfs_api;
2424
extern sai_route_api_t* sai_route_api;
2525
extern sai_neighbor_api_t* sai_neighbor_api;
2626
extern sai_switch_api_t* sai_switch_api;
27+
extern sai_vlan_api_t* sai_vlan_api;
2728

2829
extern sai_object_id_t gSwitchId;
2930
extern PortsOrch *gPortsOrch;
@@ -226,6 +227,75 @@ bool IntfsOrch::setRouterIntfsAdminStatus(const Port &port)
226227
return true;
227228
}
228229

230+
bool IntfsOrch::setIntfVlanFloodType(const Port &port, sai_vlan_flood_control_type_t vlan_flood_type)
231+
{
232+
SWSS_LOG_ENTER();
233+
234+
if (port.m_type != Port::VLAN)
235+
{
236+
SWSS_LOG_ERROR("VLAN flood type cannot be set for non VLAN interface \"%s\"", port.m_alias.c_str());
237+
return false;
238+
}
239+
240+
sai_attribute_t attr;
241+
attr.id = SAI_VLAN_ATTR_BROADCAST_FLOOD_CONTROL_TYPE;
242+
attr.value.s32 = vlan_flood_type;
243+
244+
sai_status_t status = sai_vlan_api->set_vlan_attribute(port.m_vlan_info.vlan_oid, &attr);
245+
if (status != SAI_STATUS_SUCCESS)
246+
{
247+
SWSS_LOG_ERROR("Failed to set flood type for VLAN %u, rv:%d", port.m_vlan_info.vlan_id, status);
248+
return false;
249+
}
250+
251+
return true;
252+
}
253+
254+
bool IntfsOrch::setIntfProxyArp(const string &alias, const string &proxy_arp)
255+
{
256+
SWSS_LOG_ENTER();
257+
258+
if (m_syncdIntfses.find(alias) == m_syncdIntfses.end())
259+
{
260+
SWSS_LOG_ERROR("Interface \"%s\" doesn't exist", alias.c_str());
261+
return false;
262+
}
263+
264+
if (m_syncdIntfses[alias].proxy_arp == (proxy_arp == "enabled" ? true : false))
265+
{
266+
SWSS_LOG_INFO("Proxy ARP is already set to \"%s\" on interface \"%s\"", proxy_arp.c_str(), alias.c_str());
267+
return true;
268+
}
269+
270+
Port port;
271+
if (!gPortsOrch->getPort(alias, port))
272+
{
273+
SWSS_LOG_ERROR("Failed to get port info for the interface \"%s\"", alias.c_str());
274+
return false;
275+
}
276+
277+
if (port.m_type == Port::VLAN)
278+
{
279+
sai_vlan_flood_control_type_t vlan_flood_type;
280+
if (proxy_arp == "enabled")
281+
{
282+
vlan_flood_type = SAI_VLAN_FLOOD_CONTROL_TYPE_NONE;
283+
}
284+
else
285+
{
286+
vlan_flood_type = SAI_VLAN_FLOOD_CONTROL_TYPE_ALL;
287+
}
288+
289+
if (!setIntfVlanFloodType(port, vlan_flood_type))
290+
{
291+
return false;
292+
}
293+
}
294+
295+
m_syncdIntfses[alias].proxy_arp = (proxy_arp == "enabled") ? true : false;
296+
return true;
297+
}
298+
229299
set<IpPrefix> IntfsOrch:: getSubnetRoutes()
230300
{
231301
SWSS_LOG_ENTER();
@@ -440,6 +510,7 @@ void IntfsOrch::doTask(Consumer &consumer)
440510
uint32_t mtu;
441511
bool adminUp;
442512
uint32_t nat_zone_id = 0;
513+
string proxy_arp = "";
443514

444515
for (auto idx : data)
445516
{
@@ -515,6 +586,10 @@ void IntfsOrch::doTask(Consumer &consumer)
515586
{
516587
nat_zone = value;
517588
}
589+
else if (field == "proxy_arp")
590+
{
591+
proxy_arp = value;
592+
}
518593
}
519594

520595
if (alias == "eth0" || alias == "docker0")
@@ -666,6 +741,11 @@ void IntfsOrch::doTask(Consumer &consumer)
666741
}
667742
}
668743

744+
if (!proxy_arp.empty())
745+
{
746+
setIntfProxyArp(alias, proxy_arp);
747+
}
748+
669749
it = consumer.m_toSync.erase(it);
670750
}
671751
else if (op == DEL_COMMAND)
@@ -724,6 +804,11 @@ void IntfsOrch::doTask(Consumer &consumer)
724804
vnet_name = m_vnetInfses.at(alias);
725805
}
726806

807+
if (m_syncdIntfses[alias].proxy_arp)
808+
{
809+
setIntfProxyArp(alias, "disabled");
810+
}
811+
727812
if (!vnet_name.empty())
728813
{
729814
VNetOrch* vnet_orch = gDirectory.get<VNetOrch*>();

orchagent/intfsorch.h

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct IntfsEntry
2323
std::set<IpPrefix> ip_addresses;
2424
int ref_count;
2525
sai_object_id_t vrf_id;
26+
bool proxy_arp;
2627
};
2728

2829
typedef map<string, IntfsEntry> IntfsTable;
@@ -89,6 +90,9 @@ class IntfsOrch : public Orch
8990

9091
void addDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix);
9192
void removeDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix);
93+
94+
bool setIntfVlanFloodType(const Port &port, sai_vlan_flood_control_type_t vlan_flood_type);
95+
bool setIntfProxyArp(const string &alias, const string &proxy_arp);
9296
};
9397

9498
#endif /* SWSS_INTFSORCH_H */

0 commit comments

Comments
 (0)