8000 feat: peer wireguard by coadler · Pull Request #2445 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: peer wireguard #2445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
coadler committed Jun 23, 2022
commit 2591ffc75090c1b7bc4231f365fc6f55e96a4026
25 changes: 9 additions & 16 deletions cli/wireguardtunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@ import (

func wireguardPortForward() *cobra.Command {
var (
tcpForwards []string // <port>:<port>
udpForwards []string // <port>:<port>
unixForwards []string // <path>:<path> OR <port>:<path>
tcpForwards []string // <port>:<port>
udpForwards []string // <port>:<port>
// TODO: unix support
// unixForwards []string // <path>:<path> OR <port>:<path>
)
cmd := &cobra.Command{
Use: "wireguard-port-forward <workspace>",
Aliases: []string{"wireguard-tunnel"},
Args: cobra.ExactArgs(1),
Hidden: true,
// Hide all wireguard commands for now while we test!
Hidden: true,
Example: `
- Port forward a single TCP port from 1234 in the workspace to port 5678 on
your local machine
Expand All @@ -46,17 +48,10 @@ func wireguardPortForward() *cobra.Command {

` + cliui.Styles.Code.Render("$ coder port-forward <workspace> --udp 9000") + `

- Forward a Unix socket in the workspace to a local Unix socket

` + cliui.Styles.Code.Render("$ coder port-forward <workspace> --unix ./local.sock:~/remote.sock") + `

- Forward a Unix socket in the workspace to a local TCP port

` + cliui.Styles.Code.Render("$ coder port-forward <workspace> --unix 8080:~/remote.sock") + `

- Port forward multiple TCP ports and a UDP port

` + cliui.Styles.Code.Render("$ coder port-forward <workspace> --tcp 8080:8080 --tcp 9000:3000 --udp 5353:53"),
` + cliui.Styles.Code.Render("$ coder port-forward <workspace> --tcp 8080:8080 --tcp 9000:3000 --udp 5353:53") + `
`,
RunE: func(cmd *cobra.Command, args []string) error {
specs, err := parsePortForwards(tcpForwards, nil, nil)
if err != nil {
Expand Down Expand Up @@ -177,11 +172,9 @@ func wireguardPortForward() *cobra.Command {
},
}

// Hide all wireguard commands for now while we test!
cmd.Hidden = true
cmd.Flags().StringArrayVarP(&tcpForwards, "tcp", "p", []string{}, "Forward a TCP port from the workspace to the local machine")
cmd.Flags().StringArrayVar(&udpForwards, "udp", []string{}, "Forward a UDP port from the workspace to the local machine. The UDP connection has TCP-like semantics to support stateful UDP A485 protocols")
cmd.Flags().StringArrayVar(&unixForwards, "unix", []string{}, "Forward a Unix socket in the workspace to a local Unix socket or TCP port")
// cmd.Flags().StringArrayVar(&unixForwards, "unix", []string{}, "Forward a Unix socket in the workspace to a local Unix socket or TCP port")

return cmd
}
Expand Down
2 changes: 1 addition & 1 deletion peer/peerwg/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (n *Network) forwardTCP(conn net.Conn, port uint16) {
listener, ok := n.listeners[listenKey{"tcp", "", fmt.Sprint(port)}]
n.mu.Unlock()
if !ok {
// No listener added, forward to host.
// No in-memory listener exists, forward to host.
n.forwardTCPToLocalHandler(conn, port)
return
}
Expand Down
0