summaryrefslogtreecommitdiff
path: root/lib/birdlib.h
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2017-11-28 17:06:10 +0100
committerOndrej Zajicek (work) <santiago@crfreenet.org>2017-12-07 13:53:42 +0100
commit574b2324275d3292e98a8e329f791eb5c799f7f2 (patch)
tree37f5bcc1edf1bcdcd61380c76fe214afce523bcd /lib/birdlib.h
parent3b3b0910ffb1b212b1c9ea420db6c575a3ecb71a (diff)
Timers: Fix TBF and some last remains
Diffstat (limited to 'lib/birdlib.h')
-rw-r--r--lib/birdlib.h30
1 files changed, 8 insertions, 22 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h
index 9a77fc7b..f41cceb5 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -69,7 +69,7 @@ static inline int u64_cmp(u64 i1, u64 i2)
/* Microsecond time */
typedef s64 btime;
-typedef s64 bird_clock_t;
+//typedef s64 bird_clock_t;
#define S_ * (btime) 1000000
#define MS_ * (btime) 1000
@@ -85,37 +85,23 @@ typedef s64 bird_clock_t;
#define NS /1000
#endif
+#define TIME_INFINITY ((s64) 0x7fffffffffffffff)
+
/* Rate limiting */
struct tbf {
- bird_clock_t timestamp; /* Last update */
- u16 count; /* Available tokens */
+ btime timestamp; /* Last update */
+ u64 count; /* Available micro-tokens */
u16 burst; /* Max number of tokens */
- u16 rate; /* Rate of replenishment */
- u16 mark; /* Whether last op was limited */
+ u16 rate; /* Rate of replenishment (tokens / sec) */
+ u32 drop; /* Number of failed request since last successful */
};
/* Default TBF values for rate limiting log messages */
#define TBF_DEFAULT_LOG_LIMITS { .rate = 1, .burst = 5 }
-void tbf_update(struct tbf *f);
-
-static inline int
-tbf_limit(struct tbf *f)
-{
- tbf_update(f);
-
- if (!f->count)
- {
- f->mark = 1;
- return 1;
- }
-
- f->count--;
- f->mark = 0;
- return 0;
-}
+int tbf_limit(struct tbf *f);
/* Logging and dying */