-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds stdio as a way to communicate between gvproxy and vm mainly…
… for use with WSL2, although it should work for other cases as well. When network connections between WSL2 and the Windows host are blocked, stdio is the only reliable way to establish a channel between WSL2 and the Windows host. Hyper-V socket for WSL2 is a possibility, but it requires undocumented APIs and admin privileges. Signed-off-by: Keiichi Shimamura <sakai135@users.noreply.github.com>
- Loading branch information
Showing
7 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package stdio | ||
|
||
import ( | ||
"net" | ||
"os" | ||
"os/exec" | ||
"strconv" | ||
) | ||
|
||
func Dial(endpoint string, arg ...string) (net.Conn, error) { | ||
cmd := exec.Command(endpoint, arg...) | ||
cmd.Stderr = os.Stderr | ||
|
||
stdin, err := cmd.StdinPipe() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
stdout, err := cmd.StdoutPipe() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = cmd.Start() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
local := IoAddr{path: strconv.Itoa(os.Getpid())} | ||
remote := IoAddr{path: strconv.Itoa(cmd.Process.Pid)} | ||
conn := IoConn{ | ||
reader: stdout, | ||
writer: stdin, | ||
local: local, | ||
remote: remote, | ||
close: cmd.Process.Kill, | ||
} | ||
return conn, nil | ||
} | ||
|
||
func GetStdioConn() net.Conn { | ||
local := IoAddr{path: strconv.Itoa(os.Getpid())} | ||
remote := IoAddr{path: "remote"} | ||
conn := IoConn{ | ||
writer: os.Stdout, | ||
reader: os.Stdin, | ||
local: local, | ||
remote: remote, | ||
} | ||
return conn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package stdio | ||
|
||
type IoAddr struct { | ||
path string | ||
} | ||
|
||
func (a IoAddr) Network() string { | ||
return "stdio" | ||
} | ||
func (a IoAddr) String() string { | ||
return a.path | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package stdio | ||
|
||
import ( | ||
"io" | ||
"net" | ||
"time" | ||
) | ||
|
||
type IoConn struct { | ||
writer io.Writer | ||
reader io.Reader | ||
local net.Addr | ||
remote net.Addr | ||
close func() error | ||
} | ||
|
||
func (c IoConn) Read(b []byte) (n int, err error) { | ||
return c.reader.Read(b) | ||
} | ||
|
||
func (c IoConn) Write(b []byte) (n int, err error) { | ||
return c.writer.Write(b) | ||
} | ||
|
||
func (c IoConn) Close() error { | ||
if c.close != nil { | ||
return c.close() | ||
} | ||
return nil | ||
} | ||
|
||
func (c IoConn) LocalAddr() net.Addr { | ||
return c.local | ||
} | ||
|
||
func (c IoConn) RemoteAddr() net.Addr { | ||
return c.remote | ||
} | ||
|
||
func (c IoConn) SetDeadline(t time.Time) error { | ||
return nil | ||
} | ||
|
||
func (c IoConn) SetReadDeadline(t time.Time) error { | ||
return nil | ||
} | ||
|
||
func (c IoConn) SetWriteDeadline(t time.Time) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
|
||
./bin/vm \ | ||
-url="stdio:$(pwd)/bin/gvproxy-windows.exe?listen-stdio=accept&debug=true" \ | ||
-iface="eth1" \ | ||
-stop-if-exist="" \ | ||
-debug |