mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-08-19 01:15:58 +02:00
32-fix-routing
Flooding routes into other meshes a bit like BGP.
This commit is contained in:
@@ -43,8 +43,7 @@ func (m *WgMeshConfigApplyer) convertMeshNode(node MeshNode, device *wgtypes.Dev
|
||||
allowedips[0] = *node.GetWgHost()
|
||||
|
||||
for _, route := range node.GetRoutes() {
|
||||
_, ipnet, _ := net.ParseCIDR(route)
|
||||
allowedips = append(allowedips, *ipnet)
|
||||
allowedips = append(allowedips, *route.GetDestination())
|
||||
}
|
||||
|
||||
clients, ok := peerToClients[node.GetWgHost().String()]
|
||||
@@ -96,39 +95,28 @@ func (m *WgMeshConfigApplyer) updateWgConf(mesh MeshProvider) error {
|
||||
return err
|
||||
}
|
||||
|
||||
rtnl, err := lib.NewRtNetlinkConfig()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
peerToClients := make(map[string][]net.IPNet)
|
||||
|
||||
routes := make([]lib.Route, 1)
|
||||
|
||||
for _, n := range nodes {
|
||||
if NodeEquals(n, self) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, route := range n.GetRoutes() {
|
||||
|
||||
routes = append(routes, lib.Route{
|
||||
Gateway: n.GetWgHost().IP,
|
||||
Destination: *route.GetDestination(),
|
||||
})
|
||||
}
|
||||
|
||||
if n.GetType() == conf.CLIENT_ROLE && len(peers) > 0 && self.GetType() == conf.CLIENT_ROLE {
|
||||
peer := lib.ConsistentHash(peers, n, func(mn MeshNode) int {
|
||||
return lib.HashString(mn.GetWgHost().String())
|
||||
})
|
||||
|
||||
dev, err := mesh.GetDevice()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rtnl.AddRoute(dev.Name, lib.Route{
|
||||
Gateway: peer.GetWgHost().IP,
|
||||
Destination: *n.GetWgHost(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clients, ok := peerToClients[peer.GetWgHost().String()]
|
||||
|
||||
if !ok {
|
||||
@@ -153,7 +141,8 @@ func (m *WgMeshConfigApplyer) updateWgConf(mesh MeshProvider) error {
|
||||
}
|
||||
|
||||
cfg := wgtypes.Config{
|
||||
Peers: peerConfigs,
|
||||
Peers: peerConfigs,
|
||||
ReplacePeers: true,
|
||||
}
|
||||
|
||||
dev, err := mesh.GetDevice()
|
||||
@@ -162,6 +151,12 @@ func (m *WgMeshConfigApplyer) updateWgConf(mesh MeshProvider) error {
|
||||
return err
|
||||
}
|
||||
|
||||
err = m.routeInstaller.InstallRoutes(dev.Name, routes...)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return m.meshManager.GetClient().ConfigureDevice(dev.Name, cfg)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user