MCPcopy
hub / github.com/tailscale/tailscale / newNetstack

Function newNetstack

cmd/tailscaled/netstack.go:23–75  ·  view source on GitHub ↗
(logf logger.Logf, sys *tsd.System, onlyNetstack bool)

Source from the content-addressed store, hash-verified

21}
22
23func newNetstack(logf logger.Logf, sys *tsd.System, onlyNetstack bool) (tsd.NetstackImpl, error) {
24 ns, err := netstack.Create(logf,
25 sys.Tun.Get(),
26 sys.Engine.Get(),
27 sys.MagicSock.Get(),
28 sys.Dialer.Get(),
29 sys.DNSManager.Get(),
30 sys.ProxyMapper(),
31 )
32 if err != nil {
33 return nil, err
34 }
35 // Only register debug info if we have a debug mux
36 if debugMux != nil {
37 expvar.Publish("netstack", ns.ExpVar())
38 }
39
40 sys.Set(ns)
41 ns.ProcessLocalIPs = onlyNetstack
42 ns.ProcessSubnets = onlyNetstack || handleSubnetsInNetstack()
43
44 dialer := sys.Dialer.Get() // must be set by caller already
45
46 if onlyNetstack {
47 e := sys.Engine.Get()
48 dialer.UseNetstackForIP = func(ip netip.Addr) bool {
49 _, ok := e.PeerForIP(ip)
50 return ok
51 }
52 dialer.NetstackDialTCP = func(ctx context.Context, dst netip.AddrPort) (net.Conn, error) {
53 // Note: don't just return ns.DialContextTCP or we'll return
54 // *gonet.TCPConn(nil) instead of a nil interface which trips up
55 // callers.
56 tcpConn, err := ns.DialContextTCP(ctx, dst)
57 if err != nil {
58 return nil, err
59 }
60 return tcpConn, nil
61 }
62 dialer.NetstackDialUDP = func(ctx context.Context, dst netip.AddrPort) (net.Conn, error) {
63 // Note: don't just return ns.DialContextUDP or we'll return
64 // *gonet.UDPConn(nil) instead of a nil interface which trips up
65 // callers.
66 udpConn, err := ns.DialContextUDP(ctx, dst)
67 if err != nil {
68 return nil, err
69 }
70 return udpConn, nil
71 }
72 }
73
74 return ns, nil
75}

Callers 1

getLocalBackendFunction · 0.85

Calls 10

CreateFunction · 0.92
handleSubnetsInNetstackFunction · 0.85
ProxyMapperMethod · 0.80
DialContextTCPMethod · 0.80
DialContextUDPMethod · 0.80
GetMethod · 0.65
SetMethod · 0.65
PeerForIPMethod · 0.65
PublishMethod · 0.45
ExpVarMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…