Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Swift3: Extension died unexpectedly #31

Closed
txthinking opened this issue Dec 4, 2016 · 2 comments
Closed

Swift3: Extension died unexpectedly #31

txthinking opened this issue Dec 4, 2016 · 2 comments

Comments

@txthinking
Copy link

env

  • swift: 3.0.1
  • xcode: 8.1
  • ios with network extension

First, let me make sure my app and config is correct

In startTunne methodl:

        let ipv4Settings = NEIPv4Settings(addresses: ["10.0.0.1"], subnetMasks: ["255.255.255.0"])
        let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "8.8.8.8")
        networkSettings.mtu = 1500
        networkSettings.iPv4Settings = ipv4Settings
        setTunnelNetworkSettings(networkSettings) {
            error in
            guard error == nil else {
                NSLog(error.debugDescription)
                completionHandler(error)
                return
            }
            completionHandler(nil)
        }

then start vpn, whatever the app is in the foreground or the background, the VPN is running correct. Network traffic is normal too.

Now, let me use NEKit

In startTunne method:

        let directAdapterFactory = DirectAdapterFactory()
        let allRule = AllRule(adapterFactory: directAdapterFactory)
        RuleManager.currentManager = RuleManager(fromRules: [allRule], appendDirect: true)
        RawSocketFactory.TunnelProvider = self
        self.proxyServer = GCDHTTPProxyServer(address: IPv4Address(fromString: "127.0.0.1"), port: Port(port: UInt16(self.proxyPort)))
        try! self.proxyServer.start()
        
        let networkSettings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "8.8.8.8")
        networkSettings.mtu = 1500
        
        let ipv4Settings = NEIPv4Settings(addresses: ["192.169.89.1"], subnetMasks: ["255.255.255.0"])
        ipv4Settings.includedRoutes = [NetworkExtension.NEIPv4Route.default()]
        networkSettings.iPv4Settings = ipv4Settings
        
        let proxySettings = NEProxySettings()
        proxySettings.httpEnabled = true
        proxySettings.httpServer = NEProxyServer(address: "127.0.0.1", port: proxyPort)
        proxySettings.httpsEnabled = true
        proxySettings.httpsServer = NEProxyServer(address: "127.0.0.1", port: proxyPort)
        proxySettings.excludeSimpleHostnames = true
        networkSettings.proxySettings = proxySettings
        
        let DNSSettings = NEDNSSettings(servers: ["198.18.0.1"])
        DNSSettings.matchDomains = [""]
        DNSSettings.matchDomainsNoSearch = false
        networkSettings.dnsSettings = DNSSettings
        
        setTunnelNetworkSettings(networkSettings) {
            error in
            guard error == nil else {
                DDLogError("Encountered an error setting up the network: \(error)")
                completionHandler(error)
                return
            }
            self.interface = TUNInterface(packetFlow: self.packetFlow)
            let fakeIPPool = IPv4Pool(start: IPv4Address(fromString: "198.18.1.1")!, end: IPv4Address(fromString: "198.18.255.255")!)
            let dnsServer = DNSServer(address: IPv4Address(fromString: "198.18.0.1")!, port: Port(port: 53), fakeIPPool: fakeIPPool)
            let resolver = UDPDNSResolver(address: IPv4Address(fromString: "114.114.114.114")!, port: Port(port: 53))
            dnsServer.registerResolver(resolver)
            self.interface.registerStack(dnsServer)
            DNSServer.currentServer = dnsServer
            let udpStack = UDPDirectStack()
            self.interface.registerStack(udpStack)
            let tcpStack = TCPStack.stack
            tcpStack.proxyServer = self.proxyServer
            self.interface.registerStack(tcpStack)
            self.interface.start()
            completionHandler(nil)
        }

then start vpn, the vpn can be started, but i found when network traffic was generated, the Network Extension died unexpectedly.

This article also mentioned this problem.

Thanks for your NEKit.

@zhuhaow
Copy link
Owner

zhuhaow commented Dec 4, 2016 via email

@txthinking
Copy link
Author

Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants