Hi, I am experiencing issue with NETransparentProxyProvider. I use transparent proxy to bind some sockets to physical interface when VPN is active. It works fine for all apps, except Safari. With Safari I get errors when reading from the connection in inbound copier. I use following code snippet:
let reader: TCPFlowCopierControl.Reader = { completionHandler in
self.connection.receive(minimumIncompleteLength: 1, maximumLength: 2048) { (dataQ, _, isComplete, errorQ) in
switch (dataQ, isComplete, errorQ) {
case (_, true, _): completionHandler(.success(Data()))
case (let data?, _, _): completionHandler(.success(data))
case (_, _, let error?):
NSLog("TCP attempt 1: \(self.connection.currentPath?.localEndpoint) \(self.connection.endpoint)")
completionHandler(.failure(error))
default: assert(false) // No data, no EOF, and no error. Wha?
}
}
}
let writer: TCPFlowCopierControl.Writer = { data, completionHandler in
self.flow.write(for: self, data: data) { errorQ in
self.queue.async {
switch errorQ {
case nil: completionHandler(.success(()))
case let error?:
NSLog("TCP attempt 2: \(self.connection.currentPath?.localEndpoint)")
completionHandler(.failure(error))
}
}
}
}
return TCPFlowCopierControl(reader: reader, writer: writer, done: self.copierDone(errorQ:))
}
In "TCP attempt 1" log I can see that self.connection.currentPath?.localEndpoint is nil, even though it wasn't at the time .ready state was hit. Safari itself shows "No connection" messages. This issue happens only in safari, chrome and firefox work fine. I'm also not experiencing the issue if I use NEAppProxyProvider instead of NETransparentProxyProvider, but I need to use NETransparentProxyProvider because it doesn't drop excluded sockets. Do you have any idea why this would happen?