Implement networks routed through wesher

This adds an option for specifying a routed network. Every node route
that belongs to that routed network will be announced to the cluster and
every other node will direct traffic to that node for said route.
This commit is contained in:
kaiyou
2020-05-18 10:42:32 +02:00
parent e9aae4dc3b
commit 8637377cec
6 changed files with 104 additions and 8 deletions

View File

@ -11,6 +11,7 @@ import (
// nodeMeta holds metadata sent over the cluster
type nodeMeta struct {
OverlayAddr net.IPNet
Routes []net.IPNet
PubKey string
}

32
common/routes.go Normal file
View File

@ -0,0 +1,32 @@
package common
import (
"net"
"github.com/vishvananda/netlink"
)
// Routes pushes list of local routes to a channel, after filtering using the provided network
// The full list is pushed after every routing change
func Routes(filter *net.IPNet) <-chan []net.IPNet {
routesc := make(chan []net.IPNet)
updatec := make(chan netlink.RouteUpdate)
netlink.RouteSubscribe(updatec, make(chan struct{}))
go func() {
for {
<-updatec
routes, err := netlink.RouteList(nil, netlink.FAMILY_ALL)
if err != nil {
continue
}
result := make([]net.IPNet, 0)
for _, route := range routes {
if route.Dst != nil && filter.Contains(route.Dst.IP) {
result = append(result, *route.Dst)
}
}
routesc <- result
}
}()
return routesc
}