This commit is contained in:
Mateusz Gruszczyński committed 2026-11-14 17:24:12 +01:00
1 parent 78dbb31487
commit f48843e934
83 files changed
+7304 -1203

No files matched your search

+31 -2
View File
@@ -71,14 +71,37 @@ func skipInterface(name string) bool {
return name == "docker0" || strings.HasPrefix(name, "docker") || strings.HasPrefix(name, "veth") || strings.HasPrefix(name, "br-") || strings.HasPrefix(name, "virbr")
}
func bridgeInterface(name string) bool {
name = strings.ToLower(strings.TrimSpace(name))
if strings.HasPrefix(name, "veth") {
return false
}
return skipInterface(name) || strings.HasPrefix(name, "podman") || strings.HasPrefix(name, "cni-")
}
func localHostAddresses() []hostAddress {
return interfaceAddresses(false)
}
func bridgeHostAddresses() []hostAddress {
return interfaceAddresses(true)
}
func interfaceAddresses(bridges bool) []hostAddress {
interfaces, err := net.Interfaces()
if err != nil {
return nil
}
source := "interface"
if bridges {
source = "bridge"
}
out := make([]hostAddress, 0)
for _, iface := range interfaces {
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 || skipInterface(iface.Name) {
if iface.Flags&net.FlagUp == 0 || iface.Flags&net.FlagLoopback != 0 {
continue
}
if bridges != bridgeInterface(iface.Name) || (!bridges && skipInterface(iface.Name)) {
continue
}
addrs, err := iface.Addrs()
@@ -97,7 +120,7 @@ func localHostAddresses() []hostAddress {
continue
}
ip := net.ParseIP(clean)
out = append(out, hostAddress{IP: clean, Source: "interface", Interface: iface.Name, Scope: ipScope(ip)})
out = append(out, hostAddress{IP: clean, Source: source, Interface: iface.Name, Scope: ipScope(ip)})
}
}
sort.Slice(out, func(i, j int) bool {
@@ -176,6 +199,12 @@ func detectedAddresses(ctx context.Context, cfg config, detector *ipDetector) ([
if advertised != "" {
mergeHostAddress(&out, index, hostAddress{IP: advertised, Source: "override"})
}
for _, item := range bridgeHostAddresses() {
if len(out) >= 48 {
break
}
mergeHostAddress(&out, index, item)
}
switch {
case advertised != "":