VPN Tunnels issue

98 views Asked by At

I have been working on a vpn app that requires two tunnels to be made. I create vpn tunnel and connect it with a particular server then i disconnect tunnel and made vpn tunnel for another feature that require vpn tunnel. This operation works fine but sometimes or randomly it activate the wrong configuration tunnel. I had made sure to stop previous tunnel before creating and starting new tunnel. i have been using this

    /// code to stop tunnel session
   wg_log(.debug, message: "startDeactivation: Tunnel: \(name)")
   (tunnelProvider.connection as? NETunnelProviderSession)?.stopTunnel()

I tried it calling after load preference but still it sometimes shows that random error where tunnel wiht different configuation is chosen.

NEVPNManager.shared().loadFromPreferences { error in
  assert(error == nil, "Failed to load preferences: \(error!.localizedDescription)")
  self.tunnelProvider.connection.stopVPNTunnel()
 
}

I am new to network extensions and could not come up with better solution. I am using wireguard library for vpn connections. Is there any way to maintain two tunnels and on the basis of requirement use a particular tunnel or is there any way we could over-write previous configuration of vpn.

I tried to create two tunnels using wireguard library and based on requirements disconnect the one tunnel and connect the other tunnel. Few times i pick wrong tunnel get connected even though i pass connected the other tunnel. Before creating the second tunnel, i disconnected the other tunnel and when the first tunnel is again needs to be activated, i disconnect the second tunnel. This way i want to maintain the cycle but eventually i got wrong tunnel activated(not every time).

0

There are 0 answers