shill: Connection: If IP Address changes, flush everything

If a new IP configuration arrives which changes the address
assigned to the family of this IPConfig, flush addresses
and routes before applying the new configuration.  Otherwise,
we end up adding the new address inclusively as a secondary
IP address and userspace programs continue to use the old
address.

BUG=chromium-os:33066
TEST=New unit tests.  Manual: Change DHCP server configuration,
unplug and replug to the same network.  The old DHCP configuration
is loaded (since the lease is still valid and the gateway is
reachable) but when the new DHCP information arrives, ensure that
the new IP address (and only that address) is configured, and the
routes are sane (i.e., both LAN interface route and default route
exist).

Change-Id: Ic746368d97c503271995ff30b6818d770f4340c5
Reviewed-on: https://gerrit.chromium.org/gerrit/29170
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/connection.cc b/connection.cc
index f3a2e6d..d258dd7 100644
--- a/connection.cc
+++ b/connection.cc
@@ -146,6 +146,14 @@
     LOG(WARNING) << "Expect limited network connectivity.";
   }
 
+  if (device_info_->HasOtherAddress(interface_index_, local)) {
+    // The address has changed for this interface.  We need to flush
+    // everything and start over.
+    LOG(INFO) << __func__ << ": Flushing old addresses and routes.";
+    routing_table_->FlushRoutes(interface_index_);
+    device_info_->FlushAddresses(interface_index_);
+  }
+
   LOG(INFO) << __func__ << ": Installing with parameters:"
             << " local=" << local.ToString()
             << " broadcast=" << broadcast.ToString()