face, mgmt: improve face creation failure and bad URI handling
Prevent creation of faces to endpoints owned by NFD instance
Prevent creation of UDP broadcast faces (255.255.255.255 and
those belonging to machine's interfaces) in response to
face creation command
Sanity check configuration file port numbers in face manager
refs: #1414, #1427
Change-Id: Ia3f0a9337f3d97c34388773eab05bc39ad6dd804
diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp
index 390b412..49c22b7 100644
--- a/daemon/face/udp-channel.cpp
+++ b/daemon/face/udp-channel.cpp
@@ -31,7 +31,7 @@
{
m_socket->set_option(ip::v6_only(true));
}
-
+
try {
m_socket->bind(m_localEndpoint);
}
@@ -41,9 +41,9 @@
throw Error("Failed to properly configure the socket. "
"UdpChannel creation aborted, check the address (" + std::string(e.what()) + ")");
}
-
+
this->setUri(FaceUri(localEndpoint));
-
+
//setting the timeout to close the idle faces
m_closeIdleFaceEvent = scheduler::schedule(m_idleFaceTimeout,
bind(&UdpChannel::closeIdleFaces, this));
@@ -62,7 +62,7 @@
throw Error("Listen already called on this channel");
}
m_isListening = true;
-
+
onFaceCreatedNewPeerCallback = onFaceCreated;
onConnectFailedNewPeerCallback = onListenFailed;
@@ -76,7 +76,8 @@
void
UdpChannel::connect(const udp::Endpoint& remoteEndpoint,
- const FaceCreatedCallback& onFaceCreated)
+ const FaceCreatedCallback& onFaceCreated,
+ const ConnectFailedCallback& onConnectFailed)
{
ChannelFaceMap::iterator i = m_channelFaces.find(remoteEndpoint);
if (i != m_channelFaces.end()) {
@@ -88,10 +89,10 @@
//creating a new socket for the face that will be created soon
shared_ptr<ip::udp::socket> clientSocket =
make_shared<ip::udp::socket>(boost::ref(getGlobalIoService()));
-
+
clientSocket->open(m_localEndpoint.protocol());
clientSocket->set_option(ip::udp::socket::reuse_address(true));
-
+
try {
clientSocket->bind(m_localEndpoint);
clientSocket->connect(remoteEndpoint); //@todo connect or async_connect
@@ -101,8 +102,8 @@
}
catch (boost::system::system_error& e) {
clientSocket->close();
- throw Error("Failed to properly configure the socket. Check the address ("
- + std::string(e.what()) + ")");
+ onConnectFailed("Failed to configure socket (" + std::string(e.what()) + ")");
+ return;
}
createFace(clientSocket, onFaceCreated, false);
}
@@ -144,7 +145,7 @@
return;
}
- connect(*remoteEndpoint, onFaceCreated);
+ connect(*remoteEndpoint, onFaceCreated, onConnectFailed);
}
size_t
@@ -229,7 +230,7 @@
UdpChannel::closeIdleFaces()
{
ChannelFaceMap::iterator next = m_channelFaces.begin();
-
+
while (next != m_channelFaces.end()) {
ChannelFaceMap::iterator it = next;
next++;