mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-05 04:06:35 +02:00
tstest/tailmac: remove unnecessary socketpair relay for VZ network device
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.
This commit is contained in:
parent
ef69d2041b
commit
7fe5a954b4
@ -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
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user