Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func (e *Engine) Start(netbirdConfig *mgmProto.NetbirdConfig, mgmtURL *url.URL)
e.routeManager.SetRouteChangeListener(e.mobileDep.NetworkChangeListener)

e.dnsServer.SetRouteChecker(func(ip netip.Addr) bool {
for _, routes := range e.routeManager.GetClientRoutes() {
for _, routes := range e.routeManager.GetSelectedClientRoutes() {
for _, r := range routes {
if r.Network.Contains(ip) {
return true
Expand Down
11 changes: 11 additions & 0 deletions client/internal/routemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Manager interface {
TriggerSelection(route.HAMap)
GetRouteSelector() *routeselector.RouteSelector
GetClientRoutes() route.HAMap
GetSelectedClientRoutes() route.HAMap
GetClientRoutesWithNetID() map[route.NetID][]*route.Route
SetRouteChangeListener(listener listener.NetworkChangeListener)
InitialRouteRange() []string
Expand Down Expand Up @@ -465,6 +466,16 @@ func (m *DefaultManager) GetClientRoutes() route.HAMap {
return maps.Clone(m.clientRoutes)
}

// GetSelectedClientRoutes returns only the currently selected/active client routes,
// filtering out deselected exit nodes. Use this instead of GetClientRoutes when checking
// if traffic should be routed through the tunnel.
func (m *DefaultManager) GetSelectedClientRoutes() route.HAMap {
m.mux.Lock()
defer m.mux.Unlock()

return m.routeSelector.FilterSelectedExitNodes(maps.Clone(m.clientRoutes))
}

// GetClientRoutesWithNetID returns the current routes from the route map, but the keys consist of the network ID only
func (m *DefaultManager) GetClientRoutesWithNetID() map[route.NetID][]*route.Route {
m.mux.Lock()
Expand Down
8 changes: 8 additions & 0 deletions client/internal/routemanager/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
return nil
}

// GetSelectedClientRoutes mock implementation of GetSelectedClientRoutes from Manager interface
func (m *MockManager) GetSelectedClientRoutes() route.HAMap {

Check warning on line 73 in client/internal/routemanager/mock.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Update this function so that its implementation is not identical to "GetClientRoutes" on line 65.

See more on https://sonarcloud.io/project/issues?id=netbirdio_netbird&issues=AZ1dXfkJ7Pzve-iurWES&open=AZ1dXfkJ7Pzve-iurWES&pullRequest=5802
if m.GetClientRoutesFunc != nil {
return m.GetClientRoutesFunc()
}
return nil
}

// GetClientRoutesWithNetID mock implementation of GetClientRoutesWithNetID from Manager interface
func (m *MockManager) GetClientRoutesWithNetID() map[route.NetID][]*route.Route {
if m.GetClientRoutesWithNetIDFunc != nil {
Expand Down
Loading