]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
upstream: Fix calculation of initial bandwidth limits. Account for
authordtucker@openbsd.org <dtucker@openbsd.org>
Fri, 7 Dec 2018 04:36:09 +0000 (04:36 +0000)
committerDamien Miller <djm@mindrot.org>
Thu, 27 Dec 2018 03:30:17 +0000 (14:30 +1100)
written bytes before the initial timer check so that the first buffer written
is accounted.  Set the threshold after which the timer is checked such that
the limit starts being computed as soon as possible, ie after the second
buffer is written.  This prevents an initial burst of traffic and provides a
more accurate bandwidth limit.  bz#2927, ok djm.

OpenBSD-Commit-ID: ff3ef76e4e43040ec198c2718d5682c36b255cb6

misc.c
misc.h

diff --git a/misc.c b/misc.c
index dd74c8d458748e8902684877574d8afb173adedd..275e68141ca80a726397c9b1e63061a45996eb3d 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.134 2018/11/16 03:26:01 djm Exp $ */
+/* $OpenBSD: misc.c,v 1.135 2018/12/07 04:36:09 dtucker Exp $ */
 /*
  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
  * Copyright (c) 2005,2006 Damien Miller.  All rights reserved.
@@ -1335,11 +1335,11 @@ bandwidth_limit_init(struct bwlimit *bw, u_int64_t kbps, size_t buflen)
 {
        bw->buflen = buflen;
        bw->rate = kbps;
-       bw->thresh = bw->rate;
+       bw->thresh = buflen;
        bw->lamt = 0;
        timerclear(&bw->bwstart);
        timerclear(&bw->bwend);
-}      
+}
 
 /* Callback from read/write loop to insert bandwidth-limiting delays */
 void
@@ -1348,12 +1348,11 @@ bandwidth_limit(struct bwlimit *bw, size_t read_len)
        u_int64_t waitlen;
        struct timespec ts, rm;
 
+       bw->lamt += read_len;
        if (!timerisset(&bw->bwstart)) {
                monotime_tv(&bw->bwstart);
                return;
        }
-
-       bw->lamt += read_len;
        if (bw->lamt < bw->thresh)
                return;
 
diff --git a/misc.h b/misc.h
index bcae6a509eef27be74b73906a1da6af213d1def7..2dd61dc32c39f6563e4f4f46156304ecbc1f2414 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.76 2018/11/16 03:26:01 djm Exp $ */
+/* $OpenBSD: misc.h,v 1.77 2018/12/07 04:36:09 dtucker Exp $ */
 
 /*
  * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -135,7 +135,9 @@ void                put_u32_le(void *, u_int32_t)
 
 struct bwlimit {
        size_t buflen;
-       u_int64_t rate, thresh, lamt;
+       u_int64_t rate;         /* desired rate in kbit/s */
+       u_int64_t thresh;       /* threshold after which we'll check timers */
+       u_int64_t lamt;         /* amount written in last timer interval */
        struct timeval bwstart, bwend;
 };