1
0
forked from extern/smegmesh
smegmesh/pkg/mesh/route.go

49 lines
961 B
Go
Raw Normal View History

package mesh
import (
2023-10-27 18:49:18 +02:00
"github.com/tim-beatham/wgmesh/pkg/ip"
logging "github.com/tim-beatham/wgmesh/pkg/log"
"github.com/tim-beatham/wgmesh/pkg/route"
)
type RouteManager interface {
UpdateRoutes() error
}
type RouteManagerImpl struct {
meshManager *MeshManager
routeInstaller route.RouteInstaller
}
func (r *RouteManagerImpl) UpdateRoutes() error {
2023-10-27 18:49:18 +02:00
meshes := r.meshManager.Meshes
ulaBuilder := new(ip.ULABuilder)
2023-10-27 18:49:18 +02:00
for _, mesh1 := range meshes {
for _, mesh2 := range meshes {
if mesh1 == mesh2 {
continue
}
2023-10-27 18:49:18 +02:00
ipNet, err := ulaBuilder.GetIPNet(mesh2.GetMeshId())
2023-10-27 18:49:18 +02:00
if err != nil {
logging.Log.WriteErrorf(err.Error())
return err
}
2023-10-27 18:49:18 +02:00
err = mesh1.AddRoutes(r.meshManager.HostParameters.HostEndpoint, ipNet.String())
2023-10-27 18:49:18 +02:00
if err != nil {
return err
}
}
}
return nil
}
func NewRouteManager(m *MeshManager) RouteManager {
return &RouteManagerImpl{meshManager: m, routeInstaller: route.NewRouteInstaller()}
}