shill: Connection: If gateway is unreachable, assume point-to-point

If the gateway address is still unreachable from the local address
after trying route expansion, assume that the network is point-to-point,
and specify the gateway as a peer.

BUG=chromium-os:31313
TEST=Modified unit tests (needs manual real-life testing)

Change-Id: Id396f721d897d031e59b2f820ec2156b054b81b9
Reviewed-on: https://gerrit.chromium.org/gerrit/23802
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/connection.cc b/connection.cc
index ecd59b4..476216e 100644
--- a/connection.cc
+++ b/connection.cc
@@ -139,7 +139,7 @@
     return;
   }
 
-  if (!FixGatewayReachability(&local, gateway_address, peer)) {
+  if (!FixGatewayReachability(&local, &peer, gateway_address)) {
     LOG(WARNING) << "Expect limited network connectivity.";
   }
 
@@ -241,21 +241,21 @@
 
 // static
 bool Connection::FixGatewayReachability(IPAddress *local,
-                                        const IPAddress &gateway,
-                                        const IPAddress &peer) {
+                                        IPAddress *peer,
+                                        const IPAddress &gateway) {
   if (!gateway.IsValid()) {
     LOG(WARNING) << "No gateway address was provided for this connection.";
     return false;
   }
 
-  if (peer.IsValid()) {
-    if (gateway.Equals(peer)) {
+  if (peer->IsValid()) {
+    if (gateway.Equals(*peer)) {
       return true;
     }
     LOG(WARNING) << "Gateway address "
                  << gateway.ToString()
                  << " does not match peer address "
-                 << peer.ToString();
+                 << peer->ToString();
     return false;
   }
 
@@ -280,7 +280,10 @@
   if (prefix < local->GetMinPrefixLength()) {
     // Restore the original prefix since we cannot find a better one.
     local->set_prefix(original_prefix);
-    return false;
+    DCHECK(!peer->IsValid());
+    LOG(WARNING) << "Assuming point-to-point configuration.";
+    *peer = gateway;
+    return true;
   }
 
   LOG(WARNING) << "Mitigating this by setting local prefix to " << prefix;