2024-10-24 10:53:46 +02:00
|
|
|
package systemops
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/netip"
|
|
|
|
"sync"
|
|
|
|
|
2024-10-24 14:46:24 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
|
2024-10-24 10:53:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type ShutdownState struct {
|
2024-10-24 14:46:24 +02:00
|
|
|
Counter *ExclusionCounter `json:"counter,omitempty"`
|
|
|
|
mu sync.RWMutex
|
2024-10-24 10:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShutdownState) Name() string {
|
|
|
|
return "route_state"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShutdownState) Cleanup() error {
|
|
|
|
s.mu.RLock()
|
|
|
|
defer s.mu.RUnlock()
|
|
|
|
|
2024-10-24 14:46:24 +02:00
|
|
|
if s.Counter == nil {
|
|
|
|
return nil
|
2024-10-24 10:53:46 +02:00
|
|
|
}
|
|
|
|
|
2024-10-24 14:46:24 +02:00
|
|
|
sysops := NewSysOps(nil, nil)
|
|
|
|
sysops.refCounter = refcounter.New[netip.Prefix, struct{}, Nexthop](nil, sysops.removeFromRouteTable)
|
|
|
|
sysops.refCounter.LoadData(s.Counter)
|
2024-10-24 10:53:46 +02:00
|
|
|
|
2024-10-24 14:46:24 +02:00
|
|
|
return sysops.refCounter.Flush()
|
2024-10-24 10:53:46 +02:00
|
|
|
}
|