From 724cface99da781732deea697cf23c03bb582dda Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 27 Aug 2001 15:13:14 +0000 Subject: [PATCH] Port forwarding bug fix: we were unable to handle receiving CHANNEL_OPEN_FAILURE messages, which occur when the remote side is unable to open a forwarded network connection we have requested. (It seems they _don't_ show up if you get something mundane like Connection Refused - the channel is cheerfully opened and immediately slammed shut - but they do if you try to connect to a host that doesn't even exist. Try forwarding a port to frogwibbler:4800 and see what you get.) git-svn-id: svn://svn.tartarus.org/sgt/putty@1213 cda61777-01e9-0310-a592-d414129be87e --- ssh.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ssh.c b/ssh.c index 2c538239..4856e630 100644 --- a/ssh.c +++ b/ssh.c @@ -2841,6 +2841,19 @@ static void ssh1_protocol(unsigned char *in, int inlen, int ispkt) pfd_confirm(c->u.pfd.s); } + } else if (pktin.type == SSH1_MSG_CHANNEL_OPEN_FAILURE) { + unsigned int remoteid = GET_32BIT(pktin.body); + unsigned int localid = GET_32BIT(pktin.body+4); + struct ssh_channel *c; + + c = find234(ssh_channels, &remoteid, ssh_channelfind); + if (c && c->type == CHAN_SOCKDATA_DORMANT) { + logevent("Forwarded connection refused by server"); + pfd_close(c->u.pfd.s); + del234(ssh_channels, c); + sfree(c); + } + } else if (pktin.type == SSH1_MSG_CHANNEL_CLOSE || pktin.type == SSH1_MSG_CHANNEL_CLOSE_CONFIRMATION) { /* Remote side closes a channel. */ @@ -4773,6 +4786,21 @@ static void do_ssh2_authconn(unsigned char *in, int inlen, int ispkt) c->v.v2.remmaxpkt = ssh2_pkt_getuint32(); bufchain_init(&c->v.v2.outbuffer); pfd_confirm(c->u.pfd.s); + } else if (pktin.type == SSH2_MSG_CHANNEL_OPEN_FAILURE) { + unsigned i = ssh2_pkt_getuint32(); + struct ssh_channel *c; + c = find234(ssh_channels, &i, ssh_channelfind); + if (!c) + continue; /* nonexistent channel */ + if (c->type != CHAN_SOCKDATA_DORMANT) + continue; /* dunno why they're failing this */ + + logevent("Forwarded connection refused by server"); + + pfd_close(c->u.pfd.s); + + del234(ssh_channels, c); + sfree(c); } else if (pktin.type == SSH2_MSG_CHANNEL_OPEN) { char *type; int typelen; -- 2.11.0