Skip to content

Commit

Permalink
incus-agent: Use NetlinkInterfaces
Browse files Browse the repository at this point in the history
Fetching addresses for a single interface in Go is terribly slow, use a
bulk query method.

Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
Sponsored-by: https://webdock.io
  • Loading branch information
stgraber committed Nov 11, 2024
1 parent f361f7e commit 870ddcc
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions cmd/incus-agent/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 870ddcc

Please sign in to comment.