more libcli/smb/smb_direct.c
authorStefan Metzmacher <metze@samba.org>
Fri, 30 Sep 2016 00:56:02 +0000 (02:56 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 1 Jun 2018 12:35:09 +0000 (14:35 +0200)
libcli/smb/smb_direct.c
libcli/smb/smb_direct.h

index 9c2f6ed995e3851410ff87167c03b6ab663de071..f4b2d36d2c1fe86edefd8124a140b046cd815a89 100644 (file)
@@ -27,6 +27,7 @@
 #include "libcli/smb/smb_direct.h"
 #include "lib/util/dlinklist.h"
 #include "lib/util/iov_buf.h"
+#include "librpc/ndr/libndr.h"
 
 #ifdef SMB_TRANSPORT_ENABLE_RDMA
 #include <rdma/rdma_cma_abi.h>
@@ -102,6 +103,8 @@ struct smb_direct_connection {
 struct smb_direct_connection *smb_direct_conn;
 
 #define SMB_DIRECT_IO_MAX_DATA 8192
+#define SMB_DIRECT_DATA_MIN_HDR_SIZE 0x14
+#define SMB_DIRECT_DATA_OFFSET NDR_ROUND(SMB_DIRECT_DATA_MIN_HDR_SIZE, 8)
 
 struct smb_direct_io {
        struct smb_direct_io *prev, *next;
@@ -120,8 +123,8 @@ struct smb_direct_io {
        uint32_t data_length;
        uint32_t remaining_length;
 
-       uint8_t nbt_hdr[0x04];
-       uint8_t smbd_hdr[0x18];
+       uint8_t nbt_hdr[NBT_HDR_SIZE];
+       uint8_t smbd_hdr[SMB_DIRECT_DATA_OFFSET];
        uint8_t data[SMB_DIRECT_IO_MAX_DATA];
 };
 
@@ -387,13 +390,18 @@ DEBUG(0,("%s:%s: SETUP s2r here...\n", __location__, __func__));
 static void smb_direct_connection_debug_credits(struct smb_direct_connection *c,
                                                const char *location, const char *func)
 {
-       DEBUG(0,("%s:%s: CREDITS: RMAX[%u] RTARGET[%u] R[%u] STARGET[%u] S[%u]\n",
-               location, func,
+       DEBUG(0,("%s:%s: CREDITS: RMAX[%u] RTARGET[%u] R[%u] RSIZE[%u] "
+                "STARGET[%u] S[%u] SSIZE[%u] MF[%u] MRW[%u]\n",
+               location, "",//func,
                c->state.receive_credit_max,
                c->state.receive_credit_target,
                c->state.receive_credits,
+               c->state.max_receive_size,
                c->state.send_credit_target,
-               c->state.send_credits));
+               c->state.send_credits,
+               c->state.max_send_size,
+               c->state.max_fragmented_size,
+               c->state.max_read_write_size));
 }
 
 static int smb_direct_connection_destructor(struct smb_direct_connection *c)
@@ -558,12 +566,12 @@ DEBUG(0,("%s:%s: TODO: REMOVE me ...here...\n", __location__, __func__));
 //             }
 
                if (io->data_length > 0) {
-                       data_offset = 0x18;
+                       data_offset = SMB_DIRECT_DATA_OFFSET;
                        io->sge[0].length = data_offset;
                        io->sge[1].length = io->data_length;
                        io->send_wr.num_sge = 2;
                } else {
-                       io->sge[0].length = 0x14;
+                       io->sge[0].length = SMB_DIRECT_DATA_MIN_HDR_SIZE;
                        io->send_wr.num_sge = 1;
                }
 
@@ -1747,7 +1755,7 @@ try_again:
                        smb_direct_connection_disconnect(c, status);
                        return;
                }
-               if (wc.byte_len < 0x14) {
+               if (wc.byte_len < SMB_DIRECT_DATA_MIN_HDR_SIZE) {
                        status = NT_STATUS_INVALID_NETWORK_RESPONSE;
                        DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
                                __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
@@ -1785,7 +1793,7 @@ try_again:
 
 smb_direct_connection_debug_credits(c, __location__, __func__);
                if (data_offset == 0) {
-                       if (wc.byte_len != 0x14) {
+                       if (wc.byte_len != SMB_DIRECT_DATA_MIN_HDR_SIZE) {
                                status = NT_STATUS_INVALID_NETWORK_RESPONSE;
                                DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
                                        __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
@@ -1804,7 +1812,7 @@ smb_direct_connection_debug_credits(c, __location__, __func__);
                        }
                goto try_again;
                        return;
-               } else if (data_offset == 0x18) {
+               } else if (data_offset == SMB_DIRECT_DATA_OFFSET) {
                        if (io->data_length > (c->state.max_receive_size - data_offset)) {
                                status = NT_STATUS_INVALID_NETWORK_RESPONSE;
                        DEBUG(0,("%s:%s: io->data_length[%u/0x%x] max_receive_size-data_offset[%u/0x%x] ret[%d] errno[%d] status[%s]\n",
@@ -2032,7 +2040,7 @@ DEBUG(0,("%s:%s: TEVENT_FD_NOT_WRITEABLE\n", __location__, __func__));
                                         * We need to continue to get
                                         * the incomplete packet.
                                         */
-                                       io->data_length = MIN(sizeof(io->data),
+                                       io->data_length = MIN(c->state.max_send_size - SMB_DIRECT_DATA_OFFSET,
                                                              c->s2r.remaining_length);
                                        io->remaining_length = c->s2r.remaining_length;
                                        io->remaining_length -= io->data_length;
@@ -2121,7 +2129,7 @@ DEBUG(0,("%s:%s: FINISH[%p] io->data_length[%u] io->remaining_length[%u]\n",
                                        return;
                                }
 
-                               io->data_length = MIN(sizeof(io->data),
+                               io->data_length = MIN(c->state.max_send_size - SMB_DIRECT_DATA_OFFSET,
                                                      c->s2r.remaining_length);
                                io->remaining_length = c->s2r.remaining_length;
                                io->remaining_length -= io->data_length;
@@ -2296,4 +2304,13 @@ DEBUG(0,("%s:%s: here...\n", __location__, __func__));
        return c;
 }
 
+uint32_t smb_direct_connection_max_fragmented_size(struct smb_direct_connection *c)
+{
+       return c->state.max_fragmented_size;
+}
+
+uint32_t smb_direct_connection_max_read_write_size(struct smb_direct_connection *c)
+{
+       return c->state.max_read_write_size;
+}
 #endif /* SMB_TRANSPORT_ENABLE_RDMA */
index 06b52aa237541b55f4cb3b66e564734c7eb1c22c..ae303f9b3d7138ee9f4e22c1c9aa3f73a438029c 100644 (file)
@@ -42,6 +42,9 @@ NTSTATUS smb_direct_connection_connect_recv(struct tevent_req *req, int *fd);
 NTSTATUS smb_direct_connection_setup_events(struct smb_direct_connection *c,
                                            struct tevent_context *ev);
 
+uint32_t smb_direct_connection_max_fragmented_size(struct smb_direct_connection *c);
+uint32_t smb_direct_connection_max_read_write_size(struct smb_direct_connection *c);
+
 #define SMB_DIRECT_LISTEN_BACKLOG 100
 
 struct tevent_req *smb_direct_daemon_send(TALLOC_CTX *mem_ctx,