diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 179bd2cf1aa..5dfd37da96f 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -87,33 +87,53 @@ void IntfsOrch::doTask(Consumer &consumer) } auto it_intfs = m_syncdIntfses.find(alias); - if (it_intfs == m_syncdIntfses.end() || - !m_syncdIntfses[alias].ip_addresses.contains(ip_prefix.getIp())) + if (it_intfs == m_syncdIntfses.end()) { - if (it_intfs == m_syncdIntfses.end()) + if (addRouterIntfs(port)) { - if (addRouterIntfs(port)) - { - IntfsEntry intfs_entry; - intfs_entry.ref_count = 0; - m_syncdIntfses[alias] = intfs_entry; - } - else - { - it++; - continue; - } + IntfsEntry intfs_entry; + intfs_entry.ref_count = 0; + m_syncdIntfses[alias] = intfs_entry; + } + else + { + it++; + continue; } - - addSubnetRoute(port, ip_prefix); - addIp2MeRoute(ip_prefix); - - m_syncdIntfses[alias].ip_addresses.add(ip_prefix.getIp()); - it = consumer.m_toSync.erase(it); } - else + + if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix)) + { /* Duplicate entry */ it = consumer.m_toSync.erase(it); + continue; + } + + bool overlaps = false; + for (const auto &prefixIt: m_syncdIntfses[alias].ip_addresses) + { + if (prefixIt.isAddressInSubnet(ip_prefix.getIp()) || + ip_prefix.isAddressInSubnet(prefixIt.getIp())) + { + overlaps = true; + SWSS_LOG_NOTICE("Router interface %s IP %s overlaps with %s.", port.m_alias.c_str(), + prefixIt.to_string().c_str(), ip_prefix.to_string().c_str()); + break; + } + } + + if (overlaps) + { + /* Overlap of IP address network */ + ++it; + continue; + } + + addSubnetRoute(port, ip_prefix); + addIp2MeRoute(ip_prefix); + + m_syncdIntfses[alias].ip_addresses.insert(ip_prefix); + it = consumer.m_toSync.erase(it); } else if (op == DEL_COMMAND) { @@ -134,16 +154,16 @@ void IntfsOrch::doTask(Consumer &consumer) if (m_syncdIntfses.find(alias) != m_syncdIntfses.end()) { - if (m_syncdIntfses[alias].ip_addresses.contains(ip_prefix.getIp())) + if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix)) { removeSubnetRoute(port, ip_prefix); removeIp2MeRoute(ip_prefix); - m_syncdIntfses[alias].ip_addresses.remove(ip_prefix.getIp()); + m_syncdIntfses[alias].ip_addresses.erase(ip_prefix); } /* Remove router interface that no IP addresses are associated with */ - if (m_syncdIntfses[alias].ip_addresses.getSize() == 0) + if (m_syncdIntfses[alias].ip_addresses.size() == 0) { if (removeRouterIntfs(port)) { diff --git a/orchagent/intfsorch.h b/orchagent/intfsorch.h index f72a5b88ceb..d35ac28ddd1 100644 --- a/orchagent/intfsorch.h +++ b/orchagent/intfsorch.h @@ -9,13 +9,14 @@ #include "macaddress.h" #include +#include extern sai_object_id_t gVirtualRouterId; extern MacAddress gMacAddress; struct IntfsEntry { - IpAddresses ip_addresses; + std::set ip_addresses; int ref_count; };