@@ -3,6 +3,7 @@ package vf
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "io"
6
7
"net"
7
8
"net/url"
8
9
"strconv"
@@ -11,7 +12,7 @@ import (
11
12
"inet.af/tcpproxy"
12
13
)
13
14
14
- func ExposeVsock (vm * vz.VirtualMachine , port uint , vsockPath string , listen bool ) error {
15
+ func ExposeVsock (vm * vz.VirtualMachine , port uint , vsockPath string , listen bool ) (io. Closer , error ) {
15
16
if listen {
16
17
return listenVsock (vm , port , vsockPath )
17
18
}
@@ -36,7 +37,7 @@ func ConnectVsockSync(vm *vz.VirtualMachine, port uint) (net.Conn, error) {
36
37
37
38
// connectVsock proxies connections from a host unix socket to a vsock port
38
39
// This allows the host to initiate connections to the guest over vsock
39
- func connectVsock (vm * vz.VirtualMachine , port uint , vsockPath string ) error {
40
+ func connectVsock (vm * vz.VirtualMachine , port uint , vsockPath string ) (io. Closer , error ) {
40
41
41
42
var proxy tcpproxy.Proxy
42
43
// listen for connections on the host unix socket
@@ -70,12 +71,12 @@ func connectVsock(vm *vz.VirtualMachine, port uint, vsockPath string) error {
70
71
}
71
72
},
72
73
})
73
- return proxy .Start ()
74
+ return & proxy , proxy .Start ()
74
75
}
75
76
76
77
// listenVsock proxies connections from a vsock port to a host unix socket.
77
78
// This allows the guest to initiate connections to the host over vsock
78
- func listenVsock (vm * vz.VirtualMachine , port uint , vsockPath string ) error {
79
+ func listenVsock (vm * vz.VirtualMachine , port uint , vsockPath string ) (io. Closer , error ) {
79
80
var proxy tcpproxy.Proxy
80
81
// listen for connections on the vsock port
81
82
proxy .ListenFunc = func (_ , laddr string ) (net.Listener , error ) {
@@ -116,6 +117,6 @@ func listenVsock(vm *vz.VirtualMachine, port uint, vsockPath string) error {
116
117
}
117
118
},
118
119
})
119
- // FIXME: defer proxy.Close()
120
- return proxy .Start ()
120
+
121
+ return & proxy , proxy .Start ()
121
122
}
0 commit comments