shill: openvpn: Allow automatic reconnect when underlying connection reconnects.
When the underlying connection drops, restart the openvpn client, thus
resetting the connection and initiating a reconnect attempt. The
reconnect will be held until a new carrier connection is established,
up to the connect timeout of one minute.
Also, explicitly process SUCCESS management API messages so that
they're not logged as WARNINGs.
BUG=chromium-os:32416
TEST=unit tests; while connected to corp OpenVPN, switch between APs
and observe VPN reconnects; while connected to corp OpenVPN,
disconnect or disable WiFi, reconnect or re-enable it in a couple of
seconds and observe VPN reconnects.
Change-Id: I672db885d589fa020419d0badb480aee9bcc851a
Reviewed-on: https://gerrit.chromium.org/gerrit/42616
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Commit-Queue: Darin Petkov <petkov@chromium.org>
diff --git a/openvpn_driver_unittest.cc b/openvpn_driver_unittest.cc
index 8ad04c1..7a049d1 100644
--- a/openvpn_driver_unittest.cc
+++ b/openvpn_driver_unittest.cc
@@ -122,6 +122,34 @@
return &driver_->sockets_;
}
+ void SetDevice(const VPNRefPtr &device) {
+ driver_->device_ = device;
+ }
+
+ void SetService(const VPNServiceRefPtr &service) {
+ driver_->service_ = service;
+ }
+
+ VPNServiceRefPtr GetService() {
+ return driver_->service_;
+ }
+
+ void OnConnectionDisconnected() {
+ driver_->OnConnectionDisconnected();
+ }
+
+ void OnConnectTimeout() {
+ driver_->OnConnectTimeout();
+ }
+
+ void StartConnectTimeout() {
+ driver_->StartConnectTimeout();
+ }
+
+ bool IsConnectTimeoutStarted() {
+ return driver_->IsConnectTimeoutStarted();
+ }
+
// Used to assert that a flag appears in the options.
void ExpectInFlags(const vector<string> &options, const string &flag,
const string &value);
@@ -857,10 +885,22 @@
}
TEST_F(OpenVPNDriverTest, OnConnectionDisconnected) {
- driver_->service_ = service_;
+ EXPECT_CALL(*management_server_, Restart());
+ SetDevice(device_);
+ SetService(service_);
+ EXPECT_CALL(*device_, OnDisconnected());
+ EXPECT_CALL(*service_, SetState(Service::kStateAssociating));
+ OnConnectionDisconnected();
+ EXPECT_TRUE(IsConnectTimeoutStarted());
+}
+
+TEST_F(OpenVPNDriverTest, OnConnectTimeout) {
+ StartConnectTimeout();
+ SetService(service_);
EXPECT_CALL(*service_, SetState(Service::kStateFailure));
- driver_->OnConnectionDisconnected();
- EXPECT_FALSE(driver_->service_);
+ OnConnectTimeout();
+ EXPECT_FALSE(GetService());
+ EXPECT_FALSE(IsConnectTimeoutStarted());
}
TEST_F(OpenVPNDriverTest, OnReconnecting) {