Port forwarding bug fix: we were unable to handle receiving
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 27 Aug 2001 15:13:14 +0000 (15:13 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 27 Aug 2001 15:13:14 +0000 (15:13 +0000)
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

diff --git a/ssh.c b/ssh.c
index 2c53823..4856e63 100644 (file)
--- 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;