0
0
mirror of https://github.com/OpenVPN/openvpn3.git synced 2024-09-19 19:52:15 +02:00

Added disconnect bool to TunBuilderBase::tun_builder_teardown:

+    // Indicates that tunnel is being torn down.
+    // If disconnect == true, then the teardown is occurring
+    // prior to final disconnect.
+    virtual void tun_builder_teardown(bool disconnect) {}
This commit is contained in:
James Yonan 2014-08-24 23:09:16 -06:00
parent e957170893
commit 3be8d66d0b
9 changed files with 46 additions and 12 deletions

View File

@ -66,7 +66,7 @@ public class OpenVPNClientThread extends ClientAPI_OpenVPNClient implements Runn
boolean tun_builder_set_mtu(int mtu);
boolean tun_builder_set_session_name(String name);
int tun_builder_establish();
void tun_builder_teardown();
void tun_builder_teardown(boolean disconnect);
}
public OpenVPNClientThread() {
@ -337,9 +337,9 @@ public class OpenVPNClientThread extends ClientAPI_OpenVPNClient implements Runn
}
@Override
public void tun_builder_teardown() {
public void tun_builder_teardown(boolean disconnect) {
TunBuilder tb = tun_builder;
if (tb != null)
tb.tun_builder_teardown();
tb.tun_builder_teardown(disconnect);
}
}

View File

@ -129,7 +129,10 @@ namespace openvpn {
if (pre_resolve)
pre_resolve->cancel();
if (client)
client->stop(false);
{
client->tun_set_disconnect();
client->stop(false);
}
cancel_timers();
asio_work.reset();

View File

@ -185,6 +185,12 @@ namespace openvpn {
Base::send_explicit_exit_notify();
}
void tun_set_disconnect()
{
if (tun)
tun->set_disconnect();
}
void stop(const bool call_terminate_callback)
{
if (!halt)
@ -193,12 +199,12 @@ namespace openvpn {
housekeeping_timer.cancel();
push_request_timer.cancel();
inactive_timer.cancel();
if (tun)
tun->stop();
if (transport)
transport->stop();
if (notify_callback && call_terminate_callback)
notify_callback->client_proto_terminate();
if (tun)
tun->stop(); // call after client_proto_terminate() so it can call back to tun_set_disconnect
if (transport)
transport->stop();
}
}

View File

@ -191,8 +191,10 @@ namespace openvpn {
{
}
// Called just before tunnel socket is closed
virtual void tun_builder_teardown() {}
// Indicates that tunnel is being torn down.
// If disconnect == true, then the teardown is occurring
// prior to final disconnect.
virtual void tun_builder_teardown(bool disconnect) {}
virtual ~TunBuilderBase() {}
};

View File

@ -224,6 +224,12 @@ namespace openvpn {
return "";
}
virtual void set_disconnect()
{
if (tun_persist)
tun_persist->set_disconnect();
}
virtual void stop() { stop_(); }
virtual ~Client() { stop_(); }

View File

@ -42,6 +42,7 @@ namespace openvpn {
virtual void client_start(const OptionList&, TransportClient&) = 0;
virtual void stop() = 0;
virtual void set_disconnect() = 0;
virtual bool tun_send(BufferAllocated& buf) = 0; // return true if send succeeded
virtual std::string tun_name() const = 0;
virtual std::string vpn_ip4() const = 0;

View File

@ -643,6 +643,10 @@ namespace openvpn {
return "";
}
virtual void set_disconnect()
{
}
virtual void stop() { stop_(); }
virtual ~Client() { stop_(); }

View File

@ -40,7 +40,8 @@ namespace openvpn {
: TunWrapTemplate<SCOPED_OBJ>(retain_obj),
enable_persistence_(enable_persistence),
tb_(tb),
use_persisted_tun_(false)
use_persisted_tun_(false),
disconnect(false)
{
}
@ -61,6 +62,11 @@ namespace openvpn {
TunWrapTemplate<SCOPED_OBJ>::close();
}
void set_disconnect()
{
disconnect = true;
}
// Current persisted options
const std::string& options()
{
@ -131,7 +137,7 @@ namespace openvpn {
void close_local()
{
if (tb_)
tb_->tun_builder_teardown();
tb_->tun_builder_teardown(disconnect);
state_.reset();
options_ = "";
}
@ -143,6 +149,8 @@ namespace openvpn {
TunBuilderCapture::Ptr copt_;
bool use_persisted_tun_;
bool disconnect;
};
}

View File

@ -253,6 +253,10 @@ namespace openvpn {
return "";
}
virtual void set_disconnect()
{
}
virtual void stop() { stop_(); }
virtual ~Client() { stop_(); }