Thank you @eskimo and @meaton!! It seems like my tunnel is started and I can see the IPv4Settings in System Settings > Network > VPN & Filters.
I am curious as to where I can see the log that gets output from the network extension. I have tried using os_log.Logger, NSLog, and print statements, but when I checked the Console app on my MacOS, I don't see the entries. Right now the entry is just to tell me the startTunnel method has been entered, but eventually I want to use it to see that I can capture packets and read the packets before they go on their merry way. I've also tried writing out to a temp file instead of the log, but I also couldn't find the file after running the app. Please see my code snippet of the startTunnel method below:
let logger = Logger(subsystem: "com.yourcompany.yourapp", category: "NetworkExtension")
logger.info("Inside startTunnel method")
NSLog("Inside startTunnel method")
print("Inside startTunnel method")
// Add code here to start the process of connecting the tunnel.
let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "127.0.0.1") // the dest endpoint for tunnel traffic
let ipv4Settings = NEIPv4Settings(addresses: ["1.2.3.4"], subnetMasks: ["255.255.255.255"])
let includedRoute = NEIPv4Route(destinationAddress: "0.0.0.0", subnetMask: "0.0.0.0") // all routes should go through the tunnel
ipv4Settings.includedRoutes = [includedRoute]
networkSettings.ipv4Settings = ipv4Settings
setTunnelNetworkSettings(networkSettings) { error in
if let error = error {
NSLog("Error occurred in setTunnelNetworkSettings: \(error.localizedDescription)")
} else {
NSLog("setTunnelNetworkSettings complete")
completionHandler(nil)
}
}
completionHandler(nil) // notify the system that the tunnel is ready
Please advise.