blob: 0e1384461e57501226a55583129adb8325502c44 [file] [log] [blame]
Davide Pesavento44deacc2014-02-19 10:48:07 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Junxiao Shi08d07a72014-06-09 23:17:57 -07003 * Copyright (c) 2014, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis
Alexander Afanasyev9bcbc7c2014-04-06 19:37:37 -070010 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
Junxiao Shi3ffe66d2014-11-06 15:37:59 -070024 */
Davide Pesavento44deacc2014-02-19 10:48:07 +010025
26#include "ethernet-face.hpp"
Steve DiBenedettobf6a93d2014-03-21 14:03:02 -060027#include "core/logger.hpp"
Davide Pesavento44deacc2014-02-19 10:48:07 +010028
29#include <pcap/pcap.h>
30
Davide Pesavento10783f22014-03-15 04:40:01 +010031#include <cerrno> // for errno
32#include <cstdio> // for std::snprintf()
33#include <cstring> // for std::strerror() and std::strncpy()
Davide Pesavento44deacc2014-02-19 10:48:07 +010034#include <arpa/inet.h> // for htons() and ntohs()
35#include <net/ethernet.h> // for struct ether_header
36#include <net/if.h> // for struct ifreq
Davide Pesavento44deacc2014-02-19 10:48:07 +010037#include <sys/ioctl.h> // for ioctl()
38#include <unistd.h> // for dup()
39
Davide Pesavento10783f22014-03-15 04:40:01 +010040#if defined(__linux__)
41#include <netpacket/packet.h> // for struct packet_mreq
42#include <sys/socket.h> // for setsockopt()
43#endif
44
45#ifdef SIOCADDMULTI
46#if defined(__APPLE__) || defined(__FreeBSD__)
47#include <net/if_dl.h> // for struct sockaddr_dl
48#endif
49#endif
50
Alexander Afanasyevd9479aa2014-06-26 13:52:02 -070051#if !defined(PCAP_NETMASK_UNKNOWN)
52/*
53 * Value to pass to pcap_compile() as the netmask if you don't know what
54 * the netmask is.
55 */
56#define PCAP_NETMASK_UNKNOWN 0xffffffff
57#endif
58
Davide Pesavento44deacc2014-02-19 10:48:07 +010059namespace nfd {
60
Davide Pesavento1bdef282014-04-08 20:59:50 +020061NFD_LOG_INIT("EthernetFace");
Davide Pesavento44deacc2014-02-19 10:48:07 +010062
Davide Pesavento44deacc2014-02-19 10:48:07 +010063EthernetFace::EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
Davide Pesaventob499a602014-11-18 22:36:56 +010064 const NetworkInterfaceInfo& interface,
Davide Pesavento44deacc2014-02-19 10:48:07 +010065 const ethernet::Address& address)
Davide Pesaventob499a602014-11-18 22:36:56 +010066 : Face(FaceUri(address), FaceUri::fromDev(interface.name))
Davide Pesavento7726ae52014-11-23 21:01:05 +010067 , m_pcap(nullptr, pcap_close)
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000068 , m_socket(socket)
Davide Pesavento10783f22014-03-15 04:40:01 +010069#if defined(__linux__)
70 , m_interfaceIndex(interface.index)
71#endif
Davide Pesaventob499a602014-11-18 22:36:56 +010072 , m_interfaceName(interface.name)
73 , m_srcAddress(interface.etherAddress)
Davide Pesavento44deacc2014-02-19 10:48:07 +010074 , m_destAddress(address)
75{
Davide Pesaventob60cc122014-03-19 19:26:02 +010076 NFD_LOG_INFO("Creating ethernet face on " << m_interfaceName << ": "
77 << m_srcAddress << " <--> " << m_destAddress);
Davide Pesavento44deacc2014-02-19 10:48:07 +010078 pcapInit();
79
Davide Pesavento7726ae52014-11-23 21:01:05 +010080 int fd = pcap_get_selectable_fd(m_pcap.get());
Davide Pesavento44deacc2014-02-19 10:48:07 +010081 if (fd < 0)
82 throw Error("pcap_get_selectable_fd() failed");
83
84 // need to duplicate the fd, otherwise both pcap_close()
85 // and stream_descriptor::close() will try to close the
86 // same fd and one of them will fail
87 m_socket->assign(::dup(fd));
88
Davide Pesavento44deacc2014-02-19 10:48:07 +010089 m_interfaceMtu = getInterfaceMtu();
Davide Pesaventob60cc122014-03-19 19:26:02 +010090 NFD_LOG_DEBUG("[id:" << getId() << ",endpoint:" << m_interfaceName
Davide Pesavento44deacc2014-02-19 10:48:07 +010091 << "] Interface MTU is: " << m_interfaceMtu);
92
93 char filter[100];
Davide Pesavento10783f22014-03-15 04:40:01 +010094 std::snprintf(filter, sizeof(filter),
95 "(ether proto 0x%x) && (ether dst %s) && (not ether src %s)",
96 ethernet::ETHERTYPE_NDN,
97 m_destAddress.toString().c_str(),
98 m_srcAddress.toString().c_str());
Davide Pesavento44deacc2014-02-19 10:48:07 +010099 setPacketFilter(filter);
100
Davide Pesavento10783f22014-03-15 04:40:01 +0100101 joinMulticastGroup();
102
Davide Pesavento44deacc2014-02-19 10:48:07 +0100103 m_socket->async_read_some(boost::asio::null_buffers(),
104 bind(&EthernetFace::handleRead, this,
105 boost::asio::placeholders::error,
106 boost::asio::placeholders::bytes_transferred));
107}
108
109EthernetFace::~EthernetFace()
110{
Davide Pesavento44deacc2014-02-19 10:48:07 +0100111}
112
113void
114EthernetFace::sendInterest(const Interest& interest)
115{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000116 onSendInterest(interest);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100117 sendPacket(interest.wireEncode());
118}
119
120void
121EthernetFace::sendData(const Data& data)
122{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +0000123 onSendData(data);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100124 sendPacket(data.wireEncode());
125}
126
127void
128EthernetFace::close()
129{
Davide Pesavento7726ae52014-11-23 21:01:05 +0100130 if (!m_pcap)
131 return;
Alexander Afanasyev251f3c12014-06-02 18:39:58 +0300132
Davide Pesavento7726ae52014-11-23 21:01:05 +0100133 NFD_LOG_INFO("[id:" << getId() << ",endpoint:" << m_interfaceName
134 << "] Closing face");
135
136 boost::system::error_code error;
137 m_socket->cancel(error); // ignore errors
138 m_socket->close(error); // ignore errors
139 m_pcap.reset(nullptr);
140
141 fail("Face closed");
Davide Pesavento44deacc2014-02-19 10:48:07 +0100142}
143
144void
145EthernetFace::pcapInit()
146{
Davide Pesavento7726ae52014-11-23 21:01:05 +0100147 char errbuf[PCAP_ERRBUF_SIZE] = {};
148 m_pcap.reset(pcap_create(m_interfaceName.c_str(), errbuf));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100149 if (!m_pcap)
150 throw Error("pcap_create(): " + std::string(errbuf));
151
Davide Pesaventof0ae4422014-05-05 16:32:12 +0200152#ifdef HAVE_PCAP_SET_IMMEDIATE_MODE
153 // Enable "immediate mode", effectively disabling any read buffering in the kernel.
154 // This corresponds to the BIOCIMMEDIATE ioctl on BSD-like systems (including OS X)
155 // where libpcap uses a BPF device. On Linux this forces libpcap not to use TPACKET_V3,
156 // even if the kernel supports it, thus preventing bug #1511.
Davide Pesavento7726ae52014-11-23 21:01:05 +0100157 pcap_set_immediate_mode(m_pcap.get(), 1);
Davide Pesaventof0ae4422014-05-05 16:32:12 +0200158#endif
159
Davide Pesavento7726ae52014-11-23 21:01:05 +0100160 if (pcap_activate(m_pcap.get()) < 0)
Davide Pesavento44deacc2014-02-19 10:48:07 +0100161 throw Error("pcap_activate() failed");
162
Davide Pesavento7726ae52014-11-23 21:01:05 +0100163 if (pcap_set_datalink(m_pcap.get(), DLT_EN10MB) < 0)
164 throw Error("pcap_set_datalink(): " + std::string(pcap_geterr(m_pcap.get())));
Davide Pesavento9eaeac72014-03-15 05:03:42 +0100165
Davide Pesavento7726ae52014-11-23 21:01:05 +0100166 if (pcap_setdirection(m_pcap.get(), PCAP_D_IN) < 0)
Davide Pesavento9eaeac72014-03-15 05:03:42 +0100167 // no need to throw on failure, BPF will filter unwanted packets anyway
Davide Pesavento7726ae52014-11-23 21:01:05 +0100168 NFD_LOG_WARN("pcap_setdirection(): " << pcap_geterr(m_pcap.get()));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100169}
170
171void
172EthernetFace::setPacketFilter(const char* filterString)
173{
174 bpf_program filter;
Davide Pesavento7726ae52014-11-23 21:01:05 +0100175 if (pcap_compile(m_pcap.get(), &filter, filterString, 1, PCAP_NETMASK_UNKNOWN) < 0)
176 throw Error("pcap_compile(): " + std::string(pcap_geterr(m_pcap.get())));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100177
Davide Pesavento7726ae52014-11-23 21:01:05 +0100178 int ret = pcap_setfilter(m_pcap.get(), &filter);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100179 pcap_freecode(&filter);
180 if (ret < 0)
Davide Pesavento7726ae52014-11-23 21:01:05 +0100181 throw Error("pcap_setfilter(): " + std::string(pcap_geterr(m_pcap.get())));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100182}
183
184void
Davide Pesavento10783f22014-03-15 04:40:01 +0100185EthernetFace::joinMulticastGroup()
186{
187#if defined(__linux__)
188 packet_mreq mr{};
189 mr.mr_ifindex = m_interfaceIndex;
190 mr.mr_type = PACKET_MR_MULTICAST;
191 mr.mr_alen = m_destAddress.size();
192 std::copy(m_destAddress.begin(), m_destAddress.end(), mr.mr_address);
193
194 if (::setsockopt(m_socket->native_handle(), SOL_PACKET,
195 PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr)) == 0)
196 return; // success
197
198 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
199 << "] setsockopt(PACKET_ADD_MEMBERSHIP) failed: " << std::strerror(errno));
200#endif
201
202#if defined(SIOCADDMULTI)
203 ifreq ifr{};
204 std::strncpy(ifr.ifr_name, m_interfaceName.c_str(), sizeof(ifr.ifr_name) - 1);
205
206#if defined(__APPLE__) || defined(__FreeBSD__)
207 /*
208 * Differences between Linux and the BSDs (including OS X):
209 * o BSD does not have ifr_hwaddr; use ifr_addr instead.
210 * o While OS X seems to accept both AF_LINK and AF_UNSPEC as the address
211 * family, FreeBSD explicitly requires AF_LINK, so we have to use AF_LINK
212 * and sockaddr_dl instead of the generic sockaddr structure.
213 * o BSD's sockaddr (and sockaddr_dl in particular) contains an additional
214 * field, sa_len (sdl_len), which must be set to the total length of the
215 * structure, including the length field itself.
216 * o We do not specify the interface name, thus sdl_nlen is left at 0 and
217 * LLADDR is effectively the same as sdl_data.
218 */
219 sockaddr_dl* sdl = reinterpret_cast<sockaddr_dl*>(&ifr.ifr_addr);
220 sdl->sdl_len = sizeof(ifr.ifr_addr);
221 sdl->sdl_family = AF_LINK;
222 sdl->sdl_alen = m_destAddress.size();
223 std::copy(m_destAddress.begin(), m_destAddress.end(), LLADDR(sdl));
224
225 static_assert(sizeof(ifr.ifr_addr) >= offsetof(sockaddr_dl, sdl_data) + ethernet::ADDR_LEN,
226 "ifr_addr in struct ifreq is too small on this platform");
227#else
228 ifr.ifr_hwaddr.sa_family = AF_UNSPEC;
229 std::copy(m_destAddress.begin(), m_destAddress.end(), ifr.ifr_hwaddr.sa_data);
230
231 static_assert(sizeof(ifr.ifr_hwaddr) >= offsetof(sockaddr, sa_data) + ethernet::ADDR_LEN,
232 "ifr_hwaddr in struct ifreq is too small on this platform");
233#endif
234
235 if (::ioctl(m_socket->native_handle(), SIOCADDMULTI, &ifr) >= 0)
236 return; // success
237
238 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
239 << "] ioctl(SIOCADDMULTI) failed: " << std::strerror(errno));
240#endif
241
242 if (!m_destAddress.isBroadcast())
243 {
244 NFD_LOG_DEBUG("[id:" << getId() << ",endpoint:" << m_interfaceName
245 << "] Falling back to promiscuous mode");
Davide Pesavento7726ae52014-11-23 21:01:05 +0100246 pcap_set_promisc(m_pcap.get(), 1);
Davide Pesavento10783f22014-03-15 04:40:01 +0100247 }
248}
249
250void
Davide Pesavento44deacc2014-02-19 10:48:07 +0100251EthernetFace::sendPacket(const ndn::Block& block)
252{
253 if (!m_pcap)
254 {
Davide Pesaventob60cc122014-03-19 19:26:02 +0100255 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
Davide Pesavento44deacc2014-02-19 10:48:07 +0100256 << "] Trying to send on closed face");
Davide Pesavento7726ae52014-11-23 21:01:05 +0100257 return fail("Face closed");
Davide Pesavento44deacc2014-02-19 10:48:07 +0100258 }
259
Davide Pesavento9eaeac72014-03-15 05:03:42 +0100260 /// \todo Fragmentation
Davide Pesavento44deacc2014-02-19 10:48:07 +0100261 if (block.size() > m_interfaceMtu)
Davide Pesavento9eaeac72014-03-15 05:03:42 +0100262 {
Davide Pesaventob60cc122014-03-19 19:26:02 +0100263 NFD_LOG_ERROR("[id:" << getId() << ",endpoint:" << m_interfaceName
264 << "] Fragmentation not implemented: dropping packet larger than MTU");
Davide Pesavento9eaeac72014-03-15 05:03:42 +0100265 return;
266 }
Davide Pesavento44deacc2014-02-19 10:48:07 +0100267
268 /// \todo Right now there is no reserve when packet is received, but
269 /// we should reserve some space at the beginning and at the end
270 ndn::EncodingBuffer buffer(block);
271
Davide Pesaventoe4631002014-03-21 20:55:36 +0100272 // pad with zeroes if the payload is too short
Davide Pesavento44deacc2014-02-19 10:48:07 +0100273 if (block.size() < ethernet::MIN_DATA_LEN)
274 {
Davide Pesaventob60cc122014-03-19 19:26:02 +0100275 static const uint8_t padding[ethernet::MIN_DATA_LEN] = {0};
276 buffer.appendByteArray(padding, ethernet::MIN_DATA_LEN - block.size());
Davide Pesavento44deacc2014-02-19 10:48:07 +0100277 }
278
279 // construct and prepend the ethernet header
Junxiao Shi3ffe66d2014-11-06 15:37:59 -0700280 static uint16_t ethertype = htons(ethernet::ETHERTYPE_NDN);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100281 buffer.prependByteArray(reinterpret_cast<const uint8_t*>(&ethertype), ethernet::TYPE_LEN);
Davide Pesaventob60cc122014-03-19 19:26:02 +0100282 buffer.prependByteArray(m_srcAddress.data(), m_srcAddress.size());
Davide Pesavento44deacc2014-02-19 10:48:07 +0100283 buffer.prependByteArray(m_destAddress.data(), m_destAddress.size());
284
285 // send the packet
Davide Pesavento7726ae52014-11-23 21:01:05 +0100286 int sent = pcap_inject(m_pcap.get(), buffer.buf(), buffer.size());
Davide Pesavento44deacc2014-02-19 10:48:07 +0100287 if (sent < 0)
288 {
Davide Pesavento7726ae52014-11-23 21:01:05 +0100289 return fail("pcap_inject(): " + std::string(pcap_geterr(m_pcap.get())));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100290 }
291 else if (static_cast<size_t>(sent) < buffer.size())
292 {
Davide Pesavento7726ae52014-11-23 21:01:05 +0100293 return fail("Failed to inject frame");
Davide Pesavento44deacc2014-02-19 10:48:07 +0100294 }
295
Davide Pesaventob60cc122014-03-19 19:26:02 +0100296 NFD_LOG_TRACE("[id:" << getId() << ",endpoint:" << m_interfaceName
Davide Pesavento4c1a0782014-08-14 16:13:20 +0200297 << "] Successfully sent: " << block.size() << " bytes");
298 this->getMutableCounters().getNOutBytes() += block.size();
Davide Pesavento44deacc2014-02-19 10:48:07 +0100299}
300
301void
302EthernetFace::handleRead(const boost::system::error_code& error, size_t)
303{
Davide Pesavento7726ae52014-11-23 21:01:05 +0100304 if (!m_pcap)
305 return fail("Face closed");
306
Davide Pesavento44deacc2014-02-19 10:48:07 +0100307 if (error)
308 return processErrorCode(error);
309
Davide Pesavento7726ae52014-11-23 21:01:05 +0100310 pcap_pkthdr* header;
Davide Pesavento44deacc2014-02-19 10:48:07 +0100311 const uint8_t* packet;
Davide Pesavento7726ae52014-11-23 21:01:05 +0100312 int ret = pcap_next_ex(m_pcap.get(), &header, &packet);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100313 if (ret < 0)
314 {
Davide Pesavento7726ae52014-11-23 21:01:05 +0100315 return fail("pcap_next_ex(): " + std::string(pcap_geterr(m_pcap.get())));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100316 }
317 else if (ret == 0)
318 {
Davide Pesavento7726ae52014-11-23 21:01:05 +0100319 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName << "] Read timeout");
Davide Pesavento44deacc2014-02-19 10:48:07 +0100320 }
321 else
322 {
Davide Pesavento7726ae52014-11-23 21:01:05 +0100323 processIncomingPacket(header, packet);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100324 }
325
326 m_socket->async_read_some(boost::asio::null_buffers(),
327 bind(&EthernetFace::handleRead, this,
328 boost::asio::placeholders::error,
329 boost::asio::placeholders::bytes_transferred));
330}
331
332void
Davide Pesavento7726ae52014-11-23 21:01:05 +0100333EthernetFace::processIncomingPacket(const pcap_pkthdr* header, const uint8_t* packet)
Davide Pesavento44deacc2014-02-19 10:48:07 +0100334{
Davide Pesavento7726ae52014-11-23 21:01:05 +0100335 size_t length = header->caplen;
336 if (length < ethernet::HDR_LEN + ethernet::MIN_DATA_LEN)
Davide Pesavento44deacc2014-02-19 10:48:07 +0100337 {
Davide Pesavento7726ae52014-11-23 21:01:05 +0100338 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
339 << "] Received frame is too short (" << length << " bytes)");
Davide Pesavento44deacc2014-02-19 10:48:07 +0100340 return;
341 }
342
Davide Pesavento7726ae52014-11-23 21:01:05 +0100343 const ether_header* eh = reinterpret_cast<const ether_header*>(packet);
344
345 // assert in case BPF fails to filter unwanted frames
346 BOOST_ASSERT_MSG(ethernet::Address(eh->ether_dhost) == m_destAddress,
347 "Received frame addressed to a different multicast group");
348 BOOST_ASSERT_MSG(ethernet::Address(eh->ether_shost) != m_srcAddress,
349 "Received frame sent by this host");
350 BOOST_ASSERT_MSG(ntohs(eh->ether_type) == ethernet::ETHERTYPE_NDN,
351 "Received frame with unrecognized ethertype");
352
353 packet += ethernet::HDR_LEN;
354 length -= ethernet::HDR_LEN;
355
356 /// \todo Reserve space in front and at the back of the underlying buffer
357 Block element;
358 bool isOk = Block::fromBuffer(packet, length, element);
359 if (isOk)
360 {
361 NFD_LOG_TRACE("[id:" << getId() << ",endpoint:" << m_interfaceName
362 << "] Received: " << element.size() << " bytes");
363 this->getMutableCounters().getNInBytes() += element.size();
364
365 if (!decodeAndDispatchInput(element))
366 {
367 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
368 << "] Received unrecognized block of type " << element.type());
369 }
370 }
371 else
372 {
373 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
374 << "] Received block is invalid or too large to process");
375 }
376}
377
378void
379EthernetFace::processErrorCode(const boost::system::error_code& error)
380{
381 if (error == boost::asio::error::operation_aborted)
382 // cancel() has been called on the socket
383 return;
384
Davide Pesavento44deacc2014-02-19 10:48:07 +0100385 std::string msg;
386 if (error == boost::asio::error::eof)
387 {
388 msg = "Face closed";
Davide Pesaventob60cc122014-03-19 19:26:02 +0100389 NFD_LOG_INFO("[id:" << getId() << ",endpoint:" << m_interfaceName << "] " << msg);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100390 }
391 else
392 {
Davide Pesavento7726ae52014-11-23 21:01:05 +0100393 msg = "Receive operation failed: " + error.message();
Davide Pesaventob60cc122014-03-19 19:26:02 +0100394 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName << "] " << msg);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100395 }
Junxiao Shi08d07a72014-06-09 23:17:57 -0700396 fail(msg);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100397}
398
Davide Pesavento44deacc2014-02-19 10:48:07 +0100399size_t
400EthernetFace::getInterfaceMtu() const
401{
402 size_t mtu = ethernet::MAX_DATA_LEN;
403
404#ifdef SIOCGIFMTU
Davide Pesavento10783f22014-03-15 04:40:01 +0100405 ifreq ifr{};
Davide Pesaventob60cc122014-03-19 19:26:02 +0100406 std::strncpy(ifr.ifr_name, m_interfaceName.c_str(), sizeof(ifr.ifr_name) - 1);
Davide Pesavento44deacc2014-02-19 10:48:07 +0100407
408 if (::ioctl(m_socket->native_handle(), SIOCGIFMTU, &ifr) < 0)
409 {
Davide Pesaventob60cc122014-03-19 19:26:02 +0100410 NFD_LOG_WARN("[id:" << getId() << ",endpoint:" << m_interfaceName
Davide Pesavento10783f22014-03-15 04:40:01 +0100411 << "] Failed to get interface MTU: " << std::strerror(errno));
Davide Pesavento44deacc2014-02-19 10:48:07 +0100412 }
413 else
414 {
415 mtu = std::min(mtu, static_cast<size_t>(ifr.ifr_mtu));
416 }
417#endif
418
419 return mtu;
420}
421
422} // namespace nfd