Skip to content

Commit df8b97a

Browse files
authored
Chore: Use guestVsockPorts (#373)
This was a funny oversight. We have two port spaces, one for listening sockets on the host, and one for vsock proxies in the guest, but only the host "allocator" was being used. This didn't really matter as the ports in the guest would still be unique, but would still be good to fix.
1 parent 8682365 commit df8b97a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Sources/Containerization/LinuxContainer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,13 +678,15 @@ extension LinuxContainer {
678678
var socket = socket
679679
let rootInGuest = URL(filePath: self.root)
680680

681+
let port: UInt32
681682
if socket.direction == .into {
683+
port = self.hostVsockPorts.wrappingAdd(1, ordering: .relaxed).oldValue
682684
socket.destination = rootInGuest.appending(path: socket.destination.path)
683685
} else {
686+
port = self.guestVsockPorts.wrappingAdd(1, ordering: .relaxed).oldValue
684687
socket.source = rootInGuest.appending(path: socket.source.path)
685688
}
686689

687-
let port = self.hostVsockPorts.wrappingAdd(1, ordering: .relaxed).oldValue
688690
try await relayManager.start(port: port, socket: socket)
689691
try await relayAgent.relaySocket(port: port, configuration: socket)
690692
}

Sources/Containerization/LinuxPod.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,15 @@ extension LinuxPod {
705705
// Adjust paths to be relative to the container's rootfs
706706
let rootInGuest = URL(filePath: Self.guestRootfsPath(containerID))
707707

708+
let port: UInt32
708709
if socket.direction == .into {
710+
port = self.hostVsockPorts.wrappingAdd(1, ordering: .relaxed).oldValue
709711
socket.destination = rootInGuest.appending(path: socket.destination.path)
710712
} else {
713+
port = self.guestVsockPorts.wrappingAdd(1, ordering: .relaxed).oldValue
711714
socket.source = rootInGuest.appending(path: socket.source.path)
712715
}
713716

714-
let port = self.hostVsockPorts.wrappingAdd(1, ordering: .relaxed).oldValue
715717
try await relayManager.start(port: port, socket: socket)
716718
try await relayAgent.relaySocket(port: port, configuration: socket)
717719
}

0 commit comments

Comments
 (0)