summaryrefslogtreecommitdiff
path: root/lib/birdlib.h
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2014-10-14 17:23:34 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2014-10-14 17:23:34 +0200
commit78342404ff573e85e396f0611014b90cea9b4c0a (patch)
tree39fd70db506dc05d83528b7afab258b07b8ac482 /lib/birdlib.h
parent178a197afb77770d8a90765e39065679936a45d1 (diff)
parentcfdea7b85f6c520cc5a62eb907d2190db14c9900 (diff)
Merge remote-tracking branch 'origin/master' into soft-int
Diffstat (limited to 'lib/birdlib.h')
-rw-r--r--lib/birdlib.h40
1 files changed, 33 insertions, 7 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h
index c49c5b99..84a6c1b4 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -74,6 +74,38 @@ typedef s64 btime;
#endif
+/* Rate limiting */
+
+struct tbf {
+ bird_clock_t timestamp; /* Last update */
+ u16 count; /* Available tokens */
+ u16 burst; /* Max number of tokens */
+ u16 rate; /* Rate of replenishment */
+ u16 mark; /* Whether last op was limited */
+};
+
+/* 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;
+}
+
+
/* Logging and dying */
typedef struct buffer {
@@ -94,16 +126,10 @@ typedef struct buffer {
#define LOG_BUFFER_SIZE 1024
-
-struct rate_limit {
- bird_clock_t timestamp;
- int count;
-};
-
#define log log_msg
void log_commit(int class, buffer *buf);
void log_msg(char *msg, ...);
-void log_rl(struct rate_limit *rl, char *msg, ...);
+void log_rl(struct tbf *rl, char *msg, ...);
void die(char *msg, ...) NORET;
void bug(char *msg, ...) NORET;