all: watch link state on Linux using netlink

So we can detect changed to link and trigger re-bootstrap.
This commit is contained in:
Cuong Manh Le
2023-04-29 13:56:18 +07:00
committed by Cuong Manh Le
parent 56d8dc865f
commit 5cad0d6be1
8 changed files with 60 additions and 43 deletions
+27
View File
@@ -0,0 +1,27 @@
package main
import (
"github.com/vishvananda/netlink"
"golang.org/x/sys/unix"
)
func (p *prog) watchLinkState() {
ch := make(chan netlink.LinkUpdate)
done := make(chan struct{})
defer close(done)
if err := netlink.LinkSubscribe(ch, done); err != nil {
mainLog.Warn().Err(err).Msg("could not subscribe link")
return
}
for lu := range ch {
if lu.Change == 0xFFFFFFFF {
continue
}
if lu.Change&unix.IFF_UP != 0 {
mainLog.Debug().Msgf("link state changed, re-bootstrapping")
for _, uc := range p.cfg.Upstream {
uc.ReBootstrap()
}
}
}
}
+5
View File
@@ -0,0 +1,5 @@
//go:build !linux
package main
func (p *prog) watchLinkState() {}
+2
View File
@@ -82,6 +82,8 @@ func (p *prog) run() {
uc.SetupTransport()
}
go p.watchLinkState()
for listenerNum := range p.cfg.Listener {
p.cfg.Listener[listenerNum].Init()
go func(listenerNum string) {