face: set EthernetTransport UP/DOWN based on netif state
refs #3352
Change-Id: I24476ee293d229cd9222996f91f31cfb15728c47
diff --git a/daemon/face/ethernet-transport.cpp b/daemon/face/ethernet-transport.cpp
index 7d1f7cb..412bcba 100644
--- a/daemon/face/ethernet-transport.cpp
+++ b/daemon/face/ethernet-transport.cpp
@@ -58,6 +58,11 @@
BOOST_THROW_EXCEPTION(Error(e.what()));
}
+ m_netifStateConn = localEndpoint.onStateChanged.connect(
+ [=] (ndn::net::InterfaceState, ndn::net::InterfaceState newState) {
+ handleNetifStateChange(newState);
+ });
+
asyncRead();
}
@@ -83,6 +88,20 @@
}
void
+EthernetTransport::handleNetifStateChange(ndn::net::InterfaceState netifState)
+{
+ NFD_LOG_FACE_TRACE("netif is " << netifState);
+ if (netifState == ndn::net::InterfaceState::RUNNING) {
+ if (getState() == TransportState::DOWN) {
+ this->setState(TransportState::UP);
+ }
+ }
+ else if (getState() == TransportState::UP) {
+ this->setState(TransportState::DOWN);
+ }
+}
+
+void
EthernetTransport::doSend(Transport::Packet&& packet)
{
NFD_LOG_FACE_TRACE(__func__);
diff --git a/daemon/face/ethernet-transport.hpp b/daemon/face/ethernet-transport.hpp
index 63658d0..798b937 100644
--- a/daemon/face/ethernet-transport.hpp
+++ b/daemon/face/ethernet-transport.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2014-2017, Regents of the University of California,
+ * Copyright (c) 2014-2018, Regents of the University of California,
* Arizona Board of Regents,
* Colorado State University,
* University Pierre & Marie Curie, Sorbonne University,
@@ -81,6 +81,9 @@
private:
void
+ handleNetifStateChange(ndn::net::InterfaceState netifState);
+
+ void
doSend(Transport::Packet&& packet) final;
/**
@@ -106,6 +109,7 @@
std::string m_interfaceName;
private:
+ signal::ScopedConnection m_netifStateConn;
bool m_hasRecentlyReceived;
#ifdef _DEBUG
/// number of frames dropped by the kernel, as reported by libpcap