()
| 12 | ) |
| 13 | |
| 14 | func (*RootCmd) vpnDaemonRun() *serpent.Command { |
| 15 | var ( |
| 16 | rpcReadHandleInt int64 |
| 17 | rpcWriteHandleInt int64 |
| 18 | ) |
| 19 | |
| 20 | cmd := &serpent.Command{ |
| 21 | Use: "run", |
| 22 | Short: "Run the VPN daemon on Windows and Linux.", |
| 23 | Middleware: serpent.Chain( |
| 24 | serpent.RequireNArgs(0), |
| 25 | ), |
| 26 | Options: serpent.OptionSet{ |
| 27 | { |
| 28 | Flag: "rpc-read-handle", |
| 29 | Env: "CODER_VPN_DAEMON_RPC_READ_HANDLE", |
| 30 | Description: "The handle for the pipe to read from the RPC connection.", |
| 31 | Value: serpent.Int64Of(&rpcReadHandleInt), |
| 32 | Required: true, |
| 33 | }, |
| 34 | { |
| 35 | Flag: "rpc-write-handle", |
| 36 | Env: "CODER_VPN_DAEMON_RPC_WRITE_HANDLE", |
| 37 | Description: "The handle for the pipe to write to the RPC connection.", |
| 38 | Value: serpent.Int64Of(&rpcWriteHandleInt), |
| 39 | Required: true, |
| 40 | }, |
| 41 | }, |
| 42 | Handler: func(inv *serpent.Invocation) error { |
| 43 | ctx := inv.Context() |
| 44 | sinks := []slog.Sink{ |
| 45 | sloghuman.Sink(inv.Stderr), |
| 46 | } |
| 47 | logger := inv.Logger.AppendSinks(sinks...).Leveled(slog.LevelDebug) |
| 48 | |
| 49 | if rpcReadHandleInt < 0 || rpcWriteHandleInt < 0 { |
| 50 | return xerrors.Errorf("rpc-read-handle (%v) and rpc-write-handle (%v) must be positive", rpcReadHandleInt, rpcWriteHandleInt) |
| 51 | } |
| 52 | if rpcReadHandleInt == rpcWriteHandleInt { |
| 53 | return xerrors.Errorf("rpc-read-handle (%v) and rpc-write-handle (%v) must be different", rpcReadHandleInt, rpcWriteHandleInt) |
| 54 | } |
| 55 | |
| 56 | // The manager passes the read and write descriptors directly to the |
| 57 | // daemon, so we can open the RPC pipe from the raw values. |
| 58 | logger.Info(ctx, "opening bidirectional RPC pipe", slog.F("rpc_read_handle", rpcReadHandleInt), slog.F("rpc_write_handle", rpcWriteHandleInt)) |
| 59 | pipe, err := vpn.NewBidirectionalPipe(uintptr(rpcReadHandleInt), uintptr(rpcWriteHandleInt)) |
| 60 | if err != nil { |
| 61 | return xerrors.Errorf("create bidirectional RPC pipe: %w", err) |
| 62 | } |
| 63 | defer pipe.Close() |
| 64 | |
| 65 | logger.Info(ctx, "starting VPN tunnel") |
| 66 | tunnel, err := vpn.NewTunnel(ctx, logger, pipe, vpn.NewClient(), vpn.UseOSNetworkingStack()) |
| 67 | if err != nil { |
| 68 | return xerrors.Errorf("create new tunnel for client: %w", err) |
| 69 | } |
| 70 | defer tunnel.Close() |
| 71 |
nothing calls this directly
no test coverage detected