return 0;
}
-int smb_direct_transport_fd = -1;
-const struct smb_transport *smb_direct_transport_ptr;
+//int smb_direct_transport_fd = -1;
+//const struct smb_transport *smb_direct_transport_ptr;
struct smbXcli_conn *smbXcli_conn_create(TALLOC_CTX *mem_ctx,
int fd,
conn->smb2.cc_chunk_len = 1024 * 1024;
conn->smb2.cc_max_chunks = 16;
- if (fd == smb_direct_transport_fd) {
- void *ptr = (void *)(uintptr_t)fd;
- conn->transport = discard_const_p(struct smb_transport, smb_direct_transport_ptr);
- smb_direct_transport_ptr = NULL;
- smb_direct_transport_fd = -1;
-
- DEBUG(0,("%s: %s: conn->transport [%p] ptr [%p] sock [%d]\n",
- __location__, __func__, conn->transport, ptr, fd));
-
- talloc_get_type_abort(conn->transport, struct smb_transport);
- talloc_steal(conn, conn->transport);
- conn->sock_fd = -1;
- } else {
- smb_panic(__location__);
+// if (fd == smb_direct_transport_fd) {
+// void *ptr = (void *)(uintptr_t)fd;
+// conn->transport = discard_const_p(struct smb_transport, smb_direct_transport_ptr);
+// smb_direct_transport_ptr = NULL;
+// smb_direct_transport_fd = -1;
+//
+// DEBUG(0,("%s: %s: conn->transport [%p] ptr [%p] sock [%d]\n",
+// __location__, __func__, conn->transport, ptr, fd));
+//
+// talloc_get_type_abort(conn->transport, struct smb_transport);
+// talloc_steal(conn, conn->transport);
+// conn->sock_fd = -1;
+// } else {
+// smb_panic(__location__);
conn->sock_fd = fd;
status = smb_transport_tcp_existing(conn, fd,
max_pdu_size,
if (!NT_STATUS_IS_OK(status)) {
goto error;
}
- }
+ //}
talloc_set_destructor(conn, smbXcli_conn_destructor);
return conn;
} s2r;
};
+struct smb_direct_connection *smb_direct_conn;
+
#define SMB_DIRECT_IO_MAX_DATA 8192
struct smb_direct_io {
struct smb_direct_connection *c;
int sfd[2];
int ret;
- uint16_t i;
+ //uint16_t i;
c = talloc_zero(mem_ctx, struct smb_direct_connection);
if (c == NULL) {
}
c->sock.fd = -1;
c->sock.tmp_fd = -1;
-
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
talloc_set_destructor(c, smb_direct_connection_destructor);
c->state.max_send_size = 1364;
c->state.max_receive_size = SMB_DIRECT_IO_MAX_DATA;
c->state.max_fragmented_size = 1048576;
c->state.max_read_write_size = 0;
- c->state.receive_credit_max = 16;
+ c->state.receive_credit_max = 2;
c->state.send_credit_target = 255;
c->state.keep_alive_internal = 5;
- ret = socketpair(AF_UNIX, 0, SOCK_STREAM, sfd);
+ ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sfd);
if (ret == -1) {
int saved_errno = errno;
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
errno = saved_errno;
return NULL;
}
c->sock.tmp_fd = sfd[0];
c->sock.fd = sfd[1];
+DEBUG(0,("%s:%s: sock.fd[%d] sock.tmp_fd[%d]\n",
+ __location__, __func__, c->sock.fd, c->sock.tmp_fd));
+
smb_set_close_on_exec(c->sock.tmp_fd);
smb_set_close_on_exec(c->sock.fd);
set_blocking(c->sock.fd, false);
c->rdma.cm_channel = rdma_create_event_channel();
if (c->rdma.cm_channel == NULL) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
smb_set_close_on_exec(c->rdma.cm_channel->fd);
#endif
if (ret != 0) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
+ return c;
+}
+
+static struct smb_direct_connection *smb_direct_connection_complete_alloc(struct smb_direct_connection *c)
+{
+ int ret;
+ uint16_t i;
+
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
c->ibv.pd = ibv_alloc_pd(c->rdma.cm_id->verbs);
if (c->ibv.pd == NULL) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
c->ibv.comp_channel = ibv_create_comp_channel(c->rdma.cm_id->verbs);
if (c->ibv.comp_channel == NULL) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
smb_set_close_on_exec(c->ibv.comp_channel->fd);
c, c->ibv.comp_channel, 0);
if (c->ibv.send_cq == NULL) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
c->ibv.init_attr.send_cq = c->ibv.send_cq;
c, c->ibv.comp_channel, 0);
if (c->ibv.recv_cq == NULL) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
c->ibv.init_attr.recv_cq = c->ibv.recv_cq;
ret = ibv_req_notify_cq(c->ibv.send_cq, 0);
if (ret != 0) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
ret = ibv_req_notify_cq(c->ibv.recv_cq, 0);
if (ret != 0) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
ret = rdma_create_qp(c->rdma.cm_id, c->ibv.pd, &c->ibv.init_attr);
if (ret != 0) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
c->ibv.qp = c->rdma.cm_id->qp;
c->io_mem_ctx = talloc_named_const(c, 0, "io_mem_ctx");
if (c->io_mem_ctx == NULL) {
TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return NULL;
}
struct smb_direct_io *io;
io = smb_direct_io_create(c);
+ if (io == NULL) {
+ TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
+ return NULL;
+ }
DLIST_ADD_END(c->r2s.idle, io);
}
struct smb_direct_io *io;
io = smb_direct_io_create(c);
+ if (io == NULL) {
+ TALLOC_FREE(c);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
+ return NULL;
+ }
DLIST_ADD_END(c->s2r.idle, io);
}
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return c;
}
struct ibv_recv_wr *bad_recv_wr = NULL;
int ret;
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
if (c->r2s.idle == NULL) {
return 0;
}
DLIST_CONCATENATE(c->r2s.posted, c->r2s.idle);
c->r2s.idle = NULL;
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return 0;
}
}
state->c = c;
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
talloc_set_destructor(state, smb_direct_connection_rdma_connect_state_destructor);
c->rdma.fde_channel = tevent_add_fd(ev, c,
case RDMA_CM_EVENT_ROUTE_RESOLVED:
errno = 0;
ret = 0;
+ c = smb_direct_connection_complete_alloc(c);
+ if (c == NULL) {
+ status = map_nt_error_from_unix_common(errno);
+ DEBUG(0,("%s:%s: ret[%d] errno[%d] status[%s]\n",
+ __location__, __FUNCTION__, ret, errno, nt_errstr(status)));
+ tevent_req_nterror(req, status);
+ return;
+ }
#if 0
c->ibv.pd = ibv_alloc_pd(c->rdma.cm_id->verbs);
if (c->ibv.pd == NULL) {
static NTSTATUS smb_direct_connection_rdma_connect_recv(struct tevent_req *req)
{
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return tevent_req_simple_recv_ntstatus(req);
}
}
state->c = c;
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
// TODO: cleanup
talloc_set_destructor(state, smb_direct_connection_negotiate_connect_destructor);
static NTSTATUS smb_direct_connection_negotiate_connect_recv(struct tevent_req *req)
{
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return tevent_req_simple_recv_ntstatus(req);
}
state->ev = ev;
state->c = c;
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
subreq = smb_direct_connection_rdma_connect_send(state, ev, c, src, dst, NULL, NULL);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
smb_direct_connection_connect_done_rdma,
req);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
return req;
}
struct smb_direct_connection_connect_state);
NTSTATUS status;
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
status = smb_direct_connection_rdma_connect_recv(subreq);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
subreq = smb_direct_connection_negotiate_connect_send(state, state->ev, state->c);
if (tevent_req_nomem(subreq, req)) {
return;
tevent_req_set_callback(subreq,
smb_direct_connection_connect_done_negotiate,
req);
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
}
static void smb_direct_connection_connect_done_negotiate(struct tevent_req *subreq)
struct tevent_req);
NTSTATUS status;
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
status = smb_direct_connection_negotiate_connect_recv(subreq);
TALLOC_FREE(subreq);
if (tevent_req_nterror(req, status)) {
return;
}
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
tevent_req_done(req);
}
*fd = -1;
if (tevent_req_is_nterror(req, &status)) {
+DEBUG(0,("%s:%s: here...\n", __location__, __func__));
tevent_req_received(req);
return status;
}
+DEBUG(0,("%s:%s: sock.fd[%d] sock.tmp_fd[%d]\n",
+ __location__, __func__, c->sock.fd, c->sock.tmp_fd));
*fd = c->sock.tmp_fd;
c->sock.tmp_fd = -1;
tevent_req_received(req);
#include "async_smb.h"
#include "../libcli/smb/read_smb.h"
#include "../libcli/smb/smb_transport.h"
+#include "libcli/smb/smb_direct.h"
#include "libsmb/nmblib.h"
struct cli_session_request_state {
struct tevent_req *req_139;
struct tevent_req *req_445;
struct tevent_req *req_5445;
- struct smb_transport *smb_direct;
+ //struct smb_transport *smb_direct;
+ struct smb_direct_connection *smb_direct;
int sock;
uint16_t port;
};
enum tevent_req_state req_state);
static void smbsock_connect_connected(struct tevent_req *subreq);
static void smbsock_connect_do_139(struct tevent_req *subreq);
-static void smbsock_connect_do_5445(struct tevent_req *subreq);
+//static void smbsock_connect_do_5445(struct tevent_req *subreq);
struct tevent_req *smbsock_connect_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
{
struct tevent_req *req;
struct smbsock_connect_state *state;
- NTSTATUS status;
req = tevent_req_create(mem_ctx, &state, struct smbsock_connect_state);
if (req == NULL) {
* port==0, try both
*/
- status = smb_transport_direct_create(state, &state->smb_direct);
- if (tevent_req_nterror(req, status)) {
+//struct smb_direct_connection *smb_direct_connection_create(TALLOC_CTX *mem_ctx);
+//
+//struct tevent_req *smb_direct_connection_connect_send(TALLOC_CTX *mem_ctx,
+// struct tevent_context *ev,
+// struct smb_direct_connection *c,
+// const struct sockaddr_storage *src,
+// const struct sockaddr_storage *dst);
+//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);
+ //status = smb_transport_direct_create(state, &state->smb_direct);
+ //if (tevent_req_nterror(req, status)) {
+ // return tevent_req_post(req, ev);
+ //}
+ //state->req_5445 = smb_transport_direct_connect_rdma_send(state, ev, state->smb_direct,
+ // addr, NULL, NULL);
+ //if (tevent_req_nomem(state->req_5445, req)) {
+ // return tevent_req_post(req, ev);
+ //}
+ //tevent_req_set_callback(state->req_5445, smbsock_connect_do_5445,
+ // req);
+ state->smb_direct = smb_direct_connection_create(state);
+ if (tevent_req_nomem(state->smb_direct, req)) {
return tevent_req_post(req, ev);
}
- state->req_5445 = smb_transport_direct_connect_rdma_send(state, ev, state->smb_direct,
- addr, NULL, NULL);
+ state->req_5445 = smb_direct_connection_connect_send(state, ev, state->smb_direct,
+ NULL, addr);
if (tevent_req_nomem(state->req_5445, req)) {
return tevent_req_post(req, ev);
}
- tevent_req_set_callback(state->req_5445, smbsock_connect_do_5445,
+ tevent_req_set_callback(state->req_5445, smbsock_connect_connected,
req);
if (0) {
req);
}
-static void smbsock_connect_do_5445(struct tevent_req *subreq)
-{
- struct tevent_req *req = tevent_req_callback_data(
- subreq, struct tevent_req);
- struct smbsock_connect_state *state = tevent_req_data(
- req, struct smbsock_connect_state);
- NTSTATUS status;
-
- status = smb_transport_direct_connect_rdma_recv(subreq);
- TALLOC_FREE(subreq);
- if (tevent_req_nterror(req, status)) {
- return;
- }
-
- state->req_5445 = smb_transport_direct_connect_negotiate_send(state,
- state->ev,
- state->smb_direct);
- if (tevent_req_nomem(state->req_5445, req)) {
- return;
- }
- tevent_req_set_callback(state->req_5445, smbsock_connect_connected,
- req);
-}
-
-extern int smb_direct_transport_fd;
-extern const struct smb_transport *smb_direct_transport_ptr;
+//extern int smb_direct_transport_fd;
+//extern const struct smb_transport *smb_direct_transport_ptr;
+extern struct smb_direct_connection *smb_direct_conn;
static void smbsock_connect_connected(struct tevent_req *subreq)
{
if (subreq == state->req_5445) {
- status = smb_transport_direct_connect_negotiate_recv(subreq);
+ //status = smb_transport_direct_connect_negotiate_recv(subreq);
+ status = smb_direct_connection_connect_recv(subreq, &state->sock);
TALLOC_FREE(state->req_5445);
- talloc_steal(NULL, state->smb_direct);
- state->sock = (intptr_t)state->smb_direct;
+ smb_direct_conn = talloc_steal(NULL, state->smb_direct);
+ //state->sock = (intptr_t)state->smb_direct;
state->port = 5445;
- SMB_ASSERT(smb_direct_transport_fd == -1);
- smb_direct_transport_fd = state->sock;
- smb_direct_transport_ptr = state->smb_direct;
+ //SMB_ASSERT(smb_direct_transport_fd == -1);
+ //smb_direct_transport_fd = state->sock;
+ //smb_direct_transport_ptr = state->smb_direct;
DEBUG(0,("%s: %s: smbdirect [%p:%s] sock [%d] port [%d]\n",
__location__, __func__, state->smb_direct, talloc_get_name(state->smb_direct), state->sock, state->port));