mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
- Move `util/grpc` and `util/net` to `client` so `internal` packages can be accessed - Add methods to return the next best interface after the NetBird interface. - Use `IP_UNICAST_IF` sock opt to force the outgoing interface for the NetBird `net.Dialer` and `net.ListenerConfig` to avoid routing loops. The interface is picked by the new route lookup method. - Some refactoring to avoid import cycles - Old behavior is available through `NB_USE_LEGACY_ROUTING=true` env var
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
//go:build ios
|
|
|
|
package systemops
|
|
|
|
import (
|
|
"net"
|
|
"net/netip"
|
|
"runtime"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/statemanager"
|
|
)
|
|
|
|
func (r *SysOps) SetupRouting([]net.IP, *statemanager.Manager, bool) error {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
r.prefixes = make(map[netip.Prefix]struct{})
|
|
return nil
|
|
}
|
|
|
|
func (r *SysOps) CleanupRouting(*statemanager.Manager, bool) error {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
|
|
r.prefixes = make(map[netip.Prefix]struct{})
|
|
r.notify()
|
|
return nil
|
|
}
|
|
|
|
func (r *SysOps) AddVPNRoute(prefix netip.Prefix, _ *net.Interface) error {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
|
|
r.prefixes[prefix] = struct{}{}
|
|
r.notify()
|
|
return nil
|
|
}
|
|
|
|
func (r *SysOps) RemoveVPNRoute(prefix netip.Prefix, _ *net.Interface) error {
|
|
r.mu.Lock()
|
|
defer r.mu.Unlock()
|
|
|
|
delete(r.prefixes, prefix)
|
|
r.notify()
|
|
return nil
|
|
}
|
|
|
|
func (r *SysOps) notify() {
|
|
prefixes := make([]netip.Prefix, 0, len(r.prefixes))
|
|
for prefix := range r.prefixes {
|
|
prefixes = append(prefixes, prefix)
|
|
}
|
|
r.notifier.OnNewPrefixes(prefixes)
|
|
}
|
|
|
|
func (r *SysOps) removeFromRouteTable(netip.Prefix, Nexthop) error {
|
|
return nil
|
|
}
|
|
|
|
func EnableIPForwarding() error {
|
|
log.Infof("Enable IP forwarding is not implemented on %s", runtime.GOOS)
|
|
return nil
|
|
}
|
|
|
|
func IsAddrRouted(netip.Addr, []netip.Prefix) (bool, netip.Prefix) {
|
|
return false, netip.Prefix{}
|
|
}
|