#include <log/dummylog.h>
+#include <exceptions/exceptions.h>
+
#include <asio.hpp>
#include <dns_service.h>
#include <asiolink/io_service.h>
}
void DNSService::addServerUDPFromFD(int fd, int af, ServerFlag options) {
+ if ((~SERVER_DEFINED_FLAGS & static_cast<int>(options)) != 0) {
+ isc_throw(isc::InvalidParameter, "Invalid DNS/UDP server option: "
+ << options);
+ }
if ((options & SERVER_SYNC_OK) != 0) {
impl_->addServerFromFD<DNSServiceImpl::SyncUDPServerPtr,
SyncUDPServer>(fd, af);
///< information given by the client.
};
+public:
/// \brief The destructor.
virtual ~DNSServiceBase() {}
DNSService(const DNSService& source);
DNSService& operator=(const DNSService& source);
+private:
+ // Bit or'ed all defined \c ServerFlag values. Used internally for
+ // compatibility check. Note that this doesn't have to be used by
+ // applications, and doesn't have to be defined in the "base" class.
+ static const unsigned int SERVER_DEFINED_FLAGS = 1;
+
public:
/// \brief The constructor with a specific IP address and port on which
/// the services listen on.
/// AF_INET or AF_INET6.
/// \param options Optional properties of the server (see ServerFlag).
///
- /// \throw isc::InvalidParameter if af is neither AF_INET nor AF_INET6.
+ /// \throw isc::InvalidParameter if af is neither AF_INET nor AF_INET6,
+ /// or the given \c options include an unsupported or invalid value.
/// \throw isc::asiolink::IOError when a low-level error happens, like the
/// fd is not a valid descriptor or it can't be listened on.
virtual void addServerUDPFromFD(int fd, int af,
#include <config.h>
#include <gtest/gtest.h>
+#include <exceptions/exceptions.h>
+
#include <asio.hpp>
#include <asiolink/asiolink.h>
#include <asiodns/asiodns.h>
EXPECT_EQ(first_buffer_, second_buffer_);
}
+TEST_F(UDPDNSServiceTest, addUDPServerFromFDWithUnknownOption) {
+ // Use of undefined/incompatible options should result in an exception.
+ EXPECT_THROW(dns_service.addServerUDPFromFD(
+ getSocketFD(AF_INET6, TEST_IPV6_ADDR, TEST_SERVER_PORT),
+ AF_INET6, static_cast<DNSService::ServerFlag>(2)),
+ isc::InvalidParameter);
+}
+
} // unnamed namespace