47-default-routing

Implementing default routing so that all traffic goes out of an
exit point.
This commit is contained in:
Tim Beatham
2023-12-08 11:49:24 +00:00
parent 92c0805275
commit 0058c9f4c9
5 changed files with 35 additions and 12 deletions

View File

@@ -1,6 +1,9 @@
package mesh
import (
"net"
"github.com/tim-beatham/wgmesh/pkg/conf"
"github.com/tim-beatham/wgmesh/pkg/ip"
"github.com/tim-beatham/wgmesh/pkg/lib"
logging "github.com/tim-beatham/wgmesh/pkg/log"
@@ -13,6 +16,7 @@ type RouteManager interface {
type RouteManagerImpl struct {
meshManager MeshManager
conf *conf.WgMeshConfiguration
}
func (r *RouteManagerImpl) UpdateRoutes() error {
@@ -32,12 +36,22 @@ func (r *RouteManagerImpl) UpdateRoutes() error {
return err
}
routes, err := mesh1.GetRoutes(pubKey.String())
routeMap, err := mesh1.GetRoutes(pubKey.String())
if err != nil {
return err
}
if r.conf.AdvertiseDefaultRoute {
_, defaultRoute, _ := net.ParseCIDR("::/0")
mesh1.AddRoutes(NodeID(self), &RouteStub{
Destination: defaultRoute,
HopCount: 0,
Path: make([]string, 0),
})
}
for _, mesh2 := range meshes {
if mesh1 == mesh2 {
continue
@@ -50,7 +64,9 @@ func (r *RouteManagerImpl) UpdateRoutes() error {
return err
}
err = mesh2.AddRoutes(NodeID(self), append(lib.MapValues(routes), &RouteStub{
routes := lib.MapValues(routeMap)
err = mesh2.AddRoutes(NodeID(self), append(routes, &RouteStub{
Destination: ipNet,
HopCount: 0,
Path: make([]string, 0),
@@ -88,6 +104,6 @@ func (r *RouteManagerImpl) RemoveRoutes(meshId string) error {
return nil
}
func NewRouteManager(m MeshManager) RouteManager {
return &RouteManagerImpl{meshManager: m}
func NewRouteManager(m MeshManager, conf *conf.WgMeshConfiguration) RouteManager {
return &RouteManagerImpl{meshManager: m, conf: conf}
}