shill: logging improvements (routing-related)
BUG=None
TEST=unit tests
Change-Id: I948017ae3ddc88f2c67dd80776f87887bbd3883b
Reviewed-on: https://gerrit.chromium.org/gerrit/16404
Commit-Ready: mukesh agrawal <quiche@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
diff --git a/connection.cc b/connection.cc
index 43095ec..5d549a4 100644
--- a/connection.cc
+++ b/connection.cc
@@ -36,7 +36,7 @@
}
Connection::~Connection() {
- VLOG(2) << __func__;
+ VLOG(2) << __func__ << " " << interface_name_;
DCHECK(!routing_request_count_);
routing_table_->FlushRoutes(interface_index_);
@@ -44,7 +44,7 @@
}
void Connection::UpdateFromIPConfig(const IPConfigRefPtr &config) {
- VLOG(2) << __func__;
+ VLOG(2) << __func__ << " " << interface_name_;
const IPConfig::Properties &properties = config->properties();
IPAddress local(properties.address_family);
@@ -78,7 +78,9 @@
}
void Connection::SetIsDefault(bool is_default) {
- VLOG(2) << __func__ << " " << is_default_ << " -> " << is_default;
+ VLOG(2) << __func__ << " "
+ << interface_name_ << " (index " << interface_index_ << ") "
+ << is_default_ << " -> " << is_default;
if (is_default == is_default_) {
return;
}
diff --git a/device_info.cc b/device_info.cc
index befb562..1f8bd08 100644
--- a/device_info.cc
+++ b/device_info.cc
@@ -161,7 +161,7 @@
}
}
- VLOG(2) << StringPrintf("%s: device %s is is defaulted to type ethernet",
+ VLOG(2) << StringPrintf("%s: device %s is defaulted to type ethernet",
__func__, iface_name.c_str());
return Technology::kEthernet;
}
diff --git a/http_request.cc b/http_request.cc
index 6e65538..055b62e 100644
--- a/http_request.cc
+++ b/http_request.cc
@@ -142,10 +142,8 @@
bool HTTPRequest::ConnectServer(const IPAddress &address, int port) {
VLOG(3) << "In " << __func__;
if (!server_async_connection_->Start(address, port)) {
- string address_string("<unknown>");
- address.ToString(&address_string);
LOG(ERROR) << "Could not create socket to connect to server at "
- << address_string;
+ << address.ToString();
SendStatus(kResultConnectionFailure);
return false;
}
diff --git a/ip_address.cc b/ip_address.cc
index e71f574..d360aaa 100644
--- a/ip_address.cc
+++ b/ip_address.cc
@@ -70,7 +70,7 @@
address_ = ByteString(GetAddressLength(family_));
}
-bool IPAddress::ToString(string *address_string) const {
+bool IPAddress::IntoString(string *address_string) const {
// Noting that INET6_ADDRSTRLEN > INET_ADDRSTRLEN
char address_buf[INET6_ADDRSTRLEN];
if (GetLength() != GetAddressLength(family_) ||
@@ -81,4 +81,10 @@
return true;
}
+string IPAddress::ToString() const {
+ string out("<unknown>");
+ IntoString(&out);
+ return out;
+}
+
} // namespace shill
diff --git a/ip_address.h b/ip_address.h
index 0d65fa6..7e4893b 100644
--- a/ip_address.h
+++ b/ip_address.h
@@ -61,7 +61,9 @@
// conversion succeeds in which case |address_string| is set to the
// result. Otherwise the function returns false and |address_string|
// is left unmodified.
- bool ToString(std::string *address_string) const;
+ bool IntoString(std::string *address_string) const;
+ // Similar to IntoString, but returns by value. Convenient for logging.
+ std::string ToString() const;
bool Equals(const IPAddress &b) const {
return family_ == b.family_ && address_.Equals(b.address_) &&
diff --git a/ip_address_unittest.cc b/ip_address_unittest.cc
index 47d027a..e743735 100644
--- a/ip_address_unittest.cc
+++ b/ip_address_unittest.cc
@@ -48,7 +48,7 @@
good_bytes.GetLength()));
EXPECT_TRUE(good_addr.address().Equals(good_bytes));
string address_string;
- EXPECT_TRUE(good_addr.ToString(&address_string));
+ EXPECT_TRUE(good_addr.IntoString(&address_string));
EXPECT_EQ(good_string, address_string);
IPAddress good_addr_from_bytes(family, good_bytes);
@@ -65,7 +65,7 @@
EXPECT_FALSE(bad_addr_from_bytes.IsValid());
EXPECT_FALSE(bad_addr.Equals(bad_addr_from_bytes));
- EXPECT_FALSE(bad_addr.ToString(&address_string));
+ EXPECT_FALSE(bad_addr.IntoString(&address_string));
}
};
diff --git a/routing_table.cc b/routing_table.cc
index a32549a..1c7ce76 100644
--- a/routing_table.cc
+++ b/routing_table.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// 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.
@@ -75,7 +75,10 @@
bool RoutingTable::AddRoute(int interface_index,
const RoutingTableEntry &entry) {
- VLOG(2) << __func__;
+ VLOG(2) << __func__ << " "
+ << "index " << interface_index
+ << "gateway " << entry.gateway.ToString() << " "
+ << "metric " << entry.metric;
CHECK(!entry.from_rtnl);
if (!ApplyRoute(interface_index,
@@ -91,12 +94,13 @@
bool RoutingTable::GetDefaultRoute(int interface_index,
IPAddress::Family family,
RoutingTableEntry *entry) {
- VLOG(2) << __func__;
+ VLOG(2) << __func__ << " index " << interface_index << " family " << family;
base::hash_map<int, vector<RoutingTableEntry> >::iterator table =
tables_.find(interface_index);
if (table == tables_.end()) {
+ VLOG(2) << __func__ << " no table";
return false;
}
@@ -105,21 +109,24 @@
for (nent = table->second.begin(); nent != table->second.end(); ++nent) {
if (nent->dst.IsDefault() && nent->dst.family() == family) {
*entry = *nent;
+ VLOG(2) << __func__ << " found "
+ << "gateway " << nent->gateway.ToString() << " "
+ << "metric " << nent->metric;
return true;
}
}
+ VLOG(2) << __func__ << " no route";
return false;
}
bool RoutingTable::SetDefaultRoute(int interface_index,
const IPConfigRefPtr &ipconfig,
uint32 metric) {
+ VLOG(2) << __func__ << " index " << interface_index << " metric " << metric;
+
const IPConfig::Properties &ipconfig_props = ipconfig->properties();
RoutingTableEntry old_entry;
-
- VLOG(2) << __func__;
-
IPAddress gateway_address(ipconfig_props.address_family);
if (!gateway_address.SetAddressFromString(ipconfig_props.gateway)) {
return false;
@@ -175,9 +182,10 @@
}
void RoutingTable::SetDefaultMetric(int interface_index, uint32 metric) {
- RoutingTableEntry entry;
+ VLOG(2) << __func__ << " "
+ << "index " << interface_index << " metric " << metric;
- VLOG(2) << __func__;
+ RoutingTableEntry entry;
if (GetDefaultRoute(interface_index, IPAddress::kFamilyIPv4, &entry) &&
entry.metric != metric) {
@@ -258,6 +266,10 @@
}
if (msg.mode() == RTNLMessage::kModeAdd) {
+ VLOG(2) << __func__ << " adding "
+ << "index " << interface_index
+ << "gateway " << entry.gateway.ToString() << " "
+ << "metric " << entry.metric;
table.push_back(entry);
}
}
@@ -309,6 +321,8 @@
void RoutingTable::ReplaceMetric(uint32 interface_index,
const RoutingTableEntry &entry,
uint32 metric) {
+ VLOG(2) << __func__ << " "
+ << "index " << interface_index << " metric " << metric;
RoutingTableEntry new_entry = entry;
new_entry.metric = metric;
// First create the route at the new metric.