|
|
|
@ -1114,6 +1114,8 @@ func TestEngineReconfigOnStateChange(t *testing.T) {
|
|
|
|
disconnect := &ipn.MaskedPrefs{Prefs: ipn.Prefs{WantRunning: false}, WantRunningSet: true}
|
|
|
|
disconnect := &ipn.MaskedPrefs{Prefs: ipn.Prefs{WantRunning: false}, WantRunningSet: true}
|
|
|
|
node1 := testNetmapForNode(1, "node-1", []netip.Prefix{netip.MustParsePrefix("100.64.1.1/32")})
|
|
|
|
node1 := testNetmapForNode(1, "node-1", []netip.Prefix{netip.MustParsePrefix("100.64.1.1/32")})
|
|
|
|
node2 := testNetmapForNode(2, "node-2", []netip.Prefix{netip.MustParsePrefix("100.64.1.2/32")})
|
|
|
|
node2 := testNetmapForNode(2, "node-2", []netip.Prefix{netip.MustParsePrefix("100.64.1.2/32")})
|
|
|
|
|
|
|
|
node3 := testNetmapForNode(3, "node-3", []netip.Prefix{netip.MustParsePrefix("100.64.1.3/32")})
|
|
|
|
|
|
|
|
node3.Peers = []tailcfg.NodeView{node1.SelfNode, node2.SelfNode}
|
|
|
|
routesWithQuad100 := func(extra ...netip.Prefix) []netip.Prefix {
|
|
|
|
routesWithQuad100 := func(extra ...netip.Prefix) []netip.Prefix {
|
|
|
|
return append(extra, netip.MustParsePrefix("100.100.100.100/32"))
|
|
|
|
return append(extra, netip.MustParsePrefix("100.100.100.100/32"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1308,6 +1310,40 @@ func TestEngineReconfigOnStateChange(t *testing.T) {
|
|
|
|
Hosts: hostsFor(node1),
|
|
|
|
Hosts: hostsFor(node1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name: "Start/Connect/Login/WithPeers",
|
|
|
|
|
|
|
|
steps: func(t *testing.T, lb *LocalBackend, cc func() *mockControl) {
|
|
|
|
|
|
|
|
mustDo(t)(lb.Start(ipn.Options{}))
|
|
|
|
|
|
|
|
mustDo2(t)(lb.EditPrefs(connect))
|
|
|
|
|
|
|
|
cc().authenticated(node3)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantState: ipn.Starting,
|
|
|
|
|
|
|
|
wantCfg: &wgcfg.Config{
|
|
|
|
|
|
|
|
Name: "tailscale",
|
|
|
|
|
|
|
|
NodeID: node3.SelfNode.StableID(),
|
|
|
|
|
|
|
|
Peers: []wgcfg.Peer{
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PublicKey: node1.SelfNode.Key(),
|
|
|
|
|
|
|
|
DiscoKey: node1.SelfNode.DiscoKey(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PublicKey: node2.SelfNode.Key(),
|
|
|
|
|
|
|
|
DiscoKey: node2.SelfNode.DiscoKey(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
Addresses: node3.SelfNode.Addresses().AsSlice(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantRouterCfg: &router.Config{
|
|
|
|
|
|
|
|
SNATSubnetRoutes: true,
|
|
|
|
|
|
|
|
NetfilterMode: preftype.NetfilterOn,
|
|
|
|
|
|
|
|
LocalAddrs: node3.SelfNode.Addresses().AsSlice(),
|
|
|
|
|
|
|
|
Routes: routesWithQuad100(),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
wantDNSCfg: &dns.Config{
|
|
|
|
|
|
|
|
Routes: map[dnsname.FQDN][]*dnstype.Resolver{},
|
|
|
|
|
|
|
|
Hosts: hostsFor(node3),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
for _, tt := range tests {
|
|
|
|
@ -1322,8 +1358,18 @@ func TestEngineReconfigOnStateChange(t *testing.T) {
|
|
|
|
t.Errorf("State: got %v; want %v", gotState, tt.wantState)
|
|
|
|
t.Errorf("State: got %v; want %v", gotState, tt.wantState)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if engine.Config() != nil {
|
|
|
|
|
|
|
|
for _, p := range engine.Config().Peers {
|
|
|
|
|
|
|
|
pKey := p.PublicKey.UntypedHexString()
|
|
|
|
|
|
|
|
_, err := lb.MagicConn().ParseEndpoint(pKey)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
t.Errorf("ParseEndpoint(%q) failed: %v", pKey, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
opts := []cmp.Option{
|
|
|
|
opts := []cmp.Option{
|
|
|
|
cmpopts.EquateComparable(key.NodePublic{}, netip.Addr{}, netip.Prefix{}),
|
|
|
|
cmpopts.EquateComparable(key.NodePublic{}, key.DiscoPublic{}, netip.Addr{}, netip.Prefix{}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if diff := cmp.Diff(tt.wantCfg, engine.Config(), opts...); diff != "" {
|
|
|
|
if diff := cmp.Diff(tt.wantCfg, engine.Config(), opts...); diff != "" {
|
|
|
|
t.Errorf("wgcfg.Config(+got -want): %v", diff)
|
|
|
|
t.Errorf("wgcfg.Config(+got -want): %v", diff)
|
|
|
|
@ -1356,6 +1402,8 @@ func testNetmapForNode(userID tailcfg.UserID, name string, addresses []netip.Pre
|
|
|
|
Addresses: addresses,
|
|
|
|
Addresses: addresses,
|
|
|
|
MachineAuthorized: true,
|
|
|
|
MachineAuthorized: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.Key = makeNodeKeyFromID(self.ID)
|
|
|
|
|
|
|
|
self.DiscoKey = makeDiscoKeyFromID(self.ID)
|
|
|
|
return &netmap.NetworkMap{
|
|
|
|
return &netmap.NetworkMap{
|
|
|
|
SelfNode: self.View(),
|
|
|
|
SelfNode: self.View(),
|
|
|
|
Name: self.Name,
|
|
|
|
Name: self.Name,
|
|
|
|
@ -1403,6 +1451,7 @@ func newLocalBackendWithMockEngineAndControl(t *testing.T, enableLogging bool) (
|
|
|
|
|
|
|
|
|
|
|
|
magicConn, err := magicsock.NewConn(magicsock.Options{
|
|
|
|
magicConn, err := magicsock.NewConn(magicsock.Options{
|
|
|
|
Logf: logf,
|
|
|
|
Logf: logf,
|
|
|
|
|
|
|
|
EventBus: sys.Bus.Get(),
|
|
|
|
NetMon: dialer.NetMon(),
|
|
|
|
NetMon: dialer.NetMon(),
|
|
|
|
Metrics: sys.UserMetricsRegistry(),
|
|
|
|
Metrics: sys.UserMetricsRegistry(),
|
|
|
|
HealthTracker: sys.HealthTracker(),
|
|
|
|
HealthTracker: sys.HealthTracker(),
|
|
|
|
|