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 8, 2022
1 parent 6b417a8 commit a4b82dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 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
18 changes: 13 additions & 5 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,18 @@ 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 {
networkID := getHANetworkID(newRoute)
if ownNetworkIDs[networkID] {
// 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,8 +173,7 @@ func (m *DefaultManager) UpdateRoutes(updateSerial uint64, newRoutes []*route.Ro
system.NetbirdVersion(), newRoute.Network)
continue
}
clientNetworkID := getClientNetworkID(newRoute)
newClientRoutesIDMap[clientNetworkID] = append(newClientRoutesIDMap[clientNetworkID], newRoute)
newClientRoutesIDMap[networkID] = append(newClientRoutesIDMap[networkID], newRoute)
}
}

Expand Down

0 comments on commit a4b82dc

Please sign in to comment.