Repository: syncthing/syncthing (language: go)

Issue:
connections: point-to-point links should still be announced
              I'm afraid this has an undesirable side effect:

https://github.com/syncthing/syncthing/blob/8ff670c5643cefdcb26d841123e5b71523dcb4e8/lib/connections/util.go#L62-L81

We should still announce those IPs to the global discovery server.

_Originally posted by @bt90 in https://github.com/syncthing/syncthing/issues/9720#issuecomment-2366731067_
            


Discussion / hints:
IMHO GetLans should have a parameter to control whether "virtual" LAN IPs should be ignored.

Fix patch:
diff --git a/lib/connections/service.go b/lib/connections/service.go
index 0a09f6c7ced..1aaf3633c7d 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 217d006f42d..a14b9647506 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 4400d8f23f0..ce308d9993a 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


Test patch: