|
|
@ -34,113 +34,6 @@ import (
|
|
|
|
"tailscale.com/wgengine/wgcfg"
|
|
|
|
"tailscale.com/wgengine/wgcfg"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func TestNetworkMapCompare(t *testing.T) {
|
|
|
|
|
|
|
|
prefix1, err := netip.ParsePrefix("192.168.0.0/24")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
node1 := &tailcfg.Node{Addresses: []netip.Prefix{prefix1}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prefix2, err := netip.ParsePrefix("10.0.0.0/8")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
node2 := &tailcfg.Node{Addresses: []netip.Prefix{prefix2}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
|
|
|
name string
|
|
|
|
|
|
|
|
a, b *netmap.NetworkMap
|
|
|
|
|
|
|
|
want bool
|
|
|
|
|
|
|
|
}{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"both nil",
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"b nil",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{},
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"a nil",
|
|
|
|
|
|
|
|
nil,
|
|
|
|
|
|
|
|
&netmap.NetworkMap{},
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"both default",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{},
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"names identical",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Name: "map1"},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Name: "map1"},
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"names differ",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Name: "map1"},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Name: "map2"},
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Peers identical",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{})},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{})},
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Peer list length",
|
|
|
|
|
|
|
|
// length of Peers list differs
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{}})},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{})},
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Node names identical",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "A"}})},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "A"}})},
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Node names differ",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "A"}})},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{Name: "B"}})},
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Node lists identical",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node1})},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node1})},
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Node lists differ",
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node1})},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{node1, node2})},
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"Node Users differ",
|
|
|
|
|
|
|
|
// User field is not checked.
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{User: 0}})},
|
|
|
|
|
|
|
|
&netmap.NetworkMap{Peers: nodeViews([]*tailcfg.Node{{User: 1}})},
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
|
|
|
got := dnsMapsEqual(tt.a, tt.b)
|
|
|
|
|
|
|
|
if got != tt.want {
|
|
|
|
|
|
|
|
t.Errorf("%s: Equal = %v; want %v", tt.name, got, tt.want)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func inRemove(ip netip.Addr) bool {
|
|
|
|
func inRemove(ip netip.Addr) bool {
|
|
|
|
for _, pfx := range removeFromDefaultRoute {
|
|
|
|
for _, pfx := range removeFromDefaultRoute {
|
|
|
|
if pfx.Contains(ip) {
|
|
|
|
if pfx.Contains(ip) {
|
|
|
|