Skip to content

Commit

Permalink
Improve network inteface filtering in metalprobe
Browse files Browse the repository at this point in the history
Filter out Docker, SLAAC and down networkinterfaces when running the
`metalprobe` on a `Server`.
  • Loading branch information
afritzler committed Aug 21, 2024
1 parent 252f38b commit c8d7b4d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/probe/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
}

Expand All @@ -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(),
Expand Down

0 comments on commit c8d7b4d

Please sign in to comment.