Handle --keepalive option

This commit is contained in:
Davide De Rosa 2022-01-04 09:14:39 +01:00
parent decc82fb9f
commit 430e0e6afb
3 changed files with 21 additions and 0 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- WireGuard support. [#236](https://github.com/passepartoutvpn/tunnelkit/pull/236) - WireGuard support. [#236](https://github.com/passepartoutvpn/tunnelkit/pull/236)
- Handle `--keepalive` option.
## 4.0.3 (2021-11-27) ## 4.0.3 (2021-11-27)

View File

@ -60,6 +60,8 @@ extension OpenVPN {
static let pingRestart = NSRegularExpression("^ping-restart +\\d+") static let pingRestart = NSRegularExpression("^ping-restart +\\d+")
static let keepAlive = NSRegularExpression("^keepalive +\\d+ ++\\d+")
static let renegSec = NSRegularExpression("^reneg-sec +\\d+") static let renegSec = NSRegularExpression("^reneg-sec +\\d+")
static let xorMask = NSRegularExpression("^scramble +xormask +.$") static let xorMask = NSRegularExpression("^scramble +xormask +.$")
@ -457,6 +459,14 @@ extension OpenVPN {
} }
optKeepAliveTimeoutSeconds = TimeInterval(arg) optKeepAliveTimeoutSeconds = TimeInterval(arg)
} }
Regex.keepAlive.enumerateArguments(in: line) {
isHandled = true
guard let ping = $0.first, let pingRestart = $0.last else {
return
}
optKeepAliveSeconds = TimeInterval(ping)
optKeepAliveTimeoutSeconds = TimeInterval(pingRestart)
}
Regex.renegSec.enumerateArguments(in: line) { Regex.renegSec.enumerateArguments(in: line) {
isHandled = true isHandled = true
guard let arg = $0.first else { guard let arg = $0.first else {

View File

@ -50,6 +50,16 @@ class ConfigurationParserTests: XCTestCase {
XCTAssertNoThrow(try OpenVPN.ConfigurationParser.parsed(fromLines: ["compress lzo"])) XCTAssertNoThrow(try OpenVPN.ConfigurationParser.parsed(fromLines: ["compress lzo"]))
} }
func testKeepAlive() throws {
let cfg1 = try OpenVPN.ConfigurationParser.parsed(fromLines: ["ping 10", "ping-restart 60"])
let cfg2 = try OpenVPN.ConfigurationParser.parsed(fromLines: ["keepalive 10 60"])
let cfg3 = try OpenVPN.ConfigurationParser.parsed(fromLines: ["keepalive 15 600"])
XCTAssertEqual(cfg1.configuration.keepAliveInterval, cfg2.configuration.keepAliveInterval)
XCTAssertEqual(cfg1.configuration.keepAliveTimeout, cfg2.configuration.keepAliveTimeout)
XCTAssertNotEqual(cfg1.configuration.keepAliveInterval, cfg3.configuration.keepAliveInterval)
XCTAssertNotEqual(cfg1.configuration.keepAliveTimeout, cfg3.configuration.keepAliveTimeout)
}
func testDHCPOption() throws { func testDHCPOption() throws {
let lines = [ let lines = [
"dhcp-option DNS 8.8.8.8", "dhcp-option DNS 8.8.8.8",