From 9c50e5433c818ef5c3cd09ae7f8be69635db147a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Mon, 11 Nov 2024 15:18:33 -0500 Subject: [PATCH] incus-agent: Use NetlinkInterfaces MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fetching addresses for a single interface in Go is terribly slow, use a bulk query method. Signed-off-by: Stéphane Graber Sponsored-by: https://webdock.io --- cmd/incus-agent/state.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/incus-agent/state.go b/cmd/incus-agent/state.go index 9b0218e38ee..189d6274a10 100644 --- a/cmd/incus-agent/state.go +++ b/cmd/incus-agent/state.go @@ -123,7 +123,7 @@ func memoryState() api.InstanceStateMemory { func networkState() map[string]api.InstanceStateNetwork { result := map[string]api.InstanceStateNetwork{} - ifs, err := net.Interfaces() + ifs, err := linux.NetlinkInterfaces() if err != nil { logger.Errorf("Failed to retrieve network interfaces: %v", err) return result @@ -180,9 +180,7 @@ func networkState() map[string]api.InstanceStateNetwork { } // Addresses - addrs, _ := iface.Addrs() - - for _, addr := range addrs { + for _, addr := range iface.Addresses { addressFields := strings.Split(addr.String(), "/") networkAddress := api.InstanceStateNetworkAddress{