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

Implements token bucket filter for rate limiting.

This commit is contained in:
Ondrej Zajicek
2014-10-02 11:41:34 +02:00
parent dcde7ae597
commit 1123e70740
10 changed files with 85 additions and 42 deletions

29
lib/tbf.c Normal file
View File

@@ -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;
}