From e225822fe5a961adfe39a94bd9edd64bc0fcb99f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 30 Jul 2024 14:24:31 +0200 Subject: [PATCH] Announce all IP addresses on error Don't let the first error shortcut the announcement of subsequent addresses. Loop over all addresses, and return the joined errors. Note that the caller anyway ignores the error and only uses it for debug logging. --- pkg/utils/packet.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/pkg/utils/packet.go b/pkg/utils/packet.go index 6f0a5a1e..f911c383 100644 --- a/pkg/utils/packet.go +++ b/pkg/utils/packet.go @@ -3,6 +3,7 @@ package utils import ( "bytes" "encoding/binary" + "errors" "fmt" "net" "syscall" @@ -175,26 +176,27 @@ func AnnounceIPs(ifName string, ipConfigs []*current.IPConfig) error { return fmt.Errorf("invalid Ethernet MAC address: %q", linkObj.Attrs().HardwareAddr) } + var errResult error + // For all the IP addresses assigned by IPAM, we will send either a GARP (IPv4) or Unsolicited NA (IPv6). for _, ipc := range ipConfigs { - var err error - if IsIPv6(ipc.Address.IP) { + if IsIPv4(ipc.Address.IP) { + err := SendGratuitousArp(ipc.Address.IP, linkObj) + if err != nil { + errResult = errors.Join(errResult, fmt.Errorf("failed to send GARP message for ip %s on interface %q: %v", ipc.Address.IP.String(), ifName, err)) + } + } else if IsIPv6(ipc.Address.IP) { /* As per RFC 4861, sending unsolicited neighbor advertisements should be considered as a performance * optimization. It does not reliably update caches in all nodes. The Neighbor Unreachability Detection * algorithm is more reliable although it may take slightly longer to update. */ - err = SendUnsolicitedNeighborAdvertisement(ipc.Address.IP, linkObj) - } else if IsIPv4(ipc.Address.IP) { - err = SendGratuitousArp(ipc.Address.IP, linkObj) - } else { - return fmt.Errorf("the IP %s on interface %q is neither IPv4 or IPv6", ipc.Address.IP.String(), ifName) - } - - if err != nil { - return fmt.Errorf("failed to send GARP/NA message for ip %s on interface %q: %v", ipc.Address.IP.String(), ifName, err) + err := SendUnsolicitedNeighborAdvertisement(ipc.Address.IP, linkObj) + if err != nil { + errResult = errors.Join(errResult, fmt.Errorf("failed to send NA message for ip %s on interface %q: %v", ipc.Address.IP.String(), ifName, err)) + } } } - return nil + return errResult } // Blocking wait for interface ifName to have carrier (!NO_CARRIER flag).