core: ignore non-Ethernet AF_LINK addresses when enumerating NICs.
Also modernize the code with some C++11 features.
Change-Id: Ibd29b39c37fdce8f87f917ab0cf48750e631e76c
diff --git a/daemon/face/ethernet-face.cpp b/daemon/face/ethernet-face.cpp
index 2fc24ab..ea9e522 100644
--- a/daemon/face/ethernet-face.cpp
+++ b/daemon/face/ethernet-face.cpp
@@ -49,12 +49,12 @@
NFD_LOG_INIT("EthernetFace");
EthernetFace::EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
- const shared_ptr<NetworkInterfaceInfo>& interface,
+ const NetworkInterfaceInfo& interface,
const ethernet::Address& address)
- : Face(FaceUri(address), FaceUri::fromDev(interface->name))
+ : Face(FaceUri(address), FaceUri::fromDev(interface.name))
, m_socket(socket)
- , m_interfaceName(interface->name)
- , m_srcAddress(interface->etherAddress)
+ , m_interfaceName(interface.name)
+ , m_srcAddress(interface.etherAddress)
, m_destAddress(address)
{
NFD_LOG_INFO("Creating ethernet face on " << m_interfaceName << ": "
diff --git a/daemon/face/ethernet-face.hpp b/daemon/face/ethernet-face.hpp
index 8f44eab..4383246 100644
--- a/daemon/face/ethernet-face.hpp
+++ b/daemon/face/ethernet-face.hpp
@@ -56,7 +56,7 @@
};
EthernetFace(const shared_ptr<boost::asio::posix::stream_descriptor>& socket,
- const shared_ptr<NetworkInterfaceInfo>& interface,
+ const NetworkInterfaceInfo& interface,
const ethernet::Address& address);
virtual
diff --git a/daemon/face/ethernet-factory.cpp b/daemon/face/ethernet-factory.cpp
index b96a0b4..314614e 100644
--- a/daemon/face/ethernet-factory.cpp
+++ b/daemon/face/ethernet-factory.cpp
@@ -35,14 +35,13 @@
NFD_LOG_INIT("EthernetFactory");
shared_ptr<EthernetFace>
-EthernetFactory::createMulticastFace(const shared_ptr<NetworkInterfaceInfo> &interface,
+EthernetFactory::createMulticastFace(const NetworkInterfaceInfo& interface,
const ethernet::Address &address)
{
if (!address.isMulticast())
throw Error(address.toString() + " is not a multicast address");
- const std::string& name = interface->name;
- shared_ptr<EthernetFace> face = findMulticastFace(name, address);
+ shared_ptr<EthernetFace> face = findMulticastFace(interface.name, address);
if (face)
return face;
@@ -51,8 +50,8 @@
face = make_shared<EthernetFace>(socket, interface, address);
face->onFail += bind(&EthernetFactory::afterFaceFailed,
- this, name, address);
- m_multicastFaces[std::make_pair(name, address)] = face;
+ this, interface.name, address);
+ m_multicastFaces[std::make_pair(interface.name, address)] = face;
return face;
}
diff --git a/daemon/face/ethernet-factory.hpp b/daemon/face/ethernet-factory.hpp
index f7f6588..b7d5ec0 100644
--- a/daemon/face/ethernet-factory.hpp
+++ b/daemon/face/ethernet-factory.hpp
@@ -72,7 +72,7 @@
* \throws EthernetFactory::Error or EthernetFace::Error
*/
shared_ptr<EthernetFace>
- createMulticastFace(const shared_ptr<NetworkInterfaceInfo>& interface,
+ createMulticastFace(const NetworkInterfaceInfo& interface,
const ethernet::Address& address);
/**
diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp
index 792068b..bdc8c24 100644
--- a/daemon/face/tcp-factory.cpp
+++ b/daemon/face/tcp-factory.cpp
@@ -35,7 +35,6 @@
TcpFactory::TcpFactory(const std::string& defaultPort/* = "6363"*/)
: m_defaultPort(defaultPort)
{
-
}
void
@@ -68,22 +67,11 @@
{
using namespace boost::asio::ip;
- const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
- for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
- i != nicList.end();
- ++i)
- {
- const shared_ptr<NetworkInterfaceInfo>& nic = *i;
- const std::vector<address_v4>& ipv4Addresses = nic->ipv4Addresses;
-
- for (std::vector<address_v4>::const_iterator j = ipv4Addresses.begin();
- j != ipv4Addresses.end();
- ++j)
- {
- prohibitEndpoint(tcp::Endpoint(*j, port));
- }
+ for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+ for (const address_v4& addr : nic.ipv4Addresses) {
+ prohibitEndpoint(tcp::Endpoint(addr, port));
}
+ }
}
void
@@ -91,29 +79,18 @@
{
using namespace boost::asio::ip;
- const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
- for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
- i != nicList.end();
- ++i)
- {
- const shared_ptr<NetworkInterfaceInfo>& nic = *i;
- const std::vector<address_v6>& ipv6Addresses = nic->ipv6Addresses;
-
- for (std::vector<address_v6>::const_iterator j = ipv6Addresses.begin();
- j != ipv6Addresses.end();
- ++j)
- {
- prohibitEndpoint(tcp::Endpoint(*j, port));
- }
+ for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+ for (const address_v6& addr : nic.ipv6Addresses) {
+ prohibitEndpoint(tcp::Endpoint(addr, port));
}
+ }
}
shared_ptr<TcpChannel>
TcpFactory::createChannel(const tcp::Endpoint& endpoint)
{
shared_ptr<TcpChannel> channel = findChannel(endpoint);
- if(static_cast<bool>(channel))
+ if (static_cast<bool>(channel))
return channel;
channel = make_shared<TcpChannel>(endpoint);
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index d6954af..dcb819d 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -43,8 +43,6 @@
{
}
-
-
void
UdpFactory::prohibitEndpoint(const udp::Endpoint& endpoint)
{
@@ -77,29 +75,18 @@
static const address_v4 INVALID_BROADCAST(address_v4::from_string("0.0.0.0"));
- const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
- for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
- i != nicList.end();
- ++i)
- {
- const shared_ptr<NetworkInterfaceInfo>& nic = *i;
- const std::vector<address_v4>& ipv4Addresses = nic->ipv4Addresses;
-
- for (std::vector<address_v4>::const_iterator j = ipv4Addresses.begin();
- j != ipv4Addresses.end();
- ++j)
- {
- prohibitEndpoint(udp::Endpoint(*j, port));
- }
-
- if (nic->isBroadcastCapable() && nic->broadcastAddress != INVALID_BROADCAST)
- {
- NFD_LOG_TRACE("prohibiting broadcast address: " << nic->broadcastAddress.to_string());
- prohibitEndpoint(udp::Endpoint(nic->broadcastAddress, port));
- }
+ for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+ for (const address_v4& addr : nic.ipv4Addresses) {
+ prohibitEndpoint(udp::Endpoint(addr, port));
}
+ if (nic.isBroadcastCapable() && nic.broadcastAddress != INVALID_BROADCAST)
+ {
+ NFD_LOG_TRACE("prohibiting broadcast address: " << nic.broadcastAddress.to_string());
+ prohibitEndpoint(udp::Endpoint(nic.broadcastAddress, port));
+ }
+ }
+
prohibitEndpoint(udp::Endpoint(address::from_string("255.255.255.255"), port));
}
@@ -108,35 +95,23 @@
{
using namespace boost::asio::ip;
- const std::list<shared_ptr<NetworkInterfaceInfo> > nicList(listNetworkInterfaces());
-
- for (std::list<shared_ptr<NetworkInterfaceInfo> >::const_iterator i = nicList.begin();
- i != nicList.end();
- ++i)
- {
- const shared_ptr<NetworkInterfaceInfo>& nic = *i;
- const std::vector<address_v6>& ipv6Addresses = nic->ipv6Addresses;
-
- for (std::vector<address_v6>::const_iterator j = ipv6Addresses.begin();
- j != ipv6Addresses.end();
- ++j)
- {
- prohibitEndpoint(udp::Endpoint(*j, port));
- }
+ for (const NetworkInterfaceInfo& nic : listNetworkInterfaces()) {
+ for (const address_v6& addr : nic.ipv6Addresses) {
+ prohibitEndpoint(udp::Endpoint(addr, port));
}
+ }
}
shared_ptr<UdpChannel>
UdpFactory::createChannel(const udp::Endpoint& endpoint,
const time::seconds& timeout)
{
- NFD_LOG_DEBUG("Creating unicast " << endpoint);
+ NFD_LOG_DEBUG("Creating unicast channel " << endpoint);
shared_ptr<UdpChannel> channel = findChannel(endpoint);
if (static_cast<bool>(channel))
return channel;
-
//checking if the endpoint is already in use for multicast face
shared_ptr<MulticastUdpFace> multicast = findMulticastFace(endpoint);
if (static_cast<bool>(multicast))
@@ -161,8 +136,7 @@
const std::string& localPort,
const time::seconds& timeout)
{
- return createChannel(UdpResolver::syncResolve(localHost, localPort),
- timeout);
+ return createChannel(UdpResolver::syncResolve(localHost, localPort), timeout);
}
shared_ptr<MulticastUdpFace>