Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 5 | #include "shill/netlink_manager.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 6 | |
Wade Guthrie | 89e6cb3 | 2013-03-07 08:03:45 -0800 | [diff] [blame] | 7 | #include <netlink/netlink.h> |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 8 | #include <sys/select.h> |
| 9 | #include <sys/time.h> |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 10 | |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 11 | #include <list> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 12 | #include <map> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 13 | |
| 14 | #include <base/memory/weak_ptr.h> |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 15 | #include <base/stl_util.h> |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 16 | |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 17 | #include "shill/attribute_list.h" |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 18 | #include "shill/error.h" |
Wade Guthrie | 89e6cb3 | 2013-03-07 08:03:45 -0800 | [diff] [blame] | 19 | #include "shill/event_dispatcher.h" |
Wade Guthrie | 0ae4b8e | 2013-04-10 16:49:15 -0700 | [diff] [blame] | 20 | #include "shill/generic_netlink_message.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 21 | #include "shill/io_handler.h" |
| 22 | #include "shill/logging.h" |
Wade Guthrie | 0ae4b8e | 2013-04-10 16:49:15 -0700 | [diff] [blame] | 23 | #include "shill/netlink_message.h" |
Wade Guthrie | 92d0636 | 2013-04-25 15:41:30 -0700 | [diff] [blame] | 24 | #include "shill/netlink_socket.h" |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 25 | #include "shill/nl80211_message.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 26 | #include "shill/scope_logger.h" |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 27 | #include "shill/shill_time.h" |
Wade Guthrie | fa2100e | 2013-05-15 10:11:22 -0700 | [diff] [blame] | 28 | #include "shill/sockets.h" |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 29 | |
| 30 | using base::Bind; |
| 31 | using base::LazyInstance; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 32 | using std::list; |
Wade Guthrie | c6c8196 | 2013-03-06 15:47:13 -0800 | [diff] [blame] | 33 | using std::map; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 34 | using std::string; |
| 35 | |
| 36 | namespace shill { |
| 37 | |
| 38 | namespace { |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 39 | LazyInstance<NetlinkManager> g_netlink_manager = LAZY_INSTANCE_INITIALIZER; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 40 | } // namespace |
| 41 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 42 | const char NetlinkManager::kEventTypeConfig[] = "config"; |
| 43 | const char NetlinkManager::kEventTypeScan[] = "scan"; |
| 44 | const char NetlinkManager::kEventTypeRegulatory[] = "regulatory"; |
| 45 | const char NetlinkManager::kEventTypeMlme[] = "mlme"; |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 46 | const long NetlinkManager::kMaximumNewFamilyWaitSeconds = 1; // NOLINT |
| 47 | const long NetlinkManager::kMaximumNewFamilyWaitMicroSeconds = 0; // NOLINT |
| 48 | const long NetlinkManager::kResponseTimeoutSeconds = 5; // NOLINT |
| 49 | const long NetlinkManager::kResponseTimeoutMicroSeconds = 0; // NOLINT |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 50 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 51 | NetlinkManager::NetlinkResponseHandler::NetlinkResponseHandler( |
| 52 | const NetlinkManager::NetlinkAuxilliaryMessageHandler &error_handler) |
| 53 | : error_handler_(error_handler) {} |
| 54 | |
| 55 | NetlinkManager::NetlinkResponseHandler::~NetlinkResponseHandler() {} |
| 56 | |
| 57 | void NetlinkManager::NetlinkResponseHandler::HandleError( |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 58 | AuxilliaryMessageType type, const NetlinkMessage *netlink_message) const { |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 59 | if (!error_handler_.is_null()) |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 60 | error_handler_.Run(type, netlink_message); |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | class ControlResponseHandler : public NetlinkManager::NetlinkResponseHandler { |
| 64 | public: |
| 65 | ControlResponseHandler( |
| 66 | const NetlinkManager::ControlNetlinkMessageHandler &handler, |
| 67 | const NetlinkManager::NetlinkAuxilliaryMessageHandler &error_handler) |
| 68 | : NetlinkManager::NetlinkResponseHandler(error_handler), |
| 69 | handler_(handler) {} |
| 70 | |
| 71 | virtual bool HandleMessage( |
| 72 | const NetlinkMessage &netlink_message) const override { |
| 73 | if (netlink_message.message_type() != |
| 74 | ControlNetlinkMessage::GetMessageType()) { |
| 75 | LOG(ERROR) << "Message is type " << netlink_message.message_type() |
| 76 | << ", not " << ControlNetlinkMessage::GetMessageType() |
| 77 | << " (Control)."; |
| 78 | return false; |
| 79 | } |
| 80 | if (!handler_.is_null()) { |
| 81 | const ControlNetlinkMessage *message = |
| 82 | dynamic_cast<const ControlNetlinkMessage *>(&netlink_message); |
| 83 | handler_.Run(*message); |
| 84 | } |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | private: |
| 89 | NetlinkManager::ControlNetlinkMessageHandler handler_; |
| 90 | |
| 91 | DISALLOW_COPY_AND_ASSIGN(ControlResponseHandler); |
| 92 | }; |
| 93 | |
| 94 | class Nl80211ResponseHandler : public NetlinkManager::NetlinkResponseHandler { |
| 95 | public: |
| 96 | Nl80211ResponseHandler( |
| 97 | const NetlinkManager::Nl80211MessageHandler &handler, |
| 98 | const NetlinkManager::NetlinkAuxilliaryMessageHandler &error_handler) |
| 99 | : NetlinkManager::NetlinkResponseHandler(error_handler), |
| 100 | handler_(handler) {} |
| 101 | |
| 102 | virtual bool HandleMessage( |
| 103 | const NetlinkMessage &netlink_message) const override { |
| 104 | if (netlink_message.message_type() != Nl80211Message::GetMessageType()) { |
| 105 | LOG(ERROR) << "Message is type " << netlink_message.message_type() |
| 106 | << ", not " << Nl80211Message::GetMessageType() |
| 107 | << " (Nl80211)."; |
| 108 | return false; |
| 109 | } |
| 110 | if (!handler_.is_null()) { |
| 111 | const Nl80211Message *message = |
| 112 | dynamic_cast<const Nl80211Message *>(&netlink_message); |
| 113 | handler_.Run(*message); |
| 114 | } |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | NetlinkManager::Nl80211MessageHandler handler_; |
| 120 | |
| 121 | DISALLOW_COPY_AND_ASSIGN(Nl80211ResponseHandler); |
| 122 | }; |
| 123 | |
| 124 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 125 | NetlinkManager::MessageType::MessageType() : |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 126 | family_id(NetlinkMessage::kIllegalMessageType) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 127 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 128 | NetlinkManager::NetlinkManager() |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 129 | : dispatcher_(NULL), |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 130 | weak_ptr_factory_(this), |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 131 | dispatcher_callback_(Bind(&NetlinkManager::OnRawNlMessageReceived, |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 132 | weak_ptr_factory_.GetWeakPtr())), |
Wade Guthrie | fa2100e | 2013-05-15 10:11:22 -0700 | [diff] [blame] | 133 | sock_(NULL), |
| 134 | time_(Time::GetInstance()) {} |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 135 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 136 | NetlinkManager *NetlinkManager::GetInstance() { |
| 137 | return g_netlink_manager.Pointer(); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 140 | void NetlinkManager::Reset(bool full) { |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 141 | ClearBroadcastHandlers(); |
Wade Guthrie | fa2100e | 2013-05-15 10:11:22 -0700 | [diff] [blame] | 142 | message_handlers_.clear(); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 143 | message_types_.clear(); |
Darin Petkov | d581838 | 2013-01-28 16:27:07 +0100 | [diff] [blame] | 144 | if (full) { |
| 145 | dispatcher_ = NULL; |
| 146 | delete sock_; |
| 147 | sock_ = NULL; |
| 148 | } |
Wade Guthrie | d615361 | 2012-08-23 11:36:14 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 151 | void NetlinkManager::OnNewFamilyMessage(const ControlNetlinkMessage &message) { |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 152 | uint16_t family_id; |
| 153 | string family_name; |
| 154 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 155 | if (!message.const_attributes()->GetU16AttributeValue(CTRL_ATTR_FAMILY_ID, |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 156 | &family_id)) { |
| 157 | LOG(ERROR) << __func__ << ": Couldn't get family_id attribute"; |
| 158 | return; |
| 159 | } |
| 160 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 161 | if (!message.const_attributes()->GetStringAttributeValue( |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 162 | CTRL_ATTR_FAMILY_NAME, &family_name)) { |
| 163 | LOG(ERROR) << __func__ << ": Couldn't get family_name attribute"; |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | SLOG(WiFi, 3) << "Socket family '" << family_name << "' has id=" << family_id; |
| 168 | |
| 169 | // Extract the available multicast groups from the message. |
| 170 | AttributeListConstRefPtr multicast_groups; |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 171 | if (message.const_attributes()->ConstGetNestedAttributeList( |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 172 | CTRL_ATTR_MCAST_GROUPS, &multicast_groups)) { |
| 173 | AttributeListConstRefPtr current_group; |
| 174 | |
| 175 | for (int i = 1; |
| 176 | multicast_groups->ConstGetNestedAttributeList(i, ¤t_group); |
| 177 | ++i) { |
| 178 | string group_name; |
| 179 | uint32_t group_id; |
| 180 | if (!current_group->GetStringAttributeValue(CTRL_ATTR_MCAST_GRP_NAME, |
| 181 | &group_name)) { |
| 182 | LOG(WARNING) << "Expected CTRL_ATTR_MCAST_GRP_NAME, found none"; |
| 183 | continue; |
| 184 | } |
| 185 | if (!current_group->GetU32AttributeValue(CTRL_ATTR_MCAST_GRP_ID, |
| 186 | &group_id)) { |
| 187 | LOG(WARNING) << "Expected CTRL_ATTR_MCAST_GRP_ID, found none"; |
| 188 | continue; |
| 189 | } |
| 190 | SLOG(WiFi, 3) << " Adding group '" << group_name << "' = " << group_id; |
| 191 | message_types_[family_name].groups[group_name] = group_id; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | message_types_[family_name].family_id = family_id; |
| 196 | } |
| 197 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 198 | // static |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 199 | void NetlinkManager::OnNetlinkMessageError(AuxilliaryMessageType type, |
| 200 | const NetlinkMessage *raw_message) { |
| 201 | switch (type) { |
| 202 | case kErrorFromKernel: |
| 203 | if (!raw_message) { |
| 204 | LOG(ERROR) << "Unknown error from kernel."; |
| 205 | break; |
| 206 | } |
| 207 | if (raw_message->message_type() == ErrorAckMessage::GetMessageType()) { |
| 208 | const ErrorAckMessage *error_ack_message = |
| 209 | dynamic_cast<const ErrorAckMessage *>(raw_message); |
| 210 | if (error_ack_message->error()) { |
| 211 | LOG(ERROR) << __func__ << ": Message (seq: " |
| 212 | << error_ack_message->sequence_number() << ") failed: " |
| 213 | << error_ack_message->ToString(); |
| 214 | } else { |
| 215 | SLOG(WiFi, 6) << __func__ << ": Message (seq: " |
| 216 | << error_ack_message->sequence_number() << ") ACKed"; |
| 217 | } |
| 218 | } |
| 219 | break; |
| 220 | |
| 221 | case kUnexpectedResponseType: |
| 222 | LOG(ERROR) << "Message not handled by regular message handler:"; |
| 223 | if (raw_message) { |
| 224 | raw_message->Print(0, 0); |
| 225 | } |
| 226 | break; |
| 227 | |
| 228 | case kTimeoutWaitingForResponse: |
| 229 | LOG(WARNING) << "Timeout waiting for response"; |
| 230 | break; |
| 231 | |
| 232 | default: |
| 233 | LOG(ERROR) << "Unexpected auxilliary message type: " << type; |
| 234 | break; |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 235 | } |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 238 | bool NetlinkManager::Init() { |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 239 | // Install message factory for control class of messages, which has |
| 240 | // statically-known message type. |
| 241 | message_factory_.AddFactoryMethod( |
| 242 | ControlNetlinkMessage::kMessageType, |
| 243 | Bind(&ControlNetlinkMessage::CreateMessage)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 244 | if (!sock_) { |
Wade Guthrie | cc53f23 | 2013-03-05 13:22:23 -0800 | [diff] [blame] | 245 | sock_ = new NetlinkSocket; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 246 | if (!sock_) { |
| 247 | LOG(ERROR) << "No memory"; |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | if (!sock_->Init()) { |
| 252 | return false; |
| 253 | } |
| 254 | } |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 255 | return true; |
| 256 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 257 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 258 | void NetlinkManager::Start(EventDispatcher *dispatcher) { |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 259 | dispatcher_ = dispatcher; |
| 260 | CHECK(dispatcher_); |
| 261 | // Install ourselves in the shill mainloop so we receive messages on the |
| 262 | // netlink socket. |
| 263 | dispatcher_handler_.reset(dispatcher_->CreateInputHandler( |
| 264 | file_descriptor(), |
| 265 | dispatcher_callback_, |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 266 | Bind(&NetlinkManager::OnReadError, weak_ptr_factory_.GetWeakPtr()))); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 269 | int NetlinkManager::file_descriptor() const { |
Wade Guthrie | 89e6cb3 | 2013-03-07 08:03:45 -0800 | [diff] [blame] | 270 | return (sock_ ? sock_->file_descriptor() : -1); |
| 271 | } |
| 272 | |
Wade Guthrie | fa2100e | 2013-05-15 10:11:22 -0700 | [diff] [blame] | 273 | uint16_t NetlinkManager::GetFamily(const string &name, |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 274 | const NetlinkMessageFactory::FactoryMethod &message_factory) { |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 275 | MessageType &message_type = message_types_[name]; |
| 276 | if (message_type.family_id != NetlinkMessage::kIllegalMessageType) { |
| 277 | return message_type.family_id; |
| 278 | } |
| 279 | if (!sock_) { |
| 280 | LOG(FATAL) << "Must call |Init| before this method."; |
| 281 | return false; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 284 | GetFamilyMessage msg; |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 285 | if (!msg.attributes()->SetStringAttributeValue(CTRL_ATTR_FAMILY_NAME, name)) { |
| 286 | LOG(ERROR) << "Couldn't set string attribute"; |
| 287 | return false; |
| 288 | } |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 289 | SendControlMessage(&msg, |
| 290 | Bind(&NetlinkManager::OnNewFamilyMessage, |
| 291 | weak_ptr_factory_.GetWeakPtr()), |
| 292 | Bind(&NetlinkManager::OnNetlinkMessageError)); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 293 | |
| 294 | // Wait for a response. The code absolutely needs family_ids for its |
| 295 | // message types so we do a synchronous wait. It's OK to do this because |
| 296 | // a) libnl does a synchronous wait (so there's prior art), b) waiting |
| 297 | // asynchronously would add significant and unnecessary complexity to the |
| 298 | // code that deals with pending messages that could, potentially, be waiting |
| 299 | // for a message type, and c) it really doesn't take very long for the |
| 300 | // GETFAMILY / NEWFAMILY transaction to transpire (this transaction was timed |
| 301 | // over 20 times and found a maximum duration of 11.1 microseconds and an |
| 302 | // average of 4.0 microseconds). |
Wade Guthrie | f788a0a | 2013-06-10 09:50:26 -0700 | [diff] [blame] | 303 | struct timeval now, end_time; |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 304 | struct timeval maximum_wait_duration = {kMaximumNewFamilyWaitSeconds, |
| 305 | kMaximumNewFamilyWaitMicroSeconds}; |
Wade Guthrie | f788a0a | 2013-06-10 09:50:26 -0700 | [diff] [blame] | 306 | time_->GetTimeMonotonic(&now); |
| 307 | timeradd(&now, &maximum_wait_duration, &end_time); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 308 | |
| 309 | do { |
| 310 | // Wait with timeout for a message from the netlink socket. |
| 311 | fd_set read_fds; |
| 312 | FD_ZERO(&read_fds); |
| 313 | FD_SET(file_descriptor(), &read_fds); |
| 314 | struct timeval wait_duration; |
| 315 | timersub(&end_time, &now, &wait_duration); |
Wade Guthrie | fa2100e | 2013-05-15 10:11:22 -0700 | [diff] [blame] | 316 | int result = sock_->sockets()->Select(file_descriptor() + 1, |
| 317 | &read_fds, |
| 318 | NULL, |
| 319 | NULL, |
| 320 | &wait_duration); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 321 | if (result < 0) { |
| 322 | PLOG(ERROR) << "Select failed"; |
| 323 | return NetlinkMessage::kIllegalMessageType; |
| 324 | } |
| 325 | if (result == 0) { |
| 326 | LOG(WARNING) << "Timed out waiting for family_id for family '" |
| 327 | << name << "'."; |
| 328 | return NetlinkMessage::kIllegalMessageType; |
| 329 | } |
| 330 | |
| 331 | // Read and process any messages. |
| 332 | ByteString received; |
| 333 | sock_->RecvMessage(&received); |
| 334 | InputData input_data(received.GetData(), received.GetLength()); |
| 335 | OnRawNlMessageReceived(&input_data); |
| 336 | if (message_type.family_id != NetlinkMessage::kIllegalMessageType) { |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 337 | uint16_t family_id = message_type.family_id; |
| 338 | if (family_id != NetlinkMessage::kIllegalMessageType) { |
| 339 | message_factory_.AddFactoryMethod(family_id, message_factory); |
| 340 | } |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 341 | return message_type.family_id; |
| 342 | } |
Wade Guthrie | fa2100e | 2013-05-15 10:11:22 -0700 | [diff] [blame] | 343 | time_->GetTimeMonotonic(&now); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 344 | } while (timercmp(&now, &end_time, <)); |
| 345 | |
| 346 | LOG(ERROR) << "Timed out waiting for family_id for family '" << name << "'."; |
| 347 | return NetlinkMessage::kIllegalMessageType; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 350 | bool NetlinkManager::AddBroadcastHandler(const NetlinkMessageHandler &handler) { |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 351 | if (FindBroadcastHandler(handler)) { |
| 352 | LOG(WARNING) << "Trying to re-add a handler"; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 353 | return false; // Should only be one copy in the list. |
| 354 | } |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 355 | if (handler.is_null()) { |
| 356 | LOG(WARNING) << "Trying to add a NULL handler"; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 357 | return false; |
| 358 | } |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 359 | // And add the handler to the list. |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 360 | SLOG(WiFi, 3) << "NetlinkManager::" << __func__ << " - adding handler"; |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 361 | broadcast_handlers_.push_back(handler); |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 362 | return true; |
| 363 | } |
| 364 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 365 | bool NetlinkManager::RemoveBroadcastHandler( |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 366 | const NetlinkMessageHandler &handler) { |
| 367 | list<NetlinkMessageHandler>::iterator i; |
| 368 | for (i = broadcast_handlers_.begin(); i != broadcast_handlers_.end(); ++i) { |
| 369 | if ((*i).Equals(handler)) { |
| 370 | broadcast_handlers_.erase(i); |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 371 | // Should only be one copy in the list so we don't have to continue |
| 372 | // looking for another one. |
| 373 | return true; |
| 374 | } |
| 375 | } |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 376 | LOG(WARNING) << "NetlinkMessageHandler not found."; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 377 | return false; |
| 378 | } |
| 379 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 380 | bool NetlinkManager::FindBroadcastHandler(const NetlinkMessageHandler &handler) |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 381 | const { |
| 382 | list<NetlinkMessageHandler>::const_iterator i; |
| 383 | for (i = broadcast_handlers_.begin(); i != broadcast_handlers_.end(); ++i) { |
| 384 | if ((*i).Equals(handler)) { |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 385 | return true; |
| 386 | } |
| 387 | } |
| 388 | return false; |
| 389 | } |
| 390 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 391 | void NetlinkManager::ClearBroadcastHandlers() { |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 392 | broadcast_handlers_.clear(); |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 395 | bool NetlinkManager::SendControlMessage( |
| 396 | ControlNetlinkMessage *message, |
| 397 | const ControlNetlinkMessageHandler &message_handler, |
| 398 | const NetlinkAuxilliaryMessageHandler &error_handler) { |
| 399 | return SendMessageInternal(message, |
| 400 | new ControlResponseHandler(message_handler, |
| 401 | error_handler)); |
| 402 | } |
| 403 | |
| 404 | bool NetlinkManager::SendNl80211Message( |
| 405 | Nl80211Message *message, |
| 406 | const Nl80211MessageHandler &message_handler, |
| 407 | const NetlinkAuxilliaryMessageHandler &error_handler) { |
| 408 | return SendMessageInternal(message, |
| 409 | new Nl80211ResponseHandler(message_handler, |
| 410 | error_handler)); |
| 411 | } |
| 412 | |
| 413 | bool NetlinkManager::SendMessageInternal( |
| 414 | NetlinkMessage *message, |
| 415 | NetlinkManager::NetlinkResponseHandler *response_handler) { |
Wade Guthrie | 5d53d49 | 2012-11-07 09:53:31 -0800 | [diff] [blame] | 416 | if (!message) { |
| 417 | LOG(ERROR) << "Message is NULL."; |
| 418 | return false; |
| 419 | } |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 420 | |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 421 | // Clean out timed-out message handlers. The list of outstanding messages |
| 422 | // should be small so the time wasted by looking through all of them should |
| 423 | // be small. |
| 424 | struct timeval now; |
| 425 | time_->GetTimeMonotonic(&now); |
| 426 | map<uint32_t, NetlinkResponseHandlerRefPtr>::iterator handler_it = |
| 427 | message_handlers_.begin(); |
| 428 | while (handler_it != message_handlers_.end()) { |
| 429 | if (timercmp(&now, &handler_it->second->delete_after(), >)) { |
| 430 | // A timeout isn't always unexpected so this is not a warning. |
| 431 | SLOG(WiFi, 3) << "Removing timed-out handler for sequence number " |
| 432 | << handler_it->first; |
| 433 | handler_it->second->HandleError(kTimeoutWaitingForResponse, NULL); |
| 434 | handler_it = message_handlers_.erase(handler_it); |
| 435 | } else { |
| 436 | ++handler_it; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | // On to the business at hand... |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 441 | ByteString message_string = message->Encode(this->GetSequenceNumber()); |
Wade Guthrie | cc53f23 | 2013-03-05 13:22:23 -0800 | [diff] [blame] | 442 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 443 | if (!response_handler) { |
Wade Guthrie | cc53f23 | 2013-03-05 13:22:23 -0800 | [diff] [blame] | 444 | SLOG(WiFi, 3) << "Handler for message was null."; |
| 445 | } else if (ContainsKey(message_handlers_, message->sequence_number())) { |
| 446 | LOG(ERROR) << "A handler already existed for sequence: " |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 447 | << message->sequence_number(); |
| 448 | return false; |
Wade Guthrie | cc53f23 | 2013-03-05 13:22:23 -0800 | [diff] [blame] | 449 | } else { |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 450 | struct timeval response_timeout = {kResponseTimeoutSeconds, |
| 451 | kResponseTimeoutMicroSeconds}; |
| 452 | struct timeval delete_after; |
| 453 | timeradd(&now, &response_timeout, &delete_after); |
| 454 | response_handler->set_delete_after(delete_after); |
| 455 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 456 | message_handlers_[message->sequence_number()] = |
| 457 | NetlinkResponseHandlerRefPtr(response_handler); |
Wade Guthrie | cc53f23 | 2013-03-05 13:22:23 -0800 | [diff] [blame] | 458 | } |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 459 | |
Wade Guthrie | 0b1ebf1 | 2013-04-12 09:53:33 -0700 | [diff] [blame] | 460 | SLOG(WiFi, 5) << "NL Message " << message->sequence_number() |
Wade Guthrie | cc53f23 | 2013-03-05 13:22:23 -0800 | [diff] [blame] | 461 | << " Sending (" << message_string.GetLength() |
| 462 | << " bytes) ===>"; |
Wade Guthrie | 0b1ebf1 | 2013-04-12 09:53:33 -0700 | [diff] [blame] | 463 | message->Print(6, 7); |
| 464 | NetlinkMessage::PrintBytes(8, message_string.GetConstData(), |
Wade Guthrie | cc53f23 | 2013-03-05 13:22:23 -0800 | [diff] [blame] | 465 | message_string.GetLength()); |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 466 | |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 467 | if (!sock_->SendMessage(message_string)) { |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 468 | LOG(ERROR) << "Failed to send Netlink message."; |
Wade Guthrie | 5d53d49 | 2012-11-07 09:53:31 -0800 | [diff] [blame] | 469 | return false; |
| 470 | } |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 471 | return true; |
| 472 | } |
| 473 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 474 | bool NetlinkManager::RemoveMessageHandler(const NetlinkMessage &message) { |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 475 | if (!ContainsKey(message_handlers_, message.sequence_number())) { |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 476 | return false; |
| 477 | } |
Wade Guthrie | 71cb0a7 | 2013-02-27 10:27:18 -0800 | [diff] [blame] | 478 | message_handlers_.erase(message.sequence_number()); |
Wade Guthrie | 5d3d6de | 2012-11-02 11:08:34 -0700 | [diff] [blame] | 479 | return true; |
| 480 | } |
| 481 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 482 | uint32_t NetlinkManager::GetSequenceNumber() { |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 483 | return sock_ ? |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 484 | sock_->GetSequenceNumber() : NetlinkMessage::kBroadcastSequenceNumber; |
Wade Guthrie | bdcdaa7 | 2013-03-04 12:47:12 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 487 | bool NetlinkManager::SubscribeToEvents(const string &family_id, |
| 488 | const string &group_name) { |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 489 | if (!ContainsKey(message_types_, family_id)) { |
| 490 | LOG(ERROR) << "Family '" << family_id << "' doesn't exist"; |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 491 | return false; |
| 492 | } |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 493 | |
| 494 | if (!ContainsKey(message_types_[family_id].groups, group_name)) { |
| 495 | LOG(ERROR) << "Group '" << group_name << "' doesn't exist in family '" |
| 496 | << family_id << "'"; |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | uint32_t group_id = message_types_[family_id].groups[group_name]; |
| 501 | if (!sock_) { |
| 502 | LOG(FATAL) << "Need to call |Init| first."; |
| 503 | } |
| 504 | return sock_->SubscribeToEvents(group_id); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 507 | void NetlinkManager::OnRawNlMessageReceived(InputData *data) { |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 508 | if (!data) { |
| 509 | LOG(ERROR) << __func__ << "() called with null header."; |
| 510 | return; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 511 | } |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 512 | unsigned char *buf = data->buf; |
| 513 | unsigned char *end = buf + data->len; |
| 514 | while (buf < end) { |
| 515 | nlmsghdr *msg = reinterpret_cast<nlmsghdr *>(buf); |
| 516 | // Discard the message if there're not enough bytes to a) tell the code how |
| 517 | // much space is in the message (i.e., to access nlmsg_len) or b) to hold |
| 518 | // the entire message. The odd calculation is there to keep the code from |
| 519 | // potentially calculating an illegal address (causes a segfault on some |
| 520 | // architectures). |
| 521 | size_t bytes_left = end - buf; |
| 522 | if (((bytes_left < (offsetof(nlmsghdr, nlmsg_len) + |
Liam McLoughlin | f4baef2 | 2012-08-01 19:08:25 -0700 | [diff] [blame] | 523 | sizeof(msg->nlmsg_len))) || |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 524 | (bytes_left < msg->nlmsg_len))) { |
| 525 | LOG(ERROR) << "Discarding incomplete message."; |
| 526 | return; |
| 527 | } |
| 528 | OnNlMessageReceived(msg); |
| 529 | buf += msg->nlmsg_len; |
| 530 | } |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 531 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 532 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 533 | void NetlinkManager::OnNlMessageReceived(nlmsghdr *msg) { |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 534 | if (!msg) { |
| 535 | LOG(ERROR) << __func__ << "() called with null header."; |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 536 | return; |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 537 | } |
| 538 | const uint32 sequence_number = msg->nlmsg_seq; |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 539 | |
Wade Guthrie | 12f113a | 2013-03-12 17:15:46 -0700 | [diff] [blame] | 540 | scoped_ptr<NetlinkMessage> message(message_factory_.CreateMessage(msg)); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 541 | if (message == NULL) { |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 542 | SLOG(WiFi, 3) << "NL Message " << sequence_number << " <==="; |
Wade Guthrie | b1ec860 | 2012-10-18 17:26:14 -0700 | [diff] [blame] | 543 | SLOG(WiFi, 3) << __func__ << "(msg:NULL)"; |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 544 | return; // Skip current message, continue parsing buffer. |
Christopher Wiley | 393b93f | 2012-11-08 17:30:58 -0800 | [diff] [blame] | 545 | } |
Wade Guthrie | 0b1ebf1 | 2013-04-12 09:53:33 -0700 | [diff] [blame] | 546 | SLOG(WiFi, 5) << "NL Message " << sequence_number |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 547 | << " Received (" << msg->nlmsg_len << " bytes) <==="; |
Wade Guthrie | 0b1ebf1 | 2013-04-12 09:53:33 -0700 | [diff] [blame] | 548 | message->Print(6, 7); |
Wade Guthrie | f48a195 | 2013-03-04 17:33:47 -0800 | [diff] [blame] | 549 | NetlinkMessage::PrintBytes(8, reinterpret_cast<const unsigned char *>(msg), |
Wade Guthrie | 8e27861 | 2013-02-26 10:32:34 -0800 | [diff] [blame] | 550 | msg->nlmsg_len); |
| 551 | |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 552 | if (message->message_type() == ErrorAckMessage::GetMessageType()) { |
| 553 | SLOG(WiFi, 3) << "Error response to message " << sequence_number; |
| 554 | const ErrorAckMessage *error_ack_message = |
| 555 | dynamic_cast<const ErrorAckMessage *>(message.get()); |
| 556 | if (error_ack_message->error()) { |
| 557 | if (ContainsKey(message_handlers_, sequence_number)) { |
| 558 | SLOG(WiFi, 6) << "Found message-specific error handler"; |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 559 | message_handlers_[sequence_number]->HandleError(kErrorFromKernel, |
| 560 | message.get()); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 561 | message_handlers_.erase(sequence_number); |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 562 | } |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 563 | } else { |
| 564 | SLOG(WiFi, 3) << "ACK message -- not removing callback"; |
| 565 | } |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | if (ContainsKey(message_handlers_, sequence_number)) { |
| 570 | SLOG(WiFi, 6) << "Found message-specific handler"; |
| 571 | if (!message_handlers_[sequence_number]->HandleMessage(*message)) { |
| 572 | LOG(ERROR) << "Couldn't call message handler for " << sequence_number; |
| 573 | // Call the error handler but, since we don't have an |ErrorAckMessage|, |
| 574 | // we'll have to pass a NULL pointer. |
Wade Guthrie | 84db7ce | 2013-06-12 11:40:49 -0700 | [diff] [blame] | 575 | message_handlers_[sequence_number]->HandleError(kUnexpectedResponseType, |
| 576 | NULL); |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 577 | } |
| 578 | if ((message->flags() & NLM_F_MULTI) && |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 579 | (message->message_type() != NLMSG_DONE)) { |
Wade Guthrie | 0b1ebf1 | 2013-04-12 09:53:33 -0700 | [diff] [blame] | 580 | SLOG(WiFi, 6) << "Multi-part message -- not removing callback"; |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 581 | } else { |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 582 | SLOG(WiFi, 6) << "Removing callbacks"; |
Wade Guthrie | bee87c2 | 2013-03-06 11:00:46 -0800 | [diff] [blame] | 583 | message_handlers_.erase(sequence_number); |
| 584 | } |
Wade Guthrie | 7347bf2 | 2013-04-30 11:21:51 -0700 | [diff] [blame] | 585 | return; |
| 586 | } |
| 587 | |
| 588 | for (const auto &handler : broadcast_handlers_) { |
| 589 | SLOG(WiFi, 6) << "Calling broadcast handler"; |
| 590 | if (!handler.is_null()) { |
| 591 | handler.Run(*message); |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 592 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 593 | } |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 594 | } |
| 595 | |
Wade Guthrie | bb9fca2 | 2013-04-10 17:21:42 -0700 | [diff] [blame] | 596 | void NetlinkManager::OnReadError(const Error &error) { |
| 597 | // TODO(wdg): When netlink_manager is used for scan, et al., this should |
| 598 | // either be LOG(FATAL) or the code should properly deal with errors, |
| 599 | // e.g., dropped messages due to the socket buffer being full. |
| 600 | LOG(ERROR) << "NetlinkManager's netlink Socket read returns error: " |
repo sync | bcaa694 | 2013-01-02 15:38:21 -0800 | [diff] [blame] | 601 | << error.message(); |
| 602 | } |
| 603 | |
| 604 | |
Wade Guthrie | 0d43853 | 2012-05-18 14:18:50 -0700 | [diff] [blame] | 605 | } // namespace shill. |