diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2014-10-14 17:23:34 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2014-10-14 17:23:34 +0200 |
commit | 78342404ff573e85e396f0611014b90cea9b4c0a (patch) | |
tree | 39fd70db506dc05d83528b7afab258b07b8ac482 /lib/tbf.c | |
parent | 178a197afb77770d8a90765e39065679936a45d1 (diff) | |
parent | cfdea7b85f6c520cc5a62eb907d2190db14c9900 (diff) |
Merge remote-tracking branch 'origin/master' into soft-int
Diffstat (limited to 'lib/tbf.c')
-rw-r--r-- | lib/tbf.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/tbf.c b/lib/tbf.c new file mode 100644 index 00000000..39e18e57 --- /dev/null +++ b/lib/tbf.c @@ -0,0 +1,29 @@ +/* + * BIRD Library -- Token Bucket Filter + * + * (c) 2014 Ondrej Zajicek <santiago@crfreenet.org> + * (c) 2014 CZ.NIC z.s.p.o. + * + * Can be freely distributed and used under the terms of the GNU GPL. + */ + +#include "nest/bird.h" + +void +tbf_update(struct tbf *f) +{ + bird_clock_t delta = now - f->timestamp; + + if (delta == 0) + return; + + f->timestamp = now; + + if ((0 < delta) && (delta < f->burst)) + { + u32 next = f->count + delta * f->rate; + f->count = MIN(next, f->burst); + } + else + f->count = f->burst; +} |