Skip to content

Commit 916f410

Browse files
authored
Merge branch 'netbirdio:main' into main
2 parents 8694757 + 6a49351 commit 916f410

5 files changed

Lines changed: 45 additions & 27 deletions

File tree

client/internal/routemanager/client.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,16 @@ func (c *clientNetwork) getBestRouteFromStatuses(routePeerStatuses map[string]ro
153153

154154
log.Warnf("the network %s has not been assigned a routing peer as no peers from the list %s are currently connected", c.network, peers)
155155
case chosen != currID:
156-
if currScore != 0 && currScore < chosenScore+0.1 {
156+
// we compare the current score + 10ms to the chosen score to avoid flapping between routes
157+
if currScore != 0 && currScore+0.01 > chosenScore {
158+
log.Debugf("keeping current routing peer because the score difference with latency is less than 0.01(10ms), current: %f, new: %f", currScore, chosenScore)
157159
return currID
158-
} else {
159-
var peer string
160-
if route := c.routes[chosen]; route != nil {
161-
peer = route.Peer
162-
}
163-
log.Infof("new chosen route is %s with peer %s with score %f for network %s", chosen, peer, chosenScore, c.network)
164160
}
161+
var p string
162+
if rt := c.routes[chosen]; rt != nil {
163+
p = rt.Peer
164+
}
165+
log.Infof("new chosen route is %s with peer %s with score %f for network %s", chosen, p, chosenScore, c.network)
165166
}
166167

167168
return chosen

client/internal/routemanager/client_test.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ func TestGetBestrouteFromStatuses(t *testing.T) {
241241
connected: true,
242242
relayed: false,
243243
direct: true,
244-
latency: 12 * time.Millisecond,
244+
latency: 15 * time.Millisecond,
245245
},
246246
"route2": {
247247
connected: true,
@@ -265,6 +265,37 @@ func TestGetBestrouteFromStatuses(t *testing.T) {
265265
currentRoute: "route1",
266266
expectedRouteID: "route1",
267267
},
268+
{
269+
name: "current route with bad score should be changed to route with better score",
270+
statuses: map[string]routerPeerStatus{
271+
"route1": {
272+
connected: true,
273+
relayed: false,
274+
direct: true,
275+
latency: 200 * time.Millisecond,
276+
},
277+
"route2": {
278+
connected: true,
279+
relayed: false,
280+
direct: true,
281+
latency: 10 * time.Millisecond,
282+
},
283+
},
284+
existingRoutes: map[string]*route.Route{
285+
"route1": {
286+
ID: "route1",
287+
Metric: route.MaxMetric,
288+
Peer: "peer1",
289+
},
290+
"route2": {
291+
ID: "route2",
292+
Metric: route.MaxMetric,
293+
Peer: "peer2",
294+
},
295+
},
296+
currentRoute: "route1",
297+
expectedRouteID: "route2",
298+
},
268299
{
269300
name: "current chosen route doesn't exist anymore",
270301
statuses: map[string]routerPeerStatus{

client/internal/routemanager/systemops_bsd.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ import (
1212
"golang.org/x/net/route"
1313
)
1414

15-
// selected BSD Route flags.
16-
const (
17-
RTF_UP = 0x1
18-
RTF_GATEWAY = 0x2
19-
RTF_HOST = 0x4
20-
RTF_REJECT = 0x8
21-
RTF_DYNAMIC = 0x10
22-
RTF_MODIFIED = 0x20
23-
RTF_STATIC = 0x800
24-
RTF_BLACKHOLE = 0x1000
25-
RTF_LOCAL = 0x200000
26-
RTF_BROADCAST = 0x400000
27-
RTF_MULTICAST = 0x800000
28-
)
2915

3016
func getRoutesFromTable() ([]netip.Prefix, error) {
3117
tab, err := route.FetchRIB(syscall.AF_UNSPEC, route.RIBTypeRoute, 0)
@@ -47,8 +33,8 @@ func getRoutesFromTable() ([]netip.Prefix, error) {
4733
return nil, fmt.Errorf("unexpected RIB message type: %d", m.Type)
4834
}
4935

50-
if m.Flags&RTF_UP == 0 ||
51-
m.Flags&(RTF_REJECT|RTF_BLACKHOLE) != 0 {
36+
if m.Flags&syscall.RTF_UP == 0 ||
37+
m.Flags&(syscall.RTF_REJECT|syscall.RTF_BLACKHOLE|syscall.RTF_WASCLONED) != 0 {
5238
continue
5339
}
5440

management/server/geolocation/geolocation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func NewGeolocation(dataDir string) (*Geolocation, error) {
7979
sha256sum: sha256sum,
8080
db: db,
8181
locationDB: locationDB,
82-
reloadCheckInterval: 60 * time.Second, // TODO: make configurable
82+
reloadCheckInterval: 300 * time.Second, // TODO: make configurable
8383
stopCh: make(chan struct{}),
8484
}
8585

@@ -198,7 +198,7 @@ func (gl *Geolocation) reloader() {
198198
log.Errorf("mmdb reload failed: %s", err)
199199
}
200200
} else {
201-
log.Debugf("No changes in '%s', no need to reload. Next check is in %.0f seconds.",
201+
log.Tracef("No changes in '%s', no need to reload. Next check is in %.0f seconds.",
202202
gl.mmdbPath, gl.reloadCheckInterval.Seconds())
203203
}
204204
}

management/server/geolocation/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (s *SqliteStore) reload() error {
150150

151151
log.Infof("Successfully reloaded '%s'", s.filePath)
152152
} else {
153-
log.Debugf("No changes in '%s', no need to reload", s.filePath)
153+
log.Tracef("No changes in '%s', no need to reload", s.filePath)
154154
}
155155

156156
return nil

0 commit comments

Comments
 (0)