From 36e85ebb8656b92539cd1d64ec470bd904afd92c Mon Sep 17 00:00:00 2001 From: Kiran Kumar Kella <45939429+kirankella@users.noreply.github.com> Date: Tue, 29 Jan 2019 04:06:19 +0530 Subject: [PATCH] On a routing vlan, the neighbor entry in the /31 subnet is not added to hardware (#771) * In a routing vlan, the neighbor entry in the /31 subnet is not getting added to hardware. Fix: Don't add the net broadcast neighbor entry on the /31 subnet routin vlan as there is no net broadcast address in /31 subnets. Signed-off-by: kiran.kella@broadcom.com --- orchagent/intfsorch.cpp | 32 ++++++++++++++++++++++++++------ orchagent/intfsorch.h | 4 ++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 4006d4851140..34d857b51a99 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -158,9 +158,9 @@ bool IntfsOrch::setIntf(const string& alias, sai_object_id_t vrf_id, const IpPre addSubnetRoute(port, *ip_prefix); addIp2MeRoute(vrf_id, *ip_prefix); - if (port.m_type == Port::VLAN && ip_prefix->isV4()) + if (port.m_type == Port::VLAN) { - addDirectedBroadcast(port, ip_prefix->getBroadcastIp()); + addDirectedBroadcast(port, *ip_prefix); } m_syncdIntfses[alias].ip_addresses.insert(*ip_prefix); @@ -344,9 +344,10 @@ void IntfsOrch::doTask(Consumer &consumer) { removeSubnetRoute(port, ip_prefix); removeIp2MeRoute(vrf_id, ip_prefix); - if(port.m_type == Port::VLAN && ip_prefix.isV4()) + + if(port.m_type == Port::VLAN) { - removeDirectedBroadcast(port, ip_prefix.getBroadcastIp()); + removeDirectedBroadcast(port, ip_prefix); } m_syncdIntfses[alias].ip_addresses.erase(ip_prefix); @@ -623,10 +624,20 @@ void IntfsOrch::removeIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_pref } } -void IntfsOrch::addDirectedBroadcast(const Port &port, const IpAddress &ip_addr) +void IntfsOrch::addDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix) { sai_status_t status; sai_neighbor_entry_t neighbor_entry; + IpAddress ip_addr; + + /* If not IPv4 subnet or if /31 or /32 subnet, there is no broadcast address, hence don't + * add a broadcast route. */ + if (!(ip_prefix.isV4()) || (ip_prefix.getMaskLength() > 30)) + { + return; + } + ip_addr = ip_prefix.getBroadcastIp(); + neighbor_entry.rif_id = port.m_rif_id; neighbor_entry.switch_id = gSwitchId; copy(neighbor_entry.ip_address, ip_addr); @@ -646,10 +657,19 @@ void IntfsOrch::addDirectedBroadcast(const Port &port, const IpAddress &ip_addr) SWSS_LOG_NOTICE("Add broadcast route for ip:%s", ip_addr.to_string().c_str()); } -void IntfsOrch::removeDirectedBroadcast(const Port &port, const IpAddress &ip_addr) +void IntfsOrch::removeDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix) { sai_status_t status; sai_neighbor_entry_t neighbor_entry; + IpAddress ip_addr; + + /* If not IPv4 subnet or if /31 or /32 subnet, there is no broadcast address */ + if (!(ip_prefix.isV4()) || (ip_prefix.getMaskLength() > 30)) + { + return; + } + ip_addr = ip_prefix.getBroadcastIp(); + neighbor_entry.rif_id = port.m_rif_id; neighbor_entry.switch_id = gSwitchId; copy(neighbor_entry.ip_address, ip_addr); diff --git a/orchagent/intfsorch.h b/orchagent/intfsorch.h index 33ad4a6f51db..e46e46232e39 100644 --- a/orchagent/intfsorch.h +++ b/orchagent/intfsorch.h @@ -52,8 +52,8 @@ class IntfsOrch : public Orch void addIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix); void removeIp2MeRoute(sai_object_id_t vrf_id, const IpPrefix &ip_prefix); - void addDirectedBroadcast(const Port &port, const IpAddress &ip_addr); - void removeDirectedBroadcast(const Port &port, const IpAddress &ip_addr); + void addDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix); + void removeDirectedBroadcast(const Port &port, const IpPrefix &ip_prefix); }; #endif /* SWSS_INTFSORCH_H */