face: EthernetTransport: use MTU provided by ndn::net::NetworkInterface
Change-Id: I949f054625ae6584d99505ea3fea2c4ab65b9cfb
Refs: #4021
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index 5ea05c5..5a8f91a 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -29,11 +29,8 @@
#include <pcap/pcap.h>
-#include <cerrno> // for errno
-#include <cstring> // for memcpy(), strerror(), strncpy()
#include <arpa/inet.h> // for htons()
-#include <net/if.h> // for struct ifreq
-#include <sys/ioctl.h> // for ioctl()
+#include <cstring> // for memcpy()
namespace nfd {
namespace face {
@@ -60,9 +57,6 @@
BOOST_THROW_EXCEPTION(Error(e.what()));
}
- // do this after assigning m_socket because getInterfaceMtu uses it
- this->setMtu(getInterfaceMtu());
-
asyncRead();
}
@@ -218,33 +212,5 @@
doClose();
}
-int
-EthernetTransport::getInterfaceMtu()
-{
-#ifdef SIOCGIFMTU
-#if defined(__APPLE__) || defined(__FreeBSD__)
- // see bug #2328
- using boost::asio::ip::udp;
- udp::socket sock(getGlobalIoService(), udp::v4());
- int fd = sock.native_handle();
-#else
- int fd = m_socket.native_handle();
-#endif
-
- ifreq ifr{};
- std::strncpy(ifr.ifr_name, m_interfaceName.data(), sizeof(ifr.ifr_name) - 1);
-
- if (::ioctl(fd, SIOCGIFMTU, &ifr) == 0) {
- NFD_LOG_FACE_DEBUG("Interface MTU is " << ifr.ifr_mtu);
- return ifr.ifr_mtu;
- }
-
- NFD_LOG_FACE_WARN("Failed to get interface MTU: " << std::strerror(errno));
-#endif
-
- NFD_LOG_FACE_DEBUG("Assuming default MTU of " << ethernet::MAX_DATA_LEN);
- return ethernet::MAX_DATA_LEN;
-}
-
} // namespace face
} // namespace nfd
diff --git a/daemon/face/ethernet-transport.hpp b/daemon/face/ethernet-transport.hpp
index 2412924..63658d0 100644
--- a/daemon/face/ethernet-transport.hpp
+++ b/daemon/face/ethernet-transport.hpp
@@ -98,12 +98,6 @@
void
handleError(const std::string& errorMessage);
- /**
- * @brief Returns the MTU of the underlying network interface
- */
- int
- getInterfaceMtu();
-
protected:
boost::asio::posix::stream_descriptor m_socket;
PcapHelper m_pcap;
diff --git a/daemon/face/multicast-ethernet-transport.cpp b/daemon/face/multicast-ethernet-transport.cpp
index b4adea0..b7bbdc2 100644
--- a/daemon/face/multicast-ethernet-transport.cpp
+++ b/daemon/face/multicast-ethernet-transport.cpp
@@ -61,6 +61,7 @@
this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
this->setPersistency(ndn::nfd::FACE_PERSISTENCY_PERMANENT);
this->setLinkType(linkType);
+ this->setMtu(localEndpoint.getMtu());
NFD_LOG_FACE_INFO("Creating transport");
diff --git a/daemon/face/unicast-ethernet-transport.cpp b/daemon/face/unicast-ethernet-transport.cpp
index 316c91d..e2e56d0 100644
--- a/daemon/face/unicast-ethernet-transport.cpp
+++ b/daemon/face/unicast-ethernet-transport.cpp
@@ -44,6 +44,7 @@
this->setScope(ndn::nfd::FACE_SCOPE_NON_LOCAL);
this->setPersistency(persistency);
this->setLinkType(ndn::nfd::LINK_TYPE_POINT_TO_POINT);
+ this->setMtu(localEndpoint.getMtu());
NFD_LOG_FACE_INFO("Creating transport");