mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 15:26:40 +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
68 lines
1.4 KiB
Go
68 lines
1.4 KiB
Go
//go:build windows
|
|
|
|
package net
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"sync"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/netbirdio/netbird/client/iface/netstack"
|
|
)
|
|
|
|
var (
|
|
vpnInterfaceName string
|
|
vpnInitMutex sync.RWMutex
|
|
|
|
advancedRoutingSupported bool
|
|
)
|
|
|
|
func Init() {
|
|
advancedRoutingSupported = checkAdvancedRoutingSupport()
|
|
}
|
|
|
|
func checkAdvancedRoutingSupport() bool {
|
|
var err error
|
|
var legacyRouting bool
|
|
if val := os.Getenv(envUseLegacyRouting); val != "" {
|
|
legacyRouting, err = strconv.ParseBool(val)
|
|
if err != nil {
|
|
log.Warnf("failed to parse %s: %v", envUseLegacyRouting, err)
|
|
}
|
|
}
|
|
|
|
if legacyRouting || netstack.IsEnabled() {
|
|
log.Info("advanced routing has been requested to be disabled")
|
|
return false
|
|
}
|
|
|
|
log.Info("system supports advanced routing")
|
|
|
|
return true
|
|
}
|
|
|
|
// AdvancedRouting reports whether routing loops can be avoided without using exclusion routes
|
|
func AdvancedRouting() bool {
|
|
return advancedRoutingSupported
|
|
}
|
|
|
|
// GetVPNInterfaceName returns the stored VPN interface name
|
|
func GetVPNInterfaceName() string {
|
|
vpnInitMutex.RLock()
|
|
defer vpnInitMutex.RUnlock()
|
|
return vpnInterfaceName
|
|
}
|
|
|
|
// SetVPNInterfaceName sets the VPN interface name for lazy initialization
|
|
func SetVPNInterfaceName(name string) {
|
|
vpnInitMutex.Lock()
|
|
defer vpnInitMutex.Unlock()
|
|
vpnInterfaceName = name
|
|
|
|
if name != "" {
|
|
log.Infof("VPN interface name set to %s for route exclusion", name)
|
|
}
|
|
}
|