From f09adc21926cef760b98ac0ebbf6633b201aa038 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 22:04:37 +0000 Subject: [PATCH 1/3] Update getRoutes format --- src/yggdrasil/admin.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index dea4577a..253a9bfb 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -268,11 +268,11 @@ func (a *admin) init(c *Core, listenaddr string) { return admin_info{"source_subnets": subnets}, nil }) a.addHandler("getRoutes", []string{}, func(in admin_info) (admin_info, error) { - var routes []string + routes := make(admin_info) a.core.router.doAdmin(func() { getRoutes := func(ckrs []cryptokey_route) { for _, ckr := range ckrs { - routes = append(routes, fmt.Sprintf("%s via %s", ckr.subnet.String(), hex.EncodeToString(ckr.destination[:]))) + routes[ckr.subnet.String()] = hex.EncodeToString(ckr.destination[:]) } } getRoutes(a.core.router.cryptokey.ipv4routes) From 65e34bbbab68811b362e6176b79e2409afde2a4d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 22:19:08 +0000 Subject: [PATCH 2/3] Enforce maximum CKR routing cache size --- src/yggdrasil/ckr.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/yggdrasil/ckr.go b/src/yggdrasil/ckr.go index b73946c4..2324f612 100644 --- a/src/yggdrasil/ckr.go +++ b/src/yggdrasil/ckr.go @@ -241,6 +241,16 @@ func (c *cryptokey) getPublicKeyForAddress(addr address, addrlen int) (boxPubKey for _, route := range *routingtable { // Does this subnet match the given IP? if route.subnet.Contains(ip) { + // Check if the routing cache is above a certain size, if it is evict + // a random entry so we can make room for this one. We take advantage + // of the fact that the iteration order is random here + if len(*routingcache) > 1024 { + for k := range *routingcache { + delete(*routingcache, k) + break + } + } + // Cache the entry for future packets to get a faster lookup (*routingcache)[addr] = route From 90ace46587f7f037df6f1698047886737cfd1e21 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 10 Dec 2018 22:30:31 +0000 Subject: [PATCH 3/3] Enforce CKR cache size more strongly --- src/yggdrasil/ckr.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/yggdrasil/ckr.go b/src/yggdrasil/ckr.go index 2324f612..d88b8d3c 100644 --- a/src/yggdrasil/ckr.go +++ b/src/yggdrasil/ckr.go @@ -244,11 +244,11 @@ func (c *cryptokey) getPublicKeyForAddress(addr address, addrlen int) (boxPubKey // Check if the routing cache is above a certain size, if it is evict // a random entry so we can make room for this one. We take advantage // of the fact that the iteration order is random here - if len(*routingcache) > 1024 { - for k := range *routingcache { - delete(*routingcache, k) + for k := range *routingcache { + if len(*routingcache) < 1024 { break } + delete(*routingcache, k) } // Cache the entry for future packets to get a faster lookup