From 59b86002c4ef499d787ecdd3a64348ec76575883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 7 Aug 2023 15:26:26 +0800 Subject: [PATCH] Add no route event --- monitor.go | 5 +++-- monitor_shared.go | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/monitor.go b/monitor.go index 910570a..327eff5 100644 --- a/monitor.go +++ b/monitor.go @@ -15,8 +15,9 @@ type ( ) const ( - EventInterfaceUpdate = 1 - EventAndroidVPNUpdate = 2 + EventInterfaceUpdate = iota + EventAndroidVPNUpdate + EventNoRoute ) type NetworkUpdateMonitor interface { diff --git a/monitor_shared.go b/monitor_shared.go index dbd18c5..f6460d4 100644 --- a/monitor_shared.go +++ b/monitor_shared.go @@ -4,6 +4,7 @@ package tun import ( "context" + "errors" "net" "net/netip" "sync" @@ -84,7 +85,11 @@ func (m *defaultInterfaceMonitor) delayCheckUpdate() error { if err != nil { m.networkMonitor.NewError(context.Background(), E.Cause(err, "update interfaces")) } - return m.checkUpdate() + err = m.checkUpdate() + if errors.Is(err, ErrNoRoute) { + m.emit(EventNoRoute) + } + return err } func (m *defaultInterfaceMonitor) updateInterfaces() error {