diff options
author | Thomas Markwalder <tmark@isc.org> | 2022-11-08 21:44:21 +0100 |
---|---|---|
committer | Thomas Markwalder <tmark@isc.org> | 2022-11-10 20:43:23 +0100 |
commit | 2b9f0c74468cccdd59ef6a16089282cfec3a705e (patch) | |
tree | 3a737e34542687a633742c4dde7418cb91c75823 /src/lib/tcp | |
parent | [#2583] Added connection filter callback (diff) | |
download | kea-2b9f0c74468cccdd59ef6a16089282cfec3a705e.tar.xz kea-2b9f0c74468cccdd59ef6a16089282cfec3a705e.zip |
[#2583] Make connection filter optional
Diffstat (limited to 'src/lib/tcp')
-rw-r--r-- | src/lib/tcp/tcp_connection.cc | 2 | ||||
-rw-r--r-- | src/lib/tcp/tcp_listener.h | 2 | ||||
-rw-r--r-- | src/lib/tcp/tests/tcp_listener_unittests.cc | 22 |
3 files changed, 8 insertions, 18 deletions
diff --git a/src/lib/tcp/tcp_connection.cc b/src/lib/tcp/tcp_connection.cc index aa90f9f86a..2f12a579b7 100644 --- a/src/lib/tcp/tcp_connection.cc +++ b/src/lib/tcp/tcp_connection.cc @@ -288,7 +288,7 @@ TcpConnection::acceptorCallback(const boost::system::error_code& ec) { acceptor_callback_(ec); if (!ec) { - if (!(connection_filter_(getRemoteEndpointAddressAsText()))) { + if (connection_filter_ && !(connection_filter_(getRemoteEndpointAddressAsText()))) { LOG_DEBUG(tcp_logger, isc::log::DBGLVL_TRACE_DETAIL, TCP_CONNECTION_REJECTED_BY_FILTER) .arg(getRemoteEndpointAddressAsText()); diff --git a/src/lib/tcp/tcp_listener.h b/src/lib/tcp/tcp_listener.h index 8086399e9b..fa69766e96 100644 --- a/src/lib/tcp/tcp_listener.h +++ b/src/lib/tcp/tcp_listener.h @@ -61,7 +61,7 @@ public: const unsigned short server_port, const asiolink::TlsContextPtr& tls_context, const IdleTimeout& idle_timeout, - const TcpConnectionFilterCallback& connection_filter); + const TcpConnectionFilterCallback& connection_filter = 0); /// @brief Virtual destructor. virtual ~TcpListener() { diff --git a/src/lib/tcp/tests/tcp_listener_unittests.cc b/src/lib/tcp/tests/tcp_listener_unittests.cc index e472bc06b6..35b9f8004d 100644 --- a/src/lib/tcp/tests/tcp_listener_unittests.cc +++ b/src/lib/tcp/tests/tcp_listener_unittests.cc @@ -113,7 +113,7 @@ public: const unsigned short server_port, const TlsContextPtr& tls_context, const IdleTimeout& idle_timeout, - const TcpConnectionFilterCallback& filter_callback, + const TcpConnectionFilterCallback& filter_callback = 0, const size_t read_max = 32 * 1024) : TcpListener(io_service, server_address, server_port, tls_context, idle_timeout, filter_callback), @@ -243,11 +243,6 @@ public: io_service_.poll(); } - /// @brief Pass through filter that allows all connections. - bool noFilter(const std::string& /* remote_endpoint_address */) { - return(true); - } - /// @brief Filter that denies every other connection. /// /// @param remote_endpoint_address ip address of the remote end of @@ -288,8 +283,7 @@ TEST_F(TcpListenerTest, listen) { const std::string request = "I am done"; TcpTestListener listener(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT, - TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT), - std::bind(&TcpListenerTest::noFilter, this, ph::_1)); + TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT)); ASSERT_NO_THROW(listener.start()); ASSERT_EQ(SERVER_ADDRESS, listener.getLocalAddress().toText()); @@ -314,8 +308,7 @@ TEST_F(TcpListenerTest, splitReads) { // Read at most one byte at a time. size_t read_max = 1; TcpTestListener listener(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT, - TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT), - std::bind(&TcpListenerTest::noFilter, this, ph::_1), + TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT), 0, read_max); ASSERT_NO_THROW(listener.start()); @@ -339,8 +332,7 @@ TEST_F(TcpListenerTest, splitReads) { // transmit a streamed request and receive a streamed response. TEST_F(TcpListenerTest, idleTimeoutTest) { TcpTestListener listener(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT, - TlsContextPtr(), TcpListener::IdleTimeout(SHORT_IDLE_TIMEOUT), - std::bind(&TcpListenerTest::noFilter, this, ph::_1)); + TlsContextPtr(), TcpListener::IdleTimeout(SHORT_IDLE_TIMEOUT)); ASSERT_NO_THROW(listener.start()); ASSERT_EQ(SERVER_ADDRESS, listener.getLocalAddress().toText()); @@ -366,8 +358,7 @@ TEST_F(TcpListenerTest, multipleClientsListen) { const std::string request = "I am done"; TcpTestListener listener(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT, - TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT), - std::bind(&TcpListenerTest::noFilter, this, ph::_1)); + TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT)); ASSERT_NO_THROW(listener.start()); ASSERT_EQ(SERVER_ADDRESS, listener.getLocalAddress().toText()); @@ -395,8 +386,7 @@ TEST_F(TcpListenerTest, multipleRequetsPerClients) { std::list<std::string>requests{ "one", "two", "three", "I am done"}; TcpTestListener listener(io_service_, IOAddress(SERVER_ADDRESS), SERVER_PORT, - TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT), - std::bind(&TcpListenerTest::noFilter, this, ph::_1)); + TlsContextPtr(), TcpListener::IdleTimeout(IDLE_TIMEOUT)); ASSERT_NO_THROW(listener.start()); ASSERT_EQ(SERVER_ADDRESS, listener.getLocalAddress().toText()); |