mirror of
https://github.com/deneraraujo/OpenVPNAdapter.git
synced 2026-02-11 00:00:08 +08:00
Wrap IPv6 preference
This commit is contained in:
@@ -10,6 +10,19 @@
|
||||
|
||||
// TODO: Wrap ClientAPI::Config into Objective-C class
|
||||
|
||||
/**
|
||||
IPv6 preference options
|
||||
|
||||
- IPv6PreferenceEnabled: request combined IPv4/IPv6 tunnel
|
||||
- IPv6PreferenceDisabled: disable IPv6, so tunnel will be IPv4-only
|
||||
- IPv6PreferenceDefault: leave decision to server
|
||||
*/
|
||||
typedef NS_ENUM(NSInteger, IPv6Preference) {
|
||||
IPv6PreferenceEnabled,
|
||||
IPv6PreferenceDisabled,
|
||||
IPv6PreferenceDefault
|
||||
};
|
||||
|
||||
@interface OpenVPNConfiguration : NSObject
|
||||
|
||||
/**
|
||||
@@ -42,4 +55,9 @@
|
||||
*/
|
||||
@property (nullable, nonatomic) NSString *protoOverride;
|
||||
|
||||
/**
|
||||
IPv6 preference
|
||||
*/
|
||||
@property (nonatomic) IPv6Preference ipv6;
|
||||
|
||||
@end
|
||||
|
||||
@@ -89,4 +89,36 @@ using namespace openvpn;
|
||||
_config.protoOverride = protoOverride ? std::string([protoOverride UTF8String]) : "";
|
||||
}
|
||||
|
||||
- (IPv6Preference)ipv6 {
|
||||
NSDictionary *options = @{
|
||||
@"yes": @(IPv6PreferenceEnabled),
|
||||
@"no": @(IPv6PreferenceDisabled),
|
||||
@"default": @(IPv6PreferenceDefault),
|
||||
@"": @(IPv6PreferenceDefault)
|
||||
};
|
||||
|
||||
NSString *currentValue = [NSString stringWithUTF8String:_config.ipv6.c_str()];
|
||||
|
||||
NSNumber *preference = options[currentValue];
|
||||
NSAssert(preference != nil, @"Incorrect ipv6 value");
|
||||
|
||||
return (IPv6Preference)[preference integerValue];
|
||||
}
|
||||
|
||||
- (void)setIpv6:(IPv6Preference)ipv6 {
|
||||
switch (ipv6) {
|
||||
case IPv6PreferenceEnabled:
|
||||
_config.ipv6 = "yes";
|
||||
break;
|
||||
|
||||
case IPv6PreferenceDisabled:
|
||||
_config.ipv6 = "no";
|
||||
break;
|
||||
|
||||
case IPv6PreferenceDefault:
|
||||
_config.ipv6 = "default";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user