blob: 647a4a47489917a1747c9871bebd40c28af2ddcc [file] [log] [blame]
Paul Stewartf748a362012-03-07 12:01:20 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewarta3c56f92011-05-26 07:08:52 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <errno.h>
6#include <time.h>
7#include <unistd.h>
8#include <string.h>
Darin Petkove0a312e2011-07-20 13:45:28 -07009#include <sys/ioctl.h>
Paul Stewarta3c56f92011-05-26 07:08:52 -070010#include <sys/socket.h>
11#include <arpa/inet.h>
12#include <netinet/ether.h>
13#include <net/if.h>
14#include <net/if_arp.h>
15#include <linux/netlink.h>
16#include <linux/rtnetlink.h>
17#include <fcntl.h>
Paul Stewarta3c56f92011-05-26 07:08:52 -070018
Eric Shienbrood3e20a232012-02-16 11:35:56 -050019#include <base/bind.h>
Paul Stewarta3c56f92011-05-26 07:08:52 -070020
Paul Stewart5f06a0e2012-12-20 11:11:33 -080021#include "shill/error.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070022#include "shill/event_dispatcher.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070023#include "shill/io_handler.h"
Paul Stewart1d18e8c2011-07-15 11:00:31 -070024#include "shill/ip_address.h"
Paul Stewartc39f1132011-06-22 12:02:28 -070025#include "shill/ipconfig.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070026#include "shill/logging.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070027#include "shill/rtnl_handler.h"
28#include "shill/rtnl_listener.h"
Paul Stewart75e89d22011-08-01 10:00:02 -070029#include "shill/rtnl_message.h"
Darin Petkov633ac6f2011-07-08 13:56:13 -070030#include "shill/sockets.h"
Paul Stewarta3c56f92011-05-26 07:08:52 -070031
Eric Shienbrood3e20a232012-02-16 11:35:56 -050032using base::Bind;
33using base::Unretained;
Paul Stewarta3c56f92011-05-26 07:08:52 -070034using std::string;
35
36namespace shill {
37
Ben Chanbbdef5f2012-04-23 13:58:15 -070038namespace {
39base::LazyInstance<RTNLHandler> g_rtnl_handler = LAZY_INSTANCE_INITIALIZER;
40} // namespace
Paul Stewart0d2ada32011-08-09 17:01:57 -070041
Paul Stewarta3c56f92011-05-26 07:08:52 -070042RTNLHandler::RTNLHandler()
Darin Petkov633ac6f2011-07-08 13:56:13 -070043 : sockets_(NULL),
Paul Stewarta3c56f92011-05-26 07:08:52 -070044 in_request_(false),
Paul Stewarta3c56f92011-05-26 07:08:52 -070045 rtnl_socket_(-1),
46 request_flags_(0),
mukesh agrawalf60e4062011-05-27 13:13:41 -070047 request_sequence_(0),
Paul Stewart9a908082011-08-31 12:18:48 -070048 last_dump_sequence_(0),
Eric Shienbrood3e20a232012-02-16 11:35:56 -050049 rtnl_callback_(Bind(&RTNLHandler::ParseRTNL, Unretained(this))) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070050 SLOG(RTNL, 2) << "RTNLHandler created";
Paul Stewarta3c56f92011-05-26 07:08:52 -070051}
52
53RTNLHandler::~RTNLHandler() {
Ben Chanfad4a0b2012-04-18 15:49:59 -070054 SLOG(RTNL, 2) << "RTNLHandler removed";
Paul Stewarta3c56f92011-05-26 07:08:52 -070055 Stop();
56}
57
58RTNLHandler* RTNLHandler::GetInstance() {
Paul Stewart0d2ada32011-08-09 17:01:57 -070059 return g_rtnl_handler.Pointer();
Paul Stewarta3c56f92011-05-26 07:08:52 -070060}
61
Darin Petkov633ac6f2011-07-08 13:56:13 -070062void RTNLHandler::Start(EventDispatcher *dispatcher, Sockets *sockets) {
Paul Stewarta3c56f92011-05-26 07:08:52 -070063 struct sockaddr_nl addr;
64
Darin Petkov633ac6f2011-07-08 13:56:13 -070065 if (sockets_) {
Paul Stewarta3c56f92011-05-26 07:08:52 -070066 return;
Darin Petkov633ac6f2011-07-08 13:56:13 -070067 }
Paul Stewarta3c56f92011-05-26 07:08:52 -070068
Darin Petkov633ac6f2011-07-08 13:56:13 -070069 rtnl_socket_ = sockets->Socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
Paul Stewarta3c56f92011-05-26 07:08:52 -070070 if (rtnl_socket_ < 0) {
71 LOG(ERROR) << "Failed to open rtnl socket";
72 return;
73 }
74
75 memset(&addr, 0, sizeof(addr));
76 addr.nl_family = AF_NETLINK;
Paul Stewart9a908082011-08-31 12:18:48 -070077 addr.nl_groups = RTMGRP_LINK | RTMGRP_IPV4_IFADDR | RTMGRP_IPV4_ROUTE |
78 RTMGRP_IPV6_IFADDR | RTMGRP_IPV6_ROUTE;
Paul Stewarta3c56f92011-05-26 07:08:52 -070079
Darin Petkov633ac6f2011-07-08 13:56:13 -070080 if (sockets->Bind(rtnl_socket_,
81 reinterpret_cast<struct sockaddr *>(&addr),
82 sizeof(addr)) < 0) {
83 sockets->Close(rtnl_socket_);
Paul Stewarta3c56f92011-05-26 07:08:52 -070084 rtnl_socket_ = -1;
85 LOG(ERROR) << "RTNL socket bind failed";
86 return;
87 }
88
Paul Stewart5f06a0e2012-12-20 11:11:33 -080089 rtnl_handler_.reset(dispatcher->CreateInputHandler(
90 rtnl_socket_,
91 rtnl_callback_,
92 Bind(&RTNLHandler::OnReadError, Unretained(this))));
Darin Petkov633ac6f2011-07-08 13:56:13 -070093 sockets_ = sockets;
Paul Stewarta3c56f92011-05-26 07:08:52 -070094
Paul Stewart9a908082011-08-31 12:18:48 -070095 NextRequest(last_dump_sequence_);
Ben Chanfad4a0b2012-04-18 15:49:59 -070096 SLOG(RTNL, 2) << "RTNLHandler started";
Paul Stewarta3c56f92011-05-26 07:08:52 -070097}
98
99void RTNLHandler::Stop() {
Darin Petkov633ac6f2011-07-08 13:56:13 -0700100 if (!sockets_)
Paul Stewarta3c56f92011-05-26 07:08:52 -0700101 return;
102
Paul Stewart7355ce12011-09-02 10:47:01 -0700103 rtnl_handler_.reset();
Darin Petkov633ac6f2011-07-08 13:56:13 -0700104 sockets_->Close(rtnl_socket_);
Paul Stewarta3c56f92011-05-26 07:08:52 -0700105 in_request_ = false;
Darin Petkov633ac6f2011-07-08 13:56:13 -0700106 sockets_ = NULL;
Paul Stewart65c40f52011-08-08 07:27:46 -0700107 request_flags_ = 0;
Ben Chanfad4a0b2012-04-18 15:49:59 -0700108 SLOG(RTNL, 2) << "RTNLHandler stopped";
Paul Stewarta3c56f92011-05-26 07:08:52 -0700109}
110
111void RTNLHandler::AddListener(RTNLListener *to_add) {
112 std::vector<RTNLListener *>::iterator it;
113 for (it = listeners_.begin(); it != listeners_.end(); ++it) {
114 if (to_add == *it)
115 return;
116 }
117 listeners_.push_back(to_add);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700118 SLOG(RTNL, 2) << "RTNLHandler added listener";
Paul Stewarta3c56f92011-05-26 07:08:52 -0700119}
120
121void RTNLHandler::RemoveListener(RTNLListener *to_remove) {
122 std::vector<RTNLListener *>::iterator it;
123 for (it = listeners_.begin(); it != listeners_.end(); ++it) {
124 if (to_remove == *it) {
125 listeners_.erase(it);
126 return;
127 }
128 }
Ben Chanfad4a0b2012-04-18 15:49:59 -0700129 SLOG(RTNL, 2) << "RTNLHandler removed listener";
Paul Stewarta3c56f92011-05-26 07:08:52 -0700130}
131
132void RTNLHandler::SetInterfaceFlags(int interface_index, unsigned int flags,
Darin Petkov0828f5f2011-08-11 10:18:52 -0700133 unsigned int change) {
Paul Stewart536820d2012-03-19 16:05:59 -0700134 if (!sockets_) {
135 LOG(ERROR) << __func__ << " called while not started. "
136 "Assuming we are in unit tests.";
137 return;
138 }
139
Paul Stewarta3c56f92011-05-26 07:08:52 -0700140 struct rtnl_request {
141 struct nlmsghdr hdr;
142 struct ifinfomsg msg;
143 } req;
144
145 request_sequence_++;
146 memset(&req, 0, sizeof(req));
147
148 req.hdr.nlmsg_len = sizeof(req);
149 req.hdr.nlmsg_flags = NLM_F_REQUEST;
150 req.hdr.nlmsg_pid = 0;
151 req.hdr.nlmsg_seq = request_sequence_;
152 req.hdr.nlmsg_type = RTM_NEWLINK;
153 req.msg.ifi_index = interface_index;
154 req.msg.ifi_flags = flags;
155 req.msg.ifi_change = change;
156
Darin Petkov633ac6f2011-07-08 13:56:13 -0700157 if (sockets_->Send(rtnl_socket_, &req, sizeof(req), 0) < 0) {
Paul Stewarta3c56f92011-05-26 07:08:52 -0700158 LOG(ERROR) << "RTNL sendto failed: " << strerror(errno);
159 }
160}
161
162void RTNLHandler::RequestDump(int request_flags) {
163 request_flags_ |= request_flags;
164
Ben Chanfad4a0b2012-04-18 15:49:59 -0700165 SLOG(RTNL, 2) << "RTNLHandler got request to dump "
mukesh agrawal47009f82011-08-25 14:07:35 -0700166 << std::showbase << std::hex
167 << request_flags
168 << std::dec << std::noshowbase;
Paul Stewarta3c56f92011-05-26 07:08:52 -0700169
Darin Petkov633ac6f2011-07-08 13:56:13 -0700170 if (!in_request_ && sockets_)
Paul Stewart9a908082011-08-31 12:18:48 -0700171 NextRequest(last_dump_sequence_);
Paul Stewarta3c56f92011-05-26 07:08:52 -0700172}
173
Chris Masone2aa97072011-08-09 17:35:08 -0700174void RTNLHandler::DispatchEvent(int type, const RTNLMessage &msg) {
Paul Stewarta3c56f92011-05-26 07:08:52 -0700175 std::vector<RTNLListener *>::iterator it;
176 for (it = listeners_.begin(); it != listeners_.end(); ++it) {
Chris Masone2aa97072011-08-09 17:35:08 -0700177 (*it)->NotifyEvent(type, msg);
Paul Stewarta3c56f92011-05-26 07:08:52 -0700178 }
179}
180
Paul Stewartf748a362012-03-07 12:01:20 -0800181void RTNLHandler::NextRequest(uint32 seq) {
Paul Stewarta3c56f92011-05-26 07:08:52 -0700182 int flag = 0;
Paul Stewart9a908082011-08-31 12:18:48 -0700183 RTNLMessage::Type type;
Paul Stewarta3c56f92011-05-26 07:08:52 -0700184
Ben Chanfad4a0b2012-04-18 15:49:59 -0700185 SLOG(RTNL, 2) << "RTNLHandler nextrequest " << seq << " "
186 << last_dump_sequence_
187 << std::showbase << std::hex
188 << " " << request_flags_
189 << std::dec << std::noshowbase;
Paul Stewarta3c56f92011-05-26 07:08:52 -0700190
Paul Stewart9a908082011-08-31 12:18:48 -0700191 if (seq != last_dump_sequence_)
Paul Stewarta3c56f92011-05-26 07:08:52 -0700192 return;
193
Paul Stewart8c116a92012-05-02 18:30:03 -0700194 if ((request_flags_ & kRequestAddr) != 0) {
Paul Stewart9a908082011-08-31 12:18:48 -0700195 type = RTNLMessage::kTypeAddress;
Paul Stewarta3c56f92011-05-26 07:08:52 -0700196 flag = kRequestAddr;
197 } else if ((request_flags_ & kRequestRoute) != 0) {
Paul Stewart9a908082011-08-31 12:18:48 -0700198 type = RTNLMessage::kTypeRoute;
Paul Stewarta3c56f92011-05-26 07:08:52 -0700199 flag = kRequestRoute;
Paul Stewart8c116a92012-05-02 18:30:03 -0700200 } else if ((request_flags_ & kRequestLink) != 0) {
201 type = RTNLMessage::kTypeLink;
202 flag = kRequestLink;
Paul Stewarta3c56f92011-05-26 07:08:52 -0700203 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700204 SLOG(RTNL, 2) << "Done with requests";
Paul Stewarta3c56f92011-05-26 07:08:52 -0700205 in_request_ = false;
206 return;
207 }
208
Paul Stewart9a908082011-08-31 12:18:48 -0700209 RTNLMessage msg(
210 type,
211 RTNLMessage::kModeGet,
212 0,
213 0,
214 0,
215 0,
Paul Stewart7355ce12011-09-02 10:47:01 -0700216 IPAddress::kFamilyUnknown);
Paul Stewart9a908082011-08-31 12:18:48 -0700217 CHECK(SendMessage(&msg));
Paul Stewarta3c56f92011-05-26 07:08:52 -0700218
Paul Stewart9a908082011-08-31 12:18:48 -0700219 last_dump_sequence_ = msg.seq();
Paul Stewarta3c56f92011-05-26 07:08:52 -0700220 request_flags_ &= ~flag;
221 in_request_ = true;
222}
223
224void RTNLHandler::ParseRTNL(InputData *data) {
225 unsigned char *buf = data->buf;
226 unsigned char *end = buf + data->len;
227
228 while (buf < end) {
229 struct nlmsghdr *hdr = reinterpret_cast<struct nlmsghdr *>(buf);
Julius Werner87fc23e2012-10-18 14:21:33 -0700230
231 // temporary debug output
232 // TODO(jwerner@chromium.org): Remove after gathering data (crosbug 35479)
233 if (static_cast<unsigned int>(end - buf) >= sizeof(struct nlmsghdr) &&
234 hdr->nlmsg_type == RTM_NEWLINK) {
235 if (NLMSG_OK(hdr, static_cast<unsigned int>(end - buf)) &&
236 hdr->nlmsg_len <= static_cast<unsigned int>(end - buf) &&
237 hdr->nlmsg_len >= NLMSG_LENGTH(sizeof(struct ifinfomsg))) {
238 struct ifinfomsg *info =
239 reinterpret_cast<struct ifinfomsg *>(NLMSG_DATA(hdr));
240 LOG(INFO) << "RTM_NEWLINK(idx=" << info->ifi_index << ", sender=" <<
241 hdr->nlmsg_pid << ", flags=" << std::hex << info->ifi_flags << ")";
242 } else {
243 LOG(INFO) << "Broken RTM_NEWLINK packet: " <<
244 ByteString(buf, end - buf).HexEncode();
245 }
246 }
247
mukesh agrawalf60e4062011-05-27 13:13:41 -0700248 if (!NLMSG_OK(hdr, static_cast<unsigned int>(end - buf)))
Paul Stewarta3c56f92011-05-26 07:08:52 -0700249 break;
250
Ben Chanfad4a0b2012-04-18 15:49:59 -0700251 SLOG(RTNL, 3) << __func__ << ": received payload (" << end - buf << ")";
Paul Stewart7355ce12011-09-02 10:47:01 -0700252
Chris Masone2aa97072011-08-09 17:35:08 -0700253 RTNLMessage msg;
Paul Stewart44f08cb2012-04-27 16:53:05 -0700254 ByteString payload(reinterpret_cast<unsigned char *>(hdr), hdr->nlmsg_len);
255 SLOG(RTNL, 5) << "RTNL received payload length " << payload.GetLength()
256 << ": \"" << payload.HexEncode() << "\"";
257 if (!msg.Decode(payload)) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700258 SLOG(RTNL, 3) << __func__ << ": rtnl packet type "
Paul Stewart44f08cb2012-04-27 16:53:05 -0700259 << hdr->nlmsg_type
260 << " length " << hdr->nlmsg_len
261 << " sequence " << hdr->nlmsg_seq;
262
Chris Masone2aa97072011-08-09 17:35:08 -0700263 switch (hdr->nlmsg_type) {
264 case NLMSG_NOOP:
265 case NLMSG_OVERRUN:
266 break;
267 case NLMSG_DONE:
268 NextRequest(hdr->nlmsg_seq);
269 break;
270 case NLMSG_ERROR:
271 {
272 struct nlmsgerr *err =
273 reinterpret_cast<nlmsgerr *>(NLMSG_DATA(hdr));
274 LOG(ERROR) << "error " << -err->error << " ("
275 << strerror(-err->error) << ")";
276 break;
277 }
278 default:
279 NOTIMPLEMENTED() << "Unknown NL message type.";
280 }
281 } else {
282 switch (msg.type()) {
Paul Stewart9a908082011-08-31 12:18:48 -0700283 case RTNLMessage::kTypeLink:
Chris Masone2aa97072011-08-09 17:35:08 -0700284 DispatchEvent(kRequestLink, msg);
285 break;
Paul Stewart9a908082011-08-31 12:18:48 -0700286 case RTNLMessage::kTypeAddress:
Chris Masone2aa97072011-08-09 17:35:08 -0700287 DispatchEvent(kRequestAddr, msg);
288 break;
Paul Stewart9a908082011-08-31 12:18:48 -0700289 case RTNLMessage::kTypeRoute:
Chris Masone2aa97072011-08-09 17:35:08 -0700290 DispatchEvent(kRequestRoute, msg);
291 break;
292 default:
293 NOTIMPLEMENTED() << "Unknown RTNL message type.";
294 }
295 }
Paul Stewarta3c56f92011-05-26 07:08:52 -0700296 buf += hdr->nlmsg_len;
297 }
298}
299
Paul Stewart9a908082011-08-31 12:18:48 -0700300bool RTNLHandler::AddressRequest(int interface_index,
301 RTNLMessage::Mode mode,
302 int flags,
303 const IPAddress &local,
Paul Stewart1062d9d2012-04-27 10:42:27 -0700304 const IPAddress &broadcast,
Paul Stewart48100b02012-03-19 07:53:52 -0700305 const IPAddress &peer) {
Paul Stewart1062d9d2012-04-27 10:42:27 -0700306 CHECK(local.family() == broadcast.family());
Paul Stewart48100b02012-03-19 07:53:52 -0700307 CHECK(local.family() == peer.family());
Paul Stewartc39f1132011-06-22 12:02:28 -0700308
Paul Stewart9a908082011-08-31 12:18:48 -0700309 RTNLMessage msg(
310 RTNLMessage::kTypeAddress,
311 mode,
312 NLM_F_REQUEST | flags,
313 0,
314 0,
315 interface_index,
316 local.family());
Paul Stewartc39f1132011-06-22 12:02:28 -0700317
Paul Stewart9a908082011-08-31 12:18:48 -0700318 msg.set_address_status(RTNLMessage::AddressStatus(
319 local.prefix(),
320 0,
321 0));
Paul Stewartc39f1132011-06-22 12:02:28 -0700322
Paul Stewart9a908082011-08-31 12:18:48 -0700323 msg.SetAttribute(IFA_LOCAL, local.address());
Paul Stewart1062d9d2012-04-27 10:42:27 -0700324 if (!broadcast.IsDefault()) {
325 msg.SetAttribute(IFA_BROADCAST, broadcast.address());
Paul Stewartc39f1132011-06-22 12:02:28 -0700326 }
Paul Stewart48100b02012-03-19 07:53:52 -0700327 if (!peer.IsDefault()) {
328 msg.SetAttribute(IFA_ADDRESS, peer.address());
329 }
Paul Stewartc39f1132011-06-22 12:02:28 -0700330
Paul Stewart9a908082011-08-31 12:18:48 -0700331 return SendMessage(&msg);
Paul Stewartc39f1132011-06-22 12:02:28 -0700332}
333
334bool RTNLHandler::AddInterfaceAddress(int interface_index,
Paul Stewart9a908082011-08-31 12:18:48 -0700335 const IPAddress &local,
Paul Stewart48100b02012-03-19 07:53:52 -0700336 const IPAddress &broadcast,
337 const IPAddress &peer) {
Paul Stewart9a908082011-08-31 12:18:48 -0700338 return AddressRequest(interface_index,
339 RTNLMessage::kModeAdd,
Paul Stewart8c116a92012-05-02 18:30:03 -0700340 NLM_F_CREATE | NLM_F_EXCL | NLM_F_ECHO,
Paul Stewart9a908082011-08-31 12:18:48 -0700341 local,
Paul Stewart48100b02012-03-19 07:53:52 -0700342 broadcast,
343 peer);
Paul Stewartc39f1132011-06-22 12:02:28 -0700344}
345
346bool RTNLHandler::RemoveInterfaceAddress(int interface_index,
Paul Stewart9a908082011-08-31 12:18:48 -0700347 const IPAddress &local) {
348 return AddressRequest(interface_index,
349 RTNLMessage::kModeDelete,
Paul Stewart8c116a92012-05-02 18:30:03 -0700350 NLM_F_ECHO,
Paul Stewart9a908082011-08-31 12:18:48 -0700351 local,
Paul Stewart48100b02012-03-19 07:53:52 -0700352 IPAddress(local.family()),
Paul Stewart9a908082011-08-31 12:18:48 -0700353 IPAddress(local.family()));
Paul Stewartc39f1132011-06-22 12:02:28 -0700354}
355
Paul Stewartcba0f7f2012-02-29 16:33:05 -0800356bool RTNLHandler::RemoveInterface(int interface_index) {
357 RTNLMessage msg(
358 RTNLMessage::kTypeLink,
359 RTNLMessage::kModeDelete,
360 NLM_F_REQUEST,
361 0,
362 0,
363 interface_index,
364 IPAddress::kFamilyUnknown);
365 return SendMessage(&msg);
366}
367
Darin Petkove0a312e2011-07-20 13:45:28 -0700368int RTNLHandler::GetInterfaceIndex(const string &interface_name) {
369 if (interface_name.empty()) {
370 LOG(ERROR) << "Empty interface name -- unable to obtain index.";
371 return -1;
372 }
373 struct ifreq ifr;
374 if (interface_name.size() >= sizeof(ifr.ifr_name)) {
375 LOG(ERROR) << "Interface name too long: " << interface_name.size() << " >= "
376 << sizeof(ifr.ifr_name);
377 return -1;
378 }
379 int socket = sockets_->Socket(PF_INET, SOCK_DGRAM, 0);
380 if (socket < 0) {
381 PLOG(ERROR) << "Unable to open INET socket";
382 return -1;
383 }
384 ScopedSocketCloser socket_closer(sockets_, socket);
385 memset(&ifr, 0, sizeof(ifr));
386 strncpy(ifr.ifr_name, interface_name.c_str(), sizeof(ifr.ifr_name));
387 if (sockets_->Ioctl(socket, SIOCGIFINDEX, &ifr) < 0) {
388 PLOG(ERROR) << "SIOCGIFINDEX error for " << interface_name;
389 return -1;
390 }
391 return ifr.ifr_ifindex;
392}
393
Paul Stewart75e89d22011-08-01 10:00:02 -0700394bool RTNLHandler::SendMessage(RTNLMessage *message) {
Paul Stewart44f08cb2012-04-27 16:53:05 -0700395 message->set_seq(request_sequence_);
Paul Stewart75e89d22011-08-01 10:00:02 -0700396 ByteString msgdata = message->Encode();
397
398 if (msgdata.GetLength() == 0) {
399 return false;
400 }
401
Paul Stewart44f08cb2012-04-27 16:53:05 -0700402 SLOG(RTNL, 5) << "RTNL sending payload with request sequence "
403 << request_sequence_ << ", length " << msgdata.GetLength()
404 << ": \"" << msgdata.HexEncode() << "\"";
405
406 request_sequence_++;
407
Paul Stewart75e89d22011-08-01 10:00:02 -0700408 if (sockets_->Send(rtnl_socket_,
Paul Stewart9a908082011-08-31 12:18:48 -0700409 msgdata.GetConstData(),
Paul Stewart75e89d22011-08-01 10:00:02 -0700410 msgdata.GetLength(),
411 0) < 0) {
412 PLOG(ERROR) << "RTNL send failed: " << strerror(errno);
413 return false;
414 }
415
416 return true;
417}
418
Paul Stewart5f06a0e2012-12-20 11:11:33 -0800419void RTNLHandler::OnReadError(const Error &error) {
420 LOG(FATAL) << "RTNL Socket read returns error: "
421 << error.message();
422}
423
Paul Stewarta3c56f92011-05-26 07:08:52 -0700424} // namespace shill