Repository: syncthing/syncthing (language: go)

Issue:
Syncthing announces address of interface which is down
Noticed this behaviour yesterday on my Windows machine. Syncthing seems to ignore if the interface is actually useable because it keeps announcing the manually configured IP of my winTUN interface.

It also announces a bunch of link-local 169.254.0.0/16 addresses but i can't ping any of them so i suspect that they are also from some interface but couldn't find anything in `ipconfig /all`


Discussion / hints:
Yeah, we use net.InterfaceAddrs which I think doesn't care, we should probably iterate interfaces manually and check the relevant flags ourselves.

(That said, the only definition of "usable" we can implement is "does it have `FlagUp` set". That doesn't necessary mean it's physically connected to anything, or to anything useful, or is a physical interface to begin with, etc.)
"Usable" is probably the wrong term. Checking if the interface is considered up is exactly what i had in mind.
Please note that sometimes it is desirable to announce a non-local IP address. I use this to announce the IP address of a 6tunnel endpoint that converts IPv4 traffic for my IPv6-only Syncthing installation. Hence, I would prefer "usable" over "local interface address".
Syncthing is only able to collect interface addresses and external addresses resolved via STUN. I guess that your usecase works because STUN is able detect the public IPv4 of your tunnel?

Changing the behaviour for local interfaces won't impact STUN.
> Syncthing is only able to collect interface addresses and external addresses resolved via STUN. I guess that your usecase works because STUN is able detect the public IPv4 of your tunnel?
> 
> Changing the behaviour for local interfaces won't impact STUN.

Frankly, I added the address manually in the settings. It should not be filtered out, though.
https://app.bountysource.com/issues/97258542-syncthing-announces-address-of-interface-which-is-down

Would be nice if you could also look into adding support for #7456 
Added $10 to get rid of this 😄 

Fix patch:
diff --git a/lib/osutil/lan.go b/lib/osutil/lan.go
index 68bdfcdaf39..2b498416a29 100644
--- a/lib/osutil/lan.go
+++ b/lib/osutil/lan.go
@@ -11,10 +11,21 @@ import (
 )
 
 func GetLans() ([]*net.IPNet, error) {
-	addrs, err := net.InterfaceAddrs()
+	ifs, err := net.Interfaces()
 	if err != nil {
 		return nil, err
 	}
+	addrs := []net.Addr{}
+	for _, currentIf := range ifs {
+		if currentIf.Flags&net.FlagUp != net.FlagUp {
+			continue
+		}
+		currentAddrs, err := currentIf.Addrs()
+		if err != nil {
+			return nil, err
+		}
+		addrs = append(addrs, currentAddrs...)
+	}
 
 	nets := make([]*net.IPNet, 0, len(addrs))
 


Test patch: