Skip to content

Commit 33398db

Browse files
committed
Cleanup of patch updated comments.
Removed references to items that are no longer implemented. Removed the timestamp element of the sshbuf struct. Removed time_diff from sshbuf.c as that used the buffer time stamp.
1 parent e8fd3de commit 33398db

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

sshbuf.c

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define SSHBUF_INTERNAL
2828
#include "sshbuf.h"
2929
#include "misc.h"
30+
/* #include "log.h" */
3031

3132
#define BUF_WATERSHED 256*1024
3233

@@ -51,25 +52,22 @@ struct sshbuf {
5152
int readonly; /* Refers to external, const data */
5253
u_int refcount; /* Tracks self and number of child buffers */
5354
struct sshbuf *parent; /* If child, pointer to parent */
54-
struct timeval buf_ts; /* creation time of buffer */
55-
size_t window_max; /* channel window max */
5655
char label[MAX_LABEL_LEN]; /* String for buffer label - debugging use */
5756
int type; /* type of buffer enum (sshbuf_types)*/
5857
};
5958

60-
float
61-
time_diff(struct timeval *start, struct timeval *end)
62-
{
63-
return (end->tv_sec - start->tv_sec) + 1e-6*(end->tv_usec - start->tv_usec);
64-
}
65-
59+
/* update the label string for a given sshbuf. Useful
60+
* for debugging */
6661
void
6762
sshbuf_relabel(struct sshbuf *buf, const char *label)
6863
{
6964
if (label != NULL)
7065
strncpy(buf->label, label, MAX_LABEL_LEN-1);
7166
}
7267

68+
/* set the type (from enum sshbuf_type) of the given sshbuf.
69+
* The purpose is to allow different classes of buffers to
70+
* follow different code paths if necessary */
7371
void
7472
sshbuf_type(struct sshbuf *buf, int type)
7573
{
@@ -393,38 +391,32 @@ sshbuf_allocate(struct sshbuf *buf, size_t len)
393391
* slowly. It's knows that it needs to grow but it only does so 32K
394392
* at a time. This means a lot of calls to realloc and memcpy which
395393
* kills performance until the buffer reaches some maximum size.
396-
* so we explicitly test for a buffer that's trying to grow and
397-
* if it is then we push the growth to whatever the adjusted value of
398-
* local_window_max happens to be. This significantly reduces overhead
394+
* So we explicitly test for a buffer that's trying to grow and
395+
* if it is then we push the growth by 4MB at a time. This can result in
396+
* the buffer being over allocated (in terms of actual needs) but the
397+
* process is fast. This significantly reduces overhead
399398
* and improves performance. In this case we look for a buffer that is trying
400399
* to grow larger than BUF_WATERSHED (256*1024 taken from PACKET_MAX_SIZE)
401-
* and where the local_window_max isn't zero (which is usally in the Channels
402-
* struct but we copied it into the shhbuf as window_max). If it is zero or
403-
* the buffer is smaller than BUF_WATERSHED we just use the
404-
* normal value for need. We also don't want to grow the buffer past
405-
* what we need (the size of window_max) so if the current allocation (in
406-
* buf->alloc) is greater than window_max we skip it.
407-
*
408-
* Turns out the extra functions on the following conditional aren't needed
409-
* -cjr 04/06/23
400+
* and explcitly check that the buffer is being used for inbound outbound
401+
* channel buffering.
402+
* Updated for 18.4.1 -cjr 04/20/24
410403
*/
411404
if (rlen > BUF_WATERSHED && (buf->type == BUF_CHANNEL_OUTPUT || buf->type == BUF_CHANNEL_INPUT)) {
412-
/* debug_f ("Prior: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu",
413-
buf->label, buf, rlen, need, buf->window_max, buf->max_size); */
405+
/* debug_f ("Prior: label: %s, %p, rlen is %zu need is %zu max_size is %zu",
406+
buf->label, buf, rlen, need, buf->max_size); */
414407
/* easiest thing to do is grow the nuffer by 4MB each time. It might end
415408
* up being somewhat overallocated but works quickly */
416409
need = (4*1024*1024);
417410
rlen = ROUNDUP(buf->alloc + need, SSHBUF_SIZE_INC);
418-
/* debug_f ("Post: label: %s, %p, rlen is %zu need is %zu win_max is %zu max_size is %zu", */
419-
/* buf->label, buf, rlen, need, buf->window_max, buf->max_size); */
411+
/* debug_f ("Post: label: %s, %p, rlen is %zu need is %zu max_size is %zu", */
412+
/* buf->label, buf, rlen, need, buf->max_size); */
420413
}
421414
SSHBUF_DBG(("need %zu initial rlen %zu", need, rlen));
422415

423416
/* rlen might be above the max allocation */
424-
if (rlen > buf->max_size) {
417+
if (rlen > buf->max_size)
425418
rlen = buf->max_size;
426-
/* debug_f("set rlen to %zu", buf->max_size);*/
427-
}
419+
428420
SSHBUF_DBG(("adjusted rlen %zu", rlen));
429421
if ((dp = recallocarray(buf->d, buf->alloc, rlen, 1)) == NULL) {
430422
SSHBUF_DBG(("realloc fail"));

0 commit comments

Comments
 (0)