mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 20:13:05 +02:00
Core change: provide logic for tunPerist that works with iOS-style
tun semantics, however this code has not been enabled yet on iOS because it breaks in several ways: 1. network available/unavailable detection appears to break when tun interface is kept alive across transport connection sessions. 2. plugin session persistence appears to fail when these lines are not executed immediately after transport pause/resume: VPNTunnelSetStatus(tunnelRef, kVPNTunnelStatusReasserting, 0); VPNTunnelClearConfiguration(tunnelRef) iOS Core change: change pause/reconnect delay to 3 seconds (from 2) to reduce flapping.
This commit is contained in:
parent
7e03ddff3e
commit
be3a573f66
@ -222,13 +222,12 @@ namespace openvpn {
|
||||
#if defined(OPENVPN_PLATFORM_IPHONE)
|
||||
tunconf->retain_sd = true;
|
||||
tunconf->tun_prefix = true;
|
||||
#else
|
||||
#endif
|
||||
if (config.tun_persist)
|
||||
{
|
||||
tun_persist.reset(new TunBuilderClient::TunPersist);
|
||||
tun_persist.reset(new TunBuilderClient::TunPersist(tunconf->retain_sd, config.builder));
|
||||
tunconf->tun_persist = tun_persist;
|
||||
}
|
||||
#endif
|
||||
#elif defined(OPENVPN_PLATFORM_LINUX) && !defined(OPENVPN_FORCE_TUN_NULL)
|
||||
TunLinux::ClientConfig::Ptr tunconf = TunLinux::ClientConfig::new_obj();
|
||||
tunconf->layer = cp->layer;
|
||||
|
@ -28,6 +28,7 @@ namespace openvpn {
|
||||
{
|
||||
const int ret = fd;
|
||||
fd = -1;
|
||||
//OPENVPN_LOG("**** SFD RELEASE=" << ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -45,6 +46,14 @@ namespace openvpn {
|
||||
{
|
||||
close();
|
||||
fd = fd_arg;
|
||||
//OPENVPN_LOG("**** SFD RESET=" << fd);
|
||||
}
|
||||
|
||||
// unusual semantics: replace fd without closing it first
|
||||
void replace(const int fd_arg)
|
||||
{
|
||||
//OPENVPN_LOG("**** SFD REPLACE " << fd << " -> " << fd_arg);
|
||||
fd = fd_arg;
|
||||
}
|
||||
|
||||
int close()
|
||||
@ -53,6 +62,7 @@ namespace openvpn {
|
||||
{
|
||||
const int ret = ::close(fd);
|
||||
fd = -1;
|
||||
//OPENVPN_LOG("**** SFD CLOSE=" << ret);
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
|
@ -79,7 +79,8 @@ namespace openvpn {
|
||||
public:
|
||||
typedef boost::intrusive_ptr<TunPersist> Ptr;
|
||||
|
||||
TunPersist() {}
|
||||
TunPersist(const bool retain_sd, TunBuilderBase* tb)
|
||||
: retain_sd_(retain_sd), tb_(tb) {}
|
||||
|
||||
bool defined() const
|
||||
{
|
||||
@ -93,7 +94,10 @@ namespace openvpn {
|
||||
|
||||
void persist(const int sd, const ClientState::Ptr& state, const std::string& options)
|
||||
{
|
||||
sd_.reset(sd);
|
||||
if (retain_sd_)
|
||||
sd_.replace(sd);
|
||||
else
|
||||
sd_.reset(sd);
|
||||
state_ = state;
|
||||
options_ = options;
|
||||
}
|
||||
@ -108,9 +112,19 @@ namespace openvpn {
|
||||
return state_;
|
||||
}
|
||||
|
||||
~TunPersist()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void close()
|
||||
{
|
||||
sd_.close();
|
||||
if (tb_)
|
||||
tb_->tun_builder_teardown();
|
||||
if (retain_sd_)
|
||||
sd_.release();
|
||||
else
|
||||
sd_.close();
|
||||
state_.reset();
|
||||
options_ = "";
|
||||
}
|
||||
@ -121,6 +135,8 @@ namespace openvpn {
|
||||
}
|
||||
|
||||
private:
|
||||
bool retain_sd_;
|
||||
TunBuilderBase* tb_;
|
||||
ScopedFD sd_;
|
||||
ClientState::Ptr state_;
|
||||
std::string options_;
|
||||
@ -334,7 +350,9 @@ namespace openvpn {
|
||||
// stop tun
|
||||
if (impl)
|
||||
{
|
||||
tb->tun_builder_teardown();
|
||||
// if tun_persist is defined, it owns the sd and takes responsibility for teardown
|
||||
if (!config->tun_persist)
|
||||
tb->tun_builder_teardown();
|
||||
impl->stop();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user