From 7fe5a954b48f5a868bf18ea3dbf300ab3f51680d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 10 Apr 2026 07:22:04 -0700 Subject: [PATCH] tstest/tailmac: remove unnecessary socketpair relay for VZ network device MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Give VZ the dgram socket file descriptor directly, matching what llmacstation does. The socketpair relay was added during debugging but is unnecessary — the direct approach works fine. --- .../Swift/Common/TailMacConfigHelper.swift | 37 ++----------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/tstest/tailmac/Swift/Common/TailMacConfigHelper.swift b/tstest/tailmac/Swift/Common/TailMacConfigHelper.swift index 796adf1cb..6c1db77fc 100644 --- a/tstest/tailmac/Swift/Common/TailMacConfigHelper.swift +++ b/tstest/tailmac/Swift/Common/TailMacConfigHelper.swift @@ -125,42 +125,11 @@ struct TailMacConfigHelper { print("Virtual if mac address is \(config.mac)") print("Client bound to \(clientSocket)") print("Connected to server at \(serverSocket)") + print("Socket fd is \(socket)") - // Use a socketpair between VZ and the relay. VZ reads/writes one end; - // background threads relay between the other end and the vnet dgram socket. - // This is more reliable than giving VZ the dgram socket directly. - var spFds: [Int32] = [0, 0] - guard socketpair(AF_UNIX, SOCK_DGRAM, 0, &spFds) == 0 else { - print("socketpair failed: \(String(cString: strerror(errno)))") - return networkDevice - } - let vzFd = spFds[0] - let relayFd = spFds[1] - - let vzHandle = FileHandle(fileDescriptor: vzFd) - let device = VZFileHandleNetworkDeviceAttachment(fileHandle: vzHandle) + let handle = FileHandle(fileDescriptor: socket) + let device = VZFileHandleNetworkDeviceAttachment(fileHandle: handle) networkDevice.attachment = device - - // Relay: guest→network (read from relayFd, write to dgram socket) - DispatchQueue.global().async { - var buf = [UInt8](repeating: 0, count: 65536) - while true { - let n = Darwin.read(relayFd, &buf, buf.count) - if n <= 0 { break } - Darwin.write(socket, buf, n) - } - } - - // Relay: network→guest (read from dgram socket, write to relayFd) - DispatchQueue.global().async { - var buf = [UInt8](repeating: 0, count: 65536) - while true { - let n = Darwin.read(socket, &buf, buf.count) - if n <= 0 { break } - Darwin.write(relayFd, buf, n) - } - } - return networkDevice }