I am implementing a NetworkExtension, based on NEFilterPacketProvider. My issue is that the NEFilterPacketContext is always empty. I assume that's not expected, but my code is as simple as it gets. What's the issue?
Maybe loking at attributeKeys is the wrong thing to do, but in that case, how to access context info? Specifically, I'd like to know things like which applications generated the packet, on which port, what external IP, etc.
class FilterPacketProvider: NEFilterPacketProvider {
override init() {
super.init()
os_log("FilterPacketProvider init")
}
override func startFilter(completionHandler: @escaping (Error?) -> Void) {
os_log("FilterPacketProvider startFilter")
packetHandler = { (context:NEFilterPacketContext,
interface:nw_interface_t,
direction:NETrafficDirection,
packetBytes:UnsafeRawPointer,
packetLength:Int)
in
os_log("FilterPacketProvider packet context=%{public}s %{public}s interface=%{public}s dir=%d length=%d",
context.attributeKeys.description,
context.debugDescription,
interface.description,
direction.rawValue,
packetLength
)
return .allow //.allow, .drop or .delay
}
completionHandler(nil)
}
override func stopFilter(with reason: NEProviderStopReason, completionHandler: @escaping () -> Void) {
os_log("FilterPacketProvider stopFilter")
completionHandler()
}
}