2024-10-24 10:53:46 +02:00
|
|
|
package systemops
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/netip"
|
|
|
|
|
2024-10-24 14:46:24 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
|
2024-10-24 10:53:46 +02:00
|
|
|
)
|
|
|
|
|
2024-11-15 20:05:26 +01:00
|
|
|
type ShutdownState ExclusionCounter
|
2024-10-24 10:53:46 +02:00
|
|
|
|
|
|
|
func (s *ShutdownState) Name() string {
|
|
|
|
return "route_state"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShutdownState) Cleanup() error {
|
2024-10-24 14:46:24 +02:00
|
|
|
sysops := NewSysOps(nil, nil)
|
|
|
|
sysops.refCounter = refcounter.New[netip.Prefix, struct{}, Nexthop](nil, sysops.removeFromRouteTable)
|
2024-11-15 20:05:26 +01:00
|
|
|
sysops.refCounter.LoadData((*ExclusionCounter)(s))
|
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
|
|
|
}
|
2024-11-15 20:05:26 +01:00
|
|
|
|
|
|
|
func (s *ShutdownState) MarshalJSON() ([]byte, error) {
|
|
|
|
return (*ExclusionCounter)(s).MarshalJSON()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *ShutdownState) UnmarshalJSON(data []byte) error {
|
|
|
|
return (*ExclusionCounter)(s).UnmarshalJSON(data)
|
|
|
|
}
|