Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve network inteface filtering in metalprobe #112

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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