Skip to content

Commit f936714

Browse files
authored
Merge pull request #3 from shaddybaddah/2-rtun-stall
Fix #2 reverse tunnel server side stall by recv() on rconn ack
2 parents 1a02329 + 65049c1 commit f936714

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

server/commands.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static int cmd_data(const r2tmsg_t *msg, unsigned int len)
102102

103103
static int cmd_rconn(const r2tmsg_t *msg, unsigned int len)
104104
{
105+
int ret = 0;
105106
tunnel_t *tun;
106107

107108
trace_chan("len=%u, id=0x%02x", len, msg->id);
@@ -110,9 +111,12 @@ static int cmd_rconn(const r2tmsg_t *msg, unsigned int len)
110111
error("invalid tunnel id 0x%02x", msg->id);
111112
return 0;
112113
}
114+
if (tun->connected < 0) {
115+
while ((ret = tunnel_sockrecv_event(tun)) > 0);
116+
}
113117
tun->connected = 1;
114118

115-
return 0;
119+
return ret;
116120
}
117121

118122
const cmdhandler_t cmd_handlers[R2TCMD_MAX] = {

server/r2twin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ typedef struct _vchannel {
4747
typedef struct _tunnel {
4848
struct list_head list; /**< double-linked list */
4949
sock_t sock; /**< tunnel socket */
50-
unsigned char connected; /**< 1 if tunnel is connected */
50+
char connected; /**< 1 if tunnel is connected */
5151
unsigned char server; /**< 1 for reverse-connect tunnel */
5252
unsigned char id; /**< tunnel identifier */
5353
HANDLE proc; /**< child process HANDLE */
@@ -104,6 +104,7 @@ int tunnel_event(tunnel_t *, HANDLE);
104104
int tunnel_write(tunnel_t *tun, const void *, unsigned int);
105105
void tunnel_close(tunnel_t *);
106106
void tunnels_kill(void);
107+
int tunnel_sockrecv_event(tunnel_t *tun);
107108

108109
/* errors.c ***/
109110
int wsaerror(const char *);

server/tunnel.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ void tunnel_close(tunnel_t *tun)
331331
free(tun);
332332
}
333333

334-
static int tunnel_sockrecv_event(tunnel_t *tun)
334+
int tunnel_sockrecv_event(tunnel_t *tun)
335335
{
336336
int ret;
337337
unsigned int r;
@@ -501,8 +501,10 @@ int tunnel_event(tunnel_t *tun, HANDLE h)
501501

502502
if ((ret >= 0) && (evt & FD_READ)) {
503503
debug(0, "FD_READ");
504-
if (tun->connected)
504+
if (tun->connected > 0)
505505
ret = tunnel_sockrecv_event(tun);
506+
else
507+
tun->connected = -1;
506508
if (evt & FD_CLOSE)
507509
while ((ret = tunnel_sockrecv_event(tun)) > 0);
508510
}

0 commit comments

Comments
 (0)