2024-06-13 13:24:24 +02:00
|
|
|
package systemops
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/netip"
|
2024-07-15 10:40:57 +02:00
|
|
|
"sync"
|
2024-06-13 13:24:24 +02:00
|
|
|
|
2024-07-15 10:40:57 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/notifier"
|
2024-06-13 13:24:24 +02:00
|
|
|
"github.com/netbirdio/netbird/client/internal/routemanager/refcounter"
|
|
|
|
"github.com/netbirdio/netbird/iface"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Nexthop struct {
|
|
|
|
IP netip.Addr
|
|
|
|
Intf *net.Interface
|
|
|
|
}
|
|
|
|
|
2024-10-02 13:41:00 +02:00
|
|
|
type ExclusionCounter = refcounter.Counter[netip.Prefix, struct{}, Nexthop]
|
2024-06-13 13:24:24 +02:00
|
|
|
|
|
|
|
type SysOps struct {
|
|
|
|
refCounter *ExclusionCounter
|
2024-08-29 21:31:19 +02:00
|
|
|
wgInterface iface.IWGIface
|
2024-07-15 10:40:57 +02:00
|
|
|
// prefixes is tracking all the current added prefixes im memory
|
|
|
|
// (this is used in iOS as all route updates require a full table update)
|
|
|
|
//nolint
|
|
|
|
prefixes map[netip.Prefix]struct{}
|
|
|
|
//nolint
|
|
|
|
mu sync.Mutex
|
|
|
|
// notifier is used to notify the system of route changes (also used on mobile)
|
|
|
|
notifier *notifier.Notifier
|
2024-06-13 13:24:24 +02:00
|
|
|
}
|
|
|
|
|
2024-08-29 21:31:19 +02:00
|
|
|
func NewSysOps(wgInterface iface.IWGIface, notifier *notifier.Notifier) *SysOps {
|
2024-06-13 13:24:24 +02:00
|
|
|
return &SysOps{
|
|
|
|
wgInterface: wgInterface,
|
2024-07-15 10:40:57 +02:00
|
|
|
notifier: notifier,
|
2024-06-13 13:24:24 +02:00
|
|
|
}
|
|
|
|
}
|