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