From 113f2696fe4103474cb2703e3d2f8848304fdd3d Mon Sep 17 00:00:00 2001 From: speidy Date: Sat, 8 Feb 2014 13:34:01 +0200 Subject: libxrdp: work on fastpath --- libxrdp/xrdp_mcs.c | 61 +++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 17 deletions(-) (limited to 'libxrdp/xrdp_mcs.c') diff --git a/libxrdp/xrdp_mcs.c b/libxrdp/xrdp_mcs.c index c145158c..1828b28b 100644 --- a/libxrdp/xrdp_mcs.c +++ b/libxrdp/xrdp_mcs.c @@ -127,12 +127,14 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan) while (1) { + if (xrdp_iso_recv(self->iso_layer, s) != 0) { - DEBUG((" out xrdp_mcs_recv xrdp_iso_recv returned non zero")); + free_stream(s); return 1; } + if (!s_check_rem(s, 1)) { return 1; @@ -320,10 +322,16 @@ xrdp_mcs_recv_connect_initial(struct xrdp_mcs *self) make_stream(s); init_stream(s, 16 * 1024); - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; + if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; + } + } else { + g_writeln("xrdp_mcs_recv_connect_initial: TPKT not detected"); + free_stream(s); + return 1; } if (xrdp_mcs_ber_parse_header(self, s, MCS_CONNECT_INITIAL, &len) != 0) @@ -441,10 +449,16 @@ xrdp_mcs_recv_edrq(struct xrdp_mcs *self) make_stream(s); init_stream(s, 8192); - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; + if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; + } + } else { + g_writeln("xrdp_mcs_recv_edrq: TPKT not detected"); + free_stream(s); + return 1; } if (!s_check_rem(s, 1)) @@ -503,12 +517,19 @@ xrdp_mcs_recv_aurq(struct xrdp_mcs *self) make_stream(s); init_stream(s, 8192); - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; + if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; + } + } else { + g_writeln("xrdp_mcs_recv_aurq: TPKT not detected"); + free_stream(s); + return 1; } + if (!s_check_rem(s, 1)) { free_stream(s); @@ -590,10 +611,16 @@ xrdp_mcs_recv_cjrq(struct xrdp_mcs *self) make_stream(s); init_stream(s, 8192); - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; + if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; + } + } else { + g_writeln("xrdp_mcs_recv_cjrq: TPKT not detected"); + free_stream(s); + return 1; } if (!s_check_rem(s, 1)) -- cgit v1.2.3 From 9a98299e2b3bb0c3e4f047efa4ad8f8450656dda Mon Sep 17 00:00:00 2001 From: speidy Date: Sat, 8 Feb 2014 20:55:41 +0200 Subject: libxrdp: work on fastpath --- libxrdp/xrdp_iso.c | 55 +++++++++++++++++++++-------------------- libxrdp/xrdp_mcs.c | 72 ++++++++++++++++++++---------------------------------- libxrdp/xrdp_rdp.c | 25 ++++++++----------- libxrdp/xrdp_sec.c | 14 +++++++++-- 4 files changed, 77 insertions(+), 89 deletions(-) (limited to 'libxrdp/xrdp_mcs.c') diff --git a/libxrdp/xrdp_iso.c b/libxrdp/xrdp_iso.c index 09c08f94..82a76e5f 100644 --- a/libxrdp/xrdp_iso.c +++ b/libxrdp/xrdp_iso.c @@ -95,9 +95,14 @@ xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len) *len = 0; // X.224 Length Indicator plen = xrdp_iso_recv_tpkt_header(self, s); - if (plen == 1) + + if (plen == 2) { - DEBUG((" xrdp_iso_recv_msg: error in tpkt header reading")); + DEBUG((" xrdp_iso_recv_msg: non-TPKT header detected, we try fastpath")); + return plen; + } + + if (plen == 1) { return 1; } @@ -118,10 +123,19 @@ xrdp_iso_recv(struct xrdp_iso *self, struct stream *s) { int code; int len; + int iso_msg; DEBUG((" in xrdp_iso_recv")); - if (xrdp_iso_recv_msg(self, s, &code, &len) != 0) + iso_msg = xrdp_iso_recv_msg(self, s, &code, &len); + + if (iso_msg == 2) // non-TPKT header + { + DEBUG((" out xrdp_iso_recv xrdp_iso_recv_msg return 2, non-TPKT header detected")); + return iso_msg; + } + + if (iso_msg == 1) // error { DEBUG((" out xrdp_iso_recv xrdp_iso_recv_msg return non zero")); return 1; @@ -137,38 +151,32 @@ xrdp_iso_recv(struct xrdp_iso *self, struct stream *s) return 0; } /*****************************************************************************/ -/* returns error */ +/* returns packet length or error (1) */ int APP_CC -xrdp_iso_detect_tpkt(struct xrdp_iso *self, struct stream *s) +xrdp_iso_recv_tpkt_header(struct xrdp_iso *self, struct stream *s) { + int plen; int ver; - DEBUG((" in xrdp_iso_detect_tpkt")); + DEBUG((" in xrdp_iso_recv_tpkt_header")); + if (xrdp_tcp_recv(self->tcp_layer, s, 1) != 0) { return 1; } in_uint8_peek(s, ver); - g_writeln("tpkt version: %x", ver); + g_writeln(" tpkt version: %x", ver); if (ver != 3) { - return 1; + /* + * special error code that means we got non-TPKT header, + * so we gonna try fastpath input. + */ + return 2; } - DEBUG((" out xrdp_iso_detect_tpkt")); - return 0; -} -/*****************************************************************************/ -/* returns packet length or error (1) */ -int APP_CC -xrdp_iso_recv_tpkt_header(struct xrdp_iso *self, struct stream *s) -{ - int plen; - - DEBUG((" in xrdp_iso_recv_tpkt_header")); - if (xrdp_tcp_recv(self->tcp_layer, s, 3) != 0) { return 1; @@ -374,13 +382,6 @@ xrdp_iso_incoming(struct xrdp_iso *self) init_stream(s, 8192); DEBUG((" in xrdp_iso_incoming")); - if (xrdp_iso_detect_tpkt(self, s) != 0) - { - g_writeln("xrdp_iso_incoming: TPKT not detected"); - free_stream(s); - return 1; - } - if (xrdp_iso_recv_msg(self, s, &code, &len) != 0) { DEBUG((" in xrdp_iso_recv_msg error!!")); diff --git a/libxrdp/xrdp_mcs.c b/libxrdp/xrdp_mcs.c index 1828b28b..81e8b758 100644 --- a/libxrdp/xrdp_mcs.c +++ b/libxrdp/xrdp_mcs.c @@ -122,18 +122,25 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan) int len; int userid; int chanid; - + int iso_msg; DEBUG((" in xrdp_mcs_recv")); while (1) { - if (xrdp_iso_recv(self->iso_layer, s) != 0) + iso_msg = xrdp_iso_recv(self->iso_layer, s); + + if (iso_msg == 2) // non-TPKT header { - free_stream(s); - return 1; + DEBUG((" out xrdp_mcs_recv, non-TPKT header detected, we try fastpath")); + return iso_msg; } + if (iso_msg == 1) // error + { + DEBUG((" out xrdp_mcs_recv, xrdp_iso_recv return non zero")); + return 1; + } if (!s_check_rem(s, 1)) { @@ -322,16 +329,10 @@ xrdp_mcs_recv_connect_initial(struct xrdp_mcs *self) make_stream(s); init_stream(s, 16 * 1024); - if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; - } - } else { - g_writeln("xrdp_mcs_recv_connect_initial: TPKT not detected"); - free_stream(s); - return 1; + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; } if (xrdp_mcs_ber_parse_header(self, s, MCS_CONNECT_INITIAL, &len) != 0) @@ -449,16 +450,10 @@ xrdp_mcs_recv_edrq(struct xrdp_mcs *self) make_stream(s); init_stream(s, 8192); - if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; - } - } else { - g_writeln("xrdp_mcs_recv_edrq: TPKT not detected"); - free_stream(s); - return 1; + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; } if (!s_check_rem(s, 1)) @@ -517,19 +512,12 @@ xrdp_mcs_recv_aurq(struct xrdp_mcs *self) make_stream(s); init_stream(s, 8192); - if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; - } - } else { - g_writeln("xrdp_mcs_recv_aurq: TPKT not detected"); - free_stream(s); - return 1; + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; } - if (!s_check_rem(s, 1)) { free_stream(s); @@ -611,16 +599,10 @@ xrdp_mcs_recv_cjrq(struct xrdp_mcs *self) make_stream(s); init_stream(s, 8192); - if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) { - if (xrdp_iso_recv(self->iso_layer, s) != 0) - { - free_stream(s); - return 1; - } - } else { - g_writeln("xrdp_mcs_recv_cjrq: TPKT not detected"); - free_stream(s); - return 1; + if (xrdp_iso_recv(self->iso_layer, s) != 0) + { + free_stream(s); + return 1; } if (!s_check_rem(s, 1)) diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index fa62c9c2..923b0358 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -262,19 +262,6 @@ xrdp_rdp_init_data(struct xrdp_rdp *self, struct stream *s) /* returns error */ int APP_CC xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) -{ - // Detect TPKT or FastPath - if (xrdp_iso_detect_tpkt(self->sec_layer->mcs_layer->iso_layer, s) == 0) { - return xrdp_rdp_recv_tpkt(self, s, code); - } else { - return xrdp_rdp_recv_fastpath(self, s, code); - } - -} -/*****************************************************************************/ -/* returns error */ -int APP_CC -xrdp_rdp_recv_tpkt(struct xrdp_rdp *self, struct stream *s, int *code) { int error = 0; int len = 0; @@ -288,6 +275,11 @@ xrdp_rdp_recv_tpkt(struct xrdp_rdp *self, struct stream *s, int *code) chan = 0; error = xrdp_sec_recv(self->sec_layer, s, &chan); + if (error == 2) /* we have fastpath packet! */ + { + return xrdp_rdp_recv_fastpath(self, s, code); + } + if (error == -1) /* special code for send demand active */ { s->next_packet = 0; @@ -357,7 +349,10 @@ int APP_CC xrdp_rdp_recv_fastpath(struct xrdp_rdp *self, struct stream *s, int *code) { g_writeln("Booyah!"); - return 0; + int msg; + in_uint8(s, msg); + g_writeln("msg= %x", msg); + return 1; } /*****************************************************************************/ int APP_CC @@ -793,7 +788,7 @@ xrdp_rdp_send_demand_active(struct xrdp_rdp *self) INPUT_FLAG_FASTPATH_INPUT 0x0008 INPUT_FLAG_FASTPATH_INPUT2 0x0020 */ flags = 0x0001 | 0x0004; - if (self->client_info.use_fast_path & 2) +// if (self->client_info.use_fast_path & 2) flags |= 0x0008 | 0x0020; out_uint16_le(s, flags); out_uint8s(s, 82); diff --git a/libxrdp/xrdp_sec.c b/libxrdp/xrdp_sec.c index 38ee93f3..40fedb85 100644 --- a/libxrdp/xrdp_sec.c +++ b/libxrdp/xrdp_sec.c @@ -740,12 +740,22 @@ xrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan) { int flags; int len; + int mcs_msg; DEBUG((" in xrdp_sec_recv")); - if (xrdp_mcs_recv(self->mcs_layer, s, chan) != 0) + mcs_msg = xrdp_mcs_recv(self->mcs_layer, s, chan); + + if (mcs_msg == 2) + { + DEBUG((" out xrdp_sec_recv : non-TPKT msg detected, we try fastpath")); +// xrdp_sec_recv_fastpath(self->mcs_layer->iso_layer, s); + return mcs_msg; + } + + if (mcs_msg == 1) { - DEBUG((" out xrdp_sec_recv error")); + DEBUG((" out xrdp_sec_recv : error")); return 1; } -- cgit v1.2.3 From 80204e2536327f46610d5925c552aff235e9f447 Mon Sep 17 00:00:00 2001 From: speidy Date: Tue, 11 Feb 2014 00:28:43 +0200 Subject: libxrdp: work on fastpath input, added fastpath option to xrdp.ini --- common/xrdp_constants.h | 1 + libxrdp/xrdp_fastpath.c | 8 ++--- libxrdp/xrdp_iso.c | 3 +- libxrdp/xrdp_mcs.c | 2 +- libxrdp/xrdp_rdp.c | 88 +++++++++++++++++++++++++++++++++++++++++++++---- libxrdp/xrdp_sec.c | 2 +- xrdp/xrdp.ini | 3 ++ 7 files changed, 92 insertions(+), 15 deletions(-) (limited to 'libxrdp/xrdp_mcs.c') diff --git a/common/xrdp_constants.h b/common/xrdp_constants.h index 0dc327df..d3f20a46 100644 --- a/common/xrdp_constants.h +++ b/common/xrdp_constants.h @@ -161,6 +161,7 @@ #define RDP_INPUT_VIRTKEY 2 #define RDP_INPUT_SCANCODE 4 #define RDP_INPUT_MOUSE 0x8001 +#define RDP_INPUT_MOUSEX 0x8002 /* Device flags */ #define KBD_FLAG_RIGHT 0x0001 diff --git a/libxrdp/xrdp_fastpath.c b/libxrdp/xrdp_fastpath.c index 71e7f7c6..fcd7ac72 100644 --- a/libxrdp/xrdp_fastpath.c +++ b/libxrdp/xrdp_fastpath.c @@ -58,7 +58,7 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) int fp_hdr; int len = 0; int byte; - int hdr_len = 2; + int hdr_len = 2; /* fastpath header lenght - can be 2 or 3 bytes long, depends on length */ DEBUG((" in xrdp_fastpath_recv")); /* read the first fastpath byte @@ -68,7 +68,7 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) self->numEvents = (fp_hdr & 0x3C) >> 2; self->secFlags = (fp_hdr & 0xC0) >> 6; - // receive fastpath first packet length + // receive fastpath first length packet if (xrdp_tcp_recv(self->tcp_layer, s, 1) != 0) { return 1; @@ -80,7 +80,7 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) { byte &= ~(0x80); len = (byte << 8); - // receive fastpath second packet length + // receive fastpath second length packet if (xrdp_tcp_recv(self->tcp_layer, s, 1) != 0) { return 1; @@ -94,7 +94,7 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) len = byte; } - g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data)); + //g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data)); // receive the left bytes if (xrdp_tcp_recv(self->tcp_layer, s, len - hdr_len) != 0) diff --git a/libxrdp/xrdp_iso.c b/libxrdp/xrdp_iso.c index f29cbf23..1f546b0b 100644 --- a/libxrdp/xrdp_iso.c +++ b/libxrdp/xrdp_iso.c @@ -98,7 +98,7 @@ xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len) if (plen == 2) { - DEBUG((" xrdp_iso_recv_msg: non-TPKT header detected, we try fastpath")); + DEBUG(("xrdp_iso_recv_msg: non-TPKT header detected, we try fastpath")); return plen; } @@ -164,7 +164,6 @@ xrdp_iso_recv_tpkt_header(struct xrdp_iso *self, struct stream *s) } in_uint8_peek(s, ver); // Peek only so we can use it later in fastpath layer, if needed - g_writeln(" tpkt version: %x", ver); // TODO: delete it if (ver != 3) { diff --git a/libxrdp/xrdp_mcs.c b/libxrdp/xrdp_mcs.c index 81e8b758..2c643373 100644 --- a/libxrdp/xrdp_mcs.c +++ b/libxrdp/xrdp_mcs.c @@ -132,7 +132,7 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan) if (iso_msg == 2) // non-TPKT header { - DEBUG((" out xrdp_mcs_recv, non-TPKT header detected, we try fastpath")); + DEBUG((" out xrdp_mcs_recv, non-TPKT header detected, we try fastpath")); return iso_msg; } diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index 226b1b52..a98d507e 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -118,6 +118,31 @@ xrdp_rdp_read_config(struct xrdp_client_info *client_info) { client_info->require_credentials = g_text2bool(value); } + else if (g_strcasecmp(item, "use_fastpath") == 0) + { + if (g_strcasecmp(value, "output") == 0) + { + client_info->use_fast_path = 1; + } + else if (g_strcasecmp(value, "input") == 0) + { + client_info->use_fast_path = 2; + } + else if (g_strcasecmp(value, "both") == 0) + { + client_info->use_fast_path = 3; + } + else if (g_strcasecmp(value, "none") == 0) + { + client_info->use_fast_path = 0; + } + else + { + log_message(LOG_LEVEL_ALWAYS,"Warning: Your configured fastpath level is" + "undefined, fastpath will not be used"); + client_info->use_fast_path = 0; + } + } } list_delete(items); @@ -778,7 +803,7 @@ xrdp_rdp_send_demand_active(struct xrdp_rdp *self) INPUT_FLAG_FASTPATH_INPUT 0x0008 INPUT_FLAG_FASTPATH_INPUT2 0x0020 */ flags = 0x0001 | 0x0004; -// if (self->client_info.use_fast_path & 2) + if (self->client_info.use_fast_path & 2) flags |= 0x0008 | 0x0020; out_uint16_le(s, flags); out_uint8s(s, 82); @@ -1711,6 +1736,9 @@ xrdp_rdp_process_fastpath_data_input(struct xrdp_rdp *self, struct stream *s) int flags; int param2; int time; + int pointerFlags; + int xPos; + int yPos; // process fastpath input events for (i = 0 ; i < self->sec_layer->fastpath_layer->numEvents ; i++) { @@ -1718,12 +1746,15 @@ xrdp_rdp_process_fastpath_data_input(struct xrdp_rdp *self, struct stream *s) eventFlags = (eventHeader & 0x1F); eventCode = (eventHeader >> 5); - g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d", eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents); + + //g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d", + // eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents); + switch (eventCode) { case FASTPATH_INPUT_EVENT_SCANCODE: in_uint8(s, code); /* keyCode (1 byte) */ - g_writeln("scan code detected: %d", code); + //g_writeln("scan code detected: %d", code); flags = 0; if ((eventFlags & FASTPATH_INPUT_KBDFLAGS_RELEASE)) flags |= KBD_FLAG_UP; @@ -1747,15 +1778,58 @@ xrdp_rdp_process_fastpath_data_input(struct xrdp_rdp *self, struct stream *s) break; case FASTPATH_INPUT_EVENT_MOUSE: - in_uint8s(s, 6); + in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ + in_uint16_le(s, xPos); /* xPos (2 bytes) */ + in_uint16_le(s, yPos); /* yPos (2 bytes) */ + + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_MOUSE, xPos, yPos, + pointerFlags, 0); + } break; case FASTPATH_INPUT_EVENT_MOUSEX: - in_uint8s(s, 6); + in_uint16_le(s, pointerFlags); /* pointerFlags (2 bytes) */ + in_uint16_le(s, xPos); /* xPos (2 bytes) */ + in_uint16_le(s, yPos); /* yPos (2 bytes) */ + + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_MOUSEX, xPos, yPos, + pointerFlags, 0); + } break; case FASTPATH_INPUT_EVENT_SYNC: - + /* + * The eventCode bitfield (3 bits in size) MUST be set to FASTPATH_INPUT_EVENT_SYNC (3). + * The eventFlags bitfield (5 bits in size) contains flags indicating the "on" + * status of the keyboard toggle keys. + */ + if (self->session->callback != 0) + { + /* msg_type can be + RDP_INPUT_SYNCHRONIZE - 0 + RDP_INPUT_SCANCODE - 4 + RDP_INPUT_MOUSE - 0x8001 + RDP_INPUT_MOUSEX - 0x8002 */ + /* call to xrdp_wm.c : callback */ + self->session->callback(self->session->id, RDP_INPUT_SYNCHRONIZE, eventCode, 0, + eventFlags, 0); + } break; case FASTPATH_INPUT_EVENT_UNICODE: @@ -1763,7 +1837,7 @@ xrdp_rdp_process_fastpath_data_input(struct xrdp_rdp *self, struct stream *s) break; default: - printf("Unknown eventCode %d\n", eventCode); + g_writeln("xrdp_rdp_process_fastpath_data_input: unknown eventCode %d", eventCode); break; } diff --git a/libxrdp/xrdp_sec.c b/libxrdp/xrdp_sec.c index 4846c356..37209772 100644 --- a/libxrdp/xrdp_sec.c +++ b/libxrdp/xrdp_sec.c @@ -774,8 +774,8 @@ xrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan) if (mcs_msg == 2) { - DEBUG((" out xrdp_sec_recv : non-TPKT msg detected, we try fastpath")); xrdp_sec_recv_fastpath(self, s); + DEBUG((" out xrdp_sec_recv : non-TPKT msg detected, we try fastpath")); return mcs_msg; } diff --git a/xrdp/xrdp.ini b/xrdp/xrdp.ini index 0e8d302b..f89e78d9 100644 --- a/xrdp/xrdp.ini +++ b/xrdp/xrdp.ini @@ -37,6 +37,9 @@ tcp_keepalive=yes #nego_sec_layer=0 allow_multimon=true +# fastpath - can be set to input / output / both / none +use_fastpath=input + [Logging] LogFile=xrdp.log LogLevel=DEBUG -- cgit v1.2.3 From 43f4d439ec52616ccf6380374e21bce0b7087694 Mon Sep 17 00:00:00 2001 From: speidy Date: Tue, 4 Mar 2014 10:19:19 +0200 Subject: libxrdp: work on fastpath, length issue --- libxrdp/libxrdp.c | 1 + libxrdp/xrdp_fastpath.c | 35 +++++++++++++++++++---------------- libxrdp/xrdp_iso.c | 2 +- libxrdp/xrdp_mcs.c | 12 +----------- libxrdp/xrdp_rdp.c | 22 ++++++++++++++++------ libxrdp/xrdp_sec.c | 13 +------------ xrdp/xrdp_process.c | 1 + 7 files changed, 40 insertions(+), 46 deletions(-) (limited to 'libxrdp/xrdp_mcs.c') diff --git a/libxrdp/libxrdp.c b/libxrdp/libxrdp.c index ae2690f2..dc7a9869 100644 --- a/libxrdp/libxrdp.c +++ b/libxrdp/libxrdp.c @@ -29,6 +29,7 @@ libxrdp_init(tbus id, struct trans *trans) session = (struct xrdp_session *)g_malloc(sizeof(struct xrdp_session), 1); session->id = id; + session->trans = trans; session->rdp = xrdp_rdp_create(session, trans); session->orders = xrdp_orders_create(session, (struct xrdp_rdp *)session->rdp); session->client_info = &(((struct xrdp_rdp *)session->rdp)->client_info); diff --git a/libxrdp/xrdp_fastpath.c b/libxrdp/xrdp_fastpath.c index bc6f49d2..e7308ba0 100644 --- a/libxrdp/xrdp_fastpath.c +++ b/libxrdp/xrdp_fastpath.c @@ -58,22 +58,23 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) int fp_hdr; int len = 0; int byte; - int hdr_len = 2; /* fastpath header lenght - can be 2 or 3 bytes long, depends on length */ + int hdr_len = 2; /* fastpath header length - can be 2 or 3 bytes long, depends on length */ DEBUG((" in xrdp_fastpath_recv")); /* read the first fastpath byte * (we already received it via iso layer */ + // receive fastpath first length packet + init_stream(s, hdr_len); + if (trans_force_read_s(self->trans, s, hdr_len) != 0) + { + return 1; + } in_uint8(s, fp_hdr); /* fpInputHeader (1 byte) */ self->numEvents = (fp_hdr & 0x3C) >> 2; self->secFlags = (fp_hdr & 0xC0) >> 6; // receive fastpath first length packet - if (trans_force_read_s(self->trans, s, 1) != 0) - { - return 1; - } - in_uint8(s, byte); /* length 1 */ if (byte & 0x80) @@ -81,7 +82,8 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) byte &= ~(0x80); len = (byte << 8); // receive fastpath second length packet - if (xrdp_tcp_recv(self->tcp_layer, s, 1) != 0) + init_stream(s, 1); + if (trans_force_read_s(self->trans, s, 1) != 0) { return 1; } @@ -94,10 +96,11 @@ xrdp_fastpath_recv(struct xrdp_fastpath *self, struct stream *s) len = byte; } - //g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data)); + g_writeln("len= %d , numEvents= %d, secFlags= %d, bytesleft: %d", len, self->numEvents, self->secFlags, (s->p - s->data)); // receive the left bytes - if (xrdp_tcp_recv(self->tcp_layer, s, len - hdr_len) != 0) + init_stream(s, len - hdr_len); + if (trans_force_read_s(self->trans, s, len - hdr_len) != 0) { return 1; } @@ -166,10 +169,10 @@ xrdp_fastpath_send_update_pdu(struct xrdp_fastpath *self, tui8 updateCode, // s_copy(s_send, s, len); s_mark_end(s_send); - if (xrdp_tcp_send(self->tcp_layer, s_send) != 0) - { - return 1; - } +// if (xrdp_tcp_send(self->tcp_layer, s_send) != 0) +// { +// return 1; +// } } return 0; @@ -220,12 +223,12 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, encryptionFlags = (header & 0xc0) >> 6; numberEvents = (header & 0x3c) >> 2; - xrdp_tcp_recv(self->tcp_layer, s, 1); +// xrdp_tcp_recv(self->tcp_layer, s, 1); in_uint8(s, length); if (length & 0x80) { - xrdp_tcp_recv(self->tcp_layer, s, 1); +// xrdp_tcp_recv(self->tcp_layer, s, 1); in_uint8(s, length2); length = (length & 0x7f) << 8 + length2 - 3; } @@ -234,7 +237,7 @@ xrdp_fastpath_process_data(struct xrdp_fastpath *self, struct stream *s, length -= 2; } - xrdp_tcp_recv(self->tcp_layer, s, length); +// xrdp_tcp_recv(self->tcp_layer, s, length); if (encryptionFlags != 0) { diff --git a/libxrdp/xrdp_iso.c b/libxrdp/xrdp_iso.c index df00f52b..31c279b5 100644 --- a/libxrdp/xrdp_iso.c +++ b/libxrdp/xrdp_iso.c @@ -111,7 +111,7 @@ xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len) if (ver != 3) { - return 2; // special code for fastpath + return 1; } in_uint8s(s, 1); diff --git a/libxrdp/xrdp_mcs.c b/libxrdp/xrdp_mcs.c index 526587d5..08055191 100644 --- a/libxrdp/xrdp_mcs.c +++ b/libxrdp/xrdp_mcs.c @@ -122,21 +122,11 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan) int len; int userid; int chanid; - int iso_msg; DEBUG((" in xrdp_mcs_recv")); while (1) { - - iso_msg = xrdp_iso_recv(self->iso_layer, s); - - if (iso_msg == 2) // non-TPKT header - { - DEBUG((" out xrdp_mcs_recv, non-TPKT header detected, we try fastpath")); - return iso_msg; - } - - if (iso_msg == 1) // error + if (xrdp_iso_recv(self->iso_layer, s) != 0) { DEBUG((" out xrdp_mcs_recv, xrdp_iso_recv return non zero")); return 1; diff --git a/libxrdp/xrdp_rdp.c b/libxrdp/xrdp_rdp.c index 85ca15d7..ea2204f5 100644 --- a/libxrdp/xrdp_rdp.c +++ b/libxrdp/xrdp_rdp.c @@ -299,20 +299,30 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) int len = 0; int pdu_code = 0; int chan = 0; + const tui8 *header; + header = (const tui8 *) (self->session->trans->in_s->p); DEBUG(("in xrdp_rdp_recv")); + /* not fastpath, do tpkt */ if (s->next_packet == 0 || s->next_packet >= s->end) { - chan = 0; - error = xrdp_sec_recv(self->sec_layer, s, &chan); + /* check for fastpath first */ + g_writeln("xrdp_rdp_recv: header= 0x%8.8x", header[0]); - if (error == 2) /* we have fastpath packet! */ + if ((header[0] & 0x3) == 0 && (header[0] != 0x3c)) { - *code = 2; + if (xrdp_sec_recv_fastpath(self->sec_layer, s) != 0) + { + return 1; + } + *code = 2; // special code for fastpath return 0; } + chan = 0; + error = xrdp_sec_recv(self->sec_layer, s, &chan); + if (error == -1) /* special code for send demand active */ { s->next_packet = 0; @@ -1691,8 +1701,8 @@ xrdp_rdp_process_fastpath_data_input(struct xrdp_rdp *self, struct stream *s) eventFlags = (eventHeader & 0x1F); eventCode = (eventHeader >> 5); - //g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d", - // eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents); +// g_writeln("eventCode= %d, eventFlags= %d, numEvents= %d", +// eventCode, eventFlags, self->sec_layer->fastpath_layer->numEvents); switch (eventCode) { diff --git a/libxrdp/xrdp_sec.c b/libxrdp/xrdp_sec.c index ec9b5711..6b8dbbc4 100644 --- a/libxrdp/xrdp_sec.c +++ b/libxrdp/xrdp_sec.c @@ -972,23 +972,12 @@ xrdp_sec_recv(struct xrdp_sec *self, struct stream *s, int *chan) { int flags; int len; - int mcs_msg; int ver; int pad; - DEBUG((" in xrdp_sec_recv")); - mcs_msg = xrdp_mcs_recv(self->mcs_layer, s, chan); - - if (mcs_msg == 2) - { - xrdp_sec_recv_fastpath(self, s); - DEBUG((" out xrdp_sec_recv : non-TPKT msg detected, we try fastpath")); - return mcs_msg; - } - - if (mcs_msg == 1) + if (xrdp_mcs_recv(self->mcs_layer, s, chan) != 0) { DEBUG((" out xrdp_sec_recv : error")); return 1; diff --git a/xrdp/xrdp_process.c b/xrdp/xrdp_process.c index 78576f1f..fe6e2c4b 100644 --- a/xrdp/xrdp_process.c +++ b/xrdp/xrdp_process.c @@ -123,6 +123,7 @@ xrdp_process_get_pdu_bytes(const char *aheader) rv = -1; header = (const tui8 *) aheader; + if (header[0] == 0x03) { /* TPKT */ -- cgit v1.2.3