From dde44d6666527219e129b666d83ef8c49aa4722a Mon Sep 17 00:00:00 2001 From: Owen Date: Thu, 16 Jul 2026 14:34:25 -0400 Subject: [PATCH] Filter out link local and dont send the port --- network/localendpoints.go | 28 +++++++++++++--------------- newt/clients.go | 4 ++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/network/localendpoints.go b/network/localendpoints.go index 23a2bff..bf226c2 100644 --- a/network/localendpoints.go +++ b/network/localendpoints.go @@ -4,7 +4,6 @@ import ( "net" "regexp" "sort" - "strconv" "github.com/fosrl/newt/logger" ) @@ -66,10 +65,9 @@ var ( ) const ( - scorePhysical = 0 - scoreUnknown = 10 - scoreVirtual = 20 - scoreLinkLocal = 1000 + scorePhysical = 0 + scoreUnknown = 10 + scoreVirtual = 20 ) // interfaceScore ranks an interface name by how likely it is to be a @@ -88,9 +86,9 @@ func interfaceScore(name string) int { return scoreUnknown } -// GetLocalEndpoints returns "ip:port" strings (bracketed for IPv6, e.g. -// "[fe80::1]:51820") for every usable, non-loopback IP address bound to a -// network interface on this host. The list is ordered with interfaces most +// GetLocalEndpoints returns IP address strings for every usable, +// non-loopback IP address bound to a network interface on this host. The +// list is ordered with interfaces most // likely to be a genuine host network (wired/Wi-Fi) first, and interfaces // that are typically synthetic (Docker, VPN tunnels, hypervisor bridges, // etc.) last, so callers should try the results roughly in order. @@ -101,7 +99,7 @@ func interfaceScore(name string) int { // // If interfaces cannot be enumerated (e.g. insufficient OS permissions), // an info message is logged and an empty slice is returned. -func GetLocalEndpoints(port uint16, excludeInterface string) []string { +func GetLocalEndpoints(excludeInterface string) []string { ifaces, err := net.Interfaces() if err != nil { logger.Info("Unable to enumerate local network interfaces, localEndpoints will not be reported: %v", err) @@ -141,13 +139,14 @@ func GetLocalEndpoints(port uint16, excludeInterface string) []string { if ip == nil || ip.IsLoopback() || ip.IsUnspecified() { continue } - - score := baseScore if ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() { - score += scoreLinkLocal + // Link-local addresses (169.254.0.0/16, fe80::/10) aren't + // routable off the local segment, so they're never a + // reachable endpoint for a peer. + continue } - candidates = append(candidates, candidate{score: score, ip: ip.String()}) + candidates = append(candidates, candidate{score: baseScore, ip: ip.String()}) } } @@ -155,10 +154,9 @@ func GetLocalEndpoints(port uint16, excludeInterface string) []string { return candidates[i].score < candidates[j].score }) - portStr := strconv.Itoa(int(port)) endpoints := make([]string, 0, len(candidates)) for _, c := range candidates { - endpoints = append(endpoints, net.JoinHostPort(c.ip, portStr)) + endpoints = append(endpoints, c.ip) } return endpoints } diff --git a/newt/clients.go b/newt/clients.go index a82aea0..af0f2bb 100644 --- a/newt/clients.go +++ b/newt/clients.go @@ -103,11 +103,11 @@ func (n *Newt) clientsOnConnect() { } } -// localEndpoints returns "ip:port" candidates on this host that could +// localEndpoints returns candidate IP addresses on this host that could // potentially be used to reach our WireGuard listen port, ranked with the // most likely genuine host interfaces first. func (n *Newt) localEndpoints() []string { - return network.GetLocalEndpoints(n.config.Port, n.config.InterfaceName) + return network.GetLocalEndpoints(n.config.InterfaceName) } func (n *Newt) clientsStartDirectRelay(tunnelIP string) {