pkg/mesh: move peer route generation to mesh
Signed-off-by: Lucas Servén Marín <lserven@gmail.com>
This commit is contained in:
parent
5ba45af4fe
commit
3c69e99439
@ -32,8 +32,6 @@ import (
|
|||||||
"github.com/go-kit/kit/log/level"
|
"github.com/go-kit/kit/log/level"
|
||||||
"github.com/oklog/run"
|
"github.com/oklog/run"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
"golang.org/x/sys/unix"
|
|
||||||
"golang.zx2c4.com/wireguard/wgctrl"
|
"golang.zx2c4.com/wireguard/wgctrl"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
@ -368,70 +366,7 @@ func sync(table *route.Table, peerName string, privateKey wgtypes.Key, iface int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var routes []*netlink.Route
|
if err := table.Set(t.PeerRoutes(peerName, iface, connectOpts.allowedIPs)); err != nil {
|
||||||
for _, segment := range t.Segments {
|
|
||||||
for i := range segment.CIDRS() {
|
|
||||||
// Add routes to the Pod CIDRs of nodes in other segments.
|
|
||||||
routes = append(routes, &netlink.Route{
|
|
||||||
Dst: segment.CIDRS()[i],
|
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
|
||||||
Gw: segment.WireGuardIP(),
|
|
||||||
LinkIndex: iface,
|
|
||||||
Protocol: unix.RTPROT_STATIC,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
for i := range segment.PrivateIPs() {
|
|
||||||
// Add routes to the private IPs of nodes in other segments.
|
|
||||||
routes = append(routes, &netlink.Route{
|
|
||||||
Dst: mesh.OneAddressCIDR(segment.PrivateIPs()[i]),
|
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
|
||||||
Gw: segment.WireGuardIP(),
|
|
||||||
LinkIndex: iface,
|
|
||||||
Protocol: unix.RTPROT_STATIC,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// Add routes for the allowed location IPs of all segments.
|
|
||||||
for i := range segment.AllowedLocationIPs() {
|
|
||||||
routes = append(routes, &netlink.Route{
|
|
||||||
Dst: &segment.AllowedLocationIPs()[i],
|
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
|
||||||
Gw: segment.WireGuardIP(),
|
|
||||||
LinkIndex: iface,
|
|
||||||
Protocol: unix.RTPROT_STATIC,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
routes = append(routes, &netlink.Route{
|
|
||||||
Dst: mesh.OneAddressCIDR(segment.WireGuardIP()),
|
|
||||||
LinkIndex: iface,
|
|
||||||
Protocol: unix.RTPROT_STATIC,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// Add routes for the allowed IPs of peers.
|
|
||||||
for _, peer := range t.Peers() {
|
|
||||||
// Don't add routes to ourselves.
|
|
||||||
if peer.Name == peerName {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for i := range peer.AllowedIPs {
|
|
||||||
routes = append(routes, &netlink.Route{
|
|
||||||
Dst: &peer.AllowedIPs[i],
|
|
||||||
LinkIndex: iface,
|
|
||||||
Protocol: unix.RTPROT_STATIC,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for i := range connectOpts.allowedIPs {
|
|
||||||
routes = append(routes, &netlink.Route{
|
|
||||||
Dst: &connectOpts.allowedIPs[i],
|
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
|
||||||
Gw: t.Segments[0].WireGuardIP(),
|
|
||||||
LinkIndex: iface,
|
|
||||||
Protocol: unix.RTPROT_STATIC,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
level.Debug(logger).Log("routes", routes)
|
|
||||||
if err := table.Set(routes, []*netlink.Rule{}); err != nil {
|
|
||||||
return fmt.Errorf("failed to update route table: %w", err)
|
return fmt.Errorf("failed to update route table: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func getIP(hostname string, ignoreIfaces ...int) (*net.IPNet, *net.IPNet, error)
|
|||||||
}
|
}
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
ignore[ip.String()] = struct{}{}
|
ignore[ip.String()] = struct{}{}
|
||||||
ignore[OneAddressCIDR(ip.IP).String()] = struct{}{}
|
ignore[oneAddressCIDR(ip.IP).String()] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ func assignedToInterface(ip *net.IPNet) (bool, net.IPMask, error) {
|
|||||||
// given hostname resolves.
|
// given hostname resolves.
|
||||||
func ipsForHostname(hostname string) []*net.IPNet {
|
func ipsForHostname(hostname string) []*net.IPNet {
|
||||||
if ip := net.ParseIP(hostname); ip != nil {
|
if ip := net.ParseIP(hostname); ip != nil {
|
||||||
return []*net.IPNet{OneAddressCIDR(ip)}
|
return []*net.IPNet{oneAddressCIDR(ip)}
|
||||||
}
|
}
|
||||||
ips, err := net.LookupIP(hostname)
|
ips, err := net.LookupIP(hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -205,7 +205,7 @@ func ipsForHostname(hostname string) []*net.IPNet {
|
|||||||
}
|
}
|
||||||
nets := make([]*net.IPNet, len(ips))
|
nets := make([]*net.IPNet, len(ips))
|
||||||
for i := range ips {
|
for i := range ips {
|
||||||
nets[i] = OneAddressCIDR(ips[i])
|
nets[i] = oneAddressCIDR(ips[i])
|
||||||
}
|
}
|
||||||
return nets
|
return nets
|
||||||
}
|
}
|
||||||
|
@ -43,12 +43,12 @@ func (t *Topology) Dot() (string, error) {
|
|||||||
if err := g.SetDir(true); err != nil {
|
if err := g.SetDir(true); err != nil {
|
||||||
return "", fmt.Errorf("failed to set direction")
|
return "", fmt.Errorf("failed to set direction")
|
||||||
}
|
}
|
||||||
leaders := make([]string, len(t.Segments))
|
leaders := make([]string, len(t.segments))
|
||||||
nodeAttrs := map[string]string{
|
nodeAttrs := map[string]string{
|
||||||
string(gographviz.Shape): "ellipse",
|
string(gographviz.Shape): "ellipse",
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, s := range t.Segments {
|
for i, s := range t.segments {
|
||||||
if err := g.AddSubGraph("kilo", subGraphName(s.location), nil); err != nil {
|
if err := g.AddSubGraph("kilo", subGraphName(s.location), nil); err != nil {
|
||||||
return "", fmt.Errorf("failed to add subgraph")
|
return "", fmt.Errorf("failed to add subgraph")
|
||||||
}
|
}
|
||||||
|
@ -74,11 +74,11 @@ func TestNewAllocator(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSortIPs(t *testing.T) {
|
func TestSortIPs(t *testing.T) {
|
||||||
ip1 := OneAddressCIDR(net.ParseIP("10.0.0.1"))
|
ip1 := oneAddressCIDR(net.ParseIP("10.0.0.1"))
|
||||||
ip2 := OneAddressCIDR(net.ParseIP("10.0.0.2"))
|
ip2 := oneAddressCIDR(net.ParseIP("10.0.0.2"))
|
||||||
ip3 := OneAddressCIDR(net.ParseIP("192.168.0.1"))
|
ip3 := oneAddressCIDR(net.ParseIP("192.168.0.1"))
|
||||||
ip4 := OneAddressCIDR(net.ParseIP("2001::7"))
|
ip4 := oneAddressCIDR(net.ParseIP("2001::7"))
|
||||||
ip5 := OneAddressCIDR(net.ParseIP("fd68:da49:09da:b27f::"))
|
ip5 := oneAddressCIDR(net.ParseIP("fd68:da49:09da:b27f::"))
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
ips []*net.IPNet
|
ips []*net.IPNet
|
||||||
|
@ -504,13 +504,13 @@ func (m *Mesh) applyTopology() {
|
|||||||
// tunnel has an IP address and IPIP traffic is allowed.
|
// tunnel has an IP address and IPIP traffic is allowed.
|
||||||
if m.enc.Strategy() != encapsulation.Never && m.local {
|
if m.enc.Strategy() != encapsulation.Never && m.local {
|
||||||
var cidrs []*net.IPNet
|
var cidrs []*net.IPNet
|
||||||
for _, s := range t.Segments {
|
for _, s := range t.segments {
|
||||||
// If the location prefix is not logicalLocation, but nodeLocation,
|
// If the location prefix is not logicalLocation, but nodeLocation,
|
||||||
// we don't need to set any extra rules for encapsulation anyways
|
// we don't need to set any extra rules for encapsulation anyways
|
||||||
// because traffic will go over WireGuard.
|
// because traffic will go over WireGuard.
|
||||||
if s.location == logicalLocationPrefix+nodes[m.hostname].Location {
|
if s.location == logicalLocationPrefix+nodes[m.hostname].Location {
|
||||||
for i := range s.privateIPs {
|
for i := range s.privateIPs {
|
||||||
cidrs = append(cidrs, OneAddressCIDR(s.privateIPs[i]))
|
cidrs = append(cidrs, oneAddressCIDR(s.privateIPs[i]))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -518,7 +518,7 @@ func (m *Mesh) applyTopology() {
|
|||||||
ipRules = append(ipRules, m.enc.Rules(cidrs)...)
|
ipRules = append(ipRules, m.enc.Rules(cidrs)...)
|
||||||
// If we are handling local routes, ensure the local
|
// If we are handling local routes, ensure the local
|
||||||
// tunnel has an IP address.
|
// tunnel has an IP address.
|
||||||
if err := m.enc.Set(OneAddressCIDR(newAllocator(*nodes[m.hostname].Subnet).next().IP)); err != nil {
|
if err := m.enc.Set(oneAddressCIDR(newAllocator(*nodes[m.hostname].Subnet).next().IP)); err != nil {
|
||||||
level.Error(m.logger).Log("error", err)
|
level.Error(m.logger).Log("error", err)
|
||||||
m.errorCounter.WithLabelValues("apply").Inc()
|
m.errorCounter.WithLabelValues("apply").Inc()
|
||||||
return
|
return
|
||||||
|
@ -35,8 +35,8 @@ func mustKey() wgtypes.Key {
|
|||||||
var key = mustKey()
|
var key = mustKey()
|
||||||
|
|
||||||
func TestReady(t *testing.T) {
|
func TestReady(t *testing.T) {
|
||||||
internalIP := OneAddressCIDR(net.ParseIP("1.1.1.1"))
|
internalIP := oneAddressCIDR(net.ParseIP("1.1.1.1"))
|
||||||
externalIP := OneAddressCIDR(net.ParseIP("2.2.2.2"))
|
externalIP := oneAddressCIDR(net.ParseIP("2.2.2.2"))
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
name string
|
name string
|
||||||
node *Node
|
node *Node
|
||||||
|
@ -38,16 +38,16 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
// This will be the an IP of the leader.
|
// This will be the an IP of the leader.
|
||||||
// In an IPIP encapsulated mesh it is the leader's private IP.
|
// In an IPIP encapsulated mesh it is the leader's private IP.
|
||||||
var gw net.IP
|
var gw net.IP
|
||||||
for _, segment := range t.Segments {
|
for _, segment := range t.segments {
|
||||||
if segment.location == t.location {
|
if segment.location == t.location {
|
||||||
gw = enc.Gw(t.updateEndpoint(segment.endpoint, segment.key, &segment.persistentKeepalive).IP(), segment.privateIPs[segment.leader], segment.cidrs[segment.leader])
|
gw = enc.Gw(t.updateEndpoint(segment.endpoint, segment.key, &segment.persistentKeepalive).IP(), segment.privateIPs[segment.leader], segment.cidrs[segment.leader])
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, segment := range t.Segments {
|
for _, segment := range t.segments {
|
||||||
// First, add a route to the WireGuard IP of the segment.
|
// First, add a route to the WireGuard IP of the segment.
|
||||||
routes = append(routes, encapsulateRoute(&netlink.Route{
|
routes = append(routes, encapsulateRoute(&netlink.Route{
|
||||||
Dst: OneAddressCIDR(segment.wireGuardIP),
|
Dst: oneAddressCIDR(segment.wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: gw,
|
Gw: gw,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
@ -72,7 +72,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
// to private IPs.
|
// to private IPs.
|
||||||
if enc.Strategy() == encapsulation.Always || (enc.Strategy() == encapsulation.CrossSubnet && !t.privateIP.Contains(segment.privateIPs[i])) {
|
if enc.Strategy() == encapsulation.Always || (enc.Strategy() == encapsulation.CrossSubnet && !t.privateIP.Contains(segment.privateIPs[i])) {
|
||||||
routes = append(routes, &netlink.Route{
|
routes = append(routes, &netlink.Route{
|
||||||
Dst: OneAddressCIDR(segment.privateIPs[i]),
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: segment.privateIPs[i],
|
Gw: segment.privateIPs[i],
|
||||||
LinkIndex: tunlIface,
|
LinkIndex: tunlIface,
|
||||||
@ -81,7 +81,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
})
|
})
|
||||||
rules = append(rules, defaultRule(&netlink.Rule{
|
rules = append(rules, defaultRule(&netlink.Rule{
|
||||||
Src: t.subnet,
|
Src: t.subnet,
|
||||||
Dst: OneAddressCIDR(segment.privateIPs[i]),
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
Table: kiloTableIndex,
|
Table: kiloTableIndex,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
for i := range segment.privateIPs {
|
for i := range segment.privateIPs {
|
||||||
// Add routes to the private IPs of nodes in other segments.
|
// Add routes to the private IPs of nodes in other segments.
|
||||||
routes = append(routes, encapsulateRoute(&netlink.Route{
|
routes = append(routes, encapsulateRoute(&netlink.Route{
|
||||||
Dst: OneAddressCIDR(segment.privateIPs[i]),
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: gw,
|
Gw: gw,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
@ -135,7 +135,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
}
|
}
|
||||||
return routes, rules
|
return routes, rules
|
||||||
}
|
}
|
||||||
for _, segment := range t.Segments {
|
for _, segment := range t.segments {
|
||||||
// Add routes for the current segment if local is true.
|
// Add routes for the current segment if local is true.
|
||||||
if segment.location == t.location {
|
if segment.location == t.location {
|
||||||
// If the local node does not have a private IP address,
|
// If the local node does not have a private IP address,
|
||||||
@ -157,7 +157,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
// to private IPs.
|
// to private IPs.
|
||||||
if enc.Strategy() == encapsulation.Always || (enc.Strategy() == encapsulation.CrossSubnet && !t.privateIP.Contains(segment.privateIPs[i])) {
|
if enc.Strategy() == encapsulation.Always || (enc.Strategy() == encapsulation.CrossSubnet && !t.privateIP.Contains(segment.privateIPs[i])) {
|
||||||
routes = append(routes, &netlink.Route{
|
routes = append(routes, &netlink.Route{
|
||||||
Dst: OneAddressCIDR(segment.privateIPs[i]),
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: segment.privateIPs[i],
|
Gw: segment.privateIPs[i],
|
||||||
LinkIndex: tunlIface,
|
LinkIndex: tunlIface,
|
||||||
@ -166,13 +166,13 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
})
|
})
|
||||||
rules = append(rules, defaultRule(&netlink.Rule{
|
rules = append(rules, defaultRule(&netlink.Rule{
|
||||||
Src: t.subnet,
|
Src: t.subnet,
|
||||||
Dst: OneAddressCIDR(segment.privateIPs[i]),
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
Table: kiloTableIndex,
|
Table: kiloTableIndex,
|
||||||
}))
|
}))
|
||||||
// Also encapsulate packets from the Kilo interface
|
// Also encapsulate packets from the Kilo interface
|
||||||
// headed to private IPs.
|
// headed to private IPs.
|
||||||
rules = append(rules, defaultRule(&netlink.Rule{
|
rules = append(rules, defaultRule(&netlink.Rule{
|
||||||
Dst: OneAddressCIDR(segment.privateIPs[i]),
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
Table: kiloTableIndex,
|
Table: kiloTableIndex,
|
||||||
IifName: kiloIfaceName,
|
IifName: kiloIfaceName,
|
||||||
}))
|
}))
|
||||||
@ -203,7 +203,7 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
// Number of CIDRs and private IPs always match so
|
// Number of CIDRs and private IPs always match so
|
||||||
// we can reuse the loop.
|
// we can reuse the loop.
|
||||||
routes = append(routes, &netlink.Route{
|
routes = append(routes, &netlink.Route{
|
||||||
Dst: OneAddressCIDR(segment.privateIPs[i]),
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: segment.wireGuardIP,
|
Gw: segment.wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
@ -235,6 +235,74 @@ func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface
|
|||||||
return routes, rules
|
return routes, rules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PeerRoutes generates a slice of routes and rules for a given peer in the Topology.
|
||||||
|
func (t *Topology) PeerRoutes(name string, kiloIface int, additionalAllowedIPs []net.IPNet) ([]*netlink.Route, []*netlink.Rule) {
|
||||||
|
var routes []*netlink.Route
|
||||||
|
var rules []*netlink.Rule
|
||||||
|
for _, segment := range t.segments {
|
||||||
|
for i := range segment.cidrs {
|
||||||
|
// Add routes to the Pod CIDRs of nodes in other segments.
|
||||||
|
routes = append(routes, &netlink.Route{
|
||||||
|
Dst: segment.cidrs[i],
|
||||||
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
|
Gw: segment.wireGuardIP,
|
||||||
|
LinkIndex: kiloIface,
|
||||||
|
Protocol: unix.RTPROT_STATIC,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for i := range segment.privateIPs {
|
||||||
|
// Add routes to the private IPs of nodes in other segments.
|
||||||
|
routes = append(routes, &netlink.Route{
|
||||||
|
Dst: oneAddressCIDR(segment.privateIPs[i]),
|
||||||
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
|
Gw: segment.wireGuardIP,
|
||||||
|
LinkIndex: kiloIface,
|
||||||
|
Protocol: unix.RTPROT_STATIC,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// Add routes for the allowed location IPs of all segments.
|
||||||
|
for i := range segment.allowedLocationIPs {
|
||||||
|
routes = append(routes, &netlink.Route{
|
||||||
|
Dst: &segment.allowedLocationIPs[i],
|
||||||
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
|
Gw: segment.wireGuardIP,
|
||||||
|
LinkIndex: kiloIface,
|
||||||
|
Protocol: unix.RTPROT_STATIC,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
routes = append(routes, &netlink.Route{
|
||||||
|
Dst: oneAddressCIDR(segment.wireGuardIP),
|
||||||
|
LinkIndex: kiloIface,
|
||||||
|
Protocol: unix.RTPROT_STATIC,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// Add routes for the allowed IPs of peers.
|
||||||
|
for _, peer := range t.peers {
|
||||||
|
// Don't add routes to ourselves.
|
||||||
|
if peer.Name == name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for i := range peer.AllowedIPs {
|
||||||
|
routes = append(routes, &netlink.Route{
|
||||||
|
Dst: &peer.AllowedIPs[i],
|
||||||
|
LinkIndex: kiloIface,
|
||||||
|
Protocol: unix.RTPROT_STATIC,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range additionalAllowedIPs {
|
||||||
|
routes = append(routes, &netlink.Route{
|
||||||
|
Dst: &additionalAllowedIPs[i],
|
||||||
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
|
Gw: t.segments[0].wireGuardIP,
|
||||||
|
LinkIndex: kiloIface,
|
||||||
|
Protocol: unix.RTPROT_STATIC,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return routes, rules
|
||||||
|
}
|
||||||
|
|
||||||
func encapsulateRoute(route *netlink.Route, encapsulate encapsulation.Strategy, subnet *net.IPNet, tunlIface int) *netlink.Route {
|
func encapsulateRoute(route *netlink.Route, encapsulate encapsulation.Strategy, subnet *net.IPNet, tunlIface int) *netlink.Route {
|
||||||
if encapsulate == encapsulation.Always || (encapsulate == encapsulation.CrossSubnet && !subnet.Contains(route.Gw)) {
|
if encapsulate == encapsulation.Always || (encapsulate == encapsulation.CrossSubnet && !subnet.Contains(route.Gw)) {
|
||||||
route.LinkIndex = tunlIface
|
route.LinkIndex = tunlIface
|
||||||
@ -254,7 +322,7 @@ func (t *Topology) Rules(cni, iptablesForwardRule bool) []iptables.Rule {
|
|||||||
// Leader nodes will forward packets from all nodes within a location because they act as a gateway for them.
|
// Leader nodes will forward packets from all nodes within a location because they act as a gateway for them.
|
||||||
// Non leader nodes only need to allow packages from and to their own pod CIDR.
|
// Non leader nodes only need to allow packages from and to their own pod CIDR.
|
||||||
if iptablesForwardRule && t.leader {
|
if iptablesForwardRule && t.leader {
|
||||||
for _, s := range t.Segments {
|
for _, s := range t.segments {
|
||||||
if s.location == t.location {
|
if s.location == t.location {
|
||||||
// Make sure packets to and from pod cidrs are not dropped in the forward chain.
|
// Make sure packets to and from pod cidrs are not dropped in the forward chain.
|
||||||
for _, c := range s.cidrs {
|
for _, c := range s.cidrs {
|
||||||
@ -268,8 +336,8 @@ func (t *Topology) Rules(cni, iptablesForwardRule bool) []iptables.Rule {
|
|||||||
}
|
}
|
||||||
// Make sure packets to and from private IPs are not dropped in the forward chain.
|
// Make sure packets to and from private IPs are not dropped in the forward chain.
|
||||||
for _, c := range s.privateIPs {
|
for _, c := range s.privateIPs {
|
||||||
rules = append(rules, iptables.NewRule(iptables.GetProtocol(c), "filter", "FORWARD", "-m", "comment", "--comment", "Kilo: forward packets from private IPs", "-s", OneAddressCIDR(c).String(), "-j", "ACCEPT"))
|
rules = append(rules, iptables.NewRule(iptables.GetProtocol(c), "filter", "FORWARD", "-m", "comment", "--comment", "Kilo: forward packets from private IPs", "-s", oneAddressCIDR(c).String(), "-j", "ACCEPT"))
|
||||||
rules = append(rules, iptables.NewRule(iptables.GetProtocol(c), "filter", "FORWARD", "-m", "comment", "--comment", "Kilo: forward packets to private IPs", "-d", OneAddressCIDR(c).String(), "-j", "ACCEPT"))
|
rules = append(rules, iptables.NewRule(iptables.GetProtocol(c), "filter", "FORWARD", "-m", "comment", "--comment", "Kilo: forward packets to private IPs", "-d", oneAddressCIDR(c).String(), "-j", "ACCEPT"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -278,8 +346,8 @@ func (t *Topology) Rules(cni, iptablesForwardRule bool) []iptables.Rule {
|
|||||||
rules = append(rules, iptables.NewRule(iptables.GetProtocol(t.subnet.IP), "filter", "FORWARD", "-m", "comment", "--comment", "Kilo: forward packets to the node's pod subnet", "-d", t.subnet.String(), "-j", "ACCEPT"))
|
rules = append(rules, iptables.NewRule(iptables.GetProtocol(t.subnet.IP), "filter", "FORWARD", "-m", "comment", "--comment", "Kilo: forward packets to the node's pod subnet", "-d", t.subnet.String(), "-j", "ACCEPT"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, s := range t.Segments {
|
for _, s := range t.segments {
|
||||||
rules = append(rules, iptables.NewRule(iptables.GetProtocol(s.wireGuardIP), "nat", "KILO-NAT", "-d", OneAddressCIDR(s.wireGuardIP).String(), "-m", "comment", "--comment", "Kilo: do not NAT packets destined for WireGuared IPs", "-j", "RETURN"))
|
rules = append(rules, iptables.NewRule(iptables.GetProtocol(s.wireGuardIP), "nat", "KILO-NAT", "-d", oneAddressCIDR(s.wireGuardIP).String(), "-m", "comment", "--comment", "Kilo: do not NAT packets destined for WireGuared IPs", "-j", "RETURN"))
|
||||||
for _, aip := range s.allowedIPs {
|
for _, aip := range s.allowedIPs {
|
||||||
rules = append(rules, iptables.NewRule(iptables.GetProtocol(aip.IP), "nat", "KILO-NAT", "-d", aip.String(), "-m", "comment", "--comment", "Kilo: do not NAT packets destined for known IPs", "-j", "RETURN"))
|
rules = append(rules, iptables.NewRule(iptables.GetProtocol(aip.IP), "nat", "KILO-NAT", "-d", aip.String(), "-m", "comment", "--comment", "Kilo: do not NAT packets destined for known IPs", "-j", "RETURN"))
|
||||||
}
|
}
|
||||||
|
@ -47,44 +47,44 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].cidrs[1],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].cidrs[1],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[2].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -111,23 +111,23 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[0].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[2].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -154,42 +154,42 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[0].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[0].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[1].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[1].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[2].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[2].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
@ -224,51 +224,51 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[0].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[0].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[1].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[1].cidrs[1],
|
Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].cidrs[1],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -295,44 +295,44 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[1].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[2].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[3].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[3].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[3].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[3].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -359,37 +359,37 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[0].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[2].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[3].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[3].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[3].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[3].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -416,44 +416,44 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[0].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[1].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[3].cidrs[0],
|
Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[3].cidrs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[3].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[3].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -483,42 +483,42 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["b"].Subnet,
|
Dst: nodes["b"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["c"].Subnet,
|
Dst: nodes["c"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["d"].Subnet,
|
Dst: nodes["d"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -548,42 +548,42 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["b"].Subnet,
|
Dst: nodes["b"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["c"].Subnet,
|
Dst: nodes["c"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["d"].Subnet,
|
Dst: nodes["d"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -613,14 +613,14 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["a"].Subnet,
|
Dst: nodes["a"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -634,7 +634,7 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["d"].Subnet,
|
Dst: nodes["d"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -664,14 +664,14 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["a"].Subnet,
|
Dst: nodes["a"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -683,7 +683,7 @@ func TestRoutes(t *testing.T) {
|
|||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["c"].InternalIP.IP,
|
Gw: nodes["c"].InternalIP.IP,
|
||||||
LinkIndex: tunlIface,
|
LinkIndex: tunlIface,
|
||||||
@ -693,7 +693,7 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["d"].Subnet,
|
Dst: nodes["d"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -733,7 +733,7 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Never,
|
strategy: encapsulation.Never,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[0].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
@ -747,14 +747,14 @@ func TestRoutes(t *testing.T) {
|
|||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[1].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[1].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
@ -768,7 +768,7 @@ func TestRoutes(t *testing.T) {
|
|||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[2].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: privIface,
|
LinkIndex: privIface,
|
||||||
@ -811,7 +811,7 @@ func TestRoutes(t *testing.T) {
|
|||||||
strategy: encapsulation.Always,
|
strategy: encapsulation.Always,
|
||||||
routes: []*netlink.Route{
|
routes: []*netlink.Route{
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[0].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: tunlIface,
|
LinkIndex: tunlIface,
|
||||||
@ -825,14 +825,14 @@ func TestRoutes(t *testing.T) {
|
|||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: tunlIface,
|
LinkIndex: tunlIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[1].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[1].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: tunlIface,
|
LinkIndex: tunlIface,
|
||||||
@ -854,7 +854,7 @@ func TestRoutes(t *testing.T) {
|
|||||||
Table: kiloTableIndex,
|
Table: kiloTableIndex,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).Segments[2].wireGuardIP),
|
Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].wireGuardIP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: nodes["b"].InternalIP.IP,
|
Gw: nodes["b"].InternalIP.IP,
|
||||||
LinkIndex: tunlIface,
|
LinkIndex: tunlIface,
|
||||||
@ -906,42 +906,42 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["b"].Subnet,
|
Dst: nodes["b"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["c"].Subnet,
|
Dst: nodes["c"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["d"].Subnet,
|
Dst: nodes["d"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).Segments[3].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[3].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -971,35 +971,35 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["a"].Subnet,
|
Dst: nodes["a"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["c"].Subnet,
|
Dst: nodes["c"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["c"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[2].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["d"].Subnet,
|
Dst: nodes["d"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).Segments[3].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[3].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
@ -1029,42 +1029,42 @@ func TestRoutes(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Dst: nodes["a"].Subnet,
|
Dst: nodes["a"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["a"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[0].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["b"].Subnet,
|
Dst: nodes["b"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: OneAddressCIDR(nodes["b"].InternalIP.IP),
|
Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: &nodes["b"].AllowedLocationIPs[0],
|
Dst: &nodes["b"].AllowedLocationIPs[0],
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[1].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Dst: nodes["d"].Subnet,
|
Dst: nodes["d"].Subnet,
|
||||||
Flags: int(netlink.FLAG_ONLINK),
|
Flags: int(netlink.FLAG_ONLINK),
|
||||||
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).Segments[3].wireGuardIP,
|
Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[3].wireGuardIP,
|
||||||
LinkIndex: kiloIface,
|
LinkIndex: kiloIface,
|
||||||
Protocol: unix.RTPROT_STATIC,
|
Protocol: unix.RTPROT_STATIC,
|
||||||
},
|
},
|
||||||
|
@ -39,7 +39,7 @@ type Topology struct {
|
|||||||
port int
|
port int
|
||||||
// Location is the logical location of the local host.
|
// Location is the logical location of the local host.
|
||||||
location string
|
location string
|
||||||
Segments []*Segment
|
segments []*segment
|
||||||
peers []*Peer
|
peers []*Peer
|
||||||
|
|
||||||
// hostname is the hostname of the local host.
|
// hostname is the hostname of the local host.
|
||||||
@ -65,8 +65,8 @@ type Topology struct {
|
|||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// Segment represents one logical unit in the topology that is united by one common WireGuard IP.
|
// segment represents one logical unit in the topology that is united by one common WireGuard IP.
|
||||||
type Segment struct {
|
type segment struct {
|
||||||
allowedIPs []net.IPNet
|
allowedIPs []net.IPNet
|
||||||
endpoint *wireguard.Endpoint
|
endpoint *wireguard.Endpoint
|
||||||
key wgtypes.Key
|
key wgtypes.Key
|
||||||
@ -91,21 +91,6 @@ type Segment struct {
|
|||||||
allowedLocationIPs []net.IPNet
|
allowedLocationIPs []net.IPNet
|
||||||
}
|
}
|
||||||
|
|
||||||
// CIDRS returns the cidrs of the segment.
|
|
||||||
func (s Segment) CIDRS() []*net.IPNet {
|
|
||||||
return s.cidrs
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrivateIPs returns the private IPs of the segment.
|
|
||||||
func (s Segment) PrivateIPs() []net.IP {
|
|
||||||
return s.privateIPs
|
|
||||||
}
|
|
||||||
|
|
||||||
// WireGuardIP retuns the WireGuard IP of the segment.
|
|
||||||
func (s Segment) WireGuardIP() net.IP {
|
|
||||||
return s.wireGuardIP
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewTopology creates a new Topology struct from a given set of nodes and peers.
|
// NewTopology creates a new Topology struct from a given set of nodes and peers.
|
||||||
func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Granularity, hostname string, port int, key wgtypes.Key, subnet *net.IPNet, persistentKeepalive time.Duration, logger log.Logger) (*Topology, error) {
|
func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Granularity, hostname string, port int, key wgtypes.Key, subnet *net.IPNet, persistentKeepalive time.Duration, logger log.Logger) (*Topology, error) {
|
||||||
if logger == nil {
|
if logger == nil {
|
||||||
@ -181,7 +166,7 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if node.InternalIP != nil {
|
if node.InternalIP != nil {
|
||||||
allowedIPs = append(allowedIPs, *OneAddressCIDR(node.InternalIP.IP))
|
allowedIPs = append(allowedIPs, *oneAddressCIDR(node.InternalIP.IP))
|
||||||
privateIPs = append(privateIPs, node.InternalIP.IP)
|
privateIPs = append(privateIPs, node.InternalIP.IP)
|
||||||
}
|
}
|
||||||
cidrs = append(cidrs, node.Subnet)
|
cidrs = append(cidrs, node.Subnet)
|
||||||
@ -191,7 +176,7 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
|||||||
sort.Slice(allowedLocationIPs, func(i, j int) bool {
|
sort.Slice(allowedLocationIPs, func(i, j int) bool {
|
||||||
return allowedLocationIPs[i].String() < allowedLocationIPs[j].String()
|
return allowedLocationIPs[i].String() < allowedLocationIPs[j].String()
|
||||||
})
|
})
|
||||||
t.Segments = append(t.Segments, &Segment{
|
t.segments = append(t.segments, &segment{
|
||||||
allowedIPs: allowedIPs,
|
allowedIPs: allowedIPs,
|
||||||
endpoint: topoMap[location][leader].Endpoint,
|
endpoint: topoMap[location][leader].Endpoint,
|
||||||
key: topoMap[location][leader].Key,
|
key: topoMap[location][leader].Key,
|
||||||
@ -207,8 +192,8 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
|||||||
|
|
||||||
}
|
}
|
||||||
// Sort the Topology segments so the result is stable.
|
// Sort the Topology segments so the result is stable.
|
||||||
sort.Slice(t.Segments, func(i, j int) bool {
|
sort.Slice(t.segments, func(i, j int) bool {
|
||||||
return t.Segments[i].location < t.Segments[j].location
|
return t.segments[i].location < t.segments[j].location
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, peer := range peers {
|
for _, peer := range peers {
|
||||||
@ -227,13 +212,13 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
|||||||
}
|
}
|
||||||
// Allocate IPs to the segment leaders in a stable, coordination-free manner.
|
// Allocate IPs to the segment leaders in a stable, coordination-free manner.
|
||||||
a := newAllocator(*subnet)
|
a := newAllocator(*subnet)
|
||||||
for _, segment := range t.Segments {
|
for _, segment := range t.segments {
|
||||||
ipNet := a.next()
|
ipNet := a.next()
|
||||||
if ipNet == nil {
|
if ipNet == nil {
|
||||||
return nil, errors.New("failed to allocate an IP address; ran out of IP addresses")
|
return nil, errors.New("failed to allocate an IP address; ran out of IP addresses")
|
||||||
}
|
}
|
||||||
segment.wireGuardIP = ipNet.IP
|
segment.wireGuardIP = ipNet.IP
|
||||||
segment.allowedIPs = append(segment.allowedIPs, *OneAddressCIDR(ipNet.IP))
|
segment.allowedIPs = append(segment.allowedIPs, *oneAddressCIDR(ipNet.IP))
|
||||||
if t.leader && segment.location == t.location {
|
if t.leader && segment.location == t.location {
|
||||||
t.wireGuardCIDR = &net.IPNet{IP: ipNet.IP, Mask: subnet.Mask}
|
t.wireGuardCIDR = &net.IPNet{IP: ipNet.IP, Mask: subnet.Mask}
|
||||||
}
|
}
|
||||||
@ -255,16 +240,6 @@ func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Gra
|
|||||||
return &t, nil
|
return &t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Peers returns the peers of the topology.
|
|
||||||
func (t *Topology) Peers() []*Peer {
|
|
||||||
return t.peers
|
|
||||||
}
|
|
||||||
|
|
||||||
// AllowedLocationIPs returns the allowed location IPs of the segment.
|
|
||||||
func (s *Segment) AllowedLocationIPs() []net.IPNet {
|
|
||||||
return s.allowedLocationIPs
|
|
||||||
}
|
|
||||||
|
|
||||||
func intersect(n1, n2 net.IPNet) bool {
|
func intersect(n1, n2 net.IPNet) bool {
|
||||||
return n1.Contains(n2.IP) || n2.Contains(n1.IP)
|
return n1.Contains(n2.IP) || n2.Contains(n1.IP)
|
||||||
}
|
}
|
||||||
@ -272,7 +247,7 @@ func intersect(n1, n2 net.IPNet) bool {
|
|||||||
func (t *Topology) filterAllowedLocationIPs(ips []net.IPNet, location string) (ret []net.IPNet) {
|
func (t *Topology) filterAllowedLocationIPs(ips []net.IPNet, location string) (ret []net.IPNet) {
|
||||||
CheckIPs:
|
CheckIPs:
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
for _, s := range t.Segments {
|
for _, s := range t.segments {
|
||||||
// Check if allowed location IPs are also allowed in other locations.
|
// Check if allowed location IPs are also allowed in other locations.
|
||||||
if location != s.location {
|
if location != s.location {
|
||||||
for _, i := range s.allowedLocationIPs {
|
for _, i := range s.allowedLocationIPs {
|
||||||
@ -332,7 +307,7 @@ func (t *Topology) Conf() *wireguard.Conf {
|
|||||||
ReplacePeers: true,
|
ReplacePeers: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, s := range t.Segments {
|
for _, s := range t.segments {
|
||||||
if s.location == t.location {
|
if s.location == t.location {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -366,7 +341,7 @@ func (t *Topology) Conf() *wireguard.Conf {
|
|||||||
// AsPeer generates the WireGuard peer configuration for the local location of the given Topology.
|
// AsPeer generates the WireGuard peer configuration for the local location of the given Topology.
|
||||||
// This configuration can be used to configure this location as a peer of another WireGuard interface.
|
// This configuration can be used to configure this location as a peer of another WireGuard interface.
|
||||||
func (t *Topology) AsPeer() *wireguard.Peer {
|
func (t *Topology) AsPeer() *wireguard.Peer {
|
||||||
for _, s := range t.Segments {
|
for _, s := range t.segments {
|
||||||
if s.location != t.location {
|
if s.location != t.location {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -394,7 +369,7 @@ func (t *Topology) PeerConf(name string) *wireguard.Conf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
c := &wireguard.Conf{}
|
c := &wireguard.Conf{}
|
||||||
for _, s := range t.Segments {
|
for _, s := range t.segments {
|
||||||
peer := wireguard.Peer{
|
peer := wireguard.Peer{
|
||||||
PeerConfig: wgtypes.PeerConfig{
|
PeerConfig: wgtypes.PeerConfig{
|
||||||
AllowedIPs: append(s.allowedIPs, s.allowedLocationIPs...),
|
AllowedIPs: append(s.allowedIPs, s.allowedLocationIPs...),
|
||||||
@ -416,16 +391,16 @@ func (t *Topology) PeerConf(name string) *wireguard.Conf {
|
|||||||
PersistentKeepaliveInterval: pka,
|
PersistentKeepaliveInterval: pka,
|
||||||
PublicKey: t.peers[i].PublicKey,
|
PublicKey: t.peers[i].PublicKey,
|
||||||
},
|
},
|
||||||
Endpoint: t.peers[i].Endpoint,
|
Endpoint: t.updateEndpoint(t.peers[i].Endpoint, t.peers[i].PublicKey, t.peers[i].PersistentKeepaliveInterval),
|
||||||
}
|
}
|
||||||
c.Peers = append(c.Peers, peer)
|
c.Peers = append(c.Peers, peer)
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
// OneAddressCIDR takes an IP address and returns a CIDR
|
// oneAddressCIDR takes an IP address and returns a CIDR
|
||||||
// that contains only that address.
|
// that contains only that address.
|
||||||
func OneAddressCIDR(ip net.IP) *net.IPNet {
|
func oneAddressCIDR(ip net.IP) *net.IPNet {
|
||||||
return &net.IPNet{IP: ip, Mask: net.CIDRMask(len(ip)*8, len(ip)*8)}
|
return &net.IPNet{IP: ip, Mask: net.CIDRMask(len(ip)*8, len(ip)*8)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ func TestNewTopology(t *testing.T) {
|
|||||||
subnet: nodes["a"].Subnet,
|
subnet: nodes["a"].Subnet,
|
||||||
privateIP: nodes["a"].InternalIP,
|
privateIP: nodes["a"].InternalIP,
|
||||||
wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)},
|
wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)},
|
||||||
Segments: []*Segment{
|
segments: []*segment{
|
||||||
{
|
{
|
||||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||||
endpoint: nodes["a"].Endpoint,
|
endpoint: nodes["a"].Endpoint,
|
||||||
@ -198,7 +198,7 @@ func TestNewTopology(t *testing.T) {
|
|||||||
subnet: nodes["b"].Subnet,
|
subnet: nodes["b"].Subnet,
|
||||||
privateIP: nodes["b"].InternalIP,
|
privateIP: nodes["b"].InternalIP,
|
||||||
wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)},
|
wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)},
|
||||||
Segments: []*Segment{
|
segments: []*segment{
|
||||||
{
|
{
|
||||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||||
endpoint: nodes["a"].Endpoint,
|
endpoint: nodes["a"].Endpoint,
|
||||||
@ -249,7 +249,7 @@ func TestNewTopology(t *testing.T) {
|
|||||||
subnet: nodes["c"].Subnet,
|
subnet: nodes["c"].Subnet,
|
||||||
privateIP: nodes["c"].InternalIP,
|
privateIP: nodes["c"].InternalIP,
|
||||||
wireGuardCIDR: DefaultKiloSubnet,
|
wireGuardCIDR: DefaultKiloSubnet,
|
||||||
Segments: []*Segment{
|
segments: []*segment{
|
||||||
{
|
{
|
||||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||||
endpoint: nodes["a"].Endpoint,
|
endpoint: nodes["a"].Endpoint,
|
||||||
@ -300,7 +300,7 @@ func TestNewTopology(t *testing.T) {
|
|||||||
subnet: nodes["a"].Subnet,
|
subnet: nodes["a"].Subnet,
|
||||||
privateIP: nodes["a"].InternalIP,
|
privateIP: nodes["a"].InternalIP,
|
||||||
wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)},
|
wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)},
|
||||||
Segments: []*Segment{
|
segments: []*segment{
|
||||||
{
|
{
|
||||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||||
endpoint: nodes["a"].Endpoint,
|
endpoint: nodes["a"].Endpoint,
|
||||||
@ -362,7 +362,7 @@ func TestNewTopology(t *testing.T) {
|
|||||||
subnet: nodes["b"].Subnet,
|
subnet: nodes["b"].Subnet,
|
||||||
privateIP: nodes["b"].InternalIP,
|
privateIP: nodes["b"].InternalIP,
|
||||||
wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)},
|
wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)},
|
||||||
Segments: []*Segment{
|
segments: []*segment{
|
||||||
{
|
{
|
||||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||||
endpoint: nodes["a"].Endpoint,
|
endpoint: nodes["a"].Endpoint,
|
||||||
@ -424,7 +424,7 @@ func TestNewTopology(t *testing.T) {
|
|||||||
subnet: nodes["c"].Subnet,
|
subnet: nodes["c"].Subnet,
|
||||||
privateIP: nodes["c"].InternalIP,
|
privateIP: nodes["c"].InternalIP,
|
||||||
wireGuardCIDR: &net.IPNet{IP: w3, Mask: net.CIDRMask(16, 32)},
|
wireGuardCIDR: &net.IPNet{IP: w3, Mask: net.CIDRMask(16, 32)},
|
||||||
Segments: []*Segment{
|
segments: []*segment{
|
||||||
{
|
{
|
||||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||||
endpoint: nodes["a"].Endpoint,
|
endpoint: nodes["a"].Endpoint,
|
||||||
@ -486,7 +486,7 @@ func TestNewTopology(t *testing.T) {
|
|||||||
subnet: nodes["d"].Subnet,
|
subnet: nodes["d"].Subnet,
|
||||||
privateIP: nil,
|
privateIP: nil,
|
||||||
wireGuardCIDR: &net.IPNet{IP: w4, Mask: net.CIDRMask(16, 32)},
|
wireGuardCIDR: &net.IPNet{IP: w4, Mask: net.CIDRMask(16, 32)},
|
||||||
Segments: []*Segment{
|
segments: []*segment{
|
||||||
{
|
{
|
||||||
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
allowedIPs: []net.IPNet{*nodes["a"].Subnet, *nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}},
|
||||||
endpoint: nodes["a"].Endpoint,
|
endpoint: nodes["a"].Endpoint,
|
||||||
@ -925,12 +925,12 @@ func TestFilterAllowedIPs(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
for k, v := range tc.allowedLocationIPs {
|
for k, v := range tc.allowedLocationIPs {
|
||||||
topo.Segments[k].allowedLocationIPs = v
|
topo.segments[k].allowedLocationIPs = v
|
||||||
}
|
}
|
||||||
for k, v := range topo.Segments {
|
for k, v := range topo.segments {
|
||||||
f := topo.filterAllowedLocationIPs(v.allowedLocationIPs, v.location)
|
f := topo.filterAllowedLocationIPs(v.allowedLocationIPs, v.location)
|
||||||
// Overwrite the allowedLocationIPs to mimic the actual usage of the filterAllowedLocationIPs function.
|
// Overwrite the allowedLocationIPs to mimic the actual usage of the filterAllowedLocationIPs function.
|
||||||
topo.Segments[k].allowedLocationIPs = f
|
topo.segments[k].allowedLocationIPs = f
|
||||||
if !ipNetSlicesEqual(f, tc.result[k]) {
|
if !ipNetSlicesEqual(f, tc.result[k]) {
|
||||||
t.Errorf("test case %q:\n\texpected:\n\t%q\n\tgot:\n\t%q\n", tc.name, tc.result[k], f)
|
t.Errorf("test case %q:\n\texpected:\n\t%q\n\tgot:\n\t%q\n", tc.name, tc.result[k], f)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user