Skip to content

Commit

Permalink
avoid netlink dos networkUpdateMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx authored and nekohasekai committed Apr 6, 2024
1 parent cddf605 commit fc63ec9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions monitor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"
"runtime"
"sync"
"time"

"github.com/sagernet/netlink"
E "github.com/sagernet/sing/common/exceptions"
Expand Down Expand Up @@ -67,6 +68,9 @@ func (m *networkUpdateMonitor) Start() error {
}

func (m *networkUpdateMonitor) loopUpdate() {
const minDuration = time.Second
timer := time.NewTimer(minDuration)
defer timer.Stop()
for {
select {
case <-m.close:
Expand All @@ -75,6 +79,12 @@ func (m *networkUpdateMonitor) loopUpdate() {
case <-m.linkUpdate:
}
m.emit()
select {
case <-m.close:
return
case <-timer.C:
timer.Reset(minDuration)
}
}
}

Expand Down

0 comments on commit fc63ec9

Please sign in to comment.