summaryrefslogtreecommitdiff
path: root/lib/birdlib.h
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2013-11-22 02:43:41 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2013-11-22 02:48:44 +0100
commit0aeac9cb7f9887374ce0258c8653f9518529bf08 (patch)
tree2d16e0904be1658c08a4c779cf4132bc8bf20efa /lib/birdlib.h
parent8931425d02dd8656b48142f608d3119ab6f4a96f (diff)
parent7c9930f9c8feb3b08f7a9e94a08807ccbbc096f5 (diff)
Merge commit 'origin/bfd'
Diffstat (limited to 'lib/birdlib.h')
-rw-r--r--lib/birdlib.h54
1 files changed, 47 insertions, 7 deletions
diff --git a/lib/birdlib.h b/lib/birdlib.h
index 7e6e8526..b7a5a6a6 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -10,6 +10,7 @@
#define _BIRD_BIRDLIB_H_
#include "timer.h"
+#include "alloca.h"
/* Ugly structure offset handling macros */
@@ -19,12 +20,14 @@
/* Utility macros */
-#ifdef PARSER
#define _MIN(a,b) (((a)<(b))?(a):(b))
#define _MAX(a,b) (((a)>(b))?(a):(b))
-#else
-#define MIN(a,b) (((a)<(b))?(a):(b))
-#define MAX(a,b) (((a)>(b))?(a):(b))
+
+#ifndef PARSER
+#undef MIN
+#undef MAX
+#define MIN(a,b) _MIN(a,b)
+#define MAX(a,b) _MAX(a,b)
#endif
#define ABS(a) ((a)>=0 ? (a) : -(a))
@@ -40,24 +43,61 @@
#define IP_VERSION 6
#endif
+
/* Macros for gcc attributes */
#define NORET __attribute__((noreturn))
#define UNUSED __attribute__((unused))
+
+/* Microsecond time */
+
+typedef s64 btime;
+
+#define _S *1000000
+#define _MS *1000
+#define _US *1
+#define TO_S /1000000
+#define TO_MS /1000
+#define TO_US /1
+
+#ifndef PARSER
+#define S _S
+#define MS _MS
+#define US _US
+#endif
+
+
/* Logging and dying */
+typedef struct buffer {
+ byte *start;
+ byte *pos;
+ byte *end;
+} buffer;
+
+#define STACK_BUFFER_INIT(buf,size) \
+ do { \
+ buf.start = alloca(size); \
+ buf.pos = buf.start; \
+ buf.end = buf.start + size; \
+ } while(0)
+
+#define LOG_BUFFER_INIT(buf) \
+ STACK_BUFFER_INIT(buf, LOG_BUFFER_SIZE)
+
+#define LOG_BUFFER_SIZE 1024
+
+
struct rate_limit {
bird_clock_t timestamp;
int count;
};
#define log log_msg
-void log_reset(void);
-void log_commit(int class);
+void log_commit(int class, buffer *buf);
void log_msg(char *msg, ...);
void log_rl(struct rate_limit *rl, char *msg, ...);
-void logn(char *msg, ...);
void die(char *msg, ...) NORET;
void bug(char *msg, ...) NORET;