Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion cmd/wireproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func main() {
// Wireguard doesn't allow configuring which FD to use for logging
// https://github.com/WireGuard/wireguard-go/blob/master/device/logger.go#L39
// so redirect STDOUT to STDERR, we don't want to print anything to STDOUT anyways
os.Stdout = os.NewFile(uintptr(syscall.Stderr), "/dev/stderr")
os.Stdout = os.Stderr
logLevel := device.LogLevelVerbose
if *silent {
logLevel = device.LogLevelSilent
Expand Down
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type TCPClientTunnelConfig struct {

type STDIOTunnelConfig struct {
Target string
Input *os.File
Output *os.File
}

type TCPServerTunnelConfig struct {
Expand Down Expand Up @@ -377,6 +379,8 @@ func parseSTDIOTunnelConfig(section *ini.Section) (RoutineSpawner, error) {
return nil, err
}
config.Target = targetSection
config.Input = os.Stdin
config.Output = os.Stdout

return config, nil
}
Expand Down
15 changes: 4 additions & 11 deletions routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,22 @@ func tcpClientForward(vt *VirtualTun, raddr *addressPort, conn net.Conn) {
}

// STDIOTcpForward starts a new connection via wireguard and forward traffic from `conn`
func STDIOTcpForward(vt *VirtualTun, raddr *addressPort) {
func STDIOTcpForward(vt *VirtualTun, raddr *addressPort, input *os.File, output *os.File) {
target, err := vt.resolveToAddrPort(raddr)
if err != nil {
errorLogger.Printf("Name resolution error for %s: %s\n", raddr.address, err.Error())
return
}

// os.Stdout has previously been remapped to stderr, se we can't use it
stdout, err := os.OpenFile("/dev/stdout", os.O_WRONLY, 0)
if err != nil {
errorLogger.Printf("Failed to open /dev/stdout: %s\n", err.Error())
return
}

tcpAddr := TCPAddrFromAddrPort(*target)
sconn, err := vt.Tnet.DialTCP(tcpAddr)
if err != nil {
errorLogger.Printf("TCP Client Tunnel to %s (%s): %s\n", target, tcpAddr, err.Error())
return
}

go connForward(os.Stdin, sconn)
go connForward(sconn, stdout)
go connForward(input, sconn)
go connForward(sconn, output)
}

// SpawnRoutine spawns a local TCP server which acts as a proxy to the specified target
Expand Down Expand Up @@ -272,7 +265,7 @@ func (conf *STDIOTunnelConfig) SpawnRoutine(vt *VirtualTun) {
log.Fatal(err)
}

go STDIOTcpForward(vt, raddr)
go STDIOTcpForward(vt, raddr, conf.Input, conf.Output)
}

// tcpServerForward starts a new connection locally and forward traffic from `conn`
Expand Down