Skip to content

Commit

Permalink
HA Network Routes: prevent routing directly-accessible networks throu…
Browse files Browse the repository at this point in the history
…gh VPN interface

fixes: #598
  • Loading branch information
nazarewk committed Dec 7, 2022
1 parent 6b417a8 commit 4e6823f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions client/internal/routemanager/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package routemanager
import (
"context"
"fmt"
"net/netip"

"github.com/netbirdio/netbird/client/internal/peer"
"github.com/netbirdio/netbird/client/status"
"github.com/netbirdio/netbird/iface"
"github.com/netbirdio/netbird/route"
log "github.com/sirupsen/logrus"
"net/netip"
)

type routerPeerStatus struct {
Expand Down Expand Up @@ -52,7 +53,7 @@ func newClientNetworkWatcher(ctx context.Context, wgInterface *iface.WGIface, st
return client
}

func getClientNetworkID(input *route.Route) string {
func getHANetworkID(input *route.Route) string {
return input.NetID + "-" + input.Network.String()
}

Expand Down
16 changes: 12 additions & 4 deletions client/internal/routemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package routemanager
import (
"context"
"fmt"
"runtime"
"sync"

"github.com/netbirdio/netbird/client/status"
"github.com/netbirdio/netbird/client/system"
"github.com/netbirdio/netbird/iface"
"github.com/netbirdio/netbird/route"
log "github.com/sirupsen/logrus"
"runtime"
"sync"
)

// Manager is a route manager interface
Expand Down Expand Up @@ -147,10 +148,17 @@ func (m *DefaultManager) UpdateRoutes(updateSerial uint64, newRoutes []*route.Ro

newClientRoutesIDMap := make(map[string][]*route.Route)
newServerRoutesMap := make(map[string]*route.Route)
ownNetworkIDs := make(map[string]bool)

for _, newRoute := range newRoutes {
// only linux is supported for now
if newRoute.Peer == m.pubKey {
ownNetworkIDs[getHANetworkID(newRoute)] = true
}
}

for _, newRoute := range newRoutes {
if ownNetworkIDs[getHANetworkID(newRoute)] {
// only linux is supported for now
if runtime.GOOS != "linux" {
log.Warnf("received a route to manage, but agent doesn't support router mode on %s OS", runtime.GOOS)
continue
Expand All @@ -164,7 +172,7 @@ func (m *DefaultManager) UpdateRoutes(updateSerial uint64, newRoutes []*route.Ro
system.NetbirdVersion(), newRoute.Network)
continue
}
clientNetworkID := getClientNetworkID(newRoute)
clientNetworkID := getHANetworkID(newRoute)
newClientRoutesIDMap[clientNetworkID] = append(newClientRoutesIDMap[clientNetworkID], newRoute)
}
}
Expand Down

0 comments on commit 4e6823f

Please sign in to comment.