OpenVPN / openvpn3

OpenVPN 3 is a C++ class library that implements the functionality of an OpenVPN client, and is protocol-compatible with the OpenVPN 2.x branch.
https://openvpn.net
Other
1k stars 401 forks source link

When openvpn signnal "CONNECTED" event, it did not already connecetd , and tun deivice is not created in 4-5seconds #82

Open wsktree opened 5 years ago

wsktree commented 5 years ago

Now, I am creating a openvpn client using the API on win platform. I need to do something when I get the sinal of "CONENECTED" which means the vpn network is ok.

The issue is now, when I receiver the ”CONNECTED” event, the tun network device did not created finished, it takes 4-5 seoncds after get "CONNECED" event ,then the tun decice create and network is ok.

Could you help me if there any event or how can I know the network is ready ? Can you help to fix the issue after the "CONNECTED" event signaled, it takes 4-5 seconds to finish create the tun device ? The related of the code to signal the "CONNECTED " event is bellow: ==== in tuncli.hpp virtual void tun_start(const OptionList& opt, TransportClient& transcli, CryptoDCSetting&) overide { ................... if(!dhcp_capture) parent.tun_connected(); //signal that we are connected }

=== thanks very much! BR, wsktree

schwabe commented 5 years ago

You did you determine that CONNECTED is after the tun is created and opened? This might be something in the OS that is outside our control.

wsktree commented 5 years ago

Is there any API we can use to know the tun is created and opened ?

schwabe commented 5 years ago

Let me rephrase what I have written. CONNECTED is normally after tun is opened. How did you determine that this is not case?

wsktree commented 5 years ago

Hi schwabe,

I have a callback function when receiver the “CONNECTED“ EVENT。 In this callback function, I will use the VPN network, but in the 4-5seonds, it will always failed due to network error.

Then I run a script "ipconfig" to check the tun device when recevier the "CONNECTED" event. The result is the same: 1> script result shows the tun dev is not created in the 4-5 seconds 2> the callback is error dur to network issue So, i can confirm the 4-5seconds after the "CONNECTED" message, the tun created finish.

thanks! BR, wesktree

AnthonyWharton commented 5 years ago

Are you using the generic TunBuilderBase methods or one of the OS specific models for creating a tunnel?

In the former case it is up to you to return when the tunnel is created, so you control when OpenVPN will continue the connection process as it will block until you return from that function.

I do not have experience with the latter OS specific model cases, however I would be surprised if they return that the tunnel is set up before it actually is.

dsommers commented 5 years ago

Please share your implementation (point to a publicly available git repository or so), then it is easier to spot what's going on in your code.