shill: device_info: Revamp address/route flushing
The route flushing for devices ended up floating around in the device
code with a number of changes and lodged itself in a place where it
might not even be called in some situations. The address flush code
was only being called on connection close, and only applied to
addresses that were active before the system started up.
Implemented the following fixes:
- Move FlushRoutes out of Device to the initialization code in
DeviceInfo.
- Add Address flushing code in the same place.
- Capture the list of IP addresses per-interface earlier at startup
so they can be flushed at device discovery. This involved re-ordering
the RTNL "Dump" path to dump addresses before links, and adding code
in DeviceInfo to capture these addresses in its Info structures before
the actual link was discovered. This way, when the link is discovered,
it's possible to flush the old addresses.
- Use the NLM_ECHO flag when creating and deleting IP addresses in RTNL,
so RTNL events are generated even for operations that originate from
shill, and the tables are better kept up to date, so when Connections
flush IP addresses on disconnect, this properly includes those that
were created locally.
- Break apart DeviceInfo::AddLinkMsgHandler so it can be tested.
BUG=chromium-os:30358
TEST=New unit tests + plug/unplug between different networks / kill/restart
shill.
Change-Id: Ie1a38e0e86ba3a52aaaaf9c3f0e0dfcb3c8fc276
Reviewed-on: https://gerrit.chromium.org/gerrit/21719
Commit-Ready: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/mock_modem_info.h b/mock_modem_info.h
new file mode 100644
index 0000000..0d4f42a
--- /dev/null
+++ b/mock_modem_info.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SHILL_MOCK_MODEM_INFO_
+#define SHILL_MOCK_MODEM_INFO_
+
+#include <base/basictypes.h>
+#include <gmock/gmock.h>
+
+#include "shill/modem_info.h"
+
+namespace shill {
+
+class MockModemInfo : public ModemInfo {
+ public:
+ MockModemInfo();
+ virtual ~MockModemInfo();
+
+ MOCK_METHOD0(Start, void());
+ MOCK_METHOD0(Stop, void());
+ MOCK_METHOD1(OnDeviceInfoAvailable, void(const std::string &link_name));
+
+ DISALLOW_COPY_AND_ASSIGN(MockModemInfo);
+};
+
+} // namespace shill
+
+#endif // SHILL_MOCK_MODEM_INFO_