FIUXP daemon
authorRalph Boehme <slow@samba.org>
Thu, 29 Sep 2016 05:43:29 +0000 (22:43 -0700)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Jun 2018 12:35:04 +0000 (14:35 +0200)
libcli/smb/smb_direct_daemon.c

index caee841586e088deba4c6d3d0829387b06c55fec..50cd9cac09a3132dd7cc703821867b3c7cdabc16 100644 (file)
@@ -56,6 +56,12 @@ struct smb_direct_daemon_state {
        struct tevent_fd *listen_fde;
 
        struct sdd_listen_params params;
+
+       /*
+        * Pointer to the connection in listening state. There can be
+        * only one and it will receive all new SMB-D connections.
+        */
+       struct smb_direct_daemon_conn *listening_conn;
 };
 
 struct smb_direct_daemon_conn {
@@ -82,7 +88,8 @@ struct smb_direct_daemon_conn {
 
        /*
         * A connection in the listening state can only be used with
-        * smb_direct_accept() to accept a connection fd.
+        * smb_direct_accept() to accept a connection fd and can't be
+        * used for messaging.
         */
        bool listening;
 };
@@ -506,8 +513,19 @@ static NTSTATUS smbd_direct_daemon_listen(
        struct sdd_packet_listen_request *listen_request,
        struct sdd_packet_listen_response *listen_response)
 {
+       if (conn->daemon_state->listening_conn != NULL) {
+               /* There can be only one... */
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
        conn->daemon_state->params = listen_request->params;
        conn->listening = true;
+       conn->daemon_state->listening_conn = conn;
+
+       ok = smb_direct_daemon_rdma_listen(conn->daemon_state);
+       if (!ok) {
+               return NT_STATUS_INTERNAL_ERROR;
+       }
        listen_response->status = 0;
 
        return NT_STATUS_OK;
@@ -604,6 +622,22 @@ fail:
 static void smbd_direct_daemon_conn_handler(struct tevent_req *read_req);
 static void smbd_direct_daemon_conn_handler_next(struct tevent_req *write_req);
 
+static void smb_direct_daemon_conn_cleanup(struct tevent_req *req,
+                                          enum tevent_req_state req_state)
+{
+       struct smb_direct_daemon_conn *conn = tevent_req_data(
+               req, struct smb_direct_daemon_conn);
+
+       if (conn->fd != -1) {
+               close(conn->fd);
+               conn->fd = -1;
+       }
+
+       if (conn->daemon_state->conn == conn) {
+               conn->daemon_state->conn = NULL;
+       }
+}
+
 /**
  * @brief Handle an already accepted connection
  *
@@ -639,7 +673,7 @@ static struct tevent_req *smb_direct_daemon_conn_send(
                tevent_req_post(req, ev);
        }
        tevent_req_set_callback(subreq, smbd_direct_daemon_conn_handler, req);
-
+       tevent_req_set_cleanup_fn(subreq, smb_direct_daemon_conn_cleanup);
        return req;
 }