mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-04-24 00:00:05 +08:00
Reset tunnel depending on tunPersist settings
This commit is contained in:
@@ -48,7 +48,8 @@
|
|||||||
#pragma mark - OpenVPNClient Lifecycle
|
#pragma mark - OpenVPNClient Lifecycle
|
||||||
|
|
||||||
- (OpenVPNProperties *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * __autoreleasing *)error {
|
- (OpenVPNProperties *)applyConfiguration:(OpenVPNConfiguration *)configuration error:(NSError * __autoreleasing *)error {
|
||||||
ClientAPI::EvalConfig eval = self.vpnClient->eval_config(configuration.config);
|
ClientAPI::Config *config = new ClientAPI::Config(configuration.config);
|
||||||
|
ClientAPI::EvalConfig eval = self.vpnClient->apply_config(config);
|
||||||
|
|
||||||
if (eval.error) {
|
if (eval.error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -398,7 +399,9 @@
|
|||||||
_sessionName = nil;
|
_sessionName = nil;
|
||||||
_packetFlowBridge = nil;
|
_packetFlowBridge = nil;
|
||||||
_networkSettingsBuilder = nil;
|
_networkSettingsBuilder = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)resetTun {
|
||||||
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
||||||
|
|
||||||
void (^completionHandler)(id<OpenVPNAdapterPacketFlow> _Nullable) = ^(id<OpenVPNAdapterPacketFlow> flow) {
|
void (^completionHandler)(id<OpenVPNAdapterPacketFlow> _Nullable) = ^(id<OpenVPNAdapterPacketFlow> flow) {
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
- (void)tick;
|
- (void)tick;
|
||||||
|
|
||||||
- (void)resetSettings;
|
- (void)resetSettings;
|
||||||
|
- (void)resetTun;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
@@ -60,6 +61,9 @@ using namespace openvpn;
|
|||||||
class OpenVPNClient : public ClientAPI::OpenVPNClient {
|
class OpenVPNClient : public ClientAPI::OpenVPNClient {
|
||||||
public:
|
public:
|
||||||
OpenVPNClient(id<OpenVPNClientDelegate> _Nonnull delegate);
|
OpenVPNClient(id<OpenVPNClientDelegate> _Nonnull delegate);
|
||||||
|
~OpenVPNClient();
|
||||||
|
|
||||||
|
ClientAPI::EvalConfig apply_config(ClientAPI::Config* _Nonnull config);
|
||||||
|
|
||||||
bool tun_builder_new() override;
|
bool tun_builder_new() override;
|
||||||
|
|
||||||
@@ -99,6 +103,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
__weak id<OpenVPNClientDelegate> _Nonnull delegate;
|
__weak id<OpenVPNClientDelegate> _Nonnull delegate;
|
||||||
|
ClientAPI::Config * _Nullable config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,24 @@ using ::IPv4::Addr;
|
|||||||
|
|
||||||
OpenVPNClient::OpenVPNClient(id<OpenVPNClientDelegate> delegate): ClientAPI::OpenVPNClient() {
|
OpenVPNClient::OpenVPNClient(id<OpenVPNClientDelegate> delegate): ClientAPI::OpenVPNClient() {
|
||||||
this->delegate = delegate;
|
this->delegate = delegate;
|
||||||
|
this->config = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
OpenVPNClient::~OpenVPNClient() {
|
||||||
|
if (this->config != nullptr) { delete this->config; }
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientAPI::EvalConfig OpenVPNClient::apply_config(ClientAPI::Config* _Nonnull config) {
|
||||||
|
if (this->config != nullptr) { delete this->config; }
|
||||||
|
this->config = config;
|
||||||
|
|
||||||
|
return eval_config(*config);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenVPNClient::tun_builder_new() {
|
bool OpenVPNClient::tun_builder_new() {
|
||||||
[this->delegate resetSettings];
|
[this->delegate resetSettings];
|
||||||
|
[this->delegate resetTun];
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,11 +148,15 @@ int OpenVPNClient::tun_builder_establish() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OpenVPNClient::tun_builder_persist() {
|
bool OpenVPNClient::tun_builder_persist() {
|
||||||
return true;
|
return config->tunPersist;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenVPNClient::tun_builder_teardown(bool disconnect) {
|
void OpenVPNClient::tun_builder_teardown(bool disconnect) {
|
||||||
[this->delegate resetSettings];
|
[this->delegate resetSettings];
|
||||||
|
|
||||||
|
if (disconnect || !this->tun_builder_persist()) {
|
||||||
|
[this->delegate resetTun];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OpenVPNClient::socket_protect(int socket, std::string remote, bool ipv6) {
|
bool OpenVPNClient::socket_protect(int socket, std::string remote, bool ipv6) {
|
||||||
|
|||||||
Reference in New Issue
Block a user