diff options
Diffstat (limited to 'lib/birdlib.h')
-rw-r--r-- | lib/birdlib.h | 30 |
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 */ |