]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#964,!577] Added socket descriptor parameter to IfaceMgr external callback handler
authorThomas Markwalder <tmark@isc.org>
Fri, 25 Oct 2019 18:24:42 +0000 (14:24 -0400)
committerThomas Markwalder <tmark@isc.org>
Tue, 5 Nov 2019 16:23:48 +0000 (11:23 -0500)
src/lib/dhcp/iface_mgr.*
    typedef SocketCallback - added socket descriptpor parameter
    Added socket fd to invocations of socket ready callback

src/bin/dhcp4/dhcp4to6_ipc.*
    void Dhcp4to6Ipc::handler(int /* fd */)

src/bin/dhcp6/dhcp6to4_ipc.*
    void Dhcp6to4Ipc::handler(int /* fd */)

     Dhcp6to4Ipc& ipc = Dhcp6to4Ipc::instance();
     Pkt6Ptr pkt;

src/hooks/dhcp/high_availability/ha_service.*
    socketReadyHandler() - initial stub implementation of socket ready handler

src/bin/dhcp4/dhcp4to6_ipc.cc
src/bin/dhcp4/dhcp4to6_ipc.h
src/bin/dhcp6/dhcp6to4_ipc.cc
src/bin/dhcp6/dhcp6to4_ipc.h
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/ha_service.h
src/lib/dhcp/iface_mgr.cc
src/lib/dhcp/iface_mgr.h
src/lib/dhcp/tests/iface_mgr_unittest.cc

index 1c698abffd41bbc76524743394230071a0a1684c..b78f41e957ec1d42b19f41b140668a00b68526ff 100644 (file)
@@ -52,7 +52,7 @@ void Dhcp4to6Ipc::open() {
     }
 }
 
-void Dhcp4to6Ipc::handler() {
+void Dhcp4to6Ipc::handler(int /* fd */) {
     Dhcp4to6Ipc& ipc = Dhcp4to6Ipc::instance();
     Pkt6Ptr pkt;
 
index 6b098585c562cab65784c8f3042f4ddb0578a682..ba2e1a6a93ac277bbeb25eab395c5368bab67057 100644 (file)
@@ -47,7 +47,7 @@ public:
     ///
     /// The handler processes the DHCPv4-query DHCPv6 packet and
     /// sends the DHCPv4-response DHCPv6 packet back to the DHCPv6 server
-    static void handler();
+    static void handler(int /* fd */);
 };
 
 } // namespace isc
index 02e275db802fff31c717c1c592547742d99b6894..0022aced205aec280d452da13bc6fd61c4272f98 100644 (file)
@@ -54,7 +54,7 @@ void Dhcp6to4Ipc::open() {
     }
 }
 
-void Dhcp6to4Ipc::handler() {
+void Dhcp6to4Ipc::handler(int /* fd */) {
     Dhcp6to4Ipc& ipc = Dhcp6to4Ipc::instance();
     Pkt6Ptr pkt;
 
index d039e8f1b45287fe3d6b1061b570d8596355b00b..1d393e988479f7f9b26971ff6f76411c3b4db398 100644 (file)
@@ -44,7 +44,7 @@ public:
     /// @brief On receive handler
     ///
     /// The handler sends the DHCPv6 packet back to the remote address
-    static void handler();
+    static void handler(int /* fd */);
 
     /// @param client_port UDP port where all responses are sent to.
     /// Not zero is mostly useful for testing purposes.
index 4589a8ad57a04378882d7517940ac3aa9ebe796a..0cb08bf658c433bebf81a4cc4d5234b8afb3c2a2 100644 (file)
@@ -1632,7 +1632,9 @@ HAService::clientConnectHandler(const boost::system::error_code& ec, int tcp_nat
         // run by an explicit call IOService ready in kea-dhcp<n> code.
         // We are registerin the socket only to interrupt main-thread
         // select().
-        IfaceMgr::instance().addExternalSocket(tcp_native_fd, 0);
+        IfaceMgr::instance().addExternalSocket(tcp_native_fd,
+            boost::bind(&HAService::socketReadyHandler, this, _1)
+        );
     }
 
     // If ec.value() == boost::asio::error::already_connected, we should already
@@ -1642,6 +1644,16 @@ HAService::clientConnectHandler(const boost::system::error_code& ec, int tcp_nat
     return (true);
 }
 
+void
+HAService::socketReadyHandler(int tcp_native_fd) {
+    std::cout << "HAService::socketReadyHandler - ready socket:" << tcp_native_fd << std::endl;
+    // If the socket is not usable/or in a transaction
+    // we'll unregister it
+    // if (socket bad) /{
+    //      IfaceMgr::instance().deleteExternalSocket(tcp_native_fd, 0);
+    // }
+}
+
 void
 HAService::clientCloseHandler(int tcp_native_fd) {
     if (tcp_native_fd >= 0) {
index 6765f7b0ad6ed82a9507b5b6f3bb4a87f2381878..48efda89fe178b4beecdd43dde318a85e83ac8cb 100644 (file)
@@ -738,6 +738,19 @@ protected:
     /// error we want Connection logic to process it.
     bool clientConnectHandler(const boost::system::error_code& ec, int tcp_native_fd);
 
+    /// @brief IfaceMgr external socket ready callback handler
+    ///
+    /// IfaceMgr invokes this call back when a registered socket has been
+    /// flagged as ready to read.   It is installed by the invocation to
+    /// register the socket with IfaceMgr made in @ref clientConnectHandler.
+    ///
+    /// @todo add logic to determine if the
+    /// socket is involved in an ongoing transcation or not. If not, it
+    /// will be unregistered from IfaceMgr.
+    ///
+    /// @param tcp_native_fd socket descriptor of the ready socket
+    void socketReadyHandler(int tcp_native_fd);
+
     /// @brief HttpClient close callback handler
     ///
     /// Passed into HttpClient calls to allow unregistration of client's
index 8420ead396e367b6a9ec7c17fe65e1e1c788fe50..afcdb03863bb86318a4f20b3e973e58572985427 100644 (file)
@@ -1089,7 +1089,7 @@ Pkt4Ptr IfaceMgr::receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec /
             // layer access without integrating any specific features
             // in IfaceMgr
             if (s.callback_) {
-                s.callback_();
+                s.callback_(s.socket_);
             }
 
             return (Pkt4Ptr());
@@ -1184,7 +1184,7 @@ Pkt4Ptr IfaceMgr::receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec /*
         // layer access without integrating any specific features
         // in IfaceMgr
         if (s.callback_) {
-            s.callback_();
+            s.callback_(s.socket_);
         }
 
         return (Pkt4Ptr());
@@ -1313,7 +1313,7 @@ IfaceMgr::receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ )
         // layer access without integrating any specific features
         // in IfaceMgr
         if (s.callback_) {
-            s.callback_();
+            s.callback_(s.socket_);
         }
 
         return (Pkt6Ptr());
@@ -1430,7 +1430,7 @@ IfaceMgr::receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
             // layer access without integrating any specific features
             // in IfaceMgr
             if (s.callback_) {
-                s.callback_();
+                s.callback_(s.socket_);
             }
 
             return (Pkt6Ptr());
index ef17f927454746be5354594d39d031574c162e25..fc0d044e6d524d12d8e83c33b3c332bc97ad104f 100644 (file)
@@ -478,7 +478,8 @@ boost::function<void(const std::string& errmsg)> IfaceMgrErrorMsgCallback;
 class IfaceMgr : public boost::noncopyable {
 public:
     /// Defines callback used when data is received over external sockets.
-    typedef boost::function<void ()> SocketCallback;
+    /// @param fd socket descriptor of the ready socket
+    typedef boost::function<void (int fd)> SocketCallback;
 
     /// Keeps callback information for external sockets.
     struct SocketCallbackInfo {
index c206e5e1e084163911274a74153df82729692a93..bcb3552248d98f4ce79e72362c56136d3cf79bcd 100644 (file)
@@ -695,14 +695,14 @@ public:
         int pipefd[2];
         EXPECT_TRUE(pipe(pipefd) == 0);
         EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0],
-                        [&callback_ok](){ callback_ok = true; }));
+                        [&callback_ok](int /* fd */){ callback_ok = true; }));
 
 
         // Let's create a second pipe and register it as well
         int secondpipe[2];
         EXPECT_TRUE(pipe(secondpipe) == 0);
         EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0],
-                        [&callback2_ok](){ callback2_ok = true; }));
+                        [&callback2_ok](int /* fd */){ callback2_ok = true; }));
 
         // Verify a call with no data and normal external sockets works ok.
         Pkt4Ptr pkt4;
@@ -778,14 +778,14 @@ public:
         int pipefd[2];
         EXPECT_TRUE(pipe(pipefd) == 0);
         EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0],
-                        [&callback_ok](){ callback_ok = true; }));
+                        [&callback_ok](int /* fd*/){ callback_ok = true; }));
 
 
         // Let's create a second pipe and register it as well
         int secondpipe[2];
         EXPECT_TRUE(pipe(secondpipe) == 0);
         EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0],
-                        [&callback2_ok](){ callback2_ok = true; }));
+                        [&callback2_ok](int /*fd */){ callback2_ok = true; }));
 
         // Verify a call with no data and normal external sockets works ok.
         Pkt6Ptr pkt6;
@@ -2749,11 +2749,11 @@ TEST_F(IfaceMgrTest, detectIfaces) {
 volatile bool callback_ok;
 volatile bool callback2_ok;
 
-void my_callback(void) {
+void my_callback(int /* fd */) {
     callback_ok = true;
 }
 
-void my_callback2(void) {
+void my_callback2(int /* fd */) {
     callback2_ok = true;
 }