mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-02-03 22:18:39 +00:00
By adding a logger field to "prog" struct, and use this field inside its method instead of always accessing global mainLog variable. This at least ensure more consistent usage of the logger during ctrld prog runtime, and also help refactoring the code more easily in the future (like replacing the logger library).
37 lines
721 B
Go
37 lines
721 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/vishvananda/netlink"
|
|
"golang.org/x/sys/unix"
|
|
|
|
"github.com/Control-D-Inc/ctrld"
|
|
)
|
|
|
|
func (p *prog) watchLinkState(ctx context.Context) {
|
|
ch := make(chan netlink.LinkUpdate)
|
|
done := make(chan struct{})
|
|
defer close(done)
|
|
if err := netlink.LinkSubscribe(ch, done); err != nil {
|
|
p.Warn().Err(err).Msg("could not subscribe link")
|
|
return
|
|
}
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case lu := <-ch:
|
|
if lu.Change == 0xFFFFFFFF {
|
|
continue
|
|
}
|
|
if lu.Change&unix.IFF_UP != 0 {
|
|
p.Debug().Msgf("link state changed, re-bootstrapping")
|
|
for _, uc := range p.cfg.Upstream {
|
|
uc.ReBootstrap(ctrld.LoggerCtx(ctx, p.logger.Load()))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|