]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2583] Make connection filter optional
authorThomas Markwalder <tmark@isc.org>
Tue, 8 Nov 2022 20:44:21 +0000 (15:44 -0500)
committerThomas Markwalder <tmark@isc.org>
Thu, 10 Nov 2022 19:43:23 +0000 (14:43 -0500)
src/lib/tcp/tcp_connection.cc
src/lib/tcp/tcp_listener.h
src/lib/tcp/tests/tcp_listener_unittests.cc

index aa90f9f86a443499648c4fdcdb88adbaaca97e53..2f12a579b74e5a5e486cfcd70db510eab544d0ed 100644 (file)
@@ -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());
index 8086399e9b57b5499b28da136bf4bf58811cc709..fa69766e964d3ec8b32e2d5cc8767e38327f1129 100644 (file)
@@ -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() {
index e472bc06b6c2d6d32b4ed368cc569d6f2bc88741..35b9f8004d448bb321f8b2b2912fd42be9e84b39 100644 (file)
@@ -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());