From ca53ac6b003ef1d0bd630fd3074fe3ef38967c07 Mon Sep 17 00:00:00 2001 From: Steve DiBenedetto Date: Thu, 27 Mar 2014 19:58:40 -0600 Subject: [PATCH] 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 --- daemon/core/network-interface.cpp | 11 ++++ daemon/core/network-interface.hpp | 12 ++++ daemon/face/tcp-factory.cpp | 87 +++++++++++++++++++++++++ daemon/face/tcp-factory.hpp | 12 ++++ daemon/face/udp-channel.cpp | 23 +++---- daemon/face/udp-channel.hpp | 3 +- daemon/face/udp-factory.cpp | 104 +++++++++++++++++++++++++++++- daemon/face/udp-factory.hpp | 36 +++++++---- daemon/mgmt/face-manager.cpp | 61 ++++++++++++++++-- tests/face/tcp.cpp | 34 ++++++---- tests/mgmt/face-manager.cpp | 2 +- 11 files changed, 342 insertions(+), 43 deletions(-) diff --git a/daemon/core/network-interface.cpp b/daemon/core/network-interface.cpp index ef55e7b5..c1cfaa67 100644 --- a/daemon/core/network-interface.cpp +++ b/daemon/core/network-interface.cpp @@ -95,6 +95,17 @@ listNetworkInterfaces() break; #endif } + + if (netif->isBroadcastCapable() && ifa->ifa_broadaddr != 0) + { + const sockaddr_in* sin = reinterpret_cast(ifa->ifa_broadaddr); + + char address[INET_ADDRSTRLEN]; + if (::inet_ntop(AF_INET, &sin->sin_addr, address, sizeof(address))) + netif->broadcastAddress = boost::asio::ip::address_v4::from_string(address); + else + NFD_LOG_WARN("inet_ntop() failed on " << ifname); + } } ::freeifaddrs(ifa_list); diff --git a/daemon/core/network-interface.hpp b/daemon/core/network-interface.hpp index d02171ab..0265461c 100644 --- a/daemon/core/network-interface.hpp +++ b/daemon/core/network-interface.hpp @@ -17,11 +17,13 @@ namespace nfd { class NetworkInterfaceInfo { public: + int index; std::string name; ethernet::Address etherAddress; std::vector ipv4Addresses; std::vector ipv6Addresses; + boost::asio::ip::address_v4 broadcastAddress; unsigned int flags; bool @@ -30,8 +32,12 @@ public: bool isMulticastCapable() const; + bool + isBroadcastCapable() const; + bool isUp() const; + }; inline bool @@ -46,6 +52,12 @@ NetworkInterfaceInfo::isMulticastCapable() const return (flags & IFF_MULTICAST) != 0; } +inline bool +NetworkInterfaceInfo::isBroadcastCapable() const +{ + return (flags & IFF_BROADCAST) != 0; +} + inline bool NetworkInterfaceInfo::isUp() const { diff --git a/daemon/face/tcp-factory.cpp b/daemon/face/tcp-factory.cpp index d301350e..cd3119e0 100644 --- a/daemon/face/tcp-factory.cpp +++ b/daemon/face/tcp-factory.cpp @@ -7,6 +7,7 @@ #include "tcp-factory.hpp" #include "core/resolver.hpp" #include "core/logger.hpp" +#include "core/network-interface.hpp" NFD_LOG_INIT("TcpFactory"); @@ -15,6 +16,78 @@ namespace nfd { TcpFactory::TcpFactory(const std::string& defaultPort/* = "6363"*/) : m_defaultPort(defaultPort) { + +} + +void +TcpFactory::prohibitEndpoint(const tcp::Endpoint& endpoint) +{ + using namespace boost::asio::ip; + + static const address_v4 ALL_V4_ENDPOINT(address_v4::from_string("0.0.0.0")); + static const address_v6 ALL_V6_ENDPOINT(address_v6::from_string("::")); + + const address& address = endpoint.address(); + + if (address.is_v4() && address == ALL_V4_ENDPOINT) + { + prohibitAllIpv4Endpoints(endpoint.port()); + } + else if (endpoint.address().is_v6() && address == ALL_V6_ENDPOINT) + { + prohibitAllIpv6Endpoints(endpoint.port()); + } + + NFD_LOG_TRACE("prohibiting TCP " << + endpoint.address().to_string() << ":" << endpoint.port()); + + m_prohibitedEndpoints.insert(endpoint); +} + +void +TcpFactory::prohibitAllIpv4Endpoints(const uint16_t port) +{ + using namespace boost::asio::ip; + + const std::list > nicList(listNetworkInterfaces()); + + for (std::list >::const_iterator i = nicList.begin(); + i != nicList.end(); + ++i) + { + const shared_ptr& nic = *i; + const std::vector& ipv4Addresses = nic->ipv4Addresses; + + for (std::vector::const_iterator j = ipv4Addresses.begin(); + j != ipv4Addresses.end(); + ++j) + { + prohibitEndpoint(tcp::Endpoint(*j, port)); + } + } +} + +void +TcpFactory::prohibitAllIpv6Endpoints(const uint16_t port) +{ + using namespace boost::asio::ip; + + const std::list > nicList(listNetworkInterfaces()); + + for (std::list >::const_iterator i = nicList.begin(); + i != nicList.end(); + ++i) + { + const shared_ptr& nic = *i; + const std::vector& ipv6Addresses = nic->ipv6Addresses; + + for (std::vector::const_iterator j = ipv6Addresses.begin(); + j != ipv6Addresses.end(); + ++j) + { + prohibitEndpoint(tcp::Endpoint(*j, port)); + } + } } shared_ptr @@ -26,6 +99,8 @@ TcpFactory::createChannel(const tcp::Endpoint& endpoint) channel = make_shared(boost::cref(endpoint)); m_channels[endpoint] = channel; + prohibitEndpoint(endpoint); + NFD_LOG_DEBUG("Channel [" << endpoint << "] created"); return channel; } @@ -57,6 +132,11 @@ TcpFactory::createFace(const FaceUri& uri, else if (uri.getScheme() == "tcp6") addressSelector = resolver::Ipv6Address(); + if (!uri.getPath().empty()) + { + onConnectFailed("Invalid URI"); + } + TcpResolver::asyncResolve(uri.getHost(), uri.getPort().empty() ? m_defaultPort : uri.getPort(), bind(&TcpFactory::continueCreateFaceAfterResolve, this, _1, @@ -70,6 +150,13 @@ TcpFactory::continueCreateFaceAfterResolve(const tcp::Endpoint& endpoint, const FaceCreatedCallback& onCreated, const FaceConnectFailedCallback& onConnectFailed) { + if (m_prohibitedEndpoints.find(endpoint) != m_prohibitedEndpoints.end()) + { + onConnectFailed("Requested endpoint is prohibited " + "(reserved by this NFD or disallowed by face management protocol)"); + return; + } + // very simple logic for now for (ChannelMap::iterator channel = m_channels.begin(); diff --git a/daemon/face/tcp-factory.hpp b/daemon/face/tcp-factory.hpp index 6ba2e379..d4b66183 100644 --- a/daemon/face/tcp-factory.hpp +++ b/daemon/face/tcp-factory.hpp @@ -67,6 +67,16 @@ public: const FaceConnectFailedCallback& onConnectFailed); private: + + void + prohibitEndpoint(const tcp::Endpoint& endpoint); + + void + prohibitAllIpv4Endpoints(const uint16_t port); + + void + prohibitAllIpv6Endpoints(const uint16_t port); + /** * \brief Look up TcpChannel using specified local endpoint * @@ -88,6 +98,8 @@ private: ChannelMap m_channels; std::string m_defaultPort; + + std::set m_prohibitedEndpoints; }; } // namespace nfd diff --git a/daemon/face/udp-channel.cpp b/daemon/face/udp-channel.cpp index 390b4122..49c22b78 100644 --- a/daemon/face/udp-channel.cpp +++ b/daemon/face/udp-channel.cpp @@ -31,7 +31,7 @@ UdpChannel::UdpChannel(const udp::Endpoint& localEndpoint, { m_socket->set_option(ip::v6_only(true)); } - + try { m_socket->bind(m_localEndpoint); } @@ -41,9 +41,9 @@ UdpChannel::UdpChannel(const udp::Endpoint& localEndpoint, 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 @@ UdpChannel::listen(const FaceCreatedCallback& onFaceCreated, throw Error("Listen already called on this channel"); } m_isListening = true; - + onFaceCreatedNewPeerCallback = onFaceCreated; onConnectFailedNewPeerCallback = onListenFailed; @@ -76,7 +76,8 @@ UdpChannel::listen(const FaceCreatedCallback& onFaceCreated, 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 @@ UdpChannel::connect(const udp::Endpoint& remoteEndpoint, //creating a new socket for the face that will be created soon shared_ptr clientSocket = make_shared(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 @@ UdpChannel::connect(const udp::Endpoint& remoteEndpoint, } 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 @@ UdpChannel::handleEndpointResolution(const boost::system::error_code& error, return; } - connect(*remoteEndpoint, onFaceCreated); + connect(*remoteEndpoint, onFaceCreated, onConnectFailed); } size_t @@ -229,7 +230,7 @@ void UdpChannel::closeIdleFaces() { ChannelFaceMap::iterator next = m_channelFaces.begin(); - + while (next != m_channelFaces.end()) { ChannelFaceMap::iterator it = next; next++; diff --git a/daemon/face/udp-channel.hpp b/daemon/face/udp-channel.hpp index 0243dd69..f5dd16e8 100644 --- a/daemon/face/udp-channel.hpp +++ b/daemon/face/udp-channel.hpp @@ -69,7 +69,8 @@ public: */ void connect(const udp::Endpoint& remoteEndpoint, - const FaceCreatedCallback& onFaceCreated); + const FaceCreatedCallback& onFaceCreated, + const ConnectFailedCallback& onConnectFailed); /** * \brief Create a face by establishing connection to the specified * remote host and remote port diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp index 36b1fcd4..e99961a7 100644 --- a/daemon/face/udp-factory.cpp +++ b/daemon/face/udp-factory.cpp @@ -7,6 +7,7 @@ #include "udp-factory.hpp" #include "core/global-io.hpp" #include "core/resolver.hpp" +#include "core/network-interface.hpp" namespace nfd { @@ -19,6 +20,89 @@ UdpFactory::UdpFactory(const std::string& defaultPort/* = "6363"*/) { } + + +void +UdpFactory::prohibitEndpoint(const udp::Endpoint& endpoint) +{ + using namespace boost::asio::ip; + + static const address_v4 ALL_V4_ENDPOINT(address_v4::from_string("0.0.0.0")); + static const address_v6 ALL_V6_ENDPOINT(address_v6::from_string("::")); + + const address& address = endpoint.address(); + + if (address.is_v4() && address == ALL_V4_ENDPOINT) + { + prohibitAllIpv4Endpoints(endpoint.port()); + } + else if (endpoint.address().is_v6() && address == ALL_V6_ENDPOINT) + { + prohibitAllIpv6Endpoints(endpoint.port()); + } + + NFD_LOG_TRACE("prohibiting UDP " << + endpoint.address().to_string() << ":" << endpoint.port()); + + m_prohibitedEndpoints.insert(endpoint); +} + +void +UdpFactory::prohibitAllIpv4Endpoints(const uint16_t port) +{ + using namespace boost::asio::ip; + + static const address_v4 INVALID_BROADCAST(address_v4::from_string("0.0.0.0")); + + const std::list > nicList(listNetworkInterfaces()); + + for (std::list >::const_iterator i = nicList.begin(); + i != nicList.end(); + ++i) + { + const shared_ptr& nic = *i; + const std::vector& ipv4Addresses = nic->ipv4Addresses; + + for (std::vector::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)); + } + } + + prohibitEndpoint(udp::Endpoint(address::from_string("255.255.255.255"), port)); +} + +void +UdpFactory::prohibitAllIpv6Endpoints(const uint16_t port) +{ + using namespace boost::asio::ip; + + const std::list > nicList(listNetworkInterfaces()); + + for (std::list >::const_iterator i = nicList.begin(); + i != nicList.end(); + ++i) + { + const shared_ptr& nic = *i; + const std::vector& ipv6Addresses = nic->ipv6Addresses; + + for (std::vector::const_iterator j = ipv6Addresses.begin(); + j != ipv6Addresses.end(); + ++j) + { + prohibitEndpoint(udp::Endpoint(*j, port)); + } + } +} + shared_ptr UdpFactory::createChannel(const udp::Endpoint& endpoint, const time::seconds& timeout) @@ -45,6 +129,7 @@ UdpFactory::createChannel(const udp::Endpoint& endpoint, channel = make_shared(boost::cref(endpoint), timeout); m_channels[endpoint] = channel; + prohibitEndpoint(endpoint); return channel; } @@ -80,6 +165,11 @@ UdpFactory::createMulticastFace(const udp::Endpoint& localEndpoint, "endpoint is already allocated for a UDP unicast channel"); } + if (m_prohibitedEndpoints.find(multicastEndpoint) != m_prohibitedEndpoints.end()) { + throw Error("Cannot create the requested UDP multicast face, " + "remote endpoint is owned by this NFD instance"); + } + if (localEndpoint.address().is_v6() || multicastEndpoint.address().is_v6()) { throw Error("IPv6 multicast is not supported yet. Please provide an IPv4 address"); } @@ -149,6 +239,11 @@ UdpFactory::createFace(const FaceUri& uri, else if (uri.getScheme() == "udp6") addressSelector = resolver::Ipv6Address(); + if (!uri.getPath().empty()) + { + onConnectFailed("Invalid URI"); + } + UdpResolver::asyncResolve(uri.getHost(), uri.getPort().empty() ? m_defaultPort : uri.getPort(), bind(&UdpFactory::continueCreateFaceAfterResolve, this, _1, @@ -168,6 +263,13 @@ UdpFactory::continueCreateFaceAfterResolve(const udp::Endpoint& endpoint, return; } + if (m_prohibitedEndpoints.find(endpoint) != m_prohibitedEndpoints.end()) + { + onConnectFailed("Requested endpoint is prohibited " + "(reserved by this NFD or disallowed by face management protocol)"); + return; + } + // very simple logic for now for (ChannelMap::iterator channel = m_channels.begin(); @@ -177,7 +279,7 @@ UdpFactory::continueCreateFaceAfterResolve(const udp::Endpoint& endpoint, if ((channel->first.address().is_v4() && endpoint.address().is_v4()) || (channel->first.address().is_v6() && endpoint.address().is_v6())) { - channel->second->connect(endpoint, onCreated); + channel->second->connect(endpoint, onCreated, onConnectFailed); return; } } diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp index 969ef8c6..fe697941 100644 --- a/daemon/face/udp-factory.hpp +++ b/daemon/face/udp-factory.hpp @@ -26,7 +26,7 @@ public: { Error(const std::string& what) : ProtocolFactory::Error(what) {} }; - + explicit UdpFactory(const std::string& defaultPort = "6363"); @@ -66,10 +66,10 @@ public: * * Note that this call will **BLOCK** until resolution is done or failed. * - * If localHost is a IPv6 address of a specific device, it must be in the form: + * If localHost is a IPv6 address of a specific device, it must be in the form: * ip address%interface name * Example: fe80::5e96:9dff:fe7d:9c8d%en1 - * Otherwise, you can use :: + * Otherwise, you can use :: * * Once a face is created, if it doesn't send/receive anything for * a period of time equal to timeout, it will be destroyed @@ -98,7 +98,7 @@ public: * creation fails and an exception is thrown * * \returns always a valid pointer to a MulticastUdpFace object, an exception - * is thrown if it cannot be created. + * is thrown if it cannot be created. * * \throws UdpFactory::Error * @@ -108,12 +108,12 @@ public: shared_ptr createMulticastFace(const udp::Endpoint& localEndpoint, const udp::Endpoint& multicastEndpoint); - + shared_ptr createMulticastFace(const std::string& localIp, const std::string& multicastIp, const std::string& multicastPort); - + // from Factory virtual void createFace(const FaceUri& uri, @@ -129,9 +129,19 @@ protected: MulticastFaceMap m_multicastFaces; private: + + void + prohibitEndpoint(const udp::Endpoint& endpoint); + + void + prohibitAllIpv4Endpoints(const uint16_t port); + + void + prohibitAllIpv6Endpoints(const uint16_t port); + void afterFaceFailed(udp::Endpoint& endpoint); - + /** * \brief Look up UdpChannel using specified local endpoint * @@ -142,8 +152,8 @@ private: */ shared_ptr findChannel(const udp::Endpoint& localEndpoint); - - + + /** * \brief Look up multicast UdpFace using specified local endpoint * @@ -154,16 +164,18 @@ private: */ shared_ptr findMulticastFace(const udp::Endpoint& localEndpoint); - + void continueCreateFaceAfterResolve(const udp::Endpoint& endpoint, const FaceCreatedCallback& onCreated, const FaceConnectFailedCallback& onConnectFailed); - + typedef std::map< udp::Endpoint, shared_ptr > ChannelMap; ChannelMap m_channels; - + std::string m_defaultPort; + + std::set m_prohibitedEndpoints; }; } // namespace nfd diff --git a/daemon/mgmt/face-manager.cpp b/daemon/mgmt/face-manager.cpp index 183af176..406d524e 100644 --- a/daemon/mgmt/face-manager.cpp +++ b/daemon/mgmt/face-manager.cpp @@ -242,6 +242,16 @@ FaceManager::processSectionTcp(const ConfigSection& configSection, bool isDryRun if (i->first == "port") { port = i->second.get_value(); + try + { + uint16_t portNo = boost::lexical_cast(port); + NFD_LOG_TRACE("TCP port set to " << portNo); + } + catch (const std::bad_cast& error) + { + throw ConfigFile::Error("Invalid value for option " + + i->first + "\" in \"udp\" section"); + } } else if (i->first == "listen") { @@ -311,6 +321,16 @@ FaceManager::processSectionUdp(const ConfigSection& configSection, if (i->first == "port") { port = i->second.get_value(); + try + { + uint16_t portNo = boost::lexical_cast(port); + NFD_LOG_TRACE("UDP port set to " << portNo); + } + catch (const std::bad_cast& error) + { + throw ConfigFile::Error("Invalid value for option " + + i->first + "\" in \"udp\" section"); + } } else if (i->first == "idle_timeout") { @@ -346,6 +366,16 @@ FaceManager::processSectionUdp(const ConfigSection& configSection, else if (i->first == "mcast_port") { mcastPort = i->second.get_value(); + try + { + uint16_t portNo = boost::lexical_cast(mcastPort); + NFD_LOG_TRACE("UDP multicast port set to " << portNo); + } + catch (const std::bad_cast& error) + { + throw ConfigFile::Error("Invalid value for option " + + i->first + "\" in \"udp\" section"); + } } else if (i->first == "mcast_group") { @@ -581,7 +611,7 @@ void FaceManager::onConnectFailed(const Name& requestName, const std::string& reason) { NFD_LOG_DEBUG("Failed to create face: " << reason); - sendResponse(requestName, 400, "Failed to create face"); + sendResponse(requestName, 408, reason); } void @@ -594,6 +624,7 @@ FaceManager::createFace(const Interest& request, if (!validateParameters(command, parameters)) { sendResponse(requestName, 400, "Malformed command"); + NFD_LOG_TRACE("invalid control parameters URI"); return; } @@ -601,6 +632,7 @@ FaceManager::createFace(const Interest& request, if (!uri.parse(parameters.getUri())) { sendResponse(requestName, 400, "Malformed command"); + NFD_LOG_TRACE("failed to parse URI"); return; } @@ -611,9 +643,30 @@ FaceManager::createFace(const Interest& request, return; } - factory->second->createFace(uri, - bind(&FaceManager::onCreated, this, requestName, parameters, _1), - bind(&FaceManager::onConnectFailed, this, requestName, _1)); + try + { + factory->second->createFace(uri, + bind(&FaceManager::onCreated, + this, requestName, parameters, _1), + bind(&FaceManager::onConnectFailed, + this, requestName, _1)); + } + catch (const std::runtime_error& error) + { + std::string errorMessage = "NFD error: "; + errorMessage += error.what(); + + NFD_LOG_ERROR(errorMessage); + sendResponse(requestName, 500, errorMessage); + } + catch (const std::logic_error& error) + { + std::string errorMessage = "NFD error: "; + errorMessage += error.what(); + + NFD_LOG_ERROR(errorMessage); + sendResponse(requestName, 500, errorMessage); + } } diff --git a/tests/face/tcp.cpp b/tests/face/tcp.cpp index 6bbe4bad..b71de487 100644 --- a/tests/face/tcp.cpp +++ b/tests/face/tcp.cpp @@ -161,13 +161,12 @@ public: std::list< shared_ptr > faces; }; - BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) { - TcpFactory factory; + TcpFactory factory1; - shared_ptr channel1 = factory.createChannel("127.0.0.1", "20070"); - factory.createChannel("127.0.0.1", "20071"); + shared_ptr channel1 = factory1.createChannel("127.0.0.1", "20070"); + factory1.createChannel("127.0.0.1", "20071"); BOOST_CHECK_EQUAL(channel1->isListening(), false); @@ -176,9 +175,14 @@ BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) BOOST_CHECK_EQUAL(channel1->isListening(), true); - factory.createFace(FaceUri("tcp://127.0.0.1:20070"), - bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); + TcpFactory factory2; + + shared_ptr channel2 = factory2.createChannel("127.0.0.2", "20070"); + factory2.createChannel("127.0.0.2", "20071"); + + factory2.createFace(FaceUri("tcp://127.0.0.1:20070"), + bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), + bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, "TcpChannel error: cannot connect or cannot accept connection"); @@ -253,17 +257,21 @@ BOOST_FIXTURE_TEST_CASE(EndToEnd4, EndToEndFixture) BOOST_FIXTURE_TEST_CASE(EndToEnd6, EndToEndFixture) { - TcpFactory factory; + TcpFactory factory1; - shared_ptr channel1 = factory.createChannel("::1", "20070"); - shared_ptr channel2 = factory.createChannel("::1", "20071"); + shared_ptr channel1 = factory1.createChannel("::1", "20070"); + shared_ptr channel2 = factory1.createChannel("::1", "20071"); channel1->listen(bind(&EndToEndFixture::channel1_onFaceCreated, this, _1), bind(&EndToEndFixture::channel1_onConnectFailed, this, _1)); - factory.createFace(FaceUri("tcp://[::1]:20070"), - bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), - bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); + TcpFactory factory2; + + factory2.createChannel("::2", "20070"); + + factory2.createFace(FaceUri("tcp://[::1]:20070"), + bind(&EndToEndFixture::channel2_onFaceCreated, this, _1), + bind(&EndToEndFixture::channel2_onConnectFailed, this, _1)); BOOST_CHECK_MESSAGE(limitedIo.run(2, time::seconds(10)) == LimitedIo::EXCEED_OPS, "TcpChannel error: cannot connect or cannot accept connection"); diff --git a/tests/mgmt/face-manager.cpp b/tests/mgmt/face-manager.cpp index 4d6830c0..ebae6f79 100644 --- a/tests/mgmt/face-manager.cpp +++ b/tests/mgmt/face-manager.cpp @@ -1465,7 +1465,7 @@ BOOST_FIXTURE_TEST_CASE(OnConnectFailed, AuthorizedCommandFixture) getFace()->onReceiveData += bind(&FaceFixture::validateControlResponse, this, _1, - command->getName(), 400, "Failed to create face"); + command->getName(), 408, "unit-test-reason"); onConnectFailed(command->getName(), "unit-test-reason");