From 081ee487134c36ba997e50c57df5fe81f740b6a0 Mon Sep 17 00:00:00 2001 From: Bin Liu Date: Fri, 21 Oct 2022 21:12:55 +0800 Subject: [PATCH] agent: use NLM_F_REPLACE replace NLM_F_EXCL in rtnetlink Sometimes we will face EEXIST error when adding arp neighbour. Using NLM_F_REPLACE replace NLM_F_EXCL will avoid fail if the entry exists. See https://man7.org/linux/man-pages/man7/netlink.7.html Fixes: #4895 Signed-off-by: Bin Liu --- src/agent/src/netlink.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/agent/src/netlink.rs b/src/agent/src/netlink.rs index 4d6a26e140..ef926f5157 100644 --- a/src/agent/src/netlink.rs +++ b/src/agent/src/netlink.rs @@ -529,7 +529,9 @@ impl Handle { .map_err(|e| anyhow!("Failed to parse IP {}: {:?}", ip_address, e))?; // Import rtnetlink objects that make sense only for this function - use packet::constants::{NDA_UNSPEC, NLM_F_ACK, NLM_F_CREATE, NLM_F_EXCL, NLM_F_REQUEST}; + use packet::constants::{ + NDA_UNSPEC, NLM_F_ACK, NLM_F_CREATE, NLM_F_REPLACE, NLM_F_REQUEST, + }; use packet::neighbour::{NeighbourHeader, NeighbourMessage}; use packet::nlas::neighbour::Nla; use packet::{NetlinkMessage, NetlinkPayload, RtnlMessage}; @@ -572,7 +574,7 @@ impl Handle { // Send request and ACK let mut req = NetlinkMessage::from(RtnlMessage::NewNeighbour(message)); - req.header.flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_EXCL | NLM_F_CREATE; + req.header.flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE | NLM_F_REPLACE; let mut response = self.handle.request(req)?; while let Some(message) = response.next().await {