mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2024-12-13 01:50:53 +01:00
472718c9a3
for tests and modifying network device manipulation
49 lines
961 B
Go
49 lines
961 B
Go
package mesh
|
|
|
|
import (
|
|
"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 {
|
|
meshes := r.meshManager.Meshes
|
|
ulaBuilder := new(ip.ULABuilder)
|
|
|
|
for _, mesh1 := range meshes {
|
|
for _, mesh2 := range meshes {
|
|
if mesh1 == mesh2 {
|
|
continue
|
|
}
|
|
|
|
ipNet, err := ulaBuilder.GetIPNet(mesh2.GetMeshId())
|
|
|
|
if err != nil {
|
|
logging.Log.WriteErrorf(err.Error())
|
|
return err
|
|
}
|
|
|
|
err = mesh1.AddRoutes(r.meshManager.HostParameters.HostEndpoint, ipNet.String())
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func NewRouteManager(m *MeshManager) RouteManager {
|
|
return &RouteManagerImpl{meshManager: m, routeInstaller: route.NewRouteInstaller()}
|
|
}
|