diff --git a/pkg/mesh/topology.go b/pkg/mesh/topology.go index 3c98bf5..d3ca4c2 100644 --- a/pkg/mesh/topology.go +++ b/pkg/mesh/topology.go @@ -368,7 +368,8 @@ func (t *Topology) AsPeer() *wireguard.Peer { IP: s.endpoint, Port: uint32(t.port), }, - PublicKey: s.key, + PersistentKeepalive: s.persistentKeepalive, + PublicKey: s.key, } } return nil @@ -384,7 +385,8 @@ func (t *Topology) PeerConf(name string) *wireguard.Conf { IP: s.endpoint, Port: uint32(t.port), }, - PublicKey: s.key, + PersistentKeepalive: s.persistentKeepalive, + PublicKey: s.key, } c.Peers = append(c.Peers, peer) } diff --git a/pkg/mesh/topology_test.go b/pkg/mesh/topology_test.go index 661caa9..f6402de 100644 --- a/pkg/mesh/topology_test.go +++ b/pkg/mesh/topology_test.go @@ -39,12 +39,13 @@ func setup(t *testing.T) (map[string]*Node, map[string]*Peer, []byte, uint32) { i2 := &net.IPNet{IP: net.ParseIP("192.168.0.2").To4(), Mask: net.CIDRMask(32, 32)} nodes := map[string]*Node{ "a": { - Name: "a", - ExternalIP: e1, - InternalIP: i1, - Location: "1", - Subnet: &net.IPNet{IP: net.ParseIP("10.2.1.0"), Mask: net.CIDRMask(24, 32)}, - Key: []byte("key1"), + Name: "a", + ExternalIP: e1, + InternalIP: i1, + Location: "1", + Subnet: &net.IPNet{IP: net.ParseIP("10.2.1.0"), Mask: net.CIDRMask(24, 32)}, + Key: []byte("key1"), + PersistentKeepalive: 25, }, "b": { Name: "b", @@ -117,14 +118,15 @@ func TestNewTopology(t *testing.T) { wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)}, segments: []*segment{ { - allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, - endpoint: nodes["a"].ExternalIP.IP, - key: nodes["a"].Key, - location: nodes["a"].Location, - cidrs: []*net.IPNet{nodes["a"].Subnet}, - hostnames: []string{"a"}, - privateIPs: []net.IP{nodes["a"].InternalIP.IP}, - wireGuardIP: w1, + allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, + endpoint: nodes["a"].ExternalIP.IP, + key: nodes["a"].Key, + location: nodes["a"].Location, + cidrs: []*net.IPNet{nodes["a"].Subnet}, + hostnames: []string{"a"}, + privateIPs: []net.IP{nodes["a"].InternalIP.IP}, + persistentKeepalive: nodes["a"].PersistentKeepalive, + wireGuardIP: w1, }, { allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}}, @@ -153,14 +155,15 @@ func TestNewTopology(t *testing.T) { wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)}, segments: []*segment{ { - allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, - endpoint: nodes["a"].ExternalIP.IP, - key: nodes["a"].Key, - location: nodes["a"].Location, - cidrs: []*net.IPNet{nodes["a"].Subnet}, - hostnames: []string{"a"}, - privateIPs: []net.IP{nodes["a"].InternalIP.IP}, - wireGuardIP: w1, + allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, + endpoint: nodes["a"].ExternalIP.IP, + key: nodes["a"].Key, + location: nodes["a"].Location, + cidrs: []*net.IPNet{nodes["a"].Subnet}, + hostnames: []string{"a"}, + privateIPs: []net.IP{nodes["a"].InternalIP.IP}, + persistentKeepalive: nodes["a"].PersistentKeepalive, + wireGuardIP: w1, }, { allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}}, @@ -189,14 +192,15 @@ func TestNewTopology(t *testing.T) { wireGuardCIDR: nil, segments: []*segment{ { - allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, - endpoint: nodes["a"].ExternalIP.IP, - key: nodes["a"].Key, - location: nodes["a"].Location, - cidrs: []*net.IPNet{nodes["a"].Subnet}, - hostnames: []string{"a"}, - privateIPs: []net.IP{nodes["a"].InternalIP.IP}, - wireGuardIP: w1, + allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, + endpoint: nodes["a"].ExternalIP.IP, + key: nodes["a"].Key, + location: nodes["a"].Location, + cidrs: []*net.IPNet{nodes["a"].Subnet}, + hostnames: []string{"a"}, + privateIPs: []net.IP{nodes["a"].InternalIP.IP}, + persistentKeepalive: nodes["a"].PersistentKeepalive, + wireGuardIP: w1, }, { allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, nodes["c"].Subnet, nodes["c"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}}, @@ -225,14 +229,15 @@ func TestNewTopology(t *testing.T) { wireGuardCIDR: &net.IPNet{IP: w1, Mask: net.CIDRMask(16, 32)}, segments: []*segment{ { - allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, - endpoint: nodes["a"].ExternalIP.IP, - key: nodes["a"].Key, - location: nodes["a"].Name, - cidrs: []*net.IPNet{nodes["a"].Subnet}, - hostnames: []string{"a"}, - privateIPs: []net.IP{nodes["a"].InternalIP.IP}, - wireGuardIP: w1, + allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, + endpoint: nodes["a"].ExternalIP.IP, + key: nodes["a"].Key, + location: nodes["a"].Name, + cidrs: []*net.IPNet{nodes["a"].Subnet}, + hostnames: []string{"a"}, + privateIPs: []net.IP{nodes["a"].InternalIP.IP}, + persistentKeepalive: nodes["a"].PersistentKeepalive, + wireGuardIP: w1, }, { allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}}, @@ -271,14 +276,15 @@ func TestNewTopology(t *testing.T) { wireGuardCIDR: &net.IPNet{IP: w2, Mask: net.CIDRMask(16, 32)}, segments: []*segment{ { - allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, - endpoint: nodes["a"].ExternalIP.IP, - key: nodes["a"].Key, - location: nodes["a"].Name, - cidrs: []*net.IPNet{nodes["a"].Subnet}, - hostnames: []string{"a"}, - privateIPs: []net.IP{nodes["a"].InternalIP.IP}, - wireGuardIP: w1, + allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, + endpoint: nodes["a"].ExternalIP.IP, + key: nodes["a"].Key, + location: nodes["a"].Name, + cidrs: []*net.IPNet{nodes["a"].Subnet}, + hostnames: []string{"a"}, + privateIPs: []net.IP{nodes["a"].InternalIP.IP}, + persistentKeepalive: nodes["a"].PersistentKeepalive, + wireGuardIP: w1, }, { allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}}, @@ -317,14 +323,15 @@ func TestNewTopology(t *testing.T) { wireGuardCIDR: &net.IPNet{IP: w3, Mask: net.CIDRMask(16, 32)}, segments: []*segment{ { - allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, - endpoint: nodes["a"].ExternalIP.IP, - key: nodes["a"].Key, - location: nodes["a"].Name, - cidrs: []*net.IPNet{nodes["a"].Subnet}, - hostnames: []string{"a"}, - privateIPs: []net.IP{nodes["a"].InternalIP.IP}, - wireGuardIP: w1, + allowedIPs: []*net.IPNet{nodes["a"].Subnet, nodes["a"].InternalIP, {IP: w1, Mask: net.CIDRMask(32, 32)}}, + endpoint: nodes["a"].ExternalIP.IP, + key: nodes["a"].Key, + location: nodes["a"].Name, + cidrs: []*net.IPNet{nodes["a"].Subnet}, + hostnames: []string{"a"}, + privateIPs: []net.IP{nodes["a"].InternalIP.IP}, + persistentKeepalive: nodes["a"].PersistentKeepalive, + wireGuardIP: w1, }, { allowedIPs: []*net.IPNet{nodes["b"].Subnet, nodes["b"].InternalIP, {IP: w2, Mask: net.CIDRMask(32, 32)}}, @@ -1027,6 +1034,7 @@ AllowedIPs = 10.5.0.3/24 [Peer] PublicKey = key1 Endpoint = 10.1.0.1:51820 + PersistentKeepalive = 25 AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32 [Peer] @@ -1051,6 +1059,7 @@ AllowedIPs = 10.5.0.3/24 [Peer] PublicKey = key1 Endpoint = 10.1.0.1:51820 + PersistentKeepalive = 25 AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32 [Peer] @@ -1104,6 +1113,7 @@ AllowedIPs = 10.5.0.3/24 [Peer] PublicKey = key1 Endpoint = 10.1.0.1:51820 + PersistentKeepalive = 25 AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32 [Peer] @@ -1133,6 +1143,7 @@ AllowedIPs = 10.5.0.3/24 [Peer] PublicKey = key1 Endpoint = 10.1.0.1:51820 + PersistentKeepalive = 25 AllowedIPs = 10.2.1.0/24, 192.168.0.1/32, 10.4.0.1/32 [Peer]