libxrdp: work on fastpath

This commit is contained in:
speidy 2014-02-08 13:34:01 +02:00
parent 423c583cdd
commit 113f2696fe
9 changed files with 223 additions and 104 deletions

View File

@ -116,7 +116,8 @@ struct stream
(v) = *((unsigned char*)((s)->p)); \ (v) = *((unsigned char*)((s)->p)); \
(s)->p++; \ (s)->p++; \
} while (0) } while (0)
/******************************************************************************/
#define in_uint8_peek(s, v) do { v = *s->p; } while (0)
/******************************************************************************/ /******************************************************************************/
#if defined(B_ENDIAN) || defined(NEED_ALIGN) #if defined(B_ENDIAN) || defined(NEED_ALIGN)
#define in_sint16_le(s, v) do \ #define in_sint16_le(s, v) do \

View File

@ -128,7 +128,6 @@ libxrdp_process_data(struct xrdp_session *session)
session->s); session->s);
break; break;
case RDP_PDU_DATA: /* 7 */ case RDP_PDU_DATA: /* 7 */
if (xrdp_rdp_process_data((struct xrdp_rdp *)session->rdp, if (xrdp_rdp_process_data((struct xrdp_rdp *)session->rdp,
session->s) != 0) session->s) != 0)
{ {
@ -139,7 +138,7 @@ libxrdp_process_data(struct xrdp_session *session)
break; break;
default: default:
g_writeln("unknown in libxrdp_process_data"); g_writeln("unknown in libxrdp_process_data: code= %d", code);
dead_lock_counter++; dead_lock_counter++;
break; break;
} }

View File

@ -290,6 +290,8 @@ int APP_CC
xrdp_iso_send(struct xrdp_iso* self, struct stream* s); xrdp_iso_send(struct xrdp_iso* self, struct stream* s);
int APP_CC int APP_CC
xrdp_iso_incoming(struct xrdp_iso* self); xrdp_iso_incoming(struct xrdp_iso* self);
int APP_CC
xrdp_iso_detect_tpkt(struct xrdp_iso *self, struct stream *s);
/* xrdp_mcs.c */ /* xrdp_mcs.c */
struct xrdp_mcs* APP_CC struct xrdp_mcs* APP_CC

View File

@ -2,7 +2,7 @@
* xrdp: A Remote Desktop Protocol server. * xrdp: A Remote Desktop Protocol server.
* *
* Copyright (C) Jay Sorg 2012-2013 * Copyright (C) Jay Sorg 2012-2013
* Copyright (C) Kevin Zhou 2012 * Copyright (C) Idan Freiberg 2013-2014
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

View File

@ -89,61 +89,25 @@ xrdp_iso_recv_rdpnegreq(struct xrdp_iso *self, struct stream *s)
static int APP_CC static int APP_CC
xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len) xrdp_iso_recv_msg(struct xrdp_iso *self, struct stream *s, int *code, int *len)
{ {
int ver; // TPKT Version int plen; // PacketLength
int plen; // TPKT PacketLength
*code = 0; // X.224 Packet Type *code = 0; // X.224 Packet Type
*len = 0; // X.224 Length Indicator *len = 0; // X.224 Length Indicator
if (xrdp_tcp_recv(self->tcp_layer, s, 4) != 0) plen = xrdp_iso_recv_tpkt_header(self, s);
{ if (plen == 1)
return 1;
}
in_uint8(s, ver);
if (ver != 3)
{
return 1;
}
in_uint8s(s, 1);
in_uint16_be(s, plen);
if (plen < 4)
{ {
DEBUG((" xrdp_iso_recv_msg: error in tpkt header reading"));
return 1; return 1;
} }
// receive the left bytes
if (xrdp_tcp_recv(self->tcp_layer, s, plen - 4) != 0) if (xrdp_tcp_recv(self->tcp_layer, s, plen - 4) != 0)
{ {
return 1; return 1;
} }
if (!s_check_rem(s, 2)) xrdp_iso_read_x224_header(s, code, len);
{
return 1;
}
in_uint8(s, *len);
in_uint8(s, *code);
if (*code == ISO_PDU_DT)
{
if (!s_check_rem(s, 1))
{
return 1;
}
in_uint8s(s, 1);
}
else
{
if (!s_check_rem(s, 5))
{
return 1;
}
in_uint8s(s, 5);
}
return 0; return 0;
} }
@ -172,40 +136,148 @@ xrdp_iso_recv(struct xrdp_iso *self, struct stream *s)
DEBUG((" out xrdp_iso_recv")); DEBUG((" out xrdp_iso_recv"));
return 0; return 0;
} }
/*****************************************************************************/
/* returns error */
int APP_CC
xrdp_iso_detect_tpkt(struct xrdp_iso *self, struct stream *s)
{
int ver;
DEBUG((" in xrdp_iso_detect_tpkt"));
if (xrdp_tcp_recv(self->tcp_layer, s, 1) != 0)
{
return 1;
}
in_uint8_peek(s, ver);
g_writeln("tpkt version: %x", ver);
if (ver != 3)
{
return 1;
}
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;
}
in_uint8s(s, 1);
in_uint16_be(s, plen);
if (plen < 4)
{
return 1; // tpkt must be >= 4 bytes length
}
DEBUG((" out xrdp_iso_recv_tpkt_header"));
return plen;
}
/*****************************************************************************/
void APP_CC
xrdp_iso_write_tpkt_header(struct stream *s, int len)
{
/* TPKT HEADER - 4 bytes */
out_uint8(s, 3); /* version */
out_uint8(s, 0); /* RESERVED */
out_uint16_be(s, len); /* length */
}
/*****************************************************************************/
/* returns error */
int APP_CC
xrdp_iso_read_x224_header(struct stream *s, int *code, int *len)
{
DEBUG((" in xrdp_iso_read_x224_header"));
if (!s_check_rem(s, 2))
{
return 1;
}
in_uint8(s, *len); /* length */
in_uint8(s, *code); /* code */
if (*code == ISO_PDU_DT)
{
if (!s_check_rem(s, 1))
{
return 1;
}
in_uint8s(s, 1);
}
else
{
if (!s_check_rem(s, 5))
{
return 1;
}
in_uint8s(s, 5);
}
DEBUG((" out xrdp_iso_read_x224_header"));
return 0;
}
/*****************************************************************************/
void APP_CC
xrdp_iso_write_x224_header(struct stream *s, int len, int code)
{
/* ISO LAYER - X.224 - 7 bytes*/
out_uint8(s, len); /* length */
out_uint8(s, code); /* code */
if (code == ISO_PDU_DT)
{
out_uint8(s, 0x80);
} else {
out_uint16_be(s, 0);
out_uint16_be(s, 0x1234);
out_uint8(s, 0);
}
}
/*****************************************************************************/ /*****************************************************************************/
static int APP_CC static int APP_CC
xrdp_iso_send_rdpnegrsp(struct xrdp_iso *self, struct stream *s, int code) xrdp_iso_send_rdpnegrsp(struct xrdp_iso *self, struct stream *s)
{ {
if (xrdp_tcp_init(self->tcp_layer, s) != 0) if (xrdp_tcp_init(self->tcp_layer, s) != 0)
{ {
return 1; return 1;
} }
/* TPKT HEADER - 4 bytes */ // Write TPKT Header
out_uint8(s, 3); /* version */
out_uint8(s, 0); /* RESERVED */
if (self->selectedProtocol != -1) if (self->selectedProtocol != -1)
{ {
out_uint16_be(s, 19); /* length */ //rdp negotiation happens. //rdp negotiation happens.
xrdp_iso_write_tpkt_header(s, 19);
} }
else else
{ {
out_uint16_be(s, 11); /* length */ //rdp negotiation doesn't happen. //rdp negotiation doesn't happen.
xrdp_iso_write_tpkt_header(s, 11);
} }
/* ISO LAYER - X.224 - 7 bytes*/
// Write x224 header
if (self->selectedProtocol != -1) if (self->selectedProtocol != -1)
{ {
out_uint8(s, 14); /* length */ xrdp_iso_write_x224_header(s, 14, ISO_PDU_CC);
} }
else else
{ {
out_uint8(s, 6); /* length */ xrdp_iso_write_x224_header(s, 6, ISO_PDU_CC);
} }
out_uint8(s, code); /* SHOULD BE 0xD for CC */
out_uint16_be(s, 0); /* RDP_NEG */
out_uint16_be(s, 0x1234);
out_uint8(s, 0);
if (self->selectedProtocol != -1) if (self->selectedProtocol != -1)
{ {
/* RDP_NEG_RSP - 8 bytes*/ /* RDP_NEG_RSP - 8 bytes*/
@ -226,23 +298,17 @@ xrdp_iso_send_rdpnegrsp(struct xrdp_iso *self, struct stream *s, int code)
} }
/*****************************************************************************/ /*****************************************************************************/
static int APP_CC static int APP_CC
xrdp_iso_send_rdpnegfailure(struct xrdp_iso *self, struct stream *s, int code, int failureCode) xrdp_iso_send_rdpnegfailure(struct xrdp_iso *self, struct stream *s, int failureCode)
{ {
if (xrdp_tcp_init(self->tcp_layer, s) != 0) if (xrdp_tcp_init(self->tcp_layer, s) != 0)
{ {
return 1; return 1;
} }
/* TPKT HEADER - 4 bytes */ xrdp_iso_write_tpkt_header(s, 19);
out_uint8(s, 3); /* version */
out_uint8(s, 0); /* RESERVED */ xrdp_iso_write_x224_header(s, 14, ISO_PDU_CC);
out_uint16_be(s, 19); /* length */
/* ISO LAYER - X.224 - 7 bytes*/
out_uint8(s, 14); /* length */
out_uint8(s, code); /* SHOULD BE 0xD for CC */
out_uint16_be(s, 0);
out_uint16_be(s, 0x1234);
out_uint8(s, 0);
/* RDP_NEG_FAILURE - 8 bytes*/ /* RDP_NEG_FAILURE - 8 bytes*/
out_uint8(s, RDP_NEG_FAILURE); out_uint8(s, RDP_NEG_FAILURE);
out_uint8(s, 0); /* no flags available */ out_uint8(s, 0); /* no flags available */
@ -271,8 +337,7 @@ xrdp_iso_send_nego(struct xrdp_iso *self)
if (self->requestedProtocol != PROTOCOL_RDP) if (self->requestedProtocol != PROTOCOL_RDP)
{ {
// Send RDP_NEG_FAILURE back to client // Send RDP_NEG_FAILURE back to client
if (xrdp_iso_send_rdpnegfailure(self, s, ISO_PDU_CC, if (xrdp_iso_send_rdpnegfailure(self, s, SSL_NOT_ALLOWED_BY_SERVER) != 0)
SSL_NOT_ALLOWED_BY_SERVER) != 0)
{ {
free_stream(s); free_stream(s);
return 1; return 1;
@ -282,7 +347,7 @@ xrdp_iso_send_nego(struct xrdp_iso *self)
{ {
self->selectedProtocol = PROTOCOL_RDP; self->selectedProtocol = PROTOCOL_RDP;
// Send RDP_NEG_RSP back to client // Send RDP_NEG_RSP back to client
if (xrdp_iso_send_rdpnegrsp(self, s, ISO_PDU_CC) != 0) if (xrdp_iso_send_rdpnegrsp(self, s) != 0)
{ {
free_stream(s); free_stream(s);
return 1; return 1;
@ -309,6 +374,13 @@ xrdp_iso_incoming(struct xrdp_iso *self)
init_stream(s, 8192); init_stream(s, 8192);
DEBUG((" in xrdp_iso_incoming")); 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) if (xrdp_iso_recv_msg(self, s, &code, &len) != 0)
{ {
DEBUG((" in xrdp_iso_recv_msg error!!")); DEBUG((" in xrdp_iso_recv_msg error!!"));
@ -318,6 +390,7 @@ xrdp_iso_incoming(struct xrdp_iso *self)
if ((code != ISO_PDU_CR) || (len < 6)) if ((code != ISO_PDU_CR) || (len < 6))
{ {
DEBUG((" in xrdp_iso_recv_msg error: non iso_pdu_cr msg"));
free_stream(s); free_stream(s);
return 1; return 1;
} }
@ -394,12 +467,9 @@ xrdp_iso_send(struct xrdp_iso *self, struct stream *s)
DEBUG((" in xrdp_iso_send")); DEBUG((" in xrdp_iso_send"));
s_pop_layer(s, iso_hdr); s_pop_layer(s, iso_hdr);
len = (int)(s->end - s->p); len = (int)(s->end - s->p);
out_uint8(s, 3);
out_uint8(s, 0); xrdp_iso_write_tpkt_header(s, len);
out_uint16_be(s, len); xrdp_iso_write_x224_header(s, 2, ISO_PDU_DT);
out_uint8(s, 2);
out_uint8(s, ISO_PDU_DT);
out_uint8(s, 0x80);
if (xrdp_tcp_send(self->tcp_layer, s) != 0) if (xrdp_tcp_send(self->tcp_layer, s) != 0)
{ {

View File

@ -127,12 +127,14 @@ xrdp_mcs_recv(struct xrdp_mcs *self, struct stream *s, int *chan)
while (1) while (1)
{ {
if (xrdp_iso_recv(self->iso_layer, s) != 0) 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; return 1;
} }
if (!s_check_rem(s, 1)) if (!s_check_rem(s, 1))
{ {
return 1; return 1;
@ -320,10 +322,16 @@ xrdp_mcs_recv_connect_initial(struct xrdp_mcs *self)
make_stream(s); make_stream(s);
init_stream(s, 16 * 1024); init_stream(s, 16 * 1024);
if (xrdp_iso_recv(self->iso_layer, s) != 0) if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) {
{ if (xrdp_iso_recv(self->iso_layer, s) != 0)
free_stream(s); {
return 1; 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) 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); make_stream(s);
init_stream(s, 8192); init_stream(s, 8192);
if (xrdp_iso_recv(self->iso_layer, s) != 0) if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) {
{ if (xrdp_iso_recv(self->iso_layer, s) != 0)
free_stream(s); {
return 1; 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)) if (!s_check_rem(s, 1))
@ -503,12 +517,19 @@ xrdp_mcs_recv_aurq(struct xrdp_mcs *self)
make_stream(s); make_stream(s);
init_stream(s, 8192); init_stream(s, 8192);
if (xrdp_iso_recv(self->iso_layer, s) != 0) if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) {
{ if (xrdp_iso_recv(self->iso_layer, s) != 0)
free_stream(s); {
return 1; 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)) if (!s_check_rem(s, 1))
{ {
free_stream(s); free_stream(s);
@ -590,10 +611,16 @@ xrdp_mcs_recv_cjrq(struct xrdp_mcs *self)
make_stream(s); make_stream(s);
init_stream(s, 8192); init_stream(s, 8192);
if (xrdp_iso_recv(self->iso_layer, s) != 0) if (xrdp_iso_detect_tpkt(self->iso_layer, s) == 0) {
{ if (xrdp_iso_recv(self->iso_layer, s) != 0)
free_stream(s); {
return 1; 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)) if (!s_check_rem(s, 1))

View File

@ -259,9 +259,22 @@ xrdp_rdp_init_data(struct xrdp_rdp *self, struct stream *s)
} }
/*****************************************************************************/ /*****************************************************************************/
/* returns erros */ /* returns error */
int APP_CC int APP_CC
xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code) 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 error = 0;
int len = 0; int len = 0;
@ -338,7 +351,14 @@ xrdp_rdp_recv(struct xrdp_rdp *self, struct stream *s, int *code)
return 0; return 0;
} }
} }
/*****************************************************************************/
/* returns error */
int APP_CC
xrdp_rdp_recv_fastpath(struct xrdp_rdp *self, struct stream *s, int *code)
{
g_writeln("Booyah!");
return 0;
}
/*****************************************************************************/ /*****************************************************************************/
int APP_CC int APP_CC
xrdp_rdp_send(struct xrdp_rdp *self, struct stream *s, int pdu_type) xrdp_rdp_send(struct xrdp_rdp *self, struct stream *s, int pdu_type)

View File

@ -1075,10 +1075,10 @@ xrdp_sec_process_mcs_data(struct xrdp_sec *self)
switch (tag) switch (tag)
{ {
case SEC_TAG_CLI_INFO: case SEC_TAG_CLI_INFO:
if (xrdp_sec_process_mcs_cli_info(self, s) != 0) // if (xrdp_sec_process_mcs_cli_info(self, s) != 0)
{ // {
return 1; // return 1;
} // }
break; break;
case SEC_TAG_CLI_CRYPT: case SEC_TAG_CLI_CRYPT:
break; break;

View File

@ -56,7 +56,7 @@ xrdp_tcp_init(struct xrdp_tcp *self, struct stream *s)
int APP_CC int APP_CC
xrdp_tcp_recv(struct xrdp_tcp *self, struct stream *s, int len) xrdp_tcp_recv(struct xrdp_tcp *self, struct stream *s, int len)
{ {
DEBUG((" in xrdp_tcp_recv, gota get %d bytes", len)); DEBUG((" in xrdp_tcp_recv, gota get %d bytes", len));
init_stream(s, len); init_stream(s, len);
if (trans_force_read_s(self->trans, s, len) != 0) if (trans_force_read_s(self->trans, s, len) != 0)
@ -65,7 +65,7 @@ xrdp_tcp_recv(struct xrdp_tcp *self, struct stream *s, int len)
return 1; return 1;
} }
DEBUG((" out xrdp_tcp_recv")); DEBUG((" out xrdp_tcp_recv"));
return 0; return 0;
} }