From c8d7b4dc7fa947293223bf38b3652fad0fcbe3cd Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Wed, 21 Aug 2024 16:43:08 +0200 Subject: [PATCH] Improve network inteface filtering in `metalprobe` Filter out Docker, SLAAC and down networkinterfaces when running the `metalprobe` on a `Server`. --- internal/probe/networking.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/probe/networking.go b/internal/probe/networking.go index f8c51dc..4dc1a69 100644 --- a/internal/probe/networking.go +++ b/internal/probe/networking.go @@ -10,6 +10,11 @@ import ( "github.com/ironcore-dev/metal-operator/internal/api/registry" ) +// IsSLAAC checks if the given IPv6 address is a SLAAC address. +func IsSLAAC(ip string) bool { + return strings.Contains(ip, "ff:fe") +} + // collectNetworkData collects the IP and MAC addresses of the host's network interfaces, // ignoring loopback and tunnel (tun) devices. func collectNetworkData() ([]registry.NetworkInterface, error) { @@ -20,8 +25,12 @@ func collectNetworkData() ([]registry.NetworkInterface, error) { var networkInterfaces []registry.NetworkInterface for _, iface := range interfaces { - // Skip loopback, interfaces without a MAC address, and tun devices. - if iface.Flags&net.FlagLoopback != 0 || iface.HardwareAddr.String() == "" || strings.HasPrefix(iface.Name, "tun") { + // Skip loopback, interfaces without a MAC address, tun devices, docker interface + if iface.Flags&net.FlagLoopback != 0 || + iface.HardwareAddr.String() == "" || + strings.HasPrefix(iface.Name, "tun") || + strings.HasPrefix(iface.Name, "docker0") || + iface.Flags&net.FlagUp == 0 { // Filter out interfaces that are down continue } @@ -43,6 +52,11 @@ func collectNetworkData() ([]registry.NetworkInterface, error) { continue } + // Filter out SLAAC addresses + if ip.To4() == nil && IsSLAAC(ip.String()) { + continue + } + networkInterface := registry.NetworkInterface{ Name: iface.Name, IPAddress: ip.String(),