MCPcopy Index your code
hub / github.com/coder/coder / GetNetworkingStack

Function GetNetworkingStack

vpn/tun_darwin.go:15–39  ·  view source on GitHub ↗
(t *Tunnel, req *StartRequest, _ slog.Logger)

Source from the content-addressed store, hash-verified

13)
14
15func GetNetworkingStack(t *Tunnel, req *StartRequest, _ slog.Logger) (NetworkStack, error) {
16 tunFd := int(req.GetTunnelFileDescriptor())
17 dupTunFd, err := unix.Dup(tunFd)
18 if err != nil {
19 return NetworkStack{}, xerrors.Errorf("dup tun fd: %w", err)
20 }
21
22 err = unix.SetNonblock(dupTunFd, true)
23 if err != nil {
24 unix.Close(dupTunFd)
25 return NetworkStack{}, xerrors.Errorf("set nonblock: %w", err)
26 }
27 fileTun, err := tun.CreateTUNFromFile(os.NewFile(uintptr(dupTunFd), "/dev/tun"), 0)
28 if err != nil {
29 unix.Close(dupTunFd)
30 return NetworkStack{}, xerrors.Errorf("create TUN from File: %w", err)
31 }
32
33 return NetworkStack{
34 WireguardMonitor: nil, // default is fine
35 TUNDevice: fileTun,
36 Router: NewRouter(t),
37 DNSConfigurator: NewDNSConfigurator(t),
38 }, nil
39}

Callers

nothing calls this directly

Calls 5

NewRouterFunction · 0.85
NewDNSConfiguratorFunction · 0.85
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected