cmd: allow import/running ctrld as library

This commit is contained in:
Cuong Manh Le
2023-08-15 11:15:37 +00:00
committed by Cuong Manh Le
parent 4896563e3c
commit 829e93c079
34 changed files with 195 additions and 188 deletions
+27
View File
@@ -0,0 +1,27 @@
package cli
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.Load().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.Load().Debug().Msgf("link state changed, re-bootstrapping")
for _, uc := range p.cfg.Upstream {
uc.ReBootstrap()
}
}
}
}