mirror of https://github.com/jetkvm/kvm.git
fix(lldp): use mutexes to protect state
This commit is contained in:
parent
15484f889e
commit
826e5155b2
|
|
@ -102,10 +102,10 @@ func (l *LLDP) Start() error {
|
||||||
|
|
||||||
// StartRx starts the LLDP receiver if not already running
|
// StartRx starts the LLDP receiver if not already running
|
||||||
func (l *LLDP) startRx() error {
|
func (l *LLDP) startRx() error {
|
||||||
l.mu.Lock()
|
l.mu.RLock()
|
||||||
running := l.rxRunning
|
running := l.rxRunning
|
||||||
enabled := l.enableRx
|
enabled := l.enableRx
|
||||||
l.mu.Unlock()
|
l.mu.RUnlock()
|
||||||
|
|
||||||
if running || !enabled {
|
if running || !enabled {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,11 @@ func (l *LLDP) setUpCapture() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LLDP) doCapture(logger *zerolog.Logger) {
|
func (l *LLDP) doCapture(logger *zerolog.Logger) {
|
||||||
|
if l.pktSourceRx == nil || l.rxCtx == nil {
|
||||||
|
logger.Error().Msg("packet source or RX context not initialized")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
l.rxWaitGroup.Add(1)
|
l.rxWaitGroup.Add(1)
|
||||||
defer l.rxWaitGroup.Done()
|
defer l.rxWaitGroup.Done()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,9 @@ func (l *LLDP) startTx() error {
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l.mu.Lock()
|
||||||
l.txCtx, l.txCancel = context.WithCancel(context.Background())
|
l.txCtx, l.txCancel = context.WithCancel(context.Background())
|
||||||
|
l.mu.Unlock()
|
||||||
|
|
||||||
if err := l.setUpTx(); err != nil {
|
if err := l.setUpTx(); err != nil {
|
||||||
return fmt.Errorf("failed to set up TX: %w", err)
|
return fmt.Errorf("failed to set up TX: %w", err)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue