From faa3e6df99028137237ea70c9fa99f5a8b8c097c Mon Sep 17 00:00:00 2001 From: Xichen96 Date: Mon, 20 Jul 2026 17:27:12 +0000 Subject: [PATCH] [neighorch]: Avoid inserting missing bulk neighbors Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b6b568a1-5d2a-4309-b1ac-ef21ca155079 Signed-off-by: Xichen96 --- orchagent/neighorch.cpp | 6 +++--- tests/mock_tests/neighorch_ut.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/orchagent/neighorch.cpp b/orchagent/neighorch.cpp index 7ee60a95803..60e63d351e0 100644 --- a/orchagent/neighorch.cpp +++ b/orchagent/neighorch.cpp @@ -2046,13 +2046,13 @@ bool NeighOrch::enableNeighbors(std::list& bulk_ctx_list) for (auto ctx = bulk_ctx_list.begin(); ctx != bulk_ctx_list.end(); ctx++) { const NeighborEntry& neighborEntry = ctx->neighborEntry; - ctx->mac = m_syncdNeighbors[neighborEntry].mac; - - if (m_syncdNeighbors.find(neighborEntry) == m_syncdNeighbors.end()) + auto neighborIt = m_syncdNeighbors.find(neighborEntry); + if (neighborIt == m_syncdNeighbors.end()) { SWSS_LOG_INFO("Neighbor %s not found", neighborEntry.ip_address.to_string().c_str()); continue; } + ctx->mac = neighborIt->second.mac; if (isHwConfigured(neighborEntry)) { diff --git a/tests/mock_tests/neighorch_ut.cpp b/tests/mock_tests/neighorch_ut.cpp index dc08749c370..3a21860a80d 100644 --- a/tests/mock_tests/neighorch_ut.cpp +++ b/tests/mock_tests/neighorch_ut.cpp @@ -208,6 +208,16 @@ namespace neighorch_test ASSERT_EQ(gNeighOrch->m_syncdNeighbors.count(VLAN2000_NEIGH), 0); } + TEST_F(NeighOrchTest, EnableNeighborsDoesNotInsertMissingNeighbor) + { + list contexts; + contexts.emplace_back(VLAN1000_NEIGH, true); + + ASSERT_EQ(gNeighOrch->m_syncdNeighbors.count(VLAN1000_NEIGH), 0u); + EXPECT_TRUE(gNeighOrch->enableNeighbors(contexts)); + EXPECT_EQ(gNeighOrch->m_syncdNeighbors.count(VLAN1000_NEIGH), 0u); + } + TEST_F(NeighOrchTest, MultiVlanUnableToRemoveNeighbor) { EXPECT_CALL(*mock_sai_neighbor_api, create_neighbor_entry);