mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-03-13 10:26:06 +00:00
refactor(network): consolidate network change monitoring
Remove separate watchLinkState function and integrate link state change handling directly into monitorNetworkChanges. This consolidates network monitoring logic into a single place and simplifies the codebase. Update netlink dependency from v1.2.1-beta.2 to v1.3.1 and netns from v0.0.4 to v0.0.5 to use stable versions.
This commit is contained in:
committed by
Cuong Manh Le
parent
256ed7b938
commit
bdb8bedba1
@@ -1530,6 +1530,11 @@ func (p *prog) monitorNetworkChanges(ctx context.Context) error {
|
||||
return
|
||||
}
|
||||
|
||||
p.Debug().Msg("Link state changed, re-bootstrapping")
|
||||
for _, uc := range p.cfg.Upstream {
|
||||
uc.ReBootstrap(ctrld.LoggerCtx(ctx, p.logger.Load()))
|
||||
}
|
||||
|
||||
// Get IPs from default route interface in new state
|
||||
selfIP := p.defaultRouteIP()
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
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()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
//go:build !linux
|
||||
|
||||
package cli
|
||||
|
||||
import "context"
|
||||
|
||||
func (p *prog) watchLinkState(ctx context.Context) {}
|
||||
@@ -515,7 +515,6 @@ func (p *prog) run(reload bool, reloadCh chan struct{}) {
|
||||
defer wg.Done()
|
||||
p.runClientInfoDiscover(ctx)
|
||||
}()
|
||||
go p.watchLinkState(ctx)
|
||||
}
|
||||
|
||||
if !reload {
|
||||
|
||||
Reference in New Issue
Block a user