Parcourir la source

Merge branch 'trac1485'

Tomek Mrugalski il y a 11 ans
Parent
commit
ecdb62db16

+ 7 - 2
src/bin/d2/tests/nc_test_utils.cc

@@ -16,6 +16,8 @@
 #include <dns/opcode.h>
 #include <dns/opcode.h>
 #include <dns/messagerenderer.h>
 #include <dns/messagerenderer.h>
 #include <nc_test_utils.h>
 #include <nc_test_utils.h>
+#include <asio.hpp>
+#include <asiolink/udp_endpoint.h>
 
 
 #include <gtest/gtest.h>
 #include <gtest/gtest.h>
 
 
@@ -42,7 +44,9 @@ FauxServer::FauxServer(asiolink::IOService& io_service,
     server_socket_.reset(new asio::ip::udp::socket(io_service_.get_io_service(),
     server_socket_.reset(new asio::ip::udp::socket(io_service_.get_io_service(),
                                                    asio::ip::udp::v4()));
                                                    asio::ip::udp::v4()));
     server_socket_->set_option(asio::socket_base::reuse_address(true));
     server_socket_->set_option(asio::socket_base::reuse_address(true));
-    server_socket_->bind(asio::ip::udp::endpoint(address_.getAddress(), port_));
+
+    isc::asiolink::UDPEndpoint endpoint(address_, port_);
+    server_socket_->bind(endpoint.getASIOEndpoint());
 }
 }
 
 
 FauxServer::FauxServer(asiolink::IOService& io_service,
 FauxServer::FauxServer(asiolink::IOService& io_service,
@@ -53,7 +57,8 @@ FauxServer::FauxServer(asiolink::IOService& io_service,
     server_socket_.reset(new asio::ip::udp::socket(io_service_.get_io_service(),
     server_socket_.reset(new asio::ip::udp::socket(io_service_.get_io_service(),
                                                    asio::ip::udp::v4()));
                                                    asio::ip::udp::v4()));
     server_socket_->set_option(asio::socket_base::reuse_address(true));
     server_socket_->set_option(asio::socket_base::reuse_address(true));
-    server_socket_->bind(asio::ip::udp::endpoint(address_.getAddress(), port_));
+    isc::asiolink::UDPEndpoint endpoint(address_, port_);
+    server_socket_->bind(endpoint.getASIOEndpoint());
 }
 }
 
 
 
 

+ 16 - 5
src/lib/asiolink/io_address.cc

@@ -100,14 +100,25 @@ IOAddress::getFamily() const {
     }
     }
 }
 }
 
 
-const asio::ip::address&
-IOAddress::getAddress() const {
-    return asio_address_;
+bool
+IOAddress::isV6LinkLocal() const {
+    if (!asio_address_.is_v6()) {
+        return (false);
+    }
+    return (asio_address_.to_v6().is_link_local());
+}
+
+bool
+IOAddress::isV6Multicast() const {
+    if (!asio_address_.is_v6()) {
+        return (false);
+    }
+    return (asio_address_.to_v6().is_multicast());
 }
 }
 
 
 IOAddress::operator uint32_t() const {
 IOAddress::operator uint32_t() const {
-    if (getAddress().is_v4()) {
-        return (getAddress().to_v4().to_ulong());
+    if (asio_address_.is_v4()) {
+        return (asio_address_.to_v4().to_ulong());
     } else {
     } else {
         isc_throw(BadValue, "Can't convert " << toText()
         isc_throw(BadValue, "Can't convert " << toText()
                   << " address to IPv4.");
                   << " address to IPv4.");

+ 10 - 8
src/lib/asiolink/io_address.h

@@ -91,14 +91,6 @@ public:
     /// \return A string representation of the address.
     /// \return A string representation of the address.
     std::string toText() const;
     std::string toText() const;
 
 
-    /// \brief Returns const reference to the underlying address object.
-    ///
-    /// This is useful, when access to interface offerted by
-    //  asio::ip::address_v4 and asio::ip::address_v6 is beneficial.
-    /// 
-    /// \return A const reference to asio::ip::address object
-    const asio::ip::address& getAddress() const;
-
     /// \brief Returns the address family
     /// \brief Returns the address family
     ///
     ///
     /// \return AF_INET for IPv4 or AF_INET6 for IPv6.
     /// \return AF_INET for IPv4 or AF_INET6 for IPv6.
@@ -118,6 +110,16 @@ public:
         return (asio_address_.is_v6());
         return (asio_address_.is_v6());
     }
     }
 
 
+    /// \brief checks whether and address is IPv6 and is link-local
+    ///
+    /// \return true if the address is IPv6 link-local, false otherwise
+    bool isV6LinkLocal() const;
+
+    /// \brief checks whether and address is IPv6 and is multicast
+    ///
+    /// \return true if the address is IPv6 multicast, false otherwise
+    bool isV6Multicast() const;
+
     /// \brief Creates an address from over wire data.
     /// \brief Creates an address from over wire data.
     ///
     ///
     /// \param family AF_NET for IPv4 or AF_NET6 for IPv6.
     /// \param family AF_NET for IPv4 or AF_NET6 for IPv6.

+ 35 - 0
src/lib/asiolink/tests/io_address_unittest.cc

@@ -182,3 +182,38 @@ TEST(IOAddressTest, LeftShiftOperator) {
     oss << addr;
     oss << addr;
     EXPECT_EQ(addr.toText(), oss.str());
     EXPECT_EQ(addr.toText(), oss.str());
 }
 }
+
+// Tests address classification methods (which were previously used by accessing
+// underlying asio objects directly)
+TEST(IOAddressTest, accessClassificationMethods) {
+    IOAddress addr1("192.0.2.5"); // IPv4
+    IOAddress addr2("::");  // IPv6
+    IOAddress addr3("2001:db8::1"); // global IPv6
+    IOAddress addr4("fe80::1234");  // link-local
+    IOAddress addr5("ff02::1:2");   // multicast
+
+    EXPECT_TRUE (addr1.isV4());
+    EXPECT_FALSE(addr1.isV6());
+    EXPECT_FALSE(addr1.isV6LinkLocal());
+    EXPECT_FALSE(addr1.isV6Multicast());
+
+    EXPECT_FALSE(addr2.isV4());
+    EXPECT_TRUE (addr2.isV6());
+    EXPECT_FALSE(addr2.isV6LinkLocal());
+    EXPECT_FALSE(addr2.isV6Multicast());
+
+    EXPECT_FALSE(addr3.isV4());
+    EXPECT_TRUE (addr3.isV6());
+    EXPECT_FALSE(addr3.isV6LinkLocal());
+    EXPECT_FALSE(addr3.isV6Multicast());
+
+    EXPECT_FALSE(addr4.isV4());
+    EXPECT_TRUE (addr4.isV6());
+    EXPECT_TRUE (addr4.isV6LinkLocal());
+    EXPECT_FALSE(addr4.isV6Multicast());
+
+    EXPECT_FALSE(addr5.isV4());
+    EXPECT_TRUE (addr5.isV6());
+    EXPECT_FALSE(addr5.isV6LinkLocal());
+    EXPECT_TRUE (addr5.isV6Multicast());
+}

+ 7 - 7
src/lib/dhcp/iface_mgr.cc

@@ -523,7 +523,7 @@ IfaceMgr::openSockets6(const uint16_t port,
             // with interface with 2 global addresses, we would bind 3 sockets
             // with interface with 2 global addresses, we would bind 3 sockets
             // (one for link-local and two for global). That would result in
             // (one for link-local and two for global). That would result in
             // getting each message 3 times.
             // getting each message 3 times.
-            if (!addr->getAddress().to_v6().is_link_local()){
+            if (!addr->isV6LinkLocal()){
                 continue;
                 continue;
             }
             }
 
 
@@ -693,7 +693,7 @@ int IfaceMgr::openSocketFromRemoteAddress(const IOAddress& remote_addr,
                                           const uint16_t port) {
                                           const uint16_t port) {
     try {
     try {
         // Get local address to be used to connect to remote location.
         // Get local address to be used to connect to remote location.
-        IOAddress local_address(getLocalAddress(remote_addr, port).getAddress());
+        IOAddress local_address(getLocalAddress(remote_addr, port));
         return openSocketFromAddress(local_address, port);
         return openSocketFromAddress(local_address, port);
     } catch (const Exception& e) {
     } catch (const Exception& e) {
         isc_throw(SocketConfigError, e.what());
         isc_throw(SocketConfigError, e.what());
@@ -1033,7 +1033,7 @@ uint16_t IfaceMgr::getSocket(const isc::dhcp::Pkt6& pkt) {
         }
         }
 
 
         // Sockets bound to multicast address are useless for sending anything.
         // Sockets bound to multicast address are useless for sending anything.
-        if (s->addr_.getAddress().to_v6().is_multicast()) {
+        if (s->addr_.isV6Multicast()) {
             continue;
             continue;
         }
         }
 
 
@@ -1050,10 +1050,10 @@ uint16_t IfaceMgr::getSocket(const isc::dhcp::Pkt6& pkt) {
             // If we want to send something to link-local and the socket is
             // If we want to send something to link-local and the socket is
             // bound to link-local or we want to send to global and the socket
             // bound to link-local or we want to send to global and the socket
             // is bound to global, then use it as candidate
             // is bound to global, then use it as candidate
-            if ( (pkt.getRemoteAddr().getAddress().to_v6().is_link_local() &&
-                s->addr_.getAddress().to_v6().is_link_local()) ||
-                 (!pkt.getRemoteAddr().getAddress().to_v6().is_link_local() &&
-                  !s->addr_.getAddress().to_v6().is_link_local()) ) {
+            if ( (pkt.getRemoteAddr().isV6LinkLocal() &&
+                s->addr_.isV6LinkLocal()) ||
+                 (!pkt.getRemoteAddr().isV6LinkLocal() &&
+                  !s->addr_.isV6LinkLocal()) ) {
                 candidate = s;
                 candidate = s;
             }
             }
         }
         }

+ 3 - 4
src/lib/dhcp_ddns/ncr_udp.cc

@@ -94,7 +94,7 @@ NameChangeUDPListener::~NameChangeUDPListener() {
 void
 void
 NameChangeUDPListener::open(isc::asiolink::IOService& io_service) {
 NameChangeUDPListener::open(isc::asiolink::IOService& io_service) {
     // create our endpoint and bind the the low level socket to it.
     // create our endpoint and bind the the low level socket to it.
-    isc::asiolink::UDPEndpoint endpoint(ip_address_.getAddress(), port_);
+    isc::asiolink::UDPEndpoint endpoint(ip_address_, port_);
 
 
     // Create the low level socket.
     // Create the low level socket.
     try {
     try {
@@ -227,7 +227,7 @@ NameChangeUDPSender::~NameChangeUDPSender() {
 void
 void
 NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
 NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
     // create our endpoint and bind the the low level socket to it.
     // create our endpoint and bind the the low level socket to it.
-    isc::asiolink::UDPEndpoint endpoint(ip_address_.getAddress(), port_);
+    isc::asiolink::UDPEndpoint endpoint(ip_address_, port_);
 
 
     // Create the low level socket.
     // Create the low level socket.
     try {
     try {
@@ -252,8 +252,7 @@ NameChangeUDPSender::open(isc::asiolink::IOService& io_service) {
 
 
     // Create the server endpoint
     // Create the server endpoint
     server_endpoint_.reset(new isc::asiolink::
     server_endpoint_.reset(new isc::asiolink::
-                           UDPEndpoint(server_address_.getAddress(),
-                                       server_port_));
+                           UDPEndpoint(server_address_, server_port_));
 
 
     send_callback_->setDataSource(server_endpoint_);
     send_callback_->setDataSource(server_endpoint_);
 }
 }

+ 1 - 1
src/lib/dhcpsrv/cfgmgr.cc

@@ -152,7 +152,7 @@ CfgMgr::getSubnet6(const isc::asiolink::IOAddress& hint) {
     // configuration. Such requirement makes sense in IPv4, but not in IPv6.
     // configuration. Such requirement makes sense in IPv4, but not in IPv6.
     // The server does not need to have a global address (using just link-local
     // The server does not need to have a global address (using just link-local
     // is ok for DHCPv6 server) from the pool it serves.
     // is ok for DHCPv6 server) from the pool it serves.
-    if ((subnets6_.size() == 1) && hint.getAddress().to_v6().is_link_local()) {
+    if ((subnets6_.size() == 1) && hint.isV6LinkLocal()) {
         LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
         LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE,
                   DHCPSRV_CFGMGR_ONLY_SUBNET6)
                   DHCPSRV_CFGMGR_ONLY_SUBNET6)
                   .arg(subnets6_[0]->toText()).arg(hint.toText());
                   .arg(subnets6_[0]->toText()).arg(hint.toText());

+ 1 - 1
src/lib/dhcpsrv/d2_client.cc

@@ -36,7 +36,7 @@ D2ClientConfig::D2ClientConfig(const  bool enable_updates,
                                const std::string& generated_prefix,
                                const std::string& generated_prefix,
                                const std::string& qualifying_suffix)
                                const std::string& qualifying_suffix)
     : enable_updates_(enable_updates),
     : enable_updates_(enable_updates),
-    server_ip_(server_ip.getAddress()),
+    server_ip_(server_ip),
     server_port_(server_port),
     server_port_(server_port),
     ncr_protocol_(ncr_protocol),
     ncr_protocol_(ncr_protocol),
     ncr_format_(ncr_format),
     ncr_format_(ncr_format),

+ 3 - 4
tests/tools/perfdhcp/test_control.cc

@@ -777,8 +777,7 @@ TestControl::openSocket() const {
     } else if (options.getIpVersion() == 6) {
     } else if (options.getIpVersion() == 6) {
         // If remote address is multicast we need to enable it on
         // If remote address is multicast we need to enable it on
         // the socket that has been created.
         // the socket that has been created.
-        asio::ip::address_v6 remote_v6 = remoteaddr.getAddress().to_v6();
-        if (remote_v6.is_multicast()) {
+        if (remoteaddr.isV6Multicast()) {
             int hops = 1;
             int hops = 1;
             int ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
             int ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
                                  &hops, sizeof(hops));
                                  &hops, sizeof(hops));
@@ -1640,7 +1639,7 @@ TestControl::sendRequest4(const TestControlSocket& socket,
 
 
     /// Set client address.
     /// Set client address.
     asiolink::IOAddress yiaddr = offer_pkt4->getYiaddr();
     asiolink::IOAddress yiaddr = offer_pkt4->getYiaddr();
-    if (!yiaddr.getAddress().is_v4()) {
+    if (!yiaddr.isV4()) {
         isc_throw(BadValue, "the YIADDR returned in OFFER packet is not "
         isc_throw(BadValue, "the YIADDR returned in OFFER packet is not "
                   " IPv4 address");
                   " IPv4 address");
     }
     }
@@ -1748,7 +1747,7 @@ TestControl::sendRequest4(const TestControlSocket& socket,
 
 
     /// Set client address.
     /// Set client address.
     asiolink::IOAddress yiaddr = offer_pkt4->getYiaddr();
     asiolink::IOAddress yiaddr = offer_pkt4->getYiaddr();
-    if (!yiaddr.getAddress().is_v4()) {
+    if (!yiaddr.isV4()) {
         isc_throw(BadValue, "the YIADDR returned in OFFER packet is not "
         isc_throw(BadValue, "the YIADDR returned in OFFER packet is not "
                   " IPv4 address");
                   " IPv4 address");
     }
     }