summaryrefslogtreecommitdiff
path: root/lib/tbf.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tbf.c')
-rw-r--r--lib/tbf.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/tbf.c b/lib/tbf.c
index 39e18e57..e6e84b4f 100644
--- a/lib/tbf.c
+++ b/lib/tbf.c
@@ -8,22 +8,30 @@
*/
#include "nest/bird.h"
+#include "lib/timer.h"
-void
-tbf_update(struct tbf *f)
+int
+tbf_limit(struct tbf *f)
{
- bird_clock_t delta = now - f->timestamp;
+ btime delta = current_time() - f->timestamp;
- if (delta == 0)
- return;
-
- f->timestamp = now;
+ if (delta > 0)
+ {
+ u64 next = f->count + delta * f->rate;
+ u64 burst = (u64) f->burst << 20;
+ f->count = MIN(next, burst);
+ f->timestamp += delta;
+ }
- if ((0 < delta) && (delta < f->burst))
+ if (f->count < 1000000)
{
- u32 next = f->count + delta * f->rate;
- f->count = MIN(next, f->burst);
+ f->drop++;
+ return 1;
}
else
- f->count = f->burst;
+ {
+ f->count -= 1000000;
+ f->drop = 0;
+ return 0;
+ }
}