@ -100,6 +100,8 @@ type LocalBackend struct {
filterHash deephash . Sum
filterHash deephash . Sum
filterAtomic atomic . Value // of *filter.Filter
// The mutex protects the following elements.
// The mutex protects the following elements.
mu sync . Mutex
mu sync . Mutex
httpTestClient * http . Client // for controlclient. nil by default, used by tests.
httpTestClient * http . Client // for controlclient. nil by default, used by tests.
@ -160,9 +162,6 @@ func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, e wge
osshare . SetFileSharingEnabled ( false , logf )
osshare . SetFileSharingEnabled ( false , logf )
// Default filter blocks everything and logs nothing, until Start() is called.
e . SetFilter ( filter . NewAllowNone ( logf , & netaddr . IPSet { } ) )
ctx , cancel := context . WithCancel ( context . Background ( ) )
ctx , cancel := context . WithCancel ( context . Background ( ) )
portpoll , err := portlist . NewPoller ( )
portpoll , err := portlist . NewPoller ( )
if err != nil {
if err != nil {
@ -182,6 +181,9 @@ func NewLocalBackend(logf logger.Logf, logid string, store ipn.StateStore, e wge
portpoll : portpoll ,
portpoll : portpoll ,
gotPortPollRes : make ( chan struct { } ) ,
gotPortPollRes : make ( chan struct { } ) ,
}
}
// Default filter blocks everything and logs nothing, until Start() is called.
b . setFilter ( filter . NewAllowNone ( logf , & netaddr . IPSet { } ) )
b . statusChanged = sync . NewCond ( & b . statusLock )
b . statusChanged = sync . NewCond ( & b . statusLock )
b . e . SetStatusCallback ( b . setWgengineStatus )
b . e . SetStatusCallback ( b . setWgengineStatus )
@ -1011,20 +1013,25 @@ func (b *LocalBackend) updateFilter(netMap *netmap.NetworkMap, prefs *ipn.Prefs)
if ! haveNetmap {
if ! haveNetmap {
b . logf ( "netmap packet filter: (not ready yet)" )
b . logf ( "netmap packet filter: (not ready yet)" )
b . e . S etFilter( filter . NewAllowNone ( b . logf , logNets ) )
b . s etFilter( filter . NewAllowNone ( b . logf , logNets ) )
return
return
}
}
oldFilter := b . e . GetFilter ( )
oldFilter := b . e . GetFilter ( )
if shieldsUp {
if shieldsUp {
b . logf ( "netmap packet filter: (shields up)" )
b . logf ( "netmap packet filter: (shields up)" )
b . e . S etFilter( filter . NewShieldsUpFilter ( localNets , logNets , oldFilter , b . logf ) )
b . s etFilter( filter . NewShieldsUpFilter ( localNets , logNets , oldFilter , b . logf ) )
} else {
} else {
b . logf ( "netmap packet filter: %v filters" , len ( packetFilter ) )
b . logf ( "netmap packet filter: %v filters" , len ( packetFilter ) )
b . e . S etFilter( filter . New ( packetFilter , localNets , logNets , oldFilter , b . logf ) )
b . s etFilter( filter . New ( packetFilter , localNets , logNets , oldFilter , b . logf ) )
}
}
}
}
func ( b * LocalBackend ) setFilter ( f * filter . Filter ) {
b . filterAtomic . Store ( f )
b . e . SetFilter ( f )
}
var removeFromDefaultRoute = [ ] netaddr . IPPrefix {
var removeFromDefaultRoute = [ ] netaddr . IPPrefix {
// RFC1918 LAN ranges
// RFC1918 LAN ranges
netaddr . MustParseIPPrefix ( "192.168.0.0/16" ) ,
netaddr . MustParseIPPrefix ( "192.168.0.0/16" ) ,