1 diff -p -u openssh-4.2p1/buffer.c openssh-hpn-4.2p1/buffer.c
2 --- openssh-4.2p1/buffer.c 2005-03-14 07:22:26.000000000 -0500
3 +++ openssh-hpn-4.2p1/buffer.c 2005-09-08 12:08:40.000000000 -0400
4 @@ -107,7 +107,7 @@ restart:
5 /* Increase the size of the buffer and retry. */
7 newlen = buffer->alloc + len + 32768;
8 - if (newlen > BUFFER_MAX_LEN)
9 + if (newlen > BUFFER_MAX_HPN_LEN)
10 fatal("buffer_append_space: alloc %u not supported",
12 buffer->buf = xrealloc(buffer->buf, newlen);
13 diff -p -u openssh-4.2p1/buffer.h openssh-hpn-4.2p1/buffer.h
14 --- openssh-4.2p1/buffer.h 2005-03-14 07:22:26.000000000 -0500
15 +++ openssh-hpn-4.2p1/buffer.h 2005-09-08 12:08:40.000000000 -0400
16 @@ -25,6 +25,7 @@ typedef struct {
18 #define BUFFER_MAX_CHUNK 0x100000
19 #define BUFFER_MAX_LEN 0xa00000
20 +#define BUFFER_MAX_HPN_LEN (2>>29)-1
22 void buffer_init(Buffer *);
23 void buffer_clear(Buffer *);
24 diff -p -u openssh-4.2p1/channels.c openssh-hpn-4.2p1/channels.c
25 --- openssh-4.2p1/channels.c 2005-07-17 03:22:45.000000000 -0400
26 +++ openssh-hpn-4.2p1/channels.c 2005-09-08 12:08:40.000000000 -0400
27 @@ -262,6 +262,7 @@ channel_new(char *ctype, int type, int r
28 c->local_window_max = window;
29 c->local_consumed = 0;
30 c->local_maxpacket = maxpack;
31 + c->dynamic_window = 0;
33 c->remote_name = xstrdup(remote_name);
35 @@ -716,9 +717,9 @@ static void
36 channel_pre_open(Channel *c, fd_set * readset, fd_set * writeset)
38 u_int limit = compat20 ? c->remote_window : packet_get_maxsize();
41 /* check buffer limits */
42 - limit = MIN(limit, (BUFFER_MAX_LEN - BUFFER_MAX_CHUNK - CHAN_RBUF));
43 + limit = MIN(limit, (BUFFER_MAX_HPN_LEN - BUFFER_MAX_CHUNK - CHAN_RBUF));
45 if (c->istate == CHAN_INPUT_OPEN &&
47 @@ -1537,14 +1538,29 @@ channel_check_window(Channel *c)
48 !(c->flags & (CHAN_CLOSE_SENT|CHAN_CLOSE_RCVD)) &&
49 c->local_window < c->local_window_max/2 &&
50 c->local_consumed > 0) {
51 + u_int32_t tcpwinsz = 0;
52 + socklen_t optsz = sizeof(tcpwinsz);
54 + u_int32_t addition = 0;
55 + if (c->dynamic_window) {
56 + ret = getsockopt(packet_get_connection_in(),
57 + SOL_SOCKET, SO_RCVBUF, &tcpwinsz, &optsz);
58 + if ((ret == 0) && tcpwinsz > BUFFER_MAX_HPN_LEN)
59 + tcpwinsz = BUFFER_MAX_HPN_LEN;
61 + if (c->dynamic_window && (ret == 0) &&
62 + (tcpwinsz > c->local_window_max)) {
63 + addition = tcpwinsz - c->local_window_max;
64 + c->local_window_max += addition;
66 packet_start(SSH2_MSG_CHANNEL_WINDOW_ADJUST);
67 packet_put_int(c->remote_id);
68 - packet_put_int(c->local_consumed);
69 + packet_put_int(c->local_consumed + addition);
71 debug2("channel %d: window %d sent adjust %d",
72 c->self, c->local_window,
74 - c->local_window += c->local_consumed;
75 + c->local_window += c->local_consumed + addition;
76 c->local_consumed = 0;
79 diff -p -u openssh-4.2p1/channels.h openssh-hpn-4.2p1/channels.h
80 --- openssh-4.2p1/channels.h 2005-07-17 03:19:25.000000000 -0400
81 +++ openssh-hpn-4.2p1/channels.h 2005-09-08 12:08:40.000000000 -0400
82 @@ -99,6 +99,7 @@ struct Channel {
83 u_int local_window_max;
85 u_int local_maxpacket;
88 int single_connection;
90 @@ -119,11 +120,11 @@ struct Channel {
92 /* default window/packet sizes for tcp/x11-fwd-channel */
93 #define CHAN_SES_PACKET_DEFAULT (32*1024)
94 -#define CHAN_SES_WINDOW_DEFAULT (4*CHAN_SES_PACKET_DEFAULT)
95 +#define CHAN_SES_WINDOW_DEFAULT (0xa00000/2)
96 #define CHAN_TCP_PACKET_DEFAULT (32*1024)
97 -#define CHAN_TCP_WINDOW_DEFAULT (4*CHAN_TCP_PACKET_DEFAULT)
98 +#define CHAN_TCP_WINDOW_DEFAULT (0xa00000/2)
99 #define CHAN_X11_PACKET_DEFAULT (16*1024)
100 -#define CHAN_X11_WINDOW_DEFAULT (4*CHAN_X11_PACKET_DEFAULT)
101 +#define CHAN_X11_WINDOW_DEFAULT (0xa00000/2)
103 /* possible input states */
104 #define CHAN_INPUT_OPEN 0
105 diff -p -u openssh-4.2p1/compat.c openssh-hpn-4.2p1/compat.c
106 --- openssh-4.2p1/compat.c 2005-03-01 05:24:33.000000000 -0500
107 +++ openssh-hpn-4.2p1/compat.c 2005-09-08 12:08:40.000000000 -0400
108 @@ -162,6 +162,14 @@ compat_datafellows(const char *version)
109 strlen(check[i].pat), 0) == 1) {
110 debug("match: %s pat %s", version, check[i].pat);
111 datafellows = check[i].bugs;
112 + /* Check to see if the remote side is OpenSSH and not HPN */
113 + if(strstr(version,"OpenSSH") != NULL)
115 + if (strstr(version,"hpn") == NULL)
117 + datafellows |= SSH_BUG_LARGEWINDOW;
123 diff -p -u openssh-4.2p1/compat.h openssh-hpn-4.2p1/compat.h
124 --- openssh-4.2p1/compat.h 2005-03-01 05:24:33.000000000 -0500
125 +++ openssh-hpn-4.2p1/compat.h 2005-09-08 12:08:40.000000000 -0400
127 #define SSH_BUG_PROBE 0x00400000
128 #define SSH_BUG_FIRSTKEX 0x00800000
129 #define SSH_OLD_FORWARD_ADDR 0x01000000
130 +#define SSH_BUG_LARGEWINDOW 0x02000000
132 void enable_compat13(void);
133 void enable_compat20(void);
134 Common subdirectories: openssh-4.2p1/contrib and openssh-hpn-4.2p1/contrib
135 Common subdirectories: openssh-4.2p1/openbsd-compat and openssh-hpn-4.2p1/openbsd-compat
136 diff -p -u openssh-4.2p1/readconf.h openssh-hpn-4.2p1/readconf.h
137 --- openssh-4.2p1/readconf.h 2005-06-15 23:19:42.000000000 -0400
138 +++ openssh-hpn-4.2p1/readconf.h 2005-09-08 12:08:40.000000000 -0400
139 @@ -57,6 +57,7 @@ typedef struct {
140 int compression_level; /* Compression level 1 (fast) to 9
142 int tcp_keep_alive; /* Set SO_KEEPALIVE. */
143 + int tcp_rcv_buf; /* user switch to set tcp recv buffer */
144 LogLevel log_level; /* Level for logging. */
146 int port; /* Port to connect. */
147 Common subdirectories: openssh-4.2p1/regress and openssh-hpn-4.2p1/regress
148 Common subdirectories: openssh-4.2p1/scard and openssh-hpn-4.2p1/scard
149 diff -p -u openssh-4.2p1/scp.c openssh-hpn-4.2p1/scp.c
150 --- openssh-4.2p1/scp.c 2005-08-02 03:07:08.000000000 -0400
151 +++ openssh-hpn-4.2p1/scp.c 2005-09-08 12:10:35.000000000 -0400
152 @@ -231,7 +231,7 @@ main(int argc, char **argv)
153 addargs(&args, "-oClearAllForwardings yes");
156 - while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q1246S:o:F:")) != -1)
157 + while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q1246S:o:F:w:")) != -1)
159 /* User-visible flags. */
161 @@ -292,6 +292,9 @@ main(int argc, char **argv)
162 setmode(0, O_BINARY);
166 + addargs(&args, "-w%s", optarg);
171 @@ -507,7 +510,7 @@ source(int argc, char **argv)
172 off_t i, amt, statbytes;
174 int fd = -1, haderr, indx;
175 - char *last, *name, buf[2048];
176 + char *last, *name, buf[16384];
179 for (indx = 0; indx < argc; ++indx) {
180 @@ -567,7 +570,11 @@ syserr: run_err("%s: %s", name, strerr
181 (void) atomicio(vwrite, remout, buf, strlen(buf));
184 - if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
185 + /* this change decreases the number of read/write syscalls*/
186 + /* when scp acts as data source. this is the critical change*/
187 + /* buf can actually remain at 2k but increasing both to 16k*/
188 + /* seemed to make sense*/
189 + if ((bp = allocbuf(&buffer, fd, sizeof(buf))) == NULL) {
190 next: (void) close(fd);
193 @@ -728,7 +735,7 @@ sink(int argc, char **argv)
194 int amt, exists, first, mask, mode, ofd, omode;
195 off_t size, statbytes;
196 int setimes, targisdir, wrerrno = 0;
197 - char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
198 + char ch, *cp, *np, *targ, *why, *vect[1], buf[16384];
199 struct timeval tv[2];
202 @@ -889,7 +896,7 @@ bad: run_err("%s: %s", np, strerror(er
205 (void) atomicio(vwrite, remout, "", 1);
206 - if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
207 + if ((bp = allocbuf(&buffer, ofd, sizeof(buf))) == NULL) {
211 @@ -899,8 +906,8 @@ bad: run_err("%s: %s", np, strerror(er
214 start_progress_meter(curfile, size, &statbytes);
215 - for (count = i = 0; i < size; i += 4096) {
217 + for (count = i = 0; i < size; i += sizeof(buf)) {
222 @@ -917,7 +924,7 @@ bad: run_err("%s: %s", np, strerror(er
227 + bwlimit(sizeof(buf));
229 if (count == bp->cnt) {
230 /* Keep reading so we stay sync'd up. */
231 @@ -1033,7 +1040,7 @@ usage(void)
233 (void) fprintf(stderr,
234 "usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n"
235 - " [-l limit] [-o ssh_option] [-P port] [-S program]\n"
236 + " [-l limit] [-o ssh_option] [-P port] [-w buffer size] [-S program]\n"
237 " [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
240 diff -p -u openssh-4.2p1/serverloop.c openssh-hpn-4.2p1/serverloop.c
241 --- openssh-4.2p1/serverloop.c 2005-07-17 03:26:44.000000000 -0400
242 +++ openssh-hpn-4.2p1/serverloop.c 2005-09-08 12:08:41.000000000 -0400
243 @@ -895,6 +895,8 @@ server_request_session(void)
244 c = channel_new("session", SSH_CHANNEL_LARVAL,
245 -1, -1, -1, /*window size*/0, CHAN_SES_PACKET_DEFAULT,
246 0, "server-session", 1);
247 + if (!(datafellows & SSH_BUG_LARGEWINDOW))
248 + c->dynamic_window = 1;
249 if (session_open(the_authctxt, c->self) != 1) {
250 debug("session open failed, free channel %d", c->self);
252 diff -p -u openssh-4.2p1/sshconnect.c openssh-hpn-4.2p1/sshconnect.c
253 --- openssh-4.2p1/sshconnect.c 2005-07-17 03:22:46.000000000 -0400
254 +++ openssh-hpn-4.2p1/sshconnect.c 2005-09-08 12:08:41.000000000 -0400
255 @@ -167,13 +167,58 @@ ssh_create_socket(int privileged, struct
258 debug("Allocated local port %d.", p);
261 + /* tuning needs to happen after the socket is */
262 + /* created but before the connection happens */
263 + /* so winscale is negotiated properly -cjr */
265 + /* Set tcp receive buffer if requested */
266 + if (options.tcp_rcv_buf)
268 + if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
269 + (void *)&options.tcp_rcv_buf,
270 + sizeof(options.tcp_rcv_buf)) >= 0)
272 + debug("setsockopt SO_RCVBUF: %.100s", strerror(errno));
276 + /* coudln't set the socket size to use spec. */
277 + /* should default to system param and continue */
278 + /* warn the user though - cjr */
279 + error("Couldn't set socket receive buffer as requested. Continuing anyway.");
284 sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
286 error("socket: %.100s", strerror(errno));
288 - /* Bind the socket to an alternative local IP address */
290 + /* tuning needs to happen after the socket is */
291 + /* created but before the connection happens */
292 + /* so winscale is negotiated properly -cjr */
294 + /* Set tcp receive buffer if requested */
295 + if (options.tcp_rcv_buf)
297 + if (setsockopt(sock, SOL_SOCKET, SO_RCVBUF,
298 + (void *)&options.tcp_rcv_buf,
299 + sizeof(options.tcp_rcv_buf)) >= 0)
301 + debug("setsockopt SO_RCVBUF: %.100s", strerror(errno));
305 + /* coudln't set the socket size to use spec. */
306 + /* should default to system param and continue */
307 + /* warn the user though - cjr */
308 + error("Couldn't set socket receive buffer as requested. Continuing anyway.");
312 + /* Bind the socket to an alternative local IP address */
313 if (options.bind_address == NULL)
316 @@ -480,7 +525,7 @@ ssh_exchange_identification(void)
317 snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n",
318 compat20 ? PROTOCOL_MAJOR_2 : PROTOCOL_MAJOR_1,
319 compat20 ? PROTOCOL_MINOR_2 : minor1,
322 if (atomicio(vwrite, connection_out, buf, strlen(buf)) != strlen(buf))
323 fatal("write: %.100s", strerror(errno));
324 client_version_string = xstrdup(buf);
325 diff -p -u openssh-4.2p1/sshd.c openssh-hpn-4.2p1/sshd.c
326 --- openssh-4.2p1/sshd.c 2005-07-26 07:54:56.000000000 -0400
327 +++ openssh-hpn-4.2p1/sshd.c 2005-09-08 12:08:41.000000000 -0400
328 @@ -377,7 +377,7 @@ sshd_exchange_identification(int sock_in
329 major = PROTOCOL_MAJOR_1;
330 minor = PROTOCOL_MINOR_1;
332 - snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n", major, minor, SSH_VERSION);
333 + snprintf(buf, sizeof buf, "SSH-%d.%d-%.100s\n", major, minor, SSH_RELEASE);
334 server_version_string = xstrdup(buf);
336 /* Send our protocol version identification. */
337 diff -p -u openssh-4.2p1/version.h openssh-hpn-4.2p1/version.h
338 --- openssh-4.2p1/version.h 2005-08-31 05:47:07.000000000 -0400
339 +++ openssh-hpn-4.2p1/version.h 2005-09-08 12:08:41.000000000 -0400
341 #define SSH_VERSION "OpenSSH_4.2"
343 #define SSH_PORTABLE "p1"
344 -#define SSH_RELEASE SSH_VERSION SSH_PORTABLE
345 +#define SSH_HPN "-hpn"
346 +#define SSH_RELEASE SSH_VERSION SSH_PORTABLE SSH_HPN
347 diff -p -u openssh-4.2p1/ssh.c openssh-hpn-4.2p1/ssh.c
348 --- openssh-4.2p1/ssh.c 2005-10-28 12:24:10.000000000 +0200
349 +++ openssh-hpn-4.2p1/ssh.c 2005-10-28 12:26:55.000000000 +0200
350 @@ -161,7 +161,7 @@ usage(void)
353 "usage: ssh [-1246AaBCfgkMNnqsTtVvXxY] [-b bind_address] [-c cipher_spec]\n"
354 -" [-D port] [-e escape_char] [-F configfile]\n"
355 +" [-D port] [-e escape_char] [-F configfile] [-w receive buffer size]\n"
356 " [-i identity_file] [-L [bind_address:]port:host:hostport]\n"
357 " [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]\n"
358 " [-R [bind_address:]port:host:hostport] [-S ctl_path]\n"
359 @@ -242,9 +242,12 @@ main(int ac, char **av)
360 /* Parse command-line arguments. */
363 + /* need to set options.tcp_rcv_buf to 0 */
364 + options.tcp_rcv_buf = 0;
367 while ((opt = getopt(ac, av,
368 - "1246ab:c:e:fgi:kl:m:no:p:qstvxABCD:F:I:L:MNO:PR:S:TVXY")) != -1) {
369 + "1246ab:c:e:fgi:kl:m:no:p:qstvw:xACD:F:I:L:MNO:PR:S:TVXY")) != -1) {
372 options.protocol = SSH_PROTO_1;
373 @@ -489,6 +492,9 @@ again:
378 + options.tcp_rcv_buf = atoi(optarg);
383 @@ -1098,6 +1104,7 @@ ssh_session2_open(void)
384 window = CHAN_SES_WINDOW_DEFAULT;
385 packetmax = CHAN_SES_PACKET_DEFAULT;
387 + window = 4*CHAN_SES_PACKET_DEFAULT;
391 @@ -1106,6 +1113,9 @@ ssh_session2_open(void)
392 window, packetmax, CHAN_EXTENDED_WRITE,
393 "client-session", /*nonblock*/0);
395 + if (!tty_flag && (!(datafellows & SSH_BUG_LARGEWINDOW))) {
396 + c->dynamic_window = 1;
398 debug3("ssh_session2_open: channel_new: %d", c->self);
400 channel_send_open(c->self);