diff options
Diffstat (limited to 'sysdep/unix')
-rw-r--r-- | sysdep/unix/config.Y | 14 | ||||
-rw-r--r-- | sysdep/unix/io.c | 9 | ||||
-rw-r--r-- | sysdep/unix/log.c | 14 |
3 files changed, 36 insertions, 1 deletions
diff --git a/sysdep/unix/config.Y b/sysdep/unix/config.Y index 1917fe6..46c5862 100644 --- a/sysdep/unix/config.Y +++ b/sysdep/unix/config.Y @@ -63,6 +63,20 @@ log_cat: | BUG { $$ = L_BUG[0]; } ; + +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"); + if (!f) cf_error("Unable to open MRTDump file '%s': %m", $2); + new_config->mrtdump_file = fileno(f); + } + ; + + + /* Unix specific commands */ CF_CLI_HELP(CONFIGURE, [soft] [\"<file>\"], [[Reload configuration]]) diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index cd5c5db..74612ac 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -947,7 +947,14 @@ sk_passive_connected(sock *s, struct sockaddr *sa, int al, int type) t->rbsize = s->rbsize; t->tbsize = s->tbsize; if (type == SK_TCP) - get_sockaddr((sockaddr *) sa, &t->daddr, &t->dport, 1); + { + sockaddr lsa; + int lsa_len = sizeof(lsa); + if (getsockname(fd, (struct sockaddr *) &lsa, &lsa_len) == 0) + get_sockaddr(&lsa, &t->saddr, &t->sport, 1); + + get_sockaddr((sockaddr *) sa, &t->daddr, &t->dport, 1); + } sk_insert(t); if (err = sk_setup(t)) { diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c index eb08309..dad0c5d 100644 --- a/sysdep/unix/log.c +++ b/sysdep/unix/log.c @@ -22,6 +22,7 @@ #include "nest/bird.h" #include "nest/cli.h" +#include "nest/mrtdump.h" #include "lib/string.h" #include "lib/lists.h" #include "lib/unix.h" @@ -261,3 +262,16 @@ 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); +} |