diff --git a/orchagent/intfsorch.cpp b/orchagent/intfsorch.cpp index 3111bccf899f..a7d42272f65b 100644 --- a/orchagent/intfsorch.cpp +++ b/orchagent/intfsorch.cpp @@ -174,7 +174,38 @@ void IntfsOrch::doTask(Consumer &consumer) { if (alias == "lo") { - addIp2MeRoute(vrf_id, ip_prefix); + if (!ip_prefix_in_key) + { + it = consumer.m_toSync.erase(it); + continue; + } + + bool addIp2Me = false; + // set request for lo may come after warm start restore. + // It is also to prevent dupicate set requests in normal running case. + auto it_intfs = m_syncdIntfses.find(alias); + if (it_intfs == m_syncdIntfses.end()) + { + IntfsEntry intfs_entry; + + intfs_entry.ref_count = 0; + intfs_entry.ip_addresses.insert(ip_prefix); + m_syncdIntfses[alias] = intfs_entry; + addIp2Me = true; + } + else + { + if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix) == 0) + { + m_syncdIntfses[alias].ip_addresses.insert(ip_prefix); + addIp2Me = true; + } + } + if (addIp2Me) + { + addIp2MeRoute(vrf_id, ip_prefix); + } + it = consumer.m_toSync.erase(it); continue; } @@ -261,7 +292,20 @@ void IntfsOrch::doTask(Consumer &consumer) { if (alias == "lo") { - removeIp2MeRoute(vrf_id, ip_prefix); + // TODO: handle case for which lo is not in default vrf gVirtualRouterId + if (m_syncdIntfses.find(alias) != m_syncdIntfses.end()) + { + if (m_syncdIntfses[alias].ip_addresses.count(ip_prefix)) + { + m_syncdIntfses[alias].ip_addresses.erase(ip_prefix); + removeIp2MeRoute(vrf_id, ip_prefix); + } + if (m_syncdIntfses[alias].ip_addresses.size() == 0) + { + m_syncdIntfses.erase(alias); + } + } + it = consumer.m_toSync.erase(it); continue; }