From c835d2fc5d3ff43b97eb1d11faa043a557f11377 Mon Sep 17 00:00:00 2001 From: Cyclinder Date: Fri, 14 Feb 2025 15:43:51 +0800 Subject: [PATCH] Ensure kernel sends GARPs to avoid communication failures (#4649) Signed-off-by: Cyclinder Kuo --- cmd/spiderpool/cmd/command_add.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cmd/spiderpool/cmd/command_add.go b/cmd/spiderpool/cmd/command_add.go index 5b4194911..a22338142 100644 --- a/cmd/spiderpool/cmd/command_add.go +++ b/cmd/spiderpool/cmd/command_add.go @@ -192,6 +192,30 @@ func CmdAdd(args *skel.CmdArgs) (err error) { logger.Error(err.Error()) } + // CNI will set the interface to up, and the kernel only sends GARPs/Unsolicited NA when the interface + // goes from down to up or when the link-layer address changes on the interfaces. in order to the + // kernel send GARPs/Unsolicited NA when the interface goes from down to up. + // see https://github.com/spidernet-io/spiderpool/issues/4650 + var ipRes []net.IP + for _, i := range ipamResponse.Payload.Ips { + if i.Address != nil && *i.Address != "" { + ipa, _, err := net.ParseCIDR(*i.Address) + if err != nil { + logger.Error(err.Error()) + continue + } + ipRes = append(ipRes, ipa) + } + } + + err = netns.Do(func(netNS ns.NetNS) error { + return networking.AnnounceIPs(logger, args.IfName, ipRes) + }) + + if err != nil { + logger.Error(err.Error()) + } + // Assemble the result of IPAM request response. result, err := assembleResult(conf.CNIVersion, args.IfName, ipamResponse) if err != nil {