wgengine/netstack: add an Impl.Close method for tests
Change-Id: Idbb3fd6d749d3e4effdf96de77a1106584822fef Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>pull/3769/head
parent
166fe3fb12
commit
790e41645b
|
@ -72,13 +72,15 @@ type Impl struct {
|
||||||
// It can only be set before calling Start.
|
// It can only be set before calling Start.
|
||||||
ProcessSubnets bool
|
ProcessSubnets bool
|
||||||
|
|
||||||
ipstack *stack.Stack
|
ipstack *stack.Stack
|
||||||
linkEP *channel.Endpoint
|
linkEP *channel.Endpoint
|
||||||
tundev *tstun.Wrapper
|
tundev *tstun.Wrapper
|
||||||
e wgengine.Engine
|
e wgengine.Engine
|
||||||
mc *magicsock.Conn
|
mc *magicsock.Conn
|
||||||
logf logger.Logf
|
logf logger.Logf
|
||||||
dialer *tsdial.Dialer
|
dialer *tsdial.Dialer
|
||||||
|
ctx context.Context // alive until Close
|
||||||
|
ctxCancel context.CancelFunc // called on Close
|
||||||
|
|
||||||
// atomicIsLocalIPFunc holds a func that reports whether an IP
|
// atomicIsLocalIPFunc holds a func that reports whether an IP
|
||||||
// is a local (non-subnet) Tailscale IP address of this
|
// is a local (non-subnet) Tailscale IP address of this
|
||||||
|
@ -152,10 +154,16 @@ func Create(logf logger.Logf, tundev *tstun.Wrapper, e wgengine.Engine, mc *magi
|
||||||
dialer: dialer,
|
dialer: dialer,
|
||||||
connsOpenBySubnetIP: make(map[netaddr.IP]int),
|
connsOpenBySubnetIP: make(map[netaddr.IP]int),
|
||||||
}
|
}
|
||||||
|
ns.ctx, ns.ctxCancel = context.WithCancel(context.Background())
|
||||||
ns.atomicIsLocalIPFunc.Store(tsaddr.NewContainsIPFunc(nil))
|
ns.atomicIsLocalIPFunc.Store(tsaddr.NewContainsIPFunc(nil))
|
||||||
return ns, nil
|
return ns, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ns *Impl) Close() error {
|
||||||
|
ns.ctxCancel()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// wrapProtoHandler returns protocol handler h wrapped in a version
|
// wrapProtoHandler returns protocol handler h wrapped in a version
|
||||||
// that dynamically reconfigures ns's subnet addresses as needed for
|
// that dynamically reconfigures ns's subnet addresses as needed for
|
||||||
// outbound traffic.
|
// outbound traffic.
|
||||||
|
@ -347,8 +355,12 @@ func (ns *Impl) DialContextUDP(ctx context.Context, ipp netaddr.IPPort) (*gonet.
|
||||||
|
|
||||||
func (ns *Impl) injectOutbound() {
|
func (ns *Impl) injectOutbound() {
|
||||||
for {
|
for {
|
||||||
packetInfo, ok := ns.linkEP.ReadContext(context.Background())
|
packetInfo, ok := ns.linkEP.ReadContext(ns.ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
if ns.ctx.Err() != nil {
|
||||||
|
// Return without logging.
|
||||||
|
return
|
||||||
|
}
|
||||||
ns.logf("[v2] ReadContext-for-write = ok=false")
|
ns.logf("[v2] ReadContext-for-write = ok=false")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue