diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-11-28 17:06:10 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2017-12-07 13:53:42 +0100 |
commit | 574b2324275d3292e98a8e329f791eb5c799f7f2 (patch) | |
tree | 37f5bcc1edf1bcdcd61380c76fe214afce523bcd /lib/tbf.c | |
parent | 3b3b0910ffb1b212b1c9ea420db6c575a3ecb71a (diff) |
Timers: Fix TBF and some last remains
Diffstat (limited to 'lib/tbf.c')
-rw-r--r-- | lib/tbf.c | 29 |
1 files changed, 18 insertions, 11 deletions
@@ -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 (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; + } } |