aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-03-11 09:23:11 -0700
committerJason A. Donenfeld <Jason@zx2c4.com>2021-03-11 09:23:11 -0700
commitc5f382624ee45df7b17e14800d361159eb924e6f (patch)
tree3fccc8fef4a8f071f419f1fd408108d83eef475d
parenttun: freebsd: allow empty names (diff)
downloadwireguard-go-c5f382624ee45df7b17e14800d361159eb924e6f.tar.xz
wireguard-go-c5f382624ee45df7b17e14800d361159eb924e6f.zip
tun: linux: do not spam events every second from hack listener
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--tun/tun_linux.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/tun/tun_linux.go b/tun/tun_linux.go
index e0c9878..46eb171 100644
--- a/tun/tun_linux.go
+++ b/tun/tun_linux.go
@@ -55,6 +55,11 @@ func (tun *NativeTun) routineHackListener() {
/* 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.
*/
+ last := 0
+ const (
+ up = 1
+ down = 2
+ )
for {
sysconn, err := tun.tunFile.SyscallConn()
if err != nil {
@@ -68,13 +73,19 @@ func (tun *NativeTun) routineHackListener() {
}
switch err {
case unix.EINVAL:
- // If the tunnel is up, it reports that write() is
- // allowed but we provided invalid data.
- tun.events <- EventUp
+ if last != up {
+ // If the tunnel is up, it reports that write() is
+ // allowed but we provided invalid data.
+ tun.events <- EventUp
+ last = up
+ }
case unix.EIO:
- // If the tunnel is down, it reports that no I/O
- // is possible, without checking our provided data.
- tun.events <- EventDown
+ if last != down {
+ // If the tunnel is down, it reports that no I/O
+ // is possible, without checking our provided data.
+ tun.events <- EventDown
+ last = down
+ }
default:
return
}