lib/connections: Fix lan detection (fixes #4421)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4487
This commit is contained in:
parent
9c855ab22e
commit
62a4106a79
@ -725,24 +725,6 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
|
|||||||
weakhash.Enabled = true
|
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]
|
dbFile := locations[locDatabase]
|
||||||
ldb, err := db.Open(dbFile)
|
ldb, err := db.Open(dbFile)
|
||||||
|
|
||||||
@ -818,7 +800,7 @@ func syncthingMain(runtimeOptions RuntimeOptions) {
|
|||||||
|
|
||||||
// Start connection management
|
// 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)
|
mainService.Add(connectionsService)
|
||||||
|
|
||||||
if cfg.Options().GlobalAnnEnabled {
|
if cfg.Options().GlobalAnnEnabled {
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/syncthing/syncthing/lib/discover"
|
"github.com/syncthing/syncthing/lib/discover"
|
||||||
"github.com/syncthing/syncthing/lib/events"
|
"github.com/syncthing/syncthing/lib/events"
|
||||||
"github.com/syncthing/syncthing/lib/nat"
|
"github.com/syncthing/syncthing/lib/nat"
|
||||||
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"github.com/syncthing/syncthing/lib/protocol"
|
||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
"github.com/syncthing/syncthing/lib/util"
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
@ -79,7 +80,6 @@ type Service struct {
|
|||||||
conns chan internalConn
|
conns chan internalConn
|
||||||
bepProtocolName string
|
bepProtocolName string
|
||||||
tlsDefaultCommonName string
|
tlsDefaultCommonName string
|
||||||
lans []*net.IPNet
|
|
||||||
limiter *limiter
|
limiter *limiter
|
||||||
natService *nat.Service
|
natService *nat.Service
|
||||||
natServiceToken *suture.ServiceToken
|
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,
|
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{
|
service := &Service{
|
||||||
Supervisor: suture.New("connections.Service", suture.Spec{
|
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),
|
conns: make(chan internalConn),
|
||||||
bepProtocolName: bepProtocolName,
|
bepProtocolName: bepProtocolName,
|
||||||
tlsDefaultCommonName: tlsDefaultCommonName,
|
tlsDefaultCommonName: tlsDefaultCommonName,
|
||||||
lans: lans,
|
|
||||||
limiter: newLimiter(cfg),
|
limiter: newLimiter(cfg),
|
||||||
natService: nat.NewService(myID, cfg),
|
natService: nat.NewService(myID, cfg),
|
||||||
|
|
||||||
@ -429,12 +428,30 @@ func (s *Service) isLAN(addr net.Addr) bool {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return false
|
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) {
|
if lan.Contains(tcpaddr.IP) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tcpaddr.IP.IsLoopback()
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) createListener(factory listenerFactory, uri *url.URL) bool {
|
func (s *Service) createListener(factory listenerFactory, uri *url.URL) bool {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user