mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2025-07-28 16:02:50 +02:00
tun/netstack: cleanup network stack at closing time
Colin's commit went a step further and protected tun.incomingPacket with a lock on shutdown, but let's see if the tun.stack.Close() call actually solves that on its own. Suggested-by: kshangx <hikeshang@hotmail.com> Suggested-by: Colin Adler <colin1adler@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
6a7c878409
commit
ac8a885a03
1 changed files with 5 additions and 3 deletions
|
@ -43,6 +43,7 @@ type netTun struct {
|
||||||
ep *channel.Endpoint
|
ep *channel.Endpoint
|
||||||
stack *stack.Stack
|
stack *stack.Stack
|
||||||
events chan tun.Event
|
events chan tun.Event
|
||||||
|
notifyHandle *channel.NotificationHandle
|
||||||
incomingPacket chan *buffer.View
|
incomingPacket chan *buffer.View
|
||||||
mtu int
|
mtu int
|
||||||
dnsServers []netip.Addr
|
dnsServers []netip.Addr
|
||||||
|
@ -70,7 +71,7 @@ func CreateNetTUN(localAddresses, dnsServers []netip.Addr, mtu int) (tun.Device,
|
||||||
if tcpipErr != nil {
|
if tcpipErr != nil {
|
||||||
return nil, nil, fmt.Errorf("could not enable TCP SACK: %v", tcpipErr)
|
return nil, nil, fmt.Errorf("could not enable TCP SACK: %v", tcpipErr)
|
||||||
}
|
}
|
||||||
dev.ep.AddNotify(dev)
|
dev.notifyHandle = dev.ep.AddNotify(dev)
|
||||||
tcpipErr = dev.stack.CreateNIC(1, dev.ep)
|
tcpipErr = dev.stack.CreateNIC(1, dev.ep)
|
||||||
if tcpipErr != nil {
|
if tcpipErr != nil {
|
||||||
return nil, nil, fmt.Errorf("CreateNIC: %v", tcpipErr)
|
return nil, nil, fmt.Errorf("CreateNIC: %v", tcpipErr)
|
||||||
|
@ -167,13 +168,14 @@ func (tun *netTun) WriteNotify() {
|
||||||
|
|
||||||
func (tun *netTun) Close() error {
|
func (tun *netTun) Close() error {
|
||||||
tun.stack.RemoveNIC(1)
|
tun.stack.RemoveNIC(1)
|
||||||
|
tun.stack.Close()
|
||||||
|
tun.ep.RemoveNotify(tun.notifyHandle)
|
||||||
|
tun.ep.Close()
|
||||||
|
|
||||||
if tun.events != nil {
|
if tun.events != nil {
|
||||||
close(tun.events)
|
close(tun.events)
|
||||||
}
|
}
|
||||||
|
|
||||||
tun.ep.Close()
|
|
||||||
|
|
||||||
if tun.incomingPacket != nil {
|
if tun.incomingPacket != nil {
|
||||||
close(tun.incomingPacket)
|
close(tun.incomingPacket)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue