Skip to content

Commit 28c8606

Browse files
committed
There is a situation in SSH -> HPN connection the advertised
window will 16MB and then it will cause some odd behaviour on the part of the ssh client. Basically it looks like it's doing a lot of expensive drains and fills on a buffer that significantly impacts throughput. This is a fix that annoys me because *any* SSH to HPN connection is now limited to a maximum recieve window of 15MB. Which is not optimal in anyway. Still, it's better than the through put of the pathological state which significantly slower.
1 parent 38854e0 commit 28c8606

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

channels.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,10 +1250,12 @@ channel_tcpwinsz(struct ssh *ssh)
12501250
tcpwinsz = SSHBUF_SIZE_MAX;
12511251
/* if the remote side is OpenSSH after version 8.8 we need to restrict
12521252
* the size of the advertised window. Now this means that any HPN to non-HPN
1253-
* connection will be window limited but thats okay. This bug shows up when
1254-
* sending data to an hpn */
1255-
//if ((ssh->compat & SSH_RESTRICT_WINDOW) && (tcpwinsz > NON_HPN_WINDOW_MAX))
1256-
// tcpwinsz = NON_HPN_WINDOW_MAX;
1253+
* connection will be window limited to 15MB of receive space. This is a
1254+
* non-optimal solution.
1255+
*/
1256+
1257+
if ((ssh->compat & SSH_RESTRICT_WINDOW) && (tcpwinsz > NON_HPN_WINDOW_MAX))
1258+
tcpwinsz = NON_HPN_WINDOW_MAX;
12571259
return (tcpwinsz);
12581260
}
12591261

@@ -2368,10 +2370,6 @@ channel_check_window(struct ssh *ssh, Channel *c)
23682370
c->local_consumed > 0) {
23692371
u_int addition = 0;
23702372
u_int32_t tcpwinsz = channel_tcpwinsz(ssh);
2371-
if ((ssh->compat & SSH_RESTRICT_WINDOW) &&
2372-
(tcpwinsz > NON_HPN_WINDOW_MAX))
2373-
tcpwinsz = NON_HPN_WINDOW_MAX;
2374-
23752373
/* adjust max window size if we are in a dynamic environment
23762374
* and the tcp receive buffer is larger than the ssh window */
23772375
if (c->dynamic_window && (tcpwinsz > c->local_window_max)) {
@@ -2390,8 +2388,10 @@ channel_check_window(struct ssh *ssh, Channel *c)
23902388
addition = tcpwinsz - c->local_window_max;
23912389
}
23922390
c->local_window_max += addition;
2393-
//sshbuf_set_window_max(c->output, c->local_window_max);
2394-
//sshbuf_set_window_max(c->input, c->local_window_max);
2391+
/* doesn't look like we need these
2392+
* sshbuf_set_window_max(c->output, c->local_window_max);
2393+
* sshbuf_set_window_max(c->input, c->local_window_max);
2394+
*/
23952395
debug("Channel %d: Window growth to %d by %d bytes",c->self,
23962396
c->local_window_max, addition);
23972397
}

compat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,9 @@ compat_banner(struct ssh *ssh, const char *version)
124124
{ NULL, 0 }
125125
};
126126

127-
debug ("------------------------ VERSION IS %s", version);
128127
/* process table, return first match */
129128
ssh->compat = 0;
130129
for (i = 0; check[i].pat; i++) {
131-
debug_f("PATTERN IS %d for %s\n", i, check[i].pat);
132130
if (match_pattern_list(version, check[i].pat, 0) == 1) {
133131
debug_f("match: %s pat %s compat 0x%08x",
134132
version, check[i].pat, check[i].bugs);
@@ -155,13 +153,15 @@ compat_banner(struct ssh *ssh, const char *version)
155153
debug("Remote uses HPNSSH prefixes.");
156154
break;
157155
}
156+
/* if it's openssh and not hpn */
158157
if ((strstr(version, "OpenSSH_8.9") != NULL) ||
159158
(strstr(version, "OpenSSH_9") != NULL)) {
160159
ssh->compat |= SSH_RESTRICT_WINDOW;
161160
debug("Restricting adverstised window size.");
162161
}
163162
}
164163
debug("ssh->compat is %u", ssh->compat);
164+
return;
165165
}
166166
}
167167
debug_f("no match: %s", version);

kex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,8 +1753,8 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
17531753
debug("Non-HPN to HPN Connection.");
17541754

17551755
if(ssh->compat & SSH_RESTRICT_WINDOW)
1756-
debug ("---------------------- RESTRICT");
1757-
1756+
debug ("Window size restricted.");
1757+
17581758
mismatch = 0;
17591759
switch (remote_major) {
17601760
case 2:

ssh.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2194,14 +2194,6 @@ ssh_session2_setup(struct ssh *ssh, int id, int success, void *arg)
21942194
static void
21952195
hpn_options_init(struct ssh *ssh)
21962196
{
2197-
if (ssh->compat & SSH_HPNSSH)
2198-
debug("HPN to HPN Connection.");
2199-
else
2200-
debug("Non-HPN to HPN Connection.");
2201-
2202-
if(ssh->compat & SSH_RESTRICT_WINDOW)
2203-
debug ("---------------------- RESTRICT");
2204-
22052197
channel_set_hpn_disabled(options.hpn_disabled);
22062198
debug_f("HPN disabled: %d", options.hpn_disabled);
22072199
}

sshbuf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ sshbuf_check_reserve(const struct sshbuf *buf, size_t len)
371371
void
372372
sshbuf_set_window_max(struct sshbuf *buf, size_t len)
373373
{
374-
//buf->window_max = len;
374+
buf->window_max = len;
375375
}
376376

377377
int

0 commit comments

Comments
 (0)