logID may be the zero value if logging is not in use.
(ctx context.Context, logf logger.Logf, logID logid.PublicID, sys *tsd.System)
| 614 | |
| 615 | // logID may be the zero value if logging is not in use. |
| 616 | func getLocalBackend(ctx context.Context, logf logger.Logf, logID logid.PublicID, sys *tsd.System) (_ *ipnlocal.LocalBackend, retErr error) { |
| 617 | if logPol != nil { |
| 618 | logPol.Logtail.SetNetMon(sys.NetMon.Get()) |
| 619 | } |
| 620 | |
| 621 | var startProxy proxyStartFunc |
| 622 | if listen, ok := hookOutboundProxyListen.GetOk(); ok { |
| 623 | startProxy = listen() |
| 624 | } |
| 625 | |
| 626 | dialer := &tsdial.Dialer{Logf: logf} // mutated below (before used) |
| 627 | dialer.SetBus(sys.Bus.Get()) |
| 628 | sys.Set(dialer) |
| 629 | |
| 630 | onlyNetstack, err := createEngine(logf, sys) |
| 631 | if err != nil { |
| 632 | return nil, fmt.Errorf("createEngine: %w", err) |
| 633 | } |
| 634 | if onlyNetstack && !buildfeatures.HasNetstack { |
| 635 | return nil, errors.New("userspace-networking support is not compiled in to this binary") |
| 636 | } |
| 637 | if buildfeatures.HasDebug && debugMux != nil { |
| 638 | if ms, ok := sys.MagicSock.GetOK(); ok { |
| 639 | debugMux.HandleFunc("/debug/magicsock", ms.ServeHTTPDebug) |
| 640 | } |
| 641 | go runDebugServer(logf, debugMux, args.debug) |
| 642 | } |
| 643 | |
| 644 | var ns tsd.NetstackImpl // or nil if not linked in |
| 645 | if newNetstack, ok := hookNewNetstack.GetOk(); ok { |
| 646 | ns, err = newNetstack(logf, sys, onlyNetstack) |
| 647 | if err != nil { |
| 648 | return nil, fmt.Errorf("newNetstack: %w", err) |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | if startProxy != nil { |
| 653 | go startProxy(logf, dialer) |
| 654 | } |
| 655 | |
| 656 | opts := ipnServerOpts() |
| 657 | |
| 658 | store, err := store.New(logf, statePathOrDefault()) |
| 659 | if err != nil { |
| 660 | // If we can't create the store (for example if it's TPM-sealed and the |
| 661 | // TPM is reset), create a dummy in-memory store to propagate the error |
| 662 | // to the user. |
| 663 | ht, ok := sys.HealthTracker.GetOK() |
| 664 | if !ok { |
| 665 | return nil, fmt.Errorf("store.New: %w", err) |
| 666 | } |
| 667 | logf("store.New failed: %v; starting with in-memory store with a health warning", err) |
| 668 | store = new(mem.Store) |
| 669 | ht.SetUnhealthy(ipn.StateStoreHealth, health.Args{health.ArgError: err.Error()}) |
| 670 | } |
| 671 | sys.Set(store) |
| 672 | |
| 673 | if w, ok := sys.Tun.GetOK(); ok { |
searching dependent graphs…