mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-22 23:33:09 +01:00
Close hack listener before closing channel
This commit is contained in:
parent
e28d70f5b2
commit
6307bfcdf4
@ -22,6 +22,7 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
@ -41,7 +42,7 @@ type NativeTun struct {
|
||||
nopi bool // the device was pased IFF_NO_PI
|
||||
netlinkSock int
|
||||
netlinkCancel *rwcancel.RWCancel
|
||||
|
||||
hackListenerClosed sync.Mutex
|
||||
statusListenersShutdown chan struct{}
|
||||
}
|
||||
|
||||
@ -50,6 +51,7 @@ func (tun *NativeTun) File() *os.File {
|
||||
}
|
||||
|
||||
func (tun *NativeTun) RoutineHackListener() {
|
||||
defer tun.hackListenerClosed.Unlock()
|
||||
/* This is needed for the detection to work across network namespaces
|
||||
* If you are reading this and know a better method, please get in touch.
|
||||
*/
|
||||
@ -91,6 +93,7 @@ func createNetlinkSocket() (int, error) {
|
||||
func (tun *NativeTun) RoutineNetlinkListener() {
|
||||
defer func() {
|
||||
unix.Close(tun.netlinkSock)
|
||||
tun.hackListenerClosed.Lock()
|
||||
close(tun.events)
|
||||
}()
|
||||
|
||||
@ -455,6 +458,7 @@ func CreateTUNFromFile(fd *os.File) (TUNDevice, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tun.hackListenerClosed.Lock()
|
||||
go tun.RoutineNetlinkListener()
|
||||
go tun.RoutineHackListener() // cross namespace
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user