tun: linux: do not spam events every second from hack listener
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
6005c573e2
commit
c5f382624e
|
@ -55,6 +55,11 @@ func (tun *NativeTun) routineHackListener() {
|
||||||
/* This is needed for the detection to work across network namespaces
|
/* 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.
|
* If you are reading this and know a better method, please get in touch.
|
||||||
*/
|
*/
|
||||||
|
last := 0
|
||||||
|
const (
|
||||||
|
up = 1
|
||||||
|
down = 2
|
||||||
|
)
|
||||||
for {
|
for {
|
||||||
sysconn, err := tun.tunFile.SyscallConn()
|
sysconn, err := tun.tunFile.SyscallConn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -68,13 +73,19 @@ func (tun *NativeTun) routineHackListener() {
|
||||||
}
|
}
|
||||||
switch err {
|
switch err {
|
||||||
case unix.EINVAL:
|
case unix.EINVAL:
|
||||||
|
if last != up {
|
||||||
// If the tunnel is up, it reports that write() is
|
// If the tunnel is up, it reports that write() is
|
||||||
// allowed but we provided invalid data.
|
// allowed but we provided invalid data.
|
||||||
tun.events <- EventUp
|
tun.events <- EventUp
|
||||||
|
last = up
|
||||||
|
}
|
||||||
case unix.EIO:
|
case unix.EIO:
|
||||||
|
if last != down {
|
||||||
// If the tunnel is down, it reports that no I/O
|
// If the tunnel is down, it reports that no I/O
|
||||||
// is possible, without checking our provided data.
|
// is possible, without checking our provided data.
|
||||||
tun.events <- EventDown
|
tun.events <- EventDown
|
||||||
|
last = down
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue