summaryrefslogtreecommitdiff
path: root/sysdep/unix
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2018-09-18 17:29:00 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2018-09-18 17:50:45 +0200
commitc0fc3e67185c1e0ff2d083572c6ad3983ba4ef25 (patch)
tree9fe17603f4fec18b7f9fbd8d8efc1f13a9bef8ee /sysdep/unix
parentafa14f1868f2c753efdc81ce8e2c2d44e6bdd80e (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 'sysdep/unix')
-rw-r--r--sysdep/unix/config.Y8
-rw-r--r--sysdep/unix/io.c44
-rw-r--r--sysdep/unix/log.c15
-rw-r--r--sysdep/unix/timer.h5
-rw-r--r--sysdep/unix/unix.h5
5 files changed, 48 insertions, 29 deletions
diff --git a/sysdep/unix/config.Y b/sysdep/unix/config.Y
index d6ab8cab..dc5804ed 100644
--- a/sysdep/unix/config.Y
+++ b/sysdep/unix/config.Y
@@ -42,9 +42,9 @@ syslog_name:
log_file:
text {
- FILE *f = tracked_fopen(new_config->pool, $1, "a");
+ struct rfile *f = rf_open(new_config->pool, $1, "a");
if (!f) cf_error("Unable to open log file `%s': %m", $1);
- $$ = f;
+ $$ = rf_file(f);
}
| SYSLOG syslog_name { $$ = NULL; new_config->syslog_name = $2; }
| STDERR { $$ = stderr; }
@@ -78,9 +78,9 @@ CF_ADDTO(conf, mrtdump_base)
mrtdump_base:
MRTDUMP PROTOCOLS mrtdump_mask ';' { new_config->proto_default_mrtdump = $3; }
| MRTDUMP text ';' {
- FILE *f = tracked_fopen(new_config->pool, $2, "a");
+ struct rfile *f = rf_open(new_config->pool, $2, "a");
if (!f) cf_error("Unable to open MRTDump file '%s': %m", $2);
- new_config->mrtdump_file = fileno(f);
+ new_config->mrtdump_file = rf_fileno(f);
}
;
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c
index 786c6a56..f7a9e29f 100644
--- a/sysdep/unix/io.c
+++ b/sysdep/unix/io.c
@@ -54,6 +54,7 @@
this to gen small latencies */
#define MAX_RX_STEPS 4
+
/*
* Tracked Files
*/
@@ -88,19 +89,32 @@ static struct resclass rf_class = {
NULL
};
-void *
-tracked_fopen(pool *p, char *name, char *mode)
+struct rfile *
+rf_open(pool *p, char *name, char *mode)
{
FILE *f = fopen(name, mode);
- if (f)
- {
- struct rfile *r = ralloc(p, &rf_class);
- r->f = f;
- }
- return f;
+ if (!f)
+ return NULL;
+
+ struct rfile *r = ralloc(p, &rf_class);
+ r->f = f;
+ return r;
+}
+
+void *
+rf_file(struct rfile *f)
+{
+ return f->f;
+}
+
+int
+rf_fileno(struct rfile *f)
+{
+ return fileno(f->f);
}
+
/**
* DOC: Timers
*
@@ -478,6 +492,20 @@ tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t)
strcpy(x, "<too-long>");
}
+int
+tm_format_real_time(char *x, size_t max, const char *fmt, bird_clock_t t)
+{
+ struct tm tm;
+
+ if (!localtime_r(&t, &tm))
+ return 0;
+
+ if (!strftime(x, max, fmt, &tm))
+ return 0;
+
+ return 1;
+}
+
/**
* DOC: Sockets
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 88a7188c..08623d01 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -24,7 +24,7 @@
#include "nest/bird.h"
#include "nest/cli.h"
-#include "nest/mrtdump.h"
+#include "conf/conf.h"
#include "lib/string.h"
#include "lib/lists.h"
#include "lib/unix.h"
@@ -327,16 +327,3 @@ log_init_debug(char *f)
if (dbgf)
setvbuf(dbgf, NULL, _IONBF, 0);
}
-
-void
-mrt_dump_message(struct proto *p, u16 type, u16 subtype, byte *buf, u32 len)
-{
- /* Prepare header */
- put_u32(buf+0, now_real);
- put_u16(buf+4, type);
- put_u16(buf+6, subtype);
- put_u32(buf+8, len - MRTDUMP_HDR_LENGTH);
-
- if (p->cf->global->mrtdump_file != -1)
- write(p->cf->global->mrtdump_file, buf, len);
-}
diff --git a/sysdep/unix/timer.h b/sysdep/unix/timer.h
index aa3ed143..b0f93307 100644
--- a/sysdep/unix/timer.h
+++ b/sysdep/unix/timer.h
@@ -74,8 +74,9 @@ bird_clock_t tm_parse_date(char *); /* Convert date to bird_clock_t */
bird_clock_t tm_parse_datetime(char *); /* Convert date to bird_clock_t */
#define TM_DATETIME_BUFFER_SIZE 32 /* Buffer size required by tm_format_datetime */
-void
-tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t);
+
+void tm_format_datetime(char *x, struct timeformat *fmt_spec, bird_clock_t t);
+int tm_format_real_time(char *x, size_t max, const char *fmt, bird_clock_t t);
#define TIME_T_IS_64BIT (sizeof(time_t) == 8)
#define TIME_T_IS_SIGNED ((time_t) -1 < 0)
diff --git a/sysdep/unix/unix.h b/sysdep/unix/unix.h
index 3ef2e3ef..6a05718c 100644
--- a/sysdep/unix/unix.h
+++ b/sysdep/unix/unix.h
@@ -14,6 +14,7 @@
struct pool;
struct iface;
struct birdsock;
+struct rfile;
/* main.c */
@@ -103,7 +104,9 @@ void io_init(void);
void io_loop(void);
void io_log_dump(void);
int sk_open_unix(struct birdsock *s, char *name);
-void *tracked_fopen(struct pool *, char *name, char *mode);
+struct rfile *rf_open(struct pool *, char *name, char *mode);
+void *rf_file(struct rfile *f);
+int rf_fileno(struct rfile *f);
void test_old_bird(char *path);