ss-abramchuk / OpenVPNAdapter

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

The network fails after switching the WWAN to WiFi #171

Closed guhan121 closed 4 years ago

guhan121 commented 4 years ago

because after user connect the wifi,The VPN is still in use 4g, i set tunPersist = false add some code .

[self.openVpnReach startTrackingWithCallback:^(OpenVPNReachabilityStatus status) {
        NSLog(@"[VPN]:OpenVPNReachabilityStatus: %ld", (long) status);
        if (status == OpenVPNReachabilityStatusNotReachable) {
            [self.vpnAdapter reconnectAfterTimeInterval:5];
        } else if (self.lastStatus == OpenVPNReachabilityStatusReachableViaWWAN && status == OpenVPNReachabilityStatusReachableViaWiFi) {
            NSLog(@"[VPN]:reconnect vpn after 4 second.");
            [self.vpnAdapter reconnectAfterTimeInterval:4];
        }
    }];

Although a reconnection did occur and the service server was able to see a successful connection, it appeared that the network was not connected and could not access the network properly.

It looks like the tun was not connected to the correct net interface.

@ss-abramchuk can you help me.

guhan121 commented 4 years ago

@ss-abramchuk add log when i change wifi to 4g

image

it call restart,and network work fine.

ss-abramchuk commented 4 years ago

Hi @guhan121,

Indeed, I can confirm there is such problem. Looks like it appeared not so long ago as previously the workaround with reachability worked fine for me. Initially, I thought there is something wrong with tunnel and routes but I compared routes configuration when connection works and when it doesn't and I haven't found anything suspicious. Moreover, configuration process is almost the same, no matter if you connects to VPN server first time or after loosing connection or switching network interface. So it shouldn't affect connection somehow.

Alas, but I don't have a solution right now, need to investigate why it happens

ss-abramchuk commented 4 years ago

Hi @guhan121,

Could you try feature/reconnection-issue branch and let me know if it works for you? BTW, I slightly changed API so your have to update you code as well.

guhan121 commented 4 years ago

we test it in many phone,it work fine. thanks! When do you merge it.