diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2018-11-20 17:38:19 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2018-11-20 17:45:35 +0100 |
commit | 863ecfc78538657e51f1ec67441aec32261aa405 (patch) | |
tree | 73b8628fbca9e04a554c5d08fe18bae4c647a51e /lib | |
parent | 6712e77271fb3cb4a3c48cd7b027b39c5cea00a2 (diff) |
The MRT protocol
The new MRT protocol is responsible for periodic RIB table dumps in the
MRT format (RFC 6396). Also the existing code for BGP4MP MRT dumps is
refactored and splitted between BGP to MRT protocols, will be more
integrated into MRT in the future.
Example:
protocol mrt {
table "*";
filename "%N_%F_%T.mrt";
period 60;
}
It is partially based on the old MRT code from Pavel Tvrdik.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/timer.c | 22 | ||||
-rw-r--r-- | lib/timer.h | 2 | ||||
-rw-r--r-- | lib/unaligned.h | 12 |
3 files changed, 23 insertions, 13 deletions
diff --git a/lib/timer.c b/lib/timer.c index ed731d26..ddf41340 100644 --- a/lib/timer.c +++ b/lib/timer.c @@ -305,7 +305,8 @@ tm_format_time(char *x, struct timeformat *fmt, btime t) btime rt = current_real_time() - dt; int v1 = !fmt->limit || (dt < fmt->limit); - tm_format_real_time(x, v1 ? fmt->fmt1 : fmt->fmt2, rt); + if (!tm_format_real_time(x, TM_DATETIME_BUFFER_SIZE, v1 ? fmt->fmt1 : fmt->fmt2, rt)) + strcpy(x, "<error>"); } /* Replace %f in format string with usec scaled to requested precision */ @@ -353,8 +354,8 @@ strfusec(char *buf, int size, const char *fmt, uint usec) return str - buf; } -void -tm_format_real_time(char *x, const char *fmt, btime t) +int +tm_format_real_time(char *x, size_t max, const char *fmt, btime t) { s64 t1 = t TO_S; s64 t2 = t - t1 S; @@ -362,17 +363,14 @@ tm_format_real_time(char *x, const char *fmt, btime t) time_t ts = t1; struct tm tm; if (!localtime_r(&ts, &tm)) - goto err; + return 0; byte tbuf[TM_DATETIME_BUFFER_SIZE]; - if (!strfusec(tbuf, TM_DATETIME_BUFFER_SIZE, fmt, t2)) - goto err; - - if (!strftime(x, TM_DATETIME_BUFFER_SIZE, tbuf, &tm)) - goto err; + if (!strfusec(tbuf, max, fmt, t2)) + return 0; - return; + if (!strftime(x, max, tbuf, &tm)) + return 0; -err: - strcpy(x, "<error>"); + return 1; } diff --git a/lib/timer.h b/lib/timer.h index ed8f0d02..3b99825f 100644 --- a/lib/timer.h +++ b/lib/timer.h @@ -122,6 +122,6 @@ struct timeformat { btime tm_parse_time(char *x); void tm_format_time(char *x, struct timeformat *fmt, btime t); -void tm_format_real_time(char *x, const char *fmt, btime t); +int tm_format_real_time(char *x, size_t max, const char *fmt, btime t); #endif diff --git a/lib/unaligned.h b/lib/unaligned.h index 0da1fdb4..dfe0906f 100644 --- a/lib/unaligned.h +++ b/lib/unaligned.h @@ -20,6 +20,12 @@ #include "sysdep/unix/endian.h" #include "lib/string.h" +static inline u8 +get_u8(const void *p) +{ + return * (u8 *) p; +} + static inline u16 get_u16(const void *p) { @@ -53,6 +59,12 @@ get_u64(const void *p) } static inline void +put_u8(void *p, u8 x) +{ + memcpy(p, &x, 1); +} + +static inline void put_u16(void *p, u16 x) { x = htons(x); |