From 0e1b0e24c19fa78fde796319c01f29e5593a2918 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Tue, 17 May 2016 15:57:51 +0200 Subject: [PATCH] Factor out common parts of ssh_unthrottle and sshfwd_unthrottle. The SSH-2 code is essentially all shared, but SSH-1 still has some code specific to the stdout/stderr case. --- ssh.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/ssh.c b/ssh.c index 476518f8..51605ab7 100644 --- a/ssh.c +++ b/ssh.c @@ -366,6 +366,7 @@ static void do_ssh2_authconn(Ssh ssh, const unsigned char *in, int inlen, struct Packet *pktin); static void ssh2_channel_check_close(struct ssh_channel *c); static void ssh_channel_destroy(struct ssh_channel *c); +static void ssh_channel_unthrottle(struct ssh_channel *c, int bufsize); static void ssh2_msg_something_unimplemented(Ssh ssh, struct Packet *pktin); /* @@ -5027,21 +5028,11 @@ int sshfwd_write(struct ssh_channel *c, char *buf, int len) void sshfwd_unthrottle(struct ssh_channel *c, int bufsize) { Ssh ssh = c->ssh; - int buflimit; if (ssh->state == SSH_STATE_CLOSED) return; - if (ssh->version == 1) { - buflimit = SSH1_BUFFER_LIMIT; - } else { - buflimit = c->v.v2.locmaxwin; - ssh2_set_window(c, bufsize < buflimit ? buflimit - bufsize : 0); - } - if (c->throttling_conn && bufsize <= buflimit) { - c->throttling_conn = 0; - ssh_throttle_conn(ssh, -1); - } + ssh_channel_unthrottle(c, bufsize); } static void ssh_queueing_handler(Ssh ssh, struct Packet *pktin) @@ -7880,6 +7871,26 @@ static struct Packet *ssh2_chanreq_init(struct ssh_channel *c, return pktout; } +static void ssh_channel_unthrottle(struct ssh_channel *c, int bufsize) +{ + Ssh ssh = c->ssh; + int buflimit; + + if (ssh->version == 1) { + buflimit = SSH1_BUFFER_LIMIT; + } else { + if (ssh_is_simple(ssh)) + buflimit = 0; + else + buflimit = c->v.v2.locmaxwin; + ssh2_set_window(c, bufsize < buflimit ? buflimit - bufsize : 0); + } + if (c->throttling_conn && bufsize <= buflimit) { + c->throttling_conn = 0; + ssh_throttle_conn(ssh, -1); + } +} + /* * Potentially enlarge the window on an SSH-2 channel. */ @@ -11769,7 +11780,6 @@ void ssh_send_packet_from_downstream(Ssh ssh, unsigned id, int type, static void ssh_unthrottle(void *handle, int bufsize) { Ssh ssh = (Ssh) handle; - int buflimit; if (ssh->version == 1) { if (ssh->v1_stdout_throttling && bufsize < SSH1_BUFFER_LIMIT) { @@ -11777,19 +11787,8 @@ static void ssh_unthrottle(void *handle, int bufsize) ssh_throttle_conn(ssh, -1); } } else { - if (ssh->mainchan) { - ssh2_set_window(ssh->mainchan, - bufsize < ssh->mainchan->v.v2.locmaxwin ? - ssh->mainchan->v.v2.locmaxwin - bufsize : 0); - if (ssh_is_simple(ssh)) - buflimit = 0; - else - buflimit = ssh->mainchan->v.v2.locmaxwin; - if (ssh->mainchan->throttling_conn && bufsize <= buflimit) { - ssh->mainchan->throttling_conn = 0; - ssh_throttle_conn(ssh, -1); - } - } + if (ssh->mainchan) + ssh_channel_unthrottle(ssh->mainchan, bufsize); } /* -- 2.45.2