From 69b1790bb632cc8308754f2546a1f8288708be61 Mon Sep 17 00:00:00 2001 From: Tim Beatham Date: Thu, 4 Jan 2024 22:08:14 +0000 Subject: [PATCH] 81-processes - issue with client client traversal --- pkg/mesh/config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/mesh/config.go b/pkg/mesh/config.go index 99d6795..b1d3406 100644 --- a/pkg/mesh/config.go +++ b/pkg/mesh/config.go @@ -1,6 +1,7 @@ package mesh import ( + "fmt" "net" "slices" "strings" @@ -233,8 +234,8 @@ func (m *WgMeshConfigApplyer) getClientConfig(params *GetConfigParams) (*wgtypes routesForMesh := lib.Map(lib.MapValues(params.routes), func(rns []routeNode) []routeNode { return lib.Filter(rns, func(rn routeNode) bool { - ip, _, _ := net.ParseCIDR(rn.gateway) - return meshNet.Contains(ip) + _, ipNet, _ := net.ParseCIDR(rn.gateway) + return meshNet.Contains(ipNet.IP) || ipNet.Contains(meshNet.IP) }) }) @@ -253,6 +254,10 @@ func (m *WgMeshConfigApplyer) getClientConfig(params *GetConfigParams) (*wgtypes return nil, err } + if len(params.peers) == 0 { + return nil, fmt.Errorf("no peers in the mesh") + } + peer := m.getCorrespondingPeer(params.peers, self) pubKey, _ := peer.GetPublicKey()