diff --git a/OpenVPN Adapter/OpenVPNConfiguration.h b/OpenVPN Adapter/OpenVPNConfiguration.h index 07acf6d..6f2fe17 100644 --- a/OpenVPN Adapter/OpenVPNConfiguration.h +++ b/OpenVPN Adapter/OpenVPNConfiguration.h @@ -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 diff --git a/OpenVPN Adapter/OpenVPNConfiguration.mm b/OpenVPN Adapter/OpenVPNConfiguration.mm index 892bdf1..188b65f 100644 --- a/OpenVPN Adapter/OpenVPNConfiguration.mm +++ b/OpenVPN Adapter/OpenVPNConfiguration.mm @@ -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