tests: fix UDP multicast transport tests with IPv6
A valid scope id is always required on the multicast address
Change-Id: Ic676fcde0ee50daf75eb38c137e3cb917f43699f
diff --git a/daemon/face/multicast-udp-transport.cpp b/daemon/face/multicast-udp-transport.cpp
index bcb799e..6082745 100644
--- a/daemon/face/multicast-udp-transport.cpp
+++ b/daemon/face/multicast-udp-transport.cpp
@@ -134,7 +134,7 @@
MulticastUdpTransport::openRxSocket(protocol::socket& sock,
const protocol::endpoint& multicastGroup,
const boost::asio::ip::address& localAddress,
- const shared_ptr<const ndn::net::NetworkInterface>& netif)
+ const ndn::net::NetworkInterface* netif)
{
BOOST_ASSERT(!sock.is_open());
@@ -148,16 +148,9 @@
localAddress.to_v4()));
}
else {
- BOOST_ASSERT(localAddress.is_v6());
+ BOOST_ASSERT(multicastGroup.address().to_v6().scope_id() != 0);
sock.set_option(boost::asio::ip::v6_only(true));
-#ifdef NFD_WITH_TESTS
- // To simplify unit tests, we bind to the "any" IPv6 address if the supplied multicast
- // address lacks a scope id. Calling bind() without a scope id would otherwise fail.
- if (multicastGroup.address().to_v6().scope_id() == 0)
- sock.bind(protocol::endpoint(boost::asio::ip::address_v6::any(), multicastGroup.port()));
- else
-#endif
- sock.bind(multicastGroup);
+ sock.bind(multicastGroup);
sock.set_option(boost::asio::ip::multicast::join_group(multicastGroup.address().to_v6()));
}
@@ -168,7 +161,7 @@
void
MulticastUdpTransport::openTxSocket(protocol::socket& sock,
const protocol::endpoint& localEndpoint,
- const shared_ptr<const ndn::net::NetworkInterface>& netif,
+ const ndn::net::NetworkInterface* netif,
bool enableLoopback)
{
BOOST_ASSERT(!sock.is_open());
diff --git a/daemon/face/multicast-udp-transport.hpp b/daemon/face/multicast-udp-transport.hpp
index 23c1e1d..5295238 100644
--- a/daemon/face/multicast-udp-transport.hpp
+++ b/daemon/face/multicast-udp-transport.hpp
@@ -62,16 +62,22 @@
ssize_t
getSendQueueLength() final;
+ /**
+ * \brief Opens and configures the receive-side socket
+ */
static void
openRxSocket(protocol::socket& sock,
const protocol::endpoint& multicastGroup,
- const boost::asio::ip::address& localAddress,
- const shared_ptr<const ndn::net::NetworkInterface>& netif = nullptr);
+ const boost::asio::ip::address& localAddress = {},
+ const ndn::net::NetworkInterface* netif = nullptr);
+ /**
+ * \brief Opens and configures the transmit-side socket
+ */
static void
openTxSocket(protocol::socket& sock,
const protocol::endpoint& localEndpoint,
- const shared_ptr<const ndn::net::NetworkInterface>& netif = nullptr,
+ const ndn::net::NetworkInterface* netif = nullptr,
bool enableLoopback = false);
private:
diff --git a/daemon/face/udp-factory.cpp b/daemon/face/udp-factory.cpp
index 331174d..fafa29e 100644
--- a/daemon/face/udp-factory.cpp
+++ b/daemon/face/udp-factory.cpp
@@ -324,7 +324,7 @@
}
shared_ptr<Face>
-UdpFactory::createMulticastFace(const shared_ptr<const net::NetworkInterface>& netif,
+UdpFactory::createMulticastFace(const net::NetworkInterface& netif,
const ip::address& localAddress,
const udp::Endpoint& multicastEndpoint)
{
@@ -337,7 +337,7 @@
if (mcastEp.address().is_v6()) {
// in IPv6, a scope id on the multicast address is always required
auto mcastAddress = mcastEp.address().to_v6();
- mcastAddress.scope_id(netif->getIndex());
+ mcastAddress.scope_id(netif.getIndex());
mcastEp.address(mcastAddress);
}
@@ -358,9 +358,9 @@
}
ip::udp::socket rxSock(getGlobalIoService());
- MulticastUdpTransport::openRxSocket(rxSock, mcastEp, localAddress, netif);
+ MulticastUdpTransport::openRxSocket(rxSock, mcastEp, localAddress, &netif);
ip::udp::socket txSock(getGlobalIoService());
- MulticastUdpTransport::openTxSocket(txSock, udp::Endpoint(localAddress, 0), netif);
+ MulticastUdpTransport::openTxSocket(txSock, udp::Endpoint(localAddress, 0), &netif);
GenericLinkService::Options options;
options.allowCongestionMarking = m_wantCongestionMarking;
@@ -442,7 +442,7 @@
std::vector<shared_ptr<Face>> faces;
for (const auto& addr : addrs) {
- auto face = this->createMulticastFace(netif, addr,
+ auto face = this->createMulticastFace(*netif, addr,
addr.is_v4() ? m_mcastConfig.group : m_mcastConfig.groupV6);
if (face->getId() == INVALID_FACEID) {
// new face: register with forwarding
diff --git a/daemon/face/udp-factory.hpp b/daemon/face/udp-factory.hpp
index 475621d..f0cd686 100644
--- a/daemon/face/udp-factory.hpp
+++ b/daemon/face/udp-factory.hpp
@@ -90,7 +90,7 @@
* \throw UdpFactory::Error
*/
shared_ptr<Face>
- createMulticastFace(const shared_ptr<const ndn::net::NetworkInterface>& netif,
+ createMulticastFace(const ndn::net::NetworkInterface& netif,
const boost::asio::ip::address& localAddress,
const udp::Endpoint& multicastEndpoint);