diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 316a65de..8d2795c6 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -725,24 +725,6 @@ func syncthingMain(runtimeOptions RuntimeOptions) { weakhash.Enabled = true } - if (opts.MaxRecvKbps > 0 || opts.MaxSendKbps > 0) && !opts.LimitBandwidthInLan { - lans, _ = osutil.GetLans() - for _, lan := range opts.AlwaysLocalNets { - _, ipnet, err := net.ParseCIDR(lan) - if err != nil { - l.Infoln("Network", lan, "is malformed:", err) - continue - } - lans = append(lans, ipnet) - } - - networks := make([]string, len(lans)) - for i, lan := range lans { - networks[i] = lan.String() - } - l.Infoln("Local networks:", strings.Join(networks, ", ")) - } - dbFile := locations[locDatabase] ldb, err := db.Open(dbFile) @@ -818,7 +800,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) { // Start connection management - connectionsService := connections.NewService(cfg, myID, m, tlsCfg, cachedDiscovery, bepProtocolName, tlsDefaultCommonName, lans) + connectionsService := connections.NewService(cfg, myID, m, tlsCfg, cachedDiscovery, bepProtocolName, tlsDefaultCommonName) mainService.Add(connectionsService) if cfg.Options().GlobalAnnEnabled { diff --git a/lib/connections/service.go b/lib/connections/service.go index 3eb68b21..b555ebc3 100644 --- a/lib/connections/service.go +++ b/lib/connections/service.go @@ -19,6 +19,7 @@ import ( "github.com/syncthing/syncthing/lib/discover" "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/nat" + "github.com/syncthing/syncthing/lib/osutil" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/sync" "github.com/syncthing/syncthing/lib/util" @@ -79,7 +80,6 @@ type Service struct { conns chan internalConn bepProtocolName string tlsDefaultCommonName string - lans []*net.IPNet limiter *limiter natService *nat.Service natServiceToken *suture.ServiceToken @@ -94,7 +94,7 @@ type Service struct { } func NewService(cfg *config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg *tls.Config, discoverer discover.Finder, - bepProtocolName string, tlsDefaultCommonName string, lans []*net.IPNet) *Service { + bepProtocolName string, tlsDefaultCommonName string) *Service { service := &Service{ Supervisor: suture.New("connections.Service", suture.Spec{ @@ -110,7 +110,6 @@ func NewService(cfg *config.Wrapper, myID protocol.DeviceID, mdl Model, tlsCfg * conns: make(chan internalConn), bepProtocolName: bepProtocolName, tlsDefaultCommonName: tlsDefaultCommonName, - lans: lans, limiter: newLimiter(cfg), natService: nat.NewService(myID, cfg), @@ -429,12 +428,30 @@ func (s *Service) isLAN(addr net.Addr) bool { if !ok { return false } - for _, lan := range s.lans { + + if tcpaddr.IP.IsLoopback() { + return true + } + + for _, lan := range s.cfg.Options().AlwaysLocalNets { + _, ipnet, err := net.ParseCIDR(lan) + if err != nil { + l.Debugln("Network", lan, "is malformed:", err) + continue + } + if ipnet.Contains(tcpaddr.IP) { + return true + } + } + + lans, _ := osutil.GetLans() + for _, lan := range lans { if lan.Contains(tcpaddr.IP) { return true } } - return tcpaddr.IP.IsLoopback() + + return false } func (s *Service) createListener(factory listenerFactory, uri *url.URL) bool {