Shut down on server "RESTART" control message

Fixes #131
This commit is contained in:
Davide De Rosa 2020-02-29 19:17:36 +01:00
parent f6d915e6dd
commit 311015950e
4 changed files with 23 additions and 5 deletions

View File

@ -142,6 +142,9 @@ extension OpenVPNTunnelProvider {
/// Default gateway could not be attained.
case gatewayUnattainable
/// Remove server has shut down.
case serverShutdown
/// The server replied in an unexpected way.
case unexpectedReply
}

View File

@ -876,6 +876,9 @@ extension OpenVPNTunnelProvider {
case .noRouting:
return .routing
case .serverShutdown:
return .serverShutdown
default:
return .unexpectedReply

View File

@ -77,4 +77,7 @@ public enum OpenVPNError: String, Error {
/// Missing routing information.
case noRouting
/// Remote server shut down (--explicit-exit-notify).
case serverShutdown
}

View File

@ -907,6 +907,11 @@ public class OpenVPNSession: Session {
// Ruby: handle_ctrl_msg
private func handleControlMessage(_ message: String) {
if CoreConfiguration.logsSensitiveData {
log.debug("Received control message: \"\(message)\"")
}
// disconnect on authentication failure
guard !message.hasPrefix("AUTH_FAILED") else {
// XXX: retry without client options
@ -921,14 +926,18 @@ public class OpenVPNSession: Session {
return
}
guard (negotiationKey.controlState == .preIfConfig) else {
// disconnect on remote server restart (--explicit-exit-notify)
guard !message.hasPrefix("RESTART") else {
log.debug("Disconnecting due to server shutdown")
deferStop(.shutdown, OpenVPNError.serverShutdown)
return
}
// handle authentication from now on
guard negotiationKey.controlState == .preIfConfig else {
return
}
if CoreConfiguration.logsSensitiveData {
log.debug("Received control message: \"\(message)\"")
}
let completeMessage: String
if let continuated = continuatedPushReplyMessage {
completeMessage = "\(continuated),\(message)"