ss-abramchuk / OpenVPNAdapter

Objective-C wrapper for OpenVPN library. Compatible with iOS and macOS.
GNU Affero General Public License v3.0
468 stars 205 forks source link

How can we implement Split Tunnel ? #153

Open nirwanrajat opened 4 years ago

nirwanrajat commented 4 years ago

Hi,

Thanks for providing a wonderful library and for your support.

Can you please tell, how can we implement Split Tunnel using this library?

ss-abramchuk commented 4 years ago

Hi @nirwanrajat,

I've never done split tunneling myself but I would recommend to take a look at routes configuration. NEPacketTunnelNetworkSettings has ipv4Settings and ipv6Settings properties. Both of them have two arrays includedRoutes and excludedRoutes. routingMethod property that belongs to the NEPacketTunnelProvider also maybe useful.

nirwanrajat commented 4 years ago

Hi @ss-abramchuk

Thanks for your response. As i look in code "routes configuration" is done inside the library. All the properties of NEPacketTunnelNetworkSettings is also set in library. So i think i have to made some changes in library routes configuration code.

Please suggest.

ss-abramchuk commented 4 years ago

Actually, you don't need to change anything in the library. You can override NEPacketTunnelNetworkSettings in one of the delegate methods. This one to be precise -> openVPNAdapter(openVPNAdapter:configureTunnelWithNetworkSettings:completionHandler:)

basheerpaliyathu commented 4 years ago
func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {

        // In order to direct all DNS queries first to the VPN DNS servers before the primary DNS servers
        // send empty string to NEDNSSettings.matchDomains
        networkSettings?.dnsSettings?.matchDomains = [""]

        networkSettings?.ipv4Settings?.excludedRoutes = [NEIPv4Route(destinationAddress: "xxx.xx.xxx.xx", subnetMask: "255.255.255.0")]
        // Specify the network settings for the current tunneling session.
        setTunnelNetworkSettings(networkSettings) { (error) in
            completionHandler(error == nil ? self.packetFlow : nil)
        }
    }

this is working code snippet

nirwanrajat commented 4 years ago

@ss-abramchuk using this library can we implement active/in-active VPN while VPN is connected or we have only option i.e, disconnect the VPN ?

nirwanrajat commented 4 years ago

Hi @basheerpaliyathu

Thanks for your response.....i have implemented this. Can you please confirm one thing can we pass domain name in destination address. Suppose we have to exclude youtube traffic so how we exclude that or there is any way to getting youtube destination address?

NasrullahKhan commented 3 years ago

@nirwanrajat did you achieve split tunneling for applications, for example i am using vpn on my macos app and i want skype to not use by pass vpn.

nirwanrajat commented 3 years ago

@NasrullahKhan no i am not able to achieve. I think split tunneling can not be do.

ChadiGSfeir commented 3 years ago

Hi guys, is there a way to pass a list of apps that only can use the vpn connection? example: I only need "WhatsApp, viber, others apps" to use the vpn other apps will bypass the vpn connection. Thank you in advance.

xbladesub commented 2 years ago

Did anyone figure out how to bypass VPN on specific apps?=) It's strange, that there is no any useful info/example how to do it...