WIP pass fd to smbd
authorRalph Boehme <slow@samba.org>
Sat, 1 Oct 2016 08:06:46 +0000 (01:06 -0700)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Jun 2018 12:35:14 +0000 (14:35 +0200)
libcli/smb/smb_direct.c
libcli/smb/smb_direct_daemon.c
source3/smbd/server.c

index 6cdfe16b45e9ceaa61ef31023b8fafc78e98550f..b8689ce34470c296fb599a877a6da6fe2999b3b8 100644 (file)
@@ -2989,7 +2989,7 @@ static void smb_direct_listener_accept_done(struct tevent_req *subreq)
        talloc_reparent(state, l, c);
 
        tevent_req_defer_callback(req, state->ev);
-       tevent_req_done(req);
+       tevent_req_notify_callback(req);
        return;
 }
 
@@ -3018,14 +3018,14 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
        }
 
        if (tevent_req_is_nterror(req, &status)) {
+               DEBUG(0,("%s:%s: here...[%s]\n", __location__, __func__, nt_errstr(status)));
                tevent_req_received(req);
-DEBUG(0,("%s:%s: here...\n", __location__, __func__));
                return status;
        }
 
        /*
         * We don't call tevent_req_received()
-        * because the caller can lease this alive
+        * because the caller can leave this alive
         * in order to consume more connections
         */
        if (l->ready == NULL) {
@@ -3037,6 +3037,11 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
        DLIST_REMOVE(l->ready, c);
        c->l = NULL;
 
+       if (l->ready != NULL) {
+               tevent_req_defer_callback(req, state->ev);
+               tevent_req_notify_callback(req);
+       }
+
        *fd = c->sock.tmp_fd;
        c->sock.tmp_fd = -1;
        if (laddr != NULL) {
index d9b8c0a7f5f16683af142e53f033b2b05ca1df9a..d785518552daea5fb90394e64bdcb08da598e7a2 100644 (file)
@@ -37,6 +37,7 @@
 #include "lib/util/samba_util.h"
 #include "lib/util/blocking.h"
 #include "lib/util/util_net.h"
+#include "lib/util/msghdr.h"
 
 #ifdef SMB_TRANSPORT_ENABLE_RDMA
 #include <rdma/rdma_cma_abi.h>
@@ -586,6 +587,9 @@ static NTSTATUS smbd_direct_daemon_listen(
        return NT_STATUS_OK;
 }
 
+static NTSTATUS smbd_direct_daemon_send_fd(
+       struct smb_direct_daemon_state *daemon_state, int fd);
+
 static void smbd_direct_daemon_listen_accept_done(struct tevent_req *subreq)
 {
        struct smb_direct_daemon_conn *conn = tevent_req_callback_data(subreq,
@@ -623,10 +627,48 @@ static void smbd_direct_daemon_listen_accept_done(struct tevent_req *subreq)
                fd, print_sockaddr(laddr_buf, sizeof(laddr_buf), &laddr),
                print_sockaddr(raddr_buf, sizeof(raddr_buf), &raddr));
 
-       TALLOC_FREE(c);
+       status = smbd_direct_daemon_send_fd(daemon_state, fd);
        close(fd);
 }
 
+static NTSTATUS smbd_direct_daemon_send_fd(
+       struct smb_direct_daemon_state *daemon_state, int fd)
+{
+       struct msghdr msg;
+       struct iovec iov;
+       ssize_t fdlen;
+       int ret;
+       char iobuf[1];
+
+       iov = (struct iovec) {
+               .iov_base = &iobuf[0],
+               .iov_len = 1
+       };
+
+       msg = (struct msghdr) {
+               .msg_iov = &iov,
+               .msg_iovlen = 1
+       };
+
+       fdlen = msghdr_prep_fds(&msg, NULL, 0, &fd, 1);
+       if (fdlen == -1) {
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+       {
+               uint8_t buf[fdlen];
+               msghdr_prep_fds(&msg, buf, fdlen, &fd, 1);
+
+               ret = sendmsg(daemon_state->listening_conn->conn_fd, &msg, 0);
+               if (ret == -1) {
+                       DBG_ERR("BUGBUGBUG: this should be an async func\n");
+                       return NT_STATUS_INTERNAL_ERROR;
+               }
+       }
+
+       return NT_STATUS_OK;
+}
+
 static NTSTATUS smbd_direct_daemon_dispatch(struct smb_direct_daemon_conn *conn,
                                            DATA_BLOB in_data,
                                            DATA_BLOB *out_data)
index 8732e9a6a4b9f2c298eedbfa1f5b16ea97779534..0646ae6bacb010e72cb6f5276ce1fd2fc4aa8094 100644 (file)
@@ -1294,9 +1294,12 @@ static void smbd_accept_connection(struct tevent_context *ev,
        int fd;
        pid_t pid = 0;
 
+       DBG_ERR("smbd got connection\n");
+
        if (!s->smb_direct) {
                fd = accept(s->fd, (struct sockaddr *)(void *)&addr,&in_addrlen);
        } else {
+               DBG_ERR("smbd got SMB-D connection\n");
                fd = smb_direct_accept(s->smb_direct_socket);
        }