1
0
mirror of https://gitlab.labs.nic.cz/labs/bird.git synced 2024-05-11 16:54:54 +00:00

Timers: Fix TBF and some last remains

This commit is contained in:
Ondrej Zajicek (work)
2017-11-28 17:06:10 +01:00
parent 3b3b0910ff
commit 574b232427
11 changed files with 45 additions and 50 deletions

View File

@@ -10,21 +10,28 @@
#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 ((0 < delta) && (delta < f->burst))
if (delta > 0)
{
u32 next = f->count + delta * f->rate;
f->count = MIN(next, f->burst);
u64 next = f->count + delta * f->rate;
u64 burst = (u64) f->burst << 20;
f->count = MIN(next, burst);
f->timestamp += delta;
}
if (f->count < 1000000)
{
f->drop++;
return 1;
}
else
f->count = f->burst;
{
f->count -= 1000000;
f->drop = 0;
return 0;
}
}