mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
49b34a716a
Upgrades to slog v3 which includes a small, but backward incompatible API change to the acceptible call arguments when logging. This change allows us to verify via compile time type checking that arguments are correct and won't cause a panic, as was possible in slog v1, which this replaces (v2 was tagged but never used in coder/coder). It also updates dependencies that also use slog and were updated. I've left the `aibridge` dependency as a commit SHA, under the assumption that the team there (cc @pawbana @dannykopping ) will tag and update the dependency soon and on their own schedule. Other dependencies, I pushed new tags.
40 lines
949 B
Go
40 lines
949 B
Go
//go:build darwin
|
|
|
|
package vpn
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/tailscale/wireguard-go/tun"
|
|
"golang.org/x/sys/unix"
|
|
"golang.org/x/xerrors"
|
|
|
|
"cdr.dev/slog/v3"
|
|
)
|
|
|
|
func GetNetworkingStack(t *Tunnel, req *StartRequest, _ slog.Logger) (NetworkStack, error) {
|
|
tunFd := int(req.GetTunnelFileDescriptor())
|
|
dupTunFd, err := unix.Dup(tunFd)
|
|
if err != nil {
|
|
return NetworkStack{}, xerrors.Errorf("dup tun fd: %w", err)
|
|
}
|
|
|
|
err = unix.SetNonblock(dupTunFd, true)
|
|
if err != nil {
|
|
unix.Close(dupTunFd)
|
|
return NetworkStack{}, xerrors.Errorf("set nonblock: %w", err)
|
|
}
|
|
fileTun, err := tun.CreateTUNFromFile(os.NewFile(uintptr(dupTunFd), "/dev/tun"), 0)
|
|
if err != nil {
|
|
unix.Close(dupTunFd)
|
|
return NetworkStack{}, xerrors.Errorf("create TUN from File: %w", err)
|
|
}
|
|
|
|
return NetworkStack{
|
|
WireguardMonitor: nil, // default is fine
|
|
TUNDevice: fileTun,
|
|
Router: NewRouter(t),
|
|
DNSConfigurator: NewDNSConfigurator(t),
|
|
}, nil
|
|
}
|