From a8e2c8edb67ca2c6dfe6d88e8c855d12949437c5 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 23 Sep 2024 14:32:19 +0200 Subject: [PATCH] fix(connections): announce PtP links again (fixes #9730) (#9731) --- lib/connections/service.go | 2 +- lib/connections/util.go | 2 +- lib/osutil/net.go | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/connections/service.go b/lib/connections/service.go index 0a09f6c7c..1aaf3633c 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -799,7 +799,7 @@ func (s *lanChecker) isLAN(addr net.Addr) bool { } } - lans, err := osutil.GetLans() + lans, err := osutil.GetInterfaceAddrs(false) if err != nil { l.Debugln("Failed to retrieve interface IPs:", err) priv := ip.IsPrivate() diff --git a/lib/connections/util.go b/lib/connections/util.go index 217d006f4..a14b96475 100644 --- a/lib/connections/util.go +++ b/lib/connections/util.go @@ -60,7 +60,7 @@ func getURLsForAllAdaptersIfUnspecified(network string, uri *url.URL) []*url.URL } func getHostPortsForAllAdapters(port int) []string { - nets, err := osutil.GetLans() + nets, err := osutil.GetInterfaceAddrs(true) if err != nil { // Ignore failure. return nil diff --git a/lib/osutil/net.go b/lib/osutil/net.go index 4400d8f23..ce308d999 100644 --- a/lib/osutil/net.go +++ b/lib/osutil/net.go @@ -10,7 +10,9 @@ import ( "net" ) -func GetLans() ([]*net.IPNet, error) { +// GetInterfaceAddrs returns the IP networks of all interfaces that are up. +// Point-to-point interfaces are exluded unless includePtP is true. +func GetInterfaceAddrs(includePtP bool) ([]*net.IPNet, error) { intfs, err := net.Interfaces() if err != nil { return nil, err @@ -21,7 +23,7 @@ func GetLans() ([]*net.IPNet, error) { if intf.Flags&net.FlagRunning == 0 { continue } - if intf.Flags&net.FlagPointToPoint != 0 { + if !includePtP && intf.Flags&net.FlagPointToPoint != 0 { // Point-to-point interfaces are typically VPNs and similar // which, for our purposes, do not qualify as LANs. continue